From 2704438c90e148389e6e686ee40aa5a8a347fbbc Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 04:52:59 +0200 Subject: Update inventory in pet_return_egg() only if egg was found --- src/map/pet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/pet.c b/src/map/pet.c index 2a9831ed6..21990aebf 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -405,6 +405,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) sd->status.inventory[i].attribute &= ~ATTR_BROKEN; sd->status.inventory[i].bound = IBT_NONE; sd->status.inventory[i].card[3] = pd->pet.rename_flag; + clif->inventoryList(sd); } else { // The pet egg wasn't found: it was probably hatched with the old system that deleted the egg. struct item tmp_item = {0}; @@ -422,7 +423,6 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) } } #if PACKETVER >= 20180704 - clif->inventoryList(sd); clif->send_petdata(sd, pd, 6, 0); #endif pd->pet.incubate = 1; -- cgit v1.2.3-60-g2f50 From 6d33154da962ede5f5e30fae53e76d5d2a1cc4ca Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 04:54:19 +0200 Subject: Implement intimacy display in pet egg's item description window --- src/map/atcommand.c | 2 +- src/map/clif.c | 4 ++-- src/map/pet.c | 37 ++++++++++++++++++++++++++++++++++--- src/map/pet.h | 1 + 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 76448b237..bee1f8c90 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8562,7 +8562,7 @@ ACMD(itemlist) if( it->card[0] == CARD0_PET ) { // pet egg - if (it->card[3]) + if ((it->card[3] & 1) != 0) StrBuf->Printf(&buf, msg_fd(fd,1348), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, named) else StrBuf->Printf(&buf, msg_fd(fd,1349), (unsigned int)MakeDWord(it->card[1], it->card[2])); // -> (pet egg, pet id: %u, unnamed) diff --git a/src/map/clif.c b/src/map/clif.c index 649df3e33..6eb614103 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -2519,8 +2519,8 @@ static void clif_addcards(struct EQUIPSLOTINFO *buf, struct item *item) if (item->card[0] == CARD0_PET) { //pet eggs buf->card[0] = 0; buf->card[1] = 0; - buf->card[2] = 0; - buf->card[3] = item->card[3]; //Pet renamed flag. + buf->card[2] = (item->card[3] >> 1); // Pet intimacy level. + buf->card[3] = (item->card[3] & 1); // Pet renamed flag. return; } if (item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE) { //Forged/created items diff --git a/src/map/pet.c b/src/map/pet.c index 21990aebf..1e87c6afa 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -98,6 +98,36 @@ static void pet_set_hunger(struct pet_data *pd, int value) pd->pet.hungry = cap_value(value, PET_HUNGER_STARVING, PET_HUNGER_STUFFED); } +/** + * Calculates the value to store in a pet egg's 4th card slot + * based on the passed rename flag and intimacy value. + * + * @param rename_flag The pet's rename flag. + * @param intimacy The pet's intimacy value. + * @return The value to store in the pet egg's 4th card slot. (Defaults to 0 in case of error.) + * + **/ +static int pet_get_card4_value(int rename_flag, int intimacy) +{ + Assert_ret(rename_flag == 0 || rename_flag == 1); + Assert_ret(intimacy >= PET_INTIMACY_NONE && intimacy <= PET_INTIMACY_MAX); + + int card4 = rename_flag; + + if (intimacy <= PET_INTIMACY_SHY) + card4 |= (1 << 1); + else if (intimacy <= PET_INTIMACY_NEUTRAL) + card4 |= (2 << 1); + else if (intimacy <= PET_INTIMACY_CORDIAL) + card4 |= (3 << 1); + else if (intimacy <= PET_INTIMACY_LOYAL) + card4 |= (4 << 1); + else + card4 |= (5 << 1); + + return card4; +} + /** * Sets a pet's intimacy value. * Deletes the pet if its intimacy value reaches PET_INTIMACY_NONE (0). @@ -404,7 +434,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) if (i != sd->status.inventorySize) { sd->status.inventory[i].attribute &= ~ATTR_BROKEN; sd->status.inventory[i].bound = IBT_NONE; - sd->status.inventory[i].card[3] = pd->pet.rename_flag; + sd->status.inventory[i].card[3] = pet->get_card4_value(pd->pet.rename_flag, pd->pet.intimate); clif->inventoryList(sd); } else { // The pet egg wasn't found: it was probably hatched with the old system that deleted the egg. @@ -416,7 +446,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) tmp_item.card[0] = CARD0_PET; tmp_item.card[1] = GetWord(pd->pet.pet_id, 0); tmp_item.card[2] = GetWord(pd->pet.pet_id, 1); - tmp_item.card[3] = pd->pet.rename_flag; + tmp_item.card[3] = pet->get_card4_value(pd->pet.rename_flag, pd->pet.intimate); if ((flag = pc->additem(sd, &tmp_item, 1, LOG_TYPE_EGG)) != 0) { clif->additem(sd, 0, 0, flag); map->addflooritem(&sd->bl, &tmp_item, 1, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 0, false); @@ -729,7 +759,7 @@ static bool pet_get_egg(int account_id, int pet_class, int pet_id) tmp_item.card[0] = CARD0_PET; tmp_item.card[1] = GetWord(pet_id,0); tmp_item.card[2] = GetWord(pet_id,1); - tmp_item.card[3] = 0; //New pets are not named. + tmp_item.card[3] = pet->get_card4_value(0, pet->db[i].intimate); if((ret = pc->additem(sd,&tmp_item,1,LOG_TYPE_PICKDROP_PLAYER))) { clif->additem(sd,0,0,ret); map->addflooritem(&sd->bl, &tmp_item, 1, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 0, false); @@ -1799,6 +1829,7 @@ void pet_defaults(void) pet->hungry_val = pet_hungry_val; pet->set_hunger = pet_set_hunger; + pet->get_card4_value = pet_get_card4_value; pet->set_intimate = pet_set_intimate; pet->create_egg = pet_create_egg; pet->unlocktarget = pet_unlocktarget; diff --git a/src/map/pet.h b/src/map/pet.h index fa37e896a..f010f54fa 100644 --- a/src/map/pet.h +++ b/src/map/pet.h @@ -147,6 +147,7 @@ struct pet_interface { /* */ int (*hungry_val) (struct pet_data *pd); void (*set_hunger) (struct pet_data *pd, int value); + int (*get_card4_value) (int rename_flag, int intimacy); void (*set_intimate) (struct pet_data *pd, int value); int (*create_egg) (struct map_session_data *sd, int item_id); int (*unlocktarget) (struct pet_data *pd); -- cgit v1.2.3-60-g2f50 From 484ac06f39d1b576284c137538f05347ba7aee0c Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 04:55:18 +0200 Subject: Update pet's egg data in ACMD(petrename) --- src/map/atcommand.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index bee1f8c90..379405833 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2881,6 +2881,15 @@ ACMD(petrename) } pd->pet.rename_flag = 0; + + int i; + + ARR_FIND(0, sd->status.inventorySize, i, sd->status.inventory[i].card[0] == CARD0_PET + && pd->pet.pet_id == MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])); + + if (i != sd->status.inventorySize) + sd->status.inventory[i].card[3] = pet->get_card4_value(pd->pet.rename_flag, pd->pet.intimate); + intif->save_petdata(sd->status.account_id, &pd->pet); clif->send_petstatus(sd); clif->message(fd, msg_fd(fd,187)); // You can now rename your pet. -- cgit v1.2.3-60-g2f50 From 2129555fa2752cfa0b9e73151fad2897d426fe63 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 04:56:46 +0200 Subject: Remove pet if intimacy drops to 0 --- src/map/pc.c | 2 +- src/map/pet.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/map/pc.c b/src/map/pc.c index c1261c839..ca8e35073 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -8153,7 +8153,7 @@ static int pc_dead(struct map_session_data *sd, struct block_list *src) clif->send_petdata(sd, sd->pd, 1, pd->pet.intimate); } - if (sd->pd->target_id != 0) // Unlock all targets. + if (sd->pd != NULL && sd->pd->target_id != 0) // Unlock all targets. pet->unlocktarget(sd->pd); } diff --git a/src/map/pet.c b/src/map/pet.c index 1e87c6afa..3c75c23b5 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -145,18 +145,20 @@ static void pet_set_intimate(struct pet_data *pd, int value) struct map_session_data *sd = pd->msd; - status_calc_pc(sd, SCO_NONE); - - if (pd->pet.intimate == PET_INTIMACY_NONE) { /// Pet is lost. Delete the egg. + if (pd->pet.intimate == PET_INTIMACY_NONE) { // Pet is lost, delete it. int i; ARR_FIND(0, sd->status.inventorySize, i, sd->status.inventory[i].card[0] == CARD0_PET - && pd->pet.pet_id == MakeDWord(sd->status.inventory[i].card[1], - sd->status.inventory[i].card[2])); + && pd->pet.pet_id == MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])); if (i != sd->status.inventorySize) pc->delitem(sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_EGG); + + pet_stop_attack(pd); + unit->remove_map(&pd->bl, CLR_OUTSIGHT, ALC_MARK); } + + status_calc_pc(sd, SCO_NONE); } /** @@ -342,8 +344,8 @@ static int pet_hungry(int tid, int64 tick, int id, intptr_t data) pet_stop_attack(pd); pet->set_intimate(pd, pd->pet.intimate - pd->petDB->starving_decrement); - if (pd->pet.intimate == PET_INTIMACY_NONE) - pd->status.speed = pd->db->status.speed; + if (sd->pd == NULL) + return 0; status_calc_pet(pd, SCO_NONE); clif->send_petdata(sd, pd, 1, pd->pet.intimate); @@ -978,10 +980,8 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) intimacy = intimacy * battle_config.pet_friendly_rate / 100; pet->set_intimate(pd, pd->pet.intimate + intimacy); - if (pd->pet.intimate == PET_INTIMACY_NONE) { - pet_stop_attack(pd); - pd->status.speed = pd->db->status.speed; - } + if (sd->pd == NULL) + return 0; status_calc_pet(pd, SCO_NONE); pet->set_hunger(pd, pd->pet.hungry + pd->petDB->fullness); -- cgit v1.2.3-60-g2f50 From 42a3bcaf96be26aeed560574d650e61091282995 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:03:39 +0200 Subject: Add battle flag for immediately removing the pet when its intimacy drops to 0 --- conf/map/battle/pet.conf | 4 ++++ src/map/battle.c | 1 + src/map/battle.h | 1 + src/map/pet.c | 6 ++++-- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/conf/map/battle/pet.conf b/conf/map/battle/pet.conf index 5797bb2a5..3060b6e64 100644 --- a/conf/map/battle/pet.conf +++ b/conf/map/battle/pet.conf @@ -99,3 +99,7 @@ pet_max_atk2: 1000 // If set to true, pets are automatically returned to egg when entering castles during WoE times // and hatching is forbidden within as well. pet_disable_in_gvg: false + +// Should the pet immediately be removed when its intimacy drops to 0? (Note 1) +// If set to false the pet will randomly walk around the map before being removed. +pet_remove_immediately: true diff --git a/src/map/battle.c b/src/map/battle.c index 611154953..c25825e6e 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -7101,6 +7101,7 @@ static const struct battle_data { { "pet_max_atk1", &battle_config.pet_max_atk1, 750, 0, INT_MAX, }, { "pet_max_atk2", &battle_config.pet_max_atk2, 1000, 0, INT_MAX, }, { "pet_disable_in_gvg", &battle_config.pet_no_gvg, 0, 0, 1, }, + { "pet_remove_immediately", &battle_config.pet_remove_immediately, 1, 0, 1, }, { "skill_min_damage", &battle_config.skill_min_damage, 2|4, 0, 1|2|4, }, { "finger_offensive_type", &battle_config.finger_offensive_type, 0, 0, 1, }, { "heal_exp", &battle_config.heal_exp, 0, 0, INT_MAX, }, diff --git a/src/map/battle.h b/src/map/battle.h index 55ee32445..8477d943d 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -230,6 +230,7 @@ struct Battle_Config { int pet_max_atk2; //[Skotlex] int pet_no_gvg; //Disables pets in gvg. [Skotlex] int pet_equip_required; + int pet_remove_immediately; int skill_min_damage; int finger_offensive_type; diff --git a/src/map/pet.c b/src/map/pet.c index 3c75c23b5..fe803d93f 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -154,8 +154,10 @@ static void pet_set_intimate(struct pet_data *pd, int value) if (i != sd->status.inventorySize) pc->delitem(sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_EGG); - pet_stop_attack(pd); - unit->remove_map(&pd->bl, CLR_OUTSIGHT, ALC_MARK); + if (battle_config.pet_remove_immediately != 0) { + pet_stop_attack(pd); + unit->remove_map(&pd->bl, CLR_OUTSIGHT, ALC_MARK); + } } status_calc_pc(sd, SCO_NONE); -- cgit v1.2.3-60-g2f50 From afdb49e3bd8dc186626c9defe50af5b6dceb9519 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:04:43 +0200 Subject: Add check if pet belongs to character in pet_food() --- src/map/pet.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/map/pet.c b/src/map/pet.c index fe803d93f..c6656047c 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -954,6 +954,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) { nullpo_retr(1, sd); nullpo_retr(1, pd); + Assert_retr(1, sd->status.pet_id == pd->pet.pet_id); int i = pc->search_inventory(sd, pd->petDB->FoodID); -- cgit v1.2.3-60-g2f50 From 2669d54e37bb231866479efd177808ec6ab3eab8 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:12:32 +0200 Subject: Send pet's intimacy data only in pet_set_intimate() --- src/map/pc.c | 4 +--- src/map/pet.c | 4 ++-- src/map/script.c | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/map/pc.c b/src/map/pc.c index ca8e35073..ad669c0c8 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -8148,10 +8148,8 @@ static int pc_dead(struct map_session_data *sd, struct block_list *src) if (sd->status.pet_id > 0 && sd->pd != NULL) { struct pet_data *pd = sd->pd; - if (map->list[sd->bl.m].flag.noexppenalty == 0) { + if (map->list[sd->bl.m].flag.noexppenalty == 0) pet->set_intimate(pd, pd->pet.intimate - pd->petDB->die); - clif->send_petdata(sd, sd->pd, 1, pd->pet.intimate); - } if (sd->pd != NULL && sd->pd->target_id != 0) // Unlock all targets. pet->unlocktarget(sd->pd); diff --git a/src/map/pet.c b/src/map/pet.c index c6656047c..5b2a95446 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -158,6 +158,8 @@ static void pet_set_intimate(struct pet_data *pd, int value) pet_stop_attack(pd); unit->remove_map(&pd->bl, CLR_OUTSIGHT, ALC_MARK); } + } else { + clif->send_petdata(sd, pd, 1, pd->pet.intimate); } status_calc_pc(sd, SCO_NONE); @@ -350,7 +352,6 @@ static int pet_hungry(int tid, int64 tick, int id, intptr_t data) return 0; status_calc_pet(pd, SCO_NONE); - clif->send_petdata(sd, pd, 1, pd->pet.intimate); if (pd->petDB->starving_delay > 0) interval = pd->petDB->starving_delay; @@ -989,7 +990,6 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) status_calc_pet(pd, SCO_NONE); pet->set_hunger(pd, pd->pet.hungry + pd->petDB->fullness); clif->send_petdata(sd, pd, 2, pd->pet.hungry); - clif->send_petdata(sd, pd, 1, pd->pet.intimate); clif->pet_food(sd, pd->petDB->FoodID, 1); return 0; diff --git a/src/map/script.c b/src/map/script.c index 743a1779a..d501818d9 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -20629,7 +20629,6 @@ static BUILDIN(setunitdata) break; case UDT_INTIMACY: pet->set_intimate(pd, val); - clif->send_petdata(pd->msd, pd, 1, pd->pet.intimate); break; case UDT_HUNGER: pet->set_hunger(pd, val); -- cgit v1.2.3-60-g2f50 From 3894021fba9e54b5075c502cbe05e08fc23e9795 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:13:28 +0200 Subject: Call pet->set_hunger() in ACMD(pethungry) instead of directly assigning the value --- src/map/atcommand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 379405833..3b4334275 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2855,7 +2855,7 @@ ACMD(pethungry) } if (hungry != pd->pet.hungry) { // No need to update the pet's status if hunger value won't change. - pd->pet.hungry = hungry; + pet->set_hunger(pd, hungry); clif->send_petstatus(sd); } -- cgit v1.2.3-60-g2f50 From 38a69f471210cb0dcdecdbb3b6c099efed3d7501 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:14:20 +0200 Subject: Send pet's hunger data only in pet_set_hunger() --- src/map/pet.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/map/pet.c b/src/map/pet.c index 5b2a95446..3cd873b6a 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -94,8 +94,11 @@ static int pet_hungry_val(struct pet_data *pd) static void pet_set_hunger(struct pet_data *pd, int value) { nullpo_retv(pd); + nullpo_retv(pd->msd); pd->pet.hungry = cap_value(value, PET_HUNGER_STARVING, PET_HUNGER_STUFFED); + + clif->send_petdata(pd->msd, pd, 2, pd->pet.hungry); } /** @@ -357,7 +360,6 @@ static int pet_hungry(int tid, int64 tick, int id, intptr_t data) interval = pd->petDB->starving_delay; } - clif->send_petdata(sd, pd, 2, pd->pet.hungry); interval = interval * battle_config.pet_hungry_delay_rate / 100; pd->pet_hungry_timer = timer->add(tick + max(interval, 1), pet->hungry, sd->bl.id, 0); @@ -989,7 +991,6 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) status_calc_pet(pd, SCO_NONE); pet->set_hunger(pd, pd->pet.hungry + pd->petDB->fullness); - clif->send_petdata(sd, pd, 2, pd->pet.hungry); clif->pet_food(sd, pd->petDB->FoodID, 1); return 0; -- cgit v1.2.3-60-g2f50 From 348aeaecfc9436ae22169f3667fb36ba1b3f3831 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:15:08 +0200 Subject: Remove unnecessarily sending of pet's accessory data --- src/map/pet.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/map/pet.c b/src/map/pet.c index 3cd873b6a..1ed2eeb96 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -580,7 +580,6 @@ static int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) #if PACKETVER >= 20180704 clif->send_petdata(sd, sd->pd, 6, 1); #endif - clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); clif->send_petstatus(sd); } Assert_retr(1, sd->status.pet_id == 0 || sd->pd == 0 || sd->pd->msd == sd); @@ -626,7 +625,6 @@ static int pet_recv_petdata(int account_id, struct s_pet *p, int flag) clif->spawn(&sd->pd->bl); clif->send_petdata(sd,sd->pd,0,0); clif->send_petdata(sd,sd->pd,5,battle_config.pet_hair_style); - clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); clif->send_petstatus(sd); } } @@ -865,7 +863,6 @@ static int pet_change_name_ack(struct map_session_data *sd, const char *name, in aFree(newname); clif->blname_ack(0,&pd->bl); pd->pet.rename_flag = 1; - clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); clif->send_petstatus(sd); return 1; } -- cgit v1.2.3-60-g2f50 From 18bccc7a437fb11dd65a87b860c0183308306c1b Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:15:58 +0200 Subject: Centralize pet spawn code in pet_spawn() function --- src/map/clif.c | 5 +---- src/map/pet.c | 52 +++++++++++++++++++++++++++++++++++++--------------- src/map/pet.h | 1 + 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 6eb614103..64b64fa32 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -10806,10 +10806,7 @@ static void clif_parse_LoadEndAck(int fd, struct map_session_data *sd) clif->message(sd->fd, msg_sd(sd, 866)); // "Pets are not allowed in Guild Wars." pet->menu(sd, 3); // Option 3 is return to egg. } else { - map->addblock(&sd->pd->bl); - clif->spawn(&sd->pd->bl); - clif->send_petdata(sd,sd->pd, 0, 0); - clif->send_petstatus(sd); + pet->spawn(sd, false); } } diff --git a/src/map/pet.c b/src/map/pet.c index 1ed2eeb96..9c7a1aab4 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -548,6 +548,35 @@ static int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) return 0; } +/** + * Spawns a pet. + * + * @param sd The pet's master. + * @param birth_process Whether the pet is spawned during birth process. + * @return 1 on failure, 0 on success. + * + **/ +static int pet_spawn(struct map_session_data *sd, bool birth_process) +{ + nullpo_retr(1, sd); + nullpo_retr(1, sd->pd); + + if (map->addblock(&sd->pd->bl) != 0 || !clif->spawn(&sd->pd->bl)) + return 1; + + clif->send_petdata(sd, sd->pd, 0, 0); + clif->send_petdata(sd, sd->pd, 5, battle_config.pet_hair_style); + +#if PACKETVER >= 20180704 + if (birth_process) + clif->send_petdata(sd, sd->pd, 6, 1); +#endif + + clif->send_petstatus(sd); + + return 0; +} + static int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) { nullpo_retr(1, sd); @@ -572,16 +601,11 @@ static int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) if (map->save_settings&8) chrif->save(sd,0); //is it REALLY Needed to save the char for hatching a pet? [Skotlex] - if(sd->bl.prev != NULL) { - map->addblock(&sd->pd->bl); - clif->spawn(&sd->pd->bl); - clif->send_petdata(sd,sd->pd, 0,0); - clif->send_petdata(sd,sd->pd, 5,battle_config.pet_hair_style); -#if PACKETVER >= 20180704 - clif->send_petdata(sd, sd->pd, 6, 1); -#endif - clif->send_petstatus(sd); + if (sd->pd != NULL && sd->bl.prev != NULL) { + if (pet->spawn(sd, true) != 0) + return 1; } + Assert_retr(1, sd->status.pet_id == 0 || sd->pd == 0 || sd->pd->msd == sd); return 0; @@ -620,12 +644,9 @@ static int pet_recv_petdata(int account_id, struct s_pet *p, int flag) } } else { pet->data_init(sd,p); - if(sd->pd && sd->bl.prev != NULL) { - map->addblock(&sd->pd->bl); - clif->spawn(&sd->pd->bl); - clif->send_petdata(sd,sd->pd,0,0); - clif->send_petdata(sd,sd->pd,5,battle_config.pet_hair_style); - clif->send_petstatus(sd); + if (sd->pd != NULL && sd->bl.prev != NULL) { + if (pet->spawn(sd, false) != 0) + return 1; } } @@ -1843,6 +1864,7 @@ void pet_defaults(void) pet->performance = pet_performance; pet->return_egg = pet_return_egg; pet->data_init = pet_data_init; + pet->spawn = pet_spawn; pet->birth_process = pet_birth_process; pet->recv_petdata = pet_recv_petdata; pet->select_egg = pet_select_egg; diff --git a/src/map/pet.h b/src/map/pet.h index f010f54fa..c57df9de3 100644 --- a/src/map/pet.h +++ b/src/map/pet.h @@ -160,6 +160,7 @@ struct pet_interface { int (*performance) (struct map_session_data *sd, struct pet_data *pd); int (*return_egg) (struct map_session_data *sd, struct pet_data *pd); int (*data_init) (struct map_session_data *sd, struct s_pet *petinfo); + int (*spawn) (struct map_session_data *sd, bool birth_process); int (*birth_process) (struct map_session_data *sd, struct s_pet *petinfo); int (*recv_petdata) (int account_id, struct s_pet *p, int flag); int (*select_egg) (struct map_session_data *sd, int egg_index); -- cgit v1.2.3-60-g2f50 From 6f4439ee2182dd3421ff50c7b479c1b9e7f02fcb Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:16:46 +0200 Subject: Remove/move unnecessarily calling clif_send_petstatus() --- src/map/atcommand.c | 8 ++------ src/map/pet.c | 1 - src/map/script.c | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 3b4334275..9d5c601bf 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2810,10 +2810,8 @@ ACMD(petfriendly) return false; } - if (friendly != pd->pet.intimate) { // No need to update the pet's status if intimacy value won't change. + if (friendly != pd->pet.intimate) // No need to update the pet's status if intimacy value won't change. pet->set_intimate(pd, friendly); - clif->send_petstatus(sd); - } clif->message(fd, msg_fd(fd, 182)); // Pet intimacy changed. (Send message regardless of value has changed or not.) @@ -2854,10 +2852,8 @@ ACMD(pethungry) return false; } - if (hungry != pd->pet.hungry) { // No need to update the pet's status if hunger value won't change. + if (hungry != pd->pet.hungry) // No need to update the pet's status if hunger value won't change. pet->set_hunger(pd, hungry); - clif->send_petstatus(sd); - } clif->message(fd, msg_fd(fd, 185)); // Pet hunger changed. (Send message regardless of value has changed or not.) diff --git a/src/map/pet.c b/src/map/pet.c index 9c7a1aab4..da93906ae 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -884,7 +884,6 @@ static int pet_change_name_ack(struct map_session_data *sd, const char *name, in aFree(newname); clif->blname_ack(0,&pd->bl); pd->pet.rename_flag = 1; - clif->send_petstatus(sd); return 1; } diff --git a/src/map/script.c b/src/map/script.c index d501818d9..3da0cdceb 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -20518,6 +20518,8 @@ static BUILDIN(setunitdata) break; case UDT_LEVEL: pd->pet.level = (short)val; + if (pd->msd != NULL) + clif->send_petstatus(pd->msd); // Send pet data. break; case UDT_HP: status->set_hp(bl, (unsigned int)val, STATUS_HEAL_DEFAULT); @@ -20639,7 +20641,6 @@ static BUILDIN(setunitdata) return false; } - clif->send_petstatus(pd->msd); // Send pet data. break; } case BL_MER: { -- cgit v1.2.3-60-g2f50 From d4ff27322a97ee908814ad1fe703c89be7d92af2 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:17:34 +0200 Subject: Remove ancient FIXME comment related to deleting taming items of type IT_DELAYCONSUME --- src/map/pet.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/map/pet.c b/src/map/pet.c index da93906ae..f10c55f57 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -700,8 +700,6 @@ static int pet_catch_process2(struct map_session_data *sd, int target_id) return 1; } - //FIXME: Delete taming item here, if this was an item-invoked capture and the item was flagged as delay-consume. [ultramage] - // catch_target_class == 0 is used for universal lures (except bosses for now). [Skotlex] if (sd->catch_target_class == 0 && (md->status.mode & MD_BOSS) == 0) sd->catch_target_class = md->class_; -- cgit v1.2.3-60-g2f50 From 604962fd2a7e69c812708d0cb9cfe4130e595ea2 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Mon, 22 Jun 2020 05:58:12 +0200 Subject: Add pc_has_pet() macro --- src/map/pc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/map/pc.h b/src/map/pc.h index f2e911af3..49ffcf3b0 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -727,6 +727,9 @@ END_ZEROED_BLOCK; /// Rune Knight Dragon #define pc_isridingdragon(sd) ( (sd)->sc.option&OPTION_DRAGON ) +// Check if character has a pet. +#define pc_has_pet(sd) ( (sd)->status.pet_id != 0 && (sd)->pd != NULL && (sd)->pd->pet.intimate > PET_INTIMACY_NONE ) + #define pc_stop_walking(sd, type) (unit->stop_walking(&(sd)->bl, (type))) #define pc_stop_attack(sd) (unit->stop_attack(&(sd)->bl)) -- cgit v1.2.3-60-g2f50