Skip to content

Commit 5c744a8

Browse files
sruonXaver-DaRed
authored andcommitted
Lua bindings to get/set MMM unlocks
1 parent 765afd8 commit 5c744a8

5 files changed

Lines changed: 121 additions & 0 deletions

File tree

scripts/specs/core/CBaseEntity.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,28 @@ end
908908
function CBaseEntity:setHomePoint()
909909
end
910910

911+
---@param voucherId integer
912+
---@return nil
913+
function CBaseEntity:learnMazeVoucher(voucherId)
914+
end
915+
916+
---@nodiscard
917+
---@param voucherId integer
918+
---@return boolean
919+
function CBaseEntity:hasMazeVoucher(voucherId)
920+
end
921+
922+
---@param runeId integer
923+
---@return nil
924+
function CBaseEntity:learnMazeRune(runeId)
925+
end
926+
927+
---@nodiscard
928+
---@param runeId integer
929+
---@return boolean
930+
function CBaseEntity:hasMazeRune(runeId)
931+
end
932+
911933
---@param charName string
912934
---@return nil
913935
function CBaseEntity:resetPlayer(charName)

src/map/lua/lua_baseentity.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,82 @@ void CLuaBaseEntity::setHomePoint()
39243924
PChar->id);
39253925
}
39263926

