|
|
 |
 |
 |
 |
|
 |
 |
|
 |
 |
|
 |
|
Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum) |
 |
|
 |

08-12-2008, 02:28 AM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Empty Corpse Decay Timer with Rule
This code still needs most of the important code to be written, but I don't think it will be anything too complex to finish. The Required SQL and Rule is easy enough to set, and are posted below. But, the actual part where the NPC dies and checks if the corpse is empty or not is not yet done. I am pretty sure that it needs to be added to the section of the PlayerCorpse.cpp posted below.
Required SQL:
Code:
Insert into rule_values values (0, 'npc:EmptyCorpseDecayTime', -1);
\common\ruletypes.h:
Code:
RULE_INT ( NPC, EmptyCorpseDecayTime, -1 ) //Sets the Decay Time for Empty NPC Corpses in Seconds. Default value: -1 (feature disabled)
----Below is where the work needs to be done to get this code finished----
And, something like this from a quest script I made:
Code:
if ($corpse_id->IsEmpty()) {
my $corpse_decay = $corpse_id->CastToCorpse();
$corpse_decay->SetDecayTimer(5000); }
Needs to be added as a rule into the PlayerCorpse.cpp in this section:
PlayerCorpse.cpp:
Code:
// To be used on NPC death and ZoneStateLoad
// Mongrel: added see_invis and see_invis_undead
Corpse::Corpse(NPC* in_npc, ItemList* in_itemlist, int32 in_npctypeid, const NPCType** in_npctypedata, int32 in_decaytime)
// vesuvias - appearence fix
: Mob("Unnamed_Corpse","",0,0,in_npc->GetGender(),in_npc->GetRace(),in_npc->GetClass(),BT_Humanoid//bodytype added
,in_npc->GetDeity(),in_npc->GetLevel(),in_npc->GetNPCTypeID(),in_npc->GetSize(),0,
in_npc->GetHeading(),in_npc->GetX(),in_npc->GetY(),in_npc->GetZ(),0,
in_npc->GetTexture(),in_npc->GetHelmTexture(),
0,0,0,0,0,0,0,0,0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0,0,0,0,0,0,0),
corpse_decay_timer(in_decaytime),
corpse_delay_timer(in_decaytime/2),
corpse_graveyard_timer(0)
{
corpse_graveyard_timer.Disable();
memset(item_tint, 0, sizeof(item_tint));
pIsChanged = false;
p_PlayerCorpse = false;
pLocked = false;
BeingLootedBy = 0xFFFFFFFF;
if (in_itemlist) {
itemlist = *in_itemlist;
in_itemlist->clear();
}
SetCash(in_npc->GetCopper(), in_npc->GetSilver(), in_npc->GetGold(), in_npc->GetPlatinum());
npctype_id = in_npctypeid;
SetPKItem(0);
charid = 0;
dbid = 0;
p_depop = false;
strcpy(orgname, in_npc->GetName());
strcpy(name, in_npc->GetName());
// Added By Hogie
for(int count = 0; count < 100; count++) {
if ((level >= npcCorpseDecayTimes[count].minlvl) && (level <= npcCorpseDecayTimes[count].maxlvl)) {
corpse_decay_timer.SetTimer(npcCorpseDecayTimes[count].seconds*1000);
break;
}
}
// Added By Hogie -- End
for (int i=0; i<MAX_LOOTERS; i++)
looters[i] = 0;
this->rezzexp = 0;
}
So, basically it should be:
NPC Dies
If Rule EmptyCorpseDecayTime >= 0
If Corpse is empty
Set the decay timer in seconds to the integer that the rule is set to
Continue other steps in the NPC death process
My coding skills are still very weak, so the only way I can get this completed is with help or by searching the source for similar examples of what I want to do. What I have done so far is barely anything, but I don't think the rest would be too bad if I only knew code lol. I will definitely continue to work on getting this done, but if anyone else has any input, it would be greatly appreciated 
Last edited by trevius; 08-12-2008 at 10:32 AM..
|
 |
|
 |

08-12-2008, 04:38 AM
|
Administrator
|
|
Join Date: Sep 2006
Posts: 1,348
|
|
I was actually considering putting something similar in my next patch based on several suggestions here(So no one accuse me of stealing the idea!).
|
 |
|
 |

