Planeshift
QuestManager Class Reference

This class handles quest management for the player, tracking who has what quests assigned, etc. More...

#include <questmanager.h>

Public Member Functions

void Assign (psQuest *quest, Client *who, gemNPC *assigner, csTicks timeDelay=0)
 
bool Complete (psQuest *quest, Client *who, csTicks timeDelay=0)
 
bool GiveRewardToPlayer (Client *who, QuestRewardItem &reward)
 
bool Initialize ()
 
const char * LastError ()
 
bool LoadQuestScript (int id)
 
void OfferRewardsToPlayer (Client *who, csArray< QuestRewardItem > &offer, csTicks &timeDelay)
 
int ParseCustomScript (int id, const csString &current_npc, const char *script)
 Parase a new custom script. More...
 
int ParseQuestScript (int id, const char *script)
 Parase a new quest script. More...
 
 QuestManager (CacheManager *cachemanager)
 
bool Uncomplete (psQuest *quest, Client *who, csTicks timeDelay=0)
 Discards the requested step this is used by dictionary. More...
 
virtual ~QuestManager ()
 
- Public Member Functions inherited from MessageManager< QuestManager >
void HandleMessage (MsgEntry *msg, Client *client)
 Transfers the message to the manager specific function. More...
 
void Subscribe (FunctionPointer fpt, msgtype type, uint32_t flags=0x01)
 Subscribes this manager to a specific message type with a custom callback. More...
 
bool Unsubscribe (msgtype type)
 Unsubscribes this manager from a specific message type. More...
 
bool Unsubscribe (FunctionPointer handler, msgtype type)
 Unsubscribes a specific handler from a specific message type. More...
 
bool UnsubscribeAll ()
 Unsubscribes this manager from all message types. More...
 
virtual ~MessageManager ()
 Unsubscribes all messages then destroys this object. More...
 
- Public Member Functions inherited from MessageManagerBase
csArray< csString > DecodeCommandArea (Client *client, csString target)
 Decodes an area: expression. More...
 
gemObjectFindObjectByString (const csString &str, gemActor *me) const
 Find the object we are referring to in str. More...
 
ClientFindPlayerClient (const char *name)
 Finds Client* of character with given name. More...
 
virtual bool Verify (MsgEntry *pMsg, unsigned int flags, Client *&client)
 

Protected Member Functions

NpcResponseAddResponse (const csString &current_npc, const char *response_text, int &last_response_id, psQuest *quest, csString &him, csString &her, csString &it, csString &them, csString &file_path)
 Adds a NpcResponse to the dict (global var) More...
 
bool AddTrigger (const csString &current_npc, const char *trigger, int prior_response_id, NpcResponse *trig_response, psQuest *quest, const psString &postfix)
 Adds a Trigger for a NpcResponse to the dict (global var) More...
 
void AutocompleteQuestName (csString &questname, psQuest *mainQuest)
 Checks if the quest name is existant, if it isn't it attemps to complete it with the name of the passed quest but only if the autocompleted version is found. More...
 
bool BuildTriggerList (csString &block, csStringArray &list) const
 
void CutOutParenthesis (csString &response, csString &within, char start_char, char end_char) const
 
void GetNextScriptLine (psString &scr, csString &block, size_t &start, int &line_number)
 
int GetNPCFromBlock (WordArray words, csString &current_npc)
 
bool GetResponseText (csString &block, csString &response, csString &file_path, csString &him, csString &her, csString &it, csString &them) const
 
bool HandlePlayerAction (csString &block, size_t &which_trigger, csString &current_npc, csStringArray &pending_triggers)
 
void HandleQuestInfo (MsgEntry *pMsg, Client *client)
 
void HandleQuestReward (MsgEntry *pMsg, Client *client)
 
bool HandleRequireCommand (csString &block, csString &response_requireop, psQuest *mainQuest)
 Parses a require command. More...
 
bool HandleScriptCommand (csString &block, csString &response_requireop, csString &substep_requireop, NpcResponse *last_response, psQuest *mainQuest, bool &quest_assigned_already, psQuest *quest)
 
bool LoadQuestScripts ()
 Load all scripts from db. More...
 
