Пример #1
0
    //==================================================================

    void QuickBuy()
    {
        QuickBuyRequest request = new QuickBuyRequest();

        request.api = new Model_ApiRequest().api;

        int [] types = new [] {
            (int)Model_Production.Production_Type.Food,
            (int)Model_Production.Production_Type.Oil,
            (int)Model_Production.Production_Type.Metal,
            (int)Model_Production.Production_Type.Rare,
        };

        for (int i = 0; i < 4; i++)
        {
            Production product = new Production();
            product.resourceType = types[i];
            product.num          = _resArr[i];
            if (_resArr[i] != 0)
            {
                request.buy.Add(product);
            }
        }
        int needCash = Model_Helper.GetResourcesNeedCash((float)_resArr[0], (float)_resArr[1], (float)_resArr[2], (float)_resArr[3]);

        if (ConnectionValidateHelper.IsEnoughCashBuyResources(needCash) == 0)
        {
            UIHelper.LoadingPanelIsOpen(true);
            (new PBConnect_quickBuy()).Send(request, OnQuickBuy);
        }
        else
        {
            UIHelper.BuyCashUI();
        }
    }
Пример #2
0
    void UpgradeBuilding()     // 建筑升级
    {
        UpgradeBuildingRequest request = new UpgradeBuildingRequest();


        Model_Building building = InstancePlayer.instance.model_User.buildings [Model_Building.Building_Type.ControlCenter];

        if (building != null)
        {
            request.buildingId = building.id;

            //request.byCash = 1;//是否只消耗cash来立即升级,1:是
            //request.buyQueue = 1; //是否消耗cash忽视建筑升级队列限制
            //request.buyCd = 1; //是否消耗cash忽略剩余CD时间直接完成

            Model_User user      = InstancePlayer.instance.model_User;
            int        isUpgrade = ConnectionValidateHelper.IsEnoughCashImmediateUpgradeBuinding(user, building.id);
            if (isUpgrade == 0)
            {
                // success
            }

            request.api = new Model_ApiRequest().api;
            (new PBConnect_upgradeBuilding()).Send(request, OnUpgradeBuilding);
            return;
        }

        _WARNING("no building OnUpgradeBuilding");
    }
Пример #3
0
// ======================================================
    //server


    void FinishUpgradeBuilding()
    {
        UIHelper.LoadingPanelIsOpen(true);
        UpgradeBuildingRequest request = new UpgradeBuildingRequest();

        if (InstancePlayer.instance.model_User.buildings.Count > 0)
        {
            Model_Building building = InstancePlayer.instance.model_User.buildings [_model_building.buildingType];
            if (building != null)
            {
                // 秒CD使用
                request.buildingId = building.id;
                request.buyCd      = 1;            //是否消耗cash忽略剩余CD时间直接完成

                request.api = new Model_ApiRequest().api;

                Model_User user      = InstancePlayer.instance.model_User;
                int        isUpgrade = ConnectionValidateHelper.IsEnoughCashClearBuildingCD(user, building.buildingType);

                if (isUpgrade == 0)
                {
                    (new PBConnect_FinishUpgradeBuilding()).Send(request, OnFinishUpgradeBuilding);
                }
                else
                {
                    UIHelper.BuyCashUI();
                }
                return;
            }
        }
    }
Пример #4
0
    //	加速
    void OnSpeed()
    {
        int requst = ConnectionValidateHelper.IsEnoughCashClearRepairUnitCD(InstancePlayer.instance.model_User);

        if (requst == 0)
        {
            FinishRepairUnit();
        }
        else
        {
            UIHelper.BuyCashUI();
        }
    }
Пример #5
0
    //获取需要购买的资源数量
    public static int GetNeedBuyRareCount(int resCount)
    {
        int result = -1;

        result = ConnectionValidateHelper.IsEnoughRareUse(resCount);
        if (result != 0)
        {
            result = resCount - InstancePlayer.instance.model_User.model_Resource.GetIntRare();
        }
        else
        {
            result = 0;
        }
        return(result);
    }
