示例#1
0
        public frmMain()
        {
            InitializeComponent();
            Update = Output; //Used to support calling Output() from a different thread.

            Angle angle = new Angle(60, AngleType.Degrees);
            Line line = new Line(new PointD(0, 0), angle);
            Arc arc = new Arc(new PointD(0, 0), 2);

            PointD[] intersections = line.IntersectionWith(arc);
            foreach (var point in intersections)
            {
                Output(point.ToString());
            }

            //tm.Interval = 1000 * 1000;
            //tm.MicroTimerElapsed += Tm_MicroTimerElapsed;
            //tm.Start();
        }
示例#2
0
 private void Update()
 {
     OnUpdate?.Invoke();
 }
示例#3
0
    /// <summary>
    /// Add a new late update function with the specified update order.
    /// </summary>

    static public void AddLateUpdate(MonoBehaviour mb, int updateOrder, OnUpdate func)
    {
        CreateInstance(); mInst.Add(mb, updateOrder, func, mInst.mOnLate);
    }
示例#4
0
 public void Update() => OnUpdate?.Invoke();
示例#5
0
        public List <UserFeedback> Loot(string transferFile)
        {
            Logger.Info($"Checking {transferFile} for items to loot");
            lock (_fileLock) {
                var(stash, errors) = Load(transferFile);
                if (errors.Count > 0)
                {
                    return(errors); // Cannot recover from any of these
                }

                // TODO: Delegate the stash to the crafting service
                List <UserFeedback> feedbacks = new List <UserFeedback>();
                var lootFromStashIdx          = _transferStashService.GetStashToLootFrom(stash);
                if (HasItems(stash, lootFromStashIdx))
                {
                    var classifiedItems = Classify(stash.Tabs[lootFromStashIdx]);

                    // Warn or auto delete bugged duplicates
                    if (classifiedItems.Duplicates.Count > 0)
                    {
                        if (_settings.GetPersistent().DeleteDuplicates)
                        {
                            stash.Tabs[lootFromStashIdx].Items.RemoveAll(e => classifiedItems.Duplicates.Any(m => m.Equals(e)));

                            // No items to loot, so just delete the duplicates.
                            if (classifiedItems.Remaining.Count == 0)
                            {
                                if (!_stashWriter.SafelyWriteStash(transferFile, stash))
                                {
                                    Logger.Error("Fatal error deleting items from Grim Dawn, items has been duplicated.");
                                }
                            }
                        }
                        else
                        {
                            classifiedItems.Duplicates.ForEach(item => Logger.Debug($"NotLootedDuplicate: {item}"));
                            feedbacks.Add(new UserFeedback(UserFeedbackLevel.Warning,
                                                           RuntimeSettings.Language.GetTag("iatag_feedback_duplicates_not_looted", classifiedItems.Duplicates.Count),
                                                           HelpService.GetUrl(HelpService.HelpType.DuplicateItem)
                                                           ));
                        }
                    }

                    if (classifiedItems.Stacked.Count > 0)
                    {
                        classifiedItems.Stacked.ForEach(item => Logger.Debug($"NotLootedStacked: {item}"));
                        feedbacks.Add(new UserFeedback(RuntimeSettings.Language.GetTag("iatag_feedback_stacked_not_looted", classifiedItems.Stacked.Count)));
                    }

                    // Unknown items, database not parsed for these items, IA can't deal with them.
                    if (classifiedItems.Unknown.Count > 0)
                    {
                        classifiedItems.Unknown.ForEach(item => Logger.Debug($"NotLootedUnknown: {item}"));
                        feedbacks.Add(new UserFeedback(
                                          UserFeedbackLevel.Warning,
                                          RuntimeSettings.Language.GetTag("iatag_feedback_unknown_not_looted", classifiedItems.Unknown.Count),
                                          HelpService.GetUrl(HelpService.HelpType.NotLootingUnidentified)
                                          ));
                    }

                    // The items we can actually loot (or delete duplicates)
                    if (classifiedItems.Remaining.Count > 0)
                    {
                        OnUpdate?.Invoke(this, null);

                        stash.Tabs[lootFromStashIdx].Items.RemoveAll(e => classifiedItems.Remaining.Any(m => m.Equals(e)));

                        var isHardcore = GlobalPaths.IsHardcore(transferFile);
                        if (StoreItemsToDatabase(classifiedItems.Remaining, stash.ModLabel, isHardcore))
                        {
                            feedbacks.Add(new UserFeedback(RuntimeSettings.Language.GetTag("iatag_looted_from_stash", classifiedItems.Remaining.Count, lootFromStashIdx + 1)));

                            if (!_stashWriter.SafelyWriteStash(transferFile, stash))
                            {
                                Logger.Error("Fatal error deleting items from Grim Dawn, items has been duplicated.");
                            }

                            // TODO: Do a quick check to see if the items are TRUUUULY gone from the stash?
                        }
                        else
                        {
                            feedbacks.Add(UserFeedback.FromTag("iatag_feedback_unable_to_loot_stash")); // TODO: Not sure what to report here..
                        }
                    }
                }
                else
                {
                    Logger.Info($"No items found in transfer stash {lootFromStashIdx + 1}.");
                    feedbacks.Add(UserFeedback.FromTag("iatag_feedback_no_items_to_loot"));
                }

                return(feedbacks);
            }
        }
