More refactoring and some changes
* Move protocol safeSend() to send() * Bind some new functions * Refactor lots of enums
This commit is contained in:
parent
a6d53532d2
commit
a11d6e501e
|
@ -59,8 +59,7 @@ void ModuleManager::autoLoadModules(int maxPriority)
|
|||
if(priority > maxPriority)
|
||||
break;
|
||||
ModulePtr module = pair.second;
|
||||
if(!module->isLoaded() && !module->load())
|
||||
g_logger.fatal("A required module has failed to load, cannot continue to run.");
|
||||
module->load();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -628,7 +628,7 @@ void Application::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<Protocol>("disconnect", &Protocol::disconnect);
|
||||
g_lua.bindClassMemberFunction<Protocol>("isConnected", &Protocol::isConnected);
|
||||
g_lua.bindClassMemberFunction<Protocol>("isConnecting", &Protocol::isConnecting);
|
||||
g_lua.bindClassMemberFunction<Protocol>("send", &Protocol::send); // must change to safeSend
|
||||
g_lua.bindClassMemberFunction<Protocol>("send", &Protocol::send);
|
||||
g_lua.bindClassMemberFunction<Protocol>("recv", &Protocol::recv);
|
||||
g_lua.bindClassMemberFunction<Protocol>("getXteaKey", &Protocol::getXteaKey);
|
||||
g_lua.bindClassMemberFunction<Protocol>("generateXteaKey", &Protocol::generateXteaKey);
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <otclient/position.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "cast.h"
|
||||
|
@ -53,7 +52,7 @@ typename std::enable_if<std::is_integral<T>::value ||
|
|||
std::is_floating_point<T>::value ||
|
||||
std::is_enum<T>::value, T>::type sprintf_cast(const T& t) { return t; }
|
||||
|
||||
/// Cast any class or struct convertible to std::string
|
||||
/// Cast std::string
|
||||
inline const char *sprintf_cast(const std::string& s) { return s.c_str(); }
|
||||
|
||||
template<int N>
|
||||
|
@ -181,11 +180,6 @@ inline std::string ip_to_string(uint32 ip) {
|
|||
return std::string(host);
|
||||
}
|
||||
|
||||
inline std::string pos_to_string(const Position& p)
|
||||
{
|
||||
return format("{x = %hd, y = %hd, z = %hd}", p.x, p.y, p.z);
|
||||
}
|
||||
|
||||
/// Convert utf8 characters to latin1
|
||||
inline char utf8CharToLatin1(uchar *utf8, int *read) {
|
||||
char c = '?';
|
||||
|
|
|
@ -89,7 +89,7 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate)
|
|||
void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction)
|
||||
{
|
||||
// outfit is a real creature
|
||||
if(m_outfit.getCategory() == DatCreatureCategory) {
|
||||
if(m_outfit.getCategory() == ThingCategoryCreature) {
|
||||
int animationPhase = animateWalk ? m_walkAnimationPhase : 0;
|
||||
|
||||
if(isAnimateAlways() && animateIdle) {
|
||||
|
@ -121,13 +121,13 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
|
|||
Painter::CompositionMode oldComposition = g_painter->getCompositionMode();
|
||||
g_painter->setCompositionMode(Painter::CompositionMode_Multiply);
|
||||
g_painter->setColor(m_outfit.getHeadColor());
|
||||
datType->draw(dest, scaleFactor, DatYellowMask, xPattern, yPattern, 0, animationPhase);
|
||||
datType->draw(dest, scaleFactor, SpriteMaskYellow, xPattern, yPattern, 0, animationPhase);
|
||||
g_painter->setColor(m_outfit.getBodyColor());
|
||||
datType->draw(dest, scaleFactor, DatRedMask, xPattern, yPattern, 0, animationPhase);
|
||||
datType->draw(dest, scaleFactor, SpriteMaskRed, xPattern, yPattern, 0, animationPhase);
|
||||
g_painter->setColor(m_outfit.getLegsColor());
|
||||
datType->draw(dest, scaleFactor, DatGreenMask, xPattern, yPattern, 0, animationPhase);
|
||||
datType->draw(dest, scaleFactor, SpriteMaskGreen, xPattern, yPattern, 0, animationPhase);
|
||||
g_painter->setColor(m_outfit.getFeetColor());
|
||||
datType->draw(dest, scaleFactor, DatBlueMask, xPattern, yPattern, 0, animationPhase);
|
||||
datType->draw(dest, scaleFactor, SpriteMaskBlue, xPattern, yPattern, 0, animationPhase);
|
||||
g_painter->setColor(oldColor);
|
||||
g_painter->setCompositionMode(oldComposition);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
|
|||
|
||||
// when creature is an effect we cant render the first and last animation phase,
|
||||
// instead we should loop in the phases between
|
||||
if(m_outfit.getCategory() == DatEffectCategory) {
|
||||
if(m_outfit.getCategory() == ThingCategoryEffect) {
|
||||
animationPhases = std::max(1, animationPhases-2);
|
||||
animateTicks = Otc::INVISIBLE_TICKS_PER_FRAME;
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
|
|||
animationPhase = animationPhases-1;
|
||||
}
|
||||
|
||||
if(m_outfit.getCategory() == DatEffectCategory)
|
||||
if(m_outfit.getCategory() == ThingCategoryEffect)
|
||||
animationPhase = std::min(animationPhase+1, getAnimationPhases());
|
||||
|
||||
rawGetThingType()->draw(dest, scaleFactor, 0, 0, 0, 0, animationPhase);
|
||||
|
@ -305,7 +305,7 @@ void Creature::stopWalk()
|
|||
void Creature::updateWalkAnimation(int totalPixelsWalked)
|
||||
{
|
||||
// update outfit animation
|
||||
if(m_outfit.getCategory() != DatCreatureCategory)
|
||||
if(m_outfit.getCategory() != ThingCategoryCreature)
|
||||
return;
|
||||
|
||||
int footAnimPhases = getAnimationPhases() - 1;
|
||||
|
@ -461,7 +461,7 @@ void Creature::setDirection(Otc::Direction direction)
|
|||
|
||||
void Creature::setOutfit(const Outfit& outfit)
|
||||
{
|
||||
if(!g_things.isValidDatId(outfit.getId(), DatCreatureCategory))
|
||||
if(!g_things.isValidDatId(outfit.getId(), ThingCategoryCreature))
|
||||
return;
|
||||
m_walkAnimationPhase = 0; // might happen when player is walking and outfit is changed.
|
||||
m_outfit = outfit;
|
||||
|
|
|
@ -28,12 +28,12 @@
|
|||
#include <framework/util/attribstorage.h>
|
||||
#include "outfit.h"
|
||||
|
||||
enum CreatureAttributes : unsigned char
|
||||
enum CreatureAttr : uint8
|
||||
{
|
||||
CreatureAttribPos,
|
||||
CreatureAttribName,
|
||||
CreatureAttribOutfit,
|
||||
CreatureAttribSpawnTime
|
||||
CreatureAttrPosition = 0,
|
||||
CreatureAttrName = 1,
|
||||
CreatureAttrOutfit = 2,
|
||||
CreatureAttrSpawnTime = 3
|
||||
};
|
||||
|
||||
class CreatureType : public LuaObject
|
||||
|
@ -42,15 +42,15 @@ public:
|
|||
CreatureType() { }
|
||||
CreatureType(const std::string& name) { setName(name); }
|
||||
|
||||
void setPos(const Position& pos) { m_attribs.set(CreatureAttribPos, pos); }
|
||||
void setName(const std::string& name) { m_attribs.set(CreatureAttribName, name); }
|
||||
void setOutfit(const Outfit& o) { m_attribs.set(CreatureAttribOutfit, o); }
|
||||
void setSpawnTime(int spawnTime) { m_attribs.set(CreatureAttribSpawnTime, spawnTime); }
|
||||
void setPos(const Position& pos) { m_attribs.set(CreatureAttrPosition, pos); }
|
||||
void setName(const std::string& name) { m_attribs.set(CreatureAttrName, name); }
|
||||
void setOutfit(const Outfit& o) { m_attribs.set(CreatureAttrOutfit, o); }
|
||||
void setSpawnTime(int spawnTime) { m_attribs.set(CreatureAttrSpawnTime, spawnTime); }
|
||||
|
||||
std::string getName() { return m_attribs.get<std::string>(CreatureAttribName); }
|
||||
Position getPos() { return m_attribs.get<Position>(CreatureAttribPos); }
|
||||
Outfit getOutfit() { return m_attribs.get<Outfit>(CreatureAttribOutfit); }
|
||||
int getSpawnTime() { return m_attribs.get<int>(CreatureAttribSpawnTime); }
|
||||
std::string getName() { return m_attribs.get<std::string>(CreatureAttrName); }
|
||||
Position getPos() { return m_attribs.get<Position>(CreatureAttrPosition); }
|
||||
Outfit getOutfit() { return m_attribs.get<Outfit>(CreatureAttrOutfit); }
|
||||
int getSpawnTime() { return m_attribs.get<int>(CreatureAttrSpawnTime); }
|
||||
|
||||
private:
|
||||
AttribStorage m_attribs;
|
||||
|
|
|
@ -46,17 +46,17 @@ void Effect::startAnimation()
|
|||
|
||||
void Effect::setId(uint32 id)
|
||||
{
|
||||
if(!g_things.isValidDatId(id, DatEffectCategory))
|
||||
if(!g_things.isValidDatId(id, ThingCategoryEffect))
|
||||
id = 0;
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
const ThingTypePtr& Effect::getThingType()
|
||||
{
|
||||
return g_things.getThingType(m_id, DatEffectCategory);
|
||||
return g_things.getThingType(m_id, ThingCategoryEffect);
|
||||
}
|
||||
|
||||
ThingType *Effect::rawGetThingType()
|
||||
{
|
||||
return g_things.rawGetThingType(m_id, DatEffectCategory);
|
||||
return g_things.rawGetThingType(m_id, ThingCategoryEffect);
|
||||
}
|
||||
|
|
|
@ -640,7 +640,7 @@ void Game::use(const ThingPtr& thing)
|
|||
|
||||
void Game::useInventoryItem(int itemId)
|
||||
{
|
||||
if(!canPerformGameAction() || !g_things.isValidDatId(itemId, DatItemCategory))
|
||||
if(!canPerformGameAction() || !g_things.isValidDatId(itemId, ThingCategoryItem))
|
||||
return;
|
||||
|
||||
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
||||
|
|
|
@ -29,14 +29,14 @@
|
|||
#include <framework/luaengine/luaobject.h>
|
||||
#include <framework/util/attribstorage.h>
|
||||
|
||||
enum HouseAttributes : unsigned char
|
||||
enum HouseAttr : uint8
|
||||
{
|
||||
HouseAttribId,
|
||||
HouseAttribName,
|
||||
HouseAttribTown,
|
||||
HouseAttribEntry,
|
||||
HouseAttribSize,
|
||||
HouseAttribRent
|
||||
HouseAttrId,
|
||||
HouseAttrName,
|
||||
HouseAttrTown,
|
||||
HouseAttrEntry,
|
||||
HouseAttrSize,
|
||||
HouseAttrRent
|
||||
};
|
||||
|
||||
class House : public LuaObject
|
||||
|
@ -47,17 +47,17 @@ public:
|
|||
~House() { m_tiles.clear(); }
|
||||
|
||||
void setTile(const TilePtr& tile);
|
||||
void setId(uint32 hId) { m_attribs.set(HouseAttribId, hId); }
|
||||
void setName(const std::string& name) { m_attribs.set(HouseAttribName, name); }
|
||||
void setTownId(uint32 tid) { m_attribs.set(HouseAttribTown, tid); }
|
||||
void setSize(uint32 s) { m_attribs.set(HouseAttribSize, s); }
|
||||
void setRent(uint32 r) { m_attribs.set(HouseAttribRent, r); }
|
||||
void setEntry(const Position& p) { m_attribs.set(HouseAttribEntry, p); }
|
||||
void setId(uint32 hId) { m_attribs.set(HouseAttrId, hId); }
|
||||
void setName(const std::string& name) { m_attribs.set(HouseAttrName, name); }
|
||||
void setTownId(uint32 tid) { m_attribs.set(HouseAttrTown, tid); }
|
||||
void setSize(uint32 s) { m_attribs.set(HouseAttrSize, s); }
|
||||
void setRent(uint32 r) { m_attribs.set(HouseAttrRent, r); }
|
||||
void setEntry(const Position& p) { m_attribs.set(HouseAttrEntry, p); }
|
||||
|
||||
uint32 getId() { return m_attribs.get<uint32>(HouseAttribId); }
|
||||
std::string getName() { return m_attribs.get<std::string>(HouseAttribName); }
|
||||
uint32 getRent() { return m_attribs.get<uint32>(HouseAttribRent); }
|
||||
uint32 getSize() { return m_attribs.get<uint32>(HouseAttribSize); }
|
||||
uint32 getId() { return m_attribs.get<uint32>(HouseAttrId); }
|
||||
std::string getName() { return m_attribs.get<std::string>(HouseAttrName); }
|
||||
uint32 getRent() { return m_attribs.get<uint32>(HouseAttrRent); }
|
||||
uint32 getSize() { return m_attribs.get<uint32>(HouseAttrSize); }
|
||||
|
||||
protected:
|
||||
void load(const TiXmlElement* elem);
|
||||
|
|
|
@ -176,7 +176,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate)
|
|||
|
||||
void Item::setId(uint32 id)
|
||||
{
|
||||
if(!g_things.isValidDatId(id, DatItemCategory))
|
||||
if(!g_things.isValidDatId(id, ThingCategoryItem))
|
||||
id = 0;
|
||||
//m_otbId = g_things.findOtbForClientId(id)->getServerId();
|
||||
m_id = id;
|
||||
|
@ -194,7 +194,7 @@ void Item::setOtbId(uint16 id)
|
|||
|
||||
bool Item::isValid()
|
||||
{
|
||||
return g_things.isValidDatId(m_id, DatItemCategory);
|
||||
return g_things.isValidDatId(m_id, ThingCategoryItem);
|
||||
}
|
||||
|
||||
void Item::unserializeItem(const BinaryTreePtr &in)
|
||||
|
@ -277,10 +277,10 @@ ItemPtr Item::clone()
|
|||
|
||||
const ThingTypePtr& Item::getThingType()
|
||||
{
|
||||
return g_things.getThingType(m_id, DatItemCategory);
|
||||
return g_things.getThingType(m_id, ThingCategoryItem);
|
||||
}
|
||||
|
||||
ThingType* Item::rawGetThingType()
|
||||
{
|
||||
return g_things.rawGetThingType(m_id, DatItemCategory);
|
||||
return g_things.rawGetThingType(m_id, ThingCategoryItem);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "thing.h"
|
||||
#include "itemtype.h"
|
||||
|
||||
enum AttrTypes_t
|
||||
enum ItemAttr : uint8
|
||||
{
|
||||
ATTR_END = 0,
|
||||
//ATTR_DESCRIPTION = 1,
|
||||
|
|
|
@ -29,14 +29,14 @@
|
|||
|
||||
ItemType::ItemType()
|
||||
{
|
||||
m_category = OtbInvalidCateogry;
|
||||
m_category = ItemCategoryInvalid;
|
||||
}
|
||||
|
||||
void ItemType::unserialize(const BinaryTreePtr& node)
|
||||
{
|
||||
m_null = false;
|
||||
|
||||
m_category = (OtbCategory)node->getU8();
|
||||
m_category = (ItemCategory)node->getU8();
|
||||
|
||||
node->getU32(); // flags
|
||||
|
||||
|
@ -48,31 +48,26 @@ void ItemType::unserialize(const BinaryTreePtr& node)
|
|||
|
||||
uint16 len = node->getU16();
|
||||
switch(attr) {
|
||||
case OtbAttribServerId: {
|
||||
case ItemTypeAttrServerId: {
|
||||
uint16 serverId = node->getU16();
|
||||
if(serverId > 20000 && serverId < 20100) {
|
||||
serverId -= 20000;
|
||||
} else if(lastId > 99 && lastId != serverId - 1) {
|
||||
static ItemTypePtr dummyType(g_things.getNullItemType());
|
||||
while(lastId != serverId - 1) {
|
||||
dummyType->setServerId(++lastId);
|
||||
g_things.addItemType(dummyType);
|
||||
}
|
||||
while(lastId != serverId - 1)
|
||||
++lastId;
|
||||
}
|
||||
assert(len == 2);
|
||||
setServerId(serverId);
|
||||
break;
|
||||
}
|
||||
case OtbAttribClientId: {
|
||||
case ItemTypeAttrClientId: {
|
||||
setClientId(node->getU16());
|
||||
assert(len == 2);
|
||||
break;
|
||||
}
|
||||
case OtbAttribName: {
|
||||
case ItemTypeAttrName: {
|
||||
setName(node->getString());
|
||||
break;
|
||||
}
|
||||
case OtbAttribDesc: {
|
||||
case ItemTypeAttrDesc: {
|
||||
setDesc(node->getString());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -29,57 +29,55 @@
|
|||
#include <framework/xml/tinyxml.h>
|
||||
#include <framework/util/attribstorage.h>
|
||||
|
||||
|
||||
enum OtbCategory {
|
||||
OtbInvalidCateogry = 0,
|
||||
OtbGround,
|
||||
OtbContainer,
|
||||
OtbWeapon,
|
||||
OtbAmmunition,
|
||||
OtbArmor,
|
||||
OtbCharges,
|
||||
OtbTeleport,
|
||||
OtbMagicField,
|
||||
OtbWritable,
|
||||
OtbKey,
|
||||
OtbSplash,
|
||||
OtbFluid,
|
||||
OtbDoor,
|
||||
OtbLastCategory
|
||||
enum ItemCategory {
|
||||
ItemCategoryInvalid = 0,
|
||||
ItemCategoryGround = 1,
|
||||
ItemCategoryContainer = 2,
|
||||
ItemCategoryWeapon = 3,
|
||||
ItemCategoryAmmunition = 4,
|
||||
ItemCategoryArmor = 5,
|
||||
ItemCategoryCharges = 6,
|
||||
ItemCategoryTeleport = 7,
|
||||
ItemCategoryMagicField = 8,
|
||||
ItemCategoryWritable = 9,
|
||||
ItemCategoryKey = 10,
|
||||
ItemCategorySplash = 11,
|
||||
ItemCategoryFluid = 12,
|
||||
ItemCategoryDoor = 13,
|
||||
ItemCategoryLast = 14
|
||||
};
|
||||
|
||||
enum OtbAttrib {
|
||||
OtbAttribFirst = 0x10,
|
||||
OtbAttribServerId = OtbAttribFirst,
|
||||
OtbAttribClientId,
|
||||
OtbAttribName, // deprecated
|
||||
OtbAttribDesc, // deprecated
|
||||
OtbAttribSpeed,
|
||||
OtbAttribSlot, // deprecated
|
||||
OtbAttribMaxItems, // deprecated
|
||||
OtbAttribWeight, // deprecated
|
||||
OtbAttribWeapon, // deprecated
|
||||
OtbAttribAmu, // deprecated
|
||||
OtbAttribArmor, // deprecated
|
||||
OtbAttribMagLevel, // deprecated
|
||||
OtbAttribMagicField, // deprecated
|
||||
OtbAttribWritable, // deprecated
|
||||
OtbAttribRotateTo, // deprecated
|
||||
OtbAttribDecay, // deprecated
|
||||
OtbAttribSpriteHash,
|
||||
OtbAttribMinimapColor,
|
||||
OtbAttrib07,
|
||||
OtbAttrib08,
|
||||
OtbAttribLight,
|
||||
OtbAttribDecay2, // deprecated
|
||||
OtbAttribWeapon2, // deprecated
|
||||
OtbAttribAmu2, // deprecated
|
||||
OtbAttribArmor2, // deprecated
|
||||
OtbAttribWritable2, // deprecated
|
||||
OtbAttribLight2,
|
||||
OtbAttribTopOrder,
|
||||
OtbAttribWrtiable3, // deprecated
|
||||
OtbLastAttrib
|
||||
enum ItemTypeAttr : uint8 {
|
||||
ItemTypeAttrServerId = 16,
|
||||
ItemTypeAttrClientId = 17,
|
||||
ItemTypeAttrName = 18, // deprecated
|
||||
ItemTypeAttrDesc = 19, // deprecated
|
||||
ItemTypeAttrSpeed = 20,
|
||||
ItemTypeAttrSlot = 21, // deprecated
|
||||
ItemTypeAttrMaxItems = 22, // deprecated
|
||||
ItemTypeAttrWeight = 23, // deprecated
|
||||
ItemTypeAttrWeapon = 24, // deprecated
|
||||
ItemTypeAttrAmmunition = 25, // deprecated
|
||||
ItemTypeAttrArmor = 26, // deprecated
|
||||
ItemTypeAttrMagicLevel = 27, // deprecated
|
||||
ItemTypeAttrMagicField = 28, // deprecated
|
||||
ItemTypeAttrWritable = 29, // deprecated
|
||||
ItemTypeAttrRotateTo = 30, // deprecated
|
||||
ItemTypeAttrDecay = 31, // deprecated
|
||||
ItemTypeAttrSpriteHash = 32,
|
||||
ItemTypeAttrMinimapColor = 33,
|
||||
ItemTypeAttr07 = 34,
|
||||
ItemTypeAttr08 = 35,
|
||||
ItemTypeAttrLight = 36,
|
||||
ItemTypeAttrDecay2 = 37, // deprecated
|
||||
ItemTypeAttrWeapon2 = 38, // deprecated
|
||||
ItemTypeAttrAmmunition2 = 39, // deprecated
|
||||
ItemTypeAttrArmor2 = 40, // deprecated
|
||||
ItemTypeAttrWritable2 = 41, // deprecated
|
||||
ItemTypeAttrLight2 = 42,
|
||||
ItemTypeAttrTopOrder = 43,
|
||||
ItemTypeAttrWrtiable3 = 44, // deprecated
|
||||
ItemTypeAttrLast = 45
|
||||
};
|
||||
|
||||
class ItemType : public LuaObject
|
||||
|
@ -89,21 +87,21 @@ public:
|
|||
|
||||
void unserialize(const BinaryTreePtr& node);
|
||||
|
||||
uint16 getServerId() { return m_attribs.get<uint16>(OtbAttribServerId); }
|
||||
uint16 getClientId() { return m_attribs.get<uint16>(OtbAttribClientId); }
|
||||
OtbCategory getCategory() { return m_category; }
|
||||
std::string getName() { return m_attribs.get<std::string>(OtbAttribName); }
|
||||
std::string getDesc() { return m_attribs.get<std::string>(OtbAttribDesc); }
|
||||
uint16 getServerId() { return m_attribs.get<uint16>(ItemTypeAttrServerId); }
|
||||
uint16 getClientId() { return m_attribs.get<uint16>(ItemTypeAttrClientId); }
|
||||
ItemCategory getCategory() { return m_category; }
|
||||
std::string getName() { return m_attribs.get<std::string>(ItemTypeAttrName); }
|
||||
std::string getDesc() { return m_attribs.get<std::string>(ItemTypeAttrDesc); }
|
||||
|
||||
bool isNull() { return m_null; }
|
||||
|
||||
void setClientId(uint16 clientId) { m_attribs.set(OtbAttribClientId, clientId); }
|
||||
void setServerId(uint16 serverId) { m_attribs.set(OtbAttribServerId, serverId); }
|
||||
void setName(const std::string& name) { m_attribs.set(OtbAttribName, name); }
|
||||
void setDesc(const std::string& desc) { m_attribs.set(OtbAttribDesc, desc); }
|
||||
void setClientId(uint16 clientId) { m_attribs.set(ItemTypeAttrClientId, clientId); }
|
||||
void setServerId(uint16 serverId) { m_attribs.set(ItemTypeAttrServerId, serverId); }
|
||||
void setName(const std::string& name) { m_attribs.set(ItemTypeAttrName, name); }
|
||||
void setDesc(const std::string& desc) { m_attribs.set(ItemTypeAttrDesc, desc); }
|
||||
|
||||
private:
|
||||
OtbCategory m_category;
|
||||
ItemCategory m_category;
|
||||
Boolean<true> m_null;
|
||||
|
||||
AttribStorage m_attribs;
|
||||
|
|
|
@ -54,6 +54,11 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.bindSingletonFunction("g_things", "loadOtb", &ThingTypeManager::loadOtb, &g_things);
|
||||
g_lua.bindSingletonFunction("g_things", "loadXml", &ThingTypeManager::loadXml, &g_things);
|
||||
g_lua.bindSingletonFunction("g_things", "getDatSignature", &ThingTypeManager::getDatSignature, &g_things);
|
||||
g_lua.bindSingletonFunction("g_things", "getDatSignature", &ThingTypeManager::getDatSignature, &g_things);
|
||||
g_lua.bindSingletonFunction("g_things", "getThingType", &ThingTypeManager::getThingType, &g_things);
|
||||
g_lua.bindSingletonFunction("g_things", "getItemType", &ThingTypeManager::getItemType, &g_things);
|
||||
g_lua.bindSingletonFunction("g_things", "findThingTypeByAttr", &ThingTypeManager::findThingTypeByAttr, &g_things);
|
||||
g_lua.bindSingletonFunction("g_things", "findItemTypeByCategory", &ThingTypeManager::findItemTypeByCategory, &g_things);
|
||||
|
||||
#if 0
|
||||
g_lua.registerSingletonClass("g_houses");
|
||||
|
@ -211,7 +216,6 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.registerClass<ProtocolGame, Protocol>();
|
||||
g_lua.bindClassStaticFunction<ProtocolGame>("create", []{ return ProtocolGamePtr(new ProtocolGame); });
|
||||
g_lua.bindClassMemberFunction<ProtocolGame>("login", &ProtocolGame::login);
|
||||
g_lua.bindClassMemberFunction<ProtocolGame>("safeSend", &ProtocolGame::safeSend);
|
||||
g_lua.bindClassMemberFunction<ProtocolGame>("sendExtendedOpcode", &ProtocolGame::sendExtendedOpcode);
|
||||
g_lua.bindClassMemberFunction<ProtocolGame>("addPosition", &ProtocolGame::addPosition);
|
||||
g_lua.bindClassMemberFunction<ProtocolGame>("setMapDescription", &ProtocolGame::setMapDescription);
|
||||
|
@ -329,6 +333,13 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<Creature>("asMonster", &Creature::asMonster);
|
||||
g_lua.bindClassMemberFunction<Creature>("asNpc", &Creature::asNpc);
|
||||
|
||||
g_lua.registerClass<ItemType>();
|
||||
g_lua.bindClassMemberFunction<ItemType>("getServerId", &ItemType::getServerId);
|
||||
g_lua.bindClassMemberFunction<ItemType>("getClientId", &ItemType::getClientId);
|
||||
|
||||
g_lua.registerClass<ThingType>();
|
||||
g_lua.bindClassMemberFunction<ThingType>("getMarketData", &ThingType::getMarketData);
|
||||
|
||||
g_lua.registerClass<Item, Thing>();
|
||||
g_lua.bindClassStaticFunction<Item>("create", &Item::create);
|
||||
g_lua.bindClassMemberFunction<Item>("clone", &Item::clone);
|
||||
|
|
|
@ -175,8 +175,7 @@ void Map::loadOtbm(const std::string& fileName)
|
|||
break;
|
||||
}
|
||||
default: {
|
||||
stdext::throw_exception(stdext::format("invalid tile attribute %d at pos %s",
|
||||
(int)tileAttr, stdext::pos_to_string(pos)));
|
||||
stdext::throw_exception(stdext::format("invalid tile attribute %d at pos %s", (int)tileAttr, stdext::to_string(pos)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,8 +202,7 @@ void Map::loadOtbm(const std::string& fileName)
|
|||
}
|
||||
|
||||
if(house && item->isMoveable()) {
|
||||
g_logger.warning(stdext::format("Movable item found in house: %d at pos %s - escaping...", item->getId(),
|
||||
stdext::pos_to_string(pos)));
|
||||
g_logger.warning(stdext::format("Movable item found in house: %d at pos %s - escaping...", item->getId(), stdext::to_string(pos)));
|
||||
item.reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <framework/core/clock.h>
|
||||
#include <framework/util/attribstorage.h>
|
||||
|
||||
enum OTBM_AttrTypes_t
|
||||
enum OTBM_ItemAttr
|
||||
{
|
||||
OTBM_ATTR_DESCRIPTION = 1,
|
||||
OTBM_ATTR_EXT_FILE = 2,
|
||||
|
|
|
@ -83,17 +83,17 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
|
|||
|
||||
void Missile::setId(uint32 id)
|
||||
{
|
||||
if(!g_things.isValidDatId(id, DatMissileCategory))
|
||||
if(!g_things.isValidDatId(id, ThingCategoryMissile))
|
||||
id = 0;
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
const ThingTypePtr& Missile::getThingType()
|
||||
{
|
||||
return g_things.getThingType(m_id, DatMissileCategory);
|
||||
return g_things.getThingType(m_id, ThingCategoryMissile);
|
||||
}
|
||||
|
||||
ThingType* Missile::rawGetThingType()
|
||||
{
|
||||
return g_things.rawGetThingType(m_id, DatMissileCategory);
|
||||
return g_things.rawGetThingType(m_id, ThingCategoryMissile);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
Outfit::Outfit()
|
||||
{
|
||||
m_category = DatCreatureCategory;
|
||||
m_category = ThingCategoryCreature;
|
||||
m_id = 0;
|
||||
resetClothes();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
void setFeet(int feet) { m_feet = feet; m_feetColor = getColor(feet); }
|
||||
void setAddons(int addons) { m_addons = addons; }
|
||||
void setMount(int mount) { m_mount = mount; }
|
||||
void setCategory(DatCategory category) { m_category = category; }
|
||||
void setCategory(ThingCategory category) { m_category = category; }
|
||||
|
||||
void resetClothes();
|
||||
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
int getFeet() const { return m_feet; }
|
||||
int getAddons() const { return m_addons; }
|
||||
int getMount() const { return m_mount; }
|
||||
DatCategory getCategory() const { return m_category; }
|
||||
ThingCategory getCategory() const { return m_category; }
|
||||
|
||||
Color getHeadColor() const { return m_headColor; }
|
||||
Color getBodyColor() const { return m_bodyColor; }
|
||||
|
@ -64,7 +64,7 @@ public:
|
|||
Color getFeetColor() const { return m_feetColor; }
|
||||
|
||||
private:
|
||||
DatCategory m_category;
|
||||
ThingCategory m_category;
|
||||
int m_id, m_head, m_body, m_legs, m_feet, m_addons, m_mount;
|
||||
Color m_headColor, m_bodyColor, m_legsColor, m_feetColor;
|
||||
};
|
||||
|
|
|
@ -32,17 +32,9 @@ class ProtocolGame : public Protocol
|
|||
{
|
||||
public:
|
||||
void login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName);
|
||||
void safeSend(const OutputMessagePtr& outputMessage);
|
||||
void send(const OutputMessagePtr& outputMessage);
|
||||
|
||||
void sendExtendedOpcode(uint8 opcode, const std::string& buffer);
|
||||
|
||||
protected:
|
||||
void onConnect();
|
||||
void onRecv(const InputMessagePtr& inputMessage);
|
||||
void onError(const boost::system::error_code& error);
|
||||
|
||||
friend class Game;
|
||||
|
||||
protected:
|
||||
void sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom);
|
||||
void sendLogout();
|
||||
void sendPing();
|
||||
|
@ -113,6 +105,13 @@ protected:
|
|||
void sendNewNewRuleViolation(int reason, int action, const std::string& characterName, const std::string& comment, const std::string& translation);
|
||||
void sendRequestItemInfo(int itemId, int index);
|
||||
|
||||
protected:
|
||||
void onConnect();
|
||||
void onRecv(const InputMessagePtr& inputMessage);
|
||||
void onError(const boost::system::error_code& error);
|
||||
|
||||
friend class Game;
|
||||
|
||||
public:
|
||||
void addPosition(const OutputMessagePtr& msg, const Position& position);
|
||||
|
||||
|
|
|
@ -1316,7 +1316,7 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg)
|
|||
|
||||
int lookType = msg->getU16();
|
||||
if(lookType != 0) {
|
||||
outfit.setCategory(DatCreatureCategory);
|
||||
outfit.setCategory(ThingCategoryCreature);
|
||||
int head = msg->getU8();
|
||||
int body = msg->getU8();
|
||||
int legs = msg->getU8();
|
||||
|
@ -1333,11 +1333,11 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg)
|
|||
else {
|
||||
int lookTypeEx = msg->getU16();
|
||||
if(lookTypeEx == 0) {
|
||||
outfit.setCategory(DatEffectCategory);
|
||||
outfit.setCategory(ThingCategoryEffect);
|
||||
outfit.setId(13);
|
||||
}
|
||||
else {
|
||||
outfit.setCategory(DatItemCategory);
|
||||
outfit.setCategory(ThingCategoryItem);
|
||||
outfit.setId(lookTypeEx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "protocolgame.h"
|
||||
#include "game.h"
|
||||
|
||||
void ProtocolGame::safeSend(const OutputMessagePtr& outputMessage)
|
||||
void ProtocolGame::send(const OutputMessagePtr& outputMessage)
|
||||
{
|
||||
// avoid usage of automated sends (bot modules)
|
||||
if(!g_game.checkBotProtection())
|
||||
|
@ -38,7 +38,7 @@ void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer)
|
|||
msg->addU8(Proto::ClientExtendedOpcode);
|
||||
msg->addU8(opcode);
|
||||
msg->addString(buffer);
|
||||
safeSend(msg);
|
||||
send(msg);
|
||||
} else {
|
||||
g_logger.error(stdext::format("Unable to send extended opcode %d, extended opcodes are not enabled", opcode));
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ void ProtocolGame::sendPing()
|
|||
{
|
||||
OutputMessagePtr msg(new OutputMessage);
|
||||
msg->addU8(Proto::ClientPing);
|
||||
send(msg);
|
||||
Protocol::send(msg);
|
||||
}
|
||||
|
||||
void ProtocolGame::sendPingBack()
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
ThingType::ThingType()
|
||||
{
|
||||
m_category = DatInvalidCategory;
|
||||
m_category = ThingInvalidCategory;
|
||||
m_id = 0;
|
||||
m_null = true;
|
||||
m_exactSize = 0;
|
||||
|
@ -41,43 +41,43 @@ ThingType::ThingType()
|
|||
m_layers = 0;
|
||||
}
|
||||
|
||||
void ThingType::unserialize(uint16 clientId, DatCategory category, const FileStreamPtr& fin)
|
||||
void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileStreamPtr& fin)
|
||||
{
|
||||
m_null = false;
|
||||
m_id = clientId;
|
||||
m_category = category;
|
||||
|
||||
bool done = false;
|
||||
for(int i = 0 ; i < DatLastAttrib;++i) {
|
||||
int attrib = fin->getU8();
|
||||
if(attrib == DatLastAttrib) {
|
||||
for(int i = 0 ; i < ThingLastAttr;++i) {
|
||||
int attr = fin->getU8();
|
||||
if(attr == ThingLastAttr) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(g_game.getFeature(Otc::GameChargeableItems)) {
|
||||
if(attrib == DatAttribWritable) {
|
||||
m_attribs.set(DatAttribChargeable, true);
|
||||
if(attr == ThingAttrWritable) {
|
||||
m_attribs.set(ThingAttrChargeable, true);
|
||||
continue;
|
||||
} else if(attrib > DatAttribWritable)
|
||||
attrib -= 1;
|
||||
} else if(attr > ThingAttrWritable)
|
||||
attr -= 1;
|
||||
}
|
||||
|
||||
switch(attrib) {
|
||||
case DatAttribDisplacement: {
|
||||
switch(attr) {
|
||||
case ThingAttrDisplacement: {
|
||||
m_displacement.x = fin->getU16();
|
||||
m_displacement.y = fin->getU16();
|
||||
m_attribs.set(attrib, true);
|
||||
m_attribs.set(attr, true);
|
||||
break;
|
||||
}
|
||||
case DatAttribLight: {
|
||||
case ThingAttrLight: {
|
||||
Light light;
|
||||
light.intensity = fin->getU16();
|
||||
light.color = fin->getU16();
|
||||
m_attribs.set(attrib, light);
|
||||
m_attribs.set(attr, light);
|
||||
break;
|
||||
}
|
||||
case DatAttribMarket: {
|
||||
case ThingAttrMarket: {
|
||||
MarketData market;
|
||||
market.category = fin->getU16();
|
||||
market.showAs = fin->getU16();
|
||||
|
@ -85,20 +85,20 @@ void ThingType::unserialize(uint16 clientId, DatCategory category, const FileStr
|
|||
market.name = fin->getString();
|
||||
market.restrictProfession = fin->getU16();
|
||||
market.requiredLevel = fin->getU16();
|
||||
m_attribs.set(attrib, market);
|
||||
m_attribs.set(attr, market);
|
||||
break;
|
||||
}
|
||||
case DatAttribGround:
|
||||
case DatAttribWritable:
|
||||
case DatAttribWritableOnce:
|
||||
case DatAttribElevation:
|
||||
case DatAttribMiniMapColor:
|
||||
case DatAttribCloth:
|
||||
case DatAttribLensHelp:
|
||||
m_attribs.set(attrib, fin->getU16());
|
||||
case ThingAttrGround:
|
||||
case ThingAttrWritable:
|
||||
case ThingAttrWritableOnce:
|
||||
case ThingAttrElevation:
|
||||
case ThingAttrMinimapColor:
|
||||
case ThingAttrCloth:
|
||||
case ThingAttrLensHelp:
|
||||
m_attribs.set(attr, fin->getU16());
|
||||
break;
|
||||
default:
|
||||
m_attribs.set(attrib, true);
|
||||
m_attribs.set(attr, true);
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ const TexturePtr& ThingType::getTexture(int animationPhase)
|
|||
// we don't need layers in common items, they will be pre-drawn
|
||||
int textureLayers = 1;
|
||||
int numLayers = m_layers;
|
||||
if(m_category == DatCreatureCategory && numLayers >= 2) {
|
||||
if(m_category == ThingCategoryCreature && numLayers >= 2) {
|
||||
// 5 layers: outfit base, red mask, green mask, blue mask, yellow mask
|
||||
textureLayers = 5;
|
||||
numLayers = 5;
|
||||
|
@ -182,7 +182,7 @@ const TexturePtr& ThingType::getTexture(int animationPhase)
|
|||
for(int y = 0; y < m_numPatternY; ++y) {
|
||||
for(int x = 0; x < m_numPatternX; ++x) {
|
||||
for(int l = 0; l < numLayers; ++l) {
|
||||
bool spriteMask = (m_category == DatCreatureCategory && l > 0);
|
||||
bool spriteMask = (m_category == ThingCategoryCreature && l > 0);
|
||||
int frameIndex = getTextureIndex(l % textureLayers, x, y, z);
|
||||
Point framePos = Point(frameIndex % (textureSize.width() / m_size.width()) * m_size.width(),
|
||||
frameIndex / (textureSize.width() / m_size.width()) * m_size.height()) * Otc::TILE_PIXELS;
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef THINGTYPEDAT_H
|
||||
#define THINGTYPEDAT_H
|
||||
#ifndef THINGTYPE_H
|
||||
#define THINGTYPE_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include <framework/core/declarations.h>
|
||||
|
@ -31,63 +31,59 @@
|
|||
#include <framework/net/server.h>
|
||||
#include <framework/util/attribstorage.h>
|
||||
|
||||
enum DatCategory {
|
||||
DatItemCategory = 0,
|
||||
DatCreatureCategory,
|
||||
DatEffectCategory,
|
||||
DatMissileCategory,
|
||||
DatLastCategory,
|
||||
DatInvalidCategory = DatLastCategory
|
||||
enum ThingCategory : uint8 {
|
||||
ThingCategoryItem = 0,
|
||||
ThingCategoryCreature,
|
||||
ThingCategoryEffect,
|
||||
ThingCategoryMissile,
|
||||
ThingInvalidCategory,
|
||||
ThingLastCategory = ThingInvalidCategory
|
||||
};
|
||||
|
||||
enum DatSpriteMask {
|
||||
DatRedMask = 1,
|
||||
DatGreenMask,
|
||||
DatBlueMask,
|
||||
DatYellowMask,
|
||||
DatLastMask
|
||||
enum ThingAttr : uint8 {
|
||||
ThingAttrGround = 0,
|
||||
ThingAttrGroundBorder = 1,
|
||||
ThingAttrOnBottom = 2,
|
||||
ThingAttrOnTop = 3,
|
||||
ThingAttrContainer = 4,
|
||||
ThingAttrStackable = 5,
|
||||
ThingAttrForceUse = 6,
|
||||
ThingAttrMultiUse = 7,
|
||||
ThingAttrWritable = 8,
|
||||
ThingAttrWritableOnce = 9,
|
||||
ThingAttrFluidContainer = 10,
|
||||
ThingAttrSplash = 11,
|
||||
ThingAttrNotWalkable = 12,
|
||||
ThingAttrNotMoveable = 13,
|
||||
ThingAttrBlockProjectile = 14,
|
||||
ThingAttrNotPathable = 15,
|
||||
ThingAttrPickupable = 16,
|
||||
ThingAttrHangable = 17,
|
||||
ThingAttrHookSouth = 18,
|
||||
ThingAttrHookEast = 19,
|
||||
ThingAttrRotateable = 20,
|
||||
ThingAttrLight = 21,
|
||||
ThingAttrDontHide = 22,
|
||||
ThingAttrTranslucent = 23,
|
||||
ThingAttrDisplacement = 24,
|
||||
ThingAttrElevation = 25,
|
||||
ThingAttrLyingCorpse = 26,
|
||||
ThingAttrAnimateAlways = 27,
|
||||
ThingAttrMinimapColor = 28,
|
||||
ThingAttrLensHelp = 29,
|
||||
ThingAttrFullGround = 30,
|
||||
ThingAttrLook = 31,
|
||||
ThingAttrCloth = 32,
|
||||
ThingAttrMarket = 33,
|
||||
ThingAttrChargeable = 254, // deprecated
|
||||
ThingLastAttr = 255,
|
||||
};
|
||||
|
||||
enum DatAttrib {
|
||||
DatAttribGround = 0,
|
||||
DatAttribGroundBorder,
|
||||
DatAttribOnBottom,
|
||||
DatAttribOnTop,
|
||||
DatAttribContainer,
|
||||
DatAttribStackable,
|
||||
DatAttribForceUse,
|
||||
DatAttribMultiUse,
|
||||
//DatAttribRune
|
||||
DatAttribWritable,
|
||||
DatAttribWritableOnce,
|
||||
DatAttribFluidContainer,
|
||||
DatAttribSplash,
|
||||
DatAttribNotWalkable,
|
||||
DatAttribNotMoveable,
|
||||
DatAttribBlockProjectile,
|
||||
DatAttribNotPathable,
|
||||
DatAttribPickupable,
|
||||
DatAttribHangable,
|
||||
DatAttribHookSouth,
|
||||
DatAttribHookEast,
|
||||
DatAttribRotateable,
|
||||
DatAttribLight,
|
||||
DatAttribDontHide,
|
||||
DatAttribTranslucent,
|
||||
DatAttribDisplacement,
|
||||
DatAttribElevation,
|
||||
DatAttribLyingCorpse,
|
||||
DatAttribAnimateAlways,
|
||||
DatAttribMiniMapColor,
|
||||
DatAttribLensHelp,
|
||||
DatAttribFullGround,
|
||||
DatAttribIgnoreLook,
|
||||
DatAttribCloth,
|
||||
DatAttribMarket,
|
||||
DatLastAttrib = 255,
|
||||
|
||||
// legacy attribs
|
||||
DatAttribChargeable = 254
|
||||
enum SpriteMask {
|
||||
SpriteMaskRed = 1,
|
||||
SpriteMaskGreen,
|
||||
SpriteMaskBlue,
|
||||
SpriteMaskYellow
|
||||
};
|
||||
|
||||
struct MarketData {
|
||||
|
@ -109,13 +105,14 @@ class ThingType : public LuaObject
|
|||
public:
|
||||
ThingType();
|
||||
|
||||
void unserialize(uint16 clientId, DatCategory category, const FileStreamPtr& fin);
|
||||
void unserialize(uint16 clientId, ThingCategory category, const FileStreamPtr& fin);
|
||||
|
||||
void draw(const Point& dest, float scaleFactor, int layer, int xPattern, int yPattern, int zPattern, int animationPhase);
|
||||
|
||||
uint16 getId() { return m_id; }
|
||||
DatCategory getCategory() { return m_category; }
|
||||
ThingCategory getCategory() { return m_category; }
|
||||
bool isNull() { return m_null; }
|
||||
bool hasAttr(ThingAttr attr) { return m_attribs.has(attr); }
|
||||
|
||||
Size getSize() { return m_size; }
|
||||
int getWidth() { return m_size.width(); }
|
||||
|
@ -130,49 +127,49 @@ public:
|
|||
int getDisplacementX() { return getDisplacement().x; }
|
||||
int getDisplacementY() { return getDisplacement().y; }
|
||||
|
||||
int getGroundSpeed() { return m_attribs.get<uint16>(DatAttribGround); }
|
||||
int getMaxTextLength() { return m_attribs.has(DatAttribWritableOnce) ? m_attribs.get<uint16>(DatAttribWritableOnce) : m_attribs.get<uint16>(DatAttribWritable); }
|
||||
Light getLight() { return m_attribs.get<Light>(DatAttribLight); }
|
||||
int getMinimapColor() { return m_attribs.get<uint16>(DatAttribMiniMapColor); }
|
||||
int getLensHelp() { return m_attribs.get<uint16>(DatAttribLensHelp); }
|
||||
int getClothSlot() { return m_attribs.get<uint16>(DatAttribCloth); }
|
||||
int getElevation() { return m_attribs.get<uint16>(DatAttribElevation); }
|
||||
MarketData getMarketData() { return m_attribs.get<MarketData>(DatAttribMarket); }
|
||||
bool isGround() { return m_attribs.has(DatAttribGround); }
|
||||
bool isGroundBorder() { return m_attribs.has(DatAttribGroundBorder); }
|
||||
bool isOnBottom() { return m_attribs.has(DatAttribOnBottom); }
|
||||
bool isOnTop() { return m_attribs.has(DatAttribOnTop); }
|
||||
bool isContainer() { return m_attribs.has(DatAttribContainer); }
|
||||
bool isStackable() { return m_attribs.has(DatAttribStackable); }
|
||||
bool isForceUse() { return m_attribs.has(DatAttribForceUse); }
|
||||
bool isMultiUse() { return m_attribs.has(DatAttribMultiUse); }
|
||||
bool isWritable() { return m_attribs.has(DatAttribWritable); }
|
||||
bool isChargeable() { return m_attribs.has(DatAttribChargeable); }
|
||||
bool isWritableOnce() { return m_attribs.has(DatAttribWritableOnce); }
|
||||
bool isFluidContainer() { return m_attribs.has(DatAttribFluidContainer); }
|
||||
bool isSplash() { return m_attribs.has(DatAttribSplash); }
|
||||
bool isNotWalkable() { return m_attribs.has(DatAttribNotWalkable); }
|
||||
bool isNotMoveable() { return m_attribs.has(DatAttribNotMoveable); }
|
||||
bool blockProjectile() { return m_attribs.has(DatAttribBlockProjectile); }
|
||||
bool isNotPathable() { return m_attribs.has(DatAttribNotPathable); }
|
||||
bool isPickupable() { return m_attribs.has(DatAttribPickupable); }
|
||||
bool isHangable() { return m_attribs.has(DatAttribHangable); }
|
||||
bool isHookSouth() { return m_attribs.has(DatAttribHookSouth); }
|
||||
bool isHookEast() { return m_attribs.has(DatAttribHookEast); }
|
||||
bool isRotateable() { return m_attribs.has(DatAttribRotateable); }
|
||||
bool hasLight() { return m_attribs.has(DatAttribLight); }
|
||||
bool isDontHide() { return m_attribs.has(DatAttribDontHide); }
|
||||
bool isTranslucent() { return m_attribs.has(DatAttribTranslucent); }
|
||||
bool hasDisplacement() { return m_attribs.has(DatAttribDisplacement); }
|
||||
bool hasElevation() { return m_attribs.has(DatAttribElevation); }
|
||||
bool isLyingCorpse() { return m_attribs.has(DatAttribLyingCorpse); }
|
||||
bool isAnimateAlways() { return m_attribs.has(DatAttribAnimateAlways); }
|
||||
bool hasMiniMapColor() { return m_attribs.has(DatAttribMiniMapColor); }
|
||||
bool hasLensHelp() { return m_attribs.has(DatAttribLensHelp); }
|
||||
bool isFullGround() { return m_attribs.has(DatAttribFullGround); }
|
||||
bool isIgnoreLook() { return m_attribs.has(DatAttribIgnoreLook); }
|
||||
bool isCloth() { return m_attribs.has(DatAttribCloth); }
|
||||
bool isMarketable() { return m_attribs.has(DatAttribMarket); }
|
||||
int getGroundSpeed() { return m_attribs.get<uint16>(ThingAttrGround); }
|
||||
int getMaxTextLength() { return m_attribs.has(ThingAttrWritableOnce) ? m_attribs.get<uint16>(ThingAttrWritableOnce) : m_attribs.get<uint16>(ThingAttrWritable); }
|
||||
Light getLight() { return m_attribs.get<Light>(ThingAttrLight); }
|
||||
int getMinimapColor() { return m_attribs.get<uint16>(ThingAttrMinimapColor); }
|
||||
int getLensHelp() { return m_attribs.get<uint16>(ThingAttrLensHelp); }
|
||||
int getClothSlot() { return m_attribs.get<uint16>(ThingAttrCloth); }
|
||||
int getElevation() { return m_attribs.get<uint16>(ThingAttrElevation); }
|
||||
MarketData getMarketData() { return m_attribs.get<MarketData>(ThingAttrMarket); }
|
||||
bool isGround() { return m_attribs.has(ThingAttrGround); }
|
||||
bool isGroundBorder() { return m_attribs.has(ThingAttrGroundBorder); }
|
||||
bool isOnBottom() { return m_attribs.has(ThingAttrOnBottom); }
|
||||
bool isOnTop() { return m_attribs.has(ThingAttrOnTop); }
|
||||
bool isContainer() { return m_attribs.has(ThingAttrContainer); }
|
||||
bool isStackable() { return m_attribs.has(ThingAttrStackable); }
|
||||
bool isForceUse() { return m_attribs.has(ThingAttrForceUse); }
|
||||
bool isMultiUse() { return m_attribs.has(ThingAttrMultiUse); }
|
||||
bool isWritable() { return m_attribs.has(ThingAttrWritable); }
|
||||
bool isChargeable() { return m_attribs.has(ThingAttrChargeable); }
|
||||
bool isWritableOnce() { return m_attribs.has(ThingAttrWritableOnce); }
|
||||
bool isFluidContainer() { return m_attribs.has(ThingAttrFluidContainer); }
|
||||
bool isSplash() { return m_attribs.has(ThingAttrSplash); }
|
||||
bool isNotWalkable() { return m_attribs.has(ThingAttrNotWalkable); }
|
||||
bool isNotMoveable() { return m_attribs.has(ThingAttrNotMoveable); }
|
||||
bool blockProjectile() { return m_attribs.has(ThingAttrBlockProjectile); }
|
||||
bool isNotPathable() { return m_attribs.has(ThingAttrNotPathable); }
|
||||
bool isPickupable() { return m_attribs.has(ThingAttrPickupable); }
|
||||
bool isHangable() { return m_attribs.has(ThingAttrHangable); }
|
||||
bool isHookSouth() { return m_attribs.has(ThingAttrHookSouth); }
|
||||
bool isHookEast() { return m_attribs.has(ThingAttrHookEast); }
|
||||
bool isRotateable() { return m_attribs.has(ThingAttrRotateable); }
|
||||
bool hasLight() { return m_attribs.has(ThingAttrLight); }
|
||||
bool isDontHide() { return m_attribs.has(ThingAttrDontHide); }
|
||||
bool isTranslucent() { return m_attribs.has(ThingAttrTranslucent); }
|
||||
bool hasDisplacement() { return m_attribs.has(ThingAttrDisplacement); }
|
||||
bool hasElevation() { return m_attribs.has(ThingAttrElevation); }
|
||||
bool isLyingCorpse() { return m_attribs.has(ThingAttrLyingCorpse); }
|
||||
bool isAnimateAlways() { return m_attribs.has(ThingAttrAnimateAlways); }
|
||||
bool hasMiniMapColor() { return m_attribs.has(ThingAttrMinimapColor); }
|
||||
bool hasLensHelp() { return m_attribs.has(ThingAttrLensHelp); }
|
||||
bool isFullGround() { return m_attribs.has(ThingAttrFullGround); }
|
||||
bool isIgnoreLook() { return m_attribs.has(ThingAttrLook); }
|
||||
bool isCloth() { return m_attribs.has(ThingAttrCloth); }
|
||||
bool isMarketable() { return m_attribs.has(ThingAttrMarket); }
|
||||
|
||||
private:
|
||||
const TexturePtr& getTexture(int animationPhase);
|
||||
|
@ -180,7 +177,7 @@ private:
|
|||
uint getSpriteIndex(int w, int h, int l, int x, int y, int z, int a);
|
||||
uint getTextureIndex(int l, int x, int y, int z);
|
||||
|
||||
DatCategory m_category;
|
||||
ThingCategory m_category;
|
||||
uint16 m_id;
|
||||
bool m_null;
|
||||
AttribStorage m_attribs;
|
||||
|
|
|
@ -43,16 +43,16 @@ void ThingTypeManager::init()
|
|||
m_datLoaded = false;
|
||||
m_xmlLoaded = false;
|
||||
m_otbLoaded = false;
|
||||
for(int i = 0; i < DatLastCategory; ++i)
|
||||
m_datTypes[i].resize(1, m_nullThingType);
|
||||
m_otbTypes.resize(1, m_nullItemType);
|
||||
for(int i = 0; i < ThingLastCategory; ++i)
|
||||
m_thingTypes[i].resize(1, m_nullThingType);
|
||||
m_itemTypes.resize(1, m_nullItemType);
|
||||
}
|
||||
|
||||
void ThingTypeManager::terminate()
|
||||
{
|
||||
for(int i = 0; i < DatLastCategory; ++i)
|
||||
m_datTypes[i].clear();
|
||||
m_otbTypes.clear();
|
||||
for(int i = 0; i < ThingLastCategory; ++i)
|
||||
m_thingTypes[i].clear();
|
||||
m_itemTypes.clear();
|
||||
m_nullThingType = nullptr;
|
||||
m_nullItemType = nullptr;
|
||||
}
|
||||
|
@ -66,20 +66,20 @@ bool ThingTypeManager::loadDat(const std::string& file)
|
|||
|
||||
m_datSignature = fin->getU32();
|
||||
|
||||
int numThings[DatLastCategory];
|
||||
for(int category = 0; category < DatLastCategory; ++category) {
|
||||
int numThings[ThingLastCategory];
|
||||
for(int category = 0; category < ThingLastCategory; ++category) {
|
||||
int count = fin->getU16() + 1;
|
||||
m_datTypes[category].resize(count, m_nullThingType);
|
||||
m_thingTypes[category].resize(count, m_nullThingType);
|
||||
}
|
||||
|
||||
for(int category = 0; category < DatLastCategory; ++category) {
|
||||
for(int category = 0; category < ThingLastCategory; ++category) {
|
||||
uint16 firstId = 1;
|
||||
if(category == DatItemCategory)
|
||||
if(category == ThingCategoryItem)
|
||||
firstId = 100;
|
||||
for(uint16 id = firstId; id < m_datTypes[category].size(); ++id) {
|
||||
for(uint16 id = firstId; id < m_thingTypes[category].size(); ++id) {
|
||||
ThingTypePtr type(new ThingType);
|
||||
type->unserialize(id, (DatCategory)category, fin);
|
||||
m_datTypes[category][id] = type;
|
||||
type->unserialize(id, (ThingCategory)category, fin);
|
||||
m_thingTypes[category][id] = type;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ void ThingTypeManager::loadOtb(const std::string& file)
|
|||
root->getU32(); // build number
|
||||
root->skip(128); // description
|
||||
|
||||
m_otbTypes.resize(root->getChildren().size(), m_nullItemType);
|
||||
m_itemTypes.resize(root->getChildren().size(), m_nullItemType);
|
||||
for(const BinaryTreePtr& node : root->getChildren()) {
|
||||
ItemTypePtr otbType(new ItemType);
|
||||
otbType->unserialize(node);
|
||||
|
@ -187,17 +187,17 @@ void ThingTypeManager::parseItemType(uint16 id, TiXmlElement* elem)
|
|||
void ThingTypeManager::addItemType(const ItemTypePtr& otbType)
|
||||
{
|
||||
uint16 id = otbType->getServerId();
|
||||
if(m_otbTypes.size() <= id)
|
||||
m_otbTypes.resize(id+1, m_nullItemType);
|
||||
m_otbTypes[id] = otbType;
|
||||
if(m_itemTypes.size() <= id)
|
||||
m_itemTypes.resize(id+1, m_nullItemType);
|
||||
m_itemTypes[id] = otbType;
|
||||
}
|
||||
|
||||
const ItemTypePtr& ThingTypeManager::findOtbForClientId(uint16 id)
|
||||
{
|
||||
if(m_otbTypes.empty())
|
||||
if(m_itemTypes.empty())
|
||||
return m_nullItemType;
|
||||
|
||||
for(const ItemTypePtr& otbType : m_otbTypes) {
|
||||
for(const ItemTypePtr& otbType : m_itemTypes) {
|
||||
if(otbType->getClientId() == id)
|
||||
return otbType;
|
||||
}
|
||||
|
@ -205,21 +205,46 @@ const ItemTypePtr& ThingTypeManager::findOtbForClientId(uint16 id)
|
|||
return m_nullItemType;
|
||||
}
|
||||
|
||||
const ThingTypePtr& ThingTypeManager::getThingType(uint16 id, DatCategory category)
|
||||
const ThingTypePtr& ThingTypeManager::getThingType(uint16 id, ThingCategory category)
|
||||
{
|
||||
if(category >= DatLastCategory || id >= m_datTypes[category].size()) {
|
||||
if(category >= ThingLastCategory || id >= m_thingTypes[category].size()) {
|
||||
g_logger.error(stdext::format("invalid thing type client id %d in category %d", id, category));
|
||||
return m_nullThingType;
|
||||
}
|
||||
return m_datTypes[category][id];
|
||||
return m_thingTypes[category][id];
|
||||
}
|
||||
|
||||
const ItemTypePtr& ThingTypeManager::getItemType(uint16 id)
|
||||
{
|
||||
if(id >= m_otbTypes.size()) {
|
||||
if(id >= m_itemTypes.size()) {
|
||||
g_logger.error(stdext::format("invalid thing type server id %d", id));
|
||||
return m_nullItemType;
|
||||
}
|
||||
return m_otbTypes[id];
|
||||
return m_itemTypes[id];
|
||||
}
|
||||
|
||||
ThingTypeList ThingTypeManager::findThingTypeByAttr(ThingAttr attr, ThingCategory category)
|
||||
{
|
||||
ThingTypeList ret;
|
||||
for(const ThingTypePtr& type : m_thingTypes[category])
|
||||
if(type->hasAttr(attr))
|
||||
ret.push_back(type);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ItemTypeList ThingTypeManager::findItemTypeByCategory(ItemCategory category)
|
||||
{
|
||||
ItemTypeList ret;
|
||||
for(const ItemTypePtr& type : m_itemTypes)
|
||||
if(type->getCategory() == category)
|
||||
ret.push_back(type);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const ThingTypeList& ThingTypeManager::getThingTypes(ThingCategory category)
|
||||
{
|
||||
ThingTypeList ret;
|
||||
if(category >= ThingLastCategory)
|
||||
stdext::throw_exception(stdext::format("invalid thing type category %d", category));
|
||||
return m_thingTypes[category];
|
||||
}
|
||||
|
|
|
@ -46,10 +46,16 @@ public:
|
|||
const ThingTypePtr& getNullThingType() { return m_nullThingType; }
|
||||
const ItemTypePtr& getNullItemType() { return m_nullItemType; }
|
||||
|
||||
const ThingTypePtr& getThingType(uint16 id, DatCategory category);
|
||||
const ThingTypePtr& getThingType(uint16 id, ThingCategory category);
|
||||
const ItemTypePtr& getItemType(uint16 id);
|
||||
ThingType* rawGetThingType(uint16 id, DatCategory category) { return m_datTypes[category][id].get(); }
|
||||
ItemType* rawGetItemType(uint16 id) { return m_otbTypes[id].get(); }
|
||||
ThingType* rawGetThingType(uint16 id, ThingCategory category) { return m_thingTypes[category][id].get(); }
|
||||
ItemType* rawGetItemType(uint16 id) { return m_itemTypes[id].get(); }
|
||||
|
||||
ThingTypeList findThingTypeByAttr(ThingAttr attr, ThingCategory category);
|
||||
ItemTypeList findItemTypeByCategory(ItemCategory category);
|
||||
|
||||
const ThingTypeList& getThingTypes(ThingCategory category);
|
||||
const ItemTypeList& getItemTypes() { return m_itemTypes; }
|
||||
|
||||
uint32 getDatSignature() { return m_datSignature; }
|
||||
uint32 getOtbMajorVersion() { return m_otbMajorVersion; }
|
||||
|
@ -59,12 +65,12 @@ public:
|
|||
bool isXmlLoaded() { return m_xmlLoaded; }
|
||||
bool isOtbLoaded() { return m_otbLoaded; }
|
||||
|
||||
bool isValidDatId(uint16 id, DatCategory category) { return id >= 1 && id < m_datTypes[category].size(); }
|
||||
bool isValidOtbId(uint16 id) { return id >= 1 && id < m_otbTypes.size(); }
|
||||
bool isValidDatId(uint16 id, ThingCategory category) { return id >= 1 && id < m_thingTypes[category].size(); }
|
||||
bool isValidOtbId(uint16 id) { return id >= 1 && id < m_itemTypes.size(); }
|
||||
|
||||
private:
|
||||
ThingTypeList m_datTypes[DatLastCategory];
|
||||
ItemTypeList m_otbTypes;
|
||||
ThingTypeList m_thingTypes[ThingLastCategory];
|
||||
ItemTypeList m_itemTypes;
|
||||
|
||||
ThingTypePtr m_nullThingType;
|
||||
ItemTypePtr m_nullItemType;
|
||||
|
|
Loading…
Reference in New Issue