Market item filtering improvements and other some minor improvements

* Can now filter market items by vocation, level, slot type, and depot items.
* Added new bitwise lib for handling flag operations.
* Can now get/set local player vocation/premium (TODO: spell list).
This commit is contained in:
BeniS
2012-07-24 03:11:53 +12:00
parent dc8ef845ab
commit 19dd96fd02
21 changed files with 369 additions and 116 deletions

View File

@@ -33,7 +33,10 @@ LocalPlayer::LocalPlayer()
m_lastPrewalkDone = true;
m_autoWalking = false;
m_known = false;
m_premium = false;
m_states = 0;
m_vocation = 0;
m_skillsLevel.fill(-1);
m_skillsLevelPercent.fill(-1);
@@ -327,3 +330,22 @@ void LocalPlayer::setInventoryItem(Otc::InventorySlot inventory, const ItemPtr&
callLuaField("onInventoryChange", inventory, item, oldItem);
}
}
void LocalPlayer::setVocation(int vocation)
{
if(m_vocation != vocation) {
int oldVocation = m_vocation;
m_vocation = vocation;
callLuaField("onVocationChange", vocation, oldVocation);
}
}
void LocalPlayer::setPremium(bool premium)
{
if(m_premium != premium) {
m_premium = premium;
callLuaField("onPremiumChange", premium);
}
}

View File

@@ -52,10 +52,13 @@ public:
void setStamina(double stamina);
void setKnown(bool known) { m_known = known; }
void setInventoryItem(Otc::InventorySlot inventory, const ItemPtr& item);
void setVocation(int vocation);
void setPremium(bool premium);
int getStates() { return m_states; }
int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; }
int getSkillLevelPercent(Otc::Skill skill) { return m_skillsLevelPercent[skill]; }
int getVocation() { return m_vocation; }
double getHealth() { return m_health; }
double getMaxHealth() { return m_maxHealth; }
double getFreeCapacity() { return m_freeCapacity; }
@@ -73,6 +76,7 @@ public:
bool isKnown() { return m_known; }
bool isPreWalking() { return m_preWalking; }
bool isAutoWalking() { return m_autoWalking; }
bool isPremium() { return m_premium; }
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
bool isLocalPlayer() { return true; }
@@ -96,6 +100,7 @@ private:
bool m_lastPrewalkDone;
bool m_walkLocked;
bool m_autoWalking;
bool m_premium;
Position m_lastPrewalkDestionation;
Timer m_walkLockTimer;
ItemPtr m_inventoryItems[Otc::LastInventorySlot];
@@ -106,6 +111,7 @@ private:
bool m_known;
int m_states;
int m_vocation;
double m_health;
double m_maxHealth;

View File

@@ -350,7 +350,8 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Item>("getId", &Item::getId);
g_lua.bindClassMemberFunction<Item>("isStackable", &Item::isStackable);
g_lua.bindClassMemberFunction<Item>("isMarketable", &Item::isMarketable);
g_lua.bindClassMemberFunction<Item>("getMarketData", &Item::isMarketable);
g_lua.bindClassMemberFunction<Item>("getMarketData", &Item::getMarketData);
g_lua.bindClassMemberFunction<Item>("getClothSlot", &Item::getClothSlot);
g_lua.registerClass<Effect, Thing>();
g_lua.registerClass<Missile, Thing>();
@@ -393,6 +394,8 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<LocalPlayer>("getSoul", &LocalPlayer::getSoul);
g_lua.bindClassMemberFunction<LocalPlayer>("getStamina", &LocalPlayer::getStamina);
g_lua.bindClassMemberFunction<LocalPlayer>("getInventoryItem", &LocalPlayer::getInventoryItem);
g_lua.bindClassMemberFunction<LocalPlayer>("getVocation", &LocalPlayer::getVocation);
g_lua.bindClassMemberFunction<LocalPlayer>("isPremium", &LocalPlayer::isPremium);
g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown);
g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking);
g_lua.bindClassMemberFunction<LocalPlayer>("asLocalPlayer", &LocalPlayer::asLocalPlayer);

View File

