Skip to content

Commit

Permalink
Merge branch 'main' into feature/player-onwalk-callback
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Apr 25, 2024
2 parents 3a8a5dd + bd72f66 commit e72b581
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 56 deletions.
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ bld/
[Ll]og/
build/
vcproj/
!vcproj/canary.sln
!vcproj/canary.vcxproj
!vcproj/settings.props

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down Expand Up @@ -372,19 +375,14 @@ config.lua
config_canary.lua
client_assertions.txt
.env
otservbr.otbm
canary.otbm
otservbr-custom.otbm
data-otservbr-global/world/otservbr.otbm

# Extensions
*.ini
*.otb
*.exe
*.manifest
*.rar
*-house.xml
*-monster.xml
*-npc.xml
monster_count.txt

# SFTP for Sublime
Expand All @@ -398,4 +396,4 @@ canary.old
vcpkg_installed

# CLION
cmake-build-debug*
cmake-build-*
4 changes: 2 additions & 2 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75427,7 +75427,7 @@ Granted by TibiaGoals.com"/>
<attribute key="skillboost magic level" value="3"/>
</attribute>
<attribute key="script" value="moveevent;weapon">
<attribute key="level" value="250"/>
<attribute key="level" value="600"/>
<attribute key="mana" value="21"/>
<attribute key="unproperly" value="true"/>
<attribute key="fromDamage" value="113"/>
Expand Down Expand Up @@ -75455,7 +75455,7 @@ Granted by TibiaGoals.com"/>
<attribute key="skillboost magic level" value="3"/>
</attribute>
<attribute key="script" value="moveevent;weapon">
<attribute key="level" value="250"/>
<attribute key="level" value="600"/>
<attribute key="mana" value="21"/>
<attribute key="unproperly" value="true"/>
<attribute key="fromDamage" value="103"/>
Expand Down
2 changes: 1 addition & 1 deletion data/modules/scripts/gamestore/gamestore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6770,7 +6770,7 @@ for k, category in ipairs(GameStore.Categories) do
offer.type = GameStore.OfferTypes.OFFER_TYPE_NONE
end
if not offer.coinType then
offer.coinType = GameStore.CoinType.Coin
offer.coinType = GameStore.CoinType.Transferable
end
end
end
Expand Down
46 changes: 25 additions & 21 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ GameStore.DefaultDescriptions = {
TEMPLE = { "Need a quick way home? Buy this transportation service to get instantly teleported to your home temple. \n\nNote, you cannot use this service while having a battle sign or a protection zone block. Further, the service will not work in no-logout zones or close to your home temple." },
}

GameStore.ItemLimit = {
PREY_WILDCARD = 50,
INSTANT_REWARD_ACCESS = 90,
EXPBOOST = 6,
HIRELING = 10,
}

--==Parsing==--
GameStore.isItsPacket = function(byte)
for k, v in pairs(GameStore.RecivedPackets) do
Expand Down Expand Up @@ -507,8 +514,8 @@ function parseBuyStoreOffer(playerId, msg)
if not pcallOk then
local alertMessage = pcallError.code and pcallError.message or "Something went wrong. Your purchase has been cancelled."

if not pcallError.code then -- unhandled error
-- log some debugging info
-- unhandled error
if not pcallError.code then
logger.warn("[parseBuyStoreOffer] - Purchase failed due to an unhandled script error. Stacktrace: {}", pcallError)
end

Expand Down Expand Up @@ -618,7 +625,6 @@ function sendOfferDescription(player, offerId, description)
end

function Player.canBuyOffer(self, offer)
local playerId = self:getId()
local disabled, disabledReason = 0, ""
if offer.disabled or not offer.type then
disabled = 1
Expand Down Expand Up @@ -697,12 +703,12 @@ function Player.canBuyOffer(self, offer)
disabledReason = "You already have this mount."
end
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS then
if self:getCollectionTokens() >= 90 then
if self:getCollectionTokens() >= GameStore.ItemLimit.INSTANT_REWARD_ACCESS then
disabled = 1
disabledReason = "You already have maximum of reward tokens."
end
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYBONUS then
if self:getPreyCards() >= 50 then
if self:getPreyCards() >= GameStore.ItemLimit.PREY_WILDCARD then
disabled = 1
disabledReason = "You already have maximum of prey wildcards."
end
Expand All @@ -722,7 +728,7 @@ function Player.canBuyOffer(self, offer)
disabledReason = "You already have 3 slots released."
end
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then
if self:getStorageValue(GameStore.Storages.expBoostCount) == 6 then
if self:getStorageValue(GameStore.Storages.expBoostCount) == GameStore.ItemLimit.EXPBOOST then
disabled = 1
disabledReason = "You can't buy XP Boost for today."
end
Expand All @@ -731,7 +737,7 @@ function Player.canBuyOffer(self, offer)
disabledReason = "You already have an active XP boost."
end
elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HIRELING then
if self:getHirelingsCount() >= 10 then
if self:getHirelingsCount() >= GameStore.ItemLimit.HIRELING then
disabled = 1
disabledReason = "You already have bought the maximum number of allowed hirelings."
end
Expand Down Expand Up @@ -1565,8 +1571,9 @@ function GameStore.processAllBlessingsPurchase(player, count)
end

