Exemplo n.º 1
0
        void Run(Player Owner, GameEvent gameEvent, GameEventArgs eventArgs)
        {
            ISkill        skill;
            List <Card>   cards;
            List <Player> players;

            if (Owner.AskForCardUsage(new CardUsagePrompt("XiaoXi"), new XiaoXiVerifier(verifier), out skill, out cards, out players))
            {
                NotifySkillUse();
                GameEventArgs args = new GameEventArgs();
                Owner[Sha.NumberOfShaUsed]--;
                args.Source  = Owner;
                args.Targets = players;
                args.Skill   = skill == null ? new CardWrapper(Owner, new RegularSha(), false) : skill;
                args.Cards   = new List <Card>();
                CardTransformSkill transformSkill = skill as CardTransformSkill;
                if (transformSkill != null)
                {
                    CompositeCard card;
                    transformSkill.TryTransform(new List <Card>()
                    {
                        new Card()
                        {
                            Type = new RegularSha(), Place = new DeckPlace(null, DeckType.None)
                        }
                    }, players, out card);
                    card.Subcards.Clear();
                    args.Card = card;
                }
                Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, args);
            }
        }
        public override VerifierResult FastVerify(Player source, ISkill skill, List <Card> cards, List <Player> players)
        {
            if (players != null && players.Any(p => p.IsDead))
            {
                return(VerifierResult.Fail);
            }
            if (players == null)
            {
                players = new List <Player>();
            }
            CompositeCard sha = new CompositeCard()
            {
                Type = type
            };

            if (!Game.CurrentGame.PlayerCanBeTargeted(source, players, sha))
            {
                return(VerifierResult.Fail);
            }
            List <Player> newList = new List <Player>(players);

            if (target != null)
            {
                if (!newList.Contains(target))
                {
                    newList.Insert(0, target);
                }
                else
                {
                    return(VerifierResult.Fail);
                }
            }
            if (cards != null && cards.Count > 0)
            {
                return(VerifierResult.Fail);
            }
            if (skill is CardTransformSkill)
            {
                CardTransformSkill sk = skill as CardTransformSkill;
                if (sk.TryTransform(dummyCards, null, out sha) != VerifierResult.Success)
                {
                    return(VerifierResult.Fail);
                }
                if (helper != null)
                {
                    sha[helper] = 1;
                }
                return(new Sha().VerifyCore(source, sha, newList));
            }
            else if (skill != null)
            {
                return(VerifierResult.Fail);
            }
            if (helper != null)
            {
                sha[helper] = 1;
            }
            return(new Sha().VerifyCore(source, sha, newList));
        }
Exemplo n.º 3
0
 public override VerifierResult FastVerify(Player source, ISkill skill, List <Card> cards, List <Player> players)
 {
     if (players != null && players.Any(p => p.IsDead))
     {
         return(VerifierResult.Fail);
     }
     if ((cards == null || cards.Count == 0) && skill == null)
     {
         return(VerifierResult.Fail);
     }
     if (skill is CheatSkill)
     {
         if (!Game.CurrentGame.Settings.CheatEnabled)
         {
             return(VerifierResult.Fail);
         }
         return(VerifierResult.Success);
     }
     else if (skill is ActiveSkill)
     {
         GameEventArgs arg = new GameEventArgs();
         arg.Source  = Game.CurrentGame.CurrentPlayer;
         arg.Targets = players;
         arg.Cards   = cards;
         return(((ActiveSkill)skill).Validate(arg));
     }
     else if (skill is CardTransformSkill)
     {
         CardTransformSkill s = (CardTransformSkill)skill;
         CompositeCard      result;
         VerifierResult     ret = s.TryTransform(cards, players, out result);
         if (ret == VerifierResult.Success)
         {
             return(result.Type.Verify(Game.CurrentGame.CurrentPlayer, skill, cards, players));
         }
         if (ret == VerifierResult.Partial && players != null && players.Count != 0)
         {
             return(VerifierResult.Fail);
         }
         return(ret);
     }
     else if (skill != null)
     {
         return(VerifierResult.Fail);
     }
     if (cards[0].Place.DeckType != DeckType.Hand)
     {
         return(VerifierResult.Fail);
     }
     return(cards[0].Type.Verify(Game.CurrentGame.CurrentPlayer, skill, cards, players));
 }
