WiredEffect MoveFurniToUserBox Lag

Hahn

Member
Jan 7, 2017
44
7
The furni have delay on movement with wired MoveFurniToUserBox, how to resolve this?
You must be registered for see images attach
 

cammy

Member
May 15, 2014
471
220
This was an issue I tried relentlessly to fix. I really struggled. Hope you find a solution! - Arcturus Morningstar has no issue with this.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
I would look into the OnCycle function of the wired, to see how often the wired function is being called. It might only be executed once a second, instead of everything half a second.
 

Hahn

Member
Jan 7, 2017
44
7
If your timer cycle is only checking it every second, then it's impossible for it to move every 0.5 seconds, so yes it would.
My code of MoveFurniToUser is:
C#:
public Point GetChaseMovement(Item Item)
        {
            int Distance = 99;
            Point Coord = new Point(0, 0);
            int iX = Item.GetX;
            int iY = Item.GetY;
            bool X = false;

            foreach (RoomUser User in _room.GetRoomUserManager().GetRoomUsers())
            {
                if (User.X == Item.GetX || Item.GetY == User.Y)
                {
                    if (User.X == Item.GetX)
                    {
                        int Difference = Math.Abs(User.Y - Item.GetY);
                        if (Difference < Distance)
                        {
                            Distance = Difference;
                            Coord = User.Coordinate;
                            X = false;
                        }
                        else
                            continue;

                    }
                    else if (User.Y == Item.GetY)
                    {
                        int Difference = Math.Abs(User.X - Item.GetX);
                        if (Difference < Distance)
                        {
                            Distance = Difference;
                            Coord = User.Coordinate;
                            X = true;
                        }
                        else
                            continue;
                    }
                    else if (User.Y != Item.GetY)
                    {
                        int Difference = Math.Abs(User.X - Item.GetY);
                        if (Difference < Distance)
                        {
                            Distance = Difference;
                            Coord = User.Coordinate;
                            X = true;
                        }
                        else
                            continue;
                    }
                    else
                        continue;
                }
            }

            if (Distance > 5)
                return Item.GetSides().OrderBy(x => Guid.NewGuid()).FirstOrDefault();
            if (X && Distance < 99)
            {
                if (iX > Coord.X)
                {
                    iX--;
                    return new Point(iX, iY);
                }
                else
                {
                    iX++;
                    return new Point(iX, iY);
                }
            }
            else if (!X && Distance < 99)
            {
                if (iY > Coord.Y)
                {
                    iY--;
                    return new Point(iX, iY);
                }
                else
                {
                    iY++;
                    return new Point(iX, iY);
                }
            }
            else
                return Item.Coordinate;
        }

My OnCycle:

C#:
public bool OnCycle()
        {
            if (Instance == null || !Requested || _next < 1)
                return false;
            var time = OreoServer.GetUnixTimestamp();           
            if (_next <= time)
            {
                foreach (
                    var Item in
                    SetItems.Values.ToList()
                        .Where(Item => Item != null)
                        .Where(Item => Instance.GetRoomItemHandler().GetFloor.Contains(Item)))
                {
                    Item toRemove;

                    if (Instance.GetWired().OtherBoxHasItem(this, Item.Id))
                        SetItems.TryRemove(Item.Id, out toRemove);

                    var Point = Instance.GetGameMap().GetChaseMovement(Item);

                    Instance.GetWired().onUserFurniCollision(Instance, Item);

                    if (!Instance.GetGameMap().ItemCanMove(Item, Point))
                        continue;

                    if (Instance.GetGameMap().CanRollItemHere(Point.X, Point.Y) &&
                        !Instance.GetGameMap().SquareHasUsers(Point.X, Point.Y))
                    {
                        var NewZ = Item.GetZ;
                        var CanBePlaced = true;

                        var Items = Instance.GetGameMap().GetCoordinatedItems(Point);
                        foreach (var IItem in Items.ToList().Where(IItem => IItem != null && IItem.Id != Item.Id))
                        {
                            if (!IItem.GetBaseItem().Walkable)
                            {
                                _next = 0;
                                CanBePlaced = false;
                                break;
                            }

                            if (IItem.TotalHeight > NewZ)
                                NewZ = IItem.TotalHeight;

                            if (CanBePlaced && !IItem.GetBaseItem().Stackable)
                                CanBePlaced = false;
                        }

                        if (CanBePlaced && Point != Item.Coordinate)
                        {
                            Instance.SendMessage(new SlideObjectBundleComposer(Item.GetX, Item.GetY, Item.GetZ, Point.X,
                                Point.Y, NewZ, 0, 0, Item.Id));
                            Instance.GetRoomItemHandler().SetFloorItem(Item, Point.X, Point.Y, NewZ);
                        }
                    }
                }

                _next = 0;
                return true;
            }
            return false;
        }
 