08-12-2008, 05:08 AM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
HAHA! Well, if you can get this feature coded and added in, I will stop working on it right now lol. Saves me a ton of work trying to figure out how to code by reading source examples :P
Just for reference, in case it may be useful, here are the code snippets of anything I thought might help me figure out how to add this in.
entity.cpp
Code:
void EntityList::AddCorpse(Corpse* corpse, int32 in_id) {
if (corpse == 0)
return;
if (in_id == 0xFFFFFFFF)
corpse->SetID(GetFreeID());
else
corpse->SetID(in_id);
corpse->CalcCorpseName();
corpse_list.Insert(corpse);
if(!net.corpse_timer.Enabled())
net.corpse_timer.Start();
}
attack.cpp
Code:
if (!HasOwner() && class_ != MERCHANT && class_ != ADVENTUREMERCHANT
&& MerchantType == 0 && killer && (killer->IsClient() || (killer->HasOwner() && killer->GetOwner()->IsClient()) ||
(killer->IsNPC() && killer->CastToNPC()->GetSwarmInfo() && killer->CastToNPC()->GetSwarmInfo()->owner && killer->CastToNPC()->GetSwarmInfo()->owner->IsClient()))) {
Corpse* corpse = new Corpse(this, &itemlist, GetNPCTypeID(), &NPCTypedata,level>54?RuleI(NPC,MajorNPCCorpseDecayTimeMS):RuleI(NPC,MinorNPCCorpseDecayTimeMS));
entity_list.LimitRemoveNPC(this);
entity_list.AddCorpse(corpse, this->GetID());
this->SetID(0);
if(killer->GetOwner() != 0 && killer->GetOwner()->IsClient())
killer = killer->GetOwner();
if(killer != 0 && killer->IsClient()) {
corpse->AllowMobLoot(killer, 0);
if(killer->IsGrouped()) {
Group* group = entity_list.GetGroupByClient(killer->CastToClient());
if(group != 0) {
for(int i=0;i<6;i++) { // Doesnt work right, needs work
if(group->members[i] != NULL) {
corpse->AllowMobLoot(group->members[i],i);
}
}
}
}
}
}
Code:
#if 0 // solar: commenting this out for now TODO reimplement becomenpc stuff
if (IsBecomeNPC() == true)
{
if (other != NULL && other->IsClient()) {
if (other->CastToClient()->isgrouped && entity_list.GetGroupByMob(other) != 0)
entity_list.GetGroupByMob(other->CastToClient())->SplitExp((uint32)(level*level*75*3.5f), this);
else
other->CastToClient()->AddEXP((uint32)(level*level*75*3.5f)); // Pyro: Comment this if NPC death crashes zone
//hate_list.DoFactionHits(GetNPCFactionID());
}
Corpse* corpse = new Corpse(this->CastToClient(), 0);
entity_list.AddCorpse(corpse, this->GetID());
this->SetID(0);
if(other->GetOwner() != 0 && other->GetOwner()->IsClient())
other = other->GetOwner();
if(other != 0 && other->IsClient()) {
corpse->AllowMobLoot(other, 0);
if(other->CastToClient()->isgrouped) {
Group* group = entity_list.GetGroupByClient(other->CastToClient());
if(group != 0) {
for(int i=0; i < MAX_GROUP_MEMBERS; i++) { // Doesnt work right, needs work
if(group->members[i] != NULL) {
corpse->AllowMobLoot(group->members[i],i);
}
}
}
}
}
}
#endif
zonedb.h
Code:
bool GetDecayTimes(npcDecayTimes_Struct* npcCorpseDecayTimes);
net.cpp
Code:
npcDecayTimes_Struct npcCorpseDecayTimes[100];
_log(ZONE__INIT, "Loading corpse timers");
database.GetDecayTimes(npcCorpseDecayTimes);
database.h
Code:
// Added By Hogie
// INSERT into variables (varname,value) values('decaytime [minlevel] [maxlevel]','[number of seconds]');
// IE: decaytime 1 54 = Levels 1 through 54
// decaytime 55 100 = Levels 55 through 100
// It will always put the LAST time for the level (I think) from the Database
struct npcDecayTimes_Struct {
int16 minlvl;
int16 maxlvl;
int32 seconds;
};
// Added By Hogie -- End
zone.cpp
Code:
bool ZoneDatabase::GetDecayTimes(npcDecayTimes_Struct* npcCorpseDecayTimes) {
char errbuf[MYSQL_ERRMSG_SIZE];
char* query = 0;
int i = 0;
MYSQL_RES *result;
MYSQL_ROW row;
if (RunQuery(query, MakeAnyLenString(&query, "SELECT varname, value FROM variables WHERE varname like 'decaytime%%' ORDER BY varname"), errbuf, &result)) {
safe_delete_array(query);
while((row = mysql_fetch_row(result))) {
Seperator sep(row[0]);
npcCorpseDecayTimes[i].minlvl = atoi(sep.arg[1]);
npcCorpseDecayTimes[i].maxlvl = atoi(sep.arg[2]);
if (atoi(row[1]) > 7200)
npcCorpseDecayTimes[i].seconds = 720;
else
npcCorpseDecayTimes[i].seconds = atoi(row[1]);
i++;
}
mysql_free_result(result);
}
else {
safe_delete_array(query);
return false;
}
return true;
}// Added By Hogie -- End
PlayerCorpse.cpp
Code:
extern npcDecayTimes_Struct npcCorpseDecayTimes[100];
Code:
Corpse* Corpse::LoadFromDBData(int32 in_dbid, int32 in_charid, char* in_charname, uchar* in_data, int32 in_datasize, float in_x, float in_y, float in_z, float in_heading, char* timeofdeath, bool rezzed, bool wasAtGraveyard) {
if (in_datasize < sizeof(DBPlayerCorpse_Struct)) {
cout << "Corpse::LoadFromDBData: Corrupt data: in_datasize < sizeof(DBPlayerCorpse_Struct)" << endl;
return 0;
}
DBPlayerCorpse_Struct* dbpc = (DBPlayerCorpse_Struct*) in_data;
if (in_datasize != (sizeof(DBPlayerCorpse_Struct) + (dbpc->itemcount * sizeof(ServerLootItem_Struct)))) {
cout << "Corpse::LoadFromDBData: Corrupt data: in_datasize != expected size" << endl;
return 0;
}
if (dbpc->crc != CRC32::Generate(&((uchar*) dbpc)[4], in_datasize - 4)) {
cout << "Corpse::LoadFromDBData: Corrupt data: crc failure" << endl;
return 0;
}
ItemList itemlist;
ServerLootItem_Struct* tmp = 0;
for (unsigned int i=0; i < dbpc->itemcount; i++) {
tmp = new ServerLootItem_Struct;
memcpy(tmp, &dbpc->items[i], sizeof(ServerLootItem_Struct));
itemlist.push_back(tmp);
}
Corpse* pc = new Corpse(in_dbid, in_charid, in_charname, &itemlist, dbpc->copper, dbpc->silver, dbpc->gold, dbpc->plat, in_x, in_y, in_z, in_heading, dbpc->size, dbpc->gender, dbpc->race, dbpc->class_, dbpc->deity, dbpc->level, dbpc->texture, dbpc->helmtexture,dbpc->exp, wasAtGraveyard);
if (dbpc->locked)
pc->Lock();
// load tints
memcpy(pc->item_tint, dbpc->item_tint, sizeof(pc->item_tint));
// appearance
pc->haircolor = dbpc->haircolor;
pc->beardcolor = dbpc->beardcolor;
pc->eyecolor1 = dbpc->eyecolor1;
pc->eyecolor2 = dbpc->eyecolor2;
pc->hairstyle = dbpc->hairstyle;
pc->luclinface = dbpc->face;
pc->beard = dbpc->beard;
pc->Rezzed(rezzed);
pc->become_npc = false;
return pc;
}
Code:
// To be used on NPC death and ZoneStateLoad
// Mongrel: added see_invis and see_invis_undead
Corpse::Corpse(NPC* in_npc, ItemList* in_itemlist, int32 in_npctypeid, const NPCType** in_npctypedata, int32 in_decaytime)
// vesuvias - appearence fix
: Mob("Unnamed_Corpse","",0,0,in_npc->GetGender(),in_npc->GetRace(),in_npc->GetClass(),BT_Humanoid//bodytype added
,in_npc->GetDeity(),in_npc->GetLevel(),in_npc->GetNPCTypeID(),in_npc->GetSize(),0,
in_npc->GetHeading(),in_npc->GetX(),in_npc->GetY(),in_npc->GetZ(),0,
in_npc->GetTexture(),in_npc->GetHelmTexture(),
0,0,0,0,0,0,0,0,0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0,0,0,0,0,0,0),
corpse_decay_timer(in_decaytime),
corpse_delay_timer(in_decaytime/2),
corpse_graveyard_timer(0)
{
corpse_graveyard_timer.Disable();
memset(item_tint, 0, sizeof(item_tint));
pIsChanged = false;
p_PlayerCorpse = false;
pLocked = false;
BeingLootedBy = 0xFFFFFFFF;
if (in_itemlist) {
itemlist = *in_itemlist;
in_itemlist->clear();
}
SetCash(in_npc->GetCopper(), in_npc->GetSilver(), in_npc->GetGold(), in_npc->GetPlatinum());
npctype_id = in_npctypeid;
SetPKItem(0);
charid = 0;
dbid = 0;
p_depop = false;
strcpy(orgname, in_npc->GetName());
strcpy(name, in_npc->GetName());
// Added By Hogie
for(int count = 0; count < 100; count++) {
if ((level >= npcCorpseDecayTimes[count].minlvl) && (level <= npcCorpseDecayTimes[count].maxlvl)) {
corpse_decay_timer.SetTimer(npcCorpseDecayTimes[count].seconds*1000);
break;
}
}
// Added By Hogie -- End
for (int i=0; i<MAX_LOOTERS; i++)
looters[i] = 0;
this->rezzexp = 0;
}
And don't worry, I don't deserve or want any credit lol. I am just glad to see the feature get added. Thanks KLS! 
Last edited by trevius; 08-12-2008 at 01:11 PM..
|
 |