Exemplo n.º 4
0
        void Run(Player Owner, GameEvent gameEvent, GameEventArgs eventArgs)
        {
            ISkill          skill;
            List <Card>     cards;
            List <Player>   players;
            bool            shensu1       = gameEvent == GameEvent.PhaseOutEvents[TurnPhase.Start];
            CardUsagePrompt shensu1Prompt = new CardUsagePrompt("ShenSu1", this);
            CardUsagePrompt shensu2Prompt = new CardUsagePrompt("ShenSu2", this);

            if (Owner.AskForCardUsage(shensu1 ? shensu1Prompt : shensu2Prompt, new ShenSuVerifier(shensu1, verifier), out skill, out cards, out players))
            {
                NotifySkillUse();
                if (!shensu1)
                {
                    Game.CurrentGame.HandleCardDiscard(Owner, cards);
                }
                GameEventArgs args = new GameEventArgs();
                Owner[Sha.NumberOfShaUsed]--;
                args.Source  = Owner;
                args.Targets = players;
                args.Skill   = skill == null ? new CardWrapper(Owner, new RegularSha(), false) : skill;
                args.Cards   = new List <Card>();
                CardTransformSkill transformSkill = skill as CardTransformSkill;
                if (transformSkill != null)
                {
                    CompositeCard card;
                    transformSkill.TryTransform(new List <Card>()
                    {
                        new Card()
                        {
                            Type = new RegularSha(), Place = new DeckPlace(null, DeckType.None)
                        }
                    }, players, out card);
                    card.Subcards.Clear();
                    args.Card = card;
                }
                Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, args);
                if (shensu1)
                {
                    Game.CurrentGame.PhasesSkipped.Add(TurnPhase.Judge);
                    Game.CurrentGame.PhasesSkipped.Add(TurnPhase.Draw);
                }
                else
                {
                    Game.CurrentGame.PhasesSkipped.Add(TurnPhase.Play);
                }
            }
        }
Exemplo n.º 5
0
        private void AskUiThread()
        {
            if (proxy.HostPlayer.IsDead)
            {
                return;
            }
            bool found = true;

            if (verifier.AcceptableCardTypes != null)
            {
                found = false;
                foreach (var sk in proxy.HostPlayer.ActionableSkills)
                {
                    CardTransformSkill transformSkill = sk as CardTransformSkill;
                    if (transformSkill == null)
                    {
                        continue;
                    }
                    if (transformSkill.PossibleResults == null)
                    {
                        found = true; break;
                    }
                    var commonResult = from type1 in verifier.AcceptableCardTypes
                                       where transformSkill.PossibleResults.Any(ci => type1.GetType().IsAssignableFrom(ci.GetType()))
                                       select type1;
                    if (commonResult.Count() != 0)
                    {
                        found = true;
                    }
                }
                var commonResult2 = from type1 in verifier.AcceptableCardTypes
                                    where proxy.HostPlayer.HandCards().Any(ci => type1.GetType().IsAssignableFrom(ci.Type.GetType()))
                                    select type1;
                if (commonResult2.Count() != 0)
                {
                    found = true;
                }
            }
            if (!found)
            {
                proxy.SkipAskForCardUsage();
            }
            else
            {
                proxy.TryAskForCardUsage(prompt, verifier);
            }
        }
        public virtual VerifierResult Verify(Player source, ISkill skill, List <Card> cards, List <Player> players)
        {
            CardTransformSkill transformSkill = skill as CardTransformSkill;

            if (skill is PassiveSkill)
            {
                return(VerifierResult.Fail);
            }

            if (AcceptableCardTypes == null)
            {
                return(SlowVerify(source, skill, cards, players));
            }

            if (transformSkill != null)
            {
                if (transformSkill is IAdditionalTypedSkill ||
                    transformSkill.PossibleResults == null)
                {
                    return(SlowVerify(source, skill, cards, players));
                }
                else
                {
                    var commonResult = from type1 in AcceptableCardTypes
                                       where transformSkill.PossibleResults.Any(ci => type1.GetType().IsAssignableFrom(ci.GetType()))
                                       select type1;
                    if (commonResult.Count() != 0)
                    {
                        return(SlowVerify(source, skill, cards, players));
                    }
                }
                return(VerifierResult.Fail);
            }

            if (skill is ActiveSkill)
            {
                if (SlowVerify(source, skill, null, null) == VerifierResult.Fail)
                {
                    return(VerifierResult.Fail);
                }
            }

            return(SlowVerify(source, skill, cards, players));
        }