示例#6
0
        public virtual void Update(DwarfTime time)
        {
            if (!IsVisible)
            {
                return;
            }

            UpdateSize();

            if (Tweens.Count > 0)
            {
                GUITween currTween = Tweens.First();
                currTween.Update(time);
                LocalBounds = currTween.GetCurrentRect();
                if (currTween.TweenTimer.HasTriggered)
                {
                    switch (currTween.Tween)
                    {
                    case GUITween.TweenType.TweenAnimate:
                        break;

                    case GUITween.TweenType.TweenIn:
                        break;

                    case GUITween.TweenType.TweenOut:
                        IsVisible   = false;
                        LocalBounds = currTween.Start;
                        break;
                    }

                    Tweens.RemoveAt(0);
                }
            }

            OnUpdate.Invoke();

            foreach (GUIComponent child in Children)
            {
                child.Update(time);
            }

            MouseState state = Mouse.GetState();

            if (GUI.EnableMouseEvents)
            {
                if (OverrideClickBehavior)
                {
                    HandleClicks(state);
                }
                else if (!IsClipped && GlobalBounds.Contains(state.X, state.Y))
                {
                    if (IsMouseOver)
                    {
                        HandleClicks(state);
                    }

                    if (!IsMouseOver)
                    {
                        IsMouseOver = true;
                        OnHover();
                    }
                }
                else if (IsMouseOver)
                {
                    IsMouseOver = false;
                    OnUnHover();
                    IsLeftPressed  = false;
                    IsRightPressed = false;
                }
            }

            foreach (GUIComponent child in ChildrenToAdd)
            {
                Children.Add(child);
            }
            ChildrenToAdd.Clear();

            foreach (GUIComponent child in ChildrenToRemove)
            {
                if (!Children.Remove(child))
                {
                    Console.Out.WriteLine("Something's wrong with removing child...");
                }
            }
            ChildrenToRemove.Clear();
        }
示例#7
0
 private void TriggerOnUpdate(string key, string region, CacheActionEventArgOrigin origin = CacheActionEventArgOrigin.Local)
 {
     OnUpdate?.Invoke(this, new CacheActionEventArgs(key, region, origin));
 }