Пример #6
0
 // 立即训练
 public void OnOnceTrain()
 {
     if (_dataUnit != null)
     {
         int cdCashCount  = Mathf.CeilToInt(_currentTankCount * _dataUnit.costCdCash);
         int isProduction = ConnectionValidateHelper.IsEnoughCashBuyResources(cdCashCount);
         if (isProduction == 0)
         {
             SpeedAddUnit();
         }
         else
         {
             UIHelper.BuyCashUI();
         }
     }
 }
Пример #7
0
    //  立即维修
    void OnImmediatelyRepair()
    {
        int allCash;

        _allResCountDic.TryGetValue(6, out allCash);
        int requst = ConnectionValidateHelper.IsEnoughCashBuyResources((int)allCash);

        if (requst == 0)
        {
            ImmediatelyRepairUnit();
        }
        else
        {
            UIHelper.BuyCashUI();
        }
    }
Пример #8
0
    void OnSpeed()
    {
        int requst = ConnectionValidateHelper.IsEnoughCashClearBuildUnitCD(_model_User, _model_unit.unitId);

        if (requst == 0)
        {
            if (_model_unit != null)
            {
                FinishAddUnit();
            }
        }
        else
        {
            UIHelper.BuyCashUI();
        }
    }
Пример #9
0
    public UPGRADE_PART_RESULT CanUpgradePart(int index)
    {
        DataUnitPart mainDataPart = GetDataParts()[0];
        DataUnitPart dataPart     = GetDataParts()[index];

        Trace.trace("GetPartLevelMax(index) " + GetPartLevelMax(index), Trace.CHANNEL.UI);
        if (dataPart.level + 1 > GetPartLevelMax(index))
        {
            return(UPGRADE_PART_RESULT.MAX_LEVEL);
        }
        if (dataPart.mainLevel > mainDataPart.level)
        {
            return(UPGRADE_PART_RESULT.NEED_MAIN_LEVEL);
        }
        if (index != 0)
        {
            if (mainDataPart.level < dataPart.level + 1)
            {
                return(UPGRADE_PART_RESULT.NEED_MAIN_LEVEL);
            }
        }
        else
        {
            int userLevel = InstancePlayer.instance.model_User.honorLevel;
            if (mainDataPart.level + 1 > userLevel)
            {
                return(UPGRADE_PART_RESULT.NEED_USER_LEVEL);
            }
        }


        ConnectionValidateHelper.CostCheck r = ConnectionValidateHelper.IsEnoughCost(dataPart.cost);
        if (r != ConnectionValidateHelper.CostCheck.OK)
        {
            return(UPGRADE_PART_RESULT.NEED_RESOURCE);
        }

        return(UPGRADE_PART_RESULT.OK);
    }
Пример #10
0
    //获取加速生产所需的金币数
    public static int GetClearUnitCDNeedCash(Model_User model_user, int unitId)
    {
        int result = -1;

        result = ConnectionValidateHelper.IsEnoughCashClearBuildUnitCD(model_user, unitId);

        if (result != 0)
        {
            Model_Unit model_Unit;
            model_user.unlockUnits.TryGetValue(unitId, out model_Unit);
            float needCash = model_user.model_InitialConfig.GetClearUnitCDCash(model_Unit.produceLeftTime);
            float userCash = model_user.model_Resource.cash;
            if (userCash < needCash)
            {
                result = Mathf.CeilToInt(needCash - userCash);
            }
        }
        else
        {
            result = 0;
        }
        return(result);
    }
Пример #11
0
    //	维修
    void OnRepair()
    {
        int foodCount  = 0;
        int oilCount   = 0;
        int matelCount = 0;
        int rareCount  = 0;

        _allResCountDic.TryGetValue(1, out foodCount);
        _allResCountDic.TryGetValue(2, out oilCount);
        _allResCountDic.TryGetValue(3, out matelCount);
        _allResCountDic.TryGetValue(4, out rareCount);

        int[] _resArr      = Model_Helper.GetPlayerNeedBuyRes((int)foodCount, (int)oilCount, (int)matelCount, (int)rareCount);
        bool  isNeedBuyRes = ConnectionValidateHelper.IsResourcesEnoughToUse(_resArr);

        if (isNeedBuyRes)
        {
            RepairUnit();
        }
        else
        {
            UIController.instance.CreatePanel(UICommon.UI_TIPS_BUYRES, _resArr, ResourcesBuyType.RepairTankType);
        }
    }
