Planeshift
npcmanager.h
Go to the documentation of this file.
1 /*
2 * npcmanager.h by Keith Fulton <keith@paqrat.com>
3 *
4 * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef __NPCMANAGER_H_
21 #define __NPCMANAGER_H_
22 //=============================================================================
23 // Crystal Space Includes
24 //=============================================================================
25 #include <csutil/ref.h>
26 
27 //=============================================================================
28 // Project Includes
29 //=============================================================================
30 #include "net/netbase.h" // PublishVector class
31 #include "net/npcmessages.h"
32 
33 #include "bulkobjects/psskills.h"
34 #include "cachemanager.h"
35 
36 //=============================================================================
37 // Local Includes
38 //=============================================================================
39 #include "msgmanager.h" // Subscriber class
40 
41 #define OWNER_ALL 0xFFFFFFFF
42 
43 
44 class Client;
45 class psDatabase;
48 class EntityManager;
49 class EventManager;
50 class gemObject;
51 class gemActor;
52 class gemNPC;
53 class PetOwnerSession;
54 class psPathPoint;
55 class Waypoint;
56 class psPath;
57 class Location;
58 class LocationType;
59 
60 class NPCManager : public MessageManager<NPCManager>
61 {
62 public:
64  psDatabase* db,
65  EventManager* evtmgr,
66  GEMSupervisor* gemsupervisor,
67  CacheManager* cachemanager,
68  EntityManager* entitymanager);
69 
70  virtual ~NPCManager();
71 
73  bool Initialize();
74 
76  void SendNPCList(Client* client);
77 
79  void SendAllNPCStats(Client* client);
80 
82  void Disconnect(Client* client);
83 
85  void AddEntity(gemObject* obj);
86 
88  void RemoveEntity(MsgEntry* me);
89 
91  void UpdateWorldPositions();
92 
94  void QueueAssessPerception(EID entityEID, EID targetEID, const csString &physicalAssessmentPerception,
95  const csString &physicalAssessmentDifferencePerception,
96  const csString &magicalAssessmentPerception,
97  const csString &magicalAssessmentDifferencePerception,
98  const csString &overallAssessmentPerception,
99  const csString &overallAssessmentDifferencePerception);
100 
101 
103  void QueueTalkPerception(gemActor* speaker, gemNPC* target);
104 
106  void QueueAttackPerception(gemActor* attacker,gemNPC* target);
107 
109  void QueueDamagePerception(gemActor* attacker,gemNPC* target,float dmg);
110 
112  void QueueDeathPerception(gemObject* who);
113 
115  void QueueSpellPerception(gemActor* caster, gemObject* target,const char* spell_cat, uint32_t spell_category, float severity);
116 
118  void QueueStatDR(gemActor* actor, unsigned int statsDirtyFlags);
119 
121  void QueueEnemyPerception(psNPCCommandsMessage::PerceptionType type, gemActor* npc, gemActor* player, float relative_faction);
122 
125 
127  void QueueInventoryPerception(gemActor* owner, psItem* itemdata, bool inserted);
128 
130  void QueueFlagPerception(gemActor* owner);
131 
133  void QueueNPCCmdPerception(gemActor* owner, const csString &cmd);
134 
136  void QueueTransferPerception(gemActor* owner, psItem* itemdata, csString target);
137 
139  void QueueSpawnedPerception(gemNPC* spawned, gemNPC* spawner, const csString &tribeMemberType);
140 
142  void QueueTeleportPerception(gemNPC* npc, csVector3 &pos, float yrot, iSector* sector, InstanceID instance);
143 
145  void QueueInfoRequestPerception(gemNPC* npc, Client* client, const char* infoRequestSubCmd);
146 
148  void QueueFailedToAttackPerception(gemNPC* attacker, gemObject* target);
149 
151  void QueuePerceptPerception(gemNPC* npc, csString perception, csString type);
152 
154  void QueueSpokenToPerception(gemNPC* npc, bool spokenTo);
155 
157  void QueueChangeOwnerPerception(gemNPC* npc, EID owner);
158 
165  void ChangeNPCBrain(gemNPC* npc, Client* client, const char* brainName);
166 
173  void DebugNPC(gemNPC* npc, Client* client, uint8_t debugLevel);
174 
181  void DebugTribe(gemNPC* npc, Client* client, uint8_t debugLevel);
182 
184  void SendAllCommands(bool createNewTick);
185 
187  csArray<PublishDestination> &GetSuperClients()
188  {
189  return superclients;
190  }
191 
193  void WorkDoneNotify(EID npcEID, csString reward, csString nick);
194 
196  void NewNPCNotify(PID player_id, PID master_id, PID owner_id);
197 
199  void DeletedNPCNotify(PID player_id);
200 
202  void ControlNPC(gemNPC* npc);
203 
208  void CheckWorkLocation(gemNPC* npc, Location* location);
209 
211  PetOwnerSession* CreatePetOwnerSession(gemActor*, psCharacter*);
212 
214  void DismissPet(gemNPC* pet, Client* owner);
215 
217  void RemovePetOwnerSession(PetOwnerSession* session);
218 
220  void UpdatePetTime();
221 
228  {
229  return (PSSKILL)petSkill->getValueAsInt();
230  }
231 
237  void LocationAdjusted(Location* location);
238 
244  void LocationCreated(Location* location);
245 
251  void LocationInserted(Location* location);
252 
256  void LocationRadius(Location* location);
257 
261  void LocationTypeAdd(LocationType* locationType);
262 
266  void LocationTypeRemove(const csString &locationTypeName);
267 
271  void WaypointAdjusted(Waypoint* wp);
272 
276  void PathPointAdjusted(psPathPoint* point);
277 
282  void WaypointAddAlias(const Waypoint* wp, const WaypointAlias* alias);
283 
288  void WaypointAliasRotation(const Waypoint* wp, const WaypointAlias* alias);
289 
294  void WaypointRemoveAlias(const Waypoint* wp, const csString &alias);
295 
301  void WaypointSetFlag(const Waypoint* wp, const csString &flag, bool enable);
302 
308  void PathSetFlag(const psPath* path, const csString &flag, bool enable);
309 
313  void WaypointRadius(const Waypoint* waypoint);
314 
318  void WaypointRename(const Waypoint* waypoint);
319 
323  void PathRename(const psPath* path);
324 
328  void WaypointCreate(const Waypoint* waypoint);
329 
333  void PathCreate(const psPath* path);
334 
339  void AddPoint(const psPath* path, const psPathPoint* point);
340 
345  void RemovePoint(const psPath* path, int pointId);
346 
352 
353 protected:
354 
356  void HandleAuthentRequest(MsgEntry* me,Client* client);
357 
359  void HandleCommandList(MsgEntry* me,Client* client);
360 
362  void HandleDamageEvent(MsgEntry* me,Client* client);
363 
365  void HandleDeathEvent(MsgEntry* me,Client* client);
366 
367  void HandleNPCReady(MsgEntry* me,Client* client);
368 
370  void HandleSimpleRenderMesh(MsgEntry* me, Client* client);
371 
373  void SendMapList(Client* client);
374 
376  void SendRaces(Client* client);
377 
379  bool CanPetHearYou(int clientnum, Client* owner, gemNPC* pet, const char* type);
380 
382  bool WillPetReact(int clientnum, Client* owner, gemNPC* pet, const char* type, int level);
383 
385  void HandlePetCommand(MsgEntry* me, Client* client);
386 
388  void HandlePetSkill(MsgEntry* me, Client* client);
389  void SendPetSkillList(Client* client, bool forceOpen = true, PSSKILL focus = PSSKILL_NONE);
390 
391 public:
395  void PetHasBeenKilled(gemNPC* pet);
396 
400  void PetInfo(Client* client, psCharacter* pet);
401 
402 protected:
404  void HandleConsoleCommand(MsgEntry* me,Client* client);
405 
407  void PrepareMessage();
408 
416  void CheckSendPerceptionQueue(size_t expectedAddSize);
417 
419  csArray<PublishDestination> superclients;
420 
430 
431  csHash<PetOwnerSession*, PID> OwnerPetList;
432 
435 
438 
444 };
445 
446 #endif
void WaypointAddAlias(const Waypoint *wp, const WaypointAlias *alias)
Notify superclients that a alias has been added to a waypoint.
bool CanPetHearYou(int clientnum, Client *owner, gemNPC *pet, const char *type)
Check if a pet is within range to react to commands.
void QueueAssessPerception(EID entityEID, EID targetEID, const csString &physicalAssessmentPerception, const csString &physicalAssessmentDifferencePerception, const csString &magicalAssessmentPerception, const csString &magicalAssessmentDifferencePerception, const csString &overallAssessmentPerception, const csString &overallAssessmentDifferencePerception)
Let the superclient know the result of an assessment.
void QueueEnemyPerception(psNPCCommandsMessage::PerceptionType type, gemActor *npc, gemActor *player, float relative_faction)
Let the superclient know that one enemy is close.
void WaypointRename(const Waypoint *waypoint)
Notify superclients that a waypoint has been renamed.
void QueueFailedToAttackPerception(gemNPC *attacker, gemObject *target)
Let the superclient know that an attempt to attack failed.
MathScript * petTrainingLockoutTime
Definition: npcmanager.h:443
uint32 InstanceID
Definition: psconst.h:64
void PathSetFlag(const psPath *path, const csString &flag, bool enable)
Notify superclients that a flag has been changed for a path.
void PetHasBeenKilled(gemNPC *pet)
Notification that an pet has been killed. Upon notification of a killed pet this function will start ...
void HandlePetSkill(MsgEntry *me, Client *client)
Handle network message with pet skills.
Manages CEL entities on the server.
Definition: entitymanager.h:77
void QueueInventoryPerception(gemActor *owner, psItem *itemdata, bool inserted)
Let the superclient know that one of its npcs has a change in inventory.
PSSKILL GetPetSkill()
Returns the skill used to handle pet operations.
Definition: npcmanager.h:227
PetOwnerSession * CreatePetOwnerSession(gemActor *, psCharacter *)
Add Session for pets.
Class to hold information regarding aliases for waypoints.
Definition: waypoint.h:38
csArray< PublishDestination > superclients
List of active superclients.
Definition: npcmanager.h:419
void CheckWorkLocation(gemNPC *npc, Location *location)
Check work location.
void CheckSendPerceptionQueue(size_t expectedAddSize)
Check if the perception queue is going to overflow with the next perception.
void DismissPet(gemNPC *pet, Client *owner)
Dismiss active (summoned) pet.
MathScript * petDismissLockoutTime
Definition: npcmanager.h:440
void PetInfo(Client *client, psCharacter *pet)
Provide response for the /info commands for GMs for pets.
EntityManager * entityManager
Definition: npcmanager.h:425
void WaypointAliasRotation(const Waypoint *wp, const WaypointAlias *alias)
Notify superclients that a alias has been added to a waypoint.
void QueueDamagePerception(gemActor *attacker, gemNPC *target, float dmg)
Let the superclient know that a player has taken HP from one of its npcs.
void DebugNPC(gemNPC *npc, Client *client, uint8_t debugLevel)
Requests the npcclient to change the debug level of this npc.
void WaypointAdjusted(Waypoint *wp)
Notify superclients that a waypoint where adjusted.
A MathScript is a mini-program to run.
Definition: mathscript.h:442
Definition: pspath.h:152
void QueueTransferPerception(gemActor *owner, psItem *itemdata, csString target)
Let the superclient know that a transfer has happend.
NPCManager(ClientConnectionSet *pCCS, psDatabase *db, EventManager *evtmgr, GEMSupervisor *gemsupervisor, CacheManager *cachemanager, EntityManager *entitymanager)
void LocationTypeAdd(LocationType *locationType)
Notify superclients that a location type has been added.
This class rappresents an option tree which comes from the server_options table.
Definition: cachemanager.h:147
void HandlePetCommand(MsgEntry *me, Client *client)
Handle network message with pet directives.
void WorkDoneNotify(EID npcEID, csString reward, csString nick)
Inform the npc about the reward granted after a work done.
virtual ~NPCManager()
void QueueOwnerCmdPerception(gemActor *owner, gemNPC *pet, psPETCommandMessage::PetCommand_t command)
Let the superclient know that one of its npcs has been commanded to stay.
MathScript * GetPetDismissLockoutTime()
Definition: npcmanager.h:348
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
void SendAllCommands(bool createNewTick)
Send all queued commands and perceptions to active superclients and reset the queues.
bool WillPetReact(int clientnum, Client *owner, gemNPC *pet, const char *type, int level)
Check if your pet will reacto to your command based on skills.
psNPCCommandsMessage * outbound
Definition: npcmanager.h:427
void QueueNPCCmdPerception(gemActor *owner, const csString &cmd)
Let the superclient know that a response has commanded a npc.
void DebugTribe(gemNPC *npc, Client *client, uint8_t debugLevel)
Requests the npcclient to change the debug level of this npc.
MathScript * GetMaxPetTime()
Definition: npcmanager.h:349
void WaypointRemoveAlias(const Waypoint *wp, const csString &alias)
Notify superclients that a alias has been removed from a waypoint.
MathScript * GetPetTrainingLockoutTime()
Definition: npcmanager.h:351
int cmd_count
Definition: npcmanager.h:428
void WaypointRadius(const Waypoint *waypoint)
Notify superclients that a waypoint has changed radius.
void PathRename(const psPath *path)
Notify superclients that a path has been renamed.
A waypoint is a specified circle on the map with a name, location, and a list of waypoints it is conn...
Definition: waypoint.h:81
void AddEntity(gemObject *obj)
Communicate a entity added to connected superclients.
psDatabase * database
Definition: npcmanager.h:421
csArray< PublishDestination > & GetSuperClients()
Get the vector of active superclients, used in Multicast().
Definition: npcmanager.h:187
void ControlNPC(gemNPC *npc)
Tell a superclient to control an existing npc.
MathScript * GetPetDeathLockoutTime()
Definition: npcmanager.h:350
This stores a vector of positions listing a set of points defining a common type of location...
Definition: location.h:275
EventManager * eventmanager
Definition: npcmanager.h:422
void HandleSimpleRenderMesh(MsgEntry *me, Client *client)
Handle debug meshes from superclient.
Any semi-autonomous object, either a player or an NPC.
Definition: gem.h:1170
void SendPetSkillList(Client *client, bool forceOpen=true, PSSKILL focus=PSSKILL_NONE)
void PathPointAdjusted(psPathPoint *point)
Notify superclients that a pathpoint where adjusted.
iDataConnection * db
Global connection to the Database. Set from the psDatabase class.
void QueueSpokenToPerception(gemNPC *npc, bool spokenTo)
Send a spoken to perception to the super client for the npc.
void QueueTeleportPerception(gemNPC *npc, csVector3 &pos, float yrot, iSector *sector, InstanceID instance)
Let the superclient know that the npc was teleported.
void AddPoint(const psPath *path, const psPathPoint *point)
Notify superclients that a point has been added to a path.
bool Initialize()
Initialize the npc manager.
void PrepareMessage()
Create an empty command list message, waiting for items to be queued in it.
PSSKILL
Definition: psskills.h:44
void UpdateWorldPositions()
Build a message with all changed world positions for superclients to get.
void QueueSpellPerception(gemActor *caster, gemObject *target, const char *spell_cat, uint32_t spell_category, float severity)
Let the superclient know that a spell has been cast.
int getValueAsInt()
Get the value of this specific option in int format.
Definition: cachemanager.h:178
void QueueAttackPerception(gemActor *attacker, gemNPC *target)
Let the superclient know that a player has attacked one of its npcs.
MathScript * petReactScript
Math script setup for pet should react check.
Definition: npcmanager.h:437
void ChangeNPCBrain(gemNPC *npc, Client *client, const char *brainName)
Requests the npcclient to change the brain of this npc (the type) to another one. ...
void RemovePetOwnerSession(PetOwnerSession *session)
Remove Session for pets.
MathScript * petDepletedLockoutTime
Definition: npcmanager.h:439
void NewNPCNotify(PID player_id, PID master_id, PID owner_id)
Send a newly spawned npc to a superclient to manage it.
MathScript * GetPetDepletedLockoutTime()
Definition: npcmanager.h:347
void WaypointSetFlag(const Waypoint *wp, const csString &flag, bool enable)
Notify superclients that a flag has been changed for waypoint.
MathScript * petRangeScript
Math script setup for pet range check.
Definition: npcmanager.h:434
void DeletedNPCNotify(PID player_id)
Send a deleted npc to a superclient to un-manage it.
void QueueDeathPerception(gemObject *who)
Let the superclient know that one of its npcs has died.
This class collects data of a netclient.
Definition: client.h:95
csHash< PetOwnerSession *, PID > OwnerPetList
Definition: npcmanager.h:431
void SendMapList(Client *client)
Send the list of maps for the superclient to load on startup.
void SendNPCList(Client *client)
Send a list of managed NPCs to a newly connecting superclient.
Definition: gem.h:1910
ClientConnectionSet * clients
Definition: npcmanager.h:426
void SendRaces(Client *client)
Send the list of races for the superclient to load on startup.
void Disconnect(Client *client)
Remove a disconnecting superclient from the active list.
void RemovePoint(const psPath *path, int pointId)
Notify superclients that a point has been removed from a path.
void SendAllNPCStats(Client *client)
Send stats for all managed NPCs to a newly connecting superclient.
void HandleConsoleCommand(MsgEntry *me, Client *client)
Handle network message with console commands from npcclient.
void RemoveEntity(MsgEntry *me)
Communicate a entity going away to connected superclients.
void QueueChangeOwnerPerception(gemNPC *npc, EID owner)
Send a change owner perception.
MathScript * maxPetTime
Definition: npcmanager.h:441
void WaypointCreate(const Waypoint *waypoint)
Notify superclients that a waypoint has been created.
void QueueFlagPerception(gemActor *owner)
Let the superclient know that one of the actors flags has changed.
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
optionEntry * petSkill
Definition: npcmanager.h:429
A gemObject is any solid, graphical object visible in PS with normal physics and normal collision det...
Definition: gem.h:314
void HandleNPCReady(MsgEntry *me, Client *client)
void UpdatePetTime()
Updates time in game for a pet.
This class holds the refs to the core factories, etc in CEL.
Definition: gem.h:126
void QueueStatDR(gemActor *actor, unsigned int statsDirtyFlags)
GEMSupervisor * gemSupervisor
Definition: npcmanager.h:423
void QueuePerceptPerception(gemNPC *npc, csString perception, csString type)
Send a perception to the super client for the npc.
void LocationAdjusted(Location *location)
Notify superclients that a location where adjusted.
This class is a list of several CLient objects, it&#39;s designed for finding clients very fast based on ...
Definition: clients.h:58
void LocationInserted(Location *location)
Notify superclients that a location where inserted into a region.
void HandleCommandList(MsgEntry *me, Client *client)
Handle a network msg with a list of npc directives.
void HandleDeathEvent(MsgEntry *me, Client *client)
Catch an internal server event for death so a perception can be sent about it.
A Location is a named place on the map, located dynamically by NPCs as scripted.
Definition: location.h:48
void QueueInfoRequestPerception(gemNPC *npc, Client *client, const char *infoRequestSubCmd)
Let the superclient know that info is requested for a npc.
void HandleDamageEvent(MsgEntry *me, Client *client)
Catch an internal server event for damage so a perception can be sent about it.
void LocationTypeRemove(const csString &locationTypeName)
Notify superclients that a location type has been deleted.
void HandleAuthentRequest(MsgEntry *me, Client *client)
Handle a login message from a superclient.
void LocationCreated(Location *location)
Notify superclients that a location where created.
CacheManager * cacheManager
Definition: npcmanager.h:424
MathScript * petDeathLockoutTime
Definition: npcmanager.h:442
This class handles all queueing and invoking of timed events, such as combat, spells, NPC dialog responses, range weapons, or NPC respawning.
Definition: eventmanager.h:40
Represents a point on a path between two waypoints.
Definition: pspath.h:58
void PathCreate(const psPath *path)
Notify superclients that a path has been created.
void QueueSpawnedPerception(gemNPC *spawned, gemNPC *spawner, const csString &tribeMemberType)
Let the superclient know the npc was spawned successfully.
void QueueTalkPerception(gemActor *speaker, gemNPC *target)
Let the superclient know that a player has said something to one of its npcs.
void LocationRadius(Location *location)
Notify superclients that a location radius where chaned.
The message sent from server to superclient after successful login.
Definition: npcmessages.h:198
This class embodies item instances in the game.
Definition: psitem.h:238
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106