]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_tavern.cpp
Added code for the start of the DataLayer format as well as a basic FilePlayerDAO...
[irc/gameservirc.git] / gameserv / do_tavern.cpp
1 #include "extern.h"
2 #include "aClient.h"
3 #include "flags.h"
4 #include "options.h"
5 #include "player.h"
6 #include "item.h"
7 #include "pouch.h"
8
9 void do_tavern(char *u)
10 {
11 char *cmd = strtok(NULL, " ");
12
13 aClient *user;
14 Player *p;
15
16 if (!(user = find(u)))
17 {
18 notice(s_GameServ, u, "Fatal Error. See a <S admin for help");
19 return;
20 }
21 else if (isIgnore(user))
22 {
23 #ifdef DEBUGMODE
24 log("Ignoring %s.", user->getNick());
25 #endif
26 return;
27 }
28 else if (!is_playing(user))
29 {
30 notice(s_GameServ, u, "You must be playing to go to the Tavern");
31 return;
32 }
33 else if (is_fighting(user))
34 {
35 notice(s_GameServ, u, "You cannot go to the Tavern during a fight!");
36 return;
37 }
38
39 updateTS(user->stats);
40 p = user->stats;
41
42 if (!cmd)
43 {
44 notice(s_GameServ, u, "Welcome to Boot Liquors Mystic Apothecary and General Store");
45 notice(s_GameServ, u, "Your commands:");
46 notice(s_GameServ, u, "/msg <S TAVERN {LIST | BUY} [NUMBER]");
47 notice(s_GameServ, u, "What'll it be?");
48 }
49 else if (stricmp(cmd, "LIST") == 0)
50 {
51 notice(s_GameServ, u, "Here is a list of what we have to offer:");
52 showTavern(user);
53 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY #");
54 }
55 else if (stricmp(cmd, "BUY") == 0)
56 {
57 int amt = 1;
58 char *chid = strtok(NULL, " ");
59 char *amount = strtok(NULL, " ");
60
61 if (amount)
62 amt = stringtoint(amount);
63
64 if (!chid)
65 {
66 notice(s_GameServ, u, "SYNTAX: TAVERN BUY # [#]");
67 notice(s_GameServ, u, "Example: /msg <S TAVERN BUY 6001");
68 notice(s_GameServ, u, "Example: /msg <S TAVERN BUY 6001 10");
69 return;
70 }
71 long id = stringtoint(chid);
72 tavernItem *tempItem;
73
74 if (!(tempItem = findTavernItemByID(id)) || user->stats->getLevel() < tempItem->getLevel())
75 {
76 notice(s_GameServ, u, "Invalid Choice!");
77 notice(s_GameServ, u, "Here is a list of what we have to offer:");
78 showTavern(user);
79 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY #");
80 return;
81 }
82 else if (!amount && user->stats->getGold() < tempItem->getItem()->price())
83 {
84 notice(s_GameServ, u, "You don't have enough gold!");
85 notice(s_GameServ, u, "Here is a list of what we have to offer:");
86 showTavern(user);
87 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY #");
88 }
89 else if (user->stats->getGold() < amt * tempItem->getItem()->price())
90 {
91 notice(s_GameServ, u, "You don't have enough gold!");
92 notice(s_GameServ, u, "Here is a list of what we have to offer:");
93 showTavern(user);
94 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY # [#]");
95 }
96 else
97 {
98 if (amount)
99 {
100 int amt = stringtoint(amount);
101 if (amt < 0 || amount[0] == '-')
102 {
103 notice(s_GameServ, u, "You trying to steal from me?");
104 }
105 else if (user->stats->inventory->addItem(tempItem->getItem(), amt) == NULL)
106 {
107 notice(s_GameServ, u, "You can't carry that many!");
108 }
109 else
110 {
111 notice(s_GameServ, u, "%d %s's coming right up!", amt, tempItem->getItem()->getName().c_str());
112 user->stats->subtractGold(tempItem->getItem()->price() * amt);
113 }
114 }
115 else
116 {
117 if (user->stats->inventory->addItem(tempItem->getItem()) == NULL)
118 {
119 notice(s_GameServ, u, "You can't carry any more!");
120 }
121 else
122 {
123 notice(s_GameServ, u, "One %s coming right up!", tempItem->getItem()->getName().c_str());
124 user->stats->subtractGold(tempItem->getItem()->price());
125 }
126 }
127 }
128 }
129 else
130 {
131 notice(s_GameServ, u, "Improper Syntax.");
132 notice(s_GameServ, u, "Type /msg <S HELP TAVERN for help");
133 }
134 return;
135 }
136