Skip to content

Commit

Permalink
Merge branch 'main' into fix/support-outfit-crashs
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Apr 29, 2024
2 parents be17202 + 98e927d commit 3948236
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,26 @@ function teleportBoss.onStepIn(creature, item, position, fromPosition)
end
local player = creature
if player:getLevel() < config.requiredLevel then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to be level " .. config.requiredLevel .. " or higher.")
return true
end
if locked then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There's already someone fighting with " .. config.bossName .. ".")
return false
end
if zone:countPlayers(IgnoredByMonsters) >= 5 then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The boss room is full.")
return false
end
local timeLeft = player:getBossCooldown(config.bossName) - os.time()
if timeLeft > 0 then
player:teleportTo(exitPosition, true)
player:teleportTo(config.exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have to wait " .. getTimeInWords(timeLeft) .. " to face " .. config.bossName .. " again!")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
Expand Down
36 changes: 22 additions & 14 deletions data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ local function useStaminaXpBoost(player)
return false
end

local staminaMinutes = player:getExpBoostStamina() / 60
if staminaMinutes == 0 then
local xpBoostMinutes = player:getXpBoostTime() / 60
if xpBoostMinutes == 0 then
return
end

Expand All @@ -156,18 +156,26 @@ local function useStaminaXpBoost(player)
return
end

local xpBoostLeftMinutesByDailyReward = player:kv():get("daily-reward-xp-boost") or 0
if timePassed > 60 then
if staminaMinutes > 2 then
staminaMinutes = staminaMinutes - 2
if xpBoostMinutes > 2 then
xpBoostMinutes = xpBoostMinutes - 2
if xpBoostLeftMinutesByDailyReward > 2 then
player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 2)
end
else
staminaMinutes = 0
xpBoostMinutes = 0
player:kv():remove("daily-reward-xp-boost")
end
_G.NextUseXpStamina[playerId] = currentTime + 120
else
staminaMinutes = staminaMinutes - 1
xpBoostMinutes = xpBoostMinutes - 1
if xpBoostLeftMinutesByDailyReward > 0 then
player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 1)
end
_G.NextUseXpStamina[playerId] = currentTime + 60
end
player:setExpBoostStamina(staminaMinutes * 60)
player:setXpBoostTime(xpBoostMinutes * 60)
end

local function useConcoctionTime(player)
Expand Down Expand Up @@ -519,14 +527,14 @@ function Player:onGainExperience(target, exp, rawExp)
self:addCondition(soulCondition)
end

-- Store Bonus
useStaminaXpBoost(self) -- Use store boost stamina
-- XP Boost Bonus
useStaminaXpBoost(self) -- Use stamina XP boost (store or daily reward)

local Boost = self:getExpBoostStamina()
local stillHasBoost = Boost > 0
local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0
local xpBoostTimeLeft = self:getXpBoostTime()
local stillHasXpBoost = xpBoostTimeLeft > 0
local xpBoostPercent = stillHasXpBoost and self:getXpBoostPercent() or 0

self:setStoreXpBoost(storeXpBoostAmount)
self:setXpBoostPercent(xpBoostPercent)

-- Stamina Bonus
local staminaBonusXp = 1
Expand Down Expand Up @@ -564,7 +572,7 @@ function Player:onGainExperience(target, exp, rawExp)
local lowLevelBonuxExp = self:getFinalLowLevelBonus()
local baseRate = self:getFinalBaseRateExperience()

