[Experience] Add SetExp/SetAAExp lua mods (#4292)

This commit is contained in:
Xackery 2024-05-04 16:10:27 -07:00 committed by GitHub
parent aa0e53f5fc
commit 758859eea6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 236 additions and 57 deletions

View File

@ -1131,6 +1131,18 @@ namespace LeadershipAbilitySlot {
constexpr uint16 HealthOfTargetsTarget = 14; constexpr uint16 HealthOfTargetsTarget = 14;
} }
enum ExpSource
{
Quest,
GM,
Kill,
Death,
Resurrection,
LDoNChest,
Task,
Sacrifice
};
#define PARCEL_SEND_ITEMS 0 #define PARCEL_SEND_ITEMS 0
#define PARCEL_SEND_MONEY 1 #define PARCEL_SEND_MONEY 1
#define PARCEL_MONEY_ITEM_ID 99990 // item id of money #define PARCEL_MONEY_ITEM_ID 99990 // item id of money

View File

@ -1959,7 +1959,7 @@ bool Client::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::Skil
} else { } else {
newexp -= exploss; newexp -= exploss;
} }
SetEXP(newexp, GetAAXP()); SetEXP(ExpSource::Death, newexp, GetAAXP());
//m_epp.perAA = 0; //reset to no AA exp on death. //m_epp.perAA = 0; //reset to no AA exp on death.
} }
@ -2617,7 +2617,7 @@ bool NPC::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::SkillTy
if (killer_raid) { if (killer_raid) {
if (!is_ldon_treasure && MerchantType == 0) { if (!is_ldon_treasure && MerchantType == 0) {
killer_raid->SplitExp(final_exp, this); killer_raid->SplitExp(ExpSource::Kill, final_exp, this);
if ( if (
killer_mob && killer_mob &&
@ -2683,7 +2683,7 @@ bool NPC::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::SkillTy
} }
} else if (give_exp_client->IsGrouped() && killer_group) { } else if (give_exp_client->IsGrouped() && killer_group) {
if (!is_ldon_treasure && MerchantType == 0) { if (!is_ldon_treasure && MerchantType == 0) {
killer_group->SplitExp(final_exp, this); killer_group->SplitExp(ExpSource::Kill, final_exp, this);
if ( if (
killer_mob && killer_mob &&
@ -2747,7 +2747,7 @@ bool NPC::Death(Mob* killer_mob, int64 damage, uint16 spell, EQ::skills::SkillTy
if (con_level != ConsiderColor::Gray) { if (con_level != ConsiderColor::Gray) {
if (!GetOwner() || (GetOwner() && !GetOwner()->IsClient())) { if (!GetOwner() || (GetOwner() && !GetOwner()->IsClient())) {
give_exp_client->AddEXP(final_exp, con_level); give_exp_client->AddEXP(ExpSource::Kill, final_exp, con_level);
if ( if (
killer_mob && killer_mob &&

View File

@ -3912,7 +3912,7 @@ void Client::Sacrifice(Client *caster)
if (GetLevel() >= RuleI(Spells, SacrificeMinLevel) && GetLevel() <= RuleI(Spells, SacrificeMaxLevel)) { if (GetLevel() >= RuleI(Spells, SacrificeMinLevel) && GetLevel() <= RuleI(Spells, SacrificeMaxLevel)) {
int exploss = (int)(GetLevel() * (GetLevel() / 18.0) * 12000); int exploss = (int)(GetLevel() * (GetLevel() / 18.0) * 12000);
if (exploss < GetEXP()) { if (exploss < GetEXP()) {
SetEXP(GetEXP() - exploss, GetAAXP()); SetEXP(ExpSource::Sacrifice, GetEXP() - exploss, GetAAXP(), false);
SendLogoutPackets(); SendLogoutPackets();
// make our become corpse packet, and queue to ourself before OP_Death. // make our become corpse packet, and queue to ourself before OP_Death.
@ -5019,15 +5019,15 @@ void Client::HandleLDoNOpen(NPC *target)
{ {
if(GetRaid()) if(GetRaid())
{ {
GetRaid()->SplitExp(target->GetLevel()*target->GetLevel()*2625/10, target); GetRaid()->SplitExp(ExpSource::LDoNChest, target->GetLevel()*target->GetLevel()*2625/10, target);
} }
else if(GetGroup()) else if(GetGroup())
{ {
GetGroup()->SplitExp(target->GetLevel()*target->GetLevel()*2625/10, target); GetGroup()->SplitExp(ExpSource::LDoNChest, target->GetLevel()*target->GetLevel()*2625/10, target);
} }
else else
{ {
AddEXP(target->GetLevel()*target->GetLevel()*2625/10, GetLevelCon(target->GetLevel())); AddEXP(ExpSource::LDoNChest, target->GetLevel()*target->GetLevel()*2625/10, GetLevelCon(target->GetLevel()));
} }
} }
target->Death(this, 0, SPELL_UNKNOWN, EQ::skills::SkillHandtoHand); target->Death(this, 0, SPELL_UNKNOWN, EQ::skills::SkillHandtoHand);
@ -5229,7 +5229,7 @@ void Client::SummonAndRezzAllCorpses()
int RezzExp = entity_list.RezzAllCorpsesByCharID(CharacterID()); int RezzExp = entity_list.RezzAllCorpsesByCharID(CharacterID());
if(RezzExp > 0) if(RezzExp > 0)
SetEXP(GetEXP() + RezzExp, GetAAXP(), true); SetEXP(ExpSource::Resurrection, GetEXP() + RezzExp, GetAAXP(), true);
Message(Chat::Yellow, "All your corpses have been summoned to your feet and have received a 100% resurrection."); Message(Chat::Yellow, "All your corpses have been summoned to your feet and have received a 100% resurrection.");
} }
@ -8308,7 +8308,7 @@ void Client::QuestReward(Mob* target, uint32 copper, uint32 silver, uint32 gold,
} }
if (exp > 0) { if (exp > 0) {
AddEXP(exp); AddEXP(ExpSource::Quest, exp);
} }
QueuePacket(outapp, true, Client::CLIENT_CONNECTED); QueuePacket(outapp, true, Client::CLIENT_CONNECTED);
@ -8353,7 +8353,7 @@ void Client::QuestReward(Mob* target, const QuestReward_Struct &reward, bool fac
} }
if (reward.exp_reward > 0) { if (reward.exp_reward > 0) {
AddEXP(reward.exp_reward); AddEXP(ExpSource::Quest, reward.exp_reward);
} }
QueuePacket(outapp, true, Client::CLIENT_CONNECTED); QueuePacket(outapp, true, Client::CLIENT_CONNECTED);

View File

@ -658,14 +658,14 @@ public:
void SendCrystalCounts(); void SendCrystalCounts();
uint64 GetExperienceForKill(Mob *against); uint64 GetExperienceForKill(Mob *against);
void AddEXP(uint64 in_add_exp, uint8 conlevel = 0xFF, bool resexp = false); void AddEXP(ExpSource exp_source, uint64 in_add_exp, uint8 conlevel = 0xFF, bool resexp = false);
uint64 CalcEXP(uint8 conlevel = 0xFF, bool ignore_mods = false); uint64 CalcEXP(uint8 conlevel = 0xFF, bool ignore_mods = false);
void CalculateNormalizedAAExp(uint64 &add_aaxp, uint8 conlevel, bool resexp); void CalculateNormalizedAAExp(uint64 &add_aaxp, uint8 conlevel, bool resexp);
void CalculateStandardAAExp(uint64 &add_aaxp, uint8 conlevel, bool resexp); void CalculateStandardAAExp(uint64 &add_aaxp, uint8 conlevel, bool resexp);
void CalculateLeadershipExp(uint64 &add_exp, uint8 conlevel); void CalculateLeadershipExp(uint64 &add_exp, uint8 conlevel);
void CalculateExp(uint64 in_add_exp, uint64 &add_exp, uint64 &add_aaxp, uint8 conlevel, bool resexp); void CalculateExp(uint64 in_add_exp, uint64 &add_exp, uint64 &add_aaxp, uint8 conlevel, bool resexp);
void SetEXP(uint64 set_exp, uint64 set_aaxp, bool resexp=false); void SetEXP(ExpSource exp_source, uint64 set_exp, uint64 set_aaxp, bool resexp = false);
void AddLevelBasedExp(uint8 exp_percentage, uint8 max_level = 0, bool ignore_mods = false); void AddLevelBasedExp(ExpSource exp_source, uint8 exp_percentage, uint8 max_level = 0, bool ignore_mods = false);
void SetLeadershipEXP(uint64 group_exp, uint64 raid_exp); void SetLeadershipEXP(uint64 group_exp, uint64 raid_exp);
void AddLeadershipEXP(uint64 group_exp, uint64 raid_exp); void AddLeadershipEXP(uint64 group_exp, uint64 raid_exp);
void SendLeadershipEXPUpdate(); void SendLeadershipEXPUpdate();

View File

@ -1056,10 +1056,9 @@ void Client::OPRezzAnswer(uint32 Action, uint32 SpellID, uint16 ZoneID, uint16 I
} }
if(spells[SpellID].base_value[0] < 100 && spells[SpellID].base_value[0] > 0 && PendingRezzXP > 0) { if(spells[SpellID].base_value[0] < 100 && spells[SpellID].base_value[0] > 0 && PendingRezzXP > 0) {
SetEXP(((int)(GetEXP()+((float)((PendingRezzXP / 100) * spells[SpellID].base_value[0])))), SetEXP(ExpSource::Resurrection, ((int)(GetEXP()+((float)((PendingRezzXP / 100) * spells[SpellID].base_value[0])))), GetAAXP(), true);
GetAAXP(),true);
} else if (spells[SpellID].base_value[0] == 100 && PendingRezzXP > 0) { } else if (spells[SpellID].base_value[0] == 100 && PendingRezzXP > 0) {
SetEXP((GetEXP() + PendingRezzXP), GetAAXP(), true); SetEXP(ExpSource::Resurrection, (GetEXP() + PendingRezzXP), GetAAXP(), true);
} }
//Was sending the packet back to initiate client zone... //Was sending the packet back to initiate client zone...

View File

@ -497,7 +497,7 @@ void Client::CalculateExp(uint64 in_add_exp, uint64 &add_exp, uint64 &add_aaxp,
add_exp = GetEXP() + add_exp; add_exp = GetEXP() + add_exp;
} }
void Client::AddEXP(uint64 in_add_exp, uint8 conlevel, bool resexp) { void Client::AddEXP(ExpSource exp_source, uint64 in_add_exp, uint8 conlevel, bool resexp) {
if (!IsEXPEnabled()) { if (!IsEXPEnabled()) {
return; return;
} }
@ -569,10 +569,32 @@ void Client::AddEXP(uint64 in_add_exp, uint8 conlevel, bool resexp) {
} }
// Now update our character's normal and AA xp // Now update our character's normal and AA xp
SetEXP(exp, aaexp, resexp); SetEXP(exp_source, exp, aaexp, resexp);
} }
void Client::SetEXP(uint64 set_exp, uint64 set_aaxp, bool isrezzexp) { void Client::SetEXP(ExpSource exp_source, uint64 set_exp, uint64 set_aaxp, bool isrezzexp) {
uint64 current_exp = GetEXP();
uint64 current_aa_exp = GetAAXP();
uint64 total_current_exp = current_exp + current_aa_exp;
uint64 total_add_exp = set_exp + set_aaxp;
#ifdef LUA_EQEMU
uint64 lua_ret = 0;
bool ignore_default = false;
lua_ret = LuaParser::Instance()->SetEXP(this, exp_source, current_exp, set_exp, isrezzexp, ignore_default);
if (ignore_default) {
set_exp = lua_ret;
}
lua_ret = 0;
ignore_default = false;
lua_ret = LuaParser::Instance()->SetAAEXP(this, exp_source, current_aa_exp, set_aaxp, isrezzexp, ignore_default);
if (ignore_default) {
set_aaxp = lua_ret;
}
total_add_exp = set_exp + set_aaxp;
#endif
LogDebug("Attempting to Set Exp for [{}] (XP: [{}], AAXP: [{}], Rez: [{}])", GetCleanName(), set_exp, set_aaxp, isrezzexp ? "true" : "false"); LogDebug("Attempting to Set Exp for [{}] (XP: [{}], AAXP: [{}], Rez: [{}])", GetCleanName(), set_exp, set_aaxp, isrezzexp ? "true" : "false");
auto max_AAXP = GetRequiredAAExperience(); auto max_AAXP = GetRequiredAAExperience();
@ -591,10 +613,6 @@ void Client::SetEXP(uint64 set_exp, uint64 set_aaxp, bool isrezzexp) {
} }
} }
uint64 current_exp = GetEXP();
uint64 current_aa_exp = GetAAXP();
uint64 total_current_exp = current_exp + current_aa_exp;
uint64 total_add_exp = set_exp + set_aaxp;
if (total_add_exp > total_current_exp) { if (total_add_exp > total_current_exp) {
uint64 exp_gained = set_exp - current_exp; uint64 exp_gained = set_exp - current_exp;
uint64 aa_exp_gained = set_aaxp - current_aa_exp; uint64 aa_exp_gained = set_aaxp - current_aa_exp;
@ -1084,7 +1102,7 @@ uint32 Client::GetEXPForLevel(uint16 check_level)
return finalxp; return finalxp;
} }
void Client::AddLevelBasedExp(uint8 exp_percentage, uint8 max_level, bool ignore_mods) void Client::AddLevelBasedExp(ExpSource exp_source, uint8 exp_percentage, uint8 max_level, bool ignore_mods)
{ {
uint64 award; uint64 award;
uint64 xp_for_level; uint64 xp_for_level;
@ -1113,10 +1131,10 @@ void Client::AddLevelBasedExp(uint8 exp_percentage, uint8 max_level, bool ignore
} }
uint64 newexp = GetEXP() + award; uint64 newexp = GetEXP() + award;
SetEXP(newexp, GetAAXP()); SetEXP(exp_source, newexp, GetAAXP());
} }
void Group::SplitExp(const uint64 exp, Mob* other) { void Group::SplitExp(ExpSource exp_source, const uint64 exp, Mob* other) {
if (other->CastToNPC()->MerchantType != 0) { if (other->CastToNPC()->MerchantType != 0) {
return; return;
} }
@ -1174,13 +1192,13 @@ void Group::SplitExp(const uint64 exp, Mob* other) {
if (diff >= max_diff) { if (diff >= max_diff) {
const uint64 tmp = (m->GetLevel() + 3) * (m->GetLevel() + 3) * 75 * 35 / 10; const uint64 tmp = (m->GetLevel() + 3) * (m->GetLevel() + 3) * 75 * 35 / 10;
const uint64 tmp2 = group_experience / member_count; const uint64 tmp2 = group_experience / member_count;
m->CastToClient()->AddEXP(tmp < tmp2 ? tmp : tmp2, consider_level); m->CastToClient()->AddEXP(exp_source, tmp < tmp2 ? tmp : tmp2, consider_level);
} }
} }
} }
} }
void Raid::SplitExp(const uint64 exp, Mob* other) { void Raid::SplitExp(ExpSource exp_source, const uint64 exp, Mob* other) {
if (other->CastToNPC()->MerchantType != 0) { if (other->CastToNPC()->MerchantType != 0) {
return; return;
} }
@ -1225,7 +1243,7 @@ void Raid::SplitExp(const uint64 exp, Mob* other) {
if (diff >= max_diff) { if (diff >= max_diff) {
const uint64 tmp = (m.member->GetLevel() + 3) * (m.member->GetLevel() + 3) * 75 * 35 / 10; const uint64 tmp = (m.member->GetLevel() + 3) * (m.member->GetLevel() + 3) * 75 * 35 / 10;
const uint64 tmp2 = (raid_experience / member_modifier) + 1; const uint64 tmp2 = (raid_experience / member_modifier) + 1;
m.member->AddEXP(tmp < tmp2 ? tmp : tmp2, consider_level); m.member->AddEXP(exp_source, tmp < tmp2 ? tmp : tmp2, consider_level);
} }
} }
} }

View File

@ -36,6 +36,7 @@ void SetAAEXP(Client *c, const Seperator *sep)
if (is_aa) { if (is_aa) {
t->SetEXP( t->SetEXP(
ExpSource::GM,
t->GetEXP(), t->GetEXP(),
aa_experience, aa_experience,
false false

View File

@ -26,11 +26,13 @@ void SetEXP(Client *c, const Seperator *sep)
if (is_aa) { if (is_aa) {
t->SetEXP( t->SetEXP(
ExpSource::GM,
t->GetEXP(), t->GetEXP(),
amount amount
); );
} else if (is_exp) { } else if (is_exp) {
t->SetEXP( t->SetEXP(
ExpSource::GM,
amount, amount,
t->GetAAXP() t->GetAAXP()
); );

View File

@ -76,7 +76,7 @@ public:
bool IsGroup() { return true; } bool IsGroup() { return true; }
void SendGroupJoinOOZ(Mob* NewMember); void SendGroupJoinOOZ(Mob* NewMember);
void CastGroupSpell(Mob* caster,uint16 spellid); void CastGroupSpell(Mob* caster,uint16 spellid);
void SplitExp(const uint64 exp, Mob* other); void SplitExp(ExpSource exp_source, const uint64 exp, Mob* other);
void GroupMessage(Mob* sender,uint8 language,uint8 lang_skill,const char* message); void GroupMessage(Mob* sender,uint8 language,uint8 lang_skill,const char* message);
void GroupMessageString(Mob* sender, uint32 type, uint32 string_id, const char* message,const char* message2=0,const char* message3=0,const char* message4=0,const char* message5=0,const char* message6=0,const char* message7=0,const char* message8=0,const char* message9=0, uint32 distance = 0); void GroupMessageString(Mob* sender, uint32 type, uint32 string_id, const char* message,const char* message2=0,const char* message3=0,const char* message4=0,const char* message5=0,const char* message6=0,const char* message7=0,const char* message8=0,const char* message9=0, uint32 distance = 0);
uint32 GetTotalGroupDamage(Mob* other); uint32 GetTotalGroupDamage(Mob* other);

View File

@ -252,27 +252,27 @@ void Lua_Client::SetDeity(int v) {
void Lua_Client::AddEXP(uint32 add_exp) { void Lua_Client::AddEXP(uint32 add_exp) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->AddEXP(add_exp); self->AddEXP(ExpSource::Quest, add_exp);
} }
void Lua_Client::AddEXP(uint32 add_exp, int conlevel) { void Lua_Client::AddEXP(uint32 add_exp, int conlevel) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->AddEXP(add_exp, conlevel); self->AddEXP(ExpSource::Quest, add_exp, conlevel);
} }
void Lua_Client::AddEXP(uint32 add_exp, int conlevel, bool resexp) { void Lua_Client::AddEXP(uint32 add_exp, int conlevel, bool resexp) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->AddEXP(add_exp, conlevel, resexp); self->AddEXP(ExpSource::Quest, add_exp, conlevel, resexp);
} }
void Lua_Client::SetEXP(uint64 set_exp, uint64 set_aaxp) { void Lua_Client::SetEXP(uint64 set_exp, uint64 set_aaxp) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->SetEXP(set_exp, set_aaxp); self->SetEXP(ExpSource::Quest, set_exp, set_aaxp);
} }
void Lua_Client::SetEXP(uint64 set_exp, uint64 set_aaxp, bool resexp) { void Lua_Client::SetEXP(uint64 set_exp, uint64 set_aaxp, bool resexp) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->SetEXP(set_exp, set_aaxp, resexp); self->SetEXP(ExpSource::Quest, set_exp, set_aaxp, resexp);
} }
void Lua_Client::SetBindPoint() { void Lua_Client::SetBindPoint() {
@ -1318,17 +1318,17 @@ uint32 Lua_Client::GetIP() {
void Lua_Client::AddLevelBasedExp(int exp_pct) { void Lua_Client::AddLevelBasedExp(int exp_pct) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->AddLevelBasedExp(exp_pct); self->AddLevelBasedExp(ExpSource::Quest, exp_pct);
} }
void Lua_Client::AddLevelBasedExp(int exp_pct, int max_level) { void Lua_Client::AddLevelBasedExp(int exp_pct, int max_level) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->AddLevelBasedExp(exp_pct, max_level); self->AddLevelBasedExp(ExpSource::Quest, exp_pct, max_level);
} }
void Lua_Client::AddLevelBasedExp(int exp_pct, int max_level, bool ignore_mods) { void Lua_Client::AddLevelBasedExp(int exp_pct, int max_level, bool ignore_mods) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->AddLevelBasedExp(exp_pct, max_level, ignore_mods); self->AddLevelBasedExp(ExpSource::Quest, exp_pct, max_level, ignore_mods);
} }
void Lua_Client::IncrementAA(int aa) { void Lua_Client::IncrementAA(int aa) {

View File

@ -7945,4 +7945,20 @@ luabind::scope lua_register_journal_mode() {
)]; )];
} }
luabind::scope lua_register_exp_source() {
return luabind::class_<ExpSource>("ExpSource")
.enum_("constants")
[(
luabind::value("Quest", static_cast<int>(ExpSource::Quest)),
luabind::value("GM", static_cast<int>(ExpSource::GM)),
luabind::value("Kill", static_cast<int>(ExpSource::Kill)),
luabind::value("Death", static_cast<int>(ExpSource::Death)),
luabind::value("Resurrection", static_cast<int>(ExpSource::Resurrection)),
luabind::value("LDoNChest", static_cast<int>(ExpSource::LDoNChest)),
luabind::value("Task", static_cast<int>(ExpSource::Task)),
luabind::value("Sacrifice", static_cast<int>(ExpSource::Sacrifice))
)];
}
#endif #endif

View File

@ -34,7 +34,7 @@ void Lua_Group::CastGroupSpell(Lua_Mob caster, int spell_id) {
void Lua_Group::SplitExp(uint64 exp, Lua_Mob other) { void Lua_Group::SplitExp(uint64 exp, Lua_Mob other) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->SplitExp(exp, other); self->SplitExp(ExpSource::Quest, exp, other);
} }
void Lua_Group::GroupMessage(Lua_Mob sender, const char* message) { void Lua_Group::GroupMessage(Lua_Mob sender, const char* message) {

View File

@ -633,6 +633,113 @@ void LuaMod::GetEXPForLevel(Client *self, uint16 level, uint32 &returnValue, boo
} }
} }
void LuaMod::SetEXP(Mob *self, ExpSource exp_source, uint64 current_exp, uint64 set_exp, bool is_rezz_exp, uint64 &return_value, bool &ignore_default)
{
int start = lua_gettop(L);
try {
if (!m_has_set_exp) {
return;
}
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str());
lua_getfield(L, -1, "SetEXP");
Lua_Mob l_self(self);
luabind::adl::object e = luabind::newtable(L);
e["self"] = l_self;
e["exp_source"] = exp_source;
e["current_exp"] = current_exp;
e["set_exp"] = set_exp;
e["is_rezz_exp"] = is_rezz_exp;
e.push(L);
if (lua_pcall(L, 1, 1, 0)) {
std::string error = lua_tostring(L, -1);
parser_->AddError(error);
lua_pop(L, 2);
return;
}
if (lua_type(L, -1) == LUA_TTABLE) {
luabind::adl::object ret(luabind::from_stack(L, -1));
auto ignore_default_obj = ret["ignore_default"];
if (luabind::type(ignore_default_obj) == LUA_TBOOLEAN) {
ignore_default = ignore_default || luabind::object_cast<bool>(ignore_default_obj);
}
auto return_value_obj = ret["return_value"];
if (luabind::type(return_value_obj) == LUA_TNUMBER) {
return_value = luabind::object_cast<int64>(return_value_obj);
}
}
}
catch (std::exception &ex) {
parser_->AddError(ex.what());
}
int end = lua_gettop(L);
int n = end - start;
if (n > 0) {
lua_pop(L, n);
}
}
void LuaMod::SetAAEXP(Mob *self, ExpSource exp_source, uint64 current_aa_exp, uint64 set_aa_exp, bool is_rezz_exp, uint64 &return_value, bool &ignore_default)
{
int start = lua_gettop(L);
try {
if (!m_has_set_aa_exp) {
return;
}
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str());
lua_getfield(L, -1, "SetAAEXP");
Lua_Mob l_self(self);
luabind::adl::object e = luabind::newtable(L);
e["self"] = l_self;
e["exp_source"] = exp_source;
e["current_aa_exp"] = current_aa_exp;
e["set_aa_exp"] = set_aa_exp;
e["is_rezz_exp"] = is_rezz_exp;
e.push(L);
if (lua_pcall(L, 1, 1, 0)) {
std::string error = lua_tostring(L, -1);
parser_->AddError(error);
lua_pop(L, 2);
return;
}
if (lua_type(L, -1) == LUA_TTABLE) {
luabind::adl::object ret(luabind::from_stack(L, -1));
auto ignore_default_obj = ret["ignore_default"];
if (luabind::type(ignore_default_obj) == LUA_TBOOLEAN) {
ignore_default = ignore_default || luabind::object_cast<bool>(ignore_default_obj);
}
auto return_value_obj = ret["return_value"];
if (luabind::type(return_value_obj) == LUA_TNUMBER) {
return_value = luabind::object_cast<int64>(return_value_obj);
}
}
}
catch (std::exception &ex) {
parser_->AddError(ex.what());
}
int end = lua_gettop(L);
int n = end - start;
if (n > 0) {
lua_pop(L, n);
}
}
void LuaMod::GetExperienceForKill(Client *self, Mob *against, uint64 &returnValue, bool &ignoreDefault) void LuaMod::GetExperienceForKill(Client *self, Mob *against, uint64 &returnValue, bool &ignoreDefault)
{ {
int start = lua_gettop(L); int start = lua_gettop(L);

View File

@ -10,7 +10,7 @@ class LuaMod
{ {
public: public:
LuaMod(lua_State *ls, LuaParser *lp, const std::string &package_name) { LuaMod(lua_State *ls, LuaParser *lp, const std::string &package_name) {
L = ls; L = ls;
parser_ = lp; parser_ = lp;
package_name_ = package_name; package_name_ = package_name;
Init(); Init();
@ -33,6 +33,8 @@ public:
void RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default); void RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default);
void CommonDamage(Mob *self, Mob* attacker, int64 value, uint16 spell_id, int skill_used, bool avoidable, int8 buff_slot, bool buff_tic, int special, int64 &return_value, bool &ignore_default); void CommonDamage(Mob *self, Mob* attacker, int64 value, uint16 spell_id, int skill_used, bool avoidable, int8 buff_slot, bool buff_tic, int special, int64 &return_value, bool &ignore_default);
void HealDamage(Mob *self, Mob* caster, uint64 value, uint16 spell_id, uint64 &return_value, bool &ignore_default); void HealDamage(Mob *self, Mob* caster, uint64 value, uint16 spell_id, uint64 &return_value, bool &ignore_default);
void SetEXP(Mob *self, ExpSource exp_source, uint64 current_exp, uint64 set_exp, bool is_rezz_exp, uint64 &return_value, bool &ignore_default);
void SetAAEXP(Mob *self, ExpSource exp_source, uint64 current_aa_exp, uint64 set_aa_exp, bool is_rezz_exp, uint64 &return_value, bool &ignore_default);
private: private:
LuaParser *parser_; LuaParser *parser_;
lua_State *L; lua_State *L;
@ -51,6 +53,8 @@ private:
bool m_has_register_bug; bool m_has_register_bug;
bool m_has_common_damage; bool m_has_common_damage;
bool m_has_heal_damage; bool m_has_heal_damage;
bool m_has_set_exp;
bool m_has_set_aa_exp;
bool m_has_is_immune_to_spell; bool m_has_is_immune_to_spell;
bool m_has_update_personal_faction; bool m_has_update_personal_faction;
}; };

View File

@ -1636,6 +1636,25 @@ void LuaParser::RegisterBug(Client *self, BaseBugReportsRepository::BugReports b
} }
} }
uint64 LuaParser::SetEXP(Mob *self, ExpSource exp_source, uint64 current_exp, uint64 set_exp, bool is_rezz_exp, bool &ignore_default)
{
uint64 retval = 0;
for (auto &mod : mods_) {
mod.SetEXP(self, exp_source, current_exp, set_exp, is_rezz_exp, retval, ignore_default);
}
return retval;
}
uint64 LuaParser::SetAAEXP(Mob *self, ExpSource exp_source, uint64 current_aa_exp, uint64 set_aa_exp, bool is_rezz_exp, bool &ignore_default)
{
uint64 retval = 0;
for (auto &mod : mods_) {
mod.SetAAEXP(self, exp_source, current_aa_exp, set_aa_exp, is_rezz_exp, retval, ignore_default);
}
return retval;
}
int LuaParser::EventBot( int LuaParser::EventBot(
QuestEventID evt, QuestEventID evt,
Bot *bot, Bot *bot,

View File

@ -202,8 +202,9 @@ public:
void RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default); void RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default);
int64 CommonDamage(Mob *self, Mob* attacker, int64 value, uint16 spell_id, int skill_used, bool avoidable, int8 buff_slot, bool buff_tic, int special, bool &ignore_default); int64 CommonDamage(Mob *self, Mob* attacker, int64 value, uint16 spell_id, int skill_used, bool avoidable, int8 buff_slot, bool buff_tic, int special, bool &ignore_default);
uint64 HealDamage(Mob *self, Mob* caster, uint64 value, uint16 spell_id, bool &ignore_default); uint64 HealDamage(Mob *self, Mob* caster, uint64 value, uint16 spell_id, bool &ignore_default);
uint64 SetEXP(Mob *self, ExpSource exp_source, uint64 current_exp, uint64 set_exp, bool is_rezz_exp, bool &ignore_default);
uint64 SetAAEXP(Mob *self, ExpSource exp_source, uint64 current_aa_exp, uint64 set_aa_exp, bool is_rezz_exp, bool &ignore_default);
bool IsImmuneToSpell(Mob *self, Mob* caster, uint16 spell_id, bool &ignore_default); bool IsImmuneToSpell(Mob *self, Mob* caster, uint16 spell_id, bool &ignore_default);
private: private:
LuaParser(); LuaParser();
LuaParser(const LuaParser&); LuaParser(const LuaParser&);

View File

@ -48,7 +48,7 @@ int Lua_Raid::GetGroup(Lua_Client c) {
void Lua_Raid::SplitExp(uint64 exp, Lua_Mob other) { void Lua_Raid::SplitExp(uint64 exp, Lua_Mob other) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->SplitExp(exp, other); self->SplitExp(ExpSource::Quest, exp, other);
} }
uint32 Lua_Raid::GetTotalRaidDamage(Lua_Mob other) { uint32 Lua_Raid::GetTotalRaidDamage(Lua_Mob other) {

View File

@ -216,27 +216,27 @@ void Perl_Client_SetDeity(Client* self, uint32 deity_id) // @categories Account
void Perl_Client_AddEXP(Client* self, uint32 add_exp) // @categories Experience and Level void Perl_Client_AddEXP(Client* self, uint32 add_exp) // @categories Experience and Level
{ {
self->AddEXP(add_exp); self->AddEXP(ExpSource::Quest, add_exp);
} }
void Perl_Client_AddEXP(Client* self, uint32 add_exp, uint8 conlevel) // @categories Experience and Level void Perl_Client_AddEXP(Client* self, uint32 add_exp, uint8 conlevel) // @categories Experience and Level
{ {
self->AddEXP(add_exp, conlevel); self->AddEXP(ExpSource::Quest, add_exp, conlevel);
} }
void Perl_Client_AddEXP(Client* self, uint32 add_exp, uint8 conlevel, bool resexp) // @categories Experience and Level void Perl_Client_AddEXP(Client* self, uint32 add_exp, uint8 conlevel, bool resexp) // @categories Experience and Level
{ {
self->AddEXP(add_exp, conlevel, resexp); self->AddEXP(ExpSource::Quest, add_exp, conlevel, resexp);
} }
void Perl_Client_SetEXP(Client* self, uint64 set_exp, uint64 set_aaxp) // @categories Experience and Level void Perl_Client_SetEXP(Client* self, uint64 set_exp, uint64 set_aaxp) // @categories Experience and Level
{ {
self->SetEXP(set_exp, set_aaxp); self->SetEXP(ExpSource::Quest, set_exp, set_aaxp);
} }
void Perl_Client_SetEXP(Client* self, uint64 set_exp, uint64 set_aaxp, bool resexp) // @categories Experience and Level void Perl_Client_SetEXP(Client* self, uint64 set_exp, uint64 set_aaxp, bool resexp) // @categories Experience and Level
{ {
self->SetEXP(set_exp, set_aaxp, resexp); self->SetEXP(ExpSource::Quest, set_exp, set_aaxp, resexp);
} }
void Perl_Client_SetBindPoint(Client* self) // @categories Account and Character, Stats and Attributes void Perl_Client_SetBindPoint(Client* self) // @categories Account and Character, Stats and Attributes
@ -1280,17 +1280,17 @@ uint32_t Perl_Client_GetIP(Client* self) // @categories Script Utility
void Perl_Client_AddLevelBasedExp(Client* self, uint8 exp_percentage) // @categories Experience and Level void Perl_Client_AddLevelBasedExp(Client* self, uint8 exp_percentage) // @categories Experience and Level
{ {
self->AddLevelBasedExp(exp_percentage); self->AddLevelBasedExp(ExpSource::Quest, exp_percentage);
} }
void Perl_Client_AddLevelBasedExp(Client* self, uint8 exp_percentage, uint8 max_level) // @categories Experience and Level void Perl_Client_AddLevelBasedExp(Client* self, uint8 exp_percentage, uint8 max_level) // @categories Experience and Level
{ {
self->AddLevelBasedExp(exp_percentage, max_level); self->AddLevelBasedExp(ExpSource::Quest, exp_percentage, max_level);
} }
void Perl_Client_AddLevelBasedExp(Client* self, uint8 exp_percentage, uint8 max_level, bool ignore_mods) // @categories Experience and Level void Perl_Client_AddLevelBasedExp(Client* self, uint8 exp_percentage, uint8 max_level, bool ignore_mods) // @categories Experience and Level
{ {
self->AddLevelBasedExp(exp_percentage, max_level, ignore_mods); self->AddLevelBasedExp(ExpSource::Quest, exp_percentage, max_level, ignore_mods);
} }
void Perl_Client_IncrementAA(Client* self, uint32 aa_skill_id) // @categories Alternative Advancement void Perl_Client_IncrementAA(Client* self, uint32 aa_skill_id) // @categories Alternative Advancement

View File

@ -29,7 +29,7 @@ void Perl_Group_CastGroupSpell(Group* self, Mob* caster, uint16 spell_id) // @ca
void Perl_Group_SplitExp(Group* self, uint32_t exp, Mob* other) // @categories Account and Character, Script Utility, Group void Perl_Group_SplitExp(Group* self, uint32_t exp, Mob* other) // @categories Account and Character, Script Utility, Group
{ {
self->SplitExp(exp, other); self->SplitExp(ExpSource::Quest, exp, other);
} }
void Perl_Group_GroupMessage(Group* self, Mob* sender, const char* message) // @categories Script Utility, Group void Perl_Group_GroupMessage(Group* self, Mob* sender, const char* message) // @categories Script Utility, Group

View File

@ -45,7 +45,7 @@ uint32_t Perl_Raid_GetGroup(Raid* self, Client* client) // @categories Group, Ra
void Perl_Raid_SplitExp(Raid* self, uint32 experience, Mob* other) // @categories Experience and Level, Raid void Perl_Raid_SplitExp(Raid* self, uint32 experience, Mob* other) // @categories Experience and Level, Raid
{ {
self->SplitExp(experience, other); self->SplitExp(ExpSource::Quest, experience, other);
} }
uint32_t Perl_Raid_GetTotalRaidDamage(Raid* self, Mob* other) // @categories Raid uint32_t Perl_Raid_GetTotalRaidDamage(Raid* self, Mob* other) // @categories Raid

View File

@ -1386,7 +1386,7 @@ void QuestManager::changedeity(int deity_id) {
void QuestManager::exp(int amt) { void QuestManager::exp(int amt) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if (initiator) if (initiator)
initiator->AddEXP(amt); initiator->AddEXP(ExpSource::Quest, amt);
} }
void QuestManager::level(int newlevel) { void QuestManager::level(int newlevel) {

View File

@ -165,7 +165,7 @@ public:
void RaidMessageString(Mob* sender, uint32 type, uint32 string_id, const char* message,const char* message2=0,const char* message3=0,const char* message4=0,const char* message5=0,const char* message6=0,const char* message7=0,const char* message8=0,const char* message9=0, uint32 distance = 0); void RaidMessageString(Mob* sender, uint32 type, uint32 string_id, const char* message,const char* message2=0,const char* message3=0,const char* message4=0,const char* message5=0,const char* message6=0,const char* message7=0,const char* message8=0,const char* message9=0, uint32 distance = 0);
void CastGroupSpell(Mob* caster,uint16 spellid, uint32 gid); void CastGroupSpell(Mob* caster,uint16 spellid, uint32 gid);
void SplitExp(const uint64 exp, Mob* other); void SplitExp(ExpSource exp_source, const uint64 exp, Mob* other);
uint32 GetTotalRaidDamage(Mob* other); uint32 GetTotalRaidDamage(Mob* other);
void BalanceHP(int32 penalty, uint32 gid, float range = 0, Mob* caster = nullptr, int32 limit = 0); void BalanceHP(int32 penalty, uint32 gid, float range = 0, Mob* caster = nullptr, int32 limit = 0);
void BalanceMana(int32 penalty, uint32 gid, float range = 0, Mob* caster = nullptr, int32 limit = 0); void BalanceMana(int32 penalty, uint32 gid, float range = 0, Mob* caster = nullptr, int32 limit = 0);

View File

@ -1091,14 +1091,14 @@ void ClientTaskState::RewardTask(Client *c, const TaskInformation *ti, ClientTas
auto experience_reward = ti->experience_reward; auto experience_reward = ti->experience_reward;
if (experience_reward > 0) { if (experience_reward > 0) {
c->AddEXP(experience_reward); c->AddEXP(ExpSource::Task, experience_reward);
} else if (experience_reward < 0) { } else if (experience_reward < 0) {
uint32 pos_reward = experience_reward * -1; uint32 pos_reward = experience_reward * -1;
// Minimal Level Based Exp reward Setting is 101 (1% exp at level 1) // Minimal Level Based Exp reward Setting is 101 (1% exp at level 1)
if (pos_reward > 100 && pos_reward < 25700) { if (pos_reward > 100 && pos_reward < 25700) {
uint8 max_level = pos_reward / 100; uint8 max_level = pos_reward / 100;
uint8 exp_percent = pos_reward - (max_level * 100); uint8 exp_percent = pos_reward - (max_level * 100);
c->AddLevelBasedExp(exp_percent, max_level, RuleB(TaskSystem, ExpRewardsIgnoreLevelBasedEXPMods)); c->AddLevelBasedExp(ExpSource::Task, exp_percent, max_level, RuleB(TaskSystem, ExpRewardsIgnoreLevelBasedEXPMods));
} }
} }