public override void Execute(Level level) { ClientAvatar ca = level.GetPlayerAvatar(); TrapData td = (TrapData)ObjectManager.DataTables.GetDataById(TrapId); Trap t = new Trap(td, level); if (ca.HasEnoughResources(td.GetBuildResource(0), td.GetBuildCost(0))) { if (level.HasFreeWorkers()) { ResourceData rd = td.GetBuildResource(0); ca.CommodityCountChangeHelper(0, rd, -td.GetBuildCost(0)); t.StartConstructing(X, Y); level.GameObjectManager.AddGameObject(t); } } }
public void Load(JObject jsonObject) { JArray jsonBuildings = (JArray)jsonObject["buildings"]; foreach(JObject jsonBuilding in jsonBuildings) { BuildingData bd = (BuildingData)ObjectManager.DataTables.GetDataById(jsonBuilding["data"].ToObject<int>()); Building b = new Building(bd, m_vLevel); AddGameObject(b); b.Load(jsonBuilding); } JArray jsonTraps = (JArray)jsonObject["traps"]; foreach (JObject jsonTrap in jsonTraps) { TrapData td = (TrapData)ObjectManager.DataTables.GetDataById(jsonTrap["data"].ToObject<int>()); Trap t = new Trap(td, m_vLevel); AddGameObject(t); t.Load(jsonTrap); } JArray jsonDecos = (JArray)jsonObject["decos"]; foreach (JObject jsonDeco in jsonDecos) { DecoData dd = (DecoData)ObjectManager.DataTables.GetDataById(jsonDeco["data"].ToObject<int>()); Deco d = new Deco(dd, m_vLevel); AddGameObject(d); d.Load(jsonDeco); } }