Beispiel #1
0
        private void PopulatePassive()
        {
            explicitTargetType = SpellExplicitTargetType.Caster;
            damageClass        = SpellDamageClass.None;
            spellDispel        = SpellDispelType.None;
            mechanic           = SpellMechanics.None;

            explicitCastTargets = SpellCastTargetFlags.UnitAlly;
            schoolMask          = 0;
            preventionType      = 0;
            attributes          = SpellAttributes.Passive;
            attributesExtra     = SpellExtraAttributes.DoesNotTriggerGcd | SpellExtraAttributes.IgnoreGcd | SpellExtraAttributes.NotStealable;
            attributesCustom    = SpellCustomAttributes.CastWithoutAnimation;

            targetEntityTypeMask  = EnityTypeMask.Unit;
            rangedFlags           = SpellRangeFlags.Default;
            interruptFlags        = 0;
            castIgnoringMechanics = 0;

            cooldownTime         = 0;
            categoryCooldownTime = 0;
            globalCooldownTime   = 0;
            castTime             = 0;
            minCastTime          = 0;

            minRangeHostile = 0;
            minRangeFriend  = 0;
            maxRangeHostile = 0;
            maxRangeFriend  = 0;
            speed           = 0;
        }
    public void CalculateSpellDamageTaken(SpellDamage damageInfo, int damage, TrinitySpellInfo spellInfo, bool crit)
    {
        if (damage < 0)
        {
            return;
        }

        Unit victim = damageInfo.Target;

        if (victim == null || !victim.IsAlive())
        {
            return;
        }

        SpellSchoolMask damageSchoolMask = damageInfo.SchoolMask;

        // Script Hook For CalculateSpellDamageTaken -- Allow scripts to change the Damage post class mitigation calculations
        //sScriptMgr->ModifySpellDamageTaken(damageInfo->target, damageInfo->attacker, damage);

        // Calculate absorb resist

        /*if (damage > 0)
         * {
         *  CalcAbsorbResist(victim, damageSchoolMask, SPELL_DIRECT_DAMAGE, damage, &damageInfo->absorb, &damageInfo->resist, spellInfo);
         *  damage -= damageInfo->absorb + damageInfo->resist;
         * }
         * else
         *  damage = 0;*/

        damageInfo.Damage = damage;
        damageInfo.Crit   = crit;
    }
Beispiel #3
0
        public void Initialize()
        {
            this.m_location    = Caster.Location;
            this.m_orientation = Caster.Orientation;
            this.m_health      = Caster.Health.Current;

            for (int i = 0; i < 3; i++)
            {
                m_basepoints[i] = (int)(Spell.EffectBaseDice[i] + Spell.EffectBasePoints[i]);
            }

            if (SchoolMask == SpellSchoolMask.SPELL_SCHOOL_MASK_MAGIC)
            {
                this.SchoolMask = (SpellSchoolMask)(1 << (int)Spell.School);
            }

            if (SchoolMask == SpellSchoolMask.SPELL_SCHOOL_MASK_NORMAL)
            {
                SpellType = CurrentSpellType.CURRENT_MELEE_SPELL;
            }
            else if (Spell.ChannelInterruptFlags != 0)
            {
                SpellType = CurrentSpellType.CURRENT_CHANNELED_SPELL;
            }

            this.PowerCost = SetPowerCost();
        }
Beispiel #4
0
            internal bool IsImmuneToSpellSchool(SpellSchoolMask schoolMask, SpellInfo spellInfo, Unit caster)
            {
                if (schoolMask != 0)
                {
                    SpellSchoolMask immunedSchools = 0;
                    foreach (var schoolImmunityEntry in schoolImmunities)
                    {
                        if (!schoolImmunityEntry.Key.HasAnyFlag(spellInfo.SchoolMask))
                        {
                            continue;
                        }

                        foreach (SpellInfo immunitySpells in schoolImmunityEntry.Value)
                        {
                            if (!immunitySpells.IsPositive || !spellInfo.IsPositive || caster != null && !unit.IsFriendlyTo(caster))
                            {
                                if (!spellInfo.CanPierceImmuneAura(immunitySpells))
                                {
                                    immunedSchools |= schoolImmunityEntry.Key;
                                }
                            }
                        }
                    }

                    if (immunedSchools.HasTargetFlag(spellInfo.SchoolMask))
                    {
                        return(true);
                    }
                }

                return(false);
            }
