瀏覽代碼

Fixing loot window and updating structs (for newer clients) to be compatible with code changes from LE merge

Image 4 年之前
父節點
當前提交
5644ed5574

+ 8 - 12
EQ2/source/WorldServer/Commands/Commands.cpp

@@ -2029,9 +2029,8 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 								client->Message(CHANNEL_COLOR_YELLOW, "%u - %s", *list_itr, table->name.c_str());
 						}
 					}
-					Entity* target = (Entity*)spawn;
-					client->Message(CHANNEL_COLOR_YELLOW, "Coins being carried: %u", target->GetLootCoins());
-					vector<Item*>* items = target->GetLootItems();
+					client->Message(CHANNEL_COLOR_YELLOW, "Coins being carried: %u", spawn->GetLootCoins());
+					vector<Item*>* items = spawn->GetLootItems();
 					if (items) {
 						client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is carrying the following items: ");
 						vector<Item*>::iterator itr;
@@ -2050,8 +2049,7 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 		case COMMAND_LOOT_SETCOIN:{
 			Spawn* spawn = cmdTarget;
 			if(spawn && spawn->IsEntity() && sep && sep->arg[0] && sep->IsNumber(0)){
-				Entity* target = (Entity*)spawn;
-				target->SetLootCoins(atoul(sep->arg[0]));
+				spawn->SetLootCoins(atoul(sep->arg[0]));
 				client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully set coins.");
 			}
 			else
@@ -2061,11 +2059,10 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 		case COMMAND_LOOT_ADDITEM:{
 			Spawn* spawn = cmdTarget;
 			if(spawn && spawn->IsEntity() && sep && sep->arg[0] && sep->IsNumber(0)){
-				Entity* target = (Entity*)spawn;
 				int16 charges = 1;
 				if(sep->arg[1] && sep->IsNumber(1))
 					charges = atoi(sep->arg[1]);
-				target->AddLootItem(atoul(sep->arg[0]), charges);
+				spawn->AddLootItem(atoul(sep->arg[0]), charges);
 				client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully added item.");
 			}
 			else
@@ -2075,8 +2072,7 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 		case COMMAND_LOOT_REMOVEITEM:{
 			Spawn* spawn = cmdTarget;
 			if(spawn && spawn->IsEntity() && sep && sep->arg[0] && sep->IsNumber(0)){
-				Entity* target = (Entity*)spawn;
-				target->LootItem(atoul(sep->arg[0]));
+				spawn->LootItem(atoul(sep->arg[0]));
 				client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully removed item.");
 			}
 			else
@@ -2095,10 +2091,10 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 			if(cmdTarget && cmdTarget->IsEntity()){
 				if (cmdTarget->GetDistance(client->GetPlayer()) <= rule_manager.GetGlobalRule(R_Loot, LootRadius)->GetFloat()){
 					if (!rule_manager.GetGlobalRule(R_Loot, AutoDisarmChest)->GetBool() && command->handler == COMMAND_DISARM )
-						client->OpenChest((Entity*)cmdTarget, true);
+						client->OpenChest(cmdTarget, true);
 					else
-						client->Loot((Entity*)cmdTarget, rule_manager.GetGlobalRule(R_Loot, AutoDisarmChest)->GetBool());
-					if (!((Entity*)cmdTarget)->HasLoot()){
+						client->Loot(cmdTarget, rule_manager.GetGlobalRule(R_Loot, AutoDisarmChest)->GetBool());
+					if (!(cmdTarget)->HasLoot()){
 						if (((Entity*)cmdTarget)->IsNPC())
 							client->GetCurrentZone()->RemoveDeadSpawn(cmdTarget);
 					}

+ 0 - 48
EQ2/source/WorldServer/Entity.cpp

@@ -48,8 +48,6 @@ Entity::Entity(){
 	memset(&melee_combat_data, 0, sizeof(CombatData));
 	memset(&ranged_combat_data, 0, sizeof(CombatData));
 	memset(&info_struct, 0, sizeof(InfoStruct));
-	loot_coins = 0;
-	trap_triggered = false;
 	memset(&features, 0, sizeof(CharFeatures));
 	memset(&equipment, 0, sizeof(EQ2_Equipment));
 	pet = 0;
@@ -89,9 +87,6 @@ Entity::Entity(){
 }
 
 Entity::~Entity(){
-	vector<Item*>::iterator itr;
-	for(itr = loot_items.begin(); itr != loot_items.end(); itr++)
-		safe_delete(*itr);
 	MutexList<BonusValues*>::iterator itr2 = bonus_list.begin();
 	while(itr2.Next())
 		safe_delete(itr2.value);
@@ -693,49 +688,6 @@ InfoStruct* Entity::GetInfoStruct(){
 	return &info_struct; 
 }
 
-Item* Entity::LootItem(int32 id){
-	Item* ret = 0;
-	vector<Item*>::iterator itr;
-	MLootItems.lock();
-	for(itr = loot_items.begin(); itr != loot_items.end(); itr++){
-		if((*itr)->details.item_id == id){
-			ret = *itr;
-			loot_items.erase(itr);
-			break;
-		}
-	}
-	MLootItems.unlock();
-	return ret;
-}
-
-int32 Entity::GetLootItemID(){
-	int32 ret = 0;
-	vector<Item*>::iterator itr;
-	MLootItems.lock();
-	for(itr = loot_items.begin(); itr != loot_items.end(); itr++){
-		ret = (*itr)->details.item_id;
-		break;
-	}
-	MLootItems.unlock();
-	return ret;
-}
-
-bool Entity::HasLootItemID(int32 id) {
-	bool ret = false;
-
-	vector<Item*>::iterator itr;
-	MLootItems.readlock(__FUNCTION__, __LINE__);
-	for (itr = loot_items.begin(); itr != loot_items.end(); itr++) {
-		if ((*itr)->details.item_id == id) {
-			ret = true;
-			break;
-		}
-	}
-	MLootItems.releasereadlock(__FUNCTION__, __LINE__);
-
-	return ret;
-}
-
 Skill* Entity::GetSkillByName(const char* name, bool check_update){
 	LogWrite(MISC__TODO, 1, "TODO", "This does nothing... yet...\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
 	return 0;

+ 0 - 53
EQ2/source/WorldServer/Entity.h

@@ -488,47 +488,6 @@ public:
 
 	bool	IsCasting();
 	void	IsCasting(bool val);
-	bool HasLoot(){
-		if(loot_items.size() == 0 && loot_coins == 0)
-			return false;
-		return true;
-	}
-	bool HasLootItemID(int32 id);
-	int32 GetLootItemID();
-	Item*	LootItem(int32 id);
-	vector<Item*>* GetLootItems(){
-		return &loot_items;
-	}
-	void LockLoot(){
-		MLootItems.lock();
-	}
-	void UnlockLoot(){
-		MLootItems.unlock();
-	}
-	int32 GetLootCoins(){
-		return loot_coins;
-	}
-	void SetLootCoins(int32 val){
-		loot_coins = val;
-	}
-	void AddLootCoins(int32 coins){
-		loot_coins += coins;
-	}
-	bool HasTrapTriggered() {
-		return trap_triggered;
-	}
-	void SetTrapTriggered(bool triggered) {
-		trap_triggered = triggered;
-	}
-	void AddLootItem(int32 id, int16 charges = 1){
-		Item* master_item = master_item_list.GetItem(id);
-		if(master_item){
-			Item* item = new Item(master_item);
-			item->details.count = charges;
-			loot_items.push_back(item);
-		}
-	}
-
 	void SetMount(int16 mount_id, int8 red = 0xFF, int8 green = 0xFF, int8 blue = 0xFF, bool setUpdateFlags = true)
 	{
 		if (mount_id == 0) {
@@ -837,14 +796,6 @@ public:
 
 	void CustomizeAppearance(PacketStruct* packet);
 
-	void ClearLootList() {
-		vector<Item*>::iterator itr;
-		for (itr = loot_items.begin(); itr != loot_items.end(); itr++)
-			safe_delete(*itr);
-
-		loot_items.clear();
-	}
-
 	Trade* trade;
 
 	// Keep track of entities that hate this spawn.
@@ -865,9 +816,6 @@ private:
 	map<int8, MutexList<LuaSpell*>*> control_effects;
 	map<int8, MutexList<LuaSpell*>*> immunities;
 	float	max_speed;
-	vector<Item*>	loot_items;
-	int32			loot_coins;
-	bool			trap_triggered;
 	int8	deity;
 	sint16	regen_hp_rate;
 	sint16	regen_power_rate;
@@ -884,7 +832,6 @@ private:
 	Mutex   MMaintainedSpells;
 	Mutex   MSpellEffects;
 	vector<DetrimentalEffects> detrimental_spell_effects;
-	Mutex	MLootItems;
 	// Pointers for the 4 types of pets (Summon, Charm, Deity, Cosmetic)
 	Entity*	pet;
 	Entity* charmedPet;

+ 2 - 2
EQ2/source/WorldServer/Items/Loot.cpp

@@ -452,7 +452,7 @@ NPC* Entity::DropChest() {
 
 	int8 highest_tier = 0;
 	vector<Item*>::iterator itr;	
-	for (itr = GetLootItems()->begin(); itr != GetLootItems()->end(); ) {
+	for (itr = ((Spawn*)this)->GetLootItems()->begin(); itr != ((Spawn*)this)->GetLootItems()->end(); ) {
 		if ((*itr)->details.tier >= ITEM_TAG_UNCOMMON) {
 			if ((*itr)->details.tier > highest_tier)
 				highest_tier = (*itr)->details.tier;
@@ -460,7 +460,7 @@ NPC* Entity::DropChest() {
 			// Add the item to the chest
 			chest->AddLootItem((*itr)->details.item_id, (*itr)->details.count);
 			// Remove the item from the corpse
-			itr = GetLootItems()->erase(itr);
+			itr = ((Spawn*)this)->GetLootItems()->erase(itr);
 		}
 		else
 			itr++;

+ 1 - 1
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -467,7 +467,7 @@ int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
 	Spawn* spawn = lua_interface->GetSpawn(state);
 	if (spawn && spawn->IsEntity()) {
 		int32 item_id = lua_interface->GetInt32Value(state, 2);
-		((Entity*)spawn)->LootItem(item_id);
+		spawn->LootItem(item_id);
 	}
 	return 0;
 }

+ 6 - 0
EQ2/source/WorldServer/Spawn.cpp

@@ -39,6 +39,8 @@ extern RuleManager rule_manager;
 extern World world;
 
 Spawn::Spawn(){ 
+	loot_coins = 0;
+	trap_triggered = false;
 	group_id = 0;
 	size_offset = 0;
 	merchant_id = 0;
@@ -114,6 +116,10 @@ Spawn::Spawn(){
 }
 
 Spawn::~Spawn(){
+	vector<Item*>::iterator itr;
+	for (itr = loot_items.begin(); itr != loot_items.end(); itr++)
+		safe_delete(*itr);
+
 	RemovePrimaryCommands();
 
 	for(int32 i=0;i<secondary_command_list.size();i++){

+ 3 - 3
EQ2/source/WorldServer/client.cpp

@@ -2360,13 +2360,13 @@ void Client::HandleLoot(EQApplicationPacket* app) {
 			EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
 			if (outapp)
 				QueuePacket(outapp);
-			Loot(0, player->GetPendingLootItems(loot_id), (Entity*)spawn);
+			Loot(0, player->GetPendingLootItems(loot_id), spawn);
 		}
 		else {
 			if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
 				if (loot_all) {
-					while (loot_all && ((item_id = ((Entity*)spawn)->GetLootItemID()) > 0)) {
-						loot_all = HandleLootItem((Entity*)spawn, item_id);
+					while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
+						loot_all = HandleLootItem(spawn, item_id);
 					}
 				}
 				else {

+ 4 - 4
EQ2/source/WorldServer/zoneserver.cpp

@@ -4312,12 +4312,12 @@ void ZoneServer::KillSpawn(bool spawnListLocked, Spawn* dead, Spawn* killer, boo
 		NPC* chest = 0;
 
 		if (!((NPC*)dead)->Brain()->PlayerInEncounter()) {
-			((NPC*)dead)->SetLootCoins(0);
-			((NPC*)dead)->GetLootItems()->clear();
+			dead->SetLootCoins(0);
+			dead->GetLootItems()->clear();
 		}
 
 		// If dead has loot attempt to drop a chest
-		if (((NPC*)dead)->HasLoot()) {
+		if (dead->HasLoot()) {
 			chest = ((NPC*)dead)->DropChest();
 		}
 
@@ -5744,7 +5744,7 @@ void ZoneServer::AddDeadSpawn(Spawn* spawn, int32 timer){
 	else if(timer != 0xFFFFFFFF)
 		dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + timer));
 	else{
-		if(spawn->IsEntity() && ((Entity*)spawn)->HasLoot()){
+		if(spawn->IsEntity() && spawn->HasLoot()){
 			dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + (15000 * spawn->GetLevel() + 240000)));
 			SendUpdateDefaultCommand(spawn, "loot", 10);
 		}

+ 4 - 4
server/WorldStructs.xml

@@ -6962,16 +6962,16 @@ to zero and treated like placeholders." />
 <Struct Name="WS_UpdateLoot" ClientVersion="882" OpcodeName="OP_ClientCmdMsg" OpcodeType="OP_EqUpdateLootCmd" >
 <Data ElementName="loot_count" Type="int16" />
 <Data ElementName="display" Type="int16" />
-<Data ElementName="unknown2" Type="int32" />
-<Data ElementName="unknown3" Type="int32" />
+<Data ElementName="loot_type" Type="int32" />
+<Data ElementName="lotto_timeout" Type="int32" />
 <Data ElementName="loot_id" Type="int32" />
 </Struct>
 <Struct Name="WS_UpdateLoot" ClientVersion="60114" OpcodeName="OP_ClientCmdMsg" OpcodeType="OP_EqUpdateLootCmd" >
 <Data ElementName="loot_count" Type="int16" />
 <Data ElementName="display" Type="int8" />
 <Data ElementName="unknown_605_1_MJ" Type="int8" />
-<Data ElementName="unknown2" Type="int32" />
-<Data ElementName="unknown3" Type="int32" />
+<Data ElementName="loot_type" Type="int32" />
+<Data ElementName="lotto_timeout" Type="int32" />
 <Data ElementName="loot_id" Type="int32" />
 </Struct>
 <Struct Name="WS_LootType" ClientVersion="1" OpcodeName="OP_LootItemsRequestMsg" >