示例#1
0
文件: UnitsUI.cs 项目: radtek/SCM2
    public void ResetColdown(string type)
    {
        var mainBuilder = UnitConfiguration.GetMainBuilder(type);
        var cfg         = UnitConfiguration.GetDefaultConfig(type);

        if (cfg.IsBuilding)
        {
            return;
        }

        // 同一建筑的单位一起重置 cd
        foreach (var t in coldown.Keys.ToArray())
        {
            var tcfg = UnitConfiguration.GetDefaultConfig(t);

            if (tcfg.IsBuilding)
            {
                continue;
            }

            if (UnitConfiguration.GetMainBuilder(t) == mainBuilder)
            {
                coldown[t] = coldown[t] >= 1 ? coldown[t] - 1 : 0;
            }
        }
    }
示例#2
0
文件: Room.cs 项目: radtek/SCM2
        public bool ReconstructBuilding(Unit u, string toNewType)
        {
            var player = u.Player;

            if (!CheckPrerequisites(player, toNewType))
            {
                return(false);
            }

            var cfg = UnitConfiguration.GetDefaultConfig(toNewType);

            var cost    = cfg.Cost;
            var gasCost = cfg.GasCost;

            if (GetResource(player, "Money") < cost || GetResource(player, "Gas") < gasCost)
            {
                return(false);
            }

            AddResource(player, "Money", -cost);
            AddResource(player, "Gas", -gasCost);

            // 改变建筑类型
            u.BuildingCompleted = false;
            var oldType = u.UnitType;

            u.UnitType = toNewType;
            RefreshAI(u);
            OnUnitReconstruct(u, oldType);
            return(true);
        }
示例#3
0
    private void ShowDescInfo(string unitType)
    {
        var info = UnitConfiguration.GetDefaultConfig(unitType);

        if (Need > 1)
        {
            Title.text = string.Format("{2} {0}{3} {1} {4}", SCMText.T(info.DisplayName + " "), Need,
                                       SCMText.T("解锁"), SCMText.T("将消耗"), SCMText.T("积分 "));
        }
        else
        {
            Title.text = string.Format("{2} {0}{3} {1} {4}", SCMText.T(info.DisplayName + " "), Need,
                                       SCMText.T("解锁"), SCMText.T("将消耗"), SCMText.T("积分"));
        }

        AttackType01.text = info.CanAttackGround ? "<color=green>是</color>" : "<color=red>否</color>";
        AttackType02.text = info.CanAttackAir ? "<color=green>是</color>" : "<color=red>否</color>";
        Cost.text         = info.Cost.ToString();
        GasCost.text      = info.GasCost.ToString();

        AttackPower.text  = info.CanAttackGround ? info.AttackPower[0].ToString() : "";
        AttackPower.text += info.CanAttackAir && info.CanAttackGround ? ", " : "";
        AttackPower.text += info.CanAttackAir ? info.AttackPower[1].ToString() : "";

        ConstructingTime.text = info.ConstructingTime.ToString() + "s";
        MaxHp.text            = info.MaxHp.ToString();
        Defence.text          = info.Defence.ToString();

        Desc.text = info.Desc;
    }
示例#4
0
    // 确认解锁
    public void OnUnlockConfirmBtn()
    {
        if (!IsEnough)
        {
            AddTip("当前积分余额不足!", 28);
            return;
        }

        var meInfo = GameCore.Instance.MeInfo;

        meInfo.Units[Type]      = true;
        meInfo.UUnlocks[Stage]  = true;
        meInfo.IntegrationCost += Need;

        UserManager.SyncUnits2Server();
        UserManager.SyncUUnlocks2Server();
        UserManager.SyncIntegrationCost2Server();

        AddTip(string.Format("解锁新单位{0}", UnitConfiguration.GetDefaultConfig(Type).DisplayName), 28);

        DUI.Refresh();
        MMUI.ShowUserInfo();

        ClearDescInfo();
        Hide();
    }
示例#5
0
    private void BuildItems(UserInfo info, Transform content)
    {
        var variants = info.Variants;

        foreach (var v in variants)
        {
            var cfg      = UnitConfiguration.GetDefaultConfig(v.Key);
            var isUnlock = info.Units[v.Key];

            if (v.Key == "Radar")
            {
                continue;
            }

            if (isUnlock && !cfg.IsBuilding && !cfg.NoCard)
            {
                var go = CreateItem(content);

                ShowItemInfo(go, v.Value);
            }
        }

        // 守卫
        if (info.Units["FireGuard"])
        {
            var vType = info.Variants["FireGuard"];

            var go = CreateItem(content);
            ShowItemInfo(go, vType);
        }
    }