Пример #12
0
    void ResData()
    {
        if (_tankRepairItemDic != null)
        {
            int foodCount  = 0;
            int oilCount   = 0;
            int matelCount = 0;
            int rareCount  = 0;
            int timeCount  = 0;
            int cashCount  = 0;

            foreach (KeyValuePair <int, TankRepairItem> kv in _tankRepairItemDic)
            {
                TankRepairItem        tankItem    = kv.Value;
                Dictionary <int, int> resCountDic = tankItem.GetResCountDic();
                int res_1 = 0;
                resCountDic.TryGetValue(1, out res_1);
                foodCount = foodCount + res_1;

                int res_2 = 0;
                resCountDic.TryGetValue(2, out res_2);
                oilCount = oilCount + res_2;

                int res_3 = 0;
                resCountDic.TryGetValue(3, out res_3);
                matelCount = matelCount + res_3;

                int res_4 = 0;
                resCountDic.TryGetValue(4, out res_4);
                rareCount = rareCount + res_4;

                int res_5 = 0;
                resCountDic.TryGetValue(5, out res_5);
                timeCount = timeCount + res_5;

                int res_6 = 0;
                resCountDic.TryGetValue(6, out res_6);
                cashCount = cashCount + res_6;
            }

            if (_allResCountDic != null)
            {
                _allResCountDic.Clear();
                _allResCountDic.Add(1, foodCount);
                _allResCountDic.Add(2, oilCount);
                _allResCountDic.Add(3, matelCount);
                _allResCountDic.Add(4, rareCount);
                _allResCountDic.Add(5, timeCount);
                _allResCountDic.Add(6, cashCount);
            }
        }

        if (_allResCountDic != null)
        {
            int allTime;
            _allResCountDic.TryGetValue(5, out allTime);
            _RepairTime_Value.text = UIHelper.setTimeDHMS(Mathf.RoundToInt(allTime)).ToString();

            int allCash;
            _allResCountDic.TryGetValue(6, out allCash);
            _immediatelyRepair_CoinValue.text = (int)allCash + "";

            for (int i = 1; i <= 4; i++)
            {
                int resNum = 0;
                _allResCountDic.TryGetValue(i, out resNum);
                int requst = -1;
                if (i == 1)
                {
                    requst = ConnectionValidateHelper.IsEnoughFoodUse((int)resNum);
                    if (requst == 0)
                    {
                        _resLabelList[i - 1].text = Mathf.RoundToInt(resNum).ToString() + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaFoodRes());
                    }
                    else
                    {
                        _resLabelList[i - 1].text = UIHelper.SetStringColor(Mathf.RoundToInt(resNum).ToString()) + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaFoodRes());
                    }
                }
                else if (i == 2)
                {
                    requst = ConnectionValidateHelper.IsEnoughOilUse((int)resNum);
                    if (requst == 0)
                    {
                        _resLabelList[i - 1].text = Mathf.RoundToInt(resNum).ToString() + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaOilRes());
                    }
                    else
                    {
                        _resLabelList[i - 1].text = UIHelper.SetStringColor(Mathf.RoundToInt(resNum).ToString()) + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaOilRes());
                    }
                }
                else if (i == 3)
                {
                    requst = ConnectionValidateHelper.IsEnoughMetalUse((int)resNum);
                    if (requst == 0)
                    {
                        _resLabelList[i - 1].text = Mathf.RoundToInt(resNum).ToString() + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaMatelRes());
                    }
                    else
                    {
                        _resLabelList[i - 1].text = UIHelper.SetStringColor(Mathf.RoundToInt(resNum).ToString()) + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaMatelRes());
                    }
                }
                else if (i == 4)
                {
                    requst = ConnectionValidateHelper.IsEnoughRareUse((int)resNum);
                    if (requst == 0)
                    {
                        _resLabelList[i - 1].text = Mathf.RoundToInt(resNum).ToString() + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaRareRes());
                    }
                    else
                    {
                        _resLabelList[i - 1].text = UIHelper.SetStringColor(Mathf.RoundToInt(resNum).ToString()) + "/" + UIHelper.SetResourcesShowFormat(Model_Helper.GetPlayerHavaRareRes());
                    }
                }
            }
        }
    }
