Planeshift
exchangemanager.h
Go to the documentation of this file.
1 /*
2  * exchangemanager.h
3  *
4  * Copyright (C) 2001 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 __EXCHANGEMANAGER_H__
20 #define __EXCHANGEMANAGER_H__
21 //=============================================================================
22 // Crystal Space Includes
23 //=============================================================================
24 #include <csutil/ref.h>
25 #include <csutil/refarr.h>
26 #include <csutil/parray.h>
27 
28 //=============================================================================
29 // Project Includes
30 //=============================================================================
32 
33 //=============================================================================
34 // Local Includes
35 //=============================================================================
36 #include "msgmanager.h" // Parent class
37 
39 class psSpawnManager;
40 class psServer;
41 class Exchange;
42 class ExchangeManager;
43 class psNPCDialog;
44 class psDatabase;
45 
55 {
56 public:
58 
66  bool OfferItem(int exchSlotNum, INVENTORY_SLOT_NUMBER invSlot, int stackcount, bool test);
67 
78  bool RemoveItemFromOffer(int itemNum, int count, int &remain);
79 
80  bool MoveOfferedItem(int fromSlot,int stackcount,int toSlot);
81 
85  bool IsOfferingSane();
86 
92  void TransferOffer(int targetClientNum);
93 
98  void TransferOffer(psCharacter* npc);
99 
106  void TransferMoney(int targetClientNum);
107 
111  void TransferMoney(psCharacter* target);
112 
114  {
115  return offeringMoney;
116  }
117 
124  void AdjustMoney(int coin, int delta);
125  void AdjustMoney(const psMoney &amount);
126 
127  void GetOfferingCSV(csString &buff);
128 
140  void GetOffering(csString &buff);
141 
142  psItem* GetOfferedItem(int slot);
143 
156  void GetSimpleOffering(csString &buff, psCharacter* chr, bool exact = true);
157 
161  void UpdateReceivingMoney(psMoney &money);
162 
166  void UpdateOfferingMoney();
167 
169 
173  float GetSumSize();
174 
178  float GetSumWeight();
179 
180  bool GetExchangedItems(csString &text);
181 
182 protected:
183 
184  psCharacter* GetClientCharacter(int clientNum);
185 
189 // psItem *offering[EXCHANGE_SLOT_COUNT];
190  // csArray<psItem*> itemsOffered;
191 
192  int client;
194 };
195 
196 //------------------------------------------------------------------------------
197 
205 {
206 public:
207  Exchange(Client* starter, bool automaticExchange, ExchangeManager* manager);
208  virtual ~Exchange();
209 
217  virtual void HandleEnd(Client* client) = 0;
218 
227  virtual bool HandleAccept(Client* client) = 0;
228  // virtual bool Involves(psCharacter * character) = 0;
229  // virtual bool Involves(psItem * item) = 0;
230 
243  virtual bool AddItem(Client* fromClient, INVENTORY_SLOT_NUMBER fromSlot, int stackCount, int toSlot);
244 
257  virtual void MoveItem(Client* client, int fromSlot, int stackCount, int toSlot);
258 
271  virtual bool RemoveItem(Client* fromClient, int slot, int stackCount);
272 
273  virtual psMoney GetOfferedMoney(Client* client);
274  virtual bool AdjustMoney(Client* client, int moneyType, int newMoney);
275  virtual bool AdjustMoney(Client* client, const psMoney &money);
276  int GetID() const
277  {
278  return id;
279  }
280  bool CheckRange(int clientNum, gemObject* ourActor, gemObject* otherActor);
281 
283  {
284  return starterClient; // NILAYA: Should axe.
285  }
286 
287  psItem* GetStarterOffer(int slot);
288  virtual psItem* GetTargetOffer(int slot)
289  {
290  return NULL;
291  }
292 
293 protected:
294  virtual void SendAddItemMessage(Client* fromClient, int slot, psCharacterInventory::psCharacterInventoryItem* item);
295  virtual void SendRemoveItemMessage(Client* fromClient, int slot);
296 
297  void SendEnd(int clientNum);
298  static int next_id;
299 
301  int id;
302 
306  uint32_t player;
307 
310 
312 
314 };
315 
316 //------------------------------------------------------------------------------
317 
319 {
320 public:
322  virtual ~PlayerToPlayerExchange();
323 
324  bool CheckExchange(uint32_t clientNum, bool checkRange=false);
325  bool HandleAccept(Client* client);
326  void HandleEnd(Client* client);
327  void SendExchangeStatusToBoth();
328  psMoney GetOfferedMoney(Client* client);
329  bool AdjustMoney(Client* client, int moneyType, int newMoney);
330  bool AdjustMoney(Client* client, const psMoney &money);
331 
342  virtual bool AddItem(Client* fromClient, INVENTORY_SLOT_NUMBER fromSlot, int stackCount, int toSlot);
343 
356  virtual bool RemoveItem(Client* fromClient, int slot, int stackCount);
357 
358  virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
359 
360  virtual psItem* GetTargetOffer(int slot);
361 
362 protected:
363  virtual void SendAddItemMessage(Client* fromClient, int slot, psCharacterInventory::psCharacterInventoryItem* item);
364  virtual void SendRemoveItemMessage(Client* fromClient, int slot);
365 
366 private:
368  void SendRequestToBoth();
369 
370  Client* GetOtherClient(Client* client) const;
371 
373 
375  Client* targetClient;
376  ExchangingCharacter targetChar;
377  int target;
378 
379  bool starterAccepted, targetAccepted;
380 };
381 
382 //------------------------------------------------------------------------------
383 
385 {
386 public:
387  PlayerToNPCExchange(Client* starter, gemObject* target, bool automaticExchange, int questID, ExchangeManager* manager);
388  virtual ~PlayerToNPCExchange();
389  gemObject* GetTargetGEM();
390  bool CheckExchange(uint32_t clientNum, bool checkRange=false);
391  virtual void HandleEnd(Client* client);
392  virtual bool HandleAccept(Client* client);
393  //virtual bool Involves(psCharacter * character);
394  //virtual bool Involves(psItem * item);
395  virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
396 
397 protected:
406  bool CheckXMLResponse(Client* client, psNPCDialog* dlg, csString trigger);
407 
409  int questID;
410 };
411 
412 /* Maintains a list of all the exchanges that are ongoing.
413  */
414 class ExchangeManager : public MessageManager<ExchangeManager>
415 {
416 public:
417 
419  virtual ~ExchangeManager();
420 
421  static bool ExchangeCheck(Client* client, gemObject* target, csString* errorMessage = NULL);
422 
423  void StartExchange(Client* client, bool withPlayer, bool automaticExchange = false, int questID = -1);
424 
425  void HandleExchangeRequest(MsgEntry* me,Client* client);
426  void HandleExchangeAccept(MsgEntry* me,Client* client);
427  void HandleExchangeEnd(MsgEntry* me,Client* client);
428  void HandleAutoGive(MsgEntry* me,Client* client);
429 
431  Exchange* GetExchange(int id);
432 
434  void AddExchange(Exchange* exchange)
435  {
436  exchanges.Push(exchange);
437  }
438 
440  void DeleteExchange(Exchange* exchange);
441 
442 protected:
443 
445 
446  csPDelArray<Exchange> exchanges;
447 };
448 
451 #endif
ClientConnectionSet * clients
This class handles the details behind a character&#39;s inventory system.
int GetID() const
bool IsOfferingSane()
Make sure all offered items still have legal stack counts.
A basic exchange.
void AdjustMoney(int coin, int delta)
Change the amount of money this character is offering in the exchange.
Client * starterClient
ExchangingCharacter(int client, psCharacterInventory &inv)
bool exchangeSuccess
exchange was successful and items should not be returned to owners
INVENTORY_SLOT_NUMBER
Holds a list of the possible socket identifiers that items can be attached to.
Definition: slots.h:32
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
The main server class.
Definition: psserver.h:102
void UpdateOfferingMoney()
Update the money box for money that is being offered by this character.
float GetSumSize()
Gets the total size of all the items that are offered.
void AddExchange(Exchange *exchange)
Adds given exchange to the exchange manager&#39;s exchanges list.
bool automaticExchange
the exchange is done entirely server side don&#39;t open windows on the client. This is used only with NP...
psCharacter * GetClientCharacter(int clientNum)
ExchangingCharacter starterChar
Information about the player that initiated the exchange.
void TransferMoney(int targetClientNum)
Transfers the trias from this exchanging player to a different player.
ExchangingCharacter holds relevant information about character that is participating in exchange of i...
void GetOffering(csString &buff)
Constructs an XML list of the items that are being offered.
uint32_t player
void UpdateReceivingMoney(psMoney &money)
Update the money box for money that will be received by this character.
bool MoveOfferedItem(int fromSlot, int stackcount, int toSlot)
int client
Stuff that was removed from character inventory and offered to the other character.
void GetOfferingCSV(csString &buff)
bool RemoveItemFromOffer(int itemNum, int count, int &remain)
Removes items from position &#39;itemNum&#39;.
static int next_id
void TransferOffer(int targetClientNum)
Transfers offered items and money to character &#39;target&#39;.
This class collects data of a netclient.
Definition: client.h:95
Client * GetStarterClient()
psItem * GetOfferedItem(int slot)
float GetSumWeight()
Gets the total weight of all the items that are offered.
This class exists per NPC, and holds all dialog triggers, responses and scripts for this particular N...
Definition: psnpcdialog.h:151
psCharacterInventory * chrinv
bool OfferItem(int exchSlotNum, INVENTORY_SLOT_NUMBER invSlot, int stackcount, bool test)
Inserts item to position &#39;itemNum&#39;.
ExchangeManager * exchangeMgr
A gemObject is any solid, graphical object visible in PS with normal physics and normal collision det...
Definition: gem.h:314
virtual psItem * GetTargetOffer(int slot)
bool GetExchangedItems(csString &text)
This class is a list of several CLient objects, it&#39;s designed for finding clients very fast based on ...
Definition: clients.h:58
csPDelArray< Exchange > exchanges
void GetSimpleOffering(csString &buff, psCharacter *chr, bool exact=true)
Constructs a simple XML list of the items that are being offered.
This class generically allows objects to be notified when a gemObject is removed. ...
bool exchangeEnded
exchange ended and should be deleted
int id
unique exchange ID
This class embodies item instances in the game.
Definition: psitem.h:238
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106