more fixes in count/subtypes

This commit is contained in:
Eduardo Bart 2012-04-27 21:44:55 -03:00
parent 519a52910e
commit 47bd619273
5 changed files with 15 additions and 38 deletions

View File

@ -34,7 +34,7 @@
Item::Item() : Thing() Item::Item() : Thing()
{ {
m_id = 0; m_id = 0;
m_countOrSubType = 0; m_countOrSubType = 1;
} }
ItemPtr Item::create(int id) ItemPtr Item::create(int id)
@ -44,8 +44,6 @@ ItemPtr Item::create(int id)
logTraceError("invalid item id ", id); logTraceError("invalid item id ", id);
else { else {
item->setId(id); item->setId(id);
if(item->isStackable())
item->setCount(1);
} }
return item; return item;
} }
@ -195,19 +193,3 @@ void Item::setId(uint32 id)
m_id = id; m_id = id;
m_type = g_thingsType.getThingType(m_id, ThingsType::Item); m_type = g_thingsType.getThingType(m_id, ThingsType::Item);
} }
int Item::getCount()
{
if(isStackable())
return m_countOrSubType;
else
return 1;
}
int Item::getSubType()
{
if(isFluid() || isFluidContainer())
return m_countOrSubType;
else
return 0;
}

View File

@ -36,13 +36,13 @@ public:
void draw(const Point& dest, float scaleFactor, bool animate); void draw(const Point& dest, float scaleFactor, bool animate);
void setId(uint32 id); void setId(uint32 id);
void setCountOrSubType(uint8 value) { m_countOrSubType = value; } void setCountOrSubType(int value) { m_countOrSubType = value; }
void setCount(int count) { setCountOrSubType(count); } void setCount(int count) { m_countOrSubType = count; }
void setSubType(int subType) { setCountOrSubType(subType); } void setSubType(int subType) { m_countOrSubType = subType; }
uint8 getCountOrSubType() { return m_countOrSubType; } int getCountOrSubType() { return m_countOrSubType; }
int getSubType(); int getSubType() { return m_countOrSubType; }
int getCount(); int getCount() { return m_countOrSubType; }
uint32 getId() { return m_id; } uint32 getId() { return m_id; }
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); } ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }

View File

@ -58,8 +58,8 @@ public:
void sendTurnWest(); void sendTurnWest();
void sendMove(const Position& fromPos, int itemId, int stackpos, const Position& toPos, int count); void sendMove(const Position& fromPos, int itemId, int stackpos, const Position& toPos, int count);
void sendInspectNpcTrade(int itemId, int count); void sendInspectNpcTrade(int itemId, int count);
void sendBuyItem(int itemId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack); void sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack);
void sendSellItem(int itemId, int count, int amount, bool ignoreEquipped); void sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped);
void sendCloseNpcTrade(); void sendCloseNpcTrade();
void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId); void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId);
void sendInspectTrade(bool counterOffer, int index); void sendInspectTrade(bool counterOffer, int index);

View File

@ -509,18 +509,13 @@ void ProtocolGame::parseOpenNpcTrade(InputMessage& msg)
std::vector<std::tuple<ItemPtr, std::string, int, int, int>> items; std::vector<std::tuple<ItemPtr, std::string, int, int, int>> items;
int listCount = msg.getU8(); int listCount = msg.getU8();
for(int i = 0; i < listCount; ++i) { for(int i = 0; i < listCount; ++i) {
int itemId = msg.getU16(); ItemPtr item = Item::create(msg.getU16());
int subType = msg.getU8(); item->setSubType(msg.getU8());
ItemPtr item = Item::create(itemId);
if(item->isFluidContainer() || item->isFluid())
item->setSubType(subType);
std::string name = msg.getString(); std::string name = msg.getString();
int weight = msg.getU32(); int weight = msg.getU32();
int buyPrice = msg.getU32(); int buyPrice = msg.getU32();
int sellPrice = msg.getU32(); int sellPrice = msg.getU32();
items.push_back(std::make_tuple(item, name, weight, buyPrice, sellPrice)); items.push_back(std::make_tuple(item, name, weight, buyPrice, sellPrice));
} }

View File

@ -232,24 +232,24 @@ void ProtocolGame::sendInspectNpcTrade(int itemId, int count)
send(msg); send(msg);
} }
void ProtocolGame::sendBuyItem(int itemId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack) void ProtocolGame::sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientBuyItem); msg.addU8(Proto::ClientBuyItem);
msg.addU16(itemId); msg.addU16(itemId);
msg.addU8(count); msg.addU8(subType);
msg.addU8(amount); msg.addU8(amount);
msg.addU8(ignoreCapacity ? 0x01 : 0x00); msg.addU8(ignoreCapacity ? 0x01 : 0x00);
msg.addU8(buyWithBackpack ? 0x01 : 0x00); msg.addU8(buyWithBackpack ? 0x01 : 0x00);
send(msg); send(msg);
} }
void ProtocolGame::sendSellItem(int itemId, int count, int amount, bool ignoreEquipped) void ProtocolGame::sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientSellItem); msg.addU8(Proto::ClientSellItem);
msg.addU16(itemId); msg.addU16(itemId);
msg.addU8(count); msg.addU8(subType);
msg.addU8(amount); msg.addU8(amount);
msg.addU8(ignoreEquipped ? 0x01 : 0x00); msg.addU8(ignoreEquipped ? 0x01 : 0x00);
send(msg); send(msg);