]>
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
;
172 save_day (); // here i come to save the day!
175 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
178 ts
= strtok ( NULL
, "\1" );
179 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
180 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
181 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
182 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
183 cmd
= strtok ( NULL
, " " );
186 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
190 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
192 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
194 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
196 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
200 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
201 do_inventory ( source
);
202 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
204 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
208 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
212 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
214 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
216 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
220 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
222 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
224 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
226 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
228 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
230 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
233 if (!( user
= find ( source
)))
235 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
236 log ( "Error: aClient not found: %s " , source
);
238 else if (! isAdmin ( user
))
240 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
246 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
248 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
252 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
255 if (!( user
= find ( source
)))
257 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
258 log ( "Error: aClient not found: %s " , source
);
260 else if (! isAdmin ( user
))
262 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
268 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
271 if (!( user
= find ( source
)))
273 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
274 log ( "Error: aClient not found: %s " , source
);
276 else if (! isAdmin ( user
))
278 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
282 char * cmd2
= strtok ( NULL
, " " );
285 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
288 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
290 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
294 display_help ( source
, cmd
);
297 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
300 if (!( user
= find ( source
)))
302 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
303 log ( "Error: aClient not found: %s " , source
);
305 else if (! isAdmin ( user
))
307 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
311 char * rest
= strtok ( NULL
, "" );
317 if (( user
= find ( source
)))
322 log ( "Ignoring %s ." , user
-> getNick ());
327 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
333 source
--; // Bring the ':' back so we don't leak memory
336 cmd
--; // Same thing :)
339 int stricmp ( const char * s1
, const char * s2
)
343 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
349 if ( c
< tolower (* s2
))
354 void showstats ( const char * u
, const char * nick
)
356 aClient
* ni
, * sender
= find ( u
);
362 if (!( ni
= findplayer ( nick
)))
364 notice ( s_GameServ
, u
, " %s not found" , nick
);
368 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
370 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
371 space
= spaces ( strlen ( buf
), " " );
372 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
376 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
377 space
= spaces ( strlen ( buf
), " " );
378 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
381 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
384 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
385 space
= spaces ( strlen ( buf
), " " );
386 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
387 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
390 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
391 space
= spaces ( strlen ( buf
), " " );
392 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
393 weapons
[ ni
-> stats
-> weapon
]);
396 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
397 space
= spaces ( strlen ( buf
), " " );
398 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
400 Pouch
* inv
= & ni
-> stats
-> inventory
;
402 notice ( s_GameServ
, u
, "Potions" );
403 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
404 space
= spaces ( strlen ( buf
), " " );
405 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
409 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
410 space
= spaces ( strlen ( buf
), " " );
411 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
412 space
, inv
-> Defense ());
417 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
422 char * spaces ( int len
, char * seperator
)
425 final
= new char [ 30 ];
427 strcpy ( final
, seperator
);
428 for ( y
= 0 ; y
< 30 - len
; y
++)
429 strcat ( final
, seperator
);
433 void raw ( const char * fmt
, ...)
438 input
= new char [ 1024 ];
440 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
446 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
447 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
448 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
451 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
456 sprintf ( input
, " %s%c " , input
, * t
);
461 log ( "Input: %s " , input
);
464 sprintf ( input
, " %s%s " , input
, " \r\n " );
465 sock_puts ( sock
, input
);
469 /* Send a NOTICE from the given source to the given nick. */
471 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
477 commanduse
= new char [ 16 ];
481 strcpy ( commanduse
, "P" );
483 strcpy ( commanduse
, "O" );
487 strcpy ( commanduse
, "PRIVMSG" );
489 strcpy ( commanduse
, "NOTICE" );
495 input
= new char [ 1024 ];
502 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
504 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
512 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
514 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
523 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
524 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
525 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
528 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
533 sprintf ( input
, " %s%c " , input
, * t
);
538 log ( "Input: %s " , input
);
540 sprintf ( input
, " %s%s " , input
, " \r\n " );
541 sock_puts ( sock
, input
);
542 delete [] commanduse
;
548 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
554 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
555 if ( c
== 0 || -- len
== 0 )
560 if ( c
< tolower (* s2
))
566 char * strtok ( char * str
, const char * delim
)
568 static char * current
= NULL
;
575 current
+= strspn ( current
, delim
);
576 ret
= * current
? current
: NULL
;
577 current
+= strcspn ( current
, delim
);
586 void do_list ( char * u
)
589 char * cmd
= strtok ( NULL
, " " );
591 if (!( user
= find ( u
)))
593 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
596 else if ( isIgnore ( user
))
599 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
604 ListNode
< aClient
> * temp
;
607 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
609 temp
= players
[ x
]. First ();
610 if (! players
[ x
]. isEmpty ())
614 if (! cmd
|| is_playing ( temp
-> getData ()))
618 notice ( s_GameServ
, u
, "Players:" );
622 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
623 temp
-> getData ()-> stats
-> name
);
625 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
626 temp
-> getData ()-> stats
-> name
);
635 notice ( s_GameServ
, u
, "No one is playing" );
637 notice ( s_GameServ
, u
, "End of List" );
641 void do_logout ( char * u
)
644 char * name
= strtok ( NULL
, " " );
646 if (!( user
= find ( u
)))
648 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
649 "Buf: %s LOGOUT" , u
);
650 log ( "Could not find aClient Buf: %s LOGOUT" ,
654 else if ( isIgnore ( user
))
657 log ( "Ignoring %s ." , user
-> getNick ());
666 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
668 else if (!( user
= findplayer ( name
)))
670 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
674 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
680 if (! is_playing ( user
))
682 notice ( s_GameServ
, u
, "You're not logged in!" );
684 else if ( is_fighting ( user
))
686 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
690 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
696 void logout ( aClient
* user
)
698 if ( is_playing ( user
))
700 ListNode
< aClient
> * it
;
702 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
703 it
= players
[ hv
]. Find ( user
);
707 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
708 " %S Admin. Cannot find you in the players list." );
709 log ( "Error on logout(). Can't find %s in the players list" ,
720 temp
-> stats
= new Player
;
721 temp
-> stats
-> setData ( user
-> stats
);
722 user
-> stats
-> client
= NULL
;
724 if ( player_fight ( user
))
725 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
729 temp
-> stats
-> client
= NULL
;
731 temp
-> setRealNick ( "Not Playing" );
733 temp
-> setNick ( "Not Playing" );
737 log ( "Logged out player %s " ,
749 void do_register ( char * u
)
751 char * password
, * name
;
753 name
= strtok ( NULL
, " " );
754 password
= strtok ( NULL
, " " );
756 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
759 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
760 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
765 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
769 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
771 else if (( user
= findplayer ( name
)))
773 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
774 notice ( s_GameServ
, u
, "Choose another name!" );
776 else if (!( user
= find ( u
)))
778 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
780 else if ( isIgnore ( user
))
783 log ( "Ignoring %s ." , user
-> getNick ());
789 if (! is_playing ( user
))
791 ListNode
< aClient
> * temp
;
792 user
-> stats
= new Player ( user
);
793 user
-> stats
-> client
= user
; // Set the backwards pointer
794 user
-> stats
-> reset (); // set the user up
795 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
796 strncpy ( user
-> stats
-> name
, name
, 255 );
797 unsigned long hv
= iHASH (( unsigned char *) name
);
798 updateTS ( user
-> stats
);
799 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
800 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
802 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
803 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
804 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
805 setPlaying ( user
); // set the playing flag
809 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
814 void do_identify ( char * u
)
816 char * password
, * name
;
818 name
= strtok ( NULL
, " " );
819 password
= strtok ( NULL
, " " );
820 if (! password
|| ! name
)
822 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
824 else if (!( user
= find ( u
)))
826 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
827 log ( "Error: aClient not found: %s " , u
);
829 else if ( isIgnore ( user
))
832 log ( "Ignoring %s ." , user
-> getNick ());
836 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
837 notice ( s_GameServ
, u
, "Player %s not found" , name
);
838 else if ( is_playing ( user
))
840 notice ( s_GameServ
, u
, "You are already playing!" );
842 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
844 notice ( s_GameServ
, u
, "That player has already identified." );
846 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
848 notice ( s_GameServ
, u
, "Password incorrect" );
851 ListNode
< aClient
> * temp
;
852 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
853 temp
= players
[ hv
]. Find ( p
);
856 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
860 user
-> stats
= new Player ( p
-> stats
-> name
);
862 log ( "Setting data for identified" );
864 user
-> stats
-> setData ( p
-> stats
);
865 user
-> stats
-> client
= user
;
866 updateTS ( user
-> stats
);
870 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
874 setPlaying ( user
); // set the playing flag
877 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
878 showNews ( u
, todaysnews
);
882 void do_stats ( char * u
)
887 nick
= strtok ( NULL
, " " );
889 if (!( user
= find ( u
)))
891 log ( "Fatal Error: %s not found in client list" , u
);
894 else if ( isIgnore ( user
))
897 log ( "Ignoring %s ." , user
-> getNick ());
903 if (! is_playing ( user
))
905 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
910 updateTS ( user
-> stats
);
911 showstats ( u
, user
-> stats
-> name
);
921 log ( "Calling delete_masters()" );
927 log ( "Initializing masters" );
930 for ( int x
= 0 ; x
< LEVELS
; x
++)
931 masters
[ x
] = new Monster
;
933 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
934 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
935 masters
[ 0 ]-> strength
= 32 ;
936 masters
[ 0 ]-> gold
= 0 ;
938 masters
[ 0 ]-> maxhp
= 35 ;
940 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!" );
942 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
943 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
944 masters
[ 1 ]-> strength
= 48 ;
945 masters
[ 1 ]-> gold
= 0 ;
947 masters
[ 1 ]-> maxhp
= 51 ;
949 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." );
951 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
952 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
953 masters
[ 2 ]-> strength
= 88 ;
954 masters
[ 2 ]-> gold
= 0 ;
956 masters
[ 2 ]-> maxhp
= 100 ;
957 masters
[ 2 ]-> hp
= 100 ;
958 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!" );
961 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
962 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
963 masters
[ 3 ]-> strength
= 169 ;
964 masters
[ 3 ]-> gold
= 0 ;
966 masters
[ 3 ]-> maxhp
= 165 ;
967 masters
[ 3 ]-> hp
= 165 ;
968 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
970 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
971 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
972 masters
[ 4 ]-> strength
= 275 ;
973 masters
[ 4 ]-> gold
= 0 ;
975 masters
[ 4 ]-> maxhp
= 232 ;
976 masters
[ 4 ]-> hp
= 232 ;
977 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!" );
979 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
980 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
981 masters
[ 5 ]-> strength
= 347 ;
982 masters
[ 5 ]-> gold
= 0 ;
984 masters
[ 5 ]-> maxhp
= 504 ;
985 masters
[ 5 ]-> hp
= 504 ;
986 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
989 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
990 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
991 masters
[ 6 ]-> strength
= 515 ;
992 masters
[ 6 ]-> gold
= 0 ;
994 masters
[ 6 ]-> maxhp
= 1078 ;
995 masters
[ 6 ]-> hp
= 1078 ;
996 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
998 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
999 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
1000 masters
[ 7 ]-> strength
= 655 ;
1001 masters
[ 7 ]-> gold
= 0 ;
1002 masters
[ 7 ]-> exp
= 0 ;
1003 masters
[ 7 ]-> maxhp
= 2207 ;
1004 masters
[ 7 ]-> hp
= 2207 ;
1005 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
1008 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
1009 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
1010 masters
[ 8 ]-> strength
= 819 ;
1011 masters
[ 8 ]-> gold
= 0 ;
1012 masters
[ 8 ]-> exp
= 0 ;
1013 masters
[ 8 ]-> maxhp
= 2780 ;
1014 masters
[ 8 ]-> hp
= 2780 ;
1015 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1017 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1018 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1019 masters
[ 9 ]-> strength
= 1014 ;
1020 masters
[ 9 ]-> gold
= 0 ;
1021 masters
[ 9 ]-> exp
= 0 ;
1022 masters
[ 9 ]-> maxhp
= 3046 ;
1023 masters
[ 9 ]-> hp
= 3046 ;
1024 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1026 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1027 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1028 masters
[ 10 ]-> strength
= 1286 ;
1029 masters
[ 10 ]-> gold
= 0 ;
1030 masters
[ 10 ]-> exp
= 0 ;
1031 masters
[ 10 ]-> maxhp
= 3988 ;
1032 masters
[ 10 ]-> hp
= 3988 ;
1033 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." );
1036 void init_monsters ()
1039 log ( "Calling delete_monsters" );
1044 for ( int x
= 0 ; x
< LEVELS
; x
++)
1045 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1046 monsters
[ x
][ y
] = new Monster ();
1049 void delete_monsters ()
1051 for ( int x
= 0 ; x
< LEVELS
; x
++)
1052 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1054 delete monsters
[ x
][ y
];
1057 void delete_masters ()
1059 for ( int x
= 0 ; x
< LEVELS
; x
++)
1064 void display_monster ( char * u
)
1068 aClient
* user
= find ( u
);
1069 Player
* ni
= user
-> stats
;
1071 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1072 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1073 notice ( s_GameServ
, u
, "Here are your commands:" );
1074 notice ( s_GameServ
, u
, "/msg %S attack" );
1075 notice ( s_GameServ
, u
, "/msg %S run" );
1076 notice ( s_GameServ
, u
, "What will you do?" );
1080 void display_players ( char * u
)
1083 if (!( user
= find ( u
)))
1085 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1088 display_players ( user
);
1091 void display_players ( aClient
* user
)
1093 char * u
= user
-> getNick ();
1094 if ( is_playing ( user
) && player_fight ( user
))
1096 aClient
* battle
= user
-> stats
-> battle
;
1097 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1098 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1099 notice ( s_GameServ
, u
, "Here are your commands:" );
1100 notice ( s_GameServ
, u
, "/msg %S attack" );
1101 notice ( s_GameServ
, u
, "/msg %S run" );
1102 notice ( s_GameServ
, u
, "What will you do?" );
1107 bool is_playing ( char * u
)
1110 if (!( user
= find ( u
)))
1113 return is_playing ( user
);
1116 bool is_playing ( aClient
* user
)
1118 if ( user
-> stats
== NULL
)
1122 else if ( user
-> stats
-> client
== NULL
)
1126 else if (! FL_is_playing ( user
))
1134 bool is_fighting ( char * u
)
1138 if (!( user
= find ( u
)))
1141 return is_fighting ( user
);
1144 bool is_fighting ( aClient
* user
)
1146 if (! is_playing ( user
))
1149 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1152 bool player_fight ( char * u
)
1156 if (!( user
= find ( u
)))
1159 return player_fight ( user
);
1162 bool player_fight ( aClient
* user
)
1164 if (! is_playing ( user
))
1166 else if ( user
-> stats
-> battle
!= NULL
)
1168 return user
-> stats
-> battle
-> stats
!= NULL
;
1173 bool master_fight ( char * u
)
1177 if (!( user
= find ( u
)))
1180 return master_fight ( user
);
1183 bool master_fight ( aClient
* user
)
1185 if (! is_playing ( user
))
1188 return user
-> stats
-> master
!= NULL
;
1191 void do_fight ( char * u
)
1193 aClient
* ni
, * battle
;
1195 char * nick
= strtok ( NULL
, " " );
1199 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1202 else if (!( ni
= find ( u
)))
1204 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1207 else if ( isIgnore ( ni
))
1210 log ( "Ignoring %s ." , ni
-> getNick ());
1214 else if (! is_playing ( ni
))
1216 notice ( s_GameServ
, u
, "You are not playing!" );
1220 updateTS ( ni
-> stats
);
1222 if ( ni
-> stats
-> player_fights
<= 0 )
1224 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1225 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1226 "day. You have to wait until tomorrow!" );
1228 else if (!( battle
= findplayer ( nick
)))
1230 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1232 else if (! isAlive ( ni
-> stats
))
1234 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1236 else if (! is_playing ( battle
))
1238 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1241 /* offline fighting not available yet
1242 else if (!(fight = finduser(nick)))
1244 ni->stats->battle = battle;
1245 battle->battle = ni;
1246 setYourTurn(ni->stats);
1247 clearYourTurn(battle->stats);
1249 notice(s_GameServ, u, "You decide to fight %s while they're "\
1250 "not in the realm!",
1251 battle->stats->name);
1255 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1257 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1259 else if (! isAlive ( battle
-> stats
))
1261 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1263 else if ( player_fight ( battle
))
1265 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1267 else if ( master_fight ( battle
))
1269 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1271 else if ( is_fighting ( battle
))
1273 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1275 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1277 // You can't fight someone below you by more than X level(s)
1278 // level 12 can fight level (12 - X) but not < (12 - X)
1279 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1280 battle
-> stats
-> name
);
1282 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1284 // You can't fight someone above you by more than X level(S)
1285 // level 1 can fight level (1 + X), but not > (1 + X)
1286 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1287 "weakling!" , ni
-> stats
-> name
);
1291 // Set your battle pointer to the other player
1292 ni
-> stats
-> battle
= battle
;
1294 // Set the other player's battle pointer to you
1295 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1297 // The initiator gets the first move (perhaps this should be 50/50)
1298 setYourTurn ( ni
-> stats
);
1299 clearYourTurn ( battle
-> stats
);
1301 // Initiate Battle sequence!
1302 ni
-> stats
-> player_fights
-= 1 ;
1304 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1305 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1306 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1307 "because they initiated!" , ni
-> stats
-> name
);
1308 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1309 display_players ( ni
);
1313 void do_use ( char * u
)
1318 char * item
= strtok ( NULL
, " " );
1322 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1323 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1326 else if (!( user
= find ( u
)))
1328 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1331 else if ( isIgnore ( user
))
1334 log ( "Ignoring %s ." , user
-> getNick ());
1338 else if (! is_playing ( user
))
1340 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1344 updateTS ( user
-> stats
);
1346 p
= & user
-> stats
-> inventory
;
1348 if ( stricmp ( item
, "HEALING" ) == 0 )
1350 if ( p
-> Healing () <= 0 )
1352 notice ( s_GameServ
, u
, "You are out of Healing Potions!" );
1355 int oldhealing
= user
-> stats
-> hp
;
1356 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1357 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1358 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1359 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1361 if ( player_fight ( user
))
1363 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1364 " %s has used a healing potion!" );
1367 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1369 if ( p
-> Strength () <= 0 )
1371 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1374 int oldstrength
= user
-> stats
-> strength
;
1375 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1376 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1377 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1378 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1380 if ( player_fight ( user
))
1382 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1383 " %s has used a strength potion!" );
1386 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1388 if ( p
-> Defense () <= 0 )
1390 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1393 int olddefense
= user
-> stats
-> defense
;
1394 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1395 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1396 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1397 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1399 if ( player_fight ( user
))
1401 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1402 " %s has used a defense potion!" );
1405 else if ( stricmp ( item
, "HP" ) == 0 )
1409 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1412 int oldHP
= user
-> stats
-> maxhp
;
1413 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1414 user
-> stats
-> maxhp
+= 2 +
1415 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1417 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1419 if ( player_fight ( user
))
1421 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1422 " %s has used a HP potion!" );
1427 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1431 end_turn ( user
); // If they're fighting, end their turn
1433 void do_run ( char * u
)
1436 Player
* p
, * p2
= NULL
;
1438 if (!( user
= find ( u
)))
1440 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1443 else if ( isIgnore ( user
))
1446 log ( "Ignoring %s ." , user
-> getNick ());
1450 else if (! is_playing ( user
))
1452 notice ( s_GameServ
, u
, "You must be playing to run!" );
1456 updateTS ( user
-> stats
);
1460 p2
= p
-> battle
-> stats
;
1462 if (! is_fighting ( user
))
1463 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1464 else if (! player_fight ( user
) && ! master_fight ( user
))
1466 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1470 else if ( player_fight ( user
) && isYourTurn ( p
))
1472 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1473 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1476 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1478 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1480 else if ( master_fight ( user
))
1482 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1487 void end_turn ( aClient
* user
)
1489 char * nick
, * u
= user
-> getNick ();
1494 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1496 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1499 if (! player_fight ( user
) && ! master_fight ( user
))
1500 fight
= user
-> stats
-> fight
;
1502 fight
= user
-> stats
-> master
;
1503 battle
= user
-> stats
-> battle
;
1505 if (! player_fight ( user
))
1508 mhit
= ( fight
-> strength
/ 2 ) +
1509 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1510 arbonus
[ user
-> stats
-> armor
]));
1515 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1516 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1517 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1519 if (! player_fight ( user
))
1524 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1525 fight
-> name
, fight
-> weapon
, mhit
);
1528 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1530 if ( mhit
>= user
-> stats
-> hp
)
1532 if (! master_fight ( user
))
1534 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1535 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1536 "of your experience!" );
1537 user
-> stats
-> gold
= 0 ;
1538 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1539 user
-> stats
-> hp
= 0 ;
1540 user
-> stats
-> fight
= NULL
;
1541 clearAlive ( user
-> stats
);
1546 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1547 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1548 user
-> stats
-> fight
= NULL
;
1549 user
-> stats
-> master
= NULL
;
1556 user
-> stats
-> hp
-= mhit
;
1563 clearYourTurn ( user
-> stats
);
1564 setYourTurn ( battle
-> stats
);
1565 display_players ( battle
);
1571 void do_attack ( char * u
)
1574 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1575 Monster
* fight
; // The monster they may be fighting
1577 if (!( ni
= find ( u
)))
1579 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1582 else if ( isIgnore ( ni
))
1585 log ( "Ignoring %s ." , ni
-> getNick ());
1589 else if (! is_playing ( ni
))
1591 notice ( s_GameServ
, u
, "You're not playing!" );
1594 else if (! is_fighting ( ni
))
1596 notice ( s_GameServ
, u
, "You're not in battle!" );
1601 if (! ni
-> stats
-> master
) // This is not a master fight
1602 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1603 else // This IS a master fight
1604 fight
= ni
-> stats
-> master
; // Master Could be NULL
1606 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1608 // One has to be !NULL based on the previous else if
1609 // We wouldn't be here if they were all NULL
1611 updateTS ( ni
-> stats
);
1613 if (! player_fight ( ni
))
1616 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1617 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1620 mhit
= ( fight
-> strength
/ 2 ) +
1621 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1622 arbonus
[ ni
-> stats
-> armor
]));
1627 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1628 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1629 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1632 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1633 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1634 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1637 if (! player_fight ( ni
))
1640 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1642 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1644 if ( hit
>= fight
-> hp
)
1646 if ( master_fight ( ni
))
1648 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1649 addNews ( todaysnews
, " %s has bested %s and moved " \
1650 "to level %d " , ni
-> stats
-> name
, fight
-> name
,
1651 ( ni
-> stats
-> level
+ 1 ));
1654 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1656 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1657 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1658 fight
-> exp
, fight
-> gold
);
1660 // If your new experience (or gold) will be greater than 2 billion,
1661 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1662 // This could be a problem with overflowing out of the sign bit.
1663 // Unsigned long int maybe? Leave it for now.
1664 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1665 ni
-> stats
-> exp
+ fight
-> exp
);
1667 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1668 ni
-> stats
-> gold
+ fight
-> gold
);
1671 if ( master_fight ( ni
))
1673 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1674 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1675 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1677 // Increase your level
1679 // Increase your maximum hit points
1680 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1682 // Heal the player by setting hp to their max
1683 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1685 // Add to your strength
1686 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1688 // Add to your defensive power
1689 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1693 // Clear the pointer for your master
1694 ni
-> stats
-> master
= NULL
;
1697 // They're dead so remove the pointer
1698 delete ni
-> stats
-> fight
;
1699 ni
-> stats
-> fight
= NULL
;
1700 ni
-> stats
-> master
= NULL
;
1710 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1711 fight
-> name
, fight
-> weapon
, mhit
);
1714 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1716 if ( mhit
>= ni
-> stats
-> hp
)
1718 if (! master_fight ( ni
))
1720 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1721 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1722 "of your experience!" );
1723 addNews ( todaysnews
, " %s has been killed by %s !" ,
1724 ni
-> stats
-> name
, fight
-> name
);
1725 ni
-> stats
-> gold
= 0 ;
1726 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1728 ni
-> stats
-> fight
= NULL
;
1729 clearAlive ( ni
-> stats
);
1734 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1735 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1736 addNews ( todaysnews
, " %s tried to best %s and failed!" ,
1737 ni
-> stats
-> name
, fight
-> name
);
1738 ni
-> stats
-> fight
= NULL
;
1739 ni
-> stats
-> master
= NULL
;
1746 ni
-> stats
-> hp
-= mhit
;
1752 else if ( player_fight ( ni
))
1754 /* Offline fighting not available yet
1755 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1758 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1760 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1761 if (hit >= battle->stats->hp)
1763 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1764 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1765 (long int)(battle->stats->exp * .10), battle->stats->gold);
1766 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1768 ni->stats->exp += (long int)(battle->stats->exp * .10);
1769 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1773 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1774 ni->stats->exp = 2000000000;
1777 if (2000000000 - ni->stats->gold > battle->stats->gold)
1779 * ni->stats->gold += battle->stats->gold;
1780 battle->stats->gold = 0;
1784 battle->stats->gold = 2000000000 - ni->stats->gold;
1785 ni->stats->gold = 2000000000;
1787 * ni->stats->battle->stats->alive = 0;
1788 ni->stats->battle->battle = NULL;
1789 ni->stats->battle = NULL;
1795 * battle->stats->hp -= hit;
1798 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1799 battle->nick, weapons[battle->stats->weapon], mhit);
1802 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1804 if (mhit >= ni->stats->hp)
1806 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1807 if (2000000000 - battle->stats->gold > ni->stats->gold)
1809 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1810 battle->stats->gold += ni->stats->gold;
1811 * ni->stats->gold = 0;
1815 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1817 ni->stats->gold -= (2000000000 - battle->stats->gold);
1818 notice(s_GameServ, u, "You were left dead with %d gold.",
1819 * (long int)ni->stats->gold);
1820 battle->stats->gold = 2000000000;
1822 ni->stats->battle->battle = NULL;
1823 ni->stats->battle = NULL;
1824 ni->stats->alive = 0;
1830 ni->stats->hp -= mhit;
1836 * end offline fighting */
1838 if ( is_playing ( battle
))
1840 if (! isYourTurn ( ni
-> stats
))
1842 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1843 battle
-> stats
-> name
);
1848 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1850 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1851 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1852 weapons
[ ni
-> stats
-> weapon
], hit
);
1856 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1857 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1860 if ( hit
>= battle
-> stats
-> hp
)
1862 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1863 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1864 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1865 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1867 battle
-> stats
-> hp
= 0 ;
1868 clearAlive ( battle
-> stats
);
1870 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1872 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1873 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1877 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1878 ni
-> stats
-> exp
= 2000000000 ;
1881 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1883 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1884 "all gold on hand!" );
1885 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1886 battle
-> stats
-> gold
= 0 ;
1890 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1891 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1893 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1894 "gold." , ni
-> stats
-> name
);
1896 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1897 "left. All is not lost!" , battle
-> stats
-> gold
);
1899 ni
-> stats
-> gold
= 2000000000 ;
1901 clearYourTurn ( ni
-> stats
);
1902 clearYourTurn ( battle
-> stats
);
1903 battle
-> stats
-> battle
= NULL
;
1904 ni
-> stats
-> battle
= NULL
;
1910 battle
-> stats
-> hp
-= hit
;
1911 clearYourTurn ( ni
-> stats
);
1912 setYourTurn ( battle
-> stats
);
1913 display_players ( battle
);
1914 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1915 battle
-> stats
-> name
);
1922 void do_heal ( char * u
)
1925 char * amount
= strtok ( NULL
, " " );
1930 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1933 else if (!( ni
= find ( u
)))
1935 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1938 else if ( isIgnore ( ni
))
1941 log ( "Ignoring %s ." , ni
-> getNick ());
1945 else if (! is_playing ( ni
))
1947 notice ( s_GameServ
, u
, "You aren't playing!" );
1950 else if (! isAlive ( ni
-> stats
))
1952 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1955 else if ( is_fighting ( ni
))
1957 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1960 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1962 notice ( s_GameServ
, u
, "You don't need healing!" );
1966 updateTS ( ni
-> stats
);
1967 if ( stricmp ( amount
, "ALL" ) == 0 )
1969 price
= ni
-> stats
-> level
* 3 ;
1970 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1972 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1973 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1974 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1975 ni
-> stats
-> gold
%= price
;
1979 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1980 "per point." , price
);
1981 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1982 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1983 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1984 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1985 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1988 else if ( isstringnum ( amount
))
1990 num
= stringtoint ( amount
);
1991 price
= ni
-> stats
-> level
* 3 ;
1992 if ( ni
-> stats
-> gold
< price
* num
)
1994 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1995 ( long int ) ni
-> stats
-> gold
/ price
);
1997 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1999 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2001 ni
-> stats
-> hp
+= num
;
2002 ni
-> stats
-> gold
-= num
* price
;
2004 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2006 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2007 "per point." , price
);
2008 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2009 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2010 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2011 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2014 else if ( amount
[ 0 ] == '-' )
2015 notice ( s_GameServ
, u
, "You trying to cheat?" );
2017 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2020 int isstringnum ( char * num
)
2023 for ( x
= 0 ; x
< strlen ( num
); x
++)
2025 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2031 long int stringtoint ( char * number
)
2033 long int x
, len
= strlen ( number
), sum
= 0 ;
2035 return chartoint ( number
[ 0 ]);
2036 sum
+= chartoint ( number
[ len
- 1 ]);
2037 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2038 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2042 long int pow ( int x
, int y
)
2048 if ( x
!= 0 && y
!= 0 )
2050 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2058 long int chartoint ( char ch
)
2060 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2061 return int ( ch
) - 48 ;
2068 ListNode
< aClient
> * ptr
;
2072 outfile
. open ( playerdata
);
2076 log ( "Error opening %s " , playerdata
);
2080 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2082 ptr
= players
[ x
]. First ();
2085 it
= ptr
-> getData ()-> stats
;
2087 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2088 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2089 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2090 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2091 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2092 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
2105 char * tempname
, * buf
, * password
;
2106 buf
= new char [ 1023 ];
2108 infile
. open ( playerdata
);
2112 log ( "Error opening %s " , playerdata
);
2116 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2119 tempname
= strtok ( buf
, " " );
2120 temp
-> stats
= new Player ( tempname
);
2123 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2124 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2125 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2126 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2127 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2128 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2129 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2130 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2131 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2132 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2133 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2134 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2135 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2137 password
= strtok ( NULL
, " " );
2138 strcpy ( p
-> password
, password
);
2139 temp
-> setNick ( "Not Playing" );
2141 temp
-> setRealNick ( "Not Playing" );
2144 p
-> inventory
. reset (); // Set inventory to all 0s
2145 // Old player databases didn't have these three extra values
2146 // If they come up null, leave them to 0 as the default.
2147 // On the next gameserv database save, it will save the values.
2148 tempname
= strtok ( NULL
, " " );
2150 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2152 tempname
= strtok ( NULL
, " " );
2154 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2156 tempname
= strtok ( NULL
, " " );
2158 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2160 tempname
= strtok ( NULL
, " " );
2162 p
-> inventory
. setHP ( stringtoint ( tempname
));
2163 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2165 temp
-> stats
-> client
= NULL
;
2166 players
[ hv
]. insertAtBack ( temp
);
2174 bool passcmp ( char * encrypted
, char * plaintext
)
2177 char * plaintext2
, * plainToencrypt
;
2180 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2181 strcpy ( plaintext2
, plaintext
);
2183 salt
[ 0 ] = encrypted
[ 0 ];
2184 salt
[ 1 ] = encrypted
[ 1 ];
2187 plainToencrypt
= crypt ( plaintext2
, salt
);
2189 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2191 delete [] plaintext2
;
2196 bool check_password ( char * name
, char * plaintext
)
2200 if (!( client
= findplayer ( name
)))
2204 return passcmp ( client
-> stats
-> password
, plaintext
);
2208 void do_store ( char * u
)
2210 char * cmd
= strtok ( NULL
, " " );
2211 char * item
= strtok ( NULL
, " " );
2212 char * num
= strtok ( NULL
, " " );
2220 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2221 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2222 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2225 else if (!( user
= find ( u
)))
2227 log ( "Fatal Error: could not find %s in client list" , u
);
2230 else if ( isIgnore ( user
))
2233 log ( "Ignoring %s ." , user
-> getNick ());
2237 else if (! is_playing ( user
))
2239 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2242 else if (! isAlive ( user
-> stats
))
2244 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2247 updateTS ( user
-> stats
);
2249 if ( stricmp ( cmd
, "LIST" ) == 0 )
2251 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2253 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2254 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2255 for ( int x
= 1 ; x
< WNA
; x
++)
2257 space
= spaces ( strlen ( weapons
[ x
]), "." );
2258 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2261 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2262 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2265 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2267 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2268 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2269 for ( int x
= 1 ; x
< WNA
; x
++)
2271 space
= spaces ( strlen ( armors
[ x
]), "." );
2272 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2275 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2276 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2280 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2283 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2286 else if (! isstringnum ( num
))
2288 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2291 if ( stricmp ( item
, "WEAPON" ) == 0 )
2293 wep
= stringtoint ( num
);
2294 if ( wep
>= WNA
|| wep
< 1 )
2296 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2303 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2304 else if ( p
-> gold
< prices
[ wep
- 1 ])
2305 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2308 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2310 p
-> gold
-= prices
[ wep
- 1 ];
2313 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2315 wep
= stringtoint ( num
);
2316 if ( wep
>= WNA
|| wep
< 1 )
2318 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2325 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2326 else if ( p
-> gold
< prices
[ wep
- 1 ])
2327 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2330 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2332 p
-> gold
-= prices
[ wep
- 1 ];
2336 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2340 if ( stricmp ( item
, "WEAPON" ) == 0 )
2344 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2347 else if ( p
-> gold
== 2000000000 )
2349 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2352 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2354 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2355 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2356 p
-> gold
= 2000000000 ;
2361 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2362 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2366 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2372 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2375 if ( p
-> gold
== 2000000000 )
2377 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2380 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2382 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2383 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2384 p
-> gold
= 2000000000 ;
2389 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2390 ( prices
[ p
-> armor
- 1 ] / 2 ));
2392 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2398 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2399 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2400 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2405 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2406 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2407 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2411 void do_inventory ( char * u
)
2415 if (!( user
= find ( u
)))
2417 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2420 else if ( isIgnore ( user
))
2423 log ( "Ignoring %s ." , user
-> getNick ());
2427 else if (! is_playing ( user
))
2429 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2432 updateTS ( user
-> stats
);
2433 showinventory ( user
, user
);
2435 void showinventory ( aClient
* from
, aClient
* to
)
2437 char * nick
= to
-> getNick ();
2441 if ( is_playing ( from
))
2443 Pouch
* p
= & from
-> stats
-> inventory
;
2444 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2445 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2446 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2447 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2448 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2451 void do_tavern ( char * u
)
2453 char * cmd
= strtok ( NULL
, " " );
2459 if (!( user
= find ( u
)))
2461 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2464 else if ( isIgnore ( user
))
2467 log ( "Ignoring %s ." , user
-> getNick ());
2471 else if (! is_playing ( user
))
2473 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2476 else if ( is_fighting ( user
))
2478 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2482 updateTS ( user
-> stats
);
2487 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2488 notice ( s_GameServ
, u
, "Your commands:" );
2489 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2490 notice ( s_GameServ
, u
, "What'll it be?" );
2492 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2494 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2495 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2496 1000 * p
-> level
* 4 );
2497 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2498 2500 * p
-> level
* 4 );
2499 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2500 3000 * p
-> level
* 4 );
2501 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2502 2000 * p
-> level
* 4 );
2503 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2504 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2506 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2508 char * chnum
= strtok ( NULL
, " " );
2509 int num
= stringtoint ( chnum
);
2513 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2514 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2517 if ( num
< 1 || num
> 4 )
2519 notice ( s_GameServ
, u
, "Invalid Choice!" );
2520 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2521 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2522 1000 * p
-> level
* 4 );
2523 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2524 2500 * p
-> level
* 4 );
2525 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2526 3000 * p
-> level
* 4 );
2527 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2528 2000 * p
-> level
* 4 );
2529 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2530 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2536 price
= ( 1000 * p
-> level
* 4 );
2537 if ( p
-> gold
>= price
)
2539 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2540 p
-> inventory
. incHealing ();
2544 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2547 price
= 2500 * p
-> level
* 4 ;
2548 if ( p
-> gold
>= price
)
2550 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2551 p
-> inventory
. incStrength ();
2555 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2558 price
= 3000 * p
-> level
* 4 ;
2559 if ( p
-> gold
>= price
)
2561 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2562 p
-> inventory
. incDefense ();
2566 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2569 price
= 3000 * p
-> level
* 4 ;
2570 if ( p
-> gold
>= price
)
2572 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2573 p
-> inventory
. incHP ();
2577 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2580 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2586 notice ( s_GameServ
, u
, "Improper Syntax." );
2587 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2591 void do_bank ( char * u
)
2593 char * cmd
= strtok ( NULL
, " " );
2594 char * amount
= strtok ( NULL
, " " );
2595 char * nick
= strtok ( NULL
, " " );
2600 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2602 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2603 notice ( s_GameServ
, u
, "BANK BALANCE" );
2606 else if (!( user
= find ( u
)))
2608 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2610 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2613 else if ( isIgnore ( user
))
2616 log ( "Ignoring %s ." , user
-> getNick ());
2620 else if (! is_playing ( user
))
2622 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2625 else if ( is_fighting ( user
))
2627 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2630 updateTS ( user
-> stats
);
2631 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2636 else if (! isAlive ( user
-> stats
))
2638 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2641 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2643 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2649 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2651 if ( p
-> bank
== 2000000000 )
2653 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2656 else if ( stricmp ( amount
, "ALL" ) == 0 )
2658 if ( 2000000000 - p
-> bank
< p
-> gold
)
2660 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2661 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2662 p
-> gold
-= ( 2000000000 - p
-> bank
);
2663 p
-> bank
= 2000000000 ;
2668 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2674 else if ( stringtoint ( amount
) > p
-> gold
)
2676 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2682 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2684 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2685 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2686 p
-> gold
-= ( 2000000000 - p
-> bank
);
2687 p
-> bank
= 2000000000 ;
2692 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2693 p
-> bank
+= stringtoint ( amount
);
2694 p
-> gold
-= stringtoint ( amount
);
2699 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2701 if ( p
-> gold
== 2000000000 )
2703 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2707 else if ( stricmp ( amount
, "ALL" ) == 0 )
2709 if ( 2000000000 - p
-> gold
< p
-> bank
)
2711 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2712 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2713 p
-> bank
-= ( 2000000000 - p
-> gold
);
2714 p
-> gold
= 2000000000 ;
2719 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2725 else if ( stringtoint ( amount
) > p
-> bank
)
2727 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2733 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2735 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2736 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2737 ( 2000000000 - p
-> gold
));
2738 p
-> bank
-= ( 2000000000 - p
-> gold
);
2739 p
-> gold
= 2000000000 ;
2744 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2745 p
-> gold
+= stringtoint ( amount
);
2746 p
-> bank
-= stringtoint ( amount
);
2754 void do_dragon ( char * u
)
2758 if (!( user
= find ( u
)))
2760 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2763 else if ( isIgnore ( user
))
2766 log ( "Ignoring %s ." , user
-> getNick ());
2770 else if (! is_playing ( user
))
2772 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2775 else if ( is_fighting ( user
))
2777 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2780 else if (! isAlive ( user
-> stats
))
2782 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2785 else if ( user
-> stats
-> level
< REALLEVELS
)
2787 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2788 "to vanquish any foe should DARE fight the dragon!" );
2789 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2790 "You are too weak. You must be Level %d !" , REALLEVELS
);
2794 updateTS ( user
-> stats
);
2796 Player
* p
= user
-> stats
;
2797 p
-> fight
= new Monster ( boss
);
2798 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2799 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2800 "deep, red fog rolls in. The air is filled with the " \
2801 "heated mist of deadly fire from beyond the cave " \
2803 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2804 "your %s , and venture into the hot, dark cave. " \
2805 "You are surprised at the angle of descent as you climb " \
2806 "lower and lower, deeper into the dragon's den." );
2807 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2808 "a tooth. It is a large tooth... bigger than your torso." \
2809 " Suddenly the darkness lifts from the gleam of an eye " \
2810 " staring into your soul! The eye is large... HUGE!" );
2811 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2812 "glare orange! The tooth is moving... but it is still too " \
2813 "dark for you to make out.... THE DRAGON! You see it!" );
2817 void do_master ( char * u
)
2822 if (!( user
= find ( u
)))
2824 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2827 else if ( isIgnore ( user
))
2830 log ( "Ignoring %s ." , user
-> getNick ());
2834 else if (! is_playing ( user
))
2836 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2839 else if ( is_fighting ( user
))
2841 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2844 else if (! isAlive ( user
-> stats
))
2846 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2850 updateTS ( user
-> stats
);
2852 char * cmd
= strtok ( NULL
, " " );
2853 Player
* p
= user
-> stats
;
2858 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2902 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
2906 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2912 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2916 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2924 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
));
2927 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2930 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
);
2932 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2938 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2942 void see_master ( char * u
)
2946 if (!( user
= find ( u
)))
2948 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2952 if (! is_fighting ( user
) && is_playing ( user
))
2954 Player
* p
= user
-> stats
;
2955 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2956 p
-> fight
= p
-> master
;
2957 display_monster ( u
); // Since master is the same structure, use this function
2961 void showBankBalance ( const char * u
)
2966 if (!( user
= find ( u
)))
2974 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2980 ListNode
< aClient
> * it
;
2982 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2984 it
= players
[ x
]. First ();
2988 p
= it
-> getData ()-> stats
;
2995 void refresh ( Player
* p
)
3000 if ( p
-> hp
< p
-> maxhp
)
3002 p
-> forest_fights
= forestfights
;
3003 p
-> player_fights
= 3 ;
3008 void do_refresh ( char * u
)
3010 char * nick
= strtok ( NULL
, " " );
3013 if (!( user
= find ( u
)))
3015 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3016 log ( "Error: aClient not found: %s " , u
);
3019 else if ( isIgnore ( user
))
3022 log ( "Ignoring %s ." , user
-> getNick ());
3026 else if (! isAdmin ( user
))
3028 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3033 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3036 else if ( stricmp ( nick
, "ALL" ) == 0 )
3038 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3041 else if (( user
= findplayer ( nick
)))
3043 if ( is_playing ( user
))
3046 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3048 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3050 refresh ( user
-> stats
);
3055 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3057 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3063 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3071 ListNode
< aClient
> * it
;
3074 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3076 it
= players
[ x
]. First ();
3080 p
= it
-> getData ()-> stats
;
3087 void reset ( Player
* p
)
3095 void updateTS ( Player
* p
)
3101 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3103 p
-> lastcommand
= time ( NULL
);
3105 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3110 bool timedOut ( Player
* p
)
3114 else if ( p
-> lastcommand
== 0 )
3118 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3125 void timeOutEvent ( Player
* p
)
3127 aClient
* user
= findplayer ( p
-> name
);
3129 if (! user
|| ! p
-> client
) // then they're not playing
3132 char * nick
= user
-> getNick ();
3134 if ( player_fight ( user
) && isYourTurn ( p
))
3136 // Check to see if they were the idler or if it was the other
3138 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3140 // This person's last command was given earlier,
3141 // so this person is the idler
3142 notice ( s_GameServ
, nick
, "You timed out " \
3143 "during a fight. You lose your turn!" );
3144 notice ( s_GameServ
, p
-> battle
-> getNick (),
3145 " %s hesitated for too long. Your move." , p
-> name
);
3147 setYourTurn ( p
-> battle
-> stats
);
3149 // Update the TS for both players to give them another
3150 // Chance to wake up, but if the other player doesn't
3151 // Attack now, they both get logged out.
3153 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3154 display_players ( p
-> battle
);
3159 notice ( s_GameServ
, p
-> battle
-> getNick (),
3160 "You and %s timed out at the same time." \
3161 " Don't fight if you're just going to " \
3162 "sit there!" , p
-> name
);
3163 notice ( s_GameServ
, user
-> getNick (),
3164 "You and %s timed out at the same time." \
3165 " Don't fight if you're just going to " \
3166 "sit there!" , p
-> battle
-> stats
-> name
);
3172 else if (! player_fight ( user
))
3174 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3176 // Place fun stuff here :)
3177 int randnum
= 1 + rand () % 100 ; // 1-100
3178 #define GSN(s) notice(s_GameServ, nick, s)
3179 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3183 // 35-100% of your gold goes pffft - kain
3184 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3186 GSN ( "You stop for a moment to rest on the " \
3187 "street corner. All of a sudden, you " \
3188 "are ambushed from all sides by a hoarde " \
3189 "of knife wielding thugs." );
3190 GSN2 ( "The thugs beat you into utter submission " \
3191 "and steal %d gold from you!" , stolen
);
3192 user
-> stats
-> gold
-= stolen
;
3194 else if ( randnum
>= 50 && randnum
< 75 )
3196 // 25-65% of your gold goes pffft - kain
3197 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3198 GSN ( "While dilly dallying around, you lose " \
3199 "your sense of time. Little did you know, " \
3200 "but thieves lifted your gold while you " \
3201 "weren't watching." );
3202 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3203 user
-> stats
-> gold
-= stolen
;
3205 else if ( randnum
>= 75 )
3207 // 25-75% of your gold goes pffft - kain
3208 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3209 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3210 "goblins grabbed your gold!" );
3211 GSN2 ( "They stole %d gold from you!" , stolen
);
3212 user
-> stats
-> gold
-= stolen
;
3216 // Always log out the user
3221 void do_reset ( char * u
)
3223 char * nick
= strtok ( NULL
, " " );
3226 if (!( user
= find ( u
)))
3228 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3229 log ( "Error: aClient not found: %s " , u
);
3232 else if (! isAdmin ( user
))
3234 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3240 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3243 else if ( stricmp ( nick
, "ALL" ) == 0 )
3245 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3248 else if (( user
= findbyrealnick ( nick
)))
3250 if ( is_playing ( user
))
3253 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3255 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3262 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3264 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3270 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3275 void do_help ( char * u
)
3277 char * cmd
= strtok ( NULL
, " " );
3279 display_help ( u
, cmd
);
3282 void display_help ( char * u
, char * file
)
3289 infile
. open ( "helpfiles/help" );
3292 log ( "Error opening helpfiles/help" );
3293 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3296 buf
= new char [ 1024 ];
3297 while ( infile
. getline ( buf
, 1024 ))
3299 // Written this way, it will process %S in the helpfiles
3300 // Instead of notice(s_GameServ, u, "%s", buf);
3301 notice ( s_GameServ
, u
, buf
);
3305 aClient
* user
= find ( u
);
3306 if ( user
&& isAdmin ( user
))
3307 display_help ( u
, "admin_commands" );
3312 filename
= new char [ strlen ( file
) + 11 ];
3313 strcpy ( filename
, "helpfiles/" );
3314 strcat ( filename
, file
);
3316 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3317 filename
[ x
] = tolower ( filename
[ x
]);
3319 infile
. open ( filename
);
3323 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3326 buf
= new char [ 1024 ];
3327 while ( infile
. getline ( buf
, 1024 ))
3329 // Written this way, it will process %S in the helpfiles
3330 // Instead of notice(s_GameServ, u, "%s", buf);
3331 notice ( s_GameServ
, u
, buf
);
3338 void do_admin ( char * u
)
3341 char * pass
= strtok ( NULL
, " " );
3343 if (!( user
= find ( u
)))
3345 log ( "Error: aClient not found: %s " , u
);
3346 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3352 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3358 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3361 else if ( strcmp ( pass
, adminpass
) == 0 )
3363 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3366 log ( " %s became an administrator." , user
-> getRealNick ());
3368 log ( " %s became an administrator." , user
-> getNick ());
3373 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3378 bool load_monsters ()
3381 infile
. open ( "monsters.dat" );
3387 log ( "Error opening monsters.dat" );
3391 buf
= new char [ 2048 ];
3394 log ( "Loading monsters from monsters.dat" );
3397 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3399 for ( int m
= 0 ; m
< MONSTERS
;)
3401 infile
. getline ( buf
, 2048 );
3402 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3406 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3407 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3408 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3409 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3410 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3411 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3412 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3413 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));