示例#1
0
    // 检查建筑升级的条件
    public bool CheckBuildingLevelUp(BuildingInfo info, bool quick, bool enableFreeTime)
    {
        // 尚未解锁或者是正在升级中
        if (info == null || info.IsInBuilding())
        {
            return(false);
        }

        // 主城等级检查
        if (GetPalaceLevel() < info.CfgLevel.HomeLevelDemand)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_NEED_LEVEL", info.CfgLevel.HomeLevelDemand);
            return(false);
        }

        // 玩家等级检查
        if (UserManager.Instance.Level < info.CfgLevel.PlayerLevelDemand)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_NEED_PLAYER_LEVEL", info.CfgLevel.PlayerLevelDemand);
            return(false);
        }

        // 快速升级黄金检查
        if (quick)
        {
            if (info.IsInBuilding())
            {
                if (UserManager.Instance.Gold < info.GetQuickLevelUpCost(enableFreeTime))
                {
                    UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_GOLD_LIMIT");
                    return(false);
                }
            }
        }

        // 资源检查
        if (UserManager.Instance.Wood < info.CfgLevel.CostWood)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_WOOD_LIMIT");
            return(false);
        }

        if (UserManager.Instance.Stone < info.CfgLevel.CostStone)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_STONE_LIMIT");
            return(false);
        }

        if (BuildingLevelConfigLoader.GetConfig(info.ConfigID, info.Level + 1, false) == null)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_MAX_LEVEL");
            return(false);
        }

        return(true);
    }
示例#2
0
    // 根据建筑计算玩家的最大储量(银两、木材、石材)
    public void UpdateMaxStorage()
    {
        int maxMoney = 0;
        int maxWood  = 0;
        int maxStone = 0;

        foreach (var item in BuildingList)
        {
            BuildingLevelConfig cfg = BuildingLevelConfigLoader.GetConfig(item.ConfigID, item.Level);
            int value = cfg.MaxStorage;
            switch (item.BuildingType)
            {
            case CityBuildingType.PALACE:
                // 主城会同时增加最大金钱、最大木材、石材储量
                maxMoney += value;
                maxWood  += value;
                maxStone += value;
                break;

            case CityBuildingType.MONEY_STORAGE:
                maxMoney += value;
                break;

            case CityBuildingType.WOOD_STORAGE:
                maxWood += value;
                break;

            case CityBuildingType.STONE_STORAGE:
                maxStone += value;
                break;
            }
        }

        UserManager.Instance.MaxMoneyStorage = maxMoney;
        UserManager.Instance.MaxWoodStorage  = maxWood;
        UserManager.Instance.MaxStoneStorage = maxStone;

        EventDispatcher.TriggerEvent(EventID.EVENT_UI_MAIN_REFRESH_VALUE);
    }