2011-08-28 15:17:58 +02:00
|
|
|
/*
|
2012-01-02 17:58:37 +01:00
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
2011-08-28 15:17:58 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
#ifndef CREATURE_H
|
|
|
|
#define CREATURE_H
|
|
|
|
|
|
|
|
#include "thing.h"
|
2011-11-13 09:46:19 +01:00
|
|
|
#include "outfit.h"
|
2012-01-19 05:12:53 +01:00
|
|
|
#include <framework/core/declarations.h>
|
|
|
|
#include <framework/core/timer.h>
|
2011-08-29 05:05:57 +02:00
|
|
|
#include <framework/graphics/fontmanager.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
class Creature : public Thing
|
|
|
|
{
|
|
|
|
public:
|
2012-01-05 15:24:38 +01:00
|
|
|
enum {
|
2012-01-11 23:31:23 +01:00
|
|
|
SHIELD_BLINK_TICKS = 500,
|
2012-01-05 15:24:38 +01:00
|
|
|
VOLATILE_SQUARE_DURATION = 1000
|
|
|
|
};
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
Creature();
|
|
|
|
|
2012-02-02 17:37:52 +01:00
|
|
|
virtual void draw(const Point& dest, float scaleFactor, bool animate);
|
2012-02-09 04:45:19 +01:00
|
|
|
|
2012-02-08 06:13:52 +01:00
|
|
|
void internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction);
|
|
|
|
void drawOutfit(const Rect& destRect, bool resize);
|
2012-01-30 01:00:12 +01:00
|
|
|
void drawInformation(const Point& point, bool useGray, const Rect& parentRect);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-02-02 17:37:52 +01:00
|
|
|
void setId(uint32 id) { m_id = id; }
|
2011-11-13 09:46:19 +01:00
|
|
|
void setName(const std::string& name);
|
2011-08-29 05:05:57 +02:00
|
|
|
void setHealthPercent(uint8 healthPercent);
|
2011-11-06 22:45:42 +01:00
|
|
|
void setDirection(Otc::Direction direction);
|
2011-12-02 03:29:05 +01:00
|
|
|
void setOutfit(const Outfit& outfit);
|
2011-08-17 06:45:55 +02:00
|
|
|
void setLight(const Light& light) { m_light = light; }
|
|
|
|
void setSpeed(uint16 speed) { m_speed = speed; }
|
2012-01-07 00:54:17 +01:00
|
|
|
void setSkull(uint8 skull);
|
|
|
|
void setShield(uint8 shield);
|
|
|
|
void setEmblem(uint8 emblem);
|
|
|
|
void setSkullTexture(const std::string& filename);
|
2012-01-11 23:31:23 +01:00
|
|
|
void setShieldTexture(const std::string& filename, bool blink);
|
2012-01-07 00:54:17 +01:00
|
|
|
void setEmblemTexture(const std::string& filename);
|
2011-12-30 15:15:23 +01:00
|
|
|
void setPassable(bool passable) { m_passable = passable; }
|
2012-03-19 18:54:47 +01:00
|
|
|
void setRemoved(bool removed) { m_removed = removed; }
|
2012-01-05 15:24:38 +01:00
|
|
|
|
2012-02-08 03:11:57 +01:00
|
|
|
void addTimedSquare(uint8 color);
|
|
|
|
void removeTimedSquare() { m_showTimedSquare = false; }
|
2012-01-05 15:24:38 +01:00
|
|
|
|
2012-01-06 18:29:18 +01:00
|
|
|
void showStaticSquare(const Color& color) { m_showStaticSquare = true; m_staticSquareColor = color; }
|
|
|
|
void hideStaticSquare() { m_showStaticSquare = false; }
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2012-02-02 17:37:52 +01:00
|
|
|
uint32 getId() { return m_id; }
|
2011-08-15 23:02:52 +02:00
|
|
|
std::string getName() { return m_name; }
|
|
|
|
uint8 getHealthPercent() { return m_healthPercent; }
|
2011-08-28 18:02:26 +02:00
|
|
|
Otc::Direction getDirection() { return m_direction; }
|
2011-08-17 06:45:55 +02:00
|
|
|
Outfit getOutfit() { return m_outfit; }
|
|
|
|
Light getLight() { return m_light; }
|
|
|
|
uint16 getSpeed() { return m_speed; }
|
|
|
|
uint8 getSkull() { return m_skull; }
|
|
|
|
uint8 getShield() { return m_shield; }
|
|
|
|
uint8 getEmblem() { return m_emblem; }
|
2011-12-30 15:15:23 +01:00
|
|
|
bool getPassable() { return m_passable; }
|
2012-02-02 22:20:34 +01:00
|
|
|
Point getDrawOffset();
|
|
|
|
Point getWalkOffset() { return m_walkOffset; }
|
2012-01-10 01:36:18 +01:00
|
|
|
|
2012-01-11 23:31:23 +01:00
|
|
|
void updateShield();
|
2012-01-10 01:36:18 +01:00
|
|
|
|
2012-01-15 22:19:52 +01:00
|
|
|
// walk related
|
2011-12-28 12:00:09 +01:00
|
|
|
void turn(Otc::Direction direction);
|
2012-01-19 05:12:53 +01:00
|
|
|
virtual void walk(const Position& oldPos, const Position& newPos);
|
|
|
|
virtual void stopWalk();
|
2011-08-26 07:07:23 +02:00
|
|
|
|
2011-09-01 16:49:51 +02:00
|
|
|
bool isWalking() { return m_walking; }
|
2012-03-19 18:54:47 +01:00
|
|
|
bool isRemoved() { return m_removed; }
|
2011-09-01 16:49:51 +02:00
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); }
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-11-05 21:34:49 +01:00
|
|
|
protected:
|
2012-01-19 05:12:53 +01:00
|
|
|
virtual void updateWalkAnimation(int totalPixelsWalked);
|
|
|
|
virtual void updateWalkOffset(int totalPixelsWalked);
|
2012-01-30 22:28:08 +01:00
|
|
|
void updateWalkingTile();
|
2012-01-19 05:12:53 +01:00
|
|
|
virtual void nextWalkUpdate();
|
|
|
|
virtual void updateWalk();
|
|
|
|
virtual void terminateWalk();
|
2011-11-05 22:37:36 +01:00
|
|
|
|
2012-02-02 17:37:52 +01:00
|
|
|
uint32 m_id;
|
2011-08-15 16:11:24 +02:00
|
|
|
std::string m_name;
|
2011-11-13 09:46:19 +01:00
|
|
|
Size m_nameSize;
|
2011-08-15 16:11:24 +02:00
|
|
|
uint8 m_healthPercent;
|
2011-08-28 18:02:26 +02:00
|
|
|
Otc::Direction m_direction;
|
2011-08-15 16:11:24 +02:00
|
|
|
Outfit m_outfit;
|
2011-08-17 06:45:55 +02:00
|
|
|
Light m_light;
|
2012-01-19 05:12:53 +01:00
|
|
|
int m_speed;
|
2012-02-08 22:23:15 +01:00
|
|
|
uint8 m_skull;
|
|
|
|
uint8 m_shield;
|
|
|
|
uint8 m_emblem;
|
|
|
|
TexturePtr m_skullTexture;
|
|
|
|
TexturePtr m_shieldTexture;
|
|
|
|
TexturePtr m_emblemTexture;
|
|
|
|
bool m_showShieldTexture;
|
|
|
|
bool m_shieldBlink;
|
2011-12-30 15:15:23 +01:00
|
|
|
bool m_passable;
|
2012-02-08 22:23:15 +01:00
|
|
|
Color m_timedSquareColor;
|
|
|
|
Color m_staticSquareColor;
|
|
|
|
bool m_showTimedSquare;
|
|
|
|
bool m_showStaticSquare;
|
2012-03-19 18:54:47 +01:00
|
|
|
bool m_removed;
|
2011-08-26 07:07:23 +02:00
|
|
|
|
2011-08-29 05:05:57 +02:00
|
|
|
FontPtr m_informationFont;
|
|
|
|
Color m_informationColor;
|
|
|
|
|
2012-01-19 05:12:53 +01:00
|
|
|
// walk related
|
2012-02-02 17:37:52 +01:00
|
|
|
int m_walkAnimationPhase;
|
2012-01-19 05:12:53 +01:00
|
|
|
Timer m_walkTimer;
|
2012-01-30 22:28:08 +01:00
|
|
|
TilePtr m_walkingTile;
|
2012-01-19 05:12:53 +01:00
|
|
|
int m_walkInterval;
|
2012-01-19 05:50:48 +01:00
|
|
|
int m_walkAnimationInterval;
|
2012-01-19 05:12:53 +01:00
|
|
|
bool m_walking;
|
|
|
|
ScheduledEventPtr m_walkUpdateEvent;
|
2011-11-08 02:44:30 +01:00
|
|
|
Point m_walkOffset;
|
2012-01-19 05:12:53 +01:00
|
|
|
Otc::Direction m_walkTurnDirection;
|
2011-08-15 16:11:24 +02:00
|
|
|
};
|
|
|
|
|
2012-01-09 06:23:39 +01:00
|
|
|
class Npc : public Creature {
|
|
|
|
public:
|
|
|
|
NpcPtr asNpc() { return std::static_pointer_cast<Npc>(shared_from_this()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class Monster : public Creature {
|
|
|
|
public:
|
|
|
|
MonsterPtr asMonster() { return std::static_pointer_cast<Monster>(shared_from_this()); }
|
|
|
|
};
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
#endif
|