Example #1
0
    // Enemy Statuses
    public void Boost(float speed, float timer)
    {
        if (!GetComponent <ThirdPersonCharacter>() && mobType != MobType.Tornado)
        {
            return;
        }

        ThirdPersonCharacter character;

        if (GetComponent <ThirdPersonCharacter>())
        {
            character = GetComponent <ThirdPersonCharacter>();
            character.MoveSpeedMultiplier = speed;
        }

        agent.speed = speed;

        actionBuffTimer    = timer;
        timedAction        = Boost;
        modifierResetValue = this.speed;

        if (timer > 0)
        {
            canKnockBackPlayer = true;
        }
        else
        {
            canKnockBackPlayer = false;

            if (mobType == MobType.Tikbalang)
            {
                animator.SetBool("Charging", false);
            }
        }
    }
        private void FileLoaded(object sender, EventArgs e)
        {
            var browser = sender as WebView;

            if (browser == null)
            {
                return;
            }
            var saveFile = SavePath + "\\" + browser.Source.Segments[browser.Source.Segments.Length - 1].Split('.')[0] + ".png";

            //make file name parent folder name plus file name.
            TimedAction.ExecuteWithDelay(delegate
            {
                browser.SaveToPNG(saveFile);
                //remove file
                var remaining = FileNames.Count;
                switch (remaining)
                {
                case 0:
                    break;

                case 1:
                    FileNames.Clear();
                    break;

                default:
                    FileNames.RemoveAt(0);
                    ScreenShot();
                    break;
                }
            }, TimeSpan.FromMilliseconds(Settings.AnimationDelay));
        }
Example #3
0
        private void RestartTracking()
        {
            _movingDuration.Restart();

            _autoOffTimer?.Cancel();
            _autoOffTimer = _schedulerService.In(_settings.AutoOffTimeout).Execute(() => SetState(RollerShutterStateId.Off));
        }
            private MemoryStream GetBufferedSourceStream()
            {
                wc = new WebClient();
                using (var ta = new TimedAction((ts) =>
                {
                    log.Debug($"download time {ts.ToString()}");
                }))
                {
                    buffer = new byte[8192 * 2];
                    //int counter = 0;
                    webStream = wc.OpenRead(musicSource);
                    stream    = new MemoryStream();
                    bytesRead = webStream.Read(buffer, 0, buffer.Length);
                    stream.Write(buffer, 0, bytesRead);
                    Task.Run(() =>
                    {
                        while (bytesRead > 0)
                        {
                            bytesRead = webStream.Read(buffer, 0, buffer.Length);
                            stream.Write(buffer, 0, bytesRead);
                        }
                    });
                }
                IMFByteStream bs = MediaFoundationApi.CreateByteStream(stream);

                return(stream);
            }
Example #5
0
        public void CancelTest()
        {
            var called           = false;
            var sw               = new Stopwatch();
            ManualResetEvent mre = new ManualResetEvent(false);

            Action act = new Action(() =>
            {
                called = true;
                sw.Stop();
                mre.Set();
            });

            var delayedAction = new TimedAction(act);

            sw.Start();
            delayedAction.RunWithDelay(2000);
            delayedAction.Cancel();

            var signaled = mre.WaitOne(3000);

            Assert.IsFalse(called);
            Assert.IsFalse(signaled);
            Assert.IsTrue(sw.IsRunning);
        }
            private async Task <string> DownloadFile(string url, EncodingType encodingType, string uid)
            {
                using (var ta = new TimedAction((ts) =>
                {
                    log.Debug($"download time {ts.ToString()}");
                }))
                {
                    string extension;// = null; //".mp3";
                    switch (encodingType)
                    {
                    case EncodingType.flac:
                        extension = ".flac";
                        break;

                    default:
                        extension = ".mp3";
                        break;
                    }
                    var uniqueName = Path.Combine(localStore, uid + extension);
                    var wc         = new WebClient();
                    log.Debug($"downloading from {url} to {uniqueName}");
                    await wc.DownloadFileTaskAsync(url, uniqueName);

                    return(uniqueName);
                }
            }
