/// <summary> /// Sets position same as metaposition. /// </summary> /// <param name="metaPosition"></param> public void SetPositionMyMetaPosition(Player.MetaPosition metaPosition) { if (!data.d.ContainsKey(PP.POSITION)) { data.d.Add(PP.POSITION, Player.Position.CATCHER); } if (metaPosition == Player.MetaPosition.CATCHER) { SetData(PP.POSITION, Player.Position.SUB_CATCHER); } else if (metaPosition == Player.MetaPosition.IN_FIELD_PLAYER) { SetData(PP.POSITION, Player.Position.SUB_IN_FIELD); } else if (metaPosition == Player.MetaPosition.OUT_FIELD_PLAYER) { SetData(PP.POSITION, Player.Position.SUB_OUT_FIELD); } else if (metaPosition == Player.MetaPosition.STARTER_PITCHER) { SetData(PP.POSITION, Player.Position.SUB_STARTER_PITCHER); } else if (metaPosition == Player.MetaPosition.RELIEF_PITCHER) { SetData(PP.POSITION, Player.Position.SUB_RELIEF_PITCHER); } }
public int RefreshPlayerList(Player.MetaPosition metaPosition, SortDropdown.SortMode sortMode, StartingMemberFilter startingMemberFilter = StartingMemberFilter.ALL, PlayerList.PlayerView playerView = PlayerList.PlayerView.SKILLS_AND_STATISTICS) { currentStartingMemberFilter = startingMemberFilter; isModeNow = false; currentMetaPosition = metaPosition; int instantiatedAmount = 0; //Removes children of player content. for (int i = 0; i < playerContent.transform.childCount; ++i) { Transform child = playerContent.transform.GetChild(i); Destroy(child.gameObject); } PlayerSort(Values.myTeam.players.d, sortMode); //Instantiates playerPanel to it. for (int i = 0; i < Values.myTeam.players.d.Count; ++i) { if (startingMemberFilter == StartingMemberFilter.MEMBER_EXCLUDED && Values.myTeam.players[i].Value.isStartingMember && !Values.myTeam.players[i].Value.isSubstitute) { continue; } else if (startingMemberFilter == StartingMemberFilter.MEMBER_ONLY && !Values.myTeam.players[i].Value.isStartingMember) { continue; } else if (startingMemberFilter == StartingMemberFilter.SUB_ONLY && !Values.myTeam.players[i].Value.isSubstitute) { continue; } else if (startingMemberFilter == StartingMemberFilter.SUB_EXCLUDED && Values.myTeam.players[i].Value.isSubstitute) { continue; } if (Values.myTeam.players[i].Value.playerData.GetData(PlayerData.PP.META_POSITION) != metaPosition) { continue; } ++instantiatedAmount; PlayerInstantiate(Values.myTeam.players[i].Value, playerView); } return(instantiatedAmount); }
//Member Function /// <summary> /// Dataset of player. /// </summary> /// <param name="name"></param> /// <param name="number"></param> /// <param name="height"></param> /// <param name="weight"></param> /// <param name="metaPosition">A wider position value. One metaposition can have multiple positions.</param> /// <param name="year"></param> /// <param name="month"></param> /// <param name="day"></param> public PlayerData(string name = "", int number = 0, int height = 0, int weight = 0, Player.MetaPosition metaPosition = Player.MetaPosition.STARTER_PITCHER, int year = 1994, int month = 4, int day = 17) { data = new SerializableDict <PP, object>(); SerializableDict <PP, float> SetSerializableDictPP(PP pref) { SerializableDict <PP, float> sdpp = (SerializableDict <PP, float>)data.d[pref]; foreach (PP p in serializableDictPrefs[pref]) { sdpp.d.Add( (PP)PPString.FindIndex(delegate(string cmp) { return(cmp == PPString[(int)p]); }), 50); } return(sdpp); } SerializableDict <PP, float> SetSerializableDictPP_Position(Player.MetaPosition meta) { SerializableDict <PP, float> sdpp = (SerializableDict <PP, float>)data.d[PP.POSITION_SKILLS]; foreach (Player.Position p in Player.metaPosition[meta]) { if (p == Player.Position.DESIGNATED_HITTER) { continue; } sdpp.d.Add( (PP)PPString.FindIndex(delegate(string cmp) { return(cmp == Player.positionString[(int)p]); }), 50); } return(sdpp); } data.d.Add(PP.NAME, name); data.d.Add(PP.NUMBER, number); data.d.Add(PP.BIRTH_DATE, new DateTime(year, month, day)); data.d.Add(PP.HEIGHT, height); data.d.Add(PP.WEIGHT, weight); data.d.Add(PP.META_POSITION, metaPosition); data.d.Add(PP.IS_LEFT_HANDED, true); data.d.Add(PP.CONDITION, 0f); data.d.Add(PP.STRENGTH, new SerializableDictPP()); data.d.Add(PP.CONTROL, new SerializableDictPP()); data.d.Add(PP.CONSISTENCY, new SerializableDictPP()); data.d.Add(PP.INTELLECT, new SerializableDictPP()); data.d.Add(PP.POSITION_SKILLS, new SerializableDictPP()); SetSerializableDictPP(PP.STRENGTH); SetSerializableDictPP(PP.CONTROL); SetSerializableDictPP(PP.CONSISTENCY); SetSerializableDictPP(PP.INTELLECT); SetSerializableDictPP_Position(metaPosition); SetPositionMyMetaPosition(metaPosition); }
/// <summary> /// Creats a random player. /// </summary> /// <param name="isPitcher"></param> /// <param name="metaPosition"></param> /// <returns></returns> public static Player CreatePlayer(bool isPitcher = true, Player.MetaPosition metaPosition = Player.MetaPosition.STARTER_PITCHER) { PlayerData playerData = new PlayerData("", 0, 0, 0, metaPosition); PlayerStatistics stats = new PlayerStatistics(1); playerData.SetData(PlayerData.PP.NAME, RandomNameGenerator.MakeName()); playerData.SetData(PlayerData.PP.NUMBER, UnityEngine.Random.Range(0, 100)); playerData.SetData(PlayerData.PP.BIRTH_DATE, new DateTime(UnityEngine.Random.Range(1970, 2000), UnityEngine.Random.Range(1, 13), UnityEngine.Random.Range(1, 28))); playerData.SetData(PlayerData.PP.HEIGHT, UnityEngine.Random.Range(170f, 190f)); playerData.SetData(PlayerData.PP.WEIGHT, UnityEngine.Random.Range(60f, 90f)); playerData.SetData(PlayerData.PP.IS_LEFT_HANDED, RandomHanded()); playerData.SetData(PlayerData.PP.CONDITION, UnityEngine.Random.Range(80f, 100f)); foreach (PlayerData.PP metaPref in PlayerData.serializableDictPrefs.Keys.ToList()) { if (metaPref == PlayerData.PP.PITCH) { continue; } foreach (PlayerData.PP pref in ((SerializableDictPP)playerData.data.d[metaPref]).d.Keys.ToList()) { playerData.SetDictData(metaPref, UnityEngine.Random.Range(30f, 100f), pref); } } //training Training.Train train = (Training.Train)UnityEngine.Random.Range(0, Training.trainString.Count); //pitcher if (isPitcher) { //Sets pitches. float valueTemp = UnityEngine.Random.Range(30f, 100f); Dictionary <Pitcher.Pitch, float> pitches = new Dictionary <Pitcher.Pitch, float> { { Pitcher.Pitch.FOURSEAM, valueTemp } }; playerData.data.d.Add(PlayerData.PP.PITCH, new SerializableDictPP()); playerData.SetDictData(PlayerData.PP.PITCH, valueTemp, (PlayerData.PP)PlayerData.PPString.IndexOf(Pitcher.PitchString[(int)Pitcher.Pitch.FOURSEAM])); for (int i = 0; i < UnityEngine.Random.Range(1, 6); ++i) { Pitcher.Pitch pitch; do { pitch = (Pitcher.Pitch)UnityEngine.Random.Range(0, Enum.GetNames(typeof(Pitcher.Pitch)).Length); } while (pitches.ContainsKey(pitch)); float value = UnityEngine.Random.Range(30f, 100f); pitches.Add(pitch, value); playerData.SetDictData(PlayerData.PP.PITCH, value, (PlayerData.PP)PlayerData.PPString.IndexOf(Pitcher.PitchString[(int)pitch])); } //Sets random pitcher stat data. for (int year = Values.date.Year - UnityEngine.Random.Range(1, 3); year <= Values.date.Year; ++year) { int gameTotal = UnityEngine.Random.Range(20, 33); for (int game = 0; game < gameTotal; ++game) { DateTime date = new DateTime(year, game / 28 + 1, game % 28 + 1); stats.SetStat(1, PlayerStatistics.PS.G, date); foreach (PlayerStatistics.PS stat in PlayerStatistics.pitcherPS) { stats.SetStat(UnityEngine.Random.Range(1, 3), stat, date); } } } Player.AddPlayerCreated(); return(new Pitcher(Player.GetPlayerCreated(), playerData, stats, train, pitches, playerData.GetData(PlayerData.PP.STRENGTH), playerData.GetData(PlayerData.PP.CONTROL), playerData.GetData(PlayerData.PP.CONSISTENCY), playerData.GetData(PlayerData.PP.INTELLECT))); } //batter else { //playerData.SetData(PlayerData.PP.POSITION, (Player.Position)UnityEngine.Random.Range(0, 9)); //Sets batter stat data. for (int year = Values.date.Year - UnityEngine.Random.Range(1, 3); year <= Values.date.Year; ++year) { int gameTotal = UnityEngine.Random.Range(20, 33); for (int game = 0; game < gameTotal; ++game) { DateTime date = new DateTime(year, game / 28 + 1, game % 28 + 1); stats.SetStat(1, PlayerStatistics.PS.G, date); foreach (PlayerStatistics.PS stat in PlayerStatistics.batterPS) { stats.SetStat(UnityEngine.Random.Range(1, 3), stat, date); } } } Player.AddPlayerCreated(); return(new Batter(Player.GetPlayerCreated(), playerData, stats, train, playerData.GetData(PlayerData.PP.STRENGTH), playerData.GetData(PlayerData.PP.CONTROL), playerData.GetData(PlayerData.PP.CONSISTENCY), playerData.GetData(PlayerData.PP.INTELLECT))); } }