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

Commit

Permalink
Merge branch 'feature/roe' into canary
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/map/lua/lua_baseentity.cpp
  • Loading branch information
zach2good committed Sep 19, 2020
2 parents 77da2e5 + 008c3ef commit c5b995e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 27 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
15 changes: 12 additions & 3 deletions src/map/lua/lua_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ inline int32 CLuaBaseEntity::sendGuild(lua_State* L)

GUILDSTATUS status = GUILD_OPEN;

/*
/*
* No more guild holidays since 2014
if (VanadielDay == holiday)
{
Expand Down Expand Up @@ -6926,12 +6926,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<int32>(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
35 changes: 18 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 All @@ -129,6 +136,7 @@ bool event(ROE_EVENT eventID, CCharEntity* PChar, RoeDatagramList payload)
return 0;

lua_State* L = luautils::LuaHandle;
uint32 stackTop = lua_gettop(L);
lua_getglobal(L, "tpz");
lua_getfield(L, -1, "roe");

Expand Down Expand Up @@ -183,6 +191,7 @@ bool event(ROE_EVENT eventID, CCharEntity* PChar, RoeDatagramList payload)
}
}
}
lua_settop(L, stackTop);
return true;
}

Expand All @@ -198,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 @@ -214,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
5 changes: 4 additions & 1 deletion win32/vcxproj/topaz_game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@
<ClInclude Include="..\..\src\map\packets\position.h" />
<ClInclude Include="..\..\src\map\packets\quest_mission_log.h" />
<ClInclude Include="..\..\src\map\packets\release.h" />
<ClInclude Include="..\..\src\map\packets\roe_sparkupdate.h" />
<ClInclude Include="..\..\src\map\packets\roe_questlog.h" />
<ClInclude Include="..\..\src\map\packets\roe_update.h" />
<ClInclude Include="..\..\src\map\packets\server_ip.h" />
<ClInclude Include="..\..\src\map\packets\server_message.h" />
<ClInclude Include="..\..\src\map\packets\shop_appraise.h" />
Expand All @@ -438,6 +441,7 @@
<ClInclude Include="..\..\src\map\party.h" />
<ClInclude Include="..\..\src\map\recast_container.h" />
<ClInclude Include="..\..\src\map\region.h" />
<ClInclude Include="..\..\src\map\roe.h" />
<ClInclude Include="..\..\src\map\spell.h" />
<ClInclude Include="..\..\src\map\status_effect.h" />
<ClInclude Include="..\..\src\map\status_effect_container.h" />
Expand Down Expand Up @@ -700,7 +704,6 @@
<ClCompile Include="..\..\src\map\party.cpp" />
<ClCompile Include="..\..\src\map\recast_container.cpp" />
<ClCompile Include="..\..\src\map\region.cpp" />
<ClCompile Include="..\..\src\map\roe.h" />
<ClCompile Include="..\..\src\map\roe.cpp" />
<ClCompile Include="..\..\src\map\spell.cpp" />
<ClCompile Include="..\..\src\map\status_effect.cpp" />
Expand Down
18 changes: 18 additions & 0 deletions win32/vcxproj/topaz_game.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,15 @@
<ClInclude Include="..\..\src\map\packets\release.h">
<Filter>Header Files\packets</Filter>
</ClInclude>
<ClInclude Include="..\..\src\map\packets\roe_questlog.h">
<Filter>Header Files\packets</Filter>
</ClInclude>
<ClInclude Include="..\..\src\map\packets\roe_sparkupdate.h">
<Filter>Header Files\packets</Filter>
</ClInclude>
<ClInclude Include="..\..\src\map\packets\roe_update.h">
<Filter>Header Files\packets</Filter>
</ClInclude>
<ClInclude Include="..\..\src\map\packets\server_ip.h">
<Filter>Header Files\packets</Filter>
</ClInclude>
Expand Down Expand Up @@ -1213,6 +1222,15 @@
<ClCompile Include="..\..\src\map\packets\release.cpp">
<Filter>Source Files\packets</Filter>
</ClCompile>
<ClCompile Include="..\..\src\map\packets\roe_questlog.cpp">
<Filter>Header Files\packets</Filter>
</ClCompile>
<ClCompile Include="..\..\src\map\packets\roe_sparkupdate.cpp">
<Filter>Header Files\packets</Filter>
</ClCompile>
<ClCompile Include="..\..\src\map\packets\roe_update.cpp">
<Filter>Header Files\packets</Filter>
</ClCompile>
<ClCompile Include="..\..\src\map\packets\server_ip.cpp">
<Filter>Source Files\packets</Filter>
</ClCompile>
Expand Down

0 comments on commit c5b995e

Please sign in to comment.