Exemplo n.º 1
0
        /// <summary>
        /// Drops item into region and makes it disappear after x seconds.
        /// Sends EntityAppears.
        /// </summary>
        public void DropItem(Item item, int x, int y)
        {
            item.Move(this.Id, x, y);
            item.DisappearTime = DateTime.Now.AddSeconds(Math.Max(60, (item.OptionInfo.Price / 100) * 60));

            this.AddItem(item);
        }
Exemplo n.º 2
0
		public override void AddUnsafe(Item item)
		{
			item.Move(this.Pocket, 0, 0);
			_items.Add(item);
		}
Exemplo n.º 3
0
		/// <summary>
		/// Attempts to add the item at the given position.
		/// </summary>
		/// <remarks>
		/// TODO: Inventory really needs some refactoring, we shouldn't have
		///   to override such methods.
		/// </remarks>
		/// <param name="item"></param>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <returns></returns>
		public bool TryAdd(Item item, int x, int y)
		{
			if (x + item.Data.Width > _width || y + item.Data.Height > _height)
				return false;

			var collidingItems = this.GetCollidingItems((uint)x, (uint)y, item);
			if (collidingItems.Count > 0)
				return false;

			item.Move(this.Pocket, x, y);
			this.AddUnsafe(item);

			return true;
		}
Exemplo n.º 4
0
		public override bool TryAdd(Item newItem, byte targetX, byte targetY, out Item collidingItem)
		{
			collidingItem = _item;

			// Handle stackables and sacs
			if (collidingItem != null && ((collidingItem.Data.StackType == StackType.Sac && (collidingItem.Data.StackItemId == newItem.Info.Id || collidingItem.Data.StackItemId == newItem.Data.StackItemId)) || (newItem.Data.StackType == StackType.Stackable && newItem.Info.Id == collidingItem.Info.Id)))
			{
				if (collidingItem.Info.Amount < collidingItem.Data.StackMax)
				{
					var diff = (ushort)(collidingItem.Data.StackMax - collidingItem.Info.Amount);

					collidingItem.Info.Amount += Math.Min(diff, newItem.Info.Amount);
					newItem.Info.Amount -= Math.Min(diff, newItem.Info.Amount);

					return true;
				}
			}

			// Switch items if colliding
			if (collidingItem != null)
			{
				collidingItem = _item;
				collidingItem.Move(newItem.Info.Pocket, newItem.Info.X, newItem.Info.Y);
			}

			_item = newItem;
			_item.Move(this.Pocket, 0, 0);

			return true;
		}
Exemplo n.º 5
0
		public override bool Add(Item item)
		{
			for (byte y = 0; y <= _height - item.Data.Height; ++y)
			{
				for (byte x = 0; x <= _width - item.Data.Width; ++x)
				{
					if (_map[x, y] != null)
						continue;

					if (this.GetCollidingItems(x, y, item).Count == 0)
					{
						item.Move(this.Pocket, x, y);
						this.AddUnsafe(item);
						return true;
					}
				}
			}

			return false;
		}
Exemplo n.º 6
0
		public override bool TryAdd(Item newItem, byte targetX, byte targetY, out Item collidingItem)
		{
			collidingItem = null;

			if (targetX + newItem.Data.Width > _width || targetY + newItem.Data.Height > _height)
				return false;

			var collidingItems = this.GetCollidingItems(targetX, targetY, newItem);
			if (collidingItems.Count > 1)
				return false;

			if (collidingItems.Count > 0)
				collidingItem = collidingItems[0];

			if (collidingItem != null && (
				// Colliding item is sac and new item can fill be put into it
				(collidingItem.Data.StackType == StackType.Sac && collidingItem.Data.StackItemId != 0 && (collidingItem.Data.StackItemId == newItem.Info.Id || collidingItem.Data.StackItemId == newItem.Data.StackItemId)) ||

				// Colliding item is a quiver (general arrow sac) that
				// a regular arrow can be put into.
				// Corner case, due to quiver being a sac without stack item id,
				// instead of a stackable for some reason. They possibly wanted
				// to be able to put different kinds of arrows into it,
				// otherwise they probably would have made it stackable or
				// specified a stack item id.
				(collidingItem.HasTag("/largearrowsac/") && newItem.HasTag("/arrow_bag_bundle/")) ||

				// Item is stackable and can be put into the colliding stack
				(newItem.Data.StackType == StackType.Stackable && newItem.Info.Id == collidingItem.Info.Id))
			)
			{
				if (collidingItem.Info.Amount < collidingItem.Data.StackMax)
				{
					var diff = (ushort)(collidingItem.Data.StackMax - collidingItem.Info.Amount);

					var amount = collidingItem.Info.Amount;
					collidingItem.Info.Amount += Math.Min(diff, newItem.Info.Amount);
					newItem.Info.Amount -= Math.Min(diff, newItem.Info.Amount);

					if (amount != collidingItem.Info.Amount)
						return true;
				}
			}

			if (collidingItem != null)
			{
				_items.Remove(collidingItem.EntityId);
				collidingItem.Move(newItem.Info.Pocket, newItem.Info.X, newItem.Info.Y);
				this.ClearFromMap(collidingItem);
			}

			_items.Add(newItem.EntityId, newItem);
			newItem.Move(this.Pocket, targetX, targetY);
			this.AddToMap(newItem);

			return true;
		}
Exemplo n.º 7
0
        public override bool TryAdd(Item item, byte targetX, byte targetY, out Item collidingItem)
        {
            collidingItem = null;
            if (_item != null)
            {
                collidingItem = _item;
                collidingItem.Move(item.Info.Pocket, item.Info.X, item.Info.Y);
            }

            _item = item;
            _item.Move(this.Pocket, 0, 0);

            return true;
        }
Exemplo n.º 8
0
        public override bool TryAdd(Item newItem, byte targetX, byte targetY, out Item collidingItem)
        {
            collidingItem = null;

            if (targetX + newItem.Data.Width > _width || targetY + newItem.Data.Height > _height)
                return false;

            var collidingItems = this.GetCollidingItems(targetX, targetY, newItem);
            if (collidingItems.Count > 1)
                return false;

            if (collidingItems.Count > 0)
                collidingItem = collidingItems[0];

            if (collidingItem != null && ((collidingItem.Data.StackType == StackType.Sac && (collidingItem.Data.StackItem == newItem.Info.Id || collidingItem.Data.StackItem == newItem.Data.StackItem)) || (newItem.Data.StackType == StackType.Stackable && newItem.Info.Id == collidingItem.Info.Id)))
            {
                if (collidingItem.Info.Amount < collidingItem.Data.StackMax)
                {
                    var diff = (ushort)(collidingItem.Data.StackMax - collidingItem.Info.Amount);

                    collidingItem.Info.Amount += Math.Min(diff, newItem.Info.Amount);
                    newItem.Info.Amount -= Math.Min(diff, newItem.Info.Amount);

                    return true;
                }
            }

            if (collidingItem != null)
            {
                _items.Remove(collidingItem.EntityId);
                collidingItem.Move(newItem.Info.Pocket, newItem.Info.X, newItem.Info.Y);
                this.ClearFromMap(collidingItem);
            }

            _items.Add(newItem.EntityId, newItem);
            newItem.Move(this.Pocket, targetX, targetY);
            this.AddToMap(newItem);

            return true;
        }