This is great!
Although, for anyone using this in Nekiro Downgrade 7.72 in conjunction with OTClient mehah or OTClient v8 you might want to send the fluid type data through protocol without converting to client side subtype. For example,
C++:
void ProtocolGame::AddShopItem(NetworkMessage& msg, const ShopInfo& item)
{
const ItemType& it = Item::items[item.itemId];
msg.add<uint16_t>(it.clientId);
if (it.isSplash() || it.isFluidContainer()) {
msg.addByte(serverFluidToClient(item.subType)); // <- This is already handled client side
} else {
msg.addByte(0x00);
}
msg.addString(item.realName);
msg.add<uint32_t>(it.weight);
msg.add<uint32_t>(item.buyPrice);
msg.add<uint32_t>(item.sellPrice);
}
Therefor the approate way to send this would be
C++:
if (it.isSplash() || it.isFluidContainer()) {
msg.addByte(item.subType); // <--
} else {
msg.addByte(0x00);
}
I was having an issue where the trade window displayed the wrong fluid type. So if you are having a similar issue then you might want to test and consider applying this.
EDIT:
C++:
void Game::playerPurchaseItem(uint32_t playerId, uint16_t spriteId, uint8_t count, uint8_t amount,
bool ignoreCap/* = false*/, bool inBackpacks/* = false*/)
{
if (amount == 0 || amount > 100) {
return;
}
Player* player = getPlayerByID(playerId);
if (!player) {
return;
}
int32_t onBuy, onSell;
Npc* merchant = player->getShopOwner(onBuy, onSell);
if (!merchant) {
return;
}
const ItemType& it = Item::items.getItemIdByClientId(spriteId);
if (it.id == 0) {
return;
}
uint8_t subType;
if (it.isSplash() || it.isFluidContainer()) {
subType = clientFluidToServer(count);
} else {
subType = count;
}
if (!player->hasShopItemForSale(it.id, subType)) {
return;
}
merchant->onPlayerTrade(player, onBuy, it.id, subType, amount, ignoreCap, inBackpacks);
}
This is how the server handles the data received from client side through protocol & again, it is trying to convert the subtype but the client already handles that.
C++:
if (it.isSplash() || it.isFluidContainer()) {
// subType = clientFluidToServer(count);
subType = count;
} else {
subType = count;
}
Without this change I found it impossible to be able to buy items from the npc that were fluid type.
I believe it is better to make these changes server side since we don't necessarily upgrade our engine for old protocol projects, but it's a lot likely to update the client which is why I don't recommend changing the way the client handles the data.