function GameStore.processInstantRewardAccess(player, offerCount)
if player:getCollectionTokens() + offerCount >= 91 then
return error({ code = 1, message = "You cannot own more than 90 reward tokens." })
local limit = GameStore.ItemLimit.INSTANT_REWARD_ACCESS
if player:getCollectionTokens() + offerCount >= limit + 1 then
return error({ code = 1, message = "You cannot own more than " .. limit .. " reward tokens." })
end
player:setCollectionTokens(player:getCollectionTokens() + offerCount)
end
Expand Down Expand Up @@ -1641,7 +1648,6 @@ function GameStore.processHouseRelatedPurchase(player, offer)
decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime())
end
end
player:sendUpdateContainer(inbox)
else
for i = 1, offer.count do
local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1)
Expand All @@ -1653,10 +1659,10 @@ function GameStore.processHouseRelatedPurchase(player, offer)
decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime())
end
end
player:sendUpdateContainer(inbox)
end
end
end
player:sendUpdateContainer(inbox)
end
end

Expand All @@ -1677,11 +1683,7 @@ function GameStore.processOutfitPurchase(player, offerSexIdTable, addon)
elseif player:hasOutfit(looktype, _addon) then
return error({ code = 0, message = "You already own this outfit." })
else
if
not (player:addOutfitAddon(looktype, _addon)) -- TFS call failed
or (not player:hasOutfit(looktype, _addon)) -- Additional check; if the looktype doesn't match player sex for example,
-- then the TFS check will still pass... bug? (TODO)
then
if not player:addOutfitAddon(looktype, _addon) or not player:hasOutfit(looktype, _addon) then
error({ code = 0, message = "There has been an issue with your outfit purchase. Your purchase has been cancelled." })
else
player:addOutfitAddon(offerSexIdTable.male, _addon)
Expand Down Expand Up @@ -1769,8 +1771,9 @@ function GameStore.processTaskHuntingThirdSlot(player)
end

function GameStore.processPreyBonusReroll(player, offerCount)
if player:getPreyCards() + offerCount >= 51 then
return error({ code = 1, message = "You cannot own more than 50 prey wildcards." })
local limit = GameStore.ItemLimit.PREY_WILDCARD
if player:getPreyCards() + offerCount >= limit + 1 then
return error({ code = 1, message = "You cannot own more than " .. limit .. " prey wildcards." })
end
player:addPreyCards(offerCount)
end
Expand Down Expand Up @@ -1812,8 +1815,8 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN
return addPlayerEvent(sendStorePurchaseSuccessful, 650, player:getId(), message)
-- If not, we ask him to do!
else
if player:getHirelingsCount() >= 10 then
return error({ code = 1, message = "You cannot have more than 10 hirelings." })
if player:getHirelingsCount() >= GameStore.ItemLimit.HIRELING then
return error({ code = 1, message = "You cannot have more than " .. GameStore.ItemLimit.HIRELING .. " hirelings." })
end
-- TODO: Use the correct dialog (byte 0xDB) on client 1205+
-- for compatibility, request name using the change name dialog
Expand Down Expand Up @@ -2219,7 +2222,8 @@ function sendHomePage(playerId)
msg:sendToPlayer(player)
end

function Player:openStore(serviceName) --exporting the method so other scripts can use to open store
--exporting the method so other scripts can use to open store
function Player:openStore(serviceName)
local playerId = self:getId()
openStore(playerId)

