From 402a20fbba16a9ba320db0e470dbaf0f62c3b90d Mon Sep 17 00:00:00 2001 From: "Guilherme G. Menaldo" Date: Wed, 28 Mar 2018 16:23:26 -0300 Subject: Added delay to tomb spawn --- src/map/battle.c | 1 + src/map/battle.h | 1 + src/map/mob.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/map/mob.h | 2 ++ src/map/npc.h | 1 + 5 files changed, 53 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/battle.c b/src/map/battle.c index bd7e31d05..b2490ed23 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -7265,6 +7265,7 @@ static const struct battle_data { { "atcommand_max_stat_bypass", &battle_config.atcommand_max_stat_bypass, 0, 0, 100, }, { "skill_amotion_leniency", &battle_config.skill_amotion_leniency, 90, 0, 300 }, { "mvp_tomb_enabled", &battle_config.mvp_tomb_enabled, 1, 0, 1 }, + { "mvp_tomb_spawn_delay", &battle_config.mvp_tomb_spawn_delay, 10000, 0, INT_MAX }, { "features/atcommand_suggestions", &battle_config.atcommand_suggestions_enabled, 0, 0, 1 }, { "min_npc_vendchat_distance", &battle_config.min_npc_vendchat_distance, 3, 0, 100 }, { "vendchat_near_hiddennpc", &battle_config.vendchat_near_hiddennpc, 0, 0, 1 }, diff --git a/src/map/battle.h b/src/map/battle.h index 8b7fea29f..9eb7557f8 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -490,6 +490,7 @@ struct Battle_Config { int vcast_stat_scale; int mvp_tomb_enabled; + int mvp_tomb_spawn_delay; int atcommand_suggestions_enabled; int min_npc_vendchat_distance; diff --git a/src/map/mob.c b/src/map/mob.c index e93c9009d..f2927738e 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -157,6 +157,44 @@ int mobdb_searchname_array_sub(struct mob_db* monster, const char *str, int flag /*========================================== * MvP Tomb [GreenBox] *------------------------------------------*/ + /// Creates a timer to spawn a tomb + /// @param nd : The tomb +void mvptomb_spawn_delayed(struct npc_data *nd) +{ + nullpo_retv(nd); + + if (nd->u.tomb.spawn_timer != INVALID_TIMER) + timer->delete(nd->u.tomb.spawn_timer, mob->mvptomb_delayspawn); + + nd->u.tomb.spawn_timer = timer->add(timer->gettick() + battle_config.mvp_tomb_spawn_delay, mob->mvptomb_delayspawn, nd->bl.id, 0); +} + +/// Spawns a tomb after the delay has ended +/// @param tid : Timer id +/// @param tick : current tick +/// @param id : NPC Id +/// @param data : 0 +int mvptomb_delayspawn(int tid, int64 tick, int id, intptr_t data) +{ + struct npc_data *nd = map->id2nd(id); + + if (nd == NULL) + return 0; + + if (nd->u.tomb.spawn_timer != tid) { + ShowError("mvptomb_delay_spawn: Timer mismatch: %d != %d\n", tid, nd->u.tomb.spawn_timer); + return 0; + } + + nd->u.tomb.spawn_timer = INVALID_TIMER; + + // Sets view data to make the tomb visible and notifies client + status->set_viewdata(&nd->bl, nd->class_); + clif->spawn(&(nd->bl)); + + return 0; +} + void mvptomb_create(struct mob_data *md, char *killer, time_t time) { struct npc_data *nd; @@ -172,6 +210,7 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time) nd->u.tomb.md = md; nd->u.tomb.kill_time = time; + nd->u.tomb.spawn_timer = INVALID_TIMER; if (killer) safestrncpy(nd->u.tomb.killer_name, killer, NAME_LENGTH); @@ -180,8 +219,9 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time) map->addnpc(nd->bl.m, nd); map->addblock(&nd->bl); - status->set_viewdata(&nd->bl, nd->class_); - clif->spawn(&nd->bl); + + // Tomb npc is created but not yet visible, we set view data and spawn it after some time + mob->mvptomb_spawn_delayed(nd); } void mvptomb_destroy(struct mob_data *md) { @@ -204,6 +244,9 @@ void mvptomb_destroy(struct mob_data *md) { map->list[m].npc[map->list[m].npc_num] = NULL; } + if (nd->u.tomb.spawn_timer != INVALID_TIMER) + timer->delete(nd->u.tomb.spawn_timer, mob->mvptomb_delayspawn); + map->deliddb(&nd->bl); aFree(nd); @@ -5189,6 +5232,7 @@ int do_init_mob(bool minimal) { timer->add_func_list(mob->timer_delete,"mob_timer_delete"); timer->add_func_list(mob->spawn_guardian_sub,"mob_spawn_guardian_sub"); timer->add_func_list(mob->respawn,"mob_respawn"); + timer->add_func_list(mob->mvptomb_delayspawn, "mvptomb_delayspawn"); timer->add_interval(timer->gettick()+MIN_MOBTHINKTIME,mob->ai_hard,0,0,MIN_MOBTHINKTIME); timer->add_interval(timer->gettick()+MIN_MOBTHINKTIME*10,mob->ai_lazy,0,0,MIN_MOBTHINKTIME*10); @@ -5295,6 +5339,8 @@ void mob_defaults(void) { mob->db_searchname_array_sub = mobdb_searchname_array_sub; mob->mvptomb_create = mvptomb_create; mob->mvptomb_destroy = mvptomb_destroy; + mob->mvptomb_spawn_delayed = mvptomb_spawn_delayed; + mob->mvptomb_delayspawn = mvptomb_delayspawn; mob->db_searchname_array = mobdb_searchname_array; mob->db_checkid = mobdb_checkid; mob->get_viewdata = mob_get_viewdata; diff --git a/src/map/mob.h b/src/map/mob.h index 3d1b3aadf..2a1a729de 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -447,6 +447,8 @@ struct mob_interface { int (*db_searchname) (const char *str); int (*db_searchname_array_sub) (struct mob_db *monster, const char *str, int flag); // MvP Tomb System + void (*mvptomb_spawn_delayed) (struct npc_data *nd); + int (*mvptomb_delayspawn) (int tid, int64 tick, int id, intptr_t data); void (*mvptomb_create) (struct mob_data *md, char *killer, time_t time); void (*mvptomb_destroy) (struct mob_data *md); int (*db_searchname_array) (struct mob_db **data, int size, const char *str, int flag); diff --git a/src/map/npc.h b/src/map/npc.h index 64a2b3a51..d40e352f4 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -122,6 +122,7 @@ struct npc_data { struct mob_data *md; time_t kill_time; char killer_name[NAME_LENGTH]; + int spawn_timer; } tomb; } u; struct hplugin_data_store *hdata; ///< HPM Plugin Data Store -- cgit v1.2.3-60-g2f50