protected bool CheckAllowed(Player player, MapElementInfo info, NVector pos, ActionHolder holder)
        {
            if (!holder.data.ContainsKey("allowed"))
            {
                return(false);
            }

            //load buildings
            WindowBuilderSplit b = WindowBuilderSplit.Create(holder.DataAction().Desc(), holder.DataAction().Name());

            foreach (string key in SplitHelper.Separator(holder.data["allowed"]))
            {
                AddObject(player, info, pos, key, b);
            }

            //has some?
            if (b.Count() >= 1)
            {
                b.Finish();
                return(true);
            }

            b.CloseWindow();
            info.UI().ShowPanelMessageError(S.T("tabNo", holder.DataAction().Desc()));
            return(true);
        }
Example #2
0
 public BuildSplitElement(BaseDataBuildingUnit build, MapElementInfo go, NVector pos, ISplitManager ism) : base(build.Name(), build.Sprite())
 {
     this.build = build;
     this.pos   = pos;
     this.ism   = ism;
     this.go    = go;
 }
Example #3
0
        private void PerformAction(ActionHolders holder, ActionHolder action, MapElementInfo info)
        {
            FDataAction da = action.DataAction();

            //can use?
            if (!action.req.Check(info.Player(), info, info.Pos()))
            {
                //TODO not hardcoded
                //start interact action?
                if (da.mapElement && holder.Contains("interact") && da.field == "near")
                {
                    PerformAction(holder, holder.Get("interact"), info);
                    return;
                }

                ShowPanelMessageError(action.req.Desc(info.Player(), info, info.Pos()));
                return;
            }

            //check ap
            if (action.cost > info.data.ap)
            {
                ActionHelper.WaitRound(holder, action, info, info.Pos());
                return;
            }

            string mess = holder.Perform(action, ActionEvent.Direct, S.ActPlayer(), info, info.Pos());

            if (mess != null)
            {
                ShowPanelMessageError(mess);
            }
        }
Example #4
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            int playerId = holder.data.ContainsKey("player") ? ConvertHelper.Int(holder.data["player"]) : player.id;

            S.Unit().Create(playerId, holder.data["type"], pos).FinishConstruct();
        }
Example #5
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            //create found window
            WindowPanelBuilder win = WindowPanelBuilder.Create("Found a new town");

            /*GameObject name = win.panel.AddInput("town name",NGenTown.GetTownName(PlayerMgmt.ActPlayer().Nation().TownNameGenerator),s => {});
             * win.panel.AddButton("Generate new name", () =>
             * {
             *  name.GetComponent<InputField>().text = NGenTown.GetTownName(PlayerMgmt.ActPlayer().Nation().TownNameGenerator);
             *  //name.GetComponentsInChildren<Text>()[0].text = NGenTown.GetTownName(PlayerMgmt.Get().GetActPlayer().nation);
             *  //name.GetComponentsInChildren<Text>()[1].text = NGenTown.GetTownName(PlayerMgmt.Get().GetActPlayer().nation);
             * }, "random", "random");*/

            Button button = null;

            InputField townName = win.panel.AddInputRandom("town name",
                                                           LClass.s.NameGenerator(S.ActPlayer().Nation().TownNameGenerator), s => { },
                                                           () => LClass.s.NameGenerator(S.ActPlayer().Nation().TownNameGenerator));

            var coats    = L.b.coats.GetAllByCategory("town");
            var dropdown = win.panel.AddDropdown(coats, coats.ElementAt(S.Towns().GetAll().Length % coats.Count).id,
                                                 coat =>
            {
                UIHelper.UpdateButtonImageColor(button, L.b.coats[coat].color);
            });

            button = win.panel.AddImageTextButton("Found the town", DataAction().Icon, () =>
            {
                win.Close();
                FoundTown(info, pos, townName.text, coats[dropdown.value].id, holder.data.ContainsKey("kill"));
            }, DataAction().sound);
            UIHelper.UpdateButtonImageColor(button, L.b.coats[coats[dropdown.value].id].color);
            win.Finish(400);
        }
