Beispiel #1
0
    private MatchUpStats SwitchSides(MatchUpStats matchUp)
    {
        MatchUpStats switchedMatchUp = new MatchUpStats();

        switchedMatchUp.attackerDmgModifier = matchUp.defenderDmgModifier;
        switchedMatchUp.defenderDmgModifier = matchUp.attackerDmgModifier;
        return(switchedMatchUp);
    }
Beispiel #2
0
    public void Fight()
    {
        if (attackerStrat != null && defenderStrat != null)
        {
            float attackerArmySize = attacker.armySize;
            float defenderArmySize = defender.armySize;
            float attackerDamage   = 0f;
            float defenderDamage   = 0f;

            MatchUpStats matchUp = matchUps.GetMatchUp(attackerStrat, defenderStrat);

            for (int i = 1; i <= combatRounds; i++)
            {
                attackerDamage += GetDamage(matchUp.attackerDmgModifier, attackerArmySize);
                defenderDamage += GetDamage(matchUp.defenderDmgModifier, defenderArmySize);

                if (debugLogs)
                {
                    Debug.Log("attackerDamage1: " + attackerDamage);
                }
                if (debugLogs)
                {
                    Debug.Log("defenderDamage1: " + defenderDamage);
                }

                attackerArmySize -= GetDead(ref defenderDamage);
                defenderArmySize -= GetDead(ref attackerDamage);

                if (debugLogs)
                {
                    Debug.Log("attackerDamage2: " + attackerDamage);
                }
                if (debugLogs)
                {
                    Debug.Log("defenderDamage2: " + defenderDamage);
                }

                if (attackerArmySize <= 0 || defenderArmySize <= 0)
                {
                    break;
                }
            }

            // % of enemy army killed
            float attackerPerformance = 1 - defenderArmySize / defender.armySize;
            float defenderPerformance = 1 - attackerArmySize / attacker.armySize;
            if (debugLogs)
            {
                Debug.Log("attackerPerformance: " + attackerPerformance);
            }
            if (debugLogs)
            {
                Debug.Log("defenderPerformance: " + defenderPerformance);
            }

            attacker.SetArmySize((int)Mathf.Ceil(attackerArmySize));
            defender.SetArmySize((int)Mathf.Ceil(defenderArmySize));

            gameObject.SetActive(false);
            if (debugLogs)
            {
                Debug.Log("attackerPerformance > defenderPerformance: " + (attackerPerformance > defenderPerformance));
            }

            resolveBattle.Invoke(attackerPerformance > defenderPerformance);
            resolveBattle.RemoveAllListeners();
        }
    }