示例#6
0
文件: Room.cs 项目: radtek/SCM2
        // 开始建造建筑
        public Unit ConstructBuilding(string genType, Vec2 pos, int player)
        {
            var cfg = UnitConfiguration.GetDefaultConfig(genType);

            var cost    = cfg.Cost;
            var gasCost = cfg.GasCost;

            if (GetResource(player, "Money") < cost || GetResource(player, "Gas") < gasCost)
            {
                return(null);
            }
            else if (cfg.Prerequisites != null && GetAllUnitsByPlayer(player,
                                                                      (u) => u.BuildingCompleted && CheckPrerequisites(player, u.UnitType)).Length == 0)
            {
                return(null);
            }
            else if (!cfg.NoBody && !cfg.NoCard && !CheckSpareSpace(pos, cfg.SizeRadius))
            {
                return(null);
            }

            AddResource(player, "Money", -cost);
            AddResource(player, "Gas", -gasCost);
            var building = AddNewUnit(null, genType, pos, player);

            if (building != null)
            {
                building.Hp = building.cfg.MaxHp * 0.1; // 从 10% 的血量开始建造
            }
            return(building);
        }
示例#7
0
        public Unit SrvAddBattltUnitAt(int player, string type, Vec2 pos)
        {
            if (!CheckPrerequisites(player, type))
            {
                return(null);
            }

            var cfg = UnitConfiguration.GetDefaultConfig(type);

            var cost    = cfg.Cost;
            var gasCost = cfg.GasCost;

            if (GetResource(player, "Money") < cost ||
                GetResource(player, "Gas") < gasCost)
            {
                return(null);
            }

            AddResource(player, "Money", -cost);
            AddResource(player, "Gas", -gasCost);

            var u = AddNewUnit(null, type, pos, player);

            if (u != null)
            {
                Broadcast("AddBattleUnitAt", (buff) =>
                {
                    buff.Write(player);
                    buff.Write(type);
                    buff.Write(u.Pos);
                });
            }

            return(u);
        }
示例#8
0
    // PVE001 基本建造教学
    static IEnumerator PVE001GuideImpl(Room4Client r)
    {
        var g = UIManager.Instance.Guide;


        var cc = r.GetMyFirstUnitByType("CommanderCenter");

        // 提示建造矿机
        yield return(new TimeWaiter(1000));

        g.ToClick(UIManager.Instance.World2UI(cc.Pos), "建造<u>矿机</u>可以加速资源生产");
        yield return(new ConditionWaiter(() => r.GetMyFirstUnitByType("CCAcc") != null));

        g.HideAllHints();
        yield return(new ConditionWaiter(() => r.GetMyFirstUnitByType("CCAcc").BuildingCompleted));

        UIManager.Instance.Tips.AddTip("矿机建造完成");
        g.ToClick(UIManager.Instance.World2UI(cc.Pos), "试试补充更多<u>矿机</u>");
        yield return(new ConditionWaiter(() => r.GetMyUnitsByType("CCAcc").Length >= 2));

        g.HideAllHints();

        // 提示建造兵营
        yield return(new ConditionWaiter(() => r.GetMyResource("Money") >= UnitConfiguration.GetDefaultConfig("Barrack").Cost));

        g.HideAllHints();
        g.ToPress(UIManager.Instance.World2UI(cc.Pos + new Vec2(-80, -50)), "<op>长按</op>:建造<u>兵营</u>");
        // 等待开始建造兵营
        yield return(new ConditionWaiter(() => r.GetMyFirstUnitByType("Barrack") != null));

        g.HideAllHints();
        yield return(new ConditionWaiter(() => r.GetMyFirstUnitByType("Barrack").BuildingCompleted &&
                                         r.GetMyResource("Money") >= UnitConfiguration.GetDefaultConfig("Soldier").Cost));

        g.ToPress(UIManager.Instance.World2UI(cc.Pos) - new Vec2(75, 135), "选择:<u>枪兵</u>");
        yield return(new TimeWaiter(3000));

        g.ToPress(UIManager.Instance.World2UI(cc.Pos) + new Vec2(0, 200), "<op>单击</op>地面释放<u>枪兵</u>");
        yield return(new TimeWaiter(1000));

        yield return(new ConditionWaiter(() => r.GetMyFirstUnitByType("Soldier") != null));

        g.HideAllHints();

        // 提示使用雷达
        yield return(new ConditionWaiter(() => r.GetMyResource("Money") >= UnitConfiguration.GetDefaultConfig("RadarSign").Cost));

        g.ToDrag("从<u>基地</u>拖出释放<u>雷达</u>",
                 UIManager.Instance.World2UI(cc.Pos),
                 UIManager.Instance.World2UI(r.MapSize - cc.Pos));
        yield return(new ConditionWaiter(() => r.GetMyFirstUnitByType("RadarSign") != null));

        g.HideAllHints();

        UIManager.Instance.Tips.AddTip("目标:建造更多部队,摧毁对方基地");
    }
