Ejemplo n.º 1
0
        public bool TryAnswerForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players)
        {
            object o = client.Receive();

            (o as AskForCardUsageResponse).ToAnswer(out skill, out cards, out players, client.SelfId);
            return(true);
        }
Ejemplo n.º 2
0
        public void TryAskForCardUsage(Prompt prompt, ICardUsageVerifier verifier)
        {
            ISkill        skill;
            List <Card>   cards;
            List <Player> players;

            if (!IsPlayable)
            {
                if (IsUiDetached)
                {
                    return;
                }
                uiProxy.AskForCardUsage(prompt, verifier, out skill, out cards, out players);
                return;
            }
            if (IsUiDetached || !uiProxy.AskForCardUsage(prompt, verifier, out skill, out cards, out players))
            {
                Trace.TraceInformation("Invalid answer");
                client.Send(AskForCardUsageResponse.Parse(numQuestionsAsked, null, null, null, client.SelfId));
            }
            else
            {
                client.Send(AskForCardUsageResponse.Parse(numQuestionsAsked, skill, cards, players, client.SelfId));
            }
        }
Ejemplo n.º 3
0
        public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players)
        {
            line = "U JiJiang 1: 2 3";
            Match m = Regex.Match(line, @"U\s(?<skill>[A-Za-z]*)(?<cards>(\s\d+)*):(?<players>(\s\d+)*)");

            skill   = null;
            cards   = null;
            players = null;
            if (m.Success)
            {
                if (m.Groups["skill"].Success)
                {
                    foreach (ISkill s in hostPlayer.Skills)
                    {
                        if (s is CardTransformSkill)
                        {
                        }
                        if (s is ActiveSkill)
                        {
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
        {
            line = "U JiJiang 1: 2 3";
            Match m = Regex.Match(line, @"U\s(?<skill>[A-Za-z]*)(?<cards>(\s\d+)*):(?<players>(\s\d+)*)");
            skill = null;
            cards = null;
            players = null;
            if (m.Success)
            {
                if (m.Groups["skill"].Success)
                {
                    foreach (ISkill s in hostPlayer.Skills)
                    {
                        if (s is CardTransformSkill)
                        {

                        }
                        if (s is ActiveSkill)
                        {
                        }
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 5
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players, out Player respondingPlayer)
 {
     cards = null;
     skill = null;
     players = null;
     respondingPlayer = null;
     return false;
 }
Ejemplo n.º 6
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players, out Player respondingPlayer)
 {
     cards            = null;
     skill            = null;
     players          = null;
     respondingPlayer = null;
     return(false);
 }
Ejemplo n.º 7
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players, out Player respondingPlayer)
 {
     this.prompt   = prompt;
     this.verifier = verifier;
     foreach (var inactiveProxy in inactiveProxies)
     {
         if (inactiveProxy.HostPlayer != null && !inactiveProxy.HostPlayer.IsDead)
         {
             inactiveProxy.TryAskForCardUsage(prompt, new NullVerifier());
         }
     }
     pendingUiThread = new Thread(AskUiThread)
     {
         IsBackground = true
     };
     pendingUiThread.Start();
     proxy.SimulateReplayDelay();
     if (!proxy.TryAnswerForCardUsage(prompt, verifier, out skill, out cards, out players))
     {
         cards   = new List <Card>();
         players = new List <Player>();
         skill   = null;
     }
     pendingUiThread.Abort();
     pendingUiThread = null;
     foreach (var otherProxy in inactiveProxies)
     {
         otherProxy.Freeze();
     }
     proxy.Freeze();
     proxy.NextQuestion();
     // try to determine who used this
     respondingPlayer = null;
     if (cards != null && cards.Count > 0)
     {
         respondingPlayer = cards[0].Place.Player;
     }
     else
     {
         foreach (var p in Game.CurrentGame.Players)
         {
             if (p.ActionableSkills.Contains(skill))
             {
                 respondingPlayer = p;
                 break;
             }
         }
     }
     if (skill != null || (cards != null && cards.Count > 0))
     {
         Trace.Assert(respondingPlayer != null);
     }
     if (verifier.Verify(respondingPlayer, skill, cards, players) == VerifierResult.Success)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 8
0
 public void AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, int timeOutSeconds)
 {
     CurrentQuestionState = QuestionState.AskForCardUsage;
     Gamer.ReceiveAsync();
     if (Gamer.OnlineStatus != OnlineStatus.Online)
     {
         AnswerCardUsage(null, null, null);
     }
 }
Ejemplo n.º 9
0
 protected bool AskForSkillUse(ICardUsageVerifier verifier, out List<Card> cards, out List<Player> players, Prompt prompt = null)
 {
     ISkill skill;
     if (prompt == null) prompt = new CardUsagePrompt(this.GetType().Name, this);
     var ret = Game.CurrentGame.UiProxies[Owner].AskForCardUsage(
             prompt, verifier, out skill, out cards, out players);
     Trace.Assert(skill == null);
     return ret;
 }
Ejemplo n.º 10
0
 public void AskForMultipleCardUsage(Prompt prompt, ICardUsageVerifier verifier, List <Player> players, out Dictionary <Player, ISkill> askill, out Dictionary <Player, List <Card> > acards, out Dictionary <Player, List <Player> > aplayers)
 {
     this.prompt   = prompt;
     this.verifier = verifier;
     foreach (var inactiveProxy in inactiveProxies)
     {
         if (players.Contains(inactiveProxy.HostPlayer))
         {
             inactiveProxy.TryAskForCardUsage(new CardUsagePrompt(""), new NullVerifier());
         }
     }
     pendingUiThread = new Thread(AskUiThread)
     {
         IsBackground = true
     };
     if (players.Contains(proxy.HostPlayer))
     {
         pendingUiThread = new Thread(AskUiThread)
         {
             IsBackground = true
         };
         pendingUiThread.Start();
     }
     proxy.SimulateReplayDelay();
     askill   = new Dictionary <Player, ISkill>();
     acards   = new Dictionary <Player, List <Card> >();
     aplayers = new Dictionary <Player, List <Player> >();
     foreach (var p in players)
     {
         ISkill        tempSkill;
         List <Card>   tempCards;
         List <Player> tempPlayers;
         if (!proxy.TryAnswerForCardUsage(prompt, verifier, out tempSkill, out tempCards, out tempPlayers))
         {
             tempCards   = new List <Card>();
             tempPlayers = new List <Player>();
             tempSkill   = null;
         }
         askill.Add(p, tempSkill);
         acards.Add(p, tempCards);
         aplayers.Add(p, tempPlayers);
     }
     if (players.Contains(proxy.HostPlayer))
     {
         pendingUiThread.Abort();
         proxy.Freeze();
         proxy.NextQuestion();
     }
     pendingUiThread = null;
     foreach (var otherProxy in inactiveProxies)
     {
         if (players.Contains(otherProxy.HostPlayer))
         {
             otherProxy.Freeze();
         }
     }
 }
Ejemplo n.º 11
0
 protected AutoNotifyUsagePassiveSkillTrigger(TriggerSkill skill, RelayTrigger innerTrigger, TriggerActionWithCardsAndPlayers execute, ICardUsageVerifier verifier)
 {
     AskForConfirmation = false;
     IsAutoNotify       = true;
     Skill        = skill;
     InnerTrigger = innerTrigger;
     Execute      = execute;
     Verifier     = verifier;
     base.Owner   = InnerTrigger.Owner;
 }
Ejemplo n.º 12
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players, out Player respondingPlayer)
 {
     this.prompt = prompt;
     this.verifier = verifier;
     foreach (var inactiveProxy in inactiveProxies)
     {
         if (inactiveProxy.HostPlayer != null && !inactiveProxy.HostPlayer.IsDead)
         {
             inactiveProxy.TryAskForCardUsage(prompt, new NullVerifier());
         }
     }
     pendingUiThread = new Thread(AskUiThread) { IsBackground = true };
     pendingUiThread.Start();
     proxy.SimulateReplayDelay();
     if (!proxy.TryAnswerForCardUsage(prompt, verifier, out skill, out cards, out players))
     {
         cards = new List<Card>();
         players = new List<Player>();
         skill = null;
     }
     pendingUiThread.Abort();
     pendingUiThread = null;
     foreach (var otherProxy in inactiveProxies)
     {
        otherProxy.Freeze();
     }
     proxy.Freeze();
     proxy.NextQuestion();
     // try to determine who used this
     respondingPlayer = null;
     if (cards != null && cards.Count > 0)
     {
         respondingPlayer = cards[0].Place.Player;
     }
     else
     {
         foreach (var p in Game.CurrentGame.Players)
         {
             if (p.ActionableSkills.Contains(skill))
             {
                 respondingPlayer = p;
                 break;
             }
         }
     }
     if (skill != null || (cards != null && cards.Count > 0))
     {
         Trace.Assert(respondingPlayer != null);
     }
     if (verifier.Verify(respondingPlayer, skill, cards, players) == VerifierResult.Success)
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 13
0
        protected bool AskForSkillUse(ICardUsageVerifier verifier, out List <Card> cards, out List <Player> players, Prompt prompt = null)
        {
            ISkill skill;

            if (prompt == null)
            {
                prompt = new CardUsagePrompt(this.GetType().Name, this);
            }
            var ret = Game.CurrentGame.UiProxies[Owner].AskForCardUsage(
                prompt, verifier, out skill, out cards, out players);

            Trace.Assert(skill == null);
            return(ret);
        }
Ejemplo n.º 14
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
 {
     answerPending = new Semaphore(0, 1);
     proxy.AskForCardUsage(prompt, verifier, TimeOutSeconds);
     skill = null;
     cards = null;
     players = null;
     if (answerPending.WaitOne(TimeOutSeconds * 1000))
     {
         skill = answerSkill;
         cards = answerCards;
         players = answerPlayers;
     }
     cards = cards ?? new List<Card>();
     players = players ?? new List<Player>();
     return (verifier.FastVerify(HostPlayer, answerSkill, cards, players) == VerifierResult.Success);
 }
Ejemplo n.º 15
0
        public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players)
        {
            answerPending = new Semaphore(0, 1);
            int timeOut = _GetActualTimeoutSecond(verifier.Helper);

            proxy.AskForCardUsage(prompt, verifier, timeOut);
            skill   = null;
            cards   = null;
            players = null;
            if (answerPending.WaitOne(timeOut * 1000 /* + GameDelays.UiDelayCompensation*/))
            {
                skill   = answerSkill;
                cards   = answerCards;
                players = answerPlayers;
            }
            cards   = cards ?? new List <Card>();
            players = players ?? new List <Player>();
            return(verifier.FastVerify(HostPlayer, answerSkill, cards, players) == VerifierResult.Success);
        }
Ejemplo n.º 16
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
 {
     Trace.TraceInformation("Asking Card Usage to {0}.", HostPlayer.Id);
     TryAskForCardUsage(prompt, verifier);
     if (active)
     {
         NextQuestion();
     }
     else
     {
         Trace.TraceInformation("Not active player, defaulting.");
     }
     if (TryAnswerForCardUsage(prompt, verifier, out skill, out cards, out players))
     {
         proxy.Freeze();
     #if DEBUG
         Trace.Assert(verifier.FastVerify(HostPlayer, skill, cards, players) == VerifierResult.Success);
     #endif
         return true;
     }
     proxy.Freeze();
     return false;
 }
Ejemplo n.º 17
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
 {
     bool ret = true;
     if (!TryAskForCardUsage(prompt, verifier, out skill, out cards, out players))
     {
         SendNoAnswer();
         ret = false;
     }
     else
     {
         SendCardUsage(skill, cards, players, verifier);
     }
     NextQuestion();
     if (cards == null)
     {
         cards = new List<Card>();
     }
     if (players == null)
     {
         players = new List<Player>();
     }
     return ret;
 }
Ejemplo n.º 18
0
        public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players)
        {
            bool ret = true;

            if (!TryAskForCardUsage(prompt, verifier, out skill, out cards, out players))
            {
                SendCardUsage(null, null, null, null);
                ret = false;
            }
            else
            {
                SendCardUsage(skill, cards, players, verifier);
            }
            NextQuestion();
            if (cards == null)
            {
                cards = new List <Card>();
            }
            if (players == null)
            {
                players = new List <Player>();
            }
            return(ret);
        }
Ejemplo n.º 19
0
        public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players)
        {
            Trace.TraceInformation("Asking Card Usage to {0}.", HostPlayer.Id);
            TryAskForCardUsage(prompt, verifier);
            SimulateReplayDelay();
            NextQuestion();
            if (TryAnswerForCardUsage(prompt, verifier, out skill, out cards, out players))
            {
                uiProxy.Freeze();
                if (skill == null && (cards == null || cards.Count == 0) && (players == null || players.Count == 0))
                {
                    return(false);
                }
#if DEBUG
                if (verifier.FastVerify(HostPlayer, skill, cards, players) != VerifierResult.Success)
                {
                    Trace.Assert(false);
                }
#endif
                return(true);
            }
            uiProxy.Freeze();
            return(false);
        }
Ejemplo n.º 20
0
 public AutoNotifyUsagePassiveSkillTrigger(TriggerSkill skill, TriggerActionWithCardsAndPlayers execute, TriggerCondition condition, ICardUsageVerifier verifier)
     : this(skill, new RelayTrigger(null, condition), execute, verifier)
 {
 }
Ejemplo n.º 21
0
        bool IUiProxy.AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
        {
            Player p = hostPlayer;
            Console.Write("I AM PLAYER {0}({1}): ", p.Id, p.Hero.Name);
            cards = new List<Card>();
            VerifierResult r = verifier.FastVerify(HostPlayer, null, null, null);
            skill = null;
            Console.Write("Ask for card usage, {0}: ", prompt);
            int i = 0;
            foreach (ICard card in Game.CurrentGame.Decks[p, DeckType.Hand])
            {
                Console.Write(" Card {0} {1}{2}{3}, ", i, card.Suit, card.Rank, card.Type.CardType);
                i++;
            }
            again:
            Console.Write("Card id, -1 to trigger");
            string ids = Console.ReadLine();
            if (ids == null) { Thread.Sleep(200); cards = null; players = null; return false; }
            int id = int.Parse(ids);
            if (id < -1)
            {
                cards = null;
                players = null;
            }
            else
            {
                if (id == -1)
                {
                    Console.Write("Skill ID:");
                    ids = Console.ReadLine();
                    id = int.Parse(ids);
                    if (id >= hostPlayer.Skills.Count || ((!(hostPlayer.Skills[id] is ActiveSkill)) && (!(hostPlayer.Skills[id] is CardTransformSkill))))
                    {
                        goto again;
                    }
                    skill = hostPlayer.Skills[id];
                    while (true)
                    {
                        Console.Write("Card id, -1 to end");
                        ids = Console.ReadLine();
                        id = int.Parse(ids);
                        if (id < 0)
                        {
                            break;
                        }
                        if (id >= Game.CurrentGame.Decks[p, DeckType.Hand].Count)
                        {
                            continue;
                        }
                        cards.Add(Game.CurrentGame.Decks[p, DeckType.Hand][id]);
                    }
                }
                else
                {
                    if (id < Game.CurrentGame.Decks[p, DeckType.Hand].Count)
                    {
                        cards.Add(Game.CurrentGame.Decks[p, DeckType.Hand][id]);
                    }
                }
                players = null;
                r = verifier.FastVerify(HostPlayer, skill, cards, players);
                if (r == VerifierResult.Success)
                {
                    return true;
                }
                if (r == VerifierResult.Fail)
                {
                    Console.Write("Failed check, again? 1 yes 0 no");
                    ids = Console.ReadLine();
                    id = int.Parse(ids);
                    if (id == 1)
                    {
                        goto again;
                    }
                }
            }
            {
                players = new List<Player>();
                while (true)
                {
                    Console.WriteLine("");
                    Console.Write("Target player: -1 to end");
                    ids = Console.ReadLine();
                    id = int.Parse(ids);
                    if (id < 0)
                    {
                        break;
                    }
                    if (id > Game.CurrentGame.Players.Count)
                    {
                        Console.WriteLine("out of range");
                    }
                    else
                    {
                        players.Add(Game.CurrentGame.Players[id]);
                    }
                    r = verifier.FastVerify(HostPlayer, skill, cards, players);
                    if (r == VerifierResult.Partial)
                    {
                        Console.WriteLine("Require more");
                    }
                    if (r == VerifierResult.Fail)
                    {
                        Console.WriteLine("Failed check");
                        players.Remove(Game.CurrentGame.Players[id]);
                    }
                }
                r = verifier.FastVerify(HostPlayer, skill, cards, players);
                if (r == VerifierResult.Success)
                {
                    return true;
                }
                if (r == VerifierResult.Fail)
                {
                    Console.Write("Failed check, again? 1 yes 0 no");
                    ids = Console.ReadLine();
                    id = int.Parse(ids);
                    if (id == 1)
                    {
                        goto again;
                    }
                }
                players = null;
                skill = null;
                cards = null;
                return false;

            }
        }
Ejemplo n.º 22
0
 public bool TryAskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
 {
     cards = null;
     skill = null;
     players = null;
     int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0);
     Trace.TraceInformation("Asking Card Usage to {0}, timeout {1}.", HostPlayer.Id, timeOut);
     int? count;
     if (!server.ExpectNext(clientId, timeOut))
     {
         return false;
     }
     count = server.GetInt(clientId, 0);
     if (count == null || count == 0)
     {
         return false;
     }
     if (count == null)
     {
         return false;
     }
     count = server.GetInt(clientId, 0);
     if (count == 1)
     {
         skill = server.GetSkill(clientId, 0);
         if (skill == null)
         {
             return false;
         }
         if (!(skill is CheatSkill) && !HostPlayer.ActionableSkills.Contains(skill))
         {
             Trace.TraceWarning("Client DDOS!");
             return false;
         }
     }
     count = server.GetInt(clientId, 0);
     if (count == null)
     {
         return false;
     }
     cards = new List<Card>();
     while (count-- > 0)
     {
         Card item = server.GetCard(clientId, 0);
         if (item == null)
         {
             return false;
         }
         if (item.Owner != HostPlayer)
         {
             if (!(verifier.Helper.OtherDecksUsed.Any(dc => dc == item.Place.DeckType) ||
                 (skill != null && skill.Helper.OtherDecksUsed.Any(dc => dc == item.Place.DeckType))))
             {
                 Trace.TraceWarning("Client hacking cards!");
                 return false;
             }
         }
         cards.Add(item);
     }
     count = server.GetInt(clientId, 0);
     if (count == null)
     {
         return false;
     }
     players = new List<Player>();
     while (count-- > 0)
     {
         Player item = server.GetPlayer(clientId, 0);
         if (item == null)
         {
             return false;
         }
         players.Add(item);
     }
     bool requireUnique = true;
     if (skill is ActiveSkill)
     {
         if ((skill as ActiveSkill).Helper != null && (skill as ActiveSkill).Helper.IsPlayerRepeatable) requireUnique = false;
     }
     if ((players != null && players.Distinct().Count() != players.Count && requireUnique) ||
         verifier.FastVerify(HostPlayer, skill, cards, players) != VerifierResult.Success)
     {
         Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?");
         cards = new List<Card>();
         skill = null;
         players = new List<Player>();
         return false;
     }
     return true;
 }
Ejemplo n.º 23
0
 public bool CheatGetSkill(string skillName)
 {
     lock (verifierLock)
     {
         if (currentUsageVerifier == null)
         {
             return false;
         }
         _ResetAll();
         if (currentUsageVerifier != null)
         {
             currentUsageVerifier = null;
             CardUsageAnsweredEvent(new CheatSkill() { CheatType = CheatType.Skill, SkillName = skillName }, new List<Card>(), new List<Player>());
         }
     }
     return true;
 }
Ejemplo n.º 24
0
 public void CancelCardUsageCommand(object parameter)
 {
     lock (verifierLock)
     {
         Trace.Assert(currentUsageVerifier != null);
         CardUsageAnsweredEvent(null, null, null);
         currentUsageVerifier = null;
         _ResetAll();
     }
 }
Ejemplo n.º 25
0
 public void AbortCardUsageCommand(object parameter)
 {
     lock (verifierLock)
     {
         if (currentUsageVerifier == null)
         {
             return;
         }
         Trace.Assert(currentUsageVerifier != null);
         CardUsageAnsweredEvent(null, null, null);
         currentUsageVerifier = null;
         _ResetAll();
     }
 }
Ejemplo n.º 26
0
        public void Freeze()
        {
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                lock (verifierLock)
                {
                    _ResetAll();

                    foreach (var skillCommand in SkillCommands)
                    {
                        if (skillCommand is GuHuoSkillCommand)
                        {
                            (skillCommand as GuHuoSkillCommand).GuHuoTypes.Clear();
                        }
                        skillCommand.IsHighlighted = false;
                    }

                    if (currentUsageVerifier != null)
                    {
                        currentUsageVerifier = null;
                    }
                    else if (IsCardChoiceQuestionShown)
                    {
                        _AbortCardChoice();
                    }
                    else if (IsMultiChoiceQuestionShown)
                    {
                        _AbortMultipleChoice();
                    }
                }
            });
        }