return (exp + (exp * (storeXpBoostAmount / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate
return (exp + (exp * (xpBoostPercent / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate
end

function Player:onLoseExperience(exp)
Expand Down
11 changes: 9 additions & 2 deletions data/modules/scripts/daily_reward/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,15 @@ function Player.selectDailyReward(self, msg)
end
dailyRewardMessage = "Picked items: " .. description
elseif dailyTable.type == DAILY_REWARD_TYPE_XP_BOOST then
self:setExpBoostStamina(self:getExpBoostStamina() + (rewardCount * 60))
self:setStoreXpBoost(50)
local rewardCountReviewed = rewardCount
local xpBoostLeftMinutes = self:kv():get("daily-reward-xp-boost") or 0
if xpBoostLeftMinutes > 0 then
rewardCountReviewed = rewardCountReviewed - xpBoostLeftMinutes
end

self:setXpBoostTime(self:getXpBoostTime() + (rewardCountReviewed * 60))
self:kv():set("daily-reward-xp-boost", rewardCount)
self:setXpBoostPercent(50)
dailyRewardMessage = "Picked reward: XP Bonus for " .. rewardCount .. " minutes."
elseif dailyTable.type == DAILY_REWARD_TYPE_PREY_REROLL then
self:addPreyCards(rewardCount)
Expand Down
12 changes: 6 additions & 6 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function parseBuyStoreOffer(playerId, msg)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE then
GameStore.processSexChangePurchase(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then
GameStore.processExpBoostPuchase(player)
GameStore.processExpBoostPurchase(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT then
GameStore.processTaskHuntingThirdSlot(player)
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYSLOT then
Expand Down Expand Up @@ -732,7 +732,7 @@ function Player.canBuyOffer(self, offer)
disabled = 1
disabledReason = "You can't buy XP Boost for today."
end
if self:getExpBoostStamina() > 0 then
if self:getXpBoostTime() > 0 then
disabled = 1
disabledReason = "You already have an active XP boost."
end
Expand Down Expand Up @@ -1742,12 +1742,12 @@ function GameStore.processSexChangePurchase(player)
player:toggleSex()
end

function GameStore.processExpBoostPuchase(player)
local currentExpBoostTime = player:getExpBoostStamina()
function GameStore.processExpBoostPurchase(player)
local currentXpBoostTime = player:getXpBoostTime()
local expBoostCount = player:getStorageValue(GameStore.Storages.expBoostCount)

player:setStoreXpBoost(50)
player:setExpBoostStamina(currentExpBoostTime + 3600)
player:setXpBoostPercent(50)
player:setXpBoostTime(currentXpBoostTime + 3600)

if expBoostCount == -1 or expBoostCount == 6 then
expBoostCount = 1
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/actions/items/exercise_training_weapons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ end
local exerciseTraining = Action()

function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target or not target:getId() then
if not target or type(target) == "table" or not target:getId() then
return true
end

Expand Down
3 changes: 2 additions & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ bool Creature::dropCorpse(std::shared_ptr<Creature> lastHitCreature, std::shared
auto monster = getMonster();
if (monster && !monster->isRewardBoss()) {
std::ostringstream lootMessage;
lootMessage << "Loot of " << getNameDescription() << ": " << corpseContainer->getContentDescription(player->getProtocolVersion() < 1200) << ".";
auto collorMessage = player->getProtocolVersion() < 1200 || player->getOperatingSystem() >= CLIENTOS_OTCLIENT_LINUX;
lootMessage << "Loot of " << getNameDescription() << ": " << corpseContainer->getContentDescription(collorMessage) << ".";
auto suffix = corpseContainer->getAttribute<std::string>(ItemAttribute_t::LOOTMESSAGE_SUFFIX);
if (!suffix.empty()) {
lootMessage << suffix;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,6 @@ void Player::onWalk(Direction &dir) {

Creature::onWalk(dir);
setNextActionTask(nullptr);
setNextAction(OTSYS_TIME() + getStepDuration(dir));

g_callbacks().executeCallback(EventCallback_t::playerOnWalk, &EventCallback::playerOnWalk, getPlayer(), dir);
}
Expand Down Expand Up @@ -5372,6 +5371,7 @@ uint16_t Player::getSkillLevel(skills_t skill) const {
} else if (skill == SKILL_MANA_LEECH_AMOUNT) {
skillLevel += m_wheelPlayer->getStat(WheelStat_t::MANA_LEECH);
} else if (skill == SKILL_CRITICAL_HIT_DAMAGE) {
skillLevel += m_wheelPlayer->getStat(WheelStat_t::CRITICAL_DAMAGE);
skillLevel += m_wheelPlayer->getMajorStatConditional("Combat Mastery", WheelMajor_t::CRITICAL_DMG_2);
skillLevel += m_wheelPlayer->getMajorStatConditional("Ballistic Mastery", WheelMajor_t::CRITICAL_DMG);
skillLevel += m_wheelPlayer->checkAvatarSkill(WheelAvatarSkill_t::CRITICAL_DAMAGE);
Expand Down
26 changes: 13 additions & 13 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,11 +1807,11 @@ class Player final : public Creature, public Cylinder, public Bankable {
void setGrindingXpBoost(uint16_t value) {
grindingXpBoost = std::min<uint16_t>(std::numeric_limits<uint16_t>::max(), value);
}
uint16_t getStoreXpBoost() const {
return storeXpBoost;
uint16_t getXpBoostPercent() const {
return xpBoostPercent;
}
void setStoreXpBoost(uint16_t exp) {
storeXpBoost = exp;
void setXpBoostPercent(uint16_t percent) {
xpBoostPercent = percent;
}
uint16_t getStaminaXpBoost() const {
return staminaXpBoost;
Expand All @@ -1820,17 +1820,17 @@ class Player final : public Creature, public Cylinder, public Bankable {
staminaXpBoost = std::min<uint16_t>(std::numeric_limits<uint16_t>::max(), value);
}

void setExpBoostStamina(uint16_t stamina) {
// only allow stamina boosts of 12 hours or less
if (stamina > 12 * 3600) {
expBoostStamina = 12 * 3600;
void setXpBoostTime(uint16_t timeLeft) {
// only allow time boosts of 12 hours or less
if (timeLeft > 12 * 3600) {
xpBoostTime = 12 * 3600;
return;
}
expBoostStamina = stamina;
xpBoostTime = timeLeft;
}

uint16_t getExpBoostStamina() {
return expBoostStamina;
uint16_t getXpBoostTime() {
return xpBoostTime;
}

int32_t getIdleTime() const {
Expand Down Expand Up @@ -2811,7 +2811,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
int32_t m_deathTime = 0;
uint32_t coinBalance = 0;
uint32_t coinTransferableBalance = 0;
uint16_t expBoostStamina = 0;
uint16_t xpBoostTime = 0;
uint8_t randomMount = 0;

uint16_t lastStatsTrainingTime = 0;
Expand All @@ -2821,7 +2821,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
uint16_t baseXpGain = 100;
uint16_t voucherXpBoost = 0;
uint16_t grindingXpBoost = 0;
uint16_t storeXpBoost = 0;
uint16_t xpBoostPercent = 0;
uint16_t staminaXpBoost = 100;
int16_t lastDepotId = -1;
StashItemList stashItems; // [ItemID] = amount
Expand Down
4 changes: 2 additions & 2 deletions src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr<Player> player, DBResult_p
}

player->staminaMinutes = result->getNumber<uint16_t>("stamina");
player->setStoreXpBoost(result->getNumber<uint16_t>("xpboost_value"));
player->setExpBoostStamina(result->getNumber<uint16_t>("xpboost_stamina"));
player->setXpBoostPercent(result->getNumber<uint16_t>("xpboost_value"));
player->setXpBoostTime(result->getNumber<uint16_t>("xpboost_stamina"));

player->setManaShield(result->getNumber<uint16_t>("manashield"));
player->setMaxManaShield(result->getNumber<uint16_t>("max_manashield"));
Expand Down
4 changes: 2 additions & 2 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ bool IOLoginDataSave::savePlayerFirst(std::shared_ptr<Player> player) {
query << "`skill_mana_leech_amount_tries` = " << player->skills[SKILL_MANA_LEECH_AMOUNT].tries << ",";
query << "`manashield` = " << player->getManaShield() << ",";
query << "`max_manashield` = " << player->getMaxManaShield() << ",";
query << "`xpboost_value` = " << player->getStoreXpBoost() << ",";
query << "`xpboost_stamina` = " << player->getExpBoostStamina() << ",";
query << "`xpboost_value` = " << player->getXpBoostPercent() << ",";
query << "`xpboost_stamina` = " << player->getXpBoostTime() << ",";
query << "`quickloot_fallback` = " << (player->quickLootFallbackToMainContainer ? 1 : 0) << ",";

if (!player->isOffline()) {
Expand Down
8 changes: 4 additions & 4 deletions src/items/containers/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ std::string Container::getContentDescription(bool oldProtocol) {
return getContentDescription(os, oldProtocol).str();
}

std::ostringstream &Container::getContentDescription(std::ostringstream &os, bool oldProtocol) {
std::ostringstream &Container::getContentDescription(std::ostringstream &os, bool sendColoredMessage) {
bool firstitem = true;
for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) {
std::shared_ptr<Item> item = *it;
Expand All @@ -234,10 +234,10 @@ std::ostringstream &Container::getContentDescription(std::ostringstream &os, boo
os << ", ";
}

if (oldProtocol) {
os << item->getNameDescription();
} else {
if (sendColoredMessage) {
os << "{" << item->getID() << "|" << item->getNameDescription() << "}";
} else {
os << item->getNameDescription();
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3219,23 +3219,23 @@ int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) {
return 1;
}

int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) {
// player:getStoreXpBoost()
int PlayerFunctions::luaPlayerGetXpBoostPercent(lua_State* L) {
// player:getXpBoostPercent()
std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1);
if (player) {
lua_pushnumber(L, player->getStoreXpBoost());
lua_pushnumber(L, player->getXpBoostPercent());
} else {
lua_pushnil(L);
}
return 1;
}

int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) {
// player:setStoreXpBoost(value)
int PlayerFunctions::luaPlayerSetXpBoostPercent(lua_State* L) {
// player:setXpBoostPercent(value)
std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1);
if (player) {
uint16_t experience = getNumber<uint16_t>(L, 2);
player->setStoreXpBoost(experience);
uint16_t percent = getNumber<uint16_t>(L, 2);
player->setXpBoostPercent(percent);
pushBoolean(L, true);
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -3267,12 +3267,12 @@ int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) {
return 1;
}

int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) {
// player:setExpBoostStamina(percent)
int PlayerFunctions::luaPlayerSetXpBoostTime(lua_State* L) {
// player:setXpBoostTime(timeLeft)
std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1);
if (player) {
uint16_t stamina = getNumber<uint16_t>(L, 2);
player->setExpBoostStamina(stamina);
uint16_t timeLeft = getNumber<uint16_t>(L, 2);
player->setXpBoostTime(timeLeft);
player->sendStats();
pushBoolean(L, true);
} else {
Expand All @@ -3281,11 +3281,11 @@ int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) {
return 1;
}

int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) {
// player:getExpBoostStamina()
int PlayerFunctions::luaPlayerGetXpBoostTime(lua_State* L) {
// player:getXpBoostTime()
std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1);
if (player) {
lua_pushnumber(L, player->getExpBoostStamina());
lua_pushnumber(L, player->getXpBoostTime());
} else {
lua_pushnil(L);
}
Expand Down
16 changes: 8 additions & 8 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ class PlayerFunctions final : LuaScriptInterface {
registerMethod(L, "Player", "setVoucherXpBoost", PlayerFunctions::luaPlayerSetVoucherXpBoost);
registerMethod(L, "Player", "getGrindingXpBoost", PlayerFunctions::luaPlayerGetGrindingXpBoost);
registerMethod(L, "Player", "setGrindingXpBoost", PlayerFunctions::luaPlayerSetGrindingXpBoost);
registerMethod(L, "Player", "getStoreXpBoost", PlayerFunctions::luaPlayerGetStoreXpBoost);
registerMethod(L, "Player", "setStoreXpBoost", PlayerFunctions::luaPlayerSetStoreXpBoost);
registerMethod(L, "Player", "getXpBoostPercent", PlayerFunctions::luaPlayerGetXpBoostPercent);
registerMethod(L, "Player", "setXpBoostPercent", PlayerFunctions::luaPlayerSetXpBoostPercent);
registerMethod(L, "Player", "getStaminaXpBoost", PlayerFunctions::luaPlayerGetStaminaXpBoost);
registerMethod(L, "Player", "setStaminaXpBoost", PlayerFunctions::luaPlayerSetStaminaXpBoost);
registerMethod(L, "Player", "getExpBoostStamina", PlayerFunctions::luaPlayerGetExpBoostStamina);
registerMethod(L, "Player", "setExpBoostStamina", PlayerFunctions::luaPlayerSetExpBoostStamina);
registerMethod(L, "Player", "getXpBoostTime", PlayerFunctions::luaPlayerGetXpBoostTime);
registerMethod(L, "Player", "setXpBoostTime", PlayerFunctions::luaPlayerSetXpBoostTime);

registerMethod(L, "Player", "getIdleTime", PlayerFunctions::luaPlayerGetIdleTime);
registerMethod(L, "Player", "getFreeBackpackSlots", PlayerFunctions::luaPlayerGetFreeBackpackSlots);
Expand Down Expand Up @@ -627,12 +627,12 @@ class PlayerFunctions final : LuaScriptInterface {
static int luaPlayerSetVoucherXpBoost(lua_State* L);
static int luaPlayerGetGrindingXpBoost(lua_State* L);
static int luaPlayerSetGrindingXpBoost(lua_State* L);
static int luaPlayerGetStoreXpBoost(lua_State* L);
static int luaPlayerSetStoreXpBoost(lua_State* L);
static int luaPlayerGetXpBoostPercent(lua_State* L);
static int luaPlayerSetXpBoostPercent(lua_State* L);
static int luaPlayerGetStaminaXpBoost(lua_State* L);
static int luaPlayerSetStaminaXpBoost(lua_State* L);
static int luaPlayerGetExpBoostStamina(lua_State* L);
static int luaPlayerSetExpBoostStamina(lua_State* L);
static int luaPlayerGetXpBoostTime(lua_State* L);
static int luaPlayerSetXpBoostTime(lua_State* L);

static int luaPlayerGetIdleTime(lua_State* L);
static int luaPlayerGetFreeBackpackSlots(lua_State* L);
Expand Down

0 comments on commit 3948236

Please sign in to comment.