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); }
private void UpdateStrategyDropdown() { List <Team_Strategy> list = GameData.Instance.TeamStrategies; List <string> strList = new List <string>(); for (int i = 0; i < list.Count; i++) { Team_Strategy data = list[i]; strList.Add(data.Name); } strategyDropdown.ClearOptions(); strategyDropdown.AddOptions(strList); strategyDropdown.value = (int)Team.Strategy; }
public bool IsStrategyApplicable(Zone _zone) { bool value = false; Team_Strategy teamStrategy = GameData.Instance.TeamStrategies[(int)Strategy]; switch (_zone) { case Zone.OwnGoal: value = teamStrategy.OwnGoal; break; case Zone.BLD: value = teamStrategy.BLD; break; case Zone.BRD: value = teamStrategy.BRD; break; case Zone.LD: value = teamStrategy.LD; break; case Zone.LCD: value = teamStrategy.LCD; break; case Zone.CD: value = teamStrategy.CD; break; case Zone.RCD: value = teamStrategy.RCD; break; case Zone.RD: value = teamStrategy.RD; break; case Zone.LDM: value = teamStrategy.LDM; break; case Zone.LCDM: value = teamStrategy.LCDM; break; case Zone.CDM: value = teamStrategy.CDM; break; case Zone.RCDM: value = teamStrategy.RCDM; break; case Zone.RDM: value = teamStrategy.RDM; break; case Zone.LM: value = teamStrategy.LM; break; case Zone.LCM: value = teamStrategy.LCM; break; case Zone.CM: value = teamStrategy.CM; break; case Zone.RCM: value = teamStrategy.RCM; break; case Zone.RM: value = teamStrategy.RM; break; case Zone.LAM: value = teamStrategy.LAM; break; case Zone.LCAM: value = teamStrategy.LCAM; break; case Zone.CAM: value = teamStrategy.CAM; break; case Zone.RCAM: value = teamStrategy.RCAM; break; case Zone.RAM: value = teamStrategy.RAM; break; case Zone.LF: value = teamStrategy.LF; break; case Zone.LCF: value = teamStrategy.LCF; break; case Zone.CF: value = teamStrategy.CF; break; case Zone.RCF: value = teamStrategy.RCF; break; case Zone.RF: value = teamStrategy.RF; break; case Zone.ALF: value = teamStrategy.ALF; break; case Zone.ARF: value = teamStrategy.ARF; break; case Zone.Box: value = teamStrategy.Box; break; } return(value); }
public Zone GetTargetZone(PlayInfo _playInfo) { Zone zone = _playInfo.AttackingTeam.GetTeamZone(_playInfo.Zone); MatchEvent _event = _playInfo.Event; PlayerAction _action = _playInfo.OffensiveAction; TeamStrategy _teamStrategy = _playInfo.AttackingTeam.Strategy; bool _isAwayTeam = _playInfo.AttackingTeam.IsAwayTeam; List <KeyValuePair <Zone, float> > list = new List <KeyValuePair <Zone, float> >(); _OwnGoal = 0; _BLD = 0; _BRD = 0; _LD = 0; _LCD = 0; _CD = 0; _RCD = 0; _RD = 0; _LDM = 0; _LCDM = 0; _CDM = 0; _RCDM = 0; _RDM = 0; _LM = 0; _LCM = 0; _CM = 0; _RCM = 0; _RM = 0; _LAM = 0; _LCAM = 0; _CAM = 0; _RCAM = 0; _RAM = 0; _LF = 0; _LCF = 0; _CF = 0; _RCF = 0; _RF = 0; _ALF = 0; _ARF = 0; _Box = 0; if (_event == MatchEvent.Goalkick) { _LDM = 0.15f; _LCDM = 0.15f; _CDM = 015f; _RCDM = 0.15f; _RDM = 0.15f; _LM = 1f; _LCM = 1f; _CM = 1f; _RCM = 1f; _RM = 1f; _LAM = 0.5f; _LCAM = 0.5f; _CAM = 0.5f; _RCAM = 0.5f; _RAM = 0.5f; } else if (_action == PlayerAction.Pass || _action == PlayerAction.Dribble || _action == PlayerAction.Sprint) { TargetPassPerZone data = GameData.Instance.TargetPassPerZone[(int)zone]; _OwnGoal = data.OwnGoal; _BLD = data.BLD; _BRD = data.BRD; _LD = data.LD; _LCD = data.LCD; _CD = data.CD; _RCD = data.RCD; _RD = data.RD; _LDM = data.LDM; _LCDM = data.LCDM; _CDM = data.CDM; _RCDM = data.RCDM; _RDM = data.RDM; _LM = data.LM; _LCM = data.LCM; _CM = data.CM; _RCM = data.RCM; _RM = data.RM; _LAM = data.LAM; _LCAM = data.LCAM; _CAM = data.CAM; _RCAM = data.RCAM; _RAM = data.RAM; _LF = data.LF; _LCF = data.LCF; _CF = data.CF; _RCF = data.RCF; _RF = data.RF; _ALF = data.ALF; _ARF = data.ARF; _Box = data.Box; } else if (_action == PlayerAction.Cross || _action == PlayerAction.LongPass) { CrossTargetPerZoneData.TargetCrossPerZone data = GameData.Instance.TargetCrossPerZone[(int)zone]; _OwnGoal = data.OwnGoal; _BLD = data.BLD; _BRD = data.BRD; _LD = data.LD; _LCD = data.LCD; _CD = data.CD; _RCD = data.RCD; _RD = data.RD; _LDM = data.LDM; _LCDM = data.LCDM; _CDM = data.CDM; _RCDM = data.RCDM; _RDM = data.RDM; _LM = data.LM; _LCM = data.LCM; _CM = data.CM; _RCM = data.RCM; _RM = data.RM; _LAM = data.LAM; _LCAM = data.LCAM; _CAM = data.CAM; _RCAM = data.RCAM; _RAM = data.RAM; _LF = data.LF; _LCF = data.LCF; _CF = data.CF; _RCF = data.RCF; _RF = data.RF; _ALF = data.ALF; _ARF = data.ARF; _Box = data.Box; } if (_event != MatchEvent.Goalkick) { Team_Strategy strategy = GameData.Instance.TeamStrategies[(int)_teamStrategy]; _OwnGoal *= strategy.Target_OwnGoal; _BLD *= strategy.Target_BLD; _BRD *= strategy.Target_BRD; _LD *= strategy.Target_LD; _LCD *= strategy.Target_LCD; _CD *= strategy.Target_CD; _RCD *= strategy.Target_RCD; _RD *= strategy.Target_RD; _LDM *= strategy.Target_LDM; _LCDM *= strategy.Target_LCDM; _CDM *= strategy.Target_CDM; _RCDM *= strategy.Target_RCDM; _RDM *= strategy.Target_RDM; _LM *= strategy.Target_LM; _LCM *= strategy.Target_LCM; _CM *= strategy.Target_CM; _RCM *= strategy.Target_RCM; _RM *= strategy.Target_RM; _LAM *= strategy.Target_LAM; _LCAM *= strategy.Target_LCAM; _CAM *= strategy.Target_CAM; _RCAM *= strategy.Target_RCAM; _RAM *= strategy.Target_RAM; _LF *= strategy.Target_LF; _LCF *= strategy.Target_LCF; _CF *= strategy.Target_CF; _RCF *= strategy.Target_RCF; _RF *= strategy.Target_RF; _ALF *= strategy.Target_ALF; _ARF *= strategy.Target_ARF; _Box *= strategy.Target_Box; } float total = _OwnGoal + _BLD + _BRD + _LD + _LCD + +_CD + _RCD + _RD + _LDM + _LCDM + +_CDM + _RCDM + _RDM + _LM + _LCM + _CM + _RCM + _RM + _LAM + _LCAM + _CAM + _RCAM + _RAM + _LF + _LCF + _CF + _RCF + _RF + _ALF + _ARF + _Box; _OwnGoal /= total; _BLD /= total; _BRD /= total; _LD /= total; _LCD /= total; _CD /= total; _RCD /= total; _RD /= total; _LDM /= total; _LCDM /= total; _CDM /= total; _RCDM /= total; _RDM /= total; _LM /= total; _LCM /= total; _CM /= total; _RCM /= total; _RM /= total; _LAM /= total; _LCAM /= total; _CAM /= total; _RCAM /= total; _RAM /= total; _LF /= total; _LCF /= total; _CF /= total; _RCF /= total; _RF /= total; _ALF /= total; _ARF /= total; _Box /= total; list.Add(new KeyValuePair <Zone, float>(Zone.OwnGoal, _OwnGoal)); list.Add(new KeyValuePair <Zone, float>(Zone.BLD, _BLD)); list.Add(new KeyValuePair <Zone, float>(Zone.BRD, _BRD)); list.Add(new KeyValuePair <Zone, float>(Zone.LD, _LD)); list.Add(new KeyValuePair <Zone, float>(Zone.LCD, _LCD)); list.Add(new KeyValuePair <Zone, float>(Zone.CD, _CD)); list.Add(new KeyValuePair <Zone, float>(Zone.RCD, _RCD)); list.Add(new KeyValuePair <Zone, float>(Zone.RD, _RD)); list.Add(new KeyValuePair <Zone, float>(Zone.LDM, _LDM)); list.Add(new KeyValuePair <Zone, float>(Zone.LCDM, _LCDM)); list.Add(new KeyValuePair <Zone, float>(Zone.CDM, _CDM)); list.Add(new KeyValuePair <Zone, float>(Zone.RCDM, _RCDM)); list.Add(new KeyValuePair <Zone, float>(Zone.RDM, _RDM)); list.Add(new KeyValuePair <Zone, float>(Zone.LM, _LM)); list.Add(new KeyValuePair <Zone, float>(Zone.LCM, _LCM)); list.Add(new KeyValuePair <Zone, float>(Zone.CM, _CDM)); list.Add(new KeyValuePair <Zone, float>(Zone.RCM, _RCM)); list.Add(new KeyValuePair <Zone, float>(Zone.RM, _RM)); list.Add(new KeyValuePair <Zone, float>(Zone.LAM, _LAM)); list.Add(new KeyValuePair <Zone, float>(Zone.LCAM, _LCAM)); list.Add(new KeyValuePair <Zone, float>(Zone.CAM, _CAM)); list.Add(new KeyValuePair <Zone, float>(Zone.RCAM, _RCAM)); list.Add(new KeyValuePair <Zone, float>(Zone.RAM, _RAM)); list.Add(new KeyValuePair <Zone, float>(Zone.LF, _LF)); list.Add(new KeyValuePair <Zone, float>(Zone.LCF, _LCF)); list.Add(new KeyValuePair <Zone, float>(Zone.CF, _CF)); list.Add(new KeyValuePair <Zone, float>(Zone.RCF, _RCF)); list.Add(new KeyValuePair <Zone, float>(Zone.RF, _RF)); list.Add(new KeyValuePair <Zone, float>(Zone.ALF, _ALF)); list.Add(new KeyValuePair <Zone, float>(Zone.ARF, _ARF)); list.Add(new KeyValuePair <Zone, float>(Zone.Box, _Box)); Zone target = zone; float random = Random.Range(0.00001f, 1f); float cumulative = 0; for (int i = 0; i < list.Count; i++) { cumulative += list[i].Value; if (random < cumulative) { target = list[i].Key; break; } } if (_isAwayTeam) { return(GetAwayTeamZone(target)); } else { return(target); } }
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); }