Beispiel #5
0
 public SpellNonMeleeDamage(Unit _attacker, Unit _target, SpellInfo _spellInfo, SpellCastVisual spellVisual, SpellSchoolMask _schoolMask, ObjectGuid _castId = default)
 {
     target       = _target;
     attacker     = _attacker;
     Spell        = _spellInfo;
     SpellVisual  = spellVisual;
     schoolMask   = _schoolMask;
     castId       = _castId;
     preHitHealth = (uint)_target.GetHealth();
 }
Beispiel #6
0
            internal bool IsImmunedToDamage(SpellInfo spellInfo, SpellSchoolMask?schoolMaskOverride = null, Unit caster = null)
            {
                SpellSchoolMask schoolMask = schoolMaskOverride ?? spellInfo.SchoolMask;

                if (spellInfo.HasAttribute(SpellAttributes.UnaffectedByInvulnerability) && spellInfo.HasAttribute(SpellAttributes.IgnoreHitResult))
                {
                    return(false);
                }

                if (spellInfo.HasAttribute(SpellAttributes.UnaffectedBySchoolImmune))
                {
                    return(false);
                }

                return(IsImmuneToSpellSchool(schoolMask, spellInfo, caster));
            }
    public SpellDamage(Unit attacker, Unit target, int _SpellID, SpellSchoolMask _schoolMask, Guid _castId = default(Guid))
    {
        Attacker = attacker;
        Target   = target;
        CastId   = _castId;
        SpellID  = _SpellID;

        SchoolMask = _schoolMask;

        Damage      = 0;
        Absorb      = 0;
        Resist      = 0;
        Crit        = false;
        PeriodicLog = false;

        HitInfo = HitInfo.AffectsVictim;
    }
Beispiel #8
0
 public static bool HasTargetFlag(this SpellSchoolMask baseFlags, SpellSchoolMask flag)
 {
     return((baseFlags & flag) == flag);
 }
    public int DealDamage(Unit victim, int damage, CleanDamage cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, TrinitySpellInfo spellProto)
    {
        // Hook for OnDamage Event
        //sScriptMgr->OnDamage(this, victim, damage);

        if (damage < 1)
        {
            return(0);
        }

        int health = victim.Character.health.CurrentValue;

        if (health <= damage)
        {
            Debug.Log("DealDamage: Victim just died");

            Kill(victim);
        }
        else
        {
            Debug.Log("DealDamage: Alive");

            victim.Character.health.Decrease(damage);
            //victim.ModifyHealth(-damage);
        }
        return(damage);
    }
Beispiel #10
0
        public List <SpellResourceCost> CalcPowerCost(Unit caster, SpellSchoolMask schoolMask)
        {
            var powers     = PowerCosts;
            var costs      = new List <SpellResourceCost>(PowerCosts.Count);
            int healthCost = 0;

            foreach (var power in powers)
            {
                // bse powerCost
                int powerCost = power.PowerCost;
                // percent cost from total amount
                if (power.PowerCostPercentage > 0)
                {
                    switch (power.SpellResourceType)
                    {
                    // health as power used
                    case SpellResourceType.Health:
                        powerCost += caster.MaxHealth.CalculatePercentage(power.PowerCostPercentage);
                        break;

                    case SpellResourceType.Mana:
                        powerCost += caster.BaseMana.CalculatePercentage(power.PowerCostPercentage);
                        break;

                    case SpellResourceType.Rage:
                    case SpellResourceType.Focus:
                    case SpellResourceType.Energy:
                        powerCost += caster.GetMaxPower(power.SpellResourceType).CalculatePercentage(power.PowerCostPercentage);
                        break;

                    case SpellResourceType.Runes:
                    case SpellResourceType.RunicPower:
                        Debug.unityLogger.LogWarning("Spells", $"CalculateManaCost for {power.SpellResourceType}: Not implemented yet!");
                        break;

                    default:
                        Debug.unityLogger.LogError("Spells", $"CalculateManaCost: Unknown power type '{power.SpellResourceType}' in spell {Id}");
                        continue;
                    }
                }

                if (power.SpellResourceType == SpellResourceType.Health)
                {
                    healthCost += powerCost;
                    continue;
                }

                bool found = false;
                for (int i = 0; i < costs.Count; i++)
                {
                    if (costs[i].SpellResource == power.SpellResourceType)
                    {
                        costs[i] = new SpellResourceCost(costs[i].SpellResource, costs[i].Amount + powerCost);
                        found    = true;
                    }
                }

                if (!found)
                {
                    costs.Add(new SpellResourceCost(power.SpellResourceType, powerCost));
                }
            }

            if (healthCost > 0)
            {
                costs.Add(new SpellResourceCost(SpellResourceType.Health, healthCost));
            }

            costs.RemoveAll(cost => cost.SpellResource != SpellResourceType.Runes && cost.Amount <= 0);

            return(costs);
        }
            private float CalculateSpellCriticalChance(Unit victim, SpellInfo spellInfo, SpellSchoolMask schoolMask)
            {
                if (spellInfo.HasAttribute(SpellAttributes.CantCrit) || spellInfo.DamageClass == SpellDamageClass.None)
                {
                    return(0.0f);
                }

                if (spellInfo.HasAttribute(SpellAttributes.AlwaysCrit))
                {
                    return(100.0f);
                }

                float critChance = unit.CritPercentage;

                if (victim == null)
                {
                    return(Mathf.Max(critChance, 0.0f));
                }

                switch (spellInfo.DamageClass)
                {
                case SpellDamageClass.Magic:
                    if (!spellInfo.IsPositive)
                    {
                        critChance += victim.Auras.TotalAuraModifier(AuraEffectType.ModAttackerSpellCritChance);
                    }
                    goto default;

                case SpellDamageClass.Melee:
                    if (!spellInfo.IsPositive)
                    {
                        critChance += victim.Auras.TotalAuraModifier(AuraEffectType.ModAttackerMeleeCritChance);
                    }
                    goto default;

                case SpellDamageClass.Ranged:
                    if (!spellInfo.IsPositive)
                    {
                        critChance += victim.Auras.TotalAuraModifier(AuraEffectType.ModAttackerRangedCritChance);
                    }
                    goto default;

                default:
                    critChance += victim.Auras.TotalAuraModifierForCaster(AuraEffectType.ModAttackerSpellCritChanceForCaster, unit.Id);
                    critChance += victim.Auras.TotalAuraModifier(AuraEffectType.ModAttackerSpellAndWeaponCritChance);
                    break;
                }

                return(Mathf.Max(critChance, 0.0f));
            }