Пример #13
0
    void UpdateUI()
    {
        if (_unitData != null)
        {
            _model_User  = InstancePlayer.instance.model_User;
            _model_Units = InstancePlayer.instance.model_User.unlockUnits;
            _dataUnit    = _unitData.unitData;

            _TankNameLabel.text  = _unitData.unitData.name.ToString();
            _TankNameLabel.color = _unitData.nameColor;
//			Trace.trace("_unitData.nameColor " +  _unitData.nameColor ,Trace.CHANNEL.UI);
            _iconBg.spriteName = _unitData.iconBgName;
            _icon.SetUnitSmallTexture(_unitData.id);
            if (_unitData.isUnLock)
            {
                _canResearch_Sprite.gameObject.SetActive(false);
            }
            else
            {
                _canResearch_Sprite.gameObject.SetActive(_unitData.isCanUnlock);
            }

            _format_Sprite.gameObject.SetActive(_unitData.isFormation);

            if (_unitData.isUnLock)
            {
                _model_Units.TryGetValue(_dataUnit.id, out _model_unit);
            }
            _lock_Container.gameObject.SetActive(!_unitData.isUnLock);
            _unlock_Container.gameObject.SetActive(_unitData.isUnLock);

            if (_model_unit != null && _model_unit.onProduce > 0)
            {
                if (_model_unit.produceLeftTime == 0)
                {
                    _productBtn.gameObject.SetActive(false);
                    _repairBtn.gameObject.SetActive(false);
                    _harvestBtn.gameObject.SetActive(true);
                    _speed_Container.gameObject.SetActive(false);
                }
                else
                {
                    _productBtn.gameObject.SetActive(false);
                    _repairBtn.gameObject.SetActive(false);
                    _harvestBtn.gameObject.SetActive(false);
                    _speed_Container.gameObject.SetActive(true);
                }
            }
            else
            {
                _productBtn.gameObject.SetActive(true);
                _repairBtn.gameObject.SetActive(true);
                _harvestBtn.gameObject.SetActive(false);
                _speed_Container.gameObject.SetActive(false);
            }
//
//			bool isSpeedShow ;
//			if(_model_unit != null && _model_unit.produceLeftTime > 0)
//			{
//				isSpeedShow = true;
//			}
//			else
//			{
//				isSpeedShow = false;
//			}
//			_speed_Container.gameObject.SetActive(isSpeedShow);
//			_productBtn.gameObject.SetActive(!isSpeedShow);
//			_repairBtn.gameObject.SetActive(!isSpeedShow);

            //坦克研发红点
            _researchRedPoint.gameObject.SetActive(_unitData.isCanUnlock);
            _researchBtn.isEnabled = _unitData.isCanUnlock;
//			所需图纸个数
            _needPaperValue_Label.text = _unitData.unitData.chipCount.ToString();
            Model_ItemGroup model_itemGroup = InstancePlayer.instance.model_User.model_itemGroup;
            Item            item            = model_itemGroup.QueryItem(_unitData.unitData.chipId);
//			拥有的个数
            _currentValue_Label.text = item.num.ToString();
            // 生产的小红点
            ConnectionValidateHelper.CostCheck costCheck = ConnectionValidateHelper.IsEnoughCost(_dataUnit.cost);
            if (costCheck == ConnectionValidateHelper.CostCheck.OK)
            {
                _product_redPoint.gameObject.SetActive(true);
            }
            else
            {
                _product_redPoint.gameObject.SetActive(false);
            }

            // Clear CD Need Cash
            if (_model_unit != null)
            {
                _Timer_Colored_Slider.value = (_model_unit.produceLeftTime) / (float)_model_unit.produceTotalTime;
                _timeLabel.text             = UIHelper.setTimeDHMS(_model_unit.produceLeftTime);
                float needCash = _model_User.model_InitialConfig.GetClearUnitCDCash(_model_unit.produceLeftTime);
                _speedCoinLabel.text = (int)needCash + "";
            }
        }
    }