Пример #1
0
void Creature::onDie()
{
	DeathList killers = getKillers(g_config.getNumber(ConfigManager::DEATH_ASSIST_COUNT));

	for(DeathList::const_iterator it = killers.begin(); it != killers.end(); ++it){
		if(it->isCreatureKill()){
			Creature* attacker = it->getKillerCreature();
			if(attacker){
				attacker->onKilledCreature(this);
			}
		}
	}

	for(CountMap::iterator it = damageMap.begin(); it != damageMap.end(); ++it){
		if(Creature* attacker = g_game.getCreatureByID((*it).first)){
			attacker->onAttackedCreatureKilled(this);
		}
	}

	Item* corpse = dropCorpse();
	die();

	g_game.onCreatureDeath(this, corpse, (killers.front().isCreatureKill()? killers.front().getKillerCreature() : NULL));

	if(corpse){
		Player* killer = g_game.getPlayerByID(corpse->getCorpseOwner());
		if(killer){
			killer->broadcastLoot(this, corpse->getContainer());
		}
	}

	if(getMaster()){
		getMaster()->removeSummon(this);
	}
}
Пример #2
0
Item* Monster::getCorpse()
{
	Item* corpse = Creature::getCorpse();
	if(corpse)
	{
		Creature* lastHitCreature_ = NULL;
		Creature* mostDamageCreature = NULL;
		if(getKillers(&lastHitCreature_, &mostDamageCreature) && mostDamageCreature)
		{
			uint32_t corpseOwner = 0;
			if(mostDamageCreature->getPlayer())
				corpseOwner = mostDamageCreature->getID();
			else
			{
				const Creature* mostDamageCreatureMaster = mostDamageCreature->getMaster();
				if(mostDamageCreatureMaster && mostDamageCreatureMaster->getPlayer())
					corpseOwner = mostDamageCreatureMaster->getID();
			}

			if(corpseOwner != 0)
				corpse->setCorpseOwner(corpseOwner);
		}
	}
	return corpse;
}
Пример #3
0
void Creature::onDeath()
{
	Creature* mostDamageCreatureMaster = NULL;
	Creature* lastHitCreatureMaster = NULL;

	if (getKillers(&_lastHitCreature, &_mostDamageCreature)) {
		if (_lastHitCreature) {
			lastHitUnjustified = _lastHitCreature->onKilledCreature(this);
			lastHitCreatureMaster = _lastHitCreature->getMaster();
		}

		if (_mostDamageCreature) {
			mostDamageCreatureMaster = _mostDamageCreature->getMaster();
			bool isNotLastHitMaster = (_mostDamageCreature != lastHitCreatureMaster);
			bool isNotMostDamageMaster = (_lastHitCreature != mostDamageCreatureMaster);
			bool isNotSameMaster = lastHitCreatureMaster == NULL || (mostDamageCreatureMaster != lastHitCreatureMaster);

			if (_mostDamageCreature != _lastHitCreature && isNotLastHitMaster && isNotMostDamageMaster && isNotSameMaster) {
				mostDamageUnjustified = _mostDamageCreature->onKilledCreature(this, false);
			}
		}
	}

	for (CountMap::iterator it = damageMap.begin(), end = damageMap.end(); it != end; ++it) {
		if (Creature* attacker = g_game.getCreatureByID(it->first)) {
			attacker->onAttackedCreatureKilled(this);
		}
	}

	bool droppedCorpse = dropCorpse();
	death();

	if (getMaster()) {
		getMaster()->removeSummon(this);
	}

	if (droppedCorpse) {
		g_game.removeCreature(this, false);
	}
}
Пример #4
0
Item* Actor::createCorpse()
{
  Item* corpse = Creature::createCorpse();
  if(corpse){
    DeathList killers = getKillers();
    if(!killers.empty() && (*killers.rbegin()).isCreatureKill() ){
      Creature* mostDamageCreature = (*killers.rbegin()).getKillerCreature();
      
      Player* corpseOwner = NULL;
      if(mostDamageCreature->getPlayer()){
        corpseOwner = mostDamageCreature->getPlayer();
      }
      else if(mostDamageCreature->isPlayerSummon()){
        corpseOwner = mostDamageCreature->getPlayerMaster();
      }

      if(corpseOwner != NULL){
        corpse->setCorpseOwner(corpseOwner->getID());
      }
    }
  }

  return corpse;
}
Пример #5
0
bool Creature::onDeath()
{
	DeathList deathList = getKillers();
	bool deny = false;

	CreatureEventList prepareDeathEvents = getCreatureEvents(CREATURE_EVENT_PREPAREDEATH);
	for(CreatureEventList::iterator it = prepareDeathEvents.begin(); it != prepareDeathEvents.end(); ++it)
	{
		if(!(*it)->executePrepareDeath(this, deathList) && !deny)
			deny = true;
	}

	if(deny)
		return false;

	int32_t i = 0, size = deathList.size(), limit = g_config.getNumber(ConfigManager::DEATH_ASSISTS) + 1;
	if(limit > 0 && size > limit)
		size = limit;

	Creature* tmp = NULL;
	CreatureVector justifyVec;
	for(DeathList::iterator it = deathList.begin(); it != deathList.end(); ++it, ++i)
	{
		if(it->isNameKill())
			continue;

		if(it == deathList.begin())
			it->setLast();

		if(i < size)
		{
			if(it->getKillerCreature()->getPlayer())
				tmp = it->getKillerCreature();
			else if(it->getKillerCreature()->getPlayerMaster())
				tmp = it->getKillerCreature()->getMaster();
		}

		if(tmp)
		{
			if(std::find(justifyVec.begin(), justifyVec.end(), tmp) == justifyVec.end())
			{
				it->setJustify();
				justifyVec.push_back(tmp);
			}

			tmp = NULL;
		}

		if(!it->getKillerCreature()->onKilledCreature(this, (*it)) && it->isLast())
			return false;
	}

	for(CountMap::iterator it = damageMap.begin(); it != damageMap.end(); ++it)
	{
		if((tmp = g_game.getCreatureByID(it->first)))
			tmp->onTargetKilled(this);
	}

	dropCorpse(deathList);
	if(master)
		master->removeSummon(this);

	return true;
}