void MergeTriggerMenus (NpcDialogMenu *pending_menu, const csString &current_npc)
 
bool ParseItem (const char *text, psStringArray &xmlItems, psMoney &money)
 
bool ParseItemList (const csString &input, csString &parsedItemList)
 
bool ParseQuestScriptMenu (const csString &block, const csStringArray &triggers, psQuest *quest, NpcDialogMenu *menu) const
 Parse QuestScript entries from a string. More...
 
csString ParseRequireCommand (csString &block, bool &result, psQuest *mainQuest)
 Parses a require command inner part. More...
 
int PreParseQuestScript (psQuest *mainQuest, const char *script)
 Does a first parsing of the script. More...
 
bool PrependPrerequisites (csString &substep_requireop, csString &response_requireop, bool quest_assigned_already, NpcResponse *last_response, psQuest *mainQuest)
 

Protected Attributes

CacheManagercacheManager
 
csString lastError
 Last error message to send to client on loadquest. More...
 
csPDelArray< QuestRewardOffer > offers
 

Additional Inherited Members

- Public Types inherited from MessageManager< QuestManager >
typedef void(QuestManager::* FunctionPointer) (MsgEntry *, Client *)
 

Detailed Description

This class handles quest management for the player, tracking who has what quests assigned, etc.

Definition at line 52 of file questmanager.h.

Constructor & Destructor Documentation

QuestManager::QuestManager ( CacheManager cachemanager)
virtual QuestManager::~QuestManager ( )
virtual

Member Function Documentation

NpcResponse* QuestManager::AddResponse ( const csString &  current_npc,
const char *  response_text,
int last_response_id,
psQuest quest,
csString &  him,
csString &  her,
csString &  it,
csString &  them,
csString &  file_path 
)
protected

Adds a NpcResponse to the dict (global var)

Creates a new NpcResponse object for the given npc with the given trigger and data.

Parameters
current_npcthe npc that the response is for.
response_textis the text.
last_response_idis just an output variable, and will contain the id of the new response
questis the quest generating the response
him
her
it
them
file_pathto the voice file (if any)
bool QuestManager::AddTrigger ( const csString &  current_npc,
const char *  trigger,
int  prior_response_id,
NpcResponse trig_response,
psQuest quest,
const psString postfix 
)
protected

Adds a Trigger for a NpcResponse to the dict (global var)

Creates and registeres a trigger with the dict.

Parameters
current_npcthe npc that the response is for.
triggercontains the text that evokes the trigger
prior_response_idis the preceeding response id
trig_responseis the response that was already created and registered with dict.
questis the quest generating the trigger
postfix
void QuestManager::Assign ( psQuest quest,
Client who,
gemNPC assigner,
csTicks  timeDelay = 0 
)
void QuestManager::AutocompleteQuestName ( csString &  questname,
psQuest mainQuest 
)
protected

Checks if the quest name is existant, if it isn't it attemps to complete it with the name of the passed quest but only if the autocompleted version is found.

Parameters
questnameName of the quest we have to check for. Output is written directly in the passed variable.
mainQuestThe quest where this questname was found to check for in quest completion.
bool QuestManager::BuildTriggerList ( csString &  block,
csStringArray &  list 
) const
protected
bool QuestManager::Complete ( psQuest quest,
Client who,
csTicks  timeDelay = 0 
)
void QuestManager::CutOutParenthesis ( csString &  response,
csString &  within,
char  start_char,
char  end_char 
) const
protected
void QuestManager::GetNextScriptLine ( psString scr,
csString &  block,
size_t &  start,
int line_number 
)
protected
int QuestManager::GetNPCFromBlock ( WordArray  words,
csString &  current_npc 
)
protected
bool QuestManager::GetResponseText ( csString &  block,
csString &  response,
csString &  file_path,
csString &  him,
csString &  her,
csString &  it,
csString &  them 
) const
protected
bool QuestManager::GiveRewardToPlayer ( Client who,
QuestRewardItem reward 
)
bool QuestManager::HandlePlayerAction ( csString &  block,
size_t &  which_trigger,
csString &  current_npc,
csStringArray &  pending_triggers 
)
protected
void QuestManager::HandleQuestInfo ( MsgEntry pMsg,
Client client 
)
protected
void QuestManager::HandleQuestReward ( MsgEntry pMsg,
Client client 
)
protected
bool QuestManager::HandleRequireCommand ( csString &  block,
csString &  response_requireop,
psQuest mainQuest 
)
protected