@@ -107,8 +107,8 @@ int push_luavalue(const MarketData& data)
g_lua.setField("name");
g_lua.pushInteger(data.requiredLevel);
g_lua.setField("requiredLevel");
g_lua.pushInteger(data.restrictProfession);
g_lua.setField("restrictProfession");
g_lua.pushInteger(data.restrictVocation);
g_lua.setField("restrictVocation");
g_lua.pushInteger(data.showAs);
g_lua.setField("showAs");
g_lua.pushInteger(data.tradeAs);
@@ -125,8 +125,8 @@ bool luavalue_cast(int index, MarketData& data)
data.name = g_lua.popString();
g_lua.getField("requiredLevel", index);
data.requiredLevel = g_lua.popInteger();
g_lua.getField("restrictProfession", index);
data.restrictProfession = g_lua.popInteger();
g_lua.getField("restrictVocation", index);
data.restrictVocation = g_lua.popInteger();
g_lua.getField("showAs", index);
data.showAs = g_lua.popInteger();
g_lua.getField("tradeAs", index);

View File

@@ -98,7 +98,7 @@ namespace Proto {
GameServerCreatureUnpass = 146,
GameServerEditText = 150,
GameServerEditList = 151,
GameServerPlayerDataBasic = 159, // 910
GameServerPlayerDataBasic = 159, // 950
GameServerPlayerData = 160,
GameServerPlayerSkills = 161,
GameServerPlayerState = 162,

View File

@@ -288,9 +288,6 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
parseMultiUseDelay(msg);
break;
// PROTOCOL>=910
case Proto::GameServerPlayerDataBasic:
parsePlayerInfo(msg);
break;
case Proto::GameServerChannelEvent:
parseChannelEvent(msg);
break;
@@ -300,6 +297,10 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
case Proto::GameServerPlayerInventory:
parsePlayerInventory(msg);
break;
// PROTOCOL>=950
case Proto::GameServerPlayerDataBasic:
parsePlayerInfo(msg);
break;
// otclient ONLY
case Proto::GameServerExtendedOpcode:
parseExtendedOpcode(msg);
@@ -832,12 +833,15 @@ void ProtocolGame::parseEditList(const InputMessagePtr& msg)
void ProtocolGame::parsePlayerInfo(const InputMessagePtr& msg)
{
msg->getU8(); // is premium?
msg->getU8(); // profession
int numSpells = msg->getU16();
for(int i=0;i<numSpells;++i) {
msg->getU16(); // spell id
bool premium = msg->getU8(); // premium
int vocation = msg->getU8(); // vocation
int spellCount = msg->getU16();
for(int i=0;i<spellCount;++i) {
int spellId = msg->getU16(); // spell id - TODO: add to local player
}
m_localPlayer->setPremium(premium);
m_localPlayer->setVocation(vocation);
}
void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg)
@@ -1221,7 +1225,13 @@ void ProtocolGame::parseChannelEvent(const InputMessagePtr& msg)
void ProtocolGame::parseItemInfo(const InputMessagePtr& msg)
{
//TODO
/*int count = msg.getU16() - 1;
for(int i = 0; i < count; i++)
{
int unknown1 = msg->getU8();
int unknown2 = msg->getU16();
std::string unknown3 = msg->getString();
}*/
}
void ProtocolGame::parsePlayerInventory(const InputMessagePtr& msg)

View File

@@ -83,7 +83,7 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
market.tradeAs = fin->getU16();
market.showAs = fin->getU16();
market.name = fin->getString();
market.restrictProfession = fin->getU16();
market.restrictVocation = fin->getU16();
market.requiredLevel = fin->getU16();
m_attribs.set(attr, market);
break;

View File

@@ -76,7 +76,7 @@ enum ThingAttr : uint8 {
ThingAttrCloth = 32,
ThingAttrMarket = 33,
ThingAttrChargeable = 254, // deprecated
ThingLastAttr = 255,
ThingLastAttr = 255
};
enum SpriteMask {
@@ -90,7 +90,7 @@ struct MarketData {
std::string name;
int category;
uint16 requiredLevel;
uint16 restrictProfession;
uint16 restrictVocation;
uint16 showAs;
uint16 tradeAs;
};