Esempio n. 1
0
 public virtual bool OnDroppedOnto( Mobile from, Item target )
 {
     if ( Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || target.Map == null )
         return false;
     else if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.GetWorldLocation(), 2 ) )
         return false;
     else if ( !from.CanSee( target ) || !from.InLOS( target ) )
         return false;
     else if ( !target.IsAccessibleTo( from ) )
         return false;
     else if ( !from.OnDroppedItemOnto( this, target ) )
         return false;
     else
         return target.OnDragDrop( from, this );
 }
Esempio n. 2
0
        public static bool CheckDoubleClick(
            this Item item,
            Mobile from,
            bool handle        = true,
            bool allowDead     = false,
            int range          = 20,
            bool packOnly      = false,
            bool inTrade       = false,
            bool inDisplay     = true,
            AccessLevel access = AccessLevel.Player)
        {
            if (item == null || item.Deleted || from == null || from.Deleted)
            {
                return(false);
            }

            if (from.AccessLevel < access)
            {
                if (handle)
                {
                    from.SendMessage("You do not have sufficient access to use this item.");
                }

                return(false);
            }

            if (!from.CanSee(item))
            {
                if (handle)
                {
                    from.SendMessage("This item can't be seen.");
                    item.OnDoubleClickCantSee(from);
                }

                return(false);
            }

            if (!item.IsAccessibleTo(from))
            {
                if (handle)
                {
                    item.OnDoubleClickNotAccessible(from);
                }

                return(false);
            }

            if (item.InSecureTrade && !inTrade)
            {
                if (handle)
                {
                    item.OnDoubleClickSecureTrade(from);
                }

                return(false);
            }

            if (((item.Parent == null && !item.Movable && !item.IsLockedDown && !item.IsSecure && !item.InSecureTrade) ||
                 IsShopItem(item)) && !inDisplay)
            {
                if (handle)
                {
                    from.SendMessage("This item can not be accessed because it is part of a display.");
                }

                return(false);
            }

            if (!from.Alive && !allowDead)
            {
                if (handle)
                {
                    item.OnDoubleClickDead(from);
                }

                return(false);
            }

            if (range >= 0 && !from.InRange(item.GetWorldLocation(), range) && !packOnly)
            {
                if (handle)
                {
                    if (range > 0)
                    {
                        from.SendMessage("You must be within {0:#,0} paces to use this item.", range);
                    }
                    else
                    {
                        from.SendMessage("You must be standing on this item to use it.");
                    }

                    item.OnDoubleClickOutOfRange(from);
                }

                return(false);
            }

            if (packOnly && item.RootParent != from)
            {
                if (handle)
                {
                    // This item must be in your backpack.
                    from.SendLocalizedMessage(1054107);
                }

                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        public virtual void Use( Item item )
        {
            if ( item == null || item.Deleted )
                return;

            DisruptiveAction();

            if ( m_Spell != null && !m_Spell.OnCasterUsingObject( item ) )
                return;

            object root = item.RootParent;
            bool okay = false;

            if ( !Utility.InUpdateRange( this, item.GetWorldLocation() ) )
                item.OnDoubleClickOutOfRange( this );
            else if ( !CanSee( item ) )
                item.OnDoubleClickCantSee( this );
            else if ( !item.IsAccessibleTo( this ) )
            {
                Region reg = Region.Find( item.GetWorldLocation(), item.Map );

                if ( reg == null || !reg.SendInaccessibleMessage( item, this ) )
                    item.OnDoubleClickNotAccessible( this );
            }
            else if ( !CheckAlive( false ) )
                item.OnDoubleClickDead( this );
            else if ( item.InSecureTrade )
                item.OnDoubleClickSecureTrade( this );
            else if ( !AllowItemUse( item ) )
                okay = false;
            else if ( !item.CheckItemUse( this, item ) )
                okay = false;
            else if ( root != null && root is Mobile && ((Mobile)root).IsSnoop( this ) )
                item.OnSnoop( this );
            else if ( m_Region.OnDoubleClick( this, item ) )
                okay = true;

            if ( okay )
            {
                if ( !item.Deleted )
                    item.OnItemUsed( this, item );

                if ( !item.Deleted )
                    item.OnDoubleClick( this );
            }
        }
Esempio n. 4
0
        public virtual bool DropToItem( Mobile from, Item target, Point3D p )
        {
            if ( Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || target.Map == null )
                return false;

            object root = target.RootParent;

            if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.GetWorldLocation(), 2 ) )
                return false;
            else if ( !from.CanSee( target ) || !from.InLOS( target ) )
                return false;
            else if ( !target.IsAccessibleTo( from ) )
                return false;
            else if ( root is Mobile && !((Mobile)root).CheckNonlocalDrop( from, this, target ) )
                return false;
            else if ( !from.OnDroppedItemToItem( this, target, p ) )
                return false;
            else if ( target is Container && p.m_X != -1 && p.m_Y != -1 )
                return OnDroppedInto( from, (Container)target, p );
            else
                return OnDroppedOnto( from, target );
        }
