Example #1
0
 public void InvalidateTimeline()
 {
     // clear queued invalidates
     Interlocked.Increment(ref _invlatch);
     Task.Run(async() =>
     {
         var complete = false;
         try
         {
             IsLoading = true;
             if (PreInvalidateTimeline())
             {
                 // when PreInvalidateTimeline is finished correctly,
                 // reserve to down loading flag.
                 complete = true;
             }
             // invalidate and fetch statuses
             lock (_statusIdCache)
             {
                 _statusIdCache.Clear();
                 Statuses.Clear();
             }
             // do not change loading flag in inner method
             await ReadMore(null, false).ConfigureAwait(false);
         }
         finally
         {
             if (complete)
             {
                 IsLoading = false;
             }
         }
     });
 }
Example #2
0
        public void SetStatuses(string[] active, string[] inactive)
        {
            List <string> validActive = active.Where(x => !String.IsNullOrEmpty(x))
                                        .Distinct()
                                        .ToList();

            if (validActive.Count == 0)
            {
                throw new Exception("Project must contain at least one Active status.");
            }

            List <string> validInactive = inactive.Where(x => !String.IsNullOrEmpty(x))
                                          .Distinct()
                                          .ToList();

            if (validInactive.Count == 0)
            {
                throw new Exception("Project must contain at least one Inactive status.");
            }

            string[] intersection = validActive.Intersect(validInactive).ToArray();
            if (intersection.Length > 0)
            {
                throw new Exception(String.Format("Status(es) cannot be both Active and Inactive: {0}", String.Join(", ", intersection)));
            }

            Statuses.Clear();
            Statuses.AddRange(validActive.Select(x => new Status(x, true)));
            Statuses.AddRange(validInactive.Select(x => new Status(x, false)));
        }
Example #3
0
 public void Clear()
 {
     Entities.Clear();
     Changes.Clear();
     Statuses.Clear();
     IsAction = false;
 }
Example #4
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     IsSubscribeBroadcaster = false;
     lock (_statusIdCache)
     {
         _statusIdCache.Clear();
     }
     Statuses.Clear();
 }
Example #5
0
 private void StatusesListCreator(IList <Status> list, Delegate lambdaDevice)
 {
     Statuses.Clear();
     foreach (var item in list)
     {
         var devices      = item.Devices;
         var devicesCount = devices.Count();
         if (lambdaDevice != null)
         {
             devicesCount = devices.Where((Func <Device, bool>)lambdaDevice).Count();
         }
         Statuses.Add(new SView(item, devicesCount, Statuses.Count() + 1));
     }
 }
Example #6
0
        async Task ExecuteRefreshCommandAsync()
        {
            var result = await StoreManager.StatusesService.GetStatusesAsync(position, pageIndex, pageSize);

            if (result.Success)
            {
                var statuses = JsonConvert.DeserializeObject <List <Statuses> >(result.Message.ToString());
                if (statuses.Count > 0)
                {
                    if (pageIndex == 1 && Statuses.Count > 0)
                    {
                        Statuses.Clear();
                    }
                    Statuses.AddRange(statuses);

                    if (position == 0)
                    {
                        await SqliteUtil.Current.UpdateStatuses(statuses);
                    }
                    pageIndex++;
                    if (Statuses.Count >= pageSize)
                    {
                        LoadStatus  = LoadMoreStatus.StausDefault;
                        CanLoadMore = true;
                    }
                    else
                    {
                        LoadStatus  = LoadMoreStatus.StausEnd;
                        CanLoadMore = false;
                    }
                }
                else
                {
                    CanLoadMore = false;
                    LoadStatus  = pageIndex > 1 ? LoadMoreStatus.StausEnd : LoadMoreStatus.StausNodata;
                }
            }
            else
            {
                Log.SaveLog("StatusesViewModel.GetStatusesAsync", new Exception()
                {
                    Source = result.Message
                });
                LoadStatus = pageIndex > 1 ? LoadMoreStatus.StausError : LoadMoreStatus.StausFail;
            }
        }
