public override void Execute(Level level) { ClientAvatar avatar = level.GetPlayerAvatar(); GameObject gameObjectById = level.GameObjectManager.GetGameObjectByID(BuildingId); if (gameObjectById == null) { return; } ConstructionItem constructionItem = (ConstructionItem)gameObjectById; if (!constructionItem.CanUpgrade()) { return; } ConstructionItemData constructionItemData = constructionItem.GetConstructionItemData(); if (!avatar.HasEnoughResources(constructionItemData.GetBuildResource(constructionItem.GetUpgradeLevel() + 1), constructionItemData.GetBuildCost(constructionItem.GetUpgradeLevel() + 1)) || !level.HasFreeWorkers()) { return; } string name = level.GameObjectManager.GetGameObjectByID(BuildingId).GetData().GetName(); Logger.Write("Building To Upgrade : " + name + " (" + BuildingId + ')'); if (string.Equals(name, "Alliance Castle")) { avatar.IncrementAllianceCastleLevel(); BuildingData buildingData = ((Building)level.GameObjectManager.GetGameObjectByID(BuildingId)).GetBuildingData(); avatar.SetAllianceCastleTotalCapacity(buildingData.GetUnitStorageCapacity(avatar.GetAllianceCastleLevel())); } else if (string.Equals(name, "Town Hall")) { avatar.IncrementTownHallLevel(); } ResourceData buildResource = constructionItemData.GetBuildResource(constructionItem.GetUpgradeLevel() + 1); avatar.SetResourceCount(buildResource, avatar.GetResourceCount(buildResource) - constructionItemData.GetBuildCost(constructionItem.GetUpgradeLevel() + 1)); constructionItem.StartUpgrading(); }
public override void Execute(Level level) { ClientAvatar ca = level.GetPlayerAvatar(); GameObject go = level.GameObjectManager.GetGameObjectByID(BuildingId); ConstructionItem b = (ConstructionItem)go; if (b.CanUpgrade()) { var bd = b.GetConstructionItemData(); if (ca.HasEnoughResources(bd.GetBuildResource(b.GetUpgradeLevel() + 1), bd.GetBuildCost(b.GetUpgradeLevel() + 1))) { if (level.HasFreeWorkers()) { ResourceData rd = bd.GetBuildResource(b.GetUpgradeLevel() + 1); ca.SetResourceCount(rd, ca.GetResourceCount(rd) - bd.GetBuildCost(b.GetUpgradeLevel() + 1)); b.StartUpgrading(); } } } }