Ejemplo n.º 27
0
 public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
 {
     Trace.TraceInformation("Asking Card Usage to {0}.", HostPlayer.Id);
     TryAskForCardUsage(prompt, verifier);
     SimulateReplayDelay();
     NextQuestion();
     if (TryAnswerForCardUsage(prompt, verifier, out skill, out cards, out players))
     {
         uiProxy.Freeze();
         if (skill == null && (cards == null || cards.Count == 0) && (players == null || players.Count == 0))
         {
             return false;
         }
     #if DEBUG
         if (verifier.FastVerify(HostPlayer, skill, cards, players) != VerifierResult.Success)
         {
             Trace.Assert(false);
         }
     #endif
         return true;
     }
     uiProxy.Freeze();
     return false;
 }
Ejemplo n.º 28
0
 public AutoNotifyUsagePassiveSkillTrigger(TriggerSkill skill, TriggerActionWithCardsAndPlayers execute, TriggerCondition condition, ICardUsageVerifier verifier) :
     this(skill, new RelayTrigger(null, condition), execute, verifier)
 {
 }
Ejemplo n.º 29
0
 /// <summary>
 /// 询问使用或打出卡牌,可以发动技能。
 /// </summary>
 /// <param name="prompt"></param>
 /// <param name="verifier"></param>
 /// <param name="skill"></param>
 /// <param name="cards"></param>
 /// <param name="players"></param>
 /// <returns>False if user cannot provide an answer.</returns>
 public static bool AskForCardUsage(this Player p, Prompt prompt, ICardUsageVerifier verifier,
                                    out ISkill skill, out List <Card> cards, out List <Player> players)
 {
     return(Game.CurrentGame.UiProxies[p].AskForCardUsage(prompt, verifier, out skill, out cards, out players));
 }
