private PlayerAction GetFreeKickAction(PlayInfo _currentPlay) { PlayerData player = _currentPlay.Attacker; PlayerAction action = PlayerAction.Pass; MarkingType marking = MarkingType.None; Zone zone = _currentPlay.AttackingTeam.GetTeamZone(_currentPlay.Zone); ActionChancePerZoneTable.Actions zoneChance = GameData.Instance.ActionChancePerZone[(int)zone]; float pass = player.GetActionChance(PlayerAction.Pass, zoneChance, marking, zone); float longPass = player.GetActionChance(PlayerAction.LongPass, zoneChance, marking, zone); float cross = player.GetActionChance(PlayerAction.Cross, zoneChance, marking, zone); float shoot = player.GetActionChance(PlayerAction.Shot, zoneChance, marking, zone); if (player.Team.IsStrategyApplicable(zone)) { Team_Strategy teamStrategy = GameData.Instance.TeamStrategies[(int)player.Team.Strategy]; pass *= teamStrategy.PassingChance; cross *= teamStrategy.CrossingChance; shoot *= teamStrategy.ShootingChance; longPass *= teamStrategy.LongPassChance; } float total = pass + longPass + cross + shoot; pass = pass / total; longPass /= total; cross = cross / total; shoot = shoot / total; List <KeyValuePair <PlayerAction, float> > list = new List <KeyValuePair <PlayerAction, float> > { new KeyValuePair <PlayerAction, float>(PlayerAction.Pass, pass), new KeyValuePair <PlayerAction, float>(PlayerAction.LongPass, longPass), new KeyValuePair <PlayerAction, float>(PlayerAction.Cross, cross), new KeyValuePair <PlayerAction, float>(PlayerAction.Shot, shoot) }; float random = Random.Range(0f, 1f); float cumulative = 0f; for (int i = 0; i < list.Count; i++) { cumulative += list[i].Value; if (random < cumulative) { action = list[i].Key; break; } } return(action); }
public PlayerAction GetOffensiveAction(PlayInfo _playInfo, bool _headerAvailable) { Zone zone = _playInfo.AttackingTeam.GetTeamZone(_playInfo.Zone); MarkingType _marking = _playInfo.Marking; PlayerData _player = _playInfo.Attacker; float _counterAttack = _playInfo.CounterAttack; float bonus = 0; ActionChancePerZoneTable.Actions zoneChance = GameData.Instance.ActionChancePerZone[(int)zone]; float pass = _player.GetActionChance(PlayerAction.Pass, zoneChance, _marking, zone); float longPass = _player.GetActionChance(PlayerAction.LongPass, zoneChance, _marking, zone); float dribble = _player.GetActionChance(PlayerAction.Dribble, zoneChance, _marking, zone); float cross = _player.GetActionChance(PlayerAction.Cross, zoneChance, _marking, zone); float shoot = _player.GetActionChance(PlayerAction.Shot, zoneChance, _marking, zone); float header = 0f; if (_headerAvailable) { header = _player.GetActionChance(PlayerAction.Header, zoneChance, _marking, zone); } if (_counterAttack > 0) { cross *= 1.5f; longPass *= 1.5f; } if (_player.Zone == Zone.OwnGoal) { dribble = 0; shoot = 0; header = 0; } float sprint = 0f; if (_marking == MarkingType.None) { sprint = dribble * 1.5f;; dribble = 0f; bonus = GetPlayerAttributeBonus(_player.Speed); if (Dice.Roll(20, 1, (int)Dice.RollType.None, Mathf.FloorToInt((sprint * 5) + (bonus / 10))) >= 20) { sprint *= 2f; } } float total = pass + longPass + dribble + cross + shoot + header + sprint; pass /= total; longPass /= total; dribble /= total; cross /= total; shoot /= total; header /= total; sprint /= total; List <KeyValuePair <PlayerAction, float> > list = new List <KeyValuePair <PlayerAction, float> > { new KeyValuePair <PlayerAction, float>(PlayerAction.Pass, pass), new KeyValuePair <PlayerAction, float>(PlayerAction.LongPass, longPass), new KeyValuePair <PlayerAction, float>(PlayerAction.Dribble, dribble), new KeyValuePair <PlayerAction, float>(PlayerAction.Cross, cross), new KeyValuePair <PlayerAction, float>(PlayerAction.Shot, shoot), new KeyValuePair <PlayerAction, float>(PlayerAction.Header, header), new KeyValuePair <PlayerAction, float>(PlayerAction.Sprint, sprint) }; float random = Random.Range(0.00001f, 1f); float cumulative = 0f; PlayerAction action = PlayerAction.None; for (int i = 0; i < list.Count; i++) { cumulative += list[i].Value; if (random < cumulative) { action = list[i].Key; break; } } return(action); }
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); }