Planeshift

bankmanager.h

Go to the documentation of this file.
00001 /*
00002 * bankmanager.h - Author: Mike Gist
00003 *
00004 * Copyright (C) 2007 Atomic Blue ([email protected], http://www.atomicblue.org)
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef __BANKMANAGER_H__
00021 #define __BANKMANAGER_H__
00022 //=============================================================================
00023 // Project Includes
00024 //=============================================================================
00025 #include "util/gameevent.h"
00026 
00027 //=============================================================================
00028 // Local Includes
00029 //=============================================================================
00030 #include "msgmanager.h"
00031 
00032 class psMoneyGameEvent;
00033 class Client;
00034 
00035 class BankManager : public MessageManager<BankManager>
00036 {
00037 public:
00038     BankManager();
00039     ~BankManager();
00040     inline void StartBanking(Client* client, bool guild)
00041     {
00042         SendBankWindow(client, guild, true);
00043     }
00044     void ProcessTax();
00045 
00046 protected:
00047     struct MoneyEvent
00048     {
00049         uint id;
00050         uint taxid;
00051         bool guild;
00052         int nextEvent; // YearsFrom1900:DaysSinceJan1st e.g. 107000 for Jan 1st 2007
00053         int interval; // In days
00054         int totalTrias;
00055         csString paid;
00056         csString npaid;
00057         csString fnpaid;
00058         bool latePayment;
00059         int lateBy;
00060         bool updateDate;
00061         InstanceID instance;
00062     };
00063 
00064 
00065     template<class T>
00066     void TaxAccount(T guildOrChar, MoneyEvent &monEvt, int index);
00067 
00068 private:
00069     void SendBankWindow(Client* client, bool guild, bool forceOpen);
00070     void WithdrawFunds(Client* client, bool guild, int circles, int octas, int hexas, int trias);
00071     void DepositFunds(Client* client, bool guild, int circles, int octas, int hexas, int trias);
00072     void ExchangeFunds(Client* client, bool guild, int coins, int coin);
00073     psMoney* GetTotalFunds(psCharacter* pschar, bool guild);
00074     void HandleBanking(MsgEntry* me, Client* client);
00075     int CoinsForExchange(psCharacter* pschar, bool guild, int type, float fee);
00076     int CalculateAccountLevel(psCharacter* pschar, bool guild);
00077     inline float CalculateFee(psCharacter* pschar, bool guild);
00078 
00079     csArray<MoneyEvent> monEvts;
00080 
00081     MathScript* accountCharLvlScript;
00082     MathScript* accountGuildLvlScript;
00083     MathScript* CalcBankFeeScript;
00084 };
00085 
00086 
00087 class psMoneyGameEvent : public psGameEvent
00088 {
00089 public:
00090 
00091     psMoneyGameEvent(int delayTicks, BankManager* bankMan);
00092 
00093     virtual void Trigger()
00094     {
00095         bankManager->ProcessTax();    // Abstract event processing function
00096     }
00097 
00098 private:
00099     BankManager* bankManager;
00100 };
00101 
00102 #endif // __BANKMANAGER_H__