-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blessings updated #4479
base: master
Are you sure you want to change the base?
blessings updated #4479
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return std::max(value, 0)
and get rid of the branch
@@ -10374,56 +10386,56 @@ int LuaScriptInterface::luaPlayerSetPremiumEndsAt(lua_State* L) | |||
return 1; | |||
} | |||
|
|||
int LuaScriptInterface::luaPlayerHasBlessing(lua_State* L) | |||
int LuaScriptInterface::luaPlayerAddBlessing(lua_State* L) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be written in pure Lua now, manipulating the storages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, if you do that it will be impossible to set them anyway :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
end
because 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
blessings
column fromplayers
table.Issues addressed: