summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/atcommand.c72
-rw-r--r--src/map/battle.c38
-rw-r--r--src/map/chrif.c37
-rw-r--r--src/map/clif.c125
-rw-r--r--src/map/clif.h2
-rw-r--r--src/map/guild.c113
-rw-r--r--src/map/homunculus.c355
-rw-r--r--src/map/itemdb.c211
-rw-r--r--src/map/itemdb.h2
-rw-r--r--src/map/map.c176
-rw-r--r--src/map/mercenary.c216
-rw-r--r--src/map/mob.c26
-rw-r--r--src/map/npc.c30
-rw-r--r--src/map/party.c4
-rw-r--r--src/map/pc.c92
-rw-r--r--src/map/pc.h3
-rw-r--r--src/map/pet.c32
-rw-r--r--src/map/script.c127
-rw-r--r--src/map/skill.c225
-rw-r--r--src/map/status.c224
-rw-r--r--src/map/storage.c3
-rw-r--r--src/map/trade.c3
-rw-r--r--src/map/unit.c135
-rw-r--r--src/map/vending.c33
-rw-r--r--src/map/vending.h2
25 files changed, 1047 insertions, 1239 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 95b3dc33e..cebd881ce 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1937,7 +1937,7 @@ static int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
{
TBL_PC* sd = (TBL_PC*)bl;
clif_pvpset(sd, 0, 0, 2);
- if (sd->pvp_timer != -1) {
+ if (sd->pvp_timer != INVALID_TIMER) {
delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
sd->pvp_timer = INVALID_TIMER;
}
@@ -1969,7 +1969,7 @@ ACMD_FUNC(pvpoff)
static int atcommand_pvpon_sub(struct block_list *bl,va_list ap)
{
TBL_PC* sd = (TBL_PC*)bl;
- if (sd->pvp_timer == -1) {
+ if (sd->pvp_timer == INVALID_TIMER) {
sd->pvp_timer = add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0);
sd->pvp_rank = 0;
sd->pvp_lastusers = 0;
@@ -6095,7 +6095,7 @@ ACMD_FUNC(autoloot)
}
/*==========================================
- * @autolootitem
+ * @alootid
*------------------------------------------*/
ACMD_FUNC(autolootitem)
{
@@ -6104,9 +6104,9 @@ ACMD_FUNC(autolootitem)
if (!message || !*message) {
if (sd->state.autolootid) {
sd->state.autolootid = 0;
- clif_displaymessage(fd, "Autolootitem have been turned OFF.");
+ clif_displaymessage(fd, "Autolootitem has been turned OFF.");
} else
- clif_displaymessage(fd, "Please, enter Item name or its ID (usage: @autolootitem <item_name_or_ID>).");
+ clif_displaymessage(fd, "Please, enter item name or it's ID (usage: @alootid <item_name_or_ID>).");
return -1;
}
@@ -6122,7 +6122,7 @@ ACMD_FUNC(autolootitem)
sd->state.autolootid = item_data->nameid; // Autoloot Activated
- sprintf(atcmd_output, "Autolooting Item: '%s'/'%s' {%d}",
+ sprintf(atcmd_output, "Autolooting item: '%s'/'%s' (%d)",
item_data->name, item_data->jname, item_data->nameid);
clif_displaymessage(fd, atcmd_output);
@@ -6741,7 +6741,7 @@ ACMD_FUNC(unmute)
}
pl_sd->status.manner = 0;
- status_change_end(&pl_sd->bl,SC_NOCHAT,-1);
+ status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
clif_displaymessage(sd->fd,"Player unmuted");
return 0;
@@ -6815,7 +6815,7 @@ ACMD_FUNC(mute)
sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
} else {
pl_sd->status.manner = 0;
- status_change_end(&pl_sd->bl,SC_NOCHAT,-1);
+ status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
}
clif_GM_silence(sd, pl_sd, (manner > 0 ? 1 : 0));
@@ -6986,7 +6986,7 @@ ACMD_FUNC(mobinfo)
strcpy(atcmd_output, " ");
j = 0;
for (i = 0; i < MAX_MOB_DROP; i++) {
- if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb_search(mob->dropitem[i].nameid)) == NULL)
+ if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb_exists(mob->dropitem[i].nameid)) == NULL)
continue;
if (item_data->slot)
sprintf(atcmd_output2, " - %s[%d] %02.02f%%", item_data->jname, item_data->slot, (float)mob->dropitem[i].p / 100);
@@ -7009,7 +7009,7 @@ ACMD_FUNC(mobinfo)
strcpy(atcmd_output, " MVP Items:");
j = 0;
for (i = 0; i < 3; i++) {
- if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb_search(mob->mvpitem[i].nameid)) == NULL)
+ if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb_exists(mob->mvpitem[i].nameid)) == NULL)
continue;
if (mob->mvpitem[i].p > 0) {
j++;
@@ -7115,19 +7115,18 @@ ACMD_FUNC(homlevel)
nullpo_retr(-1, sd);
- if (!message || !*message) {
- clif_displaymessage(fd, "Please, enter a level adjustment: (usage: @homlevel <+/- # of levels>.");
+ if ( !message || !*message || ( level = atoi(message) ) < 1 ) {
+ clif_displaymessage(fd, "Please, enter a level adjustment: (usage: @homlevel <# of levels to level up>.");
return -1;
}
-
+
if ( !merc_is_hom_active(sd->hd) ) {
clif_displaymessage(fd, "You do not have a homunculus.");
return -1;
}
- level = atoi(message);
hd = sd->hd;
-
+
for (i = 1; i <= level && hd->exp_next; i++){
hd->homunculus.exp += hd->exp_next;
merc_hom_levelup(hd);
@@ -7616,8 +7615,8 @@ static int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
pl_sd->status.manner -= time;
if (pl_sd->status.manner < 0)
sc_start(&pl_sd->bl,SC_NOCHAT,100,0,0);
- else if (pl_sd->sc.data[SC_NOCHAT])
- status_change_end(&pl_sd->bl, SC_NOCHAT, -1);
+ else
+ status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
}
return 0;
}
@@ -7964,6 +7963,13 @@ ACMD_FUNC(accept)
return 0;
}
+ if( duel_list[sd->duel_invite].max_players_limit > 0 && duel_list[sd->duel_invite].members_count >= duel_list[sd->duel_invite].max_players_limit )
+ {
+ // "Duel: Limit of players is reached."
+ clif_displaymessage(fd, msg_txt(351));
+ return 0;
+ }
+
duel_accept(sd->duel_invite, sd);
// "Duel: Invitation has been accepted."
clif_displaymessage(fd, msg_txt(361));
@@ -8015,30 +8021,6 @@ ACMD_FUNC(cash)
return 0;
}
-/*===================================
- * Away message (@away, @aw) [LuzZza]
- *-----------------------------------*/
-ACMD_FUNC(away)
-{
- if(strlen(message) > 0) {
- if(strlen(message) > 128)
- return -1;
- strcpy(sd->away_message, message);
- //"Away automessage has been activated."
- clif_displaymessage(fd, msg_txt(546));
- } else {
- if(strlen(sd->away_message) > 0) {
- sd->away_message[0] = 0;
- //"Away automessage has been disabled."
- clif_displaymessage(fd, msg_txt(547));
- return 0;
- }
- //"Usage: @away,@aw <message>. Enter empty message for disable it."
- clif_displaymessage(fd, msg_txt(548));
- }
- return 0;
-}
-
// @clone/@slaveclone/@evilclone <playername> [Valaris]
ACMD_FUNC(clone)
{
@@ -8323,7 +8305,7 @@ ACMD_FUNC(itemlist)
const struct item* it = &items[i];
struct item_data* itd;
- if( it->nameid == 0 || (itd = itemdb_search(it->nameid)) == NULL )
+ if( it->nameid == 0 || (itd = itemdb_exists(it->nameid)) == NULL )
continue;
counter += it->amount;
@@ -8406,7 +8388,7 @@ ACMD_FUNC(itemlist)
{
struct item_data* card;
- if( it->card[j] == 0 || (card = itemdb_search(it->card[j])) == NULL )
+ if( it->card[j] == 0 || (card = itemdb_exists(it->card[j])) == NULL )
continue;
counter2++;
@@ -8872,8 +8854,6 @@ AtCommandInfo atcommand_info[] = {
{ "leave", 1,1, atcommand_leave },
{ "accept", 1,1, atcommand_accept },
{ "reject", 1,1, atcommand_reject },
- { "away", 1,1, atcommand_away },
- { "aw", 1,1, atcommand_away },
{ "main", 1,1, atcommand_main },
{ "clone", 50,50, atcommand_clone },
{ "slaveclone", 50,50, atcommand_clone },
@@ -9118,8 +9098,8 @@ int atcommand_config_read(const char* cfgName)
}
else {
p->level2 = atoi(w3);
- p->level2 = cap_value(p->level2, 0, 100);
}
+ p->level2 = cap_value(p->level2, 0, 100);
}
else
if( strcmpi(w1, "import") == 0 )
diff --git a/src/map/battle.c b/src/map/battle.c
index 32def23f3..3e58c1209 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -160,7 +160,7 @@ int battle_delay_damage_sub(int tid, unsigned int tick, int id, intptr data)
struct block_list *target = map_id2bl(dat->target);
if (target && dat && map_id2bl(id) == dat->src && target->prev != NULL && !status_isdead(target) &&
target->m == dat->src->m &&
- (target->type != BL_PC || ((TBL_PC*)target)->invincible_timer == -1) &&
+ (target->type != BL_PC || ((TBL_PC*)target)->invincible_timer == INVALID_TIMER) &&
check_distance_bl(dat->src, target, dat->distance)) //Check to see if you haven't teleported. [Skotlex]
{
map_freeblock_lock();
@@ -263,7 +263,7 @@ int battle_attr_fix(struct block_list *src, struct block_list *target, int damag
if( tsc->data[SC_SPIDERWEB]->val2-- > 0 )
damage <<= 1; // double damage
if( tsc->data[SC_SPIDERWEB]->val2 == 0 )
- status_change_end(target,SC_SPIDERWEB,-1);
+ status_change_end(target, SC_SPIDERWEB, INVALID_TIMER);
}
return damage*ratio/100;
}
@@ -326,7 +326,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
d->dmg_lv = ATK_BLOCK;
return 0;
}
- status_change_end(bl,SC_SAFETYWALL,-1);
+ status_change_end(bl, SC_SAFETYWALL, INVALID_TIMER);
}
if( sc->data[SC_PNEUMA] && (flag&(BF_MAGIC|BF_LONG)) == BF_LONG )
@@ -381,7 +381,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
//Shouldn't end until Breaker's non-weapon part connects.
if (skill_num != ASC_BREAKER || !(flag&BF_WEAPON))
if (--(sce->val3) <= 0) //We make it work like Safety Wall, even though it only blocks 1 time.
- status_change_end(bl, SC_KAUPE, -1);
+ status_change_end(bl, SC_KAUPE, INVALID_TIMER);
return 0;
}
@@ -395,9 +395,9 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
}
//Both need to be consumed if they are active.
if (sce && --(sce->val2) <= 0)
- status_change_end(bl, SC_UTSUSEMI, -1);
+ status_change_end(bl, SC_UTSUSEMI, INVALID_TIMER);
if ((sce=sc->data[SC_BUNSINJYUTSU]) && --(sce->val2) <= 0)
- status_change_end(bl, SC_BUNSINJYUTSU, -1);
+ status_change_end(bl, SC_BUNSINJYUTSU, INVALID_TIMER);
return 0;
}
@@ -408,7 +408,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
damage <<= 1; // Lex Aeterna only doubles damage of regular attacks from mercenaries
if( skill_num != ASC_BREAKER || !(flag&BF_WEAPON) )
- status_change_end( bl,SC_AETERNA,-1 ); //Shouldn't end until Breaker's non-weapon part connects.
+ status_change_end(bl, SC_AETERNA, INVALID_TIMER); //Shouldn't end until Breaker's non-weapon part connects.
}
//Finally damage reductions....
@@ -464,7 +464,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
per /=20; //Uses 20% SP intervals.
//SP Cost: 1% + 0.5% per every 20% SP
if (!status_charge(bl, 0, (10+5*per)*status->max_sp/1000))
- status_change_end( bl,SC_ENERGYCOAT,-1 );
+ status_change_end(bl, SC_ENERGYCOAT, INVALID_TIMER);
//Reduction: 6% + 6% every 20%
damage -= damage * 6 * (1+per) / 100;
}
@@ -484,7 +484,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
status_fix_damage(bl,src,damage,clif_damage(bl,src,gettick(),0,0,damage,0,0,0));
clif_skill_nodamage(bl,bl,ST_REJECTSWORD,sce->val1,1);
if(--(sce->val3)<=0)
- status_change_end(bl, SC_REJECTSWORD, -1);
+ status_change_end(bl, SC_REJECTSWORD, INVALID_TIMER);
}
//Finally Kyrie because it may, or not, reduce damage to 0.
@@ -497,7 +497,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damag
damage=-sce->val2;
}
if((--sce->val3)<=0 || (sce->val2<=0) || skill_num == AL_HOLYLIGHT)
- status_change_end(bl, SC_KYRIE, -1);
+ status_change_end(bl, SC_KYRIE, INVALID_TIMER);
}
if (!damage) return 0;
@@ -3090,7 +3090,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
}
if (sc && sc->data[SC_CLOAKING] && !(sc->data[SC_CLOAKING]->val4&2))
- status_change_end(src,SC_CLOAKING,-1);
+ status_change_end(src, SC_CLOAKING, INVALID_TIMER);
if( tsc && tsc->data[SC_AUTOCOUNTER] && status_check_skilluse(target, src, KN_AUTOCOUNTER, 1) )
{
@@ -3102,7 +3102,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
int skilllv = tsc->data[SC_AUTOCOUNTER]->val1;
clif_skillcastcancel(target); //Remove the casting bar. [Skotlex]
clif_damage(src, target, tick, sstatus->amotion, 1, 0, 1, 0, 0); //Display MISS.
- status_change_end(target,SC_AUTOCOUNTER,-1);
+ status_change_end(target, SC_AUTOCOUNTER, INVALID_TIMER);
skill_attack(BF_WEAPON,target,target,src,KN_AUTOCOUNTER,skilllv,tick,0);
return ATK_NONE;
}
@@ -3112,7 +3112,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
{
int skilllv = tsc->data[SC_BLADESTOP_WAIT]->val1;
int duration = skill_get_time2(MO_BLADESTOP,skilllv);
- status_change_end(target, SC_BLADESTOP_WAIT, -1);
+ status_change_end(target, SC_BLADESTOP_WAIT, INVALID_TIMER);
if(sc_start4(src, SC_BLADESTOP, 100, sd?pc_checkskill(sd, MO_BLADESTOP):5, 0, 0, target->id, duration))
{ //Target locked.
clif_damage(src, target, tick, sstatus->amotion, 1, 0, 1, 0, 0); //Display MISS.
@@ -3128,7 +3128,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
if (sc && sc->data[SC_SKILLRATE_UP] && sc->data[SC_SKILLRATE_UP]->val1 == MO_TRIPLEATTACK)
{
triple_rate+= triple_rate*(sc->data[SC_SKILLRATE_UP]->val2)/100;
- status_change_end(src,SC_SKILLRATE_UP,-1);
+ status_change_end(src, SC_SKILLRATE_UP, INVALID_TIMER);
}
if (rand()%100 < triple_rate)
//FIXME: invalid return type!
@@ -3142,7 +3142,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
int skilllv = sc->data[SC_SACRIFICE]->val1;
if( --sc->data[SC_SACRIFICE]->val2 <= 0 )
- status_change_end(src, SC_SACRIFICE,-1);
+ status_change_end(src, SC_SACRIFICE, INVALID_TIMER);
status_zap(src, sstatus->max_hp*9/100, 0);//Damage to self is always 9%
@@ -3154,7 +3154,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
return (damage_lv)skill_attack(BF_MAGIC,src,src,target,NPC_MAGICALATTACK,sc->data[SC_MAGICALATTACK]->val1,tick,0);
}
- if(tsc && tsc->data[SC_KAAHI] && tsc->data[SC_KAAHI]->val4 == -1 && tstatus->hp < tstatus->max_hp)
+ if(tsc && tsc->data[SC_KAAHI] && tsc->data[SC_KAAHI]->val4 == INVALID_TIMER && tstatus->hp < tstatus->max_hp)
tsc->data[SC_KAAHI]->val4 = add_timer(tick + skill_get_time2(SL_KAAHI,tsc->data[SC_KAAHI]->val1), kaahi_heal_timer, target->id, SC_KAAHI); //Activate heal.
wd = battle_calc_attack(BF_WEAPON, src, target, 0, 0, flag);
@@ -3197,7 +3197,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
status_fix_damage(NULL, d_bl, damage, 0);
}
else
- status_change_end(target, SC_DEVOTION, -1);
+ status_change_end(target, SC_DEVOTION, INVALID_TIMER);
}
if (sc && sc->data[SC_AUTOSPELL] && rand()%100 < sc->data[SC_AUTOSPELL]->val4) {
@@ -3256,7 +3256,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
--sce->val2;
}
if (sce->val2 <= 0)
- status_change_end(target, SC_POISONREACT, -1);
+ status_change_end(target, SC_POISONREACT, INVALID_TIMER);
}
}
map_freeblock_unlock();
@@ -3344,7 +3344,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
switch( target->type )
{ // Checks on actual target
case BL_PC:
- if (((TBL_PC*)target)->invincible_timer != -1 || pc_isinvisible((TBL_PC*)target))
+ if (((TBL_PC*)target)->invincible_timer != INVALID_TIMER || pc_isinvisible((TBL_PC*)target))
return -1; //Cannot be targeted yet.
break;
case BL_MOB:
diff --git a/src/map/chrif.c b/src/map/chrif.c
index a9634d2c2..c4eeea3d9 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -36,9 +36,9 @@ static DBMap* auth_db; // int id -> struct auth_node*
static const int packet_len_table[0x3d] = { // U - used, F - free
60, 3,-1,27,10,-1, 6,-1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff
- 6,-1,18, 7,-1,35,30,-1, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, F->2b07
- 6,30,-1,-1,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, F->2b0a, F->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f
- 11,10,10, 6,11,-1,266,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, F->2b15, U->2b16, U->2b17
+ 6,-1,18, 7,-1,35,30, 0, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, F->2b07
+ 6,30, 0, 0,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, F->2b0a, F->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f
+ 11,10,10, 0,11, 0,266,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, F->2b13, U->2b14, F->2b15, U->2b16, U->2b17
2,10, 2,-1,-1,-1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f
-1,10, 8, 2, 2,14,19,19, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, U->2b24, U->2b25, U->2b26, U->2b27
};
@@ -71,7 +71,7 @@ static const int packet_len_table[0x3d] = { // U - used, F - free
//2b10: Outgoing, chrif_updatefamelist -> 'Update the fame ranking lists and send them'
//2b11: Outgoing, chrif_divorce -> 'tell the charserver to do divorce'
//2b12: Incoming, chrif_divorceack -> 'divorce chars
-//2b13: Incoming, chrif_accountdeletion -> 'Delete acc XX, if the player is on, kick ....'
+//2b13: FREE
//2b14: Incoming, chrif_accountban -> 'not sure: kick the player with message XY'
//2b15: FREE
//2b16: Outgoing, chrif_ragsrvinfo -> 'sends base / job / drop rates ....'
@@ -942,32 +942,6 @@ int chrif_deadopt(int father_id, int mother_id, int child_id)
return 0;
}
-/*==========================================
- * Disconnection of a player (account has been deleted in login-server) by [Yor]
- *------------------------------------------*/
-int chrif_accountdeletion(int fd)
-{
- int acc;
- struct map_session_data *sd;
-
- acc = RFIFOL(fd,2);
- if (battle_config.etc_log)
- ShowNotice("chrif_accountdeletion %d.\n", acc);
- sd = map_id2sd(acc);
- if (acc > 0) {
- if (sd != NULL) {
- sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
- clif_displaymessage(sd->fd, "Your account has been deleted (disconnection)...");
- set_eof(sd->fd); // forced to disconnect for the change
- map_quit(sd); // Remove leftovers (e.g. autotrading) [Paradox924X]
- }
- } else {
- if (sd != NULL)
- ShowError("chrif_accountdeletion failed - player not online.\n");
- }
-
- return 0;
-}
/*==========================================
* Disconnection of a player (account has been banned of has a status, from login-server) by [Yor]
@@ -1169,7 +1143,7 @@ int chrif_save_scdata(struct map_session_data *sd)
{
if (!sc->data[i])
continue;
- if (sc->data[i]->timer != -1)
+ if (sc->data[i]->timer != INVALID_TIMER)
{
timer = get_timer(sc->data[i]->timer);
if (timer == NULL || timer->func != status_change_timer || DIFF_TICK(timer->tick,tick) < 0)
@@ -1426,7 +1400,6 @@ int chrif_parse(int fd)
case 0x2b0d: chrif_changedsex(fd); break;
case 0x2b0f: chrif_char_ask_name_answer(RFIFOL(fd,2), (char*)RFIFOP(fd,6), RFIFOW(fd,30), RFIFOW(fd,32)); break;
case 0x2b12: chrif_divorceack(RFIFOL(fd,2), RFIFOL(fd,6)); break;
- case 0x2b13: chrif_accountdeletion(fd); break;
case 0x2b14: chrif_accountban(fd); break;
case 0x2b1b: chrif_recvfamelist(fd); break;
case 0x2b1d: chrif_load_scdata(fd); break;
diff --git a/src/map/clif.c b/src/map/clif.c
index c5796555a..b724ddbab 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -5599,9 +5599,9 @@ void clif_closevendingboard(struct block_list* bl, int fd)
}
/*==========================================
- * Sends a list of items in a shop
+ * Sends a list of items in a shop (ZC_PC_PURCHASE_ITEMLIST_FROMMC/ZC_PC_PURCHASE_ITEMLIST_FROMMC2)
* R 0133 <len>.w <ID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
- * R 0800 <len>.w <ID>.l <ID?>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
+ * R 0800 <len>.w <ID>.l <UniqueID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
*------------------------------------------*/
void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
{
@@ -5628,7 +5628,7 @@ void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* ven
WFIFOW(fd,2) = offset+count*22;
WFIFOL(fd,4) = id;
#if PACKETVER >= 20100105
- WFIFOL(fd,8) = vsd->status.char_id;
+ WFIFOL(fd,8) = vsd->vender_id;
#endif
for( i = 0; i < count; i++ )
@@ -5649,12 +5649,14 @@ void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* ven
}
/*==========================================
- * Shop purchase failure
+ * Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC)
* R 0135 <index>.w <amount>.w <fail>.B
* fail=1 - not enough zeny
* fail=2 - overweight
* fail=4 - out of stock
* fail=5 - "cannot use an npc shop while in a trade"
+ * fail=6 - Because the store information was incorrect the item was not purchased.
+ * fail=7 - No sales information.
*------------------------------------------*/
void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
{
@@ -8398,8 +8400,8 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
// item
+ clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
pc_checkitem(sd);
- clif_inventorylist(sd);
// cart
if(pc_iscarton(sd)) {
@@ -8724,11 +8726,13 @@ void clif_progressbar_abort(struct map_session_data * sd)
void clif_parse_progressbar(int fd, struct map_session_data * sd)
{
+ int npc_id = sd->progressbar.npc_id;
+
if( gettick() < sd->progressbar.timeout && sd->st )
sd->st->state = END;
- npc_scriptcont(sd, sd->progressbar.npc_id);
sd->progressbar.npc_id = sd->progressbar.timeout = 0;
+ npc_scriptcont(sd, npc_id);
}
/*==========================================
@@ -9075,7 +9079,7 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
return;
}
- if (sd->ud.skilltimer != -1 || sd->sc.opt1)
+ if (sd->ud.skilltimer != INVALID_TIMER || sd->sc.opt1)
break;
if (sd->sc.count && (
@@ -9279,19 +9283,6 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
// notify sender of success
clif_wis_end(fd, 0); // 0: success to send wisper
- // if player has an auto-away message
- if(dstsd->away_message[0] != '\0')
- {
- char output[256];
- sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
- clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
- if(dstsd->state.autotrade)
- sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
- else
- sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
- clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
- return;
- }
// Normal message
clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
return;
@@ -9562,9 +9553,11 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
WFIFOSET(fd,packet_len(0xca));
}
-/*==========================================
- *
- *------------------------------------------*/
+/// Request to sell chosen items to npc shop
+/// R 00c9 <packet len>.W {<index>.W <amount>.W}.4B*
+/// S 00cb <result>.B
+/// result = 00 -> "The deal has successfully completed."
+/// result = 01 -> "The deal has failed."
void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
{
int fail=0,n;
@@ -9848,7 +9841,7 @@ static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_sess
return;
if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
target_id = hd->bl.id;
- if( hd->ud.skilltimer != -1 )
+ if( hd->ud.skilltimer != INVALID_TIMER )
{
if( skillnum != SA_CASTCANCEL ) return;
}
@@ -9958,7 +9951,7 @@ void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
target_id = sd->bl.id;
- if( sd->ud.skilltimer != -1 )
+ if( sd->ud.skilltimer != INVALID_TIMER )
{
if( skillnum != SA_CASTCANCEL )
return;
@@ -10050,7 +10043,7 @@ void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skil
safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
}
- if( sd->ud.skilltimer != -1 )
+ if( sd->ud.skilltimer != INVALID_TIMER )
return;
if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
@@ -10880,7 +10873,7 @@ void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
}
/*==========================================
- * Shop item(s) purchase request
+ * Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC)
* S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
*------------------------------------------*/
void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
@@ -10889,21 +10882,27 @@ void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
int id = (int)RFIFOL(fd,4);
const uint8* data = (uint8*)RFIFOP(fd,8);
- vending_purchasereq(sd, id, -1, data, len/4);
+ vending_purchasereq(sd, id, sd->vended_id, data, len/4);
+
+ // whether it fails or not, the buy window is closed
+ sd->vended_id = 0;
}
/*==========================================
- * Shop item(s) purchase request
- * S 0134/0801 <len>.w <AID>.l <CID>.l {<amount>.w <index>.w}.4B*
+ * Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2)
+ * S 0801 <len>.w <AID>.l <UniqueID>.l {<amount>.w <index>.w}.4B*
*------------------------------------------*/
void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
{
int len = (int)RFIFOW(fd,2) - 12;
int aid = (int)RFIFOL(fd,4);
- int cid = (int)RFIFOL(fd,8);
+ int uid = (int)RFIFOL(fd,8);
const uint8* data = (uint8*)RFIFOP(fd,12);
- vending_purchasereq(sd, aid, cid, data, len/4);
+ vending_purchasereq(sd, aid, uid, data, len/4);
+
+ // whether it fails or not, the buy window is closed
+ sd->vended_id = 0;
}
/*==========================================
@@ -11615,7 +11614,7 @@ void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
} else {
dstsd->status.manner = 0;
- status_change_end(&dstsd->bl,SC_NOCHAT,-1);
+ status_change_end(&dstsd->bl, SC_NOCHAT, INVALID_TIMER);
}
if( type != 2 )
@@ -11674,7 +11673,7 @@ void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
* S 0198 <x>.W <y>.W <gat>.W
*------------------------------------------*/
void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
-{// FIXME: type sent by client is 0 or 1 (even if you enter 2+); that suggests, that it is walkable gat attribute
+{
int x,y,type;
if( battle_config.atc_gmonly && !pc_isGM(sd) )
@@ -12013,7 +12012,6 @@ void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
account_id = RFIFOL(fd,2);
char_id = RFIFOL(fd,6);
reply = RFIFOB(fd,10);
- //printf ("reply: %d %d %d\n", char_id, id, reply);
f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
if (f_sd == NULL)
@@ -12096,20 +12094,20 @@ void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
}
/*==========================================
- * /pvpinfo
+ * /pvpinfo (CZ_REQ_PVPPOINT & ZC_ACK_PVPPOINT)
+ * R 020f <char id>.L <account id>.L
+ * S 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
*------------------------------------------*/
void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
{
WFIFOHEAD(fd,packet_len(0x210));
WFIFOW(fd,0) = 0x210;
- //WFIFOL(fd,2) = 0; // not sure what for yet
- //WFIFOL(fd,6) = 0;
+ WFIFOL(fd,2) = sd->status.char_id;
+ WFIFOL(fd,6) = sd->status.account_id;
WFIFOL(fd,10) = sd->pvp_won; // times won
WFIFOL(fd,14) = sd->pvp_lost; // times lost
WFIFOL(fd,18) = sd->pvp_point;
WFIFOSET(fd, packet_len(0x210));
-
- return;
}
/*==========================================
@@ -12584,7 +12582,7 @@ void clif_Mail_read(struct map_session_data *sd, int mail_id)
WFIFOL(fd,72) = 0;
WFIFOL(fd,76) = msg->zeny;
- if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
+ if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL )
{
WFIFOL(fd,80) = item->amount;
WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
@@ -12650,7 +12648,7 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
struct item_data *data;
unsigned int weight;
- if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
+ if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
return;
switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
@@ -12863,7 +12861,7 @@ void clif_Auction_results(struct map_session_data *sd, short count, short pages,
WFIFOL(fd,k) = auction.auction_id;
safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
- if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
+ if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
WFIFOW(fd,28+k) = item->view_id;
else
WFIFOW(fd,28+k) = auction.item.nameid;
@@ -12924,7 +12922,7 @@ void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
return;
}
- if( (item = itemdb_search(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
+ if( (item = itemdb_exists(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
{ // Consumible or pets are not allowed
clif_Auction_setitem(sd->fd, idx, true);
return;
@@ -13025,7 +13023,7 @@ void clif_parse_Auction_register(int fd, struct map_session_data *sd)
return;
}
- if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
+ if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
{ // Just in case
clif_Auction_message(fd, 2); // The auction has been canceled
return;
@@ -13139,6 +13137,31 @@ void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
WFIFOSET(fd,WFIFOW(fd,2));
}
+/// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE)
+/// S 0289 <cash point>.L <kafra point>.L <error>.W
+///
+/// @param error
+/// 0: The deal has successfully completed. (ERROR_TYPE_NONE)
+/// 1: The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
+/// 2: The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
+/// 3: You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
+/// 4: You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
+/// 5: The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
+/// 6: You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
+/// 7: You can purchase up to 10 items.
+/// 8: Some items could not be purchased.
+void clif_cashshop_ack(struct map_session_data* sd, int error)
+{
+ int fd = sd->fd;
+
+ WFIFOHEAD(fd, packet_len(0x289));
+ WFIFOW(fd,0) = 0x289;
+ WFIFOL(fd,2) = sd->cashPoints;
+ WFIFOL(fd,6) = sd->kafraPoints;
+ WFIFOW(fd,10) = TOW(error);
+ WFIFOSET(fd, packet_len(0x289));
+}
+
void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
{
int fail = 0, amount, points;
@@ -13154,12 +13177,7 @@ void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
else
fail = npc_cashshop_buy(sd, nameid, amount, points);
- WFIFOHEAD(fd,12);
- WFIFOW(fd,0) = 0x289;
- WFIFOL(fd,2) = sd->cashPoints;
- WFIFOL(fd,6) = sd->kafraPoints;
- WFIFOW(fd,10) = fail;
- WFIFOSET(fd,12);
+ clif_cashshop_ack(sd, fail);
}
/*==========================================
@@ -13248,7 +13266,7 @@ void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
else
WFIFOB(fd,2) = 2; // First Time
}
- else if (md->spawn_timer != -1)
+ else if (md->spawn_timer != INVALID_TIMER)
{ // Boss is Dead
const struct TimerData * timer_data = get_timer(md->spawn_timer);
unsigned int seconds;
@@ -14268,7 +14286,7 @@ static int packetdb_readdb(void)
6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//#0x0280
- 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
+ 0, 0, 0, 6, 0, 0, 0, 0, 0, 12, 18, 0, 0, 0, 0, 0,
0, 4, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 0, 0, 0, 0, 0,
@@ -14579,6 +14597,7 @@ static int packetdb_readdb(void)
{clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
{clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
#endif
+ {clif_parse_PVPInfo,"pvpinfo"},
{NULL,NULL}
};
diff --git a/src/map/clif.h b/src/map/clif.h
index ded8ece30..8e9f2be7a 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -461,8 +461,6 @@ int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap);
void clif_friendslist_send(struct map_session_data *sd);
void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type);
-// [Valaris]
-int clif_mob_hp(struct mob_data *md);
void clif_weather(int m); // [Valaris]
int clif_specialeffect(struct block_list* bl, int type, enum send_target target); // special effects [Valaris]
void clif_specialeffect_single(struct block_list* bl, int type, int fd);
diff --git a/src/map/guild.c b/src/map/guild.c
index f90fc8946..7b20808d6 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -103,46 +103,34 @@ int guild_checkskill(struct guild *g,int id)
/*==========================================
* guild_skill_tree.txt reading - from jA [Komurka]
*------------------------------------------*/
-int guild_read_guildskill_tree_db(void)
-{
- int i,k,id=0,ln=0;
- FILE *fp;
- char line[1024],*p;
+static bool guild_read_guildskill_tree_db(char* split[], int columns, int current)
+{// <skill id>,<max lv>,<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>
+ int k, id, skillid;
- memset(guild_skill_tree,0,sizeof(guild_skill_tree));
- sprintf(line, "%s/guild_skill_tree.txt", db_path);
- if( (fp=fopen(line,"r"))==NULL){
- ShowError("can't read %s\n", line);
- return -1;
+ skillid = atoi(split[0]);
+ id = skillid - GD_SKILLBASE;
+
+ if( id < 0 || id >= MAX_GUILDSKILL )
+ {
+ ShowWarning("guild_read_guildskill_tree_db: Invalid skill id %d.\n", skillid);
+ return false;
+ }
+
+ guild_skill_tree[id].id = skillid;
+ guild_skill_tree[id].max = atoi(split[1]);
+
+ if( guild_skill_tree[id].id == GD_GLORYGUILD && battle_config.require_glory_guild && guild_skill_tree[id].max == 0 )
+ {// enable guild's glory when required for emblems
+ guild_skill_tree[id].max = 1;
}
- while(fgets(line, sizeof(line), fp))
+
+ for( k = 0; k < 5; k++ )
{
- char *split[50];
- if(line[0]=='/' && line[1]=='/')
- continue;
- for(i=0,p=line;i<12 && p;i++){
- split[i]=p;
- p=strchr(p,',');
- if(p) *p++=0;
- }
- if(i<12)
- continue;
- id = atoi(split[0]) - GD_SKILLBASE;
- if(id<0 || id>=MAX_GUILDSKILL)
- continue;
- guild_skill_tree[id].id=atoi(split[0]);
- guild_skill_tree[id].max=atoi(split[1]);
- if (guild_skill_tree[id].id==GD_GLORYGUILD && battle_config.require_glory_guild && guild_skill_tree[id].max==0) guild_skill_tree[id].max=1;
- for(k=0;k<5;k++){
- guild_skill_tree[id].need[k].id=atoi(split[k*2+2]);
- guild_skill_tree[id].need[k].lv=atoi(split[k*2+3]);
- }
- ln++;
+ guild_skill_tree[id].need[k].id = atoi(split[k*2+2]);
+ guild_skill_tree[id].need[k].lv = atoi(split[k*2+3]);
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"guild_skill_tree.txt");
- return 0;
+ return true;
}
/*==========================================
@@ -168,51 +156,21 @@ int guild_check_skill_require(struct guild *g,int id)
return 1;
}
-static int guild_read_castledb(void)
-{
- FILE *fp;
- char line[1024];
- int j,ln=0;
- char *str[32],*p;
+static bool guild_read_castledb(char* str[], int columns, int current)
+{// <castle id>,<map name>,<castle name>,<castle event>[,<reserved/unused switch flag>]
struct guild_castle *gc;
- sprintf(line, "%s/castle_db.txt", db_path);
- if( (fp=fopen(line,"r"))==NULL){
- ShowError("can't read %s\n", line);
- return -1;
- }
-
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0]=='/' && line[1]=='/')
- continue;
- memset(str,0,sizeof(str));
- for(j=0,p=line;j<6 && p;j++){
- str[j]=p;
- p=strchr(p,',');
- if(p) *p++=0;
- }
- if (j < 4) //Insufficient data for castle. [Skotlex]
- {
- ShowError("castle_db.txt: invalid line '%s'\n", line);
- continue;
- }
-
- gc=(struct guild_castle *)aCalloc(1,sizeof(struct guild_castle));
- gc->castle_id=atoi(str[0]);
- gc->mapindex = mapindex_name2id(str[1]);
- safestrncpy(gc->castle_name,str[2],NAME_LENGTH);
- safestrncpy(gc->castle_event,str[3],NAME_LENGTH);
+ CREATE(gc, struct guild_castle, 1);
+ gc->castle_id = atoi(str[0]);
+ gc->mapindex = mapindex_name2id(str[1]);
+ safestrncpy(gc->castle_name, str[2], sizeof(gc->castle_name));
+ safestrncpy(gc->castle_event, str[3], sizeof(gc->castle_event));
- idb_put(castle_db,gc->castle_id,gc);
+ idb_put(castle_db,gc->castle_id,gc);
- //intif_guild_castle_info(gc->castle_id);
+ //intif_guild_castle_info(gc->castle_id);
- ln++;
- }
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"castle_db.txt");
- return 0;
+ return true;
}
/// lookup: guild id -> guild*
@@ -1969,9 +1927,10 @@ void do_init_guild(void)
expcache_ers = ers_new(sizeof(struct guild_expcache));
guild_castleinfoevent_db=idb_alloc(DB_OPT_BASE);
- guild_read_castledb();
+ sv_readdb(db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb);
- guild_read_guildskill_tree_db(); //guild skill tree [Komurka]
+ memset(guild_skill_tree,0,sizeof(guild_skill_tree));
+ sv_readdb(db_path, "guild_skill_tree.txt", ',', 12, 12, -1, &guild_read_guildskill_tree_db); //guild skill tree [Komurka]
add_timer_func_list(guild_payexp_timer,"guild_payexp_timer");
add_timer_func_list(guild_send_xy_timer, "guild_send_xy_timer");
diff --git a/src/map/homunculus.c b/src/map/homunculus.c
index 0fbd7cbff..7bfb6081d 100644
--- a/src/map/homunculus.c
+++ b/src/map/homunculus.c
@@ -8,6 +8,7 @@
#include "../common/nullpo.h"
#include "../common/mmo.h"
#include "../common/showmsg.h"
+#include "../common/strlib.h"
#include "../common/utils.h"
#include "log.h"
@@ -523,7 +524,7 @@ static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data)
int merc_hom_hungry_timer_delete(struct homun_data *hd)
{
nullpo_ret(hd);
- if(hd->hungry_timer != -1) {
+ if(hd->hungry_timer != INVALID_TIMER) {
delete_timer(hd->hungry_timer,merc_hom_hungry);
hd->hungry_timer = INVALID_TIMER;
}
@@ -637,7 +638,7 @@ int merc_hom_alloc(struct map_session_data *sd, struct s_homunculus *hom)
void merc_hom_init_timers(struct homun_data * hd)
{
- if (hd->hungry_timer == -1)
+ if (hd->hungry_timer == INVALID_TIMER)
hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,merc_hom_hungry,hd->master->bl.id,0);
hd->regen.state.block = 0; //Restore HP/SP block.
}
@@ -876,226 +877,190 @@ int merc_hom_shuffle(struct homun_data *hd)
return 1;
}
+static bool read_homunculusdb_sub(char* str[], int columns, int current)
+{
+ int classid;
+ struct s_homunculus_db *db;
+
+ //Base Class,Evo Class
+ classid = atoi(str[0]);
+ if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX)
+ {
+ ShowError("read_homunculusdb : Invalid class %d\n", classid);
+ return false;
+ }
+ db = &homunculus_db[current];
+ db->base_class = classid;
+ classid = atoi(str[1]);
+ if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX)
+ {
+ db->base_class = 0;
+ ShowError("read_homunculusdb : Invalid class %d\n", classid);
+ return false;
+ }
+ db->evo_class = classid;
+ //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD
+ strncpy(db->name,str[2],NAME_LENGTH-1);
+ db->foodID = atoi(str[3]);
+ db->hungryDelay = atoi(str[4]);
+ db->base_size = atoi(str[5]);
+ db->evo_size = atoi(str[6]);
+ db->race = atoi(str[7]);
+ db->element = atoi(str[8]);
+ db->baseASPD = atoi(str[9]);
+ //base HP, SP, str, agi, vit, int, dex, luk
+ db->base.HP = atoi(str[10]);
+ db->base.SP = atoi(str[11]);
+ db->base.str = atoi(str[12]);
+ db->base.agi = atoi(str[13]);
+ db->base.vit = atoi(str[14]);
+ db->base.int_= atoi(str[15]);
+ db->base.dex = atoi(str[16]);
+ db->base.luk = atoi(str[17]);
+ //Growth Min/Max HP, SP, str, agi, vit, int, dex, luk
+ db->gmin.HP = atoi(str[18]);
+ db->gmax.HP = atoi(str[19]);
+ db->gmin.SP = atoi(str[20]);
+ db->gmax.SP = atoi(str[21]);
+ db->gmin.str = atoi(str[22]);
+ db->gmax.str = atoi(str[23]);
+ db->gmin.agi = atoi(str[24]);
+ db->gmax.agi = atoi(str[25]);
+ db->gmin.vit = atoi(str[26]);
+ db->gmax.vit = atoi(str[27]);
+ db->gmin.int_= atoi(str[28]);
+ db->gmax.int_= atoi(str[29]);
+ db->gmin.dex = atoi(str[30]);
+ db->gmax.dex = atoi(str[31]);
+ db->gmin.luk = atoi(str[32]);
+ db->gmax.luk = atoi(str[33]);
+ //Evolution Min/Max HP, SP, str, agi, vit, int, dex, luk
+ db->emin.HP = atoi(str[34]);
+ db->emax.HP = atoi(str[35]);
+ db->emin.SP = atoi(str[36]);
+ db->emax.SP = atoi(str[37]);
+ db->emin.str = atoi(str[38]);
+ db->emax.str = atoi(str[39]);
+ db->emin.agi = atoi(str[40]);
+ db->emax.agi = atoi(str[41]);
+ db->emin.vit = atoi(str[42]);
+ db->emax.vit = atoi(str[43]);
+ db->emin.int_= atoi(str[44]);
+ db->emax.int_= atoi(str[45]);
+ db->emin.dex = atoi(str[46]);
+ db->emax.dex = atoi(str[47]);
+ db->emin.luk = atoi(str[48]);
+ db->emax.luk = atoi(str[49]);
+
+ //Check that the min/max values really are below the other one.
+ if(db->gmin.HP > db->gmax.HP)
+ db->gmin.HP = db->gmax.HP;
+ if(db->gmin.SP > db->gmax.SP)
+ db->gmin.SP = db->gmax.SP;
+ if(db->gmin.str > db->gmax.str)
+ db->gmin.str = db->gmax.str;
+ if(db->gmin.agi > db->gmax.agi)
+ db->gmin.agi = db->gmax.agi;
+ if(db->gmin.vit > db->gmax.vit)
+ db->gmin.vit = db->gmax.vit;
+ if(db->gmin.int_> db->gmax.int_)
+ db->gmin.int_= db->gmax.int_;
+ if(db->gmin.dex > db->gmax.dex)
+ db->gmin.dex = db->gmax.dex;
+ if(db->gmin.luk > db->gmax.luk)
+ db->gmin.luk = db->gmax.luk;
+
+ if(db->emin.HP > db->emax.HP)
+ db->emin.HP = db->emax.HP;
+ if(db->emin.SP > db->emax.SP)
+ db->emin.SP = db->emax.SP;
+ if(db->emin.str > db->emax.str)
+ db->emin.str = db->emax.str;
+ if(db->emin.agi > db->emax.agi)
+ db->emin.agi = db->emax.agi;
+ if(db->emin.vit > db->emax.vit)
+ db->emin.vit = db->emax.vit;
+ if(db->emin.int_> db->emax.int_)
+ db->emin.int_= db->emax.int_;
+ if(db->emin.dex > db->emax.dex)
+ db->emin.dex = db->emax.dex;
+ if(db->emin.luk > db->emax.luk)
+ db->emin.luk = db->emax.luk;
+
+ return true;
+}
+
int read_homunculusdb(void)
{
- FILE *fp;
- char line[1024], *p;
- int i, k, classid;
- int j = 0;
+ int i;
const char *filename[]={"homunculus_db.txt","homunculus_db2.txt"};
- char *str[50];
- struct s_homunculus_db *db;
memset(homunculus_db,0,sizeof(homunculus_db));
- for(i = 0; i<2; i++)
+ for(i = 0; i<ARRAYLENGTH(filename); i++)
{
- sprintf(line, "%s/%s", db_path, filename[i]);
- fp = fopen(line,"r");
- if(!fp){
- if(i != 0)
- continue;
- ShowError("read_homunculusdb : can't read %s\n", line);
- return -1;
- }
+ char path[256];
- while(fgets(line, sizeof(line), fp) && j < MAX_HOMUNCULUS_CLASS)
+ if( i > 0 )
{
- if(line[0] == '/' && line[1] == '/')
- continue;
+ sprintf(path, "%s/%s", db_path, filename[i]);
- k = 0;
- p = strtok (line,",");
- while (p != NULL && k < 50)
- {
- str[k++] = p;
- p = strtok (NULL, ",");
- }
- if (k < 50 )
- {
- ShowError("read_homunculusdb : Incorrect number of columns at %s, homunculus %d. Read %d columns, 50 are needed.\n", filename[i], j+1, k);
- continue;
- }
-
- //Base Class,Evo Class
- classid = atoi(str[0]);
- if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX)
- {
- ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]);
- continue;
- }
- db = &homunculus_db[j];
- db->base_class = classid;
- classid = atoi(str[1]);
- if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX)
+ if( !exists(path) )
{
- db->base_class = 0;
- ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]);
continue;
}
- db->evo_class = classid;
- //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD
- strncpy(db->name,str[2],NAME_LENGTH-1);
- db->foodID = atoi(str[3]);
- db->hungryDelay = atoi(str[4]);
- db->base_size = atoi(str[5]);
- db->evo_size = atoi(str[6]);
- db->race = atoi(str[7]);
- db->element = atoi(str[8]);
- db->baseASPD = atoi(str[9]);
- //base HP, SP, str, agi, vit, int, dex, luk
- db->base.HP = atoi(str[10]);
- db->base.SP = atoi(str[11]);
- db->base.str = atoi(str[12]);
- db->base.agi = atoi(str[13]);
- db->base.vit = atoi(str[14]);
- db->base.int_= atoi(str[15]);
- db->base.dex = atoi(str[16]);
- db->base.luk = atoi(str[17]);
- //Growth Min/Max HP, SP, str, agi, vit, int, dex, luk
- db->gmin.HP = atoi(str[18]);
- db->gmax.HP = atoi(str[19]);
- db->gmin.SP = atoi(str[20]);
- db->gmax.SP = atoi(str[21]);
- db->gmin.str = atoi(str[22]);
- db->gmax.str = atoi(str[23]);
- db->gmin.agi = atoi(str[24]);
- db->gmax.agi = atoi(str[25]);
- db->gmin.vit = atoi(str[26]);
- db->gmax.vit = atoi(str[27]);
- db->gmin.int_= atoi(str[28]);
- db->gmax.int_= atoi(str[29]);
- db->gmin.dex = atoi(str[30]);
- db->gmax.dex = atoi(str[31]);
- db->gmin.luk = atoi(str[32]);
- db->gmax.luk = atoi(str[33]);
- //Evolution Min/Max HP, SP, str, agi, vit, int, dex, luk
- db->emin.HP = atoi(str[34]);
- db->emax.HP = atoi(str[35]);
- db->emin.SP = atoi(str[36]);
- db->emax.SP = atoi(str[37]);
- db->emin.str = atoi(str[38]);
- db->emax.str = atoi(str[39]);
- db->emin.agi = atoi(str[40]);
- db->emax.agi = atoi(str[41]);
- db->emin.vit = atoi(str[42]);
- db->emax.vit = atoi(str[43]);
- db->emin.int_= atoi(str[44]);
- db->emax.int_= atoi(str[45]);
- db->emin.dex = atoi(str[46]);
- db->emax.dex = atoi(str[47]);
- db->emin.luk = atoi(str[48]);
- db->emax.luk = atoi(str[49]);
-
- //Check that the min/max values really are below the other one.
- if(db->gmin.HP > db->gmax.HP)
- db->gmin.HP = db->gmax.HP;
- if(db->gmin.SP > db->gmax.SP)
- db->gmin.SP = db->gmax.SP;
- if(db->gmin.str > db->gmax.str)
- db->gmin.str = db->gmax.str;
- if(db->gmin.agi > db->gmax.agi)
- db->gmin.agi = db->gmax.agi;
- if(db->gmin.vit > db->gmax.vit)
- db->gmin.vit = db->gmax.vit;
- if(db->gmin.int_> db->gmax.int_)
- db->gmin.int_= db->gmax.int_;
- if(db->gmin.dex > db->gmax.dex)
- db->gmin.dex = db->gmax.dex;
- if(db->gmin.luk > db->gmax.luk)
- db->gmin.luk = db->gmax.luk;
-
- if(db->emin.HP > db->emax.HP)
- db->emin.HP = db->emax.HP;
- if(db->emin.SP > db->emax.SP)
- db->emin.SP = db->emax.SP;
- if(db->emin.str > db->emax.str)
- db->emin.str = db->emax.str;
- if(db->emin.agi > db->emax.agi)
- db->emin.agi = db->emax.agi;
- if(db->emin.vit > db->emax.vit)
- db->emin.vit = db->emax.vit;
- if(db->emin.int_> db->emax.int_)
- db->emin.int_= db->emax.int_;
- if(db->emin.dex > db->emax.dex)
- db->emin.dex = db->emax.dex;
- if(db->emin.luk > db->emax.luk)
- db->emin.luk = db->emax.luk;
-
- j++;
}
- if (j > MAX_HOMUNCULUS_CLASS)
- ShowWarning("read_homunculusdb: Reached max number of homunculus [%d]. Remaining homunculus were not read.\n ", MAX_HOMUNCULUS_CLASS);
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' homunculus in '"CL_WHITE"db/%s"CL_RESET"'.\n",j,filename[i]);
+
+ sv_readdb(db_path, filename[i], ',', 50, 50, MAX_HOMUNCULUS_CLASS, &read_homunculusdb_sub);
}
+
return 0;
}
-int read_homunculus_skilldb(void)
-{
- FILE *fp;
- char line[1024], *p;
+static bool read_homunculus_skilldb_sub(char* split[], int columns, int current)
+{// <hom class>,<skill id>,<max level>[,<job level>],<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>
int k, classid;
- int j = 0;
- char *split[15];
+ int j;
+ int minJobLevelPresent = 0;
- memset(hskill_tree,0,sizeof(hskill_tree));
- sprintf(line, "%s/homun_skill_tree.txt", db_path);
- fp=fopen(line,"r");
- if(fp==NULL){
- ShowError("can't read %s\n", line);
- return 1;
- }
+ if( columns == 14 )
+ minJobLevelPresent = 1; // MinJobLvl has been added
- while(fgets(line, sizeof(line), fp))
+ // check for bounds [celest]
+ classid = atoi(split[0]) - HM_CLASS_BASE;
+ if ( classid >= MAX_HOMUNCULUS_CLASS )
{
- int minJobLevelPresent = 0;
-
- if(line[0]=='/' && line[1]=='/')
- continue;
-
- k = 0;
- p = strtok(line,",");
- while (p != NULL && k < 15)
- {
- split[k++] = p;
- p = strtok(NULL, ",");
- }
-
- if(k < 13)
- continue;
-
- if (k == 14)
- minJobLevelPresent = 1; // MinJobLvl has been added
+ ShowWarning("read_homunculus_skilldb: Invalud homunculus class %d.\n", atoi(split[0]));
+ return false;
+ }
- // check for bounds [celest]
- classid = atoi(split[0]) - HM_CLASS_BASE;
- if ( classid >= MAX_HOMUNCULUS_CLASS )
- continue;
+ k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex]
+ // Search an empty line or a line with the same skill_id (stored in j)
+ ARR_FIND( 0, MAX_SKILL_TREE, j, !hskill_tree[classid][j].id || hskill_tree[classid][j].id == k );
+ if (j == MAX_SKILL_TREE)
+ {
+ ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid);
+ return false;
+ }
- k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex]
- // Search an empty line or a line with the same skill_id (stored in j)
- for(j = 0; j < MAX_SKILL_TREE && hskill_tree[classid][j].id && hskill_tree[classid][j].id != k; j++);
+ hskill_tree[classid][j].id = k;
+ hskill_tree[classid][j].max = atoi(split[2]);
+ if (minJobLevelPresent)
+ hskill_tree[classid][j].joblv = atoi(split[3]);
- if (j == MAX_SKILL_TREE)
- {
- ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid);
- continue;
- }
+ for( k = 0; k < MAX_PC_SKILL_REQUIRE; k++ )
+ {
+ hskill_tree[classid][j].need[k].id = atoi(split[3+k*2+minJobLevelPresent]);
+ hskill_tree[classid][j].need[k].lv = atoi(split[3+k*2+minJobLevelPresent+1]);
+ }
- hskill_tree[classid][j].id=k;
- hskill_tree[classid][j].max=atoi(split[2]);
- if (minJobLevelPresent)
- hskill_tree[classid][j].joblv=atoi(split[3]);
+ return true;
+}
- for(k=0;k<MAX_PC_SKILL_REQUIRE;k++){
- hskill_tree[classid][j].need[k].id=atoi(split[3+k*2+minJobLevelPresent]);
- hskill_tree[classid][j].need[k].lv=atoi(split[3+k*2+minJobLevelPresent+1]);
- }
- }
+int read_homunculus_skilldb(void)
+{
+ memset(hskill_tree,0,sizeof(hskill_tree));
+ sv_readdb(db_path, "homun_skill_tree.txt", ',', 13, 14, -1, &read_homunculus_skilldb_sub);
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","homun_skill_tree.txt");
return 0;
}
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 6455d10b6..bf801fefd 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -471,46 +471,32 @@ int itemdb_isidentified(int nameid)
/*==========================================
* アイテム使用可能フラグのオーバーライド
*------------------------------------------*/
-static int itemdb_read_itemavail (void)
-{
- FILE *fp;
- int nameid, j, k, ln = 0;
- char line[1024], *str[10], *p;
+static bool itemdb_read_itemavail(char* str[], int columns, int current)
+{// <nameid>,<sprite>
+ int nameid, sprite;
struct item_data *id;
- sprintf(line, "%s/item_avail.txt", db_path);
- if ((fp = fopen(line,"r")) == NULL) {
- ShowError("can't read %s\n", line);
- return -1;
- }
+ nameid = atoi(str[0]);
- while(fgets(line, sizeof(line), fp))
+ if( ( id = itemdb_exists(nameid) ) == NULL )
{
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset(str, 0, sizeof(str));
- for (j = 0, p = line; j < 2 && p; j++) {
- str[j] = p;
- p = strchr(p, ',');
- if(p) *p++ = 0;
- }
+ ShowWarning("itemdb_read_itemavail: Invalid item id %d.\n", nameid);
+ return false;
+ }
- if (j < 2 || str[0] == NULL ||
- (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
- continue;
+ sprite = atoi(str[1]);
- k = atoi(str[1]);
- if (k > 0) {
- id->flag.available = 1;
- id->view_id = k;
- } else
- id->flag.available = 0;
- ln++;
+ if( sprite > 0 )
+ {
+ id->flag.available = 1;
+ id->view_id = sprite;
+ }
+ else
+ {
+ id->flag.available = 0;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_avail.txt");
- return 0;
+ return true;
}
/*==========================================
@@ -591,137 +577,90 @@ static void itemdb_read_itemgroup(void)
/*==========================================
* 装備制限ファイル読み出し
*------------------------------------------*/
-static int itemdb_read_noequip(void)
-{
- FILE *fp;
- char line[1024];
- int ln=0;
- int nameid,j;
- char *str[32],*p;
+static bool itemdb_read_noequip(char* str[], int columns, int current)
+{// <nameid>,<mode>
+ int nameid;
struct item_data *id;
- sprintf(line, "%s/item_noequip.txt", db_path);
- if( (fp=fopen(line,"r"))==NULL ){
- ShowError("can't read %s\n", line);
- return -1;
- }
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0]=='/' && line[1]=='/')
- continue;
- memset(str,0,sizeof(str));
- for(j=0,p=line;j<2 && p;j++){
- str[j]=p;
- p=strchr(p,',');
- if(p) *p++=0;
- }
- if(str[0]==NULL)
- continue;
-
- nameid=atoi(str[0]);
- if(nameid<=0 || !(id=itemdb_exists(nameid)))
- continue;
+ nameid = atoi(str[0]);
- id->flag.no_equip |= atoi(str[1]);
+ if( ( id = itemdb_exists(nameid) ) == NULL )
+ {
+ ShowWarning("itemdb_read_noequip: Invalid item id %d.\n", nameid);
+ return false;
+ }
- ln++;
+ id->flag.no_equip |= atoi(str[1]);
- }
- fclose(fp);
- if (ln > 0) {
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"item_noequip.txt");
- }
- return 0;
+ return true;
}
/*==========================================
* Reads item trade restrictions [Skotlex]
*------------------------------------------*/
-static int itemdb_read_itemtrade(void)
-{
- FILE *fp;
- int nameid, j, flag, gmlv, ln = 0;
- char line[1024], *str[10], *p;
+static bool itemdb_read_itemtrade(char* str[], int columns, int current)
+{// <nameid>,<mask>,<gm level>
+ int nameid, flag, gmlv;
struct item_data *id;
- sprintf(line, "%s/item_trade.txt", db_path);
- if ((fp = fopen(line,"r")) == NULL) {
- ShowError("can't read %s\n", line);
- return -1;
- }
+ nameid = atoi(str[0]);
- while(fgets(line, sizeof(line), fp))
+ if( ( id = itemdb_exists(nameid) ) == NULL )
{
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset(str, 0, sizeof(str));
- for (j = 0, p = line; j < 3 && p; j++) {
- str[j] = p;
- p = strchr(p, ',');
- if(p) *p++ = 0;
- }
+ //ShowWarning("itemdb_read_itemtrade: Invalid item id %d.\n", nameid);
+ //return false;
+ // FIXME: item_trade.txt contains items, which are commented in item database.
+ return true;
+ }
- if (j < 3 || str[0] == NULL ||
- (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
- continue;
+ flag = atoi(str[1]);
+ gmlv = atoi(str[2]);
- flag = atoi(str[1]);
- gmlv = atoi(str[2]);
-
- if (flag > 0 && flag < 128 && gmlv > 0) { //Check range
- id->flag.trade_restriction = flag;
- id->gm_lv_trade_override = gmlv;
- ln++;
- }
+ if( flag < 0 || flag >= 128 )
+ {//Check range
+ ShowWarning("itemdb_read_itemtrade: Invalid trading mask %d for item id %d.\n", flag, nameid);
+ return false;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_trade.txt");
- return 0;
+ if( gmlv < 1 )
+ {
+ ShowWarning("itemdb_read_itemtrade: Invalid override GM level %d for item id %d.\n", gmlv, nameid);
+ return false;
+ }
+
+ id->flag.trade_restriction = flag;
+ id->gm_lv_trade_override = gmlv;
+
+ return true;
}
/*==========================================
* Reads item delay amounts [Paradox924X]
*------------------------------------------*/
-static int itemdb_read_itemdelay(void)
-{
- FILE *fp;
- int nameid, j, item_delays = 0;
- char line[1024], *str[10], *p;
+static bool itemdb_read_itemdelay(char* str[], int columns, int current)
+{// <nameid>,<delay>
+ int nameid, delay;
struct item_data *id;
- sprintf(line, "%s/item_delay.txt", db_path);
- if ((fp = fopen(line,"r")) == NULL) {
- ShowError("can't read %s\n", line);
- return -1;
- }
+ nameid = atoi(str[0]);
- while(fgets(line, sizeof(line), fp))
+ if( ( id = itemdb_exists(nameid) ) == NULL )
{
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (item_delays == MAX_ITEMDELAYS) {
- ShowError("itemdb_read_itemdelay: Too many entries specified in %s/item_delay.txt! Increase MAX_ITEMDELAYS in itemdb.h!\n", db_path);
- break;
- }
- memset(str, 0, sizeof(str));
- for (j = 0, p = line; j < 2 && p; j++) {
- str[j] = p;
- p = strchr(p, ',');
- if(p) *p++ = 0;
- }
+ ShowWarning("itemdb_read_itemdelay: Invalid item id %d.\n", nameid);
+ return false;
+ }
- if (j < 2 || str[0] == NULL ||
- (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
- continue;
+ delay = atoi(str[1]);
- id->delay = atoi(str[1]);
- item_delays++;
+ if( delay < 0 )
+ {
+ ShowWarning("itemdb_read_itemdelay: Invalid delay %d for item id %d.\n", id->delay, nameid);
+ return false;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", item_delays, "item_delay.txt");
- return 0;
+ id->delay = delay;
+
+ return true;
}
/*==================================================================
@@ -1076,10 +1015,10 @@ static void itemdb_read(void)
itemdb_readdb();
itemdb_read_itemgroup();
- itemdb_read_itemavail();
- itemdb_read_noequip();
- itemdb_read_itemtrade();
- itemdb_read_itemdelay();
+ sv_readdb(db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail);
+ sv_readdb(db_path, "item_noequip.txt", ',', 2, 2, -1, &itemdb_read_noequip);
+ sv_readdb(db_path, "item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade);
+ sv_readdb(db_path, "item_delay.txt", ',', 2, 2, MAX_ITEMDELAYS, &itemdb_read_itemdelay);
sv_readdb(db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack);
}
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index bc1d5b3b0..1b8917277 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -111,7 +111,7 @@ struct item_data* itemdb_exists(int nameid);
#define itemdb_wlv(n) itemdb_search(n)->wlv
#define itemdb_range(n) itemdb_search(n)->range
#define itemdb_slot(n) itemdb_search(n)->slot
-#define itemdb_available(n) (itemdb_exists(n) && itemdb_search(n)->flag.available)
+#define itemdb_available(n) (itemdb_search(n)->flag.available)
#define itemdb_viewid(n) (itemdb_search(n)->view_id)
#define itemdb_autoequip(n) (itemdb_search(n)->flag.autoequip)
const char* itemdb_typename(int type);
diff --git a/src/map/map.c b/src/map/map.c
index b052cd7bc..e3cada963 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -393,19 +393,11 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
//TODO: Perhaps some outs of bounds checking should be placed here?
if (bl->type&BL_CHAR) {
skill_unit_move(bl,tick,2);
- sc = status_get_sc(bl);
- if (sc && sc->count) {
- if (sc->data[SC_CLOSECONFINE])
- status_change_end(bl, SC_CLOSECONFINE, -1);
- if (sc->data[SC_CLOSECONFINE2])
- status_change_end(bl, SC_CLOSECONFINE2, -1);
-// if (sc->data[SC_BLADESTOP]) //Won't stop when you are knocked away, go figure...
-// status_change_end(bl, SC_BLADESTOP, -1);
- if (sc->data[SC_TATAMIGAESHI])
- status_change_end(bl, SC_TATAMIGAESHI, -1);
- if (sc->data[SC_MAGICROD])
- status_change_end(bl, SC_MAGICROD, -1);
- }
+ status_change_end(bl, SC_CLOSECONFINE, INVALID_TIMER);
+ status_change_end(bl, SC_CLOSECONFINE2, INVALID_TIMER);
+// status_change_end(bl, SC_BLADESTOP, INVALID_TIMER); //Won't stop when you are knocked away, go figure...
+ status_change_end(bl, SC_TATAMIGAESHI, INVALID_TIMER);
+ status_change_end(bl, SC_MAGICROD, INVALID_TIMER);
} else
if (bl->type == BL_NPC)
npc_unsetcells((TBL_NPC*)bl);
@@ -423,6 +415,7 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
if (bl->type&BL_CHAR) {
skill_unit_move(bl,tick,3);
+ sc = status_get_sc(bl);
if (sc) {
if (sc->count) {
if (sc->data[SC_CLOAKING])
@@ -1566,7 +1559,7 @@ int map_quit(struct map_session_data *sd)
return 0;
}
- if (sd->npc_timer_id != -1) //Cancel the event timer.
+ if (sd->npc_timer_id != INVALID_TIMER) //Cancel the event timer.
npc_timerevent_quit(sd);
if (sd->npc_id)
@@ -1580,64 +1573,40 @@ int map_quit(struct map_session_data *sd)
if( sd->sc.count )
{
//Status that are not saved...
- if(sd->sc.data[SC_BOSSMAPINFO])
- status_change_end(&sd->bl,SC_BOSSMAPINFO,-1);
- if(sd->sc.data[SC_AUTOTRADE])
- status_change_end(&sd->bl,SC_AUTOTRADE,-1);
- if(sd->sc.data[SC_SPURT])
- status_change_end(&sd->bl,SC_SPURT,-1);
- if(sd->sc.data[SC_BERSERK])
- status_change_end(&sd->bl,SC_BERSERK,-1);
- if(sd->sc.data[SC_TRICKDEAD])
- status_change_end(&sd->bl,SC_TRICKDEAD,-1);
- if(sd->sc.data[SC_GUILDAURA])
- status_change_end(&sd->bl,SC_GUILDAURA,-1);
+ status_change_end(&sd->bl, SC_BOSSMAPINFO, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_AUTOTRADE, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_SPURT, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_BERSERK, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_TRICKDEAD, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_GUILDAURA, INVALID_TIMER);
if(sd->sc.data[SC_ENDURE] && sd->sc.data[SC_ENDURE]->val4)
- status_change_end(&sd->bl,SC_ENDURE,-1); //No need to save infinite endure.
- if(sd->sc.data[SC_WEIGHT50])
- status_change_end(&sd->bl,SC_WEIGHT50,-1);
- if(sd->sc.data[SC_WEIGHT90])
- status_change_end(&sd->bl,SC_WEIGHT90,-1);
+ status_change_end(&sd->bl, SC_ENDURE, INVALID_TIMER); //No need to save infinite endure.
+ status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
if (battle_config.debuff_on_logout&1) {
- if(sd->sc.data[SC_ORCISH])
- status_change_end(&sd->bl,SC_ORCISH,-1);
- if(sd->sc.data[SC_STRIPWEAPON])
- status_change_end(&sd->bl,SC_STRIPWEAPON,-1);
- if(sd->sc.data[SC_STRIPARMOR])
- status_change_end(&sd->bl,SC_STRIPARMOR,-1);
- if(sd->sc.data[SC_STRIPSHIELD])
- status_change_end(&sd->bl,SC_STRIPSHIELD,-1);
- if(sd->sc.data[SC_STRIPHELM])
- status_change_end(&sd->bl,SC_STRIPHELM,-1);
- if(sd->sc.data[SC_EXTREMITYFIST])
- status_change_end(&sd->bl,SC_EXTREMITYFIST,-1);
- if(sd->sc.data[SC_EXPLOSIONSPIRITS])
- status_change_end(&sd->bl,SC_EXPLOSIONSPIRITS,-1);
+ status_change_end(&sd->bl, SC_ORCISH, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_STRIPWEAPON, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_STRIPARMOR, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_STRIPSHIELD, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_STRIPHELM, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_EXTREMITYFIST, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_EXPLOSIONSPIRITS, INVALID_TIMER);
if(sd->sc.data[SC_REGENERATION] && sd->sc.data[SC_REGENERATION]->val4)
- status_change_end(&sd->bl,SC_REGENERATION,-1);
+ status_change_end(&sd->bl, SC_REGENERATION, INVALID_TIMER);
//TO-DO Probably there are way more NPC_type negative status that are removed
- if(sd->sc.data[SC_CHANGEUNDEAD])
- status_change_end(&sd->bl,SC_CHANGEUNDEAD,-1);
+ status_change_end(&sd->bl, SC_CHANGEUNDEAD, INVALID_TIMER);
// Both these statuses are removed on logout. [L0ne_W0lf]
- if(sd->sc.data[SC_SLOWCAST])
- status_change_end(&sd->bl,SC_SLOWCAST,-1);
- if(sd->sc.data[SC_CRITICALWOUND])
- status_change_end(&sd->bl,SC_CRITICALWOUND,-1);
+ status_change_end(&sd->bl, SC_SLOWCAST, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_CRITICALWOUND, INVALID_TIMER);
}
if (battle_config.debuff_on_logout&2)
{
- if(sd->sc.data[SC_MAXIMIZEPOWER])
- status_change_end(&sd->bl,SC_MAXIMIZEPOWER,-1);
- if(sd->sc.data[SC_MAXOVERTHRUST])
- status_change_end(&sd->bl,SC_MAXOVERTHRUST,-1);
- if(sd->sc.data[SC_STEELBODY])
- status_change_end(&sd->bl,SC_STEELBODY,-1);
- if(sd->sc.data[SC_PRESERVE])
- status_change_end(&sd->bl,SC_PRESERVE,-1);
- if(sd->sc.data[SC_KAAHI])
- status_change_end(&sd->bl,SC_KAAHI,-1);
- if(sd->sc.data[SC_SPIRIT])
- status_change_end(&sd->bl,SC_SPIRIT,-1);
+ status_change_end(&sd->bl, SC_MAXIMIZEPOWER, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_MAXOVERTHRUST, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_STEELBODY, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_PRESERVE, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_KAAHI, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_SPIRIT, INVALID_TIMER);
}
}
@@ -2109,7 +2078,7 @@ int map_addmobtolist(unsigned short m, struct spawn_data *spawn)
void map_spawnmobs(int m)
{
int i, k=0;
- if (map[m].mob_delete_timer != -1)
+ if (map[m].mob_delete_timer != INVALID_TIMER)
{ //Mobs have not been removed yet [Skotlex]
delete_timer(map[m].mob_delete_timer, map_removemobs_timer);
map[m].mob_delete_timer = INVALID_TIMER;
@@ -2184,7 +2153,7 @@ int map_removemobs_timer(int tid, unsigned int tick, int id, intptr data)
void map_removemobs(int m)
{
- if (map[m].mob_delete_timer != -1) // should never happen
+ if (map[m].mob_delete_timer != INVALID_TIMER) // should never happen
return; //Mobs are already scheduled for removal
map[m].mob_delete_timer = add_timer(gettick()+battle_config.mob_remove_delay, map_removemobs_timer, m, 0);
@@ -2804,8 +2773,16 @@ void map_flags_init(void)
for( i = 0; i < map_num; i++ )
{
+ // mapflags
memset(&map[i].flag, 0, sizeof(map[i].flag));
+ // additional mapflag data
+ map[i].zone = 0; // restricted mapflag zone
+ map[i].nocommand = 0; // nocommand mapflag level
+ map[i].bexp = 100; // per map base exp multiplicator
+ map[i].jexp = 100; // per map job exp multiplicator
+
+ // adjustments
if( battle_config.pk_mode )
map[i].flag.pvp = 1; // make all maps pvp for pk_mode [Valaris]
}
@@ -2975,11 +2952,7 @@ int map_readallmaps (void)
map[i].bxs = (map[i].xs + BLOCK_SIZE - 1) / BLOCK_SIZE;
map[i].bys = (map[i].ys + BLOCK_SIZE - 1) / BLOCK_SIZE;
-
- // default experience multiplicators
- map[i].jexp = 100;
- map[i].bexp = 100;
-
+
size = map[i].bxs * map[i].bys * sizeof(struct block_list*);
map[i].block = (struct block_list**)aCalloc(size, 1);
map[i].block_mob = (struct block_list**)aCalloc(size, 1);
@@ -3012,7 +2985,7 @@ static int char_ip_set = 0;
/*==========================================
* Console Command Parser [Wizputer]
*------------------------------------------*/
-int parse_console(char* buf)
+int parse_console(const char* buf)
{
char type[64];
char command[64];
@@ -3026,14 +2999,20 @@ int parse_console(char* buf)
memset(&sd, 0, sizeof(struct map_session_data));
strcpy(sd.status.name, "console");
- if( (n=sscanf(buf, "%[^:]:%[^:]:%99s %d %d[^\n]",type,command,map,&x,&y)) < 5 )
- if( (n=sscanf(buf, "%[^:]:%[^\n]",type,command)) < 2 )
- n = sscanf(buf,"%[^\n]",type);
+ if( ( n = sscanf(buf, "%63[^:]:%63[^:]:%63s %d %d[^\n]", type, command, map, &x, &y) ) < 5 )
+ {
+ if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 )
+ {
+ n = sscanf(buf, "%63[^\n]", type);
+ }
+ }
- if( n == 5 ) {
+ if( n == 5 )
+ {
m = map_mapname2mapid(map);
- if( m < 0 ){
- ShowWarning("Console: Unknown map\n");
+ if( m < 0 )
+ {
+ ShowWarning("Console: Unknown map.\n");
return 0;
}
sd.bl.m = m;
@@ -3042,32 +3021,40 @@ int parse_console(char* buf)
sd.bl.x = x;
if( y > 0 )
sd.bl.y = y;
- } else {
+ }
+ else
+ {
map[0] = '\0';
- if( n < 2 ) command[0] = '\0';
- if( n < 1 ) type[0] = '\0';
+ if( n < 2 )
+ command[0] = '\0';
+ if( n < 1 )
+ type[0] = '\0';
}
- ShowInfo("Type of command: '%s' || Command: '%s' || Map: '%s' Coords: %d %d\n", type, command, map, x, y);
+ ShowNotice("Type of command: '%s' || Command: '%s' || Map: '%s' Coords: %d %d\n", type, command, map, x, y);
- if( n == 5 && strcmpi("admin",type) == 0 ){
- if( !is_atcommand(sd.fd,&sd,command,0) )
+ if( n == 5 && strcmpi("admin",type) == 0 )
+ {
+ if( !is_atcommand(sd.fd, &sd, command, 0) )
ShowInfo("Console: not atcommand\n");
- } else if( n == 2 && strcmpi("server",type) == 0 ){
- if( strcmpi("shutdown",command) == 0 ||
- strcmpi("exit",command) == 0 ||
- strcmpi("quit",command) == 0 ){
+ }
+ else if( n == 2 && strcmpi("server", type) == 0 )
+ {
+ if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 )
+ {
runflag = 0;
}
- } else if( strcmpi("help",type) == 0 ){
- ShowNotice("To use GM commands:\n");
- ShowInfo("admin:<gm command>:<map of \"gm\"> <x> <y>\n");
+ }
+ else if( strcmpi("help", type) == 0 )
+ {
+ ShowInfo("To use GM commands:\n");
+ ShowInfo(" admin:<gm command>:<map of \"gm\"> <x> <y>\n");
ShowInfo("You can use any GM command that doesn't require the GM.\n");
ShowInfo("No using @item or @warp however you can use @charwarp\n");
ShowInfo("The <map of \"gm\"> <x> <y> is for commands that need coords of the GM\n");
ShowInfo("IE: @spawn\n");
ShowInfo("To shutdown the server:\n");
- ShowInfo("server:shutdown\n");
+ ShowInfo(" server:shutdown\n");
}
return 0;
@@ -3412,9 +3399,14 @@ void do_final(void)
ShowStatus("Terminating...\n");
+ // remove all objects on maps
for (i = 0; i < map_num; i++)
+ {
+ ShowStatus("Cleaning up maps [%d/%d]: %s..."CL_CLL"\r", i+1, map_num, map[i].name);
if (map[i].m >= 0)
map_foreachinmap(cleanup_sub, i, BL_ALL);
+ }
+ ShowStatus("Cleaned up %d maps."CL_CLL"\n", map_num);
//Scan any remaining players (between maps?) to kick them out. [Skotlex]
iter = mapit_getallusers();
diff --git a/src/map/mercenary.c b/src/map/mercenary.c
index 79bec2da6..8300628d5 100644
--- a/src/map/mercenary.c
+++ b/src/map/mercenary.c
@@ -8,6 +8,7 @@
#include "../common/nullpo.h"
#include "../common/mmo.h"
#include "../common/showmsg.h"
+#include "../common/strlib.h"
#include "../common/utils.h"
#include "log.h"
@@ -249,7 +250,7 @@ int merc_delete(struct mercenary_data *md, int reply)
if( md->devotion_flag )
{
md->devotion_flag = 0;
- status_change_end(&sd->bl, SC_DEVOTION, -1);
+ status_change_end(&sd->bl, SC_DEVOTION, INVALID_TIMER);
}
switch( reply )
@@ -402,162 +403,105 @@ int mercenary_checkskill(struct mercenary_data *md, int skill_id)
return 0;
}
-int read_mercenarydb(void)
+static bool read_mercenarydb_sub(char* str[], int columns, int current)
{
- FILE *fp;
- char line[1024], *p;
- char *str[26];
- int i, j = 0, k = 0, ele;
+ int ele;
struct s_mercenary_db *db;
struct status_data *status;
- sprintf(line, "%s/%s", db_path, "mercenary_db.txt");
- memset(mercenary_db,0,sizeof(mercenary_db));
-
- fp = fopen(line, "r");
- if( !fp )
+ db = &mercenary_db[current];
+ db->class_ = atoi(str[0]);
+ strncpy(db->sprite, str[1], NAME_LENGTH);
+ strncpy(db->name, str[2], NAME_LENGTH);
+ db->lv = atoi(str[3]);
+
+ status = &db->status;
+ db->vd.class_ = db->class_;
+
+ status->max_hp = atoi(str[4]);
+ status->max_sp = atoi(str[5]);
+ status->rhw.range = atoi(str[6]);
+ status->rhw.atk = atoi(str[7]);
+ status->rhw.atk2 = status->rhw.atk + atoi(str[8]);
+ status->def = atoi(str[9]);
+ status->mdef = atoi(str[10]);
+ status->str = atoi(str[11]);
+ status->agi = atoi(str[12]);
+ status->vit = atoi(str[13]);
+ status->int_ = atoi(str[14]);
+ status->dex = atoi(str[15]);
+ status->luk = atoi(str[16]);
+ db->range2 = atoi(str[17]);
+ db->range3 = atoi(str[18]);
+ status->size = atoi(str[19]);
+ status->race = atoi(str[20]);
+
+ ele = atoi(str[21]);
+ status->def_ele = ele%10;
+ status->ele_lv = ele/20;
+ if( status->def_ele >= ELE_MAX )
{
- ShowError("read_mercenarydb : can't read mercenary_db.txt\n");
- return -1;
+ ShowWarning("Mercenary %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1);
+ status->def_ele = ELE_NEUTRAL;
}
-
- while( fgets(line, sizeof(line), fp) && j < MAX_MERCENARY_CLASS )
+ if( status->ele_lv < 1 || status->ele_lv > 4 )
{
- k++;
- if( line[0] == '/' && line[1] == '/' )
- continue;
-
- i = 0;
- p = strtok(line, ",");
- while( p != NULL && i < 26 )
- {
- str[i++] = p;
- p = strtok(NULL, ",");
- }
- if( i < 26 )
- {
- ShowError("read_mercenarydb : Incorrect number of columns at mercenary_db.txt line %d.\n", k);
- continue;
- }
-
- db = &mercenary_db[j];
- db->class_ = atoi(str[0]);
- strncpy(db->sprite, str[1], NAME_LENGTH);
- strncpy(db->name, str[2], NAME_LENGTH);
- db->lv = atoi(str[3]);
-
- status = &db->status;
- db->vd.class_ = db->class_;
-
- status->max_hp = atoi(str[4]);
- status->max_sp = atoi(str[5]);
- status->rhw.range = atoi(str[6]);
- status->rhw.atk = atoi(str[7]);
- status->rhw.atk2 = status->rhw.atk + atoi(str[8]);
- status->def = atoi(str[9]);
- status->mdef = atoi(str[10]);
- status->str = atoi(str[11]);
- status->agi = atoi(str[12]);
- status->vit = atoi(str[13]);
- status->int_ = atoi(str[14]);
- status->dex = atoi(str[15]);
- status->luk = atoi(str[16]);
- db->range2 = atoi(str[17]);
- db->range3 = atoi(str[18]);
- status->size = atoi(str[19]);
- status->race = atoi(str[20]);
-
- ele = atoi(str[21]);
- status->def_ele = ele%10;
- status->ele_lv = ele/20;
- if( status->def_ele >= ELE_MAX )
- {
- ShowWarning("Mercenary %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1);
- status->def_ele = ELE_NEUTRAL;
- }
- if( status->ele_lv < 1 || status->ele_lv > 4 )
- {
- ShowWarning("Mercenary %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv);
- status->ele_lv = 1;
- }
-
- status->aspd_rate = 1000;
- status->speed = atoi(str[22]);
- status->adelay = atoi(str[23]);
- status->amotion = atoi(str[24]);
- status->dmotion = atoi(str[25]);
-
- j++;
+ ShowWarning("Mercenary %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv);
+ status->ele_lv = 1;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' mercenaries in '"CL_WHITE"db/mercenary_db.txt"CL_RESET"'.\n",j);
+ status->aspd_rate = 1000;
+ status->speed = atoi(str[22]);
+ status->adelay = atoi(str[23]);
+ status->amotion = atoi(str[24]);
+ status->dmotion = atoi(str[25]);
- return 0;
+ return true;
}
-int read_mercenary_skilldb(void)
+int read_mercenarydb(void)
{
- FILE *fp;
- char line[1024], *p;
- char *str[3];
+ memset(mercenary_db,0,sizeof(mercenary_db));
+ sv_readdb(db_path, "mercenary_db.txt", ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub);
+
+ return 0;
+}
+
+static bool read_mercenary_skilldb_sub(char* str[], int columns, int current)
+{// <merc id>,<skill id>,<skill level>
struct s_mercenary_db *db;
- int i, j = 0, k = 0, class_;
+ int i, class_;
int skillid, skilllv;
- sprintf(line, "%s/%s", db_path, "mercenary_skill_db.txt");
- fp = fopen(line, "r");
- if( !fp )
+ class_ = atoi(str[0]);
+ ARR_FIND(0, MAX_MERCENARY_CLASS, i, class_ == mercenary_db[i].class_);
+ if( i == MAX_MERCENARY_CLASS )
{
- ShowError("read_mercenary_skilldb : can't read mercenary_skill_db.txt\n");
- return -1;
+ ShowError("read_mercenary_skilldb : Class %d not found in mercenary_db for skill entry.\n", class_);
+ return false;
}
-
- while( fgets(line, sizeof(line), fp) )
+
+ skillid = atoi(str[1]);
+ if( skillid < MC_SKILLBASE || skillid >= MC_SKILLBASE + MAX_MERCSKILL )
{
- k++;
- if( line[0] == '/' && line[1] == '/' )
- continue;
-
- i = 0;
- p = strtok(line, ",");
- while( p != NULL && i < 3 )
- {
- str[i++] = p;
- p = strtok(NULL, ",");
- }
- if( i < 3 )
- {
- ShowError("read_mercenary_skilldb : Incorrect number of columns at mercenary_skill_db.txt line %d.\n", k);
- continue;
- }
-
- class_ = atoi(str[0]);
- ARR_FIND(0, MAX_MERCENARY_CLASS, i, class_ == mercenary_db[i].class_);
- if( i == MAX_MERCENARY_CLASS )
- {
- ShowError("read_mercenary_skilldb : Class not found in mercenary_db for skill entry, line %d.\n", k);
- continue;
- }
-
- skillid = atoi(str[1]);
- if( skillid < MC_SKILLBASE || skillid >= MC_SKILLBASE + MAX_MERCSKILL )
- {
- ShowError("read_mercenary_skilldb : Skill out of range, line %d.\n", k);
- continue;
- }
-
- db = &mercenary_db[i];
- skilllv = atoi(str[2]);
-
- i = skillid - MC_SKILLBASE;
- db->skill[i].id = skillid;
- db->skill[i].lv = skilllv;
- j++;
+ ShowError("read_mercenary_skilldb : Skill %d out of range.\n", skillid);
+ return false;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/mercenary_skill_db.txt"CL_RESET"'.\n",j);
+ db = &mercenary_db[i];
+ skilllv = atoi(str[2]);
+
+ i = skillid - MC_SKILLBASE;
+ db->skill[i].id = skillid;
+ db->skill[i].lv = skilllv;
+
+ return true;
+}
+
+int read_mercenary_skilldb(void)
+{
+ sv_readdb(db_path, "mercenary_skill_db.txt", ',', 3, 3, -1, &read_mercenary_skilldb_sub);
+
return 0;
}
diff --git a/src/map/mob.c b/src/map/mob.c
index d67b470af..6135850b6 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -1183,7 +1183,7 @@ int mob_unlocktarget(struct mob_data *md, unsigned int tick)
switch (md->state.skillstate) {
case MSS_WALK:
- if (md->ud.walktimer != -1)
+ if (md->ud.walktimer != INVALID_TIMER)
break;
//Because it is not unset when the mob finishes walking.
md->state.skillstate = MSS_IDLE;
@@ -1274,7 +1274,7 @@ int mob_warpchase(struct mob_data *md, struct block_list *target)
if (target->m == md->bl.m && check_distance_bl(&md->bl, target, AREA_SIZE))
return 0; //No need to do a warp chase.
- if (md->ud.walktimer != -1 &&
+ if (md->ud.walktimer != INVALID_TIMER &&
map_getcell(md->bl.m,md->ud.to_x,md->ud.to_y,CELL_CHKNPC))
return 1; //Already walking to a warp.
@@ -1306,10 +1306,10 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
md->last_thinktime = tick;
- if (md->ud.skilltimer != -1)
+ if (md->ud.skilltimer != INVALID_TIMER)
return false;
- if(md->ud.walktimer != -1 && md->ud.walkpath.path_pos <= 3)
+ if(md->ud.walktimer != INVALID_TIMER && md->ud.walkpath.path_pos <= 3)
return false;
// Abnormalities
@@ -1331,8 +1331,8 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
{ //Check validity of current target. [Skotlex]
tbl = map_id2bl(md->target_id);
if (!tbl || tbl->m != md->bl.m ||
- (md->ud.attacktimer == -1 && !status_check_skilluse(&md->bl, tbl, 0, 0)) ||
- (md->ud.walktimer != -1 && !(battle_config.mob_ai&0x1) && !check_distance_bl(&md->bl, tbl, md->min_chase)) ||
+ (md->ud.attacktimer == INVALID_TIMER && !status_check_skilluse(&md->bl, tbl, 0, 0)) ||
+ (md->ud.walktimer != INVALID_TIMER && !(battle_config.mob_ai&0x1) && !check_distance_bl(&md->bl, tbl, md->min_chase)) ||
(
tbl->type == BL_PC &&
((((TBL_PC*)tbl)->state.gangsterparadise && !(mode&MD_BOSS)) ||
@@ -1447,7 +1447,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
if (tbl->type == BL_ITEM)
{ //Loot time.
struct flooritem_data *fitem;
- if (md->ud.target == tbl->id && md->ud.walktimer != -1)
+ if (md->ud.target == tbl->id && md->ud.walktimer != INVALID_TIMER)
return true; //Already locked.
if (md->lootitem == NULL)
{ //Can't loot...
@@ -1469,7 +1469,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
return true;
}
//Within looting range.
- if (md->ud.attacktimer != -1)
+ if (md->ud.attacktimer != INVALID_TIMER)
return true; //Busy attacking?
fitem = (struct flooritem_data *)tbl;
@@ -1497,7 +1497,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
}
//Attempt to attack.
//At this point we know the target is attackable, we just gotta check if the range matches.
- if (md->ud.target == tbl->id && md->ud.attacktimer != -1) //Already locked.
+ if (md->ud.target == tbl->id && md->ud.attacktimer != INVALID_TIMER) //Already locked.
return true;
if (battle_check_range (&md->bl, tbl, md->status.rhw.range))
@@ -1526,7 +1526,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
return true;
}
- if (md->ud.walktimer != -1 && md->ud.target == tbl->id &&
+ if (md->ud.walktimer != INVALID_TIMER && md->ud.target == tbl->id &&
(
!(battle_config.mob_ai&0x1) ||
check_distance_blxy(tbl, md->ud.to_x, md->ud.to_y, md->status.rhw.range)
@@ -2432,7 +2432,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
md->status.hp = 1;
}
- if(md->deletetimer!=-1) {
+ if(md->deletetimer != INVALID_TIMER) {
delete_timer(md->deletetimer,mob_timer_delete);
md->deletetimer = INVALID_TIMER;
}
@@ -2900,7 +2900,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
nullpo_ret(md);
nullpo_ret(ms = md->db->skill);
- if (!battle_config.mob_skill_rate || md->ud.skilltimer != -1 || !md->db->maxskill)
+ if (!battle_config.mob_skill_rate || md->ud.skilltimer != INVALID_TIMER || !md->db->maxskill)
return 0;
if (event == -1 && DIFF_TICK(md->ud.canact_tick, tick) > 0)
@@ -4123,7 +4123,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
ms->target = MST_TARGET;
}
} else if (ms->target > MST_MASTER) {
- ShowWarning("mob_parse_row_mobskilldb: Wrong mob skill target 'around' for non-ground skill %d (%s) for %s\n.",
+ ShowWarning("mob_parse_row_mobskilldb: Wrong mob skill target 'around' for non-ground skill %d (%s) for %s.\n",
ms->skill_id, skill_get_name(ms->skill_id),
mob_id < 0?"all mobs":mob_db_data[mob_id]->sprite);
ms->target = MST_TARGET;
diff --git a/src/map/npc.c b/src/map/npc.c
index 4b188c177..1bf5bd312 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -493,10 +493,10 @@ int npc_timerevent(int tid, unsigned int tick, int id, intptr data)
else
{
if( sd )
- sd->npc_timer_id = -1;
+ sd->npc_timer_id = INVALID_TIMER;
else
{
- nd->u.scr.timerid = -1;
+ nd->u.scr.timerid = INVALID_TIMER;
nd->u.scr.timertick = 0; // NPC timer stopped
}
ers_free(timer_event_ers, ted);
@@ -544,10 +544,10 @@ int npc_timerevent_start(struct npc_data* nd, int rid)
// Check if timer is already started.
if( sd )
{
- if( sd->npc_timer_id != -1 )
+ if( sd->npc_timer_id != INVALID_TIMER )
return 0;
}
- else if( nd->u.scr.timerid != -1 )
+ else if( nd->u.scr.timerid != INVALID_TIMER )
return 0;
// Arrange for the next event
@@ -587,7 +587,7 @@ int npc_timerevent_stop(struct npc_data* nd)
}
tid = sd?&sd->npc_timer_id:&nd->u.scr.timerid;
- if( *tid == -1 ) // Nothing to stop
+ if( *tid == INVALID_TIMER ) // Nothing to stop
return 0;
// Delete timer
@@ -595,7 +595,7 @@ int npc_timerevent_stop(struct npc_data* nd)
if( td && td->data )
ers_free(timer_event_ers, (void*)td->data);
delete_timer(*tid,npc_timerevent);
- *tid = -1;
+ *tid = INVALID_TIMER;
if( !sd )
{
@@ -615,11 +615,11 @@ void npc_timerevent_quit(struct map_session_data* sd)
struct timer_event_data *ted;
// Check timer existance
- if( sd->npc_timer_id == -1 )
+ if( sd->npc_timer_id == INVALID_TIMER )
return;
if( !(td = get_timer(sd->npc_timer_id)) )
{
- sd->npc_timer_id = -1;
+ sd->npc_timer_id = INVALID_TIMER;
return;
}
@@ -627,7 +627,7 @@ void npc_timerevent_quit(struct map_session_data* sd)
nd = (struct npc_data *)map_id2bl(td->id);
ted = (struct timer_event_data*)td->data;
delete_timer(sd->npc_timer_id, npc_timerevent);
- sd->npc_timer_id = -1;
+ sd->npc_timer_id = INVALID_TIMER;
// Execute OnTimerQuit
if( nd && nd->bl.type == BL_NPC )
@@ -873,7 +873,7 @@ int npc_touch_areanpc(struct map_session_data* sd, int m, int x, int y)
{ // failed to run OnTouch event, so just click the npc
struct unit_data *ud = unit_bl2ud(&sd->bl);
if( ud && ud->walkpath.path_pos < ud->walkpath.path_len )
- { // Since walktimer always == -1 at this time, we stop walking manually. [Inkfish]
+ { // Since walktimer always == INVALID_TIMER at this time, we stop walking manually. [Inkfish]
clif_fixpos(&sd->bl);
ud->walkpath.path_pos = ud->walkpath.path_len;
}
@@ -1183,7 +1183,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
if( sd->state.trading )
return 4;
- if( (item = itemdb_search(nameid)) == NULL )
+ if( (item = itemdb_exists(nameid)) == NULL )
return 5; // Invalid Item
ARR_FIND(0, nd->u.shop.count, i, nd->u.shop.shop_item[i].nameid == nameid);
@@ -1600,7 +1600,7 @@ int npc_unload(struct npc_data* nd)
}
mapit_free(iter);
- if (nd->u.scr.timerid != -1) {
+ if (nd->u.scr.timerid != INVALID_TIMER) {
const struct TimerData *td = NULL;
td = get_timer(nd->u.scr.timerid);
if (td && td->data)
@@ -2245,7 +2245,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
nd->u.scr.timeramount++;
}
}
- nd->u.scr.timerid = -1;
+ nd->u.scr.timerid = INVALID_TIMER;
return end;
}
@@ -2428,7 +2428,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
nd->u.scr.timeramount++;
}
}
- nd->u.scr.timerid = -1;
+ nd->u.scr.timerid = INVALID_TIMER;
return end;
}
@@ -3536,7 +3536,7 @@ int do_init_npc(void)
fake_nd->subtype = SCRIPT;
strdb_put(npcname_db, fake_nd->exname, fake_nd);
- fake_nd->u.scr.timerid = -1;
+ fake_nd->u.scr.timerid = INVALID_TIMER;
map_addiddb(&fake_nd->bl);
// End of initialization
diff --git a/src/map/party.c b/src/map/party.c
index 407221cde..9c55a05f2 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -298,11 +298,11 @@ int party_recv_info(struct party *sp)
int party_invite(struct map_session_data *sd,struct map_session_data *tsd)
{
- struct party_data *p=party_search(sd->status.party_id);
+ struct party_data *p;
int i,flag=0;
nullpo_ret(sd);
- if( p == NULL )
+ if( ( p = party_search(sd->status.party_id) ) == NULL )
return 0;
if( tsd == NULL) { //TODO: Find the correct reply packet.
clif_displaymessage(sd->fd, msg_txt(3));
diff --git a/src/map/pc.c b/src/map/pc.c
index e7ef23ce9..7525ff63c 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -170,7 +170,7 @@ int pc_addspiritball(struct map_session_data *sd,int interval,int max)
if( sd->spiritball && sd->spiritball >= max )
{
- if(sd->spirit_timer[0] != -1)
+ if(sd->spirit_timer[0] != INVALID_TIMER)
delete_timer(sd->spirit_timer[0],pc_spiritball_timer);
sd->spiritball--;
if( sd->spiritball != 0 )
@@ -209,14 +209,14 @@ int pc_delspiritball(struct map_session_data *sd,int count,int type)
count = MAX_SKILL_LEVEL;
for(i=0;i<count;i++) {
- if(sd->spirit_timer[i] != -1) {
+ if(sd->spirit_timer[i] != INVALID_TIMER) {
delete_timer(sd->spirit_timer[i],pc_spiritball_timer);
- sd->spirit_timer[i] = -1;
+ sd->spirit_timer[i] = INVALID_TIMER;
}
}
for(i=count;i<MAX_SKILL_LEVEL;i++) {
sd->spirit_timer[i-count] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
+ sd->spirit_timer[i] = INVALID_TIMER;
}
if(!type)
@@ -317,7 +317,7 @@ int pc_inventory_rental_clear(struct map_session_data *sd)
if( sd->rental_timer != INVALID_TIMER )
{
delete_timer(sd->rental_timer, pc_inventory_rental_end);
- sd->rental_timer = -1;
+ sd->rental_timer = INVALID_TIMER;
}
return 1;
@@ -892,9 +892,7 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim
if (!(battle_config.display_skill_fail&2))
sd->state.showdelay = 1;
- // アイテムチェック
pc_setinventorydata(sd);
- pc_checkitem(sd);
status_change_init(&sd->bl);
if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) && (pc_isGM(sd) >= get_atcommand_level(atcommand_hide)))
@@ -912,7 +910,7 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim
// Event Timers
for( i = 0; i < MAX_EVENTTIMER; i++ )
- sd->eventtimer[i] = -1;
+ sd->eventtimer[i] = INVALID_TIMER;
// Rental Timer
sd->rental_timer = INVALID_TIMER;
@@ -1418,9 +1416,9 @@ int pc_updateweightstatus(struct map_session_data *sd)
// stop old status change
if( old_overweight == 1 )
- status_change_end(&sd->bl, SC_WEIGHT50, -1);
+ status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
else if( old_overweight == 2 )
- status_change_end(&sd->bl, SC_WEIGHT90, -1);
+ status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
// start new status change
if( new_overweight == 1 )
@@ -3718,7 +3716,7 @@ int pc_useitem(struct map_session_data *sd,int n)
//perform a skill-use check before going through. [Skotlex]
//resurrection was picked as testing skill, as a non-offensive, generic skill, it will do.
//FIXME: Is this really needed here? It'll be checked in unit.c after all and this prevents skill items using when silenced [Inkfish]
- if( sd->inventory_data[n]->flag.delay_consume && ( sd->ud.skilltimer != -1 /*|| !status_check_skilluse(&sd->bl, &sd->bl, ALL_RESURRECTION, 0)*/ ) )
+ if( sd->inventory_data[n]->flag.delay_consume && ( sd->ud.skilltimer != INVALID_TIMER /*|| !status_check_skilluse(&sd->bl, &sd->bl, ALL_RESURRECTION, 0)*/ ) )
return 0;
if( sd->inventory_data[n]->delay > 0 ) { // Check if there is a delay on this item [Paradox924X]
@@ -4118,21 +4116,15 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
{ // Cancel some map related stuff.
if (sd->sc.data[SC_JAILED])
return 1; //You may not get out!
- if (sd->sc.data[SC_BOSSMAPINFO])
- status_change_end(&sd->bl,SC_BOSSMAPINFO,-1);
- if (sd->sc.data[SC_WARM])
- status_change_end(&sd->bl,SC_WARM,-1);
- if (sd->sc.data[SC_SUN_COMFORT])
- status_change_end(&sd->bl,SC_SUN_COMFORT,-1);
- if (sd->sc.data[SC_MOON_COMFORT])
- status_change_end(&sd->bl,SC_MOON_COMFORT,-1);
- if (sd->sc.data[SC_STAR_COMFORT])
- status_change_end(&sd->bl,SC_STAR_COMFORT,-1);
- if (sd->sc.data[SC_MIRACLE])
- status_change_end(&sd->bl,SC_MIRACLE,-1);
+ status_change_end(&sd->bl, SC_BOSSMAPINFO, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WARM, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_SUN_COMFORT, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_MOON_COMFORT, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_STAR_COMFORT, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_MIRACLE, INVALID_TIMER);
if (sd->sc.data[SC_KNOWLEDGE]) {
struct status_change_entry *sce = sd->sc.data[SC_KNOWLEDGE];
- if (sce->timer != -1)
+ if (sce->timer != INVALID_TIMER)
delete_timer(sce->timer, status_change_timer);
sce->timer = add_timer(gettick() + skill_get_time(SG_KNOWLEDGE, sce->val1), status_change_timer, sd->bl.id, SC_KNOWLEDGE);
}
@@ -4404,17 +4396,17 @@ int pc_checkallowskill(struct map_session_data *sd)
{ // Skills requiring specific weapon types
if(sd->sc.data[scw_list[i]] &&
!pc_check_weapontype(sd,skill_get_weapontype(status_sc2skill(scw_list[i]))))
- status_change_end(&sd->bl,scw_list[i],-1);
+ status_change_end(&sd->bl, scw_list[i], INVALID_TIMER);
}
if(sd->sc.data[SC_SPURT] && sd->status.weapon)
// Spurt requires bare hands (feet, in fact xD)
- status_change_end(&sd->bl,SC_SPURT,-1);
+ status_change_end(&sd->bl, SC_SPURT, INVALID_TIMER);
if(sd->status.shield <= 0) { // Skills requiring a shield
for (i = 0; i < ARRAYLENGTH(scs_list); i++)
if(sd->sc.data[scs_list[i]])
- status_change_end(&sd->bl,scs_list[i],-1);
+ status_change_end(&sd->bl, scs_list[i], INVALID_TIMER);
}
return 0;
}
@@ -4776,7 +4768,7 @@ int pc_follow_timer(int tid, unsigned int tick, int id, intptr data)
// either player or target is currently detached from map blocks (could be teleporting),
// but still connected to this map, so we'll just increment the timer and check back later
if (sd->bl.prev != NULL && tbl->prev != NULL &&
- sd->ud.skilltimer == -1 && sd->ud.attacktimer == -1 && sd->ud.walktimer == -1)
+ sd->ud.skilltimer == INVALID_TIMER && sd->ud.attacktimer == INVALID_TIMER && sd->ud.walktimer == INVALID_TIMER)
{
if((sd->bl.m == tbl->m) && unit_can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
if (!check_distance_bl(&sd->bl, tbl, 5))
@@ -4808,11 +4800,11 @@ int pc_follow(struct map_session_data *sd,int target_id)
struct block_list *bl = map_id2bl(target_id);
if (bl == NULL /*|| bl->type != BL_PC*/)
return 1;
- if (sd->followtimer != -1)
+ if (sd->followtimer != INVALID_TIMER)
pc_stop_following(sd);
sd->followtarget = target_id;
- pc_follow_timer(-1,gettick(),sd->bl.id,0);
+ pc_follow_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
return 0;
}
@@ -5705,7 +5697,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
for(k = 0; k < 5; k++)
if (sd->devotion[k]){
struct map_session_data *devsd = map_id2sd(sd->devotion[k]);
- if (devsd) status_change_end(&devsd->bl,SC_DEVOTION,-1);
+ if (devsd)
+ status_change_end(&devsd->bl, SC_DEVOTION, INVALID_TIMER);
sd->devotion[k] = 0;
}
@@ -5774,6 +5767,11 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
md->level++;
status_calc_mob(md, 0);
status_percent_heal(src,10,0);
+
+ if( battle_config.show_mob_info&4 )
+ {// update name with new level
+ clif_charnameack(0, &md->bl);
+ }
}
src = battle_get_master(src); // Maybe Player Summon
}
@@ -5854,7 +5852,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
sc_start(&sd->bl,status_skill2sc(MO_STEELBODY),100,1,skill_get_time(MO_STEELBODY,1));
if(map_flag_gvg(sd->bl.m))
- pc_respawn_timer(-1, gettick(), sd->bl.id, 0);
+ pc_respawn_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
return 0;
}
}
@@ -6352,7 +6350,7 @@ int pc_jobchange(struct map_session_data *sd,int job, int upper)
//Remove status specific to your current tree skills.
enum sc_type sc = status_skill2sc(id);
if (sc > SC_COMMON_MAX && sd->sc.data[sc])
- status_change_end(&sd->bl, sc, -1);
+ status_change_end(&sd->bl, sc, INVALID_TIMER);
}
}
@@ -6998,7 +6996,7 @@ static int pc_eventtimer(int tid, unsigned int tick, int id, intptr data)
ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == tid );
if( i < MAX_EVENTTIMER )
{
- sd->eventtimer[i] = -1;
+ sd->eventtimer[i] = INVALID_TIMER;
sd->eventcount--;
npc_event(sd,p,0);
}
@@ -7017,7 +7015,7 @@ int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
int i;
nullpo_ret(sd);
- ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == -1 );
+ ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == INVALID_TIMER );
if( i == MAX_EVENTTIMER )
return 0;
@@ -7042,7 +7040,7 @@ int pc_deleventtimer(struct map_session_data *sd,const char *name)
// find the named event timer
ARR_FIND( 0, MAX_EVENTTIMER, i,
- sd->eventtimer[i] != -1 &&
+ sd->eventtimer[i] != INVALID_TIMER &&
(p = (char *)(get_timer(sd->eventtimer[i])->data)) != NULL &&
strcmp(p, name) == 0
);
@@ -7050,7 +7048,7 @@ int pc_deleventtimer(struct map_session_data *sd,const char *name)
return 0; // not found
delete_timer(sd->eventtimer[i],pc_eventtimer);
- sd->eventtimer[i]=-1;
+ sd->eventtimer[i] = INVALID_TIMER;
sd->eventcount--;
aFree(p);
@@ -7067,7 +7065,7 @@ int pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick)
nullpo_ret(sd);
for(i=0;i<MAX_EVENTTIMER;i++)
- if( sd->eventtimer[i]!=-1 && strcmp(
+ if( sd->eventtimer[i] != INVALID_TIMER && strcmp(
(char *)(get_timer(sd->eventtimer[i])->data), name)==0 ){
addtick_timer(sd->eventtimer[i],tick);
break;
@@ -7089,10 +7087,10 @@ int pc_cleareventtimer(struct map_session_data *sd)
return 0;
for(i=0;i<MAX_EVENTTIMER;i++)
- if( sd->eventtimer[i]!=-1 ){
+ if( sd->eventtimer[i] != INVALID_TIMER ){
char *p = (char *)(get_timer(sd->eventtimer[i])->data);
delete_timer(sd->eventtimer[i],pc_eventtimer);
- sd->eventtimer[i]=-1;
+ sd->eventtimer[i] = INVALID_TIMER;
sd->eventcount--;
if (p) aFree(p);
}
@@ -7299,8 +7297,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag)
sd->status.weapon = sd->weapontype2;
pc_calcweapontype(sd);
clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
- if(sd->sc.data[SC_DANCING]) //When unequipping, stop dancing. [Skotlex]
- status_change_end(&sd->bl, SC_DANCING, -1);
+ status_change_end(&sd->bl, SC_DANCING, INVALID_TIMER); //When unequipping, stop dancing. [Skotlex]
}
if(sd->status.inventory[n].equip & EQP_HAND_L) {
sd->status.shield = sd->weapontype2 = 0;
@@ -7330,10 +7327,8 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag)
if(sd->status.inventory[n].equip & EQP_ARMOR) {
// On Armor Change...
- if( sd->sc.data[SC_BENEDICTIO] )
- status_change_end(&sd->bl, SC_BENEDICTIO, -1);
- if( sd->sc.data[SC_ARMOR_RESIST] )
- status_change_end(&sd->bl, SC_ARMOR_RESIST, -1);
+ status_change_end(&sd->bl, SC_BENEDICTIO, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_ARMOR_RESIST, INVALID_TIMER);
}
if( sd->state.autobonus&sd->status.inventory[n].equip )
@@ -7347,7 +7342,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag)
}
if(sd->sc.data[SC_SIGNUMCRUCIS] && !battle_check_undead(sd->battle_status.race,sd->battle_status.def_ele))
- status_change_end(&sd->bl,SC_SIGNUMCRUCIS,-1);
+ status_change_end(&sd->bl, SC_SIGNUMCRUCIS, INVALID_TIMER);
//OnUnEquip script [Skotlex]
if (sd->inventory_data[n]) {
@@ -7793,8 +7788,7 @@ int map_night_timer(int tid, unsigned int tick, int id, intptr data)
void pc_setstand(struct map_session_data *sd){
nullpo_retv(sd);
- if(sd->sc.data[SC_TENSIONRELAX])
- status_change_end(&sd->bl,SC_TENSIONRELAX,-1);
+ status_change_end(&sd->bl, SC_TENSIONRELAX, INVALID_TIMER);
//Reset sitting tick.
sd->ssregen.tick.hp = sd->ssregen.tick.sp = 0;
diff --git a/src/map/pc.h b/src/map/pc.h
index 2921b4527..c48defbf5 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -350,6 +350,7 @@ struct map_session_data {
int guildspy; // [Syrus22]
int partyspy; // [Syrus22]
+ int vended_id;
int vender_id;
int vend_num;
char message[MESSAGE_SIZE];
@@ -383,8 +384,6 @@ struct map_session_data {
int killerrid, killedrid;
- char away_message[128]; // [LuzZza]
-
int cashPoints, kafraPoints;
int rental_timer;
diff --git a/src/map/pet.c b/src/map/pet.c
index 843f1cc11..6b16fe888 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -180,7 +180,7 @@ int pet_sc_check(struct map_session_data *sd, int type)
if( pd == NULL
|| (battle_config.pet_equip_required && pd->pet.equip == 0)
|| pd->recovery == NULL
- || pd->recovery->timer != -1
+ || pd->recovery->timer != INVALID_TIMER
|| pd->recovery->type != type )
return 1;
@@ -263,7 +263,7 @@ int search_petDB_index(int key,int type)
int pet_hungry_timer_delete(struct pet_data *pd)
{
nullpo_ret(pd);
- if(pd->pet_hungry_timer != -1) {
+ if(pd->pet_hungry_timer != INVALID_TIMER) {
delete_timer(pd->pet_hungry_timer,pet_hungry);
pd->pet_hungry_timer = INVALID_TIMER;
}
@@ -666,14 +666,14 @@ int pet_equipitem(struct map_session_data *sd,int index)
if (battle_config.pet_equip_required)
{ //Skotlex: start support timers if need
unsigned int tick = gettick();
- if (pd->s_skill && pd->s_skill->timer == -1)
+ if (pd->s_skill && pd->s_skill->timer == INVALID_TIMER)
{
if (pd->s_skill->id)
pd->s_skill->timer=add_timer(tick+pd->s_skill->delay*1000, pet_skill_support_timer, sd->bl.id, 0);
else
pd->s_skill->timer=add_timer(tick+pd->s_skill->delay*1000, pet_heal_timer, sd->bl.id, 0);
}
- if (pd->bonus && pd->bonus->timer == -1)
+ if (pd->bonus && pd->bonus->timer == INVALID_TIMER)
pd->bonus->timer=add_timer(tick+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
}
@@ -706,7 +706,7 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
pd->state.skillbonus = 0;
status_calc_pc(sd,0);
}
- if( pd->s_skill && pd->s_skill->timer != -1 )
+ if( pd->s_skill && pd->s_skill->timer != INVALID_TIMER )
{
if( pd->s_skill->id )
delete_timer(pd->s_skill->timer, pet_skill_support_timer);
@@ -714,7 +714,7 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
delete_timer(pd->s_skill->timer, pet_heal_timer);
pd->s_skill->timer = INVALID_TIMER;
}
- if( pd->bonus && pd->bonus->timer != -1 )
+ if( pd->bonus && pd->bonus->timer != INVALID_TIMER )
{
delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
pd->bonus->timer = INVALID_TIMER;
@@ -825,10 +825,10 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
return 0;
pd->last_thinktime=tick;
- if(pd->ud.attacktimer != -1 || pd->ud.skilltimer != -1 || pd->bl.m != sd->bl.m)
+ if(pd->ud.attacktimer != INVALID_TIMER || pd->ud.skilltimer != INVALID_TIMER || pd->bl.m != sd->bl.m)
return 0;
- if(pd->ud.walktimer != -1 && pd->ud.walkpath.path_pos <= 2)
+ if(pd->ud.walktimer != INVALID_TIMER && pd->ud.walkpath.path_pos <= 2)
return 0; //No thinking when you just started to walk.
if(pd->pet.intimate <= 0) {
@@ -841,7 +841,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
//Master too far, chase.
if(pd->target_id)
pet_unlocktarget(pd);
- if(pd->ud.walktimer != -1 && pd->ud.target == sd->bl.id)
+ if(pd->ud.walktimer != INVALID_TIMER && pd->ud.target == sd->bl.id)
return 0; //Already walking to him
if (DIFF_TICK(tick, pd->ud.canmove_tick) < 0)
return 0; //Can't move yet.
@@ -855,7 +855,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
//Return speed to normal.
if (pd->status.speed != pd->petDB->speed) {
- if (pd->ud.walktimer != -1)
+ if (pd->ud.walktimer != INVALID_TIMER)
return 0; //Wait until the pet finishes walking back to master.
pd->status.speed = pd->petDB->speed;
}
@@ -881,7 +881,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if (check_distance_bl(&sd->bl, &pd->bl, 3))
return 0; //Already next to master.
- if(pd->ud.walktimer != -1 && check_distance_blxy(&sd->bl, pd->ud.to_x,pd->ud.to_y, 3))
+ if(pd->ud.walktimer != INVALID_TIMER && check_distance_blxy(&sd->bl, pd->ud.to_x,pd->ud.to_y, 3))
return 0; //Already walking to him
unit_calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
@@ -892,7 +892,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
}
if(pd->ud.target == target->id &&
- (pd->ud.attacktimer != -1 || pd->ud.walktimer != -1))
+ (pd->ud.attacktimer != INVALID_TIMER || pd->ud.walktimer != INVALID_TIMER))
return 0; //Target already locked.
if (target->type != BL_ITEM)
@@ -915,7 +915,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
struct flooritem_data *fitem = (struct flooritem_data *)target;
if(pd->loot->count < pd->loot->max){
memcpy(&pd->loot->item[pd->loot->count++],&fitem->item_data,sizeof(pd->loot->item[0]));
- pd->loot->weight += itemdb_search(fitem->item_data.nameid)->weight*fitem->item_data.amount;
+ pd->loot->weight += itemdb_weight(fitem->item_data.nameid)*fitem->item_data.amount;
map_clearflooritem(target->id);
}
//Target is unlocked regardless of whether it was picked or not.
@@ -1099,7 +1099,7 @@ int pet_recovery_timer(int tid, unsigned int tick, int id, intptr data)
{ //Display a heal animation?
//Detoxify is chosen for now.
clif_skill_nodamage(&pd->bl,&sd->bl,TF_DETOXIFY,1,1);
- status_change_end(&sd->bl,pd->recovery->type,-1);
+ status_change_end(&sd->bl, pd->recovery->type, INVALID_TIMER);
clif_emotion(&pd->bl, E_OK);
}
@@ -1130,7 +1130,7 @@ int pet_heal_timer(int tid, unsigned int tick, int id, intptr data)
if(pc_isdead(sd) ||
(rate = get_percentage(status->sp, status->max_sp)) > pd->s_skill->sp ||
(rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp ||
- (rate = (pd->ud.skilltimer != -1)) //Another skill is in effect
+ (rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect
) { //Wait (how long? 1 sec for every 10% of remaining)
pd->s_skill->timer=add_timer(gettick()+(rate>10?rate:10)*100,pet_heal_timer,sd->bl.id,0);
return 0;
@@ -1173,7 +1173,7 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr data)
if(pc_isdead(sd) ||
(rate = get_percentage(status->sp, status->max_sp)) > pd->s_skill->sp ||
(rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp ||
- (rate = (pd->ud.skilltimer != -1)) //Another skill is in effect
+ (rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect
) { //Wait (how long? 1 sec for every 10% of remaining)
pd->s_skill->timer=add_timer(tick+(rate>10?rate:10)*100,pet_skill_support_timer,sd->bl.id,0);
return 0;
diff --git a/src/map/script.c b/src/map/script.c
index 59a9b5448..f842b614a 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -70,6 +70,7 @@
// - remove dynamic allocation in add_word()
// - remove GETVALUE / SETVALUE
// - clean up the set_reg / set_val / setd_sub mess
+// - detect invalid label references at parse-time
//
// struct script_state* st;
@@ -977,6 +978,23 @@ const char* parse_callfunc(const char* p, int require_paren)
return p;
}
+/// Processes end of logical script line.
+/// @param first When true, only fix up scheduling data is initialized
+/// @param p Script position for error reporting in set_label
+static void parse_nextline(bool first, const char* p)
+{
+ if( !first )
+ {
+ add_scriptc(C_EOL); // mark end of line for stack cleanup
+ set_label(LABEL_NEXTLINE, script_pos, p); // fix up '-' labels
+ }
+
+ // initialize data for new '-' label fix up scheduling
+ str_data[LABEL_NEXTLINE].type = C_NOP;
+ str_data[LABEL_NEXTLINE].backpatch = -1;
+ str_data[LABEL_NEXTLINE].label = -1;
+}
+
/*==========================================
* 項の解析
*------------------------------------------*/
@@ -1541,12 +1559,17 @@ const char* parse_syntax(const char* p)
// function declaration - just register the name
int l;
l = add_word(func_name);
- if( str_data[l].type == C_NOP )// set type only if the name did not exist before
+ if( str_data[l].type == C_NOP )// register only, if the name was not used by something else
str_data[l].type = C_USERFUNC;
+ else if( str_data[l].type == C_USERFUNC )
+ ; // already registered
+ else
+ disp_error_message("parse_syntax:function: function name is invalid", func_name);
// if, for , while の閉じ判定
p = parse_syntax_close(p2 + 1);
- return p; }
+ return p;
+ }
else if(*p2 == '{')
{// function <name> <line/block of code>
char label[256];
@@ -1567,11 +1590,16 @@ const char* parse_syntax(const char* p)
// Set the position of the function (label)
l=add_word(func_name);
- if( str_data[l].type == C_NOP )// set type only if the name did not exist before
+ if( str_data[l].type == C_NOP || str_data[l].type == C_USERFUNC )// register only, if the name was not used by something else
+ {
str_data[l].type = C_USERFUNC;
- set_label(l, script_pos, p);
- if( parse_options&SCRIPT_USE_LABEL_DB )
- strdb_put(scriptlabel_db, get_str(l), (void*)script_pos);
+ set_label(l, script_pos, p);
+ if( parse_options&SCRIPT_USE_LABEL_DB )
+ strdb_put(scriptlabel_db, get_str(l), (void*)script_pos);
+ }
+ else
+ disp_error_message("parse_syntax:function: function name is invalid", func_name);
+
return skip_space(p);
}
else
@@ -1691,6 +1719,10 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
} else if(syntax.curly[pos].type == TYPE_IF) {
const char *bp = p;
const char *p2;
+
+ // if-block and else-block end is a new line
+ parse_nextline(false, p);
+
// if 最終場所へ飛ばす
sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
syntax.curly[syntax.curly_count++].type = TYPE_NULL;
@@ -1766,6 +1798,10 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
if(*p != '(') {
disp_error_message("need '('",p);
}
+
+ // do-block end is a new line
+ parse_nextline(false, p);
+
sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
add_scriptl(add_str("jump_zero"));
add_scriptc(C_ARG);
@@ -1793,6 +1829,9 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
syntax.curly_count--;
return p;
} else if(syntax.curly[pos].type == TYPE_FOR) {
+ // for-block end is a new line
+ parse_nextline(false, p);
+
// 次のループに飛ばす
sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
syntax.curly[syntax.curly_count++].type = TYPE_NULL;
@@ -1806,6 +1845,9 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
syntax.curly_count--;
return p;
} else if(syntax.curly[pos].type == TYPE_WHILE) {
+ // while-block end is a new line
+ parse_nextline(false, p);
+
// while 条件判断へ飛ばす
sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
syntax.curly[syntax.curly_count++].type = TYPE_NULL;
@@ -1974,6 +2016,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
struct script_code* code = NULL;
static int first=1;
char end;
+ bool unresolved_names = false;
if( src == NULL )
return NULL;// empty script
@@ -1988,9 +2031,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
script_buf=(unsigned char *)aMalloc(SCRIPT_BLOCK_SIZE*sizeof(unsigned char));
script_pos=0;
script_size=SCRIPT_BLOCK_SIZE;
- str_data[LABEL_NEXTLINE].type=C_NOP;
- str_data[LABEL_NEXTLINE].backpatch=-1;
- str_data[LABEL_NEXTLINE].label=-1;
+ parse_nextline(true, NULL);
// who called parse_script is responsible for clearing the database after using it, but just in case... lets clear it here
if( options&SCRIPT_USE_LABEL_DB )
@@ -2077,12 +2118,8 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
// 他は全部一緒くた
p=parse_line(p);
p=skip_space(p);
- add_scriptc(C_EOL);
- set_label(LABEL_NEXTLINE,script_pos,p);
- str_data[LABEL_NEXTLINE].type=C_NOP;
- str_data[LABEL_NEXTLINE].backpatch=-1;
- str_data[LABEL_NEXTLINE].label=-1;
+ parse_nextline(false, p);
}
add_scriptc(C_NOP);
@@ -2103,13 +2140,23 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
j=next;
}
}
+ else if( str_data[i].type == C_USERFUNC )
+ {// 'function name;' without follow-up code
+ ShowError("parse_script: function '%s' declared but not defined.\n", str_buf+str_data[i].str);
+ unresolved_names = true;
+ }
+ }
+
+ if( unresolved_names )
+ {
+ disp_error_message("parse_script: unresolved function references", p);
}
#ifdef DEBUG_DISP
for(i=0;i<script_pos;i++){
- if((i&15)==0) printf("%04x : ",i);
+ if((i&15)==0) ShowMessage("%04x : ",i);
ShowMessage("%02x ",script_buf[i]);
- if((i&15)==15) printf("\n");
+ if((i&15)==15) ShowMessage("\n");
}
ShowMessage("\n");
#endif
@@ -3235,7 +3282,7 @@ int run_script_timer(int tid, unsigned int tick, int id, intptr data)
st->rid = 0;
st->state = END;
}
- while( node && st->sleep.timer != -1 ) {
+ while( node && st->sleep.timer != INVALID_TIMER ) {
if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
script_erase_sleepdb(node);
st->sleep.timer = INVALID_TIMER;
@@ -4882,8 +4929,8 @@ BUILDIN_FUNC(setarray)
}
end = start + script_lastdata(st) - 2;
- if( end >= SCRIPT_MAX_ARRAYSIZE )
- end = SCRIPT_MAX_ARRAYSIZE-1;
+ if( end > SCRIPT_MAX_ARRAYSIZE )
+ end = SCRIPT_MAX_ARRAYSIZE;
if( is_string_variable(name) )
{// string array
@@ -4945,10 +4992,10 @@ BUILDIN_FUNC(cleararray)
v = (void*)script_getnum(st, 3);
end = start + script_getnum(st, 4);
- if( end >= SCRIPT_MAX_ARRAYSIZE )
- end = SCRIPT_MAX_ARRAYSIZE-1;
+ if( end > SCRIPT_MAX_ARRAYSIZE )
+ end = SCRIPT_MAX_ARRAYSIZE;
- for( ; start <= end; ++start )
+ for( ; start < end; ++start )
set_reg(st, sd, reference_uid(id, start), name, v, script_getref(st,2));
return 0;
}
@@ -5015,8 +5062,8 @@ BUILDIN_FUNC(copyarray)
}
count = script_getnum(st, 4);
- if( count >= SCRIPT_MAX_ARRAYSIZE - idx1 )
- count = (SCRIPT_MAX_ARRAYSIZE-1) - idx1;
+ if( count > SCRIPT_MAX_ARRAYSIZE - idx1 )
+ count = SCRIPT_MAX_ARRAYSIZE - idx1;
if( count <= 0 || (id1 == id2 && idx1 == idx2) )
return 0;// nothing to copy
@@ -5121,7 +5168,8 @@ BUILDIN_FUNC(deletearray)
return 0;// no player attached
}
- end = getarraysize(st, id, start, is_string_variable(name), reference_getref(data));
+ end = SCRIPT_MAX_ARRAYSIZE;
+
if( start >= end )
return 0;// nothing to free
@@ -6191,7 +6239,7 @@ BUILDIN_FUNC(readparam)
if( script_hasdata(st,3) )
sd=map_nick2sd(script_getstr(st,3));
else
- sd=script_rid2sd(st);
+ sd=script_rid2sd(st);
if(sd==NULL){
script_pushint(st,-1);
@@ -8321,10 +8369,10 @@ BUILDIN_FUNC(getnpctimer)
ShowError("buildin_getnpctimer: Attached player not found!\n");
break;
}
- val = (sd->npc_timer_id != -1);
+ val = (sd->npc_timer_id != INVALID_TIMER);
}
else
- val = (nd->u.scr.timerid !=-1);
+ val = (nd->u.scr.timerid != INVALID_TIMER);
break;
case 2: val = nd->u.scr.timeramount; break;
}
@@ -9705,7 +9753,7 @@ BUILDIN_FUNC(pvpon)
iter = mapit_getallusers();
for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
{
- if( sd->bl.m != m || sd->pvp_timer != -1 )
+ if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER )
continue; // not applicable
sd->pvp_timer = add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
@@ -9724,7 +9772,7 @@ static int buildin_pvpoff_sub(struct block_list *bl,va_list ap)
{
TBL_PC* sd = (TBL_PC*)bl;
clif_pvpset(sd, 0, 0, 2);
- if (sd->pvp_timer != -1) {
+ if (sd->pvp_timer != INVALID_TIMER) {
delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
sd->pvp_timer = INVALID_TIMER;
}
@@ -10809,7 +10857,7 @@ BUILDIN_FUNC(petskillbonus)
pd=sd->pd;
if (pd->bonus)
{ //Clear previous bonus
- if (pd->bonus->timer != -1)
+ if (pd->bonus->timer != INVALID_TIMER)
delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
} else //init
pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
@@ -11162,7 +11210,7 @@ BUILDIN_FUNC(petrecovery)
if (pd->recovery)
{ //Halt previous bonus
- if (pd->recovery->timer != -1)
+ if (pd->recovery->timer != INVALID_TIMER)
delete_timer(pd->recovery->timer, pet_recovery_timer);
} else //Init
pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
@@ -11188,7 +11236,7 @@ BUILDIN_FUNC(petheal)
pd=sd->pd;
if (pd->s_skill)
{ //Clear previous skill
- if (pd->s_skill->timer != -1)
+ if (pd->s_skill->timer != INVALID_TIMER)
{
if (pd->s_skill->id)
delete_timer(pd->s_skill->timer, pet_skill_support_timer);
@@ -11282,7 +11330,7 @@ BUILDIN_FUNC(petskillsupport)
pd=sd->pd;
if (pd->s_skill)
{ //Clear previous skill
- if (pd->s_skill->timer != -1)
+ if (pd->s_skill->timer != INVALID_TIMER)
{
if (pd->s_skill->id)
delete_timer(pd->s_skill->timer, pet_skill_support_timer);
@@ -11636,9 +11684,6 @@ BUILDIN_FUNC(jump_zero)
pos=script_getnum(st,3);
st->pos=pos;
st->state=GOTO;
- // printf("script: jump_zero: jumpto : %d\n",pos);
- } else {
- // printf("script: jump_zero: fail\n");
}
return 0;
}
@@ -12312,7 +12357,7 @@ BUILDIN_FUNC(autoequip)
struct item_data *item_data;
nameid=script_getnum(st,2);
flag=script_getnum(st,3);
- if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
+ if(nameid>=500 && (item_data = itemdb_exists(nameid)) != NULL){
item_data->flag.autoequip = flag>0?1:0;
}
return 0;
@@ -12362,7 +12407,7 @@ BUILDIN_FUNC(charisalpha)
const char *str=script_getstr(st,2);
int pos=script_getnum(st,3);
- int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISALPHA( str[pos] ) : 0;
+ int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISALPHA( str[pos] ) != 0 : 0;
script_pushint(st,val);
return 0;
@@ -13557,7 +13602,7 @@ BUILDIN_FUNC(awake)
struct script_state* tst = (struct script_state*)node->data;
TBL_PC* sd = map_id2sd(tst->rid);
- if( tst->sleep.timer == -1 )
+ if( tst->sleep.timer == INVALID_TIMER )
{// already awake ???
node = node->next;
continue;
@@ -14590,7 +14635,7 @@ static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
if( md->class_ != mobid )
return 0;
- if( md->ud.skilltimer != -1 ) // Cancel the casting skill.
+ if( md->ud.skilltimer != INVALID_TIMER ) // Cancel the casting skill.
unit_skillcastcancel(bl,0);
// 0:self, 1:target, 2:master, default:random
diff --git a/src/map/skill.c b/src/map/skill.c
index 6b63c2b83..cd9115df4 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -611,7 +611,7 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, int
rate = 20;
if (sc->data[SC_SKILLRATE_UP] && sc->data[SC_SKILLRATE_UP]->val1 == TK_COUNTER) {
rate += rate*sc->data[SC_SKILLRATE_UP]->val2/100;
- status_change_end(src,SC_SKILLRATE_UP,-1);
+ status_change_end(src, SC_SKILLRATE_UP, INVALID_TIMER);
}
sc_start4(src,SC_COMBO, rate, TK_COUNTER, bl->id,0,0,
(2000 - 4*sstatus->agi - 2*sstatus->dex));
@@ -883,12 +883,12 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, int
case TK_JUMPKICK:
if( dstsd && dstsd->class_ != MAPID_SOUL_LINKER && !tsc->data[SC_PRESERVE] )
{// debuff the following statuses
- status_change_end(bl, SC_SPIRIT, -1);
- status_change_end(bl, SC_ADRENALINE2, -1);
- status_change_end(bl, SC_KAITE, -1);
- status_change_end(bl, SC_KAAHI, -1);
- status_change_end(bl, SC_ONEHAND, -1);
- status_change_end(bl, SC_ASPDPOTION2, -1);
+ status_change_end(bl, SC_SPIRIT, INVALID_TIMER);
+ status_change_end(bl, SC_ADRENALINE2, INVALID_TIMER);
+ status_change_end(bl, SC_KAITE, INVALID_TIMER);
+ status_change_end(bl, SC_KAAHI, INVALID_TIMER);
+ status_change_end(bl, SC_ONEHAND, INVALID_TIMER);
+ status_change_end(bl, SC_ASPDPOTION2, INVALID_TIMER);
}
break;
case TK_TURNKICK:
@@ -1544,7 +1544,7 @@ static int skill_magic_reflect(struct block_list* src, struct block_list* bl, in
{// Kaite only works against non-players if they are low-level.
clif_specialeffect(bl, 438, AREA);
if( --sc->data[SC_KAITE]->val2 <= 0 )
- status_change_end(bl, SC_KAITE, -1);
+ status_change_end(bl, SC_KAITE, INVALID_TIMER);
return 2;
}
@@ -1719,7 +1719,7 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds
break;
default:
if( src == dsrc ) // Ground skills are exceptions. [Inkfish]
- status_change_end(src,SC_COMBO,-1);
+ status_change_end(src, SC_COMBO, INVALID_TIMER);
}
}
switch(skillid)
@@ -1904,7 +1904,7 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds
status_fix_damage(NULL, d_bl, damage, 0);
}
else
- status_change_end(bl, SC_DEVOTION, -1);
+ status_change_end(bl, SC_DEVOTION, INVALID_TIMER);
}
if(skillid == RG_INTIMIDATE && damage > 0 && !(tstatus->mode&MD_BOSS)) {
@@ -2338,8 +2338,7 @@ static int skill_timerskill(int tid, unsigned int tick, int id, intptr data)
} else {
struct status_change *sc = status_get_sc(src);
if(sc) {
- if(sc->data[SC_MAGICPOWER])
- status_change_end(src,SC_MAGICPOWER,-1);
+ status_change_end(src, SC_MAGICPOWER, INVALID_TIMER);
if(sc->data[SC_SPIRIT] &&
sc->data[SC_SPIRIT]->val2 == SL_WIZARD &&
sc->data[SC_SPIRIT]->val3 == skl->skill_id)
@@ -2469,7 +2468,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, int
{ //GTB makes all targetted magic display miss with a single bolt.
sc_type sct = status_skill2sc(skillid);
if(sct != SC_NONE)
- status_change_end(bl, sct, -1);
+ status_change_end(bl, sct, INVALID_TIMER);
clif_skill_damage(src, bl, tick, status_get_amotion(src), status_get_dmotion(bl), 0, 1, skillid, skilllv, skill_get_hit(skillid));
return 1;
}
@@ -2662,16 +2661,14 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, int
case MO_INVESTIGATE:
skill_attack(BF_WEAPON,src,src,bl,skillid,skilllv,tick,flag);
- if (sc && sc->data[SC_BLADESTOP])
- status_change_end(src,SC_BLADESTOP,-1);
+ status_change_end(src, SC_BLADESTOP, INVALID_TIMER);
break;
case RG_BACKSTAP:
{
int dir = map_calc_dir(src, bl->x, bl->y), t_dir = unit_getdir(bl);
if ((!check_distance_bl(src, bl, 0) && !map_check_dir(dir, t_dir)) || bl->type == BL_SKILL) {
- if (sc && sc->data[SC_HIDING])
- status_change_end(src, SC_HIDING, -1);
+ status_change_end(src, SC_HIDING, INVALID_TIMER);
skill_attack(BF_WEAPON, src, src, bl, skillid, skilllv, tick, flag);
dir = dir < 4 ? dir+4 : dir-4; // change direction [Celest]
unit_setdir(bl,dir);
@@ -2688,25 +2685,23 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, int
for (i = 1; i < sd->spiritball_old; i++)
skill_addtimerskill(src, tick + i * 200, bl->id, 0, 0, skillid, skilllv, BF_WEAPON, flag);
}
- if (sc && sc->data[SC_BLADESTOP])
- status_change_end(src,SC_BLADESTOP,-1);
+ status_change_end(src, SC_BLADESTOP, INVALID_TIMER);
break;
case MO_CHAINCOMBO:
skill_attack(BF_WEAPON,src,src,bl,skillid,skilllv,tick,flag);
- if (sc && sc->data[SC_BLADESTOP])
- status_change_end(src,SC_BLADESTOP,-1);
+ status_change_end(src, SC_BLADESTOP, INVALID_TIMER);
break;
case NJ_ISSEN:
- status_change_end(src,SC_NEN,-1);
- status_change_end(src,SC_HIDING,-1);
+ status_change_end(src, SC_NEN, INVALID_TIMER);
+ status_change_end(src, SC_HIDING, INVALID_TIMER);
// fall through
case MO_EXTREMITYFIST:
if( skillid == MO_EXTREMITYFIST )
{
- status_change_end(src,SC_EXPLOSIONSPIRITS,-1);
- status_change_end(src,SC_BLADESTOP,-1);
+ status_change_end(src, SC_EXPLOSIONSPIRITS, INVALID_TIMER);
+ status_change_end(src, SC_BLADESTOP, INVALID_TIMER);
}
//Client expects you to move to target regardless of distance
{
@@ -2991,8 +2986,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, int
break;
case SL_SMA:
- if (sc && sc->data[SC_SMA])
- status_change_end(src,SC_SMA,-1);
+ status_change_end(src, SC_SMA, INVALID_TIMER);
case SL_STIN:
case SL_STUN:
if (sd && !battle_config.allow_es_magic_pc && bl->type != BL_MOB) {
@@ -3065,8 +3059,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, int
if (unit_movepos(src, x, y, 0, 0))
clif_slide(src,src->x,src->y);
}
- if (sc && sc->data[SC_HIDING])
- status_change_end(src, SC_HIDING, -1);
+ status_change_end(src, SC_HIDING, INVALID_TIMER);
skill_attack(BF_WEAPON,src,src,bl,skillid,skilllv,tick,flag);
break;
case 0:
@@ -3208,7 +3201,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
if( tsc->data[SC_KAITE] && !(sstatus->mode&MD_BOSS) )
{ //Bounce back heal
if (--tsc->data[SC_KAITE]->val2 <= 0)
- status_change_end(bl, SC_KAITE, -1);
+ status_change_end(bl, SC_KAITE, INVALID_TIMER);
if (src == bl)
heal=0; //When you try to heal yourself under Kaite, the heal is voided.
else {
@@ -3327,7 +3320,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case PR_LEXDIVINA:
case MER_LEXDIVINA:
if( tsce )
- status_change_end(bl,type, -1);
+ status_change_end(bl,type, INVALID_TIMER);
else
sc_start(bl,type,100,skilllv,skill_get_time(skillid,skilllv));
clif_skill_nodamage (src, bl, skillid, skilllv, 1);
@@ -3441,9 +3434,9 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
{
const enum sc_type scs[] = { SC_QUAGMIRE, SC_PROVOKE, SC_ROKISWEIL, SC_GRAVITATION, SC_SUITON, SC_STRIPWEAPON, SC_STRIPSHIELD, SC_STRIPARMOR, SC_STRIPHELM, SC_BLADESTOP };
for (i = SC_COMMON_MIN; i <= SC_COMMON_MAX; i++)
- if (tsc->data[i]) status_change_end(bl, (sc_type)i, -1);
+ if (tsc->data[i]) status_change_end(bl, (sc_type)i, INVALID_TIMER);
for (i = 0; i < ARRAYLENGTH(scs); i++)
- if (tsc->data[scs[i]]) status_change_end(bl, scs[i], -1);
+ if (tsc->data[scs[i]]) status_change_end(bl, scs[i], INVALID_TIMER);
}
}
break;
@@ -3508,8 +3501,8 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
if( sc->data[SC_MARIONETTE ] && sc->data[SC_MARIONETTE ]->val1 == bl->id &&
tsc->data[SC_MARIONETTE2] && tsc->data[SC_MARIONETTE2]->val1 == src->id )
{
- status_change_end(src, SC_MARIONETTE, -1);
- status_change_end(bl, SC_MARIONETTE2, -1);
+ status_change_end(src, SC_MARIONETTE, INVALID_TIMER);
+ status_change_end(bl, SC_MARIONETTE2, INVALID_TIMER);
}
else
{
@@ -3698,8 +3691,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case NJ_BUNSINJYUTSU:
clif_skill_nodamage(src,bl,skillid,skilllv,
sc_start(bl,type,100,skilllv,skill_get_time(skillid,skilllv)));
- if (tsc && tsc->data[SC_NEN])
- status_change_end(bl,SC_NEN,-1);
+ status_change_end(bl, SC_NEN, INVALID_TIMER);
break;
/* Was modified to only affect targetted char. [Skotlex]
case HP_ASSUMPTIO:
@@ -3804,12 +3796,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
if( tsc && tsc->count )
{
- if( tsc->data[SC_FREEZE] )
- status_change_end(bl,SC_FREEZE,-1);
+ status_change_end(bl, SC_FREEZE, INVALID_TIMER);
if( tsc->data[SC_STONE] && tsc->opt1 == OPT1_STONE )
- status_change_end(bl,SC_STONE,-1);
- if( tsc->data[SC_SLEEP] )
- status_change_end(bl,SC_SLEEP,-1);
+ status_change_end(bl, SC_STONE, INVALID_TIMER);
+ status_change_end(bl, SC_SLEEP, INVALID_TIMER);
}
if( dstmd )
@@ -3947,7 +3937,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
skill_get_splash(skillid, skilllv), splash_target(src),
src,skillid,skilllv,tick, flag|BCT_ENEMY|1,
skill_castend_damage_id);
- status_change_end(src, SC_HIDING, -1);
+ status_change_end(src, SC_HIDING, INVALID_TIMER);
break;
case ASC_METEORASSAULT:
@@ -4016,7 +4006,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case WZ_SIGHTRASHER:
//Passive side of the attack.
- status_change_end(src,SC_SIGHT,-1);
+ status_change_end(src, SC_SIGHT, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
map_foreachinrange(skill_area_sub,src,
skill_get_splash(skillid, skilllv),BL_CHAR|BL_SKILL,
@@ -4104,7 +4094,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case GS_GATLINGFEVER:
if( tsce )
{
- clif_skill_nodamage(src,bl,skillid,skilllv,status_change_end(bl, type, -1));
+ clif_skill_nodamage(src,bl,skillid,skilllv,status_change_end(bl, type, INVALID_TIMER));
map_freeblock_unlock();
return 0;
}
@@ -4133,7 +4123,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case SM_AUTOBERSERK:
case MER_AUTOBERSERK:
if( tsce )
- i = status_change_end(bl, type, -1);
+ i = status_change_end(bl, type, INVALID_TIMER);
else
i = sc_start(bl,type,100,skilllv,60000);
clif_skill_nodamage(src,bl,skillid,skilllv,i);
@@ -4142,7 +4132,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case ST_CHASEWALK:
if (tsce)
{
- clif_skill_nodamage(src,bl,skillid,-1,status_change_end(bl, type, -1)); //Hide skill-scream animation.
+ clif_skill_nodamage(src,bl,skillid,-1,status_change_end(bl, type, INVALID_TIMER)); //Hide skill-scream animation.
map_freeblock_unlock();
return 0;
}
@@ -4151,7 +4141,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case TK_RUN:
if (tsce)
{
- clif_skill_nodamage(src,bl,skillid,skilllv,status_change_end(bl, type, -1));
+ clif_skill_nodamage(src,bl,skillid,skilllv,status_change_end(bl, type, INVALID_TIMER));
map_freeblock_unlock();
return 0;
}
@@ -4162,7 +4152,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case AS_CLOAKING:
if (tsce)
{
- i = status_change_end(bl, type, -1);
+ i = status_change_end(bl, type, INVALID_TIMER);
if( i )
clif_skill_nodamage(src,bl,skillid,-1,i);
else if( sd )
@@ -4180,7 +4170,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case BD_ADAPTATION:
if(tsc && tsc->data[SC_DANCING]){
clif_skill_nodamage(src,bl,skillid,skilllv,1);
- status_change_end(bl, SC_DANCING, -1);
+ status_change_end(bl, SC_DANCING, INVALID_TIMER);
}
break;
@@ -4253,7 +4243,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
break;
if (tsc->data[SC_STONE]) {
- status_change_end(bl,SC_STONE,-1);
+ status_change_end(bl, SC_STONE, INVALID_TIMER);
if (sd) clif_skill_fail(sd,skillid,0,0);
break;
}
@@ -4283,16 +4273,16 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
clif_skill_nodamage(src,bl,skillid,skilllv,0);
break;
}
- status_change_end(bl, SC_SILENCE , -1 );
- status_change_end(bl, SC_BLIND , -1 );
- status_change_end(bl, SC_CONFUSION, -1 );
+ status_change_end(bl, SC_SILENCE, INVALID_TIMER);
+ status_change_end(bl, SC_BLIND, INVALID_TIMER);
+ status_change_end(bl, SC_CONFUSION, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
break;
case TF_DETOXIFY:
clif_skill_nodamage(src,bl,skillid,skilllv,1);
- status_change_end(bl, SC_POISON , -1 );
- status_change_end(bl, SC_DPOISON , -1 );
+ status_change_end(bl, SC_POISON, INVALID_TIMER);
+ status_change_end(bl, SC_DPOISON, INVALID_TIMER);
break;
case PR_STRECOVERY:
@@ -4301,10 +4291,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
break;
}
if (tsc && tsc->opt1) {
- status_change_end(bl, SC_FREEZE, -1 );
- status_change_end(bl, SC_STONE, -1 );
- status_change_end(bl, SC_SLEEP, -1 );
- status_change_end(bl, SC_STUN, -1 );
+ status_change_end(bl, SC_FREEZE, INVALID_TIMER);
+ status_change_end(bl, SC_STONE, INVALID_TIMER);
+ status_change_end(bl, SC_SLEEP, INVALID_TIMER);
+ status_change_end(bl, SC_STUN, INVALID_TIMER);
}
//Is this equation really right? It looks so... special.
if(battle_check_undead(tstatus->race,tstatus->def_ele))
@@ -4321,31 +4311,31 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
// Mercenary Supportive Skills
case MER_BENEDICTION:
- status_change_end(bl, SC_CURSE, -1);
- status_change_end(bl, SC_BLIND, -1);
+ status_change_end(bl, SC_CURSE, INVALID_TIMER);
+ status_change_end(bl, SC_BLIND, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
break;
case MER_COMPRESS:
- status_change_end(bl, SC_BLEEDING, -1);
+ status_change_end(bl, SC_BLEEDING, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
break;
case MER_MENTALCURE:
- status_change_end(bl, SC_CONFUSION, -1);
+ status_change_end(bl, SC_CONFUSION, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
break;
case MER_RECUPERATE:
- status_change_end(bl, SC_POISON, -1);
- status_change_end(bl, SC_SILENCE, -1);
+ status_change_end(bl, SC_POISON, INVALID_TIMER);
+ status_change_end(bl, SC_SILENCE, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
break;
case MER_REGAIN:
- status_change_end(bl, SC_SLEEP, -1);
- status_change_end(bl, SC_STUN, -1);
+ status_change_end(bl, SC_SLEEP, INVALID_TIMER);
+ status_change_end(bl, SC_STUN, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
break;
case MER_TENDER:
- status_change_end(bl, SC_FREEZE, -1);
- status_change_end(bl, SC_STONE, -1);
+ status_change_end(bl, SC_FREEZE, INVALID_TIMER);
+ status_change_end(bl, SC_STONE, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,1);
break;
@@ -4642,8 +4632,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
case AM_CP_HELM:
{
enum sc_type scid = (sc_type)(SC_STRIPWEAPON + (skillid - AM_CP_WEAPON));
- if(tsc && tsc->data[scid])
- status_change_end(bl, scid, -1 );
+ status_change_end(bl, scid, INVALID_TIMER);
clif_skill_nodamage(src,bl,skillid,skilllv,
sc_start(bl,type,100,skilllv,skill_get_time(skillid,skilllv)));
}
@@ -4735,7 +4724,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
break;
}
if(i==SC_BERSERK) tsc->data[i]->val2=0; //Mark a dispelled berserk to avoid setting hp to 100 by setting hp penalty to 0.
- status_change_end(bl,(sc_type)i,-1);
+ status_change_end(bl, (sc_type)i, INVALID_TIMER);
}
break;
}
@@ -4796,7 +4785,8 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
} else {
struct unit_data *ud = unit_bl2ud(bl);
int bl_skillid=0,bl_skilllv=0,hp = 0;
- if (!ud || ud->skilltimer == -1) break; //Nothing to cancel.
+ if (!ud || ud->skilltimer == INVALID_TIMER)
+ break; //Nothing to cancel.
bl_skillid = ud->skillid;
bl_skilllv = ud->skilllv;
if (tstatus->mode & MD_BOSS)
@@ -5021,7 +5011,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
{
clif_emotion(bl, md->db->skill[md->skillidx].val[0]);
if(md->db->skill[md->skillidx].val[4] && tsce)
- status_change_end(bl, type, -1);
+ status_change_end(bl, type, INVALID_TIMER);
if(md->db->skill[md->skillidx].val[1] || md->db->skill[md->skillidx].val[2])
sc_start4(src, type, 100, skilllv,
@@ -5225,12 +5215,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
unit_skillcastcancel(bl,0);
if(tsc && tsc->count){
- if(tsc->data[SC_FREEZE])
- status_change_end(bl,SC_FREEZE,-1);
+ status_change_end(bl, SC_FREEZE, INVALID_TIMER);
if(tsc->data[SC_STONE] && tsc->opt1 == OPT1_STONE)
- status_change_end(bl,SC_STONE,-1);
- if(tsc->data[SC_SLEEP])
- status_change_end(bl,SC_SLEEP,-1);
+ status_change_end(bl, SC_STONE, INVALID_TIMER);
+ status_change_end(bl, SC_SLEEP, INVALID_TIMER);
}
if(dstmd)
@@ -5297,8 +5285,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
break;
}
for (i=0; i<4; i++) {
- if(tsc->data[SC_STRIPWEAPON + i])
- status_change_end(bl, (sc_type)(SC_STRIPWEAPON + i), -1 );
+ status_change_end(bl, (sc_type)(SC_STRIPWEAPON + i), INVALID_TIMER);
sc_start(bl,(sc_type)(SC_CP_WEAPON + i),100,skilllv,skilltime);
}
clif_skill_nodamage(src,bl,skillid,skilllv,1);
@@ -5771,7 +5758,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr data)
return 0;
}
- if( sd && ud->skilltimer != -1 && pc_checkskill(sd,SA_FREECAST) > 0 )
+ if( sd && ud->skilltimer != INVALID_TIMER && pc_checkskill(sd,SA_FREECAST) > 0 )
{// restore original walk speed
ud->skilltimer = INVALID_TIMER;
status_calc_bl(&sd->bl, SCB_SPEED);
@@ -5875,7 +5862,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr data)
}
//Avoid doing double checks for instant-cast skills.
- if (tid != -1 && !status_check_skilluse(src, target, ud->skillid, 1))
+ if (tid != INVALID_TIMER && !status_check_skilluse(src, target, ud->skillid, 1))
break;
if(md) {
@@ -5909,7 +5896,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr data)
if (ud->state.running && ud->skillid == TK_JUMPKICK)
flag = 1;
- if (ud->walktimer != -1 && ud->skillid != TK_RUN)
+ if (ud->walktimer != INVALID_TIMER && ud->skillid != TK_RUN)
unit_stop_walking(src,1);
if( !sd || sd->skillitem != ud->skillid || skill_get_delay(ud->skillid,ud->skilllv) )
@@ -5952,7 +5939,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr data)
if(sc && sc->count) {
if(sc->data[SC_MAGICPOWER] &&
ud->skillid != HW_MAGICPOWER && ud->skillid != WZ_WATERBALL)
- status_change_end(src,SC_MAGICPOWER,-1);
+ status_change_end(src, SC_MAGICPOWER, INVALID_TIMER);
if(sc->data[SC_SPIRIT] &&
sc->data[SC_SPIRIT]->val2 == SL_WIZARD &&
sc->data[SC_SPIRIT]->val3 == ud->skillid &&
@@ -5966,7 +5953,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr data)
if( sd && ud->skillid != SA_ABRACADABRA ) // Hocus-Pocus has just set the data so leave it as it is.[Inkfish]
sd->skillitem = sd->skillitemlv = 0;
- if (ud->skilltimer == -1) {
+ if (ud->skilltimer == INVALID_TIMER) {
if(md) md->skillidx = -1;
else ud->skillid = 0; //mobs can't clear this one as it is used for skill condition 'afterskill'
ud->skilllv = ud->skilltarget = 0;
@@ -5984,10 +5971,8 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr data)
sc = &sd->sc;
if (sc->count)
{ //End states
- if (sc->data[SC_EXPLOSIONSPIRITS])
- status_change_end(src, SC_EXPLOSIONSPIRITS, -1);
- if (sc->data[SC_BLADESTOP])
- status_change_end(src,SC_BLADESTOP,-1);
+ status_change_end(src, SC_EXPLOSIONSPIRITS, INVALID_TIMER);
+ status_change_end(src, SC_BLADESTOP, INVALID_TIMER);
}
if (target && target->m == src->m)
{ //Move character to target anyway.
@@ -6049,7 +6034,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr data)
return 0;
}
- if( sd && ud->skilltimer != -1 && pc_checkskill(sd,SA_FREECAST) > 0 )
+ if( sd && ud->skilltimer != INVALID_TIMER && pc_checkskill(sd,SA_FREECAST) > 0 )
{// restore original walk speed
ud->skilltimer = INVALID_TIMER;
status_calc_bl(&sd->bl, SCB_SPEED);
@@ -6091,7 +6076,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr data)
}
}
- if(tid != -1)
+ if(tid != INVALID_TIMER)
{ //Avoid double checks on instant cast skills. [Skotlex]
if (!status_check_skilluse(src, NULL, ud->skillid, 1))
break;
@@ -6124,7 +6109,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr data)
ShowInfo("Type %d, ID %d skill castend pos [id =%d, lv=%d, (%d,%d)]\n",
src->type, src->id, ud->skillid, ud->skilllv, ud->skillx, ud->skilly);
- if (ud->walktimer != -1)
+ if (ud->walktimer != INVALID_TIMER)
unit_stop_walking(src,1);
if( !sd || sd->skillitem != ud->skillid || skill_get_delay(ud->skillid,ud->skilllv) )
@@ -6148,7 +6133,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr data)
if( sd && sd->skillitem != AL_WARP ) // Warp-Portal thru items will clear data in skill_castend_map. [Inkfish]
sd->skillitem = sd->skillitemlv = 0;
- if (ud->skilltimer == -1) {
+ if (ud->skilltimer == INVALID_TIMER) {
if (md) md->skillidx = -1;
else ud->skillid = 0; //Non mobs can't clear this one as it is used for skill condition 'afterskill'
ud->skilllv = ud->skillx = ud->skilly = 0;
@@ -6335,7 +6320,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk
break;
case HP_BASILICA:
if( sc->data[SC_BASILICA] )
- status_change_end(src, SC_BASILICA, -1); // Cancel Basilica
+ status_change_end(src, SC_BASILICA, INVALID_TIMER); // Cancel Basilica
else
{ // Create Basilica. Start SC on caster. Unit timer start SC on others.
skill_clear_unitgroup(src);
@@ -6408,8 +6393,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk
unit_movepos(src, x, y, 1, 0);
clif_slide(src,x,y);
}
- if (sc && sc->data[SC_HIDING])
- status_change_end(src, SC_HIDING, -1);
+ status_change_end(src, SC_HIDING, INVALID_TIMER);
break;
case AM_SPHEREMINE:
case AM_CANNIBALIZE:
@@ -6544,7 +6528,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk
case PA_GOSPEL:
if (sce && sce->val4 == BCT_SELF)
{
- status_change_end(src,SC_GOSPEL,-1);
+ status_change_end(src, SC_GOSPEL, INVALID_TIMER);
return 0;
}
else
@@ -6552,7 +6536,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk
sg = skill_unitsetting(src,skillid,skilllv,src->x,src->y,0);
if (!sg) break;
if (sce)
- status_change_end(src,type,-1); //Was under someone else's Gospel. [Skotlex]
+ status_change_end(src, type, INVALID_TIMER); //Was under someone else's Gospel. [Skotlex]
sc_start4(src,type,100,skilllv,0,sg->group_id,BCT_SELF,skill_get_time(skillid,skilllv));
clif_skill_poseffect(src, skillid, skilllv, 0, 0, tick); // PA_GOSPEL music packet
}
@@ -6578,8 +6562,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk
return 1;
}
- if (sc && sc->data[SC_MAGICPOWER])
- status_change_end(src,SC_MAGICPOWER,-1);
+ status_change_end(src, SC_MAGICPOWER, INVALID_TIMER);
if( sd )
{
@@ -7807,17 +7790,17 @@ int skill_unit_onout (struct skill_unit *src, struct block_list *bl, unsigned in
case UNT_SAFETYWALL:
case UNT_PNEUMA:
if (sce)
- status_change_end(bl,type,-1);
+ status_change_end(bl, type, INVALID_TIMER);
break;
case UNT_BASILICA:
if( sce && sce->val4 == src->bl.id )
- status_change_end(bl,type,-1);
+ status_change_end(bl, type, INVALID_TIMER);
break;
case UNT_HERMODE: //Clear Hermode if the owner moved.
if (sce && sce->val3 == BCT_SELF && sce->val4 == sg->group_id)
- status_change_end(bl,type,-1);
+ status_change_end(bl, type, INVALID_TIMER);
break;
case UNT_SPIDERWEB:
@@ -7826,7 +7809,7 @@ int skill_unit_onout (struct skill_unit *src, struct block_list *bl, unsigned in
if (target && target==bl)
{
if (sce && sce->val3 == sg->group_id)
- status_change_end(bl,type,-1);
+ status_change_end(bl, type, INVALID_TIMER);
sg->limit = DIFF_TICK(tick,sg->tick)+1000;
}
break;
@@ -7857,7 +7840,7 @@ static int skill_unit_onleft (int skill_id, struct block_list *bl, unsigned int
if (bl->type==BL_MOB)
break;
if (sce)
- status_change_end(bl, type, -1);
+ status_change_end(bl, type, INVALID_TIMER);
break;
case BD_LULLABY:
@@ -7875,7 +7858,7 @@ static int skill_unit_onleft (int skill_id, struct block_list *bl, unsigned int
//it only checks if you are doing the same ensemble. So if there's two chars doing an ensemble
//which overlaps, by stepping outside of the other parther's ensemble will cause you to cancel
//your own. Let's pray that scenario is pretty unlikely and noone will complain too much about it.
- status_change_end(bl, SC_DANCING, -1);
+ status_change_end(bl, SC_DANCING, INVALID_TIMER);
}
case MG_SAFETYWALL:
case AL_PNEUMA:
@@ -7886,7 +7869,7 @@ static int skill_unit_onleft (int skill_id, struct block_list *bl, unsigned int
case HW_GRAVITATION:
case NJ_SUITON:
if (sce)
- status_change_end(bl, type, -1);
+ status_change_end(bl, type, INVALID_TIMER);
break;
case BA_POEMBRAGI:
@@ -7909,11 +7892,11 @@ static int skill_unit_onleft (int skill_id, struct block_list *bl, unsigned int
case PF_FOGWALL:
if (sce)
{
- status_change_end(bl,type,-1);
+ status_change_end(bl, type, INVALID_TIMER);
if ((sce=sc->data[SC_BLIND]))
{
if (bl->type == BL_PC) //Players get blind ended inmediately, others have it still for 30 secs. [Skotlex]
- status_change_end(bl, SC_BLIND, -1);
+ status_change_end(bl, SC_BLIND, INVALID_TIMER);
else {
delete_timer(sce->timer, status_change_timer);
sce->timer = add_timer(30000+tick, status_change_timer, bl->id, SC_BLIND);
@@ -8252,7 +8235,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, short skill, sh
switch( skill )
{
case SA_CASTCANCEL:
- if(sd->ud.skilltimer == -1) {
+ if(sd->ud.skilltimer == INVALID_TIMER) {
clif_skill_fail(sd,skill,0,0);
return 0;
}
@@ -8352,7 +8335,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, short skill, sh
if (pc_famerank(sd->status.char_id,MAPID_TAEKWON))
{ //Unlimited Combo
if (skill == sd->skillid_old) {
- status_change_end(&sd->bl, SC_COMBO, -1);
+ status_change_end(&sd->bl, SC_COMBO, INVALID_TIMER);
sd->skillid_old = sd->skilllv_old = 0;
return 0; //Can't repeat previous combo skill.
}
@@ -9046,12 +9029,12 @@ int skill_castfix_sc (struct block_list *bl, int time)
time += time * sc->data[SC_SLOWCAST]->val2 / 100;
if (sc->data[SC_SUFFRAGIUM]) {
time -= time * sc->data[SC_SUFFRAGIUM]->val2 / 100;
- status_change_end(bl, SC_SUFFRAGIUM, -1);
+ status_change_end(bl, SC_SUFFRAGIUM, INVALID_TIMER);
}
if (sc->data[SC_MEMORIZE]) {
time>>=1;
if ((--sc->data[SC_MEMORIZE]->val2) <= 0)
- status_change_end(bl, SC_MEMORIZE, -1);
+ status_change_end(bl, SC_MEMORIZE, INVALID_TIMER);
}
if (sc->data[SC_POEMBRAGI])
time -= time * sc->data[SC_POEMBRAGI]->val2 / 100;
@@ -9915,7 +9898,7 @@ int skill_enchant_elemental_end (struct block_list *bl, int type)
for (i = 0; i < ARRAYLENGTH(scs); i++)
if (type != scs[i] && sc->data[scs[i]])
- status_change_end(bl, scs[i], -1);
+ status_change_end(bl, scs[i], INVALID_TIMER);
return 0;
}
@@ -9940,7 +9923,7 @@ bool skill_check_cloaking(struct block_list *bl, struct status_change_entry *sce
if( !wall )
{
if( sce->val1 < 3 ) //End cloaking.
- status_change_end(bl, SC_CLOAKING, -1);
+ status_change_end(bl, SC_CLOAKING, INVALID_TIMER);
else
if( sce->val4&1 )
{ //Remove wall bonus
@@ -10039,7 +10022,7 @@ int skill_delunit (struct skill_unit* unit)
{
struct block_list* target = map_id2bl(group->val2);
if( target )
- status_change_end(target,SC_ANKLE,-1);
+ status_change_end(target, SC_ANKLE, INVALID_TIMER);
}
break;
case WZ_ICEWALL:
@@ -10185,7 +10168,7 @@ int skill_delunitgroup_(struct skill_unit_group *group, const char* file, int li
if (sc && sc->data[SC_DANCING])
{
sc->data[SC_DANCING]->val2 = 0 ; //This prevents status_change_end attempting to redelete the group. [Skotlex]
- status_change_end(src,SC_DANCING,-1);
+ status_change_end(src, SC_DANCING, INVALID_TIMER);
}
}
@@ -10195,7 +10178,7 @@ int skill_delunitgroup_(struct skill_unit_group *group, const char* file, int li
struct status_change *sc = status_get_sc(src);
if(sc && sc->data[SC_GOSPEL]) {
sc->data[SC_GOSPEL]->val3 = 0; //Remove reference to this group. [Skotlex]
- status_change_end(src,SC_GOSPEL,-1);
+ status_change_end(src, SC_GOSPEL, INVALID_TIMER);
}
}
@@ -10205,7 +10188,7 @@ int skill_delunitgroup_(struct skill_unit_group *group, const char* file, int li
struct status_change *sc = status_get_sc(src);
if(sc && sc->data[SC_WARM]) {
sc->data[SC_WARM]->val4 = 0;
- status_change_end(src,SC_WARM,-1);
+ status_change_end(src, SC_WARM, INVALID_TIMER);
}
}
diff --git a/src/map/status.c b/src/map/status.c
index 449ea8f56..45fe3a4cf 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -698,20 +698,20 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
if( sc ) {
struct status_change_entry *sce;
if (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE)
- status_change_end(target,SC_STONE,-1);
- status_change_end(target,SC_FREEZE,-1);
- status_change_end(target,SC_SLEEP,-1);
- status_change_end(target,SC_WINKCHARM,-1);
- status_change_end(target,SC_CONFUSION,-1);
- status_change_end(target,SC_TRICKDEAD,-1);
- status_change_end(target,SC_HIDING,-1);
- status_change_end(target,SC_CLOAKING,-1);
- status_change_end(target,SC_CHASEWALK,-1);
+ status_change_end(target, SC_STONE, INVALID_TIMER);
+ status_change_end(target, SC_FREEZE, INVALID_TIMER);
+ status_change_end(target, SC_SLEEP, INVALID_TIMER);
+ status_change_end(target, SC_WINKCHARM, INVALID_TIMER);
+ status_change_end(target, SC_CONFUSION, INVALID_TIMER);
+ status_change_end(target, SC_TRICKDEAD, INVALID_TIMER);
+ status_change_end(target, SC_HIDING, INVALID_TIMER);
+ status_change_end(target, SC_CLOAKING, INVALID_TIMER);
+ status_change_end(target, SC_CHASEWALK, INVALID_TIMER);
if ((sce=sc->data[SC_ENDURE]) && !sce->val4) {
//Endure count is only reduced by non-players on non-gvg maps.
//val4 signals infinite endure. [Skotlex]
if (src && src->type != BL_PC && !map_flag_gvg(target->m) && !map[target->m].flag.battleground && --(sce->val2) < 0)
- status_change_end(target, SC_ENDURE, -1);
+ status_change_end(target, SC_ENDURE, INVALID_TIMER);
}
if ((sce=sc->data[SC_GRAVITATION]) && sce->val3 == BCT_SELF)
{
@@ -719,11 +719,11 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
if (sg) {
skill_delunitgroup(sg);
sce->val4 = 0;
- status_change_end(target, SC_GRAVITATION, -1);
+ status_change_end(target, SC_GRAVITATION, INVALID_TIMER);
}
}
if(sc->data[SC_DANCING] && (unsigned int)hp > status->max_hp>>2)
- status_change_end(target, SC_DANCING, -1);
+ status_change_end(target, SC_DANCING, INVALID_TIMER);
}
unit_skillcastcancel(target, 2);
}
@@ -747,7 +747,7 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
status->hp < status->max_hp>>2)
sc_start4(target,SC_PROVOKE,100,10,1,0,0,0);
if (sc->data[SC_BERSERK] && status->hp <= 100)
- status_change_end(target, SC_BERSERK, -1);
+ status_change_end(target, SC_BERSERK, INVALID_TIMER);
}
switch (target->type)
@@ -899,7 +899,7 @@ int status_heal(struct block_list *bl,int hp,int sp, int flag)
sc->data[SC_PROVOKE]->val2==1 &&
status->hp>=status->max_hp>>2
) //End auto berserk.
- status_change_end(bl,SC_PROVOKE,-1);
+ status_change_end(bl, SC_PROVOKE, INVALID_TIMER);
// send hp update to client
switch(bl->type) {
@@ -2869,9 +2869,9 @@ void status_calc_bl_main(struct block_list *bl, enum scb_flag flag)
struct unit_data *ud = unit_bl2ud(bl);
status->speed = status_calc_speed(bl, sc, b_status->speed);
- //Re-walk to adjust speed (we do not check if walktimer != -1
+ //Re-walk to adjust speed (we do not check if walktimer != INVALID_TIMER
//because if you step on something while walking, the moment this
- //piece of code triggers the walk-timer is set on -1) [Skotlex]
+ //piece of code triggers the walk-timer is set on INVALID_TIMER) [Skotlex]
if (ud)
ud->state.change_walk_target = ud->state.speed_changed = 1;
@@ -3757,7 +3757,7 @@ static unsigned short status_calc_speed(struct block_list *bl, struct status_cha
if( sc == NULL )
return cap_value(speed,10,USHRT_MAX);
- if( sd && sd->ud.skilltimer != -1 && pc_checkskill(sd,SA_FREECAST) > 0 )
+ if( sd && sd->ud.skilltimer != INVALID_TIMER && pc_checkskill(sd,SA_FREECAST) > 0 )
{
speed_rate = 175 - 5 * pc_checkskill(sd,SA_FREECAST);
}
@@ -4213,7 +4213,7 @@ signed char status_get_def(struct block_list *bl)
struct status_data *status = status_get_status_data(bl);
int def = status?status->def:0;
ud = unit_bl2ud(bl);
- if (ud && ud->skilltimer != -1)
+ if (ud && ud->skilltimer != INVALID_TIMER)
def -= def * skill_get_castdef(ud->skillid)/100;
return cap_value(def, CHAR_MIN, CHAR_MAX);
}
@@ -4846,7 +4846,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
if (val3) mode|= val3; //Add mode
if (mode == bstatus->mode) { //No change.
if (sc->data[type]) //Abort previous status
- return status_change_end(bl, type, -1);
+ return status_change_end(bl, type, INVALID_TIMER);
return 0;
}
}
@@ -5001,133 +5001,132 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
//TO-DO Blessing and Agi up should do 1 damage against players on Undead Status, even on PvM
//but cannot be plagiarized (this requires aegis investigation on packets and official behavior) [Brainstorm]
if ((!undead_flag && status->race!=RC_DEMON) || bl->type == BL_PC) {
- if (sc->data[SC_CURSE])
- status_change_end(bl,SC_CURSE,-1);
+ status_change_end(bl, SC_CURSE, INVALID_TIMER);
if (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE)
- status_change_end(bl,SC_STONE,-1);
+ status_change_end(bl, SC_STONE, INVALID_TIMER);
}
break;
case SC_INCREASEAGI:
- status_change_end(bl,SC_DECREASEAGI,-1);
+ status_change_end(bl, SC_DECREASEAGI, INVALID_TIMER);
break;
case SC_QUAGMIRE:
- status_change_end(bl,SC_CONCENTRATE,-1);
- status_change_end(bl,SC_TRUESIGHT,-1);
- status_change_end(bl,SC_WINDWALK,-1);
+ status_change_end(bl, SC_CONCENTRATE, INVALID_TIMER);
+ status_change_end(bl, SC_TRUESIGHT, INVALID_TIMER);
+ status_change_end(bl, SC_WINDWALK, INVALID_TIMER);
//Also blocks the ones below...
case SC_DECREASEAGI:
- status_change_end(bl,SC_CARTBOOST,-1);
+ status_change_end(bl, SC_CARTBOOST, INVALID_TIMER);
//Also blocks the ones below...
case SC_DONTFORGETME:
- status_change_end(bl,SC_INCREASEAGI,-1);
- status_change_end(bl,SC_ADRENALINE,-1);
- status_change_end(bl,SC_ADRENALINE2,-1);
- status_change_end(bl,SC_SPEARQUICKEN,-1);
- status_change_end(bl,SC_TWOHANDQUICKEN,-1);
- status_change_end(bl,SC_ONEHAND,-1);
- status_change_end(bl,SC_MERC_QUICKEN,-1);
+ status_change_end(bl, SC_INCREASEAGI, INVALID_TIMER);
+ status_change_end(bl, SC_ADRENALINE, INVALID_TIMER);
+ status_change_end(bl, SC_ADRENALINE2, INVALID_TIMER);
+ status_change_end(bl, SC_SPEARQUICKEN, INVALID_TIMER);
+ status_change_end(bl, SC_TWOHANDQUICKEN, INVALID_TIMER);
+ status_change_end(bl, SC_ONEHAND, INVALID_TIMER);
+ status_change_end(bl, SC_MERC_QUICKEN, INVALID_TIMER);
break;
case SC_ONEHAND:
//Removes the Aspd potion effect, as reported by Vicious. [Skotlex]
- status_change_end(bl,SC_ASPDPOTION0,-1);
- status_change_end(bl,SC_ASPDPOTION1,-1);
- status_change_end(bl,SC_ASPDPOTION2,-1);
- status_change_end(bl,SC_ASPDPOTION3,-1);
+ status_change_end(bl, SC_ASPDPOTION0, INVALID_TIMER);
+ status_change_end(bl, SC_ASPDPOTION1, INVALID_TIMER);
+ status_change_end(bl, SC_ASPDPOTION2, INVALID_TIMER);
+ status_change_end(bl, SC_ASPDPOTION3, INVALID_TIMER);
break;
case SC_MAXOVERTHRUST:
//Cancels Normal Overthrust. [Skotlex]
- status_change_end(bl, SC_OVERTHRUST, -1);
+ status_change_end(bl, SC_OVERTHRUST, INVALID_TIMER);
break;
case SC_KYRIE:
//Cancels Assumptio
- status_change_end(bl,SC_ASSUMPTIO,-1);
+ status_change_end(bl, SC_ASSUMPTIO, INVALID_TIMER);
break;
case SC_DELUGE:
if (sc->data[SC_FOGWALL] && sc->data[SC_BLIND])
- status_change_end(bl,SC_BLIND,-1);
+ status_change_end(bl, SC_BLIND, INVALID_TIMER);
break;
case SC_SILENCE:
if (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF)
- status_change_end(bl,SC_GOSPEL,-1);
+ status_change_end(bl, SC_GOSPEL, INVALID_TIMER);
break;
case SC_HIDING:
- status_change_end(bl, SC_CLOSECONFINE, -1);
- status_change_end(bl, SC_CLOSECONFINE2, -1);
+ status_change_end(bl, SC_CLOSECONFINE, INVALID_TIMER);
+ status_change_end(bl, SC_CLOSECONFINE2, INVALID_TIMER);
break;
case SC_BERSERK:
if(battle_config.berserk_cancels_buffs)
{
- status_change_end(bl,SC_ONEHAND,-1);
- status_change_end(bl,SC_TWOHANDQUICKEN,-1);
- status_change_end(bl,SC_CONCENTRATION,-1);
- status_change_end(bl,SC_PARRYING,-1);
- status_change_end(bl,SC_AURABLADE,-1);
- status_change_end(bl,SC_MERC_QUICKEN,-1);
+ status_change_end(bl, SC_ONEHAND, INVALID_TIMER);
+ status_change_end(bl, SC_TWOHANDQUICKEN, INVALID_TIMER);
+ status_change_end(bl, SC_CONCENTRATION, INVALID_TIMER);
+ status_change_end(bl, SC_PARRYING, INVALID_TIMER);
+ status_change_end(bl, SC_AURABLADE, INVALID_TIMER);
+ status_change_end(bl, SC_MERC_QUICKEN, INVALID_TIMER);
}
break;
case SC_ASSUMPTIO:
- status_change_end(bl,SC_KYRIE,-1);
- status_change_end(bl,SC_KAITE,-1);
+ status_change_end(bl, SC_KYRIE, INVALID_TIMER);
+ status_change_end(bl, SC_KAITE, INVALID_TIMER);
break;
case SC_KAITE:
- status_change_end(bl,SC_ASSUMPTIO,-1);
+ status_change_end(bl, SC_ASSUMPTIO, INVALID_TIMER);
break;
case SC_CARTBOOST:
if(sc->data[SC_DECREASEAGI])
{ //Cancel Decrease Agi, but take no further effect [Skotlex]
- status_change_end(bl,SC_DECREASEAGI,-1);
+ status_change_end(bl, SC_DECREASEAGI, INVALID_TIMER);
return 0;
}
break;
case SC_FUSION:
- status_change_end(bl,SC_SPIRIT,-1);
+ status_change_end(bl, SC_SPIRIT, INVALID_TIMER);
break;
case SC_ADJUSTMENT:
- status_change_end(bl,SC_MADNESSCANCEL,-1);
+ status_change_end(bl, SC_MADNESSCANCEL, INVALID_TIMER);
break;
case SC_MADNESSCANCEL:
- status_change_end(bl,SC_ADJUSTMENT,-1);
+ status_change_end(bl, SC_ADJUSTMENT, INVALID_TIMER);
break;
//NPC_CHANGEUNDEAD will debuff Blessing and Agi Up
case SC_CHANGEUNDEAD:
- status_change_end(bl,SC_BLESSING,-1);
- status_change_end(bl,SC_INCREASEAGI,-1);
+ status_change_end(bl, SC_BLESSING, INVALID_TIMER);
+ status_change_end(bl, SC_INCREASEAGI, INVALID_TIMER);
break;
case SC_STRFOOD:
- status_change_end(bl,SC_FOOD_STR_CASH,-1);
+ status_change_end(bl, SC_FOOD_STR_CASH, INVALID_TIMER);
break;
case SC_AGIFOOD:
- status_change_end(bl,SC_FOOD_AGI_CASH,-1);
+ status_change_end(bl, SC_FOOD_AGI_CASH, INVALID_TIMER);
break;
case SC_VITFOOD:
- status_change_end(bl,SC_FOOD_VIT_CASH,-1);
+ status_change_end(bl, SC_FOOD_VIT_CASH, INVALID_TIMER);
break;
case SC_INTFOOD:
- status_change_end(bl,SC_FOOD_INT_CASH,-1);
+ status_change_end(bl, SC_FOOD_INT_CASH, INVALID_TIMER);
break;
case SC_DEXFOOD:
- status_change_end(bl,SC_FOOD_DEX_CASH,-1);
+ status_change_end(bl, SC_FOOD_DEX_CASH, INVALID_TIMER);
break;
case SC_LUKFOOD:
- status_change_end(bl,SC_FOOD_LUK_CASH,-1);
+ status_change_end(bl, SC_FOOD_LUK_CASH, INVALID_TIMER);
break;
case SC_FOOD_STR_CASH:
- status_change_end(bl,SC_STRFOOD,-1);
+ status_change_end(bl, SC_STRFOOD, INVALID_TIMER);
break;
case SC_FOOD_AGI_CASH:
- status_change_end(bl,SC_AGIFOOD,-1);
+ status_change_end(bl, SC_AGIFOOD, INVALID_TIMER);
break;
case SC_FOOD_VIT_CASH:
- status_change_end(bl,SC_VITFOOD,-1);
+ status_change_end(bl, SC_VITFOOD, INVALID_TIMER);
break;
case SC_FOOD_INT_CASH:
- status_change_end(bl,SC_INTFOOD,-1);
+ status_change_end(bl, SC_INTFOOD, INVALID_TIMER);
break;
case SC_FOOD_DEX_CASH:
- status_change_end(bl,SC_DEXFOOD,-1);
+ status_change_end(bl, SC_DEXFOOD, INVALID_TIMER);
break;
case SC_FOOD_LUK_CASH:
- status_change_end(bl,SC_LUKFOOD,-1);
+ status_change_end(bl, SC_LUKFOOD, INVALID_TIMER);
break;
}
@@ -5198,9 +5197,9 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
case SC_KAAHI:
//Kaahi overwrites previous level regardless of existing level.
//Delete timer if it exists.
- if (sce->val4 != -1) {
+ if (sce->val4 != INVALID_TIMER) {
delete_timer(sce->val4,kaahi_heal_timer);
- sce->val4=-1;
+ sce->val4 = INVALID_TIMER;
}
break;
case SC_JAILED:
@@ -5821,7 +5820,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
case SC_KAAHI:
val2 = 200*val1; //HP heal
val3 = 5*val1; //SP cost
- val4 = -1; //Kaahi Timer.
+ val4 = INVALID_TIMER; //Kaahi Timer.
break;
case SC_BLESSING:
if ((!undead_flag && status->race!=RC_DEMON) || bl->type == BL_PC)
@@ -6087,7 +6086,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
clif_changelook(bl,LOOK_CLOTHES_COLOR,val4);
break;
case SC_KAAHI:
- val4 = -1;
+ val4 = INVALID_TIMER;
break;
}
@@ -6102,7 +6101,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
pc_setstand(sd);
case SC_TRICKDEAD:
unit_stop_attack(bl);
- status_change_end(bl, SC_DANCING, -1);
+ status_change_end(bl, SC_DANCING, INVALID_TIMER);
// Cancel cast when get status [LuzZza]
if (battle_config.sc_castcancel&bl->type)
unit_skillcastcancel(bl, 0);
@@ -6448,14 +6447,14 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
sd = BL_CAST(BL_PC,bl);
- if (sce->timer != tid && tid != -1)
+ if (sce->timer != tid && tid != INVALID_TIMER)
return 0;
- if (tid == -1) {
+ if (tid == INVALID_TIMER) {
if (type == SC_ENDURE && sce->val4)
//Do not end infinite endure.
return 0;
- if (sce->timer != -1) //Could be a SC with infinite duration
+ if (sce->timer != INVALID_TIMER) //Could be a SC with infinite duration
delete_timer(sce->timer,status_change_timer);
if (sc->opt1)
switch (type) {
@@ -6514,7 +6513,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
if(!ud->state.running)
begin_spurt = false;
ud->state.running = 0;
- if (ud->walktimer != -1)
+ if (ud->walktimer != INVALID_TIMER)
unit_stop_walking(bl,1);
}
if (begin_spurt && sce->val1 >= 7 &&
@@ -6526,7 +6525,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
break;
case SC_AUTOBERSERK:
if (sc->data[SC_PROVOKE] && sc->data[SC_PROVOKE]->val2 == 1)
- status_change_end(bl,SC_PROVOKE,-1);
+ status_change_end(bl, SC_PROVOKE, INVALID_TIMER);
break;
case SC_ENDURE:
@@ -6541,14 +6540,14 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
for( i = 0; i < 5; i++ )
{
if( sd->devotion[i] && (tsd = map_id2sd(sd->devotion[i])) && tsd->sc.data[type] )
- status_change_end(&tsd->bl, type, -1);
+ status_change_end(&tsd->bl, type, INVALID_TIMER);
}
}
else if( bl->type == BL_MER && ((TBL_MER*)bl)->devotion_flag )
{ // Clear Status from Master
tsd = ((TBL_MER*)bl)->master;
if( tsd && tsd->sc.data[type] )
- status_change_end(&tsd->bl, type, -1);
+ status_change_end(&tsd->bl, type, INVALID_TIMER);
}
}
break;
@@ -6564,10 +6563,10 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
clif_devotion(d_bl, NULL);
}
- status_change_end(bl,SC_AUTOGUARD,-1);
- status_change_end(bl,SC_DEFENDER,-1);
- status_change_end(bl,SC_REFLECTSHIELD,-1);
- status_change_end(bl,SC_ENDURE,-1);
+ status_change_end(bl, SC_AUTOGUARD, INVALID_TIMER);
+ status_change_end(bl, SC_DEFENDER, INVALID_TIMER);
+ status_change_end(bl, SC_REFLECTSHIELD, INVALID_TIMER);
+ status_change_end(bl, SC_ENDURE, INVALID_TIMER);
}
break;
@@ -6581,7 +6580,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
if(tbl && tsc && tsc->data[SC_BLADESTOP])
{
tsc->data[SC_BLADESTOP]->val4 = 0;
- status_change_end(tbl,SC_BLADESTOP,-1);
+ status_change_end(tbl, SC_BLADESTOP, INVALID_TIMER);
}
clif_bladestop(bl, tid, 0);
}
@@ -6598,7 +6597,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
if(dsc)
{ //This will prevent recursive loops.
dsc->val2 = dsc->val4 = 0;
- status_change_end(&dsd->bl, SC_DANCING, -1);
+ status_change_end(&dsd->bl, SC_DANCING, INVALID_TIMER);
}
}
@@ -6621,11 +6620,11 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
if((sce->val1&0xFFFF) == CG_MOONLIT)
clif_status_change(bl,SI_MOONLIT,0,0);
- status_change_end(bl,SC_LONGING,-1);
+ status_change_end(bl, SC_LONGING, INVALID_TIMER);
}
break;
case SC_NOCHAT:
- if (sd && sd->status.manner < 0 && tid != -1)
+ if (sd && sd->status.manner < 0 && tid != INVALID_TIMER)
sd->status.manner = 0;
if (sd)
{
@@ -6636,7 +6635,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
case SC_SPLASHER:
{
struct block_list *src=map_id2bl(sce->val3);
- if(src && tid!=-1)
+ if(src && tid != INVALID_TIMER)
skill_castend_damage_id(src, bl, sce->val2, sce->val1, gettick(), SD_LEVEL );
}
break;
@@ -6648,7 +6647,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
//If status was already ended, do nothing.
//Decrease count
if (--(sc2->data[SC_CLOSECONFINE]->val1) <= 0) //No more holds, free him up.
- status_change_end(src, SC_CLOSECONFINE, -1);
+ status_change_end(src, SC_CLOSECONFINE, INVALID_TIMER);
}
}
case SC_CLOSECONFINE:
@@ -6685,7 +6684,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
if (sc2 && sc2->data[type2])
{
sc2->data[type2]->val1 = 0;
- status_change_end(pbl, type2, -1);
+ status_change_end(pbl, type2, INVALID_TIMER);
}
}
break;
@@ -6697,7 +6696,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
if(sc->data[SC_ENDURE] && sc->data[SC_ENDURE]->val4 == 2)
{
sc->data[SC_ENDURE]->val4 = 0;
- status_change_end(bl, SC_ENDURE, -1);
+ status_change_end(bl, SC_ENDURE, INVALID_TIMER);
}
sc_start4(bl, SC_REGENERATION, 100, 10,0,0,(RGN_HP|RGN_SP), skill_get_time(LK_BERSERK, sce->val1));
break;
@@ -6727,25 +6726,25 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
break;
case SC_KAAHI:
//Delete timer if it exists.
- if (sce->val4 != -1)
+ if (sce->val4 != INVALID_TIMER)
delete_timer(sce->val4,kaahi_heal_timer);
break;
case SC_JAILED:
- if(tid == -1)
+ if(tid == INVALID_TIMER)
break;
//natural expiration.
if(sd && sd->mapindex == sce->val2)
pc_setpos(sd,(unsigned short)sce->val3,sce->val4&0xFFFF, sce->val4>>16, CLR_TELEPORT);
break; //guess hes not in jail :P
case SC_CHANGE:
- if (tid == -1)
+ if (tid == INVALID_TIMER)
break;
// "lose almost all their HP and SP" on natural expiration.
status_set_hp(bl, 10, 0);
status_set_sp(bl, 10, 0);
break;
case SC_AUTOTRADE:
- if (tid == -1)
+ if (tid == INVALID_TIMER)
break;
vending_closevending(sd);
map_quit(sd);
@@ -6759,7 +6758,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid)
struct block_list* tbl = map_id2bl(sce->val2);
sce->val2 = 0;
if( tbl && (sc = status_get_sc(tbl)) && sc->data[SC_STOP] && sc->data[SC_STOP]->val2 == bl->id )
- status_change_end(tbl, SC_STOP, -1);
+ status_change_end(tbl, SC_STOP, INVALID_TIMER);
}
break;
}
@@ -6956,13 +6955,13 @@ int kaahi_heal_timer(int tid, unsigned int tick, int id, intptr data)
if(sce->val4 != tid) {
ShowError("kaahi_heal_timer: Timer mismatch: %d != %d\n", tid, sce->val4);
- sce->val4=-1;
+ sce->val4 = INVALID_TIMER;
return 0;
}
status=status_get_status_data(bl);
if(!status_charge(bl, 0, sce->val3)) {
- sce->val4=-1;
+ sce->val4 = INVALID_TIMER;
return 0;
}
@@ -6971,7 +6970,7 @@ int kaahi_heal_timer(int tid, unsigned int tick, int id, intptr data)
hp = sce->val2;
if (hp)
status_heal(bl, hp, 0, 2);
- sce->val4=-1;
+ sce->val4 = INVALID_TIMER;
return 1;
}
@@ -7350,13 +7349,13 @@ int status_change_timer_sub(struct block_list* bl, va_list ap)
{
case SC_SIGHT: /* サイト */
case SC_CONCENTRATE:
- status_change_end(bl, SC_HIDING, -1);
- status_change_end(bl, SC_CLOAKING, -1);
+ status_change_end(bl, SC_HIDING, INVALID_TIMER);
+ status_change_end(bl, SC_CLOAKING, INVALID_TIMER);
break;
case SC_RUWACH: /* ルアフ */
if (tsc && (tsc->data[SC_HIDING] || tsc->data[SC_CLOAKING])) {
- status_change_end(bl, SC_HIDING, -1);
- status_change_end(bl, SC_CLOAKING, -1);
+ status_change_end(bl, SC_HIDING, INVALID_TIMER);
+ status_change_end(bl, SC_CLOAKING, INVALID_TIMER);
if(battle_check_target( src, bl, BCT_ENEMY ) > 0)
skill_attack(BF_MAGIC,src,src,bl,AL_RUWACH,1,tick,0);
}
@@ -7373,7 +7372,7 @@ int status_change_timer_sub(struct block_list* bl, va_list ap)
//Lock char has released the hold on everyone...
if (tsc && tsc->data[SC_CLOSECONFINE2] && tsc->data[SC_CLOSECONFINE2]->val2 == src->id) {
tsc->data[SC_CLOSECONFINE2]->val2 = 0;
- status_change_end(bl, SC_CLOSECONFINE2, -1);
+ status_change_end(bl, SC_CLOSECONFINE2, INVALID_TIMER);
}
break;
}
@@ -7395,8 +7394,7 @@ int status_change_clear_buffs (struct block_list* bl, int type)
if (type&2) //Debuffs
for( i = SC_COMMON_MIN; i <= SC_COMMON_MAX; i++ )
{
- if(sc->data[i])
- status_change_end(bl,(sc_type)i,-1);
+ status_change_end(bl, (sc_type)i, INVALID_TIMER);
}
for( i = SC_COMMON_MAX+1; i < SC_MAX; i++ )
@@ -7469,7 +7467,7 @@ int status_change_clear_buffs (struct block_list* bl, int type)
continue;
break;
}
- status_change_end(bl,(sc_type)i,-1);
+ status_change_end(bl, (sc_type)i, INVALID_TIMER);
}
return 0;
}
@@ -7557,7 +7555,7 @@ static int status_natural_heal(struct block_list* bl, va_list args)
ud = unit_bl2ud(bl);
- if (flag&(RGN_HP|RGN_SHP|RGN_SSP) && ud && ud->walktimer != -1)
+ if (flag&(RGN_HP|RGN_SHP|RGN_SSP) && ud && ud->walktimer != INVALID_TIMER)
{
flag&=~(RGN_SHP|RGN_SSP);
if(!regen->state.walk)
@@ -7580,7 +7578,7 @@ static int status_natural_heal(struct block_list* bl, va_list args)
if (flag&RGN_HP)
{
rate = natural_heal_diff_tick*(regen->rate.hp+bonus);
- if (ud && ud->walktimer != -1)
+ if (ud && ud->walktimer != INVALID_TIMER)
rate/=2;
// Homun HP regen fix (they should regen as if they were sitting (twice as fast)
if(bl->type==BL_HOM) rate *=2;
diff --git a/src/map/storage.c b/src/map/storage.c
index 9aa34d3e0..116ba18c9 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -398,11 +398,12 @@ int guild_storage_additem(struct map_session_data* sd, struct guild_storage* sto
nullpo_retr(1, sd);
nullpo_retr(1, stor);
nullpo_retr(1, item_data);
- nullpo_retr(1, data = itemdb_search(item_data->nameid));
if(item_data->nameid <= 0 || amount <= 0)
return 1;
+ data = itemdb_search(item_data->nameid);
+
if( data->stack.guildstorage && amount > data->stack.amount )
{// item stack limitation
return 1;
diff --git a/src/map/trade.c b/src/map/trade.c
index 32c84b508..ba01826f2 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -56,7 +56,7 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta
}
}
- if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
+ if (target_sd->trade_partner != 0) {
clif_tradestart(sd, 2); // person is in another trade
return;
}
@@ -110,6 +110,7 @@ void trade_tradeack(struct map_session_data *sd, int type)
if (tsd->state.trading || tsd->trade_partner != sd->bl.id)
{
clif_tradestart(sd, 2);
+ sd->trade_partner=0;
return; //Already trading or wrong partner.
}
diff --git a/src/map/unit.c b/src/map/unit.c
index df4efef8e..7abfde12b 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -157,7 +157,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr data)
map_moveblock(bl, x, y, tick);
ud->walk_count++; //walked cell counter, to be used for walk-triggered skills. [Skotlex]
- if (bl->x != x || bl->y != y || ud->walktimer != -1)
+ if (bl->x != x || bl->y != y || ud->walktimer != INVALID_TIMER)
return 0; //map_moveblock has altered the object beyond what we expected (moved/warped it)
ud->walktimer = -2; // arbitrary non-INVALID_TIMER value to make the clif code send walking packets
@@ -197,11 +197,11 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr data)
if (md->min_chase > md->db->range3) md->min_chase--;
//Walk skills are triggered regardless of target due to the idle-walk mob state.
//But avoid triggering on stop-walk calls.
- if(tid != -1 &&
+ if(tid != INVALID_TIMER &&
!(ud->walk_count%WALK_SKILL_INTERVAL) &&
mobskill_use(md, tick, -1))
{
- if (!(ud->skillid == NPC_SELFDESTRUCTION && ud->skilltimer != -1))
+ if (!(ud->skillid == NPC_SELFDESTRUCTION && ud->skilltimer != INVALID_TIMER))
{ //Skill used, abort walking
clif_fixpos(bl); //Fix position as walk has been cancelled.
return 0;
@@ -211,7 +211,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr data)
}
}
- if(tid == -1) //A directly invoked timer is from battle_stop_walking, therefore the rest is irrelevant.
+ if(tid == INVALID_TIMER) //A directly invoked timer is from battle_stop_walking, therefore the rest is irrelevant.
return 0;
if(ud->state.change_walk_target)
@@ -306,14 +306,14 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
if (sc && sc->data[SC_CONFUSION]) //Randomize the target position
map_random_dir(bl, &ud->to_x, &ud->to_y);
- if(ud->walktimer != -1) {
+ if(ud->walktimer != INVALID_TIMER) {
// 現在歩いている最中の目的地変更なのでマス目の中心に来た時に
// timer関数からunit_walktoxy_subを呼ぶようにする
ud->state.change_walk_target = 1;
return 1;
}
- if(ud->attacktimer != -1) {
+ if(ud->attacktimer != INVALID_TIMER) {
delete_timer( ud->attacktimer, unit_attack_timer );
ud->attacktimer = INVALID_TIMER;
}
@@ -331,7 +331,7 @@ static int unit_walktobl_sub(int tid, unsigned int tick, int id, intptr data)
struct block_list *bl = map_id2bl(id);
struct unit_data *ud = bl?unit_bl2ud(bl):NULL;
- if (ud && ud->walktimer == -1 && ud->target == data)
+ if (ud && ud->walktimer == INVALID_TIMER && ud->target == data)
{
if (DIFF_TICK(ud->canmove_tick, tick) > 0) //Keep waiting?
add_timer(ud->canmove_tick+1, unit_walktobl_sub, id, data);
@@ -374,7 +374,7 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
if (sc && sc->data[SC_CONFUSION]) //Randomize the target position
map_random_dir(bl, &ud->to_x, &ud->to_y);
- if(ud->walktimer != -1) {
+ if(ud->walktimer != INVALID_TIMER) {
ud->state.change_walk_target = 1;
set_mobstate(bl, flag&2);
return 1;
@@ -389,7 +389,7 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
if(!unit_can_move(bl))
return 0;
- if(ud->attacktimer != -1) {
+ if(ud->attacktimer != INVALID_TIMER) {
delete_timer( ud->attacktimer, unit_attack_timer );
ud->attacktimer = INVALID_TIMER;
}
@@ -413,7 +413,7 @@ int unit_run(struct block_list *bl)
return 0;
if (!unit_can_move(bl)) {
- status_change_end(bl,SC_RUN,-1);
+ status_change_end(bl, SC_RUN, INVALID_TIMER);
return 0;
}
@@ -443,7 +443,7 @@ int unit_run(struct block_list *bl)
//Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
unit_bl2ud(bl)->state.running = 0;
- status_change_end(bl,SC_RUN,-1);
+ status_change_end(bl, SC_RUN, INVALID_TIMER);
skill_blown(bl,bl,skill_get_blewcount(TK_RUN,lv),unit_getdir(bl),0);
clif_fixpos(bl); //Why is a clif_slide (skill_blown) AND a fixpos needed? Ask Aegis.
@@ -463,7 +463,7 @@ int unit_run(struct block_list *bl)
//Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
unit_bl2ud(bl)->state.running = 0;
- status_change_end(bl,SC_RUN,-1);
+ status_change_end(bl, SC_RUN, INVALID_TIMER);
skill_blown(bl,bl,skill_get_blewcount(TK_RUN,lv),unit_getdir(bl),0);
clif_fixpos(bl);
@@ -725,7 +725,7 @@ int unit_stop_walking(struct block_list *bl,int type)
nullpo_ret(bl);
ud = unit_bl2ud(bl);
- if(!ud || ud->walktimer == -1)
+ if(!ud || ud->walktimer == INVALID_TIMER)
return 0;
//NOTE: We are using timer data after deleting it because we know the
//delete_timer function does not messes with it. If the function's
@@ -739,7 +739,7 @@ int unit_stop_walking(struct block_list *bl,int type)
|| (type&0x04 && td && DIFF_TICK(td->tick, tick) <= td->data/2) //Enough time has passed to cover half-cell
) {
ud->walkpath.path_len = ud->walkpath.path_pos+1;
- unit_walktoxy_timer(-1, tick, bl->id, ud->walkpath.path_pos);
+ unit_walktoxy_timer(INVALID_TIMER, tick, bl->id, ud->walkpath.path_pos);
}
if(type&0x01)
@@ -754,7 +754,7 @@ int unit_stop_walking(struct block_list *bl,int type)
//Readded, the check in unit_set_walkdelay means dmg during running won't fall through to this place in code [Kevin]
if (ud->state.running)
- status_change_end(bl, SC_RUN, -1);
+ status_change_end(bl, SC_RUN, INVALID_TIMER);
return 1;
}
@@ -774,7 +774,7 @@ int unit_is_walking(struct block_list *bl)
struct unit_data *ud = unit_bl2ud(bl);
nullpo_ret(bl);
if(!ud) return 0;
- return (ud->walktimer != -1);
+ return (ud->walktimer != INVALID_TIMER);
}
/*==========================================
@@ -794,7 +794,7 @@ int unit_can_move(struct block_list *bl)
if (!ud)
return 0;
- if (ud->skilltimer != -1 && (!sd || !pc_checkskill(sd, SA_FREECAST) || skill_get_inf2(ud->skillid)&INF2_GUILD_SKILL))
+ if (ud->skilltimer != INVALID_TIMER && (!sd || !pc_checkskill(sd, SA_FREECAST) || skill_get_inf2(ud->skillid)&INF2_GUILD_SKILL))
return 0; // prevent moving while casting
if (DIFF_TICK(ud->canmove_tick, gettick()) > 0)
@@ -880,7 +880,7 @@ int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int
return 0;
}
ud->canmove_tick = tick + delay;
- if (ud->walktimer != -1)
+ if (ud->walktimer != INVALID_TIMER)
{ //Stop walking, if chasing, readjust timers.
if (delay == 1)
{ //Minimal delay (walk-delay) disabled. Just stop walking.
@@ -939,8 +939,6 @@ int unit_skilluse_id2(struct block_list *src, int target_id, short skill_num, sh
if(skillnotok(skill_num, sd)) // [MouseJstr]
return 0;
- mob_ksprotected(src, map_id2bl(target_id));
-
switch(skill_num)
{ //Check for skills that auto-select target
case MO_CHAINCOMBO:
@@ -987,8 +985,11 @@ int unit_skilluse_id2(struct block_list *src, int target_id, short skill_num, sh
if( !target || src->m != target->m || !src->prev || !target->prev )
return 0;
+ if( mob_ksprotected(src, target) )
+ return 0;
+
//Normally not needed because clif.c checks for it, but the at/char/script commands don't! [Skotlex]
- if(ud->skilltimer != -1 && skill_num != SA_CASTCANCEL)
+ if(ud->skilltimer != INVALID_TIMER && skill_num != SA_CASTCANCEL)
return 0;
if(skill_get_inf2(skill_num)&INF2_NO_TARGET_SELF && src->id == target_id)
@@ -1047,7 +1048,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, short skill_num, sh
//Check range when not using skill on yourself or is a combo-skill during attack
//(these are supposed to always have the same range as your attack)
- if( src->id != target_id && (!temp || ud->attacktimer == -1) )
+ if( src->id != target_id && (!temp || ud->attacktimer == INVALID_TIMER) )
{
if( skill_get_state(ud->skillid) == ST_MOVE_ENABLE )
{
@@ -1065,7 +1066,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, short skill_num, sh
if (!temp) //Stop attack on non-combo skills [Skotlex]
unit_stop_attack(src);
- else if(ud->attacktimer != -1) //Elsewise, delay current attack sequence
+ else if(ud->attacktimer != INVALID_TIMER) //Elsewise, delay current attack sequence
ud->attackabletime = tick + status_get_adelay(src);
ud->state.skillcastcancel = castcancel;
@@ -1180,7 +1181,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, short skill_num, sh
if( sc && sc->data[SC_CLOAKING] && !(sc->data[SC_CLOAKING]->val4&4) && skill_num != AS_CLOAKING )
{
- status_change_end(src,SC_CLOAKING,-1);
+ status_change_end(src, SC_CLOAKING, INVALID_TIMER);
if (!src->prev) return 0; //Warped away!
}
@@ -1224,7 +1225,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, sh
ud = unit_bl2ud(src);
if(ud == NULL) return 0;
- if(ud->skilltimer != -1) //Normally not needed since clif.c checks for it, but at/char/script commands don't! [Skotlex]
+ if(ud->skilltimer != INVALID_TIMER) //Normally not needed since clif.c checks for it, but at/char/script commands don't! [Skotlex]
return 0;
sc = status_get_sc(src);
@@ -1285,7 +1286,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, sh
if (sc && sc->data[SC_CLOAKING] && !(sc->data[SC_CLOAKING]->val4&4))
{
- status_change_end(src,SC_CLOAKING,-1);
+ status_change_end(src, SC_CLOAKING, INVALID_TIMER);
if (!src->prev) return 0; //Warped away!
}
@@ -1310,7 +1311,7 @@ int unit_stop_attack(struct block_list *bl)
struct unit_data *ud = unit_bl2ud(bl);
nullpo_ret(bl);
- if(!ud || ud->attacktimer == -1)
+ if(!ud || ud->attacktimer == INVALID_TIMER)
return 0;
delete_timer( ud->attacktimer, unit_attack_timer );
@@ -1380,7 +1381,7 @@ int unit_attack(struct block_list *src,int target_id,int continuous)
ud->chaserange = status_get_range(src);
//Just change target/type. [Skotlex]
- if(ud->attacktimer != -1)
+ if(ud->attacktimer != INVALID_TIMER)
return 0;
//Set Mob's ANGRY/BERSERK states.
@@ -1391,7 +1392,7 @@ int unit_attack(struct block_list *src,int target_id,int continuous)
//Do attack next time it is possible. [Skotlex]
ud->attacktimer=add_timer(ud->attackabletime,unit_attack_timer,src->id,0);
else //Attack NOW.
- unit_attack_timer(-1,gettick(),src->id,0);
+ unit_attack_timer(INVALID_TIMER, gettick(), src->id, 0);
return 0;
}
@@ -1402,7 +1403,7 @@ int unit_cancel_combo(struct block_list *bl)
{
struct unit_data *ud;
- if (!status_change_end(bl, SC_COMBO, -1))
+ if (!status_change_end(bl, SC_COMBO, INVALID_TIMER))
return 0; //Combo wasn't active.
ud = unit_bl2ud(bl);
@@ -1410,7 +1411,7 @@ int unit_cancel_combo(struct block_list *bl)
ud->attackabletime = gettick() + status_get_amotion(bl);
- if (ud->attacktimer == -1)
+ if (ud->attacktimer == INVALID_TIMER)
return 1; //Nothing more to do.
delete_timer(ud->attacktimer, unit_attack_timer);
@@ -1563,12 +1564,12 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
return 0;
}
- if( ud->skilltimer != -1 && !(sd && pc_checkskill(sd,SA_FREECAST) > 0) )
+ if( ud->skilltimer != INVALID_TIMER && !(sd && pc_checkskill(sd,SA_FREECAST) > 0) )
return 0; // can't attack while casting
if( !battle_config.sdelay_attack_enable && DIFF_TICK(ud->canact_tick,tick) > 0 && !(sd && pc_checkskill(sd,SA_FREECAST) > 0) )
{ // attacking when under cast delay has restrictions:
- if( tid == -1 )
+ if( tid == INVALID_TIMER )
{ //requested attack.
if(sd) clif_skill_fail(sd,1,4,0);
return 0;
@@ -1612,14 +1613,14 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
//Sync packet only for players.
//Non-players use the sync packet on the walk timer. [Skotlex]
- if (tid == -1 && sd) clif_fixpos(src);
+ if (tid == INVALID_TIMER && sd) clif_fixpos(src);
if( DIFF_TICK(ud->attackabletime,tick) <= 0 )
{
if (battle_config.attack_direction_change && (src->type&battle_config.attack_direction_change)) {
ud->dir = map_calc_dir(src, target->x,target->y );
}
- if(ud->walktimer != -1)
+ if(ud->walktimer != INVALID_TIMER)
unit_stop_walking(src,1);
if(md) {
if (mobskill_use(md,tick,-1))
@@ -1674,7 +1675,7 @@ int unit_skillcastcancel(struct block_list *bl,int type)
int ret=0, skill;
nullpo_ret(bl);
- if (!ud || ud->skilltimer==-1)
+ if (!ud || ud->skilltimer == INVALID_TIMER)
return 0; //Nothing to cancel.
sd = BL_CAST(BL_PC, bl);
@@ -1732,9 +1733,9 @@ void unit_dataset(struct block_list *bl)
memset( ud, 0, sizeof( struct unit_data) );
ud->bl = bl;
- ud->walktimer = -1;
- ud->skilltimer = -1;
- ud->attacktimer = -1;
+ ud->walktimer = INVALID_TIMER;
+ ud->skilltimer = INVALID_TIMER;
+ ud->attacktimer = INVALID_TIMER;
ud->attackabletime =
ud->canact_tick =
ud->canmove_tick = gettick();
@@ -1754,7 +1755,7 @@ static int unit_counttargeted_sub(struct block_list* bl, va_list ap)
ud = unit_bl2ud(bl);
- if (ud && ud->target == id && ud->attacktimer != -1 && ud->attacktarget_lv >= target_lv)
+ if (ud && ud->target == id && ud->attacktimer != INVALID_TIMER && ud->attacktarget_lv >= target_lv)
return 1;
return 0;
@@ -1821,36 +1822,36 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
map_freeblock_lock();
ud->target = 0; //Unlock walk/attack target.
- if (ud->walktimer != -1)
+ if (ud->walktimer != INVALID_TIMER)
unit_stop_walking(bl,0);
- if (ud->attacktimer != -1)
+ if (ud->attacktimer != INVALID_TIMER)
unit_stop_attack(bl);
- if (ud->skilltimer != -1)
+ if (ud->skilltimer != INVALID_TIMER)
unit_skillcastcancel(bl,0);
// Do not reset can-act delay. [Skotlex]
ud->attackabletime = ud->canmove_tick /*= ud->canact_tick*/ = gettick();
if(sc && sc->count ) { //map-change/warp dispells.
- status_change_end(bl,SC_BLADESTOP,-1);
- status_change_end(bl,SC_BASILICA,-1);
- status_change_end(bl,SC_ANKLE,-1);
- status_change_end(bl,SC_TRICKDEAD,-1);
- status_change_end(bl,SC_BLADESTOP_WAIT,-1);
- status_change_end(bl,SC_RUN,-1);
- status_change_end(bl,SC_DANCING,-1);
- status_change_end(bl,SC_WARM,-1);
- status_change_end(bl,SC_DEVOTION,-1);
- status_change_end(bl,SC_MARIONETTE,-1);
- status_change_end(bl,SC_MARIONETTE2,-1);
- status_change_end(bl,SC_CLOSECONFINE,-1);
- status_change_end(bl,SC_CLOSECONFINE2,-1);
- status_change_end(bl,SC_HIDING,-1);
- status_change_end(bl,SC_CLOAKING,-1);
- status_change_end(bl,SC_CHASEWALK,-1);
+ status_change_end(bl, SC_BLADESTOP, INVALID_TIMER);
+ status_change_end(bl, SC_BASILICA, INVALID_TIMER);
+ status_change_end(bl, SC_ANKLE, INVALID_TIMER);
+ status_change_end(bl, SC_TRICKDEAD, INVALID_TIMER);
+ status_change_end(bl, SC_BLADESTOP_WAIT, INVALID_TIMER);
+ status_change_end(bl, SC_RUN, INVALID_TIMER);
+ status_change_end(bl, SC_DANCING, INVALID_TIMER);
+ status_change_end(bl, SC_WARM, INVALID_TIMER);
+ status_change_end(bl, SC_DEVOTION, INVALID_TIMER);
+ status_change_end(bl, SC_MARIONETTE, INVALID_TIMER);
+ status_change_end(bl, SC_MARIONETTE2, INVALID_TIMER);
+ status_change_end(bl, SC_CLOSECONFINE, INVALID_TIMER);
+ status_change_end(bl, SC_CLOSECONFINE2, INVALID_TIMER);
+ status_change_end(bl, SC_HIDING, INVALID_TIMER);
+ status_change_end(bl, SC_CLOAKING, INVALID_TIMER);
+ status_change_end(bl, SC_CHASEWALK, INVALID_TIMER);
if (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF)
- status_change_end(bl,SC_GOSPEL,-1);
- status_change_end(bl,SC_CHANGE,-1);
- status_change_end(bl,SC_STOP,-1);
+ status_change_end(bl, SC_GOSPEL, INVALID_TIMER);
+ status_change_end(bl, SC_CHANGE, INVALID_TIMER);
+ status_change_end(bl, SC_STOP, INVALID_TIMER);
}
if (bl->type&BL_CHAR) {
@@ -1890,7 +1891,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
sd->npc_shopid = 0;
sd->adopt_invite = 0;
- if(sd->pvp_timer!=-1) {
+ if(sd->pvp_timer != INVALID_TIMER) {
delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
sd->pvp_timer = INVALID_TIMER;
sd->pvp_rank = 0;
@@ -2052,7 +2053,7 @@ int unit_free(struct block_list *bl, clr_type clrtype)
pc_delautobonus(sd,sd->autobonus2,ARRAYLENGTH(sd->autobonus2),false);
pc_delautobonus(sd,sd->autobonus3,ARRAYLENGTH(sd->autobonus3),false);
- if( sd->followtimer != -1 )
+ if( sd->followtimer != INVALID_TIMER )
pc_stop_following(sd);
if( sd->duel_invite > 0 )
@@ -2103,7 +2104,7 @@ int unit_free(struct block_list *bl, clr_type clrtype)
}
if( pd->s_skill )
{
- if (pd->s_skill->timer != -1) {
+ if (pd->s_skill->timer != INVALID_TIMER) {
if (pd->s_skill->id)
delete_timer(pd->s_skill->timer, pet_skill_support_timer);
else
@@ -2114,14 +2115,14 @@ int unit_free(struct block_list *bl, clr_type clrtype)
}
if( pd->recovery )
{
- if(pd->recovery->timer != -1)
+ if(pd->recovery->timer != INVALID_TIMER)
delete_timer(pd->recovery->timer, pet_recovery_timer);
aFree(pd->recovery);
pd->recovery = NULL;
}
if( pd->bonus )
{
- if (pd->bonus->timer != -1)
+ if (pd->bonus->timer != INVALID_TIMER)
delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
aFree(pd->bonus);
pd->bonus = NULL;
diff --git a/src/map/vending.c b/src/map/vending.c
index 90bff7399..a47be9057 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -19,6 +19,18 @@
#include <stdio.h>
#include <string.h>
+static int vending_nextid = 1;
+
+/// Returns an unique vending shop id.
+static int vending_getuid(void)
+{
+ if(!vending_nextid)
+ {// wrapped around, 0 is reserved for "not vending" state on eathena
+ vending_nextid = 1;
+ }
+
+ return vending_nextid++;
+}
/*==========================================
* Close shop
@@ -50,13 +62,15 @@ void vending_vendinglistreq(struct map_session_data* sd, int id)
return;
}
+ sd->vended_id = vsd->vender_id; // register vending uid
+
clif_vendinglist(sd, id, vsd->vending);
}
/*==========================================
* Purchase item(s) from a shop
*------------------------------------------*/
-void vending_purchasereq(struct map_session_data* sd, int aid, int cid, const uint8* data, int count)
+void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const uint8* data, int count)
{
int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING];
double z;
@@ -64,12 +78,15 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int cid, const ui
struct map_session_data* vsd = map_id2sd(aid);
nullpo_retv(sd);
- if( vsd == NULL || vsd->vender_id == 0 || vsd->vender_id == sd->bl.id )
+ if( vsd == NULL || vsd->vender_id == 0 || vsd->bl.id == sd->bl.id )
return; // invalid shop
-#if PACKETVER >= 20100105
- if( vsd->status.char_id != cid )
- return; //Char-ID check
-#endif
+
+ if( vsd->vender_id != uid )
+ {// shop has changed
+ clif_buyvending(sd, 0, 0, 6); // store information was incorrect
+ return;
+ }
+
if( sd->bl.m != vsd->bl.m || !check_distance_bl(&sd->bl, &vsd->bl, AREA_SIZE) )
return; // shop too far away
if( count < 1 || count > MAX_VENDING || count > vsd->vend_num )
@@ -289,11 +306,11 @@ void vending_openvending(struct map_session_data* sd, const char* message, bool
return;
}
- sd->vender_id = sd->bl.id;
+ sd->vender_id = vending_getuid();
sd->vend_num = i;
safestrncpy(sd->message, message, MESSAGE_SIZE);
pc_stop_walking(sd,1);
- clif_openvending(sd,sd->vender_id,sd->vending);
+ clif_openvending(sd,sd->bl.id,sd->vending);
clif_showvendingboard(&sd->bl,message,0);
}
diff --git a/src/map/vending.h b/src/map/vending.h
index 9748b675a..3c483a38c 100644
--- a/src/map/vending.h
+++ b/src/map/vending.h
@@ -17,6 +17,6 @@ struct s_vending {
void vending_closevending(struct map_session_data* sd);
void vending_openvending(struct map_session_data* sd, const char* message, bool flag, const uint8* data, int count);
void vending_vendinglistreq(struct map_session_data* sd, int id);
-void vending_purchasereq(struct map_session_data* sd, int aid, int cid, const uint8* data, int count);
+void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const uint8* data, int count);
#endif /* _VENDING_H_ */