Example #7
0
    protected virtual void AddBeerDrinkingAction()
    {
        KeyValuePair <NeedType, float>[] rewards = new KeyValuePair <NeedType, float> [2];
        rewards[0] = new KeyValuePair <NeedType, float>(NeedType.FUN, 30f);
        rewards[1] = new KeyValuePair <NeedType, float>(NeedType.BLADDER, -20f);

        TimedAction action = new TimedAction(
            beerBottle.GetComponent <AdvertisingObject>(),
            "Drinking beer",
            null,
            rewards,
            () => { // onend
            beerBottle.transform.parent = null;
            beerBottle.GetComponent <Rigidbody>().isKinematic = false;
            beerBottle.GetComponent <Collider>().enabled      = true;
            RubbishSpawner.AddRubbishToObject(beerBottle, 5f, 2f);
            interactable = true;
            GetComponent <AIMoveController>().drunkness += 0.4f;
            ikcontrol.DrinkItem(false);
            ikcontrol.GrabItem(false);
            GetComponent <UsePPSound>().Happy();
        },
            () => {
            GetComponent <UsePPSound>().PlayBeerBotteClinging();
            ikcontrol.DrinkItem(true);
        },       // on start
            5f); // dirnking duration

        GetComponent <ActionManager>().actionQueue.Enqueue(action);
    }
Example #8
0
 public User(ulong userId, ulong guildId, TimedAction action, TimeSpan length)
 {
     UserId  = userId;
     GuildId = guildId;
     Length  = length;
     Action  = action;
 }
Example #9
0
        public static void Main(params string[] args)
        {
            ILogger logger = new ConsoleLoggerWithProgressIndicator();

            try
            {
                var parameters = Args.Parse <Parameters>(args);
                if (parameters == null)
                {
                    return;
                }

                var context     = new ActionContext(parameters, logger);
                var action      = new ActionComposer().Compose(parameters.Action, context);
                var timedAction = new TimedAction(action);
                timedAction.Execute();

                Console.WriteLine("Completed, action took {0}", timedAction.Duration);
            }
            catch (Exception e)
            {
                logger.LogInfo("An error occured: {0}", e);
                throw;
            }
        }
Example #10
0
        private void RestartTracking()
        {
            _movingDuration.Restart();

            _autoOffTimer?.Cancel();
            _autoOffTimer = _timer.In(_settings.AutoOffTimeout).Do(() => SetState(RollerShutterStateId.Off));
        }
Example #11
0
 public void Restart(TimedAction timedAction)
 {
     if (!IsActive(timedAction))
     {
         myTimers.Add(timedAction);
     }
 }
Example #12
0
    public static TimedAction CreateTimedAction(float duration, DateTime date)
    {
        TimedAction new_action = new TimedAction(duration, date);

        TimeManager.RegisterTimedAction(new_action);
        return(new_action);
    }
Example #13
0
    //warning: big boi spagaettii kode up ahead (or should i say down)
    public IEnumerator TimerCoroutine()
    {
        while (true)
        {
            TimedAction currentAction = null;
            float       zeroTime      = Time.time;

            while (true)
            {
                foreach (TimedAction action in actions)
                {
                    if (Time.time > zeroTime + action.waitTime && action.test())
                    {
                        currentAction = action;
                        break;
                    }
                }
                if (currentAction != null)
                {
                    break;
                }
                if (passiveWait == 0)
                {
                    yield return(new WaitForEndOfFrame());
                }
                else
                {
                    yield return(new WaitForSeconds(passiveWait));
                }
            }
            currentAction.action();
            yield return(new WaitForSeconds(currentAction.cooldown));
        }
    }
Example #14
0
        private void BuildGuardRecords(ref Dictionary <int, GuardRecord> records, ref TimedAction[] actions)
        {
            TimedAction lastAction  = new TimedAction();
            int         activeGuard = 0;

            foreach (TimedAction action in actions)
            {
                switch (action.action)
                {
                case GuardAction.FallsAsleep: break;

                case GuardAction.WakesUp:
                    UpdateGuardRecord(ref records, activeGuard, lastAction.time.Minute, action.time.Minute);
                    break;

                case GuardAction.StartShift: activeGuard = action.guardNumber; break;
                }

                lastAction = action;
            }

            // Take a copy of the keys so we can update the dictionary for each one
            List <int> keys = new List <int>(records.Keys);

            foreach (int key in keys)
            {
                GuardRecord record = records[key];
                record.sleepiestMinuteAndCount = GetCount(ref records, key);
                records[key] = record;
            }
        }
Example #15
0
        protected override void Execute()
        {
            var          unit       = (UnitEntity)this.Source;
            TilePosition p          = (TilePosition)this.World.GetEntityPosition(this.Source);
            Point        currentPos = p.Point;

            if (usePoint)
            {
                v = new Vector(currentPos, toward);
            }

            Point newPos  = currentPos + v;
            var   preMove = new PreMoveEvent(unit, currentPos, newPos);

            this.Source.Raise(preMove);
            if (preMove.MoveStopped)
            {
                this.moveStopped = true;
                return;
            }
            this.Source.Raise(new BeginMoveEvent(unit, currentPos, newPos, this.duration));
            if (duration != 0)
            {
                TimedAction t = this.Factory.CreateTimer(delegate
                {
                    MoveUnit(currentPos, newPos);
                });
                t.SetSingle(duration);
                this.RunAction(t);
            }
            else
            {
                MoveUnit(currentPos, newPos);
            }
        }
