コード例 #1
0
ファイル: MessageCore.cs プロジェクト: xdusongwei/SanGuoSha
        /// <summary>
        /// 问询玩家出牌
        /// </summary>
        /// <param name="aChief">被问询的玩家角色</param>
        /// <param name="aAskFor">问询的内容</param>
        /// <param name="aActiveArmor">指示是否让防具来参与问询的回应</param>
        /// <param name="aWrapper"></param>
        /// <param name="aData"></param>
        /// <returns>返回问询结果</returns>
        internal AskForResult AskForCards(ChiefBase aChief, AskForEnum aAskFor, AskForWrapper aWrapper, bool aActiveArmor, GlobalData aData)
        {
            AskForResult ret = null;

            if (aActiveArmor && aData.Game.GamePlayers[aChief].Armor != null)
            {
                if (aAskFor == AskForEnum.Shan)
                {
                    ret = Armor.AskFor(Card.Effect.Shan, aData.Game.GamePlayers[aChief].Armor.CardEffect, aChief, aData);
                    if (ret != null && ret.Effect != Card.Effect.None)
                    {
                        return(ret);
                    }
                }
            }

            //通知武将技能问询开始
            foreach (ASkill s in aChief.Skills)
            {
                s.BeforeAskfor(aChief, aAskFor, aData);
            }
            while (true)
            {
                aWrapper.SendAskFor(this);
                //使用通信方法问询玩家选择一张问询结果对应的牌
                GB.CommService.AskForCards(GB, GB.GamePlayers[aChief], aAskFor);
                if (aData.Game.Response.SkillName != string.Empty)
                {
                    //将问询通知该武将的技能,若回应非None效果,则将此Result作为结果返回
                    foreach (ASkill s in aChief.Skills)
                    {
                        try
                        {
                            AskForResult res = s.AskFor(aChief, aAskFor, aData);
                            if (res != null && res.Effect != Card.Effect.None)
                            {
                                ret = res;
                                goto FINISH;
                            }
                        }
                        catch (SkillInvalid e)
                        {
                            //return new AskForResult(false, aChief, new ChiefBase[] { }, new Card[] { }, Card.Effect.None, false, false, string.Empty);
                            continue;
                        }
                        catch (SkillFatalError e)
                        {
                            return(new AskForResult(false, aChief, new ChiefBase[] { }, new Card[] { }, Card.Effect.None, false, false, string.Empty));
                        }
                        catch (Exception e)
                        {
                            throw e;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
FINISH:
            //通知武将技能问询结束
            foreach (ASkill s in aChief.Skills)
            {
                s.FinishAskfor(aChief, aAskFor, aData);
            }
            //返回问询结果
            if (ret != null && ret.Effect != Card.Effect.None)
            {
                return(ret);
            }
            else
            {
                return(new AskForResult(GB.Response.IsTimeout, aChief, Player.Players2Chiefs(GB.Response.Targets), GB.Response.Cards, GB.Response.Effect, GB.Response.Answer, true, GB.Response.SkillName));
            }
        }