Example #7
0
        private void RefreshGrid()
        {
            Statuses.RaiseListChangedEvents = false;
            Statuses.Clear();

            new ShipmentStatusDataManager().
            Get <ShipmentStatusModel>(WhereTerm.Default(CurrentModel.Id, "shipment_id")).
            OrderByDescending(row => row.DateProcess).
            Select((row, i) => new ShipmentStatusDataRow
            {
                BranchDataManager             = BranchDataManager,
                TrackingStatusDataManager     = TrackingStatusDataManager,
                MissDeliveryReasonDataManager = MissDeliveryReasonDataManager,
                EmployeeDataManager           = EmployeeDataManager,

                Index              = i + 1,
                Id                 = row.Id,
                ShipmentId         = row.ShipmentId,
                DateProcess        = row.DateProcess,
                TrackingStatusId   = row.TrackingStatusId,
                MissDeliveryReason = row.MissDeliveryReason,
                PositionStatus     = row.PositionStatus,
                PositionStatusId   = row.PositionStatusId,
                BranchId           = row.BranchId,
                StatusBy           = row.StatusBy,
                StatusNote         = row.StatusNote,
                Reference          = row.Reference,
                Rowstatus          = row.Rowstatus,
                Rowversion         = row.Rowversion,
                Createddate        = row.Createddate,
                Createdby          = row.Createdby,
                Modifieddate       = row.Modifieddate,
                Modifiedby         = row.Modifiedby,
            })
            .ForEach(row => Statuses.Add(row));

            Statuses.RaiseListChangedEvents = true;
            Statuses.ResetBindings();
        }
Example #8
0
 private void ExecuteClearCommand()
 {
     Statuses.Clear();
 }
