Browse Source

castspell command

Fixes #25

/castspell [spellid] (tier=1) - Cast Spell with specified spell id, tier is optional, default of 1.
/castspell [spellname] - Find spells wildcard match with a partial spell name

cannot damage self with current setup.

sql query required: insert into commands set type=0,command='castspell',subcommand='',handler=509,required_status=200;
Image 1 year ago
parent
commit
856e068cad

+ 34 - 0
EQ2/source/WorldServer/Commands/Commands.cpp

@@ -2537,6 +2537,40 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie
 				((Widget*)target)->HandleUse(client, "Open", WIDGET_TYPE_DOOR);
 			break;
 		}
+		case COMMAND_CASTSPELL: {
+			if (sep && sep->arg[0] && sep->IsNumber(0))
+			{
+				int8 tier = 1;
+				if (sep->arg[1] && sep->IsNumber(1))
+					tier = atoul(sep->arg[1]);
+
+				int32 spellid = atoul(sep->arg[0]);
+				Spell* spell = master_spell_list.GetSpell(spellid, tier);
+
+				if (spell)
+				{
+					client->Message(CHANNEL_COLOR_RED, "Casting spell %u.", spellid);
+					SpellProcess* spellProcess = 0;
+					// Get the current zones spell process
+					spellProcess = client->GetCurrentZone()->GetSpellProcess();
+
+					spellProcess->CastInstant(spell, (Entity*)client->GetPlayer(), (cmdTarget && cmdTarget->IsEntity()) ? (Entity*)cmdTarget : (Entity*)client->GetPlayer());
+				}
+				else
+				{
+					client->Message(CHANNEL_COLOR_RED, "Could not find spell %u.",spellid);
+				}
+			}
+			else if (sep && sep->arg[0])
+			{
+				database.FindSpell(client, (char*)sep->argplus[0]);
+			}
+			else
+			{
+				client->Message(CHANNEL_COLOR_YELLOW, "Syntax: /castspell [spellid] (tier=1) - Cast Spell with specified spell id, tier is optional, default of 1.");
+				client->Message(CHANNEL_COLOR_YELLOW, "Syntax: /castspell [spellname] - Find spells wildcard match with a partial spell name");
+			}
+		}
 		case COMMAND_ATTACK:
 		case COMMAND_AUTO_ATTACK:{
 			int8 type = 1;

+ 1 - 0
EQ2/source/WorldServer/Commands/Commands.h

@@ -870,6 +870,7 @@ private:
 #define COMMAND_BOT_HELP				507
 
 #define COMMAND_OPEN					508
+#define COMMAND_CASTSPELL				509
 
 #define GET_AA_XML						751
 #define ADD_AA							752

+ 6 - 2
EQ2/source/WorldServer/SpellProcess.cpp

@@ -427,7 +427,11 @@ bool SpellProcess::ProcessSpell(LuaSpell* spell, bool first_cast, const char* fu
 }
 
 bool SpellProcess::CastPassives(Spell* spell, Entity* caster, bool remove) {
+	CastInstant(spell, caster, caster, remove, true);
+	return true;
+}
 
+bool SpellProcess::CastInstant(Spell* spell, Entity* caster, Entity* target, bool remove, bool passive) {
 	LuaSpell* lua_spell = 0;
 
 	if(lua_interface)
@@ -452,11 +456,11 @@ bool SpellProcess::CastPassives(Spell* spell, Entity* caster, bool remove) {
 
 	lua_spell->caster = caster;
 	lua_spell->spell = spell;
-	lua_spell->initial_target = caster->GetID();
+	lua_spell->initial_target = target->GetID();
 	GetSpellTargets(lua_spell);
 
 	if (!remove)
-		return CastProcessedSpell(lua_spell, true);
+		return CastProcessedSpell(lua_spell, passive);
 
 	lua_interface->RemoveSpell(lua_spell, true, SpellScriptTimersHasSpell(lua_spell));
 	return true;

+ 1 - 0
EQ2/source/WorldServer/SpellProcess.h

@@ -337,6 +337,7 @@ public:
 	/// <param name='caster'>The Entity to apply or remove the passive spell to</param>
 	/// <param name='remove'>Tells the function to remove the spell effects of this passive, default is false</param>
 	bool CastPassives(Spell* spell, Entity* caster, bool remove = false);
+	bool CastInstant(Spell* spell, Entity* caster, Entity* target, bool remove = false, bool passive=false);
 
 	/// <summary>Adds a spell script timer to the list</summary>
 	/// <param name='timer'>Timer to add</param>

+ 26 - 0
EQ2/source/WorldServer/WorldDatabase.cpp

@@ -6536,4 +6536,30 @@ void WorldDatabase::LoadCharacterLUAHistory(int32 char_id, Player* player) {
 	}
 
 	LogWrite(PLAYER__DEBUG, 0, "Player", "Loaded %u LUA history for %s", total, player->GetName());
+}
+
+void WorldDatabase::FindSpell(Client* client, char* findString)
+{
+	DatabaseResult result;
+		if (!database_new.Select(&result, "SELECT s.`id`, ts.spell_id, ts.index, `name`, `tier` "
+			"FROM (spells s, spell_tiers st) "
+			"LEFT JOIN spell_ts_ability_index ts "
+			"ON s.`id` = ts.spell_id "
+			"WHERE s.id = st.spell_id and s.name like '%%%s%%' AND s.is_active = 1 "
+			"ORDER BY s.`id`, `tier` limit 50", findString))
+		{
+			// error
+		}
+		else
+		{
+			client->Message(CHANNEL_COLOR_YELLOW, "SpellID (SpellTier): SpellName for %s", findString);
+			while (result.Next())
+			{
+				int32 spell_id = result.GetInt32Str("id");
+				string spell_name = result.GetStringStr("name");
+				int8 tier = result.GetInt8Str("tier");
+				client->Message(CHANNEL_COLOR_YELLOW, "%i (%i): %s", spell_id, tier, spell_name.c_str());
+			}
+			client->Message(CHANNEL_COLOR_YELLOW, "End Spell Results for %s", findString);
+		}
 }

+ 2 - 0
EQ2/source/WorldServer/WorldDatabase.h

@@ -562,6 +562,8 @@ public:
 	void				DeleteBot(int32 char_id, int32 bot_index);
 	void				SetBotStartingItems(Bot* bot, int8 class_id, int8 race_id);
 	void                LoadTransmuting();
+
+	void				FindSpell(Client* client, char* findString);
 private:
 	DatabaseNew			database_new;
 	map<int32, string>	zone_names;