示例#9
0
        void OnGetUnitCfgs(Connection conn, IReadableBuffer data, IWriteableBuffer buff, Action end)
        {
            buff.Write(UnitConfiguration.AllUnitTypes);

            for (int i = 0; i < UnitConfiguration.AllUnitTypes.Length; i++)
            {
                UnitUtils.WriteUnitInfo(UnitConfiguration.GetDefaultConfig(UnitConfiguration.AllUnitTypes[i]), buff);
            }

            end();
        }
示例#10
0
    void OnAddBattleUnitAtMsg(IReadableBuffer data)
    {
        var p  = data.ReadInt();
        var t  = data.ReadString();
        var pt = data.ReadVec2();

        var cfg = UnitConfiguration.GetDefaultConfig(t);

        AddResource(p, "Money", -cfg.Cost);
        AddResource(p, "Gas", -cfg.GasCost);
        AddNewUnit(null, t, pt, p);
    }
示例#11
0
文件: MapScene.cs 项目: radtek/SCM2
    private void OnStartConstructingBattleUnit(Unit u, string genType)
    {
        var m = UC.GetModel(u.UID);

        m.AniPlayer.ConstructingUnit();

        var vcfg = UnitConfiguration.GetDefaultConfig(genType);

        var constructingTime = vcfg.ConstructingTime;

        IndLayer.CreateProgressbar(u, constructingTime).FollowTransformRoot = m.transform;
    }
示例#12
0
    public void OnRightClick(Vec2 pt, Vector3 wp)
    {
        if (UUIs.CurUnitType == null)
        {
            return;
        }

        var cfg = UnitConfiguration.GetDefaultConfig(UUIs.CurUnitType);

        // 右键全开
        if (!UUIs.IsOpenAllUUI)
        {
            UUIs.IsOpenAllUUI = true;
        }

        var conn = GameCore.Instance.ServerConnection;

        if (UUIs.CurUnitType == "SoldierCarrier" || UUIs.CurUnitType == "RobotCarrier")
        {
            var buff = conn.Send2Srv("AddSoldierCarrierUnit4TestAnyway");

            var p = wp.z >= room.MapSize.y / 2 ? 2 : 1;
            buff.Write(p);
            buff.Write(UUIs.CurUnitType);
            buff.Write((int)wp.x);
            buff.Write((int)wp.z);
            conn.End(buff);
        }
        else if (UnitConfiguration.GetDefaultConfig(UUIs.CurUnitType).IsBuilding)
        {
            var buff = conn.Send2Srv("AddBuildingUnit4TestAnyway");

            var p = wp.z >= room.MapSize.y / 2 ? 2 : 1;
            buff.Write(p);
            buff.Write(UUIs.CurUnitType);
            buff.Write((int)wp.x);
            buff.Write((int)wp.z);
            conn.End(buff);
        }
        else
        {
            UUIs.ResetColdown(UUIs.CurUnitType);
            var buff = conn.Send2Srv("AddBattleUnit4TestAnyway");

            var p = wp.z >= room.MapSize.y / 2 ? 2 : 1;
            buff.Write(p);
            buff.Write(UUIs.CurUnitType);
            buff.Write((int)wp.x);
            buff.Write((int)wp.z);
            conn.End(buff);
        }
    }