Parses a require command.

Note
this function handles no and not and calls parseRequireCommand for the inner parsing
Parameters
blockA csString which is the block to be parsed stripped of "require".
response_requireopA csString where to append the response prerequisites.
mainQuestA pointer to the main quest, used for quest name autocompletion
Returns
A boolean indicating if the operation was successfull.
bool QuestManager::HandleScriptCommand ( csString &  block,
csString &  response_requireop,
csString &  substep_requireop,
NpcResponse last_response,
psQuest mainQuest,
bool &  quest_assigned_already,
psQuest quest 
)
protected
bool QuestManager::Initialize ( )
const char* QuestManager::LastError ( )
inline

Definition at line 252 of file questmanager.h.

bool QuestManager::LoadQuestScript ( int  id)
bool QuestManager::LoadQuestScripts ( )
protected

Load all scripts from db.

void QuestManager::MergeTriggerMenus ( NpcDialogMenu pending_menu,
const csString &  current_npc 
)
protected
void QuestManager::OfferRewardsToPlayer ( Client who,
csArray< QuestRewardItem > &  offer,
csTicks &  timeDelay 
)
int QuestManager::ParseCustomScript ( int  id,
const csString &  current_npc,
const char *  script 
)

Parase a new custom script.

This is the same as ParseQuestScript, but with all the limitaiton that is needed to allow players to script this.

bool QuestManager::ParseItem ( const char *  text,
psStringArray xmlItems,
psMoney money 
)
protected
bool QuestManager::ParseItemList ( const csString &  input,
csString &  parsedItemList 
)
protected
int QuestManager::ParseQuestScript ( int  id,
const char *  script 
)

Parase a new quest script.

bool QuestManager::ParseQuestScriptMenu ( const csString &  block,
const csStringArray &  triggers,
psQuest quest,
NpcDialogMenu menu 
) const
protected

Parse QuestScript entries from a string.

Parse all Menu: entries from a string

Parameters
blockis the string to parse.
triggersis a list of trigger strings, for each menu entry one
questthat this menu is attached to
menuto add the triggers to
csString QuestManager::ParseRequireCommand ( csString &  block,
bool &  result,
psQuest mainQuest 
)
protected

Parses a require command inner part.

Note
this functions doesn't handle the negations which are handled by HandleRequireCommand
Parameters
blockA csString which is the block to be parsed stripped of "require" and the leading no, if any.
resultA bool which will store if it was possible to parse the passed string
mainQuestA pointer to the main quest, used for quest name autocompletion
Returns
A csString which has the xml result of the parsing
int QuestManager::PreParseQuestScript ( psQuest mainQuest,
const char *  script 
)
protected

Does a first parsing of the script.

Note
curretly it just find substeps and creates the related quest in advance, so they can be used anywhere in prerequisites.
Parameters
mainQuestA pointer to the main psQuest. This can't be null it must be valid!
scriptThe entire quest script.
Returns
the line number of the parse error if any.
bool QuestManager::PrependPrerequisites ( csString &  substep_requireop,
csString &  response_requireop,
bool  quest_assigned_already,
NpcResponse last_response,
psQuest mainQuest 
)
protected
bool QuestManager::Uncomplete ( psQuest quest,
Client who,
csTicks  timeDelay = 0 
)

Discards the requested step this is used by dictionary.

Todo:
evaluate if this should be moved somewhere else togheter with the two above.
Parameters
questThe quest we are discarding.
whoThe client which is discarding the quest.
timeDelayThe delay for messages.

Member Data Documentation

CacheManager* QuestManager::cacheManager
protected

Definition at line 59 of file questmanager.h.

csString QuestManager::lastError
protected

Last error message to send to client on loadquest.

Definition at line 57 of file questmanager.h.

csPDelArray<QuestRewardOffer> QuestManager::offers
protected

Definition at line 55 of file questmanager.h.


The documentation for this class was generated from the following file: