Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public virtual ActionHolder Create(string setting)
 {
     ActionHolder dic = new ActionHolder();
     dic.id = id;
     dic.cost = dic.DataAction().cost;
     
     //copy req
     foreach (var data in dic.DataAction().req.reqs)
     {
         dic.req.Add(data[0], data[1]);
     }
     
     return dic;
 }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        public override void Perform()
        {
            //check ap
            if (action.DataAction().cost > self.data.ap)
            {
                ActionHelper.WaitRound(holders, action, self, pos);
                return;
            }

            string erg = holders.Perform(action, ActionEvent.Direct, S.ActPlayer(), self, pos);

            if (erg != null)
            {
                UIHelper.ShowOk(action.DataAction().Name(), erg);
            }
        }
Ejemplo n.º 6
0
        private bool FindPos(Player player, UnitInfo unit, NVector pos, ActionHolder holder)
        {
            if (holder.data.ContainsKey("pos"))
            {
                return(true);
            }
            DataUnit dUnit = unit.dataUnit;

            //find next field
            foreach (var p in CircleGenerator.Gen(pos, unit.data.apMax / 5 * 2))
            {
                if (AddGoal(unit, holder, p))
                {
                    return(true);
                }
            }

            //has nothing?
            //search the whole map
            for (int x = 0; x < GameMgmt.Get().data.map.width; x++)
            {
                for (int y = 0; y < GameMgmt.Get().data.map.height; y++)
                {
                    if (AddGoal(unit, holder, new NVector(x, y, pos.level)))
                    {
                        return(true);
                    }
                }
            }

            //has a field?
            unit.SetLastInfo(S.T("actionRepeatErrorDestination", holder.DataAction().Name()));
            unit.SetWaitingAction(null);
            return(false);
        }
Ejemplo n.º 7
0
        public void SetRepeatAction(ActionWaiting waiting)
        {
            data.waiting = waiting;
            if (waiting == null)
            {
                return;
            }

            waiting.endless = true;

            //perform first
            ActionHolder a   = data.action.actions[waiting.actionPos];
            string       erg = data.action.Perform(a, ActionEvent.NextRound, Player(), this, waiting.pos);

            AddNoti(S.T("actionPerform", data.name, a.DataAction().Name(), erg), a.DataAction().Icon);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            if (CheckAllowed(player, info, pos, holder))
            {
                return;
            }

            WindowTabBuilder wtb = WindowTabBuilder.Create(holder.DataAction().Desc());

            AddLast(player, info, pos, holder, wtb);

            foreach (string e in player.elements.elements)
            {
                Element         ele = L.b.elements[e];
                SplitElementTab set = new SplitElementTab(ele.Name(), ele.Icon, holder.DataAction().Name());

                var b = Objects().GetAllByCategory(ele.id).OrderBy(o => o.Name()).ToList();
                foreach (TU build in b)
                {
                    AddObject(player, info, pos, build.id, set);
                }

                if (set.Count() > 0)
                {
                    wtb.Add(set);
                }
            }

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

            wtb.CloseWindow();
            info.UI().ShowPanelMessageError(S.T("tabNo", holder.DataAction().Desc()));
        }
Ejemplo n.º 10
0
        public void StartPlayerRound()
        {
            //has a waiting round?
            if (data.waiting == null)
            {
                return;
            }

            ActionHolder a  = data.action.actions[data.waiting.actionPos];
            FDataAction  da = a.DataAction();

            //perform every turn?
            if (data.waiting.endless)
            {
                if (da.interaction)
                {
                    AddNoti(S.T("actionInteraction", data.name, da.Name()), da.Icon);
                    data.waiting.needPerform = true;
                }
                else
                {
                    string erg2 = data.action.Perform(a, ActionEvent.NextRound, Player(), this, data.waiting.pos);
                    AddNoti(S.T("actionPerform", data.name, da.Name(), erg2), da.Icon);
                }

                return;
            }

            //wait more?
            if (data.waiting.apMax > data.ap + data.waiting.ap)
            {
                data.waiting.ap += data.ap;
                data.ap          = 0;
                return;
            }

            Debug.Log(da.Name() + da.interaction);

            if (da.interaction)
            {
                AddNoti(S.T("actionInteraction", data.name, da.Name()), da.Icon);
                data.waiting.needPerform = true;
            }
            else
            {
                PerformWaitingAction();
            }
        }
Ejemplo n.º 11
0
        public string Status(int playerId)
        {
            string text = " ";

            if (!Owner(playerId))
            {
                return($"{gameObject.name} belongs to {Player().name}");
            }

            if (IsUnderConstruction())
            {
                return($"{gameObject.name} under construction ({(int) (GetComponent<Construction>().GetConstructionProcent()*100)}%) {data.info.LastInfo()}");
            }

            if (data.waiting != null)
            {
                ActionHolder a  = data.action.actions[data.waiting.actionPos];
                FDataAction  da = a.DataAction();
                text += $"Prepare {da.Name()}";

                if (data.waiting.endless)
                {
                    text += $" (repeat unlimited).";
                }
                else
                {
                    text += $" ({TextHelper.Proc(data.waiting.ap, data.waiting.apMax)}).";
                }


                if (S.Debug())
                {
                    text += data.ap + "/" + data.waiting.ap + "/" + data.waiting.apMax;
                }
            }

            //add hp?
            string hp = data.hp < data.hpMax ? $"HP:{data.hp}/{data.hpMax}, " : "";

            return($"{gameObject.name} {hp}AP:{data.ap}/{data.apMax}{text} {data.info.LastInfo()}");
        }
