public PlayerModel(string fileName) { if (null == fileName) { throw new ArgumentNullException(nameof(fileName)); } XDocument doc = ResourceHelper.LoadXmlDocument($"{nameof(Player)}.Model.Resources." + fileName); XElement modelNode = doc.Root; Name = GameObject.ReadNecessaryValue <string> (modelNode, nameof(Name)); Introduction = GameObject.ReadNecessaryValue <string> (modelNode, nameof(Introduction)); IEnumerable <PlayerSaying> tempSayingWhenGained = modelNode.Element(nameof(SayingWhenGained)).Elements( ).Select(p => new PlayerSaying(p)); SayingWhenGained.AddRange(tempSayingWhenGained); IEnumerable <PlayerSaying> tempSayingWhenHarmed = modelNode.Element(nameof(SayingWhenGained)).Elements( ).Select(p => new PlayerSaying(p)); SayingWhenHarmed.AddRange(tempSayingWhenHarmed); IEnumerable <PlayerSaying> tempSayingWhenMeet = modelNode.Element(nameof(SayingWhenMeet)).Elements( ).Select(p => new PlayerSaying(p)); SayingWhenMeet.AddRange(tempSayingWhenMeet); }
public PlayerSaying GetSayingWhenHarmed(PlayerModel gained) { while (true) { List <PlayerSaying> temp = new List <PlayerSaying> (SayingWhenHarmed.Where(saying => saying.Player == gained ? .Name)); if (temp.Count != 0) { return(temp [GameRandom.Current.Next(0, temp.Count)]); } gained = null; } }