Example #6
0
        private void ShowIntern(PanelBuilder panel, MapElementInfo onMap, NVector pos)
        {
            base.ShowLexicon(panel);
            var b = L.b.modifiers[C.BuildRes].CalcText(buildTime, S.ActPlayer(), pos);

            L.b.res[C.BuildRes].AddSubLabel(panel, b.value, "round", b.display);

            int _view = onMap == null ? visibilityRange : onMap.data.visibilityRange;
            int _atk  = onMap == null ? atk : onMap.data.atk;
            int _def  = onMap == null ? def : onMap.data.def;

            var v = L.b.modifiers[C.ViewModi].CalcText(_view, S.ActPlayer(), pos);

            L.b.modifiers[C.ViewModi].AddSubLabel(panel, v.value, "field", v.display);
            ShowWorker(panel);

            if (_atk > 0 || _def > 0)
            {
                panel.AddHeaderLabelT("fight");
            }
            panel.AddSubLabelT("atk", _atk, "atk");
            panel.AddSubLabelT("def", _def, "def");

            panel.AddResT("constructionCost", cost);
            req.BuildPanel(panel, S.T("constructionReq"), null, pos);
            panel.AddModi(modi);
        }
Example #7
0
 public BaseReqArgument(Player player, string sett, MapElementInfo onMap = null, NVector pos = null)
 {
     this.player = player;
     this.sett   = sett;
     this.onMap  = onMap;
     this.pos    = pos;
 }
Example #8
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            string[] keys;
            if (holder.data.ContainsKey("upgrade"))
            {
                keys = SplitHelper.Separator(holder.data["upgrade"]);
            }
            else
            {
                keys = info.IsBuilding()?L.b.buildings.Keys().ToArray():L.b.units.Keys().ToArray();
            }

            //load buildings
            WindowBuilderSplit b = WindowBuilderSplit.Create(holder.DataAction().Desc(), holder.DataAction().Name());

            {
                foreach (string key in keys)
                {
                    BaseDataBuildingUnit build = info.IsBuilding()?(BaseDataBuildingUnit)L.b.buildings[key]:L.b.units[key];
                    if (build.req.Check(player, info, pos, true))
                    {
                        BuildUpgradeSplitElement be = new BuildUpgradeSplitElement(build, info, pos, b);
                        be.disabled = build.req.Desc(player, info, pos);
                        b.Add(be);
                        //win.AddBuilding(build.id);
                    }
                }
            }

            b.Finish();
        }
Example #9
0
        public static void WaitRound(ActionHolders holder, ActionHolder action, MapElementInfo info, NVector pos, int cost = -1, string sett = null, ActionEvent evt = ActionEvent.Direct)
        {
            FDataAction da = action.DataAction();

            cost = cost == -1 ? action.cost : cost;
            int round = (int)Math.Ceiling((1f * cost - info.data.ap) / info.data.apMax);

            WindowPanelBuilder wpb = WindowPanelBuilder.Create($"Wait for {da.Name()}?");

            wpb.panel.RichText(da.Desc());
            wpb.panel.AddImageLabel($"Action {da.Name()} need {cost - info.data.ap} AP more. You can wait {round} rounds.",
                                    "round");
            wpb.panel.AddButton($"Wait {round} rounds", () =>
            {
                var aw   = new ActionWaiting(action, holder, pos);
                aw.apMax = cost;
                aw.sett  = sett;
                aw.evt   = evt;
                info.SetWaitingAction(aw);
                L.b.animations.Create("sandClock", pos);

                OnMapUI.Get().UpdatePanel(info.Pos());
                wpb.Close();
            });
            wpb.AddClose();
            wpb.Finish();
        }
Example #10
0
    //创建地图元素
    public void CreateElementInList()
    {
        if (createElementList == null || createElementList.Count == 0)
        {
            return;
        }

        string key = createElementList[0];

        createElementList.RemoveAt(0);
        MapElement     elementData = visionElementDic[key];
        MapElementInfo elementInfo = elementData.elementInfo;

        activeObj[elementData.elementKey] = null;

        GameObject tempObj = GetObjByDisable(elementData.elementType);

        if (tempObj != null)
        {
            elementLoader.PushCallBack(() =>
            {
                if (tempObj == null)
                {
                    return(false);
                }
                tempObj.transform.position    = elementInfo.Pos;
                tempObj.transform.eulerAngles = elementInfo.Angle;
                tempObj.transform.localScale  = elementInfo.Scale;
                tempObj.SetActive(true);
                activeObj[elementData.elementKey] = tempObj;
                return(true);
            });
        }
        else
        {
            string elementAssetPath = string.Format(MapDefine.MapElementPath, elementData.elementType);
            AssetManager.LoadAsset(elementAssetPath, (obj, str) =>
            {
                elementLoader.PushCallBack(() =>
                {
                    if (obj != null)//&& visionElementDic.ContainsKey(key))
                    {
                        if (activeObj.ContainsKey(elementData.elementKey))
                        {
                            GameObject assetTree = obj as GameObject;
                            Transform element    = GameObject.Instantiate(assetTree).transform;
                            element.SetParent(elementRoot.transform);
                            element.position    = elementInfo.Pos;
                            element.eulerAngles = elementInfo.Angle;
                            element.localScale  = elementInfo.Scale;
                            activeObj[elementData.elementKey] = element.gameObject;
                            return(true);
                        }
                        return(false);
                    }
                    return(false);
                });
            });
        }
    }
