package movement

import (
	"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
	"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
	"lab.zaar.be/thefish/alchemyst-go/engine/mob"
	"lab.zaar.be/thefish/alchemyst-go/engine/types"
	"reflect"
)

type Moveable struct {
	Controller *ecs.Controller
	Level *gamemap.Level
}


func (mov Moveable) Walk() {

}

//fixme change it to WhatsOnTile
func (mov Moveable) IsBlocked(c types.Coords) bool {
	if mov.Level.GetTile(c).BlocksPass == true {
		return true
	}
	list :=  mov.Controller.GetEntitiesWithComponent(mob.Mob{}.TypeOf())
	for idx, _ := range list {
		coords := mov.Controller.GetComponent(list[idx], types.Coords{}.TypeOf())
		if coords == nil {
			continue
		}
		coords = coords.(types.Coords)
		if coords != c {
			continue
		}
		m := mov.Controller.GetComponent(list[idx], mob.Mob{}.TypeOf())
		if m == nil {
			continue
		}
		if m.(mob.Mob).BlocksPass {
			return true
		}
	}
	return false
}

func (mov Moveable) TypeOf() reflect.Type {
	return reflect.TypeOf(mov)
}