Wait about 2s before despawning killed mobs.

This gives them enough time to play their death animations before
they disappear.
This commit is contained in:
dongresource 2020-09-22 00:21:43 +02:00
parent a768a4f539
commit 12fbdc9621
3 changed files with 21 additions and 10 deletions

View File

@ -137,15 +137,28 @@ void MobManager::killMob(CNSocket *sock, Mob *mob) {
giveReward(sock); giveReward(sock);
MissionManager::mobKilled(sock, mob->appearanceData.iNPCType); MissionManager::mobKilled(sock, mob->appearanceData.iNPCType);
INITSTRUCT(sP_FE2CL_NPC_EXIT, pkt); mob->despawned = false;
pkt.iNPC_ID = mob->appearanceData.iNPC_ID;
sock->sendPacket(&pkt, P_FE2CL_NPC_EXIT, sizeof(sP_FE2CL_NPC_EXIT));
PlayerManager::sendToViewable(sock, (void*)&pkt, P_FE2CL_NPC_EXIT, sizeof(sP_FE2CL_NPC_EXIT));
} }
void MobManager::deadStep(Mob *mob, time_t currTime) { void MobManager::deadStep(Mob *mob, time_t currTime) {
auto chunk = ChunkManager::grabChunk(mob->appearanceData.iX, mob->appearanceData.iY);
auto chunks = ChunkManager::grabChunks(chunk);
// despawn the mob after a short delay
if (mob->killedTime != 0 && !mob->despawned && currTime - mob->killedTime > 2000) {
mob->despawned = true;
INITSTRUCT(sP_FE2CL_NPC_EXIT, pkt);
pkt.iNPC_ID = mob->appearanceData.iNPC_ID;
for (Chunk *chunk : chunks) {
for (CNSocket *s : chunk->players) {
s->sendPacket(&pkt, P_FE2CL_NPC_EXIT, sizeof(sP_FE2CL_NPC_EXIT));
}
}
}
if (mob->killedTime != 0 && currTime - mob->killedTime < mob->regenTime * 100) if (mob->killedTime != 0 && currTime - mob->killedTime < mob->regenTime * 100)
return; return;
@ -158,9 +171,6 @@ void MobManager::deadStep(Mob *mob, time_t currTime) {
pkt.NPCAppearanceData = mob->appearanceData; pkt.NPCAppearanceData = mob->appearanceData;
auto chunk = ChunkManager::grabChunk(mob->appearanceData.iX, mob->appearanceData.iY);
auto chunks = ChunkManager::grabChunks(chunk);
// notify all nearby players // notify all nearby players
for (Chunk *chunk : chunks) { for (Chunk *chunk : chunks) {
for (CNSocket *s : chunk->players) { for (CNSocket *s : chunk->players) {

View File

@ -20,6 +20,7 @@ struct Mob : public BaseNPC {
const int maxHealth; const int maxHealth;
time_t killedTime = 0; time_t killedTime = 0;
const int regenTime; const int regenTime;
bool despawned = false; // for the sake of death animations
Mob(int x, int y, int z, int type, int hp, int angle, int rt) Mob(int x, int y, int z, int type, int hp, int angle, int rt)
: BaseNPC(x, y, z, type), maxHealth(hp), regenTime(rt) { : BaseNPC(x, y, z, type), maxHealth(hp), regenTime(rt) {

View File

@ -184,7 +184,7 @@ void NanoManager::addNano(CNSocket* sock, int16_t nanoId, int16_t slot) {
resp.Nano.iStamina = 150; resp.Nano.iStamina = 150;
resp.iQuestItemSlotNum = slot; resp.iQuestItemSlotNum = slot;
resp.iPC_Level = level; resp.iPC_Level = level;
resp.iPC_FusionMatter = plr->fusionmatter; // will decrese in actual nano missions resp.iPC_FusionMatter = plr->fusionmatter; // will decrease in actual nano missions
// Update player // Update player
plr->Nanos[nanoId] = resp.Nano; plr->Nanos[nanoId] = resp.Nano;