Last edited:

Hahn

Member
Jan 7, 2017
44
7
The function that calls oncycle, has nothing to do with OnCycle
I already have put the code OnCycle, don't this is?
my code wired:
C#:
 internal class MoveFurniToUserBox : IWiredItem, IWiredCycle
    {
        private double _delay;
        private double _next;
        private bool Requested;

        public MoveFurniToUserBox(Room Instance, Item Item)
        {
            this.Instance = Instance;
            this.Item = Item;
            SetItems = new ConcurrentDictionary<int, Item>();
            TickCount = Delay;
            Requested = false;
        }

             public double Delay
        {
            get { return _delay; }
            set
            {
                _delay = value;
                TickCount = value + 1;
            }
        }

        public double TickCount { get; set; }

        public bool OnCycle()
        {
            if (Instance == null || !Requested || _next < 1)
                return false;
            var time = OreoServer.GetUnixTimestamp();          
            if (_next <= time)
            {
                foreach (
                    var Item in
                    SetItems.Values.ToList()
                        .Where(Item => Item != null)
                        .Where(Item => Instance.GetRoomItemHandler().GetFloor.Contains(Item)))
                {
                    Item toRemove;

                    if (Instance.GetWired().OtherBoxHasItem(this, Item.Id))
                        SetItems.TryRemove(Item.Id, out toRemove);

                    var Point = Instance.GetGameMap().GetChaseMovement(Item);

                    Instance.GetWired().onUserFurniCollision(Instance, Item);

                    if (!Instance.GetGameMap().ItemCanMove(Item, Point))
                        continue;

                    if (Instance.GetGameMap().CanRollItemHere(Point.X, Point.Y) &&
                        !Instance.GetGameMap().SquareHasUsers(Point.X, Point.Y))
                    {
                        var NewZ = Item.GetZ;
                        var CanBePlaced = true;

                        var Items = Instance.GetGameMap().GetCoordinatedItems(Point);
                        foreach (var IItem in Items.ToList().Where(IItem => IItem != null && IItem.Id != Item.Id))
                        {
                            if (!IItem.GetBaseItem().Walkable)
                            {
                                _next = 0;
                                CanBePlaced = false;
                                break;
                            }

                            if (IItem.TotalHeight > NewZ)
                                NewZ = IItem.TotalHeight;

                            if (CanBePlaced && !IItem.GetBaseItem().Stackable)
                                CanBePlaced = false;
                        }

                        if (CanBePlaced && Point != Item.Coordinate)
                        {
                            Instance.SendMessage(new SlideObjectBundleComposer(Item.GetX, Item.GetY, Item.GetZ, Point.X,
                                Point.Y, NewZ, 0, 0, Item.Id));
                            Instance.GetRoomItemHandler().SetFloorItem(Item, Point.X, Point.Y, NewZ);
                        }
                    }
                }

                _next = 0;
                return true;
            }
            return false;
        }

        public Room Instance { get; set; }
        public Item Item { get; set; }

        public WiredBoxType Type => WiredBoxType.EffectMoveFurniToNearestUser;

        public ConcurrentDictionary<int, Item> SetItems { get; set; }
        public string StringData { get; set; }
        public bool BoolData { get; set; }
        public string ItemsData { get; set; }

        public void HandleSave(ClientPacket Packet)
        {
            var Unknown = Packet.PopInt();
            var Unknown2 = Packet.PopString();

            SetItems.Clear();

            var FurniCount = Packet.PopInt();
            for (var i = 0; i < FurniCount; i++)
            {
                var SelectedItem = Instance.GetRoomItemHandler().GetItem(Packet.PopInt());

                if (SelectedItem != null && !Instance.GetWired().OtherBoxHasItem(this, SelectedItem.Id))
                    SetItems.TryAdd(SelectedItem.Id, SelectedItem);
            }

            var Delay = Packet.PopInt();
            this.Delay = Delay;
        }

        public bool Execute(params object[] Params)
        {
            if (SetItems.Count == 0)
                return false;


            if (_next < 1 || _next < OreoServer.GetUnixTimestamp())
            {
                _next = OreoServer.GetUnixTimestamp() + Delay;
            }
            if (!Requested)
            {
                TickCount = Delay;
                Requested = true;
            }
            return true;
        }
    }
 
Last edited:

Joe

Well-Known Member
Jun 10, 2012
4,090
1,918
I think it's the WIRED Trigger: Repeat Effect that's broken, you can manually set it's delay to 0.5 and it'll run really fast however when you set it back to 0.5 it'll jump to 1, you'd have to manually edit this for now until I look into the code.
 

Users who are viewing this thread

Top