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, (it == killers.begin()));
}
}
}
std::map<Creature*, uint64_t> experienceMap;
for(CountMap::iterator it = damageMap.begin(); it != damageMap.end(); ++it){
if(Creature* attacker = g_game.getCreatureByID((*it).first)){
if (attacker != this) {
uint64_t gainExp = getGainedExperience(attacker);
if (Player* player = attacker->getPlayer()) {
Party* party = player->getParty();
if (party && party->getLeader() && party->isSharedExperienceActive() && party->isSharedExperienceEnabled()) {
attacker = party->getLeader();
}
}
std::map<Creature*, uint64_t>::iterator it = experienceMap.find(attacker);
if (it == experienceMap.end()) {
experienceMap[attacker] = gainExp;
} else {
it->second += gainExp;
}
}
}
}
dropCorpse();
die();
bool fromMonster = false;
if (this->getMonster()) {
fromMonster = true;
}
for (std::map<Creature*, uint64_t>::iterator it = experienceMap.begin(); it != experienceMap.end(); it++) {
it->first->onGainExperience(it->second, fromMonster);
}
if(getMaster()){
getMaster()->removeSummon(this);
}
}
void Creature::die()
{
g_game.removeCreature(this, false);
}
void Monster::die()
{
setAttackedCreature(NULL);
destroySummons();
clearTargetList();
clearFriendList();
onIdleStatus();
Creature::die();
}
Item* Monster::createCorpse()
{
Item* corpse = Creature::createCorpse();
return corpse;
}
void Game::checkCreatures()
{
g_scheduler.addEvent(createSchedulerTask(
EVENT_CHECK_CREATURE_INTERVAL, boost::bind(&Game::checkCreatures, this)));
Creature* creature;
std::vector<Creature*>::iterator it;
//add any new creatures
for(it = toAddCheckCreatureVector.begin(); it != toAddCheckCreatureVector.end(); ++it){
creature = (*it);
checkCreatureVectors[creature->checkCreatureVectorIndex].push_back(creature);
}
toAddCheckCreatureVector.clear();
checkCreatureLastIndex++;
if(checkCreatureLastIndex == EVENT_CREATURECOUNT){
checkCreatureLastIndex = 0;
}
std::vector<Creature*>& checkCreatureVector = checkCreatureVectors[checkCreatureLastIndex];
for(it = checkCreatureVector.begin(); it != checkCreatureVector.end();){
creature = (*it);
if(creature->creatureCheck){
if(creature->getHealth() > 0){
creature->onThink(EVENT_CREATURE_THINK_INTERVAL);
}
else{
creature->onDie();
}
++it;
}
else{
creature->checkCreatureVectorIndex = -1;
it = checkCreatureVector.erase(it);
FreeThing(creature);
}
}
cleanup();
}
Well it depends on what you want to achieve. Do you want the monsters to die and become corpses instantly or do you just want them to drop at the same time? Because the latter is probably not so tricky, to make newly created monsters fit the onThink interval simultaneously with current, alive, creatures.So it should not be a problem with setting #define EVENT_CREATURE_THINK_INTERVAL to 500 right ?. I checked some distros and some of them had 500 too.
Yea i dont care about dropping the corpse at the same time. I just wanted to lower the interval from die() to dropCorpse() and i achieved that. Thanks for your helpWell it depends on what you want to achieve. Do you want the monsters to die and become corpses instantly or do you just want them to drop at the same time? Because the latter is probably not so tricky, to make newly created monsters fit the onThink interval simultaneously with current, alive, creatures.
As the code is created now, we need to constantly check the creatures being "alive" and that is what the checkCreatures function does. However, I don't think it's impossible to make it so you check creature health (if creature should be alive or not) when damage has ben dealt to it, which means you can make the corpse drop in an instance.
But to me it seems like a lot of work for basically nothing more than aesthetics
This is due to addevent being called in a loop. I have no idea why the hell it need addevent as checkCreatures
onDie
in drainHealth / changeHealth Creature methods when new health < 1. But AFAIK creatures, sometimes, lagged to drop corpse in old times, not sure about now.I need the delay as my server is 7.6. But I need the monsters to die together, not one by one. I tried c++ 1 second "sleep function" but doesnt workYou could probably just callonDie
in drainHealth / changeHealth Creature methods when new health < 1. But AFAIK creatures, sometimes, lagged to drop corpse in old times, not sure about now.