|
 |

08-12-2008, 08:14 AM
|
Dragon
|
|
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
|
|
Is it necessary to add a rule? From what I understand, this would simply be doing something that Live eventually did.
|

08-12-2008, 04:04 PM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Well, you probably don't NEED a rule, but I think it would be nice to have the option. Some people might not want corpses to be poofing while the mob is still doing the death animation. I wouldn't mind having corpses not get made at all if it they are empty. But, I also wouldn't mind the option to set it to 5 or 10 seconds so that they at least see a corpse for a few seconds.
Rules aren't really all that hard to add, and I think they only further customize-ability of servers. Though, I think it might be a good idea to have a "Notes" column added to the Rule_Values table. It would be only for reference when setting the rule, and would be a brief description of what the rule does and how to set it. There are already descriptions for most rules directly in the ruletypes.h file, so maybe those could be pulled and put in the notes column.
|
 |
|
 |

08-13-2008, 09:11 PM
|
Discordant
|
|
Join Date: May 2004
Posts: 290
|
|
I didn't think it needed to be a rule, so I just hardcoded a 5 sec decay on empty corpses.
In zone/PlayerCorpse.cpp, near line 150 after Hogie's variable decay loop, add this.
Code:
// Added By Hogie
for(int count = 0; count < 100; count++) {
if ((level >= npcCorpseDecayTimes[count].minlvl) && (level <= npcCorpseDecayTimes[count].maxlvl)) {
corpse_decay_timer.SetTimer(npcCorpseDecayTimes[count].seconds*1000);
break;
}
}
// Added By Hogie -- End
if (itemlist.size() < 1)
corpse_decay_timer.SetTimer(5000);
for (int i=0; i<MAX_LOOTERS; i++)
looters[i] = 0;
this->rezzexp = 0;
I can put it into a rule if that's how it should be.
|

