Skip to content

Commit

Permalink
Modified status_calc_* to support multiple options. (Hercules 6f77d07)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleos89 committed May 20, 2014
1 parent 2688d78 commit 2732176
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 241 deletions.
16 changes: 9 additions & 7 deletions src/map/atcommand.c
Expand Up @@ -1398,6 +1398,7 @@ ACMD_FUNC(baselevelup)

sd->status.status_point += status_point;
sd->status.base_level += (unsigned int)level;
status_calc_pc(sd, SCO_FORCE);
status_percent_heal(&sd->bl, 100, 100);
clif_misceffect(&sd->bl, 0);
clif_displaymessage(fd, msg_txt(sd,21)); // Base level raised.
Expand All @@ -1419,13 +1420,13 @@ ACMD_FUNC(baselevelup)
sd->status.status_point -= status_point;
sd->status.base_level -= (unsigned int)level;
clif_displaymessage(fd, msg_txt(sd,22)); // Base level lowered.
status_calc_pc(sd, SCO_FORCE);
}
sd->status.base_exp = 0;
clif_updatestatus(sd, SP_STATUSPOINT);
clif_updatestatus(sd, SP_BASELEVEL);
clif_updatestatus(sd, SP_BASEEXP);
clif_updatestatus(sd, SP_NEXTBASEEXP);
status_calc_pc(sd, 0);
pc_baselevelchanged(sd);
if(sd->status.party_id)
party_send_levelup(sd);
Expand Down Expand Up @@ -1479,7 +1480,7 @@ ACMD_FUNC(joblevelup)
clif_updatestatus(sd, SP_JOBEXP);
clif_updatestatus(sd, SP_NEXTJOBEXP);
clif_updatestatus(sd, SP_SKILLPOINT);
status_calc_pc(sd, 0);
status_calc_pc(sd, SCO_FORCE);

return 0;
}
Expand Down Expand Up @@ -2539,7 +2540,7 @@ ACMD_FUNC(param)
*status[i] = new_value;
clif_updatestatus(sd, SP_STR + i);
clif_updatestatus(sd, SP_USTR + i);
status_calc_pc(sd, 0);
status_calc_pc(sd, SCO_FORCE);
clif_displaymessage(fd, msg_txt(sd,42)); // Stat changed.
} else {
if (value < 0)
Expand Down Expand Up @@ -2610,7 +2611,7 @@ ACMD_FUNC(stat_all)
}

if (count > 0) { // if at least 1 stat modified
status_calc_pc(sd, 0);
status_calc_pc(sd, SCO_FORCE);
clif_displaymessage(fd, msg_txt(sd,84)); // All stats changed!
} else {
if (value < 0)
Expand Down Expand Up @@ -7146,13 +7147,14 @@ ACMD_FUNC(homlevel)

for (i = 1; i <= level && hd->exp_next; i++){
hd->homunculus.exp += hd->exp_next;
if( !hom_levelup(hd) ){
if( !hom_levelup(hd) )
break;
}
}
status_calc_homunculus(hd,0);

status_calc_homunculus(hd, SCO_NONE);
status_percent_heal(&hd->bl, 100, 100);
clif_specialeffect(&hd->bl,568,AREA);

return 0;
}

Expand Down
39 changes: 27 additions & 12 deletions src/map/battle.c
Expand Up @@ -213,16 +213,22 @@ struct delay_damage {
enum damage_lv dmg_lv;
unsigned short attack_type;
bool additional_effects;
enum bl_type src_type;
};