示例#8
0
    /// <summary>
    /// Generic add function.
    /// Technically 'mb' is not necessary as it can be retrieved by calling 'func.Target as MonoBehaviour'.
    /// Unfortunately Flash export fails to compile with that, claiming the following:
    /// "Error: Access of possibly undefined property Target through a reference with static type Function."
    /// </summary>
    void Add(MonoBehaviour mb, int updateOrder, OnUpdate func, List<UpdateEntry> list)
    {
        #if !UNITY_FLASH
        // Flash export fails at life.
        for (int i = 0, imax = list.Count; i < imax; ++i)
        {
            UpdateEntry ent = list[i];
            if (ent.func == func) return;
        }
        #endif

        UpdateEntry item = new UpdateEntry();
        item.index = updateOrder;
        item.func = func;
        item.mb = mb;
        item.isMonoBehaviour = (mb != null);

        list.Add(item);
        if (updateOrder != 0) list.Sort(Compare);
    }
示例#9
0
        private static void UpdateTrigger(EventArgs args)
        {
            OnUpdate?.Invoke(EventArgs.Empty);

            IngameTrigger.Value = Game.IsInGame && ObjectManager.LocalHero != null && ObjectManager.LocalHero.IsValid;
        }
示例#10
0
 public static void RegisterUpdate(OnUpdate <TState> onUpdate)
 {
     _onUpdate = onUpdate;
 }
示例#11
0
 public void AddSpawn(CargoSpawn spawn)
 {
     CargoToBeSpawned.Add(spawn);
     OnUpdate?.Invoke();
 }
示例#12
0
 private void TimerElapsed(object sender, ElapsedEventArgs e)
 {
     OnUpdate?.Invoke(this, EventArgs.Empty);
 }
示例#13
0
 private void OnOnUpdate(GameTime gametime, KeyboardState keyboardState)
 {
     OnUpdate?.Invoke(gametime, keyboardState);
 }
示例#14
0
 void Update()
 {
     OnUpdate.SafeInvoke();
 }
示例#15
0
 public void InvokeOnUpdate()
 {
     OnUpdate?.Invoke();
 }
 public static void RemoveUpdate(OnUpdate func)
 {
     mInst.Remove(func, mInst.mOnUpdate);
 }
示例#17
0
 // NOTE: do not use this for game actions! only for cosmetic things like graphics, etc.
 public void Update()
 {
     OnUpdate?.Invoke(this);
 }
 public void Unsubscribe(OnUpdate <System.Object> callback)
 {
     this.OnUpdate -= callback;
 }
