mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
[Quest API] Add EVENT_LEVEL_DOWN to Perl/Lua. (#2620)
* [Quest API] Add EVENT_LEVEL_DOWN to Perl/Lua. # Perl - Add `EVENT_LEVEL_DOWN`, exports `$levels_lost`. - Add `$levels_gained` export to `EVENT_LEVEL_UP`. # Lua - Add `event_level_down`, exports `e.levels_lost`. - Add `e.levels_gained` export to `event_level_up`. # Notes - Allows operators to perform actions on level down. - Allows operators to tell how many levels were lost or gained in case people are gaining/losing multiple levels and they want to keep track or use this as a mechanic in their code somewhere. * Update exp.cpp * Update embparser.cpp
This commit is contained in:
parent
8c707f9fe5
commit
d3fac8a0cb
@ -163,11 +163,11 @@ const char *QuestEventSubroutines[_LargestEventID] = {
|
||||
"EVENT_TASK_BEFORE_UPDATE",
|
||||
"EVENT_AA_BUY",
|
||||
"EVENT_AA_GAIN",
|
||||
"EVENT_PAYLOAD"
|
||||
#ifdef BOTS
|
||||
,
|
||||
"EVENT_PAYLOAD",
|
||||
"EVENT_LEVEL_DOWN",
|
||||
#ifdef BOTS
|
||||
"EVENT_SPELL_EFFECT_BOT",
|
||||
"EVENT_SPELL_EFFECT_BUFF_TIC_BOT"
|
||||
"EVENT_SPELL_EFFECT_BUFF_TIC_BOT",
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -1703,6 +1703,7 @@ void PerlembParser::ExportEventVariables(
|
||||
ExportVar(package_name.c_str(), "popupid", data);
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_ENVIRONMENTAL_DAMAGE: {
|
||||
Seperator sep(data);
|
||||
ExportVar(package_name.c_str(), "env_damage", sep.arg[0]);
|
||||
@ -1845,6 +1846,7 @@ void PerlembParser::ExportEventVariables(
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_DROP_ITEM: {
|
||||
ExportVar(package_name.c_str(), "quantity", item_inst->IsStackable() ? item_inst->GetCharges() : 1);
|
||||
ExportVar(package_name.c_str(), "itemname", item_inst->GetItem()->Name);
|
||||
@ -1853,17 +1855,20 @@ void PerlembParser::ExportEventVariables(
|
||||
ExportVar(package_name.c_str(), "slotid", extradata);
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_SPAWN_ZONE: {
|
||||
ExportVar(package_name.c_str(), "spawned_entity_id", mob->GetID());
|
||||
ExportVar(package_name.c_str(), "spawned_npc_id", mob->GetNPCTypeID());
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_USE_SKILL: {
|
||||
Seperator sep(data);
|
||||
ExportVar(package_name.c_str(), "skill_id", sep.arg[0]);
|
||||
ExportVar(package_name.c_str(), "skill_level", sep.arg[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_COMBINE_VALIDATE: {
|
||||
Seperator sep(data);
|
||||
ExportVar(package_name.c_str(), "recipe_id", extradata);
|
||||
@ -1882,6 +1887,7 @@ void PerlembParser::ExportEventVariables(
|
||||
ExportVar(package_name.c_str(), "tradeskill_id", tradeskill_id.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_BOT_COMMAND: {
|
||||
Seperator sep(data);
|
||||
ExportVar(package_name.c_str(), "bot_command", (sep.arg[0] + 1));
|
||||
@ -1891,6 +1897,7 @@ void PerlembParser::ExportEventVariables(
|
||||
ExportVar(package_name.c_str(), "langid", extradata);
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_WARP: {
|
||||
Seperator sep(data);
|
||||
ExportVar(package_name.c_str(), "from_x", sep.arg[0]);
|
||||
@ -1981,6 +1988,16 @@ void PerlembParser::ExportEventVariables(
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_LEVEL_UP: {
|
||||
ExportVar(package_name.c_str(), "levels_gained", data);
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_LEVEL_DOWN: {
|
||||
ExportVar(package_name.c_str(), "levels_lost", data);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -107,6 +107,7 @@ typedef enum {
|
||||
EVENT_AA_BUY,
|
||||
EVENT_AA_GAIN,
|
||||
EVENT_PAYLOAD,
|
||||
EVENT_LEVEL_DOWN,
|
||||
#ifdef BOTS
|
||||
EVENT_SPELL_EFFECT_BOT,
|
||||
EVENT_SPELL_EFFECT_BUFF_TIC_BOT,
|
||||
|
||||
87
zone/exp.cpp
87
zone/exp.cpp
@ -835,55 +835,78 @@ void Client::SetLevel(uint8 set_level, bool command)
|
||||
}
|
||||
|
||||
auto outapp = new EQApplicationPacket(OP_LevelUpdate, sizeof(LevelUpdate_Struct));
|
||||
LevelUpdate_Struct* lu = (LevelUpdate_Struct*)outapp->pBuffer;
|
||||
auto* lu = (LevelUpdate_Struct *) outapp->pBuffer;
|
||||
lu->level = set_level;
|
||||
if(m_pp.level2 != 0)
|
||||
|
||||
if (m_pp.level2 != 0) {
|
||||
lu->level_old = m_pp.level2;
|
||||
else
|
||||
} else {
|
||||
lu->level_old = level;
|
||||
}
|
||||
|
||||
level = set_level;
|
||||
|
||||
if(IsRaidGrouped()) {
|
||||
if (IsRaidGrouped()) {
|
||||
Raid *r = GetRaid();
|
||||
if(r){
|
||||
if (r) {
|
||||
r->UpdateLevel(GetName(), set_level);
|
||||
}
|
||||
}
|
||||
if(set_level > m_pp.level2) {
|
||||
if(m_pp.level2 == 0)
|
||||
|
||||
if (set_level > m_pp.level2) {
|
||||
if (m_pp.level2 == 0) {
|
||||
m_pp.points += 5;
|
||||
else
|
||||
} else {
|
||||
m_pp.points += (5 * (set_level - m_pp.level2));
|
||||
}
|
||||
|
||||
m_pp.level2 = set_level;
|
||||
}
|
||||
if(set_level > m_pp.level) {
|
||||
parse->EventPlayer(EVENT_LEVEL_UP, this, "", 0);
|
||||
/* QS: PlayerLogLevels */
|
||||
if (RuleB(QueryServ, PlayerLogLevels)){
|
||||
std::string event_desc = StringFormat("Leveled UP :: to Level:%i from Level:%i in zoneid:%i instid:%i", set_level, m_pp.level, GetZoneID(), GetInstanceID());
|
||||
|
||||
if (set_level > m_pp.level) {
|
||||
const auto export_string = fmt::format("{}", (set_level - m_pp.level));
|
||||
parse->EventPlayer(EVENT_LEVEL_UP, this, export_string, 0);
|
||||
|
||||
if (RuleB(QueryServ, PlayerLogLevels)) {
|
||||
const auto event_desc = fmt::format(
|
||||
"Leveled UP :: to Level:{} from Level:{} in zoneid:{} instid:{}",
|
||||
set_level,
|
||||
m_pp.level,
|
||||
GetZoneID(),
|
||||
GetInstanceID()
|
||||
);
|
||||
QServ->PlayerLogEvent(Player_Log_Levels, CharacterID(), event_desc);
|
||||
}
|
||||
}
|
||||
else if (set_level < m_pp.level){
|
||||
/* QS: PlayerLogLevels */
|
||||
if (RuleB(QueryServ, PlayerLogLevels)){
|
||||
std::string event_desc = StringFormat("Leveled DOWN :: to Level:%i from Level:%i in zoneid:%i instid:%i", set_level, m_pp.level, GetZoneID(), GetInstanceID());
|
||||
} else if (set_level < m_pp.level) {
|
||||
const auto export_string = fmt::format("{}", (m_pp.level - set_level));
|
||||
parse->EventPlayer(EVENT_LEVEL_DOWN, this, export_string, 0);
|
||||
|
||||
if (RuleB(QueryServ, PlayerLogLevels)) {
|
||||
const auto event_desc = fmt::format(
|
||||
"Leveled DOWN :: to Level:{} from Level:{} in zoneid:{} instid:{}",
|
||||
set_level,
|
||||
m_pp.level,
|
||||
GetZoneID(),
|
||||
GetInstanceID()
|
||||
);
|
||||
QServ->PlayerLogEvent(Player_Log_Levels, CharacterID(), event_desc);
|
||||
}
|
||||
}
|
||||
|
||||
m_pp.level = set_level;
|
||||
if (command){
|
||||
|
||||
if (command) {
|
||||
m_pp.exp = GetEXPForLevel(set_level);
|
||||
Message(Chat::Yellow, "Welcome to level %i!", set_level);
|
||||
Message(Chat::Yellow, fmt::format("Welcome to level {}!", set_level).c_str());
|
||||
lu->exp = 0;
|
||||
} else {
|
||||
const auto temporary_xp = (
|
||||
static_cast<float>(m_pp.exp - GetEXPForLevel(GetLevel())) /
|
||||
static_cast<float>(GetEXPForLevel(GetLevel() + 1) - GetEXPForLevel(GetLevel()))
|
||||
);
|
||||
lu->exp = static_cast<uint32>(330.0f * temporary_xp);
|
||||
}
|
||||
else {
|
||||
float tmpxp = (float) ( (float) m_pp.exp - GetEXPForLevel( GetLevel() )) / ( (float) GetEXPForLevel(GetLevel()+1) - GetEXPForLevel(GetLevel()));
|
||||
lu->exp = (uint32)(330.0f * tmpxp);
|
||||
}
|
||||
|
||||
QueuePacket(outapp);
|
||||
safe_delete(outapp);
|
||||
SendAppearancePacket(AT_WhoLevel, set_level); // who level change
|
||||
@ -892,16 +915,18 @@ void Client::SetLevel(uint8 set_level, bool command)
|
||||
|
||||
CalcBonuses();
|
||||
|
||||
if(!RuleB(Character, HealOnLevel)) {
|
||||
int mhp = CalcMaxHP();
|
||||
if(GetHP() > mhp)
|
||||
SetHP(mhp);
|
||||
}
|
||||
else {
|
||||
if (!RuleB(Character, HealOnLevel)) {
|
||||
const auto max_hp = CalcMaxHP();
|
||||
if (GetHP() > max_hp) {
|
||||
SetHP(max_hp);
|
||||
}
|
||||
} else {
|
||||
SetHP(CalcMaxHP()); // Why not, lets give them a free heal
|
||||
}
|
||||
|
||||
if (RuleI(World, PVPMinLevel) > 0 && level >= RuleI(World, PVPMinLevel) && m_pp.pvp == 0) SetPVP(true);
|
||||
if (RuleI(World, PVPMinLevel) > 0 && level >= RuleI(World, PVPMinLevel) && m_pp.pvp == 0) {
|
||||
SetPVP(true);
|
||||
}
|
||||
|
||||
DoTributeUpdate();
|
||||
SendHPUpdate();
|
||||
|
||||
@ -4553,7 +4553,8 @@ luabind::scope lua_register_events() {
|
||||
luabind::value("task_before_update", static_cast<int>(EVENT_TASK_BEFORE_UPDATE)),
|
||||
luabind::value("aa_buy", static_cast<int>(EVENT_AA_BUY)),
|
||||
luabind::value("aa_gain", static_cast<int>(EVENT_AA_GAIN)),
|
||||
luabind::value("payload", static_cast<int>(EVENT_PAYLOAD))
|
||||
luabind::value("payload", static_cast<int>(EVENT_PAYLOAD)),
|
||||
luabind::value("level_down", static_cast<int>(EVENT_LEVEL_DOWN))
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -150,7 +150,8 @@ const char *LuaEvents[_LargestEventID] = {
|
||||
"event_task_before_update",
|
||||
"event_aa_buy",
|
||||
"event_aa_gain",
|
||||
"event_payload"
|
||||
"event_payload",
|
||||
"event_level_down"
|
||||
};
|
||||
|
||||
extern Zone *zone;
|
||||
@ -262,6 +263,8 @@ LuaParser::LuaParser() {
|
||||
PlayerArgumentDispatch[EVENT_AA_BUY] = handle_player_aa_buy;
|
||||
PlayerArgumentDispatch[EVENT_AA_GAIN] = handle_player_aa_gain;
|
||||
PlayerArgumentDispatch[EVENT_PAYLOAD] = handle_player_payload;
|
||||
PlayerArgumentDispatch[EVENT_LEVEL_UP] = handle_player_level_up;
|
||||
PlayerArgumentDispatch[EVENT_LEVEL_DOWN] = handle_player_level_down;
|
||||
|
||||
ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click;
|
||||
ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click;
|
||||
|
||||
@ -1092,6 +1092,30 @@ void handle_player_aa_gain(
|
||||
lua_setfield(L, -2, "aa_gained");
|
||||
}
|
||||
|
||||
void handle_player_level_up(
|
||||
QuestInterface *parse,
|
||||
lua_State* L,
|
||||
Client* client,
|
||||
std::string data,
|
||||
uint32 extra_data,
|
||||
std::vector<std::any> *extra_pointers
|
||||
) {
|
||||
lua_pushinteger(L, std::stoul(data));
|
||||
lua_setfield(L, -2, "levels_gained");
|
||||
}
|
||||
|
||||
void handle_player_level_down(
|
||||
QuestInterface *parse,
|
||||
lua_State* L,
|
||||
Client* client,
|
||||
std::string data,
|
||||
uint32 extra_data,
|
||||
std::vector<std::any> *extra_pointers
|
||||
) {
|
||||
lua_pushinteger(L, std::stoul(data));
|
||||
lua_setfield(L, -2, "levels_lost");
|
||||
}
|
||||
|
||||
// Item
|
||||
void handle_item_click(
|
||||
QuestInterface *parse,
|
||||
|
||||
@ -591,6 +591,24 @@ void handle_player_payload(
|
||||
std::vector<std::any> *extra_pointers
|
||||
);
|
||||
|
||||
void handle_player_level_up(
|
||||
QuestInterface *parse,
|
||||
lua_State* L,
|
||||
Client* client,
|
||||
std::string data,
|
||||
uint32 extra_data,
|
||||
std::vector<std::any> *extra_pointers
|
||||
);
|
||||
|
||||
void handle_player_level_down(
|
||||
QuestInterface *parse,
|
||||
lua_State* L,
|
||||
Client* client,
|
||||
std::string data,
|
||||
uint32 extra_data,
|
||||
std::vector<std::any> *extra_pointers
|
||||
);
|
||||
|
||||
|
||||
// Item
|
||||
void handle_item_click(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user