From 6612269d2706ca08d9b174f292671a024724e6a3 Mon Sep 17 00:00:00 2001 From: zephyrus Date: Sun, 24 Aug 2008 15:00:26 +0000 Subject: - Moving all content of Homunculus code to a proper file Homunculus.c/h - Update of all project files. NOTE: All functions on homunculus.c should be renamed i think, to remove all the merc_*. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13122 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/homunculus.c | 1177 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1177 insertions(+) create mode 100644 src/map/homunculus.c (limited to 'src/map/homunculus.c') diff --git a/src/map/homunculus.c b/src/map/homunculus.c new file mode 100644 index 000000000..454d56e57 --- /dev/null +++ b/src/map/homunculus.c @@ -0,0 +1,1177 @@ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder + +#include "../common/cbasetypes.h" +#include "../common/malloc.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/nullpo.h" +#include "../common/mmo.h" +#include "../common/showmsg.h" +#include "../common/utils.h" + +#include "log.h" +#include "clif.h" +#include "chrif.h" +#include "intif.h" +#include "itemdb.h" +#include "map.h" +#include "pc.h" +#include "status.h" +#include "skill.h" +#include "mob.h" +#include "pet.h" +#include "battle.h" +#include "party.h" +#include "guild.h" +#include "atcommand.h" +#include "script.h" +#include "npc.h" +#include "trade.h" +#include "unit.h" + +#include "homunculus.h" + +#include +#include +#include +#include + +//Better equiprobability than rand()% [orn] +#define rand(a, b) (a+(int) ((float)(b-a+1)*rand()/(RAND_MAX+1.0))) + +struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS]; //[orn] +struct skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_SKILL_TREE]; + +static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data); + +static unsigned int hexptbl[MAX_LEVEL]; + +//For holding the view data of npc classes. [Skotlex] +static struct view_data hom_viewdb[MAX_HOMUNCULUS_CLASS]; + +struct view_data* merc_get_hom_viewdata(int class_) +{ //Returns the viewdata for homunculus + if (homdb_checkid(class_)) + return &hom_viewdb[class_-HM_CLASS_BASE]; + return NULL; +} + +void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp) +{ + clif_hominfo(hd->master,hd,0); +} + +int merc_hom_dead(struct homun_data *hd, struct block_list *src) +{ + //There's no intimacy penalties on death (from Tharis) + struct map_session_data *sd = hd->master; + + clif_emotion(&hd->bl, 16) ; //wah + + //Delete timers when dead. + merc_hom_hungry_timer_delete(hd); + hd->homunculus.hp = 0; + + if (!sd) //unit remove map will invoke unit free + return 3; + + clif_emotion(&sd->bl, 28) ; //sob + //Remove from map (if it has no intimacy, it is auto-removed from memory) + return 3; +} + +//Vaporize a character's homun. If flag, HP needs to be 80% or above. +int merc_hom_vaporize(struct map_session_data *sd, int flag) +{ + struct homun_data *hd; + + nullpo_retr(0, sd); + + hd = sd->hd; + if (!hd || hd->homunculus.vaporize) + return 0; + + if (status_isdead(&hd->bl)) + return 0; //Can't vaporize a dead homun. + + if (flag && get_percentage(hd->battle_status.hp, hd->battle_status.max_hp) < 80) + return 0; + + hd->regen.state.block = 3; //Block regen while vaporized. + //Delete timers when vaporized. + merc_hom_hungry_timer_delete(hd); + hd->homunculus.vaporize = 1; + if(battle_config.hom_setting&0x40) + memset(hd->blockskill, 0, sizeof(hd->blockskill)); + clif_hominfo(sd, sd->hd, 0); + merc_save(hd); + return unit_remove_map(&hd->bl, 0); +} + +//delete a homunculus, completely "killing it". +//Emote is the emotion the master should use, send negative to disable. +int merc_hom_delete(struct homun_data *hd, int emote) +{ + struct map_session_data *sd; + nullpo_retr(0, hd); + sd = hd->master; + + if (!sd) + return unit_free(&hd->bl,1); + + if (emote >= 0) + clif_emotion(&sd->bl, emote); + + //This makes it be deleted right away. + hd->homunculus.intimacy = 0; + // Send homunculus_dead to client + hd->homunculus.hp = 0; + clif_hominfo(sd, hd, 0); + return unit_remove_map(&hd->bl,0); +} + +int merc_hom_calc_skilltree(struct homun_data *hd) +{ + int i,id=0 ; + int j,f=1; + int c=0; + + nullpo_retr(0, hd); + c = hd->homunculus.class_ - HM_CLASS_BASE; + + for(i=0;i < MAX_SKILL_TREE && (id = hskill_tree[c][i].id) > 0;i++) + { + if(hd->homunculus.hskill[id-HM_SKILLBASE].id) + continue; //Skill already known. + if(!battle_config.skillfree) + { + for(j=0;j<5;j++) + { + if( hskill_tree[c][i].need[j].id && + merc_hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv) + { + f=0; + break; + } + } + } + if (f) + hd->homunculus.hskill[id-HM_SKILLBASE].id = id ; + } + return 0; +} + +int merc_hom_checkskill(struct homun_data *hd,int skill_id) +{ + int i = skill_id - HM_SKILLBASE; + if(!hd) + return 0; + + if(hd->homunculus.hskill[i].id == skill_id) + return (hd->homunculus.hskill[i].lv); + + return 0; +} + +int merc_skill_tree_get_max(int id, int b_class){ + int i, skillid; + b_class -= HM_CLASS_BASE; + for(i=0;(skillid=hskill_tree[b_class][i].id)>0;i++) + if (id == skillid) + return hskill_tree[b_class][i].max; + return skill_get_max(id); +} + +void merc_hom_skillup(struct homun_data *hd,int skillnum) +{ + int i = 0 ; + nullpo_retv(hd); + + if(hd->homunculus.vaporize) + return; + + i = skillnum - HM_SKILLBASE; + if(hd->homunculus.skillpts > 0 && + hd->homunculus.hskill[i].id && + hd->homunculus.hskill[i].flag == 0 && //Don't allow raising while you have granted skills. [Skotlex] + hd->homunculus.hskill[i].lv < merc_skill_tree_get_max(skillnum, hd->homunculus.class_) + ) + { + hd->homunculus.hskill[i].lv++; + hd->homunculus.skillpts-- ; + status_calc_homunculus(hd,0); + if (hd->master) { + clif_homskillup(hd->master, skillnum); + clif_hominfo(hd->master,hd,0); + clif_homskillinfoblock(hd->master); + } + } +} + +int merc_hom_levelup(struct homun_data *hd) +{ + struct s_homunculus *hom; + struct h_stats *min, *max; + int growth_str, growth_agi, growth_vit, growth_int, growth_dex, growth_luk ; + int growth_max_hp, growth_max_sp ; + char output[256] ; + + if (hd->homunculus.level == MAX_LEVEL || !hd->exp_next || hd->homunculus.exp < hd->exp_next) + return 0 ; + + hom = &hd->homunculus; + hom->level++ ; + if (!(hom->level % 3)) + hom->skillpts++ ; //1 skillpoint each 3 base level + + hom->exp -= hd->exp_next ; + hd->exp_next = hexptbl[hom->level - 1] ; + + max = &hd->homunculusDB->gmax; + min = &hd->homunculusDB->gmin; + + growth_max_hp = rand(min->HP, max->HP); + growth_max_sp = rand(min->SP, max->SP); + growth_str = rand(min->str, max->str); + growth_agi = rand(min->agi, max->agi); + growth_vit = rand(min->vit, max->vit); + growth_dex = rand(min->dex, max->dex); + growth_int = rand(min->int_,max->int_); + growth_luk = rand(min->luk, max->luk); + + //Aegis discards the decimals in the stat growth values! + growth_str-=growth_str%10; + growth_agi-=growth_agi%10; + growth_vit-=growth_vit%10; + growth_dex-=growth_dex%10; + growth_int-=growth_int%10; + growth_luk-=growth_luk%10; + + hom->max_hp += growth_max_hp; + hom->max_sp += growth_max_sp; + hom->str += growth_str; + hom->agi += growth_agi; + hom->vit += growth_vit; + hom->dex += growth_dex; + hom->int_+= growth_int; + hom->luk += growth_luk; + + if ( battle_config.homunculus_show_growth ) { + sprintf(output, + "Growth: hp:%d sp:%d str(%.2f) agi(%.2f) vit(%.2f) int(%.2f) dex(%.2f) luk(%.2f) ", + growth_max_hp, growth_max_sp, + growth_str/10.0, growth_agi/10.0, growth_vit/10.0, + growth_int/10.0, growth_dex/10.0, growth_luk/10.0); + clif_disp_onlyself(hd->master,output,strlen(output)); + } + return 1 ; +} + +int merc_hom_change_class(struct homun_data *hd, short class_) +{ + int i; + i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); + if(i < 0) + return 0; + hd->homunculusDB = &homunculus_db[i]; + hd->homunculus.class_ = class_; + status_set_viewdata(&hd->bl, class_); + merc_hom_calc_skilltree(hd); + return 1; +} + +int merc_hom_evolution(struct homun_data *hd) +{ + struct s_homunculus *hom; + struct h_stats *max, *min; + struct map_session_data *sd; + nullpo_retr(0, hd); + + if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class) + { + clif_emotion(&hd->bl, 4) ; //swt + return 0 ; + } + sd = hd->master; + if (!sd) + return 0; + + if (!merc_hom_change_class(hd, hd->homunculusDB->evo_class)) { + ShowError("merc_hom_evolution: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class); + return 0; + } + + //Apply evolution bonuses + hom = &hd->homunculus; + max = &hd->homunculusDB->emax; + min = &hd->homunculusDB->emin; + hom->max_hp += rand(min->HP, max->HP); + hom->max_sp += rand(min->SP, max->SP); + hom->str += 10*rand(min->str, max->str); + hom->agi += 10*rand(min->agi, max->agi); + hom->vit += 10*rand(min->vit, max->vit); + hom->int_+= 10*rand(min->int_,max->int_); + hom->dex += 10*rand(min->dex, max->dex); + hom->luk += 10*rand(min->luk, max->luk); + hom->intimacy = 500; + + unit_remove_map(&hd->bl, 0); + map_addblock(&hd->bl); + + clif_spawn(&hd->bl); + clif_emotion(&sd->bl, 21); //no1 + clif_misceffect2(&hd->bl,568); + + //status_Calc flag&1 will make current HP/SP be reloaded from hom structure + hom->hp = hd->battle_status.hp; + hom->sp = hd->battle_status.sp; + status_calc_homunculus(hd,1); + + if (!(battle_config.hom_setting&0x2)) + skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately + + return 1 ; +} + +int merc_hom_gainexp(struct homun_data *hd,int exp) +{ + if(hd->homunculus.vaporize) + return 1; + + if( hd->exp_next == 0 ) { + hd->homunculus.exp = 0 ; + return 0; + } + + hd->homunculus.exp += exp; + + if(hd->homunculus.exp < hd->exp_next) { + clif_hominfo(hd->master,hd,0); + return 0; + } + + //levelup + do + { + merc_hom_levelup(hd) ; + } + while(hd->homunculus.exp > hd->exp_next && hd->exp_next != 0 ); + + if( hd->exp_next == 0 ) + hd->homunculus.exp = 0 ; + + clif_misceffect2(&hd->bl,568); + status_calc_homunculus(hd,0); + status_percent_heal(&hd->bl, 100, 100); + return 0; +} + +// Return the new value +int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value) +{ + if( battle_config.homunculus_friendly_rate != 100 ) + value = (value * battle_config.homunculus_friendly_rate) / 100; + + if( hd->homunculus.intimacy + value <= 100000 ) + hd->homunculus.intimacy += value; + else + hd->homunculus.intimacy = 100000; + + return hd->homunculus.intimacy; +} + +// Return 0 if decrease fails or intimacy became 0 else the new value +int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value) +{ + if (hd->homunculus.intimacy >= value) + hd->homunculus.intimacy -= value; + else + hd->homunculus.intimacy = 0; + + return hd->homunculus.intimacy; +} + +void merc_hom_heal(struct homun_data *hd,int hp,int sp) +{ + clif_hominfo(hd->master,hd,0); +} + +void merc_save(struct homun_data *hd) +{ + // copy data that must be saved in homunculus struct ( hp / sp ) + TBL_PC * sd = hd->master; + //Do not check for max_hp/max_sp caps as current could be higher to max due + //to status changes/skills (they will be capped as needed upon stat + //calculation on login) + hd->homunculus.hp = hd->battle_status.hp; + hd->homunculus.sp = hd->battle_status.sp; + intif_homunculus_requestsave(sd->status.account_id, &hd->homunculus); +} + +int merc_menu(struct map_session_data *sd,int menunum) +{ + nullpo_retr(0, sd); + if (sd->hd == NULL) + return 1; + + switch(menunum) { + case 0: + break; + case 1: + merc_hom_food(sd, sd->hd); + break; + case 2: + merc_hom_delete(sd->hd, -1); + break; + default: + ShowError("merc_menu : unknown menu choice : %d\n", menunum) ; + break; + } + return 0; +} + +int merc_hom_food(struct map_session_data *sd, struct homun_data *hd) +{ + int i, foodID, emotion; + char mes[255]; + + if(hd->homunculus.vaporize) + return 1 ; + + foodID = hd->homunculusDB->foodID; + i = pc_search_inventory(sd,foodID); + if(i < 0) { + clif_hom_food(sd,foodID,0); + return 1; + } + pc_delitem(sd,i,1,0); + + if ( hd->homunculus.hunger >= 91 ) { + merc_hom_decrease_intimacy(hd, 50); + emotion = 16; + } else if ( hd->homunculus.hunger >= 76 ) { + merc_hom_decrease_intimacy(hd, 5); + emotion = 19; + } else if ( hd->homunculus.hunger >= 26 ) { + merc_hom_increase_intimacy(hd, 75); + emotion = 2; + } else if ( hd->homunculus.hunger >= 11 ) { + merc_hom_increase_intimacy(hd, 100); + emotion = 2; + } else { + merc_hom_increase_intimacy(hd, 50); + emotion = 2; + } + + hd->homunculus.hunger += 10; //dunno increase value for each food + if(hd->homunculus.hunger > 100) + hd->homunculus.hunger = 100; + + clif_emotion(&hd->bl,emotion) ; + snprintf(mes, sizeof mes,"%s : Gracias!!",hd->homunculus.name); + clif_message(&hd->bl,mes); + + clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); + clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); + clif_hom_food(sd,foodID,1); + + // Too much food :/ + if(hd->homunculus.intimacy == 0) + return merc_hom_delete(sd->hd, 23); //omg + + return 0; +} + +static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) +{ + struct map_session_data *sd; + struct homun_data *hd; + char mes[255]; + bool talk = true; + + sd=map_id2sd(id); + if(!sd) + return 1; + + if(!sd->status.hom_id || !(hd=sd->hd)) + return 1; + + if(hd->hungry_timer != tid){ + ShowError("merc_hom_hungry_timer %d != %d\n",hd->hungry_timer,tid); + return 0; + } + + hd->hungry_timer = INVALID_TIMER; + + hd->homunculus.hunger-- ; + if(hd->homunculus.hunger <= 10) { + clif_emotion(&hd->bl, 6) ; //an + snprintf(mes, sizeof mes,"%s : Tengo mucha hambre...",hd->homunculus.name); + } else if(hd->homunculus.hunger == 25) { + clif_emotion(&hd->bl, 20) ; //hmm + snprintf(mes, sizeof mes,"%s : Tengo hambre...",hd->homunculus.name); + } else if(hd->homunculus.hunger == 75) { + clif_emotion(&hd->bl, 33) ; //ok + snprintf(mes, sizeof mes,"%s : Tengo un poco de hambre...",hd->homunculus.name); + } else + talk = false; + + if( talk ) clif_message(&hd->bl, mes); + + if(hd->homunculus.hunger < 0) { + hd->homunculus.hunger = 0; + // Delete the homunculus if intimacy <= 100 + if ( !merc_hom_decrease_intimacy(hd, 100) ) + return merc_hom_delete(hd, 23); //omg + clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); + } + + clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); + hd->hungry_timer = add_timer(tick+hd->homunculusDB->hungryDelay,merc_hom_hungry,sd->bl.id,0); //simple Fix albator + return 0; +} + +int merc_hom_hungry_timer_delete(struct homun_data *hd) +{ + nullpo_retr(0, hd); + if(hd->hungry_timer != -1) { + delete_timer(hd->hungry_timer,merc_hom_hungry); + hd->hungry_timer = INVALID_TIMER; + } + return 1; +} + +int merc_hom_change_name(struct map_session_data *sd,char *name) +{ + int i; + struct homun_data *hd; + nullpo_retr(1, sd); + + hd = sd->hd; + if (!merc_is_hom_active(hd)) + return 1; + if(hd->homunculus.rename_flag && !battle_config.hom_rename) + return 1; + + for(i=0;ihd; + if (!merc_is_hom_active(hd)) return 0; + if (!flag) { + clif_displaymessage(sd->fd, msg_txt(280)); // You cannot use this name + return 0; + } + strncpy(hd->homunculus.name,name,NAME_LENGTH); + clif_charnameack (0,&hd->bl); + hd->homunculus.rename_flag = 1; + clif_hominfo(sd,hd,0); + return 1; +} + +int search_homunculusDB_index(int key,int type) +{ + int i; + + for(i=0;istatus.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd); + + i = search_homunculusDB_index(hom->class_,HOMUNCULUS_CLASS); + if(i < 0) { + ShowError("merc_hom_alloc: unknown class [%d] for homunculus '%s', requesting deletion.\n", hom->class_, hom->name); + sd->status.hom_id = 0; + intif_homunculus_requestdelete(hom->hom_id); + return 1; + } + sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data)); + hd->bl.type = BL_HOM; + hd->bl.id = npc_get_new_npc_id(); + + hd->master = sd; + hd->homunculusDB = &homunculus_db[i]; + memcpy(&hd->homunculus, hom, sizeof(struct s_homunculus)); + hd->exp_next = hexptbl[hd->homunculus.level - 1]; + + status_set_viewdata(&hd->bl, hd->homunculus.class_); + status_change_init(&hd->bl); + unit_dataset(&hd->bl); + hd->ud.dir = sd->ud.dir; + + // Find a random valid pos around the player + hd->bl.m = sd->bl.m; + hd->bl.x = sd->bl.x; + hd->bl.y = sd->bl.y; + unit_calc_pos(&hd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); + hd->bl.x = hd->ud.to_x; + hd->bl.y = hd->ud.to_y; + + map_addiddb(&hd->bl); + status_calc_homunculus(hd,1); + + hd->hungry_timer = INVALID_TIMER; + return 0; +} + +void merc_hom_init_timers(struct homun_data * hd) +{ + if (hd->hungry_timer == -1) + hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,merc_hom_hungry,hd->master->bl.id,0); + hd->regen.state.block = 0; //Restore HP/SP block. +} + +int merc_call_homunculus(struct map_session_data *sd) +{ + struct homun_data *hd; + + if (!sd->status.hom_id) //Create a new homun. + return merc_create_homunculus_request(sd, HM_CLASS_BASE + rand(0, 7)) ; + + // If homunc not yet loaded, load it + if (!sd->hd) + return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); + + hd = sd->hd; + + if (!hd->homunculus.vaporize) + return 0; //Can't use this if homun wasn't vaporized. + + merc_hom_init_timers(hd); + hd->homunculus.vaporize = 0; + if (hd->bl.prev == NULL) + { //Spawn him + hd->bl.x = sd->bl.x; + hd->bl.y = sd->bl.y; + hd->bl.m = sd->bl.m; + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] + clif_homskillinfoblock(sd); + if (battle_config.slaves_inherit_speed&1) + status_calc_bl(&hd->bl, SCB_SPEED); + merc_save(hd); + } else + //Warp him to master. + unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,0); + return 1; +} + +// Recv homunculus data from char server +int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag) +{ + struct map_session_data *sd; + struct homun_data *hd; + + sd = map_id2sd(account_id); + if(!sd) + return 0; + if (sd->status.char_id != sh->char_id) + { + if (sd->status.hom_id == sh->hom_id) + sh->char_id = sd->status.char_id; //Correct char id. + else + return 0; + } + if(!flag) { // Failed to load + sd->status.hom_id = 0; + return 0; + } + + if (!sd->status.hom_id) //Hom just created. + sd->status.hom_id = sh->hom_id; + if (sd->hd) //uh? Overwrite the data. + memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus)); + else + merc_hom_alloc(sd, sh); + + hd = sd->hd; + if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL) + { + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] + clif_homskillinfoblock(sd); + merc_hom_init_timers(hd); + } + return 1; +} + +// Ask homunculus creation to char server +int merc_create_homunculus_request(struct map_session_data *sd, int class_) +{ + struct s_homunculus homun; + struct h_stats *base; + int i; + + nullpo_retr(1, sd); + + i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); + if(i < 0) return 0; + + memset(&homun, 0, sizeof(struct s_homunculus)); + //Initial data + strncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1); + homun.class_ = class_; + homun.level = 1; + homun.hunger = 32; //32% + homun.intimacy = 2100; //21/1000 + homun.char_id = sd->status.char_id; + + homun.hp = 10 ; + base = &homunculus_db[i].base; + homun.max_hp = base->HP; + homun.max_sp = base->SP; + homun.str = base->str *10; + homun.agi = base->agi *10; + homun.vit = base->vit *10; + homun.int_= base->int_*10; + homun.dex = base->dex *10; + homun.luk = base->luk *10; + + // Request homunculus creation + intif_homunculus_create(sd->status.account_id, &homun); + return 1; +} + +int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, short x, short y) +{ + struct homun_data* hd; + nullpo_retr(0, sd); + + if (!sd->status.hom_id) + return 0; // no homunculus + + if (!sd->hd) //Load homun data; + return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); + + hd = sd->hd; + + if (hd->homunculus.vaporize) + return 0; // vaporized homunculi need to be 'called' + + if (!status_isdead(&hd->bl)) + return 0; // already alive + + merc_hom_init_timers(hd); + + if (!hd->bl.prev) + { //Add it back to the map. + hd->bl.m = sd->bl.m; + hd->bl.x = x; + hd->bl.y = y; + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + } + status_revive(&hd->bl, per, 0); + return 1; +} + +void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp) +{ + struct map_session_data *sd = hd->master; + hd->homunculus.hp = hd->battle_status.hp; + if (!sd) + return; + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); + clif_homskillinfoblock(sd); +} + +void merc_reset_stats(struct homun_data *hd) +{ //Resets a homunc stats back to zero (but doesn't touches hunger or intimacy) + struct s_homunculus_db *db; + struct s_homunculus *hom; + struct h_stats *base; + hom = &hd->homunculus; + db = hd->homunculusDB; + base = &db->base; + hom->level = 1; + hom->hp = 10; + hom->max_hp = base->HP; + hom->max_sp = base->SP; + hom->str = base->str *10; + hom->agi = base->agi *10; + hom->vit = base->vit *10; + hom->int_= base->int_*10; + hom->dex = base->dex *10; + hom->luk = base->luk *10; + hom->exp = 0; + hd->exp_next = hexptbl[0]; + memset(&hd->homunculus.hskill, 0, sizeof hd->homunculus.hskill); + hd->homunculus.skillpts = 0; +} + +int merc_hom_shuffle(struct homun_data *hd) +{ + struct map_session_data *sd; + int lv, i, skillpts; + unsigned int exp; + struct s_skill b_skill[MAX_HOMUNSKILL]; + + if (!merc_is_hom_active(hd)) + return 0; + + sd = hd->master; + lv = hd->homunculus.level; + exp = hd->homunculus.exp; + memcpy(&b_skill, &hd->homunculus.hskill, sizeof(b_skill)); + skillpts = hd->homunculus.skillpts; + //Reset values to level 1. + merc_reset_stats(hd); + //Level it back up + for (i = 1; i < lv && hd->exp_next; i++){ + hd->homunculus.exp += hd->exp_next; + merc_hom_levelup(hd); + } + + if(hd->homunculus.class_ == hd->homunculusDB->evo_class) { + //Evolved bonuses + struct s_homunculus *hom = &hd->homunculus; + struct h_stats *max = &hd->homunculusDB->emax, *min = &hd->homunculusDB->emin; + hom->max_hp += rand(min->HP, max->HP); + hom->max_sp += rand(min->SP, max->SP); + hom->str += 10*rand(min->str, max->str); + hom->agi += 10*rand(min->agi, max->agi); + hom->vit += 10*rand(min->vit, max->vit); + hom->int_+= 10*rand(min->int_,max->int_); + hom->dex += 10*rand(min->dex, max->dex); + hom->luk += 10*rand(min->luk, max->luk); + } + + hd->homunculus.exp = exp; + memcpy(&hd->homunculus.hskill, &b_skill, sizeof(b_skill)); + hd->homunculus.skillpts = skillpts; + clif_homskillinfoblock(sd); + status_calc_homunculus(hd,0); + status_percent_heal(&hd->bl, 100, 100); + clif_misceffect2(&hd->bl,568); + + return 1; +} + +int read_homunculusdb(void) +{ + FILE *fp; + char line[1024], *p; + int i, k, classid; + int j = 0; + const char *filename[]={"homunculus_db.txt","homunculus_db2.txt"}; + char *str[50]; + struct s_homunculus_db *db; + + memset(homunculus_db,0,sizeof(homunculus_db)); + for(i = 0; i<2; i++) + { + sprintf(line, "%s/%s", db_path, filename[i]); + fp = fopen(line,"r"); + if(!fp){ + if(i != 0) + continue; + ShowError("read_homunculusdb : can't read %s\n", line); + return -1; + } + + while(fgets(line, sizeof(line), fp) && j < MAX_HOMUNCULUS_CLASS) + { + if(line[0] == '/' && line[1] == '/') + continue; + + k = 0; + p = strtok (line,","); + while (p != NULL && k < 50) + { + str[k++] = p; + p = strtok (NULL, ","); + } + if (k < 50 ) + { + ShowError("read_homunculusdb : Incorrect number of columns at %s, homunculus %d. Read %d columns, 50 are needed.\n", filename[i], j+1, k); + continue; + } + + //Base Class,Evo Class + classid = atoi(str[0]); + if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) + { + ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); + continue; + } + db = &homunculus_db[j]; + db->base_class = classid; + classid = atoi(str[1]); + if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) + { + db->base_class = 0; + ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); + continue; + } + db->evo_class = classid; + //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD + strncpy(db->name,str[2],NAME_LENGTH-1); + db->foodID = atoi(str[3]); + db->hungryDelay = atoi(str[4]); + db->base_size = atoi(str[5]); + db->evo_size = atoi(str[6]); + db->race = atoi(str[7]); + db->element = atoi(str[8]); + db->baseASPD = atoi(str[9]); + //base HP, SP, str, agi, vit, int, dex, luk + db->base.HP = atoi(str[10]); + db->base.SP = atoi(str[11]); + db->base.str = atoi(str[12]); + db->base.agi = atoi(str[13]); + db->base.vit = atoi(str[14]); + db->base.int_= atoi(str[15]); + db->base.dex = atoi(str[16]); + db->base.luk = atoi(str[17]); + //Growth Min/Max HP, SP, str, agi, vit, int, dex, luk + db->gmin.HP = atoi(str[18]); + db->gmax.HP = atoi(str[19]); + db->gmin.SP = atoi(str[20]); + db->gmax.SP = atoi(str[21]); + db->gmin.str = atoi(str[22]); + db->gmax.str = atoi(str[23]); + db->gmin.agi = atoi(str[24]); + db->gmax.agi = atoi(str[25]); + db->gmin.vit = atoi(str[26]); + db->gmax.vit = atoi(str[27]); + db->gmin.int_= atoi(str[28]); + db->gmax.int_= atoi(str[29]); + db->gmin.dex = atoi(str[30]); + db->gmax.dex = atoi(str[31]); + db->gmin.luk = atoi(str[32]); + db->gmax.luk = atoi(str[33]); + //Evolution Min/Max HP, SP, str, agi, vit, int, dex, luk + db->emin.HP = atoi(str[34]); + db->emax.HP = atoi(str[35]); + db->emin.SP = atoi(str[36]); + db->emax.SP = atoi(str[37]); + db->emin.str = atoi(str[38]); + db->emax.str = atoi(str[39]); + db->emin.agi = atoi(str[40]); + db->emax.agi = atoi(str[41]); + db->emin.vit = atoi(str[42]); + db->emax.vit = atoi(str[43]); + db->emin.int_= atoi(str[44]); + db->emax.int_= atoi(str[45]); + db->emin.dex = atoi(str[46]); + db->emax.dex = atoi(str[47]); + db->emin.luk = atoi(str[48]); + db->emax.luk = atoi(str[49]); + + //Check that the min/max values really are below the other one. + if(db->gmin.HP > db->gmax.HP) + db->gmin.HP = db->gmax.HP; + if(db->gmin.SP > db->gmax.SP) + db->gmin.SP = db->gmax.SP; + if(db->gmin.str > db->gmax.str) + db->gmin.str = db->gmax.str; + if(db->gmin.agi > db->gmax.agi) + db->gmin.agi = db->gmax.agi; + if(db->gmin.vit > db->gmax.vit) + db->gmin.vit = db->gmax.vit; + if(db->gmin.int_> db->gmax.int_) + db->gmin.int_= db->gmax.int_; + if(db->gmin.dex > db->gmax.dex) + db->gmin.dex = db->gmax.dex; + if(db->gmin.luk > db->gmax.luk) + db->gmin.luk = db->gmax.luk; + + if(db->emin.HP > db->emax.HP) + db->emin.HP = db->emax.HP; + if(db->emin.SP > db->emax.SP) + db->emin.SP = db->emax.SP; + if(db->emin.str > db->emax.str) + db->emin.str = db->emax.str; + if(db->emin.agi > db->emax.agi) + db->emin.agi = db->emax.agi; + if(db->emin.vit > db->emax.vit) + db->emin.vit = db->emax.vit; + if(db->emin.int_> db->emax.int_) + db->emin.int_= db->emax.int_; + if(db->emin.dex > db->emax.dex) + db->emin.dex = db->emax.dex; + if(db->emin.luk > db->emax.luk) + db->emin.luk = db->emax.luk; + + j++; + } + if (j > MAX_HOMUNCULUS_CLASS) + ShowWarning("read_homunculusdb: Reached max number of homunculus [%d]. Remaining homunculus were not read.\n ", MAX_HOMUNCULUS_CLASS); + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' homunculus in '"CL_WHITE"db/%s"CL_RESET"'.\n",j,filename[i]); + } + return 0; +} + +int read_homunculus_skilldb(void) +{ + FILE *fp; + char line[1024], *p; + int k, classid; + int j = 0; + char *split[15]; + + memset(hskill_tree,0,sizeof(hskill_tree)); + sprintf(line, "%s/homun_skill_tree.txt", db_path); + fp=fopen(line,"r"); + if(fp==NULL){ + ShowError("can't read %s\n", line); + return 1; + } + + while(fgets(line, sizeof(line), fp)) + { + int minJobLevelPresent = 0; + + if(line[0]=='/' && line[1]=='/') + continue; + + k = 0; + p = strtok(line,","); + while (p != NULL && k < 15) + { + split[k++] = p; + p = strtok(NULL, ","); + } + + if(k < 13) + continue; + + if (k == 14) + minJobLevelPresent = 1; // MinJobLvl has been added + + // check for bounds [celest] + classid = atoi(split[0]) - HM_CLASS_BASE; + if ( classid >= MAX_HOMUNCULUS_CLASS ) + continue; + + k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex] + // Search an empty line or a line with the same skill_id (stored in j) + for(j = 0; j < MAX_SKILL_TREE && hskill_tree[classid][j].id && hskill_tree[classid][j].id != k; j++); + + if (j == MAX_SKILL_TREE) + { + ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid); + continue; + } + + hskill_tree[classid][j].id=k; + hskill_tree[classid][j].max=atoi(split[2]); + if (minJobLevelPresent) + hskill_tree[classid][j].joblv=atoi(split[3]); + + for(k=0;k<5;k++){ + hskill_tree[classid][j].need[k].id=atoi(split[3+k*2+minJobLevelPresent]); + hskill_tree[classid][j].need[k].lv=atoi(split[3+k*2+minJobLevelPresent+1]); + } + } + + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","homun_skill_tree.txt"); + return 0; +} + +void read_homunculus_expdb(void) +{ + FILE *fp; + char line[1024]; + int i, j=0; + char *filename[]={"exp_homun.txt","exp_homun2.txt"}; + + memset(hexptbl,0,sizeof(hexptbl)); + for(i=0; i<2; i++){ + sprintf(line, "%s/%s", db_path, filename[i]); + fp=fopen(line,"r"); + if(fp == NULL){ + if(i != 0) + continue; + ShowError("can't read %s\n",line); + return; + } + while(fgets(line, sizeof(line), fp) && j < MAX_LEVEL) + { + if(line[0] == '/' && line[1] == '/') + continue; + + hexptbl[j] = strtoul(line, NULL, 10); + if (!hexptbl[j++]) + break; + } + if (hexptbl[MAX_LEVEL - 1]) // Last permitted level have to be 0! + { + ShowWarning("read_hexptbl: Reached max level in exp_homun [%d]. Remaining lines were not read.\n ", MAX_LEVEL); + hexptbl[MAX_LEVEL - 1] = 0; + } + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' levels in '"CL_WHITE"%s"CL_RESET"'.\n", j, filename[i]); + } +} + +void merc_reload(void) +{ + read_homunculusdb(); + read_homunculus_expdb(); +} + +void merc_skill_reload(void) +{ + read_homunculus_skilldb(); +} + +int do_init_merc(void) +{ + int class_; + read_homunculusdb(); + read_homunculus_expdb(); + read_homunculus_skilldb(); + + // Add homunc timer function to timer func list [Toms] + add_timer_func_list(merc_hom_hungry, "merc_hom_hungry"); + + //Stock view data for homuncs + memset(&hom_viewdb, 0, sizeof(hom_viewdb)); + for (class_ = 0; class_ < ARRAYLENGTH(hom_viewdb); class_++) + hom_viewdb[class_].class_ = HM_CLASS_BASE+class_; + return 0; +} + +int do_final_merc(void); -- cgit v1.2.3-70-g09d2 From 81601053b3df92c13a9bc0bd679b49369b2cf788 Mon Sep 17 00:00:00 2001 From: zephyrus Date: Sun, 24 Aug 2008 15:51:33 +0000 Subject: - Ops!! this is mine (homunculus hungry messages). - Fixed a bug on char delete. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13123 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/char_sql/char.c | 2 +- src/map/homunculus.c | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'src/map/homunculus.c') diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 9008ac838..67a7419f2 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -1363,7 +1363,7 @@ int delete_char_sql(int char_id) mapif_homunculus_delete(hom_id); /* remove mercenary */ if( mer_id ) - mapif_mercenary_delete(hom_id); + mapif_mercenary_delete(mer_id); /* delete char's friends list */ if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", friend_db, char_id) ) diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 454d56e57..d6832e84a 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -487,8 +487,6 @@ static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) { struct map_session_data *sd; struct homun_data *hd; - char mes[255]; - bool talk = true; sd=map_id2sd(id); if(!sd) @@ -507,18 +505,13 @@ static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) hd->homunculus.hunger-- ; if(hd->homunculus.hunger <= 10) { clif_emotion(&hd->bl, 6) ; //an - snprintf(mes, sizeof mes,"%s : Tengo mucha hambre...",hd->homunculus.name); } else if(hd->homunculus.hunger == 25) { clif_emotion(&hd->bl, 20) ; //hmm - snprintf(mes, sizeof mes,"%s : Tengo hambre...",hd->homunculus.name); } else if(hd->homunculus.hunger == 75) { clif_emotion(&hd->bl, 33) ; //ok - snprintf(mes, sizeof mes,"%s : Tengo un poco de hambre...",hd->homunculus.name); } else talk = false; - if( talk ) clif_message(&hd->bl, mes); - if(hd->homunculus.hunger < 0) { hd->homunculus.hunger = 0; // Delete the homunculus if intimacy <= 100 -- cgit v1.2.3-70-g09d2 From 2600d527592c3e5c6ed6ab827ce69c24f3c6b35b Mon Sep 17 00:00:00 2001 From: ultramage Date: Sun, 24 Aug 2008 18:33:20 +0000 Subject: Fixed a compilation problem caused by r13123. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13125 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/homunculus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/map/homunculus.c') diff --git a/src/map/homunculus.c b/src/map/homunculus.c index d6832e84a..fc2e4b0ca 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -509,8 +509,7 @@ static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) clif_emotion(&hd->bl, 20) ; //hmm } else if(hd->homunculus.hunger == 75) { clif_emotion(&hd->bl, 33) ; //ok - } else - talk = false; + } if(hd->homunculus.hunger < 0) { hd->homunculus.hunger = 0; -- cgit v1.2.3-70-g09d2 From bb7124295a174b43af7bfe88eda500b13f73bb62 Mon Sep 17 00:00:00 2001 From: ultramage Date: Tue, 26 Aug 2008 04:50:15 +0000 Subject: Reverted all mercenary changes to mapserver homunculus code git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13135 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/homunculus.c | 1169 ---------------------------------------------- src/map/homunculus.h | 89 ---- src/map/mercenary.c | 1247 ++++++++++++++++++++++++++++++++++++++++---------- src/map/mercenary.h | 94 ++-- 4 files changed, 1084 insertions(+), 1515 deletions(-) delete mode 100644 src/map/homunculus.c delete mode 100644 src/map/homunculus.h (limited to 'src/map/homunculus.c') diff --git a/src/map/homunculus.c b/src/map/homunculus.c deleted file mode 100644 index fc2e4b0ca..000000000 --- a/src/map/homunculus.c +++ /dev/null @@ -1,1169 +0,0 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder - -#include "../common/cbasetypes.h" -#include "../common/malloc.h" -#include "../common/socket.h" -#include "../common/timer.h" -#include "../common/nullpo.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" -#include "../common/utils.h" - -#include "log.h" -#include "clif.h" -#include "chrif.h" -#include "intif.h" -#include "itemdb.h" -#include "map.h" -#include "pc.h" -#include "status.h" -#include "skill.h" -#include "mob.h" -#include "pet.h" -#include "battle.h" -#include "party.h" -#include "guild.h" -#include "atcommand.h" -#include "script.h" -#include "npc.h" -#include "trade.h" -#include "unit.h" - -#include "homunculus.h" - -#include -#include -#include -#include - -//Better equiprobability than rand()% [orn] -#define rand(a, b) (a+(int) ((float)(b-a+1)*rand()/(RAND_MAX+1.0))) - -struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS]; //[orn] -struct skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_SKILL_TREE]; - -static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data); - -static unsigned int hexptbl[MAX_LEVEL]; - -//For holding the view data of npc classes. [Skotlex] -static struct view_data hom_viewdb[MAX_HOMUNCULUS_CLASS]; - -struct view_data* merc_get_hom_viewdata(int class_) -{ //Returns the viewdata for homunculus - if (homdb_checkid(class_)) - return &hom_viewdb[class_-HM_CLASS_BASE]; - return NULL; -} - -void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp) -{ - clif_hominfo(hd->master,hd,0); -} - -int merc_hom_dead(struct homun_data *hd, struct block_list *src) -{ - //There's no intimacy penalties on death (from Tharis) - struct map_session_data *sd = hd->master; - - clif_emotion(&hd->bl, 16) ; //wah - - //Delete timers when dead. - merc_hom_hungry_timer_delete(hd); - hd->homunculus.hp = 0; - - if (!sd) //unit remove map will invoke unit free - return 3; - - clif_emotion(&sd->bl, 28) ; //sob - //Remove from map (if it has no intimacy, it is auto-removed from memory) - return 3; -} - -//Vaporize a character's homun. If flag, HP needs to be 80% or above. -int merc_hom_vaporize(struct map_session_data *sd, int flag) -{ - struct homun_data *hd; - - nullpo_retr(0, sd); - - hd = sd->hd; - if (!hd || hd->homunculus.vaporize) - return 0; - - if (status_isdead(&hd->bl)) - return 0; //Can't vaporize a dead homun. - - if (flag && get_percentage(hd->battle_status.hp, hd->battle_status.max_hp) < 80) - return 0; - - hd->regen.state.block = 3; //Block regen while vaporized. - //Delete timers when vaporized. - merc_hom_hungry_timer_delete(hd); - hd->homunculus.vaporize = 1; - if(battle_config.hom_setting&0x40) - memset(hd->blockskill, 0, sizeof(hd->blockskill)); - clif_hominfo(sd, sd->hd, 0); - merc_save(hd); - return unit_remove_map(&hd->bl, 0); -} - -//delete a homunculus, completely "killing it". -//Emote is the emotion the master should use, send negative to disable. -int merc_hom_delete(struct homun_data *hd, int emote) -{ - struct map_session_data *sd; - nullpo_retr(0, hd); - sd = hd->master; - - if (!sd) - return unit_free(&hd->bl,1); - - if (emote >= 0) - clif_emotion(&sd->bl, emote); - - //This makes it be deleted right away. - hd->homunculus.intimacy = 0; - // Send homunculus_dead to client - hd->homunculus.hp = 0; - clif_hominfo(sd, hd, 0); - return unit_remove_map(&hd->bl,0); -} - -int merc_hom_calc_skilltree(struct homun_data *hd) -{ - int i,id=0 ; - int j,f=1; - int c=0; - - nullpo_retr(0, hd); - c = hd->homunculus.class_ - HM_CLASS_BASE; - - for(i=0;i < MAX_SKILL_TREE && (id = hskill_tree[c][i].id) > 0;i++) - { - if(hd->homunculus.hskill[id-HM_SKILLBASE].id) - continue; //Skill already known. - if(!battle_config.skillfree) - { - for(j=0;j<5;j++) - { - if( hskill_tree[c][i].need[j].id && - merc_hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv) - { - f=0; - break; - } - } - } - if (f) - hd->homunculus.hskill[id-HM_SKILLBASE].id = id ; - } - return 0; -} - -int merc_hom_checkskill(struct homun_data *hd,int skill_id) -{ - int i = skill_id - HM_SKILLBASE; - if(!hd) - return 0; - - if(hd->homunculus.hskill[i].id == skill_id) - return (hd->homunculus.hskill[i].lv); - - return 0; -} - -int merc_skill_tree_get_max(int id, int b_class){ - int i, skillid; - b_class -= HM_CLASS_BASE; - for(i=0;(skillid=hskill_tree[b_class][i].id)>0;i++) - if (id == skillid) - return hskill_tree[b_class][i].max; - return skill_get_max(id); -} - -void merc_hom_skillup(struct homun_data *hd,int skillnum) -{ - int i = 0 ; - nullpo_retv(hd); - - if(hd->homunculus.vaporize) - return; - - i = skillnum - HM_SKILLBASE; - if(hd->homunculus.skillpts > 0 && - hd->homunculus.hskill[i].id && - hd->homunculus.hskill[i].flag == 0 && //Don't allow raising while you have granted skills. [Skotlex] - hd->homunculus.hskill[i].lv < merc_skill_tree_get_max(skillnum, hd->homunculus.class_) - ) - { - hd->homunculus.hskill[i].lv++; - hd->homunculus.skillpts-- ; - status_calc_homunculus(hd,0); - if (hd->master) { - clif_homskillup(hd->master, skillnum); - clif_hominfo(hd->master,hd,0); - clif_homskillinfoblock(hd->master); - } - } -} - -int merc_hom_levelup(struct homun_data *hd) -{ - struct s_homunculus *hom; - struct h_stats *min, *max; - int growth_str, growth_agi, growth_vit, growth_int, growth_dex, growth_luk ; - int growth_max_hp, growth_max_sp ; - char output[256] ; - - if (hd->homunculus.level == MAX_LEVEL || !hd->exp_next || hd->homunculus.exp < hd->exp_next) - return 0 ; - - hom = &hd->homunculus; - hom->level++ ; - if (!(hom->level % 3)) - hom->skillpts++ ; //1 skillpoint each 3 base level - - hom->exp -= hd->exp_next ; - hd->exp_next = hexptbl[hom->level - 1] ; - - max = &hd->homunculusDB->gmax; - min = &hd->homunculusDB->gmin; - - growth_max_hp = rand(min->HP, max->HP); - growth_max_sp = rand(min->SP, max->SP); - growth_str = rand(min->str, max->str); - growth_agi = rand(min->agi, max->agi); - growth_vit = rand(min->vit, max->vit); - growth_dex = rand(min->dex, max->dex); - growth_int = rand(min->int_,max->int_); - growth_luk = rand(min->luk, max->luk); - - //Aegis discards the decimals in the stat growth values! - growth_str-=growth_str%10; - growth_agi-=growth_agi%10; - growth_vit-=growth_vit%10; - growth_dex-=growth_dex%10; - growth_int-=growth_int%10; - growth_luk-=growth_luk%10; - - hom->max_hp += growth_max_hp; - hom->max_sp += growth_max_sp; - hom->str += growth_str; - hom->agi += growth_agi; - hom->vit += growth_vit; - hom->dex += growth_dex; - hom->int_+= growth_int; - hom->luk += growth_luk; - - if ( battle_config.homunculus_show_growth ) { - sprintf(output, - "Growth: hp:%d sp:%d str(%.2f) agi(%.2f) vit(%.2f) int(%.2f) dex(%.2f) luk(%.2f) ", - growth_max_hp, growth_max_sp, - growth_str/10.0, growth_agi/10.0, growth_vit/10.0, - growth_int/10.0, growth_dex/10.0, growth_luk/10.0); - clif_disp_onlyself(hd->master,output,strlen(output)); - } - return 1 ; -} - -int merc_hom_change_class(struct homun_data *hd, short class_) -{ - int i; - i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); - if(i < 0) - return 0; - hd->homunculusDB = &homunculus_db[i]; - hd->homunculus.class_ = class_; - status_set_viewdata(&hd->bl, class_); - merc_hom_calc_skilltree(hd); - return 1; -} - -int merc_hom_evolution(struct homun_data *hd) -{ - struct s_homunculus *hom; - struct h_stats *max, *min; - struct map_session_data *sd; - nullpo_retr(0, hd); - - if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class) - { - clif_emotion(&hd->bl, 4) ; //swt - return 0 ; - } - sd = hd->master; - if (!sd) - return 0; - - if (!merc_hom_change_class(hd, hd->homunculusDB->evo_class)) { - ShowError("merc_hom_evolution: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class); - return 0; - } - - //Apply evolution bonuses - hom = &hd->homunculus; - max = &hd->homunculusDB->emax; - min = &hd->homunculusDB->emin; - hom->max_hp += rand(min->HP, max->HP); - hom->max_sp += rand(min->SP, max->SP); - hom->str += 10*rand(min->str, max->str); - hom->agi += 10*rand(min->agi, max->agi); - hom->vit += 10*rand(min->vit, max->vit); - hom->int_+= 10*rand(min->int_,max->int_); - hom->dex += 10*rand(min->dex, max->dex); - hom->luk += 10*rand(min->luk, max->luk); - hom->intimacy = 500; - - unit_remove_map(&hd->bl, 0); - map_addblock(&hd->bl); - - clif_spawn(&hd->bl); - clif_emotion(&sd->bl, 21); //no1 - clif_misceffect2(&hd->bl,568); - - //status_Calc flag&1 will make current HP/SP be reloaded from hom structure - hom->hp = hd->battle_status.hp; - hom->sp = hd->battle_status.sp; - status_calc_homunculus(hd,1); - - if (!(battle_config.hom_setting&0x2)) - skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately - - return 1 ; -} - -int merc_hom_gainexp(struct homun_data *hd,int exp) -{ - if(hd->homunculus.vaporize) - return 1; - - if( hd->exp_next == 0 ) { - hd->homunculus.exp = 0 ; - return 0; - } - - hd->homunculus.exp += exp; - - if(hd->homunculus.exp < hd->exp_next) { - clif_hominfo(hd->master,hd,0); - return 0; - } - - //levelup - do - { - merc_hom_levelup(hd) ; - } - while(hd->homunculus.exp > hd->exp_next && hd->exp_next != 0 ); - - if( hd->exp_next == 0 ) - hd->homunculus.exp = 0 ; - - clif_misceffect2(&hd->bl,568); - status_calc_homunculus(hd,0); - status_percent_heal(&hd->bl, 100, 100); - return 0; -} - -// Return the new value -int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value) -{ - if( battle_config.homunculus_friendly_rate != 100 ) - value = (value * battle_config.homunculus_friendly_rate) / 100; - - if( hd->homunculus.intimacy + value <= 100000 ) - hd->homunculus.intimacy += value; - else - hd->homunculus.intimacy = 100000; - - return hd->homunculus.intimacy; -} - -// Return 0 if decrease fails or intimacy became 0 else the new value -int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value) -{ - if (hd->homunculus.intimacy >= value) - hd->homunculus.intimacy -= value; - else - hd->homunculus.intimacy = 0; - - return hd->homunculus.intimacy; -} - -void merc_hom_heal(struct homun_data *hd,int hp,int sp) -{ - clif_hominfo(hd->master,hd,0); -} - -void merc_save(struct homun_data *hd) -{ - // copy data that must be saved in homunculus struct ( hp / sp ) - TBL_PC * sd = hd->master; - //Do not check for max_hp/max_sp caps as current could be higher to max due - //to status changes/skills (they will be capped as needed upon stat - //calculation on login) - hd->homunculus.hp = hd->battle_status.hp; - hd->homunculus.sp = hd->battle_status.sp; - intif_homunculus_requestsave(sd->status.account_id, &hd->homunculus); -} - -int merc_menu(struct map_session_data *sd,int menunum) -{ - nullpo_retr(0, sd); - if (sd->hd == NULL) - return 1; - - switch(menunum) { - case 0: - break; - case 1: - merc_hom_food(sd, sd->hd); - break; - case 2: - merc_hom_delete(sd->hd, -1); - break; - default: - ShowError("merc_menu : unknown menu choice : %d\n", menunum) ; - break; - } - return 0; -} - -int merc_hom_food(struct map_session_data *sd, struct homun_data *hd) -{ - int i, foodID, emotion; - char mes[255]; - - if(hd->homunculus.vaporize) - return 1 ; - - foodID = hd->homunculusDB->foodID; - i = pc_search_inventory(sd,foodID); - if(i < 0) { - clif_hom_food(sd,foodID,0); - return 1; - } - pc_delitem(sd,i,1,0); - - if ( hd->homunculus.hunger >= 91 ) { - merc_hom_decrease_intimacy(hd, 50); - emotion = 16; - } else if ( hd->homunculus.hunger >= 76 ) { - merc_hom_decrease_intimacy(hd, 5); - emotion = 19; - } else if ( hd->homunculus.hunger >= 26 ) { - merc_hom_increase_intimacy(hd, 75); - emotion = 2; - } else if ( hd->homunculus.hunger >= 11 ) { - merc_hom_increase_intimacy(hd, 100); - emotion = 2; - } else { - merc_hom_increase_intimacy(hd, 50); - emotion = 2; - } - - hd->homunculus.hunger += 10; //dunno increase value for each food - if(hd->homunculus.hunger > 100) - hd->homunculus.hunger = 100; - - clif_emotion(&hd->bl,emotion) ; - snprintf(mes, sizeof mes,"%s : Gracias!!",hd->homunculus.name); - clif_message(&hd->bl,mes); - - clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); - clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); - clif_hom_food(sd,foodID,1); - - // Too much food :/ - if(hd->homunculus.intimacy == 0) - return merc_hom_delete(sd->hd, 23); //omg - - return 0; -} - -static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) -{ - struct map_session_data *sd; - struct homun_data *hd; - - sd=map_id2sd(id); - if(!sd) - return 1; - - if(!sd->status.hom_id || !(hd=sd->hd)) - return 1; - - if(hd->hungry_timer != tid){ - ShowError("merc_hom_hungry_timer %d != %d\n",hd->hungry_timer,tid); - return 0; - } - - hd->hungry_timer = INVALID_TIMER; - - hd->homunculus.hunger-- ; - if(hd->homunculus.hunger <= 10) { - clif_emotion(&hd->bl, 6) ; //an - } else if(hd->homunculus.hunger == 25) { - clif_emotion(&hd->bl, 20) ; //hmm - } else if(hd->homunculus.hunger == 75) { - clif_emotion(&hd->bl, 33) ; //ok - } - - if(hd->homunculus.hunger < 0) { - hd->homunculus.hunger = 0; - // Delete the homunculus if intimacy <= 100 - if ( !merc_hom_decrease_intimacy(hd, 100) ) - return merc_hom_delete(hd, 23); //omg - clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); - } - - clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); - hd->hungry_timer = add_timer(tick+hd->homunculusDB->hungryDelay,merc_hom_hungry,sd->bl.id,0); //simple Fix albator - return 0; -} - -int merc_hom_hungry_timer_delete(struct homun_data *hd) -{ - nullpo_retr(0, hd); - if(hd->hungry_timer != -1) { - delete_timer(hd->hungry_timer,merc_hom_hungry); - hd->hungry_timer = INVALID_TIMER; - } - return 1; -} - -int merc_hom_change_name(struct map_session_data *sd,char *name) -{ - int i; - struct homun_data *hd; - nullpo_retr(1, sd); - - hd = sd->hd; - if (!merc_is_hom_active(hd)) - return 1; - if(hd->homunculus.rename_flag && !battle_config.hom_rename) - return 1; - - for(i=0;ihd; - if (!merc_is_hom_active(hd)) return 0; - if (!flag) { - clif_displaymessage(sd->fd, msg_txt(280)); // You cannot use this name - return 0; - } - strncpy(hd->homunculus.name,name,NAME_LENGTH); - clif_charnameack (0,&hd->bl); - hd->homunculus.rename_flag = 1; - clif_hominfo(sd,hd,0); - return 1; -} - -int search_homunculusDB_index(int key,int type) -{ - int i; - - for(i=0;istatus.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd); - - i = search_homunculusDB_index(hom->class_,HOMUNCULUS_CLASS); - if(i < 0) { - ShowError("merc_hom_alloc: unknown class [%d] for homunculus '%s', requesting deletion.\n", hom->class_, hom->name); - sd->status.hom_id = 0; - intif_homunculus_requestdelete(hom->hom_id); - return 1; - } - sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data)); - hd->bl.type = BL_HOM; - hd->bl.id = npc_get_new_npc_id(); - - hd->master = sd; - hd->homunculusDB = &homunculus_db[i]; - memcpy(&hd->homunculus, hom, sizeof(struct s_homunculus)); - hd->exp_next = hexptbl[hd->homunculus.level - 1]; - - status_set_viewdata(&hd->bl, hd->homunculus.class_); - status_change_init(&hd->bl); - unit_dataset(&hd->bl); - hd->ud.dir = sd->ud.dir; - - // Find a random valid pos around the player - hd->bl.m = sd->bl.m; - hd->bl.x = sd->bl.x; - hd->bl.y = sd->bl.y; - unit_calc_pos(&hd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); - hd->bl.x = hd->ud.to_x; - hd->bl.y = hd->ud.to_y; - - map_addiddb(&hd->bl); - status_calc_homunculus(hd,1); - - hd->hungry_timer = INVALID_TIMER; - return 0; -} - -void merc_hom_init_timers(struct homun_data * hd) -{ - if (hd->hungry_timer == -1) - hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,merc_hom_hungry,hd->master->bl.id,0); - hd->regen.state.block = 0; //Restore HP/SP block. -} - -int merc_call_homunculus(struct map_session_data *sd) -{ - struct homun_data *hd; - - if (!sd->status.hom_id) //Create a new homun. - return merc_create_homunculus_request(sd, HM_CLASS_BASE + rand(0, 7)) ; - - // If homunc not yet loaded, load it - if (!sd->hd) - return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); - - hd = sd->hd; - - if (!hd->homunculus.vaporize) - return 0; //Can't use this if homun wasn't vaporized. - - merc_hom_init_timers(hd); - hd->homunculus.vaporize = 0; - if (hd->bl.prev == NULL) - { //Spawn him - hd->bl.x = sd->bl.x; - hd->bl.y = sd->bl.y; - hd->bl.m = sd->bl.m; - map_addblock(&hd->bl); - clif_spawn(&hd->bl); - clif_send_homdata(sd,SP_ACK,0); - clif_hominfo(sd,hd,1); - clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] - clif_homskillinfoblock(sd); - if (battle_config.slaves_inherit_speed&1) - status_calc_bl(&hd->bl, SCB_SPEED); - merc_save(hd); - } else - //Warp him to master. - unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,0); - return 1; -} - -// Recv homunculus data from char server -int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag) -{ - struct map_session_data *sd; - struct homun_data *hd; - - sd = map_id2sd(account_id); - if(!sd) - return 0; - if (sd->status.char_id != sh->char_id) - { - if (sd->status.hom_id == sh->hom_id) - sh->char_id = sd->status.char_id; //Correct char id. - else - return 0; - } - if(!flag) { // Failed to load - sd->status.hom_id = 0; - return 0; - } - - if (!sd->status.hom_id) //Hom just created. - sd->status.hom_id = sh->hom_id; - if (sd->hd) //uh? Overwrite the data. - memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus)); - else - merc_hom_alloc(sd, sh); - - hd = sd->hd; - if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL) - { - map_addblock(&hd->bl); - clif_spawn(&hd->bl); - clif_send_homdata(sd,SP_ACK,0); - clif_hominfo(sd,hd,1); - clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] - clif_homskillinfoblock(sd); - merc_hom_init_timers(hd); - } - return 1; -} - -// Ask homunculus creation to char server -int merc_create_homunculus_request(struct map_session_data *sd, int class_) -{ - struct s_homunculus homun; - struct h_stats *base; - int i; - - nullpo_retr(1, sd); - - i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); - if(i < 0) return 0; - - memset(&homun, 0, sizeof(struct s_homunculus)); - //Initial data - strncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1); - homun.class_ = class_; - homun.level = 1; - homun.hunger = 32; //32% - homun.intimacy = 2100; //21/1000 - homun.char_id = sd->status.char_id; - - homun.hp = 10 ; - base = &homunculus_db[i].base; - homun.max_hp = base->HP; - homun.max_sp = base->SP; - homun.str = base->str *10; - homun.agi = base->agi *10; - homun.vit = base->vit *10; - homun.int_= base->int_*10; - homun.dex = base->dex *10; - homun.luk = base->luk *10; - - // Request homunculus creation - intif_homunculus_create(sd->status.account_id, &homun); - return 1; -} - -int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, short x, short y) -{ - struct homun_data* hd; - nullpo_retr(0, sd); - - if (!sd->status.hom_id) - return 0; // no homunculus - - if (!sd->hd) //Load homun data; - return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); - - hd = sd->hd; - - if (hd->homunculus.vaporize) - return 0; // vaporized homunculi need to be 'called' - - if (!status_isdead(&hd->bl)) - return 0; // already alive - - merc_hom_init_timers(hd); - - if (!hd->bl.prev) - { //Add it back to the map. - hd->bl.m = sd->bl.m; - hd->bl.x = x; - hd->bl.y = y; - map_addblock(&hd->bl); - clif_spawn(&hd->bl); - } - status_revive(&hd->bl, per, 0); - return 1; -} - -void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp) -{ - struct map_session_data *sd = hd->master; - hd->homunculus.hp = hd->battle_status.hp; - if (!sd) - return; - clif_send_homdata(sd,SP_ACK,0); - clif_hominfo(sd,hd,1); - clif_hominfo(sd,hd,0); - clif_homskillinfoblock(sd); -} - -void merc_reset_stats(struct homun_data *hd) -{ //Resets a homunc stats back to zero (but doesn't touches hunger or intimacy) - struct s_homunculus_db *db; - struct s_homunculus *hom; - struct h_stats *base; - hom = &hd->homunculus; - db = hd->homunculusDB; - base = &db->base; - hom->level = 1; - hom->hp = 10; - hom->max_hp = base->HP; - hom->max_sp = base->SP; - hom->str = base->str *10; - hom->agi = base->agi *10; - hom->vit = base->vit *10; - hom->int_= base->int_*10; - hom->dex = base->dex *10; - hom->luk = base->luk *10; - hom->exp = 0; - hd->exp_next = hexptbl[0]; - memset(&hd->homunculus.hskill, 0, sizeof hd->homunculus.hskill); - hd->homunculus.skillpts = 0; -} - -int merc_hom_shuffle(struct homun_data *hd) -{ - struct map_session_data *sd; - int lv, i, skillpts; - unsigned int exp; - struct s_skill b_skill[MAX_HOMUNSKILL]; - - if (!merc_is_hom_active(hd)) - return 0; - - sd = hd->master; - lv = hd->homunculus.level; - exp = hd->homunculus.exp; - memcpy(&b_skill, &hd->homunculus.hskill, sizeof(b_skill)); - skillpts = hd->homunculus.skillpts; - //Reset values to level 1. - merc_reset_stats(hd); - //Level it back up - for (i = 1; i < lv && hd->exp_next; i++){ - hd->homunculus.exp += hd->exp_next; - merc_hom_levelup(hd); - } - - if(hd->homunculus.class_ == hd->homunculusDB->evo_class) { - //Evolved bonuses - struct s_homunculus *hom = &hd->homunculus; - struct h_stats *max = &hd->homunculusDB->emax, *min = &hd->homunculusDB->emin; - hom->max_hp += rand(min->HP, max->HP); - hom->max_sp += rand(min->SP, max->SP); - hom->str += 10*rand(min->str, max->str); - hom->agi += 10*rand(min->agi, max->agi); - hom->vit += 10*rand(min->vit, max->vit); - hom->int_+= 10*rand(min->int_,max->int_); - hom->dex += 10*rand(min->dex, max->dex); - hom->luk += 10*rand(min->luk, max->luk); - } - - hd->homunculus.exp = exp; - memcpy(&hd->homunculus.hskill, &b_skill, sizeof(b_skill)); - hd->homunculus.skillpts = skillpts; - clif_homskillinfoblock(sd); - status_calc_homunculus(hd,0); - status_percent_heal(&hd->bl, 100, 100); - clif_misceffect2(&hd->bl,568); - - return 1; -} - -int read_homunculusdb(void) -{ - FILE *fp; - char line[1024], *p; - int i, k, classid; - int j = 0; - const char *filename[]={"homunculus_db.txt","homunculus_db2.txt"}; - char *str[50]; - struct s_homunculus_db *db; - - memset(homunculus_db,0,sizeof(homunculus_db)); - for(i = 0; i<2; i++) - { - sprintf(line, "%s/%s", db_path, filename[i]); - fp = fopen(line,"r"); - if(!fp){ - if(i != 0) - continue; - ShowError("read_homunculusdb : can't read %s\n", line); - return -1; - } - - while(fgets(line, sizeof(line), fp) && j < MAX_HOMUNCULUS_CLASS) - { - if(line[0] == '/' && line[1] == '/') - continue; - - k = 0; - p = strtok (line,","); - while (p != NULL && k < 50) - { - str[k++] = p; - p = strtok (NULL, ","); - } - if (k < 50 ) - { - ShowError("read_homunculusdb : Incorrect number of columns at %s, homunculus %d. Read %d columns, 50 are needed.\n", filename[i], j+1, k); - continue; - } - - //Base Class,Evo Class - classid = atoi(str[0]); - if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) - { - ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); - continue; - } - db = &homunculus_db[j]; - db->base_class = classid; - classid = atoi(str[1]); - if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) - { - db->base_class = 0; - ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); - continue; - } - db->evo_class = classid; - //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD - strncpy(db->name,str[2],NAME_LENGTH-1); - db->foodID = atoi(str[3]); - db->hungryDelay = atoi(str[4]); - db->base_size = atoi(str[5]); - db->evo_size = atoi(str[6]); - db->race = atoi(str[7]); - db->element = atoi(str[8]); - db->baseASPD = atoi(str[9]); - //base HP, SP, str, agi, vit, int, dex, luk - db->base.HP = atoi(str[10]); - db->base.SP = atoi(str[11]); - db->base.str = atoi(str[12]); - db->base.agi = atoi(str[13]); - db->base.vit = atoi(str[14]); - db->base.int_= atoi(str[15]); - db->base.dex = atoi(str[16]); - db->base.luk = atoi(str[17]); - //Growth Min/Max HP, SP, str, agi, vit, int, dex, luk - db->gmin.HP = atoi(str[18]); - db->gmax.HP = atoi(str[19]); - db->gmin.SP = atoi(str[20]); - db->gmax.SP = atoi(str[21]); - db->gmin.str = atoi(str[22]); - db->gmax.str = atoi(str[23]); - db->gmin.agi = atoi(str[24]); - db->gmax.agi = atoi(str[25]); - db->gmin.vit = atoi(str[26]); - db->gmax.vit = atoi(str[27]); - db->gmin.int_= atoi(str[28]); - db->gmax.int_= atoi(str[29]); - db->gmin.dex = atoi(str[30]); - db->gmax.dex = atoi(str[31]); - db->gmin.luk = atoi(str[32]); - db->gmax.luk = atoi(str[33]); - //Evolution Min/Max HP, SP, str, agi, vit, int, dex, luk - db->emin.HP = atoi(str[34]); - db->emax.HP = atoi(str[35]); - db->emin.SP = atoi(str[36]); - db->emax.SP = atoi(str[37]); - db->emin.str = atoi(str[38]); - db->emax.str = atoi(str[39]); - db->emin.agi = atoi(str[40]); - db->emax.agi = atoi(str[41]); - db->emin.vit = atoi(str[42]); - db->emax.vit = atoi(str[43]); - db->emin.int_= atoi(str[44]); - db->emax.int_= atoi(str[45]); - db->emin.dex = atoi(str[46]); - db->emax.dex = atoi(str[47]); - db->emin.luk = atoi(str[48]); - db->emax.luk = atoi(str[49]); - - //Check that the min/max values really are below the other one. - if(db->gmin.HP > db->gmax.HP) - db->gmin.HP = db->gmax.HP; - if(db->gmin.SP > db->gmax.SP) - db->gmin.SP = db->gmax.SP; - if(db->gmin.str > db->gmax.str) - db->gmin.str = db->gmax.str; - if(db->gmin.agi > db->gmax.agi) - db->gmin.agi = db->gmax.agi; - if(db->gmin.vit > db->gmax.vit) - db->gmin.vit = db->gmax.vit; - if(db->gmin.int_> db->gmax.int_) - db->gmin.int_= db->gmax.int_; - if(db->gmin.dex > db->gmax.dex) - db->gmin.dex = db->gmax.dex; - if(db->gmin.luk > db->gmax.luk) - db->gmin.luk = db->gmax.luk; - - if(db->emin.HP > db->emax.HP) - db->emin.HP = db->emax.HP; - if(db->emin.SP > db->emax.SP) - db->emin.SP = db->emax.SP; - if(db->emin.str > db->emax.str) - db->emin.str = db->emax.str; - if(db->emin.agi > db->emax.agi) - db->emin.agi = db->emax.agi; - if(db->emin.vit > db->emax.vit) - db->emin.vit = db->emax.vit; - if(db->emin.int_> db->emax.int_) - db->emin.int_= db->emax.int_; - if(db->emin.dex > db->emax.dex) - db->emin.dex = db->emax.dex; - if(db->emin.luk > db->emax.luk) - db->emin.luk = db->emax.luk; - - j++; - } - if (j > MAX_HOMUNCULUS_CLASS) - ShowWarning("read_homunculusdb: Reached max number of homunculus [%d]. Remaining homunculus were not read.\n ", MAX_HOMUNCULUS_CLASS); - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' homunculus in '"CL_WHITE"db/%s"CL_RESET"'.\n",j,filename[i]); - } - return 0; -} - -int read_homunculus_skilldb(void) -{ - FILE *fp; - char line[1024], *p; - int k, classid; - int j = 0; - char *split[15]; - - memset(hskill_tree,0,sizeof(hskill_tree)); - sprintf(line, "%s/homun_skill_tree.txt", db_path); - fp=fopen(line,"r"); - if(fp==NULL){ - ShowError("can't read %s\n", line); - return 1; - } - - while(fgets(line, sizeof(line), fp)) - { - int minJobLevelPresent = 0; - - if(line[0]=='/' && line[1]=='/') - continue; - - k = 0; - p = strtok(line,","); - while (p != NULL && k < 15) - { - split[k++] = p; - p = strtok(NULL, ","); - } - - if(k < 13) - continue; - - if (k == 14) - minJobLevelPresent = 1; // MinJobLvl has been added - - // check for bounds [celest] - classid = atoi(split[0]) - HM_CLASS_BASE; - if ( classid >= MAX_HOMUNCULUS_CLASS ) - continue; - - k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex] - // Search an empty line or a line with the same skill_id (stored in j) - for(j = 0; j < MAX_SKILL_TREE && hskill_tree[classid][j].id && hskill_tree[classid][j].id != k; j++); - - if (j == MAX_SKILL_TREE) - { - ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid); - continue; - } - - hskill_tree[classid][j].id=k; - hskill_tree[classid][j].max=atoi(split[2]); - if (minJobLevelPresent) - hskill_tree[classid][j].joblv=atoi(split[3]); - - for(k=0;k<5;k++){ - hskill_tree[classid][j].need[k].id=atoi(split[3+k*2+minJobLevelPresent]); - hskill_tree[classid][j].need[k].lv=atoi(split[3+k*2+minJobLevelPresent+1]); - } - } - - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","homun_skill_tree.txt"); - return 0; -} - -void read_homunculus_expdb(void) -{ - FILE *fp; - char line[1024]; - int i, j=0; - char *filename[]={"exp_homun.txt","exp_homun2.txt"}; - - memset(hexptbl,0,sizeof(hexptbl)); - for(i=0; i<2; i++){ - sprintf(line, "%s/%s", db_path, filename[i]); - fp=fopen(line,"r"); - if(fp == NULL){ - if(i != 0) - continue; - ShowError("can't read %s\n",line); - return; - } - while(fgets(line, sizeof(line), fp) && j < MAX_LEVEL) - { - if(line[0] == '/' && line[1] == '/') - continue; - - hexptbl[j] = strtoul(line, NULL, 10); - if (!hexptbl[j++]) - break; - } - if (hexptbl[MAX_LEVEL - 1]) // Last permitted level have to be 0! - { - ShowWarning("read_hexptbl: Reached max level in exp_homun [%d]. Remaining lines were not read.\n ", MAX_LEVEL); - hexptbl[MAX_LEVEL - 1] = 0; - } - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' levels in '"CL_WHITE"%s"CL_RESET"'.\n", j, filename[i]); - } -} - -void merc_reload(void) -{ - read_homunculusdb(); - read_homunculus_expdb(); -} - -void merc_skill_reload(void) -{ - read_homunculus_skilldb(); -} - -int do_init_merc(void) -{ - int class_; - read_homunculusdb(); - read_homunculus_expdb(); - read_homunculus_skilldb(); - - // Add homunc timer function to timer func list [Toms] - add_timer_func_list(merc_hom_hungry, "merc_hom_hungry"); - - //Stock view data for homuncs - memset(&hom_viewdb, 0, sizeof(hom_viewdb)); - for (class_ = 0; class_ < ARRAYLENGTH(hom_viewdb); class_++) - hom_viewdb[class_].class_ = HM_CLASS_BASE+class_; - return 0; -} - -int do_final_merc(void); diff --git a/src/map/homunculus.h b/src/map/homunculus.h deleted file mode 100644 index 9e716e566..000000000 --- a/src/map/homunculus.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder - -#ifndef _HOMUNCULUS_H_ -#define _HOMUNCULUS_H_ - -#include "status.h" // struct status_data, struct status_change -#include "unit.h" // struct unit_data - -struct h_stats { - unsigned int HP, SP; - unsigned short str, agi, vit, int_, dex, luk; -}; - -struct s_homunculus_db { - int base_class, evo_class; - char name[NAME_LENGTH]; - struct h_stats base, gmin, gmax, emin, emax; - int foodID ; - int baseASPD ; - long hungryDelay ; - unsigned char element, race, base_size, evo_size; -}; - -extern struct s_homunculus_db homuncumlus_db[MAX_HOMUNCULUS_CLASS]; -enum { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD }; -enum { - SP_ACK = 0x00, - SP_INTIMATE = 0x100, - SP_HUNGRY = 0x200 -}; - -struct homun_data { - struct block_list bl; - struct unit_data ud; - struct view_data *vd; - struct status_data base_status, battle_status; - struct status_change sc; - struct regen_data regen; - struct s_homunculus_db *homunculusDB; //[orn] - struct s_homunculus homunculus; //[orn] - - struct map_session_data *master; //pointer back to its master - int hungry_timer; //[orn] - unsigned int exp_next; - char blockskill[MAX_SKILL]; // [orn] -}; - - -#define homdb_checkid(id) (id >= HM_CLASS_BASE && id <= HM_CLASS_MAX) - -// merc_is_hom_alive(struct homun_data *) -#define merc_is_hom_active(x) (x && x->homunculus.vaporize != 1 && x->battle_status.hp > 0) -int do_init_merc(void); -int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag); //albator -struct view_data* merc_get_hom_viewdata(int class_); -void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp); -int merc_hom_dead(struct homun_data *hd, struct block_list *src); -void merc_hom_skillup(struct homun_data *hd,int skillnum); -int merc_hom_calc_skilltree(struct homun_data *hd) ; -int merc_hom_checkskill(struct homun_data *hd,int skill_id) ; -int merc_hom_gainexp(struct homun_data *hd,int exp) ; -int merc_hom_levelup(struct homun_data *hd) ; -int merc_hom_evolution(struct homun_data *hd) ; -void merc_hom_heal(struct homun_data *hd,int hp,int sp); -int merc_hom_vaporize(struct map_session_data *sd, int flag); -int merc_resurrect_homunculus(struct map_session_data *sd, unsigned char per, short x, short y); -void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp); -void merc_reset_stats(struct homun_data *hd); -int merc_hom_shuffle(struct homun_data *hd); // [Zephyrus] -void merc_save(struct homun_data *hd); -int merc_call_homunculus(struct map_session_data *sd); -int merc_create_homunculus_request(struct map_session_data *sd, int class_); -int search_homunculusDB_index(int key,int type); -int merc_menu(struct map_session_data *sd,int menunum); -int merc_hom_food(struct map_session_data *sd, struct homun_data *hd); -int merc_hom_hungry_timer_delete(struct homun_data *hd); -int merc_hom_change_name(struct map_session_data *sd,char *name); -int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag); -#define merc_stop_walking(hd, type) unit_stop_walking(&(hd)->bl, type) -#define merc_stop_attack(hd) unit_stop_attack(&(hd)->bl) -int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value); -int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value); -int merc_skill_tree_get_max(int id, int b_class); -void merc_hom_init_timers(struct homun_data * hd); -void merc_skill_reload(void); -void merc_reload(void); - -#endif /* _HOMUNCULUS_H_ */ diff --git a/src/map/mercenary.c b/src/map/mercenary.c index dc49f5e21..c56c36cdb 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -29,6 +29,7 @@ #include "npc.h" #include "trade.h" #include "unit.h" + #include "mercenary.h" #include @@ -36,348 +37,1132 @@ #include #include -struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS]; // Mercenary Database -int merc_search_index(int class_) +//Better equiprobability than rand()% [orn] +#define rand(a, b) (a+(int) ((float)(b-a+1)*rand()/(RAND_MAX+1.0))) + +struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS]; //[orn] +struct skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_SKILL_TREE]; + +static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data); + +static unsigned int hexptbl[MAX_LEVEL]; + +//For holding the view data of npc classes. [Skotlex] +static struct view_data hom_viewdb[MAX_HOMUNCULUS_CLASS]; + +struct view_data* merc_get_hom_viewdata(int class_) +{ //Returns the viewdata for homunculus + if (homdb_checkid(class_)) + return &hom_viewdb[class_-HM_CLASS_BASE]; + return NULL; +} + +void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp) { - int i; - ARR_FIND(0, MAX_MERCENARY_CLASS, i, mercenary_db[i].class_ == class_); - return (i == MAX_MERCENARY_CLASS)?-1:i; + clif_hominfo(hd->master,hd,0); } -bool merc_class(int class_) +int merc_hom_dead(struct homun_data *hd, struct block_list *src) { - return (bool)(merc_search_index(class_) > -1); + //There's no intimacy penalties on death (from Tharis) + struct map_session_data *sd = hd->master; + + clif_emotion(&hd->bl, 16) ; //wah + + //Delete timers when dead. + merc_hom_hungry_timer_delete(hd); + hd->homunculus.hp = 0; + + if (!sd) //unit remove map will invoke unit free + return 3; + + clif_emotion(&sd->bl, 28) ; //sob + //Remove from map (if it has no intimacy, it is auto-removed from memory) + return 3; } -struct view_data * merc_get_viewdata(int class_) +//Vaporize a character's homun. If flag, HP needs to be 80% or above. +int merc_hom_vaporize(struct map_session_data *sd, int flag) { - int i = merc_search_index(class_); - if( i < 0 ) + struct homun_data *hd; + + nullpo_retr(0, sd); + + hd = sd->hd; + if (!hd || hd->homunculus.vaporize) + return 0; + + if (status_isdead(&hd->bl)) + return 0; //Can't vaporize a dead homun. + + if (flag && get_percentage(hd->battle_status.hp, hd->battle_status.max_hp) < 80) return 0; - return &mercenary_db[i].vd; + hd->regen.state.block = 3; //Block regen while vaporized. + //Delete timers when vaporized. + merc_hom_hungry_timer_delete(hd); + hd->homunculus.vaporize = 1; + if(battle_config.hom_setting&0x40) + memset(hd->blockskill, 0, sizeof(hd->blockskill)); + clif_hominfo(sd, sd->hd, 0); + merc_save(hd); + return unit_remove_map(&hd->bl, 0); } -int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime) +//delete a homunculus, completely "killing it". +//Emote is the emotion the master should use, send negative to disable. +int merc_hom_delete(struct homun_data *hd, int emote) { - struct s_mercenary merc; - struct s_mercenary_db *db; - int i; - nullpo_retr(1,sd); + struct map_session_data *sd; + nullpo_retr(0, hd); + sd = hd->master; - if( (i = merc_search_index(class_)) < 0 ) - return 0; + if (!sd) + return unit_free(&hd->bl,1); - db = &mercenary_db[i]; - memset(&merc,0,sizeof(struct s_mercenary)); + if (emote >= 0) + clif_emotion(&sd->bl, emote); - merc.char_id = sd->status.char_id; - merc.class_ = class_; - merc.hp = db->status.max_hp; - merc.sp = db->status.max_sp; - merc.remain_life_time = lifetime; + //This makes it be deleted right away. + hd->homunculus.intimacy = 0; + // Send homunculus_dead to client + hd->homunculus.hp = 0; + clif_hominfo(sd, hd, 0); + return unit_remove_map(&hd->bl,0); +} - // Request Char Server to create this mercenary - intif_mercenary_create(&merc); +int merc_hom_calc_skilltree(struct homun_data *hd) +{ + int i,id=0 ; + int j,f=1; + int c=0; - return 1; + nullpo_retr(0, hd); + c = hd->homunculus.class_ - HM_CLASS_BASE; + + for(i=0;i < MAX_SKILL_TREE && (id = hskill_tree[c][i].id) > 0;i++) + { + if(hd->homunculus.hskill[id-HM_SKILLBASE].id) + continue; //Skill already known. + if(!battle_config.skillfree) + { + for(j=0;j<5;j++) + { + if( hskill_tree[c][i].need[j].id && + merc_hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv) + { + f=0; + break; + } + } + } + if (f) + hd->homunculus.hskill[id-HM_SKILLBASE].id = id ; + } + return 0; } -int mercenary_save(struct mercenary_data *md) +int merc_hom_checkskill(struct homun_data *hd,int skill_id) { - const struct TimerData * td = get_timer(md->contract_timer); + int i = skill_id - HM_SKILLBASE; + if(!hd) + return 0; - md->mercenary.hp = md->battle_status.hp; - md->mercenary.sp = md->battle_status.sp; - if( td != NULL ) - md->mercenary.remain_life_time = DIFF_TICK(td->tick, gettick()); - else + if(hd->homunculus.hskill[i].id == skill_id) + return (hd->homunculus.hskill[i].lv); + + return 0; +} + +int merc_skill_tree_get_max(int id, int b_class){ + int i, skillid; + b_class -= HM_CLASS_BASE; + for(i=0;(skillid=hskill_tree[b_class][i].id)>0;i++) + if (id == skillid) + return hskill_tree[b_class][i].max; + return skill_get_max(id); +} + +void merc_hom_skillup(struct homun_data *hd,int skillnum) +{ + int i = 0 ; + nullpo_retv(hd); + + if(hd->homunculus.vaporize) + return; + + i = skillnum - HM_SKILLBASE; + if(hd->homunculus.skillpts > 0 && + hd->homunculus.hskill[i].id && + hd->homunculus.hskill[i].flag == 0 && //Don't allow raising while you have granted skills. [Skotlex] + hd->homunculus.hskill[i].lv < merc_skill_tree_get_max(skillnum, hd->homunculus.class_) + ) { - md->mercenary.remain_life_time = 0; - ShowWarning("mercenary_save : mercenary without timer (tid %d)\n", md->contract_timer); + hd->homunculus.hskill[i].lv++; + hd->homunculus.skillpts-- ; + status_calc_homunculus(hd,0); + if (hd->master) { + clif_homskillup(hd->master, skillnum); + clif_hominfo(hd->master,hd,0); + clif_homskillinfoblock(hd->master); + } + } +} + +int merc_hom_levelup(struct homun_data *hd) +{ + struct s_homunculus *hom; + struct h_stats *min, *max; + int growth_str, growth_agi, growth_vit, growth_int, growth_dex, growth_luk ; + int growth_max_hp, growth_max_sp ; + char output[256] ; + + if (hd->homunculus.level == MAX_LEVEL || !hd->exp_next || hd->homunculus.exp < hd->exp_next) + return 0 ; + + hom = &hd->homunculus; + hom->level++ ; + if (!(hom->level % 3)) + hom->skillpts++ ; //1 skillpoint each 3 base level + + hom->exp -= hd->exp_next ; + hd->exp_next = hexptbl[hom->level - 1] ; + + max = &hd->homunculusDB->gmax; + min = &hd->homunculusDB->gmin; + + growth_max_hp = rand(min->HP, max->HP); + growth_max_sp = rand(min->SP, max->SP); + growth_str = rand(min->str, max->str); + growth_agi = rand(min->agi, max->agi); + growth_vit = rand(min->vit, max->vit); + growth_dex = rand(min->dex, max->dex); + growth_int = rand(min->int_,max->int_); + growth_luk = rand(min->luk, max->luk); + + //Aegis discards the decimals in the stat growth values! + growth_str-=growth_str%10; + growth_agi-=growth_agi%10; + growth_vit-=growth_vit%10; + growth_dex-=growth_dex%10; + growth_int-=growth_int%10; + growth_luk-=growth_luk%10; + + hom->max_hp += growth_max_hp; + hom->max_sp += growth_max_sp; + hom->str += growth_str; + hom->agi += growth_agi; + hom->vit += growth_vit; + hom->dex += growth_dex; + hom->int_+= growth_int; + hom->luk += growth_luk; + + if ( battle_config.homunculus_show_growth ) { + sprintf(output, + "Growth: hp:%d sp:%d str(%.2f) agi(%.2f) vit(%.2f) int(%.2f) dex(%.2f) luk(%.2f) ", + growth_max_hp, growth_max_sp, + growth_str/10.0, growth_agi/10.0, growth_vit/10.0, + growth_int/10.0, growth_dex/10.0, growth_luk/10.0); + clif_disp_onlyself(hd->master,output,strlen(output)); } + return 1 ; +} - intif_mercenary_save(&md->mercenary); +int merc_hom_change_class(struct homun_data *hd, short class_) +{ + int i; + i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); + if(i < 0) + return 0; + hd->homunculusDB = &homunculus_db[i]; + hd->homunculus.class_ = class_; + status_set_viewdata(&hd->bl, class_); + merc_hom_calc_skilltree(hd); return 1; } -static int merc_contract_end(int tid, unsigned int tick, int id, intptr data) +int merc_hom_evolution(struct homun_data *hd) { + struct s_homunculus *hom; + struct h_stats *max, *min; struct map_session_data *sd; - struct mercenary_data *md; + nullpo_retr(0, hd); - if( (sd = map_id2sd(id)) == NULL ) - return 1; - if( (md = sd->md) == NULL ) + if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class) + { + clif_emotion(&hd->bl, 4) ; //swt + return 0 ; + } + sd = hd->master; + if (!sd) + return 0; + + if (!merc_hom_change_class(hd, hd->homunculusDB->evo_class)) { + ShowError("merc_hom_evolution: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class); + return 0; + } + + //Apply evolution bonuses + hom = &hd->homunculus; + max = &hd->homunculusDB->emax; + min = &hd->homunculusDB->emin; + hom->max_hp += rand(min->HP, max->HP); + hom->max_sp += rand(min->SP, max->SP); + hom->str += 10*rand(min->str, max->str); + hom->agi += 10*rand(min->agi, max->agi); + hom->vit += 10*rand(min->vit, max->vit); + hom->int_+= 10*rand(min->int_,max->int_); + hom->dex += 10*rand(min->dex, max->dex); + hom->luk += 10*rand(min->luk, max->luk); + hom->intimacy = 500; + + unit_remove_map(&hd->bl, 0); + map_addblock(&hd->bl); + + clif_spawn(&hd->bl); + clif_emotion(&sd->bl, 21); //no1 + clif_misceffect2(&hd->bl,568); + + //status_Calc flag&1 will make current HP/SP be reloaded from hom structure + hom->hp = hd->battle_status.hp; + hom->sp = hd->battle_status.sp; + status_calc_homunculus(hd,1); + + if (!(battle_config.hom_setting&0x2)) + skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately + + return 1 ; +} + +int merc_hom_gainexp(struct homun_data *hd,int exp) +{ + if(hd->homunculus.vaporize) return 1; - if( md->contract_timer != tid ) - { - ShowError("merc_contract_end %d != %d.\n", md->contract_timer, tid); + if( hd->exp_next == 0 ) { + hd->homunculus.exp = 0 ; return 0; } - md->contract_timer = INVALID_TIMER; - merc_delete(md, 0); // Mercenary soldier's duty hour is over. + hd->homunculus.exp += exp; + + if(hd->homunculus.exp < hd->exp_next) { + clif_hominfo(hd->master,hd,0); + return 0; + } + //levelup + do + { + merc_hom_levelup(hd) ; + } + while(hd->homunculus.exp > hd->exp_next && hd->exp_next != 0 ); + + if( hd->exp_next == 0 ) + hd->homunculus.exp = 0 ; + + clif_misceffect2(&hd->bl,568); + status_calc_homunculus(hd,0); + status_percent_heal(&hd->bl, 100, 100); return 0; } -int merc_delete(struct mercenary_data *md, int reply) +// Return the new value +int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value) { - struct map_session_data *sd = md->master; - md->mercenary.remain_life_time = 0; + if (battle_config.homunculus_friendly_rate != 100) + value = (value * battle_config.homunculus_friendly_rate) / 100; - merc_contract_stop(md); + if (hd->homunculus.intimacy + value <= 100000) + hd->homunculus.intimacy += value; + else + hd->homunculus.intimacy = 100000; + return hd->homunculus.intimacy; +} - if( !sd ) - return unit_free(&md->bl, 1); - clif_mercenary_message(sd->fd, reply); - - return unit_remove_map(&md->bl, 1); +// Return 0 if decrease fails or intimacy became 0 else the new value +int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value) +{ + if (hd->homunculus.intimacy >= value) + hd->homunculus.intimacy -= value; + else + hd->homunculus.intimacy = 0; + + return hd->homunculus.intimacy; } -void merc_contract_stop(struct mercenary_data *md) +void merc_hom_heal(struct homun_data *hd,int hp,int sp) { - nullpo_retv(md); - if( md->contract_timer != INVALID_TIMER ) - delete_timer(md->contract_timer, merc_contract_end); - md->contract_timer = INVALID_TIMER; + clif_hominfo(hd->master,hd,0); } -void merc_contract_init(struct mercenary_data *md) +void merc_save(struct homun_data *hd) { - if( md->contract_timer == INVALID_TIMER ) - md->contract_timer = add_timer(gettick() + md->mercenary.remain_life_time, merc_contract_end, md->master->bl.id, 0); + // copy data that must be saved in homunculus struct ( hp / sp ) + TBL_PC * sd = hd->master; + //Do not check for max_hp/max_sp caps as current could be higher to max due + //to status changes/skills (they will be capped as needed upon stat + //calculation on login) + hd->homunculus.hp = hd->battle_status.hp; + hd->homunculus.sp = hd->battle_status.sp; + intif_homunculus_requestsave(sd->status.account_id, &hd->homunculus); +} - md->regen.state.block = 0; +int merc_menu(struct map_session_data *sd,int menunum) +{ + nullpo_retr(0, sd); + if (sd->hd == NULL) + return 1; + + switch(menunum) { + case 0: + break; + case 1: + merc_hom_food(sd, sd->hd); + break; + case 2: + merc_hom_delete(sd->hd, -1); + break; + default: + ShowError("merc_menu : unknown menu choice : %d\n", menunum) ; + break; + } + return 0; } -int merc_data_received(struct s_mercenary *merc, bool flag) +int merc_hom_food(struct map_session_data *sd, struct homun_data *hd) +{ + int i, foodID, emotion; + + if(hd->homunculus.vaporize) + return 1 ; + + foodID = hd->homunculusDB->foodID; + i = pc_search_inventory(sd,foodID); + if(i < 0) { + clif_hom_food(sd,foodID,0); + return 1; + } + pc_delitem(sd,i,1,0); + + if ( hd->homunculus.hunger >= 91 ) { + merc_hom_decrease_intimacy(hd, 50); + emotion = 16; + } else if ( hd->homunculus.hunger >= 76 ) { + merc_hom_decrease_intimacy(hd, 5); + emotion = 19; + } else if ( hd->homunculus.hunger >= 26 ) { + merc_hom_increase_intimacy(hd, 75); + emotion = 2; + } else if ( hd->homunculus.hunger >= 11 ) { + merc_hom_increase_intimacy(hd, 100); + emotion = 2; + } else { + merc_hom_increase_intimacy(hd, 50); + emotion = 2; + } + + hd->homunculus.hunger += 10; //dunno increase value for each food + if(hd->homunculus.hunger > 100) + hd->homunculus.hunger = 100; + + clif_emotion(&hd->bl,emotion) ; + clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); + clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); + clif_hom_food(sd,foodID,1); + + // Too much food :/ + if(hd->homunculus.intimacy == 0) + return merc_hom_delete(sd->hd, 23); //omg + + return 0; +} + +static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) { struct map_session_data *sd; - struct mercenary_data *md; - struct s_mercenary_db *db; - int i = merc_search_index(merc->class_); + struct homun_data *hd; - if( (sd = map_charid2sd(merc->char_id)) == NULL ) - return 0; - if( !flag || i < 0 ) - { // Not created - loaded - DB info - sd->status.mer_id = 0; + sd=map_id2sd(id); + if(!sd) + return 1; + + if(!sd->status.hom_id || !(hd=sd->hd)) + return 1; + + if(hd->hungry_timer != tid){ + ShowError("merc_hom_hungry_timer %d != %d\n",hd->hungry_timer,tid); return 0; } - sd->status.mer_id = merc->mercenary_id; - db = &mercenary_db[i]; + hd->hungry_timer = INVALID_TIMER; + + hd->homunculus.hunger-- ; + if(hd->homunculus.hunger <= 10) { + clif_emotion(&hd->bl, 6) ; //an + } else if(hd->homunculus.hunger == 25) { + clif_emotion(&hd->bl, 20) ; //hmm + } else if(hd->homunculus.hunger == 75) { + clif_emotion(&hd->bl, 33) ; //ok + } + + if(hd->homunculus.hunger < 0) { + hd->homunculus.hunger = 0; + // Delete the homunculus if intimacy <= 100 + if ( !merc_hom_decrease_intimacy(hd, 100) ) + return merc_hom_delete(hd, 23); //omg + clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); + } - if( !sd->md ) - { - sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data)); - md->bl.type = BL_MER; - md->bl.id = npc_get_new_npc_id(); - - md->master = sd; - md->db = db; - memcpy(&md->mercenary, merc, sizeof(struct s_mercenary)); - status_set_viewdata(&md->bl, md->mercenary.class_); - status_change_init(&md->bl); - unit_dataset(&md->bl); - md->ud.dir = sd->ud.dir; - - md->bl.m = sd->bl.m; - md->bl.x = sd->bl.x; - md->bl.y = sd->bl.y; - unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir); - md->bl.x = md->ud.to_x; - md->bl.y = md->ud.to_y; - - map_addiddb(&md->bl); - status_calc_mercenary(md,1); - md->contract_timer = INVALID_TIMER; - merc_contract_init(md); + clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); + hd->hungry_timer = add_timer(tick+hd->homunculusDB->hungryDelay,merc_hom_hungry,sd->bl.id,0); //simple Fix albator + return 0; +} + +int merc_hom_hungry_timer_delete(struct homun_data *hd) +{ + nullpo_retr(0, hd); + if(hd->hungry_timer != -1) { + delete_timer(hd->hungry_timer,merc_hom_hungry); + hd->hungry_timer = INVALID_TIMER; } - else - memcpy(&sd->md->mercenary, merc, sizeof(struct s_mercenary)); + return 1; +} - md = sd->md; - if( md && md->bl.prev == NULL && sd->bl.prev != NULL ) - { - map_addblock(&md->bl); - clif_spawn(&md->bl); - clif_mercenary_info(sd); - clif_mercenary_skillblock(sd); +int merc_hom_change_name(struct map_session_data *sd,char *name) +{ + int i; + struct homun_data *hd; + nullpo_retr(1, sd); + + hd = sd->hd; + if (!merc_is_hom_active(hd)) + return 1; + if(hd->homunculus.rename_flag && !battle_config.hom_rename) + return 1; + + for(i=0;ihd; + if (!merc_is_hom_active(hd)) return 0; + if (!flag) { + clif_displaymessage(sd->fd, msg_txt(280)); // You cannot use this name + return 0; + } + strncpy(hd->homunculus.name,name,NAME_LENGTH); + clif_charnameack (0,&hd->bl); + hd->homunculus.rename_flag = 1; + clif_hominfo(sd,hd,0); return 1; } -int read_mercenarydb(void) +int search_homunculusDB_index(int key,int type) { - FILE *fp; - char line[1024], *p; - char *str[26]; - int i, j = 0, k = 0, ele; - struct s_mercenary_db *db; - struct status_data *status; + int i; + + for(i=0;istatus.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd); + + i = search_homunculusDB_index(hom->class_,HOMUNCULUS_CLASS); + if(i < 0) { + ShowError("merc_hom_alloc: unknown class [%d] for homunculus '%s', requesting deletion.\n", hom->class_, hom->name); + sd->status.hom_id = 0; + intif_homunculus_requestdelete(hom->hom_id); + return 1; + } + sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data)); + hd->bl.type = BL_HOM; + hd->bl.id = npc_get_new_npc_id(); + + hd->master = sd; + hd->homunculusDB = &homunculus_db[i]; + memcpy(&hd->homunculus, hom, sizeof(struct s_homunculus)); + hd->exp_next = hexptbl[hd->homunculus.level - 1]; + + status_set_viewdata(&hd->bl, hd->homunculus.class_); + status_change_init(&hd->bl); + unit_dataset(&hd->bl); + hd->ud.dir = sd->ud.dir; + + // Find a random valid pos around the player + hd->bl.m = sd->bl.m; + hd->bl.x = sd->bl.x; + hd->bl.y = sd->bl.y; + x = sd->bl.x + 1; + y = sd->bl.y + 1; + map_random_dir(&hd->bl, &x, &y); + hd->bl.x = x; + hd->bl.y = y; + + map_addiddb(&hd->bl); + status_calc_homunculus(hd,1); + + hd->hungry_timer = INVALID_TIMER; + return 0; +} + +void merc_hom_init_timers(struct homun_data * hd) +{ + if (hd->hungry_timer == -1) + hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,merc_hom_hungry,hd->master->bl.id,0); + hd->regen.state.block = 0; //Restore HP/SP block. +} + +int merc_call_homunculus(struct map_session_data *sd) +{ + struct homun_data *hd; - sprintf(line, "%s/%s", db_path, "mercenary_db.txt"); - memset(mercenary_db,0,sizeof(mercenary_db)); + if (!sd->status.hom_id) //Create a new homun. + return merc_create_homunculus_request(sd, HM_CLASS_BASE + rand(0, 7)) ; - fp = fopen(line, "r"); - if( !fp ) + // If homunc not yet loaded, load it + if (!sd->hd) + return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); + + hd = sd->hd; + + if (!hd->homunculus.vaporize) + return 0; //Can't use this if homun wasn't vaporized. + + merc_hom_init_timers(hd); + hd->homunculus.vaporize = 0; + if (hd->bl.prev == NULL) + { //Spawn him + hd->bl.x = sd->bl.x; + hd->bl.y = sd->bl.y; + hd->bl.m = sd->bl.m; + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] + clif_homskillinfoblock(sd); + if (battle_config.slaves_inherit_speed&1) + status_calc_bl(&hd->bl, SCB_SPEED); + merc_save(hd); + } else + //Warp him to master. + unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,0); + return 1; +} + +// Recv homunculus data from char server +int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag) +{ + struct map_session_data *sd; + struct homun_data *hd; + + sd = map_id2sd(account_id); + if(!sd) + return 0; + if (sd->status.char_id != sh->char_id) { - ShowError("read_mercenarydb : can't read mercenary_db.txt\n"); - return -1; + if (sd->status.hom_id == sh->hom_id) + sh->char_id = sd->status.char_id; //Correct char id. + else + return 0; + } + if(!flag) { // Failed to load + sd->status.hom_id = 0; + return 0; } - while( fgets(line, sizeof(line), fp) && j < MAX_MERCENARY_CLASS ) + if (!sd->status.hom_id) //Hom just created. + sd->status.hom_id = sh->hom_id; + if (sd->hd) //uh? Overwrite the data. + memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus)); + else + merc_hom_alloc(sd, sh); + + hd = sd->hd; + if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL) { - k++; - if( line[0] == '/' && line[1] == '/' ) - continue; + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] + clif_homskillinfoblock(sd); + merc_hom_init_timers(hd); + } + return 1; +} - i = 0; - p = strtok(line, ","); - while( p != NULL && i < 26 ) - { - str[i++] = p; - p = strtok(NULL, ","); - } - if( i < 26 ) - { - ShowError("read_mercenarydb : Incorrect number of columns at mercenary_db.txt line %d.\n", k); - continue; - } +// Ask homunculus creation to char server +int merc_create_homunculus_request(struct map_session_data *sd, int class_) +{ + struct s_homunculus homun; + struct h_stats *base; + int i; + + nullpo_retr(1, sd); - db = &mercenary_db[j]; - db->class_ = atoi(str[0]); - strncpy(db->sprite, str[1], NAME_LENGTH); - strncpy(db->name, str[2], NAME_LENGTH); - db->lv = atoi(str[3]); - - status = &db->status; - db->vd.class_ = db->class_; - - status->max_hp = atoi(str[4]); - status->max_sp = atoi(str[5]); - status->rhw.range = atoi(str[6]); - status->rhw.atk = atoi(str[7]); - status->rhw.atk2 = atoi(str[8]); - status->def = atoi(str[9]); - status->mdef = atoi(str[10]); - status->str = atoi(str[11]); - status->agi = atoi(str[12]); - status->vit = atoi(str[13]); - status->int_ = atoi(str[14]); - status->dex = atoi(str[15]); - status->luk = atoi(str[16]); - db->range2 = atoi(str[17]); - db->range3 = atoi(str[18]); - status->size = atoi(str[19]); - status->race = atoi(str[20]); + i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); + if(i < 0) return 0; - ele = atoi(str[21]); - status->def_ele = ele%10; - status->ele_lv = ele/20; - if( status->def_ele >= ELE_MAX ) - { - ShowWarning("Mercenary %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1); - status->def_ele = ELE_NEUTRAL; + memset(&homun, 0, sizeof(struct s_homunculus)); + //Initial data + strncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1); + homun.class_ = class_; + homun.level = 1; + homun.hunger = 32; //32% + homun.intimacy = 2100; //21/1000 + homun.char_id = sd->status.char_id; + + homun.hp = 10 ; + base = &homunculus_db[i].base; + homun.max_hp = base->HP; + homun.max_sp = base->SP; + homun.str = base->str *10; + homun.agi = base->agi *10; + homun.vit = base->vit *10; + homun.int_= base->int_*10; + homun.dex = base->dex *10; + homun.luk = base->luk *10; + + // Request homunculus creation + intif_homunculus_create(sd->status.account_id, &homun); + return 1; +} + +int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, short x, short y) +{ + struct homun_data* hd; + nullpo_retr(0, sd); + + if (!sd->status.hom_id) + return 0; // no homunculus + + if (!sd->hd) //Load homun data; + return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); + + hd = sd->hd; + + if (hd->homunculus.vaporize) + return 0; // vaporized homunculi need to be 'called' + + if (!status_isdead(&hd->bl)) + return 0; // already alive + + merc_hom_init_timers(hd); + + if (!hd->bl.prev) + { //Add it back to the map. + hd->bl.m = sd->bl.m; + hd->bl.x = x; + hd->bl.y = y; + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + } + status_revive(&hd->bl, per, 0); + return 1; +} + +void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp) +{ + struct map_session_data *sd = hd->master; + hd->homunculus.hp = hd->battle_status.hp; + if (!sd) + return; + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); + clif_homskillinfoblock(sd); +} + +void merc_reset_stats(struct homun_data *hd) +{ //Resets a homunc stats back to zero (but doesn't touches hunger or intimacy) + struct s_homunculus_db *db; + struct s_homunculus *hom; + struct h_stats *base; + hom = &hd->homunculus; + db = hd->homunculusDB; + base = &db->base; + hom->level = 1; + hom->hp = 10; + hom->max_hp = base->HP; + hom->max_sp = base->SP; + hom->str = base->str *10; + hom->agi = base->agi *10; + hom->vit = base->vit *10; + hom->int_= base->int_*10; + hom->dex = base->dex *10; + hom->luk = base->luk *10; + hom->exp = 0; + hd->exp_next = hexptbl[0]; + memset(&hd->homunculus.hskill, 0, sizeof hd->homunculus.hskill); + hd->homunculus.skillpts = 0; +} + +int merc_hom_shuffle(struct homun_data *hd) +{ + struct map_session_data *sd; + int lv, i, skillpts; + unsigned int exp; + struct s_skill b_skill[MAX_HOMUNSKILL]; + + if (!merc_is_hom_active(hd)) + return 0; + + sd = hd->master; + lv = hd->homunculus.level; + exp = hd->homunculus.exp; + memcpy(&b_skill, &hd->homunculus.hskill, sizeof(b_skill)); + skillpts = hd->homunculus.skillpts; + //Reset values to level 1. + merc_reset_stats(hd); + //Level it back up + for (i = 1; i < lv && hd->exp_next; i++){ + hd->homunculus.exp += hd->exp_next; + merc_hom_levelup(hd); + } + + if(hd->homunculus.class_ == hd->homunculusDB->evo_class) { + //Evolved bonuses + struct s_homunculus *hom = &hd->homunculus; + struct h_stats *max = &hd->homunculusDB->emax, *min = &hd->homunculusDB->emin; + hom->max_hp += rand(min->HP, max->HP); + hom->max_sp += rand(min->SP, max->SP); + hom->str += 10*rand(min->str, max->str); + hom->agi += 10*rand(min->agi, max->agi); + hom->vit += 10*rand(min->vit, max->vit); + hom->int_+= 10*rand(min->int_,max->int_); + hom->dex += 10*rand(min->dex, max->dex); + hom->luk += 10*rand(min->luk, max->luk); + } + + hd->homunculus.exp = exp; + memcpy(&hd->homunculus.hskill, &b_skill, sizeof(b_skill)); + hd->homunculus.skillpts = skillpts; + clif_homskillinfoblock(sd); + status_calc_homunculus(hd,0); + status_percent_heal(&hd->bl, 100, 100); + clif_misceffect2(&hd->bl,568); + + return 1; +} + +int read_homunculusdb(void) +{ + FILE *fp; + char line[1024], *p; + int i, k, classid; + int j = 0; + const char *filename[]={"homunculus_db.txt","homunculus_db2.txt"}; + char *str[50]; + struct s_homunculus_db *db; + + memset(homunculus_db,0,sizeof(homunculus_db)); + for(i = 0; i<2; i++) + { + sprintf(line, "%s/%s", db_path, filename[i]); + fp = fopen(line,"r"); + if(!fp){ + if(i != 0) + continue; + ShowError("read_homunculusdb : can't read %s\n", line); + return -1; } - if( status->ele_lv < 1 || status->ele_lv > 4 ) + + while(fgets(line, sizeof(line), fp) && j < MAX_HOMUNCULUS_CLASS) { - ShowWarning("Mercenary %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv); - status->ele_lv = 1; - } + if(line[0] == '/' && line[1] == '/') + continue; - status->speed = atoi(str[22]); - status->adelay = atoi(str[23]); - status->amotion = atoi(str[24]); - status->dmotion = atoi(str[25]); + k = 0; + p = strtok (line,","); + while (p != NULL && k < 50) + { + str[k++] = p; + p = strtok (NULL, ","); + } + if (k < 50 ) + { + ShowError("read_homunculusdb : Incorrect number of columns at %s, homunculus %d. Read %d columns, 50 are needed.\n", filename[i], j+1, k); + continue; + } + + //Base Class,Evo Class + classid = atoi(str[0]); + if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) + { + ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); + continue; + } + db = &homunculus_db[j]; + db->base_class = classid; + classid = atoi(str[1]); + if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) + { + db->base_class = 0; + ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); + continue; + } + db->evo_class = classid; + //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD + strncpy(db->name,str[2],NAME_LENGTH-1); + db->foodID = atoi(str[3]); + db->hungryDelay = atoi(str[4]); + db->base_size = atoi(str[5]); + db->evo_size = atoi(str[6]); + db->race = atoi(str[7]); + db->element = atoi(str[8]); + db->baseASPD = atoi(str[9]); + //base HP, SP, str, agi, vit, int, dex, luk + db->base.HP = atoi(str[10]); + db->base.SP = atoi(str[11]); + db->base.str = atoi(str[12]); + db->base.agi = atoi(str[13]); + db->base.vit = atoi(str[14]); + db->base.int_= atoi(str[15]); + db->base.dex = atoi(str[16]); + db->base.luk = atoi(str[17]); + //Growth Min/Max HP, SP, str, agi, vit, int, dex, luk + db->gmin.HP = atoi(str[18]); + db->gmax.HP = atoi(str[19]); + db->gmin.SP = atoi(str[20]); + db->gmax.SP = atoi(str[21]); + db->gmin.str = atoi(str[22]); + db->gmax.str = atoi(str[23]); + db->gmin.agi = atoi(str[24]); + db->gmax.agi = atoi(str[25]); + db->gmin.vit = atoi(str[26]); + db->gmax.vit = atoi(str[27]); + db->gmin.int_= atoi(str[28]); + db->gmax.int_= atoi(str[29]); + db->gmin.dex = atoi(str[30]); + db->gmax.dex = atoi(str[31]); + db->gmin.luk = atoi(str[32]); + db->gmax.luk = atoi(str[33]); + //Evolution Min/Max HP, SP, str, agi, vit, int, dex, luk + db->emin.HP = atoi(str[34]); + db->emax.HP = atoi(str[35]); + db->emin.SP = atoi(str[36]); + db->emax.SP = atoi(str[37]); + db->emin.str = atoi(str[38]); + db->emax.str = atoi(str[39]); + db->emin.agi = atoi(str[40]); + db->emax.agi = atoi(str[41]); + db->emin.vit = atoi(str[42]); + db->emax.vit = atoi(str[43]); + db->emin.int_= atoi(str[44]); + db->emax.int_= atoi(str[45]); + db->emin.dex = atoi(str[46]); + db->emax.dex = atoi(str[47]); + db->emin.luk = atoi(str[48]); + db->emax.luk = atoi(str[49]); - j++; - } + //Check that the min/max values really are below the other one. + if(db->gmin.HP > db->gmax.HP) + db->gmin.HP = db->gmax.HP; + if(db->gmin.SP > db->gmax.SP) + db->gmin.SP = db->gmax.SP; + if(db->gmin.str > db->gmax.str) + db->gmin.str = db->gmax.str; + if(db->gmin.agi > db->gmax.agi) + db->gmin.agi = db->gmax.agi; + if(db->gmin.vit > db->gmax.vit) + db->gmin.vit = db->gmax.vit; + if(db->gmin.int_> db->gmax.int_) + db->gmin.int_= db->gmax.int_; + if(db->gmin.dex > db->gmax.dex) + db->gmin.dex = db->gmax.dex; + if(db->gmin.luk > db->gmax.luk) + db->gmin.luk = db->gmax.luk; - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' mercenaries in '"CL_WHITE"db/mercenary_db.txt"CL_RESET"'.\n",j); + if(db->emin.HP > db->emax.HP) + db->emin.HP = db->emax.HP; + if(db->emin.SP > db->emax.SP) + db->emin.SP = db->emax.SP; + if(db->emin.str > db->emax.str) + db->emin.str = db->emax.str; + if(db->emin.agi > db->emax.agi) + db->emin.agi = db->emax.agi; + if(db->emin.vit > db->emax.vit) + db->emin.vit = db->emax.vit; + if(db->emin.int_> db->emax.int_) + db->emin.int_= db->emax.int_; + if(db->emin.dex > db->emax.dex) + db->emin.dex = db->emax.dex; + if(db->emin.luk > db->emax.luk) + db->emin.luk = db->emax.luk; + j++; + } + if (j > MAX_HOMUNCULUS_CLASS) + ShowWarning("read_homunculusdb: Reached max number of homunculus [%d]. Remaining homunculus were not read.\n ", MAX_HOMUNCULUS_CLASS); + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' homunculus in '"CL_WHITE"db/%s"CL_RESET"'.\n",j,filename[i]); + } return 0; } -int read_mercenary_skilldb(void) +int read_homunculus_skilldb(void) { FILE *fp; char line[1024], *p; - char *str[3]; - struct s_mercenary_db *db; - int i, j = 0, k = 0, class_; - int skillid, skilllv; - - sprintf(line, "%s/%s", db_path, "mercenary_skill_db.txt"); - fp = fopen(line, "r"); - if( !fp ) - { - ShowError("read_mercenary_skilldb : can't read mercenary_skill_db.txt\n"); - return -1; + int k, classid; + int j = 0; + char *split[15]; + + memset(hskill_tree,0,sizeof(hskill_tree)); + sprintf(line, "%s/homun_skill_tree.txt", db_path); + fp=fopen(line,"r"); + if(fp==NULL){ + ShowError("can't read %s\n", line); + return 1; } - while( fgets(line, sizeof(line), fp) ) + while(fgets(line, sizeof(line), fp)) { - k++; - if( line[0] == '/' && line[1] == '/' ) + int minJobLevelPresent = 0; + + if(line[0]=='/' && line[1]=='/') continue; - i = 0; - p = strtok(line, ","); - while( p != NULL && i < 3 ) + k = 0; + p = strtok(line,","); + while (p != NULL && k < 15) { - str[i++] = p; + split[k++] = p; p = strtok(NULL, ","); } - if( i < 3 ) - { - ShowError("read_mercenary_skilldb : Incorrect number of columns at mercenary_skill_db.txt line %d.\n", k); + + if(k < 13) continue; - } - class_ = atoi(str[0]); - ARR_FIND(0, MAX_MERCENARY_CLASS, i, class_ == mercenary_db[i].class_); - if( i == MAX_MERCENARY_CLASS ) - { - ShowError("read_mercenary_skilldb : Class not found in mercenary_db for skill entry, line %d.\n", k); + if (k == 14) + minJobLevelPresent = 1; // MinJobLvl has been added + + // check for bounds [celest] + classid = atoi(split[0]) - HM_CLASS_BASE; + if ( classid >= MAX_HOMUNCULUS_CLASS ) continue; - } - - skillid = atoi(str[1]); - if( skillid < MC_SKILLBASE || skillid >= MC_SKILLBASE + MAX_MERCSKILL ) + + k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex] + // Search an empty line or a line with the same skill_id (stored in j) + for(j = 0; j < MAX_SKILL_TREE && hskill_tree[classid][j].id && hskill_tree[classid][j].id != k; j++); + + if (j == MAX_SKILL_TREE) { - ShowError("read_mercenary_skilldb : Skill out of range, line %d.\n", k); + ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid); continue; } - db = &mercenary_db[i]; - skilllv = atoi(str[2]); + hskill_tree[classid][j].id=k; + hskill_tree[classid][j].max=atoi(split[2]); + if (minJobLevelPresent) + hskill_tree[classid][j].joblv=atoi(split[3]); - i = skillid - MC_SKILLBASE; - db->skill[i].id = skillid; - db->skill[i].lv = skilllv; - j++; + for(k=0;k<5;k++){ + hskill_tree[classid][j].need[k].id=atoi(split[3+k*2+minJobLevelPresent]); + hskill_tree[classid][j].need[k].lv=atoi(split[3+k*2+minJobLevelPresent+1]); + } } fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/mercenary_skill_db.txt"CL_RESET"'.\n",j); + ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","homun_skill_tree.txt"); return 0; } -int do_init_mercenary(void) +void read_homunculus_expdb(void) { - read_mercenarydb(); - read_mercenary_skilldb(); - - //add_timer_func_list(mercenary_contract, "mercenary_contract"); + FILE *fp; + char line[1024]; + int i, j=0; + char *filename[]={"exp_homun.txt","exp_homun2.txt"}; + + memset(hexptbl,0,sizeof(hexptbl)); + for(i=0; i<2; i++){ + sprintf(line, "%s/%s", db_path, filename[i]); + fp=fopen(line,"r"); + if(fp == NULL){ + if(i != 0) + continue; + ShowError("can't read %s\n",line); + return; + } + while(fgets(line, sizeof(line), fp) && j < MAX_LEVEL) + { + if(line[0] == '/' && line[1] == '/') + continue; + + hexptbl[j] = strtoul(line, NULL, 10); + if (!hexptbl[j++]) + break; + } + if (hexptbl[MAX_LEVEL - 1]) // Last permitted level have to be 0! + { + ShowWarning("read_hexptbl: Reached max level in exp_homun [%d]. Remaining lines were not read.\n ", MAX_LEVEL); + hexptbl[MAX_LEVEL - 1] = 0; + } + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' levels in '"CL_WHITE"%s"CL_RESET"'.\n", j, filename[i]); + } +} + +void merc_reload(void) +{ + read_homunculusdb(); + read_homunculus_expdb(); +} + +void merc_skill_reload(void) +{ + read_homunculus_skilldb(); +} + +int do_init_merc(void) +{ + int class_; + read_homunculusdb(); + read_homunculus_expdb(); + read_homunculus_skilldb(); + // Add homunc timer function to timer func list [Toms] + add_timer_func_list(merc_hom_hungry, "merc_hom_hungry"); + + //Stock view data for homuncs + memset(&hom_viewdb, 0, sizeof(hom_viewdb)); + for (class_ = 0; class_ < ARRAYLENGTH(hom_viewdb); class_++) + hom_viewdb[class_].class_ = HM_CLASS_BASE+class_; return 0; } -int do_final_mercenary(void); +int do_final_merc(void); diff --git a/src/map/mercenary.h b/src/map/mercenary.h index bc2046dc7..88692b4d1 100644 --- a/src/map/mercenary.h +++ b/src/map/mercenary.h @@ -7,42 +7,84 @@ #include "status.h" // struct status_data, struct status_change #include "unit.h" // struct unit_data -struct s_mercenary_db { - int class_; - char sprite[NAME_LENGTH], name[NAME_LENGTH]; - unsigned short lv; - short range2, range3; - struct status_data status; - struct view_data vd; - struct { - unsigned short id, lv; - } skill[MAX_MERCSKILL]; +struct h_stats { + unsigned int HP, SP; + unsigned short str, agi, vit, int_, dex, luk; +}; + +struct s_homunculus_db { + int base_class, evo_class; + char name[NAME_LENGTH]; + struct h_stats base, gmin, gmax, emin, emax; + int foodID ; + int baseASPD ; + long hungryDelay ; + unsigned char element, race, base_size, evo_size; +}; + +extern struct s_homunculus_db homuncumlus_db[MAX_HOMUNCULUS_CLASS]; +enum { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD }; +enum { + SP_ACK = 0x00, + SP_INTIMATE = 0x100, + SP_HUNGRY = 0x200 }; -extern struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS]; -struct mercenary_data { +struct homun_data { struct block_list bl; - struct unit_data ud; + struct unit_data ud; struct view_data *vd; struct status_data base_status, battle_status; struct status_change sc; struct regen_data regen; + struct s_homunculus_db *homunculusDB; //[orn] + struct s_homunculus homunculus ; //[orn] - struct s_mercenary_db *db; - struct s_mercenary mercenary; - - struct map_session_data *master; - int contract_timer; + struct map_session_data *master; //pointer back to its master + int hungry_timer; //[orn] + unsigned int exp_next; + char blockskill[MAX_SKILL]; // [orn] }; -bool merc_class(int class_); -struct view_data * merc_get_viewdata(int class_); -int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime); -int merc_data_received(struct s_mercenary *merc, bool flag); -int mercenary_save(struct mercenary_data *md); -int do_init_mercenary(void); -int merc_delete(struct mercenary_data *md, int reply); -void merc_contract_stop(struct mercenary_data *md); + +#define homdb_checkid(id) (id >= HM_CLASS_BASE && id <= HM_CLASS_MAX) + +// merc_is_hom_alive(struct homun_data *) +#define merc_is_hom_active(x) (x && x->homunculus.vaporize != 1 && x->battle_status.hp > 0) +int do_init_merc(void); +int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag); //albator +struct view_data* merc_get_hom_viewdata(int class_); +void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp); +int merc_hom_dead(struct homun_data *hd, struct block_list *src); +void merc_hom_skillup(struct homun_data *hd,int skillnum); +int merc_hom_calc_skilltree(struct homun_data *hd) ; +int merc_hom_checkskill(struct homun_data *hd,int skill_id) ; +int merc_hom_gainexp(struct homun_data *hd,int exp) ; +int merc_hom_levelup(struct homun_data *hd) ; +int merc_hom_evolution(struct homun_data *hd) ; +void merc_hom_heal(struct homun_data *hd,int hp,int sp); +int merc_hom_vaporize(struct map_session_data *sd, int flag); +int merc_resurrect_homunculus(struct map_session_data *sd, unsigned char per, short x, short y); +void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp); +void merc_reset_stats(struct homun_data *hd); +int merc_hom_shuffle(struct homun_data *hd); // [Zephyrus] +void merc_save(struct homun_data *hd); +int merc_call_homunculus(struct map_session_data *sd); +int merc_create_homunculus_request(struct map_session_data *sd, int class_); +int search_homunculusDB_index(int key,int type); +int merc_menu(struct map_session_data *sd,int menunum); +int merc_hom_food(struct map_session_data *sd, struct homun_data *hd); +int merc_hom_hungry_timer_delete(struct homun_data *hd); +int merc_hom_change_name(struct map_session_data *sd,char *name); +int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag); +#define merc_stop_walking(hd, type) unit_stop_walking(&(hd)->bl, type) +#define merc_stop_attack(hd) unit_stop_attack(&(hd)->bl) +int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value); +int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value); +int merc_skill_tree_get_max(int id, int b_class); +void merc_hom_init_timers(struct homun_data * hd); +void merc_skill_reload(void); +void merc_reload(void); #endif /* _MERCENARY_H_ */ -- cgit v1.2.3-70-g09d2 From bc8bfb195d56fb9b2b41ff729f5110ea4b4a4af6 Mon Sep 17 00:00:00 2001 From: ultramage Date: Tue, 26 Aug 2008 05:03:19 +0000 Subject: Renamed files of 'mercenary' to 'homunculus'. Applied relevant changes that were reverted (relevant = not unneccessary whitespace changes). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13136 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/homunculus.c | 1166 +++++++++++++++++++++++++++++++++++++++++++++++++ src/map/homunculus.h | 89 ++++ src/map/mercenary.c | 1168 -------------------------------------------------- src/map/mercenary.h | 90 ---- 4 files changed, 1255 insertions(+), 1258 deletions(-) create mode 100644 src/map/homunculus.c create mode 100644 src/map/homunculus.h delete mode 100644 src/map/mercenary.c delete mode 100644 src/map/mercenary.h (limited to 'src/map/homunculus.c') diff --git a/src/map/homunculus.c b/src/map/homunculus.c new file mode 100644 index 000000000..02177552e --- /dev/null +++ b/src/map/homunculus.c @@ -0,0 +1,1166 @@ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder + +#include "../common/cbasetypes.h" +#include "../common/malloc.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/nullpo.h" +#include "../common/mmo.h" +#include "../common/showmsg.h" +#include "../common/utils.h" + +#include "log.h" +#include "clif.h" +#include "chrif.h" +#include "intif.h" +#include "itemdb.h" +#include "map.h" +#include "pc.h" +#include "status.h" +#include "skill.h" +#include "mob.h" +#include "pet.h" +#include "battle.h" +#include "party.h" +#include "guild.h" +#include "atcommand.h" +#include "script.h" +#include "npc.h" +#include "trade.h" +#include "unit.h" + +#include "homunculus.h" + +#include +#include +#include +#include + + +//Better equiprobability than rand()% [orn] +#define rand(a, b) (a+(int) ((float)(b-a+1)*rand()/(RAND_MAX+1.0))) + +struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS]; //[orn] +struct skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_SKILL_TREE]; + +static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data); + +static unsigned int hexptbl[MAX_LEVEL]; + +//For holding the view data of npc classes. [Skotlex] +static struct view_data hom_viewdb[MAX_HOMUNCULUS_CLASS]; + +struct view_data* merc_get_hom_viewdata(int class_) +{ //Returns the viewdata for homunculus + if (homdb_checkid(class_)) + return &hom_viewdb[class_-HM_CLASS_BASE]; + return NULL; +} + +void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp) +{ + clif_hominfo(hd->master,hd,0); +} + +int merc_hom_dead(struct homun_data *hd, struct block_list *src) +{ + //There's no intimacy penalties on death (from Tharis) + struct map_session_data *sd = hd->master; + + clif_emotion(&hd->bl, 16) ; //wah + + //Delete timers when dead. + merc_hom_hungry_timer_delete(hd); + hd->homunculus.hp = 0; + + if (!sd) //unit remove map will invoke unit free + return 3; + + clif_emotion(&sd->bl, 28) ; //sob + //Remove from map (if it has no intimacy, it is auto-removed from memory) + return 3; +} + +//Vaporize a character's homun. If flag, HP needs to be 80% or above. +int merc_hom_vaporize(struct map_session_data *sd, int flag) +{ + struct homun_data *hd; + + nullpo_retr(0, sd); + + hd = sd->hd; + if (!hd || hd->homunculus.vaporize) + return 0; + + if (status_isdead(&hd->bl)) + return 0; //Can't vaporize a dead homun. + + if (flag && get_percentage(hd->battle_status.hp, hd->battle_status.max_hp) < 80) + return 0; + + hd->regen.state.block = 3; //Block regen while vaporized. + //Delete timers when vaporized. + merc_hom_hungry_timer_delete(hd); + hd->homunculus.vaporize = 1; + if(battle_config.hom_setting&0x40) + memset(hd->blockskill, 0, sizeof(hd->blockskill)); + clif_hominfo(sd, sd->hd, 0); + merc_save(hd); + return unit_remove_map(&hd->bl, 0); +} + +//delete a homunculus, completely "killing it". +//Emote is the emotion the master should use, send negative to disable. +int merc_hom_delete(struct homun_data *hd, int emote) +{ + struct map_session_data *sd; + nullpo_retr(0, hd); + sd = hd->master; + + if (!sd) + return unit_free(&hd->bl,1); + + if (emote >= 0) + clif_emotion(&sd->bl, emote); + + //This makes it be deleted right away. + hd->homunculus.intimacy = 0; + // Send homunculus_dead to client + hd->homunculus.hp = 0; + clif_hominfo(sd, hd, 0); + return unit_remove_map(&hd->bl,0); +} + +int merc_hom_calc_skilltree(struct homun_data *hd) +{ + int i,id=0 ; + int j,f=1; + int c=0; + + nullpo_retr(0, hd); + c = hd->homunculus.class_ - HM_CLASS_BASE; + + for(i=0;i < MAX_SKILL_TREE && (id = hskill_tree[c][i].id) > 0;i++) + { + if(hd->homunculus.hskill[id-HM_SKILLBASE].id) + continue; //Skill already known. + if(!battle_config.skillfree) + { + for(j=0;j<5;j++) + { + if( hskill_tree[c][i].need[j].id && + merc_hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv) + { + f=0; + break; + } + } + } + if (f) + hd->homunculus.hskill[id-HM_SKILLBASE].id = id ; + } + return 0; +} + +int merc_hom_checkskill(struct homun_data *hd,int skill_id) +{ + int i = skill_id - HM_SKILLBASE; + if(!hd) + return 0; + + if(hd->homunculus.hskill[i].id == skill_id) + return (hd->homunculus.hskill[i].lv); + + return 0; +} + +int merc_skill_tree_get_max(int id, int b_class){ + int i, skillid; + b_class -= HM_CLASS_BASE; + for(i=0;(skillid=hskill_tree[b_class][i].id)>0;i++) + if (id == skillid) + return hskill_tree[b_class][i].max; + return skill_get_max(id); +} + +void merc_hom_skillup(struct homun_data *hd,int skillnum) +{ + int i = 0 ; + nullpo_retv(hd); + + if(hd->homunculus.vaporize) + return; + + i = skillnum - HM_SKILLBASE; + if(hd->homunculus.skillpts > 0 && + hd->homunculus.hskill[i].id && + hd->homunculus.hskill[i].flag == 0 && //Don't allow raising while you have granted skills. [Skotlex] + hd->homunculus.hskill[i].lv < merc_skill_tree_get_max(skillnum, hd->homunculus.class_) + ) + { + hd->homunculus.hskill[i].lv++; + hd->homunculus.skillpts-- ; + status_calc_homunculus(hd,0); + if (hd->master) { + clif_homskillup(hd->master, skillnum); + clif_hominfo(hd->master,hd,0); + clif_homskillinfoblock(hd->master); + } + } +} + +int merc_hom_levelup(struct homun_data *hd) +{ + struct s_homunculus *hom; + struct h_stats *min, *max; + int growth_str, growth_agi, growth_vit, growth_int, growth_dex, growth_luk ; + int growth_max_hp, growth_max_sp ; + char output[256] ; + + if (hd->homunculus.level == MAX_LEVEL || !hd->exp_next || hd->homunculus.exp < hd->exp_next) + return 0 ; + + hom = &hd->homunculus; + hom->level++ ; + if (!(hom->level % 3)) + hom->skillpts++ ; //1 skillpoint each 3 base level + + hom->exp -= hd->exp_next ; + hd->exp_next = hexptbl[hom->level - 1] ; + + max = &hd->homunculusDB->gmax; + min = &hd->homunculusDB->gmin; + + growth_max_hp = rand(min->HP, max->HP); + growth_max_sp = rand(min->SP, max->SP); + growth_str = rand(min->str, max->str); + growth_agi = rand(min->agi, max->agi); + growth_vit = rand(min->vit, max->vit); + growth_dex = rand(min->dex, max->dex); + growth_int = rand(min->int_,max->int_); + growth_luk = rand(min->luk, max->luk); + + //Aegis discards the decimals in the stat growth values! + growth_str-=growth_str%10; + growth_agi-=growth_agi%10; + growth_vit-=growth_vit%10; + growth_dex-=growth_dex%10; + growth_int-=growth_int%10; + growth_luk-=growth_luk%10; + + hom->max_hp += growth_max_hp; + hom->max_sp += growth_max_sp; + hom->str += growth_str; + hom->agi += growth_agi; + hom->vit += growth_vit; + hom->dex += growth_dex; + hom->int_+= growth_int; + hom->luk += growth_luk; + + if ( battle_config.homunculus_show_growth ) { + sprintf(output, + "Growth: hp:%d sp:%d str(%.2f) agi(%.2f) vit(%.2f) int(%.2f) dex(%.2f) luk(%.2f) ", + growth_max_hp, growth_max_sp, + growth_str/10.0, growth_agi/10.0, growth_vit/10.0, + growth_int/10.0, growth_dex/10.0, growth_luk/10.0); + clif_disp_onlyself(hd->master,output,strlen(output)); + } + return 1 ; +} + +int merc_hom_change_class(struct homun_data *hd, short class_) +{ + int i; + i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); + if(i < 0) + return 0; + hd->homunculusDB = &homunculus_db[i]; + hd->homunculus.class_ = class_; + status_set_viewdata(&hd->bl, class_); + merc_hom_calc_skilltree(hd); + return 1; +} + +int merc_hom_evolution(struct homun_data *hd) +{ + struct s_homunculus *hom; + struct h_stats *max, *min; + struct map_session_data *sd; + nullpo_retr(0, hd); + + if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class) + { + clif_emotion(&hd->bl, 4) ; //swt + return 0 ; + } + sd = hd->master; + if (!sd) + return 0; + + if (!merc_hom_change_class(hd, hd->homunculusDB->evo_class)) { + ShowError("merc_hom_evolution: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class); + return 0; + } + + //Apply evolution bonuses + hom = &hd->homunculus; + max = &hd->homunculusDB->emax; + min = &hd->homunculusDB->emin; + hom->max_hp += rand(min->HP, max->HP); + hom->max_sp += rand(min->SP, max->SP); + hom->str += 10*rand(min->str, max->str); + hom->agi += 10*rand(min->agi, max->agi); + hom->vit += 10*rand(min->vit, max->vit); + hom->int_+= 10*rand(min->int_,max->int_); + hom->dex += 10*rand(min->dex, max->dex); + hom->luk += 10*rand(min->luk, max->luk); + hom->intimacy = 500; + + unit_remove_map(&hd->bl, 0); + map_addblock(&hd->bl); + + clif_spawn(&hd->bl); + clif_emotion(&sd->bl, 21); //no1 + clif_misceffect2(&hd->bl,568); + + //status_Calc flag&1 will make current HP/SP be reloaded from hom structure + hom->hp = hd->battle_status.hp; + hom->sp = hd->battle_status.sp; + status_calc_homunculus(hd,1); + + if (!(battle_config.hom_setting&0x2)) + skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately + + return 1 ; +} + +int merc_hom_gainexp(struct homun_data *hd,int exp) +{ + if(hd->homunculus.vaporize) + return 1; + + if( hd->exp_next == 0 ) { + hd->homunculus.exp = 0 ; + return 0; + } + + hd->homunculus.exp += exp; + + if(hd->homunculus.exp < hd->exp_next) { + clif_hominfo(hd->master,hd,0); + return 0; + } + + //levelup + do + { + merc_hom_levelup(hd) ; + } + while(hd->homunculus.exp > hd->exp_next && hd->exp_next != 0 ); + + if( hd->exp_next == 0 ) + hd->homunculus.exp = 0 ; + + clif_misceffect2(&hd->bl,568); + status_calc_homunculus(hd,0); + status_percent_heal(&hd->bl, 100, 100); + return 0; +} + +// Return the new value +int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value) +{ + if (battle_config.homunculus_friendly_rate != 100) + value = (value * battle_config.homunculus_friendly_rate) / 100; + + if (hd->homunculus.intimacy + value <= 100000) + hd->homunculus.intimacy += value; + else + hd->homunculus.intimacy = 100000; + return hd->homunculus.intimacy; +} + +// Return 0 if decrease fails or intimacy became 0 else the new value +int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value) +{ + if (hd->homunculus.intimacy >= value) + hd->homunculus.intimacy -= value; + else + hd->homunculus.intimacy = 0; + + return hd->homunculus.intimacy; +} + +void merc_hom_heal(struct homun_data *hd,int hp,int sp) +{ + clif_hominfo(hd->master,hd,0); +} + +void merc_save(struct homun_data *hd) +{ + // copy data that must be saved in homunculus struct ( hp / sp ) + TBL_PC * sd = hd->master; + //Do not check for max_hp/max_sp caps as current could be higher to max due + //to status changes/skills (they will be capped as needed upon stat + //calculation on login) + hd->homunculus.hp = hd->battle_status.hp; + hd->homunculus.sp = hd->battle_status.sp; + intif_homunculus_requestsave(sd->status.account_id, &hd->homunculus); +} + +int merc_menu(struct map_session_data *sd,int menunum) +{ + nullpo_retr(0, sd); + if (sd->hd == NULL) + return 1; + + switch(menunum) { + case 0: + break; + case 1: + merc_hom_food(sd, sd->hd); + break; + case 2: + merc_hom_delete(sd->hd, -1); + break; + default: + ShowError("merc_menu : unknown menu choice : %d\n", menunum) ; + break; + } + return 0; +} + +int merc_hom_food(struct map_session_data *sd, struct homun_data *hd) +{ + int i, foodID, emotion; + + if(hd->homunculus.vaporize) + return 1 ; + + foodID = hd->homunculusDB->foodID; + i = pc_search_inventory(sd,foodID); + if(i < 0) { + clif_hom_food(sd,foodID,0); + return 1; + } + pc_delitem(sd,i,1,0); + + if ( hd->homunculus.hunger >= 91 ) { + merc_hom_decrease_intimacy(hd, 50); + emotion = 16; + } else if ( hd->homunculus.hunger >= 76 ) { + merc_hom_decrease_intimacy(hd, 5); + emotion = 19; + } else if ( hd->homunculus.hunger >= 26 ) { + merc_hom_increase_intimacy(hd, 75); + emotion = 2; + } else if ( hd->homunculus.hunger >= 11 ) { + merc_hom_increase_intimacy(hd, 100); + emotion = 2; + } else { + merc_hom_increase_intimacy(hd, 50); + emotion = 2; + } + + hd->homunculus.hunger += 10; //dunno increase value for each food + if(hd->homunculus.hunger > 100) + hd->homunculus.hunger = 100; + + clif_emotion(&hd->bl,emotion) ; + clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); + clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); + clif_hom_food(sd,foodID,1); + + // Too much food :/ + if(hd->homunculus.intimacy == 0) + return merc_hom_delete(sd->hd, 23); //omg + + return 0; +} + +static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) +{ + struct map_session_data *sd; + struct homun_data *hd; + + sd=map_id2sd(id); + if(!sd) + return 1; + + if(!sd->status.hom_id || !(hd=sd->hd)) + return 1; + + if(hd->hungry_timer != tid){ + ShowError("merc_hom_hungry_timer %d != %d\n",hd->hungry_timer,tid); + return 0; + } + + hd->hungry_timer = INVALID_TIMER; + + hd->homunculus.hunger-- ; + if(hd->homunculus.hunger <= 10) { + clif_emotion(&hd->bl, 6) ; //an + } else if(hd->homunculus.hunger == 25) { + clif_emotion(&hd->bl, 20) ; //hmm + } else if(hd->homunculus.hunger == 75) { + clif_emotion(&hd->bl, 33) ; //ok + } + + if(hd->homunculus.hunger < 0) { + hd->homunculus.hunger = 0; + // Delete the homunculus if intimacy <= 100 + if ( !merc_hom_decrease_intimacy(hd, 100) ) + return merc_hom_delete(hd, 23); //omg + clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); + } + + clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); + hd->hungry_timer = add_timer(tick+hd->homunculusDB->hungryDelay,merc_hom_hungry,sd->bl.id,0); //simple Fix albator + return 0; +} + +int merc_hom_hungry_timer_delete(struct homun_data *hd) +{ + nullpo_retr(0, hd); + if(hd->hungry_timer != -1) { + delete_timer(hd->hungry_timer,merc_hom_hungry); + hd->hungry_timer = INVALID_TIMER; + } + return 1; +} + +int merc_hom_change_name(struct map_session_data *sd,char *name) +{ + int i; + struct homun_data *hd; + nullpo_retr(1, sd); + + hd = sd->hd; + if (!merc_is_hom_active(hd)) + return 1; + if(hd->homunculus.rename_flag && !battle_config.hom_rename) + return 1; + + for(i=0;ihd; + if (!merc_is_hom_active(hd)) return 0; + if (!flag) { + clif_displaymessage(sd->fd, msg_txt(280)); // You cannot use this name + return 0; + } + strncpy(hd->homunculus.name,name,NAME_LENGTH); + clif_charnameack (0,&hd->bl); + hd->homunculus.rename_flag = 1; + clif_hominfo(sd,hd,0); + return 1; +} + +int search_homunculusDB_index(int key,int type) +{ + int i; + + for(i=0;istatus.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd); + + i = search_homunculusDB_index(hom->class_,HOMUNCULUS_CLASS); + if(i < 0) { + ShowError("merc_hom_alloc: unknown class [%d] for homunculus '%s', requesting deletion.\n", hom->class_, hom->name); + sd->status.hom_id = 0; + intif_homunculus_requestdelete(hom->hom_id); + return 1; + } + sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data)); + hd->bl.type = BL_HOM; + hd->bl.id = npc_get_new_npc_id(); + + hd->master = sd; + hd->homunculusDB = &homunculus_db[i]; + memcpy(&hd->homunculus, hom, sizeof(struct s_homunculus)); + hd->exp_next = hexptbl[hd->homunculus.level - 1]; + + status_set_viewdata(&hd->bl, hd->homunculus.class_); + status_change_init(&hd->bl); + unit_dataset(&hd->bl); + hd->ud.dir = sd->ud.dir; + + // Find a random valid pos around the player + hd->bl.m = sd->bl.m; + hd->bl.x = sd->bl.x; + hd->bl.y = sd->bl.y; + unit_calc_pos(&hd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); + hd->bl.x = hd->ud.to_x; + hd->bl.y = hd->ud.to_y; + + map_addiddb(&hd->bl); + status_calc_homunculus(hd,1); + + hd->hungry_timer = INVALID_TIMER; + return 0; +} + +void merc_hom_init_timers(struct homun_data * hd) +{ + if (hd->hungry_timer == -1) + hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,merc_hom_hungry,hd->master->bl.id,0); + hd->regen.state.block = 0; //Restore HP/SP block. +} + +int merc_call_homunculus(struct map_session_data *sd) +{ + struct homun_data *hd; + + if (!sd->status.hom_id) //Create a new homun. + return merc_create_homunculus_request(sd, HM_CLASS_BASE + rand(0, 7)) ; + + // If homunc not yet loaded, load it + if (!sd->hd) + return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); + + hd = sd->hd; + + if (!hd->homunculus.vaporize) + return 0; //Can't use this if homun wasn't vaporized. + + merc_hom_init_timers(hd); + hd->homunculus.vaporize = 0; + if (hd->bl.prev == NULL) + { //Spawn him + hd->bl.x = sd->bl.x; + hd->bl.y = sd->bl.y; + hd->bl.m = sd->bl.m; + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] + clif_homskillinfoblock(sd); + if (battle_config.slaves_inherit_speed&1) + status_calc_bl(&hd->bl, SCB_SPEED); + merc_save(hd); + } else + //Warp him to master. + unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,0); + return 1; +} + +// Recv homunculus data from char server +int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag) +{ + struct map_session_data *sd; + struct homun_data *hd; + + sd = map_id2sd(account_id); + if(!sd) + return 0; + if (sd->status.char_id != sh->char_id) + { + if (sd->status.hom_id == sh->hom_id) + sh->char_id = sd->status.char_id; //Correct char id. + else + return 0; + } + if(!flag) { // Failed to load + sd->status.hom_id = 0; + return 0; + } + + if (!sd->status.hom_id) //Hom just created. + sd->status.hom_id = sh->hom_id; + if (sd->hd) //uh? Overwrite the data. + memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus)); + else + merc_hom_alloc(sd, sh); + + hd = sd->hd; + if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL) + { + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] + clif_homskillinfoblock(sd); + merc_hom_init_timers(hd); + } + return 1; +} + +// Ask homunculus creation to char server +int merc_create_homunculus_request(struct map_session_data *sd, int class_) +{ + struct s_homunculus homun; + struct h_stats *base; + int i; + + nullpo_retr(1, sd); + + i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); + if(i < 0) return 0; + + memset(&homun, 0, sizeof(struct s_homunculus)); + //Initial data + strncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1); + homun.class_ = class_; + homun.level = 1; + homun.hunger = 32; //32% + homun.intimacy = 2100; //21/1000 + homun.char_id = sd->status.char_id; + + homun.hp = 10 ; + base = &homunculus_db[i].base; + homun.max_hp = base->HP; + homun.max_sp = base->SP; + homun.str = base->str *10; + homun.agi = base->agi *10; + homun.vit = base->vit *10; + homun.int_= base->int_*10; + homun.dex = base->dex *10; + homun.luk = base->luk *10; + + // Request homunculus creation + intif_homunculus_create(sd->status.account_id, &homun); + return 1; +} + +int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, short x, short y) +{ + struct homun_data* hd; + nullpo_retr(0, sd); + + if (!sd->status.hom_id) + return 0; // no homunculus + + if (!sd->hd) //Load homun data; + return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); + + hd = sd->hd; + + if (hd->homunculus.vaporize) + return 0; // vaporized homunculi need to be 'called' + + if (!status_isdead(&hd->bl)) + return 0; // already alive + + merc_hom_init_timers(hd); + + if (!hd->bl.prev) + { //Add it back to the map. + hd->bl.m = sd->bl.m; + hd->bl.x = x; + hd->bl.y = y; + map_addblock(&hd->bl); + clif_spawn(&hd->bl); + } + status_revive(&hd->bl, per, 0); + return 1; +} + +void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp) +{ + struct map_session_data *sd = hd->master; + hd->homunculus.hp = hd->battle_status.hp; + if (!sd) + return; + clif_send_homdata(sd,SP_ACK,0); + clif_hominfo(sd,hd,1); + clif_hominfo(sd,hd,0); + clif_homskillinfoblock(sd); +} + +void merc_reset_stats(struct homun_data *hd) +{ //Resets a homunc stats back to zero (but doesn't touches hunger or intimacy) + struct s_homunculus_db *db; + struct s_homunculus *hom; + struct h_stats *base; + hom = &hd->homunculus; + db = hd->homunculusDB; + base = &db->base; + hom->level = 1; + hom->hp = 10; + hom->max_hp = base->HP; + hom->max_sp = base->SP; + hom->str = base->str *10; + hom->agi = base->agi *10; + hom->vit = base->vit *10; + hom->int_= base->int_*10; + hom->dex = base->dex *10; + hom->luk = base->luk *10; + hom->exp = 0; + hd->exp_next = hexptbl[0]; + memset(&hd->homunculus.hskill, 0, sizeof hd->homunculus.hskill); + hd->homunculus.skillpts = 0; +} + +int merc_hom_shuffle(struct homun_data *hd) +{ + struct map_session_data *sd; + int lv, i, skillpts; + unsigned int exp; + struct s_skill b_skill[MAX_HOMUNSKILL]; + + if (!merc_is_hom_active(hd)) + return 0; + + sd = hd->master; + lv = hd->homunculus.level; + exp = hd->homunculus.exp; + memcpy(&b_skill, &hd->homunculus.hskill, sizeof(b_skill)); + skillpts = hd->homunculus.skillpts; + //Reset values to level 1. + merc_reset_stats(hd); + //Level it back up + for (i = 1; i < lv && hd->exp_next; i++){ + hd->homunculus.exp += hd->exp_next; + merc_hom_levelup(hd); + } + + if(hd->homunculus.class_ == hd->homunculusDB->evo_class) { + //Evolved bonuses + struct s_homunculus *hom = &hd->homunculus; + struct h_stats *max = &hd->homunculusDB->emax, *min = &hd->homunculusDB->emin; + hom->max_hp += rand(min->HP, max->HP); + hom->max_sp += rand(min->SP, max->SP); + hom->str += 10*rand(min->str, max->str); + hom->agi += 10*rand(min->agi, max->agi); + hom->vit += 10*rand(min->vit, max->vit); + hom->int_+= 10*rand(min->int_,max->int_); + hom->dex += 10*rand(min->dex, max->dex); + hom->luk += 10*rand(min->luk, max->luk); + } + + hd->homunculus.exp = exp; + memcpy(&hd->homunculus.hskill, &b_skill, sizeof(b_skill)); + hd->homunculus.skillpts = skillpts; + clif_homskillinfoblock(sd); + status_calc_homunculus(hd,0); + status_percent_heal(&hd->bl, 100, 100); + clif_misceffect2(&hd->bl,568); + + return 1; +} + +int read_homunculusdb(void) +{ + FILE *fp; + char line[1024], *p; + int i, k, classid; + int j = 0; + const char *filename[]={"homunculus_db.txt","homunculus_db2.txt"}; + char *str[50]; + struct s_homunculus_db *db; + + memset(homunculus_db,0,sizeof(homunculus_db)); + for(i = 0; i<2; i++) + { + sprintf(line, "%s/%s", db_path, filename[i]); + fp = fopen(line,"r"); + if(!fp){ + if(i != 0) + continue; + ShowError("read_homunculusdb : can't read %s\n", line); + return -1; + } + + while(fgets(line, sizeof(line), fp) && j < MAX_HOMUNCULUS_CLASS) + { + if(line[0] == '/' && line[1] == '/') + continue; + + k = 0; + p = strtok (line,","); + while (p != NULL && k < 50) + { + str[k++] = p; + p = strtok (NULL, ","); + } + if (k < 50 ) + { + ShowError("read_homunculusdb : Incorrect number of columns at %s, homunculus %d. Read %d columns, 50 are needed.\n", filename[i], j+1, k); + continue; + } + + //Base Class,Evo Class + classid = atoi(str[0]); + if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) + { + ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); + continue; + } + db = &homunculus_db[j]; + db->base_class = classid; + classid = atoi(str[1]); + if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) + { + db->base_class = 0; + ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); + continue; + } + db->evo_class = classid; + //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD + strncpy(db->name,str[2],NAME_LENGTH-1); + db->foodID = atoi(str[3]); + db->hungryDelay = atoi(str[4]); + db->base_size = atoi(str[5]); + db->evo_size = atoi(str[6]); + db->race = atoi(str[7]); + db->element = atoi(str[8]); + db->baseASPD = atoi(str[9]); + //base HP, SP, str, agi, vit, int, dex, luk + db->base.HP = atoi(str[10]); + db->base.SP = atoi(str[11]); + db->base.str = atoi(str[12]); + db->base.agi = atoi(str[13]); + db->base.vit = atoi(str[14]); + db->base.int_= atoi(str[15]); + db->base.dex = atoi(str[16]); + db->base.luk = atoi(str[17]); + //Growth Min/Max HP, SP, str, agi, vit, int, dex, luk + db->gmin.HP = atoi(str[18]); + db->gmax.HP = atoi(str[19]); + db->gmin.SP = atoi(str[20]); + db->gmax.SP = atoi(str[21]); + db->gmin.str = atoi(str[22]); + db->gmax.str = atoi(str[23]); + db->gmin.agi = atoi(str[24]); + db->gmax.agi = atoi(str[25]); + db->gmin.vit = atoi(str[26]); + db->gmax.vit = atoi(str[27]); + db->gmin.int_= atoi(str[28]); + db->gmax.int_= atoi(str[29]); + db->gmin.dex = atoi(str[30]); + db->gmax.dex = atoi(str[31]); + db->gmin.luk = atoi(str[32]); + db->gmax.luk = atoi(str[33]); + //Evolution Min/Max HP, SP, str, agi, vit, int, dex, luk + db->emin.HP = atoi(str[34]); + db->emax.HP = atoi(str[35]); + db->emin.SP = atoi(str[36]); + db->emax.SP = atoi(str[37]); + db->emin.str = atoi(str[38]); + db->emax.str = atoi(str[39]); + db->emin.agi = atoi(str[40]); + db->emax.agi = atoi(str[41]); + db->emin.vit = atoi(str[42]); + db->emax.vit = atoi(str[43]); + db->emin.int_= atoi(str[44]); + db->emax.int_= atoi(str[45]); + db->emin.dex = atoi(str[46]); + db->emax.dex = atoi(str[47]); + db->emin.luk = atoi(str[48]); + db->emax.luk = atoi(str[49]); + + //Check that the min/max values really are below the other one. + if(db->gmin.HP > db->gmax.HP) + db->gmin.HP = db->gmax.HP; + if(db->gmin.SP > db->gmax.SP) + db->gmin.SP = db->gmax.SP; + if(db->gmin.str > db->gmax.str) + db->gmin.str = db->gmax.str; + if(db->gmin.agi > db->gmax.agi) + db->gmin.agi = db->gmax.agi; + if(db->gmin.vit > db->gmax.vit) + db->gmin.vit = db->gmax.vit; + if(db->gmin.int_> db->gmax.int_) + db->gmin.int_= db->gmax.int_; + if(db->gmin.dex > db->gmax.dex) + db->gmin.dex = db->gmax.dex; + if(db->gmin.luk > db->gmax.luk) + db->gmin.luk = db->gmax.luk; + + if(db->emin.HP > db->emax.HP) + db->emin.HP = db->emax.HP; + if(db->emin.SP > db->emax.SP) + db->emin.SP = db->emax.SP; + if(db->emin.str > db->emax.str) + db->emin.str = db->emax.str; + if(db->emin.agi > db->emax.agi) + db->emin.agi = db->emax.agi; + if(db->emin.vit > db->emax.vit) + db->emin.vit = db->emax.vit; + if(db->emin.int_> db->emax.int_) + db->emin.int_= db->emax.int_; + if(db->emin.dex > db->emax.dex) + db->emin.dex = db->emax.dex; + if(db->emin.luk > db->emax.luk) + db->emin.luk = db->emax.luk; + + j++; + } + if (j > MAX_HOMUNCULUS_CLASS) + ShowWarning("read_homunculusdb: Reached max number of homunculus [%d]. Remaining homunculus were not read.\n ", MAX_HOMUNCULUS_CLASS); + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' homunculus in '"CL_WHITE"db/%s"CL_RESET"'.\n",j,filename[i]); + } + return 0; +} + +int read_homunculus_skilldb(void) +{ + FILE *fp; + char line[1024], *p; + int k, classid; + int j = 0; + char *split[15]; + + memset(hskill_tree,0,sizeof(hskill_tree)); + sprintf(line, "%s/homun_skill_tree.txt", db_path); + fp=fopen(line,"r"); + if(fp==NULL){ + ShowError("can't read %s\n", line); + return 1; + } + + while(fgets(line, sizeof(line), fp)) + { + int minJobLevelPresent = 0; + + if(line[0]=='/' && line[1]=='/') + continue; + + k = 0; + p = strtok(line,","); + while (p != NULL && k < 15) + { + split[k++] = p; + p = strtok(NULL, ","); + } + + if(k < 13) + continue; + + if (k == 14) + minJobLevelPresent = 1; // MinJobLvl has been added + + // check for bounds [celest] + classid = atoi(split[0]) - HM_CLASS_BASE; + if ( classid >= MAX_HOMUNCULUS_CLASS ) + continue; + + k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex] + // Search an empty line or a line with the same skill_id (stored in j) + for(j = 0; j < MAX_SKILL_TREE && hskill_tree[classid][j].id && hskill_tree[classid][j].id != k; j++); + + if (j == MAX_SKILL_TREE) + { + ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid); + continue; + } + + hskill_tree[classid][j].id=k; + hskill_tree[classid][j].max=atoi(split[2]); + if (minJobLevelPresent) + hskill_tree[classid][j].joblv=atoi(split[3]); + + for(k=0;k<5;k++){ + hskill_tree[classid][j].need[k].id=atoi(split[3+k*2+minJobLevelPresent]); + hskill_tree[classid][j].need[k].lv=atoi(split[3+k*2+minJobLevelPresent+1]); + } + } + + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","homun_skill_tree.txt"); + return 0; +} + +void read_homunculus_expdb(void) +{ + FILE *fp; + char line[1024]; + int i, j=0; + char *filename[]={"exp_homun.txt","exp_homun2.txt"}; + + memset(hexptbl,0,sizeof(hexptbl)); + for(i=0; i<2; i++){ + sprintf(line, "%s/%s", db_path, filename[i]); + fp=fopen(line,"r"); + if(fp == NULL){ + if(i != 0) + continue; + ShowError("can't read %s\n",line); + return; + } + while(fgets(line, sizeof(line), fp) && j < MAX_LEVEL) + { + if(line[0] == '/' && line[1] == '/') + continue; + + hexptbl[j] = strtoul(line, NULL, 10); + if (!hexptbl[j++]) + break; + } + if (hexptbl[MAX_LEVEL - 1]) // Last permitted level have to be 0! + { + ShowWarning("read_hexptbl: Reached max level in exp_homun [%d]. Remaining lines were not read.\n ", MAX_LEVEL); + hexptbl[MAX_LEVEL - 1] = 0; + } + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' levels in '"CL_WHITE"%s"CL_RESET"'.\n", j, filename[i]); + } +} + +void merc_reload(void) +{ + read_homunculusdb(); + read_homunculus_expdb(); +} + +void merc_skill_reload(void) +{ + read_homunculus_skilldb(); +} + +int do_init_merc(void) +{ + int class_; + read_homunculusdb(); + read_homunculus_expdb(); + read_homunculus_skilldb(); + // Add homunc timer function to timer func list [Toms] + add_timer_func_list(merc_hom_hungry, "merc_hom_hungry"); + + //Stock view data for homuncs + memset(&hom_viewdb, 0, sizeof(hom_viewdb)); + for (class_ = 0; class_ < ARRAYLENGTH(hom_viewdb); class_++) + hom_viewdb[class_].class_ = HM_CLASS_BASE+class_; + return 0; +} + +int do_final_merc(void); diff --git a/src/map/homunculus.h b/src/map/homunculus.h new file mode 100644 index 000000000..d4946da3c --- /dev/null +++ b/src/map/homunculus.h @@ -0,0 +1,89 @@ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder + +#ifndef _HOMUNCULUS_H_ +#define _HOMUNCULUS_H_ + +#include "status.h" // struct status_data, struct status_change +#include "unit.h" // struct unit_data + +struct h_stats { + unsigned int HP, SP; + unsigned short str, agi, vit, int_, dex, luk; +}; + +struct s_homunculus_db { + int base_class, evo_class; + char name[NAME_LENGTH]; + struct h_stats base, gmin, gmax, emin, emax; + int foodID ; + int baseASPD ; + long hungryDelay ; + unsigned char element, race, base_size, evo_size; +}; + +extern struct s_homunculus_db homuncumlus_db[MAX_HOMUNCULUS_CLASS]; +enum { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD }; +enum { + SP_ACK = 0x00, + SP_INTIMATE = 0x100, + SP_HUNGRY = 0x200 +}; + +struct homun_data { + struct block_list bl; + struct unit_data ud; + struct view_data *vd; + struct status_data base_status, battle_status; + struct status_change sc; + struct regen_data regen; + struct s_homunculus_db *homunculusDB; //[orn] + struct s_homunculus homunculus; //[orn] + + struct map_session_data *master; //pointer back to its master + int hungry_timer; //[orn] + unsigned int exp_next; + char blockskill[MAX_SKILL]; // [orn] +}; + + +#define homdb_checkid(id) (id >= HM_CLASS_BASE && id <= HM_CLASS_MAX) + +// merc_is_hom_alive(struct homun_data *) +#define merc_is_hom_active(x) (x && x->homunculus.vaporize != 1 && x->battle_status.hp > 0) +int do_init_merc(void); +int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag); //albator +struct view_data* merc_get_hom_viewdata(int class_); +void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp); +int merc_hom_dead(struct homun_data *hd, struct block_list *src); +void merc_hom_skillup(struct homun_data *hd,int skillnum); +int merc_hom_calc_skilltree(struct homun_data *hd) ; +int merc_hom_checkskill(struct homun_data *hd,int skill_id) ; +int merc_hom_gainexp(struct homun_data *hd,int exp) ; +int merc_hom_levelup(struct homun_data *hd) ; +int merc_hom_evolution(struct homun_data *hd) ; +void merc_hom_heal(struct homun_data *hd,int hp,int sp); +int merc_hom_vaporize(struct map_session_data *sd, int flag); +int merc_resurrect_homunculus(struct map_session_data *sd, unsigned char per, short x, short y); +void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp); +void merc_reset_stats(struct homun_data *hd); +int merc_hom_shuffle(struct homun_data *hd); // [Zephyrus] +void merc_save(struct homun_data *hd); +int merc_call_homunculus(struct map_session_data *sd); +int merc_create_homunculus_request(struct map_session_data *sd, int class_); +int search_homunculusDB_index(int key,int type); +int merc_menu(struct map_session_data *sd,int menunum); +int merc_hom_food(struct map_session_data *sd, struct homun_data *hd); +int merc_hom_hungry_timer_delete(struct homun_data *hd); +int merc_hom_change_name(struct map_session_data *sd,char *name); +int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag); +#define merc_stop_walking(hd, type) unit_stop_walking(&(hd)->bl, type) +#define merc_stop_attack(hd) unit_stop_attack(&(hd)->bl) +int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value); +int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value); +int merc_skill_tree_get_max(int id, int b_class); +void merc_hom_init_timers(struct homun_data * hd); +void merc_skill_reload(void); +void merc_reload(void); + +#endif /* _HOMUNCULUS_H_ */ diff --git a/src/map/mercenary.c b/src/map/mercenary.c deleted file mode 100644 index c56c36cdb..000000000 --- a/src/map/mercenary.c +++ /dev/null @@ -1,1168 +0,0 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder - -#include "../common/cbasetypes.h" -#include "../common/malloc.h" -#include "../common/socket.h" -#include "../common/timer.h" -#include "../common/nullpo.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" -#include "../common/utils.h" - -#include "log.h" -#include "clif.h" -#include "chrif.h" -#include "intif.h" -#include "itemdb.h" -#include "map.h" -#include "pc.h" -#include "status.h" -#include "skill.h" -#include "mob.h" -#include "pet.h" -#include "battle.h" -#include "party.h" -#include "guild.h" -#include "atcommand.h" -#include "script.h" -#include "npc.h" -#include "trade.h" -#include "unit.h" - -#include "mercenary.h" - -#include -#include -#include -#include - - -//Better equiprobability than rand()% [orn] -#define rand(a, b) (a+(int) ((float)(b-a+1)*rand()/(RAND_MAX+1.0))) - -struct s_homunculus_db homunculus_db[MAX_HOMUNCULUS_CLASS]; //[orn] -struct skill_tree_entry hskill_tree[MAX_HOMUNCULUS_CLASS][MAX_SKILL_TREE]; - -static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data); - -static unsigned int hexptbl[MAX_LEVEL]; - -//For holding the view data of npc classes. [Skotlex] -static struct view_data hom_viewdb[MAX_HOMUNCULUS_CLASS]; - -struct view_data* merc_get_hom_viewdata(int class_) -{ //Returns the viewdata for homunculus - if (homdb_checkid(class_)) - return &hom_viewdb[class_-HM_CLASS_BASE]; - return NULL; -} - -void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp) -{ - clif_hominfo(hd->master,hd,0); -} - -int merc_hom_dead(struct homun_data *hd, struct block_list *src) -{ - //There's no intimacy penalties on death (from Tharis) - struct map_session_data *sd = hd->master; - - clif_emotion(&hd->bl, 16) ; //wah - - //Delete timers when dead. - merc_hom_hungry_timer_delete(hd); - hd->homunculus.hp = 0; - - if (!sd) //unit remove map will invoke unit free - return 3; - - clif_emotion(&sd->bl, 28) ; //sob - //Remove from map (if it has no intimacy, it is auto-removed from memory) - return 3; -} - -//Vaporize a character's homun. If flag, HP needs to be 80% or above. -int merc_hom_vaporize(struct map_session_data *sd, int flag) -{ - struct homun_data *hd; - - nullpo_retr(0, sd); - - hd = sd->hd; - if (!hd || hd->homunculus.vaporize) - return 0; - - if (status_isdead(&hd->bl)) - return 0; //Can't vaporize a dead homun. - - if (flag && get_percentage(hd->battle_status.hp, hd->battle_status.max_hp) < 80) - return 0; - - hd->regen.state.block = 3; //Block regen while vaporized. - //Delete timers when vaporized. - merc_hom_hungry_timer_delete(hd); - hd->homunculus.vaporize = 1; - if(battle_config.hom_setting&0x40) - memset(hd->blockskill, 0, sizeof(hd->blockskill)); - clif_hominfo(sd, sd->hd, 0); - merc_save(hd); - return unit_remove_map(&hd->bl, 0); -} - -//delete a homunculus, completely "killing it". -//Emote is the emotion the master should use, send negative to disable. -int merc_hom_delete(struct homun_data *hd, int emote) -{ - struct map_session_data *sd; - nullpo_retr(0, hd); - sd = hd->master; - - if (!sd) - return unit_free(&hd->bl,1); - - if (emote >= 0) - clif_emotion(&sd->bl, emote); - - //This makes it be deleted right away. - hd->homunculus.intimacy = 0; - // Send homunculus_dead to client - hd->homunculus.hp = 0; - clif_hominfo(sd, hd, 0); - return unit_remove_map(&hd->bl,0); -} - -int merc_hom_calc_skilltree(struct homun_data *hd) -{ - int i,id=0 ; - int j,f=1; - int c=0; - - nullpo_retr(0, hd); - c = hd->homunculus.class_ - HM_CLASS_BASE; - - for(i=0;i < MAX_SKILL_TREE && (id = hskill_tree[c][i].id) > 0;i++) - { - if(hd->homunculus.hskill[id-HM_SKILLBASE].id) - continue; //Skill already known. - if(!battle_config.skillfree) - { - for(j=0;j<5;j++) - { - if( hskill_tree[c][i].need[j].id && - merc_hom_checkskill(hd,hskill_tree[c][i].need[j].id) < hskill_tree[c][i].need[j].lv) - { - f=0; - break; - } - } - } - if (f) - hd->homunculus.hskill[id-HM_SKILLBASE].id = id ; - } - return 0; -} - -int merc_hom_checkskill(struct homun_data *hd,int skill_id) -{ - int i = skill_id - HM_SKILLBASE; - if(!hd) - return 0; - - if(hd->homunculus.hskill[i].id == skill_id) - return (hd->homunculus.hskill[i].lv); - - return 0; -} - -int merc_skill_tree_get_max(int id, int b_class){ - int i, skillid; - b_class -= HM_CLASS_BASE; - for(i=0;(skillid=hskill_tree[b_class][i].id)>0;i++) - if (id == skillid) - return hskill_tree[b_class][i].max; - return skill_get_max(id); -} - -void merc_hom_skillup(struct homun_data *hd,int skillnum) -{ - int i = 0 ; - nullpo_retv(hd); - - if(hd->homunculus.vaporize) - return; - - i = skillnum - HM_SKILLBASE; - if(hd->homunculus.skillpts > 0 && - hd->homunculus.hskill[i].id && - hd->homunculus.hskill[i].flag == 0 && //Don't allow raising while you have granted skills. [Skotlex] - hd->homunculus.hskill[i].lv < merc_skill_tree_get_max(skillnum, hd->homunculus.class_) - ) - { - hd->homunculus.hskill[i].lv++; - hd->homunculus.skillpts-- ; - status_calc_homunculus(hd,0); - if (hd->master) { - clif_homskillup(hd->master, skillnum); - clif_hominfo(hd->master,hd,0); - clif_homskillinfoblock(hd->master); - } - } -} - -int merc_hom_levelup(struct homun_data *hd) -{ - struct s_homunculus *hom; - struct h_stats *min, *max; - int growth_str, growth_agi, growth_vit, growth_int, growth_dex, growth_luk ; - int growth_max_hp, growth_max_sp ; - char output[256] ; - - if (hd->homunculus.level == MAX_LEVEL || !hd->exp_next || hd->homunculus.exp < hd->exp_next) - return 0 ; - - hom = &hd->homunculus; - hom->level++ ; - if (!(hom->level % 3)) - hom->skillpts++ ; //1 skillpoint each 3 base level - - hom->exp -= hd->exp_next ; - hd->exp_next = hexptbl[hom->level - 1] ; - - max = &hd->homunculusDB->gmax; - min = &hd->homunculusDB->gmin; - - growth_max_hp = rand(min->HP, max->HP); - growth_max_sp = rand(min->SP, max->SP); - growth_str = rand(min->str, max->str); - growth_agi = rand(min->agi, max->agi); - growth_vit = rand(min->vit, max->vit); - growth_dex = rand(min->dex, max->dex); - growth_int = rand(min->int_,max->int_); - growth_luk = rand(min->luk, max->luk); - - //Aegis discards the decimals in the stat growth values! - growth_str-=growth_str%10; - growth_agi-=growth_agi%10; - growth_vit-=growth_vit%10; - growth_dex-=growth_dex%10; - growth_int-=growth_int%10; - growth_luk-=growth_luk%10; - - hom->max_hp += growth_max_hp; - hom->max_sp += growth_max_sp; - hom->str += growth_str; - hom->agi += growth_agi; - hom->vit += growth_vit; - hom->dex += growth_dex; - hom->int_+= growth_int; - hom->luk += growth_luk; - - if ( battle_config.homunculus_show_growth ) { - sprintf(output, - "Growth: hp:%d sp:%d str(%.2f) agi(%.2f) vit(%.2f) int(%.2f) dex(%.2f) luk(%.2f) ", - growth_max_hp, growth_max_sp, - growth_str/10.0, growth_agi/10.0, growth_vit/10.0, - growth_int/10.0, growth_dex/10.0, growth_luk/10.0); - clif_disp_onlyself(hd->master,output,strlen(output)); - } - return 1 ; -} - -int merc_hom_change_class(struct homun_data *hd, short class_) -{ - int i; - i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); - if(i < 0) - return 0; - hd->homunculusDB = &homunculus_db[i]; - hd->homunculus.class_ = class_; - status_set_viewdata(&hd->bl, class_); - merc_hom_calc_skilltree(hd); - return 1; -} - -int merc_hom_evolution(struct homun_data *hd) -{ - struct s_homunculus *hom; - struct h_stats *max, *min; - struct map_session_data *sd; - nullpo_retr(0, hd); - - if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class) - { - clif_emotion(&hd->bl, 4) ; //swt - return 0 ; - } - sd = hd->master; - if (!sd) - return 0; - - if (!merc_hom_change_class(hd, hd->homunculusDB->evo_class)) { - ShowError("merc_hom_evolution: Can't evolve homunc from %d to %d", hd->homunculus.class_, hd->homunculusDB->evo_class); - return 0; - } - - //Apply evolution bonuses - hom = &hd->homunculus; - max = &hd->homunculusDB->emax; - min = &hd->homunculusDB->emin; - hom->max_hp += rand(min->HP, max->HP); - hom->max_sp += rand(min->SP, max->SP); - hom->str += 10*rand(min->str, max->str); - hom->agi += 10*rand(min->agi, max->agi); - hom->vit += 10*rand(min->vit, max->vit); - hom->int_+= 10*rand(min->int_,max->int_); - hom->dex += 10*rand(min->dex, max->dex); - hom->luk += 10*rand(min->luk, max->luk); - hom->intimacy = 500; - - unit_remove_map(&hd->bl, 0); - map_addblock(&hd->bl); - - clif_spawn(&hd->bl); - clif_emotion(&sd->bl, 21); //no1 - clif_misceffect2(&hd->bl,568); - - //status_Calc flag&1 will make current HP/SP be reloaded from hom structure - hom->hp = hd->battle_status.hp; - hom->sp = hd->battle_status.sp; - status_calc_homunculus(hd,1); - - if (!(battle_config.hom_setting&0x2)) - skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately - - return 1 ; -} - -int merc_hom_gainexp(struct homun_data *hd,int exp) -{ - if(hd->homunculus.vaporize) - return 1; - - if( hd->exp_next == 0 ) { - hd->homunculus.exp = 0 ; - return 0; - } - - hd->homunculus.exp += exp; - - if(hd->homunculus.exp < hd->exp_next) { - clif_hominfo(hd->master,hd,0); - return 0; - } - - //levelup - do - { - merc_hom_levelup(hd) ; - } - while(hd->homunculus.exp > hd->exp_next && hd->exp_next != 0 ); - - if( hd->exp_next == 0 ) - hd->homunculus.exp = 0 ; - - clif_misceffect2(&hd->bl,568); - status_calc_homunculus(hd,0); - status_percent_heal(&hd->bl, 100, 100); - return 0; -} - -// Return the new value -int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value) -{ - if (battle_config.homunculus_friendly_rate != 100) - value = (value * battle_config.homunculus_friendly_rate) / 100; - - if (hd->homunculus.intimacy + value <= 100000) - hd->homunculus.intimacy += value; - else - hd->homunculus.intimacy = 100000; - return hd->homunculus.intimacy; -} - -// Return 0 if decrease fails or intimacy became 0 else the new value -int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value) -{ - if (hd->homunculus.intimacy >= value) - hd->homunculus.intimacy -= value; - else - hd->homunculus.intimacy = 0; - - return hd->homunculus.intimacy; -} - -void merc_hom_heal(struct homun_data *hd,int hp,int sp) -{ - clif_hominfo(hd->master,hd,0); -} - -void merc_save(struct homun_data *hd) -{ - // copy data that must be saved in homunculus struct ( hp / sp ) - TBL_PC * sd = hd->master; - //Do not check for max_hp/max_sp caps as current could be higher to max due - //to status changes/skills (they will be capped as needed upon stat - //calculation on login) - hd->homunculus.hp = hd->battle_status.hp; - hd->homunculus.sp = hd->battle_status.sp; - intif_homunculus_requestsave(sd->status.account_id, &hd->homunculus); -} - -int merc_menu(struct map_session_data *sd,int menunum) -{ - nullpo_retr(0, sd); - if (sd->hd == NULL) - return 1; - - switch(menunum) { - case 0: - break; - case 1: - merc_hom_food(sd, sd->hd); - break; - case 2: - merc_hom_delete(sd->hd, -1); - break; - default: - ShowError("merc_menu : unknown menu choice : %d\n", menunum) ; - break; - } - return 0; -} - -int merc_hom_food(struct map_session_data *sd, struct homun_data *hd) -{ - int i, foodID, emotion; - - if(hd->homunculus.vaporize) - return 1 ; - - foodID = hd->homunculusDB->foodID; - i = pc_search_inventory(sd,foodID); - if(i < 0) { - clif_hom_food(sd,foodID,0); - return 1; - } - pc_delitem(sd,i,1,0); - - if ( hd->homunculus.hunger >= 91 ) { - merc_hom_decrease_intimacy(hd, 50); - emotion = 16; - } else if ( hd->homunculus.hunger >= 76 ) { - merc_hom_decrease_intimacy(hd, 5); - emotion = 19; - } else if ( hd->homunculus.hunger >= 26 ) { - merc_hom_increase_intimacy(hd, 75); - emotion = 2; - } else if ( hd->homunculus.hunger >= 11 ) { - merc_hom_increase_intimacy(hd, 100); - emotion = 2; - } else { - merc_hom_increase_intimacy(hd, 50); - emotion = 2; - } - - hd->homunculus.hunger += 10; //dunno increase value for each food - if(hd->homunculus.hunger > 100) - hd->homunculus.hunger = 100; - - clif_emotion(&hd->bl,emotion) ; - clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); - clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); - clif_hom_food(sd,foodID,1); - - // Too much food :/ - if(hd->homunculus.intimacy == 0) - return merc_hom_delete(sd->hd, 23); //omg - - return 0; -} - -static int merc_hom_hungry(int tid, unsigned int tick, int id, intptr data) -{ - struct map_session_data *sd; - struct homun_data *hd; - - sd=map_id2sd(id); - if(!sd) - return 1; - - if(!sd->status.hom_id || !(hd=sd->hd)) - return 1; - - if(hd->hungry_timer != tid){ - ShowError("merc_hom_hungry_timer %d != %d\n",hd->hungry_timer,tid); - return 0; - } - - hd->hungry_timer = INVALID_TIMER; - - hd->homunculus.hunger-- ; - if(hd->homunculus.hunger <= 10) { - clif_emotion(&hd->bl, 6) ; //an - } else if(hd->homunculus.hunger == 25) { - clif_emotion(&hd->bl, 20) ; //hmm - } else if(hd->homunculus.hunger == 75) { - clif_emotion(&hd->bl, 33) ; //ok - } - - if(hd->homunculus.hunger < 0) { - hd->homunculus.hunger = 0; - // Delete the homunculus if intimacy <= 100 - if ( !merc_hom_decrease_intimacy(hd, 100) ) - return merc_hom_delete(hd, 23); //omg - clif_send_homdata(sd,SP_INTIMATE,hd->homunculus.intimacy / 100); - } - - clif_send_homdata(sd,SP_HUNGRY,hd->homunculus.hunger); - hd->hungry_timer = add_timer(tick+hd->homunculusDB->hungryDelay,merc_hom_hungry,sd->bl.id,0); //simple Fix albator - return 0; -} - -int merc_hom_hungry_timer_delete(struct homun_data *hd) -{ - nullpo_retr(0, hd); - if(hd->hungry_timer != -1) { - delete_timer(hd->hungry_timer,merc_hom_hungry); - hd->hungry_timer = INVALID_TIMER; - } - return 1; -} - -int merc_hom_change_name(struct map_session_data *sd,char *name) -{ - int i; - struct homun_data *hd; - nullpo_retr(1, sd); - - hd = sd->hd; - if (!merc_is_hom_active(hd)) - return 1; - if(hd->homunculus.rename_flag && !battle_config.hom_rename) - return 1; - - for(i=0;ihd; - if (!merc_is_hom_active(hd)) return 0; - if (!flag) { - clif_displaymessage(sd->fd, msg_txt(280)); // You cannot use this name - return 0; - } - strncpy(hd->homunculus.name,name,NAME_LENGTH); - clif_charnameack (0,&hd->bl); - hd->homunculus.rename_flag = 1; - clif_hominfo(sd,hd,0); - return 1; -} - -int search_homunculusDB_index(int key,int type) -{ - int i; - - for(i=0;istatus.hom_id == 0 || sd->hd == 0) || sd->hd->master == sd); - - i = search_homunculusDB_index(hom->class_,HOMUNCULUS_CLASS); - if(i < 0) { - ShowError("merc_hom_alloc: unknown class [%d] for homunculus '%s', requesting deletion.\n", hom->class_, hom->name); - sd->status.hom_id = 0; - intif_homunculus_requestdelete(hom->hom_id); - return 1; - } - sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data)); - hd->bl.type = BL_HOM; - hd->bl.id = npc_get_new_npc_id(); - - hd->master = sd; - hd->homunculusDB = &homunculus_db[i]; - memcpy(&hd->homunculus, hom, sizeof(struct s_homunculus)); - hd->exp_next = hexptbl[hd->homunculus.level - 1]; - - status_set_viewdata(&hd->bl, hd->homunculus.class_); - status_change_init(&hd->bl); - unit_dataset(&hd->bl); - hd->ud.dir = sd->ud.dir; - - // Find a random valid pos around the player - hd->bl.m = sd->bl.m; - hd->bl.x = sd->bl.x; - hd->bl.y = sd->bl.y; - x = sd->bl.x + 1; - y = sd->bl.y + 1; - map_random_dir(&hd->bl, &x, &y); - hd->bl.x = x; - hd->bl.y = y; - - map_addiddb(&hd->bl); - status_calc_homunculus(hd,1); - - hd->hungry_timer = INVALID_TIMER; - return 0; -} - -void merc_hom_init_timers(struct homun_data * hd) -{ - if (hd->hungry_timer == -1) - hd->hungry_timer = add_timer(gettick()+hd->homunculusDB->hungryDelay,merc_hom_hungry,hd->master->bl.id,0); - hd->regen.state.block = 0; //Restore HP/SP block. -} - -int merc_call_homunculus(struct map_session_data *sd) -{ - struct homun_data *hd; - - if (!sd->status.hom_id) //Create a new homun. - return merc_create_homunculus_request(sd, HM_CLASS_BASE + rand(0, 7)) ; - - // If homunc not yet loaded, load it - if (!sd->hd) - return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); - - hd = sd->hd; - - if (!hd->homunculus.vaporize) - return 0; //Can't use this if homun wasn't vaporized. - - merc_hom_init_timers(hd); - hd->homunculus.vaporize = 0; - if (hd->bl.prev == NULL) - { //Spawn him - hd->bl.x = sd->bl.x; - hd->bl.y = sd->bl.y; - hd->bl.m = sd->bl.m; - map_addblock(&hd->bl); - clif_spawn(&hd->bl); - clif_send_homdata(sd,SP_ACK,0); - clif_hominfo(sd,hd,1); - clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] - clif_homskillinfoblock(sd); - if (battle_config.slaves_inherit_speed&1) - status_calc_bl(&hd->bl, SCB_SPEED); - merc_save(hd); - } else - //Warp him to master. - unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,0); - return 1; -} - -// Recv homunculus data from char server -int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag) -{ - struct map_session_data *sd; - struct homun_data *hd; - - sd = map_id2sd(account_id); - if(!sd) - return 0; - if (sd->status.char_id != sh->char_id) - { - if (sd->status.hom_id == sh->hom_id) - sh->char_id = sd->status.char_id; //Correct char id. - else - return 0; - } - if(!flag) { // Failed to load - sd->status.hom_id = 0; - return 0; - } - - if (!sd->status.hom_id) //Hom just created. - sd->status.hom_id = sh->hom_id; - if (sd->hd) //uh? Overwrite the data. - memcpy(&sd->hd->homunculus, sh, sizeof(struct s_homunculus)); - else - merc_hom_alloc(sd, sh); - - hd = sd->hd; - if(hd && hd->homunculus.hp && !hd->homunculus.vaporize && hd->bl.prev == NULL && sd->bl.prev != NULL) - { - map_addblock(&hd->bl); - clif_spawn(&hd->bl); - clif_send_homdata(sd,SP_ACK,0); - clif_hominfo(sd,hd,1); - clif_hominfo(sd,hd,0); // send this x2. dunno why, but kRO does that [blackhole89] - clif_homskillinfoblock(sd); - merc_hom_init_timers(hd); - } - return 1; -} - -// Ask homunculus creation to char server -int merc_create_homunculus_request(struct map_session_data *sd, int class_) -{ - struct s_homunculus homun; - struct h_stats *base; - int i; - - nullpo_retr(1, sd); - - i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS); - if(i < 0) return 0; - - memset(&homun, 0, sizeof(struct s_homunculus)); - //Initial data - strncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1); - homun.class_ = class_; - homun.level = 1; - homun.hunger = 32; //32% - homun.intimacy = 2100; //21/1000 - homun.char_id = sd->status.char_id; - - homun.hp = 10 ; - base = &homunculus_db[i].base; - homun.max_hp = base->HP; - homun.max_sp = base->SP; - homun.str = base->str *10; - homun.agi = base->agi *10; - homun.vit = base->vit *10; - homun.int_= base->int_*10; - homun.dex = base->dex *10; - homun.luk = base->luk *10; - - // Request homunculus creation - intif_homunculus_create(sd->status.account_id, &homun); - return 1; -} - -int merc_resurrect_homunculus(struct map_session_data* sd, unsigned char per, short x, short y) -{ - struct homun_data* hd; - nullpo_retr(0, sd); - - if (!sd->status.hom_id) - return 0; // no homunculus - - if (!sd->hd) //Load homun data; - return intif_homunculus_requestload(sd->status.account_id, sd->status.hom_id); - - hd = sd->hd; - - if (hd->homunculus.vaporize) - return 0; // vaporized homunculi need to be 'called' - - if (!status_isdead(&hd->bl)) - return 0; // already alive - - merc_hom_init_timers(hd); - - if (!hd->bl.prev) - { //Add it back to the map. - hd->bl.m = sd->bl.m; - hd->bl.x = x; - hd->bl.y = y; - map_addblock(&hd->bl); - clif_spawn(&hd->bl); - } - status_revive(&hd->bl, per, 0); - return 1; -} - -void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp) -{ - struct map_session_data *sd = hd->master; - hd->homunculus.hp = hd->battle_status.hp; - if (!sd) - return; - clif_send_homdata(sd,SP_ACK,0); - clif_hominfo(sd,hd,1); - clif_hominfo(sd,hd,0); - clif_homskillinfoblock(sd); -} - -void merc_reset_stats(struct homun_data *hd) -{ //Resets a homunc stats back to zero (but doesn't touches hunger or intimacy) - struct s_homunculus_db *db; - struct s_homunculus *hom; - struct h_stats *base; - hom = &hd->homunculus; - db = hd->homunculusDB; - base = &db->base; - hom->level = 1; - hom->hp = 10; - hom->max_hp = base->HP; - hom->max_sp = base->SP; - hom->str = base->str *10; - hom->agi = base->agi *10; - hom->vit = base->vit *10; - hom->int_= base->int_*10; - hom->dex = base->dex *10; - hom->luk = base->luk *10; - hom->exp = 0; - hd->exp_next = hexptbl[0]; - memset(&hd->homunculus.hskill, 0, sizeof hd->homunculus.hskill); - hd->homunculus.skillpts = 0; -} - -int merc_hom_shuffle(struct homun_data *hd) -{ - struct map_session_data *sd; - int lv, i, skillpts; - unsigned int exp; - struct s_skill b_skill[MAX_HOMUNSKILL]; - - if (!merc_is_hom_active(hd)) - return 0; - - sd = hd->master; - lv = hd->homunculus.level; - exp = hd->homunculus.exp; - memcpy(&b_skill, &hd->homunculus.hskill, sizeof(b_skill)); - skillpts = hd->homunculus.skillpts; - //Reset values to level 1. - merc_reset_stats(hd); - //Level it back up - for (i = 1; i < lv && hd->exp_next; i++){ - hd->homunculus.exp += hd->exp_next; - merc_hom_levelup(hd); - } - - if(hd->homunculus.class_ == hd->homunculusDB->evo_class) { - //Evolved bonuses - struct s_homunculus *hom = &hd->homunculus; - struct h_stats *max = &hd->homunculusDB->emax, *min = &hd->homunculusDB->emin; - hom->max_hp += rand(min->HP, max->HP); - hom->max_sp += rand(min->SP, max->SP); - hom->str += 10*rand(min->str, max->str); - hom->agi += 10*rand(min->agi, max->agi); - hom->vit += 10*rand(min->vit, max->vit); - hom->int_+= 10*rand(min->int_,max->int_); - hom->dex += 10*rand(min->dex, max->dex); - hom->luk += 10*rand(min->luk, max->luk); - } - - hd->homunculus.exp = exp; - memcpy(&hd->homunculus.hskill, &b_skill, sizeof(b_skill)); - hd->homunculus.skillpts = skillpts; - clif_homskillinfoblock(sd); - status_calc_homunculus(hd,0); - status_percent_heal(&hd->bl, 100, 100); - clif_misceffect2(&hd->bl,568); - - return 1; -} - -int read_homunculusdb(void) -{ - FILE *fp; - char line[1024], *p; - int i, k, classid; - int j = 0; - const char *filename[]={"homunculus_db.txt","homunculus_db2.txt"}; - char *str[50]; - struct s_homunculus_db *db; - - memset(homunculus_db,0,sizeof(homunculus_db)); - for(i = 0; i<2; i++) - { - sprintf(line, "%s/%s", db_path, filename[i]); - fp = fopen(line,"r"); - if(!fp){ - if(i != 0) - continue; - ShowError("read_homunculusdb : can't read %s\n", line); - return -1; - } - - while(fgets(line, sizeof(line), fp) && j < MAX_HOMUNCULUS_CLASS) - { - if(line[0] == '/' && line[1] == '/') - continue; - - k = 0; - p = strtok (line,","); - while (p != NULL && k < 50) - { - str[k++] = p; - p = strtok (NULL, ","); - } - if (k < 50 ) - { - ShowError("read_homunculusdb : Incorrect number of columns at %s, homunculus %d. Read %d columns, 50 are needed.\n", filename[i], j+1, k); - continue; - } - - //Base Class,Evo Class - classid = atoi(str[0]); - if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) - { - ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); - continue; - } - db = &homunculus_db[j]; - db->base_class = classid; - classid = atoi(str[1]); - if (classid < HM_CLASS_BASE || classid > HM_CLASS_MAX) - { - db->base_class = 0; - ShowError("read_homunculusdb : Invalid class %d (%s)\n", classid, filename[i]); - continue; - } - db->evo_class = classid; - //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD - strncpy(db->name,str[2],NAME_LENGTH-1); - db->foodID = atoi(str[3]); - db->hungryDelay = atoi(str[4]); - db->base_size = atoi(str[5]); - db->evo_size = atoi(str[6]); - db->race = atoi(str[7]); - db->element = atoi(str[8]); - db->baseASPD = atoi(str[9]); - //base HP, SP, str, agi, vit, int, dex, luk - db->base.HP = atoi(str[10]); - db->base.SP = atoi(str[11]); - db->base.str = atoi(str[12]); - db->base.agi = atoi(str[13]); - db->base.vit = atoi(str[14]); - db->base.int_= atoi(str[15]); - db->base.dex = atoi(str[16]); - db->base.luk = atoi(str[17]); - //Growth Min/Max HP, SP, str, agi, vit, int, dex, luk - db->gmin.HP = atoi(str[18]); - db->gmax.HP = atoi(str[19]); - db->gmin.SP = atoi(str[20]); - db->gmax.SP = atoi(str[21]); - db->gmin.str = atoi(str[22]); - db->gmax.str = atoi(str[23]); - db->gmin.agi = atoi(str[24]); - db->gmax.agi = atoi(str[25]); - db->gmin.vit = atoi(str[26]); - db->gmax.vit = atoi(str[27]); - db->gmin.int_= atoi(str[28]); - db->gmax.int_= atoi(str[29]); - db->gmin.dex = atoi(str[30]); - db->gmax.dex = atoi(str[31]); - db->gmin.luk = atoi(str[32]); - db->gmax.luk = atoi(str[33]); - //Evolution Min/Max HP, SP, str, agi, vit, int, dex, luk - db->emin.HP = atoi(str[34]); - db->emax.HP = atoi(str[35]); - db->emin.SP = atoi(str[36]); - db->emax.SP = atoi(str[37]); - db->emin.str = atoi(str[38]); - db->emax.str = atoi(str[39]); - db->emin.agi = atoi(str[40]); - db->emax.agi = atoi(str[41]); - db->emin.vit = atoi(str[42]); - db->emax.vit = atoi(str[43]); - db->emin.int_= atoi(str[44]); - db->emax.int_= atoi(str[45]); - db->emin.dex = atoi(str[46]); - db->emax.dex = atoi(str[47]); - db->emin.luk = atoi(str[48]); - db->emax.luk = atoi(str[49]); - - //Check that the min/max values really are below the other one. - if(db->gmin.HP > db->gmax.HP) - db->gmin.HP = db->gmax.HP; - if(db->gmin.SP > db->gmax.SP) - db->gmin.SP = db->gmax.SP; - if(db->gmin.str > db->gmax.str) - db->gmin.str = db->gmax.str; - if(db->gmin.agi > db->gmax.agi) - db->gmin.agi = db->gmax.agi; - if(db->gmin.vit > db->gmax.vit) - db->gmin.vit = db->gmax.vit; - if(db->gmin.int_> db->gmax.int_) - db->gmin.int_= db->gmax.int_; - if(db->gmin.dex > db->gmax.dex) - db->gmin.dex = db->gmax.dex; - if(db->gmin.luk > db->gmax.luk) - db->gmin.luk = db->gmax.luk; - - if(db->emin.HP > db->emax.HP) - db->emin.HP = db->emax.HP; - if(db->emin.SP > db->emax.SP) - db->emin.SP = db->emax.SP; - if(db->emin.str > db->emax.str) - db->emin.str = db->emax.str; - if(db->emin.agi > db->emax.agi) - db->emin.agi = db->emax.agi; - if(db->emin.vit > db->emax.vit) - db->emin.vit = db->emax.vit; - if(db->emin.int_> db->emax.int_) - db->emin.int_= db->emax.int_; - if(db->emin.dex > db->emax.dex) - db->emin.dex = db->emax.dex; - if(db->emin.luk > db->emax.luk) - db->emin.luk = db->emax.luk; - - j++; - } - if (j > MAX_HOMUNCULUS_CLASS) - ShowWarning("read_homunculusdb: Reached max number of homunculus [%d]. Remaining homunculus were not read.\n ", MAX_HOMUNCULUS_CLASS); - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' homunculus in '"CL_WHITE"db/%s"CL_RESET"'.\n",j,filename[i]); - } - return 0; -} - -int read_homunculus_skilldb(void) -{ - FILE *fp; - char line[1024], *p; - int k, classid; - int j = 0; - char *split[15]; - - memset(hskill_tree,0,sizeof(hskill_tree)); - sprintf(line, "%s/homun_skill_tree.txt", db_path); - fp=fopen(line,"r"); - if(fp==NULL){ - ShowError("can't read %s\n", line); - return 1; - } - - while(fgets(line, sizeof(line), fp)) - { - int minJobLevelPresent = 0; - - if(line[0]=='/' && line[1]=='/') - continue; - - k = 0; - p = strtok(line,","); - while (p != NULL && k < 15) - { - split[k++] = p; - p = strtok(NULL, ","); - } - - if(k < 13) - continue; - - if (k == 14) - minJobLevelPresent = 1; // MinJobLvl has been added - - // check for bounds [celest] - classid = atoi(split[0]) - HM_CLASS_BASE; - if ( classid >= MAX_HOMUNCULUS_CLASS ) - continue; - - k = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex] - // Search an empty line or a line with the same skill_id (stored in j) - for(j = 0; j < MAX_SKILL_TREE && hskill_tree[classid][j].id && hskill_tree[classid][j].id != k; j++); - - if (j == MAX_SKILL_TREE) - { - ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", k, classid); - continue; - } - - hskill_tree[classid][j].id=k; - hskill_tree[classid][j].max=atoi(split[2]); - if (minJobLevelPresent) - hskill_tree[classid][j].joblv=atoi(split[3]); - - for(k=0;k<5;k++){ - hskill_tree[classid][j].need[k].id=atoi(split[3+k*2+minJobLevelPresent]); - hskill_tree[classid][j].need[k].lv=atoi(split[3+k*2+minJobLevelPresent+1]); - } - } - - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","homun_skill_tree.txt"); - return 0; -} - -void read_homunculus_expdb(void) -{ - FILE *fp; - char line[1024]; - int i, j=0; - char *filename[]={"exp_homun.txt","exp_homun2.txt"}; - - memset(hexptbl,0,sizeof(hexptbl)); - for(i=0; i<2; i++){ - sprintf(line, "%s/%s", db_path, filename[i]); - fp=fopen(line,"r"); - if(fp == NULL){ - if(i != 0) - continue; - ShowError("can't read %s\n",line); - return; - } - while(fgets(line, sizeof(line), fp) && j < MAX_LEVEL) - { - if(line[0] == '/' && line[1] == '/') - continue; - - hexptbl[j] = strtoul(line, NULL, 10); - if (!hexptbl[j++]) - break; - } - if (hexptbl[MAX_LEVEL - 1]) // Last permitted level have to be 0! - { - ShowWarning("read_hexptbl: Reached max level in exp_homun [%d]. Remaining lines were not read.\n ", MAX_LEVEL); - hexptbl[MAX_LEVEL - 1] = 0; - } - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' levels in '"CL_WHITE"%s"CL_RESET"'.\n", j, filename[i]); - } -} - -void merc_reload(void) -{ - read_homunculusdb(); - read_homunculus_expdb(); -} - -void merc_skill_reload(void) -{ - read_homunculus_skilldb(); -} - -int do_init_merc(void) -{ - int class_; - read_homunculusdb(); - read_homunculus_expdb(); - read_homunculus_skilldb(); - // Add homunc timer function to timer func list [Toms] - add_timer_func_list(merc_hom_hungry, "merc_hom_hungry"); - - //Stock view data for homuncs - memset(&hom_viewdb, 0, sizeof(hom_viewdb)); - for (class_ = 0; class_ < ARRAYLENGTH(hom_viewdb); class_++) - hom_viewdb[class_].class_ = HM_CLASS_BASE+class_; - return 0; -} - -int do_final_merc(void); diff --git a/src/map/mercenary.h b/src/map/mercenary.h deleted file mode 100644 index 88692b4d1..000000000 --- a/src/map/mercenary.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder - -#ifndef _MERCENARY_H_ -#define _MERCENARY_H_ - -#include "status.h" // struct status_data, struct status_change -#include "unit.h" // struct unit_data - -struct h_stats { - unsigned int HP, SP; - unsigned short str, agi, vit, int_, dex, luk; -}; - -struct s_homunculus_db { - int base_class, evo_class; - char name[NAME_LENGTH]; - struct h_stats base, gmin, gmax, emin, emax; - int foodID ; - int baseASPD ; - long hungryDelay ; - unsigned char element, race, base_size, evo_size; -}; - -extern struct s_homunculus_db homuncumlus_db[MAX_HOMUNCULUS_CLASS]; -enum { HOMUNCULUS_CLASS, HOMUNCULUS_FOOD }; -enum { - SP_ACK = 0x00, - SP_INTIMATE = 0x100, - SP_HUNGRY = 0x200 -}; - - -struct homun_data { - struct block_list bl; - struct unit_data ud; - struct view_data *vd; - struct status_data base_status, battle_status; - struct status_change sc; - struct regen_data regen; - struct s_homunculus_db *homunculusDB; //[orn] - struct s_homunculus homunculus ; //[orn] - - struct map_session_data *master; //pointer back to its master - int hungry_timer; //[orn] - unsigned int exp_next; - char blockskill[MAX_SKILL]; // [orn] -}; - - -#define homdb_checkid(id) (id >= HM_CLASS_BASE && id <= HM_CLASS_MAX) - -// merc_is_hom_alive(struct homun_data *) -#define merc_is_hom_active(x) (x && x->homunculus.vaporize != 1 && x->battle_status.hp > 0) -int do_init_merc(void); -int merc_hom_recv_data(int account_id, struct s_homunculus *sh, int flag); //albator -struct view_data* merc_get_hom_viewdata(int class_); -void merc_damage(struct homun_data *hd,struct block_list *src,int hp,int sp); -int merc_hom_dead(struct homun_data *hd, struct block_list *src); -void merc_hom_skillup(struct homun_data *hd,int skillnum); -int merc_hom_calc_skilltree(struct homun_data *hd) ; -int merc_hom_checkskill(struct homun_data *hd,int skill_id) ; -int merc_hom_gainexp(struct homun_data *hd,int exp) ; -int merc_hom_levelup(struct homun_data *hd) ; -int merc_hom_evolution(struct homun_data *hd) ; -void merc_hom_heal(struct homun_data *hd,int hp,int sp); -int merc_hom_vaporize(struct map_session_data *sd, int flag); -int merc_resurrect_homunculus(struct map_session_data *sd, unsigned char per, short x, short y); -void merc_hom_revive(struct homun_data *hd, unsigned int hp, unsigned int sp); -void merc_reset_stats(struct homun_data *hd); -int merc_hom_shuffle(struct homun_data *hd); // [Zephyrus] -void merc_save(struct homun_data *hd); -int merc_call_homunculus(struct map_session_data *sd); -int merc_create_homunculus_request(struct map_session_data *sd, int class_); -int search_homunculusDB_index(int key,int type); -int merc_menu(struct map_session_data *sd,int menunum); -int merc_hom_food(struct map_session_data *sd, struct homun_data *hd); -int merc_hom_hungry_timer_delete(struct homun_data *hd); -int merc_hom_change_name(struct map_session_data *sd,char *name); -int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag); -#define merc_stop_walking(hd, type) unit_stop_walking(&(hd)->bl, type) -#define merc_stop_attack(hd) unit_stop_attack(&(hd)->bl) -int merc_hom_increase_intimacy(struct homun_data * hd, unsigned int value); -int merc_hom_decrease_intimacy(struct homun_data * hd, unsigned int value); -int merc_skill_tree_get_max(int id, int b_class); -void merc_hom_init_timers(struct homun_data * hd); -void merc_skill_reload(void); -void merc_reload(void); - -#endif /* _MERCENARY_H_ */ -- cgit v1.2.3-70-g09d2 From 78d0348440ea4856e44044fff370b8bd4dfe90db Mon Sep 17 00:00:00 2001 From: ultramage Date: Tue, 26 Aug 2008 05:11:58 +0000 Subject: Added mercenary code (it should have been done this way in r13122). Removed 2 unused variables in homunculus code. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13137 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/homunculus.c | 1 - src/map/mercenary.c | 383 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/map/mercenary.h | 48 +++++++ 3 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 src/map/mercenary.c create mode 100644 src/map/mercenary.h (limited to 'src/map/homunculus.c') diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 02177552e..6acd969fa 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -594,7 +594,6 @@ int merc_hom_alloc(struct map_session_data *sd, struct s_homunculus *hom) { struct homun_data *hd; int i = 0; - short x,y; nullpo_retr(1, sd); diff --git a/src/map/mercenary.c b/src/map/mercenary.c new file mode 100644 index 000000000..dc49f5e21 --- /dev/null +++ b/src/map/mercenary.c @@ -0,0 +1,383 @@ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder + +#include "../common/cbasetypes.h" +#include "../common/malloc.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/nullpo.h" +#include "../common/mmo.h" +#include "../common/showmsg.h" +#include "../common/utils.h" + +#include "log.h" +#include "clif.h" +#include "chrif.h" +#include "intif.h" +#include "itemdb.h" +#include "map.h" +#include "pc.h" +#include "status.h" +#include "skill.h" +#include "mob.h" +#include "pet.h" +#include "battle.h" +#include "party.h" +#include "guild.h" +#include "atcommand.h" +#include "script.h" +#include "npc.h" +#include "trade.h" +#include "unit.h" +#include "mercenary.h" + +#include +#include +#include +#include + +struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS]; // Mercenary Database + +int merc_search_index(int class_) +{ + int i; + ARR_FIND(0, MAX_MERCENARY_CLASS, i, mercenary_db[i].class_ == class_); + return (i == MAX_MERCENARY_CLASS)?-1:i; +} + +bool merc_class(int class_) +{ + return (bool)(merc_search_index(class_) > -1); +} + +struct view_data * merc_get_viewdata(int class_) +{ + int i = merc_search_index(class_); + if( i < 0 ) + return 0; + + return &mercenary_db[i].vd; +} + +int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime) +{ + struct s_mercenary merc; + struct s_mercenary_db *db; + int i; + nullpo_retr(1,sd); + + if( (i = merc_search_index(class_)) < 0 ) + return 0; + + db = &mercenary_db[i]; + memset(&merc,0,sizeof(struct s_mercenary)); + + merc.char_id = sd->status.char_id; + merc.class_ = class_; + merc.hp = db->status.max_hp; + merc.sp = db->status.max_sp; + merc.remain_life_time = lifetime; + + // Request Char Server to create this mercenary + intif_mercenary_create(&merc); + + return 1; +} + +int mercenary_save(struct mercenary_data *md) +{ + const struct TimerData * td = get_timer(md->contract_timer); + + md->mercenary.hp = md->battle_status.hp; + md->mercenary.sp = md->battle_status.sp; + if( td != NULL ) + md->mercenary.remain_life_time = DIFF_TICK(td->tick, gettick()); + else + { + md->mercenary.remain_life_time = 0; + ShowWarning("mercenary_save : mercenary without timer (tid %d)\n", md->contract_timer); + } + + intif_mercenary_save(&md->mercenary); + return 1; +} + +static int merc_contract_end(int tid, unsigned int tick, int id, intptr data) +{ + struct map_session_data *sd; + struct mercenary_data *md; + + if( (sd = map_id2sd(id)) == NULL ) + return 1; + if( (md = sd->md) == NULL ) + return 1; + + if( md->contract_timer != tid ) + { + ShowError("merc_contract_end %d != %d.\n", md->contract_timer, tid); + return 0; + } + + md->contract_timer = INVALID_TIMER; + merc_delete(md, 0); // Mercenary soldier's duty hour is over. + + return 0; +} + +int merc_delete(struct mercenary_data *md, int reply) +{ + struct map_session_data *sd = md->master; + md->mercenary.remain_life_time = 0; + + merc_contract_stop(md); + + if( !sd ) + return unit_free(&md->bl, 1); + clif_mercenary_message(sd->fd, reply); + + return unit_remove_map(&md->bl, 1); +} + +void merc_contract_stop(struct mercenary_data *md) +{ + nullpo_retv(md); + if( md->contract_timer != INVALID_TIMER ) + delete_timer(md->contract_timer, merc_contract_end); + md->contract_timer = INVALID_TIMER; +} + +void merc_contract_init(struct mercenary_data *md) +{ + if( md->contract_timer == INVALID_TIMER ) + md->contract_timer = add_timer(gettick() + md->mercenary.remain_life_time, merc_contract_end, md->master->bl.id, 0); + + md->regen.state.block = 0; +} + +int merc_data_received(struct s_mercenary *merc, bool flag) +{ + struct map_session_data *sd; + struct mercenary_data *md; + struct s_mercenary_db *db; + int i = merc_search_index(merc->class_); + + if( (sd = map_charid2sd(merc->char_id)) == NULL ) + return 0; + if( !flag || i < 0 ) + { // Not created - loaded - DB info + sd->status.mer_id = 0; + return 0; + } + + sd->status.mer_id = merc->mercenary_id; + db = &mercenary_db[i]; + + if( !sd->md ) + { + sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data)); + md->bl.type = BL_MER; + md->bl.id = npc_get_new_npc_id(); + + md->master = sd; + md->db = db; + memcpy(&md->mercenary, merc, sizeof(struct s_mercenary)); + status_set_viewdata(&md->bl, md->mercenary.class_); + status_change_init(&md->bl); + unit_dataset(&md->bl); + md->ud.dir = sd->ud.dir; + + md->bl.m = sd->bl.m; + md->bl.x = sd->bl.x; + md->bl.y = sd->bl.y; + unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir); + md->bl.x = md->ud.to_x; + md->bl.y = md->ud.to_y; + + map_addiddb(&md->bl); + status_calc_mercenary(md,1); + md->contract_timer = INVALID_TIMER; + merc_contract_init(md); + } + else + memcpy(&sd->md->mercenary, merc, sizeof(struct s_mercenary)); + + md = sd->md; + if( md && md->bl.prev == NULL && sd->bl.prev != NULL ) + { + map_addblock(&md->bl); + clif_spawn(&md->bl); + clif_mercenary_info(sd); + clif_mercenary_skillblock(sd); + } + + return 1; +} + +int read_mercenarydb(void) +{ + FILE *fp; + char line[1024], *p; + char *str[26]; + int i, j = 0, k = 0, ele; + struct s_mercenary_db *db; + struct status_data *status; + + sprintf(line, "%s/%s", db_path, "mercenary_db.txt"); + memset(mercenary_db,0,sizeof(mercenary_db)); + + fp = fopen(line, "r"); + if( !fp ) + { + ShowError("read_mercenarydb : can't read mercenary_db.txt\n"); + return -1; + } + + while( fgets(line, sizeof(line), fp) && j < MAX_MERCENARY_CLASS ) + { + k++; + if( line[0] == '/' && line[1] == '/' ) + continue; + + i = 0; + p = strtok(line, ","); + while( p != NULL && i < 26 ) + { + str[i++] = p; + p = strtok(NULL, ","); + } + if( i < 26 ) + { + ShowError("read_mercenarydb : Incorrect number of columns at mercenary_db.txt line %d.\n", k); + continue; + } + + db = &mercenary_db[j]; + db->class_ = atoi(str[0]); + strncpy(db->sprite, str[1], NAME_LENGTH); + strncpy(db->name, str[2], NAME_LENGTH); + db->lv = atoi(str[3]); + + status = &db->status; + db->vd.class_ = db->class_; + + status->max_hp = atoi(str[4]); + status->max_sp = atoi(str[5]); + status->rhw.range = atoi(str[6]); + status->rhw.atk = atoi(str[7]); + status->rhw.atk2 = atoi(str[8]); + status->def = atoi(str[9]); + status->mdef = atoi(str[10]); + status->str = atoi(str[11]); + status->agi = atoi(str[12]); + status->vit = atoi(str[13]); + status->int_ = atoi(str[14]); + status->dex = atoi(str[15]); + status->luk = atoi(str[16]); + db->range2 = atoi(str[17]); + db->range3 = atoi(str[18]); + status->size = atoi(str[19]); + status->race = atoi(str[20]); + + ele = atoi(str[21]); + status->def_ele = ele%10; + status->ele_lv = ele/20; + if( status->def_ele >= ELE_MAX ) + { + ShowWarning("Mercenary %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1); + status->def_ele = ELE_NEUTRAL; + } + if( status->ele_lv < 1 || status->ele_lv > 4 ) + { + ShowWarning("Mercenary %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv); + status->ele_lv = 1; + } + + status->speed = atoi(str[22]); + status->adelay = atoi(str[23]); + status->amotion = atoi(str[24]); + status->dmotion = atoi(str[25]); + + j++; + } + + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' mercenaries in '"CL_WHITE"db/mercenary_db.txt"CL_RESET"'.\n",j); + + return 0; +} + +int read_mercenary_skilldb(void) +{ + FILE *fp; + char line[1024], *p; + char *str[3]; + struct s_mercenary_db *db; + int i, j = 0, k = 0, class_; + int skillid, skilllv; + + sprintf(line, "%s/%s", db_path, "mercenary_skill_db.txt"); + fp = fopen(line, "r"); + if( !fp ) + { + ShowError("read_mercenary_skilldb : can't read mercenary_skill_db.txt\n"); + return -1; + } + + while( fgets(line, sizeof(line), fp) ) + { + k++; + if( line[0] == '/' && line[1] == '/' ) + continue; + + i = 0; + p = strtok(line, ","); + while( p != NULL && i < 3 ) + { + str[i++] = p; + p = strtok(NULL, ","); + } + if( i < 3 ) + { + ShowError("read_mercenary_skilldb : Incorrect number of columns at mercenary_skill_db.txt line %d.\n", k); + continue; + } + + class_ = atoi(str[0]); + ARR_FIND(0, MAX_MERCENARY_CLASS, i, class_ == mercenary_db[i].class_); + if( i == MAX_MERCENARY_CLASS ) + { + ShowError("read_mercenary_skilldb : Class not found in mercenary_db for skill entry, line %d.\n", k); + continue; + } + + skillid = atoi(str[1]); + if( skillid < MC_SKILLBASE || skillid >= MC_SKILLBASE + MAX_MERCSKILL ) + { + ShowError("read_mercenary_skilldb : Skill out of range, line %d.\n", k); + continue; + } + + db = &mercenary_db[i]; + skilllv = atoi(str[2]); + + i = skillid - MC_SKILLBASE; + db->skill[i].id = skillid; + db->skill[i].lv = skilllv; + j++; + } + + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/mercenary_skill_db.txt"CL_RESET"'.\n",j); + return 0; +} + +int do_init_mercenary(void) +{ + read_mercenarydb(); + read_mercenary_skilldb(); + + //add_timer_func_list(mercenary_contract, "mercenary_contract"); + return 0; +} + +int do_final_mercenary(void); diff --git a/src/map/mercenary.h b/src/map/mercenary.h new file mode 100644 index 000000000..bc2046dc7 --- /dev/null +++ b/src/map/mercenary.h @@ -0,0 +1,48 @@ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder + +#ifndef _MERCENARY_H_ +#define _MERCENARY_H_ + +#include "status.h" // struct status_data, struct status_change +#include "unit.h" // struct unit_data + +struct s_mercenary_db { + int class_; + char sprite[NAME_LENGTH], name[NAME_LENGTH]; + unsigned short lv; + short range2, range3; + struct status_data status; + struct view_data vd; + struct { + unsigned short id, lv; + } skill[MAX_MERCSKILL]; +}; + +extern struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS]; + +struct mercenary_data { + struct block_list bl; + struct unit_data ud; + struct view_data *vd; + struct status_data base_status, battle_status; + struct status_change sc; + struct regen_data regen; + + struct s_mercenary_db *db; + struct s_mercenary mercenary; + + struct map_session_data *master; + int contract_timer; +}; + +bool merc_class(int class_); +struct view_data * merc_get_viewdata(int class_); +int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime); +int merc_data_received(struct s_mercenary *merc, bool flag); +int mercenary_save(struct mercenary_data *md); +int do_init_mercenary(void); +int merc_delete(struct mercenary_data *md, int reply); +void merc_contract_stop(struct mercenary_data *md); + +#endif /* _MERCENARY_H_ */ -- cgit v1.2.3-70-g09d2 From af7c783667e77887131d186f51fb60f7dc31b87c Mon Sep 17 00:00:00 2001 From: Skotlex Date: Thu, 19 Aug 2010 15:46:55 +0000 Subject: - Implemented usage of packets 0x7fa and 0x7f7, 0x7f8, 0x7f9. These are used for proper deletion of items as well as movement/spawn packets for Renewal clients. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14383 54d463be-8e91-2dee-dedb-b68131a5f0ec --- db/packet_db.txt | 8 +-- src/map/atcommand.c | 6 +- src/map/battle.c | 2 +- src/map/chrif.c | 4 +- src/map/clif.c | 193 ++++++++++++++++++++++++++++++++++++++------------- src/map/clif.h | 6 +- src/map/guild.c | 2 +- src/map/homunculus.c | 2 +- src/map/mail.c | 2 +- src/map/map.c | 4 +- src/map/npc.c | 2 +- src/map/pc.c | 20 +++--- src/map/pc.h | 2 +- src/map/pet.c | 6 +- src/map/script.c | 24 +++---- src/map/skill.c | 24 +++---- src/map/storage.c | 4 +- src/map/trade.c | 4 +- 18 files changed, 207 insertions(+), 108 deletions(-) (limited to 'src/map/homunculus.c') diff --git a/db/packet_db.txt b/db/packet_db.txt index 1a3803b14..4476dc946 100644 --- a/db/packet_db.txt +++ b/db/packet_db.txt @@ -1431,12 +1431,12 @@ packet_ver: 25 0x07f6,14 //2009-11-03aRagexeRE -//0x07f7,0 -//0x07f8,0 -//0x07f9,0 +0x07f7,-1 +0x07f8,-1 +0x07f9,-1 //2009-11-17aRagexeRE -//0x07fa,-1 +0x07fa,8 //2009-11-24aRagexeRE //0x07fb,25 diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 3f57beba6..6cb27551b 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -1719,7 +1719,7 @@ int atcommand_itemreset(const int fd, struct map_session_data* sd, const char* c if(log_config.enable_logs&0x400) log_pick_pc(sd, "A", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]); - pc_delitem(sd, i, sd->status.inventory[i].amount, 0); + pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0); } } clif_displaymessage(fd, msg_txt(20)); // All of your items have been removed. @@ -2678,7 +2678,7 @@ int atcommand_refine(const int fd, struct map_session_data* sd, const char* comm current_position = sd->status.inventory[i].equip; pc_unequipitem(sd, i, 3); clif_refine(fd, 0, i, sd->status.inventory[i].refine); - clif_delitem(sd, i, 1); + clif_delitem(sd, i, 1, 3); clif_additem(sd, i, 1, 0); pc_equipitem(sd, i, current_position); clif_misceffect(&sd->bl, 3); @@ -8489,7 +8489,7 @@ int atcommand_delitem(const int fd, struct map_session_data* sd, const char* com if(log_config.enable_logs&0x400) log_pick_pc(sd, "A", sd->status.inventory[item_position].nameid, -1, &sd->status.inventory[item_position]); - pc_delitem(sd, item_position, 1, 0); + pc_delitem(sd, item_position, 1, 0, 0); count++; item_position = pc_search_inventory(sd, item_id); // for next loop } diff --git a/src/map/battle.c b/src/map/battle.c index 12f16f83d..064ac3a7c 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -897,7 +897,7 @@ void battle_consume_ammo(TBL_PC*sd, int skill, int lv) } if(sd->equip_index[EQI_AMMO]>=0) //Qty check should have been done in skill_check_condition - pc_delitem(sd,sd->equip_index[EQI_AMMO],qty,0); + pc_delitem(sd,sd->equip_index[EQI_AMMO],qty,0,1); sd->state.arrow_atk = 0; } diff --git a/src/map/chrif.c b/src/map/chrif.c index 505405424..15b9bd624 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -902,7 +902,7 @@ int chrif_divorceack(int char_id, int partner_id) sd->status.partner_id = 0; for(i = 0; i < MAX_INVENTORY; i++) if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F) - pc_delitem(sd, i, 1, 0); + pc_delitem(sd, i, 1, 0, 0); } if( (sd = map_charid2sd(partner_id)) != NULL && sd->status.partner_id == char_id ) @@ -910,7 +910,7 @@ int chrif_divorceack(int char_id, int partner_id) sd->status.partner_id = 0; for(i = 0; i < MAX_INVENTORY; i++) if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F) - pc_delitem(sd, i, 1, 0); + pc_delitem(sd, i, 1, 0, 0); } return 0; diff --git a/src/map/clif.c b/src/map/clif.c index 3f4b314df..088bda13a 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -161,6 +161,24 @@ uint16 clif_getport(void) return map_port; } +#if PACKETVER >= 20071106 +static inline unsigned char clif_bl_type(struct block_list *bl) { + switch (bl->type) { + case BL_PC: return disguised(bl)?0x1:0x0; //PC_TYPE + case BL_ITEM: return 0x2; //ITEM_TYPE + case BL_SKILL: return 0x3; //SKILL_TYPE + case BL_CHAT: return 0x4; //UNKNOWN_TYPE + case BL_MOB: return 0x5; //NPC_MOB_TYPE + case BL_NPC: return 0x6; //NPC_EVT_TYPE + case BL_PET: return 0x7; //NPC_PET_TYPE + case BL_HOM: return 0x8; //NPC_HOM_TYPE + case BL_MER: return 0x9; //NPC_MERSOL_TYPE +// case BL_ELEM: return 0xA; //NPC_ELEMENTAL_TYPE + default: return 0x1; //NPC_TYPE + } +} +#endif + /*========================================== * clif_sendでAREA*指定時用 *------------------------------------------*/ @@ -751,36 +769,52 @@ static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool struct status_change* sc = status_get_sc(bl); struct view_data* vd = status_get_viewdata(bl); unsigned char *buf = WBUFP(buffer,0); +#if PACKETVER < 20091103 bool type = !pcdb_checkid(vd->class_); +#endif #if PACKETVER >= 7 unsigned short offset = 0; +#endif +#if PACKETVER >= 20091103 + const char *name; #endif sd = BL_CAST(BL_PC, bl); +#if PACKETVER < 20091103 if(type) WBUFW(buf,0) = spawn?0x7c:0x78; else +#endif #if PACKETVER < 4 WBUFW(buf,0) = spawn?0x79:0x78; #elif PACKETVER < 7 WBUFW(buf,0) = spawn?0x1d9:0x1d8; -#else +#elif PACKETVER < 20080102 WBUFW(buf,0) = spawn?0x22b:0x22a; +#elif PACKETVER < 20091103 + WBUFW(buf,0) = spawn?0x2ed:0x2ee; +#else + WBUFW(buf,0) = spawn?0x7f8:0x7f9; #endif -#if PACKETVER >= 20071106 - if (type) { - // shift payload 1 byte to the right for mob packets - WBUFB(buf,2) = 0; // padding? +#if PACKETVER >= 20091103 + name = status_get_name(bl); + WBUFW(buf,2) = (spawn?62:63)+strlen(name); + WBUFB(buf,4) = clif_bl_type(bl); + offset+=3; + buf = WBUFP(buffer,offset); +#elif PACKETVER >= 20071106 + if (type) { //Non-player packets + WBUFB(buf,2) = clif_bl_type(bl); offset++; buf = WBUFP(buffer,offset); } #endif - WBUFL(buf, 2) = bl->id; WBUFW(buf, 6) = status_get_speed(bl); WBUFW(buf, 8) = (sc)? sc->opt1 : 0; WBUFW(buf,10) = (sc)? sc->opt2 : 0; +#if PACKETVER < 20091103 if (type&&spawn) { //uses an older and different packet structure WBUFW(buf,12) = (sc)? sc->option : 0; WBUFW(buf,14) = vd->hair_style; @@ -789,14 +823,21 @@ static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client) WBUFW(buf,22) = vd->shield; } else { -#if PACKETVER >= 7 +#endif +#if PACKETVER >= 20091103 + WBUFL(buf,12) = (sc)? sc->option : 0; + offset+=2; + buf = WBUFP(buffer,offset); +#elif PACKETVER >= 7 if (!type) { WBUFL(buf,12) = (sc)? sc->option : 0; offset+=2; - buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields + buf = WBUFP(buffer,offset); } else -#endif WBUFW(buf,12) = (sc)? sc->option : 0; +#else + WBUFW(buf,12) = (sc)? sc->option : 0; +#endif WBUFW(buf,14) = vd->class_; WBUFW(buf,16) = vd->hair_style; WBUFW(buf,18) = vd->weapon; @@ -807,7 +848,9 @@ static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool WBUFW(buf,20) = vd->shield; WBUFW(buf,22) = vd->head_bottom; #endif +#if PACKETVER < 20091103 } +#endif WBUFW(buf,24) = vd->head_top; WBUFW(buf,26) = vd->head_mid; @@ -820,43 +863,57 @@ static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool WBUFW(buf,28) = vd->hair_color; WBUFW(buf,30) = vd->cloth_color; WBUFW(buf,32) = (sd)? sd->head_dir : 0; +#if PACKETVER < 20091103 if (type&&spawn) { //End of packet 0x7c WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma WBUFB(buf,35) = vd->sex; WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl)); WBUFB(buf,39) = 0; -#if PACKETVER >= 20071106 WBUFB(buf,40) = 0; -#endif -#if PACKETVER > 20081217 - WBUFB(buf,41) = 0; - WBUFB(buf,42) = 0; -#endif return packet_len(0x7c); } +#endif WBUFL(buf,34) = status_get_guild_id(bl); WBUFW(buf,38) = status_get_emblem_id(bl); WBUFW(buf,40) = (sd)? sd->status.manner : 0; -#if PACKETVER >= 7 +#if PACKETVER >= 20091103 + WBUFL(buf,42) = (sc)? sc->opt3 : 0; + offset+=2; + buf = WBUFP(buffer,offset); +#elif PACKETVER >= 7 if (!type) { WBUFL(buf,42) = (sc)? sc->opt3 : 0; offset+=2; - buf = WBUFP(buffer,offset); //Shift additional 2 bytes... + buf = WBUFP(buffer,offset); } else -#endif WBUFW(buf,42) = (sc)? sc->opt3 : 0; +#else + WBUFW(buf,42) = (sc)? sc->opt3 : 0; +#endif WBUFB(buf,44) = (sd)? sd->status.karma : 0; WBUFB(buf,45) = vd->sex; WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl)); WBUFB(buf,49) = (sd)? 5 : 0; WBUFB(buf,50) = (sd)? 5 : 0; - if (spawn) { - WBUFW(buf,51) = clif_setlevel(status_get_lv(bl)); - } else { + if (!spawn) { WBUFB(buf,51) = vd->dead_sit; - WBUFW(buf,52) = clif_setlevel(status_get_lv(bl)); + offset++; + buf = WBUFP(buffer,offset); } + WBUFW(buf,51) = clif_setlevel(status_get_lv(bl)); +#if PACKETVER < 20091103 + if (type) //End for non-player packet + return packet_len(WBUFW(buffer,0)); +#endif +#if PACKETVER >= 20080102 + WBUFW(buf,53) = sd?sd->state.user_font:0; +#endif +#if PACKETVER >= 20091103 + strcpy((char*)WBUFP(buf,55), name); + return WBUFW(buffer,2); +#else return packet_len(WBUFW(buffer,0)); +#endif } /*========================================== @@ -871,6 +928,9 @@ static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, un #if PACKETVER >= 7 unsigned short offset = 0; #endif +#if PACKETVER >= 20091103 + const char *name; +#endif sd = BL_CAST(BL_PC, bl); @@ -878,14 +938,24 @@ static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, un WBUFW(buf, 0) = 0x7b; #elif PACKETVER < 7 WBUFW(buf, 0) = 0x1da; -#else +#elif PACKETVER < 20080102 WBUFW(buf, 0) = 0x22c; +#elif PACKETVER < 20091103 + WBUFW(buf, 0) = 0x2ec; +#else + WBUFW(buf, 0) = 0x7f7; #endif +#if PACKETVER >= 20091103 + name = status_get_name(bl); + WBUFW(buf, 2) = 69+strlen(name); + offset+=2; + buf = WBUFP(buffer,offset); +#endif #if PACKETVER >= 20071106 - WBUFB(buf, 2) = 0; // padding? + WBUFB(buf, 2) = clif_bl_type(bl); offset++; - buf = WBUFP(buf,offset); + buf = WBUFP(buffer,offset); #endif WBUFL(buf, 2) = bl->id; WBUFW(buf, 6) = status_get_speed(bl); @@ -931,8 +1001,15 @@ static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, un WBUFB(buf,56) = (sd)? 5 : 0; WBUFB(buf,57) = (sd)? 5 : 0; WBUFW(buf,58) = clif_setlevel(status_get_lv(bl)); - +#if PACKETVER >= 20080102 + WBUFW(buf,60) = sd?sd->state.user_font:0; +#endif +#if PACKETVER >= 20091103 + strcpy((char*)WBUFP(buf,62), name); + return WBUFW(buffer,2); +#else return packet_len(WBUFW(buffer,0)); +#endif } //Modifies the buffer for disguise characters and sends it to self. @@ -1069,8 +1146,6 @@ int clif_spawn(struct block_list *bl) clif_specialeffect(bl,423,AREA); else if(sd->state.size==1) clif_specialeffect(bl,421,AREA); - if( sd->state.user_font ) - clif_font_area(sd); if( sd->state.bg_id && map[sd->bl.m].flag.battleground ) clif_sendbgemblem_area(sd); } @@ -1867,7 +1942,7 @@ int clif_additem(struct map_session_data *sd, int n, int amount, int fail) /*========================================== * *------------------------------------------*/ -int clif_delitem(struct map_session_data *sd,int n,int amount) +int clif_dropitem(struct map_session_data *sd,int n,int amount) { int fd; @@ -1883,6 +1958,43 @@ int clif_delitem(struct map_session_data *sd,int n,int amount) return 0; } +/*========================================== + * Deletes an item from your inventory. + * Reason values: + * 0 - Normal + * 1 - Item used for a skill + * 2 - Refine failed + * 3 - Material changed + * 4 - Moved to storage + * 5 - Moved to cart + * 6 - Item sold + * 7 - Item dropped + *------------------------------------------*/ +int clif_delitem(struct map_session_data *sd,int n,int amount, short reason) +{ +#if PACKETVER < 20091117 + return clif_dropitem(sd,n,amount); +#else + int fd; + + nullpo_retr(0, sd); + + if (reason == 7) + return clif_dropitem(sd,n,amount); + + fd=sd->fd; + + WFIFOHEAD(fd, packet_len(0x7fa)); + WFIFOW(fd,0)=0x7fa; + WFIFOW(fd,2)=reason; + WFIFOW(fd,4)=n+2; + WFIFOW(fd,6)=amount; + WFIFOSET(fd,packet_len(0x7fa)); + + return 0; +#endif +} + // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex] // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point. @@ -3702,8 +3814,6 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) clif_specialeffect_single(bl,423,sd->fd); else if(tsd->state.size==1) clif_specialeffect_single(bl,421,sd->fd); - if( tsd->state.user_font ) - clif_font_single(sd->fd,tsd); if( tsd->state.bg_id && map[tsd->bl.m].flag.battleground ) clif_sendbgemblem_single(sd->fd,tsd); } @@ -9352,7 +9462,7 @@ void clif_parse_DropItem(int fd, struct map_session_data *sd) } while (0); //Because the client does not like being ignored. - clif_delitem(sd, item_index,0); + clif_dropitem(sd, item_index,0); } /*========================================== @@ -12112,7 +12222,7 @@ void clif_parse_AutoRevive(int fd, struct map_session_data *sd) return; clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1); - pc_delitem(sd, item_position, 1, 0); + pc_delitem(sd, item_position, 1, 0, 1); } /// /check @@ -12770,7 +12880,7 @@ void clif_parse_Auction_register(int fd, struct map_session_data *sd) clif_Auction_message(fd, 4); // No Char Server? lets say something to the client else { - pc_delitem(sd, sd->auction.index, sd->auction.amount, 1); + pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6); sd->auction.amount = 0; pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour); } @@ -13547,7 +13657,7 @@ int clif_sendbgemblem_single(int fd, struct map_session_data *sd) * Custom Fonts * S 0x2ef .l .w *------------------------------------------*/ -int clif_font_area(struct map_session_data *sd) +int clif_font(struct map_session_data *sd) { unsigned char buf[8]; nullpo_retr(0,sd); @@ -13558,17 +13668,6 @@ int clif_font_area(struct map_session_data *sd) return 1; } -int clif_font_single(int fd, struct map_session_data *sd) -{ - nullpo_retr(0,sd); - WFIFOHEAD(fd,packet_len(0x2ef)); - WFIFOW(fd,0) = 0x2ef; - WFIFOL(fd,2) = sd->bl.id; - WFIFOW(fd,6) = sd->state.user_font; - WFIFOSET(fd,packet_len(0x2ef)); - return 1; -} - /*========================================== * Instancing Window *------------------------------------------*/ @@ -14108,7 +14207,7 @@ static int packetdb_readdb(void) 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54, #endif 0, 0, 0, 0, 0, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 14, 93, 86, 87, 0, 0, 0, 0, 26, 0, + 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 0, 0, 0, 26, 0, //#0x0800 -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/src/map/clif.h b/src/map/clif.h index 090ed71a2..68f36dc59 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -114,7 +114,8 @@ int clif_scriptinputstr(struct map_session_data *sd,int npcid); // self int clif_cutin(struct map_session_data* sd, const char* image, int type); //self int clif_viewpoint(struct map_session_data*,int,int,int,int,int,int); //self int clif_additem(struct map_session_data *sd, int n, int amount, int fail); // self -int clif_delitem(struct map_session_data*,int,int); //self +int clif_dropitem(struct map_session_data*,int,int); //self +int clif_delitem(struct map_session_data*,int,int,short); //self int clif_updatestatus(struct map_session_data*,int); //self int clif_changestatus(struct block_list*,int,int); //area int clif_damage(struct block_list* src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int type,int damage2); // area @@ -333,8 +334,7 @@ void clif_instance_join(int fd, int instance_id); void clif_instance_leave(int fd); // Custom Fonts -int clif_font_area(struct map_session_data *sd); -int clif_font_single(int fd, struct map_session_data *sd); +int clif_font(struct map_session_data *sd); // atcommand int clif_displaymessage(const int fd,const char* mes); diff --git a/src/map/guild.c b/src/map/guild.c index 937a90ea9..dbb59c334 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -440,7 +440,7 @@ int guild_created(int account_id,int guild_id) sd->status.guild_id=guild_id; clif_guild_created(sd,0); if(battle_config.guild_emperium_check) - pc_delitem(sd,pc_search_inventory(sd,714),1,0); // エンペリウム消耗 + pc_delitem(sd,pc_search_inventory(sd,714),1,0,0); // エンペリウム消耗 return 0; } diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 6acd969fa..b74fe2a13 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -444,7 +444,7 @@ int merc_hom_food(struct map_session_data *sd, struct homun_data *hd) clif_hom_food(sd,foodID,0); return 1; } - pc_delitem(sd,i,1,0); + pc_delitem(sd,i,1,0,0); if ( hd->homunculus.hunger >= 91 ) { merc_hom_decrease_intimacy(hd, 50); diff --git a/src/map/mail.c b/src/map/mail.c index d2dce6f17..afef81fe6 100644 --- a/src/map/mail.c +++ b/src/map/mail.c @@ -38,7 +38,7 @@ int mail_removeitem(struct map_session_data *sd, short flag) if(log_config.enable_logs&0x2000) log_pick_pc(sd, "E", sd->mail.nameid, -sd->mail.amount, &sd->status.inventory[sd->mail.index]); - pc_delitem(sd, sd->mail.index, sd->mail.amount, 1); + pc_delitem(sd, sd->mail.index, sd->mail.amount, 1, 0); } else clif_additem(sd, sd->mail.index, sd->mail.amount, 0); diff --git a/src/map/map.c b/src/map/map.c index 909566243..790c1515a 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2668,9 +2668,9 @@ int map_eraseipport(unsigned short mapindex, uint32 ip, uint16 port) } /*========================================== - * [Shinryo]: Init and free the mapcache + * [Shinryo]: Init the mapcache *------------------------------------------*/ -char *map_init_mapcache(FILE *fp) +static char *map_init_mapcache(FILE *fp) { size_t size = 0, read_size; char *buffer; diff --git a/src/map/npc.c b/src/map/npc.c index fe3318c9b..8db2036a2 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1406,7 +1406,7 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list) pc_setreg(sd,add_str("@sold_nameid")+(i<<24),(int)sd->status.inventory[idx].nameid); pc_setreg(sd,add_str("@sold_quantity")+(i<<24),qty); } - pc_delitem(sd,idx,qty,0); + pc_delitem(sd,idx,qty,0,6); } if (z > MAX_ZENY) z = MAX_ZENY; diff --git a/src/map/pc.c b/src/map/pc.c index 70a433c0e..f31442d28 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -339,7 +339,7 @@ void pc_inventory_rentals(struct map_session_data *sd) if( sd->status.inventory[i].expire_time <= time(NULL) ) { clif_rental_expired(sd->fd, sd->status.inventory[i].nameid); - pc_delitem(sd, i, sd->status.inventory[i].amount, 0); + pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0); } else { @@ -3124,7 +3124,7 @@ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip) // remember the card id to insert nameid = sd->status.inventory[idx_card].nameid; - if( pc_delitem(sd,idx_card,1,1) == 1 ) + if( pc_delitem(sd,idx_card,1,1,0) == 1 ) {// failed clif_insert_card(sd,idx_equip,idx_card,1); } @@ -3378,7 +3378,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount) /*========================================== * アイテムを減らす *------------------------------------------*/ -int pc_delitem(struct map_session_data *sd,int n,int amount,int type) +int pc_delitem(struct map_session_data *sd,int n,int amount,int type, short reason) { nullpo_retr(1, sd); @@ -3394,7 +3394,7 @@ int pc_delitem(struct map_session_data *sd,int n,int amount,int type) sd->inventory_data[n] = NULL; } if(!(type&1)) - clif_delitem(sd,n,amount); + clif_delitem(sd,n,amount,reason); if(!(type&2)) clif_updatestatus(sd,SP_WEIGHT); @@ -3442,7 +3442,7 @@ int pc_dropitem(struct map_session_data *sd,int n,int amount) if (!map_addflooritem(&sd->status.inventory[n], amount, sd->bl.m, sd->bl.x, sd->bl.y, 0, 0, 0, 2)) return 0; - pc_delitem(sd, n, amount, 0); + pc_delitem(sd, n, amount, 0, 7); return 1; } @@ -3705,7 +3705,7 @@ int pc_useitem(struct map_session_data *sd,int n) if( log_config.enable_logs&0x100 ) log_pick_pc(sd, "C", sd->status.inventory[n].nameid, -1, &sd->status.inventory[n]); - pc_delitem(sd,n,1,1); // Rental Usable Items are not deleted until expiration + pc_delitem(sd,n,1,1,0); // Rental Usable Items are not deleted until expiration } else clif_useitemack(sd,n,0,0); @@ -3826,7 +3826,7 @@ int pc_putitemtocart(struct map_session_data *sd,int idx,int amount) return 1; if( pc_cart_additem(sd,item_data,amount) == 0 ) - return pc_delitem(sd,idx,amount,0); + return pc_delitem(sd,idx,amount,0,5); return 1; } @@ -7230,7 +7230,7 @@ int pc_checkitem(struct map_session_data *sd) if( battle_config.item_check && !itemdb_available(id) ) { ShowWarning("illegal item id %d in %d[%s] inventory.\n",id,sd->bl.id,sd->status.name); - pc_delitem(sd,i,sd->status.inventory[i].amount,3); + pc_delitem(sd,i,sd->status.inventory[i].amount,3,0); continue; } if( i > j ) @@ -7409,9 +7409,9 @@ int pc_divorce(struct map_session_data *sd) for( i = 0; i < MAX_INVENTORY; i++ ) { if( sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F ) - pc_delitem(sd, i, 1, 0); + pc_delitem(sd, i, 1, 0, 0); if( p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F ) - pc_delitem(p_sd, i, 1, 0); + pc_delitem(p_sd, i, 1, 0, 0); } clif_divorced(sd, p_sd->status.name); diff --git a/src/map/pc.h b/src/map/pc.h index 1328e9367..9c8b524af 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -571,7 +571,7 @@ int pc_search_inventory(struct map_session_data *sd,int item_id); int pc_payzeny(struct map_session_data*,int); int pc_additem(struct map_session_data*,struct item*,int); int pc_getzeny(struct map_session_data*,int); -int pc_delitem(struct map_session_data*,int,int,int); +int pc_delitem(struct map_session_data*,int,int,int,short); // Special Shop System void pc_paycash(struct map_session_data *sd, int price, int points); diff --git a/src/map/pet.c b/src/map/pet.c index 3e7e55e3c..76f990455 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -445,7 +445,7 @@ int pet_recv_petdata(int account_id,struct s_pet *p,int flag) return 1; } if (!pet_birth_process(sd,p)) //Pet hatched. Delete egg. - pc_delitem(sd,i,1,0); + pc_delitem(sd,i,1,0,0); } else { pet_data_init(sd,p); if(sd->pd && sd->bl.prev != NULL) { @@ -659,7 +659,7 @@ int pet_equipitem(struct map_session_data *sd,int index) return 1; } - pc_delitem(sd,index,1,0); + pc_delitem(sd,index,1,0,0); pd->pet.equip = nameid; status_set_viewdata(&pd->bl, pd->pet.class_); //Updates view_data. clif_pet_equip_area(pd); @@ -734,7 +734,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd) clif_pet_food(sd,k,0); return 1; } - pc_delitem(sd,i,1,0); + pc_delitem(sd,i,1,0,0); if( pd->pet.hungry > 90 ) pet_set_intimate(pd, pd->pet.intimate - pd->petDB->r_full); diff --git a/src/map/script.c b/src/map/script.c index 3430db937..bf81b984f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5677,7 +5677,7 @@ BUILDIN_FUNC(delitem) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]); - pc_delitem(sd,i,amount,0); + pc_delitem(sd,i,amount,0,0); return 0; //we deleted exact amount of items. now exit } else { amount-=sd->status.inventory[i].amount; @@ -5688,7 +5688,7 @@ BUILDIN_FUNC(delitem) } //Logs - pc_delitem(sd,i,sd->status.inventory[i].amount,0); + pc_delitem(sd,i,sd->status.inventory[i].amount,0,0); } } //2nd pass @@ -5706,7 +5706,7 @@ BUILDIN_FUNC(delitem) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]); - pc_delitem(sd,i,amount,0); + pc_delitem(sd,i,amount,0,0); return 0; //we deleted exact amount of items. now exit } else { amount-=sd->status.inventory[i].amount; @@ -5715,7 +5715,7 @@ BUILDIN_FUNC(delitem) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]); - pc_delitem(sd,i,sd->status.inventory[i].amount,0); + pc_delitem(sd,i,sd->status.inventory[i].amount,0,0); } } @@ -5804,7 +5804,7 @@ BUILDIN_FUNC(delitem2) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]); - pc_delitem(sd,i,amount,0); + pc_delitem(sd,i,amount,0,0); return 0; //we deleted exact amount of items. now exit } else { amount-=sd->status.inventory[i].amount; @@ -5813,7 +5813,7 @@ BUILDIN_FUNC(delitem2) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]); - pc_delitem(sd,i,sd->status.inventory[i].amount,0); + pc_delitem(sd,i,sd->status.inventory[i].amount,0,0); } } @@ -6471,7 +6471,7 @@ BUILDIN_FUNC(successrefitem) pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below clif_refine(sd->fd,0,i,sd->status.inventory[i].refine); - clif_delitem(sd,i,1); + clif_delitem(sd,i,1,3); //Logs items, got from (N)PC scripts [Lupus] if(log_config.enable_logs&0x40) @@ -6526,7 +6526,7 @@ BUILDIN_FUNC(failedrefitem) // 精錬失敗エフェクトのパケット clif_refine(sd->fd,1,i,sd->status.inventory[i].refine); - pc_delitem(sd,i,1,0); + pc_delitem(sd,i,1,0,2); // 他の人にも失敗を通知 clif_misceffect(&sd->bl,2); } @@ -9798,7 +9798,7 @@ BUILDIN_FUNC(successremovecards) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]); - pc_delitem(sd,i,1,0); + pc_delitem(sd,i,1,0,3); //Logs items, got from (N)PC scripts [Lupus] if(log_config.enable_logs&0x40) @@ -9872,7 +9872,7 @@ BUILDIN_FUNC(failedremovecards) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]); - pc_delitem(sd,i,1,0); + pc_delitem(sd,i,1,0,2); } if(typefail == 1){ // カードのみ損失(武具を返す) int flag; @@ -9889,7 +9889,7 @@ BUILDIN_FUNC(failedremovecards) item_tmp.card[j]=0; for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++) item_tmp.card[j]=sd->status.inventory[i].card[j]; - pc_delitem(sd,i,1,0); + pc_delitem(sd,i,1,0,2); //Logs items, got from (N)PC scripts [Lupus] if(log_config.enable_logs&0x40) @@ -10566,7 +10566,7 @@ BUILDIN_FUNC(clearitem) if(log_config.enable_logs&0x40) log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]); - pc_delitem(sd, i, sd->status.inventory[i].amount, 0); + pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0); } } return 0; diff --git a/src/map/skill.c b/src/map/skill.c index e214a7f55..476008bf9 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -1681,7 +1681,7 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds //This should account for ground spells (and single target spells will be completed on castend_id) [Skotlex] type = pc_search_inventory (tsd, 7321); if (type >= 0) - pc_delitem(tsd, type, 1, 0); + pc_delitem(tsd, type, 1, 0, 1); if (type >= 0) { dmg.damage = dmg.damage2 = 0; @@ -2273,7 +2273,7 @@ static int skill_check_condition_mercenary(struct block_list *bl, int skill, int // Consume items for( i = 0; i < ARRAYLENGTH(itemid); i++ ) { - if( index[i] >= 0 ) pc_delitem(sd, index[i], amount[i], 0); + if( index[i] >= 0 ) pc_delitem(sd, index[i], amount[i], 0, 1); } if( type&2 ) @@ -8237,7 +8237,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, short skill, sh if( skill == WZ_EARTHSPIKE && sc && sc->data[SC_EARTHSCROLL] && rand()%100 > sc->data[SC_EARTHSCROLL]->val2 ) // [marquis007] ; //Do not consume item. else if( sd->status.inventory[i].expire_time == 0 ) - pc_delitem(sd,i,1,0); // Rental usable items are not consumed until expiration + pc_delitem(sd,i,1,0,0); // Rental usable items are not consumed until expiration } return 1; } @@ -8826,7 +8826,7 @@ int skill_consume_requirement( struct map_session_data *sd, short skill, short l continue; //Gemstones are checked, but not substracted from inventory. if( (n = pc_search_inventory(sd,req.itemid[i])) >= 0 ) - pc_delitem(sd,n,req.amount[i],0); + pc_delitem(sd,n,req.amount[i],0,1); } } @@ -9337,7 +9337,7 @@ void skill_repairweapon (struct map_session_data *sd, int idx) clif_skill_nodamage(&sd->bl,&target_sd->bl,sd->menuskill_id,1,1); item->attribute=0; clif_equiplist(target_sd); - pc_delitem(sd,pc_search_inventory(sd,material),1,0); + pc_delitem(sd,pc_search_inventory(sd,material),1,0,0); clif_item_repaireffect(sd,item->nameid,0); if(sd!=target_sd) clif_item_repaireffect(target_sd,item->nameid,0); @@ -9391,7 +9391,7 @@ void skill_weaponrefine (struct map_session_data *sd, int idx) per = percentrefinery [ditem->wlv][(int)item->refine]; per += (((signed int)sd->status.job_level)-50)/2; //Updated per the new kro descriptions. [Skotlex] - pc_delitem(sd, i, 1, 0); + pc_delitem(sd, i, 1, 0, 0); if (per > rand() % 100) { item->refine++; if(item->equip) { @@ -9399,7 +9399,7 @@ void skill_weaponrefine (struct map_session_data *sd, int idx) pc_unequipitem(sd,idx,3); } clif_refine(sd->fd,0,idx,item->refine); - clif_delitem(sd,idx,1); + clif_delitem(sd,idx,1,3); clif_additem(sd,idx,1,0); if (ep) pc_equipitem(sd,idx,ep); @@ -9425,7 +9425,7 @@ void skill_weaponrefine (struct map_session_data *sd, int idx) if(item->equip) pc_unequipitem(sd,idx,3); clif_refine(sd->fd,1,idx,item->refine); - pc_delitem(sd,idx,1,0); + pc_delitem(sd,idx,1,0,2); clif_misceffect(&sd->bl,2); clif_emotion(&sd->bl, 23); } @@ -10833,12 +10833,12 @@ int skill_produce_mix (struct map_session_data *sd, int skill_id, int nameid, in if(j < 0) continue; if(slot[i]==1000){ /* Star Crumb */ - pc_delitem(sd,j,1,1); + pc_delitem(sd,j,1,1,0); sc++; } if(slot[i]>=994 && slot[i]<=997 && ele==0){ /* Flame Heart . . . Great Nature */ static const int ele_table[4]={3,1,4,2}; - pc_delitem(sd,j,1,1); + pc_delitem(sd,j,1,1,0); ele=ele_table[slot[i]-994]; } } @@ -10856,7 +10856,7 @@ int skill_produce_mix (struct map_session_data *sd, int skill_id, int nameid, in if(j >= 0){ y = sd->status.inventory[j].amount; if(y>x)y=x; - pc_delitem(sd,j,y,0); + pc_delitem(sd,j,y,0,0); } else ShowError("skill_produce_mix: material item error\n"); @@ -11165,7 +11165,7 @@ int skill_arrow_create (struct map_session_data *sd, int nameid) if(index < 0 || (j = pc_search_inventory(sd,nameid)) < 0) return 1; - pc_delitem(sd,j,1,0); + pc_delitem(sd,j,1,0,0); for(i=0;istatus.inventory[index],amount) == 0 ) - pc_delitem(sd,index,amount,0); + pc_delitem(sd,index,amount,0,4); return 1; } @@ -477,7 +477,7 @@ int storage_guild_storageadd(struct map_session_data* sd, int index, int amount) // log_tostorage(sd, index, 1); if(guild_storage_additem(sd,stor,&sd->status.inventory[index],amount)==0) - pc_delitem(sd,index,amount,0); + pc_delitem(sd,index,amount,0,4); return 1; } diff --git a/src/map/trade.c b/src/map/trade.c index f7f986ac7..392acb33f 100644 --- a/src/map/trade.c +++ b/src/map/trade.c @@ -554,7 +554,7 @@ void trade_tradecommit(struct map_session_data *sd) log_pick_pc(sd, "T", sd->status.inventory[n].nameid, -(sd->deal.item[trade_i].amount), &sd->status.inventory[n]); log_pick_pc(tsd, "T", sd->status.inventory[n].nameid, sd->deal.item[trade_i].amount, &sd->status.inventory[n]); } - pc_delitem(sd, n, sd->deal.item[trade_i].amount, 1); + pc_delitem(sd, n, sd->deal.item[trade_i].amount, 1, 6); } else clif_additem(sd, n, sd->deal.item[trade_i].amount, 0); sd->deal.item[trade_i].index = 0; @@ -573,7 +573,7 @@ void trade_tradecommit(struct map_session_data *sd) log_pick_pc(tsd, "T", tsd->status.inventory[n].nameid, -(tsd->deal.item[trade_i].amount), &tsd->status.inventory[n]); log_pick_pc(sd, "T", tsd->status.inventory[n].nameid, tsd->deal.item[trade_i].amount, &tsd->status.inventory[n]); } - pc_delitem(tsd, n, tsd->deal.item[trade_i].amount, 1); + pc_delitem(tsd, n, tsd->deal.item[trade_i].amount, 1, 6); } else clif_additem(tsd, n, tsd->deal.item[trade_i].amount, 0); tsd->deal.item[trade_i].index = 0; -- cgit v1.2.3-70-g09d2 From 46afaed6555abf5cfdb979e7b1e0b3a619ee36ae Mon Sep 17 00:00:00 2001 From: Paradox924X Date: Sat, 9 Oct 2010 01:57:04 +0000 Subject: Replaced all nullpo_retr() calls which returned 0 with nullpo_ret() calls. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14414 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 10 +- src/map/battle.c | 12 +- src/map/battleground.c | 6 +- src/map/chat.c | 16 +-- src/map/clif.c | 306 ++++++++++++++++++++++++------------------------- src/map/guild.c | 56 ++++----- src/map/homunculus.c | 14 +-- src/map/intif.c | 8 +- src/map/itemdb.c | 4 +- src/map/log.c | 14 +-- src/map/mail.c | 6 +- src/map/map.c | 14 +-- src/map/mob.c | 54 ++++----- src/map/npc.c | 38 +++--- src/map/party.c | 14 +-- src/map/pc.c | 154 ++++++++++++------------- src/map/pet.c | 16 +-- src/map/quest.c | 4 +- src/map/skill.c | 134 +++++++++++----------- src/map/status.c | 26 ++--- src/map/storage.c | 34 +++--- src/map/unit.c | 44 +++---- 22 files changed, 492 insertions(+), 492 deletions(-) (limited to 'src/map/homunculus.c') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index eb1632b26..9fe589e73 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2569,7 +2569,7 @@ static int atkillmonster_sub(struct block_list *bl, va_list ap) struct mob_data *md; int flag; - nullpo_retr(0, md=(struct mob_data *)bl); + nullpo_ret(md=(struct mob_data *)bl); flag = va_arg(ap, int); if (md->guardian_data) @@ -6338,7 +6338,7 @@ int atcommand_mobsearch(const int fd, struct map_session_data* sd, const char* c *------------------------------------------*/ static int atcommand_cleanmap_sub(struct block_list *bl, va_list ap) { - nullpo_retr(0, bl); + nullpo_ret(bl); map_clearflooritem(bl->id); return 0; @@ -6860,7 +6860,7 @@ int atcommand_misceffect(const int fd, struct map_session_data* sd, const char* *------------------------------------------*/ int atcommand_mail(const int fd, struct map_session_data* sd, const char* command, const char* message) { - nullpo_retr(0,sd); + nullpo_ret(sd); #ifndef TXT_ONLY mail_openmail(sd); #endif @@ -7576,7 +7576,7 @@ static int atcommand_mutearea_sub(struct block_list *bl,va_list ap) int atcommand_mutearea(const int fd, struct map_session_data* sd, const char* command, const char* message) { int time; - nullpo_retr(0, sd); + nullpo_ret(sd); if (!message || !*message) { clif_displaymessage(fd, "Please, enter a time in minutes (usage: @mutearea/@stfu