Browse Source

Added GetWardValue in support of Issue #115

GetWardValue(Ward, "type")

types:
damageleft - amount of damage left ward can absorb
basedamage - original amount of damage ward can absorb in total
keepward - keep ward (don't remove spell from spawn) if it expires by absorbing all the damage
wardtype - limit damage type:
#define WARD_TYPE_ALL 0
#define WARD_TYPE_PHYSICAL 1
#define WARD_TYPE_MAGICAL 2

dmgabsorptionpct - max damage ward can absorb (eg 50% of 100 means 50 absorbed, 50 damage still hits)
dmgabsorptionmaxhealthpct - max damage ward can absorb (eg if 1000 health and 50%, any damage 500+ will not be absorbed)
Image 4 years ago
parent
commit
91cb109799

+ 38 - 0
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -35,6 +35,7 @@
 #include "RaceTypes/RaceTypes.h"
 #include "ClientPacketFunctions.h"
 #include "Transmute.h"
+#include <boost/algorithm/string/predicate.hpp>
 
 extern WorldDatabase database;
 extern LuaInterface* lua_interface;
@@ -5039,6 +5040,43 @@ int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
 	return 0;
 }
 
+int EQ2Emu_lua_GetWardValue(lua_State* state) {
+	if (!lua_interface)
+		return 0;
+
+	LuaSpell* spell = lua_interface->GetCurrentSpell(state);
+	if (!spell) {
+		lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
+		return 0;
+	}
+
+	string type = lua_interface->GetStringValue(state, 2);
+
+	if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
+
+		Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
+		WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
+		if (ward) {
+			if (boost::iequals(type, "damageleft"))
+				lua_interface->SetInt32Value(state, ward->DamageLeft);
+			else if (boost::iequals(type, "basedamage"))
+				lua_interface->SetInt32Value(state, ward->BaseDamage);
+			else if (boost::iequals(type, "keepward"))
+				lua_interface->SetBooleanValue(state, ward->keepWard);
+			else if (boost::iequals(type, "wardtype"))
+				lua_interface->SetInt32Value(state, ward->WardType);
+			else if (boost::iequals(type, "dmgabsorptionpct"))
+				lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
+			else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
+				lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
+			else
+				lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
+			return 1;
+		}
+	}
+	return 0;
+}
+
 int EQ2Emu_lua_RemoveWard(lua_State* state) {
 	if (!lua_interface)
 		return 0;

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

@@ -289,6 +289,7 @@ int EQ2Emu_lua_AddWard(lua_State* state);
 int EQ2Emu_lua_AddToWard(lua_State* state);
 int EQ2Emu_lua_RemoveWard(lua_State* state);
 int EQ2Emu_lua_GetWardAmountLeft(lua_State* state);
+int EQ2Emu_lua_GetWardValue(lua_State* state);
 
 //Combat AI related
 int EQ2Emu_lua_SetTarget(lua_State* state);

+ 1 - 0
EQ2/source/WorldServer/LuaInterface.cpp

@@ -895,6 +895,7 @@ void LuaInterface::RegisterFunctions(lua_State* state) {
 	lua_register(state, "AddToWard", EQ2Emu_lua_AddToWard);
 	lua_register(state, "RemoveWard", EQ2Emu_lua_RemoveWard);
 	lua_register(state, "GetWardAmountLeft", EQ2Emu_lua_GetWardAmountLeft);
+	lua_register(state, "GetWardValue", EQ2Emu_lua_GetWardValue);
 
 	lua_register(state, "SetTarget", EQ2Emu_lua_SetTarget);
 	lua_register(state, "IsPet", EQ2Emu_lua_IsPet);