Planeshift
questmanager.h
Go to the documentation of this file.
1 /*
2  * questmanager.h
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 #ifndef __QUESTMANAGER_H__
20 #define __QUESTMANAGER_H__
21 
22 //=============================================================================
23 // Crystal Space Includes
24 //=============================================================================
25 
26 //=============================================================================
27 // Project Includes
28 //=============================================================================
29 #include "bulkobjects/psquest.h"
30 
31 //=============================================================================
32 // Local Includes
33 //=============================================================================
34 #include "msgmanager.h" // Subscriber class
35 
36 
37 class Client;
38 class psItemStats;
39 
40 struct QuestRewardOffer;
41 struct QuestRewardItem;
42 class gemNPC;
43 class NpcDialogMenu;
44 class NpcResponse;
45 class WordArray;
46 class psString;
47 
52 class QuestManager : public MessageManager<QuestManager>
53 {
54 protected:
55  csPDelArray<QuestRewardOffer> offers;
56 
57  csString lastError;
58 
60 
64  bool LoadQuestScripts();
72  int PreParseQuestScript(psQuest* mainQuest,const char* script);
73  void CutOutParenthesis(csString &response, csString &within,char start_char,char end_char) const;
74 
75  bool GetResponseText(csString &block,csString &response,csString &file_path,
76  csString &him, csString &her, csString &it, csString &them) const;
77  bool BuildTriggerList(csString &block,csStringArray &list) const;
78 
89  bool ParseQuestScriptMenu(const csString &block,const csStringArray &triggers, psQuest* quest, NpcDialogMenu* menu) const;
90 
91  int GetNPCFromBlock(WordArray words,csString &current_npc);
92  bool ParseItemList(const csString &input, csString &parsedItemList);
93  bool ParseItem(const char* text, psStringArray &xmlItems, psMoney &money);
94 
108  NpcResponse* AddResponse(const csString &current_npc,const char* response_text,
109  int &last_response_id, psQuest* quest,
110  csString &him, csString &her, csString &it, csString &them, csString &file_path);
121  bool AddTrigger(const csString &current_npc,const char* trigger,
122  int prior_response_id,NpcResponse* trig_response, psQuest* quest, const psString &postfix);
123  void MergeTriggerMenus(NpcDialogMenu* pending_menu, const csString &current_npc);
124 
125  void GetNextScriptLine(psString &scr, csString &block, size_t &start, int &line_number);
126  bool PrependPrerequisites(csString &substep_requireop,
127  csString &response_requireop,
128  bool quest_assigned_already,
129  NpcResponse* last_response,
130  psQuest* mainQuest);
131 
132  bool HandlePlayerAction(csString &block,
133  size_t &which_trigger,
134  csString &current_npc,
135  csStringArray &pending_triggers);
136 
137  bool HandleScriptCommand(csString &block,
138  csString &response_requireop,
139  csString &substep_requireop,
140  NpcResponse* last_response,
141  psQuest* mainQuest,
142  bool &quest_assigned_already,
143  psQuest* quest);
144 
153  csString ParseRequireCommand(csString &block, bool &result, psQuest* mainQuest);
154 
162  bool HandleRequireCommand(csString &block, csString &response_requireop, psQuest* mainQuest);
163 
170  void AutocompleteQuestName(csString &questname, psQuest* mainQuest);
171 
172  void HandleQuestInfo(MsgEntry* pMsg,Client* client);
173  void HandleQuestReward(MsgEntry* pMsg,Client* client);
174 
175 private:
180  class TaskEntry
181  {
182  public:
183  csString text;
184  int completionOrder;
185  int questOrder;
186 
198  bool operator<(const TaskEntry &other) const
199  {
200  //first check if the completion order is different
201  //in that case use that as order
202  if(completionOrder != other.completionOrder)
203  {
204  return completionOrder > other.completionOrder;
205  }
206  //if they are the same check for the case the completion
207  //order is invalid and check if quest order is different
208  return questOrder > other.questOrder;
209  }
210  };
211 
212 public:
213 
214  QuestManager(CacheManager* cachemanager);
215  virtual ~QuestManager();
216 
217  bool Initialize();
218 
221  int ParseQuestScript(int id,const char* script);
222 
228  int ParseCustomScript(int id, const csString& current_npc, const char* script);
229 
232  void Assign(psQuest* quest, Client* who, gemNPC* assigner,csTicks timeDelay=0);
233 
236  bool Complete(psQuest* quest, Client* who, csTicks timeDelay = 0);
237 
246  bool Uncomplete(psQuest* quest, Client* who, csTicks timeDelay = 0);
247 
248 
249  void OfferRewardsToPlayer(Client* who, csArray<QuestRewardItem>& offer, csTicks& timeDelay);
250  bool GiveRewardToPlayer(Client* who, QuestRewardItem& reward);
251  bool LoadQuestScript(int id);
252  const char* LastError()
253  {
254  return lastError.GetData();
255  }
256 };
257 
258 
259 #endif
260 
bool BuildTriggerList(csString &block, csStringArray &list) const
bool Uncomplete(psQuest *quest, Client *who, csTicks timeDelay=0)
Discards the requested step this is used by dictionary.
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)
csPDelArray< QuestRewardOffer > offers
Definition: questmanager.h:55
void Assign(psQuest *quest, Client *who, gemNPC *assigner, csTicks timeDelay=0)
bool GiveRewardToPlayer(Client *who, QuestRewardItem &reward)
CacheManager * cacheManager
Definition: questmanager.h:59
This class holds all information for one quest with its reference to parent quest, list of steps, lockoutime, sub quests, ...
Definition: psquest.h:67
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
bool ParseQuestScriptMenu(const csString &block, const csStringArray &triggers, psQuest *quest, NpcDialogMenu *menu) const
Parse QuestScript entries from a string.
void GetNextScriptLine(psString &scr, csString &block, size_t &start, int &line_number)
void CutOutParenthesis(csString &response, csString &within, char start_char, char end_char) const
bool Complete(psQuest *quest, Client *who, csTicks timeDelay=0)
void OfferRewardsToPlayer(Client *who, csArray< QuestRewardItem > &offer, csTicks &timeDelay)
bool GetResponseText(csString &block, csString &response, csString &file_path, csString &him, csString &her, csString &it, csString &them) const
virtual ~QuestManager()
bool HandlePlayerAction(csString &block, size_t &which_trigger, csString &current_npc, csStringArray &pending_triggers)
void MergeTriggerMenus(NpcDialogMenu *pending_menu, const csString &current_npc)
int ParseQuestScript(int id, const char *script)
Parase a new quest script.
csString ParseRequireCommand(csString &block, bool &result, psQuest *mainQuest)
Parses a require command inner part.
WordArray is class that parses text command (e.g.
Definition: strutil.h:62
bool LoadQuestScripts()
Load all scripts from db.
This class collects data of a netclient.
Definition: client.h:95
Definition: gem.h:1910
This class holds several possible responses and an action script for the npc to run whenever an appro...
Definition: dictionary.h:394
bool operator<(long lhs, const GmpInt &rhs)
Definition: GmpInt.h:135
Holds the trigger menu, if it exists, for a given location in a dialog.
Definition: dictionary.h:325
int ParseCustomScript(int id, const csString &current_npc, const char *script)
Parase a new custom script.
This huge class stores all the properties of any object a player can have in the game.
Definition: psitemstats.h:463
int GetNPCFromBlock(WordArray words, csString &current_npc)
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
bool HandleScriptCommand(csString &block, csString &response_requireop, csString &substep_requireop, NpcResponse *last_response, psQuest *mainQuest, bool &quest_assigned_already, psQuest *quest)
int PreParseQuestScript(psQuest *mainQuest, const char *script)
Does a first parsing of the script.
bool ParseItem(const char *text, psStringArray &xmlItems, psMoney &money)
void HandleQuestReward(MsgEntry *pMsg, Client *client)
QuestManager(CacheManager *cachemanager)
bool LoadQuestScript(int id)
NpcResponse * 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)
Adds a NpcResponse to the dict (global var)
void AutocompleteQuestName(csString &questname, psQuest *mainQuest)
Checks if the quest name is existant, if it isn&#39;t it attemps to complete it with the name of the pass...
A slightly improved version of csStringArray, sporting the handy FormatPush method.
Definition: stringarray.h:33
bool Initialize()
This class handles quest management for the player, tracking who has what quests assigned, etc.
Definition: questmanager.h:52
bool ParseItemList(const csString &input, csString &parsedItemList)
csString lastError
Last error message to send to client on loadquest.
Definition: questmanager.h:57
bool PrependPrerequisites(csString &substep_requireop, csString &response_requireop, bool quest_assigned_already, NpcResponse *last_response, psQuest *mainQuest)
const char * LastError()
Definition: questmanager.h:252
bool HandleRequireCommand(csString &block, csString &response_requireop, psQuest *mainQuest)
Parses a require command.
void HandleQuestInfo(MsgEntry *pMsg, Client *client)
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106