08-13-2008, 09:27 PM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
LOL, I figured it would be something simple like that! I will test it out on my server tonight. My only question is if this takes coin loot into consideration, or only items?
I think you guys are right. This really doesn't have much reason to be set as a rule. I guess I just like to have as many options as possible :P
Thanks Theeper!
|

08-13-2008, 09:40 PM
|
Discordant
|
|
Join Date: May 2004
Posts: 290
|
|
I didn't think about coin, good catch Trev. Use this instead.
Code:
if (itemlist.size() < 1 && in_npc->GetCopper() == 0 && in_npc->GetSilver()== 0 && in_npc->GetGold()== 0 && in_npc->GetPlatinum() == 0)
corpse_decay_timer.SetTimer(5000);
|

08-13-2008, 09:41 PM
|
Administrator
|
|
Join Date: Sep 2006
Posts: 1,348
|
|
It doesn't have to be set as a rule but it is; there will be a rule in tonight's build along with some other stuff that's probably not as exciting for some people.
btw there's already a function to tell if the corpse is empty: Corpse::IsEmpty() =p
|

08-13-2008, 09:43 PM
|
Dragon
|
|
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
|
|
Every little bit helps, and all progress is exciting. Thanks as always =)
|

08-13-2008, 10:06 PM
|
Discordant
|
|
Join Date: May 2004
Posts: 290
|
|
Quote:
Originally Posted by KLS
btw there's already a function to tell if the corpse is empty: Corpse::IsEmpty() =p
|
LOL, that's what I get for not looking through the function list very carefully. It seems as though IsEmpty() is only used for the PERL interface right now.
Ignore the above and use this until KLS tells us how it's actually supposed to be done in one line probably :p~
Code:
if (IsEmpty())
corpse_decay_timer.SetTimer(5000);
|

