Esempio n. 1
0
 public void Detonate()
 {
     if (Detonated)
     {
         return;
     }
     projectile.scale   *= 4;
     projectile.damage  *= 2;
     this.Detonated      = true;
     projectile.velocity = Vector2.Zero;
     Frame = 9;
     projectile.timeLeft = 180;
     if (ProjMod.IsGuardianProjectile(projectile.whoAmI))
     {
         TerraGuardian tg             = ProjMod.GuardianProj[projectile.whoAmI];
         Rectangle     ExplosionRange = new Rectangle((int)projectile.position.X - (int)(48 * projectile.scale), (int)projectile.position.Y - (int)(48 * projectile.scale)
                                                      , (int)(96 * projectile.scale), (int)(96 * projectile.scale));
         for (int t = 0; t < 255; t++)
         {
             if (Main.player[t].active && tg.IsPlayerHostile(Main.player[t]) && Main.player[t].getRect().Intersects(ExplosionRange))
             {
                 double dmg = Main.player[t].Hurt(Terraria.DataStructures.PlayerDeathReason.ByCustomReason(" didn't survived a electric explosion."), projectile.damage, projectile.direction, true);
                 if (dmg > 0)
                 {
                     Main.player[t].AddBuff(Terraria.ID.BuffID.Electrified, 5 * 60);
                 }
             }
             if (t < 200 && Main.npc[t].active && tg.IsNpcHostile(Main.npc[t]) && !Main.npc[t].dontTakeDamage && Main.npc[t].getRect().Intersects(ExplosionRange))
             {
                 double dmg = Main.npc[t].StrikeNPC(projectile.damage, projectile.knockBack, projectile.direction);
                 if (dmg > 0)
                 {
                     Main.npc[t].AddBuff(Terraria.ID.BuffID.Electrified, 5 * 60);
                 }
             }
         }
         foreach (TerraGuardian othertg in MainMod.ActiveGuardians.Values)
         {
             if (tg.IsGuardianHostile(othertg) && othertg.HitBox.Intersects(ExplosionRange))
             {
                 int dmg = othertg.Hurt(projectile.damage, projectile.direction, false, false, " didn't survived a electric explosion.");
                 if (dmg > 0)
                 {
                     othertg.AddBuff(Terraria.ID.BuffID.Electrified, 5 * 60);
                 }
             }
         }
     }
     projectile.friendly = projectile.hostile = false;
 }