Ejemplo n.º 30
0
        public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players, out Player respondingPlayer)
        {
            proxyListener = new Dictionary<Player, Thread>();
            semAccess = new Semaphore(1, 1);
            semWake = new Semaphore(0, 2);
            semDone = new Semaphore(Game.CurrentGame.AlivePlayers.Count - 1, Game.CurrentGame.AlivePlayers.Count - 1);
            answerSkill = null;
            answerCard = null;
            answerPlayer = null;
            respondingPlayer = null;
            foreach (var player in Game.CurrentGame.AlivePlayers)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                UsageListenerThreadParameters para = new UsageListenerThreadParameters();
                para.prompt = prompt;
                para.proxy = proxy[player];
                para.verifier = verifier;
                Thread t = new Thread(
                    (ParameterizedThreadStart)
                    ((p) => {
                        UsageProxyListenerThread((UsageListenerThreadParameters)p);
                    })) { IsBackground = true };
                t.Start(para);
                proxyListener.Add(player, t);
            }
            bool ret = true;
            if (!semWake.WaitOne(TimeOutSeconds * 1000))
            {
                semAccess.WaitOne(0);
                skill = null;
                cards = null;
                players = null;
                respondingPlayer = null;
                ret = false;
            }
            else
            {
                skill = answerSkill;
                cards = answerCard;
                players = answerPlayer;
                respondingPlayer = responder;
            }
            //if it didn't change, then semDone was triggered
            if (skill == null && cards == null && players == null)
            {
                ret = false;
            }
            if (cards == null) cards = new List<Card>();
            if (players == null) players = new List<Player>();
            foreach (var pair in proxyListener)
            {
                pair.Value.Abort();
                proxy[pair.Key].NextQuestion();
            }
            foreach (var player in Game.CurrentGame.Players)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                else
                {
                    proxy[player].SendCardUsage(skill, cards, players, verifier);
                    break;
                }
            }

            return ret;
        }