Example #16
0
    public static TimedAction CreateTimedAction(TimedAction existing_action)
    {
        TimedAction new_action = existing_action;

        TimeManager.RegisterTimedAction(new_action);
        return(new_action);
    }
        void OnMenuLoaded(Initialized.Data e)
        {
            m_subscriberList.Unsubscribe();
            m_subscriberList.Clear();

            Log.Info("Game Loaded");

            TimedAction.DelayedCall(actionDelay, () =>
            {
                var menu = GameObject.FindObjectOfType <MainMenuLogic>();

                if (menu == null)
                {
                    Log.Error("Impossible to find the main menu object !");
                    return;
                }
                menu.OnMultiplayerClicked();

                TimedAction.DelayedCall(actionDelay, () =>
                {
                    menu.OnOnlineMPScreenClicked();
                    TimedAction.DelayedCall(actionDelay, () => OnMultiplayerMenu(menu.onlineMenuLogic_));
                });
            });
        }
Example #18
0
        /// <summary>
        /// Invokes <paramref name="action"/> after <paramref name="timeInSeconds"/> seconds has passed. Only accurate down to seconds, don't use for exact measurements.
        /// </summary>
        /// <param name="action">The action to perform.</param>
        /// <param name="timeInSeconds">The amount of seconds to wait.</param>
        protected TimedAction InvokeTimedAction(Action action, int timeInSeconds)
        {
            TimedAction ta = new TimedAction(action, timeInSeconds, GuildHandler.Clock);

            ta.OnExceptionOccured += (e) => Core.Log.Exception(e);
            ta.Start();
            return(ta);
        }
Example #19
0
        private void Start()
        {
            _powerGpioPin.Write(BinaryState.High);
            _movingDuration.Restart();

            _autoOffTimer?.Cancel();
            _autoOffTimer = _timer.In(Settings.AutoOffTimeout.Value).Do(() => SetState(RollerShutterState.Stopped));
        }
Example #20
0
    public static TimedAction CreateTimedAction(string timed_action_json)
    {
        TimedAction new_action = JsonUtility.FromJson <TimedAction> (timed_action_json);        // ERROR HERE

        new_action.DeserializeDate();
        CreateTimedAction(new_action);
        return(new_action);
    }
 private void StartTimeout(object sender, EventArgs e)
 {
     _timeout = _timer.In(_slowDuration).Do(() =>
     {
         _actuator.SetState(new StatefulComponentState("2"));
         _timeout = _timer.In(_fastDuration).Do(() => _actuator.TryTurnOff());
     });
 }
Example #22
0
 private void StartTimeout(object sender, EventArgs e)
 {
     _timeout = _schedulerService.In(_slowDuration).Execute(() =>
     {
         _actuator.SetState(new NamedComponentState("2"));
         _timeout = _schedulerService.In(_fastDuration).Execute(() => _actuator.TryTurnOff());
     });
 }
Example #23
0
        private void StartTimeout()
        {
            if (!GetConditionsAreFulfilled())
            {
                return;
            }

            _turnOffTimeout = _timer.In(_wrappedSettings.Duration).Do(TurnOff);
        }
Example #24
0
    protected virtual void AddDanceAction()
    {
        KeyValuePair <NeedType, float>[] ads = new KeyValuePair <NeedType, float> [2];
        ads[0] = new KeyValuePair <NeedType, float>(NeedType.SOCIAL, socialValue);
        ads[1] = new KeyValuePair <NeedType, float>(NeedType.FUN, funValue);
        TimedAction danceAction = new TimedAction(this, actionName, ads, ads, OnDanceEnd, null, Random.Range(danceDurationMin, danceDurationMax));

        advertisedActions.Add(danceAction);
    }
Example #25
0
        /// <summary>
        /// Stops the given timed action; preventing the event from being called
        /// </summary>
        /// <param name="action">The timed action to stop</param>
        /// <returns>False if the action is not in the list of actions</returns>
        public bool StopTimedAction(TimedAction action)
        {
            if (action == null)
            {
                return(false);
            }

            action.Disable();
            return(_timedActions.Remove(action));
        }
Example #26
0
    // Use this for initialization
    void Start()
    {
        float distance = Vector2.Distance(start_pos, destination);

        _travel_time = distance / squad.speed;
        float _travel_time_seconds = _travel_time * 3600f;

        action = TimedActionFactory.CreateTimedAction(_travel_time_seconds, DateTime.Now);
        Debug.Log(_travel_time_seconds);
    }
