Beispiel #1
0
        private void RemoveRelationship(DiscordRelationship rel, bool skipAll = false)
        {
            if (!skipAll)
            {
                if (_allList.Remove(rel))
                {
                    _syncContext.Post(a => All.Remove(rel), null);
                }
            }

            if (_onlineList.Remove(rel))
            {
                _syncContext.Post(a => Online.Remove(rel), null);
            }

            if (Pending.Contains(rel)) // is this actually faster?
            {
                _syncContext.Post(a => Pending.Remove(rel), null);
            }

            if (Blocked.Contains(rel)) // ^^
            {
                _syncContext.Post(a => Blocked.Remove(rel), null);
            }
        }
Beispiel #2
0
 public void NextMove()
 {
     if (Blocked.Contains("oui") == true)
     {
         RandomDirection();
     }
     Move();
 }
Beispiel #3
0
 public void UnblockUser(FriendModel user, [CanBeNull] Action <FriendModel> onSuccess = null, [CanBeNull] Action <Error> onError = null)
 {
     if (!Blocked.Contains(user))
     {
         RaiseOnError($"Can not unblock user with this nickname = {user.Nickname}. This user is not in the list of blocked friends.", onError);
     }
     else
     {
         SdkFriendsLogic.Instance.UnblockUser(user, u =>
         {
             RemoveUserFromMemory(user);
             onSuccess?.Invoke(u);
         }, onError);
     }
 }
Beispiel #4
0
 public void AddFriend(FriendModel user, [CanBeNull] Action <FriendModel> onSuccess = null, [CanBeNull] Action <Error> onError = null)
 {
     if (Friends.Contains(user) || Blocked.Contains(user) || Pending.Contains(user) || Requested.Contains(user))
     {
         RaiseOnError($"Can not add friend with this nickname = {user.Nickname}. This friend is not in the 'initial' state.", onError);
     }
     else
     {
         SdkFriendsLogic.Instance.SendFriendshipInvite(user, u =>
         {
             RemoveUserFromMemory(user);
             UpdateRequestedUsers(onError: onError);
             onSuccess?.Invoke(u);
         }, onError);
     }
 }
Beispiel #5
0
 public void BlockUser(FriendModel user, [CanBeNull] Action <FriendModel> onSuccess = null, [CanBeNull] Action <Error> onError = null)
 {
     if (Blocked.Contains(user))
     {
         RaiseOnError($"Can not block user with this nickname = {user.Nickname}. They are already blocked.", onError);
     }
     else
     {
         SdkFriendsLogic.Instance.BlockUser(user, blockedUser =>
         {
             RemoveUserFromMemory(user);
             UpdateBlockedUsers(onError: onError);
             onSuccess?.Invoke(blockedUser);
         }, onError);
     }
 }
Beispiel #6
0
 private void RemoveUserFromMemory(FriendModel user)
 {
     if (Friends.Contains(user))
     {
         Friends.Remove(user);
         UserFriendsUpdatedEvent?.Invoke();
     }
     if (Pending.Contains(user))
     {
         Pending.Remove(user);
         PendingUsersUpdatedEvent?.Invoke();
     }
     if (Requested.Contains(user))
     {
         Requested.Remove(user);
         RequestedUsersUpdatedEvent?.Invoke();
     }
     if (Blocked.Contains(user))
     {
         Blocked.Remove(user);
         BlockedUsersUpdatedEvent?.Invoke();
     }
 }
Beispiel #7
0
        public override void Live()
        {
            //Logger.WriteLogFile($"deltatime: {MotherNature.LastFrameDuration}");
            List <Brick> ListBricks;

            LogEnergy();
            numLive++;
            if (numLive == 1)
            {
                SudOuest(); //default start direction.
            }

            //Default behavior of movement:
            if (Blocked.Contains("oui") == true)
            {
                RandomDirection();
            }

            switch (phase)
            {
            case 1:     //Go to first brick that you find
                closestBrick = getClosestBrick();
                if (closestBrick != null)
                {
                    MoveToward(new System.Drawing.Point((int)closestBrick.Location.X, (int)closestBrick.Location.Y));
                }

                NextMove();     //Move to the next position
                if (closestBrick != null)
                {
                    if (Helpers.Distance(closestBrick.Location, SDLocation) < PICKUP_REACH)
                    {
                        phase = 2;
                    }
                }
                break;

            case 2:     //Found a brick, just pick up the brick several times
                closestBrick = getClosestBrick();

                if (Helpers.Distance(closestBrick.Location, SDLocation) < PICKUP_REACH)
                {
                    Pickup(closestBrick);
                }
                else
                {
                    MoveToward(new System.Drawing.Point((int)closestBrick.Location.X, (int)closestBrick.Location.Y));
                    NextMove();
                }

                Logger.WriteLogFile($"GreenWorker {Fullname} found brick and picked up in BrickBag: {BrickBag}");
                if (BrickBag == BRICK_BAG_SIZE * 20)
                {
                    phase = 3;
                }
                break;

            case 3:     //BrickBag is full, return back to the base
                Logger.WriteLogFile($"GreenWorker {Fullname}: Distance à la colonie{Helpers.Distance(new System.Drawing.Point((int)Colony.Location.X, (int)Colony.Location.Y), new System.Drawing.Point((int)this.SDLocation.X, (int)this.SDLocation.Y))}");
                MoveToward(new System.Drawing.Point((int)Colony.Location.X, (int)Colony.Location.Y));

                NextMove();

                if (Helpers.Distance(new System.Drawing.Point((int)Colony.Location.X, (int)Colony.Location.Y), new System.Drawing.Point((int)this.SDLocation.X, (int)this.SDLocation.Y)) < 5)
                {
                    phase = 4;
                }
                break;

            case 4:     //Build the base with bricks
                if (brickPeriod == true)
                {
                    Build();
                    Logger.WriteLogFile($"GreenWorker {Fullname} pick down a brick in the colony. BrickBag: {BrickBag}");
                    brickPeriod = false;
                }
                else
                {
                    //move a bit to exit the base
                    RandomDirection();
                    NextMove();
                    brickPeriod = true;
                }
                if (BrickBag == 0)
                {
                    phase = 1;
                }
                break;

            default:
                break;
            }
        }