Exemplo n.º 1
0
/**
 * Check to see if the player is picking up loot on the ground
 */
void GameStatePlay::checkLoot() {

	if (!pc->stats.alive)
		return;

	if (menu->isDragging())
		return;

	ItemStack pickup;

	// Autopickup
	if (AUTOPICKUP_CURRENCY) {
		pickup = loot->checkAutoPickup(pc->stats.pos);
		if (!pickup.empty()) {
			menu->inv->add(pickup, CARRIED, -1, true, true);
			pickup.clear();
		}
	}

	// Normal pickups
	if (!pc->stats.attacking) {
		pickup = loot->checkPickup(inpt->mouse, mapr->cam, pc->stats.pos);
	}

	if (!pickup.empty()) {
		menu->inv->add(pickup, CARRIED, -1, true, true);
		camp->setStatus(items->items[pickup.item].pickup_status);
		pickup.clear();
	}

}
Exemplo n.º 2
0
ItemStack MenuItemStorage::click(Point position) {
    ItemStack item;

    drag_prev_slot = slotOver(position);

    // try to click on the highlighted (aka in focus) slot
    // since mouse clicks defocus slots before this point,
    // we don't have to worry about the mouse being over another slot
    if (drag_prev_slot == -1) {
        for (unsigned int i=0; i<slots.size(); i++) {
            if (slots[i]->in_focus) {
                drag_prev_slot = i;
                break;
            }
        }
    }

    if (drag_prev_slot > -1) {
        item = storage[drag_prev_slot];
        if (TOUCHSCREEN) {
            if (!slots[drag_prev_slot]->in_focus && !item.empty()) {
                slots[drag_prev_slot]->in_focus = true;
                current_slot = slots[drag_prev_slot];
                item.clear();
                drag_prev_slot = -1;
                return item;
            }
            else {
                slots[drag_prev_slot]->in_focus = false;
                current_slot = NULL;
            }
        }
        if (!item.empty()) {
            if (item.quantity > 1 && !inpt->pressing[CTRL] && (inpt->pressing[SHIFT] || NO_MOUSE || inpt->touch_locked)) {
                // we use an external menu to let the player pick the desired quantity
                // we will subtract from this stack after they've made their decision
                return item;
            }
            subtract( drag_prev_slot, item.quantity);
        }
        // item will be cleared if item.empty() == true
        return item;
    }
    else {
        item.clear();
        return item;
    }
}
Exemplo n.º 3
0
/**
 * Click-start dragging in the inventory
 */