Ejemplo n.º 31
0
        public void AskForMultipleCardUsage(Prompt prompt, ICardUsageVerifier verifier, List<Player> players, out Dictionary<Player, ISkill> askill, out Dictionary<Player, List<Card>> acards, out Dictionary<Player, List<Player>> aplayers)
        {
            proxyListener = new Dictionary<Player, Thread>();
            semAccess = new Semaphore(1, 1);
            semWake = new Semaphore(0, 2);
            semDone = new Semaphore(players.Count - 1, players.Count - 1);
            manswerSkill = new Dictionary<Player,ISkill>();
            manswerCards = new Dictionary<Player,List<Card>>();
            manswerPlayers = new Dictionary<Player,List<Player>>();
            foreach (var player in players)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                UsageListenerThreadParameters para = new UsageListenerThreadParameters();
                para.player = player;
                para.prompt = prompt;
                para.proxy = proxy[player];
                para.verifier = verifier;
                Thread t = new Thread(
                    (ParameterizedThreadStart)
                    ((p) =>
                    {
                        MultiUsageProxyListenerThread((UsageListenerThreadParameters)p);
                    })) { IsBackground = true };
                t.Start(para);
                proxyListener.Add(player, t);
            }
            semWake.WaitOne(TimeOutSeconds * 1000);
            semAccess.WaitOne(100);

            foreach (var pair in proxyListener)
            {
                pair.Value.Abort();
                proxy[pair.Key].NextQuestion();
            }

            foreach (var player in players)
            {
                if (!manswerSkill.ContainsKey(player))
                {
                    manswerSkill.Add(player, null);
                }
                if (!manswerCards.ContainsKey(player))
                {
                    manswerCards.Add(player, new List<Card>());
                }
                if (!manswerPlayers.ContainsKey(player))
                {
                    manswerPlayers.Add(player, new List<Player>());
                }
            }

            foreach (var player in Game.CurrentGame.Players)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                else
                {
                    foreach (var p in players)
                    {
                        proxy[player].SendCardUsage(manswerSkill[p], manswerCards[p], manswerPlayers[p], verifier);
                    }
                    break;
                }
            }

            askill = manswerSkill;
            acards = manswerCards;
            aplayers = manswerPlayers;
        }
Ejemplo n.º 32
0
 public bool TryAnswerForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
 {
     skill = null;
     cards = new List<Card>();
     players = new List<Player>();
     object o = client.Receive();
     if (o == null)
     {
         return false;
     }
     if ((int)o == 0)
     {
         return false;
     }
     o = client.Receive();
     int count = (int)o;
     if (count == 1)
     {
         skill = (ISkill)client.Receive();
     }
     o = client.Receive();
     count = (int)o;
     while (count-- > 0)
     {
         o = client.Receive();
         cards.Add((Card)o);
     }
     o = client.Receive();
     count = (int)o;
     while (count-- > 0)
     {
         o = client.Receive();
         players.Add((Player)o);
     }
     return true;
 }
