Exemple #1
0
    // 请求快速升级士兵
    public void RequestQuickTrainSoldier(int soldierCfgID, bool costRes)
    {
        PCMInt data = new PCMInt();

        data.arg = soldierCfgID;

        Net.Send(eCommand.TRAIN_SOLIDER_RIGHT_NOW, data, (buffer) => {
            PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer);

            if (!Net.CheckErrorCode(ret.errorCode, eCommand.TRAIN_SOLIDER_RIGHT_NOW))
            {
                return;
            }

            TrainBuildingInfo tbinfo = GetBuildingByType(CityBuildingType.TRAIN) as TrainBuildingInfo;
            if (tbinfo != null)
            {
                if (costRes)
                {
                    // 扣去相应资源(先减再升级)
                    UserManager.Instance.CostMoney(tbinfo.GetTrainCost(soldierCfgID), PriceType.MONEY);
                }

                // 无论哪种情况都要把黄金扣了
                UserManager.Instance.CostMoney(tbinfo.GetQuickTrainCost(), PriceType.GOLD);

                tbinfo.Deserialize(ret);
                RefreshUI(tbinfo.EntityID);

                UIManager.Instance.RefreshWindow <UICityTrainSelectView>();
            }
        });
    }
Exemple #2
0
    // 请求取消升级士兵
    public void RequestCancelTrainSoldier(int soldierCfgID)
    {
        PCMInt data = new PCMInt();

        data.arg = soldierCfgID;

        Net.Send(eCommand.CANCLE_TRAIN_SOLIDER, data, (buffer) => {
            PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer);
            if (!Net.CheckErrorCode(ret.errorCode, eCommand.CANCLE_TRAIN_SOLIDER))
            {
                return;
            }

            TrainBuildingInfo tbinfo = GetBuildingByType(CityBuildingType.TRAIN) as TrainBuildingInfo;
            if (tbinfo != null)
            {
                int cost = tbinfo.GetTrainCost(tbinfo.TrainSoldierCfgID);

                // 返还资源
                UserManager.Instance.AddMoney(Mathf.FloorToInt(cost * GameConfig.CITY_BUILDING_CANCEL_BACK), PriceType.MONEY);

                tbinfo.TrainSoldierCfgID = 0;
                tbinfo.TrainRemainTime   = 0;
                tbinfo.TrainSyncTime     = 0;

                RefreshUI(tbinfo.EntityID);
            }
        });
    }