Example #11
0
        private void Set(MapElementInfo info, string key, int value)
        {
            switch (key)
            {
            case "ap":
                Set(ref info.data.ap, value);
                break;

            case "apMax":
                Set(ref info.data.apMax, value);
                break;

            case "hp":
                Set(ref info.data.hp, value);
                break;

            case "hpMax":
                Set(ref info.data.hpMax, value);
                break;

            case "atk":
                Set(ref info.data.atk, value);
                break;

            case "def":
                Set(ref info.data.def, value);
                break;

            default:
                throw new MissingMemberException("Stat " + key + " is not supported.");
            }
        }
 public ActionInteractSplitElement(ActionHolders holders, ActionHolder action, MapElementInfo self, NVector pos) : base(action.DataAction().Name(), action.DataAction().Icon)
 {
     this.holders = holders;
     this.action  = action;
     this.self    = self;
     this.pos     = pos;
 }
Example #13
0
        /// <summary>
        /// Calc the damage
        /// </summary>
        /// <param name="self"></param>
        /// <param name="nonSelf"></param>
        /// <returns></returns>
        private int CalcDamage(MapElementInfo self, MapElementInfo nonSelf)
        {
            float dam = Random.Range(self.baseData.damMin, self.baseData.damMax + 1);
            int   atk = self.baseData.atk, def = nonSelf.baseData.def;

            foreach (var fm in L.b.fightModis.Values())
            {
                if (!fm.req.Check(self, nonSelf.Pos()))
                {
                    continue;
                }

                dam *= (1 + fm.modi / 100f);
            }

            // check multi
            if (atk >= def)
            {
                dam *= 1 + 0.05f * (atk - def);
            }
            else
            {
                dam *= 1 - 0.025f * (def - atk);
            }

            return((int)dam);
        }
Example #14
0
        protected override int ValueAct(Player player, MapElementInfo onMap, string element, string sett, NVector pos)
        {
            //has it?
            if (onMap != null)
            {
                return(onMap.Town()?.level ?? 0);
            }
            //has the field it?
            UnitInfo u = S.Unit().At(pos);

            if (u != null)
            {
                return(u.Town()?.level ?? 0);
            }
            //has the field it?
            BuildingInfo b = S.Building().At(pos);

            if (b != null)
            {
                return(b.Town()?.level ?? 0);
            }
            //get the nearest town
            Town t = S.Towns().NearestTown(player, pos, false);

            return(t?.level ?? 0);
        }
Example #15
0
        private void ShowUnitAttack(MapElementInfo own, MapElementInfo enemy)
        {
            int x = own.Pos().x - enemy.Pos().x;
            int y = own.Pos().y - enemy.Pos().y;

            Debug.LogWarning(own.name + " " + own.IsBuilding());
            //show attacker animation
            if (!own.IsBuilding())
            {
                UnitInfo unit = (UnitInfo)own;

                var sq = DOTween.Sequence();
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f - x / 4f, unit.Pos().y - y / 4f), 1));
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f, unit.Pos().y), 1));
                unit.UnitAnimator().PlayFightAnimation(x > 0?UnitAnimatorType.AttackEast:x < 0?UnitAnimatorType.AttackWest:y < 0?UnitAnimatorType.AttackSouth:UnitAnimatorType.AttackNorth);
            }

            //show defender animation
            if (!enemy.IsBuilding())
            {
                UnitInfo unit = (UnitInfo)enemy;

                var sq = DOTween.Sequence();
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f - x / 4f, unit.Pos().y - y / 4f), 1));
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f, unit.Pos().y), 1));
                unit.UnitAnimator().PlayFightAnimation(x > 0?UnitAnimatorType.DefendEast:x < 0?UnitAnimatorType.DefendWest:y < 0?UnitAnimatorType.DefendSouth:UnitAnimatorType.DefendNorth);
            }
        }
Example #16
0
        private void LearnSpell(string key, MapElementInfo go)
        {
            Spell spell = Objects()[key];

            go.data.spells.Learn(spell.id);

            go.AddNoti(new Info(S.T("spellLearned", go.name, spell.Name()), spell.Icon));
        }