Example #9
0
        // TODO: Improve NPC movement to be more fluid like a player
        //General Updating
        public override void Update(long timeMs)
        {
            var curMapLink = MapId;

            base.Update(timeMs);

            var statuses = Statuses.Values.ToArray();

            foreach (var status in statuses)
            {
                if (status.Type == StatusTypes.Stun || status.Type == StatusTypes.Sleep)
                {
                    return;
                }
            }

            //TODO Clear Damage Map if out of combat (target is null and combat timer is to the point that regen has started)
            if (Target == null && Globals.Timing.Milliseconds > CombatTimer && Globals.Timing.Milliseconds > RegenTimer)
            {
                DamageMap.Clear();
            }

            var fleeing = false;

            if (Base.FleeHealthPercentage > 0)
            {
                var fleeHpCutoff = GetMaxVital(Vitals.Health) * ((float)Base.FleeHealthPercentage / 100f);
                if (GetVital(Vitals.Health) < fleeHpCutoff)
                {
                    fleeing = true;
                }
            }

            if (MoveTimer < Globals.Timing.Milliseconds)
            {
                var targetMap = Guid.Empty;
                var targetX   = 0;
                var targetY   = 0;
                var targetZ   = 0;

                //Check if there is a target, if so, run their ass down.
                if (Target != null)
                {
                    if (!Target.IsDead() && CanAttack(Target, null))
                    {
                        targetMap = Target.MapId;
                        targetX   = Target.X;
                        targetY   = Target.Y;
                        targetZ   = Target.Z;
                        var targetStatuses = Target.Statuses.Values.ToArray();
                        foreach (var targetStatus in targetStatuses)
                        {
                            if (targetStatus.Type == StatusTypes.Stealth)
                            {
                                targetMap = Guid.Empty;
                                targetX   = 0;
                                targetY   = 0;
                                targetZ   = 0;
                            }
                        }
                    }
                    else
                    {
                        if (CastTime <= 0)
                        {
                            RemoveTarget();
                        }
                    }
                }
                else //Find a target if able
                {
                    long   dmg = 0;
                    Entity tgt = null;
                    foreach (var pair in DamageMap)
                    {
                        if (pair.Value > dmg)
                        {
                            dmg = pair.Value;
                            tgt = pair.Key;
                        }
                    }

                    if (tgt != null)
                    {
                        AssignTarget(tgt);
                    }
                    else
                    {
                        // Check if attack on sight or have other npc's to target
                        TryFindNewTarget(timeMs);
                    }
                }

                if (targetMap != Guid.Empty)
                {
                    //Check if target map is on one of the surrounding maps, if not then we are not even going to look.
                    if (targetMap != MapId)
                    {
                        if (MapInstance.Get(MapId).SurroundingMaps.Count > 0)
                        {
                            for (var x = 0; x < MapInstance.Get(MapId).SurroundingMaps.Count; x++)
                            {
                                if (MapInstance.Get(MapId).SurroundingMaps[x] == targetMap)
                                {
                                    break;
                                }

                                if (x == MapInstance.Get(MapId).SurroundingMaps.Count - 1)
                                {
                                    targetMap = Guid.Empty;
                                }
                            }
                        }
                        else
                        {
                            targetMap = Guid.Empty;
                        }
                    }
                }

                if (targetMap != Guid.Empty)
                {
                    if (mPathFinder.GetTarget() != null)
                    {
                        if (targetMap != mPathFinder.GetTarget().TargetMapId ||
                            targetX != mPathFinder.GetTarget().TargetX ||
                            targetY != mPathFinder.GetTarget().TargetY)
                        {
                            mPathFinder.SetTarget(null);
                        }
                    }

                    if (mPathFinder.GetTarget() == null)
                    {
                        mPathFinder.SetTarget(new PathfinderTarget(targetMap, targetX, targetY, targetZ));
                    }
                }

                if (mPathFinder.GetTarget() != null)
                {
                    TryCastSpells();
                    if (!IsOneBlockAway(
                            mPathFinder.GetTarget().TargetMapId, mPathFinder.GetTarget().TargetX,
                            mPathFinder.GetTarget().TargetY, mPathFinder.GetTarget().TargetZ
                            ))
                    {
                        switch (mPathFinder.Update(timeMs))
                        {
                        case PathfinderResult.Success:
                            var dir = mPathFinder.GetMove();
                            if (dir > -1)
                            {
                                if (fleeing)
                                {
                                    switch (dir)
                                    {
                                    case 0:
                                        dir = 1;

                                        break;

                                    case 1:
                                        dir = 0;

                                        break;

                                    case 2:
                                        dir = 3;

                                        break;

                                    case 3:
                                        dir = 2;

                                        break;
                                    }
                                }

                                if (CanMove(dir) == -1 || CanMove(dir) == -4)
                                {
                                    //check if NPC is snared or stunned
                                    statuses = Statuses.Values.ToArray();
                                    foreach (var status in statuses)
                                    {
                                        if (status.Type == StatusTypes.Stun ||
                                            status.Type == StatusTypes.Snare ||
                                            status.Type == StatusTypes.Sleep)
                                        {
                                            return;
                                        }
                                    }

                                    Move((byte)dir, null);
                                }
                                else
                                {
                                    mPathFinder.PathFailed(timeMs);
                                }

                                // Have we reached our destination? If so, clear it.
                                var tloc = mPathFinder.GetTarget();
                                if (tloc.TargetMapId == MapId && tloc.TargetX == X && tloc.TargetY == Y)
                                {
                                    targetMap = Guid.Empty;

                                    // Reset our aggro center so we can get "pulled" again.
                                    AggroCenterMap = null;
                                    AggroCenterX   = 0;
                                    AggroCenterY   = 0;
                                    AggroCenterZ   = 0;
                                }
                            }

                            break;

                        case PathfinderResult.OutOfRange:
                            RemoveTarget();
                            targetMap = Guid.Empty;

                            break;

                        case PathfinderResult.NoPathToTarget:
                            TryFindNewTarget(timeMs, Target?.Id ?? Guid.Empty);
                            targetMap = Guid.Empty;

                            break;

                        case PathfinderResult.Failure:
                            targetMap = Guid.Empty;
                            RemoveTarget();

                            break;

                        case PathfinderResult.Wait:
                            targetMap = Guid.Empty;

                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                    else
                    {
                        var fleed = false;
                        if (Target != null && fleeing)
                        {
                            var dir = DirToEnemy(Target);
                            switch (dir)
                            {
                            case 0:
                                dir = 1;

                                break;

                            case 1:
                                dir = 0;

                                break;

                            case 2:
                                dir = 3;

                                break;

                            case 3:
                                dir = 2;

                                break;
                            }

                            if (CanMove(dir) == -1 || CanMove(dir) == -4)
                            {
                                //check if NPC is snared or stunned
                                statuses = Statuses.Values.ToArray();
                                foreach (var status in statuses)
                                {
                                    if (status.Type == StatusTypes.Stun ||
                                        status.Type == StatusTypes.Snare ||
                                        status.Type == StatusTypes.Sleep)
                                    {
                                        return;
                                    }
                                }

                                Move(dir, null);
                                fleed = true;
                            }
                        }

                        if (!fleed)
                        {
                            if (Target != null)
                            {
                                if (Dir != DirToEnemy(Target) && DirToEnemy(Target) != -1)
                                {
                                    ChangeDir(DirToEnemy(Target));
                                }
                                else
                                {
                                    if (Target.IsDisposed)
                                    {
                                        Target = null;
                                    }
                                    else
                                    {
                                        if (CanAttack(Target, null))
                                        {
                                            TryAttack(Target);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }



                //Move randomly
                if (targetMap != Guid.Empty)
                {
                    return;
                }

                if (LastRandomMove >= Globals.Timing.Milliseconds || CastTime > 0)
                {
                    return;
                }

                if (Base.Movement == (int)NpcMovement.StandStill)
                {
                    LastRandomMove = Globals.Timing.Milliseconds + Randomization.Next(1000, 3000);

                    return;
                }
                else if (Base.Movement == (int)NpcMovement.TurnRandomly)
                {
                    ChangeDir((byte)Randomization.Next(0, 4));
                    LastRandomMove = Globals.Timing.Milliseconds + Randomization.Next(1000, 3000);

                    return;
                }

                var i = Randomization.Next(0, 1);
                if (i == 0)
                {
                    i = Randomization.Next(0, 4);
                    if (CanMove(i) == -1)
                    {
                        //check if NPC is snared or stunned
                        statuses = Statuses.Values.ToArray();
                        foreach (var status in statuses)
                        {
                            if (status.Type == StatusTypes.Stun ||
                                status.Type == StatusTypes.Snare ||
                                status.Type == StatusTypes.Sleep)
                            {
                                return;
                            }
                        }

                        Move((byte)i, null);
                    }
                }

                LastRandomMove = Globals.Timing.Milliseconds + Randomization.Next(1000, 3000);

                if (fleeing)
                {
                    LastRandomMove = Globals.Timing.Milliseconds + (long)GetMovementTime();
                }
            }

            //If we switched maps, lets update the maps
            if (curMapLink != MapId)
            {
                if (curMapLink == Guid.Empty)
                {
                    MapInstance.Get(curMapLink).RemoveEntity(this);
                }

                if (MapId != Guid.Empty)
                {
                    MapInstance.Get(MapId).AddEntity(this);
                }
            }

            // Check if we've moved out of our range we're allowed to move from after being "aggro'd" by something.
            // If so, remove target and move back to the origin point.
            if (Options.Npc.AllowResetRadius && AggroCenterMap != null && GetDistanceTo(AggroCenterMap, AggroCenterX, AggroCenterY) > Options.Npc.ResetRadius)
            {
                // Remove our target.
                RemoveTarget();

                // Reset our vitals and statusses when configured.
                if (Options.Npc.ResetVitalsAndStatusses)
                {
                    Statuses.Clear();
                    DoT.Clear();
                    for (var v = 0; v < (int)Vitals.VitalCount; v++)
                    {
                        RestoreVital((Vitals)v);
                    }
                }

                // Try and move back to where we came from before we started chasing something.
                mPathFinder.SetTarget(new PathfinderTarget(AggroCenterMap.Id, AggroCenterX, AggroCenterY, AggroCenterZ));
            }
        }
Example #10
0
 public void Initialize()
 {
     Statuses.Clear();
 }
Example #11
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     CompositeDisposable.Dispose();
     Statuses.Clear();
 }
Example #12
0
        public async Task UpdateStatuses(long maxid = 0)
        {
            if (UpdatingStatuses)
            {
                return;
            }

            if (_userId == 0 || Tokens == null)
            {
                return;
            }

            UpdatingStatuses = true;

            try
            {
                var param = new Dictionary <string, object>
                {
                    { "count", 20 },
                    { "include_entities", true },
                    { "user_id", _userId },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param.Add("max_id", maxid);
                }

                var userTweets = await Tokens.Statuses.UserTimelineAsync(param);

                if (maxid == 0)
                {
                    Statuses.Clear();
                }

                foreach (var status in userTweets)
                {
                    Connecter.Instance.TweetReceive_OnCommandExecute(this,
                                                                     new TweetEventArgs(status, Tokens.UserId, new List <string> {
                        "none://"
                    }, false));

                    var id    = status.HasRetweetInformation ? status.RetweetInformation.Id : status.Id;
                    var index = Statuses.IndexOf(
                        Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) == id));
                    if (index == -1)
                    {
                        index = Statuses.IndexOf(
                            Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) < id));
                        if (index == -1)
                        {
                            Statuses.Add(status);
                        }
                        else
                        {
                            Statuses.Insert(index, status);
                        }
                    }
                }
            }
            catch
            {
                if (maxid == 0)
                {
                    Statuses.Clear();
                }

                UpdatingStatuses = false;
                return;
            }

            UpdatingStatuses = false;
        }
Example #13
0
        public async Task UpdateStatuses(long maxid = 0, bool clear = true)
        {
            if (UpdatingStatusSearch)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(_statusSearchWords) || Tokens == null)
            {
                return;
            }

            UpdatingStatusSearch = true;

            if (maxid == 0 && clear)
            {
                Statuses.Clear();
            }

            IEnumerable <Status> search;

            if (SettingService.Setting.UseOfficialApi &&
                TwitterConnectionHelper.OfficialConsumerKeyList.Contains(Tokens.ConsumerKey))
            {
                var param = new Dictionary <string, object>
                {
                    { "q", _statusSearchWords },
                    { "count", 20 },
                    { "result_type", "recent" },
                    { "modules", "status" },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param["q"] = param["q"] + " max_id:" + maxid;
                }

                try
                {
                    var res = await Tokens.TwitterTokens.SendRequestAsync(CoreTweet.MethodType.Get,
                                                                          "https://api.twitter.com/1.1/search/universal.json", param);

                    var json = await res.Source.Content.ReadAsStringAsync();

                    var jsonObject = JObject.Parse(json);
                    var modules    = jsonObject["modules"].Children <JObject>();

                    var tweets = new List <CoreTweet.Status>();
                    foreach (var status in modules)
                    {
                        foreach (var prop in status.Properties())
                        {
                            if (prop.Name == "status")
                            {
                                tweets.Add(
                                    CoreTweet.Core.CoreBase.Convert <CoreTweet.Status>(
                                        JsonConvert.SerializeObject(status["status"]["data"])));
                            }
                        }
                    }

                    search = tweets.Select(x => new Status(x));
                }
                catch
                {
                    if (maxid == 0 && clear)
                    {
                        Statuses.Clear();
                    }

                    UpdatingStatusSearch = false;
                    return;
                }
            }
            else
            {
                var param = new Dictionary <string, object>
                {
                    { "count", 20 },
                    { "include_entities", true },
                    { "q", _statusSearchWords },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param.Add("max_id", maxid);
                }

                try
                {
                    search = await Tokens.Search.TweetsAsync(param);
                }
                catch
                {
                    if (maxid == 0 && clear)
                    {
                        Statuses.Clear();
                    }

                    UpdatingStatusSearch = false;
                    return;
                }
            }

            if (maxid == 0 && clear)
            {
                Statuses.Clear();
            }

            foreach (var status in search)
            {
                Connecter.Instance.TweetReceive_OnCommandExecute(this,
                                                                 new TweetEventArgs(status, Tokens.UserId, new List <string> {
                    "none://"
                }, false));

                var id    = status.HasRetweetInformation ? status.RetweetInformation.Id : status.Id;
                var index = Statuses.IndexOf(
                    Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) == id));
                if (index == -1)
                {
                    index = Statuses.IndexOf(
                        Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) < id));
                    if (index == -1)
                    {
                        Statuses.Add(status);
                    }
                    else
                    {
                        Statuses.Insert(index, status);
                    }
                }
            }

            UpdatingStatusSearch = false;
        }