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-07-29 05:34:40 +02:00
|
|
|
#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>
|
2012-06-09 02:40:22 +02:00
|
|
|
#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
|
|
|
|
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-07-26 13:18:49 +02:00
|
|
|
void internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction);
|
2012-02-08 06:13:52 +01:00
|
|
|
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; }
|
2012-08-02 09:58:49 +02:00
|
|
|
void setSpeed(uint16 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-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; }
|
2012-07-26 08:10:28 +02:00
|
|
|
bool isPassable() { return m_passable; }
|
2012-02-02 22:20:34 +01:00
|
|
|
Point getDrawOffset();
|
2012-08-02 09:58:49 +02:00
|
|
|
int getStepDuration();
|
2012-02-02 22:20:34 +01:00
|
|
|
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();
|
2012-09-01 01:33:51 +02:00
|
|
|
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
|
|
|
|
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
|
|
|
|
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();
|
2012-07-15 15:23:13 +02:00
|
|
|
|
2012-08-03 07:05:09 +02:00
|
|
|
virtual void onPositionChange(const Position& newPos, const Position& oldPos);
|
2012-08-02 09:58:49 +02:00
|
|
|
virtual void onAppear();
|
|
|
|
virtual void onDisappear();
|
2012-08-01 09:49:09 +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;
|
|
|
|
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;
|
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;
|
2012-08-02 09:58:49 +02:00
|
|
|
stdext::boolean<true> m_removed;
|
2012-06-09 02:40:22 +02:00
|
|
|
CachedText m_nameCache;
|
2011-08-29 05:05:57 +02:00
|
|
|
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-08-02 09:58:49 +02:00
|
|
|
int m_walkedPixels;
|
2012-06-12 18:50:43 +02:00
|
|
|
uint m_footStep;
|
2012-01-19 05:12:53 +01:00
|
|
|
Timer m_walkTimer;
|
2012-06-11 21:03:36 +02:00
|
|
|
Timer m_footTimer;
|
2012-01-30 22:28:08 +01:00
|
|
|
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;
|
2012-08-02 09:58:49 +02:00
|
|
|
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;
|
2012-08-02 09:58:49 +02:00
|
|
|
Otc::Direction m_lastStepDirection;
|
2012-08-22 02:27:48 +02:00
|
|
|
Position m_lastStepFromPosition;
|
|
|
|
Position m_lastStepToPosition;
|
2012-08-02 09:58:49 +02:00
|
|
|
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
|