예제 #1
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))));
        }