Beispiel #1
0
    public bool Attack(Pawn other)
    {
        bool pawnDied = false;

        if (m_swordHp > 0.0f)
        {
            AttackOutcome outcome = other.TakeDmg(m_dmg);
            m_swordHp -= m_dmg;
            if (m_swordHp <= 0.0f)
            {
                if (armyId == GameBoard.PLAYER_ARMY_ID)
                {
                    FindObjectOfType <AdvancementManager>().NewBrokenSword(transform.position);
                }

                m_swordHp    = 0.0f;
                m_isInCombat = false;
                m_tileRemoveCallback(this);
                if ((outcome == AttackOutcome.None) || ((outcome == AttackOutcome.Repair) && other.m_isInCombat))
                {
                    m_assignToTileCallback(other, m_tilePositionX, m_tilePositionY, m_subTilePositionX, m_subTilePositionY);
                    other.m_isMovingToFreePlace = true;
                }
                else if (outcome == AttackOutcome.Death)
                {
                    m_killCallback?.Invoke(other.gameObject);
                }

                if (!(armyId == GameBoard.PLAYER_ARMY_ID && m_armyManager.AskForRepair(this)))
                {
                    m_killCallback?.Invoke(gameObject, false);
                }
                return(true);
            }

            if ((outcome == AttackOutcome.Death) || ((outcome == AttackOutcome.Repair) && !other.m_isInCombat))
            {
                m_isMovingToFreePlace = true;
                m_assignToTileCallback(this, other.m_tilePositionX, other.m_tilePositionY, other.m_subTilePositionX, other.m_subTilePositionY);
                if (outcome == AttackOutcome.Death)
                {
                    m_killCallback?.Invoke(other.gameObject, false);
                }
                m_isInCombat = false;
                pawnDied     = true;
            }
        }
        return(pawnDied);
    }
Beispiel #2
0
 private void Update()
 {
     if (m_currentCooldown <= m_attackCooldown)
     {
         m_currentCooldown += Time.deltaTime;
     }
     else
     {
         m_currentCooldown = 0.0f;
         bool finished = false;
         if (m_pawn1.initiative > m_pawn2.initiative)
         {
             finished = m_pawn1.Attack(m_pawn2);
         }
         else if (m_pawn1.initiative > m_pawn2.initiative)
         {
             finished = m_pawn1.Attack(m_pawn2);
         }
         else
         {
             // dice roll
             int roll = Random.Range(0, 1);
             if (roll == 0)
             {
                 finished = m_pawn1.Attack(m_pawn2);
             }
             else
             {
                 finished = m_pawn2.Attack(m_pawn1);
             }
         }
         if (finished)
         {
             m_killCallback?.Invoke(gameObject);
         }
     }
 }