Skip to content

Commit

Permalink
fix: price mismatch between NPCs and typo in the rent house message (o…
Browse files Browse the repository at this point in the history
…pentibiabr#2830)

Monitoring feature to alert whenever there's a price mismatch between NPCs for item transactions.
This ensures any instance where an item is sold for less than its purchase price, or vice versa, is promptly identified and reported.

Co-authored-by: Leilani A. <[email protected]>
  • Loading branch information
Majesty and kaleohanopahala authored Aug 29, 2024
1 parent 06c6a67 commit 0f8929d
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 60 deletions.
3 changes: 0 additions & 3 deletions data-otservbr-global/npc/arito.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ npcConfig.shop = {
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
2 changes: 0 additions & 2 deletions data-otservbr-global/npc/armenius.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ npcConfig.shop = {
{ itemName = "mug of rum", clientId = 2880, buy = 10, count = 13 },
{ itemName = "mug of wine", clientId = 2880, buy = 4, count = 2 },
{ itemName = "tomato", clientId = 3596, buy = 3 },
{ itemName = "vial of beer", clientId = 2874, buy = 3, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 4, count = 1, subType = 2 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
1 change: 0 additions & 1 deletion data-otservbr-global/npc/bolfona.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ npcConfig.shop = {
{ itemName = "ham", clientId = 3582, buy = 8 },
{ itemName = "meat", clientId = 3577, buy = 5 },
{ itemName = "mug of beer", clientId = 2880, buy = 2, count = 3 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
2 changes: 0 additions & 2 deletions data-otservbr-global/npc/boozer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ npcConfig.shop = {
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
{ itemName = "mug of water", clientId = 2880, buy = 2, count = 1 },
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
3 changes: 0 additions & 3 deletions data-otservbr-global/npc/clyde.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ npcConfig.shop = {
{ itemName = "mug of water", clientId = 2880, buy = 2, count = 1 },
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "tomato", clientId = 3596, buy = 3 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
2 changes: 0 additions & 2 deletions data-otservbr-global/npc/dane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ npcConfig.shop = {
{ itemName = "bottle of lemonade", clientId = 2875, buy = 12, count = 12 },
{ itemName = "bottle of milk", clientId = 2875, buy = 4, count = 9 },
{ itemName = "bottle of water", clientId = 2875, buy = 2, count = 1 },
{ itemName = "vial of milk", clientId = 2874, buy = 4, count = 1, subType = 9 },
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
2 changes: 0 additions & 2 deletions data-otservbr-global/npc/maria.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ npcConfig.shop = {
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "tomato", clientId = 3596, buy = 5 },
{ itemName = "valentine's cake", clientId = 6392, buy = 100 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
3 changes: 0 additions & 3 deletions data-otservbr-global/npc/mirabell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ npcConfig.shop = {
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
2 changes: 0 additions & 2 deletions data-otservbr-global/npc/miraia.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ npcConfig.shop = {
{ itemName = "mug of milk", clientId = 2880, buy = 5, count = 9 },
{ itemName = "mug of water", clientId = 2880, buy = 2, count = 1 },
{ itemName = "scarab cheese", clientId = 169, buy = 100 },
{ itemName = "vial of milk", clientId = 2874, buy = 5, count = 1, subType = 9 },
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
3 changes: 0 additions & 3 deletions data-otservbr-global/npc/norma.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ npcConfig.shop = {
{ itemName = "mug of milk", clientId = 2880, buy = 2, count = 6 },
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "party cake", clientId = 6279, buy = 50 },
{ itemName = "vial of beer", clientId = 2874, buy = 3, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
{ itemName = "vial of milk", clientId = 2874, buy = 2, count = 1, subType = 9 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
3 changes: 0 additions & 3 deletions data-otservbr-global/npc/pugwah.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ npcConfig.shop = {
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
{ itemName = "mug of milk", clientId = 2880, buy = 2, count = 6 },
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "vial of beer", clientId = 2874, buy = 3, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 4, count = 1, subType = 2 },
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
4 changes: 1 addition & 3 deletions data-otservbr-global/npc/ramina.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ npcConfig.shop = {
{ itemName = "mug of wine", clientId = 2880, buy = 15, count = 2 },
{ itemName = "orange", clientId = 3586, buy = 12 },
{ itemName = "peas", clientId = 11683, buy = 5 },
{ itemName = "vial of fruit juice", clientId = 2874, buy = 10, count = 14 },
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
{ itemName = "vial of wine", clientId = 2874, buy = 15, count = 1, subType = 2 },
{ itemName = "vial of water", clientId = 2874, buy = 10, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/npc/red_lilly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ npcConfig.shop = {
{ itemName = "torch", clientId = 2920, buy = 2 },
{ itemName = "vial", clientId = 2874, sell = 5 },
{ itemName = "vial of oil", clientId = 2874, buy = 20, count = 7 },
{ itemName = "vial of water", clientId = 2874, buy = 10, count = 1 },
{ itemName = "vial of water", clientId = 2874, buy = 20, count = 1 },
{ itemName = "watch", clientId = 2906, buy = 20, sell = 6 },
{ itemName = "waterskin of water", clientId = 2901, buy = 10, count = 1 },
{ itemName = "wooden hammer", clientId = 3459, sell = 15 },
Expand Down
2 changes: 0 additions & 2 deletions data-otservbr-global/npc/swolt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ npcConfig.shop = {
{ itemName = "mug of beer", clientId = 2880, buy = 2, count = 3 },
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
{ itemName = "terramite eggs", clientId = 10453, sell = 50 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
2 changes: 0 additions & 2 deletions data-otservbr-global/npc/tanaro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ npcConfig.shop = {
{ itemName = "salmon", clientId = 3579, buy = 6 },
{ itemName = "valentine's cake", clientId = 6392, buy = 100 },
{ itemName = "white mushroom", clientId = 3723, buy = 6 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
3 changes: 0 additions & 3 deletions data-otservbr-global/npc/urkalio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ npcConfig.shop = {
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
}
-- On buy npc shop message
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)
Expand Down
76 changes: 54 additions & 22 deletions data/scripts/lib/register_npc_type.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,57 @@ registerNpcType.events = function(npcType, mask)
end
end

-- Global item tracker to track buy and sell prices across all NPCs
NpcPriceChecker = NpcPriceChecker or {}

registerNpcType.shop = function(npcType, mask)
if type(mask.shop) == "table" then
for _, shopItems in pairs(mask.shop) do
local parent = Shop()
if shopItems.itemName or shopItems.itemname then
parent:setNameItem(shopItems.itemName or shopItems.itemname)
local itemName = shopItems.itemName or shopItems.itemname
local clientId = shopItems.clientId or shopItems.clientid
local buyPrice = shopItems.buy
local sellPrice = shopItems.sell
local npcName = npcType:getName() -- Assuming `npcType` has a `getName` method to get the NPC's name

if itemName then
parent:setNameItem(itemName)
end
if shopItems.clientId or shopItems.clientid then
parent:setId(shopItems.clientId or shopItems.clientid)
if clientId then
parent:setId(clientId)
end
if shopItems.subType or shopItems.subtype or shopItems.count then
parent:setCount(shopItems.subType or shopItems.subtype or shopItems.count)
end
if shopItems.buy then
parent:setBuyPrice(shopItems.buy)
if buyPrice then
parent:setBuyPrice(buyPrice)
end
if sellPrice then
parent:setSellPrice(sellPrice)
end
if shopItems.sell then
parent:setSellPrice(shopItems.sell)

if clientId then
if not NpcPriceChecker[clientId] then
NpcPriceChecker[clientId] = { buy = nil, sell = nil, buyNpc = nil, sellNpc = nil }
end

if buyPrice then
NpcPriceChecker[clientId].buy = buyPrice
NpcPriceChecker[clientId].buyNpc = npcName
end

if sellPrice then
NpcPriceChecker[clientId].sell = sellPrice
NpcPriceChecker[clientId].sellNpc = npcName
end

if NpcPriceChecker[clientId].buy and NpcPriceChecker[clientId].sell then
if NpcPriceChecker[clientId].sell > NpcPriceChecker[clientId].buy then
logger.warn("The item {} ({}) is being sold for a value greater than the value it is purchased for by the NPCs. Buy NPC: {}, Sell NPC: {}", itemName, clientId, NpcPriceChecker[clientId].buyNpc, NpcPriceChecker[clientId].sellNpc)
end
end
end

if shopItems.storageKey or shopItems.storagekey then
parent:setStorageKey(shopItems.storageKey or shopItems.storagekey)
end
Expand All @@ -169,26 +201,26 @@ registerNpcType.shop = function(npcType, mask)
if shopItems.child then
for _, children in pairs(shopItems.child) do
local child = Shop()
if shopItems.itemName or shopItems.itemname then
child:setNameItem(shopItems.itemName or shopItems.itemname)
if children.itemName or children.itemname then
child:setNameItem(children.itemName or children.itemname)
end
if shopItems.clientId or shopItems.clientid then
child:setId(shopItems.clientId or shopItems.clientid)
if children.clientId or children.clientid then
child:setId(children.clientId or children.clientid)
end
if shopItems.subType or shopItems.subtype or shopItems.count then
child:setCount(shopItems.subType or shopItems.subtype or shopItems.count)
if children.subType or children.subtype or children.count then
child:setCount(children.subType or children.subtype or children.count)
end
if shopItems.buy then
child:setBuyPrice(shopItems.buy)
if children.buy then
child:setBuyPrice(children.buy)
end
if shopItems.sell then
child:setSellPrice(shopItems.sell)
if children.sell then
child:setSellPrice(children.sell)
end
if shopItems.storageKey or shopItems.storagekey then
child:setStorageKey(shopItems.storageKey or shopItems.storagekey)
if children.storageKey or children.storagekey then
child:setStorageKey(children.storageKey or children.storagekey)
end
if shopItems.storageValue or shopItems.storagevalue then
child:setStorageValue(shopItems.storageValue or shopItems.storagevalue)
if children.storageValue or children.storagevalue then
child:setStorageValue(children.storageValue or children.storagevalue)
end
parent:addChildShop(child)
end
Expand Down
2 changes: 1 addition & 1 deletion src/map/house/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const {
}

std::ostringstream ss;
ss << "Warning! \nThe " << period << " rent of " << house->getRent() << " gold for your house \"" << house->getName() << "\" is payable. Have it within " << daysLeft << " days or you will lose static_self_cast<HouseTransferItem>() house.";
ss << "Warning! \nThe " << period << " rent of " << house->getRent() << " gold for your house \"" << house->getName() << "\" is payable. Have it within " << daysLeft << " days or you will lose this house.";
letter->setAttribute(ItemAttribute_t::TEXT, ss.str());
g_game().internalAddItem(player->getInbox(), letter, INDEX_WHEREEVER, FLAG_NOLIMIT);
house->setPayRentWarnings(house->getPayRentWarnings() + 1);
Expand Down

0 comments on commit 0f8929d

Please sign in to comment.