From 837194519b2be29aa7665828e4d7cb8035fe1c3b Mon Sep 17 00:00:00 2001 From: MadCamel Date: Sat, 29 Aug 2009 20:43:53 -0400 Subject: Converted to Mersenne Twister for random. Randomerer! Also: Fixed a security problem. Can you find it? --- src/char/Makefile | 4 +- src/common/Makefile | 3 +- src/common/core.c | 3 ++ src/common/mt_rand.c | 110 +++++++++++++++++++++++++++++++++++++++ src/common/mt_rand.h | 8 +++ src/common/utils.h | 3 +- src/ladmin/GNUmakefile | 4 +- src/ladmin/Makefile | 4 +- src/login/Makefile | 4 +- src/login/login.c | 7 ++- src/map/Makefile | 2 +- src/map/atcommand.c | 22 ++++---- src/map/battle.c | 1 + src/map/clif.c | 8 +-- src/map/map.c | 6 +-- src/map/pc.c | 22 ++++---- src/map/skill.c | 136 ++++++++++++++++++++++++------------------------- 17 files changed, 234 insertions(+), 113 deletions(-) create mode 100644 src/common/mt_rand.c create mode 100644 src/common/mt_rand.h diff --git a/src/char/Makefile b/src/char/Makefile index d4344a0..841edfd 100644 --- a/src/char/Makefile +++ b/src/char/Makefile @@ -1,8 +1,8 @@ all: char-server txt: char-server -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/malloc.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/malloc.h ../common/mt_rand.h char-server: char.o inter.o int_party.o int_guild.o int_storage.o $(COMMON_OBJ) $(CC) -o ../../$@ $> diff --git a/src/common/Makefile b/src/common/Makefile index b5b8f7c..9218a55 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -1,4 +1,4 @@ -txt sql all: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o malloc.o +txt sql all: core.o socket.o timer.o grfio.o db.o lock.o nullpo.o malloc.o mt_rand.o core.o: core.c core.h socket.o: socket.c socket.h mmo.h @@ -8,6 +8,7 @@ db.o: db.c db.h lock.o: lock.h nullpo.o: nullpo.c nullpo.h malloc.o: malloc.c malloc.h +mt_rand.o: mt_rand.c mt_rand.h clean: rm -f *.o diff --git a/src/common/core.c b/src/common/core.c index 7267d8f..94a754b 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -13,6 +13,7 @@ #include "socket.h" #include "timer.h" #include "version.h" +#include "mt_rand.h" #ifdef MEMWATCH #include "memwatch.h" @@ -133,6 +134,8 @@ int main(int argc,char **argv) { int next; + mt_seed(time(NULL) ^ getpid() ^ getppid()); + Net_Init(); do_socket(); diff --git a/src/common/mt_rand.c b/src/common/mt_rand.c new file mode 100644 index 0000000..ab733ae --- /dev/null +++ b/src/common/mt_rand.c @@ -0,0 +1,110 @@ +/* +// This is the ``Mersenne Twister'' random number generator MT19937, which +// generates pseudorandom integers uniformly distributed in 0..(2^32 - 1) +// starting from any odd seed in 0..(2^32 - 1). This version is a recode +// by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by +// Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in +// July-August 1997). +// +// Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha +// running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to +// generate 300 million random numbers; after recoding: 24.0 sec. for the same +// (i.e., 46.5% of original time), so speed is now about 12.5 million random +// number generations per second on this machine. +// +// According to the URL +// (and paraphrasing a bit in places), the Mersenne Twister is ``designed +// with consideration of the flaws of various existing generators,'' has +// a period of 2^19937 - 1, gives a sequence that is 623-dimensionally +// equidistributed, and ``has passed many stringent tests, including the +// die-hard test of G. Marsaglia and the load test of P. Hellekalek and +// S. Wegenkittl.'' It is efficient in memory usage (typically using 2506 +// to 5012 bytes of static data, depending on data type sizes, and the code +// is quite short as well). It generates random numbers in batches of 624 +// at a time, so the caching and pipelining of modern systems is exploited. +// It is also divide- and mod-free. +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Library General Public License as published by +// the Free Software Foundation (either version 2 of the License or, at your +// option, any later version). This library is distributed in the hope that +// it will be useful, but WITHOUT ANY WARRANTY, without even the implied +// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +// the GNU Library General Public License for more details. You should have +// received a copy of the GNU Library General Public License along with this +// library; if not, write to the Free Software Foundation, Inc., 59 Temple +// Place, Suite 330, Boston, MA 02111-1307, USA. +// +// The code as Shawn received it included the following notice: +// +// Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When +// you use this, send an e-mail to with +// an appropriate reference to your work. +// +// It would be nice to CC: when you write. +// +*/ + +#include +#include "mt_rand.h" + +#define N (624) /* length of state vector */ +#define M (397) /* a period parameter */ +#define K (0x9908B0DFU) /* a magic constant */ +#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */ +#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */ +#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ +#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ + +static unsigned long state[N+1]; /* state vector + 1 extra to not violate ANSI C */ +static unsigned long *next; /* next random value is computed from here */ +static int left = -1; /* can *next++ this many times before reloading */ + + +void mt_seed(unsigned long seed) +{ + register unsigned long x = (seed | 1U) & 0xFFFFFFFFU, *s = state; + register int j; + + for(left=0, *s++=x, j=N; --j; + *s++ = (x*=69069U) & 0xFFFFFFFFU); +} + + +unsigned long mt_reload(void) +{ + register unsigned long *p0=state, *p2=state+2, *pM=state+M, s0, s1; + register int j; + + if(left < -1) + mt_seed(time(NULL)); + + left=N-1, next=state+1; + + for(s0=state[0], s1=state[1], j=N-M+1; --j; s0=s1, s1=*p2++) + *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); + + for(pM=state, j=M; --j; s0=s1, s1=*p2++) + *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); + + s1=state[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); + s1 ^= (s1 >> 11); + s1 ^= (s1 << 7) & 0x9D2C5680U; + s1 ^= (s1 << 15) & 0xEFC60000U; + return(s1 ^ (s1 >> 18)); +} + + +unsigned long mt_random(void) +{ + unsigned long y; + + if(--left < 0) + return(mt_reload()); + + y = *next++; + y ^= (y >> 11); + y ^= (y << 7) & 0x9D2C5680U; + y ^= (y << 15) & 0xEFC60000U; + return(y ^ (y >> 18)); +} diff --git a/src/common/mt_rand.h b/src/common/mt_rand.h new file mode 100644 index 0000000..07f6ef0 --- /dev/null +++ b/src/common/mt_rand.h @@ -0,0 +1,8 @@ +#ifndef __mt_rand_h +#define __mt_rand_h + +void mt_seed(unsigned long seed); +unsigned long mt_reload(void); +unsigned long mt_random(void); + +#endif /* __mt_rand_h */ diff --git a/src/common/utils.h b/src/common/utils.h index 794a0b6..ba96da1 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -1,3 +1,4 @@ +#include "mt_rand.h" #ifndef NULL #define NULL (void *)0 @@ -38,5 +39,5 @@ * MRAND(10), returns 0-9. * MPRAND(5,10) returns 5-14. */ -#define MRAND(mod) (int) ((float)mod * (rand() / (RAND_MAX + 1.0))) +#define MRAND(mod) (int) ((float)mod * (mt_random() / (RAND_MAX + 1.0))) #define MPRAND(add, mod) add + MRAND(mod) diff --git a/src/ladmin/GNUmakefile b/src/ladmin/GNUmakefile index 768626f..bed7b6b 100644 --- a/src/ladmin/GNUmakefile +++ b/src/ladmin/GNUmakefile @@ -2,8 +2,8 @@ all: ladmin txt: ladmin sql: ladmin -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o ../common/mt_rand.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h ../common/mt_rand.h ladmin: ladmin.o md5calc.o $(COMMON_OBJ) $(CC) -o ../../$@ ladmin.o md5calc.o $(COMMON_OBJ) diff --git a/src/ladmin/Makefile b/src/ladmin/Makefile index 768626f..bed7b6b 100644 --- a/src/ladmin/Makefile +++ b/src/ladmin/Makefile @@ -2,8 +2,8 @@ all: ladmin txt: ladmin sql: ladmin -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/malloc.o ../common/mt_rand.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/malloc.h ../common/mt_rand.h ladmin: ladmin.o md5calc.o $(COMMON_OBJ) $(CC) -o ../../$@ ladmin.o md5calc.o $(COMMON_OBJ) diff --git a/src/login/Makefile b/src/login/Makefile index d807238..0411129 100644 --- a/src/login/Makefile +++ b/src/login/Makefile @@ -1,8 +1,8 @@ all: login-server txt: login-server -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/lock.h ../common/malloc.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h ../common/db.h ../common/lock.h ../common/malloc.h ../common/mt_rand.h login-server: login.o md5calc.o $(COMMON_OBJ) $(CC) -o ../../$@ login.o md5calc.o $(COMMON_OBJ) diff --git a/src/login/login.c b/src/login/login.c index 6c4ca82..b44eb19 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -25,6 +25,7 @@ #include "version.h" #include "db.h" #include "lock.h" +#include "mt_rand.h" #ifdef PASSWORDENC #include "md5calc.h" @@ -1153,8 +1154,8 @@ int mmo_auth(struct mmo_account* account, int fd) { sprintf(tmpstr + strlen(tmpstr), ".%03d", (int)tv.tv_usec / 1000); account->account_id = auth_dat[i].account_id; - account->login_id1 = rand(); - account->login_id2 = rand(); + account->login_id1 = mt_random(); + account->login_id2 = mt_random(); memcpy(account->lastlogin, auth_dat[i].lastlogin, 24); memcpy(auth_dat[i].lastlogin, tmpstr, 24); account->sex = auth_dat[i].sex; @@ -3785,8 +3786,6 @@ int do_init(int argc, char **argv) { save_config_in_log(); // not before, because log file name can be changed login_lan_config_read((argc > 1) ? argv[1] : LAN_CONF_NAME); - srand(time(NULL)); - for(i = 0; i< AUTH_FIFO_SIZE; i++) auth_fifo[i].delflag = 1; for(i = 0; i < MAX_SERVERS; i++) diff --git a/src/map/Makefile b/src/map/Makefile index f02d43f..7fe6876 100644 --- a/src/map/Makefile +++ b/src/map/Makefile @@ -8,7 +8,7 @@ txt: obj map-server obj: mkdir obj -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/malloc.o +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/malloc.o ../common/mt_rand.o LIBS = -lz -lm map-server: obj/tmw.o obj/magic-interpreter-lexer.o obj/magic-interpreter-parser.o obj/magic-interpreter-base.o obj/magic-expr.o obj/magic-stmt.o obj/magic.o obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/npc.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o obj/storage.o obj/skill.o obj/atcommand.o obj/battle.o obj/intif.o obj/trade.o obj/party.o obj/guild.o $(COMMON_OBJ) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index de44d77..ed213b2 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -887,9 +887,9 @@ int atcommand_charwarp( } if (x <= 0) - x = rand() % 399 + 1; + x = MRAND(399) + 1; if (y <= 0) - y = rand() % 399 + 1; + y = MRAND(399) + 1; if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); @@ -946,9 +946,9 @@ int atcommand_warp(const int fd, struct map_session_data* sd, const char* comman } if (x <= 0) - x = rand() % 399 + 1; + x = MRAND(399) + 1; if (y <= 0) - y = rand() % 399 + 1; + y = MRAND(399) + 1; if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); @@ -1057,9 +1057,9 @@ int atcommand_jump(const int fd, struct map_session_data* sd, const char* comman sscanf(message, "%d %d", &x, &y); if (x <= 0) - x = rand() % 399 + 1; + x = MRAND(399) + 1; if (y <= 0) - y = rand() % 399 + 1; + y = MRAND(399) + 1; if (x > 0 && x < 400 && y > 0 && y < 400) { if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to your actual map."); @@ -2537,11 +2537,11 @@ int atcommand_spawn(const int fd, struct map_session_data* sd, const char* comma k = 0; while(j++ < 8 && k == 0) { // try 8 times to spawn the monster (needed for close area) if (x <= 0) - mx = sd->bl.x + (rand() % range - (range / 2)); + mx = sd->bl.x + (MRAND(range) - (range / 2)); else mx = x; if (y <= 0) - my = sd->bl.y + (rand() % range - (range / 2)); + my = sd->bl.y + (MRAND(range) - (range / 2)); else my = y; k = mob_once_spawn((struct map_session_data*)sd, "this", mx, my, "", mob_id, 1, ""); @@ -5461,7 +5461,7 @@ int atcommand_jail( if ((pl_sd = map_nick2sd(character)) != NULL) { if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can jail only lower or same GM - switch(rand() % 2) { + switch(MRAND(2)) { case 0: x = 24; y = 75; @@ -6822,8 +6822,8 @@ int atcommand_summon(const int fd, struct map_session_data* sd, const char* comm if(mob_id == 0) return -1; - x = sd->bl.x + (rand() % 10 - 5); - y = sd->bl.y + (rand() % 10 - 5); + x = sd->bl.x + (MRAND(10) - 5); + y = sd->bl.y + (MRAND(10) - 5); id = mob_once_spawn(sd,"this", x, y, "--ja--", mob_id, 1, ""); if((md=(struct mob_data *)map_id2bl(id))){ diff --git a/src/map/battle.c b/src/map/battle.c index c21d69c..e424ef9 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -18,6 +18,7 @@ #include "pc.h" #include "skill.h" #include "../common/socket.h" +#include "mt_rand.h" #ifdef MEMWATCH #include "memwatch.h" diff --git a/src/map/clif.c b/src/map/clif.c index a53177d..aa7fea4 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -3369,9 +3369,9 @@ int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick, type = 9; if(sc_data[SC_HALLUCINATION].timer != -1) { if(damage > 0) - damage = damage*(5+sc_data[SC_HALLUCINATION].val1) + rand()%100; + damage = damage*(5+sc_data[SC_HALLUCINATION].val1) + MRAND(100); if(damage2 > 0) - damage2 = damage2*(5+sc_data[SC_HALLUCINATION].val1) + rand()%100; + damage2 = damage2*(5+sc_data[SC_HALLUCINATION].val1) + MRAND(100); } } @@ -3881,7 +3881,7 @@ int clif_skill_damage(struct block_list *src,struct block_list *dst, if(type != 5 && sc_data[SC_ENDURE].timer != -1) type = 9; if(sc_data[SC_HALLUCINATION].timer != -1 && damage > 0) - damage = damage*(5+sc_data[SC_HALLUCINATION].val1) + rand()%100; + damage = damage*(5+sc_data[SC_HALLUCINATION].val1) + MRAND(100); } WBUFW(buf,0)=0x1de; @@ -3921,7 +3921,7 @@ int clif_skill_damage2(struct block_list *src,struct block_list *dst, if(type != 5 && sc_data[SC_ENDURE].timer != -1) type = 9; if(sc_data[SC_HALLUCINATION].timer != -1 && damage > 0) - damage = damage*(5+sc_data[SC_HALLUCINATION].val1) + rand()%100; + damage = damage*(5+sc_data[SC_HALLUCINATION].val1) + MRAND(100); } WBUFW(buf,0)=0x115; diff --git a/src/map/map.c b/src/map/map.c index 86acb62..b3f9dd5 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -709,7 +709,7 @@ int map_searchrandfreecell(int m,int x,int y,int range) { } if(free_cell==0) return -1; - free_cell=rand()%free_cell; + free_cell=MRAND(free_cell); for(i=-range;i<=range;i++){ if(i+y<0 || i+y>=map[m].ys) continue; @@ -750,7 +750,7 @@ int map_addflooritem_any(struct item *item_data, int amount, int m, int x, int y if((xy=map_searchrandfreecell(m,x,y, dispersal))<0) return 0; - r=rand(); + r=mt_random(); fitem = (struct flooritem_data *)aCalloc(1,sizeof(*fitem)); fitem->bl.type=BL_ITEM; @@ -1833,8 +1833,6 @@ int do_init(int argc, char *argv[]) { unsigned char *MSG_CONF_NAME = "conf/msg_athena.conf"; unsigned char *GRF_PATH_FILENAME = "conf/grf-files.txt"; - srand(gettick()); - for (i = 1; i < argc ; i++) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--h") == 0 || strcmp(argv[i], "--?") == 0 || strcmp(argv[i], "/?") == 0) diff --git a/src/map/pc.c b/src/map/pc.c index d7c2b28..34cb59a 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -571,7 +571,7 @@ int pc_breakweapon(struct map_session_data *sd) if(sd==NULL) return -1; - if(sd->unbreakable>=rand()%100) + if(sd->unbreakable>=MRAND(100)) return 0; if(sd->sc_data && sd->sc_data[SC_CP_WEAPON].timer != -1) return 0; @@ -608,7 +608,7 @@ int pc_breakarmor(struct map_session_data *sd) if(sd==NULL) return -1; - if(sd->unbreakable>=rand()%100) + if(sd->unbreakable>=MRAND(100)) return 0; if(sd->sc_data && sd->sc_data[SC_CP_ARMOR].timer != -1) return 0; @@ -3399,8 +3399,8 @@ int pc_steal_coin(struct map_session_data *sd,struct block_list *bl) if(md && !md->state.steal_coin_flag && md->sc_data && md->sc_data[SC_STONE].timer == -1 && md->sc_data[SC_FREEZE].timer == -1) { skill = pc_checkskill(sd,RG_STEALCOIN)*10; rate = skill + (sd->status.base_level - mob_db[md->class].lv)*3 + sd->paramc[4]*2 + sd->paramc[5]*2; - if(rand()%1000 < rate) { - pc_getzeny(sd,mob_db[md->class].lv*10 + rand()%100); + if(MRAND(1000) < rate) { + pc_getzeny(sd,mob_db[md->class].lv*10 + MRAND(100)); md->state.steal_coin_flag = 1; return 1; } @@ -3515,8 +3515,8 @@ int pc_setpos(struct map_session_data *sd,char *mapname_org,int x,int y,int clrt printf("stacked (%d,%d)\n",x,y); } do { - x=rand()%(map[m].xs-2)+1; - y=rand()%(map[m].ys-2)+1; + x=MRAND(map[m].xs-2)+1; + y=MRAND(map[m].ys-2)+1; } while((c=read_gat(m,x,y))==1 || c==5); } @@ -3563,8 +3563,8 @@ int pc_randomwarp(struct map_session_data *sd, int type) { return 0; do{ - x=rand()%(map[m].xs-2)+1; - y=rand()%(map[m].ys-2)+1; + x=MRAND(map[m].xs-2)+1; + y=MRAND(map[m].ys-2)+1; } while (((c=read_gat(m,x,y)) == 1 || c == 5) && (i++) < 1000); if (i < 1000) @@ -5099,8 +5099,8 @@ int pc_damage(struct block_list *src,struct map_session_data *sd,int damage) } } if(eq_num > 0){ - int n = eq_n[rand()%eq_num];//�Y���A�C�e���̒����烉���_�� - if(rand()%10000 < per){ + int n = eq_n[MRAND(eq_num)];//�Y���A�C�e���̒����烉���_�� + if(MRAND(10000) < per){ if(sd->status.inventory[n].equip) pc_unequipitem(sd,n,0); pc_dropitem(sd,n,1); @@ -5110,7 +5110,7 @@ int pc_damage(struct block_list *src,struct map_session_data *sd,int damage) else if(id > 0){ for(i=0;istatus.inventory[i].nameid == id//ItemID�����v���Ă��� - && rand()%10000 < per//�h���b�v��������OK�� + && MRAND(10000) < per//�h���b�v��������OK�� && ((type == 1 && !sd->status.inventory[i].equip)//�^�C�v������OK�Ȃ��h���b�v || (type == 2 && sd->status.inventory[i].equip) || type == 3) ){ diff --git a/src/map/skill.c b/src/map/skill.c index c661dc2..0539f9a 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -943,13 +943,13 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s case 0: /* ʏU */ /* */ if( sd && pc_isfalcon(sd) && sd->status.weapon == 11 && (skill=pc_checkskill(sd,HT_BLITZBEAT))>0 && - rand()%1000 <= sd->paramc[5]*10/3+1 ) { + MRAND(1000) <= sd->paramc[5]*10/3+1 ) { int lv=(sd->status.job_level+9)/10; skill_castend_damage_id(src,bl,HT_BLITZBEAT,(skillstatus.weapon != 11 && (skill=pc_checkskill(sd,RG_SNATCHER)) > 0) - if((skill*15 + 55) + (skill2 = pc_checkskill(sd,TF_STEAL))*10 > rand()%1000) { + if((skill*15 + 55) + (skill2 = pc_checkskill(sd,TF_STEAL))*10 > MRAND(1000)) { if(pc_steal_item(sd,bl)) clif_skill_nodamage(src,bl,TF_STEAL,skill2,1); else @@ -959,14 +959,14 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s case SM_BASH: /* obVi}Uj */ if( sd && (skill=pc_checkskill(sd,SM_FATALBLOW))>0 ){ - if( rand()%100 < 6*(skilllv-5)*sc_def_vit/100 ) + if(MRAND(100) < 6*(skilllv-5)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(SM_FATALBLOW,skilllv),0); } break; case TF_POISON: /* Cxi */ case AS_SPLASHER: /* xiXvbV[ */ - if(rand()%100< (2*skilllv+10)*sc_def_vit/100 ) + if(MRAND(100) < (2*skilllv+10)*sc_def_vit/100 ) skill_status_change_start(bl,SC_POISON,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); else{ if(sd && skillid==TF_POISON) @@ -975,14 +975,14 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s break; case AS_SONICBLOW: /* \jbNu[ */ - if( rand()%100 < (2*skilllv+10)*sc_def_vit/100 ) + if(MRAND(100) < (2*skilllv+10)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case HT_FREEZINGTRAP: /* t[WOgbv */ rate=skilllv*3+35; - if(rand()%100 < rate*sc_def_mdef/100) + if(MRAND(100) < rate*sc_def_mdef/100) skill_status_change_start(bl,SC_FREEZE,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; @@ -990,7 +990,7 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s case WZ_FROSTNOVA: /* tXgm@ */ rate=(skilllv*3+35)*sc_def_mdef/100-(battle_get_int(bl)+battle_get_luk(bl))/15; rate=rate<=5?5:rate; - if(rand()%100 < rate) + if(MRAND(100) < rate) skill_status_change_start(bl,SC_FREEZE,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); else if(sd) clif_skill_fail(sd,skillid,0,0); @@ -1008,7 +1008,7 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s break; case HT_LANDMINE: /* h}C */ - if( rand()%100 < (5*skilllv+30)*sc_def_vit/100 ) + if( MRAND(100) < (5*skilllv+30)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; @@ -1019,62 +1019,62 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s } break; case HT_SANDMAN: /* Th} */ - if( rand()%100 < (5*skilllv+30)*sc_def_int/100 ) + if( MRAND(100) < (5*skilllv+30)*sc_def_int/100 ) skill_status_change_start(bl,SC_SLEEP,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case TF_SPRINKLESAND: /* ܂ */ - if( rand()%100 < 15*sc_def_int/100 ) + if( MRAND(100) < 15*sc_def_int/100 ) skill_status_change_start(bl,SC_BLIND,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case TF_THROWSTONE: /* Γ */ - if( rand()%100 < 5*sc_def_vit/100 ) + if( MRAND(100) < 5*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case CR_HOLYCROSS: /* z[[NX */ - if( rand()%100 < 3*skilllv*sc_def_int/100 ) + if( MRAND(100) < 3*skilllv*sc_def_int/100 ) skill_status_change_start(bl,SC_BLIND,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case CR_GRANDCROSS: /* OhNX */ { int race = battle_get_race(bl); - if( (battle_check_undead(race,battle_get_elem_type(bl)) || race == 6) && rand()%100 < 100000*sc_def_int/100) //t^Sϐɂ͖ + if( (battle_check_undead(race,battle_get_elem_type(bl)) || race == 6) && MRAND(100) < 100000*sc_def_int/100) //t^Sϐɂ͖ skill_status_change_start(bl,SC_BLIND,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); } break; case CR_SHIELDCHARGE: /* V[h`[W */ - if( rand()%100 < (15 + skilllv*5)*sc_def_vit/100 ) + if( MRAND(100) < (15 + skilllv*5)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case RG_RAID: /* TvCYA^bN */ - if( rand()%100 < (10+3*skilllv)*sc_def_vit/100 ) + if( MRAND(100) < (10+3*skilllv)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); - if( rand()%100 < (10+3*skilllv)*sc_def_int/100 ) + if( MRAND(100) < (10+3*skilllv)*sc_def_int/100 ) skill_status_change_start(bl,SC_BLIND,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case BA_FROSTJOKE: - if(rand()%100 < (15+5*skilllv)*sc_def_mdef/100) + if(MRAND(100) < (15+5*skilllv)*sc_def_mdef/100) skill_status_change_start(bl,SC_FREEZE,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case DC_SCREAM: - if( rand()%100 < (25+5*skilllv)*sc_def_vit/100 ) + if( MRAND(100) < (25+5*skilllv)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case BD_LULLABY: /* qS */ - if( rand()%100 < 15*sc_def_int/100 ) + if( MRAND(100) < 15*sc_def_int/100 ) skill_status_change_start(bl,SC_SLEEP,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; /* MOB̒ljʕtXL */ case NPC_PETRIFYATTACK: - if(rand()%100 < sc_def_mdef) + if(MRAND(100) < sc_def_mdef) skill_status_change_start(bl,sc[skillid-NPC_POISON],skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case NPC_POISON: @@ -1084,12 +1084,12 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s skill_status_change_start(bl,sc[skillid-NPC_POISON],skilllv,0,0,0,skilllv,0); break; case NPC_CURSEATTACK: - if(rand()%100 < sc_def_luk) + if(MRAND(100) < sc_def_luk) skill_status_change_start(bl,sc[skillid-NPC_POISON],skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case NPC_SLEEPATTACK: case NPC_BLINDATTACK: - if(rand()%100 < sc_def_int) + if(MRAND(100) < sc_def_int) skill_status_change_start(bl,sc[skillid-NPC_POISON],skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case NPC_MENTALBREAKER: @@ -1103,43 +1103,43 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s // -- moonsoul (adding status effect chance given to wizard aoe skills meteor and vermillion) // case WZ_METEOR: - if(rand()%100 < sc_def_vit) + if(MRAND(100) < sc_def_vit) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case WZ_VERMILION: - if(rand()%100 < sc_def_int) + if(MRAND(100) < sc_def_int) skill_status_change_start(bl,SC_BLIND,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; // -- moonsoul (stun ability of new champion skill tigerfist) // case CH_TIGERFIST: - if( rand()%100 < (5 + skilllv*5)*sc_def_vit/100 ) + if( MRAND(100) < (5 + skilllv*5)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case LK_SPIRALPIERCE: - if( rand()%100 < (15 + skilllv*5)*sc_def_vit/100 ) + if( MRAND(100) < (15 + skilllv*5)*sc_def_vit/100 ) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case ST_REJECTSWORD: /* t[WOgbv */ - if( rand()%100 < (10 + skilllv*5) ) + if( MRAND(100) < (10 + skilllv*5) ) skill_status_change_start(bl,SC_AUTOCOUNTER,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case PF_FOGWALL: /* z[[NX */ - if( rand()%100 < 3*skilllv*sc_def_int/100 ) + if( MRAND(100) < 3*skilllv*sc_def_int/100 ) skill_status_change_start(bl,SC_BLIND,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case LK_HEADCRUSH: /* wbhNbV */ {//ǂȂ̂œK int race=battle_get_race(bl); - if( !(battle_check_undead(race,battle_get_elem_type(bl)) || race == 6) && rand()%100 < (2*skilllv+10)*sc_def_vit/100 ) + if( !(battle_check_undead(race,battle_get_elem_type(bl)) || race == 6) && MRAND(100) < (2*skilllv+10)*sc_def_vit/100 ) skill_status_change_start(bl,SC_HEADCRUSH,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); } break; case LK_JOINTBEAT: /* WCgr[g */ //ǂȂ̂œK - if( rand()%100 < (2*skilllv+10)*sc_def_vit/100 ) + if( MRAND(100) < (2*skilllv+10)*sc_def_vit/100 ) skill_status_change_start(bl,SC_JOINTBEAT,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case PF_SPIDERWEB: /* XpC_[EFbu */ @@ -1152,9 +1152,9 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s } break; case ASC_METEORASSAULT: /* eIATg */ - if( rand()%100 < (15 + skilllv*5)*sc_def_vit/100 ) //Ԉُ͏ڍׂȂ̂œK + if( MRAND(100) < (15 + skilllv*5)*sc_def_vit/100 ) //Ԉُ͏ڍׂȂ̂œK skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); - if( rand()%100 < (10+3*skilllv)*sc_def_int/100 ) + if( MRAND(100) < (10+3*skilllv)*sc_def_int/100 ) skill_status_change_start(bl,SC_BLIND,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; case MO_EXTREMITYFIST: /* Ce */ @@ -1179,14 +1179,14 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s sc_def_card=sc_def_luk; if(!sd->state.arrow_atk) { - if(rand()%10000 < (sd->addeff[i-SC_STONE])*sc_def_card/100 ){ + if(MRAND(100) < (sd->addeff[i-SC_STONE])*sc_def_card/100 ){ if(battle_config.battle_log) printf("PC %d skill_addeff: cardɂُ픭 %d %d\n",sd->bl.id,i,sd->addeff[i-SC_STONE]); skill_status_change_start(bl,i,7,0,0,0,(i==SC_CONFUSION)? 10000+7000:skill_get_time2(sc2[i-SC_STONE],7),0); } } else { - if(rand()%10000 < (sd->addeff[i-SC_STONE]+sd->arrow_addeff[i-SC_STONE])*sc_def_card/100 ){ + if(MRAND(100) < (sd->addeff[i-SC_STONE]+sd->arrow_addeff[i-SC_STONE])*sc_def_card/100 ){ if(battle_config.battle_log) printf("PC %d skill_addeff: cardɂُ픭 %d %d\n",sd->bl.id,i,sd->addeff[i-SC_STONE]); skill_status_change_start(bl,i,7,0,0,0,(i==SC_CONFUSION)? 10000+7000:skill_get_time2(sc2[i-SC_STONE],7),0); @@ -1203,14 +1203,14 @@ int skill_additional_effect( struct block_list* src, struct block_list *bl,int s sc_def_card=sc_def_luk2; if(!sd->state.arrow_atk) { - if(rand()%10000 < (sd->addeff2[i-SC_STONE])*sc_def_card/100 ){ + if(MRAND(100) < (sd->addeff2[i-SC_STONE])*sc_def_card/100 ){ if(battle_config.battle_log) printf("PC %d skill_addeff: cardɂُ픭 %d %d\n",src->id,i,sd->addeff2[i-SC_STONE]); skill_status_change_start(src,i,7,0,0,0,(i==SC_CONFUSION)? 10000+7000:skill_get_time2(sc2[i-SC_STONE],7),0); } } else { - if(rand()%10000 < (sd->addeff2[i-SC_STONE]+sd->arrow_addeff2[i-SC_STONE])*sc_def_card/100 ){ + if(MRAND(100) < (sd->addeff2[i-SC_STONE]+sd->arrow_addeff2[i-SC_STONE])*sc_def_card/100 ){ if(battle_config.battle_log) printf("PC %d skill_addeff: cardɂُ픭 %d %d\n",src->id,i,sd->addeff2[i-SC_STONE]); skill_status_change_start(src,i,7,0,0,0,(i==SC_CONFUSION)? 10000+7000:skill_get_time2(sc2[i-SC_STONE],7),0); @@ -1564,7 +1564,7 @@ int skill_attack( int attack_type, struct block_list* src, struct block_list *ds int s_lv = battle_get_lv(src),t_lv = battle_get_lv(bl); int rate = 50 + skilllv * 5; rate = rate + (s_lv - t_lv); - if(rand()%100 < rate) + if(MRAND(100) < rate) skill_addtimerskill(src,tick + 800,bl->id,0,0,skillid,skilllv,0,flag); } if(damage > 0 && dmg.flag&BF_SKILL && bl->type==BL_PC && pc_checkskill((struct map_session_data *)bl,RG_PLAGIARISM)){ @@ -1617,22 +1617,22 @@ int skill_attack( int attack_type, struct block_list* src, struct block_list *ds struct map_session_data *sd = (struct map_session_data *)src; int hp = 0,sp = 0; nullpo_retr(0, sd); - if(sd->hp_drain_rate && sd->hp_drain_per > 0 && dmg.damage > 0 && rand()%100 < sd->hp_drain_rate) { + if(sd->hp_drain_rate && sd->hp_drain_per > 0 && dmg.damage > 0 && MRAND(100) < sd->hp_drain_rate) { hp += (dmg.damage * sd->hp_drain_per)/100; if(sd->hp_drain_rate > 0 && hp < 1) hp = 1; else if(sd->hp_drain_rate < 0 && hp > -1) hp = -1; } - if(sd->hp_drain_rate_ && sd->hp_drain_per_ > 0 && dmg.damage2 > 0 && rand()%100 < sd->hp_drain_rate_) { + if(sd->hp_drain_rate_ && sd->hp_drain_per_ > 0 && dmg.damage2 > 0 && MRAND(100) < sd->hp_drain_rate_) { hp += (dmg.damage2 * sd->hp_drain_per_)/100; if(sd->hp_drain_rate_ > 0 && hp < 1) hp = 1; else if(sd->hp_drain_rate_ < 0 && hp > -1) hp = -1; } - if(sd->sp_drain_rate > 0 && sd->sp_drain_per > 0 && dmg.damage > 0 && rand()%100 < sd->sp_drain_rate) { + if(sd->sp_drain_rate > 0 && sd->sp_drain_per > 0 && dmg.damage > 0 && MRAND(100) < sd->sp_drain_rate) { sp += (dmg.damage * sd->sp_drain_per)/100; if(sd->sp_drain_rate > 0 && sp < 1) sp = 1; else if(sd->sp_drain_rate < 0 && sp > -1) sp = -1; } - if(sd->sp_drain_rate_ > 0 && sd->sp_drain_per_ > 0 && dmg.damage2 > 0 && rand()%100 < sd->sp_drain_rate_) { + if(sd->sp_drain_rate_ > 0 && sd->sp_drain_per_ > 0 && dmg.damage2 > 0 && MRAND(100) < sd->sp_drain_rate_) { sp += (dmg.damage2 * sd->sp_drain_per_)/100; if(sd->sp_drain_rate_ > 0 && sp < 1) sp = 1; else if(sd->sp_drain_rate_ < 0 && sp > -1) sp = -1; @@ -1865,7 +1865,7 @@ static int skill_timerskill(int tid, unsigned int tick, int id,int data ) int x,y,i,j,c; pc_randomwarp(sd,3); for(i=0;i<16;i++) { - j = rand()%8; + j = MRAND(8); x = sd->bl.x + dirx[j]; y = sd->bl.y + diry[j]; if((c=map_getcell(sd->bl.m,x,y)) != 1 && c != 5) @@ -1886,7 +1886,7 @@ static int skill_timerskill(int tid, unsigned int tick, int id,int data ) int x,y,i,j,c; mob_warp(md,-1,-1,-1,3); for(i=0;i<16;i++) { - j = rand()%8; + j = MRAND(8); x = md->bl.x + dirx[j]; y = md->bl.y + diry[j]; if((c=map_getcell(md->bl.m,x,y)) != 1 && c != 5) @@ -2163,7 +2163,7 @@ int skill_castend_damage_id( struct block_list* src, struct block_list *bl,int s case AM_ACIDTERROR: /* AVbhe[ */ skill_attack(BF_WEAPON,src,src,bl,skillid,skilllv,tick,flag); - if(bl->type == BL_PC && rand()%100 < skill_get_time(skillid,skilllv) && battle_config.equipment_breaking) + if(bl->type == BL_PC && MRAND(100) < skill_get_time(skillid,skilllv) && battle_config.equipment_breaking) pc_breakarmor((struct map_session_data *)bl); break; case MO_FINGEROFFENSIVE: /* we */ @@ -2692,7 +2692,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int case AL_DECAGI: /* x */ if( bl->type==BL_PC && ((struct map_session_data *)bl)->special_state.no_magic_damage ) break; - if( rand()%100 < (50+skilllv*3+(battle_get_lv(src)+battle_get_int(src)/5)-sc_def_mdef) ) { + if( MRAND(100) < (50+skilllv*3+(battle_get_lv(src)+battle_get_int(src)/5)-sc_def_mdef) ) { clif_skill_nodamage(src,bl,skillid,skilllv,1); skill_status_change_start(bl,SkillStatusChangeTable[skillid],skilllv,0,0,0,skill_get_time(skillid,skilllv),0); } @@ -2704,7 +2704,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int if(battle_check_target(src,bl,BCT_ENEMY) && (race == 6 || battle_check_undead(race,ele))) { int slv=battle_get_lv(src),tlv=battle_get_lv(bl),rate; rate = 25 + skilllv*2 + slv - tlv; - if(rand()%100 < rate) + if(MRAND(100) < rate) skill_status_change_start(bl,SkillStatusChangeTable[skillid],skilllv,0,0,0,0,0); } } @@ -2726,7 +2726,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; if(sc_data && sc_data[SC_DIVINA].timer != -1) skill_status_change_end(bl,SC_DIVINA,-1); - else if( rand()%100 < sc_def_vit ) { + else if( MRAND(100) < sc_def_vit ) { skill_status_change_start(bl,SkillStatusChangeTable[skillid],skilllv,0,0,0,skill_get_time(skillid,skilllv),0); } } @@ -2826,7 +2826,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; } } - if(rand()%100 > (75+skilllv*1) && (skilllv != 5)) { + if(MRAND(100) > (75+skilllv*1) && (skilllv != 5)) { clif_skill_fail(sd,skillid,0,0); clif_skill_nodamage(src,bl,skillid,skilllv,0); if(bl->type==BL_PC && battle_config.equipment_breaking) { @@ -3021,7 +3021,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int } }else if(sd && dstmd){ //ΏۂX^[̏ꍇ //20%̊mőΏۂLv*2SP񕜂BƂ̓^[Qbg(߄D)йޯ!! - if(rand()%100<20){ + if(MRAND(100)<20){ i=2*mob_db[dstmd->class].lv; mob_target(dstmd,src,0); } @@ -3063,7 +3063,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int clif_skill_nodamage(src,bl,skillid,skilllv,1); if( bl->type==BL_PC && ((struct map_session_data *)bl)->special_state.no_weapon_damage ) break; - if( rand()%100 < (20+ 10*skilllv)*sc_def_vit/100 ) { + if( MRAND(100) < (20+ 10*skilllv)*sc_def_vit/100 ) { skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); } break; @@ -3318,7 +3318,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int clif_skill_nodamage(src,bl,skillid,skilllv,1); if( bl->type==BL_PC && ((struct map_session_data *)bl)->special_state.no_magic_damage ) break; - if( rand()%100 < skilllv*4+20 && !battle_check_undead(battle_get_race(bl),battle_get_elem_type(bl))) + if( MRAND(100) < skilllv*4+20 && !battle_check_undead(battle_get_race(bl),battle_get_elem_type(bl))) skill_status_change_start(bl,SC_STONE,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); else if(sd) clif_skill_fail(sd,skillid,0,0); @@ -3359,7 +3359,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int int blind_time; //blind_time=30-battle_get_vit(bl)/10-battle_get_int/15; blind_time=30*(100-(battle_get_int(bl)+battle_get_vit(bl))/2)/100; - if(rand()%100 < (100-(battle_get_int(bl)/2+battle_get_vit(bl)/3+battle_get_luk(bl)/10))) + if(MRAND(100) < (100-(battle_get_int(bl)/2+battle_get_vit(bl)/3+battle_get_luk(bl)/10))) skill_status_change_start(bl, SC_BLIND,1,0,0,0,blind_time,0); } if(dstmd){ @@ -3367,7 +3367,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int dstmd->target_id=0; dstmd->state.targettype = NONE_ATTACKABLE; dstmd->state.skillstate=MSS_IDLE; - dstmd->next_walktime=tick+rand()%3000+3000; + dstmd->next_walktime=tick+MRAND(3000)+3000; } } break; @@ -3455,7 +3455,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; strip_per = 5+2*skilllv+strip_fix/5; strip_time = skill_get_time(skillid,skilllv)+strip_fix/2; - if(rand()%100 < strip_per){ + if(MRAND(100) < strip_per){ clif_skill_nodamage(src,bl,skillid,skilllv,1); skill_status_change_start(bl,SkillStatusChangeTable[skillid],skilllv,0,0,0,strip_time,0 ); if(dstsd){ @@ -3478,7 +3478,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; strip_per = 5+2*skilllv+strip_fix/5; strip_time = skill_get_time(skillid,skilllv)+strip_fix/2; - if(rand()%100 < strip_per){ + if(MRAND(100) < strip_per){ clif_skill_nodamage(src,bl,skillid,skilllv,1); skill_status_change_start(bl,SkillStatusChangeTable[skillid],skilllv,0,0,0,strip_time,0 ); if(dstsd){ @@ -3501,7 +3501,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; strip_per = 5+2*skilllv+strip_fix/5; strip_time = skill_get_time(skillid,skilllv)+strip_fix/2; - if(rand()%100 < strip_per){ + if(MRAND(100) < strip_per){ clif_skill_nodamage(src,bl,skillid,skilllv,1); skill_status_change_start(bl,SkillStatusChangeTable[skillid],skilllv,0,0,0,strip_time,0 ); if(dstsd){ @@ -3523,7 +3523,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; strip_per = 5+2*skilllv+strip_fix/5; strip_time = skill_get_time(skillid,skilllv)+strip_fix/2; - if(rand()%100 < strip_per){ + if(MRAND(100) < strip_per){ clif_skill_nodamage(src,bl,skillid,skilllv,1); skill_status_change_start(bl,SkillStatusChangeTable[skillid],skilllv,0,0,0,strip_time,0 ); if(dstsd){ @@ -3589,7 +3589,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int } } else { - hp = (1 + rand()%400) * (100 + skilllv*10) / 100; + hp = (1 + MRAND(400)) * (100 + skilllv*10) / 100; hp = hp * (100 + (battle_get_vit(bl)<<1)) / 100; if(dstsd) hp = hp * (100 + pc_checkskill(dstsd,SM_RECOVERY)*10) / 100; @@ -3768,7 +3768,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int maxlv = skilllv - 4; } else if(skilllv >=2) { - int i = rand()%3; + int i = MRAND(3); spellid = spellarray[i]; maxlv = skilllv - 1; } @@ -3797,8 +3797,8 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int clif_skill_nodamage(src,bl,skillid,skilllv,1); md->def_ele=skill_get_pl(skillid); if(md->def_ele==0) /* _ωAA*/ - md->def_ele=rand()%10; /* s͏ */ - md->def_ele+=(1+rand()%4)*20; /* x̓_ */ + md->def_ele=MRAND(10); /* s͏ */ + md->def_ele+=(1+MRAND(4))*20; /* x̓_ */ } break; @@ -3827,7 +3827,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; if(battle_get_elem_type(bl) == 7 || battle_get_race(bl) == 6) break; - if(rand()%100 < sc_def*(50+skilllv*5)/100) { + if(MRAND(100) < sc_def*(50+skilllv*5)/100) { if(dstsd) { int hp = battle_get_hp(bl)-1; pc_heal(dstsd,-hp,0); @@ -3848,7 +3848,7 @@ int skill_castend_nodamage_id( struct block_list *src, struct block_list *bl,int break; if(dstsd) pc_heal(dstsd,0,-100); - if(rand()%100 < (skilllv*5)*sc_def_vit/100) + if(MRAND(100) < (skilllv*5)*sc_def_vit/100) skill_status_change_start(bl,SC_STAN,skilllv,0,0,0,skill_get_time2(skillid,skilllv),0); break; @@ -4313,8 +4313,8 @@ int skill_castend_pos2( struct block_list *src, int x,int y,int skillid,int skil for(i=0;i<2+(skilllv>>1);i++) { int j=0, c; do { - tmpx = x + (rand()%7 - 3); - tmpy = y + (rand()%7 - 3); + tmpx = x + (MRAND(7) - 3); + tmpy = y + (MRAND(7) - 3); if(tmpx < 0) tmpx = 0; else if(tmpx >= map[src->m].xs) @@ -5346,7 +5346,7 @@ int skill_unit_onplace(struct skill_unit *src,struct block_list *bl,unsigned int case 0xb1: /* fXg[V */ skill_attack(BF_WEAPON,ss,&src->bl,bl,sg->skill_id,sg->skill_lv,tick,0); - if(bl->type == BL_PC && rand()%100 < sg->skill_lv && battle_config.equipment_breaking) + if(bl->type == BL_PC && MRAND(100) < sg->skill_lv && battle_config.equipment_breaking) pc_breakweapon((struct map_session_data *)bl); break; case 0x99: /* g[L[{bNX */ @@ -7268,7 +7268,7 @@ int skill_frostjoke_scream(struct block_list *bl,va_list ap) if(battle_check_target(src,bl,BCT_ENEMY) > 0) skill_additional_effect(src,bl,skillnum,skilllv,BF_MISC,tick); else if(battle_check_target(src,bl,BCT_PARTY) > 0) { - if(rand()%100 < 10)//PToɂmł(Ƃ肠10%) + if(MRAND(100) < 10)//PToɂmł(Ƃ肠10%) skill_additional_effect(src,bl,skillnum,skilllv,BF_MISC,tick); } @@ -8274,7 +8274,7 @@ int skill_status_effect(struct block_list *bl, int type, int val1, int val2, int return 0; if(SC_STONE<=type && type<=SC_BLIND){ /* J[hɂϐ */ - if( sd && sd->reseff[type-SC_STONE] > 0 && rand()%10000reseff[type-SC_STONE]){ + if( sd && sd->reseff[type-SC_STONE] > 0 && MRAND(100)reseff[type-SC_STONE]){ if(battle_config.battle_log) printf("PC %d skill_sc_start: cardɂُϐ\n",sd->bl.id); return 0; -- cgit v1.2.3-70-g09d2