Fixed item bonus bAddMaxWeight (fixes #1761)

* Stored bAddMaxWeight into it's own variable for later calculation.
* Created enum constants for status_calc_weight and status_calc_cart_weight for easier readability.
This commit is contained in:
aleos89 2016-12-01 13:00:38 -05:00
parent ac2ba09415
commit c05808a305
5 changed files with 30 additions and 20 deletions

View File

@ -3220,7 +3220,7 @@ static bool intif_parse_StorageReceived(int fd)
status_set_viewdata(&sd->bl, sd->status.class_);
pc_load_combo(sd);
status_calc_pc(sd, (enum e_status_calc_opt)(SCO_FIRST|SCO_FORCE));
status_calc_weight(sd, 1|2); // Refresh item weight data
status_calc_weight(sd, CALCWT_ITEM|CALCWT_MAXBONUS); // Refresh weight data
chrif_scdata_request(sd->status.account_id, sd->status.char_id);
break;
}

View File

@ -3024,7 +3024,7 @@ void pc_bonus(struct map_session_data *sd,int type,int val)
#endif
case SP_ADDMAXWEIGHT:
if (sd->state.lr_flag != 2)
sd->max_weight += val;
sd->add_max_weight += val;
break;
case SP_ABSORB_DMG_MAXHP: // bonus bAbsorbDmgMaxHP,n;
sd->bonus.absorb_dmg_maxhp = max(sd->bonus.absorb_dmg_maxhp, val);
@ -11464,7 +11464,7 @@ void pc_scdata_received(struct map_session_data *sd) {
if (pc_iscarton(sd)) {
sd->cart_weight_max = 0; // Force a client refesh
status_calc_cart_weight(sd, 1|2|4);
status_calc_cart_weight(sd, CALCWT_ITEM|CALCWT_MAXBONUS|CALCWT_CARTSTATE);
}
}

View File