Esempio n. 5
0
        public void Lift( Item item, int amount, out bool rejected, out LRReason reject )
        {
            rejected = true;
            reject = LRReason.Inspecific;

            if ( item == null )
                return;

            Mobile from = this;
            GameClient state = m_Client;

            if ( from.AccessLevel >= AccessLevel.GameMaster || DateTime.Now >= from.NextActionTime )
            {
                if ( from.CheckAlive() )
                {
                    from.DisruptiveAction();

                    if ( from.Holding != null )
                    {
                        reject = LRReason.AreHolding;
                    }
                    else if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( item.GetWorldLocation(), 2 ) )
                    {
                        reject = LRReason.OutOfRange;
                    }
                    else if ( !from.CanSee( item ) || !from.InLOS( item ) )
                    {
                        reject = LRReason.OutOfSight;
                    }
                    else if ( !item.VerifyMove( from ) )
                    {
                        reject = LRReason.CannotLift;
                    }
                    else if ( !item.IsAccessibleTo( from ) )
                    {
                        reject = LRReason.CannotLift;
                    }
                    else if ( item.CheckLift( from, item, ref reject ) )
                    {
                        object root = item.RootParent;

                        if ( root != null && root is Mobile && !( (Mobile) root ).CheckNonlocalLift( from, item ) )
                        {
                            reject = LRReason.TryToSteal;
                        }
                        else if ( !from.OnDragLift( item ) || !item.OnDragLift( from ) )
                        {
                            reject = LRReason.Inspecific;
                        }
                        else if ( !from.CheckAlive() )
                        {
                            reject = LRReason.Inspecific;
                        }
                        else
                        {
                            if ( item.Parent != null && item.Parent is Container )
                                ( (Container) item.Parent ).FreePosition( item.GridLocation );

                            item.SetLastMoved();

                            if ( item.Spawner != null )
                            {
                                item.Spawner.Remove( item );
                                item.Spawner = null;
                            }

                            if ( amount == 0 )
                                amount = 1;

                            if ( amount > item.Amount )
                                amount = item.Amount;

                            int oldAmount = item.Amount;
                            //item.Amount = amount; //Set in LiftItemDupe

                            if ( amount < oldAmount )
                                LiftItemDupe( item, amount );

                            InvokeItemLifted( new ItemLiftedEventArgs( item, amount ) );

                            item.RecordBounce();
                            item.OnItemLifted( from, item );
                            item.Internalize();

                            from.Holding = item;

                            from.NextActionTime = DateTime.Now + TimeSpan.FromSeconds( 0.5 );

                            Point3D fixLoc = item.Location;
                            Map fixMap = item.Map;
                            bool shouldFix = ( item.Parent == null );

                            if ( fixMap != null && shouldFix )
                                fixMap.FixColumn( fixLoc.X, fixLoc.Y );

                            reject = LRReason.Inspecific;
                            rejected = false;
                        }
                    }
                }
                else
                {
                    reject = LRReason.Inspecific;
                }
            }
            else
            {
                SendActionMessage();
                reject = LRReason.Inspecific;
            }

            if ( rejected && state != null )
            {
                state.Send( LiftRej.Instantiate( reject ) );

                if ( item.Parent is Item )
                    state.Send( new ContainerContentUpdate( item ) );
                else if ( item.Parent is Mobile )
                    state.Send( new EquipUpdate( item ) );
                else
                    item.SendInfoTo( state );

                if ( ObjectPropertyListPacket.Enabled && item.Parent != null )
                    state.Send( item.OPLPacket );
            }
        }