示例#19
0
        public static void Combo()
        {
            #region R combos

            var unit =
                HeroManager.Enemies.Where(
                    x => x.Distance(Player) < 500 && !x.IsDead && x.IsValidTarget(500) && x.Health < R.GetDamage(x) + 50)
                .OrderBy(x => x.Distance(Player))
                .FirstOrDefault();
            if (unit != null)
            {
                foreach (var targets in
                         HeroManager.Enemies.Where(
                             x =>
                             !x.IsDead && x.IsValidTarget() && x.IsVisible && x.Distance(unit) < 1000 &&
                             x.Distance(unit) > 300 && x.NetworkId != unit.NetworkId && x.Health < R.GetDamage(x)))
                {
                    var prediction = Prediction.GetPrediction(targets, 0.1f);

                    var pos = prediction.UnitPosition.Extend(unit.ServerPosition,
                                                             prediction.UnitPosition.Distance(unit.ServerPosition) + 250);

                    RCombo = pos;

                    var slot = WardSorter.Wards();
                    if (unit.Distance(Player) > 500)
                    {
                        RCombo = null;
                    }

                    if (W.IsReady() && R.IsReady() && Player.ServerPosition.Distance(unit.ServerPosition) < 500 &&
                        slot != null)
                    {
                        WardJump.WardJumped(pos, false, true);
                    }
                }

                if (Player.IsDead)
                {
                    UltPoly            = null;
                    UltPolyExpectedPos = null;
                    return;
                }

                UltPoly = new Geometry.Polygon.Rectangle(Player.ServerPosition,
                                                         Player.ServerPosition.Extend(unit.Position, 1100), unit.BoundingRadius + 30);

                var counts =
                    HeroManager.Enemies.Where(
                        x => x.Distance(Player) < 1100 && x.IsValidTarget(1100) && x.Health < R.GetDamage(x))
                    .Count(h => h.NetworkId != unit.NetworkId && UltPoly.IsInside(h.ServerPosition));

                if (counts >= 1 && R.IsReady() && Created && R.IsReady())
                {
                    R.Cast(unit);
                }
            }

            #endregion

            #region Regular combo

            var target = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Physical);
            if (!target.IsValidTarget())
            {
                return;
            }

            var useq  = GetBool("useq", typeof(bool));
            var usee  = GetBool("usee", typeof(bool));
            var user  = GetBool("user", typeof(bool));
            var usew  = GetBool("wardjumpcombo", typeof(bool));
            var smite = GetBool("usessmite", typeof(bool));
            if (GetStringValue("hydrati") == 0 || GetStringValue("hydrati") == 2)
            {
                if (target.IsValidTarget(400) && (ItemReady(Tiamat) || ItemReady(Hydra)) &&
                    (HasItem(Tiamat) || HasItem(Hydra)))
                {
                    SelfCast(HasItem(Hydra) ? Hydra : Tiamat);
                }
            }

            if (GetBool("youm", typeof(bool)) && HasItem(Youm) && ItemReady(Youm) &&
                target.Distance(Player) < Q.Range - 300)
            {
                SelfCast(Youm);
            }

            if (GetBool("omen", typeof(bool)) && HasItem(Omen) && ItemReady(Omen) &&
                Player.CountAlliesInRange(400) >= GetValue("minrand"))
            {
                SelfCast(Omen);
            }
            if (usew)
            {
                if (Environment.TickCount - Lastqc > 300 && Environment.TickCount - Laste > 300 &&
                    Environment.TickCount - Lastwcombo > 300)
                {
                    if (W.IsReady() && target.Distance(Player) <= Player.AttackRange && W1())
                    {
                        W.Cast(Player);
                        Lastwcombo = Environment.TickCount;
                    }

                    if (W.IsReady() && target.Distance(Player) <= Player.AttackRange && W2() && !HasPassive())
                    {
                        W.Cast();
                    }
                }
            }

            if (useq)
            {
                if (Environment.TickCount - Lastqc > 300 && Environment.TickCount - Laste > 300 &&
                    Environment.TickCount - Lastwcombo > 300)
                {
                    var qpred = Q.GetPrediction(target);
                    if (Q.IsReady() && Q1())
                    {
                        OnUpdate.CastSpell(Q, target);
                        Lastqc = Environment.TickCount;
                    }

                    if (Q2() && Q.IsReady() && GetBool("useq2", typeof(bool)))
                    {
                        LeagueSharp.Common.Utility.DelayAction.Add(GetValue("secondqdelay"), () => Q.Cast());
                        Lastqc = Environment.TickCount;
                    }
                }
            }

            if (usee)
            {
                if (target.Distance(Player) <= E.Range && E1())
                {
                    E.Cast();
                    Laste = Environment.TickCount;
                }
                if ((Player.Distance(target) >
                     Player.AttackRange + Player.BoundingRadius + target.BoundingRadius + 100 ||
                     Environment.TickCount - Laste > 2300) && E2())
                {
                    E.Cast();
                    Laste = Environment.TickCount;
                }
            }

            if (user && target.IsValidTarget(R.Range) && R.IsReady())
            {
                if (Q.GetDamage(target) + 70 < target.Health)
                {
                    // Chat.Print("firstcheck");
                    if (target.Health > Player.GetAutoAttackDamage(target) + 30)
                    {
                        //   Chat.Print("secondCheck");
                        if (Q.IsReady() &&
                            target.Health <=
                            R.GetDamage(target) + GetQDamage(target) + Player.GetAutoAttackDamage(target) &&
                            Q.IsReady() && target.Health > GetQDamage(target))
                        {
                            R.Cast(target);
                        }

                        if (target.Health <= R.GetDamage(target) + Q.GetDamage(target) && Q.IsReady() &&
                            Player.Mana > 30)
                        {
                            R.Cast(target);
                        }
                    }
                }
            }


            if (Smite.IsReady() && target.Distance(Player) < 500 && smite && target.Health < ActiveModes.Smite.GetFuckingSmiteDamage())
            {
                Player.Spellbook.CastSpell(Smite, target);
            }

            var poss = Player.ServerPosition.Extend(target.ServerPosition, 600);
            if (!GetBool("wardjumpcombo1", typeof(bool)))
            {
                return;
            }

            if (!E.IsReady() || !W.IsReady() || !(target.Distance(Player) > E.Range) || !LastQ(target))
            {
                return;
            }
            if (!Q.IsReady() && Environment.TickCount - Q.LastCastAttemptT > 1000)
            {
                WardManager.WardJump.WardJumped(poss, true, true);
            }

            #endregion
        }
