Skip to content

Commit

Permalink
Core/Spells: move some spells so spellscripts
Browse files Browse the repository at this point in the history
  • Loading branch information
joschiwald committed Jan 26, 2014
1 parent 3c0b906 commit 96060bf
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 103 deletions.
7 changes: 7 additions & 0 deletions sql/updates/world/2014_01_26_01_world_spells.sql
@@ -0,0 +1,7 @@
DELETE FROM `spell_script_names` WHERE `spell_id` IN (58387,20230,-48438);
INSERT INTO `spell_script_names` (`spell_id` ,`ScriptName`) VALUES
(58387, 'spell_warr_glyph_of_sunder_armor'),
(20230, 'spell_warr_retaliation'),
(-48438,'spell_dru_wild_growth');

DELETE FROM `spell_proc_event` WHERE `entry`=58387;
38 changes: 7 additions & 31 deletions src/server/game/Entities/Unit/Unit.cpp
Expand Up @@ -5668,17 +5668,6 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere
break;
}
}

// Retaliation
if (dummySpell->SpellFamilyFlags[1] & 0x8)
{
// check attack comes not from behind
if (!HasInArc(M_PI, victim) || HasUnitState(UNIT_STATE_STUNNED))
return false;

triggered_spell_id = 22858;
break;
}
// Second Wind
if (dummySpell->SpellIconID == 1697)
{
Expand Down Expand Up @@ -5708,19 +5697,6 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere
triggered_spell_id = 58374;
break;
}
// Glyph of Sunder Armor
if (dummySpell->Id == 58387)
{
if (!victim || !victim->IsAlive() || !procSpell)
return false;

target = SelectNearbyTarget(victim);
if (!target)
return false;

triggered_spell_id = 58567;
break;
}
break;
}
case SPELLFAMILY_WARLOCK:
Expand Down Expand Up @@ -9365,9 +9341,7 @@ void Unit::SetMinion(Minion *minion, bool apply)
}

if (minion->m_Properties && minion->m_Properties->Type == SUMMON_TYPE_MINIPET)
{
SetCritterGUID(minion->GetGUID());
}

// PvP, FFAPvP
minion->SetByteValue(UNIT_FIELD_BYTES_2, 1, GetByteValue(UNIT_FIELD_BYTES_2, 1));
Expand Down Expand Up @@ -13274,12 +13248,14 @@ void Unit::SetLevel(uint8 lvl)
{
SetUInt32Value(UNIT_FIELD_LEVEL, lvl);

// group update
if (GetTypeId() == TYPEID_PLAYER && ToPlayer()->GetGroup())
ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL);
if (Player* player = ToPlayer())
{
// group update
if (player->GetGroup())
player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL);

if (GetTypeId() == TYPEID_PLAYER)
sWorld->UpdateCharacterNameDataLevel(ToPlayer()->GetGUIDLow(), lvl);
sWorld->UpdateCharacterNameDataLevel(GetGUIDLow(), lvl);
}
}

