00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _TMWSERV_MONSTER_H_
00022 #define _TMWSERV_MONSTER_H_
00023
00024 #include <map>
00025 #include <vector>
00026
00027 #include "game-server/attackzone.hpp"
00028 #include "game-server/being.hpp"
00029 #include "game-server/eventlistener.hpp"
00030
00031 class ItemClass;
00032
00037 struct MonsterDrop
00038 {
00039 ItemClass *item;
00040 int probability;
00041 };
00042
00043 typedef std::vector< MonsterDrop > MonsterDrops;
00044
00048 struct MonsterAttack
00049 {
00050 unsigned id;
00051 int priority;
00052 float damageFactor;
00053 int element;
00054 int type;
00055 int preDelay;
00056 int aftDelay;
00057 AttackZone attackZone;
00058 };
00059
00060 typedef std::vector< MonsterAttack *> MonsterAttacks;
00061
00065 class MonsterClass
00066 {
00067 public:
00068 MonsterClass(int id):
00069 mID(id),
00070 mAttributes(BASE_ATTR_NB, 0),
00071 mSpeed(1),
00072 mSize(16),
00073 mExp(-1),
00074 mAggressive(false),
00075 mTrackRange(1),
00076 mStrollRange(0),
00077 mMutation(0),
00078 mAttackDistance(0)
00079 {}
00080
00084 int getType() const
00085 { return mID; }
00086
00091 void setDrops(const MonsterDrops &v)
00092 { mDrops = v; }
00093
00097 void setAttribute(size_t attribute, int value)
00098 { mAttributes.at(attribute) = value; }
00099
00103 int getAttribute(size_t attribute) const
00104 { return mAttributes.at(attribute); }
00105
00107 void setSpeed(int speed) { mSpeed = speed; }
00108
00110 int getSpeed() const { return mSpeed; }
00111
00113 void setSize(int size) { mSize = size; }
00114
00116 int getSize() const { return mSize; }
00117
00119 void setExp(int exp) { mExp = exp; }
00120
00122 int getExp() const { return mExp; }
00123
00125 void setAggressive(bool aggressive) { mAggressive = aggressive; }
00126
00128 bool isAggressive() const { return mAggressive; }
00129
00131 void setTrackRange(unsigned range){ mTrackRange = range; }
00132
00136 unsigned getTrackRange() const { return mTrackRange; }
00137
00139 void setStrollRange(unsigned range) { mStrollRange = range; }
00140
00144 unsigned getStrollRange() const { return mStrollRange; }
00145
00147 void setMutation(unsigned factor) { mMutation = factor; }
00148
00150 unsigned getMutation() const { return mMutation; }
00151
00153 void setAttackDistance(unsigned distance)
00154 { mAttackDistance = distance; }
00155
00157 unsigned getAttackDistance() const { return mAttackDistance; }
00158
00160 void addAttack(MonsterAttack *type) { mAttacks.push_back(type); }
00161
00163 const MonsterAttacks &getAttacks() const { return mAttacks; }
00164
00168 ItemClass *getRandomDrop() const;
00169
00170 private:
00171 unsigned short mID;
00172 MonsterDrops mDrops;
00173 std::vector<int> mAttributes;
00174 int mSpeed;
00175 int mSize;
00176 int mExp;
00177
00178 bool mAggressive;
00179 unsigned mTrackRange;
00180 unsigned mStrollRange;
00181 unsigned mMutation;
00182 unsigned mAttackDistance;
00183 MonsterAttacks mAttacks;
00184 };
00185
00190 struct AttackPosition
00191 {
00192 AttackPosition(int posX, int posY, Direction dir):
00193 x(posX),
00194 y(posY),
00195 direction(dir)
00196 {};
00197
00198 int x;
00199 int y;
00200 Direction direction;
00201 };
00202
00206 class Monster : public Being
00207 {
00208 public:
00210 static const int KILLSTEAL_PROTECTION_TIME = 100;
00211
00215 Monster(MonsterClass *);
00216
00220 ~Monster();
00221
00225 MonsterClass *getSpecy()
00226 { return mSpecy; }
00227
00231 void update();
00232
00236 void perform();
00237
00241 virtual int getAttackType() const
00242 { return mCurrentAttack->id; }
00243
00247 void died();
00248
00252 virtual int damage(Actor *source, const Damage &damage);
00253
00257 void forgetTarget(Thing *being);
00258
00262 virtual unsigned char getWalkMask() const
00263 {
00264
00265 return 0x83;
00266 }
00267
00268 protected:
00272 virtual Map::BlockType getBlockType() const
00273 { return Map::BLOCKTYPE_MONSTER; }
00274
00275 private:
00276 int calculatePositionPriority(Point position, int targetPriority);
00277
00278 MonsterClass *mSpecy;
00279
00281 int mCountDown;
00282
00284 std::map<Being *, int> mAnger;
00285
00287 EventListener mTargetListener;
00288
00292 Character *mOwner;
00293
00298 int mOwnerTimer;
00299
00301 std::map<Character *, std::set <size_t> > mExpReceivers;
00302
00307 std::set<Character *> mLegalExpReceivers;
00308
00310 int mAttackTime;
00311
00313 MonsterAttack *mCurrentAttack;
00314
00318 std::list<AttackPosition> mAttackPositions;
00319
00320 friend struct MonsterTargetEventDispatch;
00321 };
00322
00323 #endif // _TMWSERV_MONSTER_H_