示例#20
0
 public void PerformUpdate()
 {
     OnUpdate?.Invoke(viewModel);
 }
示例#21
0
 public void Update()
 {
     OnUpdate.Call(this);
 }
示例#22
0
 /// <summary>
 /// 更新並通知
 /// </summary>
 /// <param name="dataObject"></param>
 public void Update(Object dataObject)
 {
     OnUpdate?.Invoke(dataObject);
 }
示例#23
0
 protected static void SetStatus(string status)
 {
     OnUpdate?.Invoke(new UpdateEventArgs(true, 1, status));
 }
示例#24
0
 /// <summary>
 /// Update的回调
 /// </summary>
 /// <param name="deltaTime">Time.deltaTime</param>
 public virtual void UpdateCallback(float deltaTime)
 {
     OnUpdate?.Invoke(deltaTime);
     //累计计时器
     Timer += deltaTime;
 }
示例#25
0
 internal void InvokeUpdate(float dt)
 {
     OnUpdate?.Invoke(dt);
     Update(dt);
 }
示例#26
0
 //普通帧循环
 private void Update()
 {
     mainStart?.Update();
     OnUpdate?.Invoke();
 }
示例#27
0
 void Update()
 {
     OnUpdate?.Invoke(Time.deltaTime);
 }
示例#28
0
    /// <summary>
    /// Add a new coroutine update function with the specified update order.
    /// </summary>

    static public void AddCoroutine(MonoBehaviour mb, int updateOrder, OnUpdate func)
    {
        CreateInstance(); mInst.Add(mb, updateOrder, func, mInst.mOnCoro);
    }
