PDA

View Full Version : Fix To Search All Inventory Slots For A Key


WildcardX
01-13-2007, 06:24 AM
This code will allow you to have a key anywhere in your inventory. Either in a bag, your personal inventory, the bank, the shard bank or any combination of these. This will bring the server to how keys worked just prior to Sony implementing the keyring (which is what I am going to do next). Right now, EQEmu server has an implementation that behaved like the original key system.


diff -u c:\temp\old/client.h c:\temp\new/client.h
--- c:\temp\old/client.h 2007-01-07 12:48:22.000000000 -0600
+++ c:\temp\new/client.h 2007-01-13 11:04:45.031250000 -0600
@@ -591,6 +591,7 @@
void SetTint(sint16 slot_id, Color_Struct& color);
void SetMaterial(sint16 slot_id, uint32 item_id);
void Undye();
+ uint32 FindItemInInventory(uint32 item_id);
uint32 GetItemIDAt(sint16 slot_id);
bool PutItemInInventory(sint16 slot_id, const ItemInst& inst, bool client_update = false);
bool PushItemOnCursor(const ItemInst& inst, bool client_update = false);
@@ -682,6 +683,7 @@
void OPGMTrainSkill(const EQApplicationPacket *app);
void OPGMSummon(const EQApplicationPacket *app);
void OPCombatAbility(const EQApplicationPacket *app);
+ bool SlotItemSearch(uint32 startSlot, uint32 endSlot, uint32 item_id);

sint16 CalcAC();
sint16 CalcATK();
diff -u c:\temp\old/doors.cpp c:\temp\new/doors.cpp
--- c:\temp\old/doors.cpp 2006-11-19 17:39:08.000000000 -0600
+++ c:\temp\new/doors.cpp 2007-01-13 11:49:35.546875000 -0600
@@ -100,7 +100,7 @@
//////////////////////////////////////////////////////////////////

uint32 keyneeded=GetKeyItem();
- uint32 playerkey=sender->GetItemIDAt(SLOT_CURSOR);
+ uint32 playerkey = sender->FindItemInInventory(keyneeded);

if(GetTriggerType() == 255) { // this object isnt triggered
if(trigger == 1) { // this door is only triggered by an object
@@ -137,6 +137,7 @@
else
{
// guild doors
+
if (guild_id>0 && !sender->GetGM())
{
string tmp;
@@ -167,7 +168,8 @@
}
}
else if (playerkey)
- { // they have something they are trying to open it with
+ {
+ // they have something they are trying to open it with
if (keyneeded && keyneeded == playerkey)
{ // key required and client is using the right key
sender->Message(4,"You got it open!"); // more debug spam
diff -u c:\temp\old/inventory.cpp c:\temp\new/inventory.cpp
--- c:\temp\old/inventory.cpp 2006-10-22 15:12:38.000000000 -0500
+++ c:\temp\new/inventory.cpp 2007-01-13 11:40:29.125000000 -0600
@@ -212,6 +212,54 @@
object->Save();
}

+// Searches for a specified item anywhere in Players possession
+uint32 Client::FindItemInInventory(uint32 item_id)
+{
+ uint32 result = INVALID_ID;
+
+ // See Item.h for the slot ID's used here
+
+ if(item_id)
+ {
+ if(SlotItemSearch(0, 30, item_id))
+ result = item_id;
+ else if(SlotItemSearch(251, 330, item_id))
+ result = item_id;
+ else if(SlotItemSearch(2000, 2015, item_id))
+ result = item_id;
+ else if(SlotItemSearch(2031, 2190, item_id))
+ result = item_id;
+ else if(SlotItemSearch(2500, 2501, item_id))
+ result = item_id;
+ else if(result = SlotItemSearch(2531, 2550, item_id))
+ result = item_id;
+ }
+
+ return result;
+}
+
+// Searches for a specified item in the specified slot/inventory range
+bool Client::SlotItemSearch(uint32 startSlot, uint32 endSlot, uint32 item_id)
+{
+ bool result = false;
+
+ if(item_id)
+ {
+ for(uint32 x = startSlot; x <= endSlot; x++)
+ {
+ const ItemInst* inst = m_inv[x];
+
+ if(inst)
+ {
+ if(inst->GetItem()->ID == item_id)
+ result = true;
+ }
+ }
+ }
+
+ return result;
+}
+
// Returns a slot's item ID (returns INVALID_ID if not found)
uint32 Client::GetItemIDAt(sint16 slot_id) {
const ItemInst* inst = m_inv[slot_id];



This was tested by myself and Sesmar. Enjoy!

John Adams
01-14-2007, 08:43 AM
Thank you! Good luck with the keyrings!

Teppen
01-14-2007, 11:05 AM
Nice, this could also be useful displaying what zones player is keyed for just like in the real magelo system, ex: (key to charasis, sleeper's key,.. etc.). Who was the author of the eqemu magelo system by the way? Havent seen it updated in awhile, and this would be a nice feature, especially when peq releases PoP and code is entered for "blank has recieved a character flag", then this could also help displaying planar progression flags in magelo clone.

just a thought.