Esempio n. 6
0
        public virtual void Lift( Item item, int amount, out bool rejected, out LRReason reject )
        {
            rejected = true;
            reject = LRReason.Inspecific;

            if ( item == null )
                return;

            Mobile from = this;
            NetState state = m_NetState;

            if ( from.AccessLevel >= AccessLevel.GameMaster || Core.Now >= from.NextActionTime )
            {
                if ( from.CheckAlive() )
                {
                    from.DisruptiveAction();

                    if ( from.Holding != null )
                    {
                        reject = LRReason.AreHolding;
                    }
                    else if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( item.GetWorldLocation(), 2 ) )
                    {
                        reject = LRReason.OutOfRange;
                    }
                    else if ( !from.CanSee( item ) || !from.InLOS( item ) )
                    {
                        reject = LRReason.OutOfSight;
                    }
                    else if ( !item.VerifyMove( from ) )
                    {
                        reject = LRReason.CannotLift;
                    }
                    else if ( item.InSecureTrade || !item.IsAccessibleTo( from ) )
                    {
                        reject = LRReason.CannotLift;
                    }
                    else if ( !item.CheckLift( from, item ) )
                    {
                        reject = LRReason.Inspecific;
                    }
                    else
                    {
                        object root = item.RootParent;

                        if ( root != null && root is Mobile && !((Mobile)root).CheckNonlocalLift( from, item ) )
                        {
                            reject = LRReason.TryToSteal;
                        }
                        else if ( !from.OnDragLift( item ) || !item.OnDragLift( from ) )
                        {
                            reject = LRReason.Inspecific;
                        }
                        else if ( !from.CheckAlive() )
                        {
                            reject = LRReason.Inspecific;
                        }
                        else
                        {
                            item.SetLastMoved();

                            if ( amount == 0 )
                                amount = 1;

                            if ( amount > item.Amount )
                                amount = item.Amount;

                            int oldAmount = item.Amount;
                            item.Amount = amount;

                            if ( amount < oldAmount )
                                item.Dupe( oldAmount - amount );

                            Map map = from.Map;

                            if ( Mobile.DragEffects && map != null && (root == null || root is Item))
                            {
                                IPooledEnumerable eable = map.GetClientsInRange( from.Location );
                                Packet p = null;

                                foreach ( NetState ns in eable )
                                {
                                    if ( ns.Mobile != from && ns.Mobile.CanSee( from ) )
                                    {
                                        if ( p == null )
                                        {
                                            IEntity src;

                                            if ( root == null )
                                                src = new Entity( Serial.Zero, item.Location, map );
                                            else
                                                src = new Entity( ((Item)root).Serial, ((Item)root).Location, map );

                                            p = new DragEffect( src, from, item.ItemID, item.Hue, amount );
                                        }

                                        ns.Send( p );
                                    }
                                }

                                eable.Free();
                            }

                            Point3D fixLoc = item.Location;
                            Map fixMap = item.Map;
                            bool shouldFix = ( item.Parent == null );

                            item.RecordBounce();
                            item.OnItemLifted( from, item );
                            item.Internalize();

                            from.Holding = item;

                            int liftSound = item.GetLiftSound( from );

                            if ( liftSound != -1 )
                                from.Send( new PlaySound( liftSound, from ) );

                            from.NextActionTime = Core.Now + TimeSpan.FromSeconds( 0.5 );

                            if ( fixMap != null && shouldFix )
                                fixMap.FixColumn( fixLoc.m_X, fixLoc.m_Y );

                            reject = LRReason.Inspecific;
                            rejected = false;
                        }
                    }
                }
                else
                {
                    reject = LRReason.Inspecific;
                }
            }
            else
            {
                SendActionMessage();
                reject = LRReason.Inspecific;
            }

            if ( rejected && state != null )
            {
                state.Send( new LiftRej( reject ) );

                if( item.Parent is Item ) {
                    if ( state.IsPost6017 )
                        state.Send( new ContainerContentUpdate6017( item ) );
                    else
                        state.Send( new ContainerContentUpdate( item ) );
                } else if( item.Parent is Mobile )
                    state.Send( new EquipUpdate( item ) );
                else
                    item.SendInfoTo( state );

                if ( ObjectPropertyList.Enabled && item.Parent != null )
                    state.Send( item.OPLPacket );
            }
        }
Esempio n. 7
0
		public virtual bool CanTrash(Mobile from, Item trash, bool message = true)
		{
			if (trash == null || trash.Deleted || !trash.Movable || !trash.IsAccessibleTo(from) ||
				!TrashCollection.CMOptions.ModuleEnabled)
			{
				return false;
			}

			return TrashCollection.Handlers.Values.Any(h => h != null && h.CanTrash(@from, trash, message));
		}
		public virtual bool CanTrash(Mobile from, Item trash, bool message = true)
		{
			if (!Enabled || trash == null || trash.Deleted || !trash.Movable || !trash.IsAccessibleTo(from))
			{
				return false;
			}

			Type iType = trash.GetType();

			if (!IsAccepted(from, iType) || IsIgnored(from, iType))
			{
				return false;
			}

			if (trash is Container)
			{
				Container c = (Container)trash;
				bool trashThis = c.FindItemsByType<Item>().All(ci => CanTrash(from, ci));

				if (!trashThis)
				{
					return false;
				}
			}

			return true;
		}
