diff options
author | shennetsind <ind@henn.et> | 2013-09-16 11:53:58 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-09-16 11:53:58 -0300 |
commit | a1bdf6b04263653699c3ea0ec428aadb7b297fec (patch) | |
tree | 386004147429a1e06192da586dfb06b0baca0486 /src | |
parent | 4337e65f1dc35d244dc3abf43ed084c43d064b24 (diff) | |
download | hercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.tar.gz hercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.tar.bz2 hercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.tar.xz hercules-a1bdf6b04263653699c3ea0ec428aadb7b297fec.zip |
HPM: Pet.c Interface
Fully Integrated.
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r-- | src/map/atcommand.c | 18 | ||||
-rw-r--r-- | src/map/clif.c | 16 | ||||
-rw-r--r-- | src/map/intif.c | 6 | ||||
-rw-r--r-- | src/map/map.c | 10 | ||||
-rw-r--r-- | src/map/mob.c | 2 | ||||
-rw-r--r-- | src/map/npc.c | 8 | ||||
-rw-r--r-- | src/map/pc.c | 6 | ||||
-rw-r--r-- | src/map/pet.c | 358 | ||||
-rw-r--r-- | src/map/pet.h | 87 | ||||
-rw-r--r-- | src/map/script.c | 40 | ||||
-rw-r--r-- | src/map/skill.c | 4 | ||||
-rw-r--r-- | src/map/status.c | 4 | ||||
-rw-r--r-- | src/map/unit.c | 18 |
13 files changed, 320 insertions, 257 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index a3c13228a..2b1426180 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -1162,7 +1162,7 @@ ACMD(item) for (i = 0; i < number; i += get_count) { // if not pet egg - if (!pet_create_egg(sd, item_id)) { + if (!pet->create_egg(sd, item_id)) { memset(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = item_id; item_tmp.identify = 1; @@ -2558,16 +2558,16 @@ ACMD(makeegg) else id = atoi(message); - pet_id = search_petDB_index(id, PET_CLASS); + pet_id = pet->search_petDB_index(id, PET_CLASS); if (pet_id < 0) - pet_id = search_petDB_index(id, PET_EGG); + pet_id = pet->search_petDB_index(id, PET_EGG); if (pet_id >= 0) { - sd->catch_target_class = pet_db[pet_id].class_; + 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_, (short)mob->db(pet_db[pet_id].class_)->lv, - (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate, - 100, 0, 1, pet_db[pet_id].jname); + (short)pet->db[pet_id].class_, (short)mob->db(pet->db[pet_id].class_)->lv, + (short)pet->db[pet_id].EggID, 0, (short)pet->db[pet_id].intimate, + 100, 0, 1, pet->db[pet_id].jname); } else { clif->message(fd, msg_txt(180)); // The monster/egg name/id doesn't exist. return false; @@ -2623,7 +2623,7 @@ ACMD(petfriendly) return false; } - pet_set_intimate(pd, friendly); + pet->set_intimate(pd, friendly); clif->send_petstatus(sd); clif->message(fd, msg_txt(182)); // Pet intimacy changed. return true; @@ -3596,7 +3596,7 @@ ACMD(reloaditemdb) ACMD(reloadmobdb) { nullpo_retr(-1, sd); mob->reload(); - read_petdb(); + pet->read_db(); homun->reload(); mercenary->read_db(); mercenary->read_skilldb(); diff --git a/src/map/clif.c b/src/map/clif.c index 391c3c40b..5fe08438e 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -9444,7 +9444,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) { if( sd->pd ) { if( battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m) ) { //Return the pet to egg. [Skotlex] clif->message(sd->fd, msg_txt(666)); - pet_menu(sd, 3); //Option 3 is return to egg. + pet->menu(sd, 3); //Option 3 is return to egg. } else { iMap->addblock(&sd->pd->bl); clif->spawn(&sd->pd->bl); @@ -9517,7 +9517,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) { } if(sd->pd && sd->pd->pet.intimate > 900) - clif->pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd)); + clif->pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet->hungry_val(sd->pd)); if(homun_alive(sd->hd)) homun->init_timers(sd->hd); @@ -10678,7 +10678,7 @@ void clif_parse_EquipItem(int fd,struct map_session_data *sd) return; if(sd->inventory_data[index]->type == IT_PETARMOR){ - pet_equipitem(sd,index); + pet->equipitem(sd,index); return; } @@ -13162,7 +13162,7 @@ void clif_parse_GuildBreak(int fd, struct map_session_data *sd) /// 4 = unequip accessory void clif_parse_PetMenu(int fd, struct map_session_data *sd) { - pet_menu(sd,RFIFOB(fd,2)); + pet->menu(sd,RFIFOB(fd,2)); } @@ -13170,7 +13170,7 @@ void clif_parse_PetMenu(int fd, struct map_session_data *sd) /// 019f <id>.L void clif_parse_CatchPet(int fd, struct map_session_data *sd) { - pet_catch_process2(sd,RFIFOL(fd,2)); + pet->catch_process2(sd,RFIFOL(fd,2)); } @@ -13183,7 +13183,7 @@ void clif_parse_SelectEgg(int fd, struct map_session_data *sd) clif->authfail_fd(fd, 0); return; } - pet_select_egg(sd,RFIFOW(fd,2)-2); + pet->select_egg(sd,RFIFOW(fd,2)-2); clif_menuskill_clear(sd); } @@ -13223,7 +13223,7 @@ void clif_parse_SendEmotion(int fd, struct map_session_data *sd) /// 01a5 <name>.24B void clif_parse_ChangePetName(int fd, struct map_session_data *sd) { - pet_change_name(sd,(char*)RFIFOP(fd,2)); + pet->change_name(sd,(char*)RFIFOP(fd,2)); } @@ -17319,7 +17319,7 @@ void clif_parse_CashShopBuy(int fd, struct map_session_data *sd) { pc->paycash(sd, clif->cs.data[tab][j]->price * qty, kafra_pay);// [Ryuuzaki] for (k = 0; k < qty; k += get_count) { - if (!pet_create_egg(sd, data->nameid)) { + if (!pet->create_egg(sd, data->nameid)) { memset(&item_tmp, 0, sizeof(item_tmp)); item_tmp.nameid = data->nameid; item_tmp.identify = 1; diff --git a/src/map/intif.c b/src/map/intif.c index 1713cb38e..180195e4c 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -1278,7 +1278,7 @@ int intif_parse_GuildMasterChanged(int fd) // Request pet creation int intif_parse_CreatePet(int fd) { - pet_get_egg(RFIFOL(fd,2),RFIFOL(fd,7),RFIFOB(fd,6)); + pet->get_egg(RFIFOL(fd,2),RFIFOL(fd,7),RFIFOB(fd,6)); return 0; } @@ -1294,7 +1294,7 @@ int intif_parse_RecvPetData(int fd) } else{ memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet)); - pet_recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8)); + pet->recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8)); } return 0; @@ -1330,7 +1330,7 @@ int intif_parse_ChangeNameOk(int fd) case 0: //Players [NOT SUPPORTED YET] break; case 1: //Pets - pet_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11)); + pet->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11)); break; case 2: //Hom homun->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11)); diff --git a/src/map/map.c b/src/map/map.c index a12a6579a..d84a451ec 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1187,7 +1187,7 @@ int map_clearflooritem_timer(int tid, unsigned int tick, int id, intptr_t data) } - if (search_petDB_index(fitem->item_data.nameid, PET_EGG) >= 0) + if (pet->search_petDB_index(fitem->item_data.nameid, PET_EGG) >= 0) intif->delete_petdata(MakeDWord(fitem->item_data.card[1], fitem->item_data.card[2])); clif->clearflooritem(fitem, 0); @@ -1587,7 +1587,7 @@ int map_quit(struct map_session_data *sd) { } // Return loot to owner - if( sd->pd ) pet_lootitem_drop(sd->pd, sd); + if( sd->pd ) pet->lootitem_drop(sd->pd, sd); if( sd->state.storage_flag == 1 ) sd->state.storage_flag = 0; // No need to Double Save Storage on Quit. @@ -4944,7 +4944,7 @@ void do_final(void) guild->final(); party->do_final_party(); pc->do_final_pc(); - do_final_pet(); + pet->final(); mob->final(); homun->final(); atcommand->final_msg(); @@ -5172,6 +5172,7 @@ void map_hp_symbols(void) { HPM->share(unit,"unit"); HPM->share(npc,"npc"); HPM->share(mapreg,"mapreg"); + HPM->share(pet,"pet"); /* partial */ HPM->share(mapit,"mapit"); @@ -5220,6 +5221,7 @@ void map_load_defaults(void) { mob_defaults(); unit_defaults(); mapreg_defaults(); + pet_defaults(); } int do_init(int argc, char *argv[]) { @@ -5414,7 +5416,7 @@ int do_init(int argc, char *argv[]) party->do_init_party(); guild->init(); storage->init(); - do_init_pet(); + pet->init(); homun->init(); mercenary->init(); elemental->do_init_elemental(); diff --git a/src/map/mob.c b/src/map/mob.c index 13fdae1ee..94d5b3527 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -2370,7 +2370,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) continue; if( mvp_sd && it->type == IT_PETEGG ) { - pet_create_egg(mvp_sd, md->db->dropitem[i].nameid); + pet->create_egg(mvp_sd, md->db->dropitem[i].nameid); continue; } diff --git a/src/map/npc.c b/src/map/npc.c index 1a813560b..bb3a4b38e 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1336,7 +1336,7 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns memset(&item_tmp,0,sizeof(item_tmp)); - if( !pet_create_egg(sd,nameid) ) + if( !pet->create_egg(sd,nameid) ) { item_tmp.nameid = nameid; item_tmp.identify = 1; @@ -1440,7 +1440,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po pc->paycash(sd, price, points); - if( !pet_create_egg(sd, nameid) ) + if( !pet->create_egg(sd, nameid) ) { struct item item_tmp; memset(&item_tmp, 0, sizeof(struct item)); @@ -1543,7 +1543,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list) struct item item_tmp; if (itemdb_type(nameid) == IT_PETEGG) - pet_create_egg(sd, nameid); + pet->create_egg(sd, nameid); else { memset(&item_tmp,0,sizeof(item_tmp)); item_tmp.nameid = nameid; @@ -1683,7 +1683,7 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list) amount = item_list[i*2+1]; if( sd->inventory_data[idx]->type == IT_PETEGG && sd->status.inventory[idx].card[0] == CARD0_PET ) { - if( search_petDB_index(sd->status.inventory[idx].nameid, PET_EGG) >= 0 ) { + if( pet->search_petDB_index(sd->status.inventory[idx].nameid, PET_EGG) >= 0 ) { intif->delete_petdata(MakeDWord(sd->status.inventory[idx].card[1], sd->status.inventory[idx].card[2])); } } diff --git a/src/map/pc.c b/src/map/pc.c index b591cd483..dc52c88e1 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -6700,7 +6700,7 @@ void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int h } if( sd->status.pet_id > 0 && sd->pd && battle_config.pet_damage_support ) - pet_target_check(sd,src,1); + pet->target_check(sd,src,1); if( sd->status.ele_id > 0 ) elemental->set_target(sd,src); @@ -6726,13 +6726,13 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { if(sd->status.pet_id > 0 && sd->pd) { struct pet_data *pd = sd->pd; if( !map[sd->bl.m].flag.noexppenalty ) { - pet_set_intimate(pd, pd->pet.intimate - pd->petDB->die); + pet->set_intimate(pd, pd->pet.intimate - pd->petDB->die); if( pd->pet.intimate < 0 ) pd->pet.intimate = 0; clif->send_petdata(sd,sd->pd,1,pd->pet.intimate); } if( sd->pd->target_id ) // Unlock all targets... - pet_unlocktarget(sd->pd); + pet->unlocktarget(sd->pd); } if (sd->status.hom_id > 0){ diff --git a/src/map/pet.c b/src/map/pet.c index c1bce0b5b..8498517ef 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -34,14 +34,10 @@ #include <stdlib.h> #include <string.h> +struct pet_interface pet_s; #define MIN_PETTHINKTIME 100 -struct s_pet_db pet_db[MAX_PET_DB]; - -static struct eri *item_drop_ers; //For loot drops delay structures. -static struct eri *item_drop_list_ers; - int pet_hungry_val(struct pet_data *pd) { nullpo_ret(pd); @@ -74,16 +70,16 @@ void pet_set_intimate(struct pet_data *pd, int value) int pet_create_egg(struct map_session_data *sd, int item_id) { - int pet_id = search_petDB_index(item_id, PET_EGG); + int pet_id = pet->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_; + 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_, - (short)mob->db(pet_db[pet_id].class_)->lv, - (short)pet_db[pet_id].EggID, 0, - (short)pet_db[pet_id].intimate, - 100, 0, 1, pet_db[pet_id].jname); + (short)pet->db[pet_id].class_, + (short)mob->db(pet->db[pet_id].class_)->lv, + (short)pet->db[pet_id].EggID, 0, + (short)pet->db[pet_id].intimate, + 100, 0, 1, pet->db[pet_id].jname); return 1; } @@ -187,12 +183,12 @@ int pet_sc_check(struct map_session_data *sd, int type) || pd->recovery->type != type ) return 1; - pd->recovery->timer = iTimer->add_timer(iTimer->gettick()+pd->recovery->delay*1000,pet_recovery_timer,sd->bl.id,0); + pd->recovery->timer = iTimer->add_timer(iTimer->gettick()+pd->recovery->delay*1000,pet->recovery_timer,sd->bl.id,0); return 0; } -static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data) +int pet_hungry(int tid, unsigned int tick, int id, intptr_t data) { struct map_session_data *sd; struct pet_data *pd; @@ -220,7 +216,7 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data) { pet_stop_attack(pd); pd->pet.hungry = 0; - pet_set_intimate(pd, pd->pet.intimate - battle_config.pet_hungry_friendly_decrease); + pet->set_intimate(pd, pd->pet.intimate - battle_config.pet_hungry_friendly_decrease); if( pd->pet.intimate <= 0 ) { pd->pet.intimate = 0; @@ -237,7 +233,7 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data) interval = pd->petDB->hungry_delay; if(interval <= 0) interval = 1; - pd->pet_hungry_timer = iTimer->add_timer(tick+interval,pet_hungry,sd->bl.id,0); + pd->pet_hungry_timer = iTimer->add_timer(tick+interval,pet->hungry,sd->bl.id,0); return 0; } @@ -248,14 +244,14 @@ int search_petDB_index(int key,int type) for( i = 0; i < MAX_PET_DB; i++ ) { - if(pet_db[i].class_ <= 0) + if(pet->db[i].class_ <= 0) continue; switch(type) { - case PET_CLASS: if(pet_db[i].class_ == key) return i; break; - case PET_CATCH: if(pet_db[i].itemID == key) return i; break; - case PET_EGG: if(pet_db[i].EggID == key) return i; break; - case PET_EQUIP: if(pet_db[i].AcceID == key) return i; break; - case PET_FOOD: if(pet_db[i].FoodID == key) return i; break; + case PET_CLASS: if(pet->db[i].class_ == key) return i; break; + case PET_CATCH: if(pet->db[i].itemID == key) return i; break; + case PET_EGG: if(pet->db[i].EggID == key) return i; break; + case PET_EQUIP: if(pet->db[i].AcceID == key) return i; break; + case PET_FOOD: if(pet->db[i].FoodID == key) return i; break; default: return -1; } @@ -267,14 +263,14 @@ int pet_hungry_timer_delete(struct pet_data *pd) { nullpo_ret(pd); if(pd->pet_hungry_timer != INVALID_TIMER) { - iTimer->delete_timer(pd->pet_hungry_timer,pet_hungry); + iTimer->delete_timer(pd->pet_hungry_timer,pet->hungry); pd->pet_hungry_timer = INVALID_TIMER; } return 1; } -static int pet_performance(struct map_session_data *sd, struct pet_data *pd) +int pet_performance(struct map_session_data *sd, struct pet_data *pd) { int val; @@ -287,16 +283,16 @@ static int pet_performance(struct map_session_data *sd, struct pet_data *pd) pet_stop_walking(pd,2000<<8); clif->send_petdata(NULL, pd, 4, rnd()%val + 1); - pet_lootitem_drop(pd,NULL); + pet->lootitem_drop(pd,NULL); return 1; } -static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) +int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) { struct item tmp_item; int flag; - pet_lootitem_drop(pd,sd); + pet->lootitem_drop(pd,sd); memset(&tmp_item,0,sizeof(tmp_item)); tmp_item.nameid = pd->petDB->EggID; tmp_item.identify = 1; @@ -317,7 +313,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd) return 1; } -int pet_data_init(struct map_session_data *sd, struct s_pet *pet) +int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) { struct pet_data *pd; int i=0,interval=0; @@ -326,23 +322,23 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet) Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd); - if(sd->status.account_id != pet->account_id || sd->status.char_id != pet->char_id) { + if(sd->status.account_id != petinfo->account_id || sd->status.char_id != petinfo->char_id) { sd->status.pet_id = 0; return 1; } - if (sd->status.pet_id != pet->pet_id) { + 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. - pet->incuvate = 1; - intif->save_petdata(sd->status.account_id,pet); + petinfo->incuvate = 1; + intif->save_petdata(sd->status.account_id,petinfo); sd->status.pet_id = 0; return 1; } //The pet_id value was lost? odd... restore it. - sd->status.pet_id = pet->pet_id; + sd->status.pet_id = petinfo->pet_id; } - i = search_petDB_index(pet->class_,PET_CLASS); + i = pet->search_petDB_index(petinfo->class_,PET_CLASS); if(i < 0) { sd->status.pet_id = 0; return 1; @@ -352,10 +348,10 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet) pd->bl.id = npc->get_new_npc_id(); pd->msd = sd; - pd->petDB = &pet_db[i]; - pd->db = mob->db(pet->class_); - memcpy(&pd->pet, pet, sizeof(struct s_pet)); - iStatus->set_viewdata(&pd->bl, pet->class_); + pd->petDB = &pet->db[i]; + pd->db = mob->db(petinfo->class_); + memcpy(&pd->pet, petinfo, sizeof(struct s_pet)); + iStatus->set_viewdata(&pd->bl, petinfo->class_); unit->dataset(&pd->bl); pd->ud.dir = sd->ud.dir; @@ -372,7 +368,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet) pd->last_thinktime = iTimer->gettick(); pd->state.skillbonus = 0; if( battle_config.pet_status_support ) - script->run(pet_db[i].pet_script,0,sd->bl.id,0); + script->run(pet->db[i].pet_script,0,sd->bl.id,0); if( pd->petDB && pd->petDB->equip_script ) status_calc_pc(sd,0); @@ -382,31 +378,31 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet) interval = pd->petDB->hungry_delay; if( interval <= 0 ) interval = 1; - pd->pet_hungry_timer = iTimer->add_timer(iTimer->gettick() + interval, pet_hungry, sd->bl.id, 0); + pd->pet_hungry_timer = iTimer->add_timer(iTimer->gettick() + interval, pet->hungry, sd->bl.id, 0); return 0; } -int pet_birth_process(struct map_session_data *sd, struct s_pet *pet) +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); - if(sd->status.pet_id && pet->incuvate == 1) { + if(sd->status.pet_id && petinfo->incuvate == 1) { sd->status.pet_id = 0; return 1; } - pet->incuvate = 0; - pet->account_id = sd->status.account_id; - pet->char_id = sd->status.char_id; - sd->status.pet_id = pet->pet_id; - if(pet_data_init(sd, pet)) { + petinfo->incuvate = 0; + petinfo->account_id = sd->status.account_id; + petinfo->char_id = sd->status.char_id; + sd->status.pet_id = petinfo->pet_id; + if(pet->data_init(sd, petinfo)) { sd->status.pet_id = 0; return 1; } - intif->save_petdata(sd->status.account_id,pet); + intif->save_petdata(sd->status.account_id,petinfo); if (iMap->save_settings&8) chrif->save(sd,0); //is it REALLY Needed to save the char for hatching a pet? [Skotlex] @@ -447,10 +443,10 @@ int pet_recv_petdata(int account_id,struct s_pet *p,int flag) sd->status.pet_id = 0; return 1; } - if (!pet_birth_process(sd,p)) //Pet hatched. Delete egg. + if (!pet->birth_process(sd,p)) //Pet hatched. Delete egg. pc->delitem(sd,i,1,0,0,LOG_TYPE_OTHER); } else { - pet_data_init(sd,p); + pet->data_init(sd,p); if(sd->pd && sd->bl.prev != NULL) { iMap->addblock(&sd->pd->bl); clif->spawn(&sd->pd->bl); @@ -507,7 +503,7 @@ int pet_catch_process2(struct map_session_data* sd, int target_id) //FIXME: delete taming item here, if this was an item-invoked capture and the item was flagged as delay-consume [ultramage] - i = search_petDB_index(md->class_,PET_CLASS); + i = pet->search_petDB_index(md->class_,PET_CLASS); //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)) sd->catch_target_class = md->class_; @@ -518,7 +514,7 @@ int pet_catch_process2(struct map_session_data* sd, int target_id) return 1; } - pet_catch_rate = (pet_db[i].capture + (sd->status.base_level - md->level)*30 + sd->battle_status.luk*20)*(200 - get_percentage(md->status.hp, md->status.max_hp))/100; + pet_catch_rate = (pet->db[i].capture + (sd->status.base_level - md->level)*30 + sd->battle_status.luk*20)*(200 - get_percentage(md->status.hp, md->status.max_hp))/100; if(pet_catch_rate < 1) pet_catch_rate = 1; if(battle_config.pet_catch_rate != 100) @@ -529,8 +525,8 @@ int pet_catch_process2(struct map_session_data* sd, int target_id) unit->remove_map(&md->bl,CLR_OUTSIGHT,ALC_MARK); status_kill(&md->bl); 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); + 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 { @@ -554,7 +550,7 @@ int pet_get_egg(int account_id,int pet_id,int flag) if(sd == NULL) return 0; - i = search_petDB_index(sd->catch_target_class,PET_CLASS); + i = pet->search_petDB_index(sd->catch_target_class,PET_CLASS); sd->catch_target_class = -1; if(i < 0) { @@ -563,7 +559,7 @@ int pet_get_egg(int account_id,int pet_id,int flag) } memset(&tmp_item,0,sizeof(tmp_item)); - tmp_item.nameid = pet_db[i].EggID; + tmp_item.nameid = pet->db[i].EggID; tmp_item.identify = 1; tmp_item.card[0] = CARD0_PET; tmp_item.card[1] = GetWord(pet_id,0); @@ -577,10 +573,6 @@ int pet_get_egg(int account_id,int pet_id,int flag) return 1; } -static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd); -static int pet_food(struct map_session_data *sd, struct pet_data *pd); -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; @@ -605,16 +597,16 @@ int pet_menu(struct map_session_data *sd,int menunum) clif->send_petstatus(sd); break; case 1: - pet_food(sd, sd->pd); + pet->food(sd, sd->pd); break; case 2: - pet_performance(sd, sd->pd); + pet->performance(sd, sd->pd); break; case 3: - pet_return_egg(sd, sd->pd); + pet->return_egg(sd, sd->pd); break; case 4: - pet_unequipitem(sd, sd->pd); + pet->unequipitem(sd, sd->pd); break; } return 0; @@ -684,18 +676,18 @@ int pet_equipitem(struct map_session_data *sd,int index) if (pd->s_skill && pd->s_skill->timer == INVALID_TIMER) { if (pd->s_skill->id) - pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet_skill_support_timer, sd->bl.id, 0); + pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet->skill_support_timer, sd->bl.id, 0); else - pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet_heal_timer, sd->bl.id, 0); + pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet->heal_timer, sd->bl.id, 0); } if (pd->bonus && pd->bonus->timer == INVALID_TIMER) - pd->bonus->timer=iTimer->add_timer(tick+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0); + pd->bonus->timer=iTimer->add_timer(tick+pd->bonus->delay*1000, pet->skill_bonus_timer, sd->bl.id, 0); } return 0; } -static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) +int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) { struct item tmp_item; int nameid,flag; @@ -724,14 +716,14 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) if( pd->s_skill && pd->s_skill->timer != INVALID_TIMER ) { if( pd->s_skill->id ) - iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer); else - iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer); pd->s_skill->timer = INVALID_TIMER; } if( pd->bonus && pd->bonus->timer != INVALID_TIMER ) { - iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer); + iTimer->delete_timer(pd->bonus->timer, pet->skill_bonus_timer); pd->bonus->timer = INVALID_TIMER; } } @@ -739,7 +731,7 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd) return 0; } -static int pet_food(struct map_session_data *sd, struct pet_data *pd) +int pet_food(struct map_session_data *sd, struct pet_data *pd) { int i,k; @@ -752,7 +744,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) pc->delitem(sd,i,1,0,0,LOG_TYPE_CONSUME); if( pd->pet.hungry > 90 ) - pet_set_intimate(pd, pd->pet.intimate - pd->petDB->r_full); + pet->set_intimate(pd, pd->pet.intimate - pd->petDB->r_full); else { if( battle_config.pet_friendly_rate != 100 ) @@ -765,7 +757,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) if( k <= 0 ) k = 1; } - pet_set_intimate(pd, pd->pet.intimate + k); + pet->set_intimate(pd, pd->pet.intimate + k); } if( pd->pet.intimate <= 0 ) { @@ -787,7 +779,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) return 0; } -static int pet_randomwalk(struct pet_data *pd,unsigned int tick) +int pet_randomwalk(struct pet_data *pd,unsigned int tick) { nullpo_ret(pd); @@ -828,7 +820,7 @@ static int pet_randomwalk(struct pet_data *pd,unsigned int tick) return 0; } -static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, unsigned int tick) +int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, unsigned int tick) { struct block_list *target = NULL; @@ -847,14 +839,14 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns if(pd->pet.intimate <= 0) { //Pet should just... well, random walk. - pet_randomwalk(pd,tick); + pet->randomwalk(pd,tick); return 0; } if (!check_distance_bl(&sd->bl, &pd->bl, pd->db->range3)) { //Master too far, chase. if(pd->target_id) - pet_unlocktarget(pd); + pet->unlocktarget(pd); if(pd->ud.walktimer != INVALID_TIMER && pd->ud.target == sd->bl.id) return 0; //Already walking to him if (DIFF_TICK(tick, pd->ud.canmove_tick) < 0) @@ -863,7 +855,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns if(pd->status.speed <= 0) pd->status.speed = 1; if (!unit->walktobl(&pd->bl, &sd->bl, 3, 0)) - pet_randomwalk(pd,tick); + pet->randomwalk(pd,tick); return 0; } @@ -881,13 +873,13 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns !check_distance_bl(&pd->bl, target, pd->db->range3)) { target = NULL; - pet_unlocktarget(pd); + pet->unlocktarget(pd); } } 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. - iMap->foreachinrange(pet_ai_sub_hard_lootsearch,&pd->bl, + iMap->foreachinrange(pet->ai_sub_hard_lootsearch,&pd->bl, pd->db->range2/2, BL_ITEM,pd,&target); } @@ -901,7 +893,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns unit->calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); if(!unit->walktoxy(&pd->bl,pd->ud.to_x,pd->ud.to_y,0)) - pet_randomwalk(pd,tick); + pet->randomwalk(pd,tick); return 0; } @@ -915,7 +907,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns 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. + pet->unlocktarget(pd); //Unreachable target. return 0; } //Continuous attack. @@ -924,7 +916,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns if (!check_distance_bl(&pd->bl, target, 1)) { //Out of range if(!unit->walktobl(&pd->bl, target, 1, 1)) //Unreachable target. - pet_unlocktarget(pd); + pet->unlocktarget(pd); return 0; } else{ struct flooritem_data *fitem = (struct flooritem_data *)target; @@ -934,29 +926,29 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns iMap->clearflooritem(target); } //Target is unlocked regardless of whether it was picked or not. - pet_unlocktarget(pd); + pet->unlocktarget(pd); } } return 0; } -static int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap) +int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap) { unsigned int tick = va_arg(ap,unsigned int); if(sd->status.pet_id && sd->pd) - pet_ai_sub_hard(sd->pd,sd,tick); + pet->ai_sub_hard(sd->pd,sd,tick); return 0; } -static int pet_ai_hard(int tid, unsigned int tick, int id, intptr_t data) +int pet_ai_hard(int tid, unsigned int tick, int id, intptr_t data) { - iMap->map_foreachpc(pet_ai_sub_foreachclient,tick); + iMap->map_foreachpc(pet->ai_sub_foreachclient,tick); return 0; } -static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap) +int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap) { struct pet_data* pd; struct flooritem_data *fitem = (struct flooritem_data *)bl; @@ -983,7 +975,7 @@ static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap) return 0; } -static int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data) +int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data) { struct item_drop_list *list; struct item_drop *ditem, *ditem_prev; @@ -995,9 +987,9 @@ static int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data list->first_charid,list->second_charid,list->third_charid,0); ditem_prev = ditem; ditem = ditem->next; - ers_free(item_drop_ers, ditem_prev); + ers_free(pet->item_drop_ers, ditem_prev); } - ers_free(item_drop_list_ers, list); + ers_free(pet->item_drop_list_ers, list); return 0; } @@ -1009,7 +1001,7 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd) struct item *it; if(!pd || !pd->loot || !pd->loot->count) return 0; - dlist = ers_alloc(item_drop_list_ers, struct item_drop_list); + dlist = ers_alloc(pet->item_drop_list_ers, struct item_drop_list); dlist->m = pd->bl.m; dlist->x = pd->bl.x; dlist->y = pd->bl.y; @@ -1023,14 +1015,14 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd) if(sd){ if((flag = pc->additem(sd,it,it->amount,LOG_TYPE_PICKDROP_PLAYER))){ clif->additem(sd,0,0,flag); - ditem = ers_alloc(item_drop_ers, struct item_drop); + ditem = ers_alloc(pet->item_drop_ers, struct item_drop); memcpy(&ditem->item_data, it, sizeof(struct item)); ditem->next = dlist->item; dlist->item = ditem; } } else { - ditem = ers_alloc(item_drop_ers, struct item_drop); + ditem = ers_alloc(pet->item_drop_ers, struct item_drop); memcpy(&ditem->item_data, it, sizeof(struct item)); ditem->next = dlist->item; dlist->item = ditem; @@ -1043,9 +1035,9 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd) pd->ud.canact_tick = iTimer->gettick()+10000; //prevent picked up during 10*1000ms if (dlist->item) - iTimer->add_timer(iTimer->gettick()+540,pet_delay_item_drop,0,(intptr_t)dlist); + iTimer->add_timer(iTimer->gettick()+540,pet->delay_item_drop,0,(intptr_t)dlist); else - ers_free(item_drop_list_ers, dlist); + ers_free(pet->item_drop_list_ers, dlist); return 1; } @@ -1087,7 +1079,7 @@ int pet_skill_bonus_timer(int tid, unsigned int tick, int id, intptr_t data) status_calc_pc(sd, 0); } // wait for the next timer - pd->bonus->timer=iTimer->add_timer(tick+timer,pet_skill_bonus_timer,sd->bl.id,0); + pd->bonus->timer=iTimer->add_timer(tick+timer,pet->skill_bonus_timer,sd->bl.id,0); return 0; } @@ -1146,14 +1138,14 @@ int pet_heal_timer(int tid, unsigned int tick, int id, intptr_t data) (rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp || (rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect ) { //Wait (how long? 1 sec for every 10% of remaining) - pd->s_skill->timer=iTimer->add_timer(iTimer->gettick()+(rate>10?rate:10)*100,pet_heal_timer,sd->bl.id,0); + pd->s_skill->timer=iTimer->add_timer(iTimer->gettick()+(rate>10?rate:10)*100,pet->heal_timer,sd->bl.id,0); return 0; } pet_stop_attack(pd); pet_stop_walking(pd,1); clif->skill_nodamage(&pd->bl,&sd->bl,AL_HEAL,pd->s_skill->lv,1); iStatus->heal(&sd->bl, pd->s_skill->lv,0, 0); - pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0); + pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet->heal_timer,sd->bl.id,0); return 0; } @@ -1180,7 +1172,7 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data) if (DIFF_TICK(pd->ud.canact_tick, tick) > 0) { //Wait until the pet can act again. - pd->s_skill->timer=iTimer->add_timer(pd->ud.canact_tick,pet_skill_support_timer,sd->bl.id,0); + pd->s_skill->timer=iTimer->add_timer(pd->ud.canact_tick,pet->skill_support_timer,sd->bl.id,0); return 0; } @@ -1189,13 +1181,13 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data) (rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp || (rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect ) { //Wait (how long? 1 sec for every 10% of remaining) - pd->s_skill->timer=iTimer->add_timer(tick+(rate>10?rate:10)*100,pet_skill_support_timer,sd->bl.id,0); + pd->s_skill->timer=iTimer->add_timer(tick+(rate>10?rate:10)*100,pet->skill_support_timer,sd->bl.id,0); return 0; } pet_stop_attack(pd); pet_stop_walking(pd,1); - pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0); + pd->s_skill->timer=iTimer->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) unit->skilluse_pos(&pd->bl, sd->bl.x, sd->bl.y, pd->s_skill->id, pd->s_skill->lv); else @@ -1205,8 +1197,8 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data) /*========================================== * Pet read db data - * pet_db.txt - * pet_db2.txt + * pet->db.txt + * pet->db2.txt *------------------------------------------*/ int read_petdb() { @@ -1217,20 +1209,20 @@ int read_petdb() // Remove any previous scripts in case reloaddb was invoked. for( j = 0; j < MAX_PET_DB; j++ ) { - if( pet_db[j].pet_script ) + if( pet->db[j].pet_script ) { - script->free_code(pet_db[j].pet_script); - pet_db[j].pet_script = NULL; + script->free_code(pet->db[j].pet_script); + pet->db[j].pet_script = NULL; } - if( pet_db[j].equip_script ) + if( pet->db[j].equip_script ) { - script->free_code(pet_db[j].equip_script); - pet_db[j].pet_script = NULL; + script->free_code(pet->db[j].equip_script); + pet->db[j].pet_script = NULL; } } // clear database - memset(pet_db,0,sizeof(pet_db)); + memset(pet->db,0,sizeof(pet->db)); j = 0; // entry counter for( i = 0; i < ARRAYLENGTH(filename); i++ ) @@ -1311,35 +1303,35 @@ int read_petdb() continue; } - pet_db[j].class_ = nameid; - safestrncpy(pet_db[j].name,str[1],NAME_LENGTH); - safestrncpy(pet_db[j].jname,str[2],NAME_LENGTH); - pet_db[j].itemID=atoi(str[3]); - pet_db[j].EggID=atoi(str[4]); - pet_db[j].AcceID=atoi(str[5]); - pet_db[j].FoodID=atoi(str[6]); - pet_db[j].fullness=atoi(str[7]); - pet_db[j].hungry_delay=atoi(str[8])*1000; - pet_db[j].r_hungry=atoi(str[9]); - if( pet_db[j].r_hungry <= 0 ) - pet_db[j].r_hungry=1; - pet_db[j].r_full=atoi(str[10]); - pet_db[j].intimate=atoi(str[11]); - pet_db[j].die=atoi(str[12]); - pet_db[j].capture=atoi(str[13]); - pet_db[j].speed=atoi(str[14]); - pet_db[j].s_perfor=(char)atoi(str[15]); - pet_db[j].talk_convert_class=atoi(str[16]); - pet_db[j].attack_rate=atoi(str[17]); - pet_db[j].defence_attack_rate=atoi(str[18]); - pet_db[j].change_target_rate=atoi(str[19]); - pet_db[j].pet_script = NULL; - pet_db[j].equip_script = NULL; + pet->db[j].class_ = nameid; + safestrncpy(pet->db[j].name,str[1],NAME_LENGTH); + safestrncpy(pet->db[j].jname,str[2],NAME_LENGTH); + pet->db[j].itemID=atoi(str[3]); + pet->db[j].EggID=atoi(str[4]); + pet->db[j].AcceID=atoi(str[5]); + pet->db[j].FoodID=atoi(str[6]); + pet->db[j].fullness=atoi(str[7]); + pet->db[j].hungry_delay=atoi(str[8])*1000; + pet->db[j].r_hungry=atoi(str[9]); + if( pet->db[j].r_hungry <= 0 ) + pet->db[j].r_hungry=1; + pet->db[j].r_full=atoi(str[10]); + pet->db[j].intimate=atoi(str[11]); + pet->db[j].die=atoi(str[12]); + pet->db[j].capture=atoi(str[13]); + pet->db[j].speed=atoi(str[14]); + pet->db[j].s_perfor=(char)atoi(str[15]); + pet->db[j].talk_convert_class=atoi(str[16]); + pet->db[j].attack_rate=atoi(str[17]); + pet->db[j].defence_attack_rate=atoi(str[18]); + pet->db[j].change_target_rate=atoi(str[19]); + pet->db[j].pet_script = NULL; + 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); 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); j++; entries++; @@ -1358,19 +1350,19 @@ int read_petdb() *------------------------------------------*/ int do_init_pet(void) { - read_petdb(); + pet->read_db(); - item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE); - item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.c::item_drop_list_ers",ERS_OPT_NONE); + pet->item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE); + pet->item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.c::item_drop_list_ers",ERS_OPT_NONE); - iTimer->add_timer_func_list(pet_hungry,"pet_hungry"); - iTimer->add_timer_func_list(pet_ai_hard,"pet_ai_hard"); - iTimer->add_timer_func_list(pet_skill_bonus_timer,"pet_skill_bonus_timer"); // [Valaris] - iTimer->add_timer_func_list(pet_delay_item_drop,"pet_delay_item_drop"); - iTimer->add_timer_func_list(pet_skill_support_timer, "pet_skill_support_timer"); // [Skotlex] - iTimer->add_timer_func_list(pet_recovery_timer,"pet_recovery_timer"); // [Valaris] - iTimer->add_timer_func_list(pet_heal_timer,"pet_heal_timer"); // [Valaris] - iTimer->add_timer_interval(iTimer->gettick()+MIN_PETTHINKTIME,pet_ai_hard,0,0,MIN_PETTHINKTIME); + iTimer->add_timer_func_list(pet->hungry,"pet_hungry"); + iTimer->add_timer_func_list(pet->ai_hard,"pet_ai_hard"); + iTimer->add_timer_func_list(pet->skill_bonus_timer,"pet_skill_bonus_timer"); // [Valaris] + iTimer->add_timer_func_list(pet->delay_item_drop,"pet_delay_item_drop"); + iTimer->add_timer_func_list(pet->skill_support_timer, "pet_skill_support_timer"); // [Skotlex] + iTimer->add_timer_func_list(pet->recovery_timer,"pet_recovery_timer"); // [Valaris] + iTimer->add_timer_func_list(pet->heal_timer,"pet_heal_timer"); // [Valaris] + iTimer->add_timer_interval(iTimer->gettick()+MIN_PETTHINKTIME,pet->ai_hard,0,0,MIN_PETTHINKTIME); return 0; } @@ -1380,18 +1372,68 @@ int do_final_pet(void) int i; for( i = 0; i < MAX_PET_DB; i++ ) { - if( pet_db[i].pet_script ) + if( pet->db[i].pet_script ) { - script->free_code(pet_db[i].pet_script); - pet_db[i].pet_script = NULL; + script->free_code(pet->db[i].pet_script); + pet->db[i].pet_script = NULL; } - if( pet_db[i].equip_script ) + if( pet->db[i].equip_script ) { - script->free_code(pet_db[i].equip_script); - pet_db[i].equip_script = NULL; + script->free_code(pet->db[i].equip_script); + pet->db[i].equip_script = NULL; } } - ers_destroy(item_drop_ers); - ers_destroy(item_drop_list_ers); + ers_destroy(pet->item_drop_ers); + ers_destroy(pet->item_drop_list_ers); return 0; } +void pet_defaults(void) { + pet = &pet_s; + + memset(pet->db,0,sizeof(pet->db)); + pet->item_drop_ers = NULL; + pet->item_drop_list_ers = NULL; + + /* */ + pet->init = do_init_pet; + pet->final = do_final_pet; + + /* */ + pet->hungry_val = pet_hungry_val; + pet->set_intimate = pet_set_intimate; + pet->create_egg = pet_create_egg; + pet->unlocktarget = pet_unlocktarget; + pet->attackskill = pet_attackskill; + pet->target_check = pet_target_check; + pet->sc_check = pet_sc_check; + pet->hungry = pet_hungry; + pet->search_petDB_index = search_petDB_index; + pet->hungry_timer_delete = pet_hungry_timer_delete; + pet->performance = pet_performance; + pet->return_egg = pet_return_egg; + pet->data_init = pet_data_init; + pet->birth_process = pet_birth_process; + pet->recv_petdata = pet_recv_petdata; + pet->select_egg = pet_select_egg; + pet->catch_process1 = pet_catch_process1; + pet->catch_process2 = pet_catch_process2; + pet->get_egg = pet_get_egg; + pet->unequipitem = pet_unequipitem; + pet->food = pet_food; + pet->ai_sub_hard_lootsearch = pet_ai_sub_hard_lootsearch; + pet->menu = pet_menu; + pet->change_name = pet_change_name; + pet->change_name_ack = pet_change_name_ack; + pet->equipitem = pet_equipitem; + pet->randomwalk = pet_randomwalk; + pet->ai_sub_hard = pet_ai_sub_hard; + pet->ai_sub_foreachclient = pet_ai_sub_foreachclient; + pet->ai_hard = pet_ai_hard; + pet->delay_item_drop = pet_delay_item_drop; + pet->lootitem_drop = pet_lootitem_drop; + pet->skill_bonus_timer = pet_skill_bonus_timer; + pet->recovery_timer = pet_recovery_timer; + pet->heal_timer = pet_heal_timer; + pet->skill_support_timer = pet_skill_support_timer; + pet->read_db = read_petdb; +} diff --git a/src/map/pet.h b/src/map/pet.h index 4060b5382..b0e7cec6d 100644 --- a/src/map/pet.h +++ b/src/map/pet.h @@ -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 #ifndef _PET_H_ #define _PET_H_ @@ -30,7 +31,6 @@ struct s_pet_db { struct script_code *equip_script; struct script_code *pet_script; }; -extern struct s_pet_db pet_db[MAX_PET_DB]; enum { PET_CLASS,PET_CATCH,PET_EGG,PET_EQUIP,PET_FOOD }; @@ -98,39 +98,58 @@ struct pet_data { struct map_session_data *msd; }; - - -int pet_create_egg(struct map_session_data *sd, int item_id); -int pet_hungry_val(struct pet_data *pd); -void pet_set_intimate(struct pet_data *pd, int value); -int pet_target_check(struct map_session_data *sd,struct block_list *bl,int type); -int pet_unlocktarget(struct pet_data *pd); -int pet_sc_check(struct map_session_data *sd, int type); //Skotlex -int search_petDB_index(int key,int type); -int pet_hungry_timer_delete(struct pet_data *pd); -int pet_data_init(struct map_session_data *sd, struct s_pet *pet); -int pet_birth_process(struct map_session_data *sd, struct s_pet *pet); -int pet_recv_petdata(int account_id,struct s_pet *p,int flag); -int pet_select_egg(struct map_session_data *sd,short egg_index); -int pet_catch_process1(struct map_session_data *sd,int target_class); -int pet_catch_process2(struct map_session_data *sd,int target_id); -int pet_get_egg(int account_id,int pet_id,int flag); -int pet_menu(struct map_session_data *sd,int menunum); -int pet_change_name(struct map_session_data *sd,char *name); -int pet_change_name_ack(struct map_session_data *sd, char* name, int flag); -int pet_equipitem(struct map_session_data *sd,int index); -int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd); -int pet_attackskill(struct pet_data *pd, int target_id); -int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data); // [Skotlex] -int pet_skill_bonus_timer(int tid, unsigned int tick, int id, intptr_t data); // [Valaris] -int pet_recovery_timer(int tid, unsigned int tick, int id, intptr_t data); // [Valaris] -int pet_heal_timer(int tid, unsigned int tick, int id, intptr_t data); // [Valaris] - #define pet_stop_walking(pd, type) unit->stop_walking(&(pd)->bl, type) #define pet_stop_attack(pd) unit->stop_attack(&(pd)->bl) -int read_petdb(void); -int do_init_pet(void); -int do_final_pet(void); +struct pet_interface { + struct s_pet_db db[MAX_PET_DB]; + struct eri *item_drop_ers; //For loot drops delay structures. + struct eri *item_drop_list_ers; + /* */ + int (*init) (void); + int (*final) (void); + /* */ + int (*hungry_val) (struct pet_data *pd); + 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); + int (*attackskill) (struct pet_data *pd, int target_id); + int (*target_check) (struct map_session_data *sd, struct block_list *bl, int type); + int (*sc_check) (struct map_session_data *sd, int type); + int (*hungry) (int tid, unsigned int tick, int id, intptr_t data); + int (*search_petDB_index) (int key, int type); + int (*hungry_timer_delete) (struct pet_data *pd); + 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 *pet); + int (*birth_process) (struct map_session_data *sd, struct s_pet *pet); + int (*recv_petdata) (int account_id, struct s_pet *p, int flag); + int (*select_egg) (struct map_session_data *sd, short egg_index); + int (*catch_process1) (struct map_session_data *sd, int target_class); + int (*catch_process2) (struct map_session_data *sd, int target_id); + int (*get_egg) (int account_id, int pet_id, int flag); + int (*unequipitem) (struct map_session_data *sd, struct pet_data *pd); + int (*food) (struct map_session_data *sd, struct pet_data *pd); + int (*ai_sub_hard_lootsearch) (struct block_list *bl, va_list ap); + int (*menu) (struct map_session_data *sd, int menunum); + int (*change_name) (struct map_session_data *sd, char *name); + int (*change_name_ack) (struct map_session_data *sd, char *name, int flag); + int (*equipitem) (struct map_session_data *sd, int index); + int (*randomwalk) (struct pet_data *pd, unsigned int tick); + int (*ai_sub_hard) (struct pet_data *pd, struct map_session_data *sd, unsigned int tick); + int (*ai_sub_foreachclient) (struct map_session_data *sd, va_list ap); + int (*ai_hard) (int tid, unsigned int tick, int id, intptr_t data); + int (*delay_item_drop) (int tid, unsigned int tick, int id, intptr_t data); + int (*lootitem_drop) (struct pet_data *pd, struct map_session_data *sd); + int (*skill_bonus_timer) (int tid, unsigned int tick, int id, intptr_t data); + int (*recovery_timer) (int tid, unsigned int tick, int id, intptr_t data); + int (*heal_timer) (int tid, unsigned int tick, int id, intptr_t data); + int (*skill_support_timer) (int tid, unsigned int tick, int id, intptr_t data); + int (*read_db) (); +}; + +struct pet_interface *pet; + +void pet_defaults(void); #endif /* _PET_H_ */ diff --git a/src/map/script.c b/src/map/script.c index fb8a6d8ec..feebef478 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5951,7 +5951,7 @@ BUILDIN(getitem) for (i = 0; i < amount; i += get_count) { // if not pet egg - if (!pet_create_egg(sd, nameid)) + if (!pet->create_egg(sd, nameid)) { if ((flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT))) { @@ -6049,7 +6049,7 @@ BUILDIN(getitem2) for (i = 0; i < amount; i += get_count) { // if not pet egg - if (!pet_create_egg(sd, nameid)) + if (!pet->create_egg(sd, nameid)) { if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { @@ -8350,17 +8350,17 @@ BUILDIN(makepet) if( sd == NULL ) return true; - pet_id = search_petDB_index(id, PET_CLASS); + pet_id = pet->search_petDB_index(id, PET_CLASS); if (pet_id < 0) - pet_id = search_petDB_index(id, PET_EGG); + pet_id = pet->search_petDB_index(id, PET_EGG); if (pet_id >= 0 && sd) { - sd->catch_target_class = pet_db[pet_id].class_; + 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_, (short)mob->db(pet_db[pet_id].class_)->lv, - (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate, - 100, 0, 1, pet_db[pet_id].jname); + (short)pet->db[pet_id].class_, (short)mob->db(pet->db[pet_id].class_)->lv, + (short)pet->db[pet_id].EggID, 0, (short)pet->db[pet_id].intimate, + 100, 0, 1, pet->db[pet_id].jname); } return true; @@ -9761,7 +9761,7 @@ BUILDIN(catchpet) if( sd == NULL ) return true; - pet_catch_process1(sd,pet_id); + pet->catch_process1(sd,pet_id); return true; } @@ -11695,7 +11695,7 @@ BUILDIN(petskillbonus) if (pd->bonus) { //Clear previous bonus if (pd->bonus->timer != INVALID_TIMER) - iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer); + iTimer->delete_timer(pd->bonus->timer, pet->skill_bonus_timer); } else //init pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus)); @@ -11711,7 +11711,7 @@ BUILDIN(petskillbonus) if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->bonus->timer = INVALID_TIMER; else - pd->bonus->timer = iTimer->add_timer(iTimer->gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0); + pd->bonus->timer = iTimer->add_timer(iTimer->gettick()+pd->bonus->delay*1000, pet->skill_bonus_timer, sd->bl.id, 0); return true; } @@ -11738,7 +11738,7 @@ BUILDIN(petloot) pd = sd->pd; if (pd->loot != NULL) { //Release whatever was there already and reallocate memory - pet_lootitem_drop(pd, pd->msd); + pet->lootitem_drop(pd, pd->msd); aFree(pd->loot->item); } else @@ -12065,7 +12065,7 @@ BUILDIN(petrecovery) if (pd->recovery) { //Halt previous bonus if (pd->recovery->timer != INVALID_TIMER) - iTimer->delete_timer(pd->recovery->timer, pet_recovery_timer); + iTimer->delete_timer(pd->recovery->timer, pet->recovery_timer); } else //Init pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery)); @@ -12093,9 +12093,9 @@ BUILDIN(petheal) if (pd->s_skill->timer != INVALID_TIMER) { if (pd->s_skill->id) - iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer); else - iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer); } } else //init memory pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); @@ -12111,7 +12111,7 @@ BUILDIN(petheal) if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->s_skill->timer = INVALID_TIMER; else - pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0); + pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet->heal_timer,sd->bl.id,0); return true; } @@ -12187,9 +12187,9 @@ BUILDIN(petskillsupport) if (pd->s_skill->timer != INVALID_TIMER) { if (pd->s_skill->id) - iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer); else - iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer); } } else //init memory pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); @@ -12204,7 +12204,7 @@ BUILDIN(petskillsupport) if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->s_skill->timer = INVALID_TIMER; else - pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0); + pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet->skill_support_timer,sd->bl.id,0); return true; } @@ -17046,7 +17046,7 @@ BUILDIN(getrandgroupitem) { for (i = 0; i < count; i += get_count) { // if not pet egg - if (!pet_create_egg(sd, nameid)) { + if (!pet->create_egg(sd, nameid)) { if ((flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT))) { clif->additem(sd, 0, 0, flag); if( pc->candrop(sd,&it) ) diff --git a/src/map/skill.c b/src/map/skill.c index 0f448d5cb..cb8708d52 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -5330,9 +5330,9 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui case SA_TAMINGMONSTER: clif->skill_nodamage(src,bl,skill_id,skill_lv,1); if (sd && dstmd) { - ARR_FIND( 0, MAX_PET_DB, i, dstmd->class_ == pet_db[i].class_ ); + ARR_FIND( 0, MAX_PET_DB, i, dstmd->class_ == pet->db[i].class_ ); if( i < MAX_PET_DB ) - pet_catch_process1(sd, dstmd->class_); + pet->catch_process1(sd, dstmd->class_); } break; diff --git a/src/map/status.c b/src/map/status.c index 409d4493d..ee5d4bfd5 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -8363,7 +8363,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val if( pc_iswug(sd) ) pc->setoption(sd, sd->sc.option&~OPTION_WUG); if( pc_isridingwug(sd) ) pc->setoption(sd, sd->sc.option&~OPTION_WUGRIDER); if( pc_isfalcon(sd) ) pc->setoption(sd, sd->sc.option&~OPTION_FALCON); - if( sd->status.pet_id > 0 ) pet_menu(sd, 3); + if( sd->status.pet_id > 0 ) pet->menu(sd, 3); if( homun_alive(sd->hd) ) homun->vaporize(sd,1); if( sd->md ) mercenary->delete(sd->md,3); } @@ -9133,7 +9133,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val status_calc_bl(bl,calc_flag); if(sd && sd->pd) - pet_sc_check(sd, type); //Skotlex: Pet Status Effect Healing + pet->sc_check(sd, type); //Skotlex: Pet Status Effect Healing switch (type) { case SC_BERSERK: diff --git a/src/map/unit.c b/src/map/unit.c index da6f26c9d..d8efcefef 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -1613,7 +1613,7 @@ int unit_unattackable(struct block_list *bl) if(bl->type == BL_MOB) mob->unlocktarget((struct mob_data*)bl, iTimer->gettick()) ; else if(bl->type == BL_PET) - pet_unlocktarget((struct pet_data*)bl); + pet->unlocktarget((struct pet_data*)bl); return 0; } @@ -1902,14 +1902,14 @@ int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int tick) iMap->foreachinrange(mob->linksearch, src, md->db->range2, BL_MOB, md->class_, target, tick); } } - if(src->type == BL_PET && pet_attackskill((TBL_PET*)src, target->id)) + if(src->type == BL_PET && pet->attackskill((TBL_PET*)src, target->id)) return 1; iMap->freeblock_lock(); ud->attacktarget_lv = battle->weapon_attack(src,target,tick,0); if(sd && sd->status.pet_id > 0 && sd->pd && battle_config.pet_attack_support) - pet_target_check(sd,target,0); + pet->target_check(sd,target,0); iMap->freeblock_unlock(); /** * Applied when you're unable to attack (e.g. out of ammo) @@ -2423,7 +2423,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { struct pet_data *pd = (struct pet_data*)bl; struct map_session_data *sd = pd->msd; - pet_hungry_timer_delete(pd); + pet->hungry_timer_delete(pd); if( pd->a_skill ) { aFree(pd->a_skill); @@ -2433,9 +2433,9 @@ int unit_free(struct block_list *bl, clr_type clrtype) { if (pd->s_skill->timer != INVALID_TIMER) { if (pd->s_skill->id) - iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer); else - iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer); + iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer); } aFree(pd->s_skill); pd->s_skill = NULL; @@ -2443,20 +2443,20 @@ int unit_free(struct block_list *bl, clr_type clrtype) if( pd->recovery ) { if(pd->recovery->timer != INVALID_TIMER) - iTimer->delete_timer(pd->recovery->timer, pet_recovery_timer); + iTimer->delete_timer(pd->recovery->timer, pet->recovery_timer); aFree(pd->recovery); pd->recovery = NULL; } if( pd->bonus ) { if (pd->bonus->timer != INVALID_TIMER) - iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer); + iTimer->delete_timer(pd->bonus->timer, pet->skill_bonus_timer); aFree(pd->bonus); pd->bonus = NULL; } if( pd->loot ) { - pet_lootitem_drop(pd,sd); + pet->lootitem_drop(pd,sd); if (pd->loot->item) aFree(pd->loot->item); aFree (pd->loot); |