示例#13
0
文件: UnitBase.cs 项目: radtek/SCM2
    void ShowSels(Vec2 pt)
    {
        var ui = UIManager.Instance.ShowTopUI("InBattleUI/SelectUnitUI", true) as SelectUnitUI;

        ui.Pos     = pt;
        ui.Choices = u.UnitType == "Base" ?
                     (new string[] { "CrystalMachine" }).Concat(u.cfg.ReconstructTo).ToArray() :
                     new string[] { "CrystalMachine" };

        ui.ChoicesName = ui.Choices.ToArray((i, t, skipAct) =>
        {
            var ccfg = t == "CrystalMachine" ?
                       UnitConfiguration.GetDefaultConfig("CrystalMachine") :
                       UnitConfiguration.GetDefaultConfig(t);

            return(ccfg.DisplayName);
        });
        ui.Refresh();
        ui.OnChoiceSel = (toType) =>
        {
            var unitType = toType == "CrystalMachine" ? "CrystalMachine" : toType;
            if (!U.BuildingCompleted ||
                !MG.CheckPrerequisitesAndTip(unitType) ||
                !MG.CheckResourceRequirementAndTip(unitType))
            {
                return;
            }

            if (toType == "CrystalMachine")
            {
                if (U.Room.FindNextCrystalMachinePos(U) == Vec2.Zero)
                {
                    AddTip("没有多余的矿机位置");
                    return;
                }

                var conn = GameCore.Instance.ServerConnection;
                var buff = conn.Send2Srv("ConstructCrystalMachine");
                buff.Write(U.UID);
                conn.End(buff);
            }
            else // 升级基地
            {
                var conn = GameCore.Instance.ServerConnection;
                var buff = conn.Send2Srv("ReconstructBuilding");
                buff.Write(U.UID);
                buff.Write(toType);
                conn.End(buff);
            }
        };
    }
示例#14
0
文件: UnitsUI.cs 项目: radtek/SCM2
    public void CancelSelUnit()
    {
        var vcfg = UnitConfiguration.GetDefaultConfig(CurUnitType);

        curBtn.transform.Find(vcfg.IsBuilding ? "BuildingCheck" : "Check").gameObject.SetActive(false);

        curBtn      = null;
        CurUnitType = null;

        if (null != onHideUnitPlacedArea)
        {
            onHideUnitPlacedArea();
        }
    }
示例#15
0
    // 单击地面放兵
    public void OnClickMap(Vec2 pt, Vec2 cp)
    {
        var cfg = UnitConfiguration.GetDefaultConfig(UUIs.CurUnitType);

        if (!UUIs.CheckColdown(UUIs.CurUnitType))
        {
            AddTip("部队尚未就绪");
            return;
        }

        if (!CheckPrerequisitesAndTip(UUIs.CurUnitType) ||
            !CheckResourceRequirementAndTip(UUIs.CurUnitType))
        {
            return;
        }

        UUIs.ResetColdown(UUIs.CurUnitType);
        var conn = GameCore.Instance.ServerConnection;

        if (UUIs.CurUnitType == "SoldierCarrier" || UUIs.CurUnitType == "RobotCarrier")
        {
            var buff = conn.Send2Srv("DropSoldierFromCarrier");
            buff.Write(UUIs.CurUnitType);
            buff.Write((int)cp.x);
            buff.Write((int)cp.y);
            conn.End(buff);
        }
        else if (UnitConfiguration.GetDefaultConfig(UUIs.CurUnitType).IsBuilding)
        {
            if (!room.CheckSpareSpace(cp, cfg.SizeRadius) &&
                !room.FindNearestSpareSpace(cp, cfg.SizeRadius, 1, out cp))
            {
                UIManager.Instance.Tips.AddTip("没有足够的建造空间");
                return;
            }

            var buff = conn.Send2Srv("ConstructBuilding");
            buff.Write(UUIs.CurUnitType);
            buff.Write(cp);
            conn.End(buff);
        }
        else
        {
            var buff = conn.Send2Srv("AddBattleUnitAt");
            buff.Write(UUIs.CurUnitType);
            buff.Write(cp);
            conn.End(buff);
        }
    }