void Unit::SetHealth(uint32 val)
Expand Down
24 changes: 23 additions & 1 deletion src/server/game/Entities/Unit/Unit.h
Expand Up @@ -2261,12 +2261,23 @@ namespace Trinity
{
public:
PowerPctOrderPred(Powers power, bool ascending = true) : _power(power), _ascending(ascending) { }
bool operator() (Unit const* a, Unit const* b) const

bool operator()(WorldObject const* objA, WorldObject const* objB) const
{
Unit const* a = objA->ToUnit();
Unit const* b = objB->ToUnit();
float rA = (a && a->GetMaxPower(_power)) ? float(a->GetPower(_power)) / float(a->GetMaxPower(_power)) : 0.0f;
float rB = (b && b->GetMaxPower(_power)) ? float(b->GetPower(_power)) / float(b->GetMaxPower(_power)) : 0.0f;
return _ascending ? rA < rB : rA > rB;
}

bool operator()(Unit const* a, Unit const* b) const
{
float rA = a->GetMaxPower(_power) ? float(a->GetPower(_power)) / float(a->GetMaxPower(_power)) : 0.0f;
float rB = b->GetMaxPower(_power) ? float(b->GetPower(_power)) / float(b->GetMaxPower(_power)) : 0.0f;
return _ascending ? rA < rB : rA > rB;
}

private:
Powers const _power;
bool const _ascending;
Expand All @@ -2277,12 +2288,23 @@ namespace Trinity
{
public:
HealthPctOrderPred(bool ascending = true) : _ascending(ascending) { }

bool operator()(WorldObject const* objA, WorldObject const* objB) const
{
Unit const* a = objA->ToUnit();
Unit const* b = objB->ToUnit();
float rA = (a && a->GetMaxHealth()) ? float(a->GetHealth()) / float(a->GetMaxHealth()) : 0.0f;
float rB = (b && b->GetMaxHealth()) ? float(b->GetHealth()) / float(b->GetMaxHealth()) : 0.0f;
return _ascending ? rA < rB : rA > rB;
}

bool operator() (Unit const* a, Unit const* b) const
{
float rA = a->GetMaxHealth() ? float(a->GetHealth()) / float(a->GetMaxHealth()) : 0.0f;
float rB = b->GetMaxHealth() ? float(b->GetHealth()) / float(b->GetMaxHealth()) : 0.0f;
return _ascending ? rA < rB : rA > rB;
}

private:
bool const _ascending;
};
Expand Down
81 changes: 27 additions & 54 deletions src/server/game/Spells/Spell.cpp
Expand Up @@ -1276,17 +1276,6 @@ void Spell::SelectImplicitAreaTargets(SpellEffIndex effIndex, SpellImplicitTarge
maxSize = m_spellInfo->MaxAffectedTargets;
power = POWER_HEALTH;
break;
case 57669: // Replenishment
// In arenas Replenishment may only affect the caster
if (m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->ToPlayer()->InArena())
{
unitTargets.clear();
unitTargets.push_back(m_caster);
break;
}
maxSize = 10;
power = POWER_MANA;
break;
default:
break;
}
Expand Down Expand Up @@ -1319,22 +1308,6 @@ void Spell::SelectImplicitAreaTargets(SpellEffIndex effIndex, SpellImplicitTarge
++itr;
}
break;
case SPELLFAMILY_DRUID:
if (m_spellInfo->SpellFamilyFlags[1] == 0x04000000) // Wild Growth
{
maxSize = m_caster->HasAura(62970) ? 6 : 5; // Glyph of Wild Growth
power = POWER_HEALTH;
}
else
break;

// Remove targets outside caster's raid
for (std::list<Unit*>::iterator itr = unitTargets.begin(); itr != unitTargets.end();)
if (!(*itr)->IsInRaidWith(m_caster))
itr = unitTargets.erase(itr);
else
++itr;
break;
default:
break;
}
Expand Down Expand Up @@ -1427,33 +1400,33 @@ void Spell::SelectImplicitCasterDestTargets(SpellEffIndex effIndex, SpellImplici
break;
case TARGET_DEST_CASTER_FISHING:
{
float min_dis = m_spellInfo->GetMinRange(true);
float max_dis = m_spellInfo->GetMaxRange(true);
float dis = (float)rand_norm() * (max_dis - min_dis) + min_dis;
float x, y, z, angle;
angle = (float)rand_norm() * static_cast<float>(M_PI * 35.0f / 180.0f) - static_cast<float>(M_PI * 17.5f / 180.0f);
m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE, dis, angle);

float ground = z;
float liquidLevel = m_caster->GetMap()->GetWaterOrGroundLevel(x, y, z, &ground);
if (liquidLevel <= ground) // When there is no liquid Map::GetWaterOrGroundLevel returns ground level
{
SendCastResult(SPELL_FAILED_NOT_HERE);
SendChannelUpdate(0);
finish(false);
return;
}

if (ground + 0.75 > liquidLevel)
{
SendCastResult(SPELL_FAILED_TOO_SHALLOW);
SendChannelUpdate(0);
finish(false);
return;
}

dest = SpellDestination(x, y, liquidLevel, m_caster->GetOrientation());
break;
float minDist = m_spellInfo->GetMinRange(true);
float maxDist = m_spellInfo->GetMaxRange(true);
float dist = frand(minDist, maxDist);
float x, y, z, angle;
float angle = float(rand_norm()) * static_cast<float>(M_PI * 35.0f / 180.0f) - static_cast<float>(M_PI * 17.5f / 180.0f);
m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE, dis, angle);

float ground = z;
float liquidLevel = m_caster->GetMap()->GetWaterOrGroundLevel(x, y, z, &ground);
if (liquidLevel <= ground) // When there is no liquid Map::GetWaterOrGroundLevel returns ground level
{
SendCastResult(SPELL_FAILED_NOT_HERE);
SendChannelUpdate(0);
finish(false);
return;
}

if (ground + 0.75 > liquidLevel)
{
SendCastResult(SPELL_FAILED_TOO_SHALLOW);
SendChannelUpdate(0);
finish(false);
return;
}

dest = SpellDestination(x, y, liquidLevel, m_caster->GetOrientation());
break;
}
default:
{
Expand Down
60 changes: 60 additions & 0 deletions src/server/scripts/Spells/spell_druid.cpp
Expand Up @@ -993,6 +993,65 @@ class spell_dru_t10_restoration_4p_bonus : public SpellScriptLoader
}
};

class RaidCheck
{
public:
explicit RaidCheck(Unit const* caster) : _caster(caster) { }

bool operator()(WorldObject* obj) const
{
if (Unit* target = obj->ToUnit())
return !_caster->IsInRaidWith(target);

return true;
}

private:
Unit const* _caster;
};

