コード例 #1
0
    public bool CultureAttacks(Culture attackingCulture, Tile defendingTile)
    {
        Culture defender = defendingTile.OccupyingCulture;
        float   attackingBehaviourValue = attackingCulture.GetParameterValue("Behaviour");

        //if the reputation of defender is too high (but the attacker has a small chance to attack nevertheless
        if (defender.Variables.Reputation > attackingCulture.Variables.Reputation && (Random.Range(0f, 1f) < 0.9f - attackingBehaviourValue))
        {
            return(false);
        }

        float attackArmy = attackingCulture.Variables.PopulationSize * attackingBehaviourValue;
        float defendArmy = defender.Variables.PopulationSize * defender.GetParameterValue("Behaviour");


        int   result = CalculateWin(attackArmy, defendArmy, attackingCulture.Variables.EscalationRate, Mathf.RoundToInt(attackingBehaviourValue * 8) /*TODO Luck value*/);
        float attackingPercentageLoss;
        float defendingPercantageLoss;

        switch (result)
        {
        case 1:
            //CritWin
            ForcedClaimTile(defendingTile, attackingCulture);
            attackingPercentageLoss = Random.Range(0.02f, 0.05f);
            defendingPercantageLoss = Random.Range(0.1f, 0.14f);
            break;

        case 2:
            //Win
            ForcedClaimTile(defendingTile, attackingCulture);
            attackingPercentageLoss = Random.Range(0.04f, 0.1f);
            defendingPercantageLoss = Random.Range(0.08f, 0.12f);
            break;

        case 3:
            //Lose
            TerrainManager.Instance.TileFlickering(defendingTile, Color.black);
            attackingPercentageLoss = Random.Range(0.06f, 0.15f);
            defendingPercantageLoss = Random.Range(0.06f, 0.1f);
            break;

        case 4:
            //CritLose
            TerrainManager.Instance.TileFlickering(defendingTile, Color.white);
            attackingPercentageLoss = Random.Range(0.2f, 0.25f);
            defendingPercantageLoss = Random.Range(0.04f, 0.08f);
            break;

        default:
            throw new ArgumentOutOfRangeException("the calculated WinValue is out of bounds: " + result);
        }
        attackingCulture.AddLosses(attackingPercentageLoss);
        defender.AddLosses(defendingPercantageLoss);

        return(true);
    }