]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_bank.cpp
Added code for the start of the DataLayer format as well as a basic FilePlayerDAO...
[irc/gameservirc.git] / gameserv / do_bank.cpp
1 #include "extern.h"
2 #include "aClient.h"
3 #include "player.h"
4 #include "flags.h"
5 #include "options.h"
6
7
8 void do_bank(char *u)
9 {
10 char *cmd = strtok(NULL, " ");
11 char *amount = strtok(NULL, " ");
12 char *nick = strtok(NULL, " ");
13
14 aClient *user;
15 Player *p;
16
17 if (!cmd || (!amount && stricmp(cmd, "BALANCE") != 0) || (stricmp(cmd, "TRANSFER") == 0 && !nick))
18 {
19 notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}");
20 notice (s_GameServ, u, "BANK BALANCE");
21 return;
22 }
23 else if (!(user = find(u)))
24 {
25 notice(s_GameServ, u, "Fatal Error. Couldn't find your aClient. Contact a(n) <S "\
26 " admin for help");
27 log("Fatal Error. Couldn't find %s while executing do_bank()", u);
28 return;
29 }
30 else if (isIgnore(user))
31 {
32 #ifdef DEBUGMODE
33 log("Ignoring %s.", user->getNick());
34 #endif
35 return;
36 }
37 else if (!is_playing(user))
38 {
39 notice(s_GameServ, u, "You must be playing to use the bank!");
40 return;
41 }
42 else if (is_fighting(user))
43 {
44 notice(s_GameServ, u, "You can't go to the bank during a fight!");
45 return;
46 }
47 updateTS(user->stats);
48 if (stricmp(cmd, "BALANCE") == 0)
49 {
50 showBankBalance(u);
51 return;
52 }
53 else if (!isAlive(user->stats))
54 {
55 notice(s_GameServ, u, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!");
56 return;
57 }
58 else if (!isstringnum(amount) && stricmp(amount, "ALL") != 0)
59 {
60 notice(s_GameServ, u, "I don't know how to convert alphabet letters into currency, sire!");
61 return;
62 }
63 if (stringtoint(amount) < 0)
64 {
65 notice(s_GameServ, u, "Sorry. This bank is not licensed "\
66 "to handle such sums of cash, noble Lord.");
67 return;
68 }
69 p = user->stats;
70
71 if (stricmp(cmd, "DEPOSIT") == 0)
72 {
73 if (p->getBank() == 2000000000)
74 {
75 notice(s_GameServ, u, "Your bank account is full, sire!");
76 return;
77 }
78 else if (stricmp(amount, "ALL") == 0)
79 {
80 if (2000000000 - p->getBank() < p->getGold())
81 {
82 notice(s_GameServ, u, "You don't have enough room for all of your gold.");
83 notice(s_GameServ, u, "Depositing %ld gold into your account", (2000000000 - p->getBank()));
84 p->subtractGold((2000000000 - p->getBank()));
85 p->setBank(2000000000);
86 showBankBalance(u);
87 }
88 else
89 {
90 notice(s_GameServ, u, "Depositing %ld gold into your account!", p->getGold());
91 p->addBank(p->getGold());
92 p->setGold(0);
93 showBankBalance(u);
94 }
95 }
96 else if (stringtoint(amount) > p->getGold())
97 {
98 notice(s_GameServ, u, "Sire, you only have %ld gold!", p->getGold());
99 showBankBalance(u);
100 return;
101 }
102 else
103 {
104 if (2000000000 - p->getBank() < stringtoint(amount))
105 {
106 notice(s_GameServ, u, "You don't have room in your account for that much.");
107 notice(s_GameServ, u, "Capping off your account with %ld gold!", (2000000000 - p->getBank()));
108 p->subtractGold((2000000000 - p->getBank()));
109 p->setBank(2000000000);
110 showBankBalance(u);
111 }
112 else
113 {
114 notice(s_GameServ, u, "Depositing %d gold into your account!", stringtoint(amount));
115 p->addBank(stringtoint(amount));
116 p->subtractGold(stringtoint(amount));
117 showBankBalance(u);
118 }
119 }
120 }
121 else if (stricmp(cmd, "WITHDRAW") == 0)
122 {
123 if (p->getGold() == 2000000000)
124 {
125 notice(s_GameServ, u, "You cannot carry any more gold, sire!");
126 showBankBalance(u);
127 return;
128 }
129 else if (stricmp(amount, "ALL") == 0)
130 {
131 if (2000000000 - p->getGold() < p->getBank())
132 {
133 notice(s_GameServ, u, "You don't have enough room to carry all that gold.");
134 notice(s_GameServ, u, "Withdrawing %ld gold from your account", (2000000000 - p->getGold()));
135 p->subtractBank((2000000000 - p->getGold()));
136 p->setGold(2000000000);
137 showBankBalance(u);
138 }
139 else
140 {
141 notice(s_GameServ, u, "Withdrawing %ld gold from your account!", p->getBank());
142 p->addGold(p->getBank());
143 p->setBank(0);
144 showBankBalance(u);
145 }
146 }
147 else if (stringtoint(amount) > p->getBank())
148 {
149 notice(s_GameServ, u, "Sire, you only have %ld gold in the bank!", p->getBank());
150 showBankBalance(u);
151 return;
152 }
153 else
154 {
155 if (2000000000 - p->getGold() < stringtoint(amount))
156 {
157 notice(s_GameServ, u, "You don't enough have room to carry that much gold!");
158 notice(s_GameServ, u, "You fill your pockets with %ld gold!",
159 (2000000000 - p->getGold()));
160 p->subtractBank((2000000000 - p->getGold()));
161 p->setGold(2000000000);
162 showBankBalance(u);
163 }
164 else
165 {
166 notice(s_GameServ, u, "Withdrawing %d gold from your account!", stringtoint(amount));
167 p->addGold(stringtoint(amount));
168 p->subtractBank(stringtoint(amount));
169 showBankBalance(u);
170 }
171 }
172 }
173 }