Пример #1
0
void MonsterType::createLoot(Container* corpse)
{
	if (g_config.getNumber(ConfigManager::RATE_LOOT) == 0) {
		corpse->startDecaying();
		return;
	}

	Player* owner = g_game.getPlayerByID(corpse->getCorpseOwner());
	if (!owner || owner->getStaminaMinutes() > 840) {
		for (auto it = info.lootItems.rbegin(), end = info.lootItems.rend(); it != end; ++it) {
			auto itemList = createLootItem(*it);
			if (itemList.empty()) {
				continue;
			}

			for (Item* item : itemList) {
				//check containers
				if (Container* container = item->getContainer()) {
					if (!createLootContainer(container, *it)) {
						delete container;
						continue;
					}
				}

				if (g_game.internalAddItem(corpse, item) != RETURNVALUE_NOERROR) {
					corpse->internalAddThing(item);
				}
			}
		}

		if (owner) {
			std::ostringstream ss;
			ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription();

			if (owner->getParty()) {
				owner->getParty()->broadcastPartyLoot(ss.str());
			} else {
				owner->sendTextMessage(MESSAGE_LOOT, ss.str());
			}
		}
	} else {
		std::ostringstream ss;
		ss << "Loot of " << nameDescription << ": nothing (due to low stamina)";

		if (owner->getParty()) {
			owner->getParty()->broadcastPartyLoot(ss.str());
		} else {
			owner->sendTextMessage(MESSAGE_LOOT, ss.str());
		}
	}

	corpse->startDecaying();
}
Пример #2
0
void MonsterType::createLoot(Container* corpse)
{
	Player* owner = g_game.getPlayerByID(corpse->getCorpseOwner());
	if (!owner || owner->getStaminaMinutes() > 840) {
		for (auto it = lootItems.rbegin(), end = lootItems.rend(); it != end; ++it) {
			std::list<Item*> itemList = createLootItem(*it);
			if (itemList.empty()) {
				continue;
			}

			for (Item* item : itemList) {
				//check containers
				if (Container* container = item->getContainer()) {
					if (!createLootContainer(container, *it)) {
						delete container;
					} else if (g_game.internalAddItem(corpse, item) != RET_NOERROR) {
						corpse->__internalAddThing(item);
					}
				} else if (g_game.internalAddItem(corpse, item) != RET_NOERROR) {
					corpse->__internalAddThing(item);
				}
			}
		}

		if (owner) {
			std::ostringstream ss;
			ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription();

			if (owner->getParty()) {
				owner->getParty()->broadcastPartyLoot(ss.str());
			} else {
				owner->sendTextMessage(MSG_INFO_DESCR, ss.str());
			}
		}
	} else {
		std::ostringstream ss;
		ss << "Loot of " << nameDescription << ": nothing (due to low stamina)";

		if (owner->getParty()) {
			owner->getParty()->broadcastPartyLoot(ss.str());
		} else {
			owner->sendTextMessage(MSG_INFO_DESCR, ss.str());
		}
	}

	corpse->__startDecaying();
}
Пример #3
0
void InternalCreatureType::createLoot(Container* corpse)
{
    for(LootItems::const_iterator it = lootItems.begin(); it != lootItems.end() && (corpse->capacity() - corpse->size() > 0); it++) {
        Item* tmpItem = createLootItem(*it);
        if(tmpItem) {
            //check containers
            if(Container* container = tmpItem->getContainer()) {
                createLootContainer(container, *it);
                if(container->size() == 0) {
                    delete container;
                }
                else {
                    corpse->__internalAddThing(tmpItem);
                }
            }
            else {
                corpse->__internalAddThing(tmpItem);
            }
        }
    }
}
Пример #4
0
bool MonsterType::createLootContainer(Container* parent, const LootBlock& lootblock)
{
	auto it = lootblock.childLoot.begin(), end = lootblock.childLoot.end();
	if (it == end) {
		return true;
	}

	for (; it != end && parent->size() < parent->capacity(); ++it) {
		auto itemList = createLootItem(*it);
		for (Item* tmpItem : itemList) {
			if (Container* container = tmpItem->getContainer()) {
				if (!createLootContainer(container, *it)) {
					delete container;
				} else {
					parent->internalAddThing(container);
				}
			} else {
				parent->internalAddThing(tmpItem);
			}
		}
	}
	return !parent->empty();
}
Пример #5
0
void InternalCreatureType::createLootContainer(Container* parent, const LootBlock& lootblock)
{
    if(parent->size() < parent->capacity()) {
        LootItems::const_iterator it;
        for(it = lootblock.childLoot.begin(); it != lootblock.childLoot.end(); it++) {
            Item* tmpItem = createLootItem(*it);
            if(tmpItem) {
                if(Container* container = tmpItem->getContainer()) {
                    createLootContainer(container, *it);
                    if(container->size() == 0 && it->dropEmpty == false) {
                        delete container;
                    }
                    else {
                        parent->__internalAddThing(container);
                    }
                }
                else {
                    parent->__internalAddThing(tmpItem);
                }
            }
        }
    }
}