Conversation
| addStorageValue(key, oldValue + count); | ||
| } | ||
|
|
||
| void Player::removeBlessing(uint8_t blessingId, int32_t count /* = 1*/) { addBlessing(blessingId, count * -1); } |
There was a problem hiding this comment.
| void Player::removeBlessing(uint8_t blessingId, int32_t count /* = 1*/) { addBlessing(blessingId, count * -1); } | |
| void Player::removeBlessing(uint8_t blessingId, int32_t count /* = 1*/) { addBlessing(blessingId, -count); } |
| return 0; | ||
| } | ||
|
|
||
| return value; |
There was a problem hiding this comment.
return std::max(value, 0) and get rid of the branch
| } | ||
|
|
||
| int LuaScriptInterface::luaPlayerHasBlessing(lua_State* L) | ||
| int LuaScriptInterface::luaPlayerAddBlessing(lua_State* L) |
There was a problem hiding this comment.
This can be written in pure Lua now, manipulating the storages.
There was a problem hiding this comment.
okay... should I update the int LuaScriptInterface::luaPlayerSetStorageValue(lua_State* L) method to ignore blessings range?
if (IS_IN_KEYRANGE(key, RESERVED_RANGE)) {
reportErrorFunc(L, fmt::format("Accessing reserved range: {:d}", key));
pushBoolean(L, false);
return 1;
}There was a problem hiding this comment.
No, if you do that it will be impossible to set them anyway :P
There was a problem hiding this comment.
The issue I'm having is that I cannot set blessing storages because they're reserved.
function Player.getBlessing(self, blessingId)
return math.max(0, self:getStorageValue(PlayerStorageKeys.blessingsRangeStart + blessingId))
end
function Player.addBlessing(self, blessingId, count)
local key, count = PlayerStorageKeys.blessingsRangeStart + blessingId, count or 1
self:setStorageValue(key, self:getBlessing(blessingId) + count)
end
function Player.removeBlessing(self, blessingId, count)
local count = count or 1
self:addBlessing(blessingId, -count)
endbecause of:
int LuaScriptInterface::luaPlayerSetStorageValue(lua_State* L)
{
// player:setStorageValue(key, value)
int32_t value = getNumber<int32_t>(L, 3);
uint32_t key = getNumber<uint32_t>(L, 2);
Player* player = getUserdata<Player>(L, 1);
if (IS_IN_KEYRANGE(key, RESERVED_RANGE)) {
reportErrorFunc(L, fmt::format("Accessing reserved range: {:d}", key));
pushBoolean(L, false);
return 1;
}
if (player) {
player->addStorageValue(key, value);
pushBoolean(L, true);
} else {
lua_pushnil(L);
}
return 1;
}that's why I asked if it will be ok to skip the "reserved range" check from the Player.setStorageValue function so I can move all blessings functions to lua. 😄
There was a problem hiding this comment.
Ah sorry, I thought you were asking if the blessings storage range should be added to the protected list, not the other way around. Yes, it should be removed from the reserved range, since there is a key to access them that is very clear (PlayerStorageKeys.blessingsRangeStart).
Alternatively, use a different value for PlayerStorageKeys.blessingsRangeStart that is outside the reserved range.
Pull Request Prelude
Changes Proposed
Modified how blessings are handled in the server.
blessingscolumn fromplayerstable.Issues addressed: