tibia-client/src/otclient/core/creature.cpp

96 lines
2.9 KiB
C++
Raw Normal View History

2011-08-24 05:58:23 +02:00
#include "creature.h"
2011-08-15 21:15:49 +02:00
#include "datmanager.h"
2011-08-15 16:11:24 +02:00
#include <framework/graphics/graphics.h>
#include <framework/graphics/fontmanager.h>
2011-08-15 16:11:24 +02:00
2011-08-15 23:02:52 +02:00
Creature::Creature() : Thing(THING_CREATURE)
2011-08-15 16:11:24 +02:00
{
2011-08-15 23:02:52 +02:00
m_healthPercent = 0;
m_direction = DIRECTION_SOUTH;
2011-08-15 16:11:24 +02:00
}
void Creature::draw(int x, int y)
{
int anim = 0;
2011-08-19 14:26:26 +02:00
const ThingAttributes& attributes = getAttributes();
2011-08-24 05:58:23 +02:00
for(int ydiv = 0; ydiv < attributes.ydiv; ydiv++) {
// continue if we dont have this addon.
if(ydiv > 0 && !(m_outfit.addons & (1 << (ydiv-1))))
continue;
// draw white item
internalDraw(x, y, 0, m_direction, ydiv, 0, anim);
// draw mask if exists
if(attributes.blendframes > 1) {
g_graphics.bindBlendFunc(BLEND_COLORIZING);
2011-08-19 14:26:26 +02:00
2011-08-24 05:58:23 +02:00
for(int mask = 0; mask < 4; ++mask) {
int outfitColorId = 0;
if(mask == SpriteMaskYellow)
outfitColorId = m_outfit.head;
else if(mask == SpriteMaskRed)
outfitColorId = m_outfit.body;
else if(mask == SpriteMaskGreen)
outfitColorId = m_outfit.legs;
else if(mask == SpriteMaskBlue)
outfitColorId = m_outfit.feet;
g_graphics.bindColor(OutfitColors[outfitColorId]);
internalDraw(x, y, 1, m_direction, ydiv, 0, anim, (SpriteMask)mask);
}
g_graphics.bindBlendFunc(BLEND_NORMAL);
g_graphics.bindColor(Color::white);
}
2011-08-19 14:26:26 +02:00
}
}
2011-08-19 15:23:35 +02:00
void Creature::drawInformation(int x, int y, bool useGray)
{
Color fillColor = Color(96, 96, 96);
if(!useGray) {
// health bar
fillColor = Color::black;
if(m_healthPercent > 60 && m_healthPercent <= 100) {
fillColor.setRed(0.0f);
fillColor.setGreen(0.75f);
} else if(m_healthPercent > 30 && m_healthPercent <= 60) {
fillColor.setRed(0.75f);
fillColor.setGreen(0.75f);
} else if(m_healthPercent > 10 && m_healthPercent <= 30) {
fillColor.setRed(0.75f);
fillColor.setGreen(0.00f);
} else if(m_healthPercent > 0 && m_healthPercent <= 10) {
fillColor.setRed(0.25f);
fillColor.setGreen(0.00f);
}
2011-08-19 15:23:35 +02:00
}
2011-08-22 03:01:59 +02:00
Rect backgroundRect = Rect(x-(14.5), y, 27, 4);
Rect healthRect = backgroundRect.expanded(-1);
healthRect.setWidth((m_healthPercent/100.0)*25);
2011-08-20 22:30:41 +02:00
g_graphics.bindColor(Color::black);
g_graphics.drawFilledRect(backgroundRect);
2011-08-20 22:30:41 +02:00
g_graphics.bindColor(fillColor);
g_graphics.drawFilledRect(healthRect);
2011-08-20 22:30:41 +02:00
// restore white color
g_graphics.bindColor(Color::white);
// name
FontPtr font = g_fonts.getFont("tibia-12px-rounded");
2011-08-22 03:12:37 +02:00
font->renderText(m_name, Rect(x-100, y-15, 200, 15), AlignTopCenter, fillColor);
2011-08-15 16:11:24 +02:00
}
2011-08-15 23:02:52 +02:00
const ThingAttributes& Creature::getAttributes()
{
return g_dat.getCreatureAttributes(m_outfit.type);
}