Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: price mismatch between NPCs and a typo in the rent house letter message #2706

Closed
wants to merge 14 commits into from
143 changes: 89 additions & 54 deletions data/scripts/lib/register_npc_type.lua
Original file line number Diff line number Diff line change
@@ -141,61 +141,96 @@ 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)
end
if shopItems.clientId or shopItems.clientid then
parent:setId(shopItems.clientId or shopItems.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)
end
if shopItems.sell then
parent:setSellPrice(shopItems.sell)
end
if shopItems.storageKey or shopItems.storagekey then
parent:setStorageKey(shopItems.storageKey or shopItems.storagekey)
end
if shopItems.storageValue or shopItems.storagevalue then
parent:setStorageValue(shopItems.storageValue or shopItems.storagevalue)
end
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)
end
if shopItems.clientId or shopItems.clientid then
child:setId(shopItems.clientId or shopItems.clientid)
end
if shopItems.subType or shopItems.subtype or shopItems.count then
child:setCount(shopItems.subType or shopItems.subtype or shopItems.count)
end
if shopItems.buy then
child:setBuyPrice(shopItems.buy)
end
if shopItems.sell then
child:setSellPrice(shopItems.sell)
end
if shopItems.storageKey or shopItems.storagekey then
child:setStorageKey(shopItems.storageKey or shopItems.storagekey)
end
if shopItems.storageValue or shopItems.storagevalue then
child:setStorageValue(shopItems.storageValue or shopItems.storagevalue)
end
parent:addChildShop(child)
end
end
npcType:addShopItem(parent)
end
end
if type(mask.shop) == "table" then
for _, shopItems in pairs(mask.shop) do
local parent = Shop()
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 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 buyPrice then
parent:setBuyPrice(buyPrice)
end
if sellPrice then
parent:setSellPrice(sellPrice)
end

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
if shopItems.storageValue or shopItems.storagevalue then
parent:setStorageValue(shopItems.storageValue or shopItems.storagevalue)
end
if shopItems.child then
for _, children in pairs(shopItems.child) do
local child = Shop()
if children.itemName or children.itemname then
child:setNameItem(children.itemName or children.itemname)
end
if children.clientId or children.clientid then
child:setId(children.clientId or children.clientid)
end
if children.subType or children.subtype or children.count then
child:setCount(children.subType or children.subtype or children.count)
end
if children.buy then
child:setBuyPrice(children.buy)
end
if children.sell then
child:setSellPrice(children.sell)
end
if children.storageKey or children.storagekey then
child:setStorageKey(children.storageKey or children.storagekey)
end
if children.storageValue or children.storagevalue then
child:setStorageValue(children.storageValue or children.storagevalue)
end
parent:addChildShop(child)
end
end
npcType:addShopItem(parent)
end
end
end

registerNpcType.currency = function(npcType, mask)
2 changes: 1 addition & 1 deletion src/map/house/house.cpp
Original file line number Diff line number Diff line change
@@ -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);
Loading