func (a *SummonAction) Push(L *lua.State) { L.NewTable() L.PushString("Type") L.PushString("Summon") L.SetTable(-3) L.PushString("Name") L.PushString(a.Name) L.SetTable(-3) L.PushString("Ap") L.PushInteger(a.Ap) L.SetTable(-3) L.PushString("Entity") L.PushString(a.Ent_name) L.SetTable(-3) L.PushString("Los") L.PushBoolean(a.Personal_los) L.SetTable(-3) L.PushString("Range") L.PushInteger(a.Range) L.SetTable(-3) L.PushString("Ammo") if a.Current_ammo == -1 { L.PushInteger(1000) } else { L.PushInteger(a.Current_ammo) } L.SetTable(-3) }
func (exec interactExec) Push(L *lua.State, g *game.Game) { exec.BasicActionExec.Push(L, g) if L.IsNil(-1) { return } L.PushString("Toggle Door") L.PushBoolean(exec.Toggle_door) L.SetTable(-3) if exec.Toggle_door { L.PushString("Door") game.LuaPushDoor(L, g, exec.getDoor(g)) } else { L.PushString("Target") game.LuaPushEntity(L, g.EntityById(exec.Target)) } L.SetTable(-3) }
// Decodes a value from the reader and pushes it onto the stack func LuaDecodeValue(r io.Reader, L *lua.State, g *Game) error { var le luaEncodable err := binary.Read(r, binary.LittleEndian, &le) if err != nil { return err } switch le { case luaEncBool: var v byte err = binary.Read(r, binary.LittleEndian, &v) L.PushBoolean(v == 1) case luaEncNumber: var f float64 err = binary.Read(r, binary.LittleEndian, &f) L.PushNumber(f) case luaEncNil: L.PushNil() case luaEncEntity: var id uint64 err = binary.Read(r, binary.LittleEndian, &id) ent := g.EntityById(EntityId(id)) LuaPushEntity(L, ent) if ent != nil { base.Log().Printf("LUA: Push Ent %s", ent.Name) } else { base.Log().Printf("LUA: Push Ent NIL") } case luaEncTable: err = LuaDecodeTable(r, L, g) case luaEncString: var length uint32 err = binary.Read(r, binary.LittleEndian, &length) if err != nil { return err } sb := make([]byte, length) err = binary.Read(r, binary.LittleEndian, &sb) L.PushString(string(sb)) default: return errors.New(fmt.Sprintf("Unknown lua value id == %d.", le)) } if err != nil { return err } return nil }
// Pushes an entity onto the stack, it is a table containing the following: // e.id -> EntityId of this entity // e.name -> Name as displayed to the user // e.gear_options -> Table mapping gear to icon for all available gear // e.gear -> Name of the selected gear, nil if none is selected // e.actions -> Array of actions this entity has available func LuaPushEntity(L *lua.State, _ent *Entity) { if _ent == nil { L.PushNil() return } // id and Name can be added to the ent table as static data since they // never change. L.NewTable() L.PushString("Name") L.PushString(_ent.Name) L.SetTable(-3) L.PushString("id") L.PushInteger(int(_ent.Id)) L.SetTable(-3) L.PushString("type") L.PushString("Entity") L.SetTable(-3) id := _ent.Id // Meta table for the Entity so that any dynamic data is generated // on-the-fly LuaPushSmartFunctionTable(L, FunctionTable{ "Conditions": func() { ent := _ent.Game().EntityById(id) L.NewTable() for _, condition := range ent.Stats.ConditionNames() { L.PushString(condition) L.PushBoolean(true) L.SetTable(-3) } }, "Side": func() { ent := _ent.Game().EntityById(id) L.NewTable() sides := map[string]Side{ "Denizen": SideHaunt, "Intruder": SideExplorers, "Npc": SideNpc, "Object": SideObject, } for str, side := range sides { L.PushString(str) L.PushBoolean(ent.Side() == side) L.SetTable(-3) } }, "State": func() { ent := _ent.Game().EntityById(id) L.PushString(ent.Sprite().State()) }, "Master": func() { ent := _ent.Game().EntityById(id) L.NewTable() for key, val := range ent.Ai_data { L.PushString(key) L.PushString(val) L.SetTable(-3) } }, "GearOptions": func() { ent := _ent.Game().EntityById(id) L.NewTable() if ent.ExplorerEnt != nil { for _, gear_name := range ent.ExplorerEnt.Gear_names { var g Gear g.Defname = gear_name base.GetObject("gear", &g) L.PushString(gear_name) L.PushString(g.Large_icon.Path.String()) L.SetTable(-3) } } }, "Gear": func() { ent := _ent.Game().EntityById(id) if ent.ExplorerEnt != nil && ent.ExplorerEnt.Gear != nil { L.PushString(ent.ExplorerEnt.Gear.Name) } else { L.PushNil() } }, "Actions": func() { ent := _ent.Game().EntityById(id) L.NewTable() for _, action := range ent.Actions { L.PushString(action.String()) action.Push(L) L.SetTable(-3) } }, "Pos": func() { ent := _ent.Game().EntityById(id) x, y := ent.Pos() LuaPushPoint(L, x, y) }, "Corpus": func() { ent := _ent.Game().EntityById(id) L.PushInteger(ent.Stats.Corpus()) }, "Ego": func() { ent := _ent.Game().EntityById(id) L.PushInteger(ent.Stats.Ego()) }, "HpCur": func() { ent := _ent.Game().EntityById(id) L.PushInteger(ent.Stats.HpCur()) }, "HpMax": func() { ent := _ent.Game().EntityById(id) L.PushInteger(ent.Stats.HpMax()) }, "ApCur": func() { ent := _ent.Game().EntityById(id) L.PushInteger(ent.Stats.ApCur()) }, "ApMax": func() { ent := _ent.Game().EntityById(id) L.PushInteger(ent.Stats.ApMax()) }, "Info": func() { ent := _ent.Game().EntityById(id) L.NewTable() L.PushString("LastEntityThatIAttacked") LuaPushEntity(L, ent.Game().EntityById(ent.Info.LastEntThatIAttacked)) L.SetTable(-3) L.PushString("LastEntThatAttackedMe") LuaPushEntity(L, ent.Game().EntityById(ent.Info.LastEntThatAttackedMe)) L.SetTable(-3) }, }) L.SetMetaTable(-2) }