diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/map/battle.c | 1 | ||||
-rw-r--r-- | src/map/battle.h | 1 | ||||
-rw-r--r-- | src/map/mob.c | 66 |
3 files changed, 38 insertions, 30 deletions
diff --git a/src/map/battle.c b/src/map/battle.c index bdd1b9bc9..5eabc719d 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -6715,6 +6715,7 @@ static const struct battle_data { { "copyskill_restrict", &battle_config.copyskill_restrict, 2, 0, 2, }, { "berserk_cancels_buffs", &battle_config.berserk_cancels_buffs, 0, 0, 1, }, { "monster_ai", &battle_config.mob_ai, 0x000, 0x000, 0x77F, }, + { "monster_chase_refresh", &battle_config.mob_chase_refresh, 1, 0, 30, }, { "hom_setting", &battle_config.hom_setting, 0xFFFF, 0x0000, 0xFFFF, }, { "dynamic_mobs", &battle_config.dynamic_mobs, 1, 0, 1, }, { "mob_remove_damaged", &battle_config.mob_remove_damaged, 1, 0, 1, }, diff --git a/src/map/battle.h b/src/map/battle.h index 734a6187d..eeb9897fa 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -353,6 +353,7 @@ struct Battle_Config { int copyskill_restrict; // [Aru] int berserk_cancels_buffs; // [Aru] int mob_ai; //Configures various mob_ai settings to make them smarter or dumber(official). [Skotlex] + int mob_chase_refresh; //How often a monster should refresh its chase [Playtester] int hom_setting; //Configures various homunc settings which make them behave unlike normal characters.. [Skotlex] int dynamic_mobs; // Dynamic Mobs [Wizputer] - battle.conf flag implemented by [random] int mob_remove_damaged; // Dynamic Mobs - Remove mobs even if damaged [Wizputer] diff --git a/src/map/mob.c b/src/map/mob.c index ffab804a6..cdd842075 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1298,8 +1298,7 @@ int mob_unlocktarget(struct mob_data *md, int64 tick) { break; default: mob_stop_attack(md); - if (battle_config.mob_ai&0x8) - mob_stop_walking(md,1); //Immediately stop chasing. + mob_stop_walking(md,1); //Stop chasing. md->state.skillstate = MSS_IDLE; md->next_walktime=tick+rnd()%3000+3000; break; @@ -1404,9 +1403,6 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { if (md->ud.skilltimer != INVALID_TIMER) return false; - if(md->ud.walktimer != INVALID_TIMER && md->ud.walkpath.path_pos <= 3) - return false; - // Abnormalities if(( md->sc.opt1 > 0 && md->sc.opt1 != OPT1_STONEWAIT && md->sc.opt1 != OPT1_BURNING && md->sc.opt1 != OPT1_CRYSTALIZE ) || md->sc.data[SC_DEEP_SLEEP] || md->sc.data[SC_BLADESTOP] || md->sc.data[SC__MANHOLE] || md->sc.data[SC_CURSEDCIRCLE_TARGET]) { @@ -1434,10 +1430,12 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { || ((TBL_PC*)tbl)->invincible_timer != INVALID_TIMER) ) ) { - //Unlock current target. + //No valid target if (mob->warpchase(md, tbl)) return true; //Chasing this target. - mob->unlocktarget(md, tick-(battle_config.mob_ai&0x8?3000:0)); //Immediately do random walk. + if(md->ud.walktimer != INVALID_TIMER && md->ud.walkpath.path_pos <= battle_config.mob_chase_refresh) + return true; //Walk at least "mob_chase_refresh" cells before dropping the target + mob_unlocktarget(md, tick-(battle_config.mob_ai&0x8?3000:0)); //Immediately do random walk. tbl = NULL; } } @@ -1604,27 +1602,25 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { mob->unlocktarget (md,tick); return true; } + //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 != INVALID_TIMER) //Already locked. - return true; - if (battle->check_range (&md->bl, tbl, md->status.rhw.range)) { //Target within range, engage - - if(tbl->type == BL_PC) - mob->log_damage(md, tbl, 0); //Log interaction (counts as 'attacker' for the exp bonus) - - if(!(mode&MD_RANDOMTARGET)) - unit->attack(&md->bl,tbl->id,1); - else { // Attack once and find new random target - int search_size = (view_range < md->status.rhw.range) ? view_range : md->status.rhw.range; - unit->attack(&md->bl,tbl->id,0); - tbl = battle->get_enemy(&md->bl, DEFAULT_ENEMY_TYPE(md), search_size); - // If no target was found, keep atacking the old one - if( tbl ) { - md->target_id = tbl->id; - md->min_chase = md->db->range3; + if (md->ud.target != tbl->id || md->ud.attacktimer == INVALID_TIMER) + { //Only attack if no more attack delay left + if(tbl->type == BL_PC) + mob->log_damage(md, tbl, 0); //Log interaction (counts as 'attacker' for the exp bonus) + + if( !(mode&MD_RANDOMTARGET) ) + unit->attack(&md->bl,tbl->id,1); + else { // Attack once and find a new random target + int search_size = (view_range < md->status.rhw.range) ? view_range : md->status.rhw.range; + unit->attack(&md->bl,tbl->id, 0); + if ((tbl = battle->get_enemy(&md->bl, DEFAULT_ENEMY_TYPE(md), search_size))) { + md->target_id = tbl->id; + md->min_chase = md->db->range3; + } } } return true; @@ -1633,17 +1629,23 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { //Out of range... if (!(mode&MD_CANMOVE)) { //Can't chase. Attempt an idle skill before unlocking. - md->state.skillstate = MSS_IDLE; - if (!mob->skill_use(md, tick, -1)) - mob->unlocktarget(md,tick); + if (md->ud.target != tbl->id || md->ud.attacktimer == INVALID_TIMER) + { //Only use skill if no more attack delay left + md->state.skillstate = MSS_IDLE; + if (!mob->skill_use(md, tick, -1)) + mob->unlocktarget(md,tick); + } return true; } if (!can_move) { //Stuck. Attempt an idle skill - md->state.skillstate = MSS_IDLE; - if (!(++md->ud.walk_count%IDLE_SKILL_INTERVAL)) - mob->skill_use(md, tick, -1); + if (md->ud.target != tbl->id || md->ud.attacktimer == INVALID_TIMER) + { //Only use skill if no more attack delay left + md->state.skillstate = MSS_IDLE; + if (!(++md->ud.walk_count%IDLE_SKILL_INTERVAL)) + mob->skill_use(md, tick, -1); + } return true; } @@ -1654,6 +1656,10 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { )) //Current target tile is still within attack range. return true; + //Only update target cell after having moved at least "mob_chase_refresh" cells + if(md->ud.walktimer != INVALID_TIMER && md->ud.walkpath.path_pos <= battle_config.mob_chase_refresh) + return true; + //Follow up if possible. if(!mob->can_reach(md, tbl, md->min_chase, MSS_RUSH) || !unit->walktobl(&md->bl, tbl, md->status.rhw.range, 2)) |