134 lines
2.9 KiB
C++
134 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <td/game/Towers.h>
|
|
|
|
#include <td/Maths.h>
|
|
#include <td/Types.h>
|
|
#include <td/game/Team.h>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include <sp/protocol/ConcreteMessage.h>
|
|
#include <sp/common/GenericHandler.h>
|
|
#include <sp/protocol/MessageFactory.h>
|
|
|
|
namespace td {
|
|
using Vec2fp = Vec2<FpFloat>;
|
|
|
|
namespace game {
|
|
|
|
|
|
struct WalkableTile;
|
|
|
|
enum class EffectType : std::uint8_t {
|
|
Slowness = 0,
|
|
Stun,
|
|
Fire,
|
|
Poison,
|
|
Heal,
|
|
};
|
|
|
|
enum class MobType : std::uint8_t {
|
|
Zombie = 0,
|
|
Spider,
|
|
Skeleton,
|
|
Pigman,
|
|
Creeper,
|
|
Silverfish,
|
|
Blaze,
|
|
Witch,
|
|
Slime,
|
|
Giant,
|
|
|
|
MOB_COUNT
|
|
};
|
|
|
|
typedef std::uint32_t MobID;
|
|
typedef std::uint8_t MobLevel;
|
|
typedef std::vector<TowerType> TowerImmunities;
|
|
typedef std::vector<EffectType> EffectImmunities;
|
|
|
|
struct MobStats {
|
|
float m_Damage;
|
|
float m_Speed;
|
|
Vec2f m_Size;
|
|
std::uint16_t m_MoneyCost;
|
|
std::uint16_t m_ExpCost;
|
|
std::uint16_t m_MaxLife;
|
|
std::uint16_t m_ExpReward;
|
|
};
|
|
|
|
struct EffectDuration {
|
|
EffectType type;
|
|
float duration; // in seconds
|
|
Tower* tower; // the tower that gived the effect
|
|
};
|
|
|
|
const MobStats* GetMobStats(MobType type, std::uint8_t level);
|
|
const TowerImmunities& GetMobTowerImmunities(MobType type, std::uint8_t level);
|
|
const EffectImmunities& GetMobEffectImmunities(MobType type, std::uint8_t level);
|
|
|
|
class MobHandler;
|
|
|
|
struct MobData {};
|
|
|
|
class Mob : public sp::MessageBase<MobType, MobHandler> {
|
|
public:
|
|
MobID m_ID;
|
|
MobLevel m_Level;
|
|
PlayerID m_Sender;
|
|
float m_Health;
|
|
Vec2fp m_Position;
|
|
Direction m_Direction;
|
|
std::vector<EffectDuration> m_Effects;
|
|
const Tower* m_LastDamage; // the last tower that damaged the mob
|
|
float m_HitCooldown;
|
|
TeamCastle* m_CastleTarget;
|
|
// utils::CooldownTimer m_AttackTimer;
|
|
|
|
MobPtr m_Next;
|
|
|
|
Mob() {}
|
|
|
|
Mob& operator=(const Mob& a_Other) = default;
|
|
};
|
|
|
|
template <MobType ID>
|
|
using ConcreteMob = sp::ConcreteMessage<MobData, Mob, ID>;
|
|
|
|
using Zombie = ConcreteMob<MobType::Zombie>;
|
|
using Spider = ConcreteMob<MobType::Spider>;
|
|
using Skeleton = ConcreteMob<MobType::Skeleton>;
|
|
using PigMan = ConcreteMob<MobType::Pigman>;
|
|
using Creeper = ConcreteMob<MobType::Creeper>;
|
|
using Silverfish = ConcreteMob<MobType::Silverfish>;
|
|
using Blaze = ConcreteMob<MobType::Blaze>;
|
|
using Witch = ConcreteMob<MobType::Witch>;
|
|
using Slime = ConcreteMob<MobType::Slime>;
|
|
using Giant = ConcreteMob<MobType::Giant>;
|
|
|
|
using AllMobs = std::tuple<Zombie, Spider, Skeleton, PigMan, Creeper, Silverfish, Blaze, Witch, Slime, Giant>;
|
|
|
|
class MobHandler : public sp::GenericHandler<AllMobs> {};
|
|
|
|
using MobFactory = sp::MessageFactory<Mob, AllMobs>;
|
|
|
|
class MobListener {
|
|
public:
|
|
virtual void OnMobSpawn(Mob* mob) {
|
|
MobHandler h;
|
|
}
|
|
virtual void OnMobDie(Mob* mob) {}
|
|
|
|
virtual void OnMobDamage(Mob* target, float damage, Tower* damager) {}
|
|
|
|
virtual void OnMobTouchCastle(Mob* damager, TeamCastle* enemyCastle) {}
|
|
virtual void OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {}
|
|
};
|
|
|
|
// typedef utils::ObjectNotifier<MobListener> MobNotifier;
|
|
|
|
} // namespace game
|
|
} // namespace td
|