Ejemplo n.º 12
0
        public void PerformWaitingAction()
        {
            //has a waiting round?
            if (data.waiting == null)
            {
                return;
            }

            ActionHolder a  = data.action.actions[data.waiting.actionPos];
            FDataAction  da = a.DataAction();

            data.ap           = data.waiting.apMax - data.waiting.ap;
            data.ap          += data.waiting.ap;
            a.data["waiting"] = data.waiting.sett;
            string erg = data.action.Perform(a, data.waiting.evt, Player(), this, data.waiting.pos);

            a.data.Remove("waiting");
            data.ap = data.waiting.apMax - data.waiting.ap;
            AddNoti(S.T("actionPerform", data.name, da.Name(), erg), da.Icon);
            data.waiting = null;
        }
Ejemplo n.º 13
0
        protected void AddButtons()
        {
            //remove actions
            UIHelper.ClearChild(actions);

            //has active action?
            if (ActiveAction != null)
            {
                ShowPanelMessage(ActiveAction.PanelMessage());
                FDataAction action = ActiveAction.DataAction();
                UIHelper.CreateImageTextButton(S.T("actionCancel", action.Name()), action.Sprite(), actions.transform,
                                               () => { OnMapUI.Get().SetActiveAction(null, active.GetComponent <BuildingInfo>() != null); },
                                               "cancel");
                return;
            }

            //has waiting action?
            if (active.data.waiting != null)
            {
                //can perform?
                if (active.data.waiting.needPerform)
                {
                    active.PerformWaitingAction();
                    return;
                }

                ActionHolder a = active.data.action.actions[active.data.waiting.actionPos];
                UIHelper.CreateImageTextButton(S.T("actionWaitingCancel"), a.DataAction().Sprite(), actions.transform,
                                               () =>
                {
                    active.data.ap = Math.Max(0, Math.Min(active.data.waiting.ap, active.data.apMax));
                    active.SetWaitingAction(null);
                    OnMapUI.Get().UpdatePanel(active.Pos());
                }, "cancel");
                return;
            }

            AddAllActionButtons();
        }
Ejemplo n.º 14
0
        protected void AddLast(Player player, MapElementInfo info, NVector pos, ActionHolder holder,
                               WindowTabBuilder wtb)
        {
            var last = L.b.playerOptions["last" + id];

            //add last used?
            if (!string.IsNullOrEmpty(last.Value()))
            {
                SplitElementTab set = new SplitElementTab(last.Name(), last.Icon, holder.DataAction().Name());
                foreach (string key in SplitHelper.Separator(last.Value()))
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        continue;
                    }

                    AddObject(player, info, pos, key, set);
                }

                wtb.Add(set);
            }
        }
Ejemplo n.º 15
0
        public void AddNewActionButton(ActionHolders holder, ActionHolder action, MapElementInfo info,
                                       GameObject actionPanel)
        {
            if (action == null)
            {
                throw new MissingMemberException($"Action for {info} is missing.");
            }

            //BasePerformAction ba = action.PerformAction();
            FDataAction da = action.DataAction();

            //can add under construction?
            if (info.IsUnderConstruction() && !da.useUnderConstruction)
            {
                return;
            }

            //can add from diff player?
            if (da.onlyOwner && !info.Owner(S.ActPlayerID()))
            {
                return;
            }

            //can add final?
            if (!action.req.Check(S.ActPlayer(), info, info.Pos(), true))
            {
                return;
            }

            Button button = UIElements.CreateImageButton(da.Sprite(), actionPanel.transform, () =>
            {
                PerformAction(holder, action, info);
            }, da.sound);

            UIHelper.HoverEnter(button,
                                () => { ShowPanelMessage(S.T("actionTooltip", LSys.tem.inputs.ActionName(da), action.cost, info.data.ap)); },
                                () => { ShowPanelMessage(info.Status(S.ActPlayerID())); });
        }
Ejemplo n.º 16
0
 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;
 }
Ejemplo n.º 17
0
        private void MoveToPos(Player player, UnitInfo unit, ActionHolder holder)
        {
            DataUnit dUnit = unit.dataUnit;
            NVector  dPos  = new NVector(holder.data["pos"]);
            int      level = unit.Pos().level;
            //go to this field
            List <PPoint> points = S.Map().PathFinding(level).Path(player, dUnit.movement, unit.Pos(), dPos);
            NVector       last   = null;

            Debug.Log("Go to Goal " + unit.Pos() + " " + dPos);

            //find last possible point
            foreach (PPoint pp in points)
            {
                NVector p = new NVector(pp.x, pp.y, level);

                //free field?
                string s = unit.Passable(p);
                Debug.Log(p + ": " + s);
                if (s != null)
                {
                    break;
                }

                //save it
                last = p;
            }

            Debug.Log("Go to Goal " + last);

            //move their?
            if (last == null)
            {
                if (holder.data.ContainsKey("posTried"))
                {
                    unit.SetLastInfo(S.T("actionRepeatErrorMove", holder.DataAction().Name()));
                    unit.SetRepeatAction(null);
                }
                else
                {
                    unit.SetLastInfo(S.T("actionRepeatErrorPath", holder.DataAction().Name()));
                    if (unit.data.ap == unit.data.apMax)
                    {
                        holder.data["posTried"] = "yes";
                    }
                }

                return;
            }

            //move their
            unit.MoveTo(last, true);
            holder.data.Remove("posTried");

            if (dPos.Equals(last))
            {
                //perform it
                holder.data.Remove("pos");
                PerformRepeat(player, unit, dPos, holder);
            }

            //has enough ap for a next exploration?
            //todo dynamic
            if (dUnit.ap >= 10)
            {
                //Explore(player, unit, pos, holder);
            }
        }