summaryrefslogtreecommitdiff
path: root/src/map/mob.c
diff options
context:
space:
mode:
authorKenpachi Developer <Kenpachi.Developer@gmx.de>2020-01-05 12:59:47 +0100
committerHaru <haru@dotalux.com>2020-02-09 20:23:14 +0100
commit6e4c66213fca0fd482e1d983a4e3307f08619e5c (patch)
tree32b65f068cafbcf769075a2cc621788aa5e504c1 /src/map/mob.c
parent7d7e4943617ba49020e2453c0931424f65691d24 (diff)
downloadhercules-6e4c66213fca0fd482e1d983a4e3307f08619e5c.tar.gz
hercules-6e4c66213fca0fd482e1d983a4e3307f08619e5c.tar.bz2
hercules-6e4c66213fca0fd482e1d983a4e3307f08619e5c.tar.xz
hercules-6e4c66213fca0fd482e1d983a4e3307f08619e5c.zip
Applied code style and added some minor code improvements to src/map/mob.c.
Diffstat (limited to 'src/map/mob.c')
-rw-r--r--src/map/mob.c809
1 files changed, 472 insertions, 337 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index d65108a62..6c1076114 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -337,9 +337,15 @@ static int mob_parse_dataset(struct spawn_data *data)
return 1;
}
-/*==========================================
- * Generates the basic mob data using the spawn_data provided.
- *------------------------------------------*/
+
+/**
+ * Generates basic mob data by using the passed spawn data.
+ *
+ * @param data The mobs spawn data.
+ * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC.
+ * @return The generated mob data, later used to spawn the mob.
+ *
+ **/
static struct mob_data *mob_spawn_dataset(struct spawn_data *data, int npc_id)
{
nullpo_retr(NULL, data);
@@ -510,7 +516,24 @@ static bool mob_ksprotected(struct block_list *src, struct block_list *target)
return false;
}
-static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int class_, const char *event, unsigned int size, unsigned int ai, int npc_id)
+/**
+ * Prepares a mob's spawn data.
+ *
+ * @param bl The invoking character's block list.
+ * @param m The ID of the map where the mob should be spawned.
+ * @param x The x coordinate where the mob should be spawned.
+ * @param y The y coordinate where the mob should be spawned.
+ * @param mobname The mob's display name.
+ * @param class_ The mob's ID in database.
+ * @param event The name of the event which should be executed when the mob is killed.
+ * @param size The mob's size.
+ * @param ai The mob's AI.
+ * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC.
+ * @return The mob data generated by mob->spawn_dataset().
+ *
+ **/
+static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int class_,
+ const char *event, unsigned int size, unsigned int ai, int npc_id)
{
struct spawn_data data;
@@ -531,11 +554,11 @@ static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16
if (event != NULL)
safestrncpy(data.eventname, event, sizeof(data.eventname));
- /** Locate spot next to player. */
+ /** Locate spot next to player. **/
if (bl != NULL && (x < 0 || y < 0))
map->search_freecell(bl, m, &x, &y, 1, 1, 0);
- /** If none found, pick random position on map. */
+ /** If none found, pick random position on map. **/
if (x <= 0 || x >= map->list[m].xs || y <= 0 || y >= map->list[m].ys)
map->search_freecell(NULL, m, &x, &y, -1, -1, 1);
@@ -548,56 +571,80 @@ static struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16
return mob->spawn_dataset(&data, npc_id);
}
-/*==========================================
- * Spawn a single mob on the specified coordinates.
- *------------------------------------------*/
-static int mob_once_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *mobname, int class_, int amount, const char *event, unsigned int size, unsigned int ai)
+/**
+ * Spawns a given amount of mobs.
+ *
+ * @param sd The invoking character.
+ * @param m The ID of the map where the mob should be spawned.
+ * @param x The x coordinate where the mob should be spawned.
+ * @param y The y coordinate where the mob should be spawned.
+ * @param mobname The mob's display name.
+ * @param class_ The mob's ID in database.
+ * @param amount The amount of mobs to spawn.
+ * @param event The name of the event which should be executed when the mob is killed.
+ * @param size The mob's size.
+ * @param ai The mob's AI.
+ * @return The last spawned mob's GID, or 0 if spawning failed.
+ *
+ **/
+static int mob_once_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *mobname, int class_,
+ int amount, const char *event, unsigned int size, unsigned int ai)
{
- struct mob_data* md = NULL;
- int count, lv;
bool no_guardian_data = false;
- if( ai && ai&0x200 ) {
+ if (ai > 0 && (ai & 0x200) == 0x200) {
no_guardian_data = true;
- ai &=~ 0x200;
+ ai &= ~0x200;
}
if (m < 0 || amount <= 0)
- return 0; // invalid input
+ return 0;
- lv = (sd) ? sd->status.base_level : 255;
+ struct mob_data *md = NULL;
+
+ for (int i = 0; i < amount; i++) {
+ int mob_id = class_;
+
+ if (mob_id < 0) {
+ mob_id = mob->get_random_id(-class_ - 1, (battle_config.random_monster_checklv == 1) ? 3 : 1,
+ (sd != NULL) ? sd->status.base_level : 255);
+ }
- for (count = 0; count < amount; count++) {
- int c = (class_ >= 0) ? class_ : mob->get_random_id(-class_ - 1, (battle_config.random_monster_checklv) ? 3 : 1, lv);
- md = mob->once_spawn_sub((sd != NULL) ? &sd->bl : NULL, m, x, y, mobname, c, event, size, ai, (sd != NULL) ? sd->npc_id : 0);
+ md = mob->once_spawn_sub((sd != NULL) ? &sd->bl : NULL, m, x, y, mobname, mob_id, event, size, ai,
+ (sd != NULL) ? sd->npc_id : 0);
- if (!md)
+ if (md == NULL)
continue;
if (class_ == MOBID_EMPELIUM && !no_guardian_data) {
- struct guild_castle* gc = guild->mapindex2gc(map_id2index(m));
- struct guild* g = (gc) ? guild->search(gc->guild_id) : NULL;
- if( gc ) {
+ struct guild_castle *gc = guild->mapindex2gc(map_id2index(m));
+
+ if (gc != NULL) {
+ struct guild *g = guild->search(gc->guild_id);
+
md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data));
md->guardian_data->castle = gc;
md->guardian_data->number = MAX_GUARDIANS;
- if( g )
+
+ if (g != NULL)
md->guardian_data->g = g;
- else if( gc->guild_id ) //Guild not yet available, retry in 5.
- timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id);
+ else if (gc->guild_id > 0) /// Guild not yet available, retry in 5s.
+ timer->add(timer->gettick() + 5000, mob->spawn_guardian_sub, md->bl.id,
+ gc->guild_id);
}
- } // end addition [Valaris]
+ }
mob->spawn(md);
- if (class_ < 0 && battle_config.dead_branch_active) {
- //Behold Aegis's masterful decisions yet again...
- //"I understand the "Aggressive" part, but the "Can Move" and "Can Attack" is just stupid" - Poki#3
- sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE|MD_CANATTACK|MD_CANMOVE|MD_ANGRY, 0, 60000);
+ if (class_ < 0 && battle_config.dead_branch_active == 1) {
+ /// Behold Aegis' masterful decisions yet again...
+ /// "I understand the "Aggressive" part, but the "Can Move" and "Can Attack" is just stupid" [Poki]
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE|MD_CANATTACK|MD_CANMOVE|MD_ANGRY,
+ 0, 60000);
}
}
- return (md) ? md->bl.id : 0; // id of last spawned mob
+ return (md != NULL) ? md->bl.id : 0; /// ID of last spawned mob.
}
/*==========================================
@@ -656,196 +703,236 @@ static int mob_once_spawn_area(struct map_session_data *sd, int16 m, int16 x0, i
}
/**
- * Sets a guardian's guild data and liberates castle if couldn't retrieve guild data
- * @param data (int)guild_id
- * @retval Always 0
+ * Sets a guardian's guild data and liberates castle if couldn't retrieve guild data.
+ * Required because the guild data may not be available at guardian spawn time.
+ *
+ * @param tid Required parameter for timer functions. Unused inside the function.
+ * @param tick Required parameter for timer functions. Unused inside the function.
+ * @param id The guardian mob's GID.
+ * @param data The guild ID.
+ * @return 1 on success, 0 on failure.
+ *
* @author Skotlex
+ *
**/
static int mob_spawn_guardian_sub(int tid, int64 tick, int id, intptr_t data)
{
- //Needed because the guild data may not be available at guardian spawn time.
- struct block_list* bl = map->id2bl(id);
- struct mob_data* md;
- struct guild* g;
+ struct block_list *bl = map->id2bl(id);
- if( bl == NULL ) //It is possible mob was already removed from map when the castle has no owner. [Skotlex]
+ if (bl == NULL || bl->type != BL_MOB) /// It is possible mob was already removed from map when the castle has no owner. [Skotlex]
return 0;
- Assert_ret(bl->type == BL_MOB);
- md = BL_UCAST(BL_MOB, bl);
+ struct mob_data *md = BL_UCAST(BL_MOB, bl);
+
+ if (md->guardian_data == NULL)
+ return 0;
- nullpo_ret(md->guardian_data);
- g = guild->search((int)data);
+ struct guild *g = guild->search((int)data);
- if( g == NULL ) { //Liberate castle, if the guild is not found this is an error! [Skotlex]
+ if (g == NULL) { /// Liberate castle, if the guild is not found this is an error! [Skotlex]
ShowError("mob_spawn_guardian_sub: Couldn't load guild %d!\n", (int)data);
- //Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on.
- if (md->class_ == MOBID_EMPELIUM && md->guardian_data) {
+
+ /// Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on.
+ if (md->class_ == MOBID_EMPELIUM) {
md->guardian_data->g = NULL;
- if( md->guardian_data->castle->guild_id ) {//Free castle up.
- ShowNotice("Clearing ownership of castle %d (%s)\n", md->guardian_data->castle->castle_id, md->guardian_data->castle->castle_name);
+
+ if (md->guardian_data->castle->guild_id > 0) { /// Free castle up.
+ ShowNotice("mob_spawn_guardian_sub: Clearing ownership of castle %d (%s).\n",
+ md->guardian_data->castle->castle_id,
+ md->guardian_data->castle->castle_name);
guild->castledatasave(md->guardian_data->castle->castle_id, 1, 0);
}
} else {
- if( md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS
- && md->guardian_data->castle->guardian[md->guardian_data->number].visible )
- guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
+ if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS &&
+ md->guardian_data->castle->guardian[md->guardian_data->number].visible == 1)
+ guild->castledatasave(md->guardian_data->castle->castle_id,
+ 10 + md->guardian_data->number, 0);
- unit->free(&md->bl,CLR_OUTSIGHT); // Remove guardian.
+ unit->free(&md->bl, CLR_OUTSIGHT); /// Remove guardian.
}
+
return 0;
}
- if( guild->checkskill(g,GD_GUARDUP) )
- status_calc_mob(md, SCO_NONE); // Give bonuses.
+ if (guild->checkskill(g, GD_GUARDUP) > 0)
+ status_calc_mob(md, SCO_NONE); /// Give bonuses.
- return 0;
+ return 1;
}
-/*==========================================
- * Summoning Guardians [Valaris]
- *------------------------------------------*/
-static int mob_spawn_guardian(const char *mapname, short x, short y, const char *mobname, int class_, const char *event, int guardian, bool has_index, int npc_id)
+/**
+ * Summons a castle guardian mob.
+ *
+ * @param mapname The name of the map where the guardian should be spawned.
+ * @param x The x coordinate where the guardian should be spawned.
+ * @param y The y coordinate where the guardian should be spawned.
+ * @param mobname The guardian's display name.
+ * @param class_ The guardian's mob ID in database.
+ * @param event The name of the event which should be executed when the guardian is killed.
+ * @param guardian The guardian's index.
+ * @param has_index If false, the guardian will be temporarily.
+ * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC.
+ * @return The spawned guardian's GID, or 0 if spawning failed.
+ *
+ * @author Valaris
+ *
+ **/
+static int mob_spawn_guardian(const char *mapname, short x, short y, const char *mobname, int class_, const char *event,
+ int guardian, bool has_index, int npc_id)
{
- struct mob_data *md=NULL;
- struct spawn_data data;
- struct guild *g=NULL;
- struct guild_castle *gc;
- int16 m;
-
nullpo_ret(mapname);
nullpo_ret(mobname);
nullpo_ret(event);
- memset(&data, 0, sizeof(struct spawn_data));
- data.num = 1;
+ const int map_id = map->mapname2mapid(mapname);
- m=map->mapname2mapid(mapname);
-
- if(m<0)
- {
+ if (map_id == INDEX_NOT_FOUND) {
ShowWarning("mob_spawn_guardian: Map [%s] not found.\n", mapname);
return 0;
}
- data.m = m;
- data.num = 1;
- if(class_<=0) {
- class_ = mob->get_random_id(-class_-1, 1, 99);
- if (!class_) return 0;
+
+ if ((x <= 0 || y <= 0) && map->search_freecell(NULL, map_id, &x, &y, -1, -1, 1) == 0) {
+ ShowWarning("mob_spawn_guardian: Couldn't locate a spawn cell for guardian class %d (index %d) on castle map %s.\n",
+ class_, guardian, mapname);
+ return 0;
}
- data.class_ = class_;
+ if (class_ <= 0 && (class_ = mob->get_random_id(-class_ - 1, 1, 99)) == 0)
+ return 0;
- if( !has_index ) {
+ if (!has_index) {
guardian = -1;
- } else if( guardian < 0 || guardian >= MAX_GUARDIANS ) {
- ShowError("mob_spawn_guardian: Invalid guardian index %d for guardian %d (castle map %s)\n", guardian, class_, map->list[m].name);
+ } else if (guardian < 0 || guardian >= MAX_GUARDIANS) {
+ ShowError("mob_spawn_guardian: Invalid guardian index %d for guardian %d on castle map %s.\n",
+ guardian, class_, mapname);
return 0;
}
- if((x<=0 || y<=0) && !map->search_freecell(NULL, m, &x, &y, -1,-1, 1)) {
- ShowWarning("mob_spawn_guardian: Couldn't locate a spawn cell for guardian class %d (index %d) at castle map %s\n",class_, guardian, map->list[m].name);
- return 0;
- }
+ struct spawn_data data;
+
+ memset(&data, 0, sizeof(struct spawn_data));
+ data.num = 1;
+ data.m = map_id;
+ data.class_ = class_;
data.x = x;
data.y = y;
safestrncpy(data.name, mobname, sizeof(data.name));
safestrncpy(data.eventname, event, sizeof(data.eventname));
- if (!mob->parse_dataset(&data))
+
+ if (mob->parse_dataset(&data) == 0)
return 0;
- gc=guild->mapname2gc(map->list[m].name);
+ struct guild_castle *gc = guild->mapname2gc(mapname);
+
if (gc == NULL) {
- ShowError("mob_spawn_guardian: No castle set at map %s\n", map->list[m].name);
+ ShowError("mob_spawn_guardian: No castle set on map %s.\n", mapname);
return 0;
}
- if (!gc->guild_id)
- ShowWarning("mob_spawn_guardian: Spawning guardian %d on a castle with no guild (castle map %s)\n", class_, map->list[m].name);
+
+ struct guild *g = NULL;
+
+ if (gc->guild_id == 0)
+ ShowWarning("mob_spawn_guardian: Spawning guardian %d on a castle map %s with no guild.\n",
+ class_, mapname);
else
g = guild->search(gc->guild_id);
- if( has_index && gc->guardian[guardian].id ) {
- //Check if guardian already exists, refuse to spawn if so.
- struct block_list *bl2 = map->id2bl(gc->guardian[guardian].id); // TODO: Why does this not use map->id2md?
- struct mob_data *md2 = BL_CAST(BL_MOB, bl2);
- if (md2 != NULL && md2->guardian_data != NULL && md2->guardian_data->number == guardian) {
- ShowError("mob_spawn_guardian: Attempted to spawn guardian in position %d which already has a guardian (castle map %s)\n", guardian, map->list[m].name);
+ if (has_index && gc->guardian[guardian].id != 0) { /// Check if guardian already exists, refuse to spawn if so.
+ struct mob_data *md = map->id2md(gc->guardian[guardian].id);
+
+ if (md != NULL && md->guardian_data != NULL && md->guardian_data->number == guardian) {
+ ShowError("mob_spawn_guardian: Attempted to spawn guardian in position %d which already has a guardian on castle map %s.\n",
+ guardian, mapname);
return 0;
}
}
- md = mob->spawn_dataset(&data, npc_id);
+ struct mob_data *md = mob->spawn_dataset(&data, npc_id);
+
md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data));
md->guardian_data->number = guardian;
md->guardian_data->castle = gc;
- if( has_index )
- {// permanent guardian
+
+ if (has_index) { /// Permanent guardian.
gc->guardian[guardian].id = md->bl.id;
- }
- else
- {// temporary guardian
+ } else { /// Temporary guardian.
int i;
+
ARR_FIND(0, gc->temp_guardians_max, i, gc->temp_guardians[i] == 0);
- if( i == gc->temp_guardians_max )
- {
+
+ if (i == gc->temp_guardians_max) {
++(gc->temp_guardians_max);
RECREATE(gc->temp_guardians, int, gc->temp_guardians_max);
}
+
gc->temp_guardians[i] = md->bl.id;
}
- if( g )
+
+ if (g != NULL)
md->guardian_data->g = g;
- else if( gc->guild_id )
- timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id);
- mob->spawn(md);
+ else if (gc->guild_id > 0)
+ timer->add(timer->gettick() + 5000, mob->spawn_guardian_sub, md->bl.id, gc->guild_id);
+ mob->spawn(md);
return md->bl.id;
}
-/*==========================================
- * Summoning BattleGround [Zephyrus]
- *------------------------------------------*/
-static int mob_spawn_bg(const char *mapname, short x, short y, const char *mobname, int class_, const char *event, unsigned int bg_id, int npc_id)
+/**
+ * Spawn a mob with allegiance to the given battle group.
+ *
+ * @param mapname The name of the map where the mob should be spawned.
+ * @param x The x coordinate where the mob should be spawned.
+ * @param y The y coordinate where the mob should be spawned.
+ * @param mobname The mob's display name.
+ * @param class_ The mob's mob ID in database.
+ * @param event The name of the event which should be executed when the mob is killed.
+ * @param bg_id The battle group ID.
+ * @param npc_id If spawned by NPC script, this holds the ID of the invoking NPC.
+ * @return The spawned mob's GID, or 0 if spawning failed.
+ *
+ * @author Zephyrus
+ *
+ **/
+static int mob_spawn_bg(const char *mapname, short x, short y, const char *mobname, int class_, const char *event,
+ unsigned int bg_id, int npc_id)
{
- struct mob_data *md = NULL;
- struct spawn_data data;
- int16 m;
-
nullpo_ret(mapname);
nullpo_ret(mobname);
nullpo_ret(event);
- if( (m = map->mapname2mapid(mapname)) < 0 ) {
+ const int map_id = map->mapname2mapid(mapname);
+
+ if (map_id == INDEX_NOT_FOUND) {
ShowWarning("mob_spawn_bg: Map [%s] not found.\n", mapname);
return 0;
}
- memset(&data, 0, sizeof(struct spawn_data));
- data.m = m;
- data.num = 1;
- if( class_ <= 0 )
- {
- class_ = mob->get_random_id(-class_-1,1,99);
- if( !class_ ) return 0;
+ if ((x <= 0 || y <= 0) && map->search_freecell(NULL, map_id, &x, &y, -1, -1, 1) == 0) {
+ ShowWarning("mob_spawn_bg: Couldn't locate a spawn cell for guardian class %d (bg_id %u) on map %s.\n", class_, bg_id, mapname);
+ return 0;
}
- data.class_ = class_;
- if( (x <= 0 || y <= 0) && !map->search_freecell(NULL, m, &x, &y, -1,-1, 1) ) {
- ShowWarning("mob_spawn_bg: Couldn't locate a spawn cell for guardian class %d (bg_id %u) at map %s\n", class_, bg_id, map->list[m].name);
+ if (class_ <= 0 && (class_ = mob->get_random_id(-class_ - 1, 1, 99)) == 0)
return 0;
- }
+ struct spawn_data data;
+
+ memset(&data, 0, sizeof(struct spawn_data));
+ data.num = 1;
+ data.m = map_id;
+ data.class_ = class_;
data.x = x;
data.y = y;
safestrncpy(data.name, mobname, sizeof(data.name));
safestrncpy(data.eventname, event, sizeof(data.eventname));
- if( !mob->parse_dataset(&data) )
+
+ if (mob->parse_dataset(&data) == 0)
return 0;
- md = mob->spawn_dataset(&data, npc_id);
- mob->spawn(md);
- md->bg_id = bg_id; // BG Team ID
+ struct mob_data *md = mob->spawn_dataset(&data, npc_id);
+ mob->spawn(md);
+ md->bg_id = bg_id;
return md->bl.id;
}
@@ -3107,18 +3194,25 @@ static int mob_countslave(struct block_list *bl)
return map->foreachinmap(mob->countslave_sub, bl->m, BL_MOB,bl->id);
}
-/*==========================================
- * Summons amount slaves contained in the value[5] array using round-robin. [adapted by Skotlex]
- *------------------------------------------*/
+/**
+ * Summons amount slaves contained in the value[5] array using round-robin.
+ *
+ * @param md2 The mob which summons the slaves.
+ * @param value Array with slave mob IDs.
+ * @param amount The amount of slaves to spawn.
+ * @param skill_id The Id of the skill which summons the slaves.
+ * @return 1 on success, 0 on failure.
+ *
+ * @author Skotlex
+ *
+ **/
static int mob_summonslave(struct mob_data *md2, int *value, int amount, uint16 skill_id)
{
- struct mob_data *md;
- struct spawn_data data;
- int count = 0,k=0,hp_rate=0;
-
nullpo_ret(md2);
nullpo_ret(value);
+ struct spawn_data data;
+
memset(&data, 0, sizeof(struct spawn_data));
data.m = md2->bl.m;
data.x = md2->bl.x;
@@ -3127,31 +3221,42 @@ static int mob_summonslave(struct mob_data *md2, int *value, int amount, uint16
data.state.size = md2->special_state.size;
data.state.ai = md2->special_state.ai;
- if(mob->db_checkid(value[0]) == 0)
+ if (mob->db_checkid(value[0]) == 0)
+ return 0;
+
+ md2->can_summon = 1; /// Flags this monster is able to summon; saves a worth amount of memory upon deletion.
+
+ int count = 0;
+
+ while (count < 5 && mob->db_checkid(value[count]) != 0)
+ count++;
+
+ if (count < 1)
return 0;
- /**
- * Flags this monster is able to summon; saves a worth amount of memory upon deletion
- **/
- md2->can_summon = 1;
- while(count < 5 && mob->db_checkid(value[count])) count++;
- if(count < 1) return 0;
- if (amount > 0 && amount < count) { //Do not start on 0, pick some random sub subset [Skotlex]
- k = rnd()%count;
- amount+=k; //Increase final value by same amount to preserve total number to summon.
+ int k = 0;
+
+ if (amount > 0 && amount < count) { /// Do not start on 0, pick some random sub subset. [Skotlex]
+ k = rnd() % count;
+ amount += k; /// Increase final value by same amount to preserve total number to summon.
}
- if (!battle_config.monster_class_change_recover &&
- (skill_id == NPC_TRANSFORMATION || skill_id == NPC_METAMORPHOSIS))
+ int hp_rate = 0;
+
+ if ((skill_id == NPC_TRANSFORMATION || skill_id == NPC_METAMORPHOSIS) &&
+ battle_config.monster_class_change_recover == 0)
hp_rate = get_percentage(md2->status.hp, md2->status.max_hp);
- for(;k<amount;k++) {
- short x,y;
- data.class_ = value[k%count]; //Summon slaves in round-robin fashion. [Skotlex]
+ for (; k < amount; k++) {
+ data.class_ = value[k % count]; /// Summon slaves in round-robin fashion. [Skotlex]
+
if (mob->db_checkid(data.class_) == 0)
continue;
- if (map->search_freecell(&md2->bl, 0, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 0)) {
+ short x;
+ short y;
+
+ if (map->search_freecell(&md2->bl, 0, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 0) != 0) {
data.x = x;
data.y = y;
} else {
@@ -3159,49 +3264,52 @@ static int mob_summonslave(struct mob_data *md2, int *value, int amount, uint16
data.y = md2->bl.y;
}
- //These two need to be loaded from the db for each slave.
if (battle_config.override_mob_names == 1)
strcpy(data.name, DEFAULT_MOB_NAME);
else
strcpy(data.name, DEFAULT_MOB_JNAME);
- if (!mob->parse_dataset(&data))
+ if (mob->parse_dataset(&data) == 0)
continue;
- md = mob->spawn_dataset(&data, 0);
- if(skill_id == NPC_SUMMONSLAVE){
- md->master_id=md2->bl.id;
+ struct mob_data *md = mob->spawn_dataset(&data, 0);
+
+ if (skill_id == NPC_SUMMONSLAVE) {
+ md->master_id = md2->bl.id;
md->special_state.ai = md2->special_state.ai;
}
+
mob->spawn(md);
- if (hp_rate) //Scale HP
- md->status.hp = md->status.max_hp*hp_rate/100;
+ if (hp_rate > 0) /// Scale HP.
+ md->status.hp = md->status.max_hp * hp_rate / 100;
- //Inherit the aggressive mode of the master.
- if (battle_config.slaves_inherit_mode && md->master_id) {
+ /** Inherit the aggressive mode of the master. **/
+ if (battle_config.slaves_inherit_mode > 0 && md->master_id > 0) {
switch (battle_config.slaves_inherit_mode) {
- case 1: //Always aggressive
- if (!(md->status.mode&MD_AGGRESSIVE))
- sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0);
+ case 1: /// Always aggressive.
+ if ((md->status.mode & MD_AGGRESSIVE) == 0)
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 0);
+
break;
- case 2: //Always passive
- if (md->status.mode&MD_AGGRESSIVE)
- sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0);
+ case 2: /// Always passive.
+ if ((md->status.mode & MD_AGGRESSIVE) == MD_AGGRESSIVE)
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, 0, MD_AGGRESSIVE, 0);
+
break;
- default: //Copy master.
- if (md2->status.mode&MD_AGGRESSIVE)
- sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0);
+ default: /// Copy master.
+ if ((md2->status.mode & MD_AGGRESSIVE) == MD_AGGRESSIVE)
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 0);
else
- sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0);
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, 0, MD_AGGRESSIVE, 0);
break;
}
}
- clif->skill_nodamage(&md->bl,&md->bl,skill_id,amount,1);
+ clif->skill_nodamage(&md->bl, &md->bl, skill_id, amount, 1);
}
- return 0;
+ return 1;
}
/*==========================================
@@ -3595,211 +3703,238 @@ static int mob_is_clone(int class_)
return class_;
}
-//Flag values:
-//&1: Set special AI (fight mobs, not players)
-//If mode is not passed, a default aggressive mode is used.
-//If master_id is passed, clone is attached to him.
-//Returns: ID of newly crafted copy.
-static int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, uint32 mode, int flag, unsigned int duration)
+/**
+ * Spawns a mob which is a clone of another character.
+ *
+ * @param sd The character which should be cloned.
+ * @param m The ID of the map where the clone should be spawned.
+ * @param x The x coordinate where the clone should be spawned.
+ * @param y The y coordinate where the clone should be spawned.
+ * @param event The name of the event which should be executed when the clone is killed.
+ * @param master_id If passed, the clone will be attached to this account ID.
+ * @param mode The clone's mob mode(s). (Defaults to MD_CANMOVE|MD_AGGRESSIVE|MD_ASSIST|MD_CANATTACK.)
+ * @param flag 0 - target characters; 1 - target mobs.
+ * @param duration How long the clone will live before it is auto-removed. (ms)
+ * @return The spawned clone's GID, or 0 if spawning failed.
+ *
+ **/
+static int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id,
+ uint32 mode, int flag, unsigned int duration)
{
- int class_;
- int i,j,h,inf, fd;
- struct mob_data *md;
- struct mob_skill *ms;
- struct mob_db* db;
- struct status_data *mstatus;
-
nullpo_ret(sd);
- if(pc_isdead(sd) && master_id && flag&1)
+ if (pc_isdead(sd) && master_id != 0 && flag == 1)
return 0;
- ARR_FIND( MOB_CLONE_START, MOB_CLONE_END, class_, mob->db_data[class_] == NULL );
- if(class_ < 0 || class_ >= MOB_CLONE_END)
+ int class_;
+
+ ARR_FIND(MOB_CLONE_START, MOB_CLONE_END, class_, mob->db_data[class_] == NULL);
+
+ if (class_ < 0 || class_ >= MOB_CLONE_END)
return 0;
- db = mob->db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db));
- mstatus = &db->status;
- strcpy(db->sprite,sd->status.name);
- strcpy(db->name,sd->status.name);
- strcpy(db->jname,sd->status.name);
- db->lv=status->get_lv(&sd->bl);
+ mob->db_data[class_] = (struct mob_db*)aCalloc(1, sizeof(struct mob_db));
+
+ struct mob_db *db = mob->db_data[class_];
+ struct status_data *mstatus = &db->status;
+
+ strcpy(db->sprite, sd->status.name);
+ strcpy(db->name, sd->status.name);
+ strcpy(db->jname, sd->status.name);
+ db->lv = status->get_lv(&sd->bl);
memcpy(mstatus, &sd->base_status, sizeof(struct status_data));
- mstatus->rhw.atk2= mstatus->dex + mstatus->rhw.atk + mstatus->rhw.atk2; //Max ATK
- mstatus->rhw.atk = mstatus->dex; //Min ATK
- if (mstatus->lhw.atk) {
- mstatus->lhw.atk2= mstatus->dex + mstatus->lhw.atk + mstatus->lhw.atk2; //Max ATK
- mstatus->lhw.atk = mstatus->dex; //Min ATK
+ mstatus->rhw.atk2 = mstatus->dex + mstatus->rhw.atk + mstatus->rhw.atk2; /// Max ATK.
+ mstatus->rhw.atk = mstatus->dex; /// Min ATK.
+
+ if (mstatus->lhw.atk > 0) {
+ mstatus->lhw.atk2 = mstatus->dex + mstatus->lhw.atk + mstatus->lhw.atk2; /// Max ATK.
+ mstatus->lhw.atk = mstatus->dex; /// Min ATK.
}
- if (mode != MD_NONE) //User provided mode.
+
+ if (mode != MD_NONE) /// User provided mode.
mstatus->mode = mode;
- else if (flag&1) //Friendly Character, remove looting.
+ else if (flag == 1) /// Friendly Character, remove looting.
mstatus->mode &= ~MD_LOOTER;
+
mstatus->hp = mstatus->max_hp;
mstatus->sp = mstatus->max_sp;
memcpy(&db->vd, &sd->vd, sizeof(struct view_data));
- db->base_exp=1;
- db->job_exp=1;
- db->range2=AREA_SIZE; //Let them have the same view-range as players.
- db->range3=AREA_SIZE; //Min chase of a screen.
- db->option=sd->sc.option;
+ db->base_exp = 1;
+ db->job_exp = 1;
+ db->range2 = AREA_SIZE; /// Let them have the same view-range as players.
+ db->range3 = AREA_SIZE; /// Min chase of a screen.
+ db->option = sd->sc.option;
- //Skill copy [Skotlex]
- ms = &db->skill[0];
+ const int fd = sd->fd;
- /**
- * We temporarily disable sd's fd so it doesn't receive the messages from skill_check_condition_castbegin
- **/
- fd = sd->fd;
- sd->fd = 0;
-
- //Go Backwards to give better priority to advanced skills.
- for (i=0,j = MAX_SKILL_TREE-1;j>=0 && i< MAX_MOBSKILL ;j--) {
- int idx = pc->skill_tree[pc->class2idx(sd->status.class)][j].idx;
- int skill_id = pc->skill_tree[pc->class2idx(sd->status.class)][j].id;
- if (!skill_id || sd->status.skill[idx].lv < 1 ||
- (skill->dbs->db[idx].inf2&(INF2_WEDDING_SKILL|INF2_GUILD_SKILL))
- )
+ sd->fd = 0; /// Temporarily disable sd's fd so it doesn't receive the messages from skill_check_condition_castbegin.
+
+ struct mob_skill *mob_skills = &db->skill[0];
+
+ /// Go Backwards to give better priority to advanced skills.
+ for (int i = 0, j = MAX_SKILL_TREE - 1; j >= 0 && i < MAX_MOBSKILL; j--) {
+ const int idx = pc->skill_tree[pc->class2idx(sd->status.class)][j].idx;
+ const int skill_id = pc->skill_tree[pc->class2idx(sd->status.class)][j].id;
+
+ if (skill_id == 0 || sd->status.skill[idx].lv < 1 ||
+ (skill->dbs->db[idx].inf2 & (INF2_WEDDING_SKILL | INF2_GUILD_SKILL)) > 0)
continue;
- for(h = 0; h < map->list[sd->bl.m].zone->disabled_skills_count; h++) {
- if( skill_id == map->list[sd->bl.m].zone->disabled_skills[h]->nameid && map->list[sd->bl.m].zone->disabled_skills[h]->subtype == MZS_CLONE ) {
+
+ int h;
+
+ for (h = 0; h < map->list[sd->bl.m].zone->disabled_skills_count; h++) {
+ if (skill_id == map->list[sd->bl.m].zone->disabled_skills[h]->nameid &&
+ map->list[sd->bl.m].zone->disabled_skills[h]->subtype == MZS_CLONE)
break;
- }
}
- if( h < map->list[sd->bl.m].zone->disabled_skills_count )
+
+ if (h < map->list[sd->bl.m].zone->disabled_skills_count)
continue;
- //Normal aggressive mob, disable skills that cannot help them fight
- //against players (those with flags UF_NOMOB and UF_NOPC are specific
- //to always aid players!) [Skotlex]
- if (!(flag&1) &&
- skill->get_unit_id(skill_id, 0) &&
- skill->get_unit_flag(skill_id)&(UF_NOMOB|UF_NOPC))
+
+ /// Normal aggressive mob. Disable skills that cannot help fighting against players. (Those with flags UF_NOMOB and UF_NOPC are specific to always aid players!) [Skotlex]
+ if (flag == 0 && skill->get_unit_id(skill_id, 0) != 0 &&
+ (skill->get_unit_flag(skill_id) & (UF_NOMOB | UF_NOPC)) > 0)
continue;
- /**
- * The clone should be able to cast the skill (e.g. have the required weapon) bugreport:5299)
- **/
- if( !skill->check_condition_castbegin(sd,skill_id,sd->status.skill[idx].lv) )
+
+ /// The clone should be able to cast the skill. (E.g. have the required weapon.) [bugreport:5299]
+ if (skill->check_condition_castbegin(sd, skill_id, sd->status.skill[idx].lv) == 0)
continue;
- memset (&ms[i], 0, sizeof(struct mob_skill));
- ms[i].skill_id = skill_id;
- ms[i].skill_lv = sd->status.skill[idx].lv;
- ms[i].state = MSS_ANY;
- ms[i].permillage = 500*battle_config.mob_skill_rate/100; //Default chance of all skills: 5%
- ms[i].emotion = -1;
- ms[i].cancel = 0;
- ms[i].casttime = skill->cast_fix(&sd->bl,skill_id, ms[i].skill_lv);
- ms[i].delay = 5000+skill->delay_fix(&sd->bl,skill_id, ms[i].skill_lv);
-
- inf = skill->dbs->db[idx].inf;
- if (inf&INF_ATTACK_SKILL) {
- ms[i].target = MST_TARGET;
- ms[i].cond1 = MSC_ALWAYS;
- if (skill->get_range(skill_id, ms[i].skill_lv) > 3)
- ms[i].state = MSS_ANYTARGET;
+ memset(&mob_skills[i], 0, sizeof(struct mob_skill));
+ mob_skills[i].skill_id = skill_id;
+ mob_skills[i].skill_lv = sd->status.skill[idx].lv;
+ mob_skills[i].state = MSS_ANY;
+ mob_skills[i].permillage = 500 * battle_config.mob_skill_rate / 100; /// Default chance of all skills: 5%
+ mob_skills[i].emotion = -1;
+ mob_skills[i].cancel = 0;
+ mob_skills[i].casttime = skill->cast_fix(&sd->bl, skill_id, mob_skills[i].skill_lv);
+ mob_skills[i].delay = 5000 + skill->delay_fix(&sd->bl, skill_id, mob_skills[i].skill_lv);
+
+ const int inf = skill->dbs->db[idx].inf;
+
+ if ((inf & INF_ATTACK_SKILL) == INF_ATTACK_SKILL) {
+ mob_skills[i].target = MST_TARGET;
+ mob_skills[i].cond1 = MSC_ALWAYS;
+
+ if (skill->get_range(skill_id, mob_skills[i].skill_lv) > 3)
+ mob_skills[i].state = MSS_ANYTARGET;
else
- ms[i].state = MSS_BERSERK;
- } else if(inf&INF_GROUND_SKILL) {
- if (skill->get_inf2(skill_id)&INF2_TRAP) { //Traps!
- ms[i].state = MSS_IDLE;
- ms[i].target = MST_AROUND2;
- ms[i].delay = 60000;
- } else if (skill->get_unit_target(skill_id) == BCT_ENEMY) { //Target Enemy
- ms[i].state = MSS_ANYTARGET;
- ms[i].target = MST_TARGET;
- ms[i].cond1 = MSC_ALWAYS;
- } else { //Target allies
- ms[i].target = MST_FRIEND;
- ms[i].cond1 = MSC_FRIENDHPLTMAXRATE;
- ms[i].cond2 = 95;
+ mob_skills[i].state = MSS_BERSERK;
+ } else if ((inf & INF_GROUND_SKILL) == INF_GROUND_SKILL) {
+ if ((skill->get_inf2(skill_id) & INF2_TRAP) == INF2_TRAP) { /// Traps!
+ mob_skills[i].state = MSS_IDLE;
+ mob_skills[i].target = MST_AROUND2;
+ mob_skills[i].delay = 60000;
+ } else if (skill->get_unit_target(skill_id) == BCT_ENEMY) { /// Target Enemy.
+ mob_skills[i].state = MSS_ANYTARGET;
+ mob_skills[i].target = MST_TARGET;
+ mob_skills[i].cond1 = MSC_ALWAYS;
+ } else { /// Target allies.
+ mob_skills[i].target = MST_FRIEND;
+ mob_skills[i].cond1 = MSC_FRIENDHPLTMAXRATE;
+ mob_skills[i].cond2 = 95;
}
- } else if (inf&INF_SELF_SKILL) {
- if (skill->get_inf2(skill_id)&INF2_NO_TARGET_SELF) { //auto-select target skill.
- ms[i].target = MST_TARGET;
- ms[i].cond1 = MSC_ALWAYS;
- if (skill->get_range(skill_id, ms[i].skill_lv) > 3) {
- ms[i].state = MSS_ANYTARGET;
- } else {
- ms[i].state = MSS_BERSERK;
- }
- } else { //Self skill
- ms[i].target = MST_SELF;
- ms[i].cond1 = MSC_MYHPLTMAXRATE;
- ms[i].cond2 = 90;
- ms[i].permillage = 2000;
- //Delay: Remove the stock 5 secs and add half of the support time.
- ms[i].delay += -5000 +(skill->get_time(skill_id, ms[i].skill_lv) + skill->get_time2(skill_id, ms[i].skill_lv))/2;
- if (ms[i].delay < 5000)
- ms[i].delay = 5000; //With a minimum of 5 secs.
+ } else if ((inf & INF_SELF_SKILL) == INF_SELF_SKILL) {
+ if ((skill->get_inf2(skill_id) & INF2_NO_TARGET_SELF) == INF2_NO_TARGET_SELF) { /// Auto-select target skill.
+ mob_skills[i].target = MST_TARGET;
+ mob_skills[i].cond1 = MSC_ALWAYS;
+
+ if (skill->get_range(skill_id, mob_skills[i].skill_lv) > 3)
+ mob_skills[i].state = MSS_ANYTARGET;
+ else
+ mob_skills[i].state = MSS_BERSERK;
+ } else { /// Self skill.
+ mob_skills[i].target = MST_SELF;
+ mob_skills[i].cond1 = MSC_MYHPLTMAXRATE;
+ mob_skills[i].cond2 = 90;
+ mob_skills[i].permillage = 2000;
+
+ const int time1 = skill->get_time(skill_id, mob_skills[i].skill_lv);
+ const int time2 = skill->get_time2(skill_id, mob_skills[i].skill_lv);
+
+ /** Delay: Remove the stock 5 secs and add half of the support time. **/
+ mob_skills[i].delay += -5000 + (time1 + time2) / 2;
+
+ if (mob_skills[i].delay < 5000)
+ mob_skills[i].delay = 5000; /// With a minimum of 5 seconds.
}
- } else if (inf&INF_SUPPORT_SKILL) {
- ms[i].target = MST_FRIEND;
- ms[i].cond1 = MSC_FRIENDHPLTMAXRATE;
- ms[i].cond2 = 90;
+ } else if ((inf & INF_SUPPORT_SKILL) == INF_SUPPORT_SKILL) {
+ mob_skills[i].target = MST_FRIEND;
+ mob_skills[i].cond1 = MSC_FRIENDHPLTMAXRATE;
+ mob_skills[i].cond2 = 90;
+
if (skill_id == AL_HEAL)
- ms[i].permillage = 5000; //Higher skill rate usage for heal.
+ mob_skills[i].permillage = 5000; /// Higher skill rate usage for heal.
else if (skill_id == ALL_RESURRECTION)
- ms[i].cond2 = 1;
- //Delay: Remove the stock 5 secs and add half of the support time.
- ms[i].delay += -5000 +(skill->get_time(skill_id, ms[i].skill_lv) + skill->get_time2(skill_id, ms[i].skill_lv))/2;
- if (ms[i].delay < 2000)
- ms[i].delay = 2000; //With a minimum of 2 secs.
-
- if (i+1 < MAX_MOBSKILL) { //duplicate this so it also triggers on self.
- memcpy(&ms[i+1], &ms[i], sizeof(struct mob_skill));
+ mob_skills[i].cond2 = 1;
+
+ const int time1 = skill->get_time(skill_id, mob_skills[i].skill_lv);
+ const int time2 = skill->get_time2(skill_id, mob_skills[i].skill_lv);
+
+ /** Delay: Remove the stock 5 secs and add half of the support time. **/
+ mob_skills[i].delay += -5000 + (time1 + time2) / 2;
+
+ if (mob_skills[i].delay < 2000)
+ mob_skills[i].delay = 2000; /// With a minimum of 2 seconds.
+
+ if (i + 1 < MAX_MOBSKILL) { /// Duplicate this so it also triggers on self.
+ memcpy(&mob_skills[i + 1], &mob_skills[i], sizeof(struct mob_skill));
db->maxskill = ++i;
- ms[i].target = MST_SELF;
- ms[i].cond1 = MSC_MYHPLTMAXRATE;
+ mob_skills[i].target = MST_SELF;
+ mob_skills[i].cond1 = MSC_MYHPLTMAXRATE;
}
} else {
- switch (skill_id) { //Certain Special skills that are passive, and thus, never triggered.
- case MO_TRIPLEATTACK:
- case TF_DOUBLE:
- case GS_CHAINACTION:
- ms[i].state = MSS_BERSERK;
- ms[i].target = MST_TARGET;
- ms[i].cond1 = MSC_ALWAYS;
- ms[i].permillage = skill_id==MO_TRIPLEATTACK?(3000-ms[i].skill_lv*100):(ms[i].skill_lv*500);
- ms[i].delay -= 5000; //Remove the added delay as these could trigger on "all hits".
- break;
- default: //Untreated Skill
- continue;
+ switch (skill_id) { /// Certain special skills that are passive, and thus, never triggered.
+ case MO_TRIPLEATTACK:
+ FALLTHROUGH
+ case TF_DOUBLE:
+ FALLTHROUGH
+ case GS_CHAINACTION:
+ mob_skills[i].state = MSS_BERSERK;
+ mob_skills[i].target = MST_TARGET;
+ mob_skills[i].cond1 = MSC_ALWAYS;
+
+ if (skill_id == MO_TRIPLEATTACK)
+ mob_skills[i].permillage = 3000 - mob_skills[i].skill_lv * 100;
+ else
+ mob_skills[i].permillage = mob_skills[i].skill_lv * 500;
+
+ mob_skills[i].delay -= 5000; /// Remove the added delay as these could trigger on "all hits".
+ break;
+ default: /// Untreated skill.
+ continue;
}
}
- if (battle_config.mob_skill_rate!= 100)
- ms[i].permillage = ms[i].permillage*battle_config.mob_skill_rate/100;
- if (battle_config.mob_skill_delay != 100)
- ms[i].delay = ms[i].delay*battle_config.mob_skill_delay/100;
+ mob_skills[i].permillage *= battle_config.mob_skill_rate / 100;
+ mob_skills[i].delay *= battle_config.mob_skill_delay / 100;
db->maxskill = ++i;
}
- /**
- * We grant the session it's fd value back.
- **/
- sd->fd = fd;
+ sd->fd = fd; /// We grant the session it's fd value back.
+
+ /// Finally spawn it.
+ struct mob_data *md = mob->once_spawn_sub(&sd->bl, m, x, y, DEFAULT_MOB_NAME, class_, event, SZ_SMALL, AI_NONE, 0);
- //Finally, spawn it.
- md = mob->once_spawn_sub(&sd->bl, m, x, y, DEFAULT_MOB_NAME, class_, event, SZ_SMALL, AI_NONE, 0);
- if (!md) return 0; //Failed?
+ if (md == NULL)
+ return 0; /// Failed?
md->special_state.clone = 1;
- if (master_id || flag || duration) { //Further manipulate crafted char.
- if (flag&1) //Friendly Character
- md->special_state.ai = AI_ATTACK;
- if (master_id) //Attach to Master
- md->master_id = master_id;
- if (duration) //Auto Delete after a while.
- {
- if( md->deletetimer != INVALID_TIMER )
- timer->delete(md->deletetimer, mob->timer_delete);
- md->deletetimer = timer->add(timer->gettick() + duration, mob->timer_delete, md->bl.id, 0);
- }
+ if (flag == 1) /// Friendly character.
+ md->special_state.ai = AI_ATTACK;
+
+ if (master_id != 0) /// Attach to master.
+ md->master_id = master_id;
+
+ if (duration > 0) { /// Auto delete after a while.
+ if (md->deletetimer != INVALID_TIMER)
+ timer->delete(md->deletetimer, mob->timer_delete);
+
+ md->deletetimer = timer->add(timer->gettick() + duration, mob->timer_delete, md->bl.id, 0);
}
mob->spawn(md);
-
return md->bl.id;
}