]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
15 #if defined(HAVE_CRYPT_H)
19 #elif defined(HAVE_UNISTD_H)
26 Monster
* monsters
[ LEVELS
][ MONSTERS
]; // Monsters per level. Total = MONSTERS * LEVELS
27 Monster boss
; // The boss monster
29 Monster
* masters
[ LEVELS
]; // A master for each level
37 char * strtok ( char * str
, const char * delim
);
40 int stricmp ( const char * s1
, const char * s2
);
41 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
44 /********** Password functions **********/
46 bool passcmp ( char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
48 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
50 /********** Password functions **********/
53 /********** GameServ Booleans **********/
56 bool timedOut ( Player
* p
);
57 void updateTS ( Player
* p
);
58 void timeOutEvent ( Player
* p
);
60 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
61 bool is_playing ( aClient
* user
);
63 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
64 bool is_fighting ( aClient
* user
);
66 bool player_fight ( char * u
); // True if the player is fighting another player.
67 bool player_fight ( aClient
* user
);
69 bool master_fight ( char * u
); // True if the player is fighting their master.
70 bool master_fight ( aClient
* user
);
72 /********** GameServ Booleans **********/
74 void display_help ( char * u
, char * file
= NULL
);
75 void display_monster ( char * u
);
76 void display_players ( char * u
);
77 void display_players ( aClient
* user
);
78 long int chartoint ( char ch
);
79 int isstringnum ( char * num
);
80 long int pow ( int x
, int y
);
81 long int stringtoint ( char * number
);
83 char * spaces ( int len
, char * seperator
);
84 void refresh ( Player
* p
);
86 void updateTS ( Player
* p
);
87 void reset ( Player
* p
);
91 void delete_monsters ();
92 void delete_masters ();
94 void do_admin ( char * u
);
95 void do_attack ( char * u
);
96 void do_bank ( char * u
);
97 void do_fight ( char * u
);
98 void do_heal ( char * u
);
99 void do_help ( char * u
);
100 void do_identify ( char * u
);
101 void do_inventory ( char * u
);
102 void do_refresh ( char * u
);
103 void do_register ( char * u
);
104 void do_list ( char * u
);
105 void do_logout ( char * u
);
106 void do_master ( char * u
);
107 void do_dragon ( char * u
);
108 void do_play ( char * u
);
109 void do_quitg ( char * u
);
110 void do_reset ( char * u
);
111 void do_run ( char * u
);
112 void do_stats ( char * u
);
113 void do_store ( char * u
);
114 void do_tavern ( char * u
);
115 void do_use ( char * u
);
116 void see_master ( char * u
);
118 void logout ( aClient
* user
);
119 void showstats ( const char * u
, const char * nick
);
120 void showinventory ( aClient
* from
, aClient
* to
);
121 void showBankBalance ( const char * u
);
122 void end_turn ( aClient
* user
);
125 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
126 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
127 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
128 "Light Saber" , "Masamune" , "Mystical Sword" };
130 char * armors
[ WNA
] = { "Birthday Suit" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
131 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
132 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
133 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
135 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
136 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
137 int webonus
[ WNA
] = { 2 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
138 int arbonus
[ WNA
] = { 2 , 3 , 5 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
140 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
141 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
142 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
144 void gameserv ( char * source
, char * buf
)
147 cmd
= strtok ( buf
, " " );
150 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
155 cmd
++; // Get rid of that : at the beginning of the :text (command)
158 log ( "Source: %s Command: %s " , source
, cmd
);
166 int curday
= tm
-> tm_mday
;
171 clearNews ( todaysnews
);
173 save_day (); // here i come to save the day!
176 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
179 ts
= strtok ( NULL
, "\1" );
180 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
181 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
182 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
183 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
184 cmd
= strtok ( NULL
, " " );
187 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
191 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
193 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
195 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
197 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
199 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
201 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
202 do_inventory ( source
);
203 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
205 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
207 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
209 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
211 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
213 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
215 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
217 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
219 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
221 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
223 } else if ( stricmp ( cmd
, "NEWS" ) == 0 ) {
225 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
227 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
229 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
231 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
233 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
236 if (!( user
= find ( source
)))
238 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
239 log ( "Error: aClient not found: %s " , source
);
241 else if (! isAdmin ( user
))
243 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
249 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
251 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
255 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
258 if (!( user
= find ( source
)))
260 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
261 log ( "Error: aClient not found: %s " , source
);
263 else if (! isAdmin ( user
))
265 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
271 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
274 if (!( user
= find ( source
)))
276 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
277 log ( "Error: aClient not found: %s " , source
);
279 else if (! isAdmin ( user
))
281 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
285 char * cmd2
= strtok ( NULL
, " " );
288 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
291 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
293 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
297 display_help ( source
, cmd
);
300 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
303 if (!( user
= find ( source
)))
305 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
306 log ( "Error: aClient not found: %s " , source
);
308 else if (! isAdmin ( user
))
310 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
314 char * rest
= strtok ( NULL
, "" );
320 if (( user
= find ( source
)))
325 log ( "Ignoring %s ." , user
-> getNick ());
330 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
336 source
--; // Bring the ':' back so we don't leak memory
339 cmd
--; // Same thing :)
342 int stricmp ( const char * s1
, const char * s2
)
346 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
352 if ( c
< tolower (* s2
))
357 void showstats ( const char * u
, const char * nick
)
359 aClient
* ni
, * sender
= find ( u
);
365 if (!( ni
= findplayer ( nick
)))
367 notice ( s_GameServ
, u
, " %s not found" , nick
);
371 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
373 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
374 space
= spaces ( strlen ( buf
), " " );
375 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
379 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
380 space
= spaces ( strlen ( buf
), " " );
381 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
384 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
387 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
388 space
= spaces ( strlen ( buf
), " " );
389 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
390 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
393 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
394 space
= spaces ( strlen ( buf
), " " );
395 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
396 weapons
[ ni
-> stats
-> weapon
]);
399 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
400 space
= spaces ( strlen ( buf
), " " );
401 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
403 Pouch
* inv
= & ni
-> stats
-> inventory
;
405 notice ( s_GameServ
, u
, "Potions" );
406 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
407 space
= spaces ( strlen ( buf
), " " );
408 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
412 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
413 space
= spaces ( strlen ( buf
), " " );
414 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
415 space
, inv
-> Defense ());
420 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
425 char * spaces ( int len
, char * seperator
)
428 final
= new char [ 30 ];
430 strcpy ( final
, seperator
);
431 for ( y
= 0 ; y
< 30 - len
; y
++)
432 strcat ( final
, seperator
);
436 void raw ( const char * fmt
, ...)
441 input
= new char [ 1024 ];
443 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
449 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
450 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
451 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
454 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
459 sprintf ( input
, " %s%c " , input
, * t
);
464 log ( "Input: %s " , input
);
467 sprintf ( input
, " %s%s " , input
, " \r\n " );
468 sock_puts ( sock
, input
);
472 /* Send a NOTICE from the given source to the given nick. */
474 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
480 commanduse
= new char [ 16 ];
484 strcpy ( commanduse
, "P" );
486 strcpy ( commanduse
, "O" );
490 strcpy ( commanduse
, "PRIVMSG" );
492 strcpy ( commanduse
, "NOTICE" );
498 input
= new char [ 1024 ];
505 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
507 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
515 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
517 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
526 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
527 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
528 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
531 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
536 sprintf ( input
, " %s%c " , input
, * t
);
541 log ( "Input: %s " , input
);
543 sprintf ( input
, " %s%s " , input
, " \r\n " );
544 sock_puts ( sock
, input
);
545 delete [] commanduse
;
551 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
557 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
558 if ( c
== 0 || -- len
== 0 )
563 if ( c
< tolower (* s2
))
569 char * strtok ( char * str
, const char * delim
)
571 static char * current
= NULL
;
578 current
+= strspn ( current
, delim
);
579 ret
= * current
? current
: NULL
;
580 current
+= strcspn ( current
, delim
);
589 void do_list ( char * u
)
592 char * cmd
= strtok ( NULL
, " " );
594 if (!( user
= find ( u
)))
596 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
599 else if ( isIgnore ( user
))
602 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
607 ListNode
< aClient
> * temp
;
610 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
612 temp
= players
[ x
]. First ();
613 if (! players
[ x
]. isEmpty ())
617 if (! cmd
|| is_playing ( temp
-> getData ()))
621 notice ( s_GameServ
, u
, "Players:" );
625 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
626 temp
-> getData ()-> stats
-> name
);
628 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
629 temp
-> getData ()-> stats
-> name
);
638 notice ( s_GameServ
, u
, "No one is playing" );
640 notice ( s_GameServ
, u
, "End of List" );
644 void do_logout ( char * u
)
647 char * name
= strtok ( NULL
, " " );
649 if (!( user
= find ( u
)))
651 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
652 "Buf: %s LOGOUT" , u
);
653 log ( "Could not find aClient Buf: %s LOGOUT" ,
657 else if ( isIgnore ( user
))
660 log ( "Ignoring %s ." , user
-> getNick ());
669 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
671 else if (!( user
= findplayer ( name
)))
673 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
677 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
683 if (! is_playing ( user
))
685 notice ( s_GameServ
, u
, "You're not logged in!" );
687 else if ( is_fighting ( user
))
689 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
693 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
699 void logout ( aClient
* user
)
701 if ( is_playing ( user
))
703 ListNode
< aClient
> * it
;
705 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
706 it
= players
[ hv
]. Find ( user
);
710 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
711 " %S Admin. Cannot find you in the players list." );
712 log ( "Error on logout(). Can't find %s in the players list" ,
723 temp
-> stats
= new Player
;
724 temp
-> stats
-> setData ( user
-> stats
);
725 user
-> stats
-> client
= NULL
;
727 if ( player_fight ( user
))
728 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
732 temp
-> stats
-> client
= NULL
;
734 temp
-> setRealNick ( "Not Playing" );
736 temp
-> setNick ( "Not Playing" );
740 log ( "Logged out player %s " ,
752 void do_register ( char * u
)
754 char * password
, * name
;
756 name
= strtok ( NULL
, " " );
757 password
= strtok ( NULL
, " " );
759 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
762 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
763 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
768 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
772 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
774 else if (( user
= findplayer ( name
)))
776 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
777 notice ( s_GameServ
, u
, "Choose another name!" );
779 else if (!( user
= find ( u
)))
781 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
783 else if ( isIgnore ( user
))
786 log ( "Ignoring %s ." , user
-> getNick ());
792 if (! is_playing ( user
))
794 ListNode
< aClient
> * temp
;
795 user
-> stats
= new Player ( user
);
796 user
-> stats
-> client
= user
; // Set the backwards pointer
797 user
-> stats
-> reset (); // set the user up
798 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
799 strncpy ( user
-> stats
-> name
, name
, 255 );
800 unsigned long hv
= iHASH (( unsigned char *) name
);
801 updateTS ( user
-> stats
);
802 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
803 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
805 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
806 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
807 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
808 setPlaying ( user
); // set the playing flag
812 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
817 void do_identify ( char * u
)
819 char * password
, * name
;
821 name
= strtok ( NULL
, " " );
822 password
= strtok ( NULL
, " " );
823 if (! password
|| ! name
)
825 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
827 else if (!( user
= find ( u
)))
829 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
830 log ( "Error: aClient not found: %s " , u
);
832 else if ( isIgnore ( user
))
835 log ( "Ignoring %s ." , user
-> getNick ());
839 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
840 notice ( s_GameServ
, u
, "Player %s not found" , name
);
841 else if ( is_playing ( user
))
843 notice ( s_GameServ
, u
, "You are already playing!" );
845 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
847 notice ( s_GameServ
, u
, "That player has already identified." );
849 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
851 notice ( s_GameServ
, u
, "Password incorrect" );
854 ListNode
< aClient
> * temp
;
855 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
856 temp
= players
[ hv
]. Find ( p
);
859 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
863 user
-> stats
= new Player ( p
-> stats
-> name
);
865 log ( "Setting data for identified" );
867 user
-> stats
-> setData ( p
-> stats
);
868 user
-> stats
-> client
= user
;
869 updateTS ( user
-> stats
);
873 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
877 setPlaying ( user
); // set the playing flag
880 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
881 showNews ( u
, todaysnews
);
885 void do_stats ( char * u
)
890 nick
= strtok ( NULL
, " " );
892 if (!( user
= find ( u
)))
894 log ( "Fatal Error: %s not found in client list" , u
);
897 else if ( isIgnore ( user
))
900 log ( "Ignoring %s ." , user
-> getNick ());
906 if (! is_playing ( user
))
908 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
913 updateTS ( user
-> stats
);
914 showstats ( u
, user
-> stats
-> name
);
924 log ( "Calling delete_masters()" );
930 log ( "Initializing masters" );
933 for ( int x
= 0 ; x
< LEVELS
; x
++)
934 masters
[ x
] = new Monster
;
936 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
937 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
938 masters
[ 0 ]-> strength
= 32 ;
939 masters
[ 0 ]-> gold
= 0 ;
941 masters
[ 0 ]-> maxhp
= 35 ;
943 strcpy ( masters
[ 0 ]-> death
, "You have done well my student, but the road is long. Use your new strength with humility and honor as you progress in levels!" );
945 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
946 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
947 masters
[ 1 ]-> strength
= 48 ;
948 masters
[ 1 ]-> gold
= 0 ;
950 masters
[ 1 ]-> maxhp
= 51 ;
952 strcpy ( masters
[ 1 ]-> death
, "You try to make out what Master Chang is saying, but the only thing you catch is something about a grasshopper." );
954 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
955 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
956 masters
[ 2 ]-> strength
= 88 ;
957 masters
[ 2 ]-> gold
= 0 ;
959 masters
[ 2 ]-> maxhp
= 100 ;
960 masters
[ 2 ]-> hp
= 100 ;
961 strcpy ( masters
[ 2 ]-> death
, "Be strong, and keep your goals in site. Drink milk, and don't do drugs. One day you may be fighting next to me as a Texas Ranger YEEHAW!" );
964 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
965 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
966 masters
[ 3 ]-> strength
= 169 ;
967 masters
[ 3 ]-> gold
= 0 ;
969 masters
[ 3 ]-> maxhp
= 165 ;
970 masters
[ 3 ]-> hp
= 165 ;
971 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
973 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
974 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
975 masters
[ 4 ]-> strength
= 275 ;
976 masters
[ 4 ]-> gold
= 0 ;
978 masters
[ 4 ]-> maxhp
= 232 ;
979 masters
[ 4 ]-> hp
= 232 ;
980 strcpy ( masters
[ 4 ]-> death
, "I like to let people talk who like to talk... it's easier to find out how full of it they really are!" );
982 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
983 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
984 masters
[ 5 ]-> strength
= 347 ;
985 masters
[ 5 ]-> gold
= 0 ;
987 masters
[ 5 ]-> maxhp
= 504 ;
988 masters
[ 5 ]-> hp
= 504 ;
989 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
992 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
993 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
994 masters
[ 6 ]-> strength
= 515 ;
995 masters
[ 6 ]-> gold
= 0 ;
997 masters
[ 6 ]-> maxhp
= 1078 ;
998 masters
[ 6 ]-> hp
= 1078 ;
999 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
1001 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
1002 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
1003 masters
[ 7 ]-> strength
= 655 ;
1004 masters
[ 7 ]-> gold
= 0 ;
1005 masters
[ 7 ]-> exp
= 0 ;
1006 masters
[ 7 ]-> maxhp
= 2207 ;
1007 masters
[ 7 ]-> hp
= 2207 ;
1008 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
1011 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
1012 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
1013 masters
[ 8 ]-> strength
= 819 ;
1014 masters
[ 8 ]-> gold
= 0 ;
1015 masters
[ 8 ]-> exp
= 0 ;
1016 masters
[ 8 ]-> maxhp
= 2780 ;
1017 masters
[ 8 ]-> hp
= 2780 ;
1018 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1020 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1021 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1022 masters
[ 9 ]-> strength
= 1014 ;
1023 masters
[ 9 ]-> gold
= 0 ;
1024 masters
[ 9 ]-> exp
= 0 ;
1025 masters
[ 9 ]-> maxhp
= 3046 ;
1026 masters
[ 9 ]-> hp
= 3046 ;
1027 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1029 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1030 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1031 masters
[ 10 ]-> strength
= 1286 ;
1032 masters
[ 10 ]-> gold
= 0 ;
1033 masters
[ 10 ]-> exp
= 0 ;
1034 masters
[ 10 ]-> maxhp
= 3988 ;
1035 masters
[ 10 ]-> hp
= 3988 ;
1036 strcpy ( masters
[ 10 ]-> death
, "You must learn to concentrate. It is like a finger pointing away to the moon... DONT concentrate on the finger, or you will miss all the heavenly glory." );
1039 void init_monsters ()
1042 log ( "Calling delete_monsters" );
1047 for ( int x
= 0 ; x
< LEVELS
; x
++)
1048 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1049 monsters
[ x
][ y
] = new Monster ();
1052 void delete_monsters ()
1054 for ( int x
= 0 ; x
< LEVELS
; x
++)
1055 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1057 delete monsters
[ x
][ y
];
1060 void delete_masters ()
1062 for ( int x
= 0 ; x
< LEVELS
; x
++)
1067 void display_monster ( char * u
)
1071 aClient
* user
= find ( u
);
1072 Player
* ni
= user
-> stats
;
1074 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1075 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1076 notice ( s_GameServ
, u
, "Here are your commands:" );
1077 notice ( s_GameServ
, u
, "/msg %S attack" );
1078 notice ( s_GameServ
, u
, "/msg %S run" );
1079 notice ( s_GameServ
, u
, "What will you do?" );
1083 void display_players ( char * u
)
1086 if (!( user
= find ( u
)))
1088 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1091 display_players ( user
);
1094 void display_players ( aClient
* user
)
1096 char * u
= user
-> getNick ();
1097 if ( is_playing ( user
) && player_fight ( user
))
1099 aClient
* battle
= user
-> stats
-> battle
;
1100 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1101 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1102 notice ( s_GameServ
, u
, "Here are your commands:" );
1103 notice ( s_GameServ
, u
, "/msg %S attack" );
1104 notice ( s_GameServ
, u
, "/msg %S run" );
1105 notice ( s_GameServ
, u
, "What will you do?" );
1110 bool is_playing ( char * u
)
1113 if (!( user
= find ( u
)))
1116 return is_playing ( user
);
1119 bool is_playing ( aClient
* user
)
1121 if ( user
-> stats
== NULL
)
1125 else if ( user
-> stats
-> client
== NULL
)
1129 else if (! FL_is_playing ( user
))
1137 bool is_fighting ( char * u
)
1141 if (!( user
= find ( u
)))
1144 return is_fighting ( user
);
1147 bool is_fighting ( aClient
* user
)
1149 if (! is_playing ( user
))
1152 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1155 bool player_fight ( char * u
)
1159 if (!( user
= find ( u
)))
1162 return player_fight ( user
);
1165 bool player_fight ( aClient
* user
)
1167 if (! is_playing ( user
))
1169 else if ( user
-> stats
-> battle
!= NULL
)
1171 return user
-> stats
-> battle
-> stats
!= NULL
;
1176 bool master_fight ( char * u
)
1180 if (!( user
= find ( u
)))
1183 return master_fight ( user
);
1186 bool master_fight ( aClient
* user
)
1188 if (! is_playing ( user
))
1191 return user
-> stats
-> master
!= NULL
;
1194 void do_fight ( char * u
)
1196 aClient
* ni
, * battle
;
1198 char * nick
= strtok ( NULL
, " " );
1202 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1205 else if (!( ni
= find ( u
)))
1207 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1210 else if ( isIgnore ( ni
))
1213 log ( "Ignoring %s ." , ni
-> getNick ());
1217 else if (! is_playing ( ni
))
1219 notice ( s_GameServ
, u
, "You are not playing!" );
1223 updateTS ( ni
-> stats
);
1225 if ( ni
-> stats
-> player_fights
<= 0 )
1227 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1228 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1229 "day. You have to wait until tomorrow!" );
1231 else if (!( battle
= findplayer ( nick
)))
1233 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1235 else if (! isAlive ( ni
-> stats
))
1237 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1239 else if (! is_playing ( battle
))
1241 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1244 /* offline fighting not available yet
1245 else if (!(fight = finduser(nick)))
1247 ni->stats->battle = battle;
1248 battle->battle = ni;
1249 setYourTurn(ni->stats);
1250 clearYourTurn(battle->stats);
1252 notice(s_GameServ, u, "You decide to fight %s while they're "\
1253 "not in the realm!",
1254 battle->stats->name);
1258 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1260 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1262 else if (! isAlive ( battle
-> stats
))
1264 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1266 else if ( player_fight ( battle
))
1268 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1270 else if ( master_fight ( battle
))
1272 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1274 else if ( is_fighting ( battle
))
1276 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1278 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1280 // You can't fight someone below you by more than X level(s)
1281 // level 12 can fight level (12 - X) but not < (12 - X)
1282 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1283 battle
-> stats
-> name
);
1285 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1287 // You can't fight someone above you by more than X level(S)
1288 // level 1 can fight level (1 + X), but not > (1 + X)
1289 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1290 "weakling!" , ni
-> stats
-> name
);
1294 // Set your battle pointer to the other player
1295 ni
-> stats
-> battle
= battle
;
1297 // Set the other player's battle pointer to you
1298 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1300 // The initiator gets the first move (perhaps this should be 50/50)
1301 setYourTurn ( ni
-> stats
);
1302 clearYourTurn ( battle
-> stats
);
1304 // Initiate Battle sequence!
1305 ni
-> stats
-> player_fights
-= 1 ;
1307 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1308 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1309 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1310 "because they initiated!" , ni
-> stats
-> name
);
1311 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1312 display_players ( ni
);
1316 void do_use ( char * u
)
1321 char * item
= strtok ( NULL
, " " );
1325 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1326 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1329 else if (!( user
= find ( u
)))
1331 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1334 else if ( isIgnore ( user
))
1337 log ( "Ignoring %s ." , user
-> getNick ());
1341 else if (! is_playing ( user
))
1343 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1347 updateTS ( user
-> stats
);
1349 p
= & user
-> stats
-> inventory
;
1351 if ( stricmp ( item
, "HEALING" ) == 0 )
1353 if ( p
-> Healing () <= 0 )
1355 notice ( s_GameServ
, u
, "You are out of Healing Potions!" );
1358 int oldhealing
= user
-> stats
-> hp
;
1359 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1360 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1361 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1362 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1364 if ( player_fight ( user
))
1366 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1367 " %s has used a healing potion!" );
1370 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1372 if ( p
-> Strength () <= 0 )
1374 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1377 int oldstrength
= user
-> stats
-> strength
;
1378 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1379 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1380 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1381 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1383 if ( player_fight ( user
))
1385 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1386 " %s has used a strength potion!" );
1389 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1391 if ( p
-> Defense () <= 0 )
1393 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1396 int olddefense
= user
-> stats
-> defense
;
1397 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1398 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1399 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1400 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1402 if ( player_fight ( user
))
1404 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1405 " %s has used a defense potion!" );
1408 else if ( stricmp ( item
, "HP" ) == 0 )
1412 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1415 int oldHP
= user
-> stats
-> maxhp
;
1416 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1417 user
-> stats
-> maxhp
+= 2 +
1418 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1420 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1422 if ( player_fight ( user
))
1424 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1425 " %s has used a HP potion!" );
1430 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1434 end_turn ( user
); // If they're fighting, end their turn
1436 void do_run ( char * u
)
1439 Player
* p
, * p2
= NULL
;
1441 if (!( user
= find ( u
)))
1443 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1446 else if ( isIgnore ( user
))
1449 log ( "Ignoring %s ." , user
-> getNick ());
1453 else if (! is_playing ( user
))
1455 notice ( s_GameServ
, u
, "You must be playing to run!" );
1459 updateTS ( user
-> stats
);
1463 p2
= p
-> battle
-> stats
;
1465 if (! is_fighting ( user
))
1466 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1467 else if (! player_fight ( user
) && ! master_fight ( user
))
1469 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1473 else if ( player_fight ( user
) && isYourTurn ( p
))
1475 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1476 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1479 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1481 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1483 else if ( master_fight ( user
))
1485 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1490 void end_turn ( aClient
* user
)
1492 char * nick
, * u
= user
-> getNick ();
1497 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1499 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1502 if (! player_fight ( user
) && ! master_fight ( user
))
1503 fight
= user
-> stats
-> fight
;
1505 fight
= user
-> stats
-> master
;
1506 battle
= user
-> stats
-> battle
;
1508 if (! player_fight ( user
))
1511 mhit
= ( fight
-> strength
/ 2 ) +
1512 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1513 arbonus
[ user
-> stats
-> armor
]));
1518 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1519 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1520 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1522 if (! player_fight ( user
))
1527 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1528 fight
-> name
, fight
-> weapon
, mhit
);
1531 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1533 if ( mhit
>= user
-> stats
-> hp
)
1535 if (! master_fight ( user
))
1537 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1538 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1539 "of your experience!" );
1540 user
-> stats
-> gold
= 0 ;
1541 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1542 user
-> stats
-> hp
= 0 ;
1543 user
-> stats
-> fight
= NULL
;
1544 clearAlive ( user
-> stats
);
1549 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1550 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1551 user
-> stats
-> fight
= NULL
;
1552 user
-> stats
-> master
= NULL
;
1559 user
-> stats
-> hp
-= mhit
;
1566 clearYourTurn ( user
-> stats
);
1567 setYourTurn ( battle
-> stats
);
1568 display_players ( battle
);
1574 void do_attack ( char * u
)
1577 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1578 Monster
* fight
; // The monster they may be fighting
1580 if (!( ni
= find ( u
)))
1582 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1585 else if ( isIgnore ( ni
))
1588 log ( "Ignoring %s ." , ni
-> getNick ());
1592 else if (! is_playing ( ni
))
1594 notice ( s_GameServ
, u
, "You're not playing!" );
1597 else if (! is_fighting ( ni
))
1599 notice ( s_GameServ
, u
, "You're not in battle!" );
1604 if (! ni
-> stats
-> master
) // This is not a master fight
1605 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1606 else // This IS a master fight
1607 fight
= ni
-> stats
-> master
; // Master Could be NULL
1609 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1611 // One has to be !NULL based on the previous else if
1612 // We wouldn't be here if they were all NULL
1614 updateTS ( ni
-> stats
);
1616 if (! player_fight ( ni
))
1619 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1620 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1623 mhit
= ( fight
-> strength
/ 2 ) +
1624 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1625 arbonus
[ ni
-> stats
-> armor
]));
1630 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1631 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1632 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1635 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1636 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1637 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1640 if (! player_fight ( ni
))
1643 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1645 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1647 if ( hit
>= fight
-> hp
)
1649 if ( master_fight ( ni
))
1651 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1652 addNews ( todaysnews
, " %s has bested %s and moved " \
1653 "to level %d " , ni
-> stats
-> name
, fight
-> name
,
1654 ( ni
-> stats
-> level
+ 1 ));
1657 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1659 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1660 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1661 fight
-> exp
, fight
-> gold
);
1663 // If your new experience (or gold) will be greater than 2 billion,
1664 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1665 // This could be a problem with overflowing out of the sign bit.
1666 // Unsigned long int maybe? Leave it for now.
1667 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1668 ni
-> stats
-> exp
+ fight
-> exp
);
1670 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1671 ni
-> stats
-> gold
+ fight
-> gold
);
1674 if ( master_fight ( ni
))
1676 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1677 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1678 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1680 // Increase your level
1682 // Increase your maximum hit points
1683 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1685 // Heal the player by setting hp to their max
1686 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1688 // Add to your strength
1689 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1691 // Add to your defensive power
1692 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1696 // Clear the pointer for your master
1697 ni
-> stats
-> master
= NULL
;
1700 // They're dead so remove the pointer
1701 delete ni
-> stats
-> fight
;
1702 ni
-> stats
-> fight
= NULL
;
1703 ni
-> stats
-> master
= NULL
;
1713 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1714 fight
-> name
, fight
-> weapon
, mhit
);
1717 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1719 if ( mhit
>= ni
-> stats
-> hp
)
1721 if (! master_fight ( ni
))
1723 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1724 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1725 "of your experience!" );
1726 addNews ( todaysnews
, " %s has been killed by %s !" ,
1727 ni
-> stats
-> name
, fight
-> name
);
1728 ni
-> stats
-> gold
= 0 ;
1729 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1731 ni
-> stats
-> fight
= NULL
;
1732 clearAlive ( ni
-> stats
);
1737 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1738 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1739 addNews ( todaysnews
, " %s tried to best %s and failed!" ,
1740 ni
-> stats
-> name
, fight
-> name
);
1741 ni
-> stats
-> fight
= NULL
;
1742 ni
-> stats
-> master
= NULL
;
1749 ni
-> stats
-> hp
-= mhit
;
1755 else if ( player_fight ( ni
))
1757 /* Offline fighting not available yet
1758 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1761 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1763 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1764 if (hit >= battle->stats->hp)
1766 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1767 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1768 (long int)(battle->stats->exp * .10), battle->stats->gold);
1769 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1771 ni->stats->exp += (long int)(battle->stats->exp * .10);
1772 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1776 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1777 ni->stats->exp = 2000000000;
1780 if (2000000000 - ni->stats->gold > battle->stats->gold)
1782 * ni->stats->gold += battle->stats->gold;
1783 battle->stats->gold = 0;
1787 battle->stats->gold = 2000000000 - ni->stats->gold;
1788 ni->stats->gold = 2000000000;
1790 * ni->stats->battle->stats->alive = 0;
1791 ni->stats->battle->battle = NULL;
1792 ni->stats->battle = NULL;
1798 * battle->stats->hp -= hit;
1801 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1802 battle->nick, weapons[battle->stats->weapon], mhit);
1805 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1807 if (mhit >= ni->stats->hp)
1809 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1810 if (2000000000 - battle->stats->gold > ni->stats->gold)
1812 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1813 battle->stats->gold += ni->stats->gold;
1814 * ni->stats->gold = 0;
1818 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1820 ni->stats->gold -= (2000000000 - battle->stats->gold);
1821 notice(s_GameServ, u, "You were left dead with %d gold.",
1822 * (long int)ni->stats->gold);
1823 battle->stats->gold = 2000000000;
1825 ni->stats->battle->battle = NULL;
1826 ni->stats->battle = NULL;
1827 ni->stats->alive = 0;
1833 ni->stats->hp -= mhit;
1839 * end offline fighting */
1841 if ( is_playing ( battle
))
1843 if (! isYourTurn ( ni
-> stats
))
1845 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1846 battle
-> stats
-> name
);
1851 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1853 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1854 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1855 weapons
[ ni
-> stats
-> weapon
], hit
);
1859 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1860 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1863 if ( hit
>= battle
-> stats
-> hp
)
1865 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1866 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1867 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1868 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1870 battle
-> stats
-> hp
= 0 ;
1871 clearAlive ( battle
-> stats
);
1873 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1875 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1876 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1880 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1881 ni
-> stats
-> exp
= 2000000000 ;
1884 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1886 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1887 "all gold on hand!" );
1888 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1889 battle
-> stats
-> gold
= 0 ;
1893 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1894 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1896 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1897 "gold." , ni
-> stats
-> name
);
1899 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1900 "left. All is not lost!" , battle
-> stats
-> gold
);
1902 ni
-> stats
-> gold
= 2000000000 ;
1904 clearYourTurn ( ni
-> stats
);
1905 clearYourTurn ( battle
-> stats
);
1906 battle
-> stats
-> battle
= NULL
;
1907 ni
-> stats
-> battle
= NULL
;
1913 battle
-> stats
-> hp
-= hit
;
1914 clearYourTurn ( ni
-> stats
);
1915 setYourTurn ( battle
-> stats
);
1916 display_players ( battle
);
1917 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1918 battle
-> stats
-> name
);
1925 void do_heal ( char * u
)
1928 char * amount
= strtok ( NULL
, " " );
1933 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1936 else if (!( ni
= find ( u
)))
1938 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1941 else if ( isIgnore ( ni
))
1944 log ( "Ignoring %s ." , ni
-> getNick ());
1948 else if (! is_playing ( ni
))
1950 notice ( s_GameServ
, u
, "You aren't playing!" );
1953 else if (! isAlive ( ni
-> stats
))
1955 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1958 else if ( is_fighting ( ni
))
1960 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1963 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1965 notice ( s_GameServ
, u
, "You don't need healing!" );
1969 updateTS ( ni
-> stats
);
1970 if ( stricmp ( amount
, "ALL" ) == 0 )
1972 price
= ni
-> stats
-> level
* 3 ;
1973 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1975 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1976 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1977 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1978 ni
-> stats
-> gold
%= price
;
1982 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1983 "per point." , price
);
1984 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1985 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1986 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1987 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1988 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1991 else if ( isstringnum ( amount
))
1993 num
= stringtoint ( amount
);
1994 price
= ni
-> stats
-> level
* 3 ;
1995 if ( ni
-> stats
-> gold
< price
* num
)
1997 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1998 ( long int ) ni
-> stats
-> gold
/ price
);
2000 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2002 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2004 ni
-> stats
-> hp
+= num
;
2005 ni
-> stats
-> gold
-= num
* price
;
2007 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2009 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2010 "per point." , price
);
2011 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2012 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2013 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2014 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2017 else if ( amount
[ 0 ] == '-' )
2018 notice ( s_GameServ
, u
, "You trying to cheat?" );
2020 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2023 int isstringnum ( char * num
)
2026 for ( x
= 0 ; x
< strlen ( num
); x
++)
2028 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2034 long int stringtoint ( char * number
)
2036 long int x
, len
= strlen ( number
), sum
= 0 ;
2038 return chartoint ( number
[ 0 ]);
2039 sum
+= chartoint ( number
[ len
- 1 ]);
2040 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2041 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2045 long int pow ( int x
, int y
)
2051 if ( x
!= 0 && y
!= 0 )
2053 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2061 long int chartoint ( char ch
)
2063 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2064 return int ( ch
) - 48 ;
2071 ListNode
< aClient
> * ptr
;
2075 outfile
. open ( playerdata
);
2079 log ( "Error opening %s " , playerdata
);
2083 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2085 ptr
= players
[ x
]. First ();
2088 it
= ptr
-> getData ()-> stats
;
2090 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2091 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2092 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2093 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2094 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2095 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
2108 char * tempname
, * buf
, * password
;
2109 buf
= new char [ 1023 ];
2111 infile
. open ( playerdata
);
2115 log ( "Error opening %s " , playerdata
);
2119 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2122 tempname
= strtok ( buf
, " " );
2123 temp
-> stats
= new Player ( tempname
);
2126 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2127 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2128 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2129 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2130 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2131 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2132 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2133 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2134 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2135 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2136 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2137 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2138 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2140 password
= strtok ( NULL
, " " );
2141 strcpy ( p
-> password
, password
);
2142 temp
-> setNick ( "Not Playing" );
2144 temp
-> setRealNick ( "Not Playing" );
2147 p
-> inventory
. reset (); // Set inventory to all 0s
2148 // Old player databases didn't have these three extra values
2149 // If they come up null, leave them to 0 as the default.
2150 // On the next gameserv database save, it will save the values.
2151 tempname
= strtok ( NULL
, " " );
2153 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2155 tempname
= strtok ( NULL
, " " );
2157 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2159 tempname
= strtok ( NULL
, " " );
2161 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2163 tempname
= strtok ( NULL
, " " );
2165 p
-> inventory
. setHP ( stringtoint ( tempname
));
2166 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2168 temp
-> stats
-> client
= NULL
;
2169 players
[ hv
]. insertAtBack ( temp
);
2177 bool passcmp ( char * encrypted
, char * plaintext
)
2180 char * plaintext2
, * plainToencrypt
;
2183 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2184 strcpy ( plaintext2
, plaintext
);
2186 salt
[ 0 ] = encrypted
[ 0 ];
2187 salt
[ 1 ] = encrypted
[ 1 ];
2190 plainToencrypt
= crypt ( plaintext2
, salt
);
2192 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2194 delete [] plaintext2
;
2199 bool check_password ( char * name
, char * plaintext
)
2203 if (!( client
= findplayer ( name
)))
2207 return passcmp ( client
-> stats
-> password
, plaintext
);
2211 void do_store ( char * u
)
2213 char * cmd
= strtok ( NULL
, " " );
2214 char * item
= strtok ( NULL
, " " );
2215 char * num
= strtok ( NULL
, " " );
2223 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2224 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2225 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2228 else if (!( user
= find ( u
)))
2230 log ( "Fatal Error: could not find %s in client list" , u
);
2233 else if ( isIgnore ( user
))
2236 log ( "Ignoring %s ." , user
-> getNick ());
2240 else if (! is_playing ( user
))
2242 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2245 else if (! isAlive ( user
-> stats
))
2247 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2250 updateTS ( user
-> stats
);
2252 if ( stricmp ( cmd
, "LIST" ) == 0 )
2254 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2256 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2257 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2258 for ( int x
= 1 ; x
< WNA
; x
++)
2260 space
= spaces ( strlen ( weapons
[ x
]), "." );
2261 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2264 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2265 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2268 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2270 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2271 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2272 for ( int x
= 1 ; x
< WNA
; x
++)
2274 space
= spaces ( strlen ( armors
[ x
]), "." );
2275 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2278 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2279 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2283 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2286 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2289 else if (! isstringnum ( num
))
2291 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2294 if ( stricmp ( item
, "WEAPON" ) == 0 )
2296 wep
= stringtoint ( num
);
2297 if ( wep
>= WNA
|| wep
< 1 )
2299 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2306 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2307 else if ( p
-> gold
< prices
[ wep
- 1 ])
2308 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2311 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2313 p
-> gold
-= prices
[ wep
- 1 ];
2316 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2318 wep
= stringtoint ( num
);
2319 if ( wep
>= WNA
|| wep
< 1 )
2321 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2328 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2329 else if ( p
-> gold
< prices
[ wep
- 1 ])
2330 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2333 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2335 p
-> gold
-= prices
[ wep
- 1 ];
2339 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2343 if ( stricmp ( item
, "WEAPON" ) == 0 )
2347 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2350 else if ( p
-> gold
== 2000000000 )
2352 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2355 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2357 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2358 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2359 p
-> gold
= 2000000000 ;
2364 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2365 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2369 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2375 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2378 if ( p
-> gold
== 2000000000 )
2380 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2383 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2385 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2386 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2387 p
-> gold
= 2000000000 ;
2392 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2393 ( prices
[ p
-> armor
- 1 ] / 2 ));
2395 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2401 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2402 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2403 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2408 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2409 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2410 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2414 void do_inventory ( char * u
)
2418 if (!( user
= find ( u
)))
2420 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2423 else if ( isIgnore ( user
))
2426 log ( "Ignoring %s ." , user
-> getNick ());
2430 else if (! is_playing ( user
))
2432 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2435 updateTS ( user
-> stats
);
2436 showinventory ( user
, user
);
2438 void showinventory ( aClient
* from
, aClient
* to
)
2440 char * nick
= to
-> getNick ();
2444 if ( is_playing ( from
))
2446 Pouch
* p
= & from
-> stats
-> inventory
;
2447 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2448 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2449 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2450 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2451 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2454 void do_tavern ( char * u
)
2456 char * cmd
= strtok ( NULL
, " " );
2462 if (!( user
= find ( u
)))
2464 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2467 else if ( isIgnore ( user
))
2470 log ( "Ignoring %s ." , user
-> getNick ());
2474 else if (! is_playing ( user
))
2476 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2479 else if ( is_fighting ( user
))
2481 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2485 updateTS ( user
-> stats
);
2490 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2491 notice ( s_GameServ
, u
, "Your commands:" );
2492 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2493 notice ( s_GameServ
, u
, "What'll it be?" );
2495 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2497 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2498 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2499 1000 * p
-> level
* 4 );
2500 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2501 2500 * p
-> level
* 4 );
2502 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2503 3000 * p
-> level
* 4 );
2504 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2505 2000 * p
-> level
* 4 );
2506 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2507 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2509 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2511 char * chnum
= strtok ( NULL
, " " );
2512 int num
= stringtoint ( chnum
);
2516 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2517 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2520 if ( num
< 1 || num
> 4 )
2522 notice ( s_GameServ
, u
, "Invalid Choice!" );
2523 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2524 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2525 1000 * p
-> level
* 4 );
2526 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2527 2500 * p
-> level
* 4 );
2528 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2529 3000 * p
-> level
* 4 );
2530 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2531 2000 * p
-> level
* 4 );
2532 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2533 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2539 price
= ( 1000 * p
-> level
* 4 );
2540 if ( p
-> gold
>= price
)
2542 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2543 p
-> inventory
. incHealing ();
2547 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2550 price
= 2500 * p
-> level
* 4 ;
2551 if ( p
-> gold
>= price
)
2553 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2554 p
-> inventory
. incStrength ();
2558 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2561 price
= 3000 * p
-> level
* 4 ;
2562 if ( p
-> gold
>= price
)
2564 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2565 p
-> inventory
. incDefense ();
2569 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2572 price
= 3000 * p
-> level
* 4 ;
2573 if ( p
-> gold
>= price
)
2575 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2576 p
-> inventory
. incHP ();
2580 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2583 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2589 notice ( s_GameServ
, u
, "Improper Syntax." );
2590 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2594 void do_bank ( char * u
)
2596 char * cmd
= strtok ( NULL
, " " );
2597 char * amount
= strtok ( NULL
, " " );
2598 char * nick
= strtok ( NULL
, " " );
2603 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2605 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2606 notice ( s_GameServ
, u
, "BANK BALANCE" );
2609 else if (!( user
= find ( u
)))
2611 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2613 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2616 else if ( isIgnore ( user
))
2619 log ( "Ignoring %s ." , user
-> getNick ());
2623 else if (! is_playing ( user
))
2625 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2628 else if ( is_fighting ( user
))
2630 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2633 updateTS ( user
-> stats
);
2634 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2639 else if (! isAlive ( user
-> stats
))
2641 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2644 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2646 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2652 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2654 if ( p
-> bank
== 2000000000 )
2656 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2659 else if ( stricmp ( amount
, "ALL" ) == 0 )
2661 if ( 2000000000 - p
-> bank
< p
-> gold
)
2663 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2664 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2665 p
-> gold
-= ( 2000000000 - p
-> bank
);
2666 p
-> bank
= 2000000000 ;
2671 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2677 else if ( stringtoint ( amount
) > p
-> gold
)
2679 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2685 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2687 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2688 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2689 p
-> gold
-= ( 2000000000 - p
-> bank
);
2690 p
-> bank
= 2000000000 ;
2695 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2696 p
-> bank
+= stringtoint ( amount
);
2697 p
-> gold
-= stringtoint ( amount
);
2702 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2704 if ( p
-> gold
== 2000000000 )
2706 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2710 else if ( stricmp ( amount
, "ALL" ) == 0 )
2712 if ( 2000000000 - p
-> gold
< p
-> bank
)
2714 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2715 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2716 p
-> bank
-= ( 2000000000 - p
-> gold
);
2717 p
-> gold
= 2000000000 ;
2722 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2728 else if ( stringtoint ( amount
) > p
-> bank
)
2730 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2736 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2738 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2739 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2740 ( 2000000000 - p
-> gold
));
2741 p
-> bank
-= ( 2000000000 - p
-> gold
);
2742 p
-> gold
= 2000000000 ;
2747 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2748 p
-> gold
+= stringtoint ( amount
);
2749 p
-> bank
-= stringtoint ( amount
);
2757 void do_dragon ( char * u
)
2761 if (!( user
= find ( u
)))
2763 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2766 else if ( isIgnore ( user
))
2769 log ( "Ignoring %s ." , user
-> getNick ());
2773 else if (! is_playing ( user
))
2775 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2778 else if ( is_fighting ( user
))
2780 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2783 else if (! isAlive ( user
-> stats
))
2785 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2788 else if ( user
-> stats
-> level
< REALLEVELS
)
2790 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2791 "to vanquish any foe should DARE fight the dragon!" );
2792 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2793 "You are too weak. You must be Level %d !" , REALLEVELS
);
2797 updateTS ( user
-> stats
);
2799 Player
* p
= user
-> stats
;
2800 p
-> fight
= new Monster ( boss
);
2801 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2802 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2803 "deep, red fog rolls in. The air is filled with the " \
2804 "heated mist of deadly fire from beyond the cave " \
2806 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2807 "your %s , and venture into the hot, dark cave. " \
2808 "You are surprised at the angle of descent as you climb " \
2809 "lower and lower, deeper into the dragon's den." );
2810 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2811 "a tooth. It is a large tooth... bigger than your torso." \
2812 " Suddenly the darkness lifts from the gleam of an eye " \
2813 " staring into your soul! The eye is large... HUGE!" );
2814 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2815 "glare orange! The tooth is moving... but it is still too " \
2816 "dark for you to make out.... THE DRAGON! You see it!" );
2820 void do_master ( char * u
)
2825 if (!( user
= find ( u
)))
2827 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2830 else if ( isIgnore ( user
))
2833 log ( "Ignoring %s ." , user
-> getNick ());
2837 else if (! is_playing ( user
))
2839 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2842 else if ( is_fighting ( user
))
2844 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2847 else if (! isAlive ( user
-> stats
))
2849 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2853 updateTS ( user
-> stats
);
2855 char * cmd
= strtok ( NULL
, " " );
2856 Player
* p
= user
-> stats
;
2861 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2905 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
2909 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2915 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2919 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2927 notice ( s_GameServ
, u
, "You are not worthy of fighting %s ! You need %l d more experience." , masters
[ p
-> level
- 1 ]-> name
, ( need
- p
-> exp
));
2930 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2933 notice ( s_GameServ
, u
, " %s looks you up and down and decides you are more ready than you will ever be." , masters
[ p
-> level
- 1 ]-> name
);
2935 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2941 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2945 void see_master ( char * u
)
2949 if (!( user
= find ( u
)))
2951 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2955 if (! is_fighting ( user
) && is_playing ( user
))
2957 Player
* p
= user
-> stats
;
2958 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2959 p
-> fight
= p
-> master
;
2960 display_monster ( u
); // Since master is the same structure, use this function
2964 void showBankBalance ( const char * u
)
2969 if (!( user
= find ( u
)))
2977 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2983 ListNode
< aClient
> * it
;
2985 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2987 it
= players
[ x
]. First ();
2991 p
= it
-> getData ()-> stats
;
2998 void refresh ( Player
* p
)
3003 if ( p
-> hp
< p
-> maxhp
)
3005 p
-> forest_fights
= forestfights
;
3006 p
-> player_fights
= 3 ;
3011 void do_refresh ( char * u
)
3013 char * nick
= strtok ( NULL
, " " );
3016 if (!( user
= find ( u
)))
3018 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3019 log ( "Error: aClient not found: %s " , u
);
3022 else if ( isIgnore ( user
))
3025 log ( "Ignoring %s ." , user
-> getNick ());
3029 else if (! isAdmin ( user
))
3031 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3036 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3039 else if ( stricmp ( nick
, "ALL" ) == 0 )
3041 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3044 else if (( user
= findplayer ( nick
)))
3046 if ( is_playing ( user
))
3049 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3051 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3053 refresh ( user
-> stats
);
3058 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3060 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3066 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3074 ListNode
< aClient
> * it
;
3077 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3079 it
= players
[ x
]. First ();
3083 p
= it
-> getData ()-> stats
;
3090 void reset ( Player
* p
)
3098 void updateTS ( Player
* p
)
3104 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3106 p
-> lastcommand
= time ( NULL
);
3108 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3113 bool timedOut ( Player
* p
)
3117 else if ( p
-> lastcommand
== 0 )
3121 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3128 void timeOutEvent ( Player
* p
)
3130 aClient
* user
= findplayer ( p
-> name
);
3132 if (! user
|| ! p
-> client
) // then they're not playing
3135 char * nick
= user
-> getNick ();
3137 if ( player_fight ( user
) && isYourTurn ( p
))
3139 // Check to see if they were the idler or if it was the other
3141 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3143 // This person's last command was given earlier,
3144 // so this person is the idler
3145 notice ( s_GameServ
, nick
, "You timed out " \
3146 "during a fight. You lose your turn!" );
3147 notice ( s_GameServ
, p
-> battle
-> getNick (),
3148 " %s hesitated for too long. Your move." , p
-> name
);
3150 setYourTurn ( p
-> battle
-> stats
);
3152 // Update the TS for both players to give them another
3153 // Chance to wake up, but if the other player doesn't
3154 // Attack now, they both get logged out.
3156 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3157 display_players ( p
-> battle
);
3162 notice ( s_GameServ
, p
-> battle
-> getNick (),
3163 "You and %s timed out at the same time." \
3164 " Don't fight if you're just going to " \
3165 "sit there!" , p
-> name
);
3166 notice ( s_GameServ
, user
-> getNick (),
3167 "You and %s timed out at the same time." \
3168 " Don't fight if you're just going to " \
3169 "sit there!" , p
-> battle
-> stats
-> name
);
3175 else if (! player_fight ( user
))
3177 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3179 // Place fun stuff here :)
3180 int randnum
= 1 + rand () % 100 ; // 1-100
3181 #define GSN(s) notice(s_GameServ, nick, s)
3182 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3186 // 35-100% of your gold goes pffft - kain
3187 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3189 GSN ( "You stop for a moment to rest on the " \
3190 "street corner. All of a sudden, you " \
3191 "are ambushed from all sides by a hoarde " \
3192 "of knife wielding thugs." );
3193 GSN2 ( "The thugs beat you into utter submission " \
3194 "and steal %d gold from you!" , stolen
);
3195 user
-> stats
-> gold
-= stolen
;
3197 else if ( randnum
>= 50 && randnum
< 75 )
3199 // 25-65% of your gold goes pffft - kain
3200 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3201 GSN ( "While dilly dallying around, you lose " \
3202 "your sense of time. Little did you know, " \
3203 "but thieves lifted your gold while you " \
3204 "weren't watching." );
3205 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3206 user
-> stats
-> gold
-= stolen
;
3208 else if ( randnum
>= 75 )
3210 // 25-75% of your gold goes pffft - kain
3211 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3212 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3213 "goblins grabbed your gold!" );
3214 GSN2 ( "They stole %d gold from you!" , stolen
);
3215 user
-> stats
-> gold
-= stolen
;
3219 // Always log out the user
3224 void do_reset ( char * u
)
3226 char * nick
= strtok ( NULL
, " " );
3229 if (!( user
= find ( u
)))
3231 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3232 log ( "Error: aClient not found: %s " , u
);
3235 else if (! isAdmin ( user
))
3237 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3243 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3246 else if ( stricmp ( nick
, "ALL" ) == 0 )
3248 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3251 else if (( user
= findbyrealnick ( nick
)))
3253 if ( is_playing ( user
))
3256 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3258 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3265 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3267 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3273 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3278 void do_help ( char * u
)
3280 char * cmd
= strtok ( NULL
, " " );
3282 display_help ( u
, cmd
);
3285 void display_help ( char * u
, char * file
)
3292 infile
. open ( "helpfiles/help" );
3295 log ( "Error opening helpfiles/help" );
3296 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3299 buf
= new char [ 1024 ];
3300 while ( infile
. getline ( buf
, 1024 ))
3302 // Written this way, it will process %S in the helpfiles
3303 // Instead of notice(s_GameServ, u, "%s", buf);
3304 notice ( s_GameServ
, u
, buf
);
3308 aClient
* user
= find ( u
);
3309 if ( user
&& isAdmin ( user
))
3310 display_help ( u
, "admin_commands" );
3315 filename
= new char [ strlen ( file
) + 11 ];
3316 strcpy ( filename
, "helpfiles/" );
3317 strcat ( filename
, file
);
3319 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3320 filename
[ x
] = tolower ( filename
[ x
]);
3322 infile
. open ( filename
);
3326 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3329 buf
= new char [ 1024 ];
3330 while ( infile
. getline ( buf
, 1024 ))
3332 // Written this way, it will process %S in the helpfiles
3333 // Instead of notice(s_GameServ, u, "%s", buf);
3334 notice ( s_GameServ
, u
, buf
);
3341 void do_admin ( char * u
)
3344 char * pass
= strtok ( NULL
, " " );
3346 if (!( user
= find ( u
)))
3348 log ( "Error: aClient not found: %s " , u
);
3349 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3355 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3361 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3364 else if ( strcmp ( pass
, adminpass
) == 0 )
3366 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3369 log ( " %s became an administrator." , user
-> getRealNick ());
3371 log ( " %s became an administrator." , user
-> getNick ());
3376 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3381 bool load_monsters ()
3384 infile
. open ( "monsters.dat" );
3390 log ( "Error opening monsters.dat" );
3394 buf
= new char [ 2048 ];
3397 log ( "Loading monsters from monsters.dat" );
3400 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3402 for ( int m
= 0 ; m
< MONSTERS
;)
3404 infile
. getline ( buf
, 2048 );
3405 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3409 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3410 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3411 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3412 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3413 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3414 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3415 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3416 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));