summaryrefslogtreecommitdiff
path: root/src/map/pet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/pet.c')
-rw-r--r--src/map/pet.c179
1 files changed, 124 insertions, 55 deletions
diff --git a/src/map/pet.c b/src/map/pet.c
index 7089875c9..f933836a1 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -56,6 +56,20 @@ int pet_hungry_val(struct pet_data *pd)
return 0;
}
+void pet_set_intimate(struct pet_data *pd, int value)
+{
+ int intimate;
+ struct map_session_data *sd;
+
+ nullpo_retv(pd);
+ intimate = pd->pet.intimate;
+ sd = pd->msd;
+
+ pd->pet.intimate = value;
+ if( (intimate >= battle_config.pet_equip_min_friendly && pd->pet.intimate < battle_config.pet_equip_min_friendly) || (intimate < battle_config.pet_equip_min_friendly && pd->pet.intimate >= battle_config.pet_equip_min_friendly) )
+ status_calc_pc(sd,0);
+}
+
int pet_create_egg(struct map_session_data *sd, int item_id)
{
int pet_id = search_petDB_index(item_id, PET_EGG);
@@ -179,7 +193,7 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr data)
{
struct map_session_data *sd;
struct pet_data *pd;
- int interval,t;
+ int interval;
sd=map_id2sd(id);
if(!sd)
@@ -199,12 +213,13 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr data)
return 1; //You lost the pet already, the rest is irrelevant.
pd->pet.hungry--;
- t = pd->pet.intimate;
- if(pd->pet.hungry < 0) {
+ if( pd->pet.hungry < 0 )
+ {
pet_stop_attack(pd);
pd->pet.hungry = 0;
- pd->pet.intimate -= battle_config.pet_hungry_friendly_decrease;
- if(pd->pet.intimate <= 0) {
+ pet_set_intimate(pd, pd->pet.intimate - battle_config.pet_hungry_friendly_decrease);
+ if( pd->pet.intimate <= 0 )
+ {
pd->pet.intimate = 0;
pd->status.speed = pd->db->status.speed;
}
@@ -291,13 +306,9 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
map_addflooritem(&tmp_item,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
}
pd->pet.incuvate = 1;
- //No need, pet is saved on unit_free below.
- //intif_save_petdata(sd->status.account_id,&pd->pet);
- if(pd->state.skillbonus) {
- pd->state.skillbonus = 0;
- status_calc_pc(sd,0);
- }
unit_free(&pd->bl,0);
+
+ status_calc_pc(sd,0);
sd->status.pet_id = 0;
return 1;
@@ -358,7 +369,9 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
pd->last_thinktime = gettick();
pd->state.skillbonus = 0;
if( battle_config.pet_status_support )
- run_script(pet_db[i].script,0,sd->bl.id,0);
+ run_script(pet_db[i].pet_script,0,sd->bl.id,0);
+ if( pd->petDB && pd->petDB->equip_script )
+ status_calc_pc(sd,0);
if( battle_config.pet_hungry_delay_rate != 100 )
interval = (pd->petDB->hungry_delay*battle_config.pet_hungry_delay_rate)/100;
@@ -686,21 +699,22 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
clif_additem(sd,0,0,flag);
map_addflooritem(&tmp_item,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
}
- if (battle_config.pet_equip_required)
- { //Skotlex: halt support timers if needed
- if(pd->state.skillbonus) {
+ if( battle_config.pet_equip_required )
+ { // Skotlex: halt support timers if needed
+ if( pd->state.skillbonus )
+ {
pd->state.skillbonus = 0;
status_calc_pc(sd,0);
}
- if (pd->s_skill && pd->s_skill->timer != -1)
+ if( pd->s_skill && pd->s_skill->timer != -1 )
{
- if (pd->s_skill->id)
+ if( pd->s_skill->id )
delete_timer(pd->s_skill->timer, pet_skill_support_timer);
else
delete_timer(pd->s_skill->timer, pet_heal_timer);
pd->s_skill->timer = INVALID_TIMER;
}
- if (pd->bonus && pd->bonus->timer != -1)
+ if( pd->bonus && pd->bonus->timer != -1 )
{
delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
pd->bonus->timer = INVALID_TIMER;
@@ -722,30 +736,33 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
}
pc_delitem(sd,i,1,0);
- if(pd->pet.hungry > 90)
- pd->pet.intimate -= pd->petDB->r_full;
- else {
- if(battle_config.pet_friendly_rate != 100)
+ if( pd->pet.hungry > 90 )
+ pet_set_intimate(pd, pd->pet.intimate - pd->petDB->r_full);
+ else
+ {
+ if( battle_config.pet_friendly_rate != 100 )
k = (pd->petDB->r_hungry * battle_config.pet_friendly_rate)/100;
else
k = pd->petDB->r_hungry;
- if(pd->pet.hungry > 75) {
+ if( pd->pet.hungry > 75 )
+ {
k = k >> 1;
- if(k <= 0)
+ if( k <= 0 )
k = 1;
}
- pd->pet.intimate += k;
+ pet_set_intimate(pd, pd->pet.intimate + k);
}
- if(pd->pet.intimate <= 0) {
+ if( pd->pet.intimate <= 0 )
+ {
pd->pet.intimate = 0;
pet_stop_attack(pd);
pd->status.speed = pd->db->status.speed;
}
- else if(pd->pet.intimate > 1000)
+ else if( pd->pet.intimate > 1000 )
pd->pet.intimate = 1000;
status_calc_pet(pd, 0);
pd->pet.hungry += pd->petDB->fullness;
- if(pd->pet.hungry > 100)
+ if( pd->pet.hungry > 100 )
pd->pet.hungry = 100;
clif_send_petdata(sd,pd,2,pd->pet.hungry);
@@ -1185,10 +1202,18 @@ int read_petdb()
// Remove any previous scripts in case reloaddb was invoked.
for( j = 0; j < MAX_PET_DB; j++ )
- if (pet_db[j].script) {
- script_free_code(pet_db[j].script);
- pet_db[j].script = NULL;
+ {
+ if( pet_db[j].pet_script )
+ {
+ script_free_code(pet_db[j].pet_script);
+ pet_db[j].pet_script = NULL;
}
+ if( pet_db[j].equip_script )
+ {
+ script_free_code(pet_db[j].equip_script);
+ pet_db[j].pet_script = NULL;
+ }
+ }
// clear database
memset(pet_db,0,sizeof(pet_db));
@@ -1211,30 +1236,63 @@ int read_petdb()
lines = 0;
while( fgets(line, sizeof(line), fp) && j < MAX_PET_DB )
{
- char *str[32],*p,*np;
-
+ char *str[22], *p;
lines++;
if(line[0] == '/' && line[1] == '/')
continue;
+ memset(str, 0, sizeof(str));
+ p = line;
+ while( ISSPACE(*p) )
+ ++p;
+ if( *p == '\0' )
+ continue; // empty line
+ for( k = 0; k < 20; ++k )
+ {
+ str[k] = p;
+ p = strchr(p,',');
+ if( p == NULL )
+ break; // comma not found
+ *p = '\0';
+ ++p;
+ }
- // split string into table columns
- for(k=0,p=line;k<20;k++){
- if((np=strchr(p,','))!=NULL){
- str[k]=p;
- *np=0;
- p=np+1;
- } else {
- str[k]=p;
- p+=strlen(p);
- }
+ if( p == NULL )
+ {
+ ShowError("read_petdb: Insufficient columns in line %d, skipping.\n", lines);
+ continue;
+ }
+
+ // Pet Script
+ if( *p != '{' )
+ {
+ ShowError("read_petdb: Invalid format (Pet Script column) in line %d, skipping.\n", lines);
+ continue;
+ }
+
+ str[20] = p;
+ p = strstr(p+1,"},");
+ if( p == NULL )
+ {
+ ShowError("read_petdb: Invalid format (Pet Script column) in line %d, skipping.\n", lines);
+ continue;
+ }
+ p[1] = '\0';
+ p += 2;
+
+ // Equip Script
+ if( *p != '{' )
+ {
+ ShowError("read_petdb: Invalid format (Equip Script column) in line %d, skipping.\n", lines);
+ continue;
}
+ str[21] = p;
- nameid=atoi(str[0]);
- if(nameid<=0)
+ if( (nameid = atoi(str[0])) <= 0 )
continue;
- if (!mobdb_checkid(nameid)) {
+ if( !mobdb_checkid(nameid) )
+ {
ShowWarning("pet_db reading: Invalid mob-class %d, pet not read.\n", nameid);
continue;
}
@@ -1249,7 +1307,7 @@ int read_petdb()
pet_db[j].fullness=atoi(str[7]);
pet_db[j].hungry_delay=atoi(str[8])*1000;
pet_db[j].r_hungry=atoi(str[9]);
- if(pet_db[j].r_hungry <= 0)
+ if( pet_db[j].r_hungry <= 0 )
pet_db[j].r_hungry=1;
pet_db[j].r_full=atoi(str[10]);
pet_db[j].intimate=atoi(str[11]);
@@ -1261,10 +1319,14 @@ int read_petdb()
pet_db[j].attack_rate=atoi(str[17]);
pet_db[j].defence_attack_rate=atoi(str[18]);
pet_db[j].change_target_rate=atoi(str[19]);
- pet_db[j].script = NULL;
- if((np=strchr(p,'{'))==NULL)
- continue;
- pet_db[j].script = parse_script(np, filename[i], lines, 0);
+ pet_db[j].pet_script = NULL;
+ pet_db[j].equip_script = NULL;
+
+ if( *str[20] )
+ pet_db[j].pet_script = parse_script(str[20], filename[i], lines, 0);
+ if( *str[21] )
+ pet_db[j].equip_script = parse_script(str[21], filename[i], lines, 0);
+
j++;
}
@@ -1301,10 +1363,17 @@ int do_init_pet(void)
int do_final_pet(void)
{
int i;
- for( i = 0; i < MAX_PET_DB; i++ ) {
- if(pet_db[i].script) {
- script_free_code(pet_db[i].script);
- pet_db[i].script = NULL;
+ for( i = 0; i < MAX_PET_DB; i++ )
+ {
+ if( pet_db[i].pet_script )
+ {
+ script_free_code(pet_db[i].pet_script);
+ pet_db[i].pet_script = NULL;
+ }
+ if( pet_db[i].equip_script )
+ {
+ script_free_code(pet_db[i].equip_script);
+ pet_db[i].equip_script = NULL;
}
}
ers_destroy(item_drop_ers);