Example #17
0
        private static void Cast(Spell spell, MapElementInfo go)
        {
            //find destination
            ActionHolder ah = new ActionHolder();

            ah.data["waiting"] = spell.id;
            LClass.s.GetNewAction("magicSelect").PerformCheck(ActionEvent.Direct, S.ActPlayer(), go, go.Pos(), ah);
        }
Example #18
0
 protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                 ActionHolder holder)
 {
     foreach (var ele in holder.data)
     {
         Set(info, ele.Key, ConvertHelper.Int(ele.Value));
     }
 }
Example #19
0
 protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                 ActionHolder holder)
 {
     foreach (var ele in holder.data)
     {
         info.data.modi[ele.Key] = ele.Value;
     }
 }
Example #20
0
        public override bool Check(Player player, MapElementInfo onMap, string sett, NVector pos)
        {
            if (onMap == null || !onMap.IsBuilding())
            {
                onMap = S.Building(pos);
            }

            return(onMap != null && onMap.baseData.category.Contains(sett));
        }
Example #21
0
        public override string Desc(Player player, MapElementInfo onMap, string sett, NVector pos)
        {
            if (onMap == null || !onMap.IsBuilding())
            {
                onMap = S.Building(pos);
            }

            return(Desc(player, sett) + (onMap == null?S.T("reqBuildingCategoryNone"):S.T("reqBuildingCategoryHere", onMap.baseData.category)));
        }
Example #22
0
 public void Init(BuildingUnitData data, Dictionary <string, int> construction, MapElementInfo info, int buildTime)
 {
     data.constructionOrg = new Dictionary <string, int>(construction);
     data.construction    = construction;
     data.construction.Add(C.BuildRes, buildTime + 1);
     data.buildTime = buildTime;
     this._data     = data;
     this._info     = info;
 }
Example #23
0
 protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                 ActionHolder holder)
 {
     if (evt == ActionEvent.NextRound)
     {
         LearnSpell(holder.data["waiting"], info);
         return;
     }
     base.Perform(evt, player, info, pos, holder);
 }
 public BaseSelectElementSplitElement(string id, T ele, MapElementInfo go, NVector pos, ISplitManager ism, Action <MapElementInfo, NVector> perform, Action <PanelBuilder> inform = null) : base(ele.Name(), ele.Sprite())
 {
     this.id      = id;
     this.ele     = ele;
     this.pos     = pos;
     this.ism     = ism;
     this.go      = go;
     this.perform = perform;
     this.inform  = inform;
 }
Example #25
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            if (!info.IsBuilding())
            {
                MoveUnit(info, pos);
                return;
            }

            MoveBuilding(info, pos, holder);
        }
Example #26
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            if (evt == ActionEvent.Direct)
            {
                SetRepeat(info, pos, holder);
                return;
            }

            Repeat(player, info, pos, holder);
        }
Example #27
0
 protected override SplitElement CreateSplitElement(DataBuilding build, MapElementInfo info, NVector pos, ISplitManager ism)
 {
     return(new BaseSelectElementSplitElement <DataBuilding>(id, build, info, pos, ism, (mei, position) =>
     {
         MaterialWindow.ShowBuildMaterialWindow(build, pos, cost =>
         {
             GameMgmt.Get().building.Create(S.Towns().NearestTown(S.ActPlayer(), pos, false).id, build.id, pos, cost);
             OnMapUI.Get().UpdatePanel(pos);
         });
     }));
 }
Example #28
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            //info.data.ap = 0;

            if (evt == ActionEvent.Direct)
            {
                info.SetRepeatAction(new ActionWaiting(holder, info.data.action, pos));
                OnMapUI.Get().UpdatePanel(info.Pos());
            }
        }
Example #29
0
        public string Performs(ActionEvent evt, Player player, [CanBeNull] MapElementInfo info, NVector pos)
        {
            string mess = null;

            foreach (var action in Is(evt))
            {
                mess = mess + (string.IsNullOrEmpty(mess)?null:", ") + Perform(action, evt, player, info, pos);
            }

            return(mess);
        }
Example #30
0
 protected override SplitElement CreateSplitElement(DataUnit build, MapElementInfo info, NVector pos, ISplitManager ism)
 {
     return(new BaseSelectElementSplitElement <DataUnit>(id, build, info, pos, ism, (mei, position) =>
     {
         MaterialWindow.ShowBuildMaterialWindow(build, pos, cost =>
         {
             GameMgmt.Get().unit.Create(S.ActPlayerID(), build.id, pos, cost);
             OnMapUI.Get().UpdatePanel(pos);
         });
     }));
 }