public void RequestQuickProduceSoldier(long buildingID, int soldierID) { TroopBuildingInfo infoSend = GetBuilding(buildingID) as TroopBuildingInfo; if (infoSend == null) { return; } PCMLongInt data = new PCMLongInt(); data.arg1 = buildingID; data.arg2 = soldierID; Net.Send(eCommand.PRODUCT_SOLIDER_RIGHT_NOW, data, (buffer) => { PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.PRODUCT_SOLIDER_RIGHT_NOW)) { return; } UserManager.Instance.CostMoney(infoSend.GetQuickProducingCost(), PriceType.GOLD); infoSend.Deserialize(ret); RefreshUI(buildingID); UIManager.Instance.CloseWindow <UICitySoldierSelectView>(); UIManager.Instance.CloseWindow <UICitySoldierSwitchView>(); }); }
// 请求取消生产士兵 public void RequestCancelProduceSoldier(long buildingID, int soldierID) { TroopBuildingInfo infoSend = GetBuilding(buildingID) as TroopBuildingInfo; if (infoSend == null) { return; } PCMLongInt data = new PCMLongInt(); data.arg1 = buildingID; data.arg2 = soldierID; Net.Send(eCommand.CANCLE_PRODUCT_SOLIDER, data, (buffer) => { PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.CANCLE_PRODUCT_SOLIDER)) { return; } infoSend.Deserialize(ret); // 请求同步数据(因为士兵有生产过程,所以客户端很难去计算正确的结果) UserManager.Instance.RequestSyncRes(); RefreshUI(buildingID); }); }
// 请求取消升级建筑 public void RequestCancelUpgradeBuilding(long buildingID) { BuildingInfo infoSend = GetBuilding(buildingID); if (infoSend == null) { return; } PCMLongInt data = new PCMLongInt(); data.arg1 = buildingID; data.arg2 = infoSend.Cfg.BuildingType; Net.Send(eCommand.CANCLE_UPGRADE_BUILD, data, (buffer) => { CommonAnswer ret = Net.Deserialize <CommonAnswer>(buffer); if (!Net.CheckErrorCode(ret.err_code, eCommand.CANCLE_UPGRADE_BUILD)) { return; } // 返还资源 UserManager.Instance.AddMoney(Mathf.FloorToInt(infoSend.CfgLevel.CostStone * GameConfig.CITY_BUILDING_CANCEL_BACK), PriceType.STONE); UserManager.Instance.AddMoney(Mathf.FloorToInt(infoSend.CfgLevel.CostWood * GameConfig.CITY_BUILDING_CANCEL_BACK), PriceType.WOOD); infoSend.LevelUpRemainTime.Reset(); // TODO 返还资源由服务器推送 RefreshUI(buildingID); }); }
// 请求收获 public void RequestHarvest(long buildingID) { BuildingInfo infoSend = GetBuilding(buildingID); if (infoSend == null) { return; } PCMLongInt data = new PCMLongInt(); data.arg1 = buildingID; data.arg2 = infoSend.Cfg.BuildingType; Net.Send(eCommand.COLLECT_RESOURCE, data, (byte[] buffer) => { PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.COLLECT_RESOURCE)) { return; } DoHarvest(buildingID, ret.addNum); // 刷新城池 EventDispatcher.TriggerEvent(EventID.EVENT_CITY_BUILDING_REFRESH, buildingID); // 刷新主界面的数据 EventDispatcher.TriggerEvent(EventID.EVENT_UI_MAIN_REFRESH_VALUE); }); }
// 请求立即升级建筑 public void RequestQuickUpgradeBuilding(long buildingID, bool costRes) { BuildingInfo infoSend = GetBuilding(buildingID); if (infoSend == null) { return; } PCMLongInt data = new PCMLongInt(); data.arg1 = buildingID; data.arg2 = infoSend.Cfg.BuildingType; Net.Send(eCommand.UPGRADE_BUILD_RIGHT_NOW, data, (buffer) => { PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.UPGRADE_BUILD_RIGHT_NOW)) { return; } BuildingInfo info = GetBuilding(buildingID); if (info != null) { if (costRes) { // 扣除资源(如果是在升级过程中点击快速升级,则不扣除资源) UserManager.Instance.CostMoney(info.CfgLevel.CostStone, PriceType.STONE); UserManager.Instance.CostMoney(info.CfgLevel.CostWood, PriceType.WOOD); } UserManager.Instance.CostMoney(info.GetQuickLevelUpCost(false), PriceType.GOLD); info.Deserialize(ret); info.OnLevelUpFinish(); if (info.BuildingType == CityBuildingType.PALACE) { // 如果是主城升级完毕,重新取建筑列表,可能会解锁建筑 RequestBuildingList(); } } // 升级成功,更新建筑物的最大储量 UpdateMaxStorage(); RefreshUI(buildingID); }); }
// 请求升级建筑 public void RequestUpgradeBuilding(long buildingID) { if (IsInBuilding()) { return; } BuildingInfo infoSend = GetBuilding(buildingID); if (infoSend == null) { return; } PCMLongInt data = new PCMLongInt(); data.arg1 = buildingID; data.arg2 = infoSend.Cfg.BuildingType; Net.Send(eCommand.UPGRADE_BUILD_LEVEL, data, (byte[] buffer) => { PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.UPGRADE_BUILD_LEVEL)) { return; } BuildingInfo info = GetBuilding(buildingID); if (info != null) { // 扣除相应资源 UserManager.Instance.CostMoney(info.CfgLevel.CostStone, PriceType.STONE); UserManager.Instance.CostMoney(info.CfgLevel.CostWood, PriceType.WOOD); info.Deserialize(ret); } // 升级的时候有增加的资源(当资源满的特殊情况) if (ret.addNum > 0) { DoHarvest(buildingID, ret.addNum); } RefreshUI(buildingID); EventDispatcher.TriggerEvent(EventID.EVENT_CITY_BUILDING_LEVELUP, buildingID); }); }