コード例 #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);
        }
コード例 #2
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            var unit = S.Unit().At(pos);

            if (!CreateBonus(unit.Player(), unit, pos, unit.Town()))
            {
                info.UI().ShowPanelMessageError(S.T("presentNone", info.data.name, unit.data.name));
                return;
            }

            info.data.apMax += 1;
            info.UI().ShowPanelMessage(S.T("presentSuccessful", info.data.name, unit.data.name));

            //gift self? add costs
            if (unit.Player() == info.Player())
            {
                holder.cost += Random.Range(1, 1 + holder.cost / 4);
                info.AddNoti(S.T("presentOwn"), DataAction().Icon);
            }
        }
コード例 #3
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()));
        }
コード例 #4
0
ファイル: Spell.cs プロジェクト: TrutzX/9Nations
        public void Perform(Player player, MapElementInfo mapElementInfo, NVector pos, bool ani)
        {
            //mapElementInfo.data.ap -= cost;
            var    target = S.MapElement(pos);
            string msg    = null;
            int    ap     = 0;
            int    chance = mapElementInfo.data.spells.CalcChance(id);

            mapElementInfo.data.spells.Cast(id);
            target = (target != null) ? target : mapElementInfo;
            //can perform?
            if (chance > Random.Range(0, 100))
            {
                //calc cost
                foreach (var ah in action.actions)
                {
                    ap += ah.DataAction().cost;
                }

                mapElementInfo.data.ap += ap; //tmp for spell using
                msg = action.Performs(ActionEvent.All, player, target, pos);

                //success?
                if (String.IsNullOrEmpty(msg))
                {
                    if (ani && !String.IsNullOrEmpty(animation))
                    {
                        L.b.animations.Create(animation, pos);
                        NAudio.Play(Sound);
                        if (!mapElementInfo.IsBuilding())
                        {
                            ((UnitInfo)mapElementInfo).UnitAnimator().PlayIdleAnimation(UnitAnimatorType.Cast);
                        }
                    }

                    mapElementInfo.AddNoti(S.T("spellSuccess", Name()), Icon);

                    return;
                }
            }

            //falure

            //calc cost
            ap = 0;
            foreach (var ah in action.actions)
            {
                ap += ah.DataAction().cost;
            }

            mapElementInfo.data.ap += ap; //tmp for spell using
            var nmsg = actionFail.Performs(ActionEvent.All, player, target, pos);

            if (ani)
            {
                L.b.animations.Create("broken", pos);
                mapElementInfo.UI().ShowPanelMessageError(S.T("spellError", Name()));
            }

            msg = $"{msg} {nmsg}";

            mapElementInfo.AddNoti(S.T("spellError", Name(), msg), Icon);
        }