diff options
author | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-12-02 10:30:10 +0000 |
---|---|---|
committer | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-12-02 10:30:10 +0000 |
commit | 4afe95f6ad237ebddbc913f9e02dd1bbd4fb28b9 (patch) | |
tree | 3bb5818ac995b3853d9f0cd46de07542eddc2c4e /src/map/pc.c | |
parent | aefb12e53cbeed61558283309a5f8e2f31963fdb (diff) | |
download | hercules-4afe95f6ad237ebddbc913f9e02dd1bbd4fb28b9.tar.gz hercules-4afe95f6ad237ebddbc913f9e02dd1bbd4fb28b9.tar.bz2 hercules-4afe95f6ad237ebddbc913f9e02dd1bbd4fb28b9.tar.xz hercules-4afe95f6ad237ebddbc913f9e02dd1bbd4fb28b9.zip |
* Autobonus code cleanups.
- removed the 'script_parsed' flag to fix the issues with combo items.
- introduced a global cache for autobonus scripts so that we don't have to parse scripts everytime invoking status_calc_bl.
- fixed such script commands as 'getrefine()' not working inside autobonus scripts.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14180 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/pc.c')
-rw-r--r-- | src/map/pc.c | 64 |
1 files changed, 29 insertions, 35 deletions
diff --git a/src/map/pc.c b/src/map/pc.c index b2db9858d..5f724012f 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -1622,7 +1622,7 @@ static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id return 1; } -int pc_addautobonus(struct s_autobonus *bonus,char max,struct script_code *script,short rate,unsigned int dur,short flag,struct script_code *other_script,unsigned short pos,bool onskill) +int pc_addautobonus(struct s_autobonus *bonus,char max,const char *script,short rate,unsigned int dur,short flag,const char *other_script,unsigned short pos,bool onskill) { int i; @@ -1653,8 +1653,8 @@ int pc_addautobonus(struct s_autobonus *bonus,char max,struct script_code *scrip bonus[i].active = INVALID_TIMER; bonus[i].atk_type = flag; bonus[i].pos = pos; - bonus[i].bonus_script = script; - bonus[i].other_script = other_script; + bonus[i].bonus_script = aStrdup(script); + bonus[i].other_script = other_script?aStrdup(other_script):NULL; return 1; } @@ -1665,31 +1665,30 @@ int pc_delautobonus(struct map_session_data* sd, struct s_autobonus *autobonus,c for( i = 0; i < max; i++ ) { - if( autobonus[i].active != INVALID_TIMER && !(restore && sd->state.autobonus&autobonus[i].pos) ) - { // Logout / Unequipped an item with an activated bonus - delete_timer(autobonus[i].active,pc_endautobonus); - autobonus[i].active = INVALID_TIMER; - } - - if( restore && sd->state.autobonus&autobonus[i].pos ) + if( autobonus[i].active != INVALID_TIMER ) { - if( autobonus[i].active != INVALID_TIMER && autobonus[i].bonus_script ) - run_script(autobonus[i].bonus_script,0,sd->bl.id,0); - continue; + if( restore && sd->state.autobonus&autobonus[i].pos ) + { + if( autobonus[i].bonus_script ) + { + int j; + ARR_FIND( 0, EQI_MAX-1, j, sd->equip_index[j] >= 0 && sd->status.inventory[sd->equip_index[j]].equip == autobonus[i].pos ); + if( j < EQI_MAX-1 ) + script_run_autobonus(autobonus[i].bonus_script,sd->bl.id,sd->equip_index[j]); + } + continue; + } + else + { // Logout / Unequipped an item with an activated bonus + delete_timer(autobonus[i].active,pc_endautobonus); + autobonus[i].active = INVALID_TIMER; + } } - if( sd->state.autocast ) - continue; - - if( autobonus[i].pos&sd->state.script_parsed && restore ) - continue; - - if( autobonus[i].bonus_script ) - script_free_code(autobonus[i].bonus_script); - if( autobonus[i].other_script ) - script_free_code(autobonus[i].other_script); - autobonus[i].rate = autobonus[i].atk_type = autobonus[i].duration = autobonus[i].pos = 0; + if( autobonus[i].bonus_script ) aFree(autobonus[i].bonus_script); + if( autobonus[i].other_script ) aFree(autobonus[i].other_script); autobonus[i].bonus_script = autobonus[i].other_script = NULL; + autobonus[i].rate = autobonus[i].atk_type = autobonus[i].duration = autobonus[i].pos = 0; autobonus[i].active = INVALID_TIMER; } @@ -1703,9 +1702,10 @@ int pc_exeautobonus(struct map_session_data *sd,struct s_autobonus *autobonus) if( autobonus->other_script ) { - sd->state.autocast = 1; - run_script(autobonus->other_script,0,sd->bl.id,0); - sd->state.autocast = 0; + int j; + ARR_FIND( 0, EQI_MAX-1, j, sd->equip_index[j] >= 0 && sd->status.inventory[sd->equip_index[j]].equip == autobonus->pos ); + if( j < EQI_MAX-1 ) + script_run_autobonus(autobonus->other_script,sd->bl.id,sd->equip_index[j]); } autobonus->active = add_timer(gettick()+autobonus->duration, pc_endautobonus, sd->bl.id, (intptr)autobonus); @@ -7001,7 +7001,6 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos) * 0 - only unequip * 1 - calculate status after unequipping * 2 - force unequip - * 4 - ignore autobonus flags *------------------------------------------*/ int pc_unequipitem(struct map_session_data *sd,int n,int flag) { @@ -7074,13 +7073,8 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) status_change_end(&sd->bl, SC_ARMOR_RESIST, -1); } - if( !(flag&4) ) - { - if( sd->state.script_parsed&sd->status.inventory[n].equip ) - sd->state.script_parsed &= ~sd->status.inventory[n].equip; - if( sd->state.autobonus&sd->status.inventory[n].equip ) - sd->state.autobonus &= ~sd->status.inventory[n].equip; //Check for activated autobonus [Inkfish] - } + if( sd->state.autobonus&sd->status.inventory[n].equip ) + sd->state.autobonus &= ~sd->status.inventory[n].equip; //Check for activated autobonus [Inkfish] sd->status.inventory[n].equip=0; |