ItemStack MenuInventory::click(Point position) {
	ItemStack item;

	drag_prev_src = areaOver(position);
	if (drag_prev_src > -1) {
		item = inventory[drag_prev_src].click(position);

		if (TOUCHSCREEN) {
			tablist.setCurrent(inventory[drag_prev_src].current_slot);
		}

		if (item.empty()) {
			drag_prev_src = -1;
			return item;
		}

		// if dragging equipment, prepare to change stats/sprites
		if (drag_prev_src == EQUIPMENT) {
			if (stats->humanoid) {
				updateEquipment(inventory[EQUIPMENT].drag_prev_slot);
			}
			else {
				itemReturn(item);
				item.clear();
			}
		}
	}

	return item;
}
Exemplo n.º 4
0
ItemStack MenuItemStorage::click(Point position) {
	ItemStack item;

	drag_prev_slot = slotOver(position);

	// try to click on the highlighted (aka in focus) slot
	// since mouse clicks defocus slots before this point,
	// we don't have to worry about the mouse being over another slot
	if (drag_prev_slot == -1) {
		for (unsigned int i=0; i<slots.size(); i++) {
			if (slots[i]->in_focus) {
				drag_prev_slot = i;
				break;
			}
		}
	}

	if (drag_prev_slot > -1) {
		item = storage[drag_prev_slot];
		if (TOUCHSCREEN) {
			if (!slots[drag_prev_slot]->in_focus && !item.empty()) {
				slots[drag_prev_slot]->in_focus = true;
				current_slot = slots[drag_prev_slot];
				item.clear();
				return item;
			}
			else {
				slots[drag_prev_slot]->in_focus = false;
				current_slot = NULL;
			}
		}
		if (!item.empty()) {
			if (inpt->pressing[SHIFT] || NO_MOUSE || inpt->touch_locked) {
				item.quantity = 1;
			}
			substract( drag_prev_slot, item.quantity);
		}
		// item will be cleared if item.empty() == true
		return item;
	}
	else {
		item.clear();
		return item;
	}
}
// Crafting helper
bool getCraftingResult(Inventory *inv, ItemStack& result,
		std::vector<ItemStack> &output_replacements,
		bool decrementInput, IGameDef *gamedef)
{
	DSTACK(__FUNCTION_NAME);
	
	result.clear();

	// Get the InventoryList in which we will operate
	InventoryList *clist = inv->getList("craft");
	if(!clist)
		return false;

	// Mangle crafting grid to an another format
	CraftInput ci;
	ci.method = CRAFT_METHOD_NORMAL;
	ci.width = clist->getWidth() ? clist->getWidth() : 3;
	for(u16 i=0; i<clist->getSize(); i++)
		ci.items.push_back(clist->getItem(i));

	// Find out what is crafted and add it to result item slot
	CraftOutput co;
	bool found = gamedef->getCraftDefManager()->getCraftResult(
			ci, co, output_replacements, decrementInput, gamedef);
	if(found)
		result.deSerialize(co.item, gamedef->getItemDefManager());

	if(found && decrementInput)
	{
		// CraftInput has been changed, apply changes in clist
		for(u16 i=0; i<clist->getSize(); i++)
		{
			clist->changeItem(i, ci.items[i]);
		}
	}

	return found;
}
Exemplo n.º 6
0
/**
 * Insert item into first available carried slot, preferably in the optionnal specified slot
 *
 * @param ItemStack Stack of items
 * @param area Area number where it will try to store the item
 * @param slot Slot number where it will try to store the item
 */
bool MenuInventory::add(ItemStack stack, int area, int slot, bool play_sound, bool auto_equip) {
	if (stack.empty())
		return true;

	bool success = true;

	if (play_sound)
		items->playSound(stack.item);

	if (auto_equip && AUTO_EQUIP) {
		int equip_slot = getEquipSlotFromItem(stack.item, true);

		if (equip_slot >= 0 && inventory[EQUIPMENT].slots[equip_slot]->enabled) {
			area = EQUIPMENT;
			slot = equip_slot;
		}
	}

	if (area == CARRIED) {
		ItemStack leftover = inventory[CARRIED].add(stack, slot);
		if (!leftover.empty()) {
			pc->logMsg(msg->get("Inventory is full."), true);
			drop_stack.push(leftover);
			success = false;
		}
	}
	else if (area == EQUIPMENT) {
		ItemStack &dest = inventory[EQUIPMENT].storage[slot];
		ItemStack leftover;
		leftover.item = stack.item;

		if (!dest.empty() && dest.item != stack.item) {
			// items don't match, so just add the stack to the carried area
			leftover.quantity = stack.quantity;
		}
		else if (dest.quantity + stack.quantity > items->items[stack.item].max_quantity) {
			// items match, so attempt to merge the stacks. Any leftover will be added to the carried area
			leftover.quantity = dest.quantity + stack.quantity - items->items[stack.item].max_quantity;
			stack.quantity = items->items[stack.item].max_quantity - dest.quantity;
			if (stack.quantity > 0) {
				add(stack, EQUIPMENT, slot, false, false);
			}
		}
		else {
			// put the item in the appropriate equipment slot
			inventory[EQUIPMENT].add(stack, slot);
			updateEquipment(slot);
			leftover.clear();
		}

		if (!leftover.empty()) {
			add(leftover, CARRIED, -1, false, false);
		}

		applyEquipment();
	}

	// if this item has a power, place it on the action bar if possible
	if (success && items->items[stack.item].type == "consumable" && items->items[stack.item].power > 0) {
		menu_act->addPower(items->items[stack.item].power, 0);
	}

	drag_prev_src = -1;

	return success;
}