diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/battle.cpp | 33 | ||||
-rw-r--r-- | src/map/clif.cpp | 46 | ||||
-rw-r--r-- | src/map/magic-expr.cpp | 7 | ||||
-rw-r--r-- | src/map/map.hpp | 2 | ||||
-rw-r--r-- | src/map/pc.cpp | 71 | ||||
-rw-r--r-- | src/map/script.cpp | 16 |
6 files changed, 94 insertions, 81 deletions
diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 49a0538..75ae4f0 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -1306,8 +1306,9 @@ int battle_is_unarmed(dumb_ptr<block_list> bl) { dumb_ptr<map_session_data> sd = bl->is_player(); - return (sd->equip_index[EQUIP::SHIELD] == -1 - && sd->equip_index[EQUIP::WEAPON] == -1); + int sidx = sd->equip_index_maybe[EQUIP::SHIELD]; + int widx = sd->equip_index_maybe[EQUIP::WEAPON]; + return sidx == -1 && widx == -1; } else return 0; @@ -1426,15 +1427,14 @@ struct Damage battle_calc_pc_weapon_attack(dumb_ptr<block_list> src, atkmin = atkmin_ = dex; //最低ATKはDEXで初期化? sd->state.arrow_atk = 0; //arrow_atk初期化 - if (sd->equip_index[EQUIP::WEAPON] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]) - atkmin = - atkmin * (80 + - sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->wlv * 20) / 100; - if (sd->equip_index[EQUIP::SHIELD] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]) - atkmin_ = - atkmin_ * (80 + - sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->wlv * 20) / - 100; + + int widx = sd->equip_index_maybe[EQUIP::WEAPON]; + int sidx = sd->equip_index_maybe[EQUIP::SHIELD]; + + if (widx >= 0 && sd->inventory_data[widx]) + atkmin = atkmin * (80 + sd->inventory_data[widx]->wlv * 20) / 100; + if (sidx >= 0 && sd->inventory_data[sidx]) + atkmin_ = atkmin_ * (80 + sd->inventory_data[sidx]->wlv * 20) / 100; if (sd->status.weapon == ItemLook::BOW) { //武器が弓矢の場合 atkmin = watk * ((atkmin < watk) ? atkmin : watk) / 100; //弓用最低ATK計算 @@ -1989,10 +1989,11 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, // 攻撃対象となりうるので攻撃 if (sd && sd->status.weapon == ItemLook::BOW) { - if (sd->equip_index[EQUIP::ARROW] >= 0) + int aidx = sd->equip_index_maybe[EQUIP::ARROW]; + if (aidx >= 0) { if (battle_config.arrow_decrement) - pc_delitem(sd, sd->equip_index[EQUIP::ARROW], 1, 0); + pc_delitem(sd, aidx, 1, 0); } else { @@ -2036,10 +2037,10 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, if (src->bl_type == BL::PC) { - int weapon_index = sd->equip_index[EQUIP::WEAPON]; + int weapon_index = sd->equip_index_maybe[EQUIP::WEAPON]; int weapon = 0; - if (sd->inventory_data[weapon_index] - && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON)) + if (weapon_index >= 0 && sd->inventory_data[weapon_index] + && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON)) weapon = sd->inventory_data[weapon_index]->nameid; MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d", diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 3290013..ecf9ec6 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -674,23 +674,23 @@ int clif_set0078(dumb_ptr<map_session_data> sd, unsigned char *buf) WBUFW(buf, 12) = static_cast<uint16_t>(sd->status.option); WBUFW(buf, 14) = sd->status.species; WBUFW(buf, 16) = sd->status.hair; + + int widx = sd->equip_index_maybe[EQUIP::WEAPON]; + int sidx = sd->equip_index_maybe[EQUIP::SHIELD]; if (sd->attack_spell_override) WBUFW(buf, 18) = sd->attack_spell_look_override; else { - if (sd->equip_index[EQUIP::WEAPON] >= 0 - && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]) + if (widx >= 0 && sd->inventory_data[widx]) { - WBUFW(buf, 18) = sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid; + WBUFW(buf, 18) = sd->status.inventory[widx].nameid; } else WBUFW(buf, 18) = 0; } - if (sd->equip_index[EQUIP::SHIELD] >= 0 - && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON] - && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]) + if (sidx >= 0 && sidx != widx && sd->inventory_data[sidx]) { - WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid; + WBUFW(buf, 20) = sd->status.inventory[sidx].nameid; } else WBUFW(buf, 20) = 0; @@ -734,18 +734,17 @@ int clif_set007b(dumb_ptr<map_session_data> sd, unsigned char *buf) WBUFW(buf, 12) = static_cast<uint16_t>(sd->status.option); WBUFW(buf, 14) = sd->status.species; WBUFW(buf, 16) = sd->status.hair; - if (sd->equip_index[EQUIP::WEAPON] >= 0 - && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]) + int widx = sd->equip_index_maybe[EQUIP::WEAPON]; + int sidx = sd->equip_index_maybe[EQUIP::SHIELD]; + if (widx >= 0 && sd->inventory_data[widx]) { - WBUFW(buf, 18) = sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid; + WBUFW(buf, 18) = sd->status.inventory[widx].nameid; } else WBUFW(buf, 18) = 0; - if (sd->equip_index[EQUIP::SHIELD] >= 0 - && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON] - && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]) + if (sidx >= 0 && sidx != widx && sd->inventory_data[sidx]) { - WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid; + WBUFW(buf, 20) = sd->status.inventory[sidx].nameid; } else WBUFW(buf, 20) = 0; @@ -1793,10 +1792,10 @@ int clif_changelook_towards(dumb_ptr<block_list> bl, LOOK type, int val, EQUIP equip_point = equip_points[type]; WBUFB(buf, 6) = uint16_t(type); - if (sd->equip_index[equip_point] >= 0 - && sd->inventory_data[sd->equip_index[equip_point]]) + int idx = sd->equip_index_maybe[equip_point]; + if (idx >= 0 && sd->inventory_data[idx]) { - WBUFW(buf, 7) = sd->status.inventory[sd->equip_index[equip_point]].nameid; + WBUFW(buf, 7) = sd->status.inventory[idx].nameid; } else WBUFW(buf, 7) = 0; @@ -1805,23 +1804,22 @@ int clif_changelook_towards(dumb_ptr<block_list> bl, LOOK type, int val, else { WBUFB(buf, 6) = 2; + int widx = sd->equip_index_maybe[EQUIP::WEAPON]; + int sidx = sd->equip_index_maybe[EQUIP::SHIELD]; if (sd->attack_spell_override) WBUFW(buf, 7) = sd->attack_spell_look_override; else { - if (sd->equip_index[EQUIP::WEAPON] >= 0 - && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]) + if (widx >= 0 && sd->inventory_data[widx]) { - WBUFW(buf, 7) = sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid; + WBUFW(buf, 7) = sd->status.inventory[widx].nameid; } else WBUFW(buf, 7) = 0; } - if (sd->equip_index[EQUIP::SHIELD] >= 0 - && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON] - && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]) + if (sidx >= 0 && sidx != widx && sd->inventory_data[sidx]) { - WBUFW(buf, 9) = sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid; + WBUFW(buf, 9) = sd->status.inventory[sidx].nameid; } else WBUFW(buf, 9) = 0; diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 1881afc..d05f713 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -830,13 +830,14 @@ int fun_is_equipped(dumb_ptr<env_t>, val_t *result, Slice<val_t> args) return 1; for (EQUIP i : EQUIPs) - if (chr->equip_index[i] >= 0 - && chr->status.inventory[chr->equip_index[i]].nameid == - item.nameid) + { + int idx = chr->equip_index_maybe[i]; + if (idx >= 0 && chr->status.inventory[idx].nameid == item.nameid) { retval = true; break; } + } RESULTINT = retval; return 0; diff --git a/src/map/map.hpp b/src/map/map.hpp index cb57c6b..9ab256d 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -174,7 +174,7 @@ struct map_session_data : block_list, SessionData CharKey status_key; CharData status; Array<struct item_data *, MAX_INVENTORY> inventory_data; - earray<short, EQUIP, EQUIP::COUNT> equip_index; + earray<short, EQUIP, EQUIP::COUNT> equip_index_maybe; int weight, max_weight; MapName mapname_; Session *sess; // use this, you idiots! diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 343e0fc..7077b44 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -543,7 +543,7 @@ int pc_setequipindex(dumb_ptr<map_session_data> sd) nullpo_ret(sd); for (EQUIP i : EQUIPs) - sd->equip_index[i] = -1; + sd->equip_index_maybe[i] = -1; for (int i = 0; i < MAX_INVENTORY; i++) { @@ -553,7 +553,7 @@ int pc_setequipindex(dumb_ptr<map_session_data> sd) { for (EQUIP j : EQUIPs) if (bool(sd->status.inventory[i].equip & equip_pos[j])) - sd->equip_index[j] = i; + sd->equip_index_maybe[j] = i; if (bool(sd->status.inventory[i].equip & EPOS::WEAPON)) { if (sd->inventory_data[i]) @@ -897,7 +897,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) int b_watk, b_def, b_watk2, b_def2, b_flee2, b_critical, b_attackrange, b_matk1, b_matk2, b_mdef, b_mdef2; int b_base_atk; - int bl, index; + int bl; int aspd_rate, refinedef = 0; int str, dstr, dex; @@ -1005,16 +1005,16 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) for (EQUIP i : EQUIPs_noarrow) { - index = sd->equip_index[i]; + int index = sd->equip_index_maybe[i]; if (index < 0) continue; - if (i == EQUIP::WEAPON && sd->equip_index[EQUIP::SHIELD] == index) + if (i == EQUIP::WEAPON && sd->equip_index_maybe[EQUIP::SHIELD] == index) continue; - if (i == EQUIP::TORSO && sd->equip_index[EQUIP::LEGS] == index) + if (i == EQUIP::TORSO && sd->equip_index_maybe[EQUIP::LEGS] == index) continue; if (i == EQUIP::HAT - && (sd->equip_index[EQUIP::TORSO] == index - || sd->equip_index[EQUIP::LEGS] == index)) + && (sd->equip_index_maybe[EQUIP::TORSO] == index + || sd->equip_index_maybe[EQUIP::LEGS] == index)) continue; if (sd->inventory_data[index]) @@ -1041,16 +1041,16 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) // 装備品によるステータス変化はここで実行 for (EQUIP i : EQUIPs_noarrow) { - index = sd->equip_index[i]; + int index = sd->equip_index_maybe[i]; if (index < 0) continue; - if (i == EQUIP::WEAPON && sd->equip_index[EQUIP::SHIELD] == index) + if (i == EQUIP::WEAPON && sd->equip_index_maybe[EQUIP::SHIELD] == index) continue; - if (i == EQUIP::TORSO && sd->equip_index[EQUIP::LEGS] == index) + if (i == EQUIP::TORSO && sd->equip_index_maybe[EQUIP::LEGS] == index) continue; if (i == EQUIP::HAT - && (sd->equip_index[EQUIP::TORSO] == index - || sd->equip_index[EQUIP::LEGS] == index)) + && (sd->equip_index_maybe[EQUIP::TORSO] == index + || sd->equip_index_maybe[EQUIP::LEGS] == index)) continue; if (sd->inventory_data[index]) { @@ -1117,9 +1117,10 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) sd->watk_2 += skill_power(sd, SkillID::TMW_BRAWLING) >> 3; // +25 for 200 } - if (sd->equip_index[EQUIP::ARROW] >= 0) + int aidx = sd->equip_index_maybe[EQUIP::ARROW]; + if (aidx >= 0) { // 矢 - index = sd->equip_index[EQUIP::ARROW]; + int index = aidx; if (sd->inventory_data[index]) { //まだ属性が入っていない argrec_t arg[2] = @@ -2687,7 +2688,7 @@ int pc_checkequip(dumb_ptr<map_session_data> sd, EPOS pos) for (EQUIP i : EQUIPs) { if (bool(pos & equip_pos[i])) - return sd->equip_index[i]; + return sd->equip_index_maybe[i]; } return -1; @@ -3278,12 +3279,15 @@ int pc_resetlvl(dumb_ptr<map_session_data> sd, int type) for (EQUIP i : EQUIPs) { // unequip items that can't be equipped by base 1 [Valaris] - if (sd->equip_index[i] >= 0) - if (!pc_isequip(sd, sd->equip_index[i])) + short *idx = &sd->equip_index_maybe[i]; + if (*idx >= 0) + { + if (!pc_isequip(sd, *idx)) { - pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER); - sd->equip_index[i] = -1; + pc_unequipitem(sd, *idx, CalcStatus::LATER); + *idx = -1; } + } } clif_skillinfoblock(sd); @@ -4394,10 +4398,12 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS) { // アクセサリ用例外処理 EPOS epor = EPOS::ZERO; - if (sd->equip_index[EQUIP::MISC2] >= 0) - epor |= sd->status.inventory[sd->equip_index[EQUIP::MISC2]].equip; - if (sd->equip_index[EQUIP::CAPE] >= 0) - epor |= sd->status.inventory[sd->equip_index[EQUIP::CAPE]].equip; + int midx = sd->equip_index_maybe[EQUIP::MISC2]; + int cidx = sd->equip_index_maybe[EQUIP::CAPE]; + if (midx >= 0) + epor |= sd->status.inventory[midx].equip; + if (cidx >= 0) + epor |= sd->status.inventory[cidx].equip; epor &= (EPOS::MISC2 | EPOS::CAPE); pos = (epor == EPOS::CAPE ? EPOS::MISC2 : EPOS::CAPE); } @@ -4406,9 +4412,10 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS) { if (bool(pos & equip_pos[i])) { - if (sd->equip_index[i] >= 0) //Slot taken, remove item from there. - pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER); - sd->equip_index[i] = n; + short *idx = &sd->equip_index_maybe[i]; + if (*idx >= 0) //Slot taken, remove item from there. + pc_unequipitem(sd, *idx, CalcStatus::LATER); + *idx = n; } } // 弓矢装備 @@ -4427,7 +4434,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS) for (EQUIP i : EQUIPs) { if (bool(pos & equip_pos[i])) - sd->equip_index[i] = n; + sd->equip_index_maybe[i] = n; } sd->status.inventory[n].equip = pos; @@ -4517,7 +4524,7 @@ int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type) for (EQUIP i : EQUIPs) { if (bool(sd->status.inventory[n].equip & equip_pos[i])) - sd->equip_index[i] = -1; + sd->equip_index_maybe[i] = -1; } if (bool(sd->status.inventory[n].equip & EPOS::WEAPON)) { @@ -4574,11 +4581,11 @@ int pc_unequipinvyitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type) { if (equip_pos[i] != EPOS::ZERO && !bool(equip_pos[i] & EPOS::ARROW) // probably a bug - && sd->equip_index[i] == n) + && sd->equip_index_maybe[i] == n) { //Slot taken, remove item from there. - pc_unequipitem(sd, sd->equip_index[i], type); - sd->equip_index[i] = -1; + pc_unequipitem(sd, sd->equip_index_maybe[i], type); + sd->equip_index_maybe[i] = -1; } } diff --git a/src/map/script.cpp b/src/map/script.cpp index 18055b8..3fffba0 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -3662,8 +3662,11 @@ void builtin_nude(ScriptState *st) return; for (EQUIP i : EQUIPs) - if (sd->equip_index[i] >= 0) - pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER); + { + int idx = sd->equip_index_maybe[i]; + if (idx >= 0) + pc_unequipitem(sd, idx, CalcStatus::LATER); + } pc_calcstatus(sd, 0); } @@ -3682,9 +3685,12 @@ void builtin_unequipbyid(ScriptState *st) EQUIP slot_id = EQUIP(conv_num(st, &AARGO2(2))); - if (slot_id >= EQUIP() && slot_id < EQUIP::COUNT - && sd->equip_index[slot_id] >= 0) - pc_unequipitem(sd, sd->equip_index[slot_id], CalcStatus::LATER); + if (slot_id >= EQUIP() && slot_id < EQUIP::COUNT) + { + int idx = sd->equip_index_maybe[slot_id]; + if (idx >= 0) + pc_unequipitem(sd, idx, CalcStatus::LATER); + } pc_calcstatus(sd, 0); |