Example #1
0
    public float GetActionChance(PlayerAction _action, ActionChancePerZoneTable.Actions _zoneChance, MarkingType _marking, Zone _zone)
    {
        float         chance       = 0f;
        float         bonus        = 0f;
        Team_Strategy teamStrategy = Team.GetStrategy();

        switch (_action)
        {
        case PlayerAction.Pass:
            chance = _zoneChance.Pass * Prob_Pass;
            bonus  = GetAttributeBonus(Passing);
            if (_marking == MarkingType.Close)
            {
                chance *= 2f;
            }
            if (Dice.Roll(20, 1, (int)Dice.RollType.None, Mathf.FloorToInt((chance * 5) + (bonus / 10)), 100) >= 20)
            {
                chance *= 2f;
            }
            if (Team.IsStrategyApplicable(_zone))
            {
                chance *= teamStrategy.PassingChance;
            }
            break;

        case PlayerAction.LongPass:
            float longPass = _zoneChance.LongPass * Prob_LongPass;
            bonus = GetAttributeBonus(Mathf.FloorToInt((float)(Passing + Strength) / 2));
            if (_marking == MarkingType.Close)
            {
                longPass *= 1.75f;
            }
            if (Dice.Roll(20, 1, (int)Dice.RollType.None, Mathf.FloorToInt((longPass * 5) + (bonus / 10)), 100) >= 20)
            {
                longPass *= 2f;
            }
            if (Team.IsStrategyApplicable(_zone))
            {
                chance *= teamStrategy.LongPassChance;
            }
            break;

        case PlayerAction.Dribble:
            chance = _zoneChance.Dribble * Prob_Dribble;
            bonus  = GetAttributeBonus(Dribbling);
            if (_marking == MarkingType.Close)
            {
                chance *= 0.5f;
            }
            else if (_marking == MarkingType.Distance)
            {
                chance *= 1.5f;
            }
            if (Dice.Roll(20, 1, (int)Dice.RollType.None, Mathf.FloorToInt((chance * 5) + (bonus / 10))) >= 20)
            {
                chance *= 2f;
            }
            if (Team.IsStrategyApplicable(_zone))
            {
                chance *= teamStrategy.DribblingChance;
            }
            break;

        case PlayerAction.Cross:
            chance = _zoneChance.Cross * Prob_Crossing;
            bonus  = GetAttributeBonus(Crossing);
            if (_marking == MarkingType.Close)
            {
                chance *= 0.5f;
            }
            if (Dice.Roll(20, 1, (int)Dice.RollType.None, Mathf.FloorToInt((chance * 5) + (bonus / 10))) >= 20)
            {
                chance *= 2f;
            }
            if (Team.IsStrategyApplicable(_zone))
            {
                chance *= teamStrategy.CrossingChance;
            }
            break;

        case PlayerAction.Shot:
            chance = _zoneChance.Shot * Prob_Shoot;
            bonus  = GetAttributeBonus(Shooting);
            if (_marking == MarkingType.Close)
            {
                chance *= 0.5f;
            }
            else if (_marking == MarkingType.None)
            {
                chance *= 3f;
            }
            if (Dice.Roll(20, 1, (int)Dice.RollType.None, Mathf.FloorToInt((chance * 5) + (bonus / 10))) >= 20)
            {
                chance *= 2f;
            }
            if (Team.IsStrategyApplicable(_zone))
            {
                chance *= teamStrategy.ShootingChance;
            }
            break;

        case PlayerAction.Header:
            chance = (_zoneChance.Shot + Prob_Shoot) * 1.5f;
            bonus  = GetAttributeBonus(Heading);
            if (_marking == MarkingType.Distance)
            {
                chance *= 2f;
            }
            else if (_marking == MarkingType.None)
            {
                chance *= 3f;
            }
            if (Dice.Roll(20, 1, (int)Dice.RollType.None, Mathf.FloorToInt((chance * 5) + (bonus / 10))) >= 20)
            {
                chance *= 2f;
            }
            if (Team.IsStrategyApplicable(_zone))
            {
                chance *= teamStrategy.ShootingChance;
            }
            break;
        }

        return(chance);
    }