示例#29
0
        public static void Insec()
        {
            #region Target, Slots, Prediction

            EloBuddy.Player.IssueOrder(GameObjectOrder.MoveTo, Game.CursorPos);

            var target = TargetSelector.GetTarget(Q.Range + 800, TargetSelector.DamageType.Physical);
            if (target != null)
            {
                target = TargetSelector.GetSelectedTarget() == null ? target : TargetSelector.SelectedTarget;
            }

            if (target == null)
            {
                return;
            }
            var qpred = Q.GetPrediction(target);

            var col = qpred.CollisionObjects;

            var slot = WardSorter.Wards();
            #endregion

            if (Player.Distance(target) > 500)
            {
                if (Q2() && Q.IsReady() && (R.IsReady() || Environment.TickCount - Lastr < 4000))
                {
                    if (CanQ2())
                    {
                        LeagueSharp.Common.Utility.DelayAction.Add(400, () => Q.Cast());
                    }
                }
            }

            if (Q1() && Player.Distance(target) <= Q.Range)
            {
                OnUpdate.CastSpell(Q, target);
            }


            var poss = InsecPos.WardJumpInsecPosition.InsecPos(target, GetValue("fixedwardrange"), true);
            if (!GetBool("laggy", typeof(bool)))
            {
                var min =
                    SebbyLib.Cache.GetMinions(Player.Position, Q.Range)
                    .Where(
                        x => x.Health > Q.GetDamage(x) + 30 && !x.IsDead);

                foreach (var mins in min.Where(mins => mins.Distance(target) < 800 ||
                                               mins.Distance(poss.To3D()) < 530 ||
                                               (CanWardFlash(target) &&
                                                mins.Distance(target) < 600)).Where(mins => col.Count != 0))
                {
                    if (Q1() && Q.IsReady())
                    {
                        Q.Cast(mins);
                    }
                    if (Q1() && Q.IsReady())
                    {
                        Q.Cast(mins);
                    }

                    if (Q2() && mins.HasBuff("blindmonkqtwo"))
                    {
                        Q.Cast();
                    }
                }
            }


            if ((Steps == LeeSin.steps.WardJump || Environment.TickCount - Lastwardjump < 1500) && slot != null && W.IsReady() && R.IsReady())
            {
                if (GetValue("fixedwardrange") + Player.ServerPosition.Distance(target.ServerPosition) < 700 &&
                    Environment.TickCount - LastTeleported > 500)
                {
                    WardManager.WardJump.WardJumped(poss.To3D(), false, false);
                    LeeSin.Lastwardjumpd = Environment.TickCount;
                    Canwardflash         = false;
                }
                else if (CanWardFlash(target))
                {
                    Canwardflash = true;
                }
            }

            if (Environment.TickCount - Lastprocessw < 1500 || (Steps == LeeSin.steps.Flash && HasFlash()) ||
                Environment.TickCount - Lastwcasted < 1500 || Player.Distance(poss) < 50)
            {
                if (R.IsReady())
                {
                    R.Cast(target);
                }
            }

            if ((!W.IsReady() || W2()) && !GetBool("prioflash", typeof(bool)) &&
                Environment.TickCount - Lastwcasted > 1500 && LastQ(target))
            {
                Lastflashoverprio = Environment.TickCount;
                R.Cast(target);
            }
            #region Q Smite

            var prediction = Prediction.GetPrediction(target, Q.Delay);

            var collision = Q.GetCollision(Player.Position.To2D(),
                                           new List <Vector2> {
                prediction.UnitPosition.To2D()
            });

            foreach (var collisions in collision)
            {
                if (collision.Count == 1)
                {
                    if (collision[0].IsMinion && collision[0].IsEnemy)
                    {
                        if (GetBool("UseSmite", typeof(bool)))
                        {
                            if (Q.IsReady())
                            {
                                if (collision[0].Distance(Player) < 500)
                                {
                                    if (collision[0].Health <= ActiveModes.Smite.GetFuckingSmiteDamage() &&
                                        Smite.IsReady())
                                    {
                                        Q.Cast(prediction.CastPosition);
                                        Player.Spellbook.CastSpell(Smite, collision[0]);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            #endregion
            #region Determine if we want to flash or ward jump

            if (R.IsReady())
            {
                if (slot != null && (W.IsReady() || Environment.TickCount - Lastprocessw < 1500))
                {
                    if (GetBool("prioflash", typeof(bool)) && Player.GetSpellSlot("summonerflash").IsReady())
                    {
                        Steps = LeeSin.steps.Flash;
                        if (Environment.TickCount - Lastqcasted < 600)
                        {
                            Canwardflash = false;
                        }
                        else if (CanWardFlash(target))
                        {
                            Canwardflash = true;
                        }
                    }
                    else if (GetValue("fixedwardrange") + Player.ServerPosition.Distance(target.ServerPosition) < 900)
                    {
                        if (CanWardFlash(target))
                        {
                            Canwardflash = true;
                        }
                        Lastwardjump = Environment.TickCount;
                    }
                }
                else if (GetBool("useflash", typeof(bool)) && target.Distance(Player) < 400 &&
                         Player.GetSpellSlot("SummonerFlash").IsReady() && (slot == null || !W.IsReady() || W2()) &&
                         (Environment.TickCount - Lastwcasted > 2000 || Environment.TickCount - Lastprocessw > 2000))
                {
                    Steps = LeeSin.steps.Flash;
                }
            }

            var wardtotargetpos = Player.Position.Extend(target.Position, Player.Distance(target) - 150);

            if (!Canwardflash)
            {
                return;
            }
            if (Player.HasBuff("blindmonkqtwodash"))
            {
                return;
            }

            if (Player.Distance(target) < 350 || target.Distance(Player) > 900 ||
                Environment.TickCount - Lastq1Casted < 500 ||
                !CanWardFlash(target) || Environment.TickCount - LeeSin.Lsatcanjump1 < 3000 ||
                target.Buffs.Any(x => x.Name.ToLower().Contains("blindmonkqone")))
            {
                return;
            }



            if (!Checkno1(target))
            {
                return;
            }
            // if ( Q2()) return;
            //  if (!HasFlash()) return;
            if (LastQ(target) &&
                Environment.TickCount - LastTeleported > 500)
            {
                WardManager.WardJump.WardJumped(wardtotargetpos, true, false);
                Wardjumpedto       = Environment.TickCount;
                Wardjumpedtotarget = true;
                Lastflashward      = Environment.TickCount;
            }

            #endregion
        }
示例#30
0
 public void OnSignaledDataUpdated()
 {
     RunOnUiThread(() => OnUpdate?.Invoke());
 }
 public void Update(ConfirmOptions options)
 {
     OnUpdate?.Invoke(options);
 }
 void Remove(OnUpdate func, List<UpdateEntry> list)
 {
     int updateOrder = 0;
     for (int i = 0, imax = list.Count; i < imax; ++i)
     {
         UpdateEntry en = list[i];
         updateOrder = en.index;
         if (en.func.Equals(func)) {
             en.mb = null;
             break;
         }
     }
     if (updateOrder != 0) list.Sort(Compare);
 }
示例#33
0
 public virtual void CallOnUpdateEvent()
 {
     OnUpdate?.Invoke(this, new EventArgs());
 }
示例#34
0
 public static void SetUpdateDelegate(OnUpdate delegateOnUpdate)
 {
     m_delegateOnUpdate = delegateOnUpdate;
 }
示例#35
0
        /// <summary>
        /// Main update loop
        /// </summary>
        private async void Update()
        {
            // Loop as long as the daemon is connected
            while (Connected)
            {
                try
                {
                    // Ensure network connection is still alive
                    if (!Local && !TurtleCoin.Ping(Address, Port))
                    {
                        // Connection was lost
                        await Exit();

                        ThrowError(ErrorCode.CONNECTION_LOST);
                        LogLine("Connection lost");
                        OnDisconnect?.Invoke(this, EventArgs.Empty);
                        break;
                    }
                    else if (Local && Process.HasExited)
                    {
                        // Connection was lost
                        await Exit();

                        ThrowError(ErrorCode.CONNECTION_LOST);
                        LogLine("Connection lost");
                        OnDisconnect?.Invoke(this, EventArgs.Empty);
                        break;
                    }

                    // Create a result object to recycle throughout updates
                    JObject Result = new JObject();

                    // Update status
                    await SendRequestAsync(RequestMethod.GET_INFO, new JObject { }, out Result);

                    // Make sure daemon is correct version
                    if (Result["synced"] == null)
                    {
                        // Incorrect daemon version
                        await Exit();

                        ThrowError(ErrorCode.INCORRECT_DAEMON_VERSION);
                        LogLine("Daemon is wrong version, use a newer version");
                        OnDisconnect?.Invoke(this, EventArgs.Empty);
                        break;
                    }

                    // Populate network info
                    AltBlocksCount           = (double)Result["alt_blocks_count"];
                    Difficulty               = (double)Result["difficulty"];
                    GreyPeerlistSize         = (double)Result["grey_peerlist_size"];
                    Hashrate                 = (double)Result["hashrate"];
                    Height                   = (double)Result["height"];
                    IncomingConnectionsCount = (double)Result["incoming_connections_count"];
                    LastKnownBlockIndex      = (double)Result["last_known_block_index"];
                    NetworkHeight            = (double)Result["network_height"];
                    OutgoingConnectionsCount = (double)Result["outgoing_connections_count"];
                    Status                   = (string)Result["status"];
                    TransactionCount         = (double)Result["tx_count"];
                    TransactionPoolSize      = (double)Result["tx_pool_size"];
                    WhitePeerlistSize        = (double)Result["white_peerlist_size"];

                    // Check if daemon is ready
                    if (!Synced && (bool)Result["synced"] == true)
                    {
                        // Set ready status
                        Synced = true;

                        // Trigger ready event handler
                        LogLine("Synced");
                        OnSynced?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        Synced = false;
                    }

                    // Do updating

                    // Invoke update event
                    OnUpdate?.Invoke(this, EventArgs.Empty);

                    // Wait for specified amount of time
                    await Task.Delay(RefreshRate, CancellationSource.Token);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
示例#36
0
 /// <summary>
 /// Add a new update function with the specified update order.
 /// </summary>
 public static void AddUpdate(MonoBehaviour mb, int updateOrder, OnUpdate func)
 {
     CreateInstance(); mInst.Add(mb, updateOrder, func, mInst.mOnUpdate);
 }
        public void Init()
        {
            Table = new Table();
            Robot = new Arm();
            Puck = new Puck();

            #region Physical Defaults
            Table.Height = 1.987; //198.7 cm, or 8 feet
            Table.Width = 0.965;
            Line Left_Side = new Line(new PointD(0, 0), new Angle(90, AngleType.Degrees));
            Line Right_Side = new Line(new PointD(Table.Width, 0), new Angle(90, AngleType.Degrees));
            Line Light_Side = new Line(new PointD(0, Table.Height), new Angle(0.001, AngleType.Degrees));
            Line Dark_Side = new Line(new PointD(0, 0), new Angle(0.001, AngleType.Degrees));
            Table.Walls.Add(Left_Side); Table.Walls.Add(Right_Side); Table.Walls.Add(Light_Side); Table.Walls.Add(Dark_Side);
            Table.Friction = 0.000250 / 1000;
            Table.Goal_Width = .26; //26 cm

            Arc arc_test = new Arc(new PointD(Table.Width, Table.Height / 2), 0.4175);
            Table.Arcs.Add(arc_test);
            Arc arc_test2 = new Arc(new PointD(0, Table.Height / 2), Table.Width);
            Table.Arcs.Add(arc_test2);

            Robot.Arm_Length = .3; //30 cm
            Robot.Arm_Angle = new Angle(90, AngleType.Degrees);
            Robot.Forearm_Length = .3;
            Robot.Forearm_Angle = new Angle(90, AngleType.Degrees);

            Puck.Weight = 18; //18 grams
            Puck.Radius = 0.03175; //The diameter of a standard hockey puck is 6.35 cm
            Puck.Location = new PointD(Table.Width / 2, Table.Height / 2);
            Puck.Velocity.Direction = new Angle(((double)(new Random()).Next(0, 36000) / 100.0), AngleType.Degrees);
            //Puck.Velocity.Speed = 10.30 / 1000;
            #endregion

            //Timer
            Updated = OnUpdated;
            tm.Interval = (1000 * 1000) / 60;
            tm.MicroTimerElapsed += Tm_MicroTimerElapsed;
            tm.Start();
        }