Skip to content

Commit

Permalink
Additional configs for mobs idle AI (#4503)
Browse files Browse the repository at this point in the history
* Added conf options to enable/disable monsters using idle skills and move when there's no players nearby.

Thanks to @aleos89
Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>
  • Loading branch information
Daegaladh committed Jan 2, 2020
1 parent c52b3b7 commit e27aa8b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
11 changes: 11 additions & 0 deletions conf/battle/monster.conf
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,14 @@ monster_hp_bars_info: yes
// This can be legit gameplay (e.g. players keeping an MVP stuck inside icewall), but if you want to prevent any
// exploits and be notified about them, you can set this to yes.
monster_stuck_warning: no

// Rate at which monsters use their idle skills when there are no players nearby (Note 2)
// On official servers monsters use their idle skills if they have been spotted once, even if there are no players nearby anymore.
// On small-medium sized servers this can cause all monsters like eggs and Fabre/Pupa to metamorph.
// To switch it off, set it to 0.
mob_nopc_idleskill_rate: 100

// Rate at which monsters move when there are no players nearby (Note 2)
// On official servers monsters always move if they have been spotted once, even if there are no players nearby anymore.
// To switch it off, set it to 0.
mob_nopc_move_rate: 100
2 changes: 2 additions & 0 deletions src/map/battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8557,6 +8557,8 @@ static const struct _battle_data {
{ "feature.equipswitch", &battle_config.feature_equipswitch, 1, 0, 1, },
{ "pet_walk_speed", &battle_config.pet_walk_speed, 1, 1, 3, },
{ "blacksmith_fame_refine_threshold", &battle_config.blacksmith_fame_refine_threshold,10, 1, MAX_REFINE, },
{ "mob_nopc_idleskill_rate", &battle_config.mob_nopc_idleskill_rate, 100, 0, 100, },
{ "mob_nopc_move_rate", &battle_config.mob_nopc_move_rate, 100, 0, 100, },

#include "../custom/battle_config_init.inc"
};
Expand Down
2 changes: 2 additions & 0 deletions src/map/battle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ struct Battle_Config
int feature_equipswitch;
int pet_walk_speed;
int blacksmith_fame_refine_threshold;
int mob_nopc_idleskill_rate;
int mob_nopc_move_rate;

#include "../custom/battle_config_struct.inc"
};
Expand Down
15 changes: 7 additions & 8 deletions src/map/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ using namespace rathena;

#define IDLE_SKILL_INTERVAL 10 //Active idle skills should be triggered every 1 second (1000/MIN_MOBTHINKTIME)

// Probability for mobs far from players from doing their IDLE skill. (rate of 1000 minute)
// in Aegis, this is 100% for mobs that have been activated by players and none otherwise.
#define MOB_LAZYSKILLPERC(md) (mob_is_spotted(md)?1000:0)
// Move probability for mobs away from players (rate of 1000 minute)
// in Aegis, this is 100% for mobs that have been activated by players and none otherwise.
#define MOB_LAZYMOVEPERC(md) (mob_is_spotted(md)?1000:0)
const t_tick MOB_MAX_DELAY = 24 * 3600 * 1000;
#define MAX_MINCHASE 30 //Max minimum chase value to use for mobs.
#define RUDE_ATTACKED_COUNT 1 //After how many rude-attacks should the skill be used?
Expand Down Expand Up @@ -2052,14 +2046,19 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args)

if( DIFF_TICK(md->next_walktime,tick) < 0 && status_has_mode(&md->status,MD_CANMOVE) && unit_can_move(&md->bl) )
{
if( rnd()%1000 < MOB_LAZYMOVEPERC(md) )
// Move probability for mobs away from players
// In Aegis, this is 100% for mobs that have been activated by players and none otherwise.
if( mob_is_spotted(md) && rnd()%100 < battle_config.mob_nopc_move_rate )
mob_randomwalk(md, tick);
}
else if( md->ud.walktimer == INVALID_TIMER )
{
//Because it is not unset when the mob finishes walking.
md->state.skillstate = MSS_IDLE;
if( rnd()%1000 < MOB_LAZYSKILLPERC(md) ) //Chance to do a mob's idle skill.

// Probability for mobs far from players from doing their IDLE skill.
// In Aegis, this is 100% for mobs that have been activated by players and none otherwise.
if( mob_is_spotted(md) && rnd()%100 < battle_config.mob_nopc_idleskill_rate )
mobskill_use(md, tick, -1);
}

Expand Down

0 comments on commit e27aa8b

Please sign in to comment.