/// <summary> /// 安置乐不思蜀的过程 /// </summary> /// <param name="r">子事件的起始节点</param> /// <returns></returns> private EventRecoard LeBuSiShuProc(EventRecoard r) { //玩家不能是自己并且对方不能死亡 if (r.Target != r.Source && !GamePlayers[r.Target].Dead) { //对方不能有乐不思蜀的buff if (!GamePlayers[r.Target].HasDebuff(Card.Effect.LeBuSiShu)) { //把乐不思蜀从垃圾桶中拿出来 PickRubbish(r.Cards); //把乐不思蜀加入到对方的buff列表中 GamePlayers[r.Target].Debuff.Push(r.Cards[0]); AsynchronousCore.SendMessage( new Beaver("lbss", r.Source.ChiefName, r.Target.ChiefName, r.SkillName, Card.Cards2Beaver("cards", r.Cards)).ToString()); //new XElement("lbss", // new XElement("from", r.Source.ChiefName), // new XElement("to", r.Target.ChiefName), // new XElement("skill", r.SkillName), // Card.Cards2XML("cards", r.Cards) // ) //); } } return(r); }
/// <summary> /// 从牌堆取出一张牌作为判定牌 /// </summary> /// <param name="aChief">判定的武将对象</param> /// <param name="aEffect">要判定的效果</param> /// <returns>一张判定牌</returns> internal Card popJudgementCard(ChiefBase aChief, Card.Effect aEffect) { Card c = CardsHeap.Pop(); //取一张牌 AsynchronousCore.SendMessage( new Beaver("judgmentcard", aChief.ChiefName, aEffect.ToString(), Card.Cards2Beaver("cards", new Card[] { c })).ToString()); //new XElement("judgmentcard", // new XElement("target", aChief.ChiefName), // new XElement("effect", aEffect), // Card.Cards2XML("cards", new Card[] { c }) //)); //发送揭出判定牌的消息 ChiefBase t = aChief; //现在从判定牌持有的玩家开始,轮询武将OnChiefJudgementCardShow_Turn方法 do { foreach (ASkill s in t.Skills) { c = s.OnChiefJudgementCardShow_Turn(aChief, c, t, gData); } t = t.Next; }while (t != aChief); c.CardEffect = aEffect; //最后这里设定判定牌的性质是考虑之前判定牌不确定的因素 return(c); }
/// <summary> /// 借刀杀人的过程 /// </summary> /// <param name="r">子事件的起始节点</param> /// <returns></returns> private EventRecoard JieDaoShaRenProc(EventRecoard r) { //玩家自己和两个目标不能死亡,目标不能没有武器 if (!GamePlayers[r.Source].Dead && !GamePlayers[r.Target].Dead && !GamePlayers[r.Target2].Dead && GamePlayers[r.Target].Weapon != null) { //无懈可击 if (WuXieProc(r.Target, Card.Effect.JieDaoShaRen)) { return(r); } string msg = new Beaver("askfor.jdsr.sha", r.Target.ChiefName, r.Target2.ChiefName, r.Source.ChiefName).ToString(); //new XElement("askfor.jdsr.sha", // new XElement("target", r.Target.ChiefName), // new XElement("target2", r.Target2.ChiefName), // new XElement("source", r.Source.ChiefName) //); //向目标问询杀 MessageCore.AskForResult res = AsynchronousCore.AskForCards(r.Target, MessageCore.AskForEnum.Sha, new AskForWrapper(msg, this), gData); ValidityResult(r.Target, ref res); if (res.Effect == Card.Effect.None) { //获得对方的武器对象 Card weapon = GamePlayers[r.Target].Weapon; Move(r.Target, r.Source, new Card[] { weapon }); //玩家得到武器牌 AsynchronousCore.SendMessage(MessageCore.MakeStealMessage(r.Target, r.Source, new Card[] { weapon })); //new XElement("steal", // new XElement("from", r.Target.ChiefName), // new XElement("to", r.Source.ChiefName), // Card.Cards2XML("cards", new Card[] { weapon }) // ) //); } else if (res.Effect == Card.Effect.Sha) { AsynchronousCore.SendMessage( new Beaver("sha", r.Target.ChiefName, ChiefBase.Chiefs2Beaver("to", new ChiefBase[] { r.Target2 }), res.SkillName, Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("sha", // new XElement("from", r.Target.ChiefName), // ChiefBase.Chiefs2XML("to", new ChiefBase[] { r.Target2 }), // new XElement("skill", res.SkillName), // Card.Cards2XML("cards", res.Cards) // ) // ); //再此子事件上创建杀的子事件 DropCards(true, CardFrom.Hand, string.Empty, res.Cards, Card.Effect.Sha, r.Target, r.Target2, null); //执行杀的子事件 ShaProc(lstRecoard.Last());// lstRecoard.ElementAt(lstRecoard.Count - 1) } } return(r); }
internal void RegainHealth(ChiefBase aChief, sbyte aRegain) { if (GamePlayers[aChief].MaxHealth != GamePlayers[aChief].Health) { GamePlayers[aChief].Health += aRegain; AsynchronousCore.SendMessage(new Beaver("health", aChief.ChiefName, GamePlayers[aChief].MaxHealth.ToString(), GamePlayers[aChief].Health.ToString()).ToString()); //new XElement("health", //new XElement("target", aChief.ChiefName), //new XElement("max", GamePlayers[aChief].MaxHealth), //new XElement("current", GamePlayers[aChief].Health) //)); } }
/// <summary> /// 南蛮入侵的过程 /// </summary> /// <param name="r">子事件的起始节点</param> /// <returns></returns> private EventRecoard NanManRuQinProc(EventRecoard r) { //对方不能死亡 if (!GamePlayers[r.Target].Dead) { //无懈可击的执行过程 if (WuXieProc(r.Target, Card.Effect.NanManRuQin)) { return(r); } if (GamePlayers[r.Target].Armor == null || Armor.EnableFor(GamePlayers[r.Target].Armor.CardEffect, r.Cards, Card.Effect.NanManRuQin, r.Target)) { string msg = new Beaver("askfor.nmrq.sha", r.Target.ChiefName, r.Source.ChiefName).ToString(); //new XElement("askfor.nmrq.sha", // new XElement("target", r.Target.ChiefName), // new XElement("source", r.Source.ChiefName) //); //问询杀 MessageCore.AskForResult resSha = AsynchronousCore.AskForCards(r.Target, MessageCore.AskForEnum.Sha, new AskForWrapper(msg, this), gData); ValidityResult(r.Target, ref resSha); if (resSha.Effect == Card.Effect.Sha) { //将杀放入子事件节点 if (resSha.PlayerLead) { DropCards(true, CardFrom.Hand, resSha.SkillName, resSha.Cards, Card.Effect.None, resSha.Leader, r.Source, null); foreach (ASkill s in resSha.Leader.Skills) { s.OnUseEffect(resSha.Leader, Card.Effect.Sha, gData); } AsynchronousCore.SendMessage( new Beaver("nmrq.sha", r.Target.ChiefName, r.Source.ChiefName, resSha.SkillName, Card.Cards2Beaver("cards", resSha.Cards)).ToString()); // new XElement("nmrq.sha", // new XElement("target", r.Target.ChiefName), // new XElement("source", r.Source.ChiefName), // new XElement("skill", resSha.SkillName), // Card.Cards2XML("cards", resSha.Cards) // )); } } else { //没有杀,费血 DamageHealth(r.Target, 1, r.Source, r); } } } return(r); }
/// <summary> /// 顺手牵羊的过程 /// </summary> /// <param name="r">子事件的起始节点</param> /// <returns></returns> private EventRecoard ShunShouQianYangProc(EventRecoard r) { //玩家自己和对方不能死亡,并且对方有牌 if (!GamePlayers[r.Source].Dead && !GamePlayers[r.Target].Dead && GamePlayers[r.Target].HasCardWithJudgementArea) { //无懈可击的过程 if (WuXieProc(r.Target, Card.Effect.ShunShouQianYang)) { return(r); } AsynchronousCore.SendMessage( new Beaver("askfor.ssqy.select", r.Source.ChiefName, r.Target.ChiefName).ToString()); //new XElement("askfor.ssqy.select", // new XElement("target", r.Source.ChiefName), // new XElement("target2", r.Target.ChiefName) //)); //问询玩家选择对方一张牌 MessageCore.AskForResult res = AsynchronousCore.AskForCards(r.Source, MessageCore.AskForEnum.TargetCardWithJudgementArea, r.Target); //如果没有选那就自动抽一张 if (res.Effect == Card.Effect.None || res.Cards.Count() != 1) { Card auto = AutoSelect(r.Target); if (auto == null) { res = new MessageCore.AskForResult(false, res.Leader, res.Targets, new Card[0] { }, Card.Effect.ShunShouQianYang, false, true, string.Empty); } else { res = new MessageCore.AskForResult(false, res.Leader, res.Targets, new Card[] { auto }, Card.Effect.ShunShouQianYang, false, true, string.Empty); } } if (res.Cards.Count() != 0) { Move(r.Target, r.Source, res.Cards); ////把牌给玩家 //foreach (Card c in res.Cards) //{ // AsynchronousCore.SendStealMessage(r.Target, r.Source, new Card[] { c }, GamePlayers); // GamePlayers[r.Source].Hands.Add(c.GetOriginalCard()); //} ////增加节点:顺手牵羊选择的牌 //EventNode(false, CardFrom.HandAndEquipageAndJudgement, res.SkillName, res.Cards, Card.Effect.None, r.Target, r.Source, null); } } return(r); }
/// <summary> /// 过河拆桥的过程 /// </summary> /// <param name="r">子事件的起始节点</param> /// <returns></returns> private EventRecoard GuoHeChaiQiaoProc(EventRecoard r) { //双方不能有任何一方,并且对方有牌可以选择死亡 if (!GamePlayers[r.Source].Dead && !GamePlayers[r.Target].Dead && GamePlayers[r.Target].HasCardWithJudgementArea) { //进入无懈可击的过程 if (WuXieProc(r.Target, Card.Effect.GuoHeChaiQiao)) { return(r); } AsynchronousCore.SendMessage( new Beaver("askfor.ghcq.select", r.Source.ChiefName, r.Target.ChiefName).ToString()); //new XElement("askfor.ghcq.select", // new XElement("target", r.Source.ChiefName), // new XElement("target2", r.Target.ChiefName) //)); //问询玩家选择对方一张牌 MessageCore.AskForResult res = AsynchronousCore.AskForCards(r.Source, MessageCore.AskForEnum.TargetCardWithJudgementArea, r.Target); //如果没有选择那就系统选择一张牌 if (res.Effect == Card.Effect.None) { Card auto = AutoSelect(r.Target); if (auto == null) { res = new MessageCore.AskForResult(false, res.Leader, res.Targets, new Card[0] { }, Card.Effect.GuoHeChaiQiao, false, true, string.Empty); } else { res = new MessageCore.AskForResult(false, res.Leader, res.Targets, new Card[] { auto }, Card.Effect.GuoHeChaiQiao, false, true, string.Empty); } } if (res.Cards.Count() != 0) { //将对方的这张牌加入到子事件节点上并弃置到垃圾桶中 DropCards(true, CardFrom.HandAndEquipageAndJudgement, res.SkillName, res.Cards, Card.Effect.None, r.Target, r.Source, null); AsynchronousCore.SendMessage(MessageCore.MakeDropMessage(r.Source, r.Target, res.Cards)); } } return(r); }
/// <summary> /// 五谷丰登的执行过程 /// </summary> /// <param name="r">起始子事件对象</param> /// <returns>起始子事件</returns> private EventRecoard WuGuFengDengProc(EventRecoard r) { //子事件的目标必须存在且目标不能死亡 if (r.Target != null && !GamePlayers[r.Target].Dead) { //开始无懈可击的处理 if (WuXieProc(r.Target, Card.Effect.WuGuFengDeng)) { return(r); } //发送问询 string msg = new Beaver("askfor.wgfd.select", r.Target.ChiefName).ToString(); //new XElement("askfor.wgfd.select", // new XElement("target", r.Target.ChiefName) // ); //获取问询结果 MessageCore.AskForResult res = AsynchronousCore.AskForCards(r.Target, MessageCore.AskForEnum.WuGuFengDeng, new AskForWrapper(msg, this), gData); //回应的牌不正确,则自动选择一张 if (res.Cards.Count() != 1 || (res.Cards.Count() == 1 && !CardsBuffer[WGFDSlotName].Cards.Contains(res.Cards[0]))) { res = new MessageCore.AskForResult(false, r.Target, new ChiefBase[] { }, new Card[] { CardsBuffer[WGFDSlotName].Cards[GetRandom(CardsBuffer[WGFDSlotName].Cards.Count)] }, Card.Effect.None, false, false, res.SkillName); } foreach (Card c in res.Cards) { CardsBuffer[WGFDSlotName].Cards.Remove(c); GamePlayers[r.Target].Hands.Add(c); } //发送消息 AsynchronousCore.SendMessage( new Beaver("wgfd.select", r.Target.ChiefName, Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("wgfd.select", // new XElement("target", r.Target.ChiefName), // Card.Cards2XML("cards", res.Cards) //)); } return(r); }
/// <summary> /// 安置闪电的过程 /// </summary> /// <param name="r">子事件的起始节点</param> /// <returns></returns> private EventRecoard ShanDianProc(EventRecoard r) { //玩家本人不能死亡 if (!GamePlayers[r.Source].Dead) { //本人不能有闪电buff if (!GamePlayers[r.Source].HasDebuff(Card.Effect.ShanDian)) { //把闪电从垃圾桶中拿出来 PickRubbish(r.Cards); //把闪电放置到自己的buff GamePlayers[r.Source].Debuff.Push(r.Cards[0]); AsynchronousCore.SendMessage( new Beaver("sd", r.Source.ChiefName, r.SkillName, Card.Cards2Beaver("cards", r.Cards)).ToString()); //new XElement("sd", // new XElement("from", r.Source.ChiefName), // new XElement("skill", r.SkillName), // Card.Cards2XML("cards", r.Cards) // ) //); } } return(r); }
/// <summary>弃牌问询,注意该方法仅用于弃牌阶段 /// </summary> /// <param name="aChief">需要弃牌的武将</param> /// <returns>返回true表示弃牌正常</returns> private bool Abandonment(ChiefBase aChief) { bool first = true; //确定玩家弃牌的要求是否达到 while (GamePlayers[aChief].Hands.Count > (GamePlayers[aChief].Health < 0 ? 0 : GamePlayers[aChief].Health)) { //问询武将出牌 string msg = new Beaver("askfor.abandonment", aChief.ChiefName).ToString(); //new XElement("askfor.abandonment", // new XElement("target", aChief.ChiefName) //); MessageCore.AskForResult res = null; if (first) { first = false; //弃牌问询 res = AsynchronousCore.AskForCards(aChief, MessageCore.AskForEnum.Abandonment, new AskForWrapper(msg, this), gData); } else { //弃牌问询 res = AsynchronousCore.AskForCards(aChief, MessageCore.AskForEnum.AbandonmentNext, new AskForWrapper(msg, this), gData); } if (res.TimeOut || res.Cards.Count() == 0) { res = new MessageCore.AskForResult(false, aChief, new ChiefBase[0], AutoAbandonment(aChief), Card.Effect.None, false, true, string.Empty); } //是否超过弃牌数 if (GamePlayers[aChief].Hands.Count - res.Cards.Count() < (GamePlayers[aChief].Health < 0 ? 0 : GamePlayers[aChief].Health)) { //超过了,不合法,自动选择 Card[] cards = AutoAbandonment(aChief); if (!RemoveHand(aChief, cards)) { return(false); } CardsHeap.AddCards(cards); AsynchronousCore.SendMessage(new Beaver("abandonment", aChief.ChiefName, GamePlayers[aChief].Hands.Count.ToString(), Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("abandonment", // new XElement("target", aChief.ChiefName), // new XElement("count", GamePlayers[aChief].Hands.Count), // Card.Cards2XML("cards", res.Cards) //)); } else { if (!RemoveHand(aChief, res.Cards)) { return(false); } //EventNode(true, CardFrom.Hand, res.Cards, Card.Effect.None, aChief, null, null); CardsHeap.AddCards(res.Cards); AsynchronousCore.SendMessage( new Beaver("abandonment", aChief.ChiefName, GamePlayers[aChief].Hands.Count, Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("abandonment", // new XElement("target", aChief.ChiefName), // new XElement("count", GamePlayers[aChief].Hands.Count), // Card.Cards2XML("cards", res.Cards) //)); } //若牌数满足上限,弃牌完成 if (GamePlayers[aChief].Hands.Count == GamePlayers[aChief].Health) { return(true); } } //牌数小于限制,跳过弃牌 return(true); }
/// <summary> /// 开始玩家的选将过程,要求玩家数量必须等于游戏模式中指定的数量 /// </summary> /// <returns>若该过程无误,则返回true</returns> public bool SelectChiefs() { if (GamePlayers.All.Count() < 2) { return(false); } foreach (Player p in GamePlayers.All) { p.Chief = null; p.AvailableChiefs = new ChiefBase[0] { }; } //发送游戏环境数据给所有玩家 AsynchronousCore.SendEnvironmentMessage(); int m = 0; int l1 = 0; int l2 = 0; int i1 = 0; int i2 = 0; int i3 = 0; int i4 = 0; int s1 = 0; int s2 = 0; //获取场上玩家数量 int max = GamePlayers.All.Count(); //重置牌堆 CardsHeap = new CardHeap(this); //一个用来放置可选武将的列表 List <ChiefBase> heap = new List <ChiefBase>(); //根据模式设置牌堆里面的牌 switch (Mode) { case GameMode.FiveJunZheng: case GameMode.EightJunZheng: CardsHeap.FillOriginCards(); CardsHeap.FillExCards(); CardsHeap.FillShenCards(); break; case GameMode.FiveSTD: case GameMode.EightSTD: CardsHeap.FillOriginCards(); CardsHeap.FillExCards(); break; } //根据扩展包情况加入武将 heap = ChiefHeap.GetOriginChiefs(); //主公可选武将列表 List <ChiefBase> mLst = new List <ChiefBase>(); mLst.AddRange(heap.Where(c => c.ChiefName == "刘备" || c.ChiefName == "孙权" || c.ChiefName == "曹操")); if (GamePacks.Contains(GamePack.Feng)) { heap.AddRange(ChiefHeap.GetFengPackChiefs()); mLst.AddRange(heap.Where(c => c.ChiefName == "张角")); } if (GamePacks.Contains(GamePack.Huo)) { heap.AddRange(ChiefHeap.GetHuoPackChiefs()); mLst.AddRange(heap.Where(c => c.ChiefName == "袁绍")); } if (GamePacks.Contains(GamePack.Lin)) { heap.AddRange(ChiefHeap.GetLinPackChiefs()); mLst.AddRange(heap.Where(c => c.ChiefName == "董卓")); } //乱序可选武将 heap = ShuffleList <ChiefBase>(heap); //将非主公武将从heap中找到放置到heap2 ChiefBase[] heap2 = heap.Where(c => c.ChiefName != "刘备" && c.ChiefName != "孙权" && c.ChiefName != "曹操" && c.ChiefName != "张角" && c.ChiefName != "袁绍" && c.ChiefName != "董卓").ToArray(); //加入两个非主公武将到主公可选武将列表中 mLst.Add(heap2[0]); mLst.Add(heap2[1]); //把主公可选武将写成XML格式 Beaver r = null; foreach (ChiefBase c in mLst) { if (r == null) { r = new Beaver("chiefs", c.ChiefName); } else { r.Add(string.Empty, c.ChiefName); } } if (r == null) { r = new Beaver("chiefs"); } //表决字典 Dictionary <Player, bool> Abstention = new Dictionary <Player, bool>(); //这个列表用来产生身份序列 List <int> l = null; //按照人数开始配置角色 switch (Mode) { case GameMode.FiveSTD: case GameMode.FiveJunZheng: //五人场人数必须为5 if (GamePlayers.All.Count() != 5) { return(false); } l = new List <int>(new int[] { 0, 1, 2, 3, 4 }); l = ShuffleList <int>(l); m = l[0]; //主 l1 = l[1]; //忠 s1 = l[2]; //内 i1 = l[3]; //反 i2 = l[4]; //反 //给所有玩家群发主公是谁 AsynchronousCore.SendMessage(new Player[] { GamePlayers[m] }, new Beaver("ChiefStatus", ChiefBase.Status.Majesty.ToString(), GamePlayers[m].UID).ToString(), true); //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Majesty), // new XElement("UID", GamePlayers[m].UID) // ), true); //给其他角色发送自己身份是什么 AsynchronousCore.SendMessage(new Player[] { GamePlayers[l1] }, new Beaver("ChiefStatus", ChiefBase.Status.Loyalist.ToString(), GamePlayers[l1].UID).ToString(), false); //new Player[] { GamePlayers[l1] }, //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Loyalist), // new XElement("UID", GamePlayers[l1].UID) // ), false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[s1] }, new Beaver("ChiefStatus", ChiefBase.Status.Spy.ToString(), GamePlayers[s1].UID).ToString(), false); //new Player[] { GamePlayers[s1] }, //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Spy), // new XElement("UID", GamePlayers[s1].UID) // ), false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[i1] }, new Beaver("ChiefStatus", ChiefBase.Status.Insurgent.ToString(), GamePlayers[i1].UID).ToString(), false); //new Player[] { GamePlayers[i1] }, //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Insurgent), // new XElement("UID", GamePlayers[i1].UID) // ), false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[i2] }, new Beaver("ChiefStatus", ChiefBase.Status.Insurgent.ToString(), GamePlayers[i2].UID).ToString(), false); //new Player[] { GamePlayers[i2] }, //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Insurgent), // new XElement("UID", GamePlayers[i2].UID) // ), false); //设置主公可选武将列表 GamePlayers[m].AvailableChiefs = mLst.ToArray(); //通知主公选武将 AsynchronousCore.SendMessage( new Player[] { GamePlayers[m] }, new Beaver("askfor.selectchief", GamePlayers[m].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[m].UID), // r) , false); //通知其他玩家主公正在选武将 AsynchronousCore.SendMessage( GamePlayers.All.Where(c => c.UID != GamePlayers[m].UID).ToArray(), new Beaver("askfor.selectchief", GamePlayers[m].UID).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[m].UID)) , true); //设置表决字典,除了主公玩家置false,其他玩家置true foreach (Player p in GamePlayers.All) { if (GamePlayers[m] == p && !p.IsEscaped && !p.IsOffline) { Abstention.Add(p, false); } else { Abstention.Add(p, true); } } //等待问询结果 AsynchronousCore.AskForChief(Abstention); //主公没选择武将的话,随机配置一个 if (GamePlayers[m].Chief == null) { GamePlayers[m].Chief = mLst[GetRandom(mLst.Count)]; } //设置主公的一些属性 GamePlayers[m].Chief.ChiefStatus = ChiefBase.Status.Majesty; GamePlayers[m].Chief.playersObject = GamePlayers; GamePlayers[m].MaxHealth = GamePlayers[m].Chief.Health; GamePlayers[m].MaxHealth++; GamePlayers[m].Health = GamePlayers[m].MaxHealth; //通知玩家主公选择了谁 AsynchronousCore.SendMessage( new Beaver("selectchief", GamePlayers[m].UID, GamePlayers[m].Chief.ChiefName, GamePlayers[m].MaxHealth.ToString()).ToString()); //new XElement("selectchief", // new XElement("UID", GamePlayers[m].UID), // new XElement("chief_name", GamePlayers[m].Chief.ChiefName), // new XElement("max_health", GamePlayers[m].MaxHealth) // ) //); //heap中去除掉主公选择的武将并重新乱序排列 heap = ShuffleList <ChiefBase>(heap.Where(c => c != GamePlayers[m].Chief).ToList()); //其他玩家每人抽三个武将到自己的可选武将中 GamePlayers[l1].AvailableChiefs = heap.GetRange(0, 3).ToArray(); GamePlayers[s1].AvailableChiefs = heap.GetRange(3, 3).ToArray(); GamePlayers[i1].AvailableChiefs = heap.GetRange(6, 3).ToArray(); GamePlayers[i2].AvailableChiefs = heap.GetRange(9, 3).ToArray(); //重新设置表决字典,除了主公,其他人都置false Abstention = new Dictionary <Player, bool>(); foreach (Player p in GamePlayers.All) { if (GamePlayers[m] == p) { Abstention.Add(p, true); } else { Abstention.Add(p, false); } } //通知非主公玩家去选自己的武将 r = Chiefs2Beaver(l1); AsynchronousCore.SendMessage( new Player[] { GamePlayers[l1] }, new Beaver("askfor.selectchief", GamePlayers[l1].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[l1].UID), // r) , false); r = Chiefs2Beaver(s1); AsynchronousCore.SendMessage( new Player[] { GamePlayers[s1] }, new Beaver("askfor.selectchief", GamePlayers[s1].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[s1].UID), // new XElement("chiefs", // new XElement("chief", GamePlayers[s1].AvailableChiefs[0].ChiefName), // new XElement("chief", GamePlayers[s1].AvailableChiefs[1].ChiefName), // new XElement("chief", GamePlayers[s1].AvailableChiefs[2].ChiefName) // )) , false); r = Chiefs2Beaver(i1); AsynchronousCore.SendMessage( new Player[] { GamePlayers[i1] }, new Beaver("askfor.selectchief", GamePlayers[i1].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[i1].UID), // new XElement("chiefs", // new XElement("chief", GamePlayers[i1].AvailableChiefs[0].ChiefName), // new XElement("chief", GamePlayers[i1].AvailableChiefs[1].ChiefName), // new XElement("chief", GamePlayers[i1].AvailableChiefs[2].ChiefName) // )) , false); r = Chiefs2Beaver(i2); AsynchronousCore.SendMessage( new Player[] { GamePlayers[i2] }, new Beaver("askfor.selectchief", GamePlayers[i2].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[i2].UID), // new XElement("chiefs", // new XElement("chief", GamePlayers[i2].AvailableChiefs[0].ChiefName), // new XElement("chief", GamePlayers[i2].AvailableChiefs[1].ChiefName), // new XElement("chief", GamePlayers[i2].AvailableChiefs[2].ChiefName) // )) , false); //问询玩家选择武将 AsynchronousCore.AskForChief(Abstention); //针对非主公玩家配置数据 foreach (Player p in GamePlayers.All) { p.Score = 0; if (GamePlayers[m] == p) { continue; } if (p.Chief == null) { //没选武将随机配置一个 p.Chief = p.AvailableChiefs[GetRandom(p.AvailableChiefs.Count())]; } p.Chief.playersObject = GamePlayers; p.MaxHealth = p.Chief.Health; p.Health = p.MaxHealth; //通知所有玩家该玩家选择的武将 AsynchronousCore.SendMessage( new Beaver("selectchief", p.UID, p.Chief.ChiefName, p.MaxHealth).ToString() //new XElement("selectchief", // new XElement("UID", p.UID), // new XElement("chief_name", p.Chief.ChiefName), // new XElement("max_health", p.MaxHealth) // ) ); } ////开始分配武将的技能 //foreach (Player p in GamePlayers.All) //{ // //再发送出去 // p.Chief.ReportSkills(gData); //} //设置非主公武将的身份 GamePlayers[l1].Chief.ChiefStatus = Data.ChiefBase.Status.Loyalist; GamePlayers[s1].Chief.ChiefStatus = Data.ChiefBase.Status.Spy; GamePlayers[i1].Chief.ChiefStatus = Data.ChiefBase.Status.Insurgent; GamePlayers[i2].Chief.ChiefStatus = Data.ChiefBase.Status.Insurgent; //事件结束 AsynchronousCore.SendClearMessage(); return(true); case GameMode.EightSTD: case GameMode.EightJunZheng: //玩家人数不为8则不能执行 if (GamePlayers.All.Count() != 8) { return(false); } l = new List <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }); l = ShuffleList <int>(l); m = l[0]; //主 l1 = l[1]; //忠 l2 = l[2]; //忠 s1 = l[3]; //内 i1 = l[4]; //反 i2 = l[5]; //反 i3 = l[6]; //反 i4 = l[7]; //反 //给所有玩家通知主公是谁 AsynchronousCore.SendMessage( new Beaver("ChiefStatus", ChiefBase.Status.Majesty.ToString(), GamePlayers[m].UID).ToString()); //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Majesty), // new XElement("UID", GamePlayers[m].UID) // )); //其他玩家自己收到自己的身份 AsynchronousCore.SendMessage(new Player[] { GamePlayers[l1] }, new Beaver("ChiefStatus", ChiefBase.Status.Loyalist.ToString(), GamePlayers[l1].UID).ToString() //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Loyalist), // new XElement("UID", GamePlayers[l1].UID)) , false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[l2] }, new Beaver("ChiefStatus", ChiefBase.Status.Loyalist.ToString(), GamePlayers[l2].UID).ToString() //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Loyalist), // new XElement("UID", GamePlayers[l2].UID)) , false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[s1] }, new Beaver("ChiefStatus", ChiefBase.Status.Spy.ToString(), GamePlayers[s1].UID).ToString() //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Spy), // new XElement("UID", GamePlayers[s1].UID)) , false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[i1] }, new Beaver("ChiefStatus", ChiefBase.Status.Insurgent.ToString(), GamePlayers[i1].UID).ToString() //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Insurgent), // new XElement("UID", GamePlayers[i1].UID)) , false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[i2] }, new Beaver("ChiefStatus", ChiefBase.Status.Insurgent.ToString(), GamePlayers[i2].UID).ToString() //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Insurgent), // new XElement("UID", GamePlayers[i2].UID)) , false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[i3] }, new Beaver("ChiefStatus", ChiefBase.Status.Insurgent.ToString(), GamePlayers[i3].UID).ToString() //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Insurgent), // new XElement("UID", GamePlayers[i3].UID)) , false); AsynchronousCore.SendMessage(new Player[] { GamePlayers[i4] }, new Beaver("ChiefStatus", ChiefBase.Status.Insurgent.ToString(), GamePlayers[i4].UID).ToString() //new XElement("ChiefStatus", // new XElement("Status", ChiefBase.Status.Insurgent), // new XElement("UID", GamePlayers[i4].UID)) , false); //设置主公可选的武将列表 GamePlayers[m].AvailableChiefs = mLst.ToArray(); //给主公私下发送的选将事件 AsynchronousCore.SendMessage( new Player[] { GamePlayers[m] }, new Beaver("askfor.selectchief", GamePlayers[m].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[m].UID), // r) , false); //给所有非主公玩家通知主公在选将 AsynchronousCore.SendMessage( GamePlayers.All.Where(c => c.UID != GamePlayers[m].UID).ToArray(), new Beaver("askfor.selectchief", GamePlayers[m].UID).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[m].UID)) , true); //设置表决字典,让主公玩家未表决 Abstention = new Dictionary <Player, bool>(); foreach (Player p in GamePlayers.All) { if (GamePlayers[m] == p) { Abstention.Add(p, false); } else { Abstention.Add(p, true); } } //开始问询 AsynchronousCore.AskForChief(Abstention); //没有选将设置随机选择武将 if (GamePlayers[m].Chief == null) { GamePlayers[m].Chief = mLst[GetRandom(mLst.Count)]; } //设置主公玩家的一些属性 GamePlayers[m].Chief.ChiefStatus = ChiefBase.Status.Majesty; GamePlayers[m].Chief.playersObject = GamePlayers; GamePlayers[m].MaxHealth = GamePlayers[m].Chief.Health; GamePlayers[m].MaxHealth++; GamePlayers[m].Health = GamePlayers[m].MaxHealth; //通知玩家主公选择了什么以及血量 AsynchronousCore.SendMessage( new Beaver("selectchief", GamePlayers[m].UID, GamePlayers[m].Chief.ChiefName, GamePlayers[m].MaxHealth.ToString()).ToString()); //new XElement("selectchief", // new XElement("UID", GamePlayers[m].UID), // new XElement("chief_name", GamePlayers[m].Chief.ChiefName), // new XElement("max_health", GamePlayers[m].MaxHealth) // ) //); //武将堆排除掉主公选择的武将之后重新排序 heap = ShuffleList <ChiefBase>(heap.Where(c => c != GamePlayers[m].Chief).ToList()); //其他玩家从heap抽3个武将作为可选武将 GamePlayers[l1].AvailableChiefs = heap.GetRange(0, 3).ToArray(); GamePlayers[l2].AvailableChiefs = heap.GetRange(3, 3).ToArray(); GamePlayers[s1].AvailableChiefs = heap.GetRange(6, 3).ToArray(); GamePlayers[i1].AvailableChiefs = heap.GetRange(9, 3).ToArray(); GamePlayers[i2].AvailableChiefs = heap.GetRange(12, 3).ToArray(); GamePlayers[i3].AvailableChiefs = heap.GetRange(15, 3).ToArray(); GamePlayers[i4].AvailableChiefs = heap.GetRange(18, 3).ToArray(); //设置表决字典,让非主公玩家选将 Abstention = new Dictionary <Player, bool>(); foreach (Player p in GamePlayers.All) { if (GamePlayers[m] == p) { Abstention.Add(p, true); } else { Abstention.Add(p, false); } } AsynchronousCore.SendMessage( new Beaver("askfor.selectchief").ToString()); //new XElement("askfor.selectchief") //); r = Chiefs2Beaver(l1); AsynchronousCore.SendMessage( new Player[] { GamePlayers[l1] }, new Beaver("askfor.selectchief", GamePlayers[l1].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[l1].UID), // r) , false); r = Chiefs2Beaver(l2); AsynchronousCore.SendMessage( new Player[] { GamePlayers[l2] }, new Beaver("askfor.selectchief", GamePlayers[l2].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[l2].UID), // r) , false); r = Chiefs2Beaver(s1); AsynchronousCore.SendMessage( new Player[] { GamePlayers[s1] }, new Beaver("askfor.selectchief", GamePlayers[s1].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[s1].UID), // r) , false); r = Chiefs2Beaver(i1); AsynchronousCore.SendMessage( new Player[] { GamePlayers[i1] }, new Beaver("askfor.selectchief", GamePlayers[i1].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[i1].UID), // r) , false); r = Chiefs2Beaver(i2); AsynchronousCore.SendMessage( new Player[] { GamePlayers[i2] }, new Beaver("askfor.selectchief", GamePlayers[i2].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[i2].UID), // r) , false); r = Chiefs2Beaver(i3); AsynchronousCore.SendMessage( new Player[] { GamePlayers[i3] }, new Beaver("askfor.selectchief", GamePlayers[i3].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[i3].UID), // r) , false); r = Chiefs2Beaver(i4); AsynchronousCore.SendMessage( new Player[] { GamePlayers[i4] }, new Beaver("askfor.selectchief", GamePlayers[i4].UID, r).ToString() //new XElement("askfor.selectchief", // new XElement("UID", GamePlayers[i4].UID), // r) , false); AsynchronousCore.AskForChief(Abstention); foreach (Player p in GamePlayers.All) { p.Score = 0; if (GamePlayers[m] == p) { continue; } if (p.Chief == null) { p.Chief = p.AvailableChiefs[GetRandom(p.AvailableChiefs.Count())]; } p.Chief.playersObject = GamePlayers; p.MaxHealth = p.Chief.Health; p.Health = p.MaxHealth; p.Dead = false; AsynchronousCore.SendMessage( new Beaver("selectchief", p.UID, p.Chief.ChiefName, p.MaxHealth.ToString()).ToString()); //new XElement("selectchief", // new XElement("UID", p.UID), // new XElement("chief_name", p.Chief.ChiefName), // new XElement("max_health", p.MaxHealth) // ) //); } ////开始分配武将的技能 //foreach (Player p in GamePlayers.All) //{ // //再发送出去 // p.Chief.ReportSkills(gData); //} GamePlayers[l1].Chief.ChiefStatus = Data.ChiefBase.Status.Loyalist; GamePlayers[l2].Chief.ChiefStatus = ChiefBase.Status.Loyalist; GamePlayers[s1].Chief.ChiefStatus = Data.ChiefBase.Status.Spy; GamePlayers[i1].Chief.ChiefStatus = Data.ChiefBase.Status.Insurgent; GamePlayers[i2].Chief.ChiefStatus = Data.ChiefBase.Status.Insurgent; GamePlayers[i3].Chief.ChiefStatus = Data.ChiefBase.Status.Insurgent; GamePlayers[i4].Chief.ChiefStatus = Data.ChiefBase.Status.Insurgent; AsynchronousCore.SendClearMessage(); return(true); } return(false); }
/// <summary> /// 玩家出牌阶段的处理方法 /// </summary> /// <param name="aResult">问询玩家产生的结果</param> /// <returns>如果出牌合法,那么将返回true</returns> protected bool LeadEvent(MessageCore.AskForResult aResult) { //对参数的检查 if (aResult == null) { return(false); //参数不可以是null } if (aResult.Leader == null) { return(false); //问询回应者不能是null } if (aResult.Targets == null) { return(false); //问询目标数组不能是null,但可以是空数组 } if (aResult.Cards == null) { return(false); //问询的出牌数组不能是null,但可以是空数组 } foreach (ChiefBase c in aResult.Targets) //每个目标对象不能是null { if (c == null) { return(false); } } foreach (Card c in aResult.Cards) //每个牌对象不能是null { if (c == null) { return(false); } } //出牌无效 if (!CheckValid(aResult, aResult.Leader)) { return(false); } //将结果安置在这些临时变量中 ChiefBase aChiefSource = aResult.Leader; ChiefBase[] aChiefTarget = aResult.Targets; Card[] aCards = aResult.Cards; Card.Effect aEffect = aResult.Effect; //清除 打牌列表 FreeCardBin(); //清除事件队列 queRecoard.Clear(); //清除子事件队列 lstRecoard.Clear(); //根据牌的效果确定游戏玩法 //并将事件安置到子事件队列 switch (aEffect) { //技能处理过的回应,那这里就不处理他了 case Card.Effect.Skill: DropCards(true, CardFrom.Slot, string.Empty, CardsBuffer[WGFDSlotName].Cards.ToArray(), Card.Effect.None, null, null, null); CardsBuffer[WGFDSlotName].Cards.Clear(); //释放打牌列表,将这些牌放进弃牌堆 FreeCardBin(); //清除事件队列 queRecoard.Clear(); //清除子事件队列 lstRecoard.Clear(); return(true); //出杀 case Card.Effect.Sha: //若出杀有限制且已经没有机会杀了不能执行 if (!gData.ShaNoLimit && gData.KillRemain < 1) { goto FAILED; } //if (GamePlayers[aChiefSource].Weapon != null) // Weapon.ModifyProperty(GamePlayers[aChiefSource].Weapon.CardEffect, aCards, aChiefSource, aChiefTarget, MessageCore.AskForEnum.Aggressive, Card.Effect.Sha, gData); //杀的目标数量高于最大值不能执行 if (CalcMaxShaTargets(aChiefSource, aCards) < aChiefTarget.Count()) { goto FAILED; } //没有目标不能执行 if (aChiefTarget.Count() == 0) { goto FAILED; } //遍历目标集合,如果目标有自己或者目标已死亡或者 够不到对方不能执行 foreach (ChiefBase c in aChiefTarget) { if (c.IsMe(aChiefSource) || GamePlayers[c].Dead || !WithinShaRange(aChiefSource, c)) { goto FAILED; } bool Enable = true; foreach (ASkill s in c.Skills) { Enable = s.EffectFeasible(aCards, aEffect, c, Enable, gData); } if (!Enable) { goto FAILED; } } //如果有重复的目标也不能执行 if (aChiefTarget.Distinct().Count() != aChiefTarget.Count()) { goto FAILED; } //设置杀计数器 if (gData.KillRemain < 2) { gData.KillRemain = 0; } else { --gData.KillRemain; } //将杀事件按目标分解成一个个小事件,并装进子事件队列 //即每个子事件都是玩家杀单独的玩家的处理事件 foreach (ChiefBase c in aChiefTarget) { queRecoard.Enqueue(new EventRecoard(aChiefSource, c, aCards, aEffect, aResult.SkillName)); } //发送消息 if (aResult.PlayerLead) { AsynchronousCore.SendMessage( new Beaver("sha", aChiefSource.ChiefName, ChiefBase.Chiefs2Beaver("to", aChiefTarget), aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); } //new XElement("sha", // new XElement("from", aChiefSource.ChiefName), // ChiefBase.Chiefs2XML("to", aChiefTarget), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) // ); //通知武将技能 玩家使用了杀效果 foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //决斗 case Card.Effect.JueDou: if (aChiefTarget.Count() == 1) { //目标不能是自己 if (aChiefTarget[0].IsMe(aChiefSource)) { goto FAILED; } //对方不能死亡 if (GamePlayers[aChiefTarget[0]].Dead) { goto FAILED; } bool Enable = true; foreach (ASkill s in aChiefTarget[0].Skills) { Enable = s.EffectFeasible(aCards, aEffect, aChiefTarget[0], Enable, gData); } if (!Enable) { goto FAILED; } //安置到事件子队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefTarget[0], aCards, aEffect, aResult.SkillName)); //发送消息 AsynchronousCore.SendMessage( new Beaver("jd", aChiefSource.ChiefName, aChiefTarget[0].ChiefName, aResult.SkillName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("jd", // new XElement("from", aChiefSource.ChiefName), // new XElement("to", aChiefTarget[0].ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); //通知武将技能 玩家使用了效果 foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } } else if (aChiefTarget.Count() == 2) { if (aChiefTarget[0] == aChiefTarget[1]) { goto FAILED; } if (GamePlayers[aChiefTarget[0]].Dead || GamePlayers[aChiefTarget[1]].Dead) { goto FAILED; } bool Enable = true; foreach (ASkill s in aChiefTarget[1].Skills) { Enable = s.EffectFeasible(aCards, aEffect, aChiefTarget[1], Enable, gData); } if (!Enable) { goto FAILED; } //安置到事件子队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefTarget[0], aChiefTarget[1], aCards, aEffect, aResult.SkillName)); //发送消息 AsynchronousCore.SendMessage( new Beaver("jd", aChiefTarget[0].ChiefName, aChiefTarget[1].ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("jd", // new XElement("from", aChiefTarget[0].ChiefName), // new XElement("to", aChiefTarget[1].ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); } else { goto FAILED; } break; //桃 case Card.Effect.Tao: //血量不能大于等于体力上限 if (GamePlayers[aChiefSource].Health == GamePlayers[aChiefSource].MaxHealth) { goto FAILED; } //安置到事件子队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefSource, aCards, aEffect, aResult.SkillName)); //发送消息 AsynchronousCore.SendMessage( new Beaver("tao", aChiefSource.ChiefName, aChiefSource.ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); // new XElement("tao", // new XElement("from", aChiefSource.ChiefName), // new XElement("to", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); //通知武将技能 玩家使用了效果 foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //南蛮入侵 case Card.Effect.NanManRuQin: //下面是把出牌玩家以后的其他玩家依次装入子事件列表中 ChiefBase t = GamePlayers.NextChief(aChiefSource); while (!t.IsMe(aChiefSource)) { queRecoard.Enqueue(new EventRecoard(aChiefSource, t, aCards, aEffect, aResult.SkillName)); t = GamePlayers.NextChief(t); } AsynchronousCore.SendMessage( new Beaver("nmrq", aChiefSource.ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("nmrq", // new XElement("from", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //万箭齐发 case Card.Effect.WanJianQiFa: //下面是把出牌玩家以后的其他玩家依次装入子事件列表中 ChiefBase t2 = GamePlayers.NextChief(aChiefSource); while (!t2.IsMe(aChiefSource)) { queRecoard.Enqueue(new EventRecoard(aChiefSource, t2, aCards, aEffect, aResult.SkillName)); t2 = GamePlayers.NextChief(t2); } AsynchronousCore.SendMessage( new Beaver("wjqf", aChiefSource.ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("wjqf", // new XElement("from", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //桃园结义 case Card.Effect.TaoYuanJieYi: //下面是把从出牌玩家开始的所有玩家依次装入子事件列表中 ChiefBase t3 = aChiefSource; do { if (GamePlayers[t3].Health < GamePlayers[t3].MaxHealth) { queRecoard.Enqueue(new EventRecoard(aChiefSource, t3, aCards, aEffect, aResult.SkillName)); } t3 = GamePlayers.NextChief(t3); } while (!t3.IsMe(aChiefSource)); AsynchronousCore.SendMessage( new Beaver("tyjy", aChiefSource.ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("tyjy", // new XElement("from", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) // ); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //无中生有 case Card.Effect.WuZhongShengYou: //添加进子事件队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefSource, aCards, aEffect, aResult.SkillName)); AsynchronousCore.SendMessage( new Beaver("wzsy", aChiefSource.ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("wzsy", // new XElement("from", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //过河拆桥 case Card.Effect.GuoHeChaiQiao: //必须有目标 if (aChiefTarget.Count() != 1) { goto FAILED; } //目标不能是自己 if (aChiefTarget[0].IsMe(aChiefSource)) { goto FAILED; } //对方不能死亡 if (GamePlayers[aChiefTarget[0]].Dead) { goto FAILED; } //对方要有牌 if (!GamePlayers[aChiefTarget[0]].HasCardWithJudgementArea) { goto FAILED; } //添加进子事件队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefTarget[0], aCards, aEffect, aResult.SkillName)); AsynchronousCore.SendMessage( new Beaver("ghcq", aChiefSource.ChiefName, aChiefTarget[0].ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("ghcq", // new XElement("from", aChiefSource.ChiefName), // new XElement("to", aChiefTarget[0].ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; case Card.Effect.ShunShouQianYang: //必须有目标 if (aChiefTarget.Count() != 1) { goto FAILED; } //目标不能是自己 if (aChiefTarget[0].IsMe(aChiefSource)) { goto FAILED; } //对方不能死亡 if (GamePlayers[aChiefTarget[0]].Dead) { goto FAILED; } //对方要有牌 if (!GamePlayers[aChiefTarget[0]].HasCardWithJudgementArea) { goto FAILED; } //可以够到对方 if (!WithinKitRange(aChiefSource, aChiefTarget[0])) { goto FAILED; } //添加进子事件队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefTarget[0], aCards, aEffect, aResult.SkillName)); AsynchronousCore.SendMessage( new Beaver("sspy", aChiefSource.ChiefName, aChiefTarget[0].ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("ssqy", // new XElement("from", aChiefSource.ChiefName), // new XElement("to", aChiefTarget[0].ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //借刀杀人 case Card.Effect.JieDaoShaRen: //必须有两个目标 if (aChiefTarget.Count() != 2) { goto FAILED; } //第一个目标不能是自己 if (aChiefTarget[0].IsMe(aChiefSource)) { goto FAILED; } //第一个目标不能死亡 if (GamePlayers[aChiefTarget[0]].Dead) { goto FAILED; } //第二个目标不能死亡 if (GamePlayers[aChiefTarget[1]].Dead) { goto FAILED; } //两个目标不能一样 if (aChiefTarget[0].IsMe(aChiefTarget[1])) { goto FAILED; } //必须能能够到对方 if (!WithinShaRange(aChiefTarget[0], aChiefTarget[1])) { goto FAILED; } //添加进子事件队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefTarget[0], aChiefTarget[1], aCards, aEffect, aResult.SkillName)); AsynchronousCore.SendMessage( new Beaver("jdsr", aChiefSource.ChiefName, aChiefTarget[0].ChiefName, aChiefTarget[1].ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("jdsr", // new XElement("from", aChiefSource.ChiefName), // new XElement("to", aChiefTarget[0].ChiefName), // new XElement("to2", aChiefTarget[1].ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //乐不思蜀 case Card.Effect.LeBuSiShu: //必须有目标且目标不能使自己且目标不能死亡 if (aChiefTarget.Count() != 1 || aChiefTarget[0] == aChiefSource || GamePlayers[aChiefTarget[0]].Dead) { goto FAILED; } //目标不能有乐不思蜀buff if (GamePlayers[aChiefTarget[0]].HasDebuff(Card.Effect.LeBuSiShu)) { goto FAILED; } //添加进子事件队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefTarget[0], aCards, aEffect, aResult.SkillName)); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //闪电 case Card.Effect.ShanDian: //玩家不能死亡 if (GamePlayers[aChiefSource].Dead) { goto FAILED; } //玩家不能有闪电buff if (GamePlayers[aChiefSource].HasDebuff(Card.Effect.ShanDian)) { goto FAILED; } //添加进子事件队列 queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefSource, aCards, aEffect, aResult.SkillName)); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //五谷丰登 case Card.Effect.WuGuFengDeng: ChiefBase t4 = aChiefSource; do { queRecoard.Enqueue(new EventRecoard(aChiefSource, t4, aCards, aEffect, aResult.SkillName)); t4 = GamePlayers.NextChief(t4); } while (!t4.IsMe(aChiefSource)); //List<Card> lstWGFD = CardsHeap.Pop(GamePlayers.PeoplealiveCount).ToList(); //lstWGFDBuff = lstWGFD; CardsBuffer[WGFDSlotName].Cards.Clear(); CardsBuffer[WGFDSlotName].Cards.AddRange(CardsHeap.Pop(GamePlayers.PeoplealiveCount)); AsynchronousCore.SendMessage( new Beaver("wgfd", aChiefSource.ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", CardsBuffer[WGFDSlotName].Cards.ToArray())).ToString()); //new XElement("wgfd", //new XElement("from", aChiefSource.ChiefName), //new XElement("skill", aResult.SkillName), //Card.Cards2XML("cards", CardsBuffer[WGFDSlotName].Cards.ToArray()))); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //八卦阵 case Card.Effect.BaGuaZhen: //藤甲 case Card.Effect.TengJia: //仁王盾 case Card.Effect.RenWangDun: //白银狮子 case Card.Effect.BaiYinShiZi: queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefSource, aCards, aEffect, aResult.SkillName)); AsynchronousCore.SendMessage( new Beaver("armor", aChiefSource.ChiefName, aResult.SkillName, Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("armor", // new XElement("from", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; //武器 case Card.Effect.ZhangBaSheMao: case Card.Effect.ZhuGeLianNu: case Card.Effect.GuDianDao: case Card.Effect.QiLinGong: case Card.Effect.GuanShiFu: case Card.Effect.QingLongYanYueDao: case Card.Effect.QingGangJian: case Card.Effect.CiXiongShuangGuJian: case Card.Effect.ZhuQueYuShan: case Card.Effect.FangTianHuaJi: queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefSource, aCards, aEffect, aResult.SkillName)); AsynchronousCore.SendMessage( new Beaver("weapon", aChiefSource.ChiefName, aResult.SkillName, aResult.Effect.ToString(), Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("weapon", // new XElement("from", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // new XElement("effect", aResult.Effect), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; case Card.Effect.Jia1: case Card.Effect.Jian1: queRecoard.Enqueue(new EventRecoard(aChiefSource, aChiefSource, aCards, aEffect, aResult.SkillName)); AsynchronousCore.SendMessage( new Beaver("horse", aChiefSource.ChiefName, aResult.SkillName, aResult.Effect.ToString(), Card.Cards2Beaver("cards", aCards)).ToString()); //new XElement("horse", // new XElement("from", aChiefSource.ChiefName), // new XElement("skill", aResult.SkillName), // new XElement("effect", aResult.Effect), // Card.Cards2XML("cards", aCards) // ) //); foreach (ASkill s in aChiefSource.Skills) { s.OnUseEffect(aChiefSource, aEffect, gData); } break; default: return(false); } if (aResult.PlayerLead) { if (!RemoveHand(aChiefSource, aCards)) { goto FAILED; } } AsynchronousCore.LeadingValid(aChiefSource); //将牌放入 打牌列表 if (aResult.PlayerLead) { lstCardBin.AddRange(aCards); } //处理子事件 while (queRecoard.Count != 0) { EventProc(); //清除子事件节点 lstRecoard.Clear(); } //删除五谷丰登牌堆中的牌 DropCards(true, CardFrom.Slot, string.Empty, CardsBuffer[WGFDSlotName].Cards.ToArray(), Card.Effect.None, null, null, null); CardsBuffer[WGFDSlotName].Cards.Clear(); //释放打牌列表,将这些牌放进弃牌堆 FreeCardBin(); //清除事件队列 queRecoard.Clear(); //清除子事件队列 lstRecoard.Clear(); //执行成功 return(true); FAILED: AsynchronousCore.LeadingInvalid(aChiefSource); DropCards(true, CardFrom.Slot, string.Empty, CardsBuffer[WGFDSlotName].Cards.ToArray(), Card.Effect.None, null, null, null); CardsBuffer[WGFDSlotName].Cards.Clear(); //释放打牌列表,将这些牌放进弃牌堆 FreeCardBin(); //清除事件队列 queRecoard.Clear(); //清除子事件队列 lstRecoard.Clear(); //执行成功 return(false); }
/// <summary> /// 角色求救过程 /// </summary> /// <param name="aChiefSource">伤害的来源,可以是null</param> /// <param name="aPreDefunct">求救武将</param> /// <param name="aRescuePoint">求救血量</param> /// <returns>返回true表示该角色求救失败,false表示求救成功</returns> private bool Cry4HelpProc(ChiefBase aChiefSource, ChiefBase aPreDefunct, sbyte aRescuePoint) { if (aPreDefunct == null || aRescuePoint < 1) { return(true); } ChiefBase start = aChiefSource != null ? aChiefSource : aPreDefunct; ChiefBase t = start; string msg = null; do { MessageCore.AskForResult res = null; if (t == aPreDefunct) { msg = new Beaver("askfor.cry4help.taoorjiu", t.ChiefName, aPreDefunct.ChiefName, aRescuePoint.ToString()).ToString(); //new XElement("askfor.cry4help.taoorjiu", // new XElement("target", t.ChiefName), // new XElement("target2", aPreDefunct.ChiefName), // new XElement("rescuepoint", aRescuePoint) //); res = AsynchronousCore.AskForCards(t, MessageCore.AskForEnum.AskForTaoOrJiu, new AskForWrapper(msg, this), gData); AsynchronousCore.LeadingValid(t); } else { msg = new Beaver("askfor.cry4help.tao", t.ChiefName, aPreDefunct.ChiefName, aRescuePoint.ToString()).ToString(); //new XElement("askfor.cry4help.tao", // new XElement("target", t.ChiefName), // new XElement("target2", aPreDefunct.ChiefName), // new XElement("rescuepoint", aRescuePoint) //); res = AsynchronousCore.AskForCards(t, MessageCore.AskForEnum.AskForTao, new AskForWrapper(msg, this), gData); AsynchronousCore.LeadingValid(t); } ValidityResult(t, ref res); if (res.Effect != Card.Effect.None) { if (res.Effect == Card.Effect.Tao) { AsynchronousCore.SendMessage( new Beaver("tao", t.ChiefName, aChiefSource.ChiefName, res.SkillName, Card.Cards2Beaver("cards", res.Cards)).ToString()); // new XElement("tao", // new XElement("from", t.ChiefName), // new XElement("to", aChiefSource.ChiefName), // new XElement("skill" , res.SkillName ), // Card.Cards2XML("cards", res.Cards) // ) //); } else if (res.Effect == Card.Effect.Jiu) { AsynchronousCore.SendMessage(new Beaver("jiu", t.ChiefName, res.SkillName, Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("jiu", // new XElement("from", t.ChiefName), // new XElement("skill", res.SkillName), // Card.Cards2XML("cards", res.Cards) //) //); } if (res.Effect == Card.Effect.Tao || res.Effect == Card.Effect.Jiu) { sbyte cost = 1; foreach (ASkill s in aPreDefunct.Skills) { cost = s.CalcRescuePoint(aPreDefunct, res.Leader, res.Effect, cost, gData); } aRescuePoint -= cost; if (res.PlayerLead) { DropCards(true, CardFrom.HandAndEquipage, res.SkillName, res.Cards, res.Effect, t, aPreDefunct, null); } if (aRescuePoint < 1) { break; } continue; } } t = GamePlayers.NextChief(t); } while (!t.IsMe(start)); --aRescuePoint; if (aRescuePoint < 0) { GamePlayers[aPreDefunct].Health = Math.Abs(aRescuePoint); AsynchronousCore.SendMessage(new Beaver("health", aPreDefunct.ChiefName, GamePlayers[aPreDefunct].MaxHealth.ToString(), GamePlayers[aPreDefunct].Health.ToString()).ToString()); //new XElement("health", // new XElement("target", aPreDefunct.ChiefName), // new XElement("max", GamePlayers[aPreDefunct].MaxHealth), // new XElement("current", GamePlayers[aPreDefunct].Health) // )); } else { GamePlayers[aPreDefunct].Health = 0; } return(aRescuePoint < 0 ? false : true); }
/// <summary> /// 要求武将消耗体力值 /// </summary> /// <param name="aChief">受伤害的武将</param> /// <param name="aDamage">伤害量</param> /// <param name="aSource">伤害来源,非玩家操作置null</param> /// <param name="aSourceEvent">伤害来源事件</param> internal void DamageHealth(ChiefBase aChief, sbyte aDamage, ChiefBase aSource, EventRecoard aSourceEvent) { if (GamePlayers[aChief].Health - aDamage < 1) { AsynchronousCore.SendMessage( new Beaver("health", aChief.ChiefName, GamePlayers[aChief].MaxHealth.ToString(), "0").ToString()); //new XElement("health", //new XElement("target", aChief.ChiefName), //new XElement("max", GamePlayers[aChief].MaxHealth), //new XElement("current", 0) //)); if (Cry4HelpProc(aSource, aChief, (sbyte)Math.Abs(GamePlayers[aChief].Health - aDamage - 1))) { //GamePlayers[aChief].Health = 0; GamePlayers[aChief].Dead = true; //drop all cards List <Card> lstDrop = new List <Card>(); lstDrop.AddRange(GamePlayers[aChief].Hands); lstDrop.AddRange(GamePlayers[aChief].Debuff); if (GamePlayers[aChief].Weapon != null) { lstDrop.Add(GamePlayers[aChief].Weapon); } if (GamePlayers[aChief].Armor != null) { lstDrop.Add(GamePlayers[aChief].Armor); } if (GamePlayers[aChief].Jia1Ma != null) { lstDrop.Add(GamePlayers[aChief].Jia1Ma); } if (GamePlayers[aChief].Jian1Ma != null) { lstDrop.Add(GamePlayers[aChief].Jian1Ma); } AsynchronousCore.SendMessage( new Beaver("fall", aChief.ChiefName, aChief.ChiefStatus).ToString()); //new XElement("fall", // new XElement("target", aChief.ChiefName), // new XElement("status", aChief.ChiefStatus) // ) //); AsynchronousCore.SendMessage(MessageCore.MakeDropMessage(aChief, aChief, lstDrop.ToArray())); DropCards(true, CardFrom.HandAndEquipageAndJudgement, string.Empty, lstDrop.ToArray(), Card.Effect.None, aChief, null, null); RefereeProc(); if (aChief.ChiefStatus == ChiefBase.Status.Insurgent && aSource != null && !GamePlayers[aSource].Dead) { TakeingCards(aSource, 3); } return; } } else { AsynchronousCore.SendMessage(new Beaver("health", aChief.ChiefName, GamePlayers[aChief].MaxHealth.ToString(), (GamePlayers[aChief].Health - aDamage).ToString()).ToString()); //new XElement("health", //new XElement("target", aChief.ChiefName), //new XElement("max", GamePlayers[aChief].MaxHealth), //new XElement("current", GamePlayers[aChief].Health - aDamage) //)); GamePlayers[aChief].Health -= aDamage; } foreach (ASkill s in GamePlayers[aChief].Chief.Skills) { s.OnChiefHarmed(aSourceEvent, aSource, aChief, gData, aDamage); } }
/// <summary> /// 杀的过程 /// </summary> /// <param name="r"></param> /// <returns></returns> internal EventRecoard ShaProc(EventRecoard r) { foreach (ASkill s in r.Target.Skills) { s.PreprocessingSubEvent(r.Target, ref r, gData); } //这里再检查一次玩家是否死亡是怕玩家在以前的子事件中挂掉了,如果真挂了就忽略掉这次事件 if (!GamePlayers[r.Target].Dead) { if (GamePlayers[r.Source].Weapon != null) { Weapon.Lead(GamePlayers[r.Source].Weapon.CardEffect, r.Effect, r.Cards, gData, r.Source, r.Target); } if (GamePlayers[r.Target].Armor == null || (GamePlayers[r.Source].Weapon != null && Weapon.EnableTargetArmorWithMessage(GamePlayers[r.Source].Weapon.CardEffect, r.Source, r.Target, gData) && Armor.EnableFor(GamePlayers[r.Target].Armor.CardEffect, r.Cards, Card.Effect.Sha, r.Target)) || !(GamePlayers[r.Source].Weapon != null && Weapon.EnableTargetArmor(GamePlayers[r.Source].Weapon.CardEffect, r.Source, r.Target))) { MessageCore.AskForResult res = null; bool EnableDamage = false; int times = 1; foreach (ASkill s in r.Source.Skills) { times = s.CalcAskforTimes(r.Source, r.Target, Card.Effect.Sha, times, gData); } for (int i = 0; i < times; i++) { res = null; EnableDamage = false; string msg = new Beaver("askfor.sha.shan", r.Target.ChiefName, r.Source.ChiefName).ToString(); //new XElement("askfor.sha.shan", // new XElement("target", r.Target.ChiefName), // new XElement("source", r.Source.ChiefName) // ); if (GamePlayers[r.Target].Armor != null && (GamePlayers[r.Source].Weapon == null || Weapon.EnableTargetArmor(GamePlayers[r.Source].Weapon.CardEffect, r.Source, r.Target))) { //问询 闪 res = AsynchronousCore.AskForCards(r.Target, MessageCore.AskForEnum.Shan, new AskForWrapper(msg, this), gData); } else { //问询 闪 res = AsynchronousCore.AskForCards(r.Target, MessageCore.AskForEnum.Shan, new AskForWrapper(msg, this), false, gData); } //检验出牌合法性 ValidityResult(r.Target, ref res); //问询结果放入子事件处理列表 if (res.PlayerLead) { DropCards(true, CardFrom.Hand, res.SkillName, res.Cards, res.Effect, res.Leader, r.Source, null); } else { DropCards(false, CardFrom.None, res.SkillName, res.Cards, res.Effect, res.Leader, r.Source, null); } if (res.Effect == Card.Effect.Shan) { if (res.PlayerLead) { AsynchronousCore.LeadingValid(r.Target); AsynchronousCore.SendMessage( new Beaver("sha.shan", r.Target.ChiefName, r.Source.ChiefName, res.SkillName, Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("sha.shan", // new XElement("from", r.Target.ChiefName), // new XElement("to", r.Source.ChiefName), // new XElement("skill", res.SkillName), // Card.Cards2XML("cards", res.Cards) // ) //); } foreach (ASkill s in res.Leader.Skills) { s.OnUseEffect(res.Leader, Card.Effect.Shan, gData); } if (GamePlayers[r.Source].Weapon != null) { EnableDamage = Weapon.TargetShan(GamePlayers[r.Source].Weapon.CardEffect, r.Source, r.Target, gData, r); } } if (res.Effect == Card.Effect.None || EnableDamage) { break; } } if (res == null || res.Effect == Card.Effect.None || EnableDamage) { sbyte cost = 1; if (GamePlayers[r.Source].Weapon != null) { cost = Weapon.CalcDamage(GamePlayers[r.Source].Weapon.CardEffect, r.Source, r.Target, Card.Effect.Sha, cost, gData); } foreach (ASkill s in r.Source.Skills) { cost = s.CalcDamage(r.Source, r.Effect, cost, gData); } if (GamePlayers[r.Target].Armor != null && GamePlayers[r.Source].Weapon != null && Weapon.EnableTargetArmor(GamePlayers[r.Source].Weapon.CardEffect, r.Source, r.Target)) { cost = Armor.CalcDamage(1, r.Cards, GamePlayers[r.Target].Armor.CardEffect); } DamageHealth(r.Target, cost, r.Source, r); } } } return(r); }
/// <summary> /// 开启逻辑循环 /// </summary> /// <param name="aChiefStart">设置首个进入回合的武将</param> /// <param name="aIgnoreTakeCards">是否忽略一开始对玩家每人发4张牌的过程</param> protected void LogicLoop(ChiefBase aChiefStart, bool aIgnoreTakeCards) { AsynchronousCore.SendEnvironmentMessage(); ChiefBase target = aChiefStart; //target , 问询的目标 ChiefBase loop = aChiefStart; do { foreach (ASkill s in loop.Skills) { s.OnCreate(loop); } loop.ReportSkills(gData); loop = loop.Next; } while (loop != target); if (!aIgnoreTakeCards) { loop = aChiefStart; //轮询给每个武将4张牌 do { TakeingCards(loop, 4); loop = loop.Next; } while (loop != target); } RefereeProc(); //游戏的轮询 do { //复位游戏规则控制数据 gData = new GlobalData(); gData.Game = this; //设置执行回合的武将 gData.Active = target; //若武将有武器,尝试让该武将的武器配置玩家的某些进攻性属性 if (GamePlayers[target].Weapon != null) { Weapon.ActiveWeapon(GamePlayers[target].Weapon.CardEffect, gData); } //改变武将状态-回合开始 AsynchronousCore.SendChangeStatusMessage(target, MessageCore.PlayerStatus.Start); { gData.ChiefStatus = "turnStart"; //通知该武将的技能该武将进入回合开始阶段 foreach (ASkill s in target.Skills) { s.BeforeTurnStart(target, gData); } //事件结束 ClearEventProc(); } //改变武将状态-判定 AsynchronousCore.SendChangeStatusMessage(target, MessageCore.PlayerStatus.Judgment); { gData.ChiefStatus = "judgment"; //执行武将判定区的判定 Judgement(target, gData); //事件结束 ClearEventProc(); } foreach (ASkill s in target.Skills) { s.BeforeTakeCards(target, gData); } if (gData.Take) { //改变武将状态-拿牌 AsynchronousCore.SendChangeStatusMessage(target, MessageCore.PlayerStatus.Take); { gData.ChiefStatus = "take"; foreach (ASkill s in target.Skills) { s.TakingCards(target, gData); } //从牌堆取 gData.TakeCardsCount 张牌 Card[] ret = TakeingCards(target, gData.TakeCardsCount); //事件结束 ClearEventProc(); } } //武将状态-出牌 //要求 允许出牌且玩家未死亡 if (gData.Lead && !GamePlayers[target].Dead) { //改变武将状态-出牌 AsynchronousCore.SendChangeStatusMessage(target, MessageCore.PlayerStatus.Lead); gData.ChiefStatus = "lead"; foreach (ASkill s in target.Skills) { s.Leading(target, gData); } //这里是一个循环,不断问询玩家出牌,若玩家Effect为None,就跳过这个阶段 while (!GamePlayers[target].Dead) { //重置全局数据中的活动部分 gData.Reset(); string msg = new Beaver("askfor.aggressive", target.ChiefName).ToString(); //new XElement("askfor.aggressive", // new XElement("target", target.ChiefName) //); //开始问询 MessageCore.AskForResult res = AsynchronousCore.AskForCards(target, MessageCore.AskForEnum.Aggressive, new AskForWrapper(msg, this), gData); //是否跳过该阶段 if (res.Effect == Card.Effect.None) { AsynchronousCore.SendClearMessage(); break; } //出牌进行处理,并反馈是否符合规则 if (!LeadEvent(res)) { ClearEventProc(); break; } else { ClearEventProc(); } } } //在进入弃牌阶段前,通知武将的技能 foreach (ASkill s in target.Skills) { s.BeforeAbandonment(target, gData); } //允许武将进入弃牌阶段 if (gData.Abandonment) { //改变武将状态-弃牌 AsynchronousCore.SendChangeStatusMessage(target, MessageCore.PlayerStatus.Abandoment); { gData.ChiefStatus = "abandoment"; //玩家弃牌的问询 if (!Abandonment(target)) { AsynchronousCore.LeadingInvalid(target); } else { AsynchronousCore.LeadingValid(target); } ClearEventProc(); } } //玩家回合结束前通知武将的技能 foreach (ASkill s in target.Skills) { s.AfterTurnEnd(target, gData); } //牌检查器报告情况 AsynchronousCore.SendMessage(CardsHeap.CardsChecker(this)); } while ((target = target.Next) != null); //target=下一个玩家 //----------------------------------------------------------- //如果玩家都死光了...没分胜负,我想这里会有异常吧 }
/// <summary> /// 无懈可击子事件 /// </summary> /// <param name="aTarget">需要无懈可击的目标</param> /// <param name="aEffect">无懈可击的效果</param> /// <returns>true表示无懈可击成立,反之不成立</returns> protected bool WuXieProc(ChiefBase aTarget, Card.Effect aEffect) { //这个量来表示场上是否有无懈可击存在 bool WuXieExist = false; //表决字典 //表决字典是用来记录玩家(键)的表态(值) //某个玩家的值为false代表没有表态,true表带已表态 //通信层根据这个字典会对值为False的玩家进行并行问询 //若其中有玩家问询时选择确认(一般指放弃),将其值定位true //若所有玩家都是true或超时,表决结束,问询返回None //若有玩家出 无懈可击 时,表决问询将直接结束,返回 WuXieKeJi问询 Dictionary <Player, bool> abstention = new Dictionary <Player, bool>(); ChiefBase s = aTarget; //遍历场上的玩家 do { if (!GamePlayers[s].Dead && GamePlayers[s].Hands.Find(c => c.CardEffect == Card.Effect.WuXieKeJi) != null) { //这个玩家有手牌无懈可击,将他加入表决字典并置value为false,表示他可以表决 abstention.Add(GamePlayers[s], false); //无懈可击存在 WuXieExist = true; } else { //这个玩家没有无懈可击,设置其值为true,表示已表决 abstention.Add(GamePlayers[s], true); } s = s.Next; } while (s != aTarget); //无懈可击存在,启动问询 if (WuXieExist) { AsynchronousCore.SendMessage( new Beaver("askfor.wxkj", aTarget.ChiefName, aEffect.ToString()).ToString()); //new XElement("askfor.wxkj", // new XElement("from", aTarget.ChiefName), // new XElement("effect", aEffect) // ) //); //开始问询 MessageCore.AskForResult res = AsynchronousCore.AskForCards(MessageCore.AskForEnum.WuXieKeJi, abstention); ValidityResult(res.Leader, ref res); //若有玩家打出无懈可击 if (res.Effect == Card.Effect.WuXieKeJi) { //事件节点加入 DropCards(true, CardFrom.Hand, res.SkillName, res.Cards, Card.Effect.WuXieKeJi, res.Leader, aTarget, null); AsynchronousCore.SendMessage( new Beaver("wxkj", res.Leader.ChiefName, Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("wxkj", // new XElement("from", res.Leader.ChiefName), // Card.Cards2XML("cards", res.Cards) //)); //目标换成出牌者 aTarget = res.Leader; //两个结果异或即本轮结果 return(true ^ WuXieProc(aTarget, Card.Effect.WuXieKeJi)); } } //返回false return(false); }
/// <summary> /// 判定过程 /// </summary> /// <param name="aChief">执行过程的武将</param> /// <param name="aData">全局数据</param> private void Judgement(ChiefBase aChief, GlobalData aData) { //清除垃圾桶,事件队列 FreeCardBin(); queRecoard.Clear(); //Debuff栈退栈循环 while (GamePlayers[aChief].Debuff.Count != 0 && !GamePlayers[aChief].Dead) { //清除事件子队列 lstRecoard.Clear(); //取Debuff栈元素,退栈 Card buff = GamePlayers[aChief].Debuff.Pop(); //加入子事件队列 queRecoard.Enqueue(new EventRecoard(aChief, aChief, new Card[] { buff }, buff.CardEffect, string.Empty)); lstCardBin.Add(buff); //判断Debuff类型 switch (buff.CardEffect) { //兵粮寸断 case Card.Effect.BingLiangCunDuan: //无懈可击的过程 if (WuXieProc(aChief, Card.Effect.BingLiangCunDuan)) { continue; } //获取判定牌 Card judgementBLCD = popJudgementCard(aChief, buff.CardEffect); //对判定牌的处理 if (judgementBLCD.CardHuaSe != Card.Suit.CaoHua) { aData.Take = false; } else { aData.Take = true; } AsynchronousCore.SendMessage( new Beaver("removedebuff", aChief.ChiefName, Card.Cards2Beaver("cards", new Card[] { buff })).ToString()); //new XElement("removedebuff", // new XElement("target", aChief.ChiefName), // Card.Cards2XML("cards", new Card[] { buff }) //)); DropCards(true, CardFrom.JudgementCard, string.Empty, new Card[] { judgementBLCD }, Card.Effect.None, aChief, aChief, null); break; //乐不思蜀 case Card.Effect.LeBuSiShu: //无懈可击的过程 if (WuXieProc(aChief, Card.Effect.LeBuSiShu)) { continue; } //获取判定牌 Card judgementLBSS = popJudgementCard(aChief, buff.CardEffect); //对判定牌的处理 if (judgementLBSS.CardHuaSe != Card.Suit.HongTao) { aData.Lead = false; } else { aData.Lead = true; } AsynchronousCore.SendMessage( new Beaver("removedebuff", aChief.ChiefName, Card.Cards2Beaver("cards", new Card[] { buff })).ToString()); //new XElement("removedebuff", // new XElement("target", aChief.ChiefName), // Card.Cards2XML("cards", new Card[] { buff }) //)); DropCards(true, CardFrom.JudgementCard, string.Empty, new Card[] { judgementLBSS }, Card.Effect.None, aChief, aChief, null); break; //闪电 case Card.Effect.ShanDian: //无懈可击的过程 if (WuXieProc(aChief, Card.Effect.ShanDian)) { //没有费血,把debuff牌从垃圾桶里拣出来 PickRubbish(new Card[] { buff }); //闪电需要挂到下一位武将的判定区,如果下一位的判定区有闪电,那就是再下一位...直到处理到该玩家为之 ChiefBase next = GamePlayers.NextChief(aChief); //指示闪电是否安置好了 bool handle = false; if (next != aChief) { do { //如果这个武将没有闪电,那就把闪电放到他的debuff中 if (!GamePlayers[next].HasDebuff(Card.Effect.ShanDian)) { GamePlayers[next].Debuff.Push(buff); AsynchronousCore.SendMessage( new Beaver("sd.moved", aChief.ChiefName, next.ChiefName, Card.Cards2Beaver("cards", new Card[] { buff })).ToString()); //new XElement("sd.moved", // new XElement("from", aChief.ChiefName), // new XElement("to", next.ChiefName), // Card.Cards2XML("cards", new Card[] { buff }) //)); //闪电已安置 handle = true; break; } } while (aChief != (next = GamePlayers.NextChief(next))); } //如果闪电没有安置,那就挂到玩家的新debuff栈中 if (!handle) { gData.stkNewBuff.Push(buff.GetOriginalCard()); } continue; } //取出判定牌 Card judgementSD = popJudgementCard(aChief, buff.CardEffect); //费血 if (judgementSD.CardHuaSe == Card.Suit.HeiTao && judgementSD.CardNumber > 1 && judgementSD.CardNumber < 10) { AsynchronousCore.SendMessage( new Beaver("removedebuff", aChief.ChiefName, Card.Cards2Beaver("cards", new Card[] { buff })).ToString() //new XElement("removedebuff", // new XElement("target", aChief.ChiefName), // Card.Cards2XML("cards", new Card[] { buff })) ); if (GamePlayers[aChief].Armor != null) { DamageHealth(aChief, Armor.CalcDamage(3, new Card[] { buff }, GamePlayers[aChief].Armor.CardEffect), null, new EventRecoard(null, aChief, null, new Card[] { buff }, Card.Effect.ShanDian, string.Empty)); } else { DamageHealth(aChief, 3, null, new EventRecoard(null, aChief, null, new Card[] { buff }, Card.Effect.ShanDian, string.Empty)); } } else { //没有费血,把debuff牌从垃圾桶里拣出来 PickRubbish(new Card[] { buff }); //闪电需要挂到下一位武将的判定区,如果下一位的判定区有闪电,那就是再下一位...直到处理到该玩家为之 ChiefBase next = GamePlayers.NextChief(aChief); //指示闪电是否安置好了 bool handle = false; if (next != aChief) { do { //如果这个武将没有闪电,那就把闪电放到他的debuff中 if (!GamePlayers[next].HasDebuff(Card.Effect.ShanDian)) { GamePlayers[next].Debuff.Push(buff); AsynchronousCore.SendMessage( new Beaver("sd.moved", aChief.ChiefName, next.ChiefName, Card.Cards2Beaver("cards", new Card[] { buff })).ToString() //new XElement("sd.moved", // new XElement("from", aChief.ChiefName), // new XElement("to", next.ChiefName), // Card.Cards2XML("cards", new Card[] { buff })) ); //闪电已安置 handle = true; break; } } while (aChief != (next = GamePlayers.NextChief(next))); } //如果闪电没有安置,那就挂到玩家的新debuff栈中 if (!handle) { gData.stkNewBuff.Push(buff.GetOriginalCard()); } } //判定牌加入子事件节点 DropCards(true, CardFrom.JudgementCard, string.Empty, new Card[] { judgementSD }, Card.Effect.None, aChief, aChief, null); break; } //清除子事件 lstRecoard.Clear(); } //设置玩家的debuff栈 GamePlayers[aChief].Debuff = gData.stkNewBuff; //清除事件记录 FreeCardBin(); queRecoard.Clear(); lstRecoard.Clear(); }
/// <summary> /// 万箭齐发的过程 /// </summary> /// <param name="r">子事件的起始节点</param> /// <returns></returns> private EventRecoard WanJianQiFaProc(EventRecoard r) { string msg = null; //对方不能死亡 if (!GamePlayers[r.Target].Dead) { //进入无懈可击的过程 if (WuXieProc(r.Target, Card.Effect.WanJianQiFa)) { return(r); } if (GamePlayers[r.Target].Armor == null || Armor.EnableFor(GamePlayers[r.Target].Armor.CardEffect, r.Cards, Card.Effect.WanJianQiFa, r.Target)) { MessageCore.AskForResult resShan = null; msg = new Beaver("askfor.wjqf.shan", r.Target.ChiefName, r.Source.ChiefName).ToString(); //new XElement("askfor.wjqf.shan", // new XElement("target", r.Target.ChiefName), // new XElement("source", r.Source.ChiefName) //); //问询闪 resShan = AsynchronousCore.AskForCards(r.Target, MessageCore.AskForEnum.Shan, new AskForWrapper(msg, this), true, gData); ValidityResult(r.Target, ref resShan); //} if (resShan.PlayerLead) { DropCards(true, CardFrom.Hand, resShan.SkillName, resShan.Cards, resShan.Effect, resShan.Leader, r.Source, null); } else { DropCards(false, CardFrom.None, resShan.SkillName, resShan.Cards, resShan.Effect, resShan.Leader, r.Source, null); } //将问询的牌放入到子事件节点 //EventNode(true, CardFrom.Hand, resShan.SkillName , resShan.Cards, resShan.Effect, r.Target, r.Source, null); foreach (ASkill s in resShan.Leader.Skills) { s.OnUseEffect(resShan.Leader, Card.Effect.Shan, gData); } if (resShan.Effect == Card.Effect.Shan) { if (resShan.PlayerLead) { AsynchronousCore.SendMessage( new Beaver("wjqf.shan", r.Target.ChiefName, r.Source.ChiefName, resShan.SkillName, Card.Cards2Beaver("cards", resShan.Cards)).ToString()); } //new XElement("wjqf.shan", // new XElement("target", r.Target.ChiefName), // new XElement("source", r.Source.ChiefName), // new XElement("skill", resShan.SkillName), // Card.Cards2XML("cards", resShan.Cards) //)); } else { //没有出闪费血 DamageHealth(r.Target, 1, r.Source, r); } } } return(r); }
/// <summary> /// 决斗的执行过程 /// </summary> /// <param name="r">子事件起始节点</param> /// <returns></returns> internal EventRecoard JueDouProc(EventRecoard r) { string msg = null; if (r.Target2 != null) { r.Source = r.Target; r.Target = r.Target2; } //玩家双方都不能死亡 if (!GamePlayers[r.Target].Dead && !GamePlayers[r.Source].Dead) { if (r.Target2 == null) { //无懈可击的过程 if (WuXieProc(r.Target, Card.Effect.JueDou)) { return(r); } } while (true) { int times = 1; foreach (ASkill s in r.Source.Skills) { times = s.CalcAskforTimes(r.Source, r.Target, Card.Effect.JueDou, times, gData); } for (int i = 0; i < times; i++) { //先询问对方要出杀 MessageCore.AskForResult res = null; msg = new Beaver("askfor.jd.sha", r.Target.ChiefName, r.Source.ChiefName).ToString(); //new XElement("askfor.jd.sha", //new XElement("target", r.Target.ChiefName), //new XElement("opponent", r.Source.ChiefName) //); res = AsynchronousCore.AskForCards(r.Target, MessageCore.AskForEnum.Sha, new AskForWrapper(msg, this), gData); ValidityResult(r.Target, ref res); if (res.Effect != Card.Effect.Sha) { //不出杀费血 sbyte cost = 1; foreach (ASkill s in r.Source.Skills) { cost = s.CalcDamage(r.Source, Card.Effect.JueDou, cost, gData); } if (GamePlayers[r.Target].Armor != null) { cost = Armor.CalcDamage(cost, r.Cards, GamePlayers[r.Target].Armor.CardEffect); } DamageHealth(r.Target, cost, r.Source, r); return(r); } else { //出杀加入子事件节点 if (res.PlayerLead) { DropCards(true, CardFrom.Hand, res.SkillName, res.Cards, Card.Effect.Sha, res.Leader, r.Source, null); } foreach (ASkill s in res.Leader.Skills) { s.OnUseEffect(res.Leader, Card.Effect.Sha, gData); } AsynchronousCore.SendMessage( new Beaver("jd.sha", r.Target.ChiefName, r.Source.ChiefName, Card.Cards2Beaver("cards", res.Cards)).ToString()); //new XElement("jd.sha", // new XElement("target", r.Target.ChiefName), // new XElement("opponent", r.Source.ChiefName), // Card.Cards2XML("cards", res.Cards) //)); } } times = 1; foreach (ASkill s in r.Target.Skills) { times = s.CalcAskforTimes(r.Target, r.Source, Card.Effect.JueDou, times, gData); } for (int i = 0; i < times; i++) { msg = new Beaver("askfor.jd.sha", r.Source.ChiefName, r.Target.ChiefName).ToString(); //new XElement("askfor.jd.sha", //new XElement("target", r.Source.ChiefName), //new XElement("opponent", r.Target.ChiefName) //); //问询自己出杀 MessageCore.AskForResult res2 = AsynchronousCore.AskForCards(r.Source, MessageCore.AskForEnum.Sha, new AskForWrapper(msg, this), gData); ValidityResult(r.Source, ref res2); if (res2.Effect != Card.Effect.Sha) { //不出杀费血 sbyte cost = 1; foreach (ASkill s in r.Target.Skills) { cost = s.CalcDamage(r.Target, r.Effect, cost, gData); } if (GamePlayers[r.Source].Armor != null) { cost = Armor.CalcDamage(cost, r.Cards, GamePlayers[r.Source].Armor.CardEffect); } DamageHealth(r.Source, cost, r.Target, r); return(r); } else { //出杀加入子事件节点 if (res2.PlayerLead) { DropCards(true, CardFrom.Hand, res2.SkillName, res2.Cards, Card.Effect.Sha, res2.Leader, r.Target, null); } foreach (ASkill s in res2.Leader.Skills) { s.OnUseEffect(res2.Leader, Card.Effect.Sha, gData); } AsynchronousCore.SendMessage( new Beaver("jd.sha", r.Source.ChiefName, r.Target.ChiefName, Card.Cards2Beaver("cards", res2.Cards)).ToString()); //new XElement("jd.sha", // new XElement("target", r.Source.ChiefName), // new XElement("opponent", r.Target.ChiefName), // Card.Cards2XML("cards", res2.Cards) //)); } } } } return(r); }