示例#16
0
文件: UnitsUI.cs 项目: radtek/SCM2
    // 构造所有的UUI
    private void BuildAllUUIs()
    {
        var uts = UnitConfiguration.AllUnitTypes.Select((ut) =>
        {
            var meInfo = GameCore.Instance.MeInfo;

            var orgType = meInfo.Variants.ContainsKey(ut) ? ut : UnitConfiguration.GetDefaultConfig(ut).OriginalType;

            bool isUnlock  = meInfo.Units[ut];
            bool isVarType = meInfo.Variants[orgType] == ut;
            bool isNoCard  = UnitConfiguration.GetDefaultConfig(ut).NoCard;

            return(isUnlock && isVarType && !isNoCard);
        });

        for (var i = 0; i < uts.Count; i++)
        {
            var ut  = uts [i];
            var cfg = UnitConfiguration.GetDefaultConfig(ut);

            Transform parent = null;

            if (cfg.IsThirdType)
            {
                parent = ThirdContent;
            }
            else if (cfg.IsBuilding)
            {
                parent = BuildingContent;
            }
            else
            {
                parent = ArmyContent;
            }

            GameObject uui = CreateUUI(parent);
            SetUUIInfo(uui, ut);

            var btn = uui.GetComponent <UnitCardUI>();
            btn.OnPtDown    += () => OnSelUnit(ut);
            btn.OnBeginDrag += OnBeginDrag;
            btn.OnDrag      += OnDrag;
            btn.OnEndDrag   += OnEndDrag;

            btns[ut] = btn;
            uui.SetActive(false);
        }
    }
示例#17
0
文件: UnitsUI.cs 项目: radtek/SCM2
    // 设置页签默认选定按钮
    private void SetDefaultSelBtn(string ut)
    {
        if (!(null == curBtn || !curBtn.gameObject.activeSelf))
        {
            return;
        }

        var cfg = UnitConfiguration.GetDefaultConfig(ut);

        if ((cfg.IsBuilding && !IsShowArmyList) || (!cfg.IsBuilding && IsShowArmyList))
        {
            CurUnitType = ut;
            curBtn      = btns[ut];
            btns[ut].OnPtDown();
        }
    }