int battle_delay_damage_sub(int tid, unsigned int tick, int id, intptr_t data) {
struct delay_damage *dat = (struct delay_damage *)data;

if ( dat ) {
struct block_list* src;
struct block_list* src = NULL;
struct block_list* target = map_id2bl(dat->target_id);

if( !target || status_isdead(target) ) {/* nothing we can do */
if( !target || status_isdead(target) ) { /* Nothing we can do */
if( dat->src_type == BL_PC && (src = map_id2bl(dat->src_id)) &&
--((TBL_PC*)src)->delayed_damage == 0 && ((TBL_PC*)src)->state.hold_recalc ) {
((TBL_PC*)src)->state.hold_recalc = 0;
status_calc_pc(((TBL_PC*)src), SCO_FORCE);
}
ers_free(delay_damage_ers, dat);
return 0;
}
Expand All @@ -248,12 +254,17 @@ int battle_delay_damage_sub(int tid, unsigned int tick, int id, intptr_t data) {
status_fix_damage(target, target, dat->damage, dat->delay);
map_freeblock_unlock();
}

if( src && src->type == BL_PC && --((TBL_PC*)src)->delayed_damage == 0 && ((TBL_PC*)src)->state.hold_recalc ) {
((TBL_PC*)src)->state.hold_recalc = 0;
status_calc_pc(((TBL_PC*)src), SCO_FORCE);
}
}
ers_free(delay_damage_ers, dat);
return 0;
}

int battle_delay_damage (unsigned int tick, int amotion, struct block_list *src, struct block_list *target, int attack_type, uint16 skill_id, uint16 skill_lv, int64 damage, enum damage_lv dmg_lv, int ddelay, bool additional_effects)
int battle_delay_damage(unsigned int tick, int amotion, struct block_list *src, struct block_list *target, int attack_type, uint16 skill_id, uint16 skill_lv, int64 damage, enum damage_lv dmg_lv, int ddelay, bool additional_effects)
{
struct delay_damage *dat;
struct status_change *sc;
Expand Down Expand Up @@ -286,18 +297,24 @@ int battle_delay_damage (unsigned int tick, int amotion, struct block_list *src,
dat->delay = ddelay;
dat->distance = distance_bl(src, target)+10; //Attack should connect regardless unless you teleported.
dat->additional_effects = additional_effects;
dat->src_type = src->type;
if (src->type != BL_PC && amotion > 1000)
amotion = 1000; //Aegis places a damage-delay cap of 1 sec to non player attacks. [Skotlex]

if( src->type == BL_PC )
((TBL_PC*)src)->delayed_damage++;

add_timer(tick+amotion, battle_delay_damage_sub, 0, (intptr_t)dat);

return 0;
}
int battle_attr_ratio(int atk_elem,int def_type, int def_lv){

int battle_attr_ratio(int atk_elem,int def_type, int def_lv) {
if (atk_elem < ELE_NEUTRAL || atk_elem >= ELE_ALL)
return 100;
if (def_type < ELE_NEUTRAL || def_type > ELE_ALL || def_lv < 1 || def_lv > 4)
return 100;

return attr_fix_table[def_lv-1][atk_elem][def_type];
}

Expand Down Expand Up @@ -2569,12 +2586,10 @@ struct Damage battle_calc_damage_parts(struct Damage wd, struct block_list *src,
wd.statusAtk += battle_calc_status_attack(sstatus, EQI_HAND_R);
wd.statusAtk2 += battle_calc_status_attack(sstatus, EQI_HAND_L);

if (skill_id || (sd && sd->sc.data[SC_SEVENWIND])) {
// Mild Wind applies element to status ATK as well as weapon ATK [helvetica]
if (skill_id || (sd && sd->sc.data[SC_SEVENWIND])) { // Mild Wind applies element to status ATK as well as weapon ATK [helvetica]
wd.statusAtk = (int)battle_attr_fix(src, target, wd.statusAtk, right_element, tstatus->def_ele, tstatus->ele_lv);
wd.statusAtk2 = (int)battle_attr_fix(src, target, wd.statusAtk, left_element, tstatus->def_ele, tstatus->ele_lv);
}
else { // status atk is considered neutral on normal attacks [helvetica]
} else { // status atk is considered neutral on normal attacks [helvetica]
wd.statusAtk = (int)battle_attr_fix(src, target, wd.statusAtk, ELE_NEUTRAL, tstatus->def_ele, tstatus->ele_lv);
wd.statusAtk2 = (int)battle_attr_fix(src, target, wd.statusAtk, ELE_NEUTRAL, tstatus->def_ele, tstatus->ele_lv);
}
Expand Down Expand Up @@ -4775,6 +4790,7 @@ void battle_do_reflect(int attack_type, struct Damage *wd, struct block_list* sr
}
}
}

/*============================================
* Calculate "weapon"-type attacks and skills
*--------------------------------------------
Expand Down Expand Up @@ -5886,7 +5902,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *

memset(&md,0,sizeof(md));

if( src == NULL || target == NULL ){
if (src == NULL || target == NULL) {
nullpo_info(NLP_MARK);
return md;
}
Expand Down Expand Up @@ -5918,8 +5934,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
//Skill Range Criteria
md.flag |= battle_range_type(src, target, skill_id, skill_lv);

switch( skill_id )
{
switch (skill_id) {
case NC_MAGMA_ERUPTION:
md.damage = 1200 + 400 * skill_lv;
break;
Expand Down Expand Up @@ -7281,7 +7296,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
if(s_guild && t_guild && (s_guild == t_guild || (!(flag&BCT_SAMEGUILD) && guild_isallied(s_guild, t_guild))))
state |= BCT_GUILD;
}
} //end non pvp/gvg chk rivality
} //end non pvp/gvg chk rivality

if( !state ) //If not an enemy, nor a guild, nor party, nor yourself, it's neutral.
state = BCT_NEUTRAL;
Expand Down
2 changes: 1 addition & 1 deletion src/map/chrif.c
Expand Up @@ -1897,7 +1897,7 @@ int chrif_load_bsdata(int fd) {
calc = true;
}
if (calc)
status_calc_pc(sd,false);
status_calc_pc(sd,SCO_NONE);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/map/clif.c
Expand Up @@ -9758,7 +9758,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
}

map_iwall_get(sd); // Updates Walls Info on this Map to Client
status_calc_pc(sd, false); // Some conditions are map-dependent so we must recalculate
status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
sd->state.changemap = false;

// Instances do not need their own channels
Expand Down
2 changes: 1 addition & 1 deletion src/map/elemental.c
Expand Up @@ -263,7 +263,7 @@ int elemental_data_received(struct s_elemental *ele, bool flag) {
ed->bl.y = ed->ud.to_y;

map_addiddb(&ed->bl);
status_calc_elemental(ed,1);
status_calc_elemental(ed,SCO_FIRST);
ed->last_spdrain_time = ed->last_thinktime = gettick();
ed->summon_timer = INVALID_TIMER;
ed->masterteleport_timer = INVALID_TIMER;
Expand Down
2 changes: 1 addition & 1 deletion src/map/guild.c
Expand Up @@ -1876,7 +1876,7 @@ int guild_castledatasave(int castle_id, int index, int value) {
for (i = 0; i < MAX_GUARDIANS; i++){
struct mob_data *gd;
if (gc->guardian[i].visible && (gd = map_id2md(gc->guardian[i].id)) != NULL)
status_calc_mob(gd, 0);
status_calc_mob(gd, SCO_NONE);
}
break;
}
Expand Down
19 changes: 10 additions & 9 deletions src/map/homunculus.c
Expand Up @@ -300,7 +300,7 @@ void hom_skillup(struct homun_data *hd,uint16 skill_id)
{
hd->homunculus.hskill[i].lv++;
hd->homunculus.skillpts-- ;
status_calc_homunculus(hd,0);
status_calc_homunculus(hd, SCO_NONE);
if (hd->master) {
clif_homskillup(hd->master, skill_id);
clif_hominfo(hd->master,hd,0);
Expand Down Expand Up @@ -417,8 +417,7 @@ int hom_evolution(struct homun_data *hd)
struct map_session_data *sd;
nullpo_ret(hd);

if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class)
{
if(!hd->homunculusDB->evo_class || hd->homunculus.class_ == hd->homunculusDB->evo_class) {
clif_emotion(&hd->bl, E_SWT);
return 0 ;
}
Expand Down Expand Up @@ -456,7 +455,7 @@ int hom_evolution(struct homun_data *hd)
//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);
status_calc_homunculus(hd, SCO_FIRST);

if (!(battle_config.hom_setting&0x2))
skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
Expand Down Expand Up @@ -510,7 +509,7 @@ int hom_mutate(struct homun_data *hd, int homun_id)
hom->hp = hd->battle_status.hp;
hom->sp = hd->battle_status.sp;
hom->prev_class = prev_class;
status_calc_homunculus(hd,1);
status_calc_homunculus(hd, SCO_FIRST);

if (!(battle_config.hom_setting&0x2))
skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
Expand Down Expand Up @@ -556,7 +555,7 @@ int hom_gainexp(struct homun_data *hd,int exp)
hd->homunculus.exp = 0 ;

clif_specialeffect(&hd->bl,568,AREA);
status_calc_homunculus(hd,0);
status_calc_homunculus(hd, SCO_NONE);
status_percent_heal(&hd->bl, 100, 100);
return 0;
}
Expand Down Expand Up @@ -785,7 +784,8 @@ int hom_search(int key,int type)
}

// Create homunc structure
void hom_alloc(struct map_session_data *sd, struct s_homunculus *hom) {
void hom_alloc(struct map_session_data *sd, struct s_homunculus *hom)
{
struct homun_data *hd;
int i = 0;

Expand Down Expand Up @@ -823,7 +823,8 @@ void hom_alloc(struct map_session_data *sd, struct s_homunculus *hom) {
hd->bl.y = hd->ud.to_y;

map_addiddb(&hd->bl);
status_calc_homunculus(hd,1);
status_calc_homunculus(hd, SCO_FIRST);
status_percent_heal(&hd->bl, 100, 100);

hd->hungry_timer = INVALID_TIMER;
hd->masterteleport_timer = INVALID_TIMER;
Expand Down Expand Up @@ -1093,7 +1094,7 @@ int hom_shuffle(struct homun_data *hd)
memcpy(&hd->homunculus.hskill, &b_skill, sizeof(b_skill));
hd->homunculus.skillpts = skillpts;
clif_homskillinfoblock(sd);
status_calc_homunculus(hd,0);
status_calc_homunculus(hd, SCO_NONE);
status_percent_heal(&hd->bl, 100, 100);
clif_specialeffect(&hd->bl,568,AREA);

Expand Down
3 changes: 1 addition & 2 deletions src/map/itemdb.c
Expand Up @@ -1753,14 +1753,13 @@ void itemdb_reload(void) {
sd->combos.id = NULL;
sd->combos.count = 0;
if( pc_load_combo(sd) > 0 )
status_calc_pc(sd,0);
status_calc_pc(sd, SCO_FORCE);
}

}
mapit_free(iter);
}


/**
* Finalizing Item DB
*/
Expand Down
18 changes: 7 additions & 11 deletions src/map/mercenary.c
Expand Up @@ -341,23 +341,22 @@ void merc_contract_init(struct mercenary_data *md) {
* @param flag : if inter-serv request was sucessfull
* @return false:failure, true:sucess
*/
bool mercenary_recv_data(struct s_mercenary *merc, bool flag){
bool mercenary_recv_data(struct s_mercenary *merc, bool flag)
{
struct map_session_data *sd;
struct mercenary_data *md;
struct s_mercenary_db *db;
int i = mercenary_search_index(merc->class_);

if( (sd = map_charid2sd(merc->char_id)) == NULL )
return false;
if( !flag || i < 0 )
{ // Not created - loaded - DB info
if( !flag || i < 0 ) { // Not created - loaded - DB info
sd->status.mer_id = 0;
return false;
}

db = &mercenary_db[i];
if( !sd->md )
{
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();
Expand All @@ -379,13 +378,11 @@ bool mercenary_recv_data(struct s_mercenary *merc, bool flag){
md->bl.y = md->ud.to_y;

map_addiddb(&md->bl);
status_calc_mercenary(md,1);
status_calc_mercenary(md, SCO_FIRST);
md->contract_timer = INVALID_TIMER;
md->masterteleport_timer = INVALID_TIMER;
merc_contract_init(md);
}
else
{
} else {
memcpy(&sd->md->mercenary, merc, sizeof(struct s_mercenary));
md = sd->md;
}
Expand All @@ -394,8 +391,7 @@ bool mercenary_recv_data(struct s_mercenary *merc, bool flag){
mercenary_set_calls(md, 1);
sd->status.mer_id = merc->mercenary_id;

if( md && md->bl.prev == NULL && sd->bl.prev != NULL )
{
if( md && md->bl.prev == NULL && sd->bl.prev != NULL ) {
if(map_addblock(&md->bl))
return false;
clif_spawn(&md->bl);
Expand Down

0 comments on commit 2732176

Please sign in to comment.