Browse Source

Add creature type icons for summons

Kamil Chojnowski 2 years ago
parent
commit
3b23b787f3

data/images/game/summon_other.png → data/images/game/creaturetype/summon_other.png View File


data/images/game/summon_own.png → data/images/game/creaturetype/summon_own.png View File


+ 24
- 1
modules/gamelib/creature.lua View File

@@ -33,6 +33,12 @@ NpcIconTrade = 2
33 33
 NpcIconQuest = 3
34 34
 NpcIconTradeQuest = 4
35 35
 
36
+CreatureTypePlayer = 0
37
+CreatureTypeMonster = 1
38
+CreatureTypeNpc = 2
39
+CreatureTypeSummonOwn = 3
40
+CreatureTypeSummonOther = 4
41
+
36 42
 -- @}
37 43
 
38 44
 function getNextSkullId(skullId)
@@ -104,6 +110,16 @@ function getEmblemImagePath(emblemId)
104 110
   return path
105 111
 end
106 112
 
113
+function getTypeImagePath(creatureType)
114
+  local path
115
+  if creatureType == CreatureTypeSummonOwn then
116
+    path = '/images/game/creaturetype/summon_own'
117
+  elseif creatureType == CreatureTypeSummonOther then
118
+    path = '/images/game/creaturetype/summon_other'
119
+  end
120
+  return path
121
+end
122
+
107 123
 function getIconImagePath(iconId)
108 124
   local path
109 125
   if iconId == NpcIconChat then
@@ -139,9 +155,16 @@ function Creature:onEmblemChange(emblemId)
139 155
   end
140 156
 end
141 157
 
158
+function Creature:onTypeChange(typeId)
159
+  local imagePath = getTypeImagePath(typeId)
160
+  if imagePath then
161
+    self:setTypeTexture(imagePath)
162
+  end
163
+end
164
+
142 165
 function Creature:onIconChange(iconId)
143 166
   local imagePath = getIconImagePath(iconId)
144 167
   if imagePath then
145 168
     self:setIconTexture(imagePath)
146 169
   end
147
-end
170
+end

+ 17
- 1
src/client/creature.cpp View File

@@ -53,6 +53,7 @@ Creature::Creature() : Thing()
53 53
     m_skull = Otc::SkullNone;
54 54
     m_shield = Otc::ShieldNone;
55 55
     m_emblem = Otc::EmblemNone;
56
+    m_type = Proto::CreatureTypeUnknown;
56 57
     m_icon = Otc::NpcIconNone;
57 58
     m_lastStepDirection = Otc::InvalidDirection;
58 59
     m_nameCache.setFont(g_fonts.getFont("verdana-11px-rounded"));
@@ -309,6 +310,11 @@ void Creature::drawInformation(const Point& point, bool useGray, const Rect& par
309 310
         Rect emblemRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 16, m_emblemTexture->getSize());
310 311
         g_painter->drawTexturedRect(emblemRect, m_emblemTexture);
311 312
     }
313
+    if(m_type != Proto::CreatureTypeUnknown && m_typeTexture) {
314
+        g_painter->setColor(Color::white);
315
+        Rect typeRect = Rect(backgroundRect.x() + 13.5 + 12 + 12, backgroundRect.y() + 16, m_typeTexture->getSize());
316
+        g_painter->drawTexturedRect(typeRect, m_typeTexture);
317
+    }
312 318
     if(m_icon != Otc::NpcIconNone && m_iconTexture) {
313 319
         g_painter->setColor(Color::white);
314 320
         Rect iconRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_iconTexture->getSize());
@@ -745,6 +751,12 @@ void Creature::setEmblem(uint8 emblem)
745 751
     callLuaField("onEmblemChange", m_emblem);
746 752
 }
747 753
 
754
+void Creature::setType(uint8 type)
755
+{
756
+    m_type = type;
757
+    callLuaField("onTypeChange", m_type);
758
+}
759
+
748 760
 void Creature::setIcon(uint8 icon)
749 761
 {
750 762
     m_icon = icon;
@@ -776,12 +788,16 @@ void Creature::setEmblemTexture(const std::string& filename)
776 788
     m_emblemTexture = g_textures.getTexture(filename);
777 789
 }
778 790
 
791
+void Creature::setTypeTexture(const std::string& filename)
792
+{
793
+    m_typeTexture = g_textures.getTexture(filename);
794
+}
795
+
779 796
 void Creature::setIconTexture(const std::string& filename)
780 797
 {
781 798
     m_iconTexture = g_textures.getTexture(filename);
782 799
 }
783 800
 
784
-
785 801
 void Creature::setSpeedFormula(double speedA, double speedB, double speedC)
