Beispiel #1
0
 /// <summary>
 /// 问询出牌合法性检验,并回应武将所控制的玩家出牌合法性结果,对于判断为非法的出牌,将会设置用户返回结果
 /// </summary>
 /// <param name="aChief">出牌武将</param>
 /// <param name="aResult">问询结果,若出牌不合法,则问询会被修改为默认对象</param>
 /// <remarks>此方法用于通过回调通知调试客户端操作的合法性,回调仅适合用于测试类库逻辑</remarks>
 private void ValidityResult(ChiefBase aChief, ref MessageCore.AskForResult aResult)
 {
     if (!CheckValid(aResult, aChief))
     {
         AsynchronousCore.LeadingInvalid(aChief);
         aResult = new MessageCore.AskForResult(false, aResult.Leader, new ChiefBase[] { }, new Card[] { }, Card.Effect.None, false, true, string.Empty);
     }
     else
     {
         AsynchronousCore.LeadingValid(aChief);
     }
 }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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=下一个玩家

            //-----------------------------------------------------------
            //如果玩家都死光了...没分胜负,我想这里会有异常吧
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <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);
        }