public void SendCardChoice(ICardChoiceVerifier verifier, List <List <Card> > answer, AdditionalCardChoiceOptions options) { for (int i = 0; i < server.MaxClients; i++) { int j = 0; if (answer != null) { foreach (var cards in answer) { foreach (Card c in cards) { if (verifier.Helper != null && (verifier.Helper.RevealCards || (verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy != null && verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy[j]))) { if (c.Place.DeckType != DeckType.Equipment && c.Place.DeckType != DeckType.DelayedTools) { c.RevealOnce = true; } } } j++; } } server.SendPacket(i, AskForCardChoiceResponse.Parse(proxy.QuestionId, answer, options == null? 0 : options.OptionResult, i)); } }
/// <summary> /// 询问用户从若干牌堆中选择卡牌,例如顺手牵羊,观星等等。 /// </summary> /// <param name="prompt"></param> /// <param name="sourceDecks"></param> /// <param name="resultDeckNames"></param> /// <param name="resultDeckMaximums"></param> /// <param name="verifier"></param> /// <param name="answer">用户选择结果。对应resultDeckNames,每个选出的牌堆占用一个list。</param> /// <returns>False if user cannot provide an answer.</returns> public static bool AskForCardChoice(this Player p, Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions helper = null, CardChoiceRearrangeCallback callback = null) { return Game.CurrentGame.UiProxies[p].AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, helper, callback); }
/// <summary> /// 询问用户从若干牌堆中选择卡牌,例如顺手牵羊,观星等等。 /// </summary> /// <param name="prompt"></param> /// <param name="sourceDecks"></param> /// <param name="resultDeckNames"></param> /// <param name="resultDeckMaximums"></param> /// <param name="verifier"></param> /// <param name="answer">用户选择结果。对应resultDeckNames,每个选出的牌堆占用一个list。</param> /// <returns>False if user cannot provide an answer.</returns> public static bool AskForCardChoice(this Player p, Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions helper = null, CardChoiceRearrangeCallback callback = null) { return(Game.CurrentGame.UiProxies[p].AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, helper, callback)); }
public bool TryAnswerForCardChoice(Prompt prompt, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { object o = client.Receive(); int opt; answer = (o as AskForCardChoiceResponse).ToAnswer(client.SelfId, out opt); if (options != null) { options.OptionResult = opt; } return(true); }
public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback) { answerPending = new Semaphore(0, 1); proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, TimeOutSeconds, rearrangeable, ref windowId, callback); if (answerPending.WaitOne(TimeOutSeconds * 1000)) { answer = answerCardsOfCards; } else { answer = null; } if (verifier.Verify(answer) == VerifierResult.Success) { return true; } return false; }
public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answerPending = new Semaphore(0, 1); proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, TimeOutSeconds, options, callback); answer = null; if (answerPending.WaitOne(TimeOutSeconds * 1000)) { answer = answerCardsOfCards; } if (answer == null) { return false; } else { return (verifier.Verify(answer) == VerifierResult.Success); } }
public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options = null, CardChoiceRearrangeCallback callback = null) { Trace.TraceInformation("Asking Card Choice to {0}.", HostPlayer.Id); TryAskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, options, callback); SimulateReplayDelay(); NextQuestion(); if (TryAnswerForCardChoice(prompt, verifier, out answer, options, callback)) { uiProxy.Freeze(); if (answer == null || answer.Count == 0) { return false; } #if DEBUG Trace.Assert(verifier.Verify(answer) == VerifierResult.Success); #endif return true; } uiProxy.Freeze(); return false; }
public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback) { Trace.TraceInformation("Asking Card Choice to {0}.", HostPlayer.Id); TryAskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, rearrangeable, ref windowId, callback); if (active) { NextQuestion(); } else { Trace.TraceInformation("Not active player, defaulting."); } if (TryAnswerForCardChoice(prompt, verifier, out answer, callback)) { proxy.Freeze(); #if DEBUG Trace.Assert(verifier.Verify(answer) == VerifierResult.Success); #endif return true; } proxy.Freeze(); return false; }
public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; bool ret = true; if (!TryAskForCardChoice(sourceDecks, resultDeckMaximums, verifier, out answer, options, callback)) { SendNoAnswer(); ret = false; } else { SendCardChoice(verifier, answer, options); } NextQuestion(); if (answer == null) { answer = new List<List<Card>>(); foreach (var v in resultDeckMaximums) { answer.Add(new List<Card>()); } } return ret; }
public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback) { throw new NotImplementedException(); }
public void AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, int timeOutSeconds, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { Trace.Assert(resultDeckMaximums.Count == resultDeckNames.Count); Application.Current.Dispatcher.Invoke((ThreadStart)delegate() { lock (verifierLock) { GameModel.CurrentActivePlayer = this; if (!IsPlayable) { Trace.Assert(currentUsageVerifier == null); TimeOutSeconds = timeOutSeconds; CardChoiceAnsweredEvent(null); prompt.ResourceKey = prompt.ResourceKey + Prompt.NonPlaybleAppendix; prompt.Values.Insert(0, Player); } if (options != null && options.IsWuGu) { Trace.Assert(GameModel.WuGuModel != null); TimeOutSeconds = timeOutSeconds; GameModel.WuGuModel.IsEnabled = IsPlayable; GameModel.WuGuModel.Prompt = PromptFormatter.Format(prompt); } else { _currentChoiceOptions = options; _ConstructCardChoiceModel(sourceDecks, resultDeckNames, resultDeckMaximums, options, verifier, timeOutSeconds, callback); CardChoiceModel.Prompt = PromptFormatter.Format(prompt); if (!IsPlayable) { CardChoiceModel.DisplayOnly = true; prompt.Values.Insert(0, Player); CurrentCardChoiceRearrangeCallback = null; } else { CurrentCardChoiceRearrangeCallback = callback; } IsCardChoiceQuestionShown = true; } } }); }
public bool TryAskForCardChoice(List<DeckPlace> sourceDecks, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0); Trace.TraceInformation("Asking Card Choice 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; } answer = new List<List<Card>>(); count = server.GetInt(clientId, 0); while (count-- > 0) { int? subCount = server.GetInt(clientId, 0); ; var theList = new List<Card>(); answer.Add(theList); while (subCount-- > 0) { Card item = server.GetCard(clientId, 0); if (item == null) { return false; } bool exist = false; foreach (var v in sourceDecks) { if (Game.CurrentGame.Decks[v].Contains(item)) { exist = true; break; } } if (options != null && options.DefaultResult != null) { foreach (var dk in options.DefaultResult) { if (dk.Contains(item)) { exist = true; break; } } } if (!exist) { Trace.TraceWarning("Client DDOS!"); return false; } theList.Add(item); } } if (options != null && options.Options != null) { int? opr = server.GetInt(clientId, 0); if (opr == null) return false; if (opr < 0 || opr >= options.Options.Count) return false; options.OptionResult = (int)opr; } if (verifier.Verify(answer) != VerifierResult.Success) { Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?"); answer = null; return false; } return true; }
public void AskForHeroChoice(Dictionary<Player, List<Card>> restDraw, Dictionary<Player, List<Card>> heroSelection, int numberOfHeroes, ICardChoiceVerifier verifier) { throw new NotImplementedException(); }
public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions helper = null, CardChoiceRearrangeCallback callback = null) { throw new NotImplementedException(); }
public void AskForHeroChoice(Dictionary<Player, List<Card>> restDraw, Dictionary<Player, List<Card>> heroSelection, int numberOfHeroes, ICardChoiceVerifier verifier) { proxyListener = new Dictionary<Player, Thread>(); semAccess = new Semaphore(1, 1); semWake = new Semaphore(0, 2); semDone = new Semaphore(proxy.Count - 2, proxy.Count - 1); answerHero = heroSelection; DeckType temp = new DeckType("Temp"); foreach (var player in Game.CurrentGame.Players) { if (!proxy.ContainsKey(player) || player.Role == Role.Ruler) { continue; } ChoiceListenerThreadParameters para = new ChoiceListenerThreadParameters(); para.proxy = proxy[player]; para.verifier = verifier; para.player = player; para.places = new List<DeckPlace>() { new DeckPlace(player, temp) }; para.options = null; para.resultMax = new List<int> { numberOfHeroes }; Game.CurrentGame.Decks[player, temp].Clear(); Game.CurrentGame.Decks[player, temp].AddRange(restDraw[player]); Thread t = new Thread( (ParameterizedThreadStart) ((p) => { ChoiceProxyListenerThread((ChoiceListenerThreadParameters)p); })) { IsBackground = true }; t.Start(para); proxyListener.Add(player, t); } if (!semWake.WaitOne(TimeOutSeconds * 1000)) { semAccess.WaitOne(0); } foreach (var pair in proxyListener) { pair.Value.Abort(); } }
public void TryAskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { List<List<Card>> answer; if (!IsPlayable) { if (IsUiDetached) return; uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback); return; } if (IsUiDetached || !uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback) || answer == null) { Trace.TraceInformation("Invalid answer"); client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, null, 0, client.SelfId)); } else { client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, answer, options == null ? 0 : options.OptionResult, client.SelfId)); } }
public void AskForCardChoice(Prompt prompt, List<Cards.DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, int timeOutSeconds, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { currentChoiceOptions = options; CurrentQuestionState = QuestionState.AskForCardChoice; Gamer.ReceiveAsync(); if (Gamer.OnlineStatus != OnlineStatus.Online) AnswerCardChoice(null); }
public void AskForHeroChoice(Dictionary <Player, List <Card> > restDraw, Dictionary <Player, List <Card> > heroSelection, int numberOfHeroes, ICardChoiceVerifier verifier) { DeckType temp = DeckType.Register("Temp"); foreach (var inactiveProxy in inactiveProxies) { if (restDraw.ContainsKey(inactiveProxy.HostPlayer)) { inactiveProxy.TryAskForCardUsage(new CardUsagePrompt(""), new NullVerifier()); } } if (!restDraw.ContainsKey(proxy.HostPlayer)) { return; } Game.CurrentGame.Decks[proxy.HostPlayer, temp].Clear(); Game.CurrentGame.Decks[proxy.HostPlayer, temp].AddRange(restDraw[proxy.HostPlayer]); List <DeckPlace> sourceDecks = new List <DeckPlace>(); sourceDecks.Add(new DeckPlace(proxy.HostPlayer, temp)); List <string> resultDeckNames = new List <string>() { "HeroChoice" }; List <int> resultDeckMaximums = new List <int>() { numberOfHeroes }; proxy.TryAskForCardChoice(new CardChoicePrompt("HeroChoice"), sourceDecks, resultDeckNames, resultDeckMaximums, verifier, null, null); }
public bool TryAskForCardChoice(List<DeckPlace> sourceDecks, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, CardChoiceRearrangeCallback callback) { answer = null; Trace.TraceInformation("Asking Card Choice to {0}, timeout {1}.", HostPlayer.Id, TimeOutSeconds); int? count; if (!server.ExpectNext(clientId, TimeOutSeconds)) { return false; } count = server.GetInt(clientId, 0); if (count == null || count == 0) { return false; } if (count == null) { return false; } answer = new List<List<Card>>(); count = server.GetInt(clientId, 0); while (count-- > 0) { int? subCount = server.GetInt(clientId, 0); ; var theList = new List<Card>(); answer.Add(theList); while (subCount-- > 0) { Card item = server.GetCard(clientId, 0); if (item == null) { return false; } bool exist = false; foreach (var v in sourceDecks) { if (Game.CurrentGame.Decks[v].Contains(item)) { exist = true; break; } } if (!exist) { Trace.TraceWarning("Client DDOS!"); return false; } theList.Add(item); } } if (verifier.Verify(answer) != VerifierResult.Success) { Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?"); answer = null; return false; } return true; }
public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; bool ret = true; if (!TryAskForCardChoice(sourceDecks, resultDeckMaximums, verifier, out answer, options, callback)) { SendCardChoice(null, null, null); ret = false; } else { SendCardChoice(verifier, answer, options); } NextQuestion(); if (answer == null) { answer = new List <List <Card> >(); foreach (var v in resultDeckMaximums) { answer.Add(new List <Card>()); } } return(ret); }
public bool TryAskForCardChoice(List <DeckPlace> sourceDecks, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0); Trace.TraceInformation("Asking Card Choice to {0}, timeout {1}.", HostPlayer.Id, timeOut); var answerReady = new Semaphore(0, Int16.MaxValue); CardChoiceAnsweredEventHandler handler = (c) => { choiceAnswer = c; answerReady.Release(1); }; proxy.CardChoiceAnsweredEvent += handler; proxy.AskForCardChoice(new Prompt(), sourceDecks, new List <string>(), resultDeckMaximums, verifier, timeOut, options, callback); bool noAnswer = false; if (!answerReady.WaitOne(timeOut * 1000)) { noAnswer = true; } proxy.CardChoiceAnsweredEvent -= handler; proxy.Freeze(); if (noAnswer) { return(false); } answer = choiceAnswer; if (answer != null) { foreach (var list in answer) { foreach (var item in list) { if (item == null) { return(false); } bool exist = false; foreach (var v in sourceDecks) { if (Game.CurrentGame.Decks[v].Contains(item)) { exist = true; break; } } if (options != null && options.DefaultResult != null) { foreach (var dk in options.DefaultResult) { if (dk.Contains(item)) { exist = true; break; } } } if (!exist) { Trace.TraceWarning("Client DDOS!"); return(false); } } } } else { answer = new List <List <Card> >(); } while (answer.Count < resultDeckMaximums.Count) { answer.Add(new List <Card>()); } if (verifier.Verify(answer) != VerifierResult.Success) { Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?"); answer = null; return(false); } return(true); }
public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answerPending = new Semaphore(0, 1); int timeOut = _GetActualTimeoutSecond(verifier.Helper); proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, timeOut, options, callback); answer = null; if (answerPending.WaitOne(timeOut * 1000 /* + GameDelays.UiDelayCompensation*/)) { answer = answerCardsOfCards; } if (answer == null) { return(false); } else { return(verifier.Verify(answer) == VerifierResult.Success); } }
public void AskForHeroChoice(Dictionary <Player, List <Card> > restDraw, Dictionary <Player, List <Card> > heroSelection, int numberOfHeroes, ICardChoiceVerifier verifier) { proxyListener = new Dictionary <Player, Thread>(); semAccess = new Semaphore(1, 1); semWake = new Semaphore(0, 2); semDone = new Semaphore(restDraw.Count - 1, restDraw.Count); answerHero = heroSelection; DeckType temp = DeckType.Register("Temp"); foreach (var player in Game.CurrentGame.Players) { if (!proxy.ContainsKey(player) || !restDraw.ContainsKey(player)) { continue; } ChoiceListenerThreadParameters para = new ChoiceListenerThreadParameters(); para.proxy = proxy[player]; para.verifier = verifier; para.player = player; para.places = new List <DeckPlace>() { new DeckPlace(player, temp) }; para.options = null; para.resultMax = new List <int> { numberOfHeroes }; Game.CurrentGame.Decks[player, temp].Clear(); Game.CurrentGame.Decks[player, temp].AddRange(restDraw[player]); Thread t = new Thread( (ParameterizedThreadStart) ((p) => { ChoiceProxyListenerThread((ChoiceListenerThreadParameters)p); })) { IsBackground = true }; t.Start(para); proxyListener.Add(player, t); } if (!semWake.WaitOne(TimeOutSeconds * 1000)) { semAccess.WaitOne(0); } foreach (var pair in proxyListener) { pair.Value.Abort(); } }
public void AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, int timeOutSeconds, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { if (ViewModelBase.IsDetached) return; Trace.Assert(!Player.IsDead); if (this != GameModel.MainPlayerModel && (verifier.Helper == null || !verifier.Helper.ShowToAll)) { TimeOutSeconds = timeOutSeconds; CardChoiceAnsweredEvent(null); return; } Trace.Assert(resultDeckMaximums.Count == resultDeckNames.Count); Application.Current.Dispatcher.Invoke((ThreadStart)delegate() { GameModel.CurrentActivePlayer = this; if (!IsPlayable) { Trace.Assert(currentUsageVerifier == null); TimeOutSeconds = timeOutSeconds; CardChoiceAnsweredEvent(null); } if (GameModel.MainPlayerModel != this) { prompt.ResourceKey = prompt.ResourceKey + Prompt.NonPlaybleAppendix; prompt.Values.Insert(0, Player); } if (options != null && options.IsWuGu) { // Trace.Assert(GameModel.WuGuModel != null); TimeOutSeconds = timeOutSeconds; // @todo: Fix this to show wugu on reconnection if (GameModel != null && GameModel.WuGuModel != null) { GameModel.WuGuModel.IsEnabled = IsPlayable; GameModel.WuGuModel.Prompt = LogFormatter.Translate(prompt); } } else if (options != null && options.IsTwoSidesCardChoice) { if (GameModel != null && GameModel.TwoSidesCardChoiceModel != null) { GameModel.TwoSidesCardChoiceModel.IsEnabled = IsPlayable; GameModel.TwoSidesCardChoiceModel.Prompt = LogFormatter.Translate(prompt); bool isMainPlayer = GameModel.TwoSidesCardChoiceModel.GroupOfPlayer[GameModel.MainPlayerModel.Id] == GameModel.TwoSidesCardChoiceModel.GroupOfPlayer[Id]; if (isMainPlayer) { GameModel.TwoSidesCardChoiceModel.TimeOutSeconds1 = timeOutSeconds; } else { GameModel.TwoSidesCardChoiceModel.TimeOutSeconds2 = timeOutSeconds; } } } else { _currentChoiceOptions = options; _ConstructCardChoiceModel(sourceDecks, resultDeckNames, resultDeckMaximums, options, verifier, timeOutSeconds, callback); CardChoiceModel.Prompt = LogFormatter.Translate(prompt); if (!IsPlayable) { CardChoiceModel.DisplayOnly = true; prompt.Values.Insert(0, Player); CurrentCardChoiceRearrangeCallback = null; } else { CurrentCardChoiceRearrangeCallback = callback; } IsCardChoiceQuestionShown = true; } }); }
public void SendCardChoice(ICardChoiceVerifier verifier, List<List<Card>> answer, AdditionalCardChoiceOptions options) { for (int i = 0; i < server.MaxClients; i++) { server.SendObject(i, 1); server.SendObject(i, answer.Count); foreach (var cards in answer) { server.SendObject(i, cards.Count); foreach (Card c in cards) { if (verifier.Helper != null && verifier.Helper.RevealCards) { c.RevealOnce = true; } server.SendObject(i, c); } } if (options != null && options.Options != null) server.SendObject(i, options.OptionResult); server.Flush(i); } }
public void AskForCardChoice(Prompt prompt, List <Cards.DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, int timeOutSeconds, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { currentChoiceOptions = options; CurrentQuestionState = QuestionState.AskForCardChoice; Gamer.ReceiveAsync(); if (Gamer.OnlineStatus != OnlineStatus.Online) { AnswerCardChoice(null); } }
public void AskForHeroChoice(Dictionary<Player, List<Card>> restDraw, Dictionary<Player, List<Card>> heroSelection, int numberOfHeroes, ICardChoiceVerifier verifier) { DeckType temp = DeckType.Register("Temp"); foreach (var inactiveProxy in inactiveProxies) { if (restDraw.ContainsKey(inactiveProxy.HostPlayer)) { inactiveProxy.TryAskForCardUsage(new CardUsagePrompt(""), new NullVerifier()); } } if (!restDraw.ContainsKey(proxy.HostPlayer)) { return; } Game.CurrentGame.Decks[proxy.HostPlayer, temp].Clear(); Game.CurrentGame.Decks[proxy.HostPlayer, temp].AddRange(restDraw[proxy.HostPlayer]); List<DeckPlace> sourceDecks = new List<DeckPlace>(); sourceDecks.Add(new DeckPlace(proxy.HostPlayer, temp)); List<string> resultDeckNames = new List<string>() { "HeroChoice" }; List<int> resultDeckMaximums = new List<int>() { numberOfHeroes }; proxy.TryAskForCardChoice(new CardChoicePrompt("HeroChoice"), sourceDecks, resultDeckNames, resultDeckMaximums, verifier, null, null); }
public bool TryAnswerForCardChoice(Prompt prompt, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { object o = client.Receive(); int opt; answer = (o as AskForCardChoiceResponse).ToAnswer(client.SelfId, out opt); if (options != null) options.OptionResult = opt; return true; }
public void AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, int timeOutSeconds, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { Trace.Assert(resultDeckMaximums.Count == resultDeckNames.Count); Application.Current.Dispatcher.Invoke((ThreadStart)delegate() { if (!IsPlayable) { Trace.Assert(currentUsageVerifier == null); TimeOutSeconds = timeOutSeconds; CardChoiceAnsweredEvent(null); return; } lock (verifierLock) { _currentChoiceOptions = options; _ConstructCardChoiceModel(sourceDecks, resultDeckNames, resultDeckMaximums, options, verifier, timeOutSeconds, callback); CardChoiceModel.Prompt = PromptFormatter.Format(prompt); IsCardChoiceQuestionShown = true; } }); }
public bool AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options = null, CardChoiceRearrangeCallback callback = null) { Trace.TraceInformation("Asking Card Choice to {0}.", HostPlayer.Id); TryAskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, options, callback); SimulateReplayDelay(); NextQuestion(); if (TryAnswerForCardChoice(prompt, verifier, out answer, options, callback)) { uiProxy.Freeze(); if (answer == null || answer.Count == 0) { return(false); } #if DEBUG Trace.Assert(verifier.Verify(answer) == VerifierResult.Success); #endif return(true); } uiProxy.Freeze(); return(false); }
public void TryAskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { List <List <Card> > answer; if (!IsPlayable) { if (IsUiDetached) { return; } uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback); return; } if (IsUiDetached || !uiProxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback) || answer == null) { Trace.TraceInformation("Invalid answer"); client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, null, 0, client.SelfId)); } else { client.Send(AskForCardChoiceResponse.Parse(numQuestionsAsked, answer, options == null ? 0 : options.OptionResult, client.SelfId)); } }
public void AskForHeroChoice(Dictionary <Player, List <Card> > restDraw, Dictionary <Player, List <Card> > heroSelection, int numberOfHeroes, ICardChoiceVerifier verifier) { }
public bool TryAnswerForCardChoice(Prompt prompt, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; object o = client.Receive(); if (o == null) { return false; } if ((int)o == 0) { return false; } answer = new List<List<Card>>(); o = client.Receive(); int count = (int)o; while (count-- > 0) { o = client.Receive(); if (o == null) { return false; } int subCount = (int)o; var theList = new List<Card>(); answer.Add(theList); while (subCount-- > 0) { o = client.Receive(); if (o == null) { return false; } theList.Add((Card)o); } } if (options != null && options.Options != null) { options.OptionResult = (int)client.Receive(); } return true; }
private void _ConstructCardChoiceModel(List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, AdditionalCardChoiceOptions options, ICardChoiceVerifier verifier, int timeOutSeconds, CardChoiceRearrangeCallback callback) { bool isSingleResult = (resultDeckMaximums.Sum() == 1); var choiceModel = new CardChoiceViewModel(); int numLines = sourceDecks.Count; foreach (var deck in sourceDecks) { if (Game.CurrentGame.Decks[deck].Count == 0) { continue; } CardChoiceLineViewModel line = new CardChoiceLineViewModel(); line.DeckName = deck.DeckType.Name; line.IsResultDeck = false; int i = 0; int numCards = Game.CurrentGame.Decks[deck].Count; int maxColumns = Math.Max(numCards / 2 + 1, 5); bool firstRow = true; foreach (var card in Game.CurrentGame.Decks[deck]) { if (numLines == 1 && isSingleResult && i >= maxColumns && firstRow) { Trace.Assert(choiceModel.CardStacks.Count == 0); choiceModel.CardStacks.Add(line); line = new CardChoiceLineViewModel(); line.DeckName = deck.DeckType.Name; line.IsResultDeck = false; firstRow = false; } CardViewModel model = new CardViewModel() { Card = card, IsSelectionMode = isSingleResult, IsEnabled = true }; line.Cards.Add(model); i++; } choiceModel.CardStacks.Add(line); } if (!isSingleResult) { int k = 0; foreach (var deckName in resultDeckNames) { CardChoiceLineViewModel line = new CardChoiceLineViewModel(); line.DeckName = deckName; if (options != null) { if (options.Rearrangeable != null) { line.Rearrangable = options.Rearrangeable[k]; } if (options.DefaultResult != null) { foreach (var card in options.DefaultResult[k]) { line.Cards.Add(new CardViewModel() { Card = card }); } } } line.Capacity = resultDeckMaximums[k++]; line.IsResultDeck = true; choiceModel.CardStacks.Add(line); } } if (options != null && options.Options != null) { for (int i = 0; i < options.Options.Count; i++) { MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand) { CanExecuteStatus = false, ChoiceKey = options.Options[i], ChoiceIndex = i }; choiceModel.MultiChoiceCommands.Add(command); } } else { MultiChoiceCommand command = new MultiChoiceCommand(ExecuteCardChoiceCommand) { CanExecuteStatus = false, ChoiceKey = new OptionPrompt("Confirm") }; choiceModel.MultiChoiceCommands.Add(command); } if (options != null && options.IsCancellable) { MultiChoiceCommand command = new MultiChoiceCommand(CancelCardChoiceCommand) { IsCancel = true, ChoiceKey = new OptionPrompt("Cancel") }; choiceModel.MultiChoiceCommands.Add(command); } choiceModel.Verifier = verifier; choiceModel.TimeOutSeconds = timeOutSeconds; CardChoiceModel = choiceModel; }
public void TryAskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { List<List<Card>> answer; if (!active) { proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback); return; } if (!proxy.AskForCardChoice(prompt, sourceDecks, resultDeckNames, resultDeckMaximums, verifier, out answer, options, callback) || answer == null) { Trace.TraceInformation("Invalid answer"); client.AnswerNext(); client.AnswerItem(0); } else { client.AnswerNext(); client.AnswerItem(1); client.AnswerItem(answer.Count); foreach (var subList in answer) { client.AnswerItem(subList.Count); foreach (Card c in subList) { client.AnswerItem(c); } } if (options != null && options.Options != null) { client.AnswerItem(options.OptionResult); } } client.Flush(); }
public void SendCardChoice(ICardChoiceVerifier verifier, List<List<Card>> answer, AdditionalCardChoiceOptions options) { for (int i = 0; i < server.MaxClients; i++) { server.SendObject(i, 1); server.SendObject(i, answer.Count); int j = 0; foreach (var cards in answer) { server.SendObject(i, cards.Count); foreach (Card c in cards) { if (verifier.Helper != null && (verifier.Helper.RevealCards || (verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy != null && verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy[j]))) { if (c.Place.DeckType != DeckType.Equipment && c.Place.DeckType != DeckType.DelayedTools) { c.RevealOnce = true; } } server.SendObject(i, c); } j++; } if (options != null && options.Options != null) server.SendObject(i, options.OptionResult); server.Flush(i); } }
bool IUiProxy.AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, List<bool> rearrangeable, ref int windowId, CardChoiceRearrangeCallback callback) { answer = null; return false; }
bool IUiProxy.AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; return false; }
public void AskForHeroChoice(Dictionary<Player, List<Card>> restDraw, Dictionary<Player, List<Card>> heroSelection, int numberOfHeroes, ICardChoiceVerifier verifier) { }
public void SendCardChoice(ICardChoiceVerifier verifier, List<List<Card>> answer, AdditionalCardChoiceOptions options) { for (int i = 0; i < server.MaxClients; i++) { int j = 0; if (answer != null) { foreach (var cards in answer) { foreach (Card c in cards) { if (verifier.Helper != null && (verifier.Helper.RevealCards || (verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy != null && verifier.Helper.AdditionalFineGrainedCardChoiceRevealPolicy[j]))) { if (c.Place.DeckType != DeckType.Equipment && c.Place.DeckType != DeckType.DelayedTools) { c.RevealOnce = true; } } } j++; } } server.SendPacket(i, AskForCardChoiceResponse.Parse(proxy.QuestionId, answer, options == null? 0 : options.OptionResult, i)); } }
public bool TryAskForCardChoice(List<DeckPlace> sourceDecks, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; int timeOut = TimeOutSeconds + (verifier.Helper != null ? verifier.Helper.ExtraTimeOutSeconds : 0); Trace.TraceInformation("Asking Card Choice to {0}, timeout {1}.", HostPlayer.Id, timeOut); var answerReady = new Semaphore(0, Int16.MaxValue); CardChoiceAnsweredEventHandler handler = (c) => { choiceAnswer = c; answerReady.Release(1); }; proxy.CardChoiceAnsweredEvent += handler; proxy.AskForCardChoice(new Prompt(), sourceDecks, new List<string>(), resultDeckMaximums, verifier, timeOut, options, callback); bool noAnswer = false; if (!answerReady.WaitOne(timeOut * 1000)) noAnswer = true; proxy.CardChoiceAnsweredEvent -= handler; proxy.Freeze(); if (noAnswer) return false; answer = choiceAnswer; if (answer != null) { foreach (var list in answer) { foreach (var item in list) { if (item == null) { return false; } bool exist = false; foreach (var v in sourceDecks) { if (Game.CurrentGame.Decks[v].Contains(item)) { exist = true; break; } } if (options != null && options.DefaultResult != null) { foreach (var dk in options.DefaultResult) { if (dk.Contains(item)) { exist = true; break; } } } if (!exist) { Trace.TraceWarning("Client DDOS!"); return false; } } } } else { answer = new List<List<Card>>(); } while (answer.Count < resultDeckMaximums.Count) { answer.Add(new List<Card>()); } if (verifier.Verify(answer) != VerifierResult.Success) { Trace.TraceWarning("Client seems to be sending invalid answers at us. DDOS?"); answer = null; return false; } return true; }
public bool AskForCardChoice(Prompt prompt, List<DeckPlace> sourceDecks, List<string> resultDeckNames, List<int> resultDeckMaximums, ICardChoiceVerifier verifier, out List<List<Card>> answer, AdditionalCardChoiceOptions helper = null, CardChoiceRearrangeCallback callback = null) { throw new NotImplementedException(); }
bool IPlayerProxy.AskForCardChoice(Prompt prompt, List <DeckPlace> sourceDecks, List <string> resultDeckNames, List <int> resultDeckMaximums, ICardChoiceVerifier verifier, out List <List <Card> > answer, AdditionalCardChoiceOptions options, CardChoiceRearrangeCallback callback) { answer = null; return(false); }