Example #1
0
    public PlayInfo GetActionSuccess(PlayInfo _currentPlay, PlayInfo _lastPlay)
    {
        MatchEvent lastEvent = _lastPlay != null ? _lastPlay.Event : MatchEvent.None;

        PlayerData attacker = _currentPlay.Attacker;
        PlayerData defender = null;

        TeamData attackingTeam = _currentPlay.Attacker.Team;
        TeamData defendingTeam = null;

        Zone defendingZone = Zone.CM;

        Zone         zone                   = _currentPlay.Zone;
        PlayerAction lastAction             = PlayerAction.None;
        bool         isLastActionSuccessful = false;
        MarkingType  marking                = _currentPlay.Marking;
        bool         isTackling             = false;
        float        fault                  = faultChance;
        float        agilityBonus;

        if (_currentPlay.Defender != null)
        {
            defender      = _currentPlay.Defender;
            defendingTeam = _currentPlay.DefendingTeam;
            defendingZone = defendingTeam.GetTeamZone(zone);
        }

        _currentPlay.AttackFatigueRate  = fatigueLow;
        _currentPlay.DefenseFatigueRate = fatigueLow;
        _currentPlay.AttackingBonus     = 1;
        //_currentPlay.TargetZone = zone;

        if (_lastPlay != null)
        {
            lastAction             = _lastPlay.OffensiveAction;
            isLastActionSuccessful = _lastPlay.IsActionSuccessful;
            if (isLastActionSuccessful)
            {
                _currentPlay.AttackingBonus = _lastPlay.AttackingBonus;
            }
        }

        //If attacker has no action = fail
        if (_currentPlay.OffensiveAction == PlayerAction.None)
        {
            _currentPlay.IsActionSuccessful = false;
            return(_currentPlay);
        }
        else
        {
            _currentPlay = GetOffensiveActionRolls(_currentPlay, _lastPlay);
        }

        _currentPlay = playDiceRolls.GetAttackRollResult(_currentPlay);
        _currentPlay.AttackerRoll *= attacker.FatigueModifier();
        if (_currentPlay.AttackerRoll <= 0)
        {
            return(_currentPlay);
        }

        //Check if tackling is really happening
        if (defender == null)
        {
            isTackling = false;
            _currentPlay.DefensiveAction = PlayerAction.None;
        }
        else
        {
            float tackleChance = 0.75f * GameData.Instance.ActionChancePerZone[(int)defendingZone].Tackle * defender.Prob_Tackling;
            if (marking == MarkingType.Close)
            {
                tackleChance *= 1.25f;
            }

            if (defender.Team.IsStrategyApplicable(defendingZone))
            {
                tackleChance *= GameData.Instance.TeamStrategies[(int)defender.Team.Strategy].TacklingChance;
            }

            isTackling |= tackleChance >= Random.Range(0f, 1f);
        }

        if (isTackling)
        {
            //Roll dice
            _currentPlay = playDiceRolls.GetDefenseRollResult(_currentPlay);

            agilityBonus  = (float)defender.GetAttributeBonus(defender.Agility) / 100;
            agilityBonus *= defender.FatigueModifier();
            fault        *= (1f - agilityBonus);

            _currentPlay.DefenderRoll      *= defender.FatigueModifier();
            _currentPlay.DefenseFatigueRate = fatigueMedium;


            //Check if tackle resulted in a fault
            if (fault >= Random.Range(0f, 1f))
            {
                if (_currentPlay.AttackingTeam.GetTeamZone(zone) == Zone.Box)
                {
                    _currentPlay.Event = MatchEvent.Penalty;
                }
                else
                {
                    _currentPlay.Event = MatchEvent.Fault;
                }

                _currentPlay.IsActionSuccessful = false;
            }

            else
            {
                _currentPlay.IsActionSuccessful = _currentPlay.AttackerRoll > _currentPlay.DefenderRoll;
                _currentPlay.IsActionDefended   = !_currentPlay.IsActionSuccessful;
            }

            defender.MatchStats.Tackles++;
        }

        else
        {
            float difficulty = Random.Range(0f, 1f);
            float bonus      = (float)attacker.GetOverall() / 100;
            if (bonus > 0)
            {
                difficulty -= bonus;
            }

            _currentPlay.IsActionSuccessful = _currentPlay.AttackerRoll > difficulty;
        }

        if (defender != null)
        {
            defender.Fatigue -= _currentPlay.DefenseFatigueRate * (25 / (float)defender.Stamina);
        }
        return(_currentPlay);
    }