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

Commit c5b995e

Browse files
committed
Merge branch 'feature/roe' into canary
# Conflicts: # src/map/lua/lua_baseentity.cpp
2 parents 77da2e5 + 008c3ef commit c5b995e

File tree

6 files changed

+60
-27
lines changed

6 files changed

+60
-27
lines changed

scripts/globals/roe.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ end
6868
local defaults = {
6969
check = checks.masterCheck, -- Check function should return true/false
7070
increment = 1, -- Amount to increment per successful check
71+
notify = 1, -- Progress notifications shown every X increases
7172
goal = 1, -- Progress goal
7273
reqs = {}, -- Other requirements. List of function names from above, with required values.
74+
reward = {}, -- Reward parameters give on completion. (See completeRecord directly below.)
7375
}
7476

7577
--[[ **************************************************************************
@@ -282,6 +284,7 @@ tpz.roe.records =
282284
trigger = triggers.dmgDealt,
283285
goal = 100000,
284286
increment = 0,
287+
notify = 5000,
285288
reward = { sparks = 1000, xp = 5000 , item = { 6181 } },
286289
check = function(self, player, params)
287290
if params.dmg and params.dmg > 0 then

src/map/lua/lua_baseentity.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ inline int32 CLuaBaseEntity::sendGuild(lua_State* L)
23942394

23952395
GUILDSTATUS status = GUILD_OPEN;
23962396

2397-
/*
2397+
/*
23982398
* No more guild holidays since 2014
23992399
if (VanadielDay == holiday)
24002400
{
@@ -6926,12 +6926,21 @@ inline int32 CLuaBaseEntity::setEminenceProgress(lua_State *L)
69266926
CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
69276927
uint16 recordID = static_cast<uint16>(lua_tointeger(L, 1));
69286928
uint32 progress = static_cast<uint32>(lua_tointeger(L, 2));
6929+
uint32 total = static_cast<uint32>(lua_tointeger(L, 3));
6930+
6931+
// Determine threshold for sending progress messages
6932+
bool progressNotify {true};
6933+
if (uint32 threshold = roeutils::RoeCache.NotifyThresholds[recordID]; threshold > 1)
6934+
{
6935+
uint32 prevStep = static_cast<uint32>(roeutils::GetEminenceRecordProgress(PChar, recordID) / threshold);
6936+
uint32 nextStep = static_cast<uint32>(progress / threshold);
6937+
progressNotify = nextStep > prevStep;
6938+
}
69296939

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

6933-
uint32 total = static_cast<int32>(lua_tointeger(L, 3));
6934-
if (total)
6943+
if (total && progressNotify)
69356944
{
69366945
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, recordID, 0, MSGBASIC_ROE_RECORD));
69376946
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, progress, total, MSGBASIC_ROE_PROGRESS));

src/map/roe.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "packets/roe_update.h"
3434

3535
std::array<RoeCheckHandler, ROE_NONE> RoeHandlers;
36-
RoeCache roeutils::RoeBitmaps;
36+
RoeSystemData roeutils::RoeCache;
3737

3838
namespace roeutils
3939
{
@@ -84,8 +84,9 @@ int32 RegisterHandler(lua_State* L)
8484

8585
int32 ParseRecords(lua_State* L)
8686
{
87-
roeutils::RoeBitmaps.ImplementedRecords.reset();
88-
roeutils::RoeBitmaps.RepeatableRecords.reset();
87+
roeutils::RoeCache.ImplementedRecords.reset();
88+
roeutils::RoeCache.RepeatableRecords.reset();
89+
roeutils::RoeCache.NotifyThresholds.fill(1);
8990

9091
if (lua_isnil(L, -1) || !lua_istable(L, -1))
9192
return 0;
@@ -96,7 +97,13 @@ int32 ParseRecords(lua_State* L)
9697
{
9798
// Set Implemented bit.
9899
uint32 recordID = static_cast<uint32>(lua_tointeger(L, -2));
99-
roeutils::RoeBitmaps.ImplementedRecords.set(recordID);
100+
roeutils::RoeCache.ImplementedRecords.set(recordID);
101+
102+
// Set notification threshold
103+
lua_getfield(L, -1, "notify");
104+
if (!lua_isnil(L, -1))
105+
roeutils::RoeCache.NotifyThresholds[recordID] = static_cast<uint32>((lua_tointeger(L, -1)));
106+
lua_pop(L, 1);
100107

101108
// Set repeatability bit
102109
lua_getfield(L, -1, "reward");
@@ -105,7 +112,7 @@ int32 ParseRecords(lua_State* L)
105112
lua_getfield(L, -1, "repeatable");
106113
if (lua_toboolean(L, -1))
107114
{
108-
roeutils::RoeBitmaps.RepeatableRecords.set(recordID);
115+
roeutils::RoeCache.RepeatableRecords.set(recordID);
109116
}
110117
lua_pop(L, 1);
111118
}
@@ -129,6 +136,7 @@ bool event(ROE_EVENT eventID, CCharEntity* PChar, RoeDatagramList payload)
129136
return 0;
130137

131138
lua_State* L = luautils::LuaHandle;
139+
uint32 stackTop = lua_gettop(L);
132140
lua_getglobal(L, "tpz");
133141
lua_getfield(L, -1, "roe");
134142

@@ -183,6 +191,7 @@ bool event(ROE_EVENT eventID, CCharEntity* PChar, RoeDatagramList payload)
183191
}
184192
}
185193
}
194+
lua_settop(L, stackTop);
186195
return true;
187196
}
188197

@@ -198,7 +207,7 @@ bool event(ROE_EVENT eventID, CCharEntity* PChar) // shorthand for no-datagram c
198207

199208
void SetEminenceRecordCompletion(CCharEntity* PChar, uint16 recordID, bool newStatus)
200209
{
201-
uint8 page = recordID / 8;
210+
uint16 page = recordID / 8;
202211
uint8 bit = recordID % 8;
203212
if (newStatus)
204213
PChar->m_eminenceLog.complete[page] |= (1 << bit);
@@ -214,32 +223,24 @@ void SetEminenceRecordCompletion(CCharEntity* PChar, uint16 recordID, bool newSt
214223

215224
bool GetEminenceRecordCompletion(CCharEntity* PChar, uint16 recordID)
216225
{
217-
uint8 page = recordID / 8;
226+
uint16 page = recordID / 8;
218227
uint8 bit = recordID % 8;
219228
return PChar->m_eminenceLog.complete[page] & (1 << bit);
220229
}
221230

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

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

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

245246
// Per above, this i < 30 is correct.

src/map/roe.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ enum ROE_EVENT
5050
ROE_NONE // End of enum marker and OOB checkpost. Do not move or remove, place any new types above.
5151
};
5252

53-
struct RoeCache
53+
struct RoeSystemData
5454
{
5555
std::bitset<4096> ImplementedRecords;
5656
std::bitset<4096> RepeatableRecords;
57+
std::array<uint32, 4096> NotifyThresholds;
5758
};
5859

5960
struct RoeCheckHandler
@@ -79,16 +80,14 @@ struct RoeDatagram
7980
CItem* item;
8081
} data;
8182

82-
RoeDatagram(std::string param, uint32 id)
83+
RoeDatagram(std::string param, uint32 id) : param{param}
8384
{
8485
this->type = RoeDatagramPayload::uinteger;
85-
this->param = param;
8686
this->data.uinteger = id;
8787
}
88-
RoeDatagram(std::string param, CMobEntity* PMob)
88+
RoeDatagram(std::string param, CMobEntity* PMob) : param{param}
8989
{
9090
this->type = RoeDatagramPayload::mob;
91-
this->param = param;
9291
this->data.mobEntity = PMob;
9392
}
9493
};
@@ -97,7 +96,7 @@ typedef std::vector<RoeDatagram> RoeDatagramList;
9796

9897
namespace roeutils
9998
{
100-
extern RoeCache RoeBitmaps;
99+
extern RoeSystemData RoeCache;
101100

102101
void init();
103102
int32 RegisterHandler(lua_State* L);

win32/vcxproj/topaz_game.vcxproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@
417417
<ClInclude Include="..\..\src\map\packets\position.h" />
418418
<ClInclude Include="..\..\src\map\packets\quest_mission_log.h" />
419419
<ClInclude Include="..\..\src\map\packets\release.h" />
420+
<ClInclude Include="..\..\src\map\packets\roe_sparkupdate.h" />
421+
<ClInclude Include="..\..\src\map\packets\roe_questlog.h" />
422+
<ClInclude Include="..\..\src\map\packets\roe_update.h" />
420423
<ClInclude Include="..\..\src\map\packets\server_ip.h" />
421424
<ClInclude Include="..\..\src\map\packets\server_message.h" />
422425
<ClInclude Include="..\..\src\map\packets\shop_appraise.h" />
@@ -438,6 +441,7 @@
438441
<ClInclude Include="..\..\src\map\party.h" />
439442
<ClInclude Include="..\..\src\map\recast_container.h" />
440443
<ClInclude Include="..\..\src\map\region.h" />
444+
<ClInclude Include="..\..\src\map\roe.h" />
441445
<ClInclude Include="..\..\src\map\spell.h" />
442446
<ClInclude Include="..\..\src\map\status_effect.h" />
443447
<ClInclude Include="..\..\src\map\status_effect_container.h" />
@@ -700,7 +704,6 @@
700704
<ClCompile Include="..\..\src\map\party.cpp" />
701705
<ClCompile Include="..\..\src\map\recast_container.cpp" />
702706
<ClCompile Include="..\..\src\map\region.cpp" />
703-
<ClCompile Include="..\..\src\map\roe.h" />
704707
<ClCompile Include="..\..\src\map\roe.cpp" />
705708
<ClCompile Include="..\..\src\map\spell.cpp" />
706709
<ClCompile Include="..\..\src\map\status_effect.cpp" />

win32/vcxproj/topaz_game.vcxproj.filters

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@
419419
<ClInclude Include="..\..\src\map\packets\release.h">
420420
<Filter>Header Files\packets</Filter>
421421
</ClInclude>
422+
<ClInclude Include="..\..\src\map\packets\roe_questlog.h">
423+
<Filter>Header Files\packets</Filter>
424+
</ClInclude>
425+
<ClInclude Include="..\..\src\map\packets\roe_sparkupdate.h">
426+
<Filter>Header Files\packets</Filter>
427+
</ClInclude>
428+
<ClInclude Include="..\..\src\map\packets\roe_update.h">
429+
<Filter>Header Files\packets</Filter>
430+
</ClInclude>
422431
<ClInclude Include="..\..\src\map\packets\server_ip.h">
423432
<Filter>Header Files\packets</Filter>
424433
</ClInclude>
@@ -1213,6 +1222,15 @@
12131222
<ClCompile Include="..\..\src\map\packets\release.cpp">
12141223
<Filter>Source Files\packets</Filter>
12151224
</ClCompile>
1225+
<ClCompile Include="..\..\src\map\packets\roe_questlog.cpp">
1226+
<Filter>Header Files\packets</Filter>
1227+
</ClCompile>
1228+
<ClCompile Include="..\..\src\map\packets\roe_sparkupdate.cpp">
1229+
<Filter>Header Files\packets</Filter>
1230+
</ClCompile>
1231+
<ClCompile Include="..\..\src\map\packets\roe_update.cpp">
1232+
<Filter>Header Files\packets</Filter>
1233+
</ClCompile>
12161234
<ClCompile Include="..\..\src\map\packets\server_ip.cpp">
12171235
<Filter>Source Files\packets</Filter>
12181236
</ClCompile>

0 commit comments

Comments
 (0)