Skip to content

Commit

Permalink
Merge branch 'main' into phacUFPE/fix_party_shared_exp
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE authored Nov 21, 2024
2 parents 0b0ddb6 + ed8abb6 commit 59ec44f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions data-canary/scripts/actions/objects/imbuement_shrine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ function imbuement.onUse(player, item, fromPosition, target, toPosition, isHotke
return true
end

imbuement:position({ x = 1943, y = 1340, z = 7 }, 25061)

imbuement:id(25060, 25061, 25103, 25104, 25202, 25174, 25175, 25182, 25183)
imbuement:register()
3 changes: 2 additions & 1 deletion data/events/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder,
end

-- Reward System
if toPosition.x == CONTAINER_POSITION then
local containerThing = tile and tile:getItemByType(ITEM_TYPE_CONTAINER)
if containerThing and toPosition.x == CONTAINER_POSITION then
local containerId = toPosition.y - 64
local container = self:getContainerById(containerId)
if not container then
Expand Down
15 changes: 8 additions & 7 deletions data/libs/systems/blessing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ Blessings.BuyAllBlesses = function(player)
local hasToF = Blessings.Config.HasToF and player:hasBlessing(1) or true
local missingBless = player:getBlessings(nil, donthavefilter)
local missingBlessAmt = #missingBless + (hasToF and 0 or 1)
local totalCost
for i, bless in ipairs(missingBless) do
local totalCost = 0

for _, bless in ipairs(missingBless) do
totalCost = totalCost + Blessings.getBlessingCost(player:getLevel(), true, bless.id >= 7)
end

Expand All @@ -274,19 +275,19 @@ Blessings.BuyAllBlesses = function(player)
end

if player:removeMoneyBank(totalCost) then
metrics.addCounter("balance_decrease", remainsPrice, {
metrics.addCounter("balance_decrease", totalCost, {
player = player:getName(),
context = "blessings",
})

for i, v in ipairs(missingBless) do
player:addBlessing(v.id, 1)
for _, bless in ipairs(missingBless) do
player:addBlessing(bless.id, 1)
end

player:sendCancelMessage("You received the remaining " .. missingBlessAmt .. " blesses for a total of " .. totalCost .. " gold.")
player:sendCancelMessage(string.format("You received the remaining %d blesses for a total of %d gold.", missingBlessAmt, totalCost))
player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
else
player:sendCancelMessage("You don't have enough money. You need " .. totalCost .. " to buy all blesses.", cid)
player:sendCancelMessage(string.format("You don't have enough money. You need %d to buy all blesses.", totalCost))
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end

Expand Down
33 changes: 29 additions & 4 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3409,18 +3409,22 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* =
const auto &slotItem = player->getInventoryItem(slot);
const auto &equipItem = searchForItem(backpack, it.id, hasTier, tier);
ReturnValue ret = RETURNVALUE_NOERROR;

if (slotItem && slotItem->getID() == it.id && (!it.stackable || slotItem->getItemCount() == slotItem->getStackSize() || !equipItem)) {
ret = internalMoveItem(slotItem->getParent(), player, CONST_SLOT_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr);
g_logger().debug("Item {} was unequipped", slotItem->getName());
} else if (equipItem) {
// Shield slot item
const auto &rightItem = player->getInventoryItem(CONST_SLOT_RIGHT);

// Check Ammo item
if (it.weaponType == WEAPON_AMMO) {
if (rightItem && rightItem->isQuiver()) {
ret = internalMoveItem(equipItem->getParent(), rightItem->getContainer(), 0, equipItem, equipItem->getItemCount(), nullptr);
}
} else {
const auto &leftItem = player->getInventoryItem(CONST_SLOT_LEFT);

const int32_t &slotPosition = equipItem->getSlotPosition();
// Checks if a two-handed item is being equipped in the left slot when the right slot is already occupied and move to backpack
if (
Expand All @@ -3429,10 +3433,35 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* =
&& rightItem
&& !(it.weaponType == WEAPON_DISTANCE)
&& !rightItem->isQuiver()
&& (!leftItem || leftItem->getWeaponType() != WEAPON_DISTANCE)
) {
ret = internalCollectManagedItems(player, rightItem, getObjectCategory(rightItem), false);
}

// Check if trying to equip a quiver while another quiver is already equipped in the right slot
if (slot == CONST_SLOT_RIGHT && rightItem && rightItem->isQuiver() && it.isQuiver()) {
// Replace the existing quiver with the new one
ret = internalMoveItem(rightItem->getParent(), player, INDEX_WHEREEVER, rightItem, rightItem->getItemCount(), nullptr);
if (ret == RETURNVALUE_NOERROR) {
g_logger().debug("Quiver {} was unequipped to equip new quiver", rightItem->getName());
} else {
player->sendCancelMessage(ret);
return;
}
} else {
// Check if trying to equip a shield while a two-handed weapon is equipped in the left slot
if (slot == CONST_SLOT_RIGHT && leftItem && leftItem->getSlotPosition() & SLOTP_TWO_HAND) {
// Unequip the two-handed weapon from the left slot
ret = internalMoveItem(leftItem->getParent(), player, INDEX_WHEREEVER, leftItem, leftItem->getItemCount(), nullptr);
if (ret == RETURNVALUE_NOERROR) {
g_logger().debug("Two-handed weapon {} was unequipped to equip shield", leftItem->getName());
} else {
player->sendCancelMessage(ret);
return;
}
}
}

if (slotItem) {
ret = internalMoveItem(slotItem->getParent(), player, INDEX_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr);
g_logger().debug("Item {} was moved back to player", slotItem->getName());
Expand Down Expand Up @@ -7428,10 +7457,6 @@ bool Game::combatChangeHealth(const std::shared_ptr<Creature> &attacker, const s

target->drainHealth(attacker, realDamage);
if (realDamage > 0 && targetMonster) {
if (attackerPlayer && attackerPlayer->getPlayer()) {
attackerPlayer->updateImpactTracker(damage.secondary.type, damage.secondary.value);
}

if (targetMonster->israndomStepping()) {
targetMonster->setIgnoreFieldDamage(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lua/functions/lua_functions_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Lua {
static void setCreatureMetatable(lua_State* L, int32_t index, const std::shared_ptr<Creature> &creature);

template <typename T>
static T getNumber(lua_State* L, int32_t arg) {
static T getNumber(lua_State* L, int32_t arg, std::source_location location = std::source_location::current()) {
auto number = lua_tonumber(L, arg);

if constexpr (std::is_enum_v<T>) {
Expand All @@ -73,7 +73,7 @@ class Lua {
if constexpr (std::is_integral_v<T>) {
if constexpr (std::is_unsigned_v<T>) {
if (number < 0) {
g_logger().debug("[{}] overflow, setting to default unsigned value (0)", __FUNCTION__);
g_logger().debug("[{}] overflow, setting to default unsigned value (0), called line: {}:{}, in {}", __FUNCTION__, location.line(), location.column(), location.function_name());
return T(0);
}
}
Expand Down

0 comments on commit 59ec44f

Please sign in to comment.