示例#18
0
文件: UnitsUI.cs 项目: radtek/SCM2
    // 设置UUI信息
    private void SetUUIInfo(GameObject uui, string type)
    {
        var cfg = UnitConfiguration.GetDefaultConfig(type);

        Sprite img = Resources.Load <Sprite>(@"Texture\UnitCard\" + type);

        if (null != img)
        {
            uui.transform.Find("Name").gameObject.SetActive(true);
            uui.transform.Find("Icon").gameObject.SetActive(true);
            uui.transform.Find("Icon").GetComponent <Image>().sprite = img;
            uui.transform.Find("Icon").GetComponent <Image>().SetNativeSize();
        }
        else
        {
            uui.transform.Find("Name").gameObject.SetActive(true);
            uui.transform.Find("Icon").gameObject.SetActive(false);
        }

        var okImg = uui.transform.Find("OK").GetComponent <Image>();

        uui.transform.Find("Name").GetComponent <Text>().text    = cfg.DisplayName;
        uui.transform.Find("Cost").GetComponent <Text>().text    = cfg.Cost.ToString();
        uui.transform.Find("GasCost").GetComponent <Text>().text = cfg.GasCost.ToString();
        uui.transform.Find("Num").GetComponent <Text>().text     = "0";
        uui.transform.Find("OK").gameObject.SetActive(!cfg.IsBuilding);
        uui.transform.Find("BuildingOK").gameObject.SetActive(cfg.IsBuilding);

        if (!cfg.IsBuilding)
        {
            var mainBuilder = UnitConfiguration.GetMainBuilder(type);

            if (mainBuilder == "Barrack")
            {
                okImg.sprite = Resources.Load <Sprite>(@"Texture\CombatUI\zhandou_27");
            }
            else if (mainBuilder == "Factory")
            {
                okImg.sprite = Resources.Load <Sprite>(@"Texture\CombatUI\zhandou_28");
            }
            else if (mainBuilder == "Airport")
            {
                okImg.sprite = Resources.Load <Sprite>(@"Texture\CombatUI\zhandou_29");
            }
        }
    }
示例#19
0
文件: Room.cs 项目: radtek/SCM2
        // 空投伞兵到指定位置,路径随机
        public bool CreateSoldierCarrier(string type, int player, Vec2 dropPt)
        {
            var cfg = UnitConfiguration.GetDefaultConfig(type);

            var cost    = cfg.Cost;
            var gasCost = cfg.GasCost;

            if (GetResource(player, "Money") < cost || GetResource(player, "Gas") < gasCost)
            {
                return(false);
            }
            else if (cfg.Prerequisites != null && GetAllUnitsByPlayer(player,
                                                                      (u) => u.BuildingCompleted && CheckPrerequisites(player, u.UnitType)).Length == 0)
            {
                return(false);
            }

            var aps = GetUnitsByType(UnitConfiguration.GetMainBuilder(type), player);

            if (aps.Length == 0)
            {
                return(false);
            }

            AddResource(player, "Money", -cost);
            AddResource(player, "Gas", -gasCost);

            // 随机从一个机场出发
            var fromPt = aps[RandomNext(0, aps.Length)].Pos;
            var dir    = dropPt - fromPt;
            var mr     = MapSize.x > MapSize.y ? MapSize.x : MapSize.y;

            dir = dir.Length > 1 ? dir / dir.Length : Vec2.Zero;
            var toPt = dropPt + dir * mr;
            var stc  = AddNewUnit(null, type, fromPt, player);

            var pType = cfg.Pets[0];
            var pCnt  = int.Parse(cfg.Pets[1]);

            FC.For(pCnt, (i) => { stc.UnitCosntructingWaitingList.Add(pType); });
            stc.Dir = dir.Dir();
            stc.MovePath.Add(dropPt);
            stc.MovePath.Add(toPt);

            return(true);
        }
示例#20
0
文件: UnitsUI.cs 项目: radtek/SCM2
    // 刷新所有按钮状态
    private void RefreshBtns()
    {
        if (MG.Room == null)
        {
            return;
        }

        needRefreshBtns = false;
        foreach (var ut in btns.Keys)
        {
            var cfg = UnitConfiguration.GetDefaultConfig(ut);

            // 前置条件
            var ok = cfg.Prerequisites == null || MG.Room.CheckPrerequisites(GameCore.Instance.MePlayer, ut);

            if (IsOpenAllUUI)
            {
                ok = true;
            }

            var btn = btns[ut];
            btn.gameObject.SetActive(ok);
            btn.transform.Find(cfg.IsBuilding ? "BuildingCheck" : "Check").gameObject.SetActive(btn == curBtn);

            var coreBuilder = UnitConfiguration.GetMainBuilder(ut);
            if (coreBuilder != null)
            {
                builder[ut]     = MG.Room.GetAllMyUnits((u) => (u.UnitType == coreBuilder || u.cfg.ReconstructFrom == coreBuilder) && u.BuildingCompleted).Length;
                builderAccs[ut] = MG.Room.GetMyUnitsByType("Accessory", (u) =>
                                                           u.Owner != null && u.BuildingCompleted &&
                                                           u.Owner.BuildingCompleted && (u.Owner.UnitType == coreBuilder || u.Owner.cfg.ReconstructFrom == coreBuilder)).Length;
            }
            else
            {
                builder[ut]     = 1;
                builderAccs[ut] = 0;
            }

            if (ok)
            {
                // 当前默认选定第一个
                SetDefaultSelBtn(ut);
            }
        }
    }
示例#21
0
文件: DescUI.cs 项目: radtek/SCM2
    private void ShowDescInfo(string unitType)
    {
        var info = UnitConfiguration.GetDefaultConfig(unitType);

        AttackType01.text = info.CanAttackGround ? "<color=green>是</color>" : "<color=red>否</color>";
        AttackType02.text = info.CanAttackAir ? "<color=green>是</color>" : "<color=red>否</color>";
        Cost.text         = info.Cost.ToString();
        GasCost.text      = info.GasCost.ToString();

        AttackPower.text  = info.CanAttackGround ? info.AttackPower[0].ToString() : "";
        AttackPower.text += info.CanAttackAir && info.CanAttackGround ? ", " : "";
        AttackPower.text += info.CanAttackAir ? info.AttackPower[1].ToString() : "";

        ConstructingTime.text = info.ConstructingTime.ToString() + "s";
        MaxHp.text            = info.MaxHp.ToString();
        Defence.text          = info.Defence.ToString();

        Desc.text = info.Desc;
    }
示例#22
0
    public bool CheckResourceRequirementAndTip(string unitType)
    {
        var cfg = UnitConfiguration.GetDefaultConfig(unitType);

        var cost    = cfg.Cost;
        var gasCost = cfg.GasCost;

        if (GameCore.Instance.GetMyResource("Money") < cost)
        {
            AddTip("晶矿不足");
            return(false);
        }
        else if (GameCore.Instance.GetMyResource("Gas") < gasCost)
        {
            AddTip("瓦斯不足");
            return(false);
        }

        return(true);
    }
示例#23
0
    void ShowLevelUpSel(string[] newTypes, Vec2 pt)
    {
        // var btns = new string[newTypes.Length + 1];
        // newTypes.CopyTo(btns, 0);
        // btns[newTypes.Length] = "DestroyBuilding";
        var btns = newTypes;

        var ui = UIManager.Instance.ShowTopUI("InBattleUI/SelectUnitUI", true) as SelectUnitUI;

        ui.Pos         = pt;
        ui.Choices     = btns;
        ui.ChoicesName = btns.ToArray((i, t, skipAct) =>
        {
            //if (t == "DestroyBuilding")
            //    return "回收";

            var ccfg = UnitConfiguration.GetDefaultConfig(t);
            return(ccfg.DisplayName);
        });
        ui.Refresh();
        ui.OnChoiceSel = (toType) =>
        {
            if (toType == "DestroyBuilding")
            {
                ShowReDestroySel(pt);
            }
            else if (!U.BuildingCompleted || !MG.CheckPrerequisitesAndTip(toType) || !MG.CheckResourceRequirementAndTip(toType))
            {
                return;
            }
            else
            {
                var conn = GameCore.Instance.ServerConnection;
                var buff = conn.Send2Srv("ReconstructBuilding");
                buff.Write(U.UID);
                buff.Write(toType);
                conn.End(buff);
            }
        };
    }
示例#24
0
        public override void Init()
        {
            room = (Room4Server)Room;

            sm.NewState("createBarrack").Run((st, te) =>
            {
                if (barrackU == null)
                {
                    barrackU = room.SrvConstructBuilding(Player, "Barrack", new Vec2(30, 20));
                }
            }).AsDefault();

            var cd = Fix64.Zero;

            sm.NewState("addSoldier").Run((st, te) =>
            {
                if (!barrackU.BuildingCompleted)
                {
                    return;
                }

                var sd = room.SrvAddBattltUnitAt(Player, "SoldierWithDog", new Vec2(30, 25));

                if (sd != null)
                {
                    cd = UnitConfiguration.GetDefaultConfig("Soldier").ConstructingTime;
                }
            });

            sm.NewState("addSoldierCD").Run((st, te) =>
            {
                cd -= te;
            });

            sm.Trans().From("createBarrack").To("addSoldier").When((st) => barrackU != null);
            sm.Trans().From("addSoldier").To("createBarrack").When((st) => barrackU.Hp <= 0);
            sm.Trans().From("addSoldier").To("addSoldierCD").When((st) => cd > 0);
            sm.Trans().From("addSoldierCD").To("addSoldier").When((st) => cd <= 0);
        }
示例#25
0
文件: Room.cs 项目: radtek/SCM2
        // 检查前置单位条件是否具备
        public bool CheckPrerequisites(int player, string unitType)
        {
            var cfg = UnitConfiguration.GetDefaultConfig(unitType);

            if (cfg.Prerequisites == null || cfg.Prerequisites.Length == 0)
            {
                return(true);
            }

            foreach (var rs in cfg.Prerequisites)
            {
                var satisfied = true;
                foreach (var r in rs)
                {
                    if (r[0] == '-') // 指示 “必须没有某单位” 这种条件,建筑的互斥条件不需要等造完
                    {
                        if (ExistsUnit(player, (u) => ((u.BuildingCompleted || cfg.IsBuilding) && r.EndsWith(u.UnitType)) ||
                                       (u.cfg.ReconstructFrom != null && !u.BuildingCompleted && r.EndsWith(u.cfg.ReconstructFrom))))
                        {
                            satisfied = false;
                            break;
                        }
                    } // 默认是 “必须有某单位” 这种条件
                    else if (!ExistsUnit(player, (u) => (u.UnitType == r && u.BuildingCompleted) ||
                                         (u.cfg.ReconstructFrom != null && !u.BuildingCompleted && u.cfg.ReconstructFrom == r)))
                    {
                        satisfied = false;
                        break;
                    }
                }

                if (satisfied)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#26
0
文件: UnitsUI.cs 项目: radtek/SCM2
    private void OnEndDrag(bool cancelDrag)
    {
        if (string.IsNullOrEmpty(CurUnitType))
        {
            return;
        }

        if (cancelDrag || !UnitConfiguration.GetDefaultConfig(CurUnitType).IsBuilding)
        {
            MG.UPSUI.Hide();
        }

        if (cancelDrag)
        {
            return;
        }

        HitGroundPos();
        Vec2 pt = UIManager.Instance.World2UI(hitPt);

        MG.OnClick(pt, UIManager.Instance.View2Ground(ptNow));
    }
示例#27
0
    private void ShowUnitInfo(string type, GameObject go)
    {
        var name    = go.transform.Find("Name");
        var icon    = go.transform.Find("Icon");
        var cost    = go.transform.Find("Cost");
        var gasCost = go.transform.Find("GasCost");

        Sprite img = Resources.Load <Sprite>(@"Texture\UnitCard\" + type);

        if (null != img)
        {
            name.gameObject.SetActive(true);
            icon.gameObject.SetActive(true);
            icon.GetComponent <Image>().sprite = img;
            icon.GetComponent <Image>().SetNativeSize();
        }
        else
        {
            name.gameObject.SetActive(true);
            icon.gameObject.SetActive(false);
        }

        var cfg = UnitConfiguration.GetDefaultConfig(type);

        if (cfg == null)
        {
            return;
        }

        var myMoney = GameCore.Instance.GetMyResource("Money");
        var myGas   = GameCore.Instance.GetMyResource("Gas");

        var costTxt    = myMoney >= cfg.Cost ? "<color=#00D8FFFF>" + cfg.Cost + "</color>" : "<color=red>" + cfg.Cost + "</color>";
        var gasCostTxt = myGas >= cfg.GasCost ? "<color=#10EE25FF>" + cfg.GasCost + "</color>" : "<color=red>" + cfg.GasCost + "</color>";

        cost.GetComponent <Text>().text    = costTxt;
        gasCost.GetComponent <Text>().text = gasCostTxt;
    }
示例#28
0
文件: UnitsUI.cs 项目: radtek/SCM2
    public void OnSelUnit(string c)
    {
        // 再次点击取消选中
        if (CurUnitType == c)
        {
            CancelSelUnit();
            return;
        }

        if (curBtn != null)
        {
            var vcfg = UnitConfiguration.GetDefaultConfig(CurUnitType);

            curBtn.transform.Find(vcfg.IsBuilding ? "BuildingCheck" : "Check").gameObject.SetActive(false);
        }

        curBtn      = btns[c];
        CurUnitType = c;

        var vcfg1 = UnitConfiguration.GetDefaultConfig(CurUnitType);

        curBtn.transform.Find(vcfg1.IsBuilding ? "BuildingCheck" : "Check").gameObject.SetActive(true);

        if (null != onSelUnit)
        {
            onSelUnit();
        }

        if (null != onHideUnitPlacedArea)
        {
            onHideUnitPlacedArea();
        }

        if (null != onShowUnitPlacedArea)
        {
            onShowUnitPlacedArea(c);
        }
    }
示例#29
0
文件: DescUI.cs 项目: radtek/SCM2
    private void BuildAllVariants(string orgType)
    {
        ItemDic = new Dictionary <string, GameObject>();

        var cfgKeys = UnitConfiguration.AllUnitTypes;

        for (int i = 0; i < cfgKeys.Length; i++)
        {
            var info = UnitConfiguration.GetDefaultConfig(cfgKeys[i]);

            if (string.IsNullOrEmpty(info.OriginalType))
            {
                if (cfgKeys[i] == orgType)
                {
                    CreateItem(cfgKeys[i]);
                }
            }
            else if (info.OriginalType == orgType)
            {
                CreateItem(cfgKeys[i]);
            }
        }
    }
示例#30
0
文件: DescUI.cs 项目: radtek/SCM2
    private void OnVariantChanged(bool isOn, GameObject go)
    {
        if (!isOn)
        {
            go.transform.Find("Mark").gameObject.SetActive(false);
            return;
        }

        ClearDescInfo();

        go.transform.Find("Mark").gameObject.SetActive(true);

        var type = go.name;

        ShowDescInfo(type);

        var info    = GameCore.Instance.MeInfo;
        var orgType = info.Variants.ContainsKey(type) ? type : UnitConfiguration.GetDefaultConfig(type).OriginalType;

        info.Variants[orgType] = type;

        UserManager.SyncVariants2Server();
    }