/// <summary> /// 产生某个玩家手牌序列Beaver消息 /// </summary> /// <param name="aPlayer">玩家对象</param> /// <returns>Beaver对象</returns> private Beaver MakeHandMessage(Player aPlayer) { Beaver ret = new Beaver(); foreach (Card c in aPlayer.Hands) { ret.Add(string.Empty, c.ID); } ret.SetHeaderElementName("hands"); return(ret); }
internal static BeaverMarkupLanguage.Beaver Chiefs2Beaver(string aNodeName, ChiefBase[] aChiefs) { Beaver ret = new Beaver(); foreach (ChiefBase c in aChiefs) { ret.Add(string.Empty, c.ChiefName); } ret.SetHeaderElementName(aNodeName); return(ret); //return new BeaverMarkupLanguage.Beaver(aNodeName, aChiefs.Select(i => i.ChiefName.ToString())); }
internal static BeaverMarkupLanguage.Beaver Cards2Beaver(string aNodeName, Card[] aCards) { Beaver ret = new Beaver(); foreach (Card c in aCards) { ret.Add(string.Empty, c.ID); } ret.SetHeaderElementName(aNodeName); return(ret); //return new BeaverMarkupLanguage.Beaver(aNodeName, aCards.Select(i => i.CardNumber).ToArray()); }
private Beaver Chiefs2Beaver(int aIndex) { Beaver ret = new Beaver(); foreach (ChiefBase c in GamePlayers[aIndex].AvailableChiefs) { ret.Add(string.Empty, c.ChiefName); } ret.SetHeaderElementName("chiefs"); return(ret); //Beaver r = null; //foreach (ChiefBase c in GamePlayers[aIndex].AvailableChiefs) // if (r == null) // r = new Beaver("chiefs", c.ChiefName); // else // r.Add(string.Empty, c.ChiefName); //if (r == null) // r = new Beaver("chiefs"); //return r; }
/// <summary> /// 产生所有玩家状态的XML消息 /// </summary> /// <param name="aChief">产生信息的武将对象,对于请求公共信息,这里使用null</param> /// <returns>XML消息</returns> internal string MakeEnvironmentXMLReport(ChiefBase aChief) { Beaver env = new Beaver(); Beaver players = new Beaver(); Beaver chain = new Beaver(); Beaver hands = null; foreach (Player p in GB.GamePlayers.All) { hands = new Beaver("hands"); Beaver debuffs = new Beaver(); Beaver skills = new Beaver(); foreach (Card c in p.Debuff) { debuffs.Add(string.Empty, new Beaver(c.CardEffect.ToString(), c.ID)); } //new XElement("effect", c.CardEffect), //new XElement("card", c.ID) //)); debuffs.SetHeaderElementName("debuffs"); if (p.Chief != null) { foreach (SkillBase s in p.Chief.Skills) { skills.Add(string.Empty, new Beaver(string.Empty, s.SkillName, s.SkillStatus.ToString())); // new XElement("skill", new XElement("name", s.SkillName), new XElement("status", s.SkillStatus))); } if (p.Chief == aChief) { lock (GB.AsynchronousCore.MessageLocker) { foreach (string item in GB.EventChain) { chain.Add(item); } } hands = MakeHandMessage(p); } skills.SetHeaderElementName("skills"); } if (p.Chief != null && p.Chief == aChief) { Beaver player = new Beaver(); player.Add(string.Empty, p.UID, p.PlayerName, p.Dead.ToString(), p.MaxHealth.ToString(), p.Health.ToString()); player.Add(string.Empty, hands, debuffs, skills, p.Chief == null ? string.Empty : p.Chief.ChiefName, p.Chief != null && p.Chief.ChiefStatus == ChiefBase.Status.Majesty ? ChiefBase.Status.Majesty.ToString() : p.Chief != null && p.Dead ? p.Chief.ChiefStatus.ToString() : ChiefBase.Status.Unknown.ToString()); if (p.Weapon != null) { player.Add("weapon", p.Weapon.ID); } if (p.Armor != null) { player.Add("armor", p.Armor.ID); } if (p.Jia1Ma != null) { player.Add("jia1", p.Jia1Ma.ID); } if (p.Jian1Ma != null) { player.Add("jian1", p.Jian1Ma.ID); } players.Add(string.Empty, player); //new XElement("player", // new XElement("UID", p.UID), // new XElement("name", p.PlayerName), // new XElement("dead", p.Dead), // new XElement("max_health", p.MaxHealth), // new XElement("health", p.Health), // p.Weapon == null ? new XElement("weapon") :new XElement("weapon", p.Weapon.ID), // p.Armor == null ?new XElement("armor") :new XElement("armor" , p.Armor.ID), // p.Jia1Ma == null ? new XElement("jia1"):new XElement("jia1",p.Jia1Ma.ID), // p.Jian1Ma == null ? new XElement("jian1") : new XElement("jian1", p.Jian1Ma.ID), // hands, // debuffs, // new XElement("chief_name", p.Chief == null ? string.Empty : p.Chief.ChiefName), // new XElement("status", p.Chief != null && p.Chief.ChiefStatus == ChiefBase.Status.Majesty ? ChiefBase.Status.Majesty : p.Chief != null && p.Dead ? p.Chief.ChiefStatus : ChiefBase.Status.Unknown), // skills //)); } else { Beaver player = new Beaver(); player.Add(string.Empty, p.UID, p.PlayerName, p.Dead.ToString(), p.MaxHealth.ToString(), p.Health.ToString()); player.Add(string.Empty, p.Hands.Count, debuffs, skills, p.Chief == null ? string.Empty : p.Chief.ChiefName, p.Chief != null && p.Chief.ChiefStatus == ChiefBase.Status.Majesty ? ChiefBase.Status.Majesty.ToString() : p.Chief != null && p.Dead ? p.Chief.ChiefStatus.ToString() : ChiefBase.Status.Unknown.ToString()); if (p.Weapon != null) { player.Add("weapon", p.Weapon.ID); } if (p.Armor != null) { player.Add("armor", p.Armor.ID); } if (p.Jia1Ma != null) { player.Add("jia1", p.Jia1Ma.ID); } if (p.Jian1Ma != null) { player.Add("jian1", p.Jian1Ma.ID); } players.Add(string.Empty, player); //players.Add( // new XElement("player", // new XElement("UID", p.UID), // new XElement("name", p.PlayerName), // new XElement("dead", p.Dead), // new XElement("max_health", p.MaxHealth), // new XElement("health", p.Health), // p.Weapon == null ? new XElement("weapon") : new XElement("weapon", p.Weapon.ID), // p.Armor == null ? new XElement("armor") : new XElement("armor", p.Armor.ID), // p.Jia1Ma == null ? new XElement("jia1") : new XElement("jia1", p.Jia1Ma.ID), // p.Jian1Ma == null ? new XElement("jian1") : new XElement("jian1", p.Jian1Ma.ID), // new XElement("hands_count", p.Hands.Count), // debuffs, // new XElement("chief_name", p.Chief == null ? string.Empty : p.Chief.ChiefName), // new XElement("status", p.Chief != null && p.Chief.ChiefStatus == ChiefBase.Status.Majesty ? ChiefBase.Status.Majesty : p.Chief != null && p.Dead ? p.Chief.ChiefStatus : ChiefBase.Status.Unknown), // skills // )); } } if (aChief == null) { lock (GB.EventChainLocker) { foreach (string item in GB.EventChain) { chain.Add(string.Empty, item); } } } //env.Add(players); //env.Add(new XElement("latency", GB.WaittingData.Latency)); //env.Add(new XElement("mode", GB.Mode)); //env.Add(chain); //env.Add(new XElement("active" , GB.gData.Active == null ? string.Empty : GB.gData.Active.ChiefName)); //env.Add(new XElement("status" , GB.gData.ChiefStatus)); env.Add(string.Empty, players); env.Add("common", GB.WaittingData.Latency, GB.Mode.ToString(), chain, GB.gData.Active == null ? string.Empty : GB.gData.Active.ChiefName, GB.gData.ChiefStatus); env.SetHeaderElementName("environment"); return(env.ToString()); }