Beispiel #12
0
        public void LockSpellSchool(SpellSchoolMask schoolMask, TimeSpan lockoutTime)
        {
            DateTime now        = GameTime.GetGameTimeSystemPoint();
            DateTime lockoutEnd = now + lockoutTime;

            for (int i = 0; i < (int)SpellSchools.Max; ++i)
            {
                if (Convert.ToBoolean((SpellSchoolMask)(1 << i) & schoolMask))
                {
                    _schoolLockouts[i] = lockoutEnd;
                }
            }

            List <uint> knownSpells = new();
            Player      plrOwner    = _owner.ToPlayer();

            if (plrOwner)
            {
                foreach (var p in plrOwner.GetSpellMap())
                {
                    if (p.Value.State != PlayerSpellState.Removed)
                    {
                        knownSpells.Add(p.Key);
                    }
                }
            }
            else if (_owner.IsPet())
            {
                Pet petOwner = _owner.ToPet();
                foreach (var p in petOwner.m_spells)
                {
                    if (p.Value.state != PetSpellState.Removed)
                    {
                        knownSpells.Add(p.Key);
                    }
                }
            }
            else
            {
                Creature creatureOwner = _owner.ToCreature();
                for (byte i = 0; i < SharedConst.MaxCreatureSpells; ++i)
                {
                    if (creatureOwner.m_spells[i] != 0)
                    {
                        knownSpells.Add(creatureOwner.m_spells[i]);
                    }
                }
            }

            SpellCooldownPkt spellCooldown = new();

            spellCooldown.Caster = _owner.GetGUID();
            spellCooldown.Flags  = SpellCooldownFlags.LossOfControlUi;
            foreach (uint spellId in knownSpells)
            {
                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, _owner.GetMap().GetDifficultyID());
                if (spellInfo.IsCooldownStartedOnEvent())
                {
                    continue;
                }

                if (!spellInfo.PreventionType.HasAnyFlag(SpellPreventionType.Silence))
                {
                    continue;
                }

                if ((schoolMask & spellInfo.GetSchoolMask()) == 0)
                {
                    continue;
                }

                if (GetRemainingCooldown(spellInfo) < lockoutTime)
                {
                    AddCooldown(spellId, 0, lockoutEnd, 0, now);
                }

                // always send cooldown, even if it will be shorter than already existing cooldown for LossOfControl UI
                spellCooldown.SpellCooldowns.Add(new SpellCooldownStruct(spellId, (uint)lockoutTime.TotalMilliseconds));
            }

            Player player = GetPlayerOwner();

            if (player)
            {
                if (!spellCooldown.SpellCooldowns.Empty())
                {
                    player.SendPacket(spellCooldown);
                }
            }
        }