/// <summary>
 /// 排除互斥事件的延迟,同种类型的事件只能触发一个
 /// 比如战斗的数值是预计算的,A先放一个技能,3s后造成伤害;B再放一个技能,1s后造成伤害
 /// 这个时候如果按照action的实际情况去push,就会出现血条显示异常的情况,采用这种互斥事件,可以排除掉A的那个action
 /// </summary>
 /// <param name="delayType">延迟类型</param>
 /// <param name="delay">延迟时间</param>
 /// <param name="action">回调</param>
 /// <returns>action的ID</returns>
 public int PushAction(DelayType delayType, float delay, Action action)
 {
     if (delay > 0)
     {
         GetNewAction();
         InitAction(delay, action);
         m_NewEvent.delayType = delayType;
         for (int i = m_Active.Count - 1; i >= 0; i--)
         {
             if (m_Active[i].delayType == delayType && m_Active[i].EndTime >= m_NewEvent.EndTime)
             {
                 m_Active[i].Recycle();
             }
         }
         m_Active.Insert(0, m_NewEvent);
         return(actionID);
     }
     else
     {
         //如果delay=0,表示立刻执行的事件,这个时候回收所有的相同类型事件,立刻执行最后push的事件
         for (int i = m_Active.Count - 1; i >= 0; i--)
         {
             if (m_Active[i].delayType == delayType)
             {
                 m_Active[i].Recycle();
             }
         }
         action?.Invoke();
         return(-1);
     }
 }
        public void DelayPage(DelayType type)
        {
            this.wait = new WebDriverWait(this.driver, TimeSpan.FromMilliseconds((double)type));
            DateTime now = DateTime.Now;

            this.wait.Until(wd => (DateTime.Now - now) - TimeSpan.FromMilliseconds((double)type) > TimeSpan.Zero);
        }
Beispiel #3
0
 private CommandHandler(string name, UserType access, DelayType delayType, Func<MessageEventArgs, ChatMemberViewModel, SendMessage> handler)
 {
     Name = name.ToLower();
     Access = access;
     DelayType = delayType;
     Handler = handler;
 }
