Fix potential crash in Sacrifice

This commit is contained in:
Michael Cook (mackal) 2016-08-13 15:35:28 -04:00
parent 00cfe2d25f
commit ef3cf099b8

View File

@ -3683,58 +3683,58 @@ void Client::SacrificeConfirm(Client *caster)
//Essentially a special case death function //Essentially a special case death function
void Client::Sacrifice(Client *caster) void Client::Sacrifice(Client *caster)
{ {
if(GetLevel() >= RuleI(Spells, SacrificeMinLevel) && GetLevel() <= RuleI(Spells, SacrificeMaxLevel)){ if (GetLevel() >= RuleI(Spells, SacrificeMinLevel) && GetLevel() <= RuleI(Spells, SacrificeMaxLevel)) {
int exploss = (int)(GetLevel() * (GetLevel() / 18.0) * 12000); int exploss = (int)(GetLevel() * (GetLevel() / 18.0) * 12000);
if(exploss < GetEXP()){ if (exploss < GetEXP()) {
SetEXP(GetEXP()-exploss, GetAAXP()); SetEXP(GetEXP() - exploss, GetAAXP());
SendLogoutPackets(); SendLogoutPackets();
//make our become corpse packet, and queue to ourself before OP_Death. // make our become corpse packet, and queue to ourself before OP_Death.
EQApplicationPacket app2(OP_BecomeCorpse, sizeof(BecomeCorpse_Struct)); EQApplicationPacket app2(OP_BecomeCorpse, sizeof(BecomeCorpse_Struct));
BecomeCorpse_Struct* bc = (BecomeCorpse_Struct*)app2.pBuffer; BecomeCorpse_Struct *bc = (BecomeCorpse_Struct *)app2.pBuffer;
bc->spawn_id = GetID(); bc->spawn_id = GetID();
bc->x = GetX(); bc->x = GetX();
bc->y = GetY(); bc->y = GetY();
bc->z = GetZ(); bc->z = GetZ();
QueuePacket(&app2); QueuePacket(&app2);
// make death packet // make death packet
EQApplicationPacket app(OP_Death, sizeof(Death_Struct)); EQApplicationPacket app(OP_Death, sizeof(Death_Struct));
Death_Struct* d = (Death_Struct*)app.pBuffer; Death_Struct *d = (Death_Struct *)app.pBuffer;
d->spawn_id = GetID(); d->spawn_id = GetID();
d->killer_id = caster ? caster->GetID() : 0; d->killer_id = caster ? caster->GetID() : 0;
d->bindzoneid = GetPP().binds[0].zoneId; d->bindzoneid = GetPP().binds[0].zoneId;
d->spell_id = SPELL_UNKNOWN; d->spell_id = SPELL_UNKNOWN;
d->attack_skill = 0xe7; d->attack_skill = 0xe7;
d->damage = 0; d->damage = 0;
app.priority = 6; app.priority = 6;
entity_list.QueueClients(this, &app); entity_list.QueueClients(this, &app);
BuffFadeAll(); BuffFadeAll();
UnmemSpellAll(); UnmemSpellAll();
Group *g = GetGroup(); Group *g = GetGroup();
if(g){ if (g) {
g->MemberZoned(this); g->MemberZoned(this);
} }
Raid *r = entity_list.GetRaidByClient(this); Raid *r = entity_list.GetRaidByClient(this);
if(r){ if (r) {
r->MemberZoned(this); r->MemberZoned(this);
} }
ClearAllProximities(); ClearAllProximities();
if(RuleB(Character, LeaveCorpses)){ if (RuleB(Character, LeaveCorpses)) {
auto new_corpse = new Corpse(this, 0); auto new_corpse = new Corpse(this, 0);
entity_list.AddCorpse(new_corpse, GetID()); entity_list.AddCorpse(new_corpse, GetID());
SetID(0); SetID(0);
entity_list.QueueClients(this, &app2, true); entity_list.QueueClients(this, &app2, true);
} }
Save(); Save();
GoToDeath(); GoToDeath();
caster->SummonItem(RuleI(Spells, SacrificeItemID)); if (caster) // I guess it's possible?
} caster->SummonItem(RuleI(Spells, SacrificeItemID));
} }
else{ } else {
caster->Message_StringID(13, SAC_TOO_LOW); //This being is not a worthy sacrifice. caster->Message_StringID(13, SAC_TOO_LOW); // This being is not a worthy sacrifice.
} }
} }
void Client::SendOPTranslocateConfirm(Mob *Caster, uint16 SpellID) { void Client::SendOPTranslocateConfirm(Mob *Caster, uint16 SpellID) {