diff options
Diffstat (limited to 'src/map/pet.c')
-rw-r--r-- | src/map/pet.c | 107 |
1 files changed, 58 insertions, 49 deletions
diff --git a/src/map/pet.c b/src/map/pet.c index 5c7f15151..c85092a01 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #include "../common/db.h" #include "../common/timer.h" @@ -75,6 +76,7 @@ int pet_create_egg(struct map_session_data *sd, int item_id) { int pet_id = search_petDB_index(item_id, PET_EGG); if (pet_id < 0) return 0; //No pet egg here. + if (!pc_inventoryblank(sd)) return 0; // Inventory full sd->catch_target_class = pet_db[pet_id].class_; intif_create_pet(sd->status.account_id, sd->status.char_id, (short)pet_db[pet_id].class_, @@ -100,8 +102,6 @@ int pet_unlocktarget(struct pet_data *pd) *------------------------------------------*/ int pet_attackskill(struct pet_data *pd, int target_id) { - struct block_list *bl; - if (!battle_config.pet_status_support || !pd->a_skill || (battle_config.pet_equip_required && !pd->pet.equip)) return 0; @@ -112,13 +112,14 @@ int pet_attackskill(struct pet_data *pd, int target_id) if (rnd()%100 < (pd->a_skill->rate +pd->pet.intimate*pd->a_skill->bonusrate/1000)) { //Skotlex: Use pet's skill int inf; + struct block_list *bl; bl=map_id2bl(target_id); if(bl == NULL || pd->bl.m != bl->m || bl->prev == NULL || status_isdead(bl) || !check_distance_bl(&pd->bl, bl, pd->db->range3)) return 0; - inf = skill_get_inf(pd->a_skill->id); + inf = skill->get_inf(pd->a_skill->id); if (inf & INF_GROUND_SKILL) unit_skilluse_pos(&pd->bl, bl->x, bl->y, pd->a_skill->id, pd->a_skill->lv); else //Offensive self skill? Could be stuff like GX. @@ -226,9 +227,9 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data) pd->status.speed = pd->db->status.speed; } status_calc_pet(pd, 0); - clif_send_petdata(sd,pd,1,pd->pet.intimate); + clif->send_petdata(sd,pd,1,pd->pet.intimate); } - clif_send_petdata(sd,pd,2,pd->pet.hungry); + clif->send_petdata(sd,pd,2,pd->pet.hungry); if(battle_config.pet_hungry_delay_rate != 100) interval = (pd->petDB->hungry_delay*battle_config.pet_hungry_delay_rate)/100; @@ -285,7 +286,7 @@ static int pet_performance(struct map_session_data *sd, struct pet_data *pd) val = 1; pet_stop_walking(pd,2000<<8); - clif_pet_performance(pd, rnd()%val + 1); + clif->send_petdata(NULL, pd, 4, rnd()%val + 1); pet_lootitem_drop(pd,NULL); return 1; } @@ -304,7 +305,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) tmp_item.card[2] = GetWord(pd->pet.pet_id,1); tmp_item.card[3] = pd->pet.rename_flag; if((flag = pc_additem(sd,&tmp_item,1,LOG_TYPE_OTHER))) { - clif_additem(sd,0,0,flag); + clif->additem(sd,0,0,flag); map_addflooritem(&tmp_item,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } pd->pet.incuvate = 1; @@ -411,11 +412,11 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *pet) 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); - clif_pet_equip_area(sd->pd); - clif_send_petstatus(sd); + 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); } Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); @@ -452,11 +453,11 @@ int pet_recv_petdata(int account_id,struct s_pet *p,int flag) 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_pet_equip_area(sd->pd); - clif_send_petstatus(sd); + 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); } } @@ -483,7 +484,7 @@ int pet_catch_process1(struct map_session_data *sd,int target_class) nullpo_ret(sd); sd->catch_target_class = target_class; - clif_catch_process(sd); + clif->catch_process(sd); return 0; } @@ -498,7 +499,7 @@ int pet_catch_process2(struct map_session_data* sd, int target_id) md = (struct mob_data*)map_id2bl(target_id); if(!md || md->bl.type != BL_MOB || md->bl.prev == NULL) { // Invalid inputs/state, abort capture. - clif_pet_roulette(sd,0); + clif->pet_roulette(sd,0); sd->catch_target_class = -1; sd->itemid = sd->itemindex = -1; return 1; @@ -511,8 +512,8 @@ int pet_catch_process2(struct map_session_data* sd, int target_id) if (sd->catch_target_class == 0 && !(md->status.mode&MD_BOSS)) sd->catch_target_class = md->class_; if(i < 0 || sd->catch_target_class != md->class_) { - clif_emotion(&md->bl, E_AG); //mob will do /ag if wrong lure is used on them. - clif_pet_roulette(sd,0); + clif->emotion(&md->bl, E_AG); //mob will do /ag if wrong lure is used on them. + clif->pet_roulette(sd,0); sd->catch_target_class = -1; return 1; } @@ -527,13 +528,13 @@ int pet_catch_process2(struct map_session_data* sd, int target_id) { unit_remove_map(&md->bl,CLR_OUTSIGHT); status_kill(&md->bl); - clif_pet_roulette(sd,1); + clif->pet_roulette(sd,1); intif_create_pet(sd->status.account_id,sd->status.char_id,pet_db[i].class_,mob_db(pet_db[i].class_)->lv, pet_db[i].EggID,0,pet_db[i].intimate,100,0,1,pet_db[i].jname); } else { - clif_pet_roulette(sd,0); + clif->pet_roulette(sd,0); sd->catch_target_class = -1; } @@ -569,7 +570,7 @@ int pet_get_egg(int account_id,int pet_id,int flag) tmp_item.card[2] = GetWord(pet_id,1); tmp_item.card[3] = 0; //New pets are not named. if((ret = pc_additem(sd,&tmp_item,1,LOG_TYPE_PICKDROP_PLAYER))) { - clif_additem(sd,0,0,ret); + clif->additem(sd,0,0,ret); map_addflooritem(&tmp_item,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } @@ -582,6 +583,7 @@ static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap); int pet_menu(struct map_session_data *sd,int menunum) { + struct item_data *egg_id; nullpo_ret(sd); if (sd->pd == NULL) return 1; @@ -589,10 +591,18 @@ int pet_menu(struct map_session_data *sd,int menunum) //You lost the pet already. if(!sd->status.pet_id || sd->pd->pet.intimate <= 0 || sd->pd->pet.incuvate) return 1; + + egg_id = itemdb_exists(sd->pd->petDB->EggID); + if (egg_id) { + if ((egg_id->flag.trade_restriction&0x01) && !pc_inventoryblank(sd)) { + clif->message(sd->fd, msg_txt(451)); // You can't return your pet because your inventory is full. + return 1; + } + } switch(menunum) { case 0: - clif_send_petstatus(sd); + clif->send_petstatus(sd); break; case 1: pet_food(sd, sd->pd); @@ -636,15 +646,15 @@ int pet_change_name_ack(struct map_session_data *sd, char* name, int flag) normalize_name(name," ");//bugreport:3032 if ( !flag || !strlen(name) ) { - clif_displaymessage(sd->fd, msg_txt(280)); // You cannot use this name for your pet. - clif_send_petstatus(sd); //Send status so client knows oet name change got rejected. + clif->message(sd->fd, msg_txt(280)); // You cannot use this name for your pet. + clif->send_petstatus(sd); //Send status so client knows oet name change got rejected. return 0; } memcpy(pd->pet.name, name, NAME_LENGTH); - clif_charnameack (0,&pd->bl); + clif->charnameack (0,&pd->bl); pd->pet.rename_flag = 1; - clif_pet_equip_area(pd); - clif_send_petstatus(sd); + clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); + clif->send_petstatus(sd); return 1; } @@ -660,14 +670,14 @@ int pet_equipitem(struct map_session_data *sd,int index) nameid = sd->status.inventory[index].nameid; if(pd->petDB->AcceID == 0 || nameid != pd->petDB->AcceID || pd->pet.equip != 0) { - clif_equipitemack(sd,0,0,0); + clif->equipitemack(sd,0,0,0); return 1; } pc_delitem(sd,index,1,0,0,LOG_TYPE_OTHER); pd->pet.equip = nameid; status_set_viewdata(&pd->bl, pd->pet.class_); //Updates view_data. - clif_pet_equip_area(pd); + clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); if (battle_config.pet_equip_required) { //Skotlex: start support timers if need unsigned int tick = gettick(); @@ -696,12 +706,12 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) nameid = pd->pet.equip; pd->pet.equip = 0; status_set_viewdata(&pd->bl, pd->pet.class_); - clif_pet_equip_area(pd); + clif->send_petdata(NULL, sd->pd, 3, sd->pd->vd.head_bottom); memset(&tmp_item,0,sizeof(tmp_item)); tmp_item.nameid = nameid; tmp_item.identify = 1; if((flag = pc_additem(sd,&tmp_item,1,LOG_TYPE_OTHER))) { - clif_additem(sd,0,0,flag); + clif->additem(sd,0,0,flag); map_addflooritem(&tmp_item,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } if( battle_config.pet_equip_required ) @@ -736,7 +746,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) k=pd->petDB->FoodID; i=pc_search_inventory(sd,k); if(i < 0) { - clif_pet_food(sd,k,0); + clif->pet_food(sd,k,0); return 1; } pc_delitem(sd,i,1,0,0,LOG_TYPE_CONSUME); @@ -770,22 +780,21 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) if( pd->pet.hungry > 100 ) pd->pet.hungry = 100; - 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); + 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; } static int pet_randomwalk(struct pet_data *pd,unsigned int tick) { - const int retrycount=20; - nullpo_ret(pd); Assert((pd->msd == 0) || (pd->msd->pd == pd)); if(DIFF_TICK(pd->next_walktime,tick) < 0 && unit_can_move(&pd->bl)) { + const int retrycount=20; int i,x,y,c,d=12-pd->move_fail_count; if(d<5) d=5; for(i=0;i<retrycount;i++){ @@ -876,7 +885,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns } } - if(!target && pd->loot && pd->loot->count < pd->loot->max && DIFF_TICK(tick,pd->ud.canact_tick)>0) { + if(!target && pd->loot && pd->msd && pc_has_permission(pd->msd, PC_PERM_TRADE) && pd->loot->count < pd->loot->max && DIFF_TICK(tick,pd->ud.canact_tick)>0) { //Use half the pet's range of sight. map_foreachinrange(pet_ai_sub_hard_lootsearch,&pd->bl, pd->db->range2/2, BL_ITEM,pd,&target); @@ -903,7 +912,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns if (target->type != BL_ITEM) { //enemy targetted - if(!battle_check_range(&pd->bl,target,pd->status.rhw.range)) + if(!battle->check_range(&pd->bl,target,pd->status.rhw.range)) { //Chase if(!unit_walktobl(&pd->bl, target, pd->status.rhw.range, 2)) pet_unlocktarget(pd); //Unreachable target. @@ -1013,7 +1022,7 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd) it = &pd->loot->item[i]; if(sd){ if((flag = pc_additem(sd,it,it->amount,LOG_TYPE_PICKDROP_PLAYER))){ - clif_additem(sd,0,0,flag); + clif->additem(sd,0,0,flag); ditem = ers_alloc(item_drop_ers, struct item_drop); memcpy(&ditem->item_data, it, sizeof(struct item)); ditem->next = dlist->item; @@ -1103,9 +1112,9 @@ int pet_recovery_timer(int tid, unsigned int tick, int id, intptr_t data) if(sd->sc.data[pd->recovery->type]) { //Display a heal animation? //Detoxify is chosen for now. - clif_skill_nodamage(&pd->bl,&sd->bl,TF_DETOXIFY,1,1); + clif->skill_nodamage(&pd->bl,&sd->bl,TF_DETOXIFY,1,1); status_change_end(&sd->bl, pd->recovery->type, INVALID_TIMER); - clif_emotion(&pd->bl, E_OK); + clif->emotion(&pd->bl, E_OK); } pd->recovery->timer = INVALID_TIMER; @@ -1142,7 +1151,7 @@ int pet_heal_timer(int tid, unsigned int tick, int id, intptr_t data) } pet_stop_attack(pd); pet_stop_walking(pd,1); - clif_skill_nodamage(&pd->bl,&sd->bl,AL_HEAL,pd->s_skill->lv,1); + clif->skill_nodamage(&pd->bl,&sd->bl,AL_HEAL,pd->s_skill->lv,1); status_heal(&sd->bl, pd->s_skill->lv,0, 0); pd->s_skill->timer=add_timer(tick+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0); return 0; @@ -1187,7 +1196,7 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data) pet_stop_attack(pd); pet_stop_walking(pd,1); pd->s_skill->timer=add_timer(tick+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0); - if (skill_get_inf(pd->s_skill->id) & INF_GROUND_SKILL) + if (skill->get_inf(pd->s_skill->id) & INF_GROUND_SKILL) unit_skilluse_pos(&pd->bl, sd->bl.x, sd->bl.y, pd->s_skill->id, pd->s_skill->lv); else unit_skilluse_id(&pd->bl, sd->bl.id, pd->s_skill->id, pd->s_skill->lv); |