Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Quest API] Add EVENT_LEVEL_DOWN to Perl/Lua. #2620

Merged
merged 3 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions zone/embparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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]);
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions zone/event_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
87 changes: 56 additions & 31 deletions zone/exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion zone/lua_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4530,7 +4530,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))
];
}

Expand Down
5 changes: 4 additions & 1 deletion zone/lua_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions zone/lua_parser_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions zone/lua_parser_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down