Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1160 from Kreidos/roe-notify
Browse files Browse the repository at this point in the history
Add notification thresholds on RoE records
  • Loading branch information
zach2good authored Sep 19, 2020
2 parents 8ecfd90 + 19dfe49 commit 008c3ef
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
3 changes: 3 additions & 0 deletions scripts/globals/roe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ end
local defaults = {
check = checks.masterCheck, -- Check function should return true/false
increment = 1, -- Amount to increment per successful check
notify = 1, -- Progress notifications shown every X increases
goal = 1, -- Progress goal
reqs = {}, -- Other requirements. List of function names from above, with required values.
reward = {}, -- Reward parameters give on completion. (See completeRecord directly below.)
}

--[[ **************************************************************************
Expand Down Expand Up @@ -282,6 +284,7 @@ tpz.roe.records =
trigger = triggers.dmgDealt,
goal = 100000,
increment = 0,
notify = 5000,
reward = { sparks = 1000, xp = 5000 , item = { 6181 } },
check = function(self, player, params)
if params.dmg and params.dmg > 0 then
Expand Down
13 changes: 11 additions & 2 deletions src/map/lua/lua_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6810,12 +6810,21 @@ inline int32 CLuaBaseEntity::setEminenceProgress(lua_State *L)
CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
uint16 recordID = static_cast<uint16>(lua_tointeger(L, 1));
uint32 progress = static_cast<uint32>(lua_tointeger(L, 2));
uint32 total = static_cast<uint32>(lua_tointeger(L, 3));

// Determine threshold for sending progress messages
bool progressNotify {true};
if (uint32 threshold = roeutils::RoeCache.NotifyThresholds[recordID]; threshold > 1)
{
uint32 prevStep = static_cast<uint32>(roeutils::GetEminenceRecordProgress(PChar, recordID) / threshold);
uint32 nextStep = static_cast<uint32>(progress / threshold);
progressNotify = nextStep > prevStep;
}

bool result = roeutils::SetEminenceRecordProgress(PChar, recordID, progress);
lua_pushboolean(L, result);

uint32 total = static_cast<uint32>(lua_tointeger(L, 3));
if (total)
if (total && progressNotify)
{
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, recordID, 0, MSGBASIC_ROE_RECORD));
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, progress, total, MSGBASIC_ROE_PROGRESS));
Expand Down
33 changes: 16 additions & 17 deletions src/map/roe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "packets/roe_update.h"

std::array<RoeCheckHandler, ROE_NONE> RoeHandlers;
RoeCache roeutils::RoeBitmaps;
RoeSystemData roeutils::RoeCache;

namespace roeutils
{
Expand Down Expand Up @@ -84,8 +84,9 @@ int32 RegisterHandler(lua_State* L)

int32 ParseRecords(lua_State* L)
{
roeutils::RoeBitmaps.ImplementedRecords.reset();
roeutils::RoeBitmaps.RepeatableRecords.reset();
roeutils::RoeCache.ImplementedRecords.reset();
roeutils::RoeCache.RepeatableRecords.reset();
roeutils::RoeCache.NotifyThresholds.fill(1);

if (lua_isnil(L, -1) || !lua_istable(L, -1))
return 0;
Expand All @@ -96,7 +97,13 @@ int32 ParseRecords(lua_State* L)
{
// Set Implemented bit.
uint32 recordID = static_cast<uint32>(lua_tointeger(L, -2));
roeutils::RoeBitmaps.ImplementedRecords.set(recordID);
roeutils::RoeCache.ImplementedRecords.set(recordID);

// Set notification threshold
lua_getfield(L, -1, "notify");
if (!lua_isnil(L, -1))
roeutils::RoeCache.NotifyThresholds[recordID] = static_cast<uint32>((lua_tointeger(L, -1)));
lua_pop(L, 1);

// Set repeatability bit
lua_getfield(L, -1, "reward");
Expand All @@ -105,7 +112,7 @@ int32 ParseRecords(lua_State* L)
lua_getfield(L, -1, "repeatable");
if (lua_toboolean(L, -1))
{
roeutils::RoeBitmaps.RepeatableRecords.set(recordID);
roeutils::RoeCache.RepeatableRecords.set(recordID);
}
lua_pop(L, 1);
}
Expand Down Expand Up @@ -200,7 +207,7 @@ bool event(ROE_EVENT eventID, CCharEntity* PChar) // shorthand for no-datagram c

void SetEminenceRecordCompletion(CCharEntity* PChar, uint16 recordID, bool newStatus)
{
uint8 page = recordID / 8;
uint16 page = recordID / 8;
uint8 bit = recordID % 8;
if (newStatus)
PChar->m_eminenceLog.complete[page] |= (1 << bit);
Expand All @@ -216,32 +223,24 @@ void SetEminenceRecordCompletion(CCharEntity* PChar, uint16 recordID, bool newSt

bool GetEminenceRecordCompletion(CCharEntity* PChar, uint16 recordID)
{
uint8 page = recordID / 8;
uint16 page = recordID / 8;
uint8 bit = recordID % 8;
return PChar->m_eminenceLog.complete[page] & (1 << bit);
}

bool AddEminenceRecord(CCharEntity* PChar, uint16 recordID)
{
// TODO: Time limited records aren't implemented yet and can't be accepted normally.
// For now we are refusing their IDs outright and protecting its slot from use here.
if (recordID > 2047)
{
std::string message = "Special Event/Timed Records can not be taken.";
PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_NS_SAY, message, "RoE System"));
return false;
}

// We deny taking records which aren't implemented in the Lua
if (!roeutils::RoeBitmaps.ImplementedRecords.test(recordID))
if (!roeutils::RoeCache.ImplementedRecords.test(recordID))
{
std::string message = "The record #" + std::to_string(recordID) + " is not implemented at this time.";
PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_NS_SAY, message, "RoE System"));
return false;
}

// Prevent packet-injection for re-taking completed records which aren't marked repeatable.
if (roeutils::GetEminenceRecordCompletion(PChar, recordID) && !roeutils::RoeBitmaps.RepeatableRecords.test(recordID))
if (roeutils::GetEminenceRecordCompletion(PChar, recordID) && !roeutils::RoeCache.RepeatableRecords.test(recordID))
return false;

// Per above, this i < 30 is correct.
Expand Down
11 changes: 5 additions & 6 deletions src/map/roe.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ enum ROE_EVENT
ROE_NONE // End of enum marker and OOB checkpost. Do not move or remove, place any new types above.
};

struct RoeCache
struct RoeSystemData
{
std::bitset<4096> ImplementedRecords;
std::bitset<4096> RepeatableRecords;
std::array<uint32, 4096> NotifyThresholds;
};

struct RoeCheckHandler
Expand All @@ -79,16 +80,14 @@ struct RoeDatagram
CItem* item;
} data;

RoeDatagram(std::string param, uint32 id)
RoeDatagram(std::string param, uint32 id) : param{param}
{
this->type = RoeDatagramPayload::uinteger;
this->param = param;
this->data.uinteger = id;
}
RoeDatagram(std::string param, CMobEntity* PMob)
RoeDatagram(std::string param, CMobEntity* PMob) : param{param}
{
this->type = RoeDatagramPayload::mob;
this->param = param;
this->data.mobEntity = PMob;
}
};
Expand All @@ -97,7 +96,7 @@ typedef std::vector<RoeDatagram> RoeDatagramList;

namespace roeutils
{
extern RoeCache RoeBitmaps;
extern RoeSystemData RoeCache;

void init();
int32 RegisterHandler(lua_State* L);
Expand Down

0 comments on commit 008c3ef

Please sign in to comment.