/* EQ2Emulator: Everquest II Server Emulator Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net) This file is part of EQ2Emulator. EQ2Emulator is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. EQ2Emulator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EQ2Emulator. If not, see . */ #ifndef __NPC_AI_H__ #define __NPC_AI_H__ #include "NPC.h" #include #include using namespace std; class Brain { public: Brain(NPC* npc); virtual ~Brain(); /// The main loop for the brain. This will do all the AI work virtual void Think(); /* Timer related functions */ /// Gets the time between calls to Think() /// Time in miliseconds between calls to Think() int16 Tick() { return m_tick; } /// Sets the time between calls to Think() /// Time in miliseconds void SetTick(int16 time) { m_tick = time; } /// Gets the timestamp of the last call to Think() /// Timestamp of the last call to Think() int32 LastTick() { return m_lastTick; } /// Sets the last tick to the given time /// The time to set the last tick to void SetLastTick(int32 time) { m_lastTick = time; } /* Hate related functions */ /// Gets the amount of hate this npc has towards the given entity /// The entity to check /// The amount of hate towards the given entity sint32 GetHate(Entity* entity); /// Add hate for the given entity to this NPC /// The entity we are adding to this NPC's hate list /// The amount of hate to add virtual void AddHate(Entity* entity, sint32 hate); /// Completely clears the hate list for this npc void ClearHate(); /// Removes the given entity from this NPC's hate list /// Entity to remove from this NPC's hate list void ClearHate(Entity* entity); /// Get the entity this NPC hates the most /// The entity this NPC hates the most Entity* GetMostHated(); /// Gets a percentage of hate owned by the given entity /// Entity to get the percentage for /// Percentage of hate as a sint8 sint8 GetHatePercentage(Entity* entity); ///Gets a list of all the entities in the hate list vector* GetHateList(); /* Combat related functions */ /// /// /// virtual bool ProcessSpell(Entity* target, float distance); /// /// True if a buff starts casting bool CheckBuffs(); /// Has the NPC make a melee attack /// The target to attack /// The current distance from the target void ProcessMelee(Entity* target, float distance); /* Encounter related functions */ /// Adds the given entity and its group and raid members to the encounter list /// Entity we are adding to the encounter list void AddToEncounter(Entity* entity); /// Checks to see if the given entity can loot the corpse /// Entity trying to loot /// True if the entity can loot bool CheckLootAllowed(Entity* entity); /// Gets the size of the encounter list /// The size of the list as an int8 int8 GetEncounterSize(); /// Clears the encounter list void ClearEncounter(); /// Gets a copy of the encounter list /// A copy of the encounter list as a vector* vector* GetEncounter(); /// Checks to see if a player is in the encounter /// True if the encounter list contains a player bool PlayerInEncounter() { return m_playerInEncounter; } /* Helper functions*/ /// Gets the NPC this brain controls /// The NPC this brain controls NPC* GetBody() { return m_body; } /// Checks to see if the NPC can cast /// True if the NPC can cast bool HasRecovered(); /// Tells the NPC to move closer to the given target /// The target to move closer to void MoveCloser(Entity* target); protected: // m_body = the npc this brain controls NPC* m_body; // m_spellRecovery = time stamp for when the npc can cast again int32 m_spellRecovery; private: // MHateList = mutex to lock and unlock the hate list Mutex MHateList; // m_hatelist = the list that stores all the hate, // entity is the entity this npc hates and the int32 is the value for how much we hate the entity map m_hatelist; // m_lastTick = the last time we ran this brain int32 m_lastTick; // m_tick = the amount of time between Think() calls in milliseconds int16 m_tick; // m_encounter = list of players (entities) that will get a reward (xp/loot) for killing this npc vector m_encounter; map m_encounter_playerlist; // MEncounter = mutex to lock and unlock the encounter list Mutex MEncounter; //m_playerInEncounter = true if a player is added to the encounter bool m_playerInEncounter; }; // Extension of the default brain for combat pets class CombatPetBrain : public Brain { public: CombatPetBrain(NPC* body); virtual ~CombatPetBrain(); void Think(); }; class NonCombatPetBrain : public Brain { public: NonCombatPetBrain(NPC* body); virtual ~NonCombatPetBrain(); void Think(); }; class BlankBrain : public Brain { public: BlankBrain(NPC* body); virtual ~BlankBrain(); void Think(); }; class LuaBrain : public Brain { public: LuaBrain(NPC* body); virtual ~LuaBrain(); void Think(); }; class DumbFirePetBrain : public Brain { public: DumbFirePetBrain(NPC* body, Entity* target, int32 expire_time); virtual ~DumbFirePetBrain(); void Think(); void AddHate(Entity* entity, sint32 hate); private: int32 m_expireTime; }; #endif