Ejemplo n.º 33
0
        public void AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, int timeOutSeconds)
        {
            if (ViewModelBase.IsDetached) return;
            Trace.Assert(!Player.IsDead);
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                GameModel.CurrentActivePlayer = this;
                TimeOutSeconds = timeOutSeconds;
                currentUsageVerifier = verifier;
                Trace.Assert(currentUsageVerifier != null);
                CurrentPrompt = prompt;
                CurrentPromptString = LogFormatter.Translate(prompt);

                if (prompt.Values.Count != 0 && prompt.Values[0] is TriggerSkill)
                {
                    var triggerSkill = (prompt.Values[0] as TriggerSkill);
                    foreach (var skill in SkillCommands)
                    {
                        if (skill.Skill is CardTransformSkill && (skill.Skill as CardTransformSkill).LinkedPassiveSkill != triggerSkill) continue;
                        if (skill.Skill is ActiveSkill && (skill.Skill as ActiveSkill).LinkedPassiveSkill != triggerSkill) continue;
                        if (skill.Skill is TriggerSkill && skill.Skill != triggerSkill) continue;
                        skill.IsHighlighted = true;
                        break;
                    }
                }

                if (verifier != null)
                {
                    foreach (var skillCommand in ActiveSkillCommands)
                    {
                        skillCommand.IsEnabled = (currentUsageVerifier.Verify(HostPlayer, skillCommand.Skill, new List<Card>(), new List<Player>()) != VerifierResult.Fail);
                    }

                    if (verifier.Helper != null &&
                    verifier.Helper.OtherDecksUsed != null && verifier.Helper.OtherDecksUsed.Count != 0)
                    {
                        var helper = verifier.Helper;
                        if (helper.OtherDecksUsed.Count > 0)
                        {
                            if (helper.OtherDecksUsed.Count != 1)
                            {
                                throw new NotImplementedException("Currently using more than one private decks is not supported");
                            }
                            var deck = helper.OtherDecksUsed[0];
                            var deckModel = PrivateDecks.FirstOrDefault(d => d.Name == deck.Name);
                            Trace.Assert(deckModel != null);
                            if (deckModel != CurrentSpecialDeck)
                            {
                                if (CurrentSpecialDeck != null)
                                {
                                    foreach (var card in CurrentSpecialDeck.Cards)
                                    {
                                        card.IsSelectionMode = false;
                                        card.OnSelectedChanged -= _OnCardSelected;
                                    }
                                }
                                foreach (var card in deckModel.Cards)
                                {
                                    card.IsSelectionMode = IsPlayable;
                                    card.OnSelectedChanged += _OnCardSelected;
                                }
                                CurrentSpecialDeck = deckModel;
                            }
                        }
                    }
                }

                if (!IsPlayable)
                {
                    TimeOutSeconds = timeOutSeconds;
                    CardUsageAnsweredEvent(null, null, null);
                    return;
                }

                foreach (var equipCommand in EquipCommands)
                {
                    equipCommand.OnSelectedChanged += _OnCardUsageSelectionChanged;
                    equipCommand.IsSelectionMode = true;
                }

                foreach (var card in HandCards)
                {
                    card.IsSelectionMode = true;
                    card.OnSelectedChanged += _OnCardSelected;
                }

                foreach (var playerModel in _game.PlayerModels)
                {
                    playerModel.IsSelectionMode = true;
                    playerModel.IsSelectionRepeatable = verifier.Helper.IsPlayerRepeatable;
                    playerModel.OnSelectedChanged += _OnCardUsageSelectionChanged;
                }

                foreach (var skillCommand in ActiveSkillCommands)
                {
                    if (skillCommand is GuHuoSkillCommand)
                    {
                        (skillCommand as GuHuoSkillCommand).GuHuoChoice = null;
                    }
                    skillCommand.OnSelectedChanged += _OnSkillCommandSelected;
                }

                if (verifier.AcceptableCardTypes != null)
                {
                    var defaultCard = HandCards.FirstOrDefault(c =>
                        verifier.Verify(HostPlayer, null, new List<Card>() { c.Card }, new List<Player>()) == VerifierResult.Success);
                    if (defaultCard != null)
                    {
                        defaultCard.IsSelected = true;
                    }
                }

                // @todo: update this.
                SubmitAnswerCommand = submitCardUsageCommand;
                CancelAnswerCommand = cancelCardUsageCommand;
                AbortAnswerCommand = abortCardUsageCommand;
                abortCardUsageCommand.CanExecuteStatus = currentUsageVerifier.Helper.IsActionStage;
                cancelCardUsageCommand.CanExecuteStatus = !currentUsageVerifier.Helper.IsActionStage;

                _UpdateCardUsageStatus();
            });
        }
Ejemplo n.º 34
0
 protected AutoNotifyUsagePassiveSkillTrigger(TriggerSkill skill, RelayTrigger innerTrigger, TriggerActionWithCardsAndPlayers execute, ICardUsageVerifier verifier)
 {
     AskForConfirmation = false;
     IsAutoNotify = true;
     Skill = skill;
     InnerTrigger = innerTrigger;
     Execute = execute;
     Verifier = verifier;
     base.Owner = InnerTrigger.Owner;
 }
Ejemplo n.º 35
0
 public void SendCardUsage(ISkill skill, List <Card> cards, List <Player> players, ICardUsageVerifier verifier)
 {
     for (int i = 0; i < server.MaxClients; i++)
     {
         if (cards != null)
         {
             foreach (var c in cards)
             {
                 if (!(skill != null && skill.Helper.NoCardReveal) && !(verifier.Helper.NoCardReveal))
                 {
                     if (c.Place.DeckType != DeckType.Equipment && c.Place.DeckType != DeckType.DelayedTools)
                     {
                         c.RevealOnce = true;
                     }
                 }
                 if (c.Place.DeckType == DeckType.Equipment || c.Place.DeckType == DeckType.DelayedTools)
                 {
                     c.RevealOnce = false;
                 }
             }
         }
         server.SendPacket(i, AskForCardUsageResponse.Parse(proxy.QuestionId, skill, cards, players, i));
     }
 }
        public bool AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players, out Player respondingPlayer)
        {
            Trace.Assert(Game.CurrentGame.AlivePlayers.Count > 1);
            proxyListener    = new Dictionary <Player, Thread>();
            semAccess        = new Semaphore(1, 1);
            semWake          = new Semaphore(0, 2);
            semDone          = new Semaphore(Game.CurrentGame.AlivePlayers.Count - 1, Game.CurrentGame.AlivePlayers.Count - 1);
            answerSkill      = null;
            answerCard       = null;
            answerPlayer     = null;
            respondingPlayer = null;
            foreach (var player in Game.CurrentGame.AlivePlayers)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                UsageListenerThreadParameters para = new UsageListenerThreadParameters();
                para.prompt   = prompt;
                para.proxy    = proxy[player];
                para.verifier = verifier;
                Thread t = new Thread(
                    (ParameterizedThreadStart)
                    ((p) => {
                    UsageProxyListenerThread((UsageListenerThreadParameters)p);
                }))
                {
                    IsBackground = true
                };
                t.Start(para);
                proxyListener.Add(player, t);
            }
            bool ret = true;

            if (!semWake.WaitOne(TimeOutSeconds * 1000))
            {
                semAccess.WaitOne(0);
                skill            = null;
                cards            = null;
                players          = null;
                respondingPlayer = null;
                ret = false;
            }
            else
            {
                skill            = answerSkill;
                cards            = answerCard;
                players          = answerPlayer;
                respondingPlayer = responder;
            }
            //if it didn't change, then semDone was triggered
            if (skill == null && cards == null && players == null)
            {
                ret = false;
            }
            if (cards == null)
            {
                cards = new List <Card>();
            }
            if (players == null)
            {
                players = new List <Player>();
            }
            foreach (var pair in proxyListener)
            {
                pair.Value.Abort();
                proxy[pair.Key].NextQuestion();
            }
            foreach (var player in Game.CurrentGame.Players)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                else
                {
                    proxy[player].SendCardUsage(skill, cards, players, verifier);
                    break;
                }
            }

            return(ret);
        }
