Ejemplo n.º 1
0
SpellDesc* MoonScriptCreatureAI::AddSpell(uint32 pSpellId, TargetType pTargetType, float pChance, float pCastTime, int32 pCooldown, float pMinRange, float pMaxRange, bool pStrictRange, const char* pText, TextType pTextType, uint32 pSoundId, EmoteType pEmoteType)
{
	//Cannot add twice same spell id	- M4ksiu: Disabled, until I rewrite SetPhase(...) function to not disable same spells that are in different phases
	//SpellDesc* NewSpell = FindSpellById(pSpellId);
	//if( NewSpell ) return NewSpell;
	SpellDesc* NewSpell = NULL;

	//Find spell info from spell id
	SpellEntry* Info = dbcSpell.LookupEntry(pSpellId);

	// Let us just make sure
	// Use DBC info if we need to.
	if(Info != NULL)
	{
		if(pCastTime == NULL)
			pCastTime = GetDBCCastTime(dbcSpellCastTime.LookupEntry(Info->CastingTimeIndex));
			
		if(pCooldown == NULL)
			pCooldown = Info->RecoveryTime;
			
		if(pMinRange == NULL)
			pMinRange = GetDBCMinRange(dbcSpellRange.LookupEntry(Info->rangeIndex));
			
		if(pMaxRange == NULL)
			pMaxRange = GetDBCMaxRange(dbcSpellRange.LookupEntry(Info->rangeIndex));
	}

	//Create new spell
	NewSpell = new SpellDesc(Info, NULL, pTargetType, pChance, pCastTime, pCooldown, pMinRange, pMaxRange, pStrictRange, pText, pTextType, pSoundId, pEmoteType);
	mSpells.push_back(NewSpell);
	return NewSpell;
}
Ejemplo n.º 2
0
void AIInterface::addSpellToList(AI_Spell *sp)
{
	ASSERT(m_Unit != NULL);
	if(sp->info == NULL)
		return;
	if(sp->info->Id == 0)
		return;

	AI_Spell* nSP = new AI_Spell(sp, sp->cooldown, sp->procCounter);
	if(nSP->info->buffType)
		if(nSP->TargetType != TargetGen_SummonOwner)
			nSP->TargetType = TargetGen_Self;
	if(nSP->casttime == 0)
		nSP->casttime = GetDBCCastTime(dbcSpellCastTime.LookupEntry( nSP->info->CastingTimeIndex ));
	if(nSP->maxdist2cast == 0.0f)
	{
		nSP->maxdist2cast = GetDBCMaxRange( dbcSpellRange.LookupEntry( nSP->info->rangeIndex ) );
		if( nSP->maxdist2cast < sqrt( nSP->info->base_range_or_radius_sqr ) )
			nSP->maxdist2cast = sqrt( nSP->info->base_range_or_radius_sqr );
	}
	if(nSP->mindist2cast == 0.0f)
		nSP->mindist2cast = GetDBCMinRange( dbcSpellRange.LookupEntry( nSP->info->rangeIndex ) );
	if(nSP->cooldown == 0)
		nSP->cooldown = nSP->info->StartRecoveryTime; //avoid spell spamming
	if(nSP->cooldown == 0)
		nSP->cooldown = nSP->info->StartRecoveryCategory; //still 0 ?
	if(nSP->cooldown == 0)
		nSP->cooldown = 4000; //omg, avoid spamming at least
	m_spells.insert(make_pair(nSP->info->Id, nSP));
}
Ejemplo n.º 3
0
void Spell::AddChainTargets(uint32 i, uint32 TargetType, float r, uint32 maxtargets)
{
    if(!m_caster->IsInWorld())
        return;

    Object* targ = m_caster->GetMapMgr()->_GetObject(m_targets.m_unitTarget);
    if(targ == NULL)
        return;

    //if selected target is party member, then jumps on party
    Unit* firstTarget = NULL;
    if(targ->IsUnit())
        firstTarget = TO_UNIT(targ);
    else
        firstTarget = u_caster;

    bool RaidOnly = false;
    float range = GetDBCMaxRange(dbcSpellRange.LookupEntry(m_spellInfo->rangeIndex));//this is probably wrong,
    //this is cast distance, not searching distance
    range *= range;

    //is this party only?
    Player* casterFrom = NULL;
    if(u_caster->IsPlayer())
        casterFrom = TO_PLAYER(u_caster);

    Player* pfirstTargetFrom = NULL;
    if(firstTarget->IsPlayer())
        pfirstTargetFrom = TO_PLAYER(firstTarget);

    if(casterFrom != NULL && pfirstTargetFrom != NULL && casterFrom->GetGroup() == pfirstTargetFrom->GetGroup())
        RaidOnly = true;

    uint32 jumps = m_spellInfo->EffectChainTarget[i];

    //range
    range /= jumps; //hacky, needs better implementation!

    if(m_spellInfo->SpellGroupType && u_caster != NULL)
        SM_FIValue(u_caster->SM[SMT_JUMP_REDUCE][0], (int32*)&jumps, m_spellInfo->SpellGroupType);

    AddTarget(i, TargetType, firstTarget);

    if(jumps <= 1 || ManagedTargets.size() == 0) //1 because we've added the first target, 0 size if spell is resisted
        return;

    ObjectSet::iterator itr;
    for(itr = firstTarget->GetInRangeSetBegin(); itr != firstTarget->GetInRangeSetEnd(); itr++)
    {
        if(!(*itr)->IsUnit() || !TO_UNIT((*itr))->isAlive())
            continue;

        if(RaidOnly)
        {
            if(!(*itr)->IsPlayer())
                continue;

            if(!pfirstTargetFrom->IsGroupMember(TO_PLAYER(*itr)))
                continue;
        }

        //healing spell, full health target = NONO
        if(IsHealingSpell(m_spellInfo) && TO_UNIT(*itr)->GetHealthPct() == 100)
            continue;

        size_t oldsize;
        if(IsInrange(firstTarget->GetPositionX(), firstTarget->GetPositionY(), firstTarget->GetPositionZ(), (*itr), range))
        {
            oldsize = ManagedTargets.size();
            AddTarget(i, TargetType, (*itr));
            if(ManagedTargets.size() == oldsize || ManagedTargets.size() >= jumps) //either out of jumps or a resist
                return;
        }
    }
}