Example #27
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var fileContents = File.ReadAllLines(levelSelectModel.filePath);

            fileContents[0] = "\0\0\0\0\0\0\0\0" + LevelSelectModel.Levels.FirstOrDefault(x => x.Value == comboBox.SelectedValue.ToString()).Value;
            fileContents[1] = LevelSelectModel.Levels.FirstOrDefault(x => x.Value == comboBox.SelectedValue.ToString()).Key;
            File.WriteAllLines(levelSelectModel.filePath, fileContents);
            lblSaved.Content = "Saved!";
            TimedAction.ExecuteWithDelay(new Action(delegate { lblSaved.Content = ""; }), TimeSpan.FromSeconds(2));
        }
Example #28
0
        private void TryInvokeTimedEvent(float time, int index)
        {
            TimedAction action = _timedActions[index];

            if (time - action.TimeStarted >= action.Duration && action.GetEnabled())
            {
                action.Disable();
                action.Event.Invoke();
                _timedActions.Remove(action);
            }
        }
Example #29
0
 public void Schedule(TimedAction timedAction)
 {
     if (timedAction == null)
     {
         return;
     }
     if (!IsActive(timedAction))
     {
         myTimers.Add(timedAction);
     }
 }
Example #30
0
        private void StartBathode(IArea bathroom)
        {
            bathroom.GetMotionDetector().Settings.IsEnabled = false;

            bathroom.GetLamp(LowerBathroom.LightCeilingDoor).TryTurnOn();
            bathroom.GetLamp(LowerBathroom.LightCeilingMiddle).TryTurnOff();
            bathroom.GetLamp(LowerBathroom.LightCeilingWindow).TryTurnOff();
            bathroom.GetLamp(LowerBathroom.LampMirror).TryTurnOff();

            _bathmodeResetTimer?.Cancel();
            _bathmodeResetTimer = _schedulerService.In(TimeSpan.FromHours(1)).Execute(() => bathroom.GetMotionDetector().Settings.IsEnabled = true);
        }
Example #31
0
        protected override bool Execute(float delta)
        {
            if(_current==null)
                if (Actions.Any())
                {
                    _current = Actions[0];
                    Actions.RemoveAt(0);
                }
                else
                    return false;

            _current.Time += delta;
            if (_current.Action(_current.Time))
                return true;
            _current = null;
            return Actions.Any();
        }
 //C# 6.0
 void Disable(TimedAction unused)
 {
     WasDisabled = !UI_Object.interactable;
     UI_Object.interactable = false;
 }
Example #33
0
 void EndAction()
 {
     if (CurrentAction.ProducedItems != null)
     {
         Inventory inventory = GameObject.FindWithTag("InventoryManager").GetComponent<InventoryManager>().Inventory;
         foreach (TimedAction.ProducedItem item in CurrentAction.ProducedItems)
             inventory.AddItem(item.ItemID, item.Quantity);
     }
     CurrentAction = null;
 }
Example #34
0
 void PerformAction(Action action)
 {
     if (action is TimedAction)
     {
         TimedAction ta = action as TimedAction;
         CurrentAction = ta;
         EventManager.OnActionStart(ta);
     }
     else if (action is DefenceAction)
     {
         (action as DefenceAction).TryPerform(ref DamageTemp);
         ApplyDamage(DamageTemp, ApplyArmorTemp);
     }
     else if (action is AttackAction)
     {
         AttackAction aa = action as AttackAction;
         Attack(aa.Target, Weapon.Damage * aa.DamageMultiplier, aa.Chance);
     }
 }
Example #35
0
 void PerformCraftAction(Blueprint blueprint)
 {
     TimedAction timedAction = CraftActionCashe.GetComponent<TimedAction>();
     timedAction.Duration = blueprint.CraftTime;
     timedAction.StaminaConsumption = 0.5f;
     timedAction.Sprite = blueprint.Item.Icon;
     CurrentAction = timedAction;
     EventManager.OnActionStart(timedAction);
 }
Example #36
0
 public void AddWhile(TimedAction timedAction)
 {
     Actions.Add(timedAction);
 }
Example #37
0
 public static void OnActionStart(TimedAction a)//C#6.0 EBD
 {
     ActionStarted(a);
 }
Example #38
0
 void Run(TimedAction action)
 {
     StartCoroutine(RunTimeCoroutine(action.Duration));
 }
    void Deactivate2(TimedAction unused = null)
    {
        //foreach(Behaviour b in GetComponents<Behaviour>())
        //	b.enabled=false;
        //GetComponent<DuringActionDisabler>().enabled=true;

        //TODO Ждём C# 6.0
        if (GetComponent<SpriteRenderer>() != null)
            GetComponent<SpriteRenderer>().enabled = false;
        if (GetComponent<Collider2D>() != null)
            GetComponent<Collider2D>().enabled = false;
    }