Esempio n. 2
0
        public bool IsFriendly(TerraGuardian guardian)
        {
            switch (CharType)
            {
            case TerraGuardian.TargetTypes.Player:
                return(!guardian.IsPlayerHostile(Main.player[MyPosition]));

            case TerraGuardian.TargetTypes.Npc:
                return(!guardian.IsNpcHostile(Main.npc[MyPosition]));

            case TerraGuardian.TargetTypes.Guardian:
                return(!guardian.IsGuardianHostile(MainMod.ActiveGuardians[MyPosition]));
            }
            return(false);
        }
        public GuardianSpecialAttackData.AffectedTargets[] AreaDamage(TerraGuardian Caster, int Damage, float Knockback, Rectangle Hitbox, byte CriticalRate = 0, bool AffectAllies = false, bool BlockConsecutiveHits = true)
        {
            List <GuardianSpecialAttackData.AffectedTargets> Targets = new List <GuardianSpecialAttackData.AffectedTargets>();
            float StackedDamage   = 0;
            float StackedCritical = 0;
            int   NewDamage       = Damage;

            if (Caster.OwnerPos > -1 && !MainMod.DisableDamageReductionByNumberOfCompanions)
            {
                float DamageMult = Main.player[Caster.OwnerPos].GetModPlayer <PlayerMod>().DamageMod;
                NewDamage = (int)(NewDamage * DamageMult);
            }
            for (int i = 0; i < 255; i++)
            {
                if (Main.player[i].active && !Main.player[i].dead)
                {
                    Player player = Main.player[i];
                    if ((!BlockConsecutiveHits || !Caster.PlayerHasBeenHit(i)) && (AffectAllies || Caster.IsPlayerHostile(player)) && player.getRect().Intersects(Hitbox))
                    {
                        int HitDirection = Caster.Direction;
                        if ((HitDirection == 1 && player.Center.X < Caster.Position.X) ||
                            (HitDirection == -1 && player.Center.X > Caster.Position.X))
                        {
                            HitDirection *= -1;
                        }
                        bool   Critical = Main.rand.Next(100) < CriticalRate;
                        double result   = player.Hurt(Terraria.DataStructures.PlayerDeathReason.ByCustomReason(" didn't survived " + Caster.Name + "'s attack."), NewDamage, HitDirection, false, false, Critical);
                        if (result > 0)
                        {
                            GuardianSpecialAttackData.AffectedTargets affected = new GuardianSpecialAttackData.AffectedTargets(player);
                            affected.SetDamage((int)result);
                            Targets.Add(affected);
                            if (BlockConsecutiveHits)
                            {
                                Caster.AddPlayerHit(player.whoAmI);
                            }
                            Caster.IncreaseDamageStacker((int)result, player.statLifeMax2);
                            StackedDamage += (float)result;
                            if (Critical)
                            {
                                StackedCritical += (float)result;
                            }
                        }
                    }
                }
                if (i < 200 && Main.npc[i].active)
                {
                    NPC npc = Main.npc[i];
                    if ((!BlockConsecutiveHits || !Caster.NpcHasBeenHit(i)) && Caster.IsNpcHostile(npc) && npc.getRect().Intersects(Hitbox))
                    {
                        int HitDirection = Caster.Direction;
                        if ((HitDirection == 1 && npc.Center.X < Caster.Position.X) ||
                            (HitDirection == -1 && npc.Center.X > Caster.Position.X))
                        {
                            HitDirection *= -1;
                        }
                        bool   Critical = Main.rand.Next(100) < CriticalRate;
                        double result   = npc.StrikeNPC(NewDamage, Knockback, HitDirection, Critical);
                        if (result > 0)
                        {
                            GuardianSpecialAttackData.AffectedTargets affected = new GuardianSpecialAttackData.AffectedTargets(npc);
                            affected.SetDamage((int)result);
                            Targets.Add(affected);
                            if (BlockConsecutiveHits)
                            {
                                Caster.AddNpcHit(npc.whoAmI);
                            }
                            Caster.IncreaseDamageStacker((int)result, npc.lifeMax);
                            StackedDamage += (float)result;
                            if (Critical)
                            {
                                StackedCritical += (float)result;
                            }
                        }
                    }
                }
            }
            foreach (int i in MainMod.ActiveGuardians.Keys)
            {
                if (i != Caster.WhoAmID && (AffectAllies || Caster.IsGuardianHostile(MainMod.ActiveGuardians[i])))
                {
                    TerraGuardian tg = MainMod.ActiveGuardians[i];
                    if (tg.HitBox.Intersects(Hitbox))
                    {
                        int HitDirection = Caster.Direction;
                        if ((HitDirection == 1 && tg.Position.X < Caster.Position.X) ||
                            (HitDirection == -1 && tg.Position.X > Caster.Position.X))
                        {
                            HitDirection *= -1;
                        }
                        bool   Critical = Main.rand.Next(100) < CriticalRate;
                        double result   = tg.Hurt(NewDamage, HitDirection, Critical, DeathMessage: " didn't survived " + Caster.Name + "'s attack.");
                        if (result > 0)
                        {
                            GuardianSpecialAttackData.AffectedTargets affected = new GuardianSpecialAttackData.AffectedTargets(tg);
                            affected.SetDamage((int)result);
                            Targets.Add(affected);
                            Caster.IncreaseDamageStacker((int)result, tg.MHP);
                            StackedDamage += (float)result;
                            if (Critical)
                            {
                                StackedCritical += (float)result;
                            }
                        }
                    }
                }
            }
            if (StackedDamage > 0)
            {
                GuardianSkills.SkillTypes AttackSkill = GuardianSkills.SkillTypes.Strength;
                switch (AttackType)
                {
                case SubAttackCombatType.Ranged:
                    AttackSkill = GuardianSkills.SkillTypes.Ballistic;
                    break;

                case SubAttackCombatType.Magic:
                    AttackSkill = GuardianSkills.SkillTypes.Mysticism;
                    break;
                }
                Caster.AddSkillProgress(StackedDamage, AttackSkill);
                if (StackedCritical > 0)
                {
                    Caster.AddSkillProgress(StackedDamage, GuardianSkills.SkillTypes.Luck);
                }
            }
            return(Targets.ToArray());
        }
        public override void Update(TerraGuardian guardian)
        {
            LiebreBase.ReaperGuardianData data = (LiebreBase.ReaperGuardianData)guardian.Data;
            switch (Step)
            {
            case 0:
                if (StepStart)
                {
                    SoulsValue = data.SoulsLoaded;
                    if (SoulsValue >= LiebreBase.MaxSoulsContainedValue)
                    {
                        guardian.SaySomething("*I must go, now!*");
                    }
                    else if (SoulsValue >= LiebreBase.MaxSoulsContainedValue * 0.9f)
                    {
                        guardian.SaySomething("*I'll unload those souls, I feel like I'm reaching my capacity.*");
                    }
                    else
                    {
                        guardian.SaySomething("*I'll be right back.*");
                    }
                }
                IgnoreCombat = true;
                if (Main.rand.NextDouble() < 0.333)
                {
                    Dust.NewDust(guardian.TopLeftPosition, guardian.Width, guardian.Height, 192, 0, -0.2f, Scale: Main.rand.NextFloat(0.8f, 1.2f));
                }
                if (Time >= 3 * 60)
                {
                    ChangeStep();
                    data.SoulsLoaded     = 0;
                    Invisibility         = true;
                    LastWasPlayerMounted = guardian.PlayerMounted;
                    guardian.ToggleMount(true);
                    guardian.ClearMessagesSaid();
                }
                break;

            case 1:
                Invisibility = true;
                IgnoreCombat = true;
                Inactivity   = true;
                if (guardian.OwnerPos > -1)
                {
                    guardian.Position = Main.player[guardian.OwnerPos].Bottom;
                }
                if (Time >= 10 * 60)
                {
                    ChangeStep();
                }
                break;

            case 2:
                Invisibility = false;
                IgnoreCombat = false;
                Inactivity   = false;
                if (StepStart)
                {
                    guardian.Spawn();
                    if (guardian.OwnerPos > -1)
                    {
                        guardian.Position = Main.player[guardian.OwnerPos].Bottom;
                        if (LastWasPlayerMounted)
                        {
                            guardian.ToggleMount(true, false);
                        }
                    }
                }
                if (Time >= 30)
                {
                    if (SoulsValue >= LiebreBase.MaxSoulsContainedValue)
                    {
                        guardian.SaySomething("*I felt like about to blow...*");
                    }
                    else if (SoulsValue >= LiebreBase.MaxSoulsContainedValue * 0.9f)
                    {
                        guardian.SaySomething("*I'm glad I managed to do the delivery in time.*");
                    }
                    else
                    {
                        guardian.SaySomething("*I returned.*");
                    }
                }
                if (Time % 10 == 0)
                {
                    float HeightVal = Time / 10 * 0.1f * guardian.Height;
                    for (int i = -1; i < 2; i++)
                    {
                        Vector2 EffectPosition = new Vector2(guardian.Position.X, guardian.Position.Y);
                        EffectPosition.Y -= HeightVal;
                        EffectPosition.X += guardian.Width * 0.6f * i;
                        Dust.NewDust(EffectPosition, 1, 1, 192, 0, -0.2f, 192, Scale: Main.rand.NextFloat(0.8f, 1.2f));
                    }
                }
                if (Time >= 100)
                {
                    {
                        float CapacityPercentage = (float)SoulsValue / LiebreBase.MaxSoulsContainedValue;
                        int   BuffDuration       = (int)(CapacityPercentage * 900) * 60;
                        if (SoulsValue > LiebreBase.MaxSoulsContainedValue)
                        {
                            BuffDuration = (int)(BuffDuration * 0.75f);
                        }
                        for (int i = 0; i < CapacityPercentage * 5; i++)
                        {
                            int BuffID = Utils.SelectRandom(Main.rand, new int[] { Terraria.ID.BuffID.Lifeforce, Terraria.ID.BuffID.Regeneration,
                                                                                   Terraria.ID.BuffID.Endurance, Terraria.ID.BuffID.ManaRegeneration, Terraria.ID.BuffID.Mining, Terraria.ID.BuffID.ObsidianSkin,
                                                                                   Terraria.ID.BuffID.Thorns });
                            for (int p = 0; p < 255; p++)
                            {
                                if (Main.player[p].active && !guardian.IsPlayerHostile(Main.player[p]))
                                {
                                    Main.player[p].AddBuff(BuffID, BuffDuration);
                                }
                            }
                            foreach (TerraGuardian g in MainMod.ActiveGuardians.Values)
                            {
                                if (g.OwnerPos == guardian.OwnerPos && !g.IsGuardianHostile(guardian))
                                {
                                    g.AddBuff(BuffID, BuffDuration);
                                }
                            }
                        }
                        guardian.SaySomethingCanSchedule("*Take this blessing as a reward for helping me.*");
                    }
                    guardian.DoAction.InUse = false;
                }
                break;
            }
        }