Пример #1
0
    public bool AddItem(OSItem item)
    {
        if (!item)
        {
            return(false);
        }

        item.definitions = this.definitions;

        // Check if similar item is already in the inventory
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i].item.id == item.id)
            {
                if (item.stackable)
                {
                    slots[i].quantity++;

                    // TODO: Find a way to store ammunition information *not* in the OSItem prefab itself
                    //} else if ( item.ammunition.enabled ) {
                    //	slots[i].item.ChangeAmmunition ( item.ammunition.value );

                    return(true);
                }
            }
        }

        // If not, search for available slots
        OSPoint availableCell = new OSPoint(-1, -1);

        availableCell = grid.GetAvailableCell(item);

        if (OSPoint.IsNullOrNegative(availableCell))
        {
            return(false);
        }
        else
        {
            slots.Add(new OSSlot(availableCell.x, availableCell.y, item));
            return(true);
        }
    }
Пример #2
0
    public OSPoint GetAvailableCell(OSItem item)
    {
        bool [ , ] skip = GetSkippedSlots();

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                bool    cancel = false;
                OSPoint point  = new OSPoint(x, y);

                for (int sx = 0; sx < item.slotSize.x; sx++)
                {
                    for (int sy = 0; sy < item.slotSize.y; sy++)
                    {
                        OSSlot slot = inventory.GetSlot(x + sx, y + sy);

                        if (slot != null && !slot.hidden && slot.item != null || x + sx >= width || y + sy >= height || skip [x + sx, y + sy])
                        {
                            cancel = true;
                        }
                    }
                }

                if (cancel)
                {
                    continue;
                }
                else
                {
                    return(point);
                }
            }
        }

        return(null);
    }
Пример #3
0
	public OSPoint GetAvailableCell ( OSItem item ) {
		bool [ , ] skip = GetSkippedSlots ();

		for ( int y = 0; y < height; y++ ) {
			for ( int x = 0; x < width; x++ ) {
				bool cancel = false;
				OSPoint point = new OSPoint ( x, y );

				for ( int sx = 0; sx < item.slotSize.x; sx++ ) {
					for ( int sy = 0; sy < item.slotSize.y; sy++ ) {
						OSSlot slot = inventory.GetSlot ( x + sx, y + sy );

						if ( slot != null && !slot.hidden && slot.item != null || x + sx >= width || y + sy >= height || skip [ x + sx, y + sy ] ) {
							cancel = true;
						}
					}
				}
				
				if ( cancel ) {
					continue;

				} else {
					return point;

				}
			}
		}

		return null;
	}
Пример #4
0
	public bool AddItem ( OSItem item ) {
		if ( !item ) { return false; }
	
		item.definitions = this.definitions;
	
		// Check if similar item is already in the inventory
		for ( int i = 0; i < slots.Count; i++ ) {
			if ( slots[i].item.id == item.id ) {
			       	if ( item.stackable ) {
					slots[i].quantity++;
				
				// TODO: Find a way to store ammunition information *not* in the OSItem prefab itself
				//} else if ( item.ammunition.enabled ) {
				//	slots[i].item.ChangeAmmunition ( item.ammunition.value );
				
					return true;
				}
			}
		}
		
		// If not, search for available slots
		OSPoint availableCell = new OSPoint ( -1, -1 );

		availableCell = grid.GetAvailableCell ( item );
		
		if ( OSPoint.IsNullOrNegative ( availableCell ) ) {
			return false;

		} else {
			slots.Add ( new OSSlot ( availableCell.x, availableCell.y, item ) );
			return true;

		}

	}
Пример #5
0
	public static bool IsNullOrNegative ( OSPoint p ) {
		return ( p == null || p.x < 0 || p.y < 0 );
	}
Пример #6
0
 public static bool IsNullOrNegative(OSPoint p)
 {
     return(p == null || p.x < 0 || p.y < 0);
 }