Skip to content

Commit

Permalink
Fix reflect damage and and LOS on damage area
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhobean committed Oct 15, 2023
1 parent cbc82a1 commit 5caa2cf
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/game/chars/CCharAct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,7 @@ bool CChar::ItemEquip( CItem * pItem, CChar * pCharMsg, bool fFromDClick )

if (pItem->IsTypeWeapon())
{
//Necromancy Curse weapon
//Necromancy Curse weapon
CItem * pCursedMemory = LayerFind(LAYER_SPELL_Curse_Weapon); // Remove the cursed state from SPELL_Curse_Weapon.
if (pCursedMemory)
pItem->ModPropNum(pItemCCPItemEquippable, PROPIEQUIP_HITLEECHLIFE, + pCursedMemory->m_itSpell.m_spelllevel, pItemBaseCCPItemEquippable);
Expand Down
131 changes: 70 additions & 61 deletions src/game/chars/CCharFight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,26 +985,32 @@ int CChar::OnTakeDamage( int iDmg, CChar * pSrc, DAMAGE_TYPE uType, int iDmgPhys

void CChar::OnTakeDamageArea(int iDmg, CChar* pSrc, DAMAGE_TYPE uType, int iDmgPhysical, int iDmgFire, int iDmgCold, int iDmgPoison, int iDmgEnergy, HUE_TYPE effectHue, SOUND_TYPE effectSound)
{
ADDTOCALLSTACK("CChar::OnTakeDamageArea");
ADDTOCALLSTACK("CChar::OnTakeDamageArea");

bool fMakeSound = false;
// Damage perimeter should be ajust to more realist "nearby targets"
// Like this area damage touch everyone! Pet, NPC etc
CWorldSearch AreaChars(GetTopPoint(), UO_MAP_VIEW_SIGHT);
for (;;)
{
CChar* pChar = AreaChars.GetChar();
if (!pChar)
break;
if ((pChar == this) || (pChar == pSrc))
continue;
bool fMakeSound = false;
// Like this area damage touch everyone! Pet, NPC etc We should ignore pet and Criminal action?

pChar->OnTakeDamage(iDmg, pSrc, uType, iDmgPhysical, iDmgFire, iDmgCold, iDmgPoison, iDmgEnergy);
pChar->Effect(EFFECT_OBJ, ITEMID_FX_SPARKLE_2, this, 1, 15, false, effectHue);
fMakeSound = true;
}
if (fMakeSound && (effectSound != SOUND_NONE))
Sound(effectSound);
int iDistance = 5;
if (IsAosFlagEnabled(FEATURE_AOS_DAMAGE))
iDistance=10; // 5 for ML and 10 for aos

CWorldSearch AreaChars(GetTopPoint(), iDistance);
for (;;)
{
CChar* pChar = AreaChars.GetChar();
if (!pChar)
break;
if (!pChar->CanSeeLOS(pSrc))
break;
if ((pChar == this) || (pChar == pSrc))
continue;

pChar->OnTakeDamage(iDmg, pSrc, uType, iDmgPhysical, iDmgFire, iDmgCold, iDmgPoison, iDmgEnergy);
pChar->Effect(EFFECT_OBJ, ITEMID_FX_SPARKLE_2, this, 1, 15, false, effectHue);
fMakeSound = true;
}
if (fMakeSound && (effectSound != SOUND_NONE))
Sound(effectSound);
}

//*******************************************************************************
Expand Down Expand Up @@ -2189,61 +2195,64 @@ WAR_SWING_TYPE CChar::Fight_Hit( CChar * pCharTarg )

if ( fMakeLeechSound )
Sound(0x44d);

//There a bug here... This line never read correctly the target REFLECTPHYSICALDAM value
if (pCharTarg->GetPropNum(pCCPChar, PROPCH_REFLECTPHYSICALDAM, pBaseCCPChar))
{
// REFLECTPHYSICALDAM suppose to reflect only physical? How we block other damage here?
OnTakeDamage(
iDmg * pCharTarg->GetPropNum(pCCPChar, PROPCH_REFLECTPHYSICALDAM, pBaseCCPChar) / 100,
this,
iDmgType,
(int)GetPropNum(pCCPChar, PROPCH_DAMPHYSICAL, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMFIRE, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMCOLD, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMPOISON, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMENERGY, pBaseCCPChar)
);
}

if (pWeapon)
{
bool fElemental = IsSetCombatFlags(COMBAT_ELEMENTAL_ENGINE);
// REFLECTPHYSICALDAM
const CCPropsChar* pCCPCharTarg = pCharTarg->GetComponentProps<CCPropsChar>();
const CCPropsChar* pBaseCCPCharTarg = pCharTarg->Base_GetDef()->GetComponentProps<CCPropsChar>();
int iTargReflectPhysicalDam =pCharTarg->GetPropNum(pCCPCharTarg, PROPCH_REFLECTPHYSICALDAM, pBaseCCPCharTarg);
if (iTargReflectPhysicalDam)
{
// REFLECTPHYSICALDAM suppose to reflect only physical? How we block other damage here?
OnTakeDamage(
iDmg * iTargReflectPhysicalDam / 100,
this,
iDmgType,
(int)GetPropNum(pCCPChar, PROPCH_DAMPHYSICAL, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMFIRE, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMCOLD, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMPOISON, pBaseCCPChar),
(int)GetPropNum(pCCPChar, PROPCH_DAMENERGY, pBaseCCPChar)
);
}

if (fElemental)
{
if (GetPropNum(pCCPChar, PROPCH_HITAREAPHYSICAL, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 100, 0, 0, 0, 0, static_cast<HUE_TYPE>(0x32), static_cast<SOUND_TYPE>(0x10E));
if (pWeapon)
{
bool fElemental = IsSetCombatFlags(COMBAT_ELEMENTAL_ENGINE);

if (fElemental)
{
if (GetPropNum(pCCPChar, PROPCH_HITAREAPHYSICAL, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 100, 0, 0, 0, 0, static_cast<HUE_TYPE>(0x32), static_cast<SOUND_TYPE>(0x10E));

if (GetPropNum(pCCPChar, PROPCH_HITAREAFIRE, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 100, 0, 0, 0, static_cast<HUE_TYPE>(0x488), static_cast<SOUND_TYPE>(0x11D));
if (GetPropNum(pCCPChar, PROPCH_HITAREAFIRE, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 100, 0, 0, 0, static_cast<HUE_TYPE>(0x488), static_cast<SOUND_TYPE>(0x11D));

if (GetPropNum(pCCPChar, PROPCH_HITAREACOLD, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 0, 100, 0, 0, static_cast<HUE_TYPE>(0x834), static_cast<SOUND_TYPE>(0xFC));
if (GetPropNum(pCCPChar, PROPCH_HITAREACOLD, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 0, 100, 0, 0, static_cast<HUE_TYPE>(0x834), static_cast<SOUND_TYPE>(0xFC));

if (GetPropNum(pCCPChar, PROPCH_HITAREAPOISON, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 0, 0, 100, 0, static_cast<HUE_TYPE>(0x48E), static_cast<SOUND_TYPE>(0x205));
if (GetPropNum(pCCPChar, PROPCH_HITAREAPOISON, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 0, 0, 100, 0, static_cast<HUE_TYPE>(0x48E), static_cast<SOUND_TYPE>(0x205));

if (GetPropNum(pCCPChar, PROPCH_HITAREAENERGY, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 0, 0, 0, 100, static_cast<HUE_TYPE>(0x78), static_cast<SOUND_TYPE>(0x1F1));
if (GetPropNum(pCCPChar, PROPCH_HITAREAENERGY, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnTakeDamageArea(iDmg / 2, this, DAMAGE_GENERAL, 0, 0, 0, 0, 100, static_cast<HUE_TYPE>(0x78), static_cast<SOUND_TYPE>(0x1F1));

}
}

if (GetPropNum(pCCPChar, PROPCH_HITDISPEL, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Dispel, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);
if (GetPropNum(pCCPChar, PROPCH_HITDISPEL, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Dispel, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);

if (GetPropNum(pCCPChar, PROPCH_HITFIREBALL, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Fireball, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);
if (GetPropNum(pCCPChar, PROPCH_HITFIREBALL, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Fireball, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);

if (GetPropNum(pCCPChar, PROPCH_HITHARM, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Harm, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);
if (GetPropNum(pCCPChar, PROPCH_HITHARM, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Harm, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);

if (GetPropNum(pCCPChar, PROPCH_HITLIGHTNING, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Lightning, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);
if (GetPropNum(pCCPChar, PROPCH_HITLIGHTNING, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Lightning, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);

if (GetPropNum(pCCPChar, PROPCH_HITMAGICARROW, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Magic_Arrow, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);
}
if (GetPropNum(pCCPChar, PROPCH_HITMAGICARROW, pBaseCCPChar) > Calc_GetRandLLVal(100))
pCharTarg->OnSpellEffect(SPELL_Magic_Arrow, this, Skill_GetAdjusted(SKILL_MAGERY), pWeapon);
}

// Make blood effects
if ( pCharTarg->_wBloodHue != (HUE_TYPE)(-1) )
Expand Down

0 comments on commit 5caa2cf

Please sign in to comment.