Exemplo n.º 1
0
        internal static int Drag(Item i, int amount, bool fromClient, bool doLast)
        {
            LiftReq lr   = new LiftReq(i.Serial, amount, fromClient, doLast);
            LiftReq prev = null;

            if (Full)
            {
                Log("Queue FULL {0}", lr);
                World.Player.SendMessage(MsgLevel.Error, LocString.DragDropQueueFull);
                if (fromClient)
                {
                    Assistant.Client.Instance.SendToClient(new LiftRej());
                }
                return(0);
            }

            Log("Queuing Drag request {0}", lr);

            if (m_Back >= m_LiftReqs.Length)
            {
                m_Back = 0;
            }

            if (m_Back <= 0)
            {
                prev = m_LiftReqs[m_LiftReqs.Length - 1];
            }
            else if (m_Back <= m_LiftReqs.Length)
            {
                prev = m_LiftReqs[m_Back - 1];
            }

            // if the current last req must stay last, then insert this one in its place
            if (prev != null && prev.DoLast)
            {
                Log("Back-Queuing {0}", prev);
                if (m_Back <= 0)
                {
                    m_LiftReqs[m_LiftReqs.Length - 1] = lr;
                }
                else if (m_Back <= m_LiftReqs.Length)
                {
                    m_LiftReqs[m_Back - 1] = lr;
                }

                // and then re-insert it at the end
                lr = prev;
            }

            m_LiftReqs[m_Back++] = lr;

            ActionQueue.SignalLift(!fromClient);
            return(lr.Id);
        }
Exemplo n.º 2
0
        public static int Drag(Item i, int amount, bool fromClient, bool doLast)
        {
            LiftReq lr   = new LiftReq(i.Serial, amount, fromClient, doLast);
            LiftReq prev = null;

            if (Full)
            {
                if (fromClient)
                {
                    ClientCommunication.SendToClient(new LiftRej());
                }
                return(0);
            }

            Log("Queuing Drag request {0}", lr);

            if (m_Back >= m_LiftReqs.Length)
            {
                m_Back = 0;
            }

            if (m_Back <= 0)
            {
                prev = m_LiftReqs[m_LiftReqs.Length - 1];
            }
            else if (m_Back <= m_LiftReqs.Length)
            {
                prev = m_LiftReqs[m_Back - 1];
            }

            // if the current last req must stay last, then insert this one in its place
            if (prev != null && prev.DoLast)
            {
                Log("Back-Queuing {0}", prev);
                if (m_Back <= 0)
                {
                    m_LiftReqs[m_LiftReqs.Length - 1] = lr;
                }
                else if (m_Back <= m_LiftReqs.Length)
                {
                    m_LiftReqs[m_Back - 1] = lr;
                }

                // and then re-insert it at the end
                lr = prev;
            }

            m_LiftReqs[m_Back++] = lr;

            ActionQueue.SignalLift(!fromClient);
            return(lr.Id);
        }
Exemplo n.º 3
0
        public static int Drag( Item i, int amount, bool fromClient, bool doLast )
        {
            LiftReq lr = new LiftReq( i.Serial, amount, fromClient, doLast );
            LiftReq prev = null;

            if ( Full )
            {
                World.Player.SendMessage( MsgLevel.Error, LocString.DragDropQueueFull );
                if ( fromClient )
                    ClientCommunication.SendToClient( new LiftRej() );
                return 0;
            }

            Log( "Queuing Drag request {0}", lr );

            if ( m_Back >= m_LiftReqs.Length )
                m_Back = 0;

            if ( m_Back <= 0 )
                prev = m_LiftReqs[m_LiftReqs.Length-1];
            else if ( m_Back <= m_LiftReqs.Length )
                prev = m_LiftReqs[m_Back-1];

            // if the current last req must stay last, then insert this one in its place
            if ( prev != null && prev.DoLast )
            {
                Log( "Back-Queuing {0}", prev );
                if ( m_Back <= 0 )
                    m_LiftReqs[m_LiftReqs.Length-1] = lr;
                else if ( m_Back <= m_LiftReqs.Length )
                    m_LiftReqs[m_Back-1] = lr;

                // and then re-insert it at the end
                lr = prev;
            }

            m_LiftReqs[m_Back++] = lr;

            ActionQueue.SignalLift( !fromClient );
            return lr.Id;
        }
Exemplo n.º 4
0
        public static ProcStatus ProcessNext(int numPending)
        {
            if (m_Pending != Serial.Zero)
            {
                if (m_Lifted + TimeSpan.FromMinutes(2) < DateTime.UtcNow)
                {
                    Item i = World.FindItem(m_Pending);

                    Log("Lift timeout, forced drop to pack for {0}", m_Pending);

                    if (World.Player != null)
                    {
                        World.Player.SendMessage(MsgLevel.Force, LocString.ForceEndHolding);

                        if (World.Player.Backpack != null)
                        {
                            Client.Instance.SendToServer(new DropRequest(m_Pending, Point3D.MinusOne,
                                                                         World.Player.Backpack.Serial));
                        }
                        else
                        {
                            Client.Instance.SendToServer(new DropRequest(m_Pending, World.Player.Position,
                                                                         Serial.Zero));
                        }
                    }

                    m_Holding     = m_Pending = Serial.Zero;
                    m_HoldingItem = null;
                    m_Lifted      = DateTime.MinValue;
                }
                else
                {
                    return(ProcStatus.KeepWaiting);
                }
            }

            if (m_Front == m_Back)
            {
                m_Front = m_Back = 0;
                return(ProcStatus.Nothing);
            }

            LiftReq lr = m_LiftReqs[m_Front];

            if (numPending > 0 && lr != null && lr.DoLast)
            {
                return(ProcStatus.ReQueue);
            }

            m_LiftReqs[m_Front] = null;
            m_Front++;
            if (lr != null)
            {
                Log("Lifting {0}", lr);

                Item item = World.FindItem(lr.Serial);
                if (item != null && item.Container == null)
                {
                    // if the item is on the ground and out of range then dont grab it
                    if (Utility.Distance(item.GetWorldPosition(), World.Player.Position) > 3)
                    {
                        Log("Item is too far away... uncaching.");
                        ScavengerAgent.Instance.Uncache(item.Serial);
                        return(ProcStatus.Nothing);
                    }
                }

                Client.Instance.SendToServer(new LiftRequest(lr.Serial, lr.Amount));

                m_LastID        = lr.Id;
                m_Holding       = lr.Serial;
                m_HoldingItem   = World.FindItem(lr.Serial);
                m_ClientLiftReq = lr.FromClient;

                DropReq dr = DequeueDropFor(lr.Serial);
                if (dr != null)
                {
                    m_Pending = Serial.Zero;
                    m_Lifted  = DateTime.MinValue;

                    Log("Dropping {0} to {1}", lr, dr.Serial);

                    if (dr.Serial.IsMobile && dr.Layer > Layer.Invalid && dr.Layer <= Layer.LastUserValid)
                    {
                        Client.Instance.SendToServer(new EquipRequest(lr.Serial, dr.Serial, dr.Layer));
                    }
                    else
                    {
                        Client.Instance.SendToServer(new DropRequest(lr.Serial, dr.Point, dr.Serial));
                    }
                }
                else
                {
                    m_Pending = lr.Serial;
                    m_Lifted  = DateTime.UtcNow;
                }

                return(ProcStatus.Success);
            }
            else
            {
                Log("No lift to be done?!");
                return(ProcStatus.Nothing);
            }
        }