Exemplo n.º 1
0
 public ChallengeForm(KgsChallenge challenge, KgsConnection connection)
 {
     InitializeComponent();
     this.challenge            = challenge;
     this._connection          = connection;
     this.lblInfo.Text         = challenge.ToString();
     connection.Events.Unjoin += Events_Unjoin;
     challenge.StatusChanged  += ChallengeStatusChanged;
     RefreshEvents();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Joins the specified challenge. If it isn't loaded in Data yet, it is loaded now.
        /// </summary>
        /// <param name="challenge">The challenge to join.</param>
        public void JoinChallenge(KgsChallenge challenge)
        {
            bool wasJoined = challenge.Joined;

            JoinChannel(challenge);
            if (!wasJoined)
            {
                this._kgsConnection.Events.RaiseChallengeJoined(challenge);
            }
        }
Exemplo n.º 3
0
        public override void Process(KgsConnection connection)
        {
            KgsChallenge createdChallenge = KgsChallenge.FromChannel(Game);

            if (createdChallenge != null)
            {
                createdChallenge.OwnedByUs = true;
                connection.Data.JoinChallenge(createdChallenge);
            }
            createdChallenge.RaiseStatusChanged();
        }
Exemplo n.º 4
0
 public async Task DeclineChallengeAsync(KgsChallenge challenge, Proposal incomingChallenge)
 {
     string targetName =
         incomingChallenge.Players.Select(pl => pl.User?.Name)
         .First(name => name != null && name != kgsConnection.Username);
     await kgsConnection.MakeUnattendedRequestAsync("CHALLENGE_DECLINE", new
     {
         ChannelId = challenge.ChannelId,
         Name      = targetName
     });
 }
Exemplo n.º 5
0
 public async Task ChallengeProposalAsync(KgsChallenge challenge, Proposal incomingChallenge)
 {
     Proposal outgoing = incomingChallenge.ToUpstream();
     await kgsConnection.MakeUnattendedRequestAsync("CHALLENGE_PROPOSAL", new
     {
         ChannelId = challenge.ChannelId,
         GameType  = outgoing.GameType,
         Rules     = outgoing.Rules,
         Nigiri    = outgoing.Nigiri,
         Players   = outgoing.Players
     });
 }
Exemplo n.º 6
0
        public async Task JoinAndSubmitSelfToChallengeAsync(KgsChallenge selectedItem)
        {
            // Join
            var             simpleProposal = SubmitOurselvesIntoProposal(selectedItem);
            ChallengeWaiter waiter         = new Kgs.KgsCommands.ChallengeWaiter(kgsConnection, selectedItem.ChannelId, simpleProposal);

            this.kgsConnection.Events.ChannelJoined   += waiter.Joined;
            this.kgsConnection.Events.ChannelUnjoined += waiter.Unjoined;
            await kgsConnection.MakeUnattendedRequestAsync("JOIN_REQUEST", new
            {
                ChannelId = selectedItem.ChannelId
            });
        }
        public override void Process(KgsConnection connection)
        {
            var          channel   = connection.Data.GetChannel(this.ChannelId);
            KgsChallenge challenge = channel as KgsChallenge;

            if (challenge != null)
            {
                challenge.Events.Add(this.Type);
            }
            else
            {
                Debug.WriteLine("That was supposed to be a challenge.");
            }
        }
Exemplo n.º 8
0
        private object SubmitOurselvesIntoProposal(KgsChallenge selectedItem)
        {
            var originalProposal = selectedItem.Proposal;

            if (selectedItem.CreatorsNewProposal != null)
            {
                originalProposal = selectedItem.CreatorsNewProposal;
            }
            var ourName          = this.kgsConnection.Username;
            var upstreamProposal = originalProposal.ToUpstream();
            var emptySeat        = upstreamProposal.Players.FirstOrDefault(pl => pl.Name == null);

            if (emptySeat != null)
            {
                emptySeat.Name = ourName;
            }
            var simpleProposal = new
            {
                ChannelId = selectedItem.ChannelId,
                GameType  = upstreamProposal.GameType,
                Rules     = upstreamProposal.Rules,
                Nigiri    = upstreamProposal.Nigiri,
                Players   = new[]
                {
                    new
                    {
                        Role = upstreamProposal.Players[0].Role,
                        Name = upstreamProposal.Players[0].Name
                    },
                    new
                    {
                        Role = upstreamProposal.Players[1].Role,
                        Name = upstreamProposal.Players[1].Name
                    }
                }
            };

            return(simpleProposal);
        }
Exemplo n.º 9
0
 internal void RaiseChallengeJoined(KgsChallenge createdChallenge)
 {
     ChallengeJoined?.Invoke(this, createdChallenge);
 }
Exemplo n.º 10
0
 protected KgsNegotiationBundle(KgsChallenge challenge)
 {
     Challenge = challenge;
 }
Exemplo n.º 11
0
 private void Events_ChallengeJoined(object sender, KgsChallenge e)
 {
     ChallengeForm form = new FormsPrototype.ChallengeForm(e, kgs);
     form.Show();
 }
Exemplo n.º 12
0
 public KgsChallengeManagementBundle(KgsChallenge challenge) : base(challenge)
 {
 }
Exemplo n.º 13
0
 public async Task AcceptChallenge(KgsChallenge challenge)
 {
     var newProposal = SubmitOurselvesIntoProposal(challenge);
     await kgsConnection.MakeUnattendedRequestAsync("CHALLENGE_ACCEPT", newProposal);
 }
Exemplo n.º 14
0
 public KgsJoinChallengeBundle(KgsChallenge challenge) : base(challenge)
 {
 }