Exemplo n.º 7
0
            public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
            {
                Player currentPlayer = Game.CurrentGame.CurrentPlayer;

                Trace.TraceInformation("Player {0} action.", currentPlayer.Id);
                while (!currentPlayer.IsDead)
                {
                    bool newturn = false;
                    foreach (var pl in Game.CurrentGame.Players)
                    {
                        if (GetReadyToGo(pl) && pl == currentPlayer)
                        {
                            newturn = true;
                        }
                    }
                    if (newturn)
                    {
                        return;
                    }
                    Trace.Assert(Game.CurrentGame.UiProxies.ContainsKey(currentPlayer));
                    IPlayerProxy              proxy = Game.CurrentGame.UiProxies[currentPlayer];
                    ISkill                    skill;
                    List <Card>               cards;
                    List <Player>             players;
                    PlayerActionStageVerifier v = new PlayerActionStageVerifier();
                    Game.CurrentGame.Emit(GameEvent.PlayerIsAboutToUseCard, new PlayerIsAboutToUseOrPlayCardEventArgs()
                    {
                        Source = currentPlayer, Verifier = v
                    });
                    if (!proxy.AskForCardUsage(new Prompt(Prompt.PlayingPhasePrompt), v, out skill, out cards, out players))
                    {
                        break;
                    }
                    if (skill != null)
                    {
                        if (skill is CheatSkill)
                        {
                            if (!Game.CurrentGame.Settings.CheatEnabled)
                            {
                                break;
                            }
                            CheatSkill cs = skill as CheatSkill;
                            if (cs.CheatType == CheatType.Card)
                            {
                                if (Game.CurrentGame.IsClient)
                                {
                                    Game.CurrentGame.SyncUnknownLocationCardAll(null);
                                }
                                else
                                {
                                    foreach (var searchCard in Game.CurrentGame.CardSet)
                                    {
                                        if (searchCard.Id == cs.CardId)
                                        {
                                            Game.CurrentGame.SyncUnknownLocationCardAll(searchCard);
                                            break;
                                        }
                                    }
                                }
                                foreach (var searchCard in Game.CurrentGame.CardSet)
                                {
                                    if (searchCard.Id == cs.CardId)
                                    {
                                        CardsMovement move = new CardsMovement();
                                        move.Cards = new List <Card>()
                                        {
                                            searchCard
                                        };
                                        move.To     = new DeckPlace(Game.CurrentGame.CurrentPlayer, DeckType.Hand);
                                        move.Helper = new MovementHelper();
                                        Game.CurrentGame.MoveCards(move);
                                        break;
                                    }
                                }
                            }
                            else if (cs.CheatType == CheatType.Skill)
                            {
                                foreach (var hero in Game.CurrentGame.OriginalCardSet)
                                {
                                    bool found = false;
                                    if (hero.Type is HeroCardHandler)
                                    {
                                        foreach (var sk in (hero.Type as HeroCardHandler).Hero.Skills)
                                        {
                                            if (sk.GetType().Name == cs.SkillName)
                                            {
                                                Game.CurrentGame.PlayerAcquireAdditionalSkill(currentPlayer, sk.Clone() as ISkill, currentPlayer.Hero);
                                                found = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (found)
                                    {
                                        break;
                                    }
                                }
                            }
                            continue;
                        }
                        else if (skill is ActiveSkill)
                        {
                            GameEventArgs arg = new GameEventArgs();
                            arg.Source  = Game.CurrentGame.CurrentPlayer;
                            arg.Targets = players;
                            arg.Cards   = cards;
                            ((ActiveSkill)skill).NotifyAndCommit(arg);
                            Game.CurrentGame.NotificationProxy.NotifyActionComplete();
                            Game.CurrentGame.LastAction = skill;
                            continue;
                        }
                        CompositeCard      c;
                        CardTransformSkill s = (CardTransformSkill)skill;
                        VerifierResult     r = s.TryTransform(cards, players, out c);
                        Trace.TraceInformation("Player used {0}", c.Type);
                    }
                    else
                    {
                        Trace.Assert(cards[0] != null && cards.Count == 1);
                        Trace.TraceInformation("Player used {0}", cards[0].Type);
                    }
                    try
                    {
                        Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, new Triggers.GameEventArgs()
                        {
                            Skill = skill, Source = Game.CurrentGame.CurrentPlayer, Targets = players, Cards = cards
                        });
                    }
                    catch (TriggerResultException)
                    {
                    }
                    Game.CurrentGame.NotificationProxy.NotifyActionComplete();
                    Game.CurrentGame.LastAction = skill;
                }
            }
Exemplo n.º 8
0
        public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
        {
            ReadOnlyCard            card = eventArgs.ReadonlyCard;
            SingleCardUsageVerifier v1   = new SingleCardUsageVerifier((c) => { return(c.Type is WuXieKeJi); }, true, new WuXieKeJi());

            v1.Helper.ExtraTimeOutSeconds = -9;
            List <Card>   cards;
            List <Player> players;
            ISkill        skill;
            Player        responder;
            bool          WuXieSuccess = false;

            Trace.Assert(eventArgs.Targets.Count == 1);
            Player promptPlayer = eventArgs.Targets[0];
            ICard  promptCard   = eventArgs.ReadonlyCard;

            if (card != null && CardCategoryManager.IsCardCategory(card.Type.Category, CardCategory.Tool) &&
                card[WuXieKeJi.CannotBeCountered] == 0 && card[WuXieKeJi.CannotBeCountered[promptPlayer]] == 0)
            {
                bool askWuXie = false;
                foreach (var p in Game.CurrentGame.AlivePlayers)
                {
                    foreach (var c in Game.CurrentGame.Decks[p, DeckType.Hand])
                    {
                        if (c.Type is WuXieKeJi)
                        {
                            askWuXie = true;
                            break;
                        }
                    }
                    foreach (var sk in p.ActionableSkills)
                    {
                        CardTransformSkill cts = sk as CardTransformSkill;
                        if (cts != null)
                        {
                            if (cts.PossibleResults == null)
                            {
                                askWuXie = true;
                                break;
                            }
                            foreach (var pr in cts.PossibleResults)
                            {
                                if (pr is WuXieKeJi)
                                {
                                    askWuXie = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (askWuXie)
                    {
                        break;
                    }
                }
                Game.CurrentGame.SyncConfirmationStatus(ref askWuXie);
                if (!askWuXie)
                {
                    return;
                }
                foreach (var p in Game.CurrentGame.AlivePlayers)
                {
                    Game.CurrentGame.Emit(GameEvent.PlayerIsAboutToPlayCard, new PlayerIsAboutToUseOrPlayCardEventArgs()
                    {
                        Source = p, Verifier = v1
                    });
                }
                while (true)
                {
                    Prompt prompt = new CardUsagePrompt("WuXieKeJi", promptPlayer, promptCard);
                    if (Game.CurrentGame.GlobalProxy.AskForCardUsage(
                            prompt, v1, out skill, out cards, out players, out responder))
                    {
                        try
                        {
                            GameEventArgs args = new GameEventArgs();
                            args.Source  = responder;
                            args.Targets = players;
                            args.Skill   = skill;
                            args.Cards   = cards;
                            Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, args);
                        }
                        catch (TriggerResultException e)
                        {
                            Trace.Assert(e.Status == TriggerResult.Retry);
                            continue;
                        }
                        promptPlayer    = responder;
                        promptCard      = new CompositeCard();
                        promptCard.Type = new WuXieKeJi();
                        (promptCard as CompositeCard).Subcards = null;
                        WuXieSuccess = !WuXieSuccess;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (WuXieSuccess)
            {
                throw new TriggerResultException(TriggerResult.End);
            }
        }
 public override VerifierResult FastVerify(Player source, ISkill skill, List <Card> cards, List <Player> players)
 {
     if (players != null && players.Count != 0)
     {
         return(VerifierResult.Fail);
     }
     if (skill != null)
     {
         CompositeCard card;
         if (!(skill is CardTransformSkill))
         {
             return(VerifierResult.Fail);
         }
         CardTransformSkill s = (CardTransformSkill)skill;
         VerifierResult     r = s.TryTransform(cards, players, out card, !isUseCard);
         if (r != VerifierResult.Success)
         {
             return(r);
         }
         if (!Match(card))
         {
             return(VerifierResult.Fail);
         }
         if (isUseCard)
         {
             if (!Game.CurrentGame.PlayerCanUseCard(source, card))
             {
                 return(VerifierResult.Fail);
             }
         }
         else
         {
             if (!Game.CurrentGame.PlayerCanPlayCard(source, card))
             {
                 return(VerifierResult.Fail);
             }
         }
         return(VerifierResult.Success);
     }
     if (cards != null && cards.Count > 1)
     {
         return(VerifierResult.Fail);
     }
     if (cards == null || cards.Count == 0)
     {
         return(VerifierResult.Partial);
     }
     if (cards[0].Place.DeckType != DeckType.Hand)
     {
         return(VerifierResult.Fail);
     }
     if (!Match(cards[0]))
     {
         return(VerifierResult.Fail);
     }
     if (isUseCard)
     {
         if (!Game.CurrentGame.PlayerCanUseCard(source, cards[0]))
         {
             return(VerifierResult.Fail);
         }
     }
     else
     {
         if (!Game.CurrentGame.PlayerCanPlayCard(source, cards[0]))
         {
             return(VerifierResult.Fail);
         }
     }
     return(VerifierResult.Success);
 }
Exemplo n.º 10
0
        /// <summary>
        /// 卡牌UI合法性检查
        /// </summary>
        /// <param name="source"></param>
        /// <param name="skill"></param>
        /// <param name="cards"></param>
        /// <param name="targets"></param>
        /// <param name="notReforging">不是重铸中,检查PlayerCanUseCard</param>
        /// <returns></returns>
        protected VerifierResult VerifyHelper(Player source, ISkill skill, List <Card> cards, List <Player> targets, bool isReforging)
        {
            ICard card;

            if (skill != null)
            {
                CompositeCard c;
                if (skill is CardTransformSkill)
                {
                    CardTransformSkill s = skill as CardTransformSkill;
                    VerifierResult     r = s.TryTransform(cards, targets, out c);
                    if (c != null && c.Type != null && !(this.GetType().IsAssignableFrom(c.Type.GetType())))
                    {
                        return(VerifierResult.Fail);
                    }
                    if (r != VerifierResult.Success)
                    {
                        return(r);
                    }
                    if (!isReforging)
                    {
                        if (!Game.CurrentGame.PlayerCanUseCard(source, c))
                        {
                            return(VerifierResult.Fail);
                        }
                    }
                    HoldInTemp(c.Subcards);
                    card = c;
                }
                else
                {
                    return(VerifierResult.Fail);
                }
            }
            else
            {
                if (cards == null || cards.Count != 1)
                {
                    return(VerifierResult.Fail);
                }
                card = cards[0];
                if (!(this.GetType().IsAssignableFrom(card.Type.GetType())))
                {
                    return(VerifierResult.Fail);
                }

                if (!isReforging)
                {
                    if (!Game.CurrentGame.PlayerCanUseCard(source, card))
                    {
                        return(VerifierResult.Fail);
                    }
                }
                HoldInTemp(cards);
            }

            var targetCheck = ActualTargets(source, targets, card);

            if (targetCheck != null && targetCheck.Count != 0)
            {
                if (!isReforging)
                {
                    if (!Game.CurrentGame.PlayerCanBeTargeted(source, targetCheck, card))
                    {
                        ReleaseHoldInTemp();
                        return(VerifierResult.Fail);
                    }
                }
            }
            VerifierResult ret = Verify(source, card, targets);

            ReleaseHoldInTemp();
            return(ret);
        }