Expand Down
16 changes: 8 additions & 8 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3273,13 +3273,6 @@ ReturnValue Player::queryAdd(int32_t index, const std::shared_ptr<Thing> &thing,
case CONST_SLOT_LEFT: {
if (item->isQuiver()) {
ret = RETURNVALUE_CANNOTBEDRESSED;
} else if (slotPosition & SLOTP_LEFT) {
WeaponType_t type = item->getWeaponType();
if (type == WEAPON_NONE || type == WEAPON_SHIELD || type == WEAPON_AMMO) {
ret = RETURNVALUE_CANNOTBEDRESSED;
} else {
ret = RETURNVALUE_NOERROR;
}
} else if (slotPosition & SLOTP_TWO_HAND) {
if (inventory[CONST_SLOT_RIGHT]) {
WeaponType_t type = item->getWeaponType();
Expand All @@ -3292,6 +3285,13 @@ ReturnValue Player::queryAdd(int32_t index, const std::shared_ptr<Thing> &thing,
} else {
ret = RETURNVALUE_NOERROR;
}
} else if (slotPosition & SLOTP_LEFT) {
WeaponType_t type = item->getWeaponType();
if (type == WEAPON_NONE || type == WEAPON_SHIELD || type == WEAPON_AMMO) {
ret = RETURNVALUE_CANNOTBEDRESSED;
} else {
ret = RETURNVALUE_NOERROR;
}
} else if (inventory[CONST_SLOT_RIGHT]) {
std::shared_ptr<Item> rightItem = inventory[CONST_SLOT_RIGHT];
WeaponType_t type = item->getWeaponType(), rightType = rightItem->getWeaponType();
Expand Down Expand Up @@ -6690,7 +6690,7 @@ void Player::triggerTranscendance() {
outfit.lookType = getVocation()->getAvatarLookType();
outfitCondition->setOutfit(outfit);
addCondition(outfitCondition);
wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR, OTSYS_TIME() + duration);
wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_FORGE, OTSYS_TIME() + duration);
g_game().addMagicEffect(getPosition(), CONST_ME_AVATAR_APPEAR);
sendTextMessage(MESSAGE_ATTENTION, "Transcendance was triggered.");
sendSkills();
Expand Down
24 changes: 14 additions & 10 deletions src/creatures/players/wheel/player_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2410,21 +2410,25 @@ int32_t PlayerWheel::checkBattleHealingAmount() const {
}

int32_t PlayerWheel::checkAvatarSkill(WheelAvatarSkill_t skill) const {
if (skill == WheelAvatarSkill_t::NONE || getOnThinkTimer(WheelOnThink_t::AVATAR) <= OTSYS_TIME()) {
if (skill == WheelAvatarSkill_t::NONE || (getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL) <= OTSYS_TIME() && getOnThinkTimer(WheelOnThink_t::AVATAR_FORGE) <= OTSYS_TIME())) {
return 0;
}

uint8_t stage = 0;
if (getInstant("Avatar of Light")) {
stage = getStage(WheelStage_t::AVATAR_OF_LIGHT);
} else if (getInstant("Avatar of Steel")) {
stage = getStage(WheelStage_t::AVATAR_OF_STEEL);
} else if (getInstant("Avatar of Nature")) {
stage = getStage(WheelStage_t::AVATAR_OF_NATURE);
} else if (getInstant("Avatar of Storm")) {
stage = getStage(WheelStage_t::AVATAR_OF_STORM);
if (getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL) > OTSYS_TIME()) {
if (getInstant("Avatar of Light")) {
stage = getStage(WheelStage_t::AVATAR_OF_LIGHT);
} else if (getInstant("Avatar of Steel")) {
stage = getStage(WheelStage_t::AVATAR_OF_STEEL);
} else if (getInstant("Avatar of Nature")) {
stage = getStage(WheelStage_t::AVATAR_OF_NATURE);
} else if (getInstant("Avatar of Storm")) {
stage = getStage(WheelStage_t::AVATAR_OF_STORM);
} else {
return 0;
}
} else {
return 0;
stage = 3;
}

if (skill == WheelAvatarSkill_t::DAMAGE_REDUCTION) {
Expand Down
5 changes: 3 additions & 2 deletions src/creatures/players/wheel/wheel_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ enum class WheelOnThink_t : uint8_t {
FOCUS_MASTERY = 4,
GIFT_OF_LIFE = 5,
DIVINE_EMPOWERMENT = 6,
AVATAR = 7,
AVATAR_SPELL = 7,
AVATAR_FORGE = 8,

TOTAL_COUNT = 8
TOTAL_COUNT = 9
};

enum class WheelStat_t : uint8_t {
Expand Down
13 changes: 10 additions & 3 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5384,6 +5384,11 @@ void Game::playerSetManagedContainer(uint32_t playerId, ObjectCategory_t categor
return;
}

if (container->getID() == ITEM_GOLD_POUCH && !isLootContainer) {
player->sendTextMessage(MESSAGE_FAILURE, "You can only set the gold pouch as a loot container.");
return;
}

if (container->getHoldingPlayer() != player) {
player->sendCancelMessage("You must be holding the container to set it as a loot container.");
return;
Expand Down Expand Up @@ -7836,9 +7841,11 @@ void Game::addBestiaryList(uint16_t raceid, std::string name) {
}

void Game::broadcastMessage(const std::string &text, MessageClasses type) const {
g_logger().info("Broadcasted message: {}", text);
for (const auto &it : players) {
it.second->sendTextMessage(type, text);
if (!text.empty()) {
g_logger().info("Broadcasted message: {}", text);
for (const auto &it : players) {
it.second->sendTextMessage(type, text);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3997,9 +3997,9 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) {
}

if (lua_gettop(L) == 1) {
lua_pushnumber(L, (lua_Number)player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR));
lua_pushnumber(L, (lua_Number)player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL));
} else {
player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR, getNumber<int64_t>(L, 2));
player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_SPELL, getNumber<int64_t>(L, 2));
pushBoolean(L, true);
}
return 1;
Expand Down

0 comments on commit e72b581

Please sign in to comment.