]>
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
);
161 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
164 ts
= strtok ( NULL
, "\1" );
165 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
166 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
167 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
168 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
169 cmd
= strtok ( NULL
, " " );
172 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
176 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
178 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
180 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
182 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
184 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
186 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
187 do_inventory ( source
);
188 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
190 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
192 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
194 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
196 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
200 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
202 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
204 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
208 } else if ( stricmp ( cmd
, "NEWS" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
212 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
214 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
216 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
221 if (!( user
= find ( source
)))
223 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
224 log ( "Error: aClient not found: %s " , source
);
226 else if (! isAdmin ( user
))
228 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
234 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
236 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
240 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
243 if (!( user
= find ( source
)))
245 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
246 log ( "Error: aClient not found: %s " , source
);
248 else if (! isAdmin ( user
))
250 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
256 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
259 if (!( user
= find ( source
)))
261 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
262 log ( "Error: aClient not found: %s " , source
);
264 else if (! isAdmin ( user
))
266 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
270 char * cmd2
= strtok ( NULL
, " " );
273 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
276 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
278 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
282 display_help ( source
, cmd
);
285 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
288 if (!( user
= find ( source
)))
290 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
291 log ( "Error: aClient not found: %s " , source
);
293 else if (! isAdmin ( user
))
295 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
299 char * rest
= strtok ( NULL
, "" );
305 if (( user
= find ( source
)))
310 log ( "Ignoring %s ." , user
-> getNick ());
315 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
321 source
--; // Bring the ':' back so we don't leak memory
324 cmd
--; // Same thing :)
327 int stricmp ( const char * s1
, const char * s2
)
331 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
337 if ( c
< tolower (* s2
))
342 void showstats ( const char * u
, const char * nick
)
344 aClient
* ni
, * sender
= find ( u
);
350 if (!( ni
= findplayer ( nick
)))
352 notice ( s_GameServ
, u
, " %s not found" , nick
);
356 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
358 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
359 space
= spaces ( strlen ( buf
), " " );
360 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
364 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
365 space
= spaces ( strlen ( buf
), " " );
366 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
369 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
372 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
373 space
= spaces ( strlen ( buf
), " " );
374 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
375 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
378 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
379 space
= spaces ( strlen ( buf
), " " );
380 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
381 weapons
[ ni
-> stats
-> weapon
]);
384 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
385 space
= spaces ( strlen ( buf
), " " );
386 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
388 Pouch
* inv
= & ni
-> stats
-> inventory
;
390 notice ( s_GameServ
, u
, "Potions" );
391 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
392 space
= spaces ( strlen ( buf
), " " );
393 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
397 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
398 space
= spaces ( strlen ( buf
), " " );
399 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
400 space
, inv
-> Defense ());
405 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
410 char * spaces ( int len
, char * seperator
)
413 final
= new char [ 30 ];
415 strcpy ( final
, seperator
);
416 for ( y
= 0 ; y
< 30 - len
; y
++)
417 strcat ( final
, seperator
);
421 void raw ( const char * fmt
, ...)
426 input
= new char [ 1024 ];
428 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
434 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
435 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
436 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
439 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
444 sprintf ( input
, " %s%c " , input
, * t
);
449 log ( "Input: %s " , input
);
452 sprintf ( input
, " %s%s " , input
, " \r\n " );
453 sock_puts ( sock
, input
);
457 /* Send a NOTICE from the given source to the given nick. */
459 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
465 commanduse
= new char [ 16 ];
469 strcpy ( commanduse
, "P" );
471 strcpy ( commanduse
, "O" );
475 strcpy ( commanduse
, "PRIVMSG" );
477 strcpy ( commanduse
, "NOTICE" );
483 input
= new char [ 1024 ];
490 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
492 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
500 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
502 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
511 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
512 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
513 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
516 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
521 sprintf ( input
, " %s%c " , input
, * t
);
526 log ( "Input: %s " , input
);
528 sprintf ( input
, " %s%s " , input
, " \r\n " );
529 sock_puts ( sock
, input
);
530 delete [] commanduse
;
536 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
542 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
543 if ( c
== 0 || -- len
== 0 )
548 if ( c
< tolower (* s2
))
554 char * strtok ( char * str
, const char * delim
)
556 static char * current
= NULL
;
563 current
+= strspn ( current
, delim
);
564 ret
= * current
? current
: NULL
;
565 current
+= strcspn ( current
, delim
);
574 void do_list ( char * u
)
577 char * cmd
= strtok ( NULL
, " " );
579 if (!( user
= find ( u
)))
581 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
584 else if ( isIgnore ( user
))
587 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
592 ListNode
< aClient
> * temp
;
595 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
597 temp
= players
[ x
]. First ();
598 if (! players
[ x
]. isEmpty ())
602 if (! cmd
|| is_playing ( temp
-> getData ()))
606 notice ( s_GameServ
, u
, "Players:" );
610 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
611 temp
-> getData ()-> stats
-> name
);
613 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
614 temp
-> getData ()-> stats
-> name
);
623 notice ( s_GameServ
, u
, "No one is playing" );
625 notice ( s_GameServ
, u
, "End of List" );
629 void do_logout ( char * u
)
632 char * name
= strtok ( NULL
, " " );
634 if (!( user
= find ( u
)))
636 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
637 "Buf: %s LOGOUT" , u
);
638 log ( "Could not find aClient Buf: %s LOGOUT" ,
642 else if ( isIgnore ( user
))
645 log ( "Ignoring %s ." , user
-> getNick ());
654 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
656 else if (!( user
= findplayer ( name
)))
658 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
662 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
668 if (! is_playing ( user
))
670 notice ( s_GameServ
, u
, "You're not logged in!" );
672 else if ( is_fighting ( user
))
674 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
678 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
684 void logout ( aClient
* user
)
686 if ( is_playing ( user
))
688 ListNode
< aClient
> * it
;
690 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
691 it
= players
[ hv
]. Find ( user
);
695 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
696 " %S Admin. Cannot find you in the players list." );
697 log ( "Error on logout(). Can't find %s in the players list" ,
708 temp
-> stats
= new Player
;
709 temp
-> stats
-> setData ( user
-> stats
);
710 user
-> stats
-> client
= NULL
;
712 if ( player_fight ( user
))
713 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
717 temp
-> stats
-> client
= NULL
;
719 temp
-> setRealNick ( "Not Playing" );
721 temp
-> setNick ( "Not Playing" );
725 log ( "Logged out player %s " ,
737 void do_register ( char * u
)
739 char * password
, * name
;
741 name
= strtok ( NULL
, " " );
742 password
= strtok ( NULL
, " " );
744 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
747 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
748 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
753 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
757 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
759 else if (( user
= findplayer ( name
)))
761 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
762 notice ( s_GameServ
, u
, "Choose another name!" );
764 else if (!( user
= find ( u
)))
766 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
768 else if ( isIgnore ( user
))
771 log ( "Ignoring %s ." , user
-> getNick ());
777 if (! is_playing ( user
))
779 ListNode
< aClient
> * temp
;
780 user
-> stats
= new Player ( user
);
781 user
-> stats
-> client
= user
; // Set the backwards pointer
782 user
-> stats
-> reset (); // set the user up
783 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
784 strncpy ( user
-> stats
-> name
, name
, 255 );
785 unsigned long hv
= iHASH (( unsigned char *) name
);
786 updateTS ( user
-> stats
);
787 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
788 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
790 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
791 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
792 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
793 setPlaying ( user
); // set the playing flag
797 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
802 void do_identify ( char * u
)
804 char * password
, * name
;
806 name
= strtok ( NULL
, " " );
807 password
= strtok ( NULL
, " " );
808 if (! password
|| ! name
)
810 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
812 else if (!( user
= find ( u
)))
814 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
815 log ( "Error: aClient not found: %s " , u
);
817 else if ( isIgnore ( user
))
820 log ( "Ignoring %s ." , user
-> getNick ());
824 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
825 notice ( s_GameServ
, u
, "Player %s not found" , name
);
826 else if ( is_playing ( user
))
828 notice ( s_GameServ
, u
, "You are already playing!" );
830 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
832 notice ( s_GameServ
, u
, "That player has already identified." );
834 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
836 notice ( s_GameServ
, u
, "Password incorrect" );
839 ListNode
< aClient
> * temp
;
840 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
841 temp
= players
[ hv
]. Find ( p
);
844 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
848 user
-> stats
= new Player ( p
-> stats
-> name
);
850 log ( "Setting data for identified" );
852 user
-> stats
-> setData ( p
-> stats
);
853 user
-> stats
-> client
= user
;
854 updateTS ( user
-> stats
);
858 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
862 setPlaying ( user
); // set the playing flag
865 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
866 showNews ( u
, todaysnews
);
870 void do_stats ( char * u
)
875 nick
= strtok ( NULL
, " " );
877 if (!( user
= find ( u
)))
879 log ( "Fatal Error: %s not found in client list" , u
);
882 else if ( isIgnore ( user
))
885 log ( "Ignoring %s ." , user
-> getNick ());
891 if (! is_playing ( user
))
893 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
898 updateTS ( user
-> stats
);
899 showstats ( u
, user
-> stats
-> name
);
909 log ( "Calling delete_masters()" );
915 log ( "Initializing masters" );
918 for ( int x
= 0 ; x
< LEVELS
; x
++)
919 masters
[ x
] = new Monster
;
921 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
922 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
923 masters
[ 0 ]-> strength
= 32 ;
924 masters
[ 0 ]-> gold
= 0 ;
926 masters
[ 0 ]-> maxhp
= 35 ;
928 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!" );
930 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
931 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
932 masters
[ 1 ]-> strength
= 48 ;
933 masters
[ 1 ]-> gold
= 0 ;
935 masters
[ 1 ]-> maxhp
= 51 ;
937 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." );
939 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
940 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
941 masters
[ 2 ]-> strength
= 88 ;
942 masters
[ 2 ]-> gold
= 0 ;
944 masters
[ 2 ]-> maxhp
= 100 ;
945 masters
[ 2 ]-> hp
= 100 ;
946 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!" );
949 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
950 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
951 masters
[ 3 ]-> strength
= 169 ;
952 masters
[ 3 ]-> gold
= 0 ;
954 masters
[ 3 ]-> maxhp
= 165 ;
955 masters
[ 3 ]-> hp
= 165 ;
956 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
958 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
959 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
960 masters
[ 4 ]-> strength
= 275 ;
961 masters
[ 4 ]-> gold
= 0 ;
963 masters
[ 4 ]-> maxhp
= 232 ;
964 masters
[ 4 ]-> hp
= 232 ;
965 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!" );
967 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
968 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
969 masters
[ 5 ]-> strength
= 347 ;
970 masters
[ 5 ]-> gold
= 0 ;
972 masters
[ 5 ]-> maxhp
= 504 ;
973 masters
[ 5 ]-> hp
= 504 ;
974 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
977 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
978 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
979 masters
[ 6 ]-> strength
= 515 ;
980 masters
[ 6 ]-> gold
= 0 ;
982 masters
[ 6 ]-> maxhp
= 1078 ;
983 masters
[ 6 ]-> hp
= 1078 ;
984 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
986 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
987 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
988 masters
[ 7 ]-> strength
= 655 ;
989 masters
[ 7 ]-> gold
= 0 ;
991 masters
[ 7 ]-> maxhp
= 2207 ;
992 masters
[ 7 ]-> hp
= 2207 ;
993 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
996 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
997 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
998 masters
[ 8 ]-> strength
= 819 ;
999 masters
[ 8 ]-> gold
= 0 ;
1000 masters
[ 8 ]-> exp
= 0 ;
1001 masters
[ 8 ]-> maxhp
= 2780 ;
1002 masters
[ 8 ]-> hp
= 2780 ;
1003 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1005 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1006 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1007 masters
[ 9 ]-> strength
= 1014 ;
1008 masters
[ 9 ]-> gold
= 0 ;
1009 masters
[ 9 ]-> exp
= 0 ;
1010 masters
[ 9 ]-> maxhp
= 3046 ;
1011 masters
[ 9 ]-> hp
= 3046 ;
1012 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1014 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1015 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1016 masters
[ 10 ]-> strength
= 1286 ;
1017 masters
[ 10 ]-> gold
= 0 ;
1018 masters
[ 10 ]-> exp
= 0 ;
1019 masters
[ 10 ]-> maxhp
= 3988 ;
1020 masters
[ 10 ]-> hp
= 3988 ;
1021 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." );
1024 void init_monsters ()
1027 log ( "Calling delete_monsters" );
1032 for ( int x
= 0 ; x
< LEVELS
; x
++)
1033 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1034 monsters
[ x
][ y
] = new Monster ();
1037 void delete_monsters ()
1039 for ( int x
= 0 ; x
< LEVELS
; x
++)
1040 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1042 delete monsters
[ x
][ y
];
1045 void delete_masters ()
1047 for ( int x
= 0 ; x
< LEVELS
; x
++)
1052 void display_monster ( char * u
)
1056 aClient
* user
= find ( u
);
1057 Player
* ni
= user
-> stats
;
1059 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1060 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1061 notice ( s_GameServ
, u
, "Here are your commands:" );
1062 notice ( s_GameServ
, u
, "/msg %S attack" );
1063 notice ( s_GameServ
, u
, "/msg %S run" );
1064 notice ( s_GameServ
, u
, "What will you do?" );
1068 void display_players ( char * u
)
1071 if (!( user
= find ( u
)))
1073 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1076 display_players ( user
);
1079 void display_players ( aClient
* user
)
1081 char * u
= user
-> getNick ();
1082 if ( is_playing ( user
) && player_fight ( user
))
1084 aClient
* battle
= user
-> stats
-> battle
;
1085 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1086 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1087 notice ( s_GameServ
, u
, "Here are your commands:" );
1088 notice ( s_GameServ
, u
, "/msg %S attack" );
1089 notice ( s_GameServ
, u
, "/msg %S run" );
1090 notice ( s_GameServ
, u
, "What will you do?" );
1095 bool is_playing ( char * u
)
1098 if (!( user
= find ( u
)))
1101 return is_playing ( user
);
1104 bool is_playing ( aClient
* user
)
1106 if ( user
-> stats
== NULL
)
1110 else if ( user
-> stats
-> client
== NULL
)
1114 else if (! FL_is_playing ( user
))
1122 bool is_fighting ( char * u
)
1126 if (!( user
= find ( u
)))
1129 return is_fighting ( user
);
1132 bool is_fighting ( aClient
* user
)
1134 if (! is_playing ( user
))
1137 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1140 bool player_fight ( char * u
)
1144 if (!( user
= find ( u
)))
1147 return player_fight ( user
);
1150 bool player_fight ( aClient
* user
)
1152 if (! is_playing ( user
))
1154 else if ( user
-> stats
-> battle
!= NULL
)
1156 return user
-> stats
-> battle
-> stats
!= NULL
;
1161 bool master_fight ( char * u
)
1165 if (!( user
= find ( u
)))
1168 return master_fight ( user
);
1171 bool master_fight ( aClient
* user
)
1173 if (! is_playing ( user
))
1176 return user
-> stats
-> master
!= NULL
;
1179 void do_fight ( char * u
)
1181 aClient
* ni
, * battle
;
1183 char * nick
= strtok ( NULL
, " " );
1187 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1190 else if (!( ni
= find ( u
)))
1192 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1195 else if ( isIgnore ( ni
))
1198 log ( "Ignoring %s ." , ni
-> getNick ());
1202 else if (! is_playing ( ni
))
1204 notice ( s_GameServ
, u
, "You are not playing!" );
1208 updateTS ( ni
-> stats
);
1210 if ( ni
-> stats
-> player_fights
<= 0 )
1212 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1213 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1214 "day. You have to wait until tomorrow!" );
1216 else if (!( battle
= findplayer ( nick
)))
1218 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1220 else if (! isAlive ( ni
-> stats
))
1222 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1224 else if (! is_playing ( battle
))
1226 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1229 /* offline fighting not available yet
1230 else if (!(fight = finduser(nick)))
1232 ni->stats->battle = battle;
1233 battle->battle = ni;
1234 setYourTurn(ni->stats);
1235 clearYourTurn(battle->stats);
1237 notice(s_GameServ, u, "You decide to fight %s while they're "\
1238 "not in the realm!",
1239 battle->stats->name);
1243 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1245 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1247 else if (! isAlive ( battle
-> stats
))
1249 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1251 else if ( player_fight ( battle
))
1253 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1255 else if ( master_fight ( battle
))
1257 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1259 else if ( is_fighting ( battle
))
1261 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1263 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1265 // You can't fight someone below you by more than X level(s)
1266 // level 12 can fight level (12 - X) but not < (12 - X)
1267 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1268 battle
-> stats
-> name
);
1270 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1272 // You can't fight someone above you by more than X level(S)
1273 // level 1 can fight level (1 + X), but not > (1 + X)
1274 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1275 "weakling!" , ni
-> stats
-> name
);
1279 // Set your battle pointer to the other player
1280 ni
-> stats
-> battle
= battle
;
1282 // Set the other player's battle pointer to you
1283 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1285 // The initiator gets the first move (perhaps this should be 50/50)
1286 setYourTurn ( ni
-> stats
);
1287 clearYourTurn ( battle
-> stats
);
1289 // Initiate Battle sequence!
1290 ni
-> stats
-> player_fights
-= 1 ;
1292 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1293 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1294 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1295 "because they initiated!" , ni
-> stats
-> name
);
1296 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1297 display_players ( ni
);
1301 void do_use ( char * u
)
1306 char * item
= strtok ( NULL
, " " );
1310 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1311 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1314 else if (!( user
= find ( u
)))
1316 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1319 else if ( isIgnore ( user
))
1322 log ( "Ignoring %s ." , user
-> getNick ());
1326 else if (! is_playing ( user
))
1328 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1332 updateTS ( user
-> stats
);
1334 p
= & user
-> stats
-> inventory
;
1336 if ( stricmp ( item
, "HEALING" ) == 0 )
1338 if ( p
-> Healing () <= 0 )
1340 notice ( s_GameServ
, u
, "You are out of Healing Potions!" );
1343 int oldhealing
= user
-> stats
-> hp
;
1344 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1345 if ( user
-> stats
-> hp
- user
-> stats
-> maxhp
>= 100 )
1347 user
-> stats
-> hp
= user
-> stats
-> maxhp
+ 100 ;
1349 if ( oldhealing
>= ( user
-> stats
-> maxhp
+ 100 ))
1351 notice ( s_GameServ
, u
, "You cannot hold anymore 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 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1360 if ( player_fight ( user
))
1362 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1363 " %s has used a healing potion!" );
1366 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1368 if ( p
-> Strength () <= 0 )
1370 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1373 int oldstrength
= user
-> stats
-> strength
;
1374 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1375 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1376 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1377 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1379 if ( player_fight ( user
))
1381 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1382 " %s has used a strength potion!" );
1385 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1387 if ( p
-> Defense () <= 0 )
1389 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1392 int olddefense
= user
-> stats
-> defense
;
1393 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1394 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1395 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1396 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1398 if ( player_fight ( user
))
1400 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1401 " %s has used a defense potion!" );
1404 else if ( stricmp ( item
, "HP" ) == 0 )
1408 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1411 int oldHP
= user
-> stats
-> maxhp
;
1412 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1413 user
-> stats
-> maxhp
+= 2 +
1414 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1416 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1418 if ( player_fight ( user
))
1420 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1421 " %s has used a HP potion!" );
1426 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1430 end_turn ( user
); // If they're fighting, end their turn
1432 void do_run ( char * u
)
1435 Player
* p
, * p2
= NULL
;
1437 if (!( user
= find ( u
)))
1439 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1442 else if ( isIgnore ( user
))
1445 log ( "Ignoring %s ." , user
-> getNick ());
1449 else if (! is_playing ( user
))
1451 notice ( s_GameServ
, u
, "You must be playing to run!" );
1455 updateTS ( user
-> stats
);
1459 p2
= p
-> battle
-> stats
;
1461 if (! is_fighting ( user
))
1462 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1463 else if (! player_fight ( user
) && ! master_fight ( user
))
1465 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1469 else if ( player_fight ( user
) && isYourTurn ( p
))
1471 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1472 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1475 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1477 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1479 else if ( master_fight ( user
))
1481 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1486 void end_turn ( aClient
* user
)
1488 char * nick
, * u
= user
-> getNick ();
1493 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1495 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1498 if (! player_fight ( user
) && ! master_fight ( user
))
1499 fight
= user
-> stats
-> fight
;
1501 fight
= user
-> stats
-> master
;
1502 battle
= user
-> stats
-> battle
;
1504 if (! player_fight ( user
))
1507 mhit
= ( fight
-> strength
/ 2 ) +
1508 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1509 arbonus
[ user
-> stats
-> armor
]));
1514 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1515 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1516 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1518 if (! player_fight ( user
))
1523 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1524 fight
-> name
, fight
-> weapon
, mhit
);
1527 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1529 if ( mhit
>= user
-> stats
-> hp
)
1531 if (! master_fight ( user
))
1533 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1534 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1535 "of your experience!" );
1536 user
-> stats
-> gold
= 0 ;
1537 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1538 user
-> stats
-> hp
= 0 ;
1539 user
-> stats
-> fight
= NULL
;
1540 clearAlive ( user
-> stats
);
1545 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1546 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1547 user
-> stats
-> fight
= NULL
;
1548 user
-> stats
-> master
= NULL
;
1555 user
-> stats
-> hp
-= mhit
;
1562 clearYourTurn ( user
-> stats
);
1563 setYourTurn ( battle
-> stats
);
1564 display_players ( battle
);
1570 void do_attack ( char * u
)
1573 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1574 Monster
* fight
; // The monster they may be fighting
1576 if (!( ni
= find ( u
)))
1578 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1581 else if ( isIgnore ( ni
))
1584 log ( "Ignoring %s ." , ni
-> getNick ());
1588 else if (! is_playing ( ni
))
1590 notice ( s_GameServ
, u
, "You're not playing!" );
1593 else if (! is_fighting ( ni
))
1595 notice ( s_GameServ
, u
, "You're not in battle!" );
1600 if (! ni
-> stats
-> master
) // This is not a master fight
1601 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1602 else // This IS a master fight
1603 fight
= ni
-> stats
-> master
; // Master Could be NULL
1605 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1607 // One has to be !NULL based on the previous else if
1608 // We wouldn't be here if they were all NULL
1610 updateTS ( ni
-> stats
);
1612 if (! player_fight ( ni
))
1615 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1616 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1619 mhit
= ( fight
-> strength
/ 2 ) +
1620 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1621 arbonus
[ ni
-> stats
-> armor
]));
1626 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1627 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1628 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1631 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1632 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1633 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1636 if (! player_fight ( ni
))
1639 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1641 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1643 if ( hit
>= fight
-> hp
)
1645 if ( master_fight ( ni
))
1647 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1648 addNews ( todaysnews
, " %s has bested %s and moved " \
1649 "to level %d " , ni
-> stats
-> name
, fight
-> name
,
1650 ( ni
-> stats
-> level
+ 1 ));
1653 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1655 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1656 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1657 fight
-> exp
, fight
-> gold
);
1659 // If your new experience (or gold) will be greater than 2 billion,
1660 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1661 // This could be a problem with overflowing out of the sign bit.
1662 // Unsigned long int maybe? Leave it for now.
1663 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1664 ni
-> stats
-> exp
+ fight
-> exp
);
1666 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1667 ni
-> stats
-> gold
+ fight
-> gold
);
1670 if ( master_fight ( ni
))
1672 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1673 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1674 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1676 // Increase your level
1678 // Increase your maximum hit points
1679 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1681 // Heal the player by setting hp to their max
1682 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1684 // Add to your strength
1685 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1687 // Add to your defensive power
1688 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1692 // Clear the pointer for your master
1693 ni
-> stats
-> master
= NULL
;
1696 // They're dead so remove the pointer
1697 delete ni
-> stats
-> fight
;
1698 ni
-> stats
-> fight
= NULL
;
1699 ni
-> stats
-> master
= NULL
;
1709 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1710 fight
-> name
, fight
-> weapon
, mhit
);
1713 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1715 if ( mhit
>= ni
-> stats
-> hp
)
1717 if (! master_fight ( ni
))
1719 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1720 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1721 "of your experience!" );
1722 addNews ( todaysnews
, " %s has been killed by %s !" ,
1723 ni
-> stats
-> name
, fight
-> name
);
1724 ni
-> stats
-> gold
= 0 ;
1725 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1727 ni
-> stats
-> fight
= NULL
;
1728 clearAlive ( ni
-> stats
);
1733 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1734 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1735 addNews ( todaysnews
, " %s tried to best %s and failed!" ,
1736 ni
-> stats
-> name
, fight
-> name
);
1737 ni
-> stats
-> fight
= NULL
;
1738 ni
-> stats
-> master
= NULL
;
1745 ni
-> stats
-> hp
-= mhit
;
1751 else if ( player_fight ( ni
))
1753 /* Offline fighting not available yet
1754 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1757 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1759 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1760 if (hit >= battle->stats->hp)
1762 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1763 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1764 (long int)(battle->stats->exp * .10), battle->stats->gold);
1765 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1767 ni->stats->exp += (long int)(battle->stats->exp * .10);
1768 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1772 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1773 ni->stats->exp = 2000000000;
1776 if (2000000000 - ni->stats->gold > battle->stats->gold)
1778 * ni->stats->gold += battle->stats->gold;
1779 battle->stats->gold = 0;
1783 battle->stats->gold = 2000000000 - ni->stats->gold;
1784 ni->stats->gold = 2000000000;
1786 * ni->stats->battle->stats->alive = 0;
1787 ni->stats->battle->battle = NULL;
1788 ni->stats->battle = NULL;
1794 * battle->stats->hp -= hit;
1797 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1798 battle->nick, weapons[battle->stats->weapon], mhit);
1801 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1803 if (mhit >= ni->stats->hp)
1805 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1806 if (2000000000 - battle->stats->gold > ni->stats->gold)
1808 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1809 battle->stats->gold += ni->stats->gold;
1810 * ni->stats->gold = 0;
1814 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1816 ni->stats->gold -= (2000000000 - battle->stats->gold);
1817 notice(s_GameServ, u, "You were left dead with %d gold.",
1818 * (long int)ni->stats->gold);
1819 battle->stats->gold = 2000000000;
1821 ni->stats->battle->battle = NULL;
1822 ni->stats->battle = NULL;
1823 ni->stats->alive = 0;
1829 ni->stats->hp -= mhit;
1835 * end offline fighting */
1837 if ( is_playing ( battle
))
1839 if (! isYourTurn ( ni
-> stats
))
1841 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1842 battle
-> stats
-> name
);
1847 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1849 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1850 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1851 weapons
[ ni
-> stats
-> weapon
], hit
);
1855 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1856 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1859 if ( hit
>= battle
-> stats
-> hp
)
1861 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1862 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1863 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1864 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1866 battle
-> stats
-> hp
= 0 ;
1867 clearAlive ( battle
-> stats
);
1869 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1871 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1872 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1876 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1877 ni
-> stats
-> exp
= 2000000000 ;
1880 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1882 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1883 "all gold on hand!" );
1884 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1885 battle
-> stats
-> gold
= 0 ;
1889 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1890 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1892 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1893 "gold." , ni
-> stats
-> name
);
1895 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1896 "left. All is not lost!" , battle
-> stats
-> gold
);
1898 ni
-> stats
-> gold
= 2000000000 ;
1900 clearYourTurn ( ni
-> stats
);
1901 clearYourTurn ( battle
-> stats
);
1902 battle
-> stats
-> battle
= NULL
;
1903 ni
-> stats
-> battle
= NULL
;
1909 battle
-> stats
-> hp
-= hit
;
1910 clearYourTurn ( ni
-> stats
);
1911 setYourTurn ( battle
-> stats
);
1912 display_players ( battle
);
1913 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1914 battle
-> stats
-> name
);
1921 void do_heal ( char * u
)
1924 char * amount
= strtok ( NULL
, " " );
1929 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1932 else if (!( ni
= find ( u
)))
1934 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1937 else if ( isIgnore ( ni
))
1940 log ( "Ignoring %s ." , ni
-> getNick ());
1944 else if (! is_playing ( ni
))
1946 notice ( s_GameServ
, u
, "You aren't playing!" );
1949 else if (! isAlive ( ni
-> stats
))
1951 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1954 else if ( is_fighting ( ni
))
1956 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1959 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1961 notice ( s_GameServ
, u
, "You don't need healing!" );
1965 updateTS ( ni
-> stats
);
1966 if ( stricmp ( amount
, "ALL" ) == 0 )
1968 price
= ni
-> stats
-> level
* 3 ;
1969 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1971 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1972 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1973 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1974 ni
-> stats
-> gold
%= price
;
1978 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1979 "per point." , price
);
1980 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1981 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1982 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1983 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1984 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1987 else if ( isstringnum ( amount
))
1989 num
= stringtoint ( amount
);
1990 price
= ni
-> stats
-> level
* 3 ;
1991 if ( ni
-> stats
-> gold
< price
* num
)
1993 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1994 ( long int ) ni
-> stats
-> gold
/ price
);
1996 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1998 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2000 ni
-> stats
-> hp
+= num
;
2001 ni
-> stats
-> gold
-= num
* price
;
2003 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2005 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2006 "per point." , price
);
2007 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2008 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2009 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2010 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2013 else if ( amount
[ 0 ] == '-' )
2014 notice ( s_GameServ
, u
, "You trying to cheat?" );
2016 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2019 int isstringnum ( char * num
)
2022 for ( x
= 0 ; x
< strlen ( num
); x
++)
2024 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2030 long int stringtoint ( char * number
)
2032 long int x
, len
= strlen ( number
), sum
= 0 ;
2034 return chartoint ( number
[ 0 ]);
2035 sum
+= chartoint ( number
[ len
- 1 ]);
2036 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2037 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2041 long int pow ( int x
, int y
)
2047 if ( x
!= 0 && y
!= 0 )
2049 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2057 long int chartoint ( char ch
)
2059 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2060 return int ( ch
) - 48 ;
2067 ListNode
< aClient
> * ptr
;
2071 outfile
. open ( playerdata
);
2075 log ( "Error opening %s " , playerdata
);
2079 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2081 ptr
= players
[ x
]. First ();
2084 it
= ptr
-> getData ()-> stats
;
2086 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2087 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2088 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2089 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2090 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2091 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
2104 char * tempname
, * buf
, * password
;
2105 buf
= new char [ 1023 ];
2107 infile
. open ( playerdata
);
2111 log ( "Error opening %s " , playerdata
);
2115 for ( int x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2117 ListNode
< aClient
> * tempNode
;
2118 tempNode
= players
[ x
]. First ();
2121 if ( tempNode
-> getData ()-> stats
-> client
)
2122 logout ( tempNode
-> getData ()-> stats
-> client
);
2123 tempNode
= tempNode
-> Next ();
2125 players
[ x
]. deleteNodes ();
2128 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2131 tempname
= strtok ( buf
, " " );
2132 temp
-> stats
= new Player ( tempname
);
2135 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2136 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2137 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2138 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2139 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2140 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2141 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2142 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2143 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2144 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2145 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2146 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2147 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2149 password
= strtok ( NULL
, " " );
2150 strcpy ( p
-> password
, password
);
2151 temp
-> setNick ( "Not Playing" );
2153 temp
-> setRealNick ( "Not Playing" );
2156 p
-> inventory
. reset (); // Set inventory to all 0s
2157 // Old player databases didn't have these three extra values
2158 // If they come up null, leave them to 0 as the default.
2159 // On the next gameserv database save, it will save the values.
2160 tempname
= strtok ( NULL
, " " );
2162 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2164 tempname
= strtok ( NULL
, " " );
2166 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2168 tempname
= strtok ( NULL
, " " );
2170 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2172 tempname
= strtok ( NULL
, " " );
2174 p
-> inventory
. setHP ( stringtoint ( tempname
));
2175 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2177 temp
-> stats
-> client
= NULL
;
2178 players
[ hv
]. insertAtBack ( temp
);
2186 bool passcmp ( char * encrypted
, char * plaintext
)
2189 char * plaintext2
, * plainToencrypt
;
2192 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2193 strcpy ( plaintext2
, plaintext
);
2195 salt
[ 0 ] = encrypted
[ 0 ];
2196 salt
[ 1 ] = encrypted
[ 1 ];
2199 plainToencrypt
= crypt ( plaintext2
, salt
);
2201 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2203 delete [] plaintext2
;
2208 bool check_password ( char * name
, char * plaintext
)
2212 if (!( client
= findplayer ( name
)))
2216 return passcmp ( client
-> stats
-> password
, plaintext
);
2220 void do_store ( char * u
)
2222 char * cmd
= strtok ( NULL
, " " );
2223 char * item
= strtok ( NULL
, " " );
2224 char * num
= strtok ( NULL
, " " );
2232 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2233 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2234 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2237 else if (!( user
= find ( u
)))
2239 log ( "Fatal Error: could not find %s in client list" , u
);
2242 else if ( isIgnore ( user
))
2245 log ( "Ignoring %s ." , user
-> getNick ());
2249 else if (! is_playing ( user
))
2251 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2254 else if (! isAlive ( user
-> stats
))
2256 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2259 updateTS ( user
-> stats
);
2261 if ( stricmp ( cmd
, "LIST" ) == 0 )
2263 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2265 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2266 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2267 for ( int x
= 1 ; x
< WNA
; x
++)
2269 space
= spaces ( strlen ( weapons
[ x
]), "." );
2270 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2273 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2274 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2277 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2279 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2280 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2281 for ( int x
= 1 ; x
< WNA
; x
++)
2283 space
= spaces ( strlen ( armors
[ x
]), "." );
2284 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2287 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2288 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2292 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2295 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2298 else if (! isstringnum ( num
))
2300 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2303 if ( stricmp ( item
, "WEAPON" ) == 0 )
2305 wep
= stringtoint ( num
);
2306 if ( wep
>= WNA
|| wep
< 1 )
2308 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2315 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2316 else if ( p
-> gold
< prices
[ wep
- 1 ])
2317 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2320 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2322 p
-> gold
-= prices
[ wep
- 1 ];
2325 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2327 wep
= stringtoint ( num
);
2328 if ( wep
>= WNA
|| wep
< 1 )
2330 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2337 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2338 else if ( p
-> gold
< prices
[ wep
- 1 ])
2339 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2342 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2344 p
-> gold
-= prices
[ wep
- 1 ];
2348 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2352 if ( stricmp ( item
, "WEAPON" ) == 0 )
2356 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2359 else if ( p
-> gold
== 2000000000 )
2361 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2364 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2366 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2367 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2368 p
-> gold
= 2000000000 ;
2373 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2374 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2378 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2384 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2387 if ( p
-> gold
== 2000000000 )
2389 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2392 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2394 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2395 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2396 p
-> gold
= 2000000000 ;
2401 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2402 ( prices
[ p
-> armor
- 1 ] / 2 ));
2404 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2410 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2411 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2412 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2417 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2418 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2419 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2423 void do_inventory ( char * u
)
2427 if (!( user
= find ( u
)))
2429 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2432 else if ( isIgnore ( user
))
2435 log ( "Ignoring %s ." , user
-> getNick ());
2439 else if (! is_playing ( user
))
2441 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2444 updateTS ( user
-> stats
);
2445 showinventory ( user
, user
);
2447 void showinventory ( aClient
* from
, aClient
* to
)
2449 char * nick
= to
-> getNick ();
2453 if ( is_playing ( from
))
2455 Pouch
* p
= & from
-> stats
-> inventory
;
2456 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2457 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2458 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2459 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2460 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2463 void do_tavern ( char * u
)
2465 char * cmd
= strtok ( NULL
, " " );
2471 if (!( user
= find ( u
)))
2473 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2476 else if ( isIgnore ( user
))
2479 log ( "Ignoring %s ." , user
-> getNick ());
2483 else if (! is_playing ( user
))
2485 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2488 else if ( is_fighting ( user
))
2490 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2494 updateTS ( user
-> stats
);
2499 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2500 notice ( s_GameServ
, u
, "Your commands:" );
2501 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2502 notice ( s_GameServ
, u
, "What'll it be?" );
2504 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2506 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2507 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2508 1000 * p
-> level
* 4 );
2509 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2510 2500 * p
-> level
* 4 );
2511 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2512 3000 * p
-> level
* 4 );
2513 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2514 2000 * p
-> level
* 4 );
2515 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2516 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2518 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2520 char * chnum
= strtok ( NULL
, " " );
2524 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2525 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2528 int num
= stringtoint ( chnum
);
2530 if ( num
< 1 || num
> 4 )
2532 notice ( s_GameServ
, u
, "Invalid Choice!" );
2533 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2534 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2535 1000 * p
-> level
* 4 );
2536 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2537 2500 * p
-> level
* 4 );
2538 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2539 3000 * p
-> level
* 4 );
2540 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2541 2000 * p
-> level
* 4 );
2542 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2543 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2549 price
= ( 1000 * p
-> level
* 4 );
2550 if ( p
-> gold
>= price
)
2552 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2553 p
-> inventory
. incHealing ();
2557 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2560 price
= 2500 * p
-> level
* 4 ;
2561 if ( p
-> gold
>= price
)
2563 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2564 p
-> inventory
. incStrength ();
2568 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2571 price
= 3000 * p
-> level
* 4 ;
2572 if ( p
-> gold
>= price
)
2574 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2575 p
-> inventory
. incDefense ();
2579 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2582 price
= 3000 * p
-> level
* 4 ;
2583 if ( p
-> gold
>= price
)
2585 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2586 p
-> inventory
. incHP ();
2590 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2593 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2599 notice ( s_GameServ
, u
, "Improper Syntax." );
2600 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2604 void do_bank ( char * u
)
2606 char * cmd
= strtok ( NULL
, " " );
2607 char * amount
= strtok ( NULL
, " " );
2608 char * nick
= strtok ( NULL
, " " );
2613 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2615 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2616 notice ( s_GameServ
, u
, "BANK BALANCE" );
2619 else if (!( user
= find ( u
)))
2621 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2623 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2626 else if ( isIgnore ( user
))
2629 log ( "Ignoring %s ." , user
-> getNick ());
2633 else if (! is_playing ( user
))
2635 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2638 else if ( is_fighting ( user
))
2640 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2643 updateTS ( user
-> stats
);
2644 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2649 else if (! isAlive ( user
-> stats
))
2651 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2654 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2656 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2659 if ( stringtoint ( amount
) < 0 )
2661 notice ( s_GameServ
, u
, "Sorry. This bank is not licensed " \
2662 "to handle such sums of cash, noble Lord." );
2667 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2669 if ( p
-> bank
== 2000000000 )
2671 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2674 else if ( stricmp ( amount
, "ALL" ) == 0 )
2676 if ( 2000000000 - p
-> bank
< p
-> gold
)
2678 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2679 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2680 p
-> gold
-= ( 2000000000 - p
-> bank
);
2681 p
-> bank
= 2000000000 ;
2686 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2692 else if ( stringtoint ( amount
) > p
-> gold
)
2694 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2700 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2702 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2703 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2704 p
-> gold
-= ( 2000000000 - p
-> bank
);
2705 p
-> bank
= 2000000000 ;
2710 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2711 p
-> bank
+= stringtoint ( amount
);
2712 p
-> gold
-= stringtoint ( amount
);
2717 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2719 if ( p
-> gold
== 2000000000 )
2721 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2725 else if ( stricmp ( amount
, "ALL" ) == 0 )
2727 if ( 2000000000 - p
-> gold
< p
-> bank
)
2729 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2730 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2731 p
-> bank
-= ( 2000000000 - p
-> gold
);
2732 p
-> gold
= 2000000000 ;
2737 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2743 else if ( stringtoint ( amount
) > p
-> bank
)
2745 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2751 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2753 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2754 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2755 ( 2000000000 - p
-> gold
));
2756 p
-> bank
-= ( 2000000000 - p
-> gold
);
2757 p
-> gold
= 2000000000 ;
2762 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2763 p
-> gold
+= stringtoint ( amount
);
2764 p
-> bank
-= stringtoint ( amount
);
2772 void do_dragon ( char * u
)
2776 if (!( user
= find ( u
)))
2778 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2781 else if ( isIgnore ( user
))
2784 log ( "Ignoring %s ." , user
-> getNick ());
2788 else if (! is_playing ( user
))
2790 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2793 else if ( is_fighting ( user
))
2795 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2798 else if (! isAlive ( user
-> stats
))
2800 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2803 else if ( user
-> stats
-> level
< REALLEVELS
)
2805 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2806 "to vanquish any foe should DARE fight the dragon!" );
2807 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2808 "You are too weak. You must be Level %d !" , REALLEVELS
);
2812 updateTS ( user
-> stats
);
2814 Player
* p
= user
-> stats
;
2815 p
-> fight
= new Monster ( boss
);
2816 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2817 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2818 "deep, red fog rolls in. The air is filled with the " \
2819 "heated mist of deadly fire from beyond the cave " \
2821 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2822 "your %s , and venture into the hot, dark cave. " \
2823 "You are surprised at the angle of descent as you climb " \
2824 "lower and lower, deeper into the dragon's den." );
2825 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2826 "a tooth. It is a large tooth... bigger than your torso." \
2827 " Suddenly the darkness lifts from the gleam of an eye " \
2828 " staring into your soul! The eye is large... HUGE!" );
2829 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2830 "glare orange! The tooth is moving... but it is still too " \
2831 "dark for you to make out.... THE DRAGON! You see it!" );
2835 void do_master ( char * u
)
2840 if (!( user
= find ( u
)))
2842 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2845 else if ( isIgnore ( user
))
2848 log ( "Ignoring %s ." , user
-> getNick ());
2852 else if (! is_playing ( user
))
2854 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2857 else if ( is_fighting ( user
))
2859 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2862 else if (! isAlive ( user
-> stats
))
2864 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2868 updateTS ( user
-> stats
);
2870 char * cmd
= strtok ( NULL
, " " );
2871 Player
* p
= user
-> stats
;
2876 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2920 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
2924 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2930 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2934 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2942 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
));
2945 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2948 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
);
2950 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2956 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2960 void see_master ( char * u
)
2964 if (!( user
= find ( u
)))
2966 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2970 if (! is_fighting ( user
) && is_playing ( user
))
2972 Player
* p
= user
-> stats
;
2973 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2974 p
-> fight
= p
-> master
;
2975 display_monster ( u
); // Since master is the same structure, use this function
2979 void showBankBalance ( const char * u
)
2984 if (!( user
= find ( u
)))
2992 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2998 ListNode
< aClient
> * it
;
3000 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3002 it
= players
[ x
]. First ();
3006 p
= it
-> getData ()-> stats
;
3013 void refresh ( Player
* p
)
3018 if ( p
-> hp
< p
-> maxhp
)
3020 p
-> forest_fights
= forestfights
;
3021 p
-> player_fights
= 3 ;
3026 void do_refresh ( char * u
)
3028 char * nick
= strtok ( NULL
, " " );
3031 if (!( user
= find ( u
)))
3033 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3034 log ( "Error: aClient not found: %s " , u
);
3037 else if ( isIgnore ( user
))
3040 log ( "Ignoring %s ." , user
-> getNick ());
3044 else if (! isAdmin ( user
))
3046 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3051 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3054 else if ( stricmp ( nick
, "ALL" ) == 0 )
3056 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3059 else if (( user
= findplayer ( nick
)))
3061 if ( is_playing ( user
))
3064 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3066 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3068 refresh ( user
-> stats
);
3073 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3075 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3081 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3089 ListNode
< aClient
> * it
;
3092 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3094 it
= players
[ x
]. First ();
3098 p
= it
-> getData ()-> stats
;
3105 void reset ( Player
* p
)
3113 void updateTS ( Player
* p
)
3119 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3121 p
-> lastcommand
= time ( NULL
);
3123 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3128 bool timedOut ( Player
* p
)
3132 else if ( p
-> lastcommand
== 0 )
3136 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3143 void timeOutEvent ( Player
* p
)
3145 aClient
* user
= findplayer ( p
-> name
);
3147 if (! user
|| ! p
-> client
) // then they're not playing
3150 char * nick
= user
-> getNick ();
3152 if ( player_fight ( user
) && isYourTurn ( p
))
3154 // Check to see if they were the idler or if it was the other
3156 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3158 // This person's last command was given earlier,
3159 // so this person is the idler
3160 notice ( s_GameServ
, nick
, "You timed out " \
3161 "during a fight. You lose your turn!" );
3162 notice ( s_GameServ
, p
-> battle
-> getNick (),
3163 " %s hesitated for too long. Your move." , p
-> name
);
3165 setYourTurn ( p
-> battle
-> stats
);
3167 // Update the TS for both players to give them another
3168 // Chance to wake up, but if the other player doesn't
3169 // Attack now, they both get logged out.
3171 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3172 display_players ( p
-> battle
);
3177 notice ( s_GameServ
, p
-> battle
-> getNick (),
3178 "You and %s timed out at the same time." \
3179 " Don't fight if you're just going to " \
3180 "sit there!" , p
-> name
);
3181 notice ( s_GameServ
, user
-> getNick (),
3182 "You and %s timed out at the same time." \
3183 " Don't fight if you're just going to " \
3184 "sit there!" , p
-> battle
-> stats
-> name
);
3190 else if (! player_fight ( user
))
3192 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3194 // Place fun stuff here :)
3195 int randnum
= 1 + rand () % 100 ; // 1-100
3196 #define GSN(s) notice(s_GameServ, nick, s)
3197 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3201 // 35-100% of your gold goes pffft - kain
3202 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3204 GSN ( "You stop for a moment to rest on the " \
3205 "street corner. All of a sudden, you " \
3206 "are ambushed from all sides by a hoarde " \
3207 "of knife wielding thugs." );
3208 GSN2 ( "The thugs beat you into utter submission " \
3209 "and steal %d gold from you!" , stolen
);
3210 user
-> stats
-> gold
-= stolen
;
3212 else if ( randnum
>= 50 && randnum
< 75 )
3214 // 25-65% of your gold goes pffft - kain
3215 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3216 GSN ( "While dilly dallying around, you lose " \
3217 "your sense of time. Little did you know, " \
3218 "but thieves lifted your gold while you " \
3219 "weren't watching." );
3220 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3221 user
-> stats
-> gold
-= stolen
;
3223 else if ( randnum
>= 75 )
3225 // 25-75% of your gold goes pffft - kain
3226 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3227 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3228 "goblins grabbed your gold!" );
3229 GSN2 ( "They stole %d gold from you!" , stolen
);
3230 user
-> stats
-> gold
-= stolen
;
3234 // Always log out the user
3239 void do_reset ( char * u
)
3241 char * nick
= strtok ( NULL
, " " );
3244 if (!( user
= find ( u
)))
3246 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3247 log ( "Error: aClient not found: %s " , u
);
3250 else if (! isAdmin ( user
))
3252 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3258 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3261 else if ( stricmp ( nick
, "ALL" ) == 0 )
3263 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3266 else if (( user
= findbyrealnick ( nick
)))
3268 if ( is_playing ( user
))
3271 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3273 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3280 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3282 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3288 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3293 void do_help ( char * u
)
3295 char * cmd
= strtok ( NULL
, " " );
3297 display_help ( u
, cmd
);
3300 void display_help ( char * u
, char * file
)
3307 infile
. open ( "helpfiles/help" );
3310 log ( "Error opening helpfiles/help" );
3311 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3314 buf
= new char [ 1024 ];
3315 while ( infile
. getline ( buf
, 1024 ))
3317 // Written this way, it will process %S in the helpfiles
3318 // Instead of notice(s_GameServ, u, "%s", buf);
3319 notice ( s_GameServ
, u
, buf
);
3323 aClient
* user
= find ( u
);
3324 if ( user
&& isAdmin ( user
))
3325 display_help ( u
, "admin_commands" );
3330 filename
= new char [ strlen ( file
) + 11 ];
3331 strcpy ( filename
, "helpfiles/" );
3332 strcat ( filename
, file
);
3334 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3335 filename
[ x
] = tolower ( filename
[ x
]);
3337 infile
. open ( filename
);
3341 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3344 buf
= new char [ 1024 ];
3345 while ( infile
. getline ( buf
, 1024 ))
3347 // Written this way, it will process %S in the helpfiles
3348 // Instead of notice(s_GameServ, u, "%s", buf);
3349 notice ( s_GameServ
, u
, buf
);
3356 void do_admin ( char * u
)
3359 char * pass
= strtok ( NULL
, " " );
3361 if (!( user
= find ( u
)))
3363 log ( "Error: aClient not found: %s " , u
);
3364 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3370 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3376 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3379 else if ( strcmp ( pass
, adminpass
) == 0 )
3381 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3384 log ( " %s became an administrator." , user
-> getRealNick ());
3386 log ( " %s became an administrator." , user
-> getNick ());
3391 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3396 bool load_monsters ()
3399 infile
. open ( "monsters.dat" );
3405 log ( "Error opening monsters.dat" );
3409 buf
= new char [ 2048 ];
3412 log ( "Loading monsters from monsters.dat" );
3415 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3417 for ( int m
= 0 ; m
< MONSTERS
;)
3419 infile
. getline ( buf
, 2048 );
3420 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3424 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3425 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3426 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3427 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3428 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3429 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3430 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3431 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));