Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2008, 02:28 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default 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
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!

Last edited by trevius; 08-12-2008 at 10:32 AM..
Reply With Quote
  #2  
Old 08-12-2008, 04:38 AM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

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!).
Reply With Quote
  #3  
Old 08-12-2008, 05:08 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

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!
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!

Last edited by trevius; 08-12-2008 at 01:11 PM..
Reply With Quote
  #4  
Old 08-12-2008, 08:14 AM
So_1337
Dragon
 
Join Date: May 2006
Location: Cincinnati, OH
Posts: 689
Default

Is it necessary to add a rule? From what I understand, this would simply be doing something that Live eventually did.
Reply With Quote
  #5  
Old 08-12-2008, 04:04 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

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.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #6  
Old 08-13-2008, 09:11 PM
Theeper
Discordant
 
Join Date: May 2004
Posts: 290
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 07:24 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3