Ejemplo n.º 1
0
    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;
            }
        }
    }
Ejemplo n.º 2
0
Archivo: Room.cs Proyecto: 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);
        }
Ejemplo n.º 3
0
    // 设置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");
            }
        }
    }
Ejemplo n.º 4
0
    // 刷新所有按钮状态
    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);
            }
        }
    }