Esempio n. 9
0
 public virtual bool OnDroppedOnto( Mobile from, Item target )
 {
     if ( IsUnderYourFeet( from, target ) )
     {
         from.SendMessage( "No puedes mover eso, ¡estás pisando la bolsa!" );
         return false;
     }
     else if ( Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || target.Map == null )
         return false;
     else if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.GetWorldLocation(), 2 ) )
         return false;
     else if ( !from.CanSee( target ) || !from.InLOS( target ) )
         return false;
     else if ( !target.IsAccessibleTo( from ) )
         return false;
     else if ( !from.OnDroppedItemOnto( this, target ) )
         return false;
     else if ( NonTransferable && from.IsPlayer && from.AccessLevel <= AccessLevel.GameMaster )
     {
         HandleInvalidTransfer( from );
         return false;
     }
     else
         return target.OnDragDrop( from, this );
 }
Esempio n. 10
0
		public bool Add(Mobile m, Item item, RuneCodexCategory cat, bool message)
		{
			if (m == null || m.Deleted || item == null || item.Deleted || !item.IsAccessibleTo(m))
			{
				return false;
			}

			if (item is RecallRune)
			{
				return AddRune(m, (RecallRune)item, cat, message);
			}

			if (item is Runebook)
			{
				return AddRunebook(m, (Runebook)item, cat, message);
			}

			#region Master Runebook Support
			//Using Reflection for shards that don't have it installed.
			Type t = item.GetType();

			if (Insensitive.Equals(t.Name, "MasterRunebook"))
			{
				var pi = t.GetProperty("Books");

				if (pi != null && pi.CanRead)
				{
					var obj = pi.GetValue(item, null);

					if (obj is ICollection)
					{
						var ex = new Queue<Runebook>(((ICollection)obj).OfType<Runebook>().Where(r => r.Entries.Count > 0));

						if (ex.Count == 0)
						{
							if (message)
							{
								m.SendMessage("That master rune book is empty.");
							}

							return false;
						}

						if (Categories.Count + ex.Count > Categories.Capacity)
						{
							if (message)
							{
								m.SendMessage("That master rune book won't fit in this rune codex.");
							}

							return false;
						}

						int extracted = 0;

						while (ex.Count > 0)
						{
							var b = ex.Dequeue();

							if (AddRunebook(m, b, cat, message))
							{
								++extracted;
							}
						}

						if (extracted > 0)
						{
							if (message)
							{
								m.SendMessage(
									"You extract {0:#,0} book{1} from the master rune book and add them to the codex.",
									extracted,
									extracted != 1 ? "s" : String.Empty);
							}

							return true;
						}

						if (message)
						{
							m.SendMessage("There was nothing in the master rune book to extract.");
						}
					}
				}

				return false;
			}
			#endregion Master Runebook Support

			if (AddCharges(m, item, message))
			{
				return item.Deleted;
			}

			if (message)
			{
				m.SendMessage("Drop a rune book or recall rune on the codex to add them.");
			}

			return false;
		}
Esempio n. 11
0
		public virtual bool AddCharges(Mobile m, Item item, bool message)
		{
			if (m == null || m.Deleted || item == null || item.Deleted || !item.IsAccessibleTo(m))
			{
				return false;
			}

			int cost;

			if (!CanChargeWith(m, item, out cost, message))
			{
				return false;
			}

			if (item.Amount < cost)
			{
				if (message)
				{
					m.SendMessage("One charge costs {0:#,0} {1}.", cost, item.ResolveName(m));
				}

				return false;
			}

			int c = (int)Math.Min((long)(Charges + (int)Math.Floor(item.Amount / (double)cost)), Int32.MaxValue) - Charges;

			if (c <= 0)
			{
				return false;
			}

			int con = c * cost;

			item.Consume(con);

			Charges += c;

			if (message)
			{
				m.SendMessage(
					"You added {0:#,0} charge{1} to the codex and consumed {2:#,0} {3}.",
					c,
					c != 1 ? "s" : String.Empty,
					con,
					item.ResolveName());
			}

			InvalidateProperties();
			return true;
		}
Esempio n. 12
0
		public virtual bool CanChargeWith(Mobile m, Item item, out int cost, bool message)
		{
			cost = 0;

			if (m == null || m.Deleted || item == null || item.Deleted || !item.IsAccessibleTo(m))
			{
				return false;
			}

			Type t = item.GetType();

			if (ChargeTypes.ContainsKey(t))
			{
				cost = ChargeTypes[t];
				return true;
			}

			if (message)
			{
				m.SendMessage("That item is not accepted for charging this codex.");
			}

			return false;
		}
Esempio n. 13
0
		public virtual bool CanTrash(Mobile from, Item trash, bool message = true)
		{
			if (!Enabled || trash == null || trash.Deleted || !trash.Movable || !trash.IsAccessibleTo(from))
			{
				return false;
			}

			if (IgnoreInsured && trash.Insured)
			{
				return false;
			}

			if (IgnoreBlessed && (trash.LootType == LootType.Blessed || trash.BlessedFor != null))
			{
				return false;
			}

			var iType = trash.GetType();

			return IsAccepted(from, iType) && !IsIgnored(from, iType);
		}