Ejemplo n.º 37
0
        public void SubmitCardUsageCommand(object parameter)
        {
            List<Card> cards = _GetSelectedNonEquipCards();
            List<Player> players = _GetSelectedPlayers();
            ISkill skill = null;
            bool isEquipSkill;
            SkillCommand skillCommand = _GetSelectedSkillCommand(out isEquipSkill);

            if (skillCommand != null)
            {
                skill = skillCommand.Skill;
            }

            // are we really able to use this equip as command?
            if (isEquipSkill)
            {
                Trace.Assert(skill != null);
                if (currentUsageVerifier.Verify(HostPlayer, skill, new List<Card>(), new List<Player>()) == VerifierResult.Fail)
                {
                    //nope, not really
                    isEquipSkill = false;
                    skill = null;
                }
            }

            foreach (var equipCommand in EquipCommands)
            {
                if (!isEquipSkill && equipCommand.IsSelected)
                {
                    cards.Add(equipCommand.Card);
                }
            }

            // Card usage question
            lock (verifierLock)
            {
                _ResetAll();
                if (currentUsageVerifier != null)
                {
                    currentUsageVerifier = null;
                    CardUsageAnsweredEvent(skill, cards, players);
                }
            }
        }
Ejemplo n.º 38
0
 public void AskForMultipleCardUsage(Prompt prompt, ICardUsageVerifier verifier, List<Player> players, out Dictionary<Player, ISkill> askill, out Dictionary<Player, List<Card>> acards, out Dictionary<Player, List<Player>> aplayers)
 {
     this.prompt = prompt;
     this.verifier = verifier;
     foreach (var inactiveProxy in inactiveProxies)
     {
         if (players.Contains(inactiveProxy.HostPlayer))
         {
             inactiveProxy.TryAskForCardUsage(new CardUsagePrompt(""), new NullVerifier());
         }
     }
     pendingUiThread = new Thread(AskUiThread) { IsBackground = true };
     if (players.Contains(proxy.HostPlayer))
     {
         pendingUiThread = new Thread(AskUiThread) { IsBackground = true };
         pendingUiThread.Start();
     }
     proxy.SimulateReplayDelay();
     askill = new Dictionary<Player, ISkill>();
     acards = new Dictionary<Player, List<Card>>();
     aplayers = new Dictionary<Player, List<Player>>();
     foreach (var p in players)
     {
         ISkill tempSkill;
         List<Card> tempCards;
         List<Player> tempPlayers;
         if (!proxy.TryAnswerForCardUsage(prompt, verifier, out tempSkill, out tempCards, out tempPlayers))
         {
             tempCards = new List<Card>();
             tempPlayers = new List<Player>();
             tempSkill = null;
         }
         askill.Add(p, tempSkill);
         acards.Add(p, tempCards);
         aplayers.Add(p, tempPlayers);
     }
     if (players.Contains(proxy.HostPlayer))
     {
         pendingUiThread.Abort();
         proxy.Freeze();
         proxy.NextQuestion();
     }
     pendingUiThread = null;
     foreach (var otherProxy in inactiveProxies)
     {
         if (players.Contains(otherProxy.HostPlayer))
         {
             otherProxy.Freeze();
         }
     }
 }
Ejemplo n.º 39
0
        public void AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, int timeOutSeconds)
        {
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                GameModel.CurrentActivePlayer = this;
                lock (verifierLock)
                {
                    TimeOutSeconds = timeOutSeconds;
                    currentUsageVerifier = verifier;
                    Trace.Assert(currentUsageVerifier != null);
                    CurrentPrompt = prompt;
                    CurrentPromptString = PromptFormatter.Format(prompt);
                }

                if (verifier != null && verifier.Helper != null &&
                    verifier.Helper.OtherDecksUsed != null && verifier.Helper.OtherDecksUsed.Count != 0)
                {
                    var helper = verifier.Helper;
                    if (helper.OtherDecksUsed.Count > 0)
                    {
                        if (helper.OtherDecksUsed.Count != 1)
                        {
                            throw new NotImplementedException("Currently using more than one private decks is not supported");
                        }
                        var deck = helper.OtherDecksUsed[0];
                        var deckModel = PrivateDecks.FirstOrDefault(d => d.Name == deck.Name);
                        Trace.Assert(deckModel != null);
                        if (deckModel != CurrentPrivateDeck)
                        {
                            if (CurrentPrivateDeck != null)
                            {
                                foreach (var card in CurrentPrivateDeck.Cards)
                                {
                                    card.IsSelectionMode = false;
                                    card.OnSelectedChanged -= _updateCardUsageStatusHandler;
                                }
                            }
                            foreach (var card in deckModel.Cards)
                            {
                                card.IsSelectionMode = IsPlayable;
                                card.OnSelectedChanged += _updateCardUsageStatusHandler;
                            }
                            CurrentPrivateDeck = deckModel;
                        }
                    }
                }

                if (!IsPlayable)
                {
                    TimeOutSeconds = timeOutSeconds;
                    CardUsageAnsweredEvent(null, null, null);
                    return;
                }

                foreach (var equipCommand in EquipCommands)
                {
                    equipCommand.OnSelectedChanged += _updateCardUsageStatusHandler;
                    equipCommand.IsSelectionMode = true;
                }

                foreach (var card in HandCards)
                {
                    card.IsSelectionMode = true;
                    card.OnSelectedChanged += _updateCardUsageStatusHandler;
                }

                foreach (var playerModel in _game.PlayerModels)
                {
                    playerModel.IsSelectionMode = true;
                    playerModel.IsSelectionRepeatable = verifier.Helper.IsPlayerRepeatable;
                    playerModel.OnSelectedChanged += _updateCardUsageStatusHandler;
                }

                foreach (var skillCommand in ActiveSkillCommands)
                {
                    if (skillCommand is GuHuoSkillCommand)
                    {
                        (skillCommand as GuHuoSkillCommand).GuHuoChoice = null;
                    }
                    skillCommand.OnSelectedChanged += _updateCardUsageStatusHandler;
                }

                // @todo: update this.
                SubmitAnswerCommand = submitCardUsageCommand;
                CancelAnswerCommand = cancelCardUsageCommand;
                AbortAnswerCommand = abortCardUsageCommand;
                abortCardUsageCommand.CanExecuteStatus = currentUsageVerifier.Helper.IsActionStage;
                cancelCardUsageCommand.CanExecuteStatus = !currentUsageVerifier.Helper.IsActionStage;

                _UpdateCardUsageStatus();
            });
        }
