[Patch] Cancel Maintained & Use Equipped Item Commands

EQ2Emulator Development forum.

Moderator: Team Members

Post Reply
User avatar
Rhas
Retired
Posts: 33
Joined: Sat May 29, 2010 11:39 am
Location: Kansas City

[Patch] Cancel Maintained & Use Equipped Item Commands

Post by Rhas » Mon May 31, 2010 10:12 pm

I've added two commands that I'd like you guys to take a look at to make sure it looks okay.

The first is COMMAND_USE_EQUIPPED_ITEM (275). It is implemented almost exactly like COMMAND_USE_ITEM except the slot_id is passed in instead of the item_index. I also check if the item is useable before calling the item script. I verified this works by hooking up one of the mount whistles to a lua script I created (see horsemount.lua below) and tied the item to that script in the database. The script just calls the beta mount spell. It worked like a charm from the inventory and also when equipped in the charm slot. :D I also realize there is more stuff to add to make usable items work like live but this is a start.

horsemount.lua

Code: Select all

function used(Item, ItemUser)
	CastSpell(ItemUser, 3101, 1, ItemUser)
end
The second command I added was COMMAND_CANCEL_MAINTAINED (276). After I used the beta mount, I couldn't figure out how to get rid of it (besides logging), so I implemented this command. The code is pretty simple. The client sends the maintained spell index. I use that to get the spell from the master_spell_list. After verifying that it is a friendly spell, I call the DeleteCasterSpell function (already implemented) which handles the removal of the buffs. I tested this solo and in a group. I also tested when I had more that one maintained spell active.

Also, obviously the handlers have to be updated in the database as well. As always, let me know if I overlooked something. I'm not sure how much time I can devote to this project so don't call me official yet but I am having a blast so far. :D

Commands.h

Code: Select all

--- Commands.h (revision 437)
+++ Commands.h	(working copy)
@@ -477,4 +477,6 @@
 #define COMMAND_LOCATION_REMOVE		272
 #define COMMAND_LOCATION_DELETE		273
 #define COMMAND_LOCATION_LIST		274
+#define COMMAND_USE_EQUIPPED_ITEM	275
+#define COMMAND_CANCEL_MAINTAINED	276
 #endif
Commands.cpp

Code: Select all

--- Commands.cpp (Revision 437)
+++ Commands.cpp (working copy)
@@ -960,6 +960,16 @@
 				client->SimpleMessage(CHANNEL_COLOR_YELLOW,"Usage:  /info {inventory|equipment|spell} {id}");
 			break;
 						  }
+
+		case COMMAND_USE_EQUIPPED_ITEM:
+			if (sep && sep->arg[0] && sep->IsNumber(0)) {
+				int32 slot_id = atoul(sep->arg[0]);
+				Item* item = player->GetEquipmentList()->GetItem(slot_id);				
+				if (item && item->generic_info.usable && item->GetItemScript())				
+					lua_interface->RunItemScript(item->GetItemScript(), "used", item, player);				
+			}
+			break;
+
 	    case COMMAND_USE_ITEM: {
 			if (sep && sep->arg[0] && sep->IsNumber(0)) {
 				int32 item_index = atoul(sep->arg[0]);
@@ -3978,6 +3988,21 @@
 			client->Message(CHANNEL_COLOR_YELLOW,"You are %s invisible to who queries.", client->GetPlayer()->get_character_flag(CF_GM_HIDDEN)?"now":"no longer");
 			break;
 		}
+		case COMMAND_CANCEL_MAINTAINED:{
+			if (sep && sep->arg[0] && sep->IsNumber(0)) {
+				int32 spell_index = atoul(sep->arg[0]);
+				MaintainedEffects mEffects = client->GetPlayer()->GetInfoStruct()->maintained_effects[spell_index];
+
+				Spell* spell = master_spell_list.GetSpell(mEffects.spell_id, mEffects.tier);
+				if(spell && spell->GetSpellData()->friendly_spell){
+					if(!client->GetPlayer()->GetZone()->GetSpellProcess()->DeleteCasterSpell(client->GetPlayer(), spell))
+						client->Message(CHANNEL_COLOR_RED, "The maintained spell could not be cancelled.");
+				}
+				else
+					client->Message(CHANNEL_COLOR_RED, "You can only cancel friendly spells!");
+			}
+			break;
+		}
 		default:{
 			LogFile->write(EQEMuLog::Status, "Unhandled command: %s", command->command.data.c_str());
 				}

User avatar
Zcoretri
Team Member
Posts: 1642
Joined: Fri Jul 27, 2007 12:55 pm
Location: SoCal

Re: [Patch] Cancel Maintained & Use Equipped Item Commands

Post by Zcoretri » Tue Jun 01, 2010 10:27 am

Any amount of time you can spare we will gladly accept.

I'm excited about this addition, we will add it and check it out.

Thanks Rhas! :mrgreen:

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: [Patch] Cancel Maintained & Use Equipped Item Commands

Post by John Adams » Tue Jun 01, 2010 11:10 am

I'll try and get the commands table updated this week. Busy week at work, thanks again!

User avatar
Zcoretri
Team Member
Posts: 1642
Joined: Fri Jul 27, 2007 12:55 pm
Location: SoCal

Re: [Patch] Cancel Maintained & Use Equipped Item Commands

Post by Zcoretri » Tue Jun 01, 2010 10:41 pm

Very nice...I got this working. :mrgreen:
I'm not getting any visual for a mount...I take it that we have not implemented that yet?

John, do you have to do some magic with version.h first? What else do I have to do to commit this?

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: [Patch] Cancel Maintained & Use Equipped Item Commands

Post by John Adams » Wed Jun 02, 2010 7:48 am

For command entries inside a table (just data added/changed), no there is no version.h bump. version.h only needs a bump when the table/DB structure changes.

You can commit the code now, the commands have been updated in the `commands` table.

User avatar
Zcoretri
Team Member
Posts: 1642
Joined: Fri Jul 27, 2007 12:55 pm
Location: SoCal

Re: [Patch] Cancel Maintained & Use Equipped Item Commands

Post by Zcoretri » Wed Jun 02, 2010 8:56 am

John Adams wrote:For command entries inside a table (just data added/changed), no there is no version.h bump. version.h only needs a bump when the table/DB structure changes.

You can commit the code now, the commands have been updated in the `commands` table.
OK, I seem to remember that now. It has been a while since we have changed DB structure :shock:

Thanks John, I will go ahead and commit.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests