示例#1
0
        public async Task Start(IGuildUser user)
        {
            if (_phase == Phase.Started || _phase == Phase.Ended)
            {
                await _channel.SendErrorAsync(user.Mention + GetText("ttt_already_running")).ConfigureAwait(false);

                return;
            }
            else if (_users[0] == user)
            {
                await _channel.SendErrorAsync(user.Mention + GetText("ttt_against_yourself")).ConfigureAwait(false);

                return;
            }

            _users[1] = user;

            _phase = Phase.Started;

            _timeoutTimer = new Timer(async(_) =>
            {
                await _moveLock.WaitAsync().ConfigureAwait(false);
                try
                {
                    if (_phase == Phase.Ended)
                    {
                        return;
                    }

                    _phase = Phase.Ended;
                    if (_users[1] != null)
                    {
                        _winner = _users[_curUserIndex ^= 1];
                        var del = _previousMessage?.DeleteAsync();
                        try
                        {
                            await _channel.EmbedAsync(GetEmbed(GetText("ttt_time_expired"))).ConfigureAwait(false);
                            if (del != null)
                            {
                                await del.ConfigureAwait(false);
                            }
                        }
                        catch { }
                    }

                    OnEnded?.Invoke(this);
                }
                catch { }
                finally
                {
                    _moveLock.Release();
                }
            }, null, _options.TurnTimer * 1000, Timeout.Infinite);

            _client.MessageReceived += Client_MessageReceived;


            _previousMessage = await _channel.EmbedAsync(GetEmbed(GetText("game_started"))).ConfigureAwait(false);
        }
示例#2
0
        public async Task OnEndedEventHandler(string currentSrc)
        {
            PlayerState.CurrentSrc = new Uri(currentSrc);
            PlayerState.PlayState  = BulMediaPlayState.Stopped;
            await OnEnded.InvokeAsync(PlayerState);

            StateHasChanged();
        }
示例#3
0
        private async Task Start()
        {
            CurrentPhase = Phase.Running;
            if (_users.Count <= 1)
            {
                foreach (var user in _users)
                {
                    if (user.Bet > 0)
                    {
                        await _currency.AddAsync(user.UserId, "Race refund", user.Bet).ConfigureAwait(false);
                    }
                }

                var _sf = OnStartingFailed?.Invoke(this);
                CurrentPhase = Phase.Ended;
                return;
            }

            var _  = OnStarted?.Invoke(this);
            var _t = Task.Run(async() =>
            {
                var rng = new NadekoRandom();
                while (!_users.All(x => x.Progress >= 60))
                {
                    foreach (var user in _users)
                    {
                        user.Progress += rng.Next(1, 11);
                        if (user.Progress >= 60)
                        {
                            user.Progress = 60;
                        }
                    }

                    var finished = _users.Where(x => x.Progress >= 60 && !FinishedUsers.Contains(x))
                                   .Shuffle();

                    FinishedUsers.AddRange(finished);

                    var _ignore = OnStateUpdate?.Invoke(this);
                    await Task.Delay(2500).ConfigureAwait(false);
                }

                var win_amount = 0;

                foreach (var u in FinishedUsers)
                {
                    win_amount += (int)u.Bet;
                }

                if (FinishedUsers[0].Bet > 0)
                {
                    await _currency.AddAsync(FinishedUsers[0].UserId, "Won a Race", win_amount)
                    .ConfigureAwait(false);
                }

                var _ended = OnEnded?.Invoke(this);
            });
        }
示例#4
0
        public Boolean Initiate(IAccept _iIAccept)
        {
            _mIAccept     = _iIAccept;
            _mOnInitiated = OnInitiatedDelegate;
            _mOnEnded     = OnEndedDelegate;

            Boolean ret = VidyoCallInitiateNative(objPtr, _mOnInitiated, _mOnEnded);

            return(ret);
        }
示例#5
0
 // Update is called once per frame
 void Update()
 {
     if (Source.time >= CurrentLevel.Clip.length && !Ended)
     {
         if (OnEnded != null)
         {
             Ended = true;
             OnEnded.Invoke();
         }
     }
 }
示例#6
0
        public void Start()
        {
            var estimatedPasswordLength = 0;

            for (int i = 0; i < MaxLength; i++)
            {
                estimatedPasswordLength++;
                OnStringLengthChanged(estimatedPasswordLength);
                startBruteForce(estimatedPasswordLength);
            }
            OnEnded?.Invoke();
        }
示例#7
0
        /// <summary>
        /// Stop the objective
        /// </summary>
        public virtual void stop(bool removePhysicalElements = false)
        {
            this.elapsedTime = 0;

            this.depopulateDestructibleElements(removePhysicalElements);

            this.inProgress = false;

            this.ObjectiveText = "";
            this.AdviceText    = "";

            OnEnded?.Invoke(this);
        }
示例#8
0
    void OnTweenComplete()
    {
        target.SetActive(false);

        if (shotsFired < 3)
        {
            Triggered();
        }
        else
        {
            Reset();
            OnEnded.Invoke();
        }
    }