3927+
/************************************************************************
3928+
* Function: learnMazeVoucher(uint8)
3929+
* Purpose : Marks a Moblin Maze Mongers voucher as learned, persists it,
3930+
* and refreshes the client's voucher/rune list.
3931+
* Example : player:learnMazeVoucher(xi.maze.voucher.SANITIZATION_TEAM_ALPHA)
3932+
************************************************************************/
3933+
3934+
void CLuaBaseEntity::learnMazeVoucher(uint8 voucherId)
3935+
{
3936+
auto* PChar = dynamic_cast<CCharEntity*>(m_PBaseEntity);
3937+
if (!PChar)
3938+
{
3939+
ShowWarningFmt("CLuaBaseEntity::learnMazeVoucher called on non-PC entity ({}).", m_PBaseEntity->getName());
3940+
return;
3941+
}
3942+
3943+
PChar->maze().learnVoucher(voucherId);
3944+
charutils::SaveMazeUnlocks(PChar);
3945+
}
3946+
3947+
/************************************************************************
3948+
* Function: hasMazeVoucher(uint8)
3949+
* Purpose : Returns true if the player has learned the given voucher.
3950+
* Example : player:hasMazeVoucher(xi.maze.voucher.SANITIZATION_TEAM_ALPHA)
3951+
************************************************************************/
3952+
3953+
auto CLuaBaseEntity::hasMazeVoucher(uint8 voucherId) -> bool
3954+
{
3955+
auto* PChar = dynamic_cast<CCharEntity*>(m_PBaseEntity);
3956+
if (!PChar)
3957+
{
3958+
ShowWarningFmt("CLuaBaseEntity::hasMazeVoucher called on non-PC entity ({}).", m_PBaseEntity->getName());
3959+
return false;
3960+
}
3961+
3962+
return PChar->maze().hasVoucher(voucherId);
3963+
}
3964+
3965+
/************************************************************************
3966+
* Function: learnMazeRune(uint8)
3967+
* Purpose : Marks a Moblin Maze Mongers rune as learned, persists it,
3968+
* and refreshes the client's voucher/rune list.
3969+
* Example : player:learnMazeRune(xi.maze.rune.GUIDANCE_CONTRACT)
3970+
************************************************************************/
3971+
3972+
void CLuaBaseEntity::learnMazeRune(uint16 runeId)
3973+
{
3974+
auto* PChar = dynamic_cast<CCharEntity*>(m_PBaseEntity);
3975+
if (!PChar)
3976+
{
3977+
ShowWarningFmt("CLuaBaseEntity::learnMazeRune called on non-PC entity ({}).", m_PBaseEntity->getName());
3978+
return;
3979+
}
3980+
3981+
PChar->maze().learnRune(runeId);
3982+
charutils::SaveMazeUnlocks(PChar);
3983+
}
3984+
3985+
/************************************************************************
3986+
* Function: hasMazeRune(uint16)
3987+
* Purpose : Returns true if the player has learned the given rune.
3988+
* Example : player:hasMazeRune(xi.maze.rune.GUIDANCE_CONTRACT)
3989+
************************************************************************/
3990+
3991+
auto CLuaBaseEntity::hasMazeRune(uint16 runeId) -> bool
3992+
{
3993+
auto* PChar = dynamic_cast<CCharEntity*>(m_PBaseEntity);
3994+
if (!PChar)
3995+
{
3996+
ShowWarningFmt("CLuaBaseEntity::hasMazeRune called on non-PC entity ({}).", m_PBaseEntity->getName());
3997+
return false;
3998+
}
3999+
4000+
return PChar->maze().hasRune(runeId);
4001+
}
4002+
39274003
/************************************************************************
39284004
* Function: resetPlayer()
39294005
* Purpose : Delete player's account session and send them to Lower Jeuno
@@ -19808,6 +19884,10 @@ void CLuaBaseEntity::Register()
1980819884
SOL_REGISTER("setTeleportMenu", CLuaBaseEntity::setTeleportMenu);
1980919885
SOL_REGISTER("getTeleportMenu", CLuaBaseEntity::getTeleportMenu);
1981019886
SOL_REGISTER("setHomePoint", CLuaBaseEntity::setHomePoint);
19887+
SOL_REGISTER("learnMazeVoucher", CLuaBaseEntity::learnMazeVoucher);
19888+
SOL_REGISTER("hasMazeVoucher", CLuaBaseEntity::hasMazeVoucher);
19889+
SOL_REGISTER("learnMazeRune", CLuaBaseEntity::learnMazeRune);
19890+
SOL_REGISTER("hasMazeRune", CLuaBaseEntity::hasMazeRune);
1981119891
SOL_REGISTER("resetPlayer", CLuaBaseEntity::resetPlayer);
1981219892

1981319893
SOL_REGISTER("gotoEntity", CLuaBaseEntity::gotoEntity);

src/map/lua/lua_baseentity.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ class CLuaBaseEntity
236236
auto getTeleportMenu(uint8 type) -> sol::table;
237237
void setHomePoint();
238238

239+
void learnMazeVoucher(uint8 voucherId);
240+
auto hasMazeVoucher(uint8 voucherId) -> bool;
241+
void learnMazeRune(uint16 runeId);
242+
auto hasMazeRune(uint16 runeId) -> bool;
243+
239244
void resetPlayer(const char* charName);
240245

241246
void gotoEntity(uint32 targetID, const sol::object& option);

src/map/utils/charutils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "packets/s2c/0x061_clistatus.h"
5555
#include "packets/s2c/0x062_clistatus2.h"
5656
#include "packets/s2c/0x0ac_command_data.h"
57+
#include "packets/s2c/0x0ad_dungeon.h"
5758
#include "packets/s2c/0x0e0_group_comlink.h"
5859
#include "packets/s2c/0x119_abil_recast.h"
5960

@@ -6716,6 +6717,18 @@ void SaveTeleport(CCharEntity* PChar, TELEPORT_TYPE type)
67166717
}
67176718
}
67186719

6720+
void SaveMazeUnlocks(CCharEntity* PChar)
6721+
{
6722+
TracyZoneScoped;
6723+
6724+
db::preparedStmt("UPDATE char_unlocks SET maze_vouchers = ?, maze_runes = ? WHERE charid = ? LIMIT 1",
6725+
PChar->maze().vouchers,
6726+
PChar->maze().runes,
6727+
PChar->id);
6728+
6729+
PChar->pushPacket<GP_SERV_COMMAND_DUNGEON>(PChar);
6730+
}
6731+
67196732
void SaveLastLogout(const CCharEntity* PChar)
67206733
{
67216734
TracyZoneScoped;

src/map/utils/charutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void SaveCampaignAllegiance(const CCharEntity* PChar); // save the char
218218
void SaveCharMoghancement(const CCharEntity* PChar); // save the character's current moghancement
219219
void SaveCharSkills(const CCharEntity* PChar, uint8 skillID); // save the character's skills
220220
void SaveTeleport(CCharEntity* PChar, TELEPORT_TYPE type); // save the character's teleports (homepoints, outposts, maws, etc)
221+
void SaveMazeUnlocks(CCharEntity* PChar); // save the character's learned Moblin Maze Mongers vouchers and runes
221222
void SaveDeathTime(CCharEntity* PChar); // save when this character last died
222223
void SavePlayTime(CCharEntity* PChar); // save this character's total play time
223224
void SaveLastLogout(const CCharEntity* PChar); // save the last logout time of this character

0 commit comments

Comments
 (0)