// -48438 - Wild Growth
class spell_dru_wild_growth : public SpellScriptLoader
{
public:
spell_dru_wild_growth() : SpellScriptLoader("spell_dru_wild_growth") { }

class spell_dru_wild_growth_SpellScript : public SpellScript
{
PrepareSpellScript(spell_dru_wild_growth_SpellScript);

bool Validate(SpellInfo const* spellInfo) OVERRIDE
{
if (spellInfo->Effects[EFFECT_2].IsEffect() || !spellInfo->Effects[EFFECT_2].CalcValue())
return false;
return true;
}

void FilterTargets(std::list<WorldObject*>& targets)
{
targets.remove_if(RaidCheck(GetCaster()));

int32 const maxTargets = GetSpellInfo()->Effects[EFFECT_2].CalcValue(GetCaster());

if (targets.size() > maxTargets)
{
targets.sort(Trinity::HealthPctOrderPred());
targets.resize(maxTargets);
}
}

void Register() OVERRIDE
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_dru_wild_growth_SpellScript::FilterTargets, EFFECT_0, TARGET_UNIT_DEST_AREA_ALLY);
}
};

SpellScript* GetSpellScript() const OVERRIDE
{
return new spell_dru_wild_growth_SpellScript();
}
};

void AddSC_druid_spell_scripts()
{
new spell_dru_dash();
Expand All @@ -1018,4 +1077,5 @@ void AddSC_druid_spell_scripts()
new spell_dru_tiger_s_fury();
new spell_dru_typhoon();
new spell_dru_t10_restoration_4p_bonus();
new spell_dru_wild_growth();
}
57 changes: 50 additions & 7 deletions src/server/scripts/Spells/spell_generic.cpp
Expand Up @@ -2963,22 +2963,65 @@ enum Replenishment
SPELL_INFINITE_REPLENISHMENT = 61782
};

class ReplenishmentCheck
{
public:
bool operator()(WorldObject* obj) const
{
if (Unit* target = obj->ToUnit())
return target->getPowerType() != POWER_MANA;

return true;
}
};

class spell_gen_replenishment : public SpellScriptLoader
{
public:
spell_gen_replenishment() : SpellScriptLoader("spell_gen_replenishment") { }

class spell_gen_replenishment_AuraScript : public AuraScript
class spell_gen_replenishment_SpellScript : public SpellScript
{
PrepareAuraScript(spell_gen_replenishment_AuraScript);
PrepareSpellScript(spell_gen_replenishment_SpellScript);

bool Validate(SpellInfo const* /*spellInfo*/) OVERRIDE
void RemoveInvalidTargets(std::list<WorldObject*>& targets)
{
if (!sSpellMgr->GetSpellInfo(SPELL_REPLENISHMENT) ||
!sSpellMgr->GetSpellInfo(SPELL_INFINITE_REPLENISHMENT))
return false;
return true;
// In arenas Replenishment may only affect the caster
if (Player* caster = GetCaster()->ToPlayer())
{
if (caster->InArena())
{
targets.clear();
targets.push_back(caster);
return;
}
}

targets.remove_if(ReplenishmentCheck());

uint8 const maxTargets = 10;

if (targets.size() > maxTargets)
{
targets.sort(Trinity::PowerPctOrderPred(POWER_MANA));
targets.resize(maxTargets);
}
}

void Register() OVERRIDE
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_gen_replenishment_SpellScript::RemoveInvalidTargets, EFFECT_ALL, TARGET_UNIT_CASTER_AREA_RAID);
}
};

SpellScript* GetSpellScript() const OVERRIDE
{
return new spell_gen_replenishment_SpellScript();
}

class spell_gen_replenishment_AuraScript : public AuraScript
{
PrepareAuraScript(spell_gen_replenishment_AuraScript);

bool Load() OVERRIDE
{
Expand Down
5 changes: 3 additions & 2 deletions src/server/scripts/Spells/spell_rogue.cpp
Expand Up @@ -255,10 +255,11 @@ class spell_rog_deadly_poison : public SpellScriptLoader
};

// 51690 - Killing Spree
#define KillingSpreeScriptName "spell_rog_killing_spree"
class spell_rog_killing_spree : public SpellScriptLoader
{
public:
spell_rog_killing_spree() : SpellScriptLoader("spell_rog_killing_spree") { }
spell_rog_killing_spree() : SpellScriptLoader(KillingSpreeScriptName) { }

class spell_rog_killing_spree_SpellScript : public SpellScript
{
Expand All @@ -274,7 +275,7 @@ class spell_rog_killing_spree : public SpellScriptLoader
{
if (Aura* aura = GetCaster()->GetAura(SPELL_ROGUE_KILLING_SPREE))
{
if (spell_rog_killing_spree_AuraScript* script = dynamic_cast<spell_rog_killing_spree_AuraScript*>(aura->GetScriptByName("spell_rog_killing_spree")))
if (spell_rog_killing_spree_AuraScript* script = dynamic_cast<spell_rog_killing_spree_AuraScript*>(aura->GetScriptByName(KillingSpreeScriptName)))
script->AddTarget(GetHitUnit());
}
}
Expand Down

1 comment on commit 96060bf

@L30m4nc3r
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.