]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_fight.cpp
Removed GameServ.suo
[irc/gameservirc.git] / gameserv / do_fight.cpp
1 #include "extern.h"
2 #include "aClient.h"
3 #include "player.h"
4 #include "options.h"
5 #include "flags.h"
6
7 void do_fight(char *u)
8 {
9 aClient *ni;
10 Player *battle;
11
12 char *nick = strtok(NULL, " ");
13
14 if (!nick)
15 {
16 notice(s_GameServ, u, "SYNTAX: /msg <S FIGHT PLAYER");
17 return;
18 }
19 else if (!(ni = find(u)))
20 {
21 notice(s_GameServ, u, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL, ""));
22 return;
23 }
24 else if (isIgnore(ni))
25 {
26 #ifdef DEBUGMODE
27 log("Ignoring %s.", ni->getNick());
28 #endif
29 return;
30 }
31 else if (!is_playing(ni))
32 {
33 notice(s_GameServ, u, "You are not playing!");
34 return;
35 }
36
37 updateTS(ni->stats);
38
39 if (ni->stats->getPlayerFights() <= 0)
40 {
41 ni->stats->setPlayerFights(0); // just to be safe
42 notice(s_GameServ, u, "You are out of player fights for the "\
43 "day. You have to wait until tomorrow!");
44 }
45 else if (!(battle = findplayer(nick)))
46 {
47 notice(s_GameServ, u, "Player %s not found!", nick);
48 }
49 else if (!isAlive(ni->stats))
50 {
51 notice(s_GameServ, u, "You are dead. Wait until tomorrow to fight others!");
52 }
53 else if (!is_playing(battle->getClient()))
54 {
55 notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick);
56 }
57
58 /* offline fighting not available yet
59 else if (!(fight = finduser(nick)))
60 {
61 ni->stats->battle = battle;
62 battle->battle = ni;
63 setYourTurn(ni->stats);
64 clearYourTurn(battle->stats);
65
66 notice(s_GameServ, u, "You decide to fight %s while they're "\
67 "not in the realm!",
68 battle->stats->name.c_str());
69 display_players(u);
70 }
71 */
72 else if (stricmp(ni->stats->getName().c_str(), battle->getName().c_str()) == 0)
73 {
74 notice(s_GameServ, u, "Are you trying to commit suicide!?");
75 }
76 else if (!isAlive(battle))
77 {
78 notice(s_GameServ, u, "They are dead. Cannot fight dead players!");
79 }
80 else if (player_fight(battle->getClient()))
81 {
82 notice(s_GameServ, u, "%s is fighting %s already!", battle->getName().c_str(), battle->getBattle()->stats->getName().c_str());
83 }
84 else if (master_fight(battle->getClient()))
85 {
86 notice(s_GameServ, u, "%s is fighting their master!", battle->getName().c_str());
87 }
88 else if (is_fighting(battle->getClient()))
89 {
90 notice(s_GameServ, u, "%s is fighting %s already!", battle->getName().c_str(), battle->getMonster()->name.c_str());
91 }
92 else if (!isAdmin(ni) && isFairFights() && (ni->stats->getStrength()/2 - battle->getDefense()) > battle->getHP())
93 {
94 notice(s_GameServ, u, "Fair fighting is enabled, and you're too strong for %s!", battle->getName().c_str());
95 }
96 else if (ni->stats->getLevel() - battle->getLevel() > maxbfightdistance)
97 {
98 // You can't fight someone below you by more than X level(s)
99 // level 12 can fight level (12 - X) but not < (12 - X)
100 notice(s_GameServ, u, "You may not fight %s. You're too strong!",
101 battle->getName().c_str());
102 }
103 else if (battle->getLevel() - ni->stats->getLevel() > maxafightdistance)
104 {
105 // You can't fight someone above you by more than X level(S)
106 // level 1 can fight level (1 + X), but not > (1 + X)
107 notice(s_GameServ, u, "%s, do you really have a death wish? Try the forest you "\
108 "weakling!", ni->stats->getName().c_str());
109 }
110 else
111 {
112 // Set your battle pointer to the other player
113 ni->stats->setBattle(battle->getClient());
114
115 // Set the other player's battle pointer to you
116 battle->setBattle(ni);
117
118 // The initiator gets the first move (perhaps this should be 50/50)
119 setYourTurn(ni->stats);
120 clearYourTurn(battle);
121
122 // Initiate Battle sequence!
123 ni->stats->subtractPlayerFights(1);
124
125 notice(s_GameServ, u, "You challenge %s to an online duel!", battle->getName().c_str());
126 notice(s_GameServ, c_Forest, "%s walks up and hits %s in the face! Let's see who will bite the dust.",
127 ni->stats->getName().c_str(), battle->getName().c_str()); /* DrLnet - Modified by Kain*/
128
129 notice(s_GameServ, battle->getClient()->getNick(), "%s has challenged you to an online duel!", ni->stats->getName().c_str());
130 notice(s_GameServ, battle->getClient()->getNick(), "%s gets to go first "\
131 "because they initiated!", ni->stats->getName().c_str());
132 notice(s_GameServ, battle->getClient()->getNick(), "Please wait while %s decides what to do.", ni->stats->getName().c_str());
133 display_players(ni);
134 }
135 }