示例#1
0
文件: player.cpp 项目: vidarn/mgrl
void
Player::doDrop()
{
    bool dropped = false;
    std::vector<ListDefinition>itemList;
    for(unsigned int i=0; i<m_inventory.size(); i++) {
        Actor *actor = m_inventory[i];
        if(!actor->hasTag(ITEM_DONT_DROP)) {
            std::string st = actor->m_name;
            itemList.push_back(ListDefinition(LIST_ENTRY, actor->m_letter, st));
        }
    }
    ListOverlay itemOverlay(30, 30, "Drop what?", true, true, itemList);
    itemOverlay.main(m_level);
    for(unsigned int i=0; i<itemOverlay.m_definition.size(); i++) {
        ListDefinition &def = itemOverlay.m_definition[i];
        if(def.m_selected) {
            Actor *item = getFromInventory(def.m_key);
            if(item != 0) {
                std::string msg = "You drop the ";
                msg += item->m_name;
                m_level->m_messages->showMessage(msg,MESSAGE_NOTIFICATION);
                item->m_x = m_x;
                item->m_y = m_y;
                m_level->m_actors.push_back(item);
                removeFromInventory(item);
                dropped = true;
            }
        }
    }
    if(dropped)
        act();
}
示例#2
0
void CPetControl::onSummonBot(const CString &name, int val) {
	CGameObject *bot = findBot(name, getHiddenRoom());
	if (!bot) {
		bot = findBot(name, getRoot());
	}

	if (bot) {
		removeFromInventory(bot, false, false);

		COnSummonBotMsg summonMsg(val);
		summonMsg.execute(bot);
	}
}
示例#3
0
文件: player.cpp 项目: vidarn/mgrl
void
Player::doQuaff()
{
    act();
    std::vector<ListDefinition>itemList;
    for(unsigned int i=0; i<m_inventory.size(); i++) {
        Actor *actor = m_inventory[i];
        if(actor->hasTag(ITEM_QUAFF)) {
            std::string st = actor->m_name;
            itemList.push_back(ListDefinition(LIST_ENTRY, actor->m_letter, st));
        }
    }
    ListOverlay itemOverlay(30, 30, "Drink what?", false, true, itemList);
    itemOverlay.main(m_level);
    for(unsigned int i=0; i<itemOverlay.m_definition.size(); i++) {
        ListDefinition &def = itemOverlay.m_definition[i];
        if(def.m_selected) {
            Actor *item = getFromInventory(def.m_key);
            if(item != 0) {
                std::string msg = "You drink the ";
                msg += item->m_name;
                m_level->m_messages->showMessage(msg,MESSAGE_NOTIFICATION);
                item->quaff(this);
                item->m_amount--;
                if(item->m_amount <= 0) {
                    removeFromInventory(item);
                    if(item->hasTag(POTION_SACRED_NECTAR)) {
                        for(unsigned int i=0; i<m_abilities.size(); i++) {
                            Ability *ab = m_abilities[i];
                            if(ab->m_id == AB_SACRED_NECTAR && ab->m_active) {
                                AbSacredNectar *bt = static_cast<AbSacredNectar *>(ab);
                                if(bt->m_nectar == item) {
                                    invokeAbility(i);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
示例#4
0
void CPetControl::removeFromInventory(CGameObject *item, bool refreshUI, bool sendMsg) {
	CViewItem *view = getGameManager()->getView();
	removeFromInventory(item, view, refreshUI, sendMsg);
}
示例#5
0
文件: player.cpp 项目: vidarn/mgrl
void
Player::doFire()
{
    if(m_quiver == -1) {
        m_level->m_messages->showMessage("You have nothing quivered", MESSAGE_NOTIFICATION);
        return;
    }
    bool ok = false;
    if(m_weapon != -1) {
        if(m_inventory[m_weapon]->hasTag(ITEM_RANGED)) {
            if(m_quiver != -1 && m_inventory[m_quiver]->hasTag(ITEM_AMMO_BOW)) {
                ok = true;
            }
        }
    }
    if(ok) {
        Actor *target = getTarget(TARGET_HOSTILE);
        if(target != 0) {
            double breakProbability[] = {0.3, 0.7};
            boost::random::discrete_distribution<> breakDist(breakProbability);
            if(true) {
                bool done = false;
                std::vector<int> tags;
                tags.push_back(ITEM_STACK);
                std::vector<Actor *> onGround= m_level->getActors(target->m_x,target->m_y,tags);
                for(unsigned int i=0; i<onGround.size(); i++) {
                    Actor *a = onGround[i];
                    if(a->m_name == m_inventory[m_quiver]->m_name) {
                        a->m_amount++;
                        done = true;
                    }
                }
                if(!done) {
                    Actor *shot;
                    shot = new Actor;
                    *shot = *(m_inventory[m_quiver]);
                    shot->m_amount = 1;
                    shot->m_x = target->m_x;
                    shot->m_y = target->m_y;
                    m_level->m_actors.push_back(shot);
                }
            }

            attack(target,ATTACK_RANGED);
            act();

            m_inventory[m_quiver]->m_amount--;
            if(m_inventory[m_quiver]->m_amount <=0) {
                m_quiver = -1;
                Actor *tmp = m_inventory[m_quiver];
                removeFromInventory(tmp);
            }
        }
        else
        {
            m_level->m_messages->showMessage("You change your mind", MESSAGE_FLAVOUR);
        }
    }
    else {
        std::string msg = "You cannot fire ";
        msg += m_inventory[m_quiver]->m_name;
        msg += " with your ";
        if(m_weapon != -1) {
            msg += m_inventory[m_weapon]->m_name;
        }
        else {
            msg += "bare hands";
        }
        m_level->m_messages->showMessage(msg, MESSAGE_NOTIFICATION);
    }
}
示例#6
0
文件: inventory.cpp 项目: ufoai/ufoai
/**
 * @brief Conditions for moving items between containers.
 * @param[in] inv The inventory to move in.
 * @param[in] from Source container.
 * @param[in] fItem The item to be moved.
 * @param[in] to Destination container.
 * @param[in] tx X coordinate in destination container.
 * @param[in] ty Y coordinate in destination container.
 * @param[in,out] TU pointer to entity available TU at this moment
 * or @c nullptr if TU doesn't matter (outside battlescape)
 * @param[out] uponItem The item fItem is evetually dropped upon
 * @return IA_NOTIME when not enough TU.
 * @return IA_NONE if no action possible.
 * @return IA_NORELOAD if you cannot reload a weapon.
 * @return IA_RELOAD_SWAP in case of exchange of ammo in a weapon.
 * @return IA_RELOAD when reloading.
 * @return IA_ARMOUR when placing an armour on the actor.
 * @return IA_MOVE when just moving an item.
 */
inventory_action_t InventoryInterface::moveInInventory (Inventory* const inv, const invDef_t* from, Item* fItem, const invDef_t* to, int tx, int ty, int* TU, Item**  uponItem)
{
	assert(to);
	assert(from);

	if (uponItem)
		*uponItem = nullptr;

	if (from == to && fItem->getX() == tx && fItem->getY() == ty)
		return IA_NONE;

	int time = from->out + to->in;
	if (from == to) {
		if (from->isFloorDef())
			time = 0;
		else
			time /= 2;
	}

	if (TU && *TU < time)
		return IA_NOTIME;

	assert(inv);

	int checkedTo = INV_DOES_NOT_FIT;
	/* Special case for moving an item within the same container. */
	if (from == to) {
		/* Do nothing if we move inside a scroll container. */
		if (from->scroll)
			return IA_NONE;

		const Container& cont = inv->getContainer(from->id);
		Item* item = nullptr;
		while ((item = cont.getNextItem(item))) {
			if (item != fItem)
				continue;

			if (item->getAmount() <= 1)
				continue;
			checkedTo = inv->canHoldItem(to, item->def(), tx, ty, fItem);
			if (!(checkedTo & INV_FITS))
				return IA_NONE;

			item->setX(tx);
			item->setY(ty);
			if (uponItem)
				*uponItem = item;
			return IA_MOVE;
		}
	}

	/* If weapon is twohanded and is moved from hand to hand do nothing. */
	/* Twohanded weapon are only in CID_RIGHT. */
	if (fItem->def()->fireTwoHanded && to->isLeftDef() && from->isRightDef()) {
		return IA_NONE;
	}

	/* If non-armour moved to an armour slot then abort.
	 * Same for non extension items when moved to an extension slot. */
	if ((to->armour && !fItem->isArmour())
	 || (to->implant && !fItem->def()->implant)
	 || (to->headgear && !fItem->def()->headgear)) {
		return IA_NONE;
	}

	/* Check if the target is a blocked inv-armour and source!=dest. */
	if (to->single)
		checkedTo = inv->canHoldItem(to, fItem->def(), 0, 0, fItem);
	else {
		if (tx == NONE || ty == NONE)
			inv->findSpace(to, fItem, &tx, &ty, fItem);
		/* still no valid location found */
		if (tx == NONE || ty == NONE)
			return IA_NONE;

		checkedTo = inv->canHoldItem(to, fItem->def(), tx, ty, fItem);
	}

	Item* ic;
	bool alreadyRemovedSource = false;
	if (to->armour && from != to && !checkedTo) {
		/* Store x/y origin coordinates of removed (source) item.
		 * When we re-add it we can use this. */
		const int cacheFromX = fItem->getX();
		const int cacheFromY = fItem->getY();

		/* Check if destination/blocking item is the same as source/from item.
		 * In that case the move is not needed -> abort. */
		Item* icTo = inv->getItemAtPos(to, tx, ty);
		if (fItem->def() == icTo->def())
			return IA_NONE;

		/* Actually remove the ammo from the 'from' container. */
		if (!removeFromInventory(inv, from, fItem))
			return IA_NONE;
		else
			/* Removal successful - store this info. */
			alreadyRemovedSource = true;

		Item cacheItem2 = this->cacheItem; /* Save/cache (source) item. The cacheItem is modified in MoveInInventory. */

		/* Move the destination item to the source. */
		moveInInventory(inv, to, icTo, from, cacheFromX, cacheFromY, TU, uponItem);

		/* Reset the cached item (source) (It'll be move to container emptied by destination item later.) */
		this->cacheItem = cacheItem2;
		checkedTo = inv->canHoldItem(to, this->cacheItem.def(), 0, 0, fItem);
	} else if (!checkedTo) {
		/* Get the target-invlist (e.g. a weapon). We don't need to check for
		 * scroll because checkedTo is always true here. */
		ic = inv->getItemAtPos(to, tx, ty);

		if (ic && !to->isEquipDef() && fItem->def()->isLoadableInWeapon(ic->def())) {
			/* A target-item was found and the dragged item (implicitly ammo)
			 * can be loaded in it (implicitly weapon). */
			if (ic->getAmmoLeft() >= ic->def()->ammo && ic->ammoDef() == fItem->def()) {
				/* Weapon already fully loaded with the same ammunition -> abort */
				return IA_NORELOAD;
			}
			time += ic->def()->getReloadTime();
			if (!TU || *TU >= time) {
				if (TU)
					*TU -= time;
				if (ic->getAmmoLeft() >= ic->def()->ammo) {
					/* exchange ammo */
					const Item item(ic->ammoDef());
					/* Put current ammo in place of the new ammo unless floor - there can be more than 1 item */
					const int cacheFromX = from->isFloorDef() ? NONE : fItem->getX();
					const int cacheFromY = from->isFloorDef() ? NONE : fItem->getY();

					/* Actually remove the ammo from the 'from' container. */
					if (!removeFromInventory(inv, from, fItem))
						return IA_NONE;

					/* Add the currently used ammo in place of the new ammo in the "from" container. */
					if (addToInventory(inv, &item, from, cacheFromX, cacheFromY, 1) == nullptr)
						Sys_Error("Could not reload the weapon - add to inventory failed (%s)", invName);

					ic->setAmmoDef(this->cacheItem.def());
					if (uponItem)
						*uponItem = ic;
					return IA_RELOAD_SWAP;
				} else {
					/* Actually remove the ammo from the 'from' container. */
					if (!removeFromInventory(inv, from, fItem))
						return IA_NONE;

					ic->setAmmoDef(this->cacheItem.def());
					/* loose ammo of type ic->m saved on server side */
					ic->setAmmoLeft(ic->def()->ammo);
					if (uponItem)
						*uponItem = ic;
					return IA_RELOAD;
				}
			}
			/* Not enough time -> abort. */
			return IA_NOTIME;
		}

		/* temp container like CID_EQUIP and CID_FLOOR */
		if (ic && to->temp) {
			/* We are moving to a blocked location container but it's the base-equipment floor or a battlescape floor.
			 * We add the item anyway but it'll not be displayed (yet)
			 * This is then used in addToInventory below.*/
			/** @todo change the other code to browse through these things. */
			inv->findSpace(to, fItem, &tx, &ty, fItem);
			if (tx == NONE || ty == NONE) {
				Com_DPrintf(DEBUG_SHARED, "MoveInInventory - item will be added non-visible (%s)\n", invName);
			}
		} else {
			/* Impossible move -> abort. */
			return IA_NONE;
		}
	}

	/* twohanded exception - only CID_RIGHT is allowed for fireTwoHanded weapons */
	if (fItem->def()->fireTwoHanded && to->isLeftDef())
		to = &this->csi->ids[CID_RIGHT];

	switch (checkedTo) {
	case INV_DOES_NOT_FIT:
		/* Impossible move - should be handled above, but add an abort just in case */
		Com_Printf("MoveInInventory: Item doesn't fit into container.");
		return IA_NONE;
	case INV_FITS:
		/* Remove rotated tag */
		fItem->rotated = false;
		break;
	case INV_FITS_ONLY_ROTATED:
		/* Set rotated tag */
		fItem->rotated = true;
		break;
	case INV_FITS_BOTH:
		/* Leave rotated tag as-is */
		break;
	}

	/* Actually remove the item from the 'from' container (if it wasn't already removed). */
	if (!alreadyRemovedSource)
		if (!removeFromInventory(inv, from, fItem))
			return IA_NONE;

	/* successful */
	if (TU)
		*TU -= time;

	assert(this->cacheItem.def());
	ic = addToInventory(inv, &this->cacheItem, to, tx, ty, 1);

	/* return data */
	if (uponItem) {
		assert(ic);
		*uponItem = ic;
	}

	if (to->isArmourDef()) {
		assert(this->cacheItem.isArmour());
		return IA_ARMOUR;
	}

	return IA_MOVE;
}