gdle/Source/SpellProjectile.cpp

312 lines
9.4 KiB
C++
Raw Permalink Normal View History

2019-07-07 20:56:15 +00:00
#include <StdAfx.h>
2018-03-29 17:01:57 -04:00
#include "SpellProjectile.h"
#include "World.h"
#include "Monster.h"
#include "CombatFormulas.h"
#include "Player.h"
2018-03-29 17:01:57 -04:00
const float MAX_SPELL_PROJECTILE_LIFETIME = 30.0f;
2018-03-29 17:01:57 -04:00
2019-07-07 20:56:15 +00:00
CSpellProjectile::CSpellProjectile(const SpellCastData &scd, uint32_t target_id)//, unsigned int damage)
2018-03-29 17:01:57 -04:00
{
m_CachedSpellCastData = scd;
m_SourceID = scd.source_id;
m_TargetID = target_id;
//m_Damage = damage;
m_fSpawnTime = Timer::cur_time;
m_fDestroyTime = FLT_MAX;
m_fFriction = 1.0f;
m_fElasticity = 0.0f;
m_DefaultScript = 0x5A;
m_DefaultScriptIntensity = 1.0f;
m_fEffectMod = max(0.0, min(1.0, ((scd.power_level_of_power_component - 1.0) / 15.0)));
2018-03-29 17:01:57 -04:00
SetItemType(ITEM_TYPE::TYPE_SELF);
m_Qualities.SetBool(STUCK_BOOL, TRUE);
m_Qualities.SetBool(ATTACKABLE_BOOL, TRUE);
m_Qualities.SetBool(UI_HIDDEN_BOOL, TRUE);
SetInitialPhysicsState(INELASTIC_PS | SCRIPTED_COLLISION_PS | REPORT_COLLISIONS_PS | MISSILE_PS | LIGHTING_ON_PS | PATHCLIPPED_PS | ALIGNPATH_PS);
}
CSpellProjectile::~CSpellProjectile()
{
}
void CSpellProjectile::Tick()
{
2018-07-12 14:41:21 -07:00
if (!m_bDestroyMe)
2018-03-29 17:01:57 -04:00
{
if (!InValidCell() || (m_fDestroyTime <= Timer::cur_time))
{
2018-07-12 14:41:21 -07:00
MarkForDestroy();
}
// not destroyed yet and distance/time exceeded
else if (m_fDestroyTime > Timer::cur_time + 10 && (m_Position.distance(m_CachedSpellCastData.initial_cast_position) > m_CachedSpellCastData.max_range || (m_fSpawnTime + MAX_SPELL_PROJECTILE_LIFETIME - 1) <= Timer::cur_time))
{
HandleExplode();
m_fDestroyTime = Timer::cur_time + 1;
}
}
2018-03-29 17:01:57 -04:00
}
void CSpellProjectile::PostSpawn()
{
CWeenieObject::PostSpawn();
EmitEffect(PS_Launch, m_fEffectMod);
m_fSpawnTime = Timer::cur_time;
}
void CSpellProjectile::HandleExplode()
{
EmitEffect(PS_Explode, m_fEffectMod);
// INELASTIC_PS | SCRIPTED_COLLISION_PS | REPORT_COLLISIONS_PS | MISSILE_PS | LIGHTING_ON_PS | PATHCLIPPED_PS | ALIGNPATH_PS
set_state(/*0x128374*/
INELASTIC_PS | SCRIPTED_COLLISION_PS | MISSILE_PS | PATHCLIPPED_PS | ALIGNPATH_PS | ETHEREAL_PS | IGNORE_COLLISIONS_PS | NODRAW_PS | CLOAKED_PS, TRUE);
// no more REPORT_COLLISIONS_PS and no more LIGHTING_ON_PS
}
BOOL CSpellProjectile::DoCollision(const class EnvCollisionProfile &prof)
{
Movement_UpdatePos();
HandleExplode();
m_fDestroyTime = Timer::cur_time + 1.0;
return CWeenieObject::DoCollision(prof);
}
BOOL CSpellProjectile::DoCollision(const class AtkCollisionProfile &prof)
{
2018-07-12 14:41:21 -07:00
CWeenieObject *pHit = g_pWorld->FindWithinPVS(this, prof.id);
2018-03-29 17:01:57 -04:00
if (pHit && (!m_TargetID || m_TargetID == pHit->GetID()) && (pHit->GetID() != m_SourceID))
{
if (pHit->m_Qualities.m_WeenieType == CombatPet_WeenieType)
return 1;
2018-07-12 14:41:21 -07:00
CWeenieObject *pSource = NULL;
2018-03-29 17:01:57 -04:00
if (m_SourceID)
pSource = g_pWorld->FindObject(m_SourceID);
2020-07-07 13:39:25 -07:00
if (!pSource)
return 1;
2018-03-29 17:01:57 -04:00
2020-05-17 00:49:05 -07:00
pHit->m_Qualities.SetInstanceID(CURRENT_ATTACKER_IID, m_SourceID);
uint32_t currentEnemy;
if (pHit->m_Qualities.InqInstanceID(CURRENT_ENEMY_IID, currentEnemy))
{
if(currentEnemy == 0)
pHit->m_Qualities.SetInstanceID(CURRENT_ENEMY_IID, m_SourceID);
}
2018-03-29 17:01:57 -04:00
if (!pHit->ImmuneToDamage(pSource))
{
Movement_UpdatePos();
// EmitEffect(5, 0.8f);
HandleExplode();
m_fDestroyTime = Timer::cur_time + 0.5;
2018-03-29 17:01:57 -04:00
if (pSource && pHit && pSource->AsPlayer() && pHit->AsPlayer())
{
pSource->AsPlayer()->UpdatePKActivity();
pHit->AsPlayer()->UpdatePKActivity();
}
2020-05-16 18:39:12 -07:00
if (m_CachedSpellCastData.spell_id == 1783 || m_CachedSpellCastData.spell_id == 1784 || m_CachedSpellCastData.spell_id == 1785 || m_CachedSpellCastData.spell_id == 1786
|| m_CachedSpellCastData.spell_id == 1787 || m_CachedSpellCastData.spell_id == 1788 || m_CachedSpellCastData.spell_id == 1789 || m_CachedSpellCastData.spell_id == 5331)
{
if (m_CachedSpellCastData.caster_id != m_CachedSpellCastData.source_id)
{
CWeenieObject* casterObj = g_pWorld->FindObject(m_CachedSpellCastData.caster_id);
2020-07-07 13:39:25 -07:00
if (casterObj && casterObj->IsCloak())
{
int wieldDiff = 0;
if (casterObj->m_Qualities.InqInt(WIELD_DIFFICULTY_INT, wieldDiff))
{
m_CachedSpellCastData.current_skill = wieldDiff * 3;
}
else
{
m_CachedSpellCastData.current_skill = 150;
SERVER_ERROR << "Cloak found missing WieldDiff";
}
}
}
2020-05-16 18:39:12 -07:00
}
2018-03-29 17:01:57 -04:00
// try to resist
bool bResisted = false;
if (m_CachedSpellCastData.spell->_bitfield & Resistable_SpellIndex)
{
if (pSource != pHit)
{
if (pHit->TryMagicResist(m_CachedSpellCastData.current_skill))
{
pHit->EmitSound(Sound_ResistSpell, 1.0f, false);
if (pSource)
{
pHit->SendText(csprintf("You resist the spell cast by %s", pSource->GetName().c_str()), LTT_MAGIC);
pSource->SendText(csprintf("%s resists your spell", pHit->GetName().c_str()), LTT_MAGIC);
pHit->OnResistSpell(pSource);
2020-05-16 18:39:12 -07:00
if (pSource->AsPlayer())
pSource->AsPlayer()->HandleAetheriaProc(0);
2018-03-29 17:01:57 -04:00
}
bResisted = true;
}
}
}
if (!bResisted)
{
2018-07-12 14:41:21 -07:00
CWeenieObject *wand = g_pWorld->FindObject(m_CachedSpellCastData.wand_id);
2019-07-07 11:39:24 -07:00
if (isEnchantProjectile)
2018-03-29 17:01:57 -04:00
{
2019-07-07 11:39:24 -07:00
ProjectileEnchantmentSpellEx *meta = (ProjectileEnchantmentSpellEx *)m_CachedSpellCastData.spellEx->_meta_spell._spell;
Enchantment enchant;
enchant._id = m_CachedSpellCastData.spell_id | ((uint32_t)m_CachedSpellCastData.serial << (uint32_t)16);
2019-07-07 11:39:24 -07:00
enchant.m_SpellSetID = 0; // ???
enchant._spell_category = m_CachedSpellCastData.spellEx->_category; // meta->_spellCategory;
enchant._power_level = m_CachedSpellCastData.spell->_power;
enchant._start_time = Timer::cur_time;
int buffDuration = 1;
2019-07-21 21:08:27 -07:00
enchant._duration = meta->_duration;
2019-07-07 11:39:24 -07:00
enchant._caster = pSource->GetID();
enchant._degrade_modifier = meta->_degrade_modifier;
enchant._degrade_limit = meta->_degrade_limit;
enchant._last_time_degraded = -1.0;
enchant._smod = meta->_smod;
enchant._dtype = meta->_etype;
enchant._duration += 0.25; // Handle extra time so all ticks happen
if (pHit->AsMonster() && !pHit->AsPlayer())
{
int currentDotValue = pHit->m_Qualities.GetInt(NETHER_OVER_TIME_INT, 0);
pHit->m_Qualities.SetInt(NETHER_OVER_TIME_INT, (currentDotValue + enchant._smod.val));
}
pHit->HandleAggro(pSource);
pHit->m_Qualities.UpdateEnchantment(&enchant);
pHit->NotifyEnchantmentUpdated(&enchant);
2020-05-16 18:39:12 -07:00
if (m_CachedSpellCastData.spell_id < 5754 || m_CachedSpellCastData.spell_id > 5756)
{
if (pSource->AsPlayer())
pSource->AsPlayer()->SendText(csprintf("You cast %s on %s", m_CachedSpellCastData.spell->_name.c_str(), pHit->GetName().c_str()), LTT_MAGIC);
2019-07-07 11:39:24 -07:00
2020-05-16 18:39:12 -07:00
if (pHit->AsPlayer())
pHit->AsPlayer()->SendText(csprintf("%s cast %s on you", pSource->GetName().c_str(), m_CachedSpellCastData.spell->_name.c_str()), LTT_MAGIC);
}
2018-03-29 17:01:57 -04:00
}
else
{
2019-07-07 11:39:24 -07:00
int preVarianceDamage;
double baseDamage;
if (isLifeProjectile)
{
2019-07-07 11:39:24 -07:00
preVarianceDamage = selfDrainedAmount;
baseDamage = selfDrainedAmount * selfDrainedDamageRatio;
}
2019-07-07 11:39:24 -07:00
else
{
ProjectileSpellEx *meta = (ProjectileSpellEx *)m_CachedSpellCastData.spellEx->_meta_spell._spell;
double minDamage = (double)meta->_baseIntensity;
double maxDamage = (double)minDamage + meta->_variance;
2018-03-29 17:01:57 -04:00
2019-07-07 11:39:24 -07:00
preVarianceDamage = maxDamage;
baseDamage = Random::RollDice(minDamage, maxDamage);
2018-03-29 17:01:57 -04:00
2019-07-07 11:39:24 -07:00
if (wand)
{
2020-07-15 16:29:27 -07:00
double elementalDamageMod = 1.0;
if (wand->InqDamageType() == InqDamageType())
{
elementalDamageMod = wand->GetElementalDamageMod();
2020-07-15 16:29:27 -07:00
}
2019-07-07 11:39:24 -07:00
if (pSource->AsPlayer() && pHit->AsPlayer()) //pvp
elementalDamageMod = ((elementalDamageMod - 1.0) / 2.0) + 1.0;
baseDamage *= elementalDamageMod;
}
2020-05-16 18:39:12 -07:00
2019-07-07 11:39:24 -07:00
}
2018-03-29 17:01:57 -04:00
2019-07-07 11:39:24 -07:00
DamageEventData dmgEvent;
dmgEvent.source = pSource;
dmgEvent.target = pHit;
dmgEvent.weapon = wand;
dmgEvent.damage_form = DF_MAGIC;
dmgEvent.damage_type = InqDamageType();
dmgEvent.hit_quadrant = DAMAGE_QUADRANT::DQ_UNDEF; //should spells have hit quadrants?
dmgEvent.attackSkill = m_CachedSpellCastData.spell->InqSkillForSpell();
dmgEvent.attackSkillLevel = m_CachedSpellCastData.current_skill;
dmgEvent.preVarianceDamage = preVarianceDamage;
dmgEvent.baseDamage = baseDamage;
2019-07-07 11:39:24 -07:00
dmgEvent.isProjectileSpell = true;
dmgEvent.spell_name = m_CachedSpellCastData.spell->_name;
2019-04-22 22:19:31 +00:00
2019-07-07 11:39:24 -07:00
CalculateCriticalHitData(&dmgEvent, &m_CachedSpellCastData);
dmgEvent.wasCrit = (Random::GenFloat(0.0, 1.0) < dmgEvent.critChance) ? true : false;
2019-07-07 11:39:24 -07:00
double angle = pSource->HeadingFrom(pHit, false);
2018-03-29 17:01:57 -04:00
2019-07-07 11:39:24 -07:00
CalculateAttackConditions(&dmgEvent, 0.0f, angle);
2019-07-07 11:39:24 -07:00
CalculateDamage(&dmgEvent, &m_CachedSpellCastData);
pHit->TryToDealDamage(dmgEvent);
if (pSource && pSource->AsPlayer())
{
// update the target's health on the casting player asap
((CPlayerWeenie*)pSource)->RefreshTargetHealth();
}
}
2020-05-21 21:36:26 +00:00
if (pSource && pSource->AsPlayer())
2020-05-16 18:39:12 -07:00
pSource->AsPlayer()->HandleAetheriaProc(pHit->GetID());
2018-03-29 17:01:57 -04:00
}
}
}
return CWeenieObject::DoCollision(prof);
}
BOOL CSpellProjectile::DoCollision(const class ObjCollisionProfile &prof)
{
Movement_UpdatePos();
// EmitEffect(5, 0.8f);
HandleExplode();
m_fDestroyTime = Timer::cur_time + 1.0;
return CWeenieObject::DoCollision(prof);
}
2019-07-07 20:56:15 +00:00
void CSpellProjectile::DoCollisionEnd(uint32_t object_id)
2018-03-29 17:01:57 -04:00
{
CWeenieObject::DoCollisionEnd(object_id);
}
void CSpellProjectile::makeLifeProjectile(int iSelfDrainedAmount, float fSelfDrainedDamageRatio)
{
isLifeProjectile = true;
selfDrainedAmount = iSelfDrainedAmount;
selfDrainedDamageRatio = fSelfDrainedDamageRatio;
}
2018-03-29 17:01:57 -04:00