Beispiel #4
0
        public static void CancelAfterSlim(this CancellationTokenSource cts, int millisecondsDelay,
                                           DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
        {
            var delay = UniTask.Delay(millisecondsDelay, delayType, delayTiming, cts.Token);

            CancelAfterCore(cts, delay).Forget();
        }
        public static PlayerLoopTimer StartNew(TimeSpan interval, bool periodic, DelayType delayType, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action <object> timerCallback, object state)
        {
            var timer = Create(interval, periodic, delayType, playerLoopTiming, cancellationToken, timerCallback, state);

            timer.Restart();
            return(timer);
        }
        public static UniTask Delay(TimeSpan delayTimeSpan, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (delayTimeSpan < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("Delay does not allow minus delayTimeSpan. delayTimeSpan:" + delayTimeSpan);
            }

            switch (delayType)
            {
            case DelayType.UnscaledDeltaTime:
            {
                return(new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.Realtime:
            {
                return(new UniTask(DelayRealtimePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.DeltaTime:
            default:
            {
                return(new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }
            }
        }
        public static UniTask Delay(TimeSpan delayTimeSpan, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (delayTimeSpan < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("Delay does not allow minus delayTimeSpan. delayTimeSpan:" + delayTimeSpan);
            }

#if UNITY_EDITOR
            // force use Realtime.
            if (PlayerLoopHelper.IsMainThread && !UnityEditor.EditorApplication.isPlaying)
            {
                delayType = DelayType.Realtime;
            }
#endif

            switch (delayType)
            {
            case DelayType.UnscaledDeltaTime:
            {
                return(new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.Realtime:
            {
                return(new UniTask(DelayRealtimePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.DeltaTime:
            default:
            {
                return(new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }
            }
        }
Beispiel #8
0
 public void StartDelay(DelayType type)
 {
     ScoreBoard.PauseTimer();
     leftPaddle.CanMove  = false;
     rightPaddle.CanMove = false;
     gameBall.CanMove    = false;
     delay.Start(type);
 }
Beispiel #9
0
        public static UniTask Delay(int millisecondsDelay, DelayType delayType,
                                    PlayerLoopTiming delayTiming        = PlayerLoopTiming.Update,
                                    CancellationToken cancellationToken = default(CancellationToken))
        {
            var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay);

            return(Delay(delayTimeSpan, delayType, delayTiming, cancellationToken));
        }
Beispiel #10
0
        public void UpdateDelay(DelayType DelayType, int Delay, int DelayRange)
        {
            tmpDelayType  = DelayType;
            tmpDelay      = Delay;
            tmpDelayRange = DelayRange;

            delayUpdated = true;
        }
Beispiel #11
0
 private void Reset()
 {
     this.Id        = 0;
     this.StartTime = 0;
     this.EndTime   = 0;
     this.action    = null;
     this.delayType = DelayType.Invalid;
 }
Beispiel #12
0
 public TimeoutController(DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
 {
     this.timeoutSource = new CancellationTokenSource();
     this.originalLinkCancellationTokenSource = null;
     this.linkedSource = null;
     this.delayType    = delayType;
     this.delayTiming  = delayTiming;
 }
Beispiel #13
0
 public TimeoutController(CancellationTokenSource linkCancellationTokenSource, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
 {
     this.timeoutSource = new CancellationTokenSource();
     this.originalLinkCancellationTokenSource = linkCancellationTokenSource;
     this.linkedSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, linkCancellationTokenSource.Token);
     this.delayType    = delayType;
     this.delayTiming  = delayTiming;
 }
Beispiel #14
0
    public static void Main (string[] args) {
        Console.WriteLine(delayType);

        if ((delayType == DelayType.NoDelay) &&
            (highlightedCombatant != null) && someBool) {
            delayType = DelayType.EndCharacterTurn;
        }

        Console.WriteLine(delayType);
    }
Beispiel #15
0
 public void UpdateDelay(DelayType DelayType, int Delay, int DelayRange, int Index)
 {
     if (tmpActions.Count > Index)
     {
         tmpActions[Index].delayType  = DelayType;
         tmpActions[Index].delay      = Delay;
         tmpActions[Index].delayRange = DelayRange;
         actionUpdated = true;
     }
     delayUpdated = true;
 }
Beispiel #16
0
    public static void Main(string[] args)
    {
        Console.WriteLine(delayType);

        if ((delayType == DelayType.NoDelay) &&
            (highlightedCombatant != null) && someBool)
        {
            delayType = DelayType.EndCharacterTurn;
        }

        Console.WriteLine(delayType);
    }
Beispiel #17
0
        /// <summary>
        /// Timeout with suppress OperationCanceledException. Returns (bool, IsCacneled).
        /// </summary>
        public static async UniTask <bool> TimeoutWithoutException(this UniTask task, TimeSpan timeout,
                                                                   DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update,
                                                                   CancellationTokenSource taskCancellationTokenSource = null)
        {
            var delayCancellationTokenSource = new CancellationTokenSource();
            var timeoutTask = UniTask.Delay(timeout, delayType, timeoutCheckTiming, delayCancellationTokenSource.Token)
                              .SuppressCancellationThrow();

            int  winArgIndex;
            bool taskResultIsCanceled;

            try {
                (winArgIndex, taskResultIsCanceled, _) =
                    await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask);
            }
            catch {
                delayCancellationTokenSource.Cancel();
                delayCancellationTokenSource.Dispose();
                return(true);
            }

            // timeout
            if (winArgIndex == 1)
            {
                if (taskCancellationTokenSource != null)
                {
                    taskCancellationTokenSource.Cancel();
                    taskCancellationTokenSource.Dispose();
                }

                return(true);
            }
            else
            {
                delayCancellationTokenSource.Cancel();
                delayCancellationTokenSource.Dispose();
            }

            if (taskResultIsCanceled)
            {
                return(true);
            }

            return(false);
        }
Beispiel #18
0
    public void Start(DelayType type)
    {
        this.Type = type;
        switch (type)
        {
        case DelayType.RESUME:
            lengthOfDelay = .25f;
            break;

        case DelayType.NEWROUND:
            lengthOfDelay = 2;
            break;

        case DelayType.NONE:
            return;
        }
        startOfDelay = Time.time;
    }
Beispiel #19
0
        public static async UniTask <T> Timeout <T>(this UniTask <T> task, TimeSpan timeout,
                                                    DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update,
                                                    CancellationTokenSource taskCancellationTokenSource = null)
        {
            var delayCancellationTokenSource = new CancellationTokenSource();
            var timeoutTask = UniTask.Delay(timeout, delayType, timeoutCheckTiming, delayCancellationTokenSource.Token)
                              .SuppressCancellationThrow();

            int winArgIndex;

            (bool IsCanceled, T Result)taskResult;
            try {
                (winArgIndex, taskResult, _) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask);
            }
            catch {
                delayCancellationTokenSource.Cancel();
                delayCancellationTokenSource.Dispose();
                throw;
            }

            // timeout
            if (winArgIndex == 1)
            {
                if (taskCancellationTokenSource != null)
                {
                    taskCancellationTokenSource.Cancel();
                    taskCancellationTokenSource.Dispose();
                }

                throw new TimeoutException("Exceed Timeout:" + timeout);
            }
            else
            {
                delayCancellationTokenSource.Cancel();
                delayCancellationTokenSource.Dispose();
            }

            if (taskResult.IsCanceled)
            {
                Error.ThrowOperationCanceledException();
            }

            return(taskResult.Result);
        }
Beispiel #20
0
        private void SendDelayTaskMessage(List <ProcessTask> processTasks, DelayType delayType)
        {
            foreach (var task in processTasks)
            {
                var remindInfos = _tacticManager.GetRemindPersonByDelayTask(task, delayType).GetAwaiter().GetResult();
                foreach (var remindInfo in remindInfos)
                {
                    var remindPerson = remindInfo.Person;
                    //如果提醒间隔小于1天,则不再提醒
                    var count = RemindLogManager.GetAll().Where(o => o.RemindType == "延期提醒" && o.Name == remindPerson.Name && o.TenantId == task.TenantId && o.Message == (task.ProcessSN + "-" + delayType.ToString()) && (o.CreationTime - DateTime.Now).TotalDays < 1).Count();
                    if (count == 0)
                    {
                        var openid = remindPerson.GetPropertyValue <string>("OpenId");
                        //先产生一条提醒记录
                        var remindLog = new RemindLog()
                        {
                            RemindType = "延期提醒",
                            Name       = remindPerson.Name,
                            TenantId   = task.TenantId,
                            Message    = task.ProcessSN + "-" + delayType.ToString()
                        };
                        var timespan = remindInfo.GetAvailableRemindTimeSpan();
                        if (timespan.TotalMinutes > 0)
                        {
                            remindLog.SetPropertyValue("errMsg", $"延迟{timespan.TotalMinutes.ToString("0")}分钟后运行");
                        }
                        var remindLogId = RemindLogManager.InsertAndGetIdAsync(remindLog).Result;
                        var arg         = new SendWeiXinMessageJobArgs()
                        {
                            OpenId      = openid,
                            DataId      = task.Id,
                            RemindLogId = remindLogId,
                            ExtendInfo  = delayType.ToString()
                        };


                        _backgroundJobManager.Enqueue <SendDelayTaskWeiXinMessageJob, SendWeiXinMessageJobArgs>(arg, BackgroundJobPriority.Normal, timespan);
                    }
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Waits until the audio has finished playing. This method will return instantly for looping AudioPlayer.
        /// </summary>
        public async UniTask WaitUntilCompletion()
        {
            if (_player == null)
            {
                return;
            }

            if (_player.Loop)
            {
                return;
            }

            if (_completionTime <= Time.time)
            {
                return;
            }

            DelayType type = Application.isPlaying ? DelayType.DeltaTime : DelayType.Realtime;

            await UniTask.Delay(TimeSpan.FromSeconds(_completionTime - Time.time), type);
        }
Beispiel #22
0
        private void SyncSettings()
        {
            if (buttonUpdated)
            {
                buttonType  = tmpButtonType;
                doubleClick = tmpDoubleClick;

                buttonUpdated = false;
            }

            if (locationUpdated)
            {
                locationType = tmpLocationType;
                x            = tmpX;
                y            = tmpY;
                width        = tmpWidth;
                height       = tmpHeight;

                locationUpdated = false;
            }

            if (delayUpdated)
            {
                delayType  = tmpDelayType;
                delay      = tmpDelay;
                delayRange = tmpDelayRange;

                delayUpdated = false;
            }

            if (countUpdated)
            {
                countType = tmpCountType;
                count     = tmpCount;

                countUpdated = false;
            }
            //System.Diagnostics.Debug.Print("Settings synced");
        }
Beispiel #23
0
        private void SyncSettings()
        {
            if (buttonUpdated)
            {
                buttonType  = tmpButtonType;
                doubleClick = tmpDoubleClick;

                buttonUpdated = false;
            }

            if (locationUpdated)
            {
                locationType = tmpLocationType;
                x            = tmpX;
                y            = tmpY;
                width        = tmpWidth;
                height       = tmpHeight;

                locationUpdated = false;
            }

            if (delayUpdated)
            {
                delayType  = tmpDelayType;
                delay      = tmpDelay;
                delayRange = tmpDelayRange;

                delayUpdated = false;
            }

            if (countUpdated)
            {
                countType = tmpCountType;
                count     = tmpCount;

                countUpdated = false;
            }
        }
        public static PlayerLoopTimer Create(TimeSpan interval, bool periodic, DelayType delayType, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action <object> timerCallback, object state)
        {
#if UNITY_EDITOR
            // force use Realtime.
            if (PlayerLoopHelper.IsMainThread && !UnityEditor.EditorApplication.isPlaying)
            {
                delayType = DelayType.Realtime;
            }
#endif

            switch (delayType)
            {
            case DelayType.UnscaledDeltaTime:
                return(new IgnoreTimeScalePlayerLoopTimer(interval, periodic, playerLoopTiming, cancellationToken, timerCallback, state));

            case DelayType.Realtime:
                return(new RealtimePlayerLoopTimer(interval, periodic, playerLoopTiming, cancellationToken, timerCallback, state));

            case DelayType.DeltaTime:
            default:
                return(new DeltaTimePlayerLoopTimer(interval, periodic, playerLoopTiming, cancellationToken, timerCallback, state));
            }
        }
Beispiel #25
0
        /// <summary>
        /// Update any delays in the combat system.
        /// </summary>
        /// <remarks>
        /// This function may cause combat to end, setting the singleton to null.
        /// </remarks>
        private void UpdateDelay(int elapsedMilliseconds)
        {
            if (delayType == DelayType.NoDelay)
            {
                return;
            }

            // increment the delay
            currentDelay += elapsedMilliseconds;

            // if the delay is ongoing, then we're done
            if (currentDelay < totalDelay)
            {
                return;
            }
            currentDelay = 0;

            // the delay has ended, so the operation implied by the DelayType happens
            switch (delayType)
            {
                case DelayType.StartCombat:
                    // determine who goes first and start combat
                    int whoseTurn = Session.Random.Next(2);
                    if (whoseTurn == 0)
                    {
                        BeginPlayersTurn();
                    }
                    else
                    {
                        BeginMonstersTurn();
                    }
                    delayType = DelayType.NoDelay;
                    break;

                case DelayType.EndCharacterTurn:
                    if (IsPlayersTurn)
                    {
                        // check to see if the players' turn is complete
                        if (IsPlayersTurnComplete)
                        {
                            delayType = DelayType.EndRound;
                            break;
                        }
                        // find the next player
                        int highlightedIndex = players.FindIndex(
                            delegate(CombatantPlayer player)
                            {
                                return (player == 
                                    highlightedCombatant as CombatantPlayer);
                            });
                        int nextIndex = (highlightedIndex + 1) % players.Count;
                        while (players[nextIndex].IsDeadOrDying ||
                            players[nextIndex].IsTurnTaken)
                        {
                            nextIndex = (nextIndex + 1) % players.Count;
                        }
                        BeginPlayerTurn(players[nextIndex]);
                    }
                    else
                    {
                        // check to see if the monsters' turn is complete
                        if (IsMonstersTurnComplete)
                        {
                            delayType = DelayType.EndRound;
                            break;
                        }
                        // find the next monster
                        BeginMonsterTurn(null);
                    }
                    delayType = DelayType.NoDelay;
                    break;

                case DelayType.EndRound:
                    // check for turn completion
                    if (IsPlayersTurn && IsPlayersTurnComplete)
                    {
                        BeginMonstersTurn();
                    }
                    else if (!IsPlayersTurn && IsMonstersTurnComplete)
                    {
                        BeginPlayersTurn();
                    }
                    delayType = DelayType.NoDelay;
                    break;

                case DelayType.FleeAttempt:
                    if (fleeThreshold <= 0)
                    {
                        delayType = DelayType.EndCharacterTurn;
                        Session.Hud.ActionText = "This Fight Cannot Be Escaped...";
                        if (highlightedCombatant != null)
                        {
                            highlightedCombatant.IsTurnTaken = true;
                        }
                    }
                    else if (CalculateFleeAttempt())
                    {
                        delayType = DelayType.FleeSuccessful;
                        Session.Hud.ActionText = "Your Party Has Fled!";
                    }
                    else
                    {
                        delayType = DelayType.EndCharacterTurn;
                        Session.Hud.ActionText = "Your Party Failed to Escape!";
                        if (highlightedCombatant != null)
                        {
                            highlightedCombatant.IsTurnTaken = true;
                        }
                    }
                    break;

                case DelayType.FleeSuccessful:
                    EndCombat(CombatEndingState.Fled);
                    delayType = DelayType.NoDelay;
                    break;
            }
        }
 /// <summary>
 /// Timeout with suppress OperationCanceledException. Returns (bool IsTimeout, T Result).
 /// </summary>
 public static async UniTask <(bool IsTimeout, T Result)> TimeoutWithoutException <T>(this UniTask <T> task, TimeSpan timeout, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming timeoutCheckTiming = PlayerLoopTiming.Update, CancellationTokenSource taskCancellationTokenSource = null)
 {
 public UnityEventLooper(DelayType delayType) : base(delayType)
 {
 }
 public UnityEventLooper(DelayType delayType, string name) : base(delayType, name)
 {
 }
Beispiel #29
0
        public ChorusEffector(
            IBGCStream stream,
            double minDelay     = 0.040,
            double maxDelay     = 0.060,
            double rate         = 0.25,
            DelayType delayType = DelayType.Sine,
            TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Passthrough)
            : base(stream)
        {
            int adjustmentSamples = (int)Math.Round(SamplingRate / rate);

            adjustments = new int[Channels * adjustmentSamples];

            double centerDelay    = 0.5 * (maxDelay + minDelay);
            double delayAmplitude = 0.5 * (maxDelay - minDelay);

            switch (delayType)
            {
            case DelayType.Sine:
                for (int samp = 0; samp < adjustmentSamples; samp++)
                {
                    for (int chan = 0; chan < Channels; chan++)
                    {
                        adjustments[samp * Channels + chan] = (int)Math.Round(stream.SamplingRate * (centerDelay + delayAmplitude * Math.Sin(2.0 * Math.PI * samp / adjustmentSamples)));
                    }
                }
                break;

            case DelayType.Triangle:
            {
                int peakSample   = adjustmentSamples / 4;
                int valleySample = 3 * peakSample;

                for (int samp = 0; samp < adjustmentSamples; samp++)
                {
                    double triangleValue;
                    if (samp < peakSample)
                    {
                        //Initial Rise
                        triangleValue = GeneralMath.Lerp(0, 1.0, samp / (double)peakSample);
                    }
                    else if (samp < valleySample)
                    {
                        triangleValue = GeneralMath.Lerp(1.0, -1.0, (samp - peakSample) / (double)(valleySample - peakSample));
                    }
                    else
                    {
                        triangleValue = GeneralMath.Lerp(-1.0, 0.0, (samp - valleySample) / (double)(adjustmentSamples - valleySample));
                    }


                    for (int chan = 0; chan < Channels; chan++)
                    {
                        adjustments[samp * Channels + chan] = (int)Math.Round(stream.SamplingRate * (centerDelay + delayAmplitude * triangleValue));
                    }
                }
            }
            break;

            default:
                throw new StreamCompositionException($"Unexpected DelayType: {delayType}");
            }


            adjIndexA = 0;
            adjIndexB = adjustments.Length / 2;

            int maxAdjustment = adjustments.Max();

            bufferSize = Math.Max(MIN_BUFFER_SIZE, Channels * maxAdjustment.CeilingToPowerOfTwo());

            newBuffer = new float[bufferSize];
            oldBuffer = new float[bufferSize];

            this.rmsBehavior = rmsBehavior;

            channelSampleAdjustment = (int)Math.Ceiling(maxDelay * stream.SamplingRate);

            if (stream.ChannelSamples == int.MaxValue)
            {
                ChannelSamples = int.MaxValue;
                TotalSamples   = int.MaxValue;
            }
            else
            {
                ChannelSamples = stream.ChannelSamples + channelSampleAdjustment;
                TotalSamples   = Channels * ChannelSamples;
            }
        }
Beispiel #30
0
        /// <summary>
        /// Update the combat engine for this frame.
        /// </summary>
        private void UpdateCombatEngine(GameTime gameTime)
        {
            // check for the end of combat
            if (ArePlayersDefeated)
            {
                EndCombat(CombatEndingState.Loss);
                return;
            }
            else if (AreMonstersDefeated)
            {
                EndCombat(CombatEndingState.Victory);
                return;
            }

            // update the target selections
            if ((highlightedCombatant != null) &&
                (highlightedCombatant.CombatAction != null))
            {
                SetTargets(highlightedCombatant.CombatAction.Target,
                    highlightedCombatant.CombatAction.AdjacentTargets);
            }

            //update active battle timers
            foreach (CombatantPlayer player in players)
            {
                if (player.AC > 5000 && player.readyForQueue)
                {
                    player.AC = 5000;

                    //add player if hes not already there
                    if (!selectionQueue.Contains(player))
                    {
                        selectionQueue.Enqueue(player);
                        player.readyForQueue = false;
                    }
                }
                else if(!player.IsDeadOrDying)
                    player.AC += gameTime.ElapsedGameTime.Milliseconds;

            }

            foreach (CombatantMonster monster in monsters)
            {
                if (monster.AC > 4000 && monster.readyForQueue)
                {
                    monster.AC = 4000;

                    //add player if hes not already there
                    if (!actionQueue.Contains(monster))
                    {
                        actionQueue.Enqueue(monster);
                        monster.readyForQueue = false;
                    }
                }
                else if(!monster.IsDeadOrDying)
                    monster.AC += gameTime.ElapsedGameTime.Milliseconds;
            }

            //show action menu if player's turn is ready
            if (selectionQueue.Count > 0 && !selectionQueueLocked)
            {
                if (currentSelector == null)
                {
                    isPlayersTurn = true;
                    currentSelector = selectionQueue.Peek();
                    currentSelector.IsTurnTaken = false;
                    BeginPlayerTurn((CombatantPlayer)selectionQueue.Peek());
                    selectionQueue.Dequeue();
                    selectionQueueLocked = true;
                }
            }

            //resolve actions
            bool removeAction = false;

            //remove dead people in the front of the queue
            while(actionQueue.Count > 0 && actionQueue.Peek().IsDeadOrDying)
                actionQueue.Dequeue();

            if (actionQueue.Count > 0 )
            {
                //unlock queue after current combatant finishes its action.
                if(currentCombatant != null)
                    if(currentCombatant.CombatAction == null)
                        actionQueueLocked = false;
                    else if(currentCombatant.CombatAction.Stage == CombatAction.CombatActionStage.NotStarted)
                        actionQueueLocked = false;

                if (actionQueue.Peek().GetType() == typeof(CombatantPlayer) && !actionQueueLocked)
                {
                    //execute player action
                    actionQueue.Peek().CombatAction.Start();

                    currentCombatant = actionQueue.Peek();
                    removeAction = true;
                }

                if (actionQueue.Peek().GetType() == typeof(CombatantMonster) && !actionQueueLocked)
                {
                    //execute monster action
                    BeginMonsterTurn((CombatantMonster)actionQueue.Peek() );

                    currentCombatant = actionQueue.Peek();
                    removeAction = true;
                }

                if (removeAction)
                {
                    actionQueue.Dequeue();
                    actionQueueLocked = true;
                }
            }

            // update the delay
            UpdateDelay(gameTime.ElapsedGameTime.Milliseconds);

            // UpdateDelay might cause combat to end due to a successful escape,
            // which will set the singleton to null.
            if (singleton == null)
            {
                return;
            }

            // update the players
            foreach (CombatantPlayer player in players)
            {
                player.Update(gameTime);
            }

            // update the monsters
            foreach (CombatantMonster monster in monsters)
            {
                monster.Update(gameTime);
            }

            // check for completion of the highlighted combatant
            if ((delayType == DelayType.NoDelay) &&
                (highlightedCombatant != null) && highlightedCombatant.IsTurnTaken)
            {
                delayType = DelayType.EndCharacterTurn;
            }

            // handle any player input
            HandleInput();
        }
Beispiel #31
0
        private void Filter(string bandwidth, string sessions, int minDelay, int maxDelay,
                            DelayType type, bool removeInner, bool removeMore)
        {
            for (int row = 0; row < 4; row++)
            {
                for (int col = 0; col < 5; col++)
                {
                    m_data[row, col] = new List <Point>();

                    if ((bandwidth != "ALL" && bandwidth != cols[col]) ||
                        (sessions != "ALL" && sessions != rows[row]))
                    {
                        continue;
                    }

                    MemoryStream ms = new MemoryStream(m_file);
                    StreamReader sr = new StreamReader(ms);
                    string       line;

                    // Skip the first two lines
                    sr.ReadLine();
                    sr.ReadLine();

                    // Process the remaining
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] fields = line.Split('\t');

                        double bw   = Convert.ToDouble(fields[0]);
                        int    num  = Convert.ToInt32(fields[1]);
                        double pct  = Convert.ToDouble(fields[2]);
                        int    qlen = Convert.ToInt32(fields[3]);
                        double maxq = Convert.ToDouble(fields[4]);
                        double avgq = Convert.ToDouble(fields[5]);
                        int    maxd = Convert.ToInt32(fields[6]);
                        int    avgd = Convert.ToInt32(fields[7]);

                        // Rate is like "26.8 (0.42)"
                        string[] rateFields = fields[8].Split(new char[] { ' ', '(', ')' },
                                                              StringSplitOptions.RemoveEmptyEntries);
                        double rate = Convert.ToDouble(rateFields[1]);

                        if (rows[row] == fields[1] && cols[col] == fields[0])
                        {
                            if (type == DelayType.Maximum)
                            {
                                if (maxd >= minDelay && maxd <= maxDelay)
                                {
                                    m_data[row, col].Add(
                                        new Point((float)pct, qlen, maxd, (float)rate));
                                }
                            }
                            else if (type == DelayType.Average)
                            {
                                if (avgd >= minDelay && avgd <= maxDelay)
                                {
                                    m_data[row, col].Add(
                                        new Point((float)pct, qlen, avgd, (float)rate));
                                }
                            }
                        }
                    }
                    sr.Close();
                    ms.Close();

                    if (removeInner) // Remove inner nodes when necessary
                    {
                        List <Point> points = m_data[row, col];
                        for (int i = 0; i < points.Count; i++)
                        {
                            Point p    = points[i];
                            float pct  = p.TokenRate;
                            int   qlen = p.BufferSize;

                            // Determine if it's an inner point
                            bool top   = false; // if there's a point on top
                            bool right = false; // if there's a point on the right
                            for (int j = i + 1; j < points.Count; j++)
                            {
                                if (points[j].BufferSize == qlen && points[j].TokenRate > pct)
                                {
                                    right = true;
                                }
                                if (points[j].TokenRate == pct && points[j].BufferSize > qlen)
                                {
                                    top = true;
                                }
                                if (right && top)
                                {
                                    break;
                                }
                            }

                            if (top && right)
                            {
                                points.RemoveAt(i--);
                            }
                            else if ((top || right) && removeMore)
                            {
                                points.RemoveAt(i--);
                            }
                        }
                    }
                }
            }
        }
Beispiel #32
0
        /// <summary>
        /// Construct a new CombatEngine object.
        /// </summary>
        /// <param name="players">The player combatants.</param>
        /// <param name="monsters">The monster combatants.</param>
        /// <param name="fleeThreshold">The odds of success when fleeing.</param>
        private CombatEngine(List<CombatantPlayer> players,
            List<CombatantMonster> monsters, int fleeThreshold)
        {
            // check the parameters
            if ((players == null) || (players.Count <= 0) || 
                (players.Count > PlayerPositions.Length))
            {
                throw new ArgumentException("players");
            }
            if ((monsters == null) || (monsters.Count <= 0) || 
                (monsters.Count > MonsterPositions.Length))
            {
                throw new ArgumentException("monsters");
            }

            // assign the parameters
            this.players = players;
            this.monsters = monsters;
            this.fleeThreshold = fleeThreshold;

            // assign positions
            for (int i = 0; i < players.Count; i++)
            {
                if (i >= PlayerPositions.Length)
                {
                    break;
                }
                players[i].Position =
                    players[i].OriginalPosition =
                    PlayerPositions[i];
            }
            for (int i = 0; i < monsters.Count; i++)
            {
                if (i >= MonsterPositions.Length)
                {
                    break;
                }
                monsters[i].Position =
                    monsters[i].OriginalPosition =
                    MonsterPositions[i];
            }

            // sort the monsters by the y coordinates, descending
            monsters.Sort(delegate(CombatantMonster monster1, CombatantMonster monster2)
            {
                return monster2.OriginalPosition.Y.CompareTo(
                    monster1.OriginalPosition.Y);
            });

            // create the selection sprites
            CreateSelectionSprites();

            // create the combat effect sprites
            CreateCombatEffectSprites();

            // start the first combat turn after a delay
            delayType = DelayType.StartCombat;

            // start the combat music
    //        AudioManager.PushMusic(TileEngine.Map.CombatMusicCueName);
        }
Beispiel #33
0
 public ActionLooper(DelayType delayType, string name) : base(delayType, name)
 {
 }
Beispiel #34
0
 private static extern ErrorCode SetDelay(IntPtr channel, DelayType delaytype, uint delayhi, uint delaylo);
Beispiel #35
0
        private void SyncSettings()
        {
            if (buttonUpdated)
            {
                buttonType = tmpButtonType;
                doubleClick = tmpDoubleClick;

                buttonUpdated = false;
            }

            if (locationUpdated)
            {
                locationType = tmpLocationType;
                x = tmpX;
                y = tmpY;
                width = tmpWidth;
                height = tmpHeight;

                locationUpdated = false;
            }

            if (delayUpdated)
            {
                delayType = tmpDelayType;
                delay = tmpDelay;
                delayRange = tmpDelayRange;

                delayUpdated = false;
            }

            if (countUpdated)
            {
                countType = tmpCountType;
                count = tmpCount;

                countUpdated = false;
            }
            //System.Diagnostics.Debug.Print("Settings synced");
        }
Beispiel #36
0
        public void UpdateDelay(DelayType DelayType, int Delay, int DelayRange)
        {
            tmpDelayType = DelayType;
            tmpDelay = Delay;
            tmpDelayRange = DelayRange;

            delayUpdated = true;
        }
Beispiel #37
0
 public ActionLooper(DelayType delayType) : base(delayType)
 {
 }
Beispiel #38
0
        /// <summary>
        /// Update the combat engine for this frame.
        /// </summary>
        private void UpdateCombatEngine(GameTime gameTime)
        {
            // check for the end of combat
            if (ArePlayersDefeated)
            {
                EndCombat(CombatEndingState.Loss);
                return;
            }
            else if (AreMonstersDefeated)
            {
                EndCombat(CombatEndingState.Victory);
                return;
            }

            // update the target selections
            if ((highlightedCombatant != null) &&
                (highlightedCombatant.CombatAction != null))
            {
                SetTargets(highlightedCombatant.CombatAction.Target,
                    highlightedCombatant.CombatAction.AdjacentTargets);
            }

            // update the delay
            UpdateDelay(gameTime.ElapsedGameTime.Milliseconds);
            // UpdateDelay might cause combat to end due to a successful escape,
            // which will set the singleton to null.
            if (singleton == null)
            {
                return;
            }

            // update the players
            foreach (CombatantPlayer player in players)
            {
                player.Update(gameTime);
            }

            // update the monsters
            foreach (CombatantMonster monster in monsters)
            {
                monster.Update(gameTime);
            }

            // check for completion of the highlighted combatant
            if ((delayType == DelayType.NoDelay) &&
                (highlightedCombatant != null) && highlightedCombatant.IsTurnTaken)
            {
                delayType = DelayType.EndCharacterTurn;
            }

            // handle any player input
            HandleInput();
        }
Beispiel #39
0
    void DrawItem()
    {
        contentColor    = GUI.contentColor;
        backgroundColor = GUI.backgroundColor;

        string oldStringValue = string.Empty;
        int    oldIntValue    = 0;
        float  oldFloatValue  = 0;
        bool   oldBoolValue   = true;

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("ID:", GUILayout.Width(100));
        oldStringValue = rewardData.id;
        rewardData.id  = EditorGUILayout.TextField(rewardData.id, GUILayout.Width(150));
        if (rewardData.id != oldStringValue)
        {
            dirty = true;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Reward Type:", GUILayout.Width(100));
        RewardType oldRewardType = rewardData.rewardType;

        rewardData.rewardType = (RewardType)EditorGUILayout.EnumPopup(rewardData.rewardType, GUILayout.Width(150));
        if (rewardData.rewardType != oldRewardType)
        {
            dirty = true;
        }
        EditorGUILayout.EndHorizontal();

        if (rewardData.rewardType != RewardType.MysteryBox)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Delay Type:", GUILayout.Width(100));
            DelayType oldDelayType = rewardData.delayType;
            rewardData.delayType = (DelayType)EditorGUILayout.EnumPopup(rewardData.delayType, GUILayout.Width(150));
            if (rewardData.delayType != oldDelayType)
            {
                dirty = true;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            EditorHelpers.DrawListOfInts("Delays:", rewardData.delays, ref dirty);
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Social Factor:", GUILayout.Width(100));
        oldFloatValue           = rewardData.socialFactor;
        rewardData.socialFactor = EditorGUILayout.FloatField(rewardData.socialFactor, GUILayout.Width(150));
        if (rewardData.socialFactor != oldFloatValue)
        {
            dirty = true;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("RV Factor:", GUILayout.Width(100));
        oldFloatValue       = rewardData.rvFactor;
        rewardData.rvFactor = EditorGUILayout.FloatField(rewardData.rvFactor, GUILayout.Width(150));
        if (rewardData.rvFactor != oldFloatValue)
        {
            dirty = true;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Double Factor:", GUILayout.Width(100));
        oldBoolValue            = rewardData.doubleFactor;
        rewardData.doubleFactor = EditorGUILayout.Toggle(rewardData.doubleFactor, GUILayout.Width(150));
        if (rewardData.doubleFactor != oldBoolValue)
        {
            dirty = true;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Permanent Social Factor:", GUILayout.Width(100));
        oldBoolValue = rewardData.permanentSocialFactor;
        rewardData.permanentSocialFactor = EditorGUILayout.Toggle(rewardData.permanentSocialFactor, GUILayout.Width(150));
        if (rewardData.permanentSocialFactor != oldBoolValue)
        {
            dirty = true;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();
        EditorHelpers.DrawListOfGameElemetData("Restrictions:", rewardData.restrictions, ref dirty);
        EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
    }