From 3b23b787f30505957ac30f771b81074dbb5a1c20 Mon Sep 17 00:00:00 2001 From: Kamil Chojnowski Date: Sun, 19 Nov 2017 02:37:41 +0100 Subject: [PATCH] Add creature type icons for summons --- .../game/{ => creaturetype}/summon_other.png | Bin .../game/{ => creaturetype}/summon_own.png | Bin modules/gamelib/creature.lua | 25 +++++++++++++++++- src/client/creature.cpp | 18 ++++++++++++- src/client/creature.h | 5 ++++ src/client/luafunctions.cpp | 2 ++ src/client/protocolcodes.h | 3 ++- src/client/protocolgameparse.cpp | 18 ++++++++++--- 8 files changed, 65 insertions(+), 6 deletions(-) rename data/images/game/{ => creaturetype}/summon_other.png (100%) rename data/images/game/{ => creaturetype}/summon_own.png (100%) diff --git a/data/images/game/summon_other.png b/data/images/game/creaturetype/summon_other.png similarity index 100% rename from data/images/game/summon_other.png rename to data/images/game/creaturetype/summon_other.png diff --git a/data/images/game/summon_own.png b/data/images/game/creaturetype/summon_own.png similarity index 100% rename from data/images/game/summon_own.png rename to data/images/game/creaturetype/summon_own.png diff --git a/modules/gamelib/creature.lua b/modules/gamelib/creature.lua index 382c468c..1c4c9cee 100644 --- a/modules/gamelib/creature.lua +++ b/modules/gamelib/creature.lua @@ -33,6 +33,12 @@ NpcIconTrade = 2 NpcIconQuest = 3 NpcIconTradeQuest = 4 +CreatureTypePlayer = 0 +CreatureTypeMonster = 1 +CreatureTypeNpc = 2 +CreatureTypeSummonOwn = 3 +CreatureTypeSummonOther = 4 + -- @} function getNextSkullId(skullId) @@ -104,6 +110,16 @@ function getEmblemImagePath(emblemId) return path end +function getTypeImagePath(creatureType) + local path + if creatureType == CreatureTypeSummonOwn then + path = '/images/game/creaturetype/summon_own' + elseif creatureType == CreatureTypeSummonOther then + path = '/images/game/creaturetype/summon_other' + end + return path +end + function getIconImagePath(iconId) local path if iconId == NpcIconChat then @@ -139,9 +155,16 @@ function Creature:onEmblemChange(emblemId) end end +function Creature:onTypeChange(typeId) + local imagePath = getTypeImagePath(typeId) + if imagePath then + self:setTypeTexture(imagePath) + end +end + function Creature:onIconChange(iconId) local imagePath = getIconImagePath(iconId) if imagePath then self:setIconTexture(imagePath) end -end \ No newline at end of file +end diff --git a/src/client/creature.cpp b/src/client/creature.cpp index 661aa717..00d23d54 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -53,6 +53,7 @@ Creature::Creature() : Thing() m_skull = Otc::SkullNone; m_shield = Otc::ShieldNone; m_emblem = Otc::EmblemNone; + m_type = Proto::CreatureTypeUnknown; m_icon = Otc::NpcIconNone; m_lastStepDirection = Otc::InvalidDirection; m_nameCache.setFont(g_fonts.getFont("verdana-11px-rounded")); @@ -309,6 +310,11 @@ void Creature::drawInformation(const Point& point, bool useGray, const Rect& par Rect emblemRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 16, m_emblemTexture->getSize()); g_painter->drawTexturedRect(emblemRect, m_emblemTexture); } + if(m_type != Proto::CreatureTypeUnknown && m_typeTexture) { + g_painter->setColor(Color::white); + Rect typeRect = Rect(backgroundRect.x() + 13.5 + 12 + 12, backgroundRect.y() + 16, m_typeTexture->getSize()); + g_painter->drawTexturedRect(typeRect, m_typeTexture); + } if(m_icon != Otc::NpcIconNone && m_iconTexture) { g_painter->setColor(Color::white); Rect iconRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_iconTexture->getSize()); @@ -745,6 +751,12 @@ void Creature::setEmblem(uint8 emblem) callLuaField("onEmblemChange", m_emblem); } +void Creature::setType(uint8 type) +{ + m_type = type; + callLuaField("onTypeChange", m_type); +} + void Creature::setIcon(uint8 icon) { m_icon = icon; @@ -776,12 +788,16 @@ void Creature::setEmblemTexture(const std::string& filename) m_emblemTexture = g_textures.getTexture(filename); } +void Creature::setTypeTexture(const std::string& filename) +{ + m_typeTexture = g_textures.getTexture(filename); +} + void Creature::setIconTexture(const std::string& filename) { m_iconTexture = g_textures.getTexture(filename); } - void Creature::setSpeedFormula(double speedA, double speedB, double speedC) { m_speedFormula[Otc::SpeedFormulaA] = speedA; diff --git a/src/client/creature.h b/src/client/creature.h index a11e0f6a..ba9895f5 100644 --- a/src/client/creature.h +++ b/src/client/creature.h @@ -62,10 +62,12 @@ public: void setSkull(uint8 skull); void setShield(uint8 shield); void setEmblem(uint8 emblem); + void setType(uint8 type); void setIcon(uint8 icon); void setSkullTexture(const std::string& filename); void setShieldTexture(const std::string& filename, bool blink); void setEmblemTexture(const std::string& filename); + void setTypeTexture(const std::string& filename); void setIconTexture(const std::string& filename); void setPassable(bool passable) { m_passable = passable; } void setSpeedFormula(double speedA, double speedB, double speedC); @@ -87,6 +89,7 @@ public: uint8 getSkull() { return m_skull; } uint8 getShield() { return m_shield; } uint8 getEmblem() { return m_emblem; } + uint8 getType() { return m_type; } uint8 getIcon() { return m_icon; } bool isPassable() { return m_passable; } Point getDrawOffset(); @@ -153,10 +156,12 @@ protected: uint8 m_skull; uint8 m_shield; uint8 m_emblem; + uint8 m_type; uint8 m_icon; TexturePtr m_skullTexture; TexturePtr m_shieldTexture; TexturePtr m_emblemTexture; + TexturePtr m_typeTexture; TexturePtr m_iconTexture; stdext::boolean m_showShieldTexture; stdext::boolean m_shieldBlink; diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index e8344792..d068f8f1 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -456,6 +456,7 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("getSkull", &Creature::getSkull); g_lua.bindClassMemberFunction("getShield", &Creature::getShield); g_lua.bindClassMemberFunction("getEmblem", &Creature::getEmblem); + g_lua.bindClassMemberFunction("getType", &Creature::getType); g_lua.bindClassMemberFunction("getIcon", &Creature::getIcon); g_lua.bindClassMemberFunction("setOutfit", &Creature::setOutfit); g_lua.bindClassMemberFunction("getOutfit", &Creature::getOutfit); @@ -469,6 +470,7 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("setSkullTexture", &Creature::setSkullTexture); g_lua.bindClassMemberFunction("setShieldTexture", &Creature::setShieldTexture); g_lua.bindClassMemberFunction("setEmblemTexture", &Creature::setEmblemTexture); + g_lua.bindClassMemberFunction("setTypeTexture", &Creature::setTypeTexture); g_lua.bindClassMemberFunction("setIconTexture", &Creature::setIconTexture); g_lua.bindClassMemberFunction("showStaticSquare", &Creature::showStaticSquare); g_lua.bindClassMemberFunction("hideStaticSquare", &Creature::hideStaticSquare); diff --git a/src/client/protocolcodes.h b/src/client/protocolcodes.h index c6e2347d..0d95444f 100644 --- a/src/client/protocolcodes.h +++ b/src/client/protocolcodes.h @@ -278,7 +278,8 @@ namespace Proto { CreatureTypeMonster, CreatureTypeNpc, CreatureTypeSummonOwn, - CreatureTypeSummonOther + CreatureTypeSummonOther, + CreatureTypeUnknown = 0xFF }; enum CreaturesIdRange { diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index 4d75a099..5bb49816 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -2031,6 +2031,12 @@ void ProtocolGame::parseCreatureType(const InputMessagePtr& msg) { uint32 id = msg->getU32(); uint8 type = msg->getU8(); + + CreaturePtr creature = g_map.getCreatureById(id); + if(creature) + creature->setType(type); + else + g_logger.traceError("could not get creature"); } void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height) @@ -2262,8 +2268,9 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) int shield = msg->getU8(); // emblem is sent only when the creature is not known - int emblem = -1; - int icon = -1; + int8 emblem = -1; + int8 creatureType = -1; + int8 icon = -1; bool unpass = true; uint8 mark; @@ -2271,7 +2278,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) emblem = msg->getU8(); if(g_game.getFeature(Otc::GameThingMarks)) { - msg->getU8(); // creature type for summons + creatureType = msg->getU8(); } if(g_game.getFeature(Otc::GameCreatureIcons)) { @@ -2302,8 +2309,13 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) creature->setShield(shield); creature->setPassable(!unpass); creature->setLight(light); + if(emblem != -1) creature->setEmblem(emblem); + + if(creatureType != -1) + creature->setType(creatureType); + if(icon != -1) creature->setIcon(icon);