private void OnMsgPushBuildStatus(byte[] buffer) { PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.PUSH_BUILD_STATUS)) { return; } BuildingInfo info = GetBuildingByConfigID(ret.cfgId); if (info == null) { return; } info.Deserialize(ret); info.OnLevelUpFinish(); if (info.BuildingType == CityBuildingType.PALACE) { // 如果是主城升级完毕,重新取建筑列表,可能会解锁建筑 RequestBuildingList(); } }
private void OnMsgGetBuildInfo(byte[] buffer) { PBuildList ret = Net.Deserialize <PBuildList>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.GET_BUILD_INFO)) { return; } foreach (var item in ret.buildList) { BuildingInfo info = GetBuilding(item.buildId); if (info == null) { // 新增建筑 info = CreateBuilding(item.cfgId); BuildingList.Add(info); } info.Deserialize(item); } // 更新最大储量 UpdateMaxStorage(); // 刷新地图 UIManager.Instance.RefreshWindow <UICityView>(); }
public void Deserialize(PPlayerInfo data) { if (data.pBattlePT.Count < 2) { Log.Error("Error Battle Formation"); return; } // pvp的阵型数据 PBattlePT formation = data.pBattlePT[1]; // 英雄 HeroList.Clear(); foreach (var item in formation.heroPT) { HeroInfo info = new HeroInfo(); info.Deserialize(item.hero, false); HeroList.Add(info); } SoldierList.Clear(); foreach (var item in formation.buildPT) { BuildingInfo binfo = CityManager.Instance.CreateBuilding(item.build.cfgId); if (binfo == null) { continue; } TroopBuildingInfo tbinfo = binfo as TroopBuildingInfo; if (tbinfo != null) { // TODO 暂时只处理兵营数据,将来再处理校场,校场含有士兵等级数据 binfo.Deserialize(item.build); SoldierInfo info = new SoldierInfo(); info.ConfigID = tbinfo.SoldierConfigID; SoldierList.Add(info); } if (binfo.BuildingType == CityBuildingType.TRAIN) { // 校场,持有士兵等级数据 } else if (binfo.BuildingType == CityBuildingType.TROOP) { // 兵营 } } }
// 请求立即升级建筑 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); }); }
private void OnMsgPushGetBuild(byte[] buffer) { PBuildList ret = Net.Deserialize <PBuildList>(buffer); if (!Net.CheckErrorCode(ret.errorCode, eCommand.PUSH_GET_BUILD)) { return; } foreach (var item in ret.buildList) { BuildingInfo info = CreateBuilding(item.cfgId); info.Deserialize(item); BuildingList.Add(info); } // 刷新地图 UIManager.Instance.RefreshWindow <UICityView>(); }