示例#9
0
 public override async Task Stop()
 {
     try
     {
         _client.MessageReceived -= SneakyGameMessageReceivedEventHandler;
         Code = string.Empty;
         _sneakyGameAwardedUsers.Clear();
         await _client.SetGameAsync(null).ConfigureAwait(false);
     }
     catch { }
     finally
     {
         OnEnded?.Invoke();
     }
 }
示例#10
0
    protected override void DoUpdate()
    {
        //Debug.DrawRay(target.transform.position, target.transform.TransformDirection(Vector3.forward) * 100, Color.yellow);

        RaycastHit hit;

        if (Physics.Raycast(target.transform.position, target.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
        {
            if (!(hit.collider.gameObject.tag == "Player"))
            {
                return;
            }
            iTween.StopByName("turning");   // can interrupt tween, stop turning
            Reset();
            OnEnded.Invoke();
        }
    }
示例#11
0
        // ReSharper disable once UnusedMember.Local
        private void Update()
        {
            if (State == AnimationState.Stopped)
            {
                return;
            }

            DeltaTime = (Direction == AnimationDirection.Forward ? 1f : -1f) *
                        (UnityEngine.Time.deltaTime / Settings.Duration);

            Time = Mathf.Clamp(Time + DeltaTime, 0f, 1f);

            var easingTime = Easings.Interpolate(Time, Settings.EasingType);

            DeltaEasingTime = easingTime - EasingTime;
            EasingTime      = easingTime;

            Animate();

            if (Time >= 1f && Direction == AnimationDirection.Forward ||
                Time <= 0f && Direction == AnimationDirection.Backward)
            {
                if (Settings.PlayType == AnimationPlayType.EndReset)
                {
                    Repeats++;
                    OnRepeat.Invoke();
                    Time       = 0f;
                    EasingTime = 0f;
                }
                else if (Settings.PlayType == AnimationPlayType.EndFlip)
                {
                    Repeats++;
                    OnRepeat.Invoke();
                    Direction = Direction == AnimationDirection.Forward
                        ? AnimationDirection.Backward
                        : AnimationDirection.Forward;
                }

                if (Settings.PlayType == AnimationPlayType.PlayOnce ||
                    Settings.MaxRepeats > 0 && Repeats >= Settings.MaxRepeats)
                {
                    State = AnimationState.Stopped;
                    OnEnded.Invoke();
                }
            }
        }
示例#12
0
    void UpdateTime()
    {
        float timecount = Time.time - starttime;
        float min       = Mathf.Floor((timecount / 60f));
        float sec       = (timecount % 60f);
        float fraction  = ((timecount * 10) % 10);

        time = new TimeEntity {
            min = min, sec = sec, fraction = fraction
        };

        if (timeCounter)
        {
            timeCounter.text = String.Format("{0:00}:{1:00}:{2:00}", time.min, time.sec, time.fraction) + " Collect: " + score.ToString() + " V: " + string.Format("{0:0.##}", visibleTimes);
        }

        if (time.min >= maxMinutes)
        {
            OnEnded?.Invoke();
        }
    }
示例#13
0
        internal void StateChangeHandler(CallingEventParams eventParams, CallingEventParams.StateParams stateParams)
        {
            PreviousState = State;
            State         = stateParams.CallState;

            OnStateChange?.Invoke(mAPI, this, eventParams, stateParams);

            switch (stateParams.CallState)
            {
            case CallState.ringing:
                OnRinging?.Invoke(mAPI, this, eventParams, stateParams);
                break;

            case CallState.answered:
                OnAnswered?.Invoke(mAPI, this, eventParams, stateParams);
                break;

            case CallState.ending:
                OnEnding?.Invoke(mAPI, this, eventParams, stateParams);
                break;

            case CallState.ended:
                mAPI.RemoveCall(stateParams.CallID);
                if (stateParams.Peer != null && Peer != null && Peer.ID == stateParams.Peer.CallID)
                {
                    // Detach peer from this ended call
                    Peer.Peer = null;
                    Peer      = null;
                }
                if (stateParams.EndReason == DisconnectReason.busy)
                {
                    mBusy = true;
                }
                OnEnded?.Invoke(mAPI, this, eventParams, stateParams);
                break;
            }
        }
示例#14
0
        internal void StateChangeHandler(CallEventParams.StateParams stateParams)
        {
            CallState oldState = State;

            State = stateParams.CallState;

            OnStateChange?.Invoke(mAPI, this, oldState, stateParams);

            switch (stateParams.CallState)
            {
            case CallState.ringing:
                OnRinging?.Invoke(mAPI, this, oldState, stateParams);
                break;

            case CallState.answered:
                OnAnswered?.Invoke(mAPI, this, oldState, stateParams);
                break;

            case CallState.ending:
                OnEnding?.Invoke(mAPI, this, oldState, stateParams);
                break;

            case CallState.ended:
                mAPI.RemoveCall(stateParams.CallID);
                if (stateParams.Peer != null && Peer != null && Peer.CallID == stateParams.Peer.CallID)
                {
                    // Detach peer from this ended call
                    Peer.Peer = null;
                    Peer      = null;
                }
                OnEnded?.Invoke(mAPI, this, oldState, stateParams);
                break;

            default: break;
            }
        }
示例#15
0
        private Task Client_MessageReceived(SocketMessage msg)
        {
            var _ = Task.Run(async() =>
            {
                await _moveLock.WaitAsync().ConfigureAwait(false);
                try
                {
                    var curUser = _users[_curUserIndex];
                    if (_phase == Phase.Ended || msg.Author?.Id != curUser.Id)
                    {
                        return;
                    }

                    if (int.TryParse(msg.Content, out var index) &&
                        --index >= 0 &&
                        index <= 9 &&
                        _state[index / 3, index % 3] == null)
                    {
                        _state[index / 3, index % 3] = _curUserIndex;

                        // i'm lazy
                        if (_state[index / 3, 0] == _state[index / 3, 1] && _state[index / 3, 1] == _state[index / 3, 2])
                        {
                            _state[index / 3, 0] = _curUserIndex + 2;
                            _state[index / 3, 1] = _curUserIndex + 2;
                            _state[index / 3, 2] = _curUserIndex + 2;

                            _phase = Phase.Ended;
                        }
                        else if (_state[0, index % 3] == _state[1, index % 3] && _state[1, index % 3] == _state[2, index % 3])
                        {
                            _state[0, index % 3] = _curUserIndex + 2;
                            _state[1, index % 3] = _curUserIndex + 2;
                            _state[2, index % 3] = _curUserIndex + 2;

                            _phase = Phase.Ended;
                        }
                        else if (_curUserIndex == _state[0, 0] && _state[0, 0] == _state[1, 1] && _state[1, 1] == _state[2, 2])
                        {
                            _state[0, 0] = _curUserIndex + 2;
                            _state[1, 1] = _curUserIndex + 2;
                            _state[2, 2] = _curUserIndex + 2;

                            _phase = Phase.Ended;
                        }
                        else if (_curUserIndex == _state[0, 2] && _state[0, 2] == _state[1, 1] && _state[1, 1] == _state[2, 0])
                        {
                            _state[0, 2] = _curUserIndex + 2;
                            _state[1, 1] = _curUserIndex + 2;
                            _state[2, 0] = _curUserIndex + 2;

                            _phase = Phase.Ended;
                        }
                        var reason = "";

                        if (_phase == Phase.Ended) // if user won, stop receiving moves
                        {
                            reason  = GetText("ttt_matched_three");
                            _winner = _users[_curUserIndex];
                            _client.MessageReceived -= Client_MessageReceived;
                            OnEnded?.Invoke(this);
                        }
                        else if (IsDraw())
                        {
                            reason = GetText("ttt_a_draw");
                            _phase = Phase.Ended;
                            _client.MessageReceived -= Client_MessageReceived;
                            OnEnded?.Invoke(this);
                        }

                        var sendstate = Task.Run(async() =>
                        {
                            var del1 = msg.DeleteAsync();
                            var del2 = _previousMessage?.DeleteAsync();
                            try { _previousMessage = await _channel.EmbedAsync(GetEmbed(reason)).ConfigureAwait(false); } catch { }
                            try { await del1.ConfigureAwait(false); } catch { }
                            try { if (del2 != null)
                                  {
                                      await del2.ConfigureAwait(false);
                                  }
                            } catch { }
                        });
                        _curUserIndex ^= 1;

                        _timeoutTimer.Change(_options.TurnTimer * 1000, Timeout.Infinite);
                    }
                }
                finally
                {
                    _moveLock.Release();
                }
            });

            return(Task.CompletedTask);
        }
示例#16
0
 void OnLowerComplete()
 {
     Reset();
     OnEnded.Invoke();
 }
示例#17
0
 private static extern Boolean VidyoCallInitiateNative(IntPtr c, OnInitiated onInitiated, OnEnded onEnded);
示例#18
0
 public static void AudioEnded()
 {
     OnEnded?.Invoke();
 }
示例#19
0
 public void EndGame()
 {
     OnEnded?.Invoke();
 }
示例#20
0
 private MediaStreamTrack(IJSRuntime jsRuntime, JsObjectRef jsObjectRef) : base(jsRuntime, jsObjectRef)
 {
     AddNativeEventListener("ended", (s, e) => OnEnded?.Invoke(s, e));
     AddNativeEventListener("mute", (s, e) => OnMute?.Invoke(s, e));
     AddNativeEventListener("unmute", (s, e) => OnUnmute?.Invoke(s, e));
 }
示例#21
0
 private async ValueTask OnEndedCallback()
 {
     ReadyState = "ended";
     OnEnded?.Invoke(this, EventArgs.Empty);
 }
示例#22
0
 private void Bruteforce_OnEnded()
 {
     OnEnded?.Invoke();
 }