tibia-client/src/client/creature.h

219 lines
7.8 KiB
C
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
2014-04-01 07:36:42 +02:00
* Copyright (c) 2010-2014 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 "mapview.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();
virtual void draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView = nullptr);
void internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction, LightView *lightView = nullptr);
void drawOutfit(const Rect& destRect, bool resize);
2013-02-01 15:38:17 +01:00
void drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags);
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 setOutfitColor(const Color& color, int duration);
void setLight(const Light& light) { m_light = light; }
void setSpeed(uint16 speed);
void setBaseSpeed(double baseSpeed);
void setSkull(uint8 skull);
void setShield(uint8 shield);
void setEmblem(uint8 emblem);
2014-03-12 06:39:20 +01:00
void setIcon(uint8 icon);
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);
2014-03-12 06:39:20 +01:00
void setIconTexture(const std::string& filename);
2011-12-30 15:15:23 +01:00
void setPassable(bool passable) { m_passable = passable; }
void setSpeedFormula(double speedA, double speedB, double speedC);
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; }
double getBaseSpeed() { return m_baseSpeed; }
uint8 getSkull() { return m_skull; }
uint8 getShield() { return m_shield; }
uint8 getEmblem() { return m_emblem; }
2014-03-12 06:39:20 +01:00
uint8 getIcon() { return m_icon; }
2012-07-26 08:10:28 +02:00
bool isPassable() { return m_passable; }
Point getDrawOffset();
int getStepDuration(bool ignoreDiagonal = false, Otc::Direction dir = Otc::InvalidDirection);
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(); }
float getStepTicksLeft() { return getStepDuration() - m_walkTimer.ticksElapsed(); }
ticks_t getWalkTicksElapsed() { return m_walkTimer.ticksElapsed(); }
double getSpeedFormula(Otc::SpeedFormula formula) { return m_speedFormula[formula]; }
bool hasSpeedFormula();
std::array<double, Otc::LastSpeedFormula> getSpeedFormulaArray() { return m_speedFormula; }
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);
PointF getJumpOffset() { return m_jumpOffset; }
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);
void jump(int height, int duration);
2012-01-19 05:12:53 +01:00
virtual void walk(const Position& oldPos, const Position& newPos);
virtual void stopWalk();
2012-12-04 00:26:58 +01:00
void allowAppearWalk() { m_allowAppearWalk = true; }
2011-09-01 16:49:51 +02:00
bool isWalking() { return m_walking; }
bool isRemoved() { return m_removed; }
2012-10-05 21:13:50 +02:00
bool isInvisible() { return m_outfit.getCategory() == ThingCategoryEffect && m_outfit.getAuxId() == 13; }
2014-06-02 00:04:56 +02:00
bool isDead() { return m_healthPercent <= 0; }
2012-10-05 21:13:50 +02:00
bool canBeSeen() { return !isInvisible() || isPlayer(); }
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();
virtual void onDeath();
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();
void updateOutfitColor(Color color, Color finalColor, Color delta, int duration);
void updateJump();
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;
double m_baseSpeed;
2012-02-08 22:23:15 +01:00
uint8 m_skull;
uint8 m_shield;
uint8 m_emblem;
2014-03-12 06:39:20 +01:00
uint8 m_icon;
2012-02-08 22:23:15 +01:00
TexturePtr m_skullTexture;
TexturePtr m_shieldTexture;
TexturePtr m_emblemTexture;
2014-03-12 06:39:20 +01:00
TexturePtr m_iconTexture;
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;
Color m_outfitColor;
ScheduledEventPtr m_outfitColorUpdateEvent;
Timer m_outfitColorTimer;
2011-08-29 05:05:57 +02:00
std::array<double, Otc::LastSpeedFormula> m_speedFormula;
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;
2012-12-04 00:26:58 +01:00
stdext::boolean<false> m_allowAppearWalk;
2012-07-29 12:32:44 +02:00
stdext::boolean<false> m_footStepDrawn;
2012-01-19 05:12:53 +01:00
ScheduledEventPtr m_walkUpdateEvent;
2013-01-22 20:28:44 +01:00
ScheduledEventPtr m_walkFinishAnimEvent;
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;
// jump related
float m_jumpHeight;
float m_jumpDuration;
PointF m_jumpOffset;
Timer m_jumpTimer;
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