Ejemplo n.º 40
0
        public bool TryAskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players)
        {
            cards   = null;
            skill   = null;
            players = null;
            int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0);

            Trace.TraceInformation("Asking Card Usage to {0}, timeout {1}.", HostPlayer.Id, timeOut);
            var answerReady = new Semaphore(0, Int16.MaxValue);
            CardUsageAnsweredEventHandler handler = (s, c, p) =>
            {
                skillAnswer   = s;
                cardsAnswer   = c;
                playersAnswer = p;
                answerReady.Release(1);
            };

            proxy.CardUsageAnsweredEvent += handler;
            proxy.AskForCardUsage(prompt, verifier, timeOut);
            bool noAnswer = false;

            if (!answerReady.WaitOne(timeOut * 1000))
            {
                noAnswer = true;
            }
            proxy.CardUsageAnsweredEvent -= handler;
            proxy.Freeze();
            if (noAnswer)
            {
                return(false);
            }

            skill   = skillAnswer;
            cards   = cardsAnswer;
            players = playersAnswer;

            if (skill != null && !(skill is CheatSkill) && !HostPlayer.ActionableSkills.Contains(skill))
            {
                Trace.TraceWarning("Client DDOS!");
                return(false);
            }
            if (cards != null)
            {
                foreach (var item in cards)
                {
                    if (item == null)
                    {
                        return(false);
                    }
                    if (item.Owner != HostPlayer)
                    {
                        if (!(verifier.Helper.OtherDecksUsed.Any(dc => dc == item.Place.DeckType) ||
                              (skill != null && skill.Helper.OtherDecksUsed.Any(dc => dc == item.Place.DeckType)) ||
                              (verifier.Helper.OtherGlobalCardDeckUsed.Any(dc => dc.Key.Player == item.Place.Player && dc.Key.DeckType == item.Place.DeckType)) ||
                              (skill != null && skill.Helper.OtherGlobalCardDeckUsed.Any(dc => dc.Key.Player == item.Place.Player && dc.Key.DeckType == item.Place.DeckType))))
                        {
                            Trace.TraceWarning("Client hacking cards!");
                            return(false);
                        }
                    }
                }
            }
            else
            {
                cards = new List <Card>();
            }
            if (players != null)
            {
                foreach (var item in players)
                {
                    if (item == null)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                players = new List <Player>();
            }
            bool requireUnique = true;

            if (skill is ActiveSkill)
            {
                if ((skill as ActiveSkill).Helper != null && (skill as ActiveSkill).Helper.IsPlayerRepeatable)
                {
                    requireUnique = false;
                }
            }
            if ((players != null && players.Distinct().Count() != players.Count && requireUnique) ||
                verifier.FastVerify(HostPlayer, skill, cards, players) != VerifierResult.Success)
            {
                Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?");
                cards   = new List <Card>();
                skill   = null;
                players = new List <Player>();
                return(false);
            }
            return(true);
        }
Ejemplo n.º 41
0
 public bool CheatGetCard(Card card)
 {
     lock (verifierLock)
     {
         if (currentUsageVerifier == null)
         {
             return false;
         }
         _ResetAll();
         if (currentUsageVerifier != null)
         {
             currentUsageVerifier = null;
             CardUsageAnsweredEvent(new CheatSkill() { CheatType = CheatType.Card, CardId = card.Id }, new List<Card>(), new List<Player>());
         }
     }
     return true;
 }
        public void AskForMultipleCardUsage(Prompt prompt, ICardUsageVerifier verifier, List <Player> players, out Dictionary <Player, ISkill> askill, out Dictionary <Player, List <Card> > acards, out Dictionary <Player, List <Player> > aplayers)
        {
            proxyListener  = new Dictionary <Player, Thread>();
            semAccess      = new Semaphore(1, 1);
            semWake        = new Semaphore(0, 2);
            semDone        = new Semaphore(players.Count - 1, players.Count - 1);
            manswerSkill   = new Dictionary <Player, ISkill>();
            manswerCards   = new Dictionary <Player, List <Card> >();
            manswerPlayers = new Dictionary <Player, List <Player> >();
            foreach (var player in players)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                UsageListenerThreadParameters para = new UsageListenerThreadParameters();
                para.player   = player;
                para.prompt   = prompt;
                para.proxy    = proxy[player];
                para.verifier = verifier;
                Thread t = new Thread(
                    (ParameterizedThreadStart)
                    ((p) =>
                {
                    MultiUsageProxyListenerThread((UsageListenerThreadParameters)p);
                }))
                {
                    IsBackground = true
                };
                t.Start(para);
                proxyListener.Add(player, t);
            }
            semWake.WaitOne(TimeOutSeconds * 1000);
            semAccess.WaitOne(100);

            foreach (var pair in proxyListener)
            {
                pair.Value.Abort();
                proxy[pair.Key].NextQuestion();
            }

            foreach (var player in players)
            {
                if (!manswerSkill.ContainsKey(player))
                {
                    manswerSkill.Add(player, null);
                }
                if (!manswerCards.ContainsKey(player))
                {
                    manswerCards.Add(player, new List <Card>());
                }
                if (!manswerPlayers.ContainsKey(player))
                {
                    manswerPlayers.Add(player, new List <Player>());
                }
            }

            foreach (var player in Game.CurrentGame.Players)
            {
                if (!proxy.ContainsKey(player))
                {
                    continue;
                }
                else
                {
                    foreach (var p in players)
                    {
                        proxy[player].SendCardUsage(manswerSkill[p], manswerCards[p], manswerPlayers[p], verifier);
                    }
                    break;
                }
            }

            askill   = manswerSkill;
            acards   = manswerCards;
            aplayers = manswerPlayers;
        }
Ejemplo n.º 43
0
 public void SendCardUsage(ISkill skill, List<Card> cards, List<Player> players, ICardUsageVerifier verifier)
 {
     for (int i = 0; i < server.MaxClients; i++)
     {
         server.SendObject(i, 1);
         if (skill != null)
         {
             server.SendObject(i, 1);
             server.SendObject(i, skill);
         }
         else
         {
             server.SendObject(i, 0);
         }
         if (cards != null)
         {
             server.SendObject(i, cards.Count);
             foreach (Card c in cards)
             {
                 if (!(skill != null && skill.Helper.NoCardReveal) && !(verifier.Helper.NoCardReveal))
                 {
                     if (c.Place.DeckType != DeckType.Equipment && c.Place.DeckType != DeckType.DelayedTools)
                     {
                         c.RevealOnce = true;
                     }
                 }
                 if (c.Place.DeckType == DeckType.Equipment || c.Place.DeckType == DeckType.DelayedTools)
                 {
                     c.RevealOnce = false;
                 }
                 server.SendObject(i, c);
             }
         }
         else
         {
             server.SendObject(i, 0);
         }
         if (players != null)
         {
             server.SendObject(i, players.Count);
             foreach (Player p in players)
             {
                 server.SendObject(i, p);
             }
         }
         else
         {
             server.SendObject(i, 0);
         }
         server.Flush(i);
     }
 }
Ejemplo n.º 44
0
 public void AskForMultipleCardUsage(Prompt prompt, ICardUsageVerifier verifier, List <Player> players, out Dictionary <Player, ISkill> askill, out Dictionary <Player, List <Card> > acards, out Dictionary <Player, List <Player> > aplayers)
 {
     acards   = new Dictionary <Player, List <Card> >();
     aplayers = new Dictionary <Player, List <Player> >();
     askill   = new Dictionary <Player, ISkill>();
 }
Ejemplo n.º 45
0
 public void AskForMultipleCardUsage(Prompt prompt, ICardUsageVerifier verifier, List<Player> players, out Dictionary<Player, ISkill> askill, out Dictionary<Player, List<Card>> acards, out Dictionary<Player, List<Player>> aplayers)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 46
