Skip to content

Commit

Permalink
Merge branch 'main' into merge-branches
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Mar 21, 2024
2 parents 509ea09 + 198f79b commit 0351c06
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 38 deletions.
8 changes: 6 additions & 2 deletions data-otservbr-global/npc/cledwyn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ end

local charge = {}

local chargePrice = {}

local chargeItem = {
["pendulet"] = { noChargeID = 29429, ChargeID = 30344 },
["sleep shawl"] = { noChargeID = 29428, ChargeID = 30342 },
Expand Down Expand Up @@ -137,18 +139,20 @@ local function creatureSayCallback(npc, creature, type, message)
elseif table.contains({ "pendulet", "sleep shawl", "blister ring", "theurgic amulet", "ring of souls", "turtle amulet" }, message:lower()) and npcHandler:getTopic(playerId) == 1 then
npcHandler:say("Should I enchant the item " .. message .. " for 2 " .. ItemType(npc:getCurrency()):getPluralName():lower() .. "?", npc, creature)
charge = message:lower()
chargePrice = 2
npcHandler:setTopic(playerId, 2)
elseif table.contains({ "spiritthorn ring", "alicorn ring", "arcanomancer sigil", "arboreal ring" }, message:lower()) and npcHandler:getTopic(playerId) == 1 then
npcHandler:say("Should I enchant the item " .. message .. " for 5 " .. ItemType(npc:getCurrency()):getPluralName():lower() .. "?", npc, creature)
charge = message:lower()
chargePrice = 5
npcHandler:setTopic(playerId, 2)
elseif npcHandler:getTopic(playerId) == 2 then
if MsgContains(message, "yes") then
if not chargeItem[charge] then
npcHandler:say("Sorry, you don't have an unenchanted " .. charge .. ".", npc, creature)
else
if (player:getItemCount(npc:getCurrency()) >= 2) and (player:getItemCount(chargeItem[charge].noChargeID) >= 1) then
player:removeItem(npc:getCurrency(), 2)
if (player:getItemCount(npc:getCurrency()) >= chargePrice) and (player:getItemCount(chargeItem[charge].noChargeID) >= 1) then
player:removeItem(npc:getCurrency(), chargePrice)
player:removeItem(chargeItem[charge].noChargeID, 1)
local itemAdd = player:addItem(chargeItem[charge].ChargeID, 1)
npcHandler:say("Ah, excellent. Here is your " .. itemAdd:getName():lower() .. ".", npc, creature)
Expand Down
40 changes: 31 additions & 9 deletions data/npclib/npc_system/bank_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,41 @@ function Npc:parseBank(message, npc, creature, npcHandler)
return true
elseif npcHandler:getTopic(playerId) == 7 then
if MsgContains(message, "yes") then
local totalValue = count[playerId]
local crystalCoins = math.floor(totalValue / 10000)
totalValue = totalValue % 10000
local platinumCoins = math.floor(totalValue / 100)
totalValue = totalValue % 100
local goldCoins = math.floor(totalValue / 1)
local crystalPiles = math.floor((crystalCoins + 99) / 100)
local platinumPiles = math.floor((platinumCoins + 99) / 100)
local goldPiles = math.floor((goldCoins + 99) / 100)
local totalPiles = crystalPiles + platinumPiles + goldPiles
if player:getFreeCapacity() >= getMoneyWeight(count[playerId]) then
if not player:withdrawMoney(count[playerId]) then
npcHandler:say("There is not enough gold on your account.", npc, creature)
if player:getFreeBackpackSlots() >= totalPiles then
if not player:withdrawMoney(count[playerId]) then
npcHandler:say("There is not enough gold on your account.", npc, creature)
else
npcHandler:say(string.format("Here you are, %i gold. Please let me know if there is something else I can do for you.", count[playerId]), npc, creature)
end
else
npcHandler:say(string.format("Here you are, %d gold. Please let me know if there is something else I can do for you.", count[playerId]), npc, creature)
npcHandler:say(
string.format(
"Hold on, you don't have enough room in your backpack to carry all these coins. \nI don't want you to drop them on the floor, perhaps come back when you have more space in your backpack!\nYou will receive %i crystal stacks (%i coins), %i platinum stacks (%i coins), and %i gold stacks (%i coins). Please ensure you have at least %i free slots in your backpack.\n",
crystalPiles,
crystalCoins,
platinumPiles,
platinumCoins,
goldPiles,
goldCoins,
totalPiles
),
npc,
creature
)
end
else
npcHandler:say(
"Whoah, hold on, you have no room in your inventory to carry all those coins. \z
I don't want you to drop it on the floor, maybe come back with a cart!",
npc,
creature
)
npcHandler:say("Whoah, hold on, you have no free capacity to carry all those coins!", npc, creature)
end
npcHandler:setTopic(playerId, 0)
elseif MsgContains(message, "no") then
Expand Down
1 change: 1 addition & 0 deletions data/scripts/runes/avalanche.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ rune:level(30)
rune:magicLevel(4)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
2 changes: 1 addition & 1 deletion data/scripts/runes/energy_bomb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ rune:level(37)
rune:magicLevel(10)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(true) -- True = Solid / False = Creature
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
2 changes: 1 addition & 1 deletion data/scripts/runes/energy_wall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ rune:level(41)
rune:magicLevel(9)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(true) -- True = Solid / False = Creature
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
2 changes: 1 addition & 1 deletion data/scripts/runes/fire_bomb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ rune:level(27)
rune:magicLevel(5)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(true) -- True = Solid / False = Creature
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
2 changes: 1 addition & 1 deletion data/scripts/runes/fire_wall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ rune:level(33)
rune:magicLevel(6)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(true) -- True = Solid / False = Creature
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
2 changes: 1 addition & 1 deletion data/scripts/runes/great_fireball.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ rune:level(30)
rune:magicLevel(4)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(true) -- True = Solid / False = Creature
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
2 changes: 1 addition & 1 deletion data/scripts/runes/poison_bomb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ rune:level(25)
rune:magicLevel(4)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(true) -- True = Solid / False = Creature
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
2 changes: 1 addition & 1 deletion data/scripts/runes/poison_wall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ rune:level(29)
rune:magicLevel(5)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(true) -- True = Solid / False = Creature
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
1 change: 1 addition & 0 deletions data/scripts/runes/stone_shower.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ rune:level(28)
rune:magicLevel(4)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
1 change: 1 addition & 0 deletions data/scripts/runes/thunderstorm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ rune:level(28)
rune:magicLevel(4)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:isBlocking(false) -- True = Solid / False = Creature
rune:register()
4 changes: 2 additions & 2 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ void Combat::setupChain(const std::shared_ptr<Weapon> &weapon) {
}

const auto &weaponType = weapon->getWeaponType();
if (weaponType == WEAPON_NONE || weaponType == WEAPON_SHIELD || weaponType == WEAPON_AMMO || weaponType == WEAPON_DISTANCE) {
if (weaponType == WEAPON_NONE || weaponType == WEAPON_SHIELD || weaponType == WEAPON_AMMO || weaponType == WEAPON_DISTANCE || weaponType == WEAPON_MISSILE) {
return;
}

Expand Down Expand Up @@ -2131,7 +2131,7 @@ void Combat::applyExtensions(std::shared_ptr<Creature> caster, std::shared_ptr<C
if (player) {
chance = player->getSkillLevel(SKILL_CRITICAL_HIT_CHANCE);
bonus = player->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE);
if (target) {
if (target && target->getMonster()) {
uint16_t playerCharmRaceid = player->parseRacebyCharm(CHARM_LOW, false, 0);
if (playerCharmRaceid != 0) {
const auto mType = g_monsters().getMonsterType(target->getName());
Expand Down
38 changes: 25 additions & 13 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3153,28 +3153,40 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* =

auto slotItem = player->getInventoryItem(slot);
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)) {
internalMoveItem(slotItem->getParent(), player, CONST_SLOT_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr);
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) {
auto quiver = player->getInventoryItem(CONST_SLOT_RIGHT);
if (quiver && quiver->isQuiver()) {
internalMoveItem(equipItem->getParent(), quiver->getContainer(), 0, equipItem, equipItem->getItemCount(), nullptr);
return;
if (rightItem && rightItem->isQuiver()) {
ret = internalMoveItem(equipItem->getParent(), rightItem->getContainer(), 0, equipItem, equipItem->getItemCount(), nullptr);
}
} else {
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 (slotPosition & SLOTP_LEFT && rightItem && (slotPosition & SLOTP_TWO_HAND)) {
ret = internalCollectManagedItems(player, rightItem, getObjectCategory(rightItem), false);
}
}

if (slotItem) {
internalMoveItem(slotItem->getParent(), player, INDEX_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr);
g_logger().debug("Item {} was moved back to player", slotItem->getName());
}
if (slotItem) {
ret = internalMoveItem(slotItem->getParent(), player, INDEX_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr);
g_logger().debug("Item {} was moved back to player", slotItem->getName());
}

auto ret = internalMoveItem(equipItem->getParent(), player, slot, equipItem, equipItem->getItemCount(), nullptr);
if (ret == RETURNVALUE_NOERROR) {
g_logger().debug("Item {} was equipped", equipItem->getName());
ret = internalMoveItem(equipItem->getParent(), player, slot, equipItem, equipItem->getItemCount(), nullptr);
if (ret == RETURNVALUE_NOERROR) {
g_logger().debug("Item {} was equipped", equipItem->getName());
}
}
}

if (ret != RETURNVALUE_NOERROR) {
player->sendCancelMessage(ret);
}
}

void Game::playerMove(uint32_t playerId, Direction direction) {
Expand Down
13 changes: 8 additions & 5 deletions src/items/functions/item/item_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,14 +1165,16 @@ void ItemParse::createAndRegisterScript(ItemType &itemType, pugi::xml_node attri
} else {
g_logger().warn("[{}] - wandtype '{}' does not exist", __FUNCTION__, elementName);
}

} else if (stringKey == "chain" && weapon) {
if (auto value = subValueAttribute.as_double()) {
weapon->setChainSkillValue(value);
g_logger().trace("Found chain skill value '{}' for weapon: {}", value, itemType.name);
auto doubleValue = subValueAttribute.as_double();
if (doubleValue > 0) {
weapon->setChainSkillValue(doubleValue);
g_logger().trace("Found chain skill value '{}' for weapon: {}", doubleValue, itemType.name);
}
if (subValueAttribute.as_bool() == false) {
if (doubleValue < 0.1 && subValueAttribute.as_bool() == false) {
weapon->setDisabledChain();
g_logger().warn("Chain disabled for weapon: {}", itemType.name);
g_logger().trace("Chain disabled for weapon: {}", itemType.name);
}
}
}
Expand All @@ -1182,6 +1184,7 @@ void ItemParse::createAndRegisterScript(ItemType &itemType, pugi::xml_node attri
g_logger().trace("Added weapon damage from '{}', to '{}'", fromDamage, toDamage);
weaponWand->setMinChange(fromDamage);
weaponWand->setMaxChange(toDamage);
weaponWand->configureWeapon(itemType);
}

auto combat = weapon->getCombat();
Expand Down

0 comments on commit 0351c06

Please sign in to comment.