Skip to content

Commit

Permalink
Merge pull request #5136 from TracentEden2/fix_ksnm_trial_weapons_cri…
Browse files Browse the repository at this point in the history
…t_rates

[core, sql] Fix KSNM trial weapon crit mods to only apply to themselves
  • Loading branch information
claywar authored Apr 17, 2024
2 parents 38b6371 + 84fd70b commit dbb607a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions scripts/enum/mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ xi.mod =
DARK_ABSORB = 466, -- Occasionally absorbs dark elemental damage.

CRITHITRATE = 165,
CRITHITRATE_ONLY_WEP = 141,
CRIT_DMG_INCREASE = 421,
RANGED_CRIT_DMG_INCREASE = 964, -- Increases ranged critical damage by a percent
ENEMYCRITRATE = 166,
Expand Down
24 changes: 12 additions & 12 deletions sql/item_latents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ INSERT INTO `item_latents` VALUES (17447,5,20,53,1); -- MP +20 in areas outs
INSERT INTO `item_latents` VALUES (17448,13,1,53,1); -- MND +1 in areas outside own nation's control
INSERT INTO `item_latents` VALUES (17449,13,2,53,1); -- MND +2 in areas outside own nation's control

INSERT INTO `item_latents` VALUES (17451,165,6,47,0); -- Morgenstern Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17451,141,6,47,0); -- Morgenstern Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17451,287,13,47,0); -- Morgenstern DMG+13 when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17456,2,-10,47,0);
INSERT INTO `item_latents` VALUES (17456,5,-10,47,0);
Expand Down Expand Up @@ -1734,7 +1734,7 @@ INSERT INTO `item_latents` VALUES (17507,20,-10,47,0);
-- Master Caster's baghnakhs
-- INSERT INTO `item_latents` VALUES (17508,23,10,?,?); -- Citizens of Windurst: Attack+10

INSERT INTO `item_latents` VALUES (17509,165,6,47,0); -- Destroyers Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17509,141,6,47,0); -- Destroyers Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17509,287,13,47,0); -- Destroyers DMG+13 when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17527,2,-10,47,0);
INSERT INTO `item_latents` VALUES (17527,5,-10,47,0);
Expand All @@ -1750,7 +1750,7 @@ INSERT INTO `item_latents` VALUES (17540,5,12,53,1); -- MP +12 in areas outs
INSERT INTO `item_latents` VALUES (17581,17,15,31,0); -- Mighty Pole [Element: Wind]+15 on Windsday
INSERT INTO `item_latents` VALUES (17581,111,13,31,0); -- Mighty Pole Divine magic skill +13 Windsday
INSERT INTO `item_latents` VALUES (17581,115,13,31,0); -- Mighty Pole Elemental magic skill +13 Windsday
INSERT INTO `item_latents` VALUES (17589,165,6,47,0); -- Thyrsusstab Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17589,141,6,47,0); -- Thyrsusstab Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17589,287,13,47,0); -- Thyrsusstab DMG+13 when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17590,25,10,49,4468); -- Primate Staff (pamamas)
INSERT INTO `item_latents` VALUES (17590,25,10,49,4596); -- (wild pamamas)
Expand Down Expand Up @@ -1822,7 +1822,7 @@ INSERT INTO `item_latents` VALUES (17681,5,20,53,1); -- MP +20 in areas outs

INSERT INTO `item_latents` VALUES (17697,17,15,31,0); -- Mighty Talwar [Element: Wind]+15 on Windsday
INSERT INTO `item_latents` VALUES (17697,287,8,31,0); -- Mighty Talwar DMG+8 on Windsday
INSERT INTO `item_latents` VALUES (17699,165,6,47,0); -- Dissector Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17699,141,6,47,0); -- Dissector Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17699,287,13,47,0); -- Dissector DMG+13 when broken (500 WS points)

-- Shiva's Shotel
Expand Down Expand Up @@ -1867,7 +1867,7 @@ INSERT INTO `item_latents` VALUES (17788,8,4,32,0); -- Sairen STR +4 on Dar
INSERT INTO `item_latents` VALUES (17788,27,1,32,0); -- Enmity +1
INSERT INTO `item_latents` VALUES (17791,15,15,28,0); -- Rai Kunimitsu [Element: Fire]+15 on Firesday
INSERT INTO `item_latents` VALUES (17791,287,7,28,0); -- Rai Kunimitsu DMG+7 on Firesday
INSERT INTO `item_latents` VALUES (17793,165,6,47,0); -- Senjuinrikio Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17793,141,6,47,0); -- Senjuinrikio Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17793,287,13,47,0); -- Senjuinrikio DMG+13 when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17804,25,7,59,6); -- Ushikirimaru - Vs. beasts: Accuracy+7

