diff options
Diffstat (limited to 'src/map/pet.c')
-rw-r--r-- | src/map/pet.c | 133 |
1 files changed, 74 insertions, 59 deletions
diff --git a/src/map/pet.c b/src/map/pet.c index c04d9267a..e083e58d1 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -2,37 +2,39 @@ // See the LICENSE file // Portions Copyright (c) Athena Dev Teams -#include "../common/db.h" -#include "../common/timer.h" -#include "../common/nullpo.h" -#include "../common/malloc.h" -#include "../common/random.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" -#include "../common/utils.h" -#include "../common/ers.h" +#define HERCULES_CORE -#include "pc.h" -#include "status.h" -#include "map.h" -#include "path.h" -#include "intif.h" -#include "clif.h" -#include "chrif.h" #include "pet.h" -#include "itemdb.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "atcommand.h" // msg_txt() #include "battle.h" +#include "chrif.h" +#include "clif.h" +#include "intif.h" +#include "itemdb.h" +#include "log.h" +#include "map.h" #include "mob.h" #include "npc.h" +#include "path.h" +#include "pc.h" #include "script.h" #include "skill.h" +#include "status.h" #include "unit.h" -#include "atcommand.h" // msg_txt() -#include "log.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include "../common/db.h" +#include "../common/ers.h" +#include "../common/malloc.h" +#include "../common/nullpo.h" +#include "../common/random.h" +#include "../common/showmsg.h" +#include "../common/strlib.h" +#include "../common/timer.h" +#include "../common/utils.h" struct pet_interface pet_s; @@ -97,7 +99,7 @@ int pet_unlocktarget(struct pet_data *pd) * Pet Attack Skill [Skotlex] *------------------------------------------*/ int pet_attackskill(struct pet_data *pd, int target_id) { - if (!battle_config.pet_status_support || !pd->a_skill || + if (!battle_config.pet_status_support || !pd->a_skill || (battle_config.pet_equip_required && !pd->pet.equip)) return 0; @@ -105,7 +107,7 @@ int pet_attackskill(struct pet_data *pd, int target_id) { return 0; if (rnd()%100 < (pd->a_skill->rate +pd->pet.intimate*pd->a_skill->bonusrate/1000)) { - //Skotlex: Use pet's skill + //Skotlex: Use pet's skill int inf; struct block_list *bl; @@ -156,7 +158,7 @@ int pet_target_check(struct map_session_data *sd,struct block_list *bl,int type) if(pd->petDB->defence_attack_rate > 0 && rate <= 0) rate = 1; } - if(rnd()%10000 < rate) + if(rnd()%10000 < rate) { if(pd->target_id == 0 || rnd()%10000 < pd->petDB->change_target_rate) pd->target_id = bl->id; @@ -301,7 +303,7 @@ int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) 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; + pd->pet.incubate = 1; unit->free(&pd->bl,CLR_OUTSIGHT); status_calc_pc(sd,SCO_NONE); @@ -317,7 +319,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) nullpo_retr(1, sd); - Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); + Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); if(sd->status.account_id != petinfo->account_id || sd->status.char_id != petinfo->char_id) { sd->status.pet_id = 0; @@ -325,8 +327,8 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) } if (sd->status.pet_id != petinfo->pet_id) { if (sd->status.pet_id) { - //Wrong pet?? Set incuvate to no and send it back for saving. - petinfo->incuvate = 1; + //Wrong pet?? Set incubate to no and send it back for saving. + petinfo->incubate = 1; intif->save_petdata(sd->status.account_id,petinfo); sd->status.pet_id = 0; return 1; @@ -388,14 +390,14 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) { nullpo_retr(1, sd); - Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); + Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); - if(sd->status.pet_id && petinfo->incuvate == 1) { + if(sd->status.pet_id && petinfo->incubate == 1) { sd->status.pet_id = 0; return 1; } - petinfo->incuvate = 0; + petinfo->incubate = 0; petinfo->account_id = sd->status.account_id; petinfo->char_id = sd->status.char_id; sd->status.pet_id = petinfo->pet_id; @@ -416,7 +418,7 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo) 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); + Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); return 0; } @@ -431,7 +433,7 @@ int pet_recv_petdata(int account_id,struct s_pet *p,int flag) { sd->status.pet_id = 0; return 1; } - if(p->incuvate == 1) { + if(p->incubate == 1) { int i; //Delete egg from inventory. [Skotlex] for (i = 0; i < MAX_INVENTORY; i++) { @@ -537,25 +539,38 @@ int pet_catch_process2(struct map_session_data* sd, int target_id) { return 0; } -///This function is invoked when a new pet has been created, and at no other time! -int pet_get_egg(int account_id,int pet_id,int flag) { +/** + * Is invoked _only_ when a new pet has been created is a product of packet 0x3880 + * see mapif_pet_created@int_pet.c for more information + * Handles new pet data from inter-server and prepares item information + * to add pet egg + * + * pet_id - Should contain pet id otherwise means failure + * returns true on success + **/ +bool pet_get_egg(int account_id, short pet_class, int pet_id ) { struct map_session_data *sd; struct item tmp_item; - int i=0,ret=0; + int i = 0, ret = 0; - if(flag) - return 0; - - sd = map->id2sd(account_id); - if(sd == NULL) - return 0; + if( pet_id == 0 || pet_class == 0 ) + return false; - i = pet->search_petDB_index(sd->catch_target_class,PET_CLASS); + sd = map->id2sd(account_id); + if( sd == NULL ) + return false; + + // i = pet->search_petDB_index(sd->catch_target_class,PET_CLASS); + // issue: 8150 + // Before this change in cases where more than one pet egg were requested in a short + // period of time it wasn't possible to know which kind of egg was being requested after + // the first request. [Panikon] + i = pet->search_petDB_index(pet_class,PET_CLASS); sd->catch_target_class = -1; if(i < 0) { intif->delete_petdata(pet_id); - return 0; + return false; } memset(&tmp_item,0,sizeof(tmp_item)); @@ -570,7 +585,7 @@ int pet_get_egg(int account_id,int pet_id,int flag) { map->addflooritem(&tmp_item,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } - return 1; + return true; } int pet_menu(struct map_session_data *sd,int menunum) @@ -581,12 +596,12 @@ int pet_menu(struct map_session_data *sd,int menunum) return 1; //You lost the pet already. - if(!sd->status.pet_id || sd->pd->pet.intimate <= 0 || sd->pd->pet.incuvate) + if(!sd->status.pet_id || sd->pd->pet.intimate <= 0 || sd->pd->pet.incubate) return 1; egg_id = itemdb->exists(sd->pd->petDB->EggID); if (egg_id) { - if ((egg_id->flag.trade_restriction&0x01) && !pc->inventoryblank(sd)) { + if ((egg_id->flag.trade_restriction&ITR_NODROP) && !pc->inventoryblank(sd)) { clif->message(sd->fd, msg_txt(451)); // You can't return your pet because your inventory is full. return 1; } @@ -897,7 +912,7 @@ int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int64 tick (pd->ud.attacktimer != INVALID_TIMER || pd->ud.walktimer != INVALID_TIMER)) return 0; //Target already locked. - if (target->type != BL_ITEM) + if (target->type != BL_ITEM) { //enemy targetted if(!battle->check_range(&pd->bl,target,pd->status.rhw.range)) { //Chase @@ -919,7 +934,7 @@ int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int64 tick memcpy(&pd->loot->item[pd->loot->count++],&fitem->item_data,sizeof(pd->loot->item[0])); pd->loot->weight += itemdb_weight(fitem->item_data.nameid)*fitem->item_data.amount; map->clearflooritem(target); - } + } //Target is unlocked regardless of whether it was picked or not. pet->unlocktarget(pd); } @@ -1035,7 +1050,7 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd) /*========================================== * pet bonus giving skills [Valaris] / Rewritten by [Skotlex] - *------------------------------------------*/ + *------------------------------------------*/ int pet_skill_bonus_timer(int tid, int64 tick, int id, intptr_t data) { struct map_session_data *sd=map->id2sd(id); struct pet_data *pd; @@ -1076,7 +1091,7 @@ int pet_skill_bonus_timer(int tid, int64 tick, int id, intptr_t data) { /*========================================== * pet recovery skills [Valaris] / Rewritten by [Skotlex] - *------------------------------------------*/ + *------------------------------------------*/ int pet_recovery_timer(int tid, int64 tick, int id, intptr_t data) { struct map_session_data *sd=map->id2sd(id); struct pet_data *pd; @@ -1092,7 +1107,7 @@ int pet_recovery_timer(int tid, int64 tick, int id, intptr_t data) { } if(sd->sc.data[pd->recovery->type]) - { //Display a heal animation? + { //Display a heal animation? //Detoxify is chosen for now. clif->skill_nodamage(&pd->bl,&sd->bl,TF_DETOXIFY,1,1); status_change_end(&sd->bl, pd->recovery->type, INVALID_TIMER); @@ -1140,7 +1155,7 @@ int pet_heal_timer(int tid, int64 tick, int id, intptr_t data) { /*========================================== * pet support skills [Skotlex] - *------------------------------------------*/ + *------------------------------------------*/ int pet_skill_support_timer(int tid, int64 tick, int id, intptr_t data) { struct map_session_data *sd=map->id2sd(id); struct pet_data *pd; @@ -1187,12 +1202,12 @@ int pet_skill_support_timer(int tid, int64 tick, int id, intptr_t data) { * Pet read db data * pet->db.txt * pet->db2.txt - *------------------------------------------*/ + *------------------------------------------*/ int read_petdb() { char* filename[] = {"pet_db.txt","pet_db2.txt"}; FILE *fp; - int nameid,i,j,k; + int nameid,i,j,k; // Remove any previous scripts in case reloaddb was invoked. for( j = 0; j < MAX_PET_DB; j++ ) @@ -1314,9 +1329,9 @@ int read_petdb() pet->db[j].equip_script = NULL; if( *str[20] ) - pet->db[j].pet_script = script->parse(str[20], filename[i], lines, 0); + pet->db[j].pet_script = script->parse(str[20], filename[i], lines, 0, NULL); if( *str[21] ) - pet->db[j].equip_script = script->parse(str[21], filename[i], lines, 0); + pet->db[j].equip_script = script->parse(str[21], filename[i], lines, 0, NULL); j++; entries++; |