tibia-client/src/otclient/creature.h

181 lines
6.0 KiB
C
Raw Normal View History

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"
#include "tile.h"
#include <framework/core/scheduledevent.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>
#include <framework/graphics/cachedtext.h>
2011-08-15 16:11:24 +02:00
2012-06-22 05:14:13 +02:00
// @bindclass
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-08-20 00:30:49 +02:00
virtual void draw(const Point& dest, float scaleFactor, bool animate);
void internalDrawOutfit(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
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);
void setLight(const Light& light) { m_light = light; }
void setSpeed(uint16 speed);
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);
void setEmblemTexture(const std::string& filename);
2011-12-30 15:15:23 +01:00
void setPassable(bool passable) { m_passable = passable; }
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
uint32 getId() { return m_id; }
2011-08-15 23:02:52 +02:00
std::string getName() { return m_name; }
uint8 getHealthPercent() { return m_healthPercent; }
Otc::Direction getDirection() { return m_direction; }
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; }
2012-07-26 08:10:28 +02:00
bool isPassable() { return m_passable; }
Point getDrawOffset();
int getStepDuration();
Point getWalkOffset() { return m_walkOffset; }
2012-08-22 02:27:48 +02:00
Position getLastStepFromPosition() { return m_lastStepFromPosition; }
Position getLastStepToPosition() { return m_lastStepToPosition; }
float getStepProgress() { return m_walkTimer.ticksElapsed() / getStepDuration(); }
2012-08-17 23:36:53 +02:00
virtual Point getDisplacement();
virtual int getDisplacementX();
virtual int getDisplacementY();
virtual int getExactSize(int layer = 0, int xPattern = 0, int yPattern = 0, int zPattern = 0, int animationPhase = 0);
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
// 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-09-01 16:49:51 +02:00
bool isWalking() { return m_walking; }
bool isRemoved() { return m_removed; }
2011-09-01 16:49:51 +02:00
2012-06-05 17:36:27 +02:00
bool isCreature() { return true; }
2011-08-15 16:11:24 +02:00
2012-07-19 23:22:52 +02:00
const ThingTypePtr& getThingType();
ThingType *rawGetThingType();
virtual void onPositionChange(const Position& newPos, const Position& oldPos);
virtual void onAppear();
virtual void onDisappear();
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);
void updateWalkingTile();
2012-01-19 05:12:53 +01:00
virtual void nextWalkUpdate();
virtual void updateWalk();
virtual void terminateWalk();
uint32 m_id;
2011-08-15 16:11:24 +02:00
std::string m_name;
uint8 m_healthPercent;
Otc::Direction m_direction;
2011-08-15 16:11:24 +02:00
Outfit m_outfit;
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;
2012-07-29 12:32:44 +02:00
stdext::boolean<true> m_showShieldTexture;
stdext::boolean<false> m_shieldBlink;
stdext::boolean<false> m_passable;
2012-02-08 22:23:15 +01:00
Color m_timedSquareColor;
Color m_staticSquareColor;
2012-07-29 12:32:44 +02:00
stdext::boolean<false> m_showTimedSquare;
stdext::boolean<false> m_showStaticSquare;
stdext::boolean<true> m_removed;
CachedText m_nameCache;
2011-08-29 05:05:57 +02:00
Color m_informationColor;
2012-01-19 05:12:53 +01:00
// walk related
int m_walkAnimationPhase;
int m_walkedPixels;
uint m_footStep;
2012-01-19 05:12:53 +01:00
Timer m_walkTimer;
Timer m_footTimer;
TilePtr m_walkingTile;
2012-07-29 12:32:44 +02:00
stdext::boolean<false> m_walking;
stdext::boolean<false> m_footStepDrawn;
2012-01-19 05:12:53 +01:00
ScheduledEventPtr m_walkUpdateEvent;
EventPtr m_disappearEvent;
2011-11-08 02:44:30 +01:00
Point m_walkOffset;
2012-01-19 05:12:53 +01:00
Otc::Direction m_walkTurnDirection;
Otc::Direction m_lastStepDirection;
2012-08-22 02:27:48 +02:00
Position m_lastStepFromPosition;
Position m_lastStepToPosition;
Position m_oldPosition;
2011-08-15 16:11:24 +02:00
};
2012-06-22 05:14:13 +02:00
// @bindclass
class Npc : public Creature
{
2012-01-09 06:23:39 +01:00
public:
2012-06-05 17:36:27 +02:00
bool isNpc() { return true; }
2012-01-09 06:23:39 +01:00
};
2012-06-22 05:14:13 +02:00
// @bindclass
class Monster : public Creature
{
2012-01-09 06:23:39 +01:00
public:
2012-06-05 17:36:27 +02:00
bool isMonster() { return true; }
2012-01-09 06:23:39 +01:00
};
2011-08-15 23:02:52 +02:00
#endif