08-13-2008, 10:28 PM
|
Administrator
|
|
Join Date: Sep 2006
Posts: 1,348
|
|
Well that's actually basically it.
|
 |
|
 |

08-13-2008, 10:39 PM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Oh, and the main reason I think it would be nice to have as a rule would be to have the option to make corpses poof immediately without even starting a timer. This would probably reduce some of the load on servers after a large AE pull is killed. I know when I have 30ish mobs all die at once, it almost always crashes the zone.
One thing I was thinking is that instead of a rule, it might be nice to have the decay timer be an actual setting in the Zones table similar to canbind, accept the number would be the time in seconds of how long the corpse would last. In most zones, I would like the 5 second timer to be set, because I think it would just be a little weird for corpses to disapear immediately. But there are definitely a couple of zones where I would prefer to have them vanish immediately, mostly because there are often AE groups in those zones and the server needs any help it can get to reduce performance issues from AEing.
|
 |
|
 |
 |
|
 |

08-14-2008, 12:39 AM
|
Developer
|
|
Join Date: Mar 2007
Location: Ohio
Posts: 648
|
|
Quote:
Originally Posted by trevius
Doesn't it need the brackets around it like this?
Code:
if (IsEmpty()) {
corpse_decay_timer.SetTimer(5000); }
Or am I still too much of a coding newbie? :P
|
If you have only 1 thing to process in an if, else, etc, statement, you don't need brackets. I know this is true for C++ & Perl, pretty sure it's the same for other languages including PHP.
I know there's another weird function using : and ? for a very simple if/else statement, but I never really paid attention to the syntax.
Quote:
Originally Posted by trevius
Oh, and the main reason I think it would be nice to have as a rule would be to have the option to make corpses poof immediately without even starting a timer. This would probably reduce some of the load on servers after a large AE pull is killed. I know when I have 30ish mobs all die at once, it almost always crashes the zone.
One thing I was thinking is that instead of a rule, it might be nice to have the decay timer be an actual setting in the Zones table similar to canbind, accept the number would be the time in seconds of how long the corpse would last. In most zones, I would like the 5 second timer to be set, because I think it would just be a little weird for corpses to disapear immediately. But there are definitely a couple of zones where I would prefer to have them vanish immediately, mostly because there are often AE groups in those zones and the server needs any help it can get to reduce performance issues from AEing.
|
You could set it up one of many different ways. Unfortunately, I don't know if there's really one "best" way to do it. You could do it on a per-mob basis, per zone basis, per server basis, or a combination of the above. If you really want to add flexibility, I would say all of the above, using mob, zone, then server as the priority using an if, else if, else statement. I'm not sure of the exact code needed, but the idea would be something like this:
Code:
if (mob.empty_corpse_timer != NULL) corpse_decay_timer.SetTimer(mob.empty_corpse_timer)
else if (zone.empty_corpse_timer != NULL) corpse_decay_timer.SetTimer(zone.empty_corpse_timer)
else corpse_decay_timer.SetTimer(RuleI(NPC,EmptyNPCCorpseDecayTimeMS)+1000)
|
 |
|
 |
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 01:10 AM.
|
|
 |
|
 |
|
|
|
 |
|
 |
|
 |