示例#1
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));
        }
示例#2
0
        public virtual void Perform(MapElementInfo self, MapElementInfo nonSelf)
        {
            // calc damage
            int damage = CalcDamage(self, nonSelf);

            string a = $"{self.name} ({self.Player().name})";
            string d = $"{nonSelf.name} ({nonSelf.Player().name})";

            Debug.LogError("Damage:" + damage);

            // check it
            if (damage == 0)
            {
                OnMapUI.Get().unitUI.ShowPanelMessage(S.T("attackDamEqual", self.name, d));
                NAudio.Play("defend");
                //inform another player
                nonSelf.AddNoti($"Defended against {a}", self.baseData.Icon);
                return;
            }

            // counter fight
            if (damage < 0)
            {
                Perform(nonSelf, self);
                OnMapUI.Get().unitUI.ShowPanelMessage($"{d} fight back.");
                return;
            }

            // win
            ShowUnitAttack(self, nonSelf);
            nonSelf.AddHp(-damage);
            L.b.animations.Hp(-damage, nonSelf.Pos(), nonSelf);
            OnMapUI.Get().unitUI.ShowPanelMessage($"You won. {d} lose {damage} HP.");
            nonSelf.AddNoti($"{a} attacked you. {nonSelf.name} lose {damage} HP.", self.baseData.Icon);
            //int oX = defensor.getX();
            //int oY = defensor.getY();
            //UiHelper.textAnimation("-" + damage + " hp", oX, oY, true, Color.SALMON);

            //TODO add animation
            //defensor.getActor().addAction(Actions.sequence(Actions.color(Color.RED, 1), Actions.color(Color.WHITE, 1)));
            //getActor().addAction(Actions.parallel(Actions.sequence(Actions.moveTo(oX * 32, oY * 32, 1), Actions.moveTo(x * 32, y * 32, 1)),
            //    Actions.sequence(Actions.color(Color.BLACK, 1), Actions.color(Color.WHITE, 1))));
        }
示例#3
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);
            }
        }
示例#4
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            //dying?
            if (holder.trigger == ActionEvent.NextRound)
            {
                info.Kill();
                info.AddNoti(S.T("destroyDie", info.name), DataAction().Icon);
                return;
            }

            WindowPanelBuilder wpb = WindowPanelBuilder.Create(S.T("destroyKill", info.name));

            wpb.panel.AddImageTextButton(S.T("destroyKill", info.name), info.Sprite(), (() =>
            {
                info.Kill();
                OnMapUI.Get().UpdatePanel(info.Pos());
                wpb.Close();
            }));
            wpb.AddClose();
            wpb.Finish();
        }
示例#5
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);
        }