786 802
 {
787 803
     m_speedFormula[Otc::SpeedFormulaA] = speedA;

+ 5
- 0
src/client/creature.h View File

@@ -62,10 +62,12 @@ public:
62 62
     void setSkull(uint8 skull);
63 63
     void setShield(uint8 shield);
64 64
     void setEmblem(uint8 emblem);
65
+    void setType(uint8 type);
65 66
     void setIcon(uint8 icon);
66 67
     void setSkullTexture(const std::string& filename);
67 68
     void setShieldTexture(const std::string& filename, bool blink);
68 69
     void setEmblemTexture(const std::string& filename);
70
+    void setTypeTexture(const std::string& filename);
69 71
     void setIconTexture(const std::string& filename);
70 72
     void setPassable(bool passable) { m_passable = passable; }
71 73
     void setSpeedFormula(double speedA, double speedB, double speedC);
@@ -87,6 +89,7 @@ public:
87 89
     uint8 getSkull() { return m_skull; }
88 90
     uint8 getShield() { return m_shield; }
89 91
     uint8 getEmblem() { return m_emblem; }
92
+    uint8 getType() { return m_type; }
90 93
     uint8 getIcon() { return m_icon; }
91 94
     bool isPassable() { return m_passable; }
92 95
     Point getDrawOffset();
@@ -153,10 +156,12 @@ protected:
153 156
     uint8 m_skull;
154 157
     uint8 m_shield;
155 158
     uint8 m_emblem;
159
+    uint8 m_type;
156 160
     uint8 m_icon;
157 161
     TexturePtr m_skullTexture;
158 162
     TexturePtr m_shieldTexture;
159 163
     TexturePtr m_emblemTexture;
164
+    TexturePtr m_typeTexture;
160 165
     TexturePtr m_iconTexture;
161 166
     stdext::boolean<true> m_showShieldTexture;
162 167
     stdext::boolean<false> m_shieldBlink;

+ 2
- 0
src/client/luafunctions.cpp View File

@@ -456,6 +456,7 @@ void Client::registerLuaFunctions()
456 456
     g_lua.bindClassMemberFunction<Creature>("getSkull", &Creature::getSkull);
457 457
     g_lua.bindClassMemberFunction<Creature>("getShield", &Creature::getShield);
458 458
     g_lua.bindClassMemberFunction<Creature>("getEmblem", &Creature::getEmblem);
459
+    g_lua.bindClassMemberFunction<Creature>("getType", &Creature::getType);
459 460
     g_lua.bindClassMemberFunction<Creature>("getIcon", &Creature::getIcon);
460 461
     g_lua.bindClassMemberFunction<Creature>("setOutfit", &Creature::setOutfit);
461 462
     g_lua.bindClassMemberFunction<Creature>("getOutfit", &Creature::getOutfit);
@@ -469,6 +470,7 @@ void Client::registerLuaFunctions()
469 470
     g_lua.bindClassMemberFunction<Creature>("setSkullTexture", &Creature::setSkullTexture);
470 471
     g_lua.bindClassMemberFunction<Creature>("setShieldTexture", &Creature::setShieldTexture);
471 472
     g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture);
473
+    g_lua.bindClassMemberFunction<Creature>("setTypeTexture", &Creature::setTypeTexture);
472 474
     g_lua.bindClassMemberFunction<Creature>("setIconTexture", &Creature::setIconTexture);
473 475
     g_lua.bindClassMemberFunction<Creature>("showStaticSquare", &Creature::showStaticSquare);
474 476
     g_lua.bindClassMemberFunction<Creature>("hideStaticSquare", &Creature::hideStaticSquare);

+ 2
- 1
src/client/protocolcodes.h View File

@@ -278,7 +278,8 @@ namespace Proto {
278 278
         CreatureTypeMonster,
279 279
         CreatureTypeNpc,
280 280
         CreatureTypeSummonOwn,
281
-        CreatureTypeSummonOther
281
+        CreatureTypeSummonOther,
282
+        CreatureTypeUnknown = 0xFF
282 283
     };
283 284
 
284 285
     enum CreaturesIdRange {

+ 15
- 3
src/client/protocolgameparse.cpp View File

@@ -2031,6 +2031,12 @@ void ProtocolGame::parseCreatureType(const InputMessagePtr& msg)
2031 2031
 {
2032 2032
     uint32 id = msg->getU32();
2033 2033
     uint8 type = msg->getU8();
2034
+
2035
+    CreaturePtr creature = g_map.getCreatureById(id);
2036
+    if(creature)
2037
+        creature->setType(type);
2038
+    else
2039
+        g_logger.traceError("could not get creature");
2034 2040
 }
2035 2041
 
2036 2042
 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)
2262 2268
         int shield = msg->getU8();
2263 2269
 
2264 2270
         // emblem is sent only when the creature is not known
2265
-        int emblem = -1;
2266
-        int icon = -1;
2271
+        int8 emblem = -1;
2272
+        int8 creatureType = -1;
2273
+        int8 icon = -1;
2267 2274
         bool unpass = true;
2268 2275
         uint8 mark;
2269 2276
 
@@ -2271,7 +2278,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
2271 2278
             emblem = msg->getU8();
2272 2279
 
2273 2280
         if(g_game.getFeature(Otc::GameThingMarks)) {
2274
-            msg->getU8(); // creature type for summons
2281
+            creatureType = msg->getU8();
2275 2282
         }
2276 2283
 
2277 2284
         if(g_game.getFeature(Otc::GameCreatureIcons)) {
@@ -2302,8 +2309,13 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
2302 2309
             creature->setShield(shield);
2303 2310
             creature->setPassable(!unpass);
2304 2311
             creature->setLight(light);
2312
+
2305 2313
             if(emblem != -1)
2306 2314
                 creature->setEmblem(emblem);
2315
+
2316
+            if(creatureType != -1)
2317
+                creature->setType(creatureType);
2318
+
2307 2319
             if(icon != -1)
2308 2320
                 creature->setIcon(icon);
2309 2321
 

Loading…
Cancel
Save