Expand All @@ -1882,7 +1882,7 @@ INSERT INTO `item_latents` VALUES (17815,16,-10,47,0);
INSERT INTO `item_latents` VALUES (17815,22,-10,47,0);
INSERT INTO `item_latents` VALUES (17824,15,15,28,0); -- Nukemaru [Element: Fire]+15 on Firesday
INSERT INTO `item_latents` VALUES (17824,287,10,28,0); -- Nukemaru DMG+10 on Firesday
INSERT INTO `item_latents` VALUES (17827,165,6,47,0); -- Michishiba Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17827,141,6,47,0); -- Michishiba Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17827,287,13,47,0); -- Michishiba DMG+13 when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17831,369,1,13,2);
INSERT INTO `item_latents` VALUES (17831,370,1,13,19);
Expand All @@ -1905,7 +1905,7 @@ INSERT INTO `item_latents` VALUES (17934,23,10,44,0); -- Citizens of San d'Oria:

INSERT INTO `item_latents` VALUES (17941,17,15,31,0); -- Mighty Pick [Element: Wind]+15 on Windsday
INSERT INTO `item_latents` VALUES (17941,287,5,31,0); -- Mighty Pick DMG+5 on Windsday
INSERT INTO `item_latents` VALUES (17944,165,6,47,0); -- Retributor Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17944,141,6,47,0); -- Retributor Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (17944,287,13,47,0); -- Retributor DMG+13 when broken (500 WS points)

-- Maneater
Expand Down Expand Up @@ -1967,7 +1967,7 @@ INSERT INTO `item_latents` VALUES (17991,5,16,53,1); -- MP +16 in areas outs

INSERT INTO `item_latents` VALUES (18000,17,15,31,0); -- Mighty Knife [Element: Wind]+15 on Windsday
INSERT INTO `item_latents` VALUES (18000,287,10,31,0); -- Mighty Knife DMG+10 on Windsday
INSERT INTO `item_latents` VALUES (18005,165,6,47,0); -- Heart Snatcher Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18005,141,6,47,0); -- Heart Snatcher Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18005,287,15,47,0); -- Heart Snatcher DMG+15 when broken (500 WS points)

-- Blau Dolch
Expand All @@ -1984,7 +1984,7 @@ INSERT INTO `item_latents` VALUES (18036,5,10,53,1); -- MP +10 in areas outs
INSERT INTO `item_latents` VALUES (18037,5,12,53,1); -- MP +12 in areas outside own nation's control
INSERT INTO `item_latents` VALUES (18049,17,15,31,0); -- Mighty Zaghnal [Element: Wind]+15 on Windsday
INSERT INTO `item_latents` VALUES (18049,287,8,31,0); -- Mighty Zaghnal DMG+8 on Windsday
INSERT INTO `item_latents` VALUES (18053,165,6,47,0); -- Gravedigger Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18053,141,6,47,0); -- Gravedigger Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18053,287,13,47,0); -- Gravedigger DMG+13 when broken (500 WS points)

-- Garuda's Sickle
Expand All @@ -2010,7 +2010,7 @@ INSERT INTO `item_latents` VALUES (18084,369,-3,56,0); -- Rune Halberd -3MP/ti

INSERT INTO `item_latents` VALUES (18091,15,15,28,0); -- Mighty Lance [Element: Fire]+15 on Firesday
INSERT INTO `item_latents` VALUES (18091,287,12,28,0); -- Mighty Lance DMG+12 on Firesday
INSERT INTO `item_latents` VALUES (18097,165,6,47,0); -- Gondo-Shizunori Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18097,141,6,47,0); -- Gondo-Shizunori Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18097,287,13,47,0); -- Gondo-Shizunori DMG+13 when broken (500 WS points)

-- Stone-splitter
Expand Down Expand Up @@ -2056,7 +2056,7 @@ INSERT INTO `item_latents` VALUES (18206,369,-3,56,0); -- Rune Chopper -3MP/ti
INSERT INTO `item_latents` VALUES (18206,384,900,56,0); -- Rune Chopper +9% haste
INSERT INTO `item_latents` VALUES (18213,15,15,28,0); -- Mighty Axe [Element: Fire]+15 on Firesday
INSERT INTO `item_latents` VALUES (18213,287,10,28,0); -- Mighty Axe DMG+10 on Firesday
INSERT INTO `item_latents` VALUES (18217,165,6,47,0); -- Rampager Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18217,141,6,47,0); -- Rampager Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18217,287,13,47,0); -- Rampager DMG+13 when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18256,23,1,25,0); -- Orphic Egg,ATT+1 song/roll active
INSERT INTO `item_latents` VALUES (18256,25,1,25,0); -- Orphic Egg,ACC+1 song/roll active
Expand Down Expand Up @@ -2198,7 +2198,7 @@ INSERT INTO `item_latents` VALUES (18364,287,2,58,0); -- Pahluwan Katars dmg
INSERT INTO `item_latents` VALUES (18364,291,1,58,0); -- counter +1
INSERT INTO `item_latents` VALUES (18374,15,15,28,0); -- Mighty Sword [Element: Fire]+15
INSERT INTO `item_latents` VALUES (18374,287,9,28,0); -- Mighty Sword DMG+9 on Firesday
INSERT INTO `item_latents` VALUES (18378,165,6,47,0); -- Subduer Crit Rate +6% when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18378,141,6,47,0); -- Subduer Crit Rate +6% (for this weapon only) when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18378,287,13,47,0); -- Subduer DMG+13 when broken (500 WS points)
INSERT INTO `item_latents` VALUES (18387,25,5,58,0); -- Djinnbringer Accuracy +5 in Assault
INSERT INTO `item_latents` VALUES (18387,287,3,58,0); -- Djinnbringer DMG+3 in Assault
Expand Down
2 changes: 1 addition & 1 deletion sql/item_mods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32750,7 +32750,7 @@ INSERT INTO `item_mods` VALUES (16897,953,20); -- ITEM_ADDEFFECT_DURATION: 20
INSERT INTO `item_mods` VALUES (16899,25,3); -- ACC: 3

