Skip to content

Commit 0f8929d

Browse files
fix: price mismatch between NPCs and typo in the rent house message (#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. <168607226+kaleohanopahala@users.noreply.github.com>
1 parent 06c6a67 commit 0f8929d

18 files changed

+57
-60
lines changed

data-otservbr-global/npc/arito.lua

-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ npcConfig.shop = {
134134
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
135135
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
136136
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
137-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
138-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
139-
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
140137
}
141138
-- On buy npc shop message
142139
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/armenius.lua

-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ npcConfig.shop = {
9797
{ itemName = "mug of rum", clientId = 2880, buy = 10, count = 13 },
9898
{ itemName = "mug of wine", clientId = 2880, buy = 4, count = 2 },
9999
{ itemName = "tomato", clientId = 3596, buy = 3 },
100-
{ itemName = "vial of beer", clientId = 2874, buy = 3, count = 1, subType = 3 },
101-
{ itemName = "vial of wine", clientId = 2874, buy = 4, count = 1, subType = 2 },
102100
}
103101
-- On buy npc shop message
104102
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/bolfona.lua

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ npcConfig.shop = {
103103
{ itemName = "ham", clientId = 3582, buy = 8 },
104104
{ itemName = "meat", clientId = 3577, buy = 5 },
105105
{ itemName = "mug of beer", clientId = 2880, buy = 2, count = 3 },
106-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
107106
}
108107
-- On buy npc shop message
109108
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/boozer.lua

-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ npcConfig.shop = {
9898
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
9999
{ itemName = "mug of water", clientId = 2880, buy = 2, count = 1 },
100100
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
101-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
102-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
103101
}
104102
-- On buy npc shop message
105103
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/clyde.lua

-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ npcConfig.shop = {
6464
{ itemName = "mug of water", clientId = 2880, buy = 2, count = 1 },
6565
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
6666
{ itemName = "tomato", clientId = 3596, buy = 3 },
67-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
68-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
69-
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
7067
}
7168
-- On buy npc shop message
7269
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/dane.lua

-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ npcConfig.shop = {
6767
{ itemName = "bottle of lemonade", clientId = 2875, buy = 12, count = 12 },
6868
{ itemName = "bottle of milk", clientId = 2875, buy = 4, count = 9 },
6969
{ itemName = "bottle of water", clientId = 2875, buy = 2, count = 1 },
70-
{ itemName = "vial of milk", clientId = 2874, buy = 4, count = 1, subType = 9 },
71-
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
7270
}
7371
-- On buy npc shop message
7472
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/maria.lua

-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ npcConfig.shop = {
6565
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
6666
{ itemName = "tomato", clientId = 3596, buy = 5 },
6767
{ itemName = "valentine's cake", clientId = 6392, buy = 100 },
68-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
69-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
7068
}
7169
-- On buy npc shop message
7270
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/mirabell.lua

-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ npcConfig.shop = {
134134
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
135135
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
136136
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
137-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
138-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
139-
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
140137
}
141138
-- On buy npc shop message
142139
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/miraia.lua

-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ npcConfig.shop = {
200200
{ itemName = "mug of milk", clientId = 2880, buy = 5, count = 9 },
201201
{ itemName = "mug of water", clientId = 2880, buy = 2, count = 1 },
202202
{ itemName = "scarab cheese", clientId = 169, buy = 100 },
203-
{ itemName = "vial of milk", clientId = 2874, buy = 5, count = 1, subType = 9 },
204-
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
205203
}
206204
-- On buy npc shop message
207205
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/norma.lua

-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ npcConfig.shop = {
200200
{ itemName = "mug of milk", clientId = 2880, buy = 2, count = 6 },
201201
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
202202
{ itemName = "party cake", clientId = 6279, buy = 50 },
203-
{ itemName = "vial of beer", clientId = 2874, buy = 3, count = 1, subType = 3 },
204-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
205-
{ itemName = "vial of milk", clientId = 2874, buy = 2, count = 1, subType = 9 },
206203
}
207204
-- On buy npc shop message
208205
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/pugwah.lua

-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ npcConfig.shop = {
6161
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
6262
{ itemName = "mug of milk", clientId = 2880, buy = 2, count = 6 },
6363
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
64-
{ itemName = "vial of beer", clientId = 2874, buy = 3, count = 1, subType = 3 },
65-
{ itemName = "vial of wine", clientId = 2874, buy = 4, count = 1, subType = 2 },
66-
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
6764
}
6865
-- On buy npc shop message
6966
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/ramina.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ npcConfig.shop = {
6464
{ itemName = "mug of wine", clientId = 2880, buy = 15, count = 2 },
6565
{ itemName = "orange", clientId = 3586, buy = 12 },
6666
{ itemName = "peas", clientId = 11683, buy = 5 },
67-
{ itemName = "vial of fruit juice", clientId = 2874, buy = 10, count = 14 },
68-
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
69-
{ itemName = "vial of wine", clientId = 2874, buy = 15, count = 1, subType = 2 },
67+
{ itemName = "vial of water", clientId = 2874, buy = 10, count = 1 },
7068
}
7169
-- On buy npc shop message
7270
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/red_lilly.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ npcConfig.shop = {
8585
{ itemName = "torch", clientId = 2920, buy = 2 },
8686
{ itemName = "vial", clientId = 2874, sell = 5 },
8787
{ itemName = "vial of oil", clientId = 2874, buy = 20, count = 7 },
88-
{ itemName = "vial of water", clientId = 2874, buy = 10, count = 1 },
88+
{ itemName = "vial of water", clientId = 2874, buy = 20, count = 1 },
8989
{ itemName = "watch", clientId = 2906, buy = 20, sell = 6 },
9090
{ itemName = "waterskin of water", clientId = 2901, buy = 10, count = 1 },
9191
{ itemName = "wooden hammer", clientId = 3459, sell = 15 },

data-otservbr-global/npc/swolt.lua

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ npcConfig.shop = {
8686
{ itemName = "mug of beer", clientId = 2880, buy = 2, count = 3 },
8787
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
8888
{ itemName = "terramite eggs", clientId = 10453, sell = 50 },
89-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
90-
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
9189
}
9290
-- On buy npc shop message
9391
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/tanaro.lua

-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ npcConfig.shop = {
6767
{ itemName = "salmon", clientId = 3579, buy = 6 },
6868
{ itemName = "valentine's cake", clientId = 6392, buy = 100 },
6969
{ itemName = "white mushroom", clientId = 3723, buy = 6 },
70-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
71-
{ itemName = "vial of water", clientId = 2874, buy = 2, count = 1 },
7270
}
7371
-- On buy npc shop message
7472
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data-otservbr-global/npc/urkalio.lua

-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ npcConfig.shop = {
6262
{ itemName = "mug of lemonade", clientId = 2880, buy = 2, count = 12 },
6363
{ itemName = "mug of water", clientId = 2880, buy = 1, count = 1 },
6464
{ itemName = "mug of wine", clientId = 2880, buy = 3, count = 2 },
65-
{ itemName = "vial of beer", clientId = 2874, buy = 2, count = 1, subType = 3 },
66-
{ itemName = "vial of wine", clientId = 2874, buy = 3, count = 1, subType = 2 },
67-
{ itemName = "vial of water", clientId = 2874, buy = 1, count = 1 },
6865
}
6966
-- On buy npc shop message
7067
npcType.onBuyItem = function(npc, player, itemId, subType, amount, ignore, inBackpacks, totalCost)

data/scripts/lib/register_npc_type.lua

+54-22
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,57 @@ registerNpcType.events = function(npcType, mask)
141141
end
142142
end
143143

144+
-- Global item tracker to track buy and sell prices across all NPCs
145+
NpcPriceChecker = NpcPriceChecker or {}
146+
144147
registerNpcType.shop = function(npcType, mask)
145148
if type(mask.shop) == "table" then
146149
for _, shopItems in pairs(mask.shop) do
147150
local parent = Shop()
148-
if shopItems.itemName or shopItems.itemname then
149-
parent:setNameItem(shopItems.itemName or shopItems.itemname)
151+
local itemName = shopItems.itemName or shopItems.itemname
152+
local clientId = shopItems.clientId or shopItems.clientid
153+
local buyPrice = shopItems.buy
154+
local sellPrice = shopItems.sell
155+
local npcName = npcType:getName() -- Assuming `npcType` has a `getName` method to get the NPC's name
156+
157+
if itemName then
158+
parent:setNameItem(itemName)
150159
end
151-
if shopItems.clientId or shopItems.clientid then
152-
parent:setId(shopItems.clientId or shopItems.clientid)
160+
if clientId then
161+
parent:setId(clientId)
153162
end
154163
if shopItems.subType or shopItems.subtype or shopItems.count then
155164
parent:setCount(shopItems.subType or shopItems.subtype or shopItems.count)
156165
end
157-
if shopItems.buy then
158-
parent:setBuyPrice(shopItems.buy)
166+
if buyPrice then
167+
parent:setBuyPrice(buyPrice)
168+
end
169+
if sellPrice then
170+
parent:setSellPrice(sellPrice)
159171
end
160-
if shopItems.sell then
161-
parent:setSellPrice(shopItems.sell)
172+
173+
if clientId then
174+
if not NpcPriceChecker[clientId] then
175+
NpcPriceChecker[clientId] = { buy = nil, sell = nil, buyNpc = nil, sellNpc = nil }
176+
end
177+
178+
if buyPrice then
179+
NpcPriceChecker[clientId].buy = buyPrice
180+
NpcPriceChecker[clientId].buyNpc = npcName
181+
end
182+
183+
if sellPrice then
184+
NpcPriceChecker[clientId].sell = sellPrice
185+
NpcPriceChecker[clientId].sellNpc = npcName
186+
end
187+
188+
if NpcPriceChecker[clientId].buy and NpcPriceChecker[clientId].sell then
189+
if NpcPriceChecker[clientId].sell > NpcPriceChecker[clientId].buy then
190+
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)
191+
end
192+
end
162193
end
194+
163195
if shopItems.storageKey or shopItems.storagekey then
164196
parent:setStorageKey(shopItems.storageKey or shopItems.storagekey)
165197
end
@@ -169,26 +201,26 @@ registerNpcType.shop = function(npcType, mask)
169201
if shopItems.child then
170202
for _, children in pairs(shopItems.child) do
171203
local child = Shop()
172-
if shopItems.itemName or shopItems.itemname then
173-
child:setNameItem(shopItems.itemName or shopItems.itemname)
204+
if children.itemName or children.itemname then
205+
child:setNameItem(children.itemName or children.itemname)
174206
end
175-
if shopItems.clientId or shopItems.clientid then
176-
child:setId(shopItems.clientId or shopItems.clientid)
207+
if children.clientId or children.clientid then
208+
child:setId(children.clientId or children.clientid)
177209
end
178-
if shopItems.subType or shopItems.subtype or shopItems.count then
179-
child:setCount(shopItems.subType or shopItems.subtype or shopItems.count)
210+
if children.subType or children.subtype or children.count then
211+
child:setCount(children.subType or children.subtype or children.count)
180212
end
181-
if shopItems.buy then
182-
child:setBuyPrice(shopItems.buy)
213+
if children.buy then
214+
child:setBuyPrice(children.buy)
183215
end
184-
if shopItems.sell then
185-
child:setSellPrice(shopItems.sell)
216+
if children.sell then
217+
child:setSellPrice(children.sell)
186218
end
187-
if shopItems.storageKey or shopItems.storagekey then
188-
child:setStorageKey(shopItems.storageKey or shopItems.storagekey)
219+
if children.storageKey or children.storagekey then
220+
child:setStorageKey(children.storageKey or children.storagekey)
189221
end
190-
if shopItems.storageValue or shopItems.storagevalue then
191-
child:setStorageValue(shopItems.storageValue or shopItems.storagevalue)
222+
if children.storageValue or children.storagevalue then
223+
child:setStorageValue(children.storageValue or children.storagevalue)
192224
end
193225
parent:addChildShop(child)
194226
end

src/map/house/house.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const {
871871
}
872872

873873
std::ostringstream ss;
874-
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.";
874+
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.";
875875
letter->setAttribute(ItemAttribute_t::TEXT, ss.str());
876876
g_game().internalAddItem(player->getInbox(), letter, INDEX_WHEREEVER, FLAG_NOLIMIT);
877877
house->setPayRentWarnings(house->getPayRentWarnings() + 1);

0 commit comments

Comments
 (0)