예제 #1
0
파일: entity.go 프로젝트: genbattle/haunts
func DoInteractWithObjectFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "DoInteractWithObject", game.LuaEntity) {
			return 0
		}
		object := game.LuaToEntity(L, a.ent.Game(), -1)
		var interact *actions.Interact
		for _, action := range a.ent.Actions {
			var ok bool
			interact, ok = action.(*actions.Interact)
			if ok {
				break
			}
		}
		if interact == nil {
			game.LuaDoError(L, "Tried to interact with an object, but don't have an interact action.")
			L.PushNil()
			return 1
		}
		exec := interact.AiInteractWithObject(a.ent, object)
		if exec != nil {
			a.execs <- exec
			<-a.pause
			L.PushBoolean(true)
		} else {
			L.PushNil()
		}
		return 1
	}
}