-- Fudo
INSERT INTO `item_mods` VALUES (16904,165,3); -- CRITHITRATE: 3
INSERT INTO `item_mods` VALUES (16904,141,3); -- CRITHITRATE_ONLY_WEP: 3

-- Bokuto
INSERT INTO `item_mods` VALUES (16905,431,2); -- ITEM_ADDEFFECT_TYPE: DEBUFF
Expand Down
3 changes: 2 additions & 1 deletion src/map/entities/battleentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2272,8 +2272,9 @@ bool CBattleEntity::OnAttack(CAttackState& state, action_t& action)
}
else
{
SLOTTYPE weaponSlot = static_cast<SLOTTYPE>(attack.GetWeaponSlot());
// Set this attack's critical flag.
attack.SetCritical(xirand::GetRandomNumber(100) < battleutils::GetCritHitRate(this, PTarget, !attack.IsFirstSwing()));
attack.SetCritical(xirand::GetRandomNumber(100) < battleutils::GetCritHitRate(this, PTarget, !attack.IsFirstSwing(), weaponSlot));

this->PAI->EventHandler.triggerListener("MELEE_SWING_HIT", CLuaBaseEntity(this), CLuaBaseEntity(PTarget), CLuaAttack(&attack));

Expand Down
1 change: 1 addition & 0 deletions src/map/modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ enum class Mod

// Crit Damage / Delay
CRITHITRATE = 165, // Raises chance to crit
CRITHITRATE_ONLY_WEP = 141, // Raises chance to crit (but only for attacks with the specific weapon that has the mod)
CRIT_DMG_INCREASE = 421, // Raises the damage of critical hit by percent %
RANGED_CRIT_DMG_INCREASE = 964, // Increases ranged critical damage by a percent
ENEMYCRITRATE = 166, // Raises chance enemy will crit
Expand Down
13 changes: 12 additions & 1 deletion src/map/utils/battleutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2747,7 +2747,7 @@ namespace battleutils
* *
************************************************************************/

uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack)
uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack, SLOTTYPE weaponSlot)
{
int32 critHitRate = 5;
if (PAttacker->StatusEffectContainer->HasStatusEffect(EFFECT_MIGHTY_STRIKES, 0) ||
Expand Down Expand Up @@ -2810,6 +2810,17 @@ namespace battleutils
critHitRate += GetDexCritBonus(PAttacker, PDefender);
critHitRate += PAttacker->getMod(Mod::CRITHITRATE);
critHitRate += PDefender->getMod(Mod::ENEMYCRITRATE);

// need to check for mods that only impact attacks with a specific weapon (like Senjuinrikio)
if (auto* player = dynamic_cast<CCharEntity*>(PAttacker))
{
auto* weapon = dynamic_cast<CItemWeapon*>(player->getEquip(weaponSlot));
if (weapon && weapon->getModifier(Mod::CRITHITRATE_ONLY_WEP) > 0)
{
critHitRate += weapon->getModifier(Mod::CRITHITRATE_ONLY_WEP);
}
}

critHitRate = std::clamp(critHitRate, 0, 100);
}
return (uint8)critHitRate;
Expand Down
2 changes: 1 addition & 1 deletion src/map/utils/battleutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace battleutils
uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender);
uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 attackNumber);
uint8 GetHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint8 attackNumber, int8 offsetAccuracy);
uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack);
uint8 GetCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender, bool ignoreSneakTrickAttack, SLOTTYPE weaponSlot = SLOT_MAIN);
uint8 GetRangedCritHitRate(CBattleEntity* PAttacker, CBattleEntity* PDefender);
int8 GetDexCritBonus(CBattleEntity* PAttacker, CBattleEntity* PDefender);
int8 GetAGICritBonus(CBattleEntity* PAttacker, CBattleEntity* PDefender);
Expand Down

0 comments on commit dbb607a

Please sign in to comment.