Inheritance: Sanguosha.Core.UI.CardUsageVerifier
Example #1
0
        public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
        {
            Player target = eventArgs.Targets[0];

            if (target.Health > 0)
            {
                return;
            }
            LifeSaverVerifier v = new LifeSaverVerifier();

            v.DyingPlayer = target;
            List <Player> toAsk = Game.CurrentGame.AlivePlayers;

            foreach (Player p in toAsk)
            {
                if (p.IsDead)
                {
                    continue;
                }
                if (!_CanUseTaoToSaveOther(p) && !_CanUseSaveLifeSkillToSaveOther(p) && p != target)
                {
                    continue;
                }
                while (!target.IsDead && target.Health <= 0)
                {
                    ISkill        skill;
                    List <Card>   cards;
                    List <Player> players;
                    Game.CurrentGame.Emit(GameEvent.PlayerIsAboutToUseCard, new PlayerIsAboutToUseOrPlayCardEventArgs()
                    {
                        Source = p, Verifier = v
                    });
                    if (Game.CurrentGame.UiProxies[p].AskForCardUsage(new CardUsagePrompt("SaveALife", target, 1 - target.Health), v, out skill, out cards, out players))
                    {
                        if (skill != null && skill is SaveLifeSkill)
                        {
                            GameEventArgs arg = new GameEventArgs();
                            arg.Source  = p;
                            arg.Targets = players;
                            arg.Cards   = cards;
                            ((SaveLifeSkill)skill).NotifyAndCommit(arg);
                        }
                        else
                        {
                            try
                            {
                                GameEventArgs args = new GameEventArgs();
                                args.Source = p;
                                args.Skill  = skill;
                                args.Cards  = cards;
                                Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, args);
                            }
                            catch (TriggerResultException e)
                            {
                                Trace.Assert(e.Status == TriggerResult.Retry);
                                continue;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Example #2
0
 public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
 {
     Player target = eventArgs.Targets[0];
     if (target.Health > 0) return;
     LifeSaverVerifier v = new LifeSaverVerifier();
     v.DyingPlayer = target;
     List<Player> toAsk = Game.CurrentGame.AlivePlayers;
     foreach (Player p in toAsk)
     {
         if (p.IsDead) continue;
         if (!_CanUseTaoToSaveOther(p) && !_CanUseSaveLifeSkillToSaveOther(p) && p != target) continue;
         while (!target.IsDead && target.Health <= 0)
         {
             ISkill skill;
             List<Card> cards;
             List<Player> players;
             if (Game.CurrentGame.UiProxies[p].AskForCardUsage(new CardUsagePrompt("SaveALife", target, 1 - target.Health), v, out skill, out cards, out players))
             {
                 if (skill != null && skill is SaveLifeSkill)
                 {
                     GameEventArgs arg = new GameEventArgs();
                     arg.Source = p;
                     arg.Targets = players;
                     arg.Cards = cards;
                     ((SaveLifeSkill)skill).NotifyAndCommit(arg);
                 }
                 else
                 {
                     try
                     {
                         GameEventArgs args = new GameEventArgs();
                         args.Source = p;
                         args.Skill = skill;
                         args.Cards = cards;
                         Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, args);
                     }
                     catch (TriggerResultException e)
                     {
                         Trace.Assert(e.Status == TriggerResult.Retry);
                         continue;
                     }
                 }
             }
             else break;
         }
     }
 }
Example #3
0
 public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
 {
     Player target = eventArgs.Targets[0];
     if (Game.CurrentGame.IsDying.Contains(target)) return;
     if (target.Health > 0) return;
     Game.CurrentGame.IsDying.Push(target);
     List<Player> toAsk = new List<Player>(Game.CurrentGame.AlivePlayers);
     Game.CurrentGame.SortByOrderOfComputation(Game.CurrentGame.CurrentPlayer, toAsk);
     LifeSaverVerifier v = new LifeSaverVerifier();
     v.DyingPlayer = target;
     foreach (Player p in toAsk)
     {
         if (p.IsDead) continue;
         while (true)
         {
             ISkill skill;
             List<Card> cards;
             List<Player> players;
             if (Game.CurrentGame.UiProxies[p].AskForCardUsage(new CardUsagePrompt("SaveALife", target, 1 - target.Health), v, out skill, out cards, out players))
             {
                 try
                 {
                     GameEventArgs args = new GameEventArgs();
                     args.Source = p;
                     args.Skill = skill;
                     args.Cards = cards;
                     Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, args);
                 }
                 catch (TriggerResultException e)
                 {
                     Trace.Assert(e.Status == TriggerResult.Retry);
                     continue;
                 }
                 if (target.Health > 0)
                 {
                     Trace.Assert(target == Game.CurrentGame.IsDying.Pop());
                     return;
                 }
             }
             else
             {
                 break;
             }
         }
     }
     Trace.TraceInformation("Player {0} dead", target.Id);
     Trace.Assert(target == Game.CurrentGame.IsDying.Pop());
     Game.CurrentGame.Emit(GameEvent.GameProcessPlayerIsDead, eventArgs);
     target.IsDead = true;
     Game.CurrentGame.SyncCardsAll(Game.CurrentGame.Decks[target, DeckType.Hand]);
     CardsMovement move = new CardsMovement();
     move.cards = new List<Card>();
     move.cards.AddRange(Game.CurrentGame.Decks[target, DeckType.Hand]);
     move.cards.AddRange(Game.CurrentGame.Decks[target, DeckType.Equipment]);
     move.cards.AddRange(Game.CurrentGame.Decks[target, DeckType.DelayedTools]);
     move.to = new DeckPlace(null, DeckType.Discard);
     Game.CurrentGame.MoveCards(move, null);
 }
Example #4
0
 public override void Run(GameEvent gameEvent, GameEventArgs eventArgs)
 {
     Player target = eventArgs.Targets[0];
     if (Game.CurrentGame.IsDying.Contains(target)) return;
     if (target.Health > 0) return;
     Game.CurrentGame.IsDying.Push(target);
     target[Player.IsDying] = 1;
     List<Player> toAsk = new List<Player>(Game.CurrentGame.AlivePlayers);
     LifeSaverVerifier v = new LifeSaverVerifier();
     v.DyingPlayer = target;
     foreach (Player p in toAsk)
     {
         if (p.IsDead) continue;
         while (true)
         {
             ISkill skill;
             List<Card> cards;
             List<Player> players;
             if (Game.CurrentGame.UiProxies[p].AskForCardUsage(new CardUsagePrompt("SaveALife", target, 1 - target.Health), v, out skill, out cards, out players))
             {
                 try
                 {
                     GameEventArgs args = new GameEventArgs();
                     args.Source = p;
                     args.Skill = skill;
                     args.Cards = cards;
                     Game.CurrentGame.Emit(GameEvent.CommitActionToTargets, args);
                 }
                 catch (TriggerResultException e)
                 {
                     Trace.Assert(e.Status == TriggerResult.Retry);
                     continue;
                 }
                 if (!Game.CurrentGame.IsDying.Contains(target))
                 {
                     target[Player.IsDying] = 0;
                     return;
                 }
                 if (target.Health > 0)
                 {
                     Trace.Assert(target == Game.CurrentGame.IsDying.Pop());
                     target[Player.IsDying] = 0;
                     return;
                 }
             }
             else
             {
                 break;
             }
         }
     }
     Trace.TraceInformation("Player {0} dead", target.Id);
     Trace.Assert(target == Game.CurrentGame.IsDying.Pop());
     target[Player.IsDying] = 0;
     Game.CurrentGame.Emit(GameEvent.GameProcessPlayerIsDead, eventArgs);
 }