0
 public void TryAskForCardUsage(Prompt prompt, ICardUsageVerifier verifier)
 {
     ISkill skill;
     List<Card> cards;
     List<Player> players;
     if (!active)
     {
         proxy.AskForCardUsage(prompt, verifier, out skill, out cards, out players);
         return;
     }
     if (!proxy.AskForCardUsage(prompt, verifier, out skill, out cards, out players))
     {
         Trace.TraceInformation("Invalid answer");
         client.AnswerNext();
         client.AnswerItem(0);
     }
     else
     {
         client.AnswerNext();
         client.AnswerItem(1);
         if (skill == null)
         {
             client.AnswerItem(0);
         }
         else
         {
             client.AnswerItem(1);
             client.AnswerItem(skill);
         }
         if (cards == null)
         {
             client.AnswerItem(0);
         }
         else
         {
             client.AnswerItem(cards.Count);
             foreach (Card c in cards)
             {
                 client.AnswerItem(c);
             }
         }
         if (players == null)
         {
             client.AnswerItem(0);
         }
         else
         {
             client.AnswerItem(players.Count);
             foreach (Player p in players)
             {
                 client.AnswerItem(p);
             }
         }
     }
     client.Flush();
 }
Ejemplo n.º 47
0
 public bool TryAnswerForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List<Card> cards, out List<Player> players)
 {
     object o = client.Receive();
     (o as AskForCardUsageResponse).ToAnswer(out skill, out cards, out players, client.SelfId);
     return true;
 }
Ejemplo n.º 48
0
        public void SubmitCardUsageCommand(object parameter)
        {
            List<Card> cards = _GetSelectedNonEquipCards();
            List<Player> players = _GetSelectedPlayers();
            ISkill skill = null;
            bool isEquipSkill;
            SkillCommand skillCommand = _GetSelectedSkillCommand(out isEquipSkill);

            if (skillCommand != null)
            {
                skill = skillCommand.Skill;
            }

            // are we really able to use this equip as command?
            if (isEquipSkill)
            {
                Trace.Assert(skill != null);
                if (currentUsageVerifier.Verify(HostPlayer, skill, new List<Card>(), new List<Player>()) == VerifierResult.Fail)
                {
                    //nope, not really
                    isEquipSkill = false;
                    skill = null;
                }
            }

            foreach (var equipCommand in EquipCommands)
            {
                if (!isEquipSkill && equipCommand.IsSelected)
                {
                    cards.Add(equipCommand.Card);
                }
            }

            // Card usage question
            var guHuoSkill = skill as IAdditionalTypedSkill;
            if (guHuoSkill != null)
            {
                // Reset all will also clear the GuHuoChoice recorded. So restore it after resetting the buttons.
                var backup = guHuoSkill.AdditionalType;
                _ResetAll();
                guHuoSkill.AdditionalType = backup;
            }
            else
            {
                _ResetAll();
            }
            if (currentUsageVerifier != null)
            {
                currentUsageVerifier = null;
                CardUsageAnsweredEvent(skill, cards, players);
            }
        }
Ejemplo n.º 49
0
 public void TryAskForCardUsage(Prompt prompt, ICardUsageVerifier verifier)
 {
     ISkill skill;
     List<Card> cards;
     List<Player> players;
     if (!IsPlayable)
     {
         if (IsUiDetached) return;
         uiProxy.AskForCardUsage(prompt, verifier, out skill, out cards, out players);
         return;
     }
     if (IsUiDetached || !uiProxy.AskForCardUsage(prompt, verifier, out skill, out cards, out players))
     {
         Trace.TraceInformation("Invalid answer");
         client.Send(AskForCardUsageResponse.Parse(numQuestionsAsked, null, null, null, client.SelfId));
     }
     else
     {
         client.Send(AskForCardUsageResponse.Parse(numQuestionsAsked, skill, cards, players, client.SelfId));
     }
 }
Ejemplo n.º 50
0
        bool IPlayerProxy.AskForCardUsage(Prompt prompt, ICardUsageVerifier verifier, out ISkill skill, out List <Card> cards, out List <Player> players)
        {
            Player p = hostPlayer;

            Console.Write("I AM PLAYER {0}({1}): ", p.Id, p.Hero.Name);
            cards = new List <Card>();
            VerifierResult r = verifier.FastVerify(HostPlayer, null, null, null);

            skill = null;
            Console.Write("Ask for card usage, {0}: ", prompt);
            int i = 0;

            foreach (ICard card in Game.CurrentGame.Decks[p, DeckType.Hand])
            {
                Console.Write(" Card {0} {1}{2}{3}, ", i, card.Suit, card.Rank, card.Type.Name);
                i++;
            }
again:
            Console.Write("Card id, -1 to trigger");
            string ids = Console.ReadLine();

            if (ids == null)
            {
                Thread.Sleep(200); cards = null; players = null; return(false);
            }
            int id = int.Parse(ids);

            if (id < -1)
            {
                cards   = null;
                players = null;
            }
            else
            {
                if (id == -1)
                {
                    Console.Write("Skill ID:");
                    ids = Console.ReadLine();
                    id  = int.Parse(ids);
                    if (id >= hostPlayer.Skills.Count || ((!(hostPlayer.Skills[id] is ActiveSkill)) && (!(hostPlayer.Skills[id] is CardTransformSkill))))
                    {
                        goto again;
                    }
                    skill = hostPlayer.Skills[id];
                    while (true)
                    {
                        Console.Write("Card id, -1 to end");
                        ids = Console.ReadLine();
                        id  = int.Parse(ids);
                        if (id < 0)
                        {
                            break;
                        }
                        if (id >= Game.CurrentGame.Decks[p, DeckType.Hand].Count)
                        {
                            continue;
                        }
                        cards.Add(Game.CurrentGame.Decks[p, DeckType.Hand][id]);
                    }
                }
                else
                {
                    if (id < Game.CurrentGame.Decks[p, DeckType.Hand].Count)
                    {
                        cards.Add(Game.CurrentGame.Decks[p, DeckType.Hand][id]);
                    }
                }
                players = null;
                r       = verifier.FastVerify(HostPlayer, skill, cards, players);
                if (r == VerifierResult.Success)
                {
                    return(true);
                }
                if (r == VerifierResult.Fail)
                {
                    Console.Write("Failed check, again? 1 yes 0 no");
                    ids = Console.ReadLine();
                    id  = int.Parse(ids);
                    if (id == 1)
                    {
                        goto again;
                    }
                }
            }
            {
                players = new List <Player>();
                while (true)
                {
                    Console.WriteLine("");
                    Console.Write("Target player: -1 to end");
                    ids = Console.ReadLine();
                    id  = int.Parse(ids);
                    if (id < 0)
                    {
                        break;
                    }
                    if (id > Game.CurrentGame.Players.Count)
                    {
                        Console.WriteLine("out of range");
                    }
                    else
                    {
                        players.Add(Game.CurrentGame.Players[id]);
                    }
                    r = verifier.FastVerify(HostPlayer, skill, cards, players);
                    if (r == VerifierResult.Partial)
                    {
                        Console.WriteLine("Require more");
                    }
                    if (r == VerifierResult.Fail)
                    {
                        Console.WriteLine("Failed check");
                        players.Remove(Game.CurrentGame.Players[id]);
                    }
                }
                r = verifier.FastVerify(HostPlayer, skill, cards, players);
                if (r == VerifierResult.Success)
                {
                    return(true);
                }
                if (r == VerifierResult.Fail)
                {
                    Console.Write("Failed check, again? 1 yes 0 no");
                    ids = Console.ReadLine();
                    id  = int.Parse(ids);
                    if (id == 1)
                    {
                        goto again;
                    }
                }
                players = null;
                skill   = null;
                cards   = null;
                return(false);
            }
        }