public static void GetGuardianHurt(BinaryReader reader, int SenderWhoAmI) { int WhoAmID = reader.ReadInt32(); Vector2 Position = reader.ReadVector2(); int Damage = reader.ReadInt32(); sbyte Direction = reader.ReadSByte(); bool Critical = reader.ReadBoolean(); string DeathMessage = reader.ReadString(); byte DownState = reader.ReadByte(); int HP = reader.ReadInt32(); if (!MainMod.ActiveGuardians.ContainsKey(WhoAmID)) { return; } TerraGuardian tg = MainMod.ActiveGuardians[WhoAmID]; tg.Position = Position; tg.Hurt(Damage, (int)Direction, Critical, true); switch (DownState) { case 3: tg.Knockout(DeathMessage); break; case 2: if (!tg.KnockedOut) { tg.EnterDownedState(); } tg.KnockedOutCold = true; break; case 1: if (!tg.KnockedOut) { tg.EnterDownedState(); } tg.KnockedOutCold = false; break; } tg.HP = HP; if (Main.netMode == 2) { SendGuardianHurt(WhoAmID, Damage, (int)Direction, Critical, DeathMessage, -1, SenderWhoAmI); } }
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) { IgnoreCombat = true; AvoidItemUsage = true; if (guardian.SittingOnPlayerMount) { guardian.DoSitOnPlayerMount(false); } if (guardian.PlayerMounted) { guardian.ToggleMount(true); } if (guardian.IsBeingPulledByPlayer) { guardian.IsBeingPulledByPlayer = false; } guardian.MoveLeft = guardian.MoveRight = false; switch (Step) { case 0: if (guardian.furniturex > -1) { guardian.LeaveFurniture(); } if (guardian.ItemAnimationTime == 0 && ((Target != null && TryReachingPlayer(guardian, Target)) || (TargetTg != null && TryReachingTg(guardian, TargetTg)))) //guardian.HitBox.Intersects(p.getRect()) && !guardian.BeingPulledByPlayer && { ChangeStep(); if (Target != null && Target.mount.Active) { Target.mount.Dismount(Target); } } else { if (Time >= 300) { InUse = false; } } break; case 1: guardian.Ducking = false; Vector2 HandPosition = guardian.GetGuardianBetweenHandPosition; BlockOffHandUsage = true; if (Time < 12) { if (Target != null) { Target.Center = HandPosition; Target.velocity = Vector2.Zero; Target.velocity.Y = -Player.defaultGravity; Target.fallStart = (int)Target.position.Y / 16; } else { TargetTg.Position = HandPosition + new Vector2(0, TargetTg.Height * 0.5f); TargetTg.Velocity = Vector2.Zero; TargetTg.SetFallStart(); } FocusCameraOnGuardian = true; } else { if (Time == 18 && Target != null && Collision.SolidCollision(Target.position, Target.width, Target.height)) { Target.Hurt(Terraria.DataStructures.PlayerDeathReason.ByCustomReason(" should've noticed the ceiling was low, before asking " + guardian.Name + " to lift it up..."), 20, 0); guardian.DisplayEmotion(TerraGuardian.Emotions.Sweat); if (Target.dead || Target.GetModPlayer <PlayerMod>().KnockedOut) { InUse = false; } ChangeStep(); } else if (Time == 18 && TargetTg != null && Collision.SolidCollision(TargetTg.TopLeftPosition, TargetTg.Width, TargetTg.Height)) { TargetTg.Hurt(20, 0, DeathMessage: " should've noticed the ceiling was low, before asking " + guardian.Name + " to lift it up..."); guardian.DisplayEmotion(TerraGuardian.Emotions.Sweat); if (TargetTg.Downed || TargetTg.KnockedOut) { InUse = false; } ChangeStep(); } else { FocusCameraOnGuardian = false; if (Target != null) { Target.position.Y = HandPosition.Y - Target.height; Target.position.X = HandPosition.X - Target.width * 0.5f; Target.velocity.Y = -Target.gravity; Target.velocity.X = 0; Target.fallStart = (int)Target.position.Y / 16; if (Target.controlRight) { guardian.MoveRight = true; } if (Target.controlLeft) { guardian.MoveLeft = true; } if (Target.controlJump) { Target.justJumped = true; Target.velocity.Y = -Player.jumpSpeed * Target.gravDir; Target.jump = Player.jumpHeight; InUse = false; } } else { TargetTg.Position = HandPosition; TargetTg.Velocity.Y = -0.3f; TargetTg.Velocity.X = 0; TargetTg.SetFallStart(); if (TargetTg.LastMoveRight) { guardian.MoveRight = true; } if (TargetTg.LastMoveLeft) { guardian.MoveLeft = true; } if (TargetTg.LastJump) { TargetTg.Velocity.Y = -TargetTg.JumpSpeed * TargetTg.GravityDirection; InUse = false; } } } } break; case 2: FocusCameraOnGuardian = true; if (Time >= 22) { if (Target != null) { Target.position.X = guardian.Position.X - Target.width * 0.5f; Target.position.Y = guardian.Position.Y - Target.height; Target.fallStart = (int)Target.position.Y / 16; Target.velocity = Vector2.Zero; Target.velocity.Y = -Player.defaultGravity; InUse = false; } else { TargetTg.Position = guardian.Position; TargetTg.Velocity.Y = 0; TargetTg.Velocity.X = 0; TargetTg.SetFallStart(); } } else { if (Target != null) { Target.Center = guardian.GetGuardianBetweenHandPosition; Target.fallStart = (int)Target.position.Y / 16; } else { TargetTg.Position = guardian.GetGuardianBetweenHandPosition + new Vector2(0, TargetTg.Height * 0.5f); TargetTg.SetFallStart(); } } break; } }