@ -282,7 +282,7 @@ struct map_session_data {
struct item_data* inventory_data[MAX_INVENTORY]; // direct pointers to itemdb entries (faster than doing item_id lookups)
short equip_index[EQI_MAX];
unsigned int weight,max_weight;
unsigned int weight,max_weight,add_max_weight;
int cart_weight,cart_num,cart_weight_max;
int fd;
unsigned short mapindex;

View File

@ -3118,11 +3118,11 @@ static unsigned int status_calc_maxhpsp_pc(struct map_session_data* sd, unsigned
* Calculates player's weight
* @param sd: Player object
* @param flag: Calculation type
* 1 - Item weight
* 2 - Skill/Status/Configuration max weight bonus
* CALCWT_ITEM - Item weight
* CALCWT_MAXBONUS - Skill/Status/Configuration max weight bonus
* @return false - failed, true - success
*/
bool status_calc_weight(struct map_session_data *sd, uint8 flag)
bool status_calc_weight(struct map_session_data *sd, enum e_status_calc_weight_opt flag)
{
int b_weight, b_max_weight, skill, i;
struct status_change *sc;
@ -3134,7 +3134,7 @@ bool status_calc_weight(struct map_session_data *sd, uint8 flag)
b_weight = sd->weight; // Store current weight for later comparison
sd->max_weight = job_info[pc_class2idx(sd->status.class_)].max_weight_base + sd->status.str * 300; // Recalculate max weight
if (flag&1) {
if (flag&CALCWT_ITEM) {
sd->weight = 0; // Reset current weight
for(i = 0; i < MAX_INVENTORY; i++) {
@ -3144,8 +3144,9 @@ bool status_calc_weight(struct map_session_data *sd, uint8 flag)
}
}
if (flag&2) {
if (flag&CALCWT_MAXBONUS) {
// Skill/Status bonus weight increases
sd->max_weight += sd->add_max_weight; // From bAddMaxWeight
if ((skill = pc_checkskill(sd, MC_INCCARRY)) > 0)
sd->max_weight += 2000 * skill;
if (pc_isriding(sd) && pc_checkskill(sd, KN_RIDING) > 0)
@ -3173,24 +3174,24 @@ bool status_calc_weight(struct map_session_data *sd, uint8 flag)
* Calculates player's cart weight
* @param sd: Player object
* @param flag: Calculation type
* 1 - Cart item weight
* 2 - Skill/Status/Configuration max weight bonus
* 4 - Whether to check for cart status
* CALCWT_ITEM - Cart item weight
* CALCWT_MAXBONUS - Skill/Status/Configuration max weight bonus
* CALCWT_CARTSTATE - Whether to check for cart state
* @return false - failed, true - success
*/
bool status_calc_cart_weight(struct map_session_data *sd, uint8 flag)
bool status_calc_cart_weight(struct map_session_data *sd, enum e_status_calc_weight_opt flag)
{
int b_cart_weight_max, i;
nullpo_retr(false, sd);
if (!pc_iscarton(sd) && !(flag&4))
if (!pc_iscarton(sd) && !(flag&CALCWT_CARTSTATE))
return false;
b_cart_weight_max = sd->cart_weight_max; // Store cart max weight for later comparison
sd->cart_weight_max = battle_config.max_cart_weight; // Recalculate max weight
if (flag&1) {
if (flag&CALCWT_ITEM) {
sd->cart_weight = 0; // Reset current cart weight
sd->cart_num = 0; // Reset current cart item count
@ -3203,7 +3204,7 @@ bool status_calc_cart_weight(struct map_session_data *sd, uint8 flag)
}
// Skill bonus max weight increases
if (flag&2)
if (flag&CALCWT_MAXBONUS)
sd->cart_weight_max += (pc_checkskill(sd, GN_REMODELING_CART) * 5000);
// Update the client if the new weight calculations don't match
@ -3258,6 +3259,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt)
sd->critical_rate = sd->hit_rate = sd->flee_rate = sd->flee2_rate = 100;
sd->def_rate = sd->def2_rate = sd->mdef_rate = sd->mdef2_rate = 100;
sd->regen.state.block = 0;
sd->add_max_weight = 0;
// Zeroed arrays, order follows the order in pc.h.
// Add new arrays to the end of zeroed area in pc.h (see comments) and size here. [zzo]
@ -3938,8 +3940,8 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt)
// ----- MISC CALCULATIONS -----
// Weight
status_calc_weight(sd, 2);
status_calc_cart_weight(sd, 2);
status_calc_weight(sd, CALCWT_MAXBONUS);
status_calc_cart_weight(sd, CALCWT_MAXBONUS);
if (pc_checkskill(sd,SM_MOVINGRECOVERY)>0)
sd->regen.state.walk = 1;

View File

@ -2003,6 +2003,14 @@ enum e_status_bonus {
STATUS_BONUS_RATE = 1,
};
/// Enum for status_calc_weight and status_calc_cart_weight
enum e_status_calc_weight_opt {
CALCWT_NONE = 0x0,
CALCWT_ITEM = 0x1, ///< Recalculate item weight
CALCWT_MAXBONUS = 0x2, ///< Recalculate max weight based on skill/status/configuration bonuses
CALCWT_CARTSTATE = 0x4, ///< Whether to check for cart state
};
///Define to determine who gets HP/SP consumed on doing skills/etc. [Skotlex]
#define BL_CONSUME (BL_PC|BL_HOM|BL_MER|BL_ELEM)
///Define to determine who has regen
@ -2277,8 +2285,8 @@ void status_change_clear_onChangeMap(struct block_list *bl, struct status_change
#define status_calc_elemental(ed, opt) status_calc_bl_(&(ed)->bl, SCB_ALL, opt)
#define status_calc_npc(nd, opt) status_calc_bl_(&(nd)->bl, SCB_ALL, opt)
bool status_calc_weight(struct map_session_data *sd, uint8 flag);
bool status_calc_cart_weight(struct map_session_data *sd, uint8 flag);
bool status_calc_weight(struct map_session_data *sd, enum e_status_calc_weight_opt flag);
bool status_calc_cart_weight(struct map_session_data *sd, enum e_status_calc_weight_opt flag);
void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_calc_opt opt);
int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt);
void status_calc_pet_(struct pet_data* pd, enum e_status_calc_opt opt);