From cac7e87ca0036fd2e0c4fbd791fbadd77646cf37 Mon Sep 17 00:00:00 2001 From: Controllerdestiny <523321293@qq.com> Date: Fri, 24 May 2024 19:25:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20Economics.Projectile=20?= =?UTF-8?q?=E5=8F=AC=E5=94=A4=E7=89=A9=E6=94=BB=E5=87=BB=E9=97=B4=E9=9A=94?= =?UTF-8?q?=E6=97=A0=E6=95=88=EF=BC=8C=E5=BC=B9=E5=B9=95=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=9E=84=E5=87=86=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Economics.Projectile/Plugin.cs | 31 ++++++++++++++++----------- EconomicsAPI/Utils/SpawnProjectile.cs | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Economics.Projectile/Plugin.cs b/Economics.Projectile/Plugin.cs index 00da0c697..ce43161b4 100644 --- a/Economics.Projectile/Plugin.cs +++ b/Economics.Projectile/Plugin.cs @@ -1,4 +1,5 @@ -using EconomicsAPI.Extensions; +using EconomicsAPI.Extensions; +using Microsoft.Xna.Framework; using System.Reflection; using Terraria; using TerrariaApi.Server; @@ -24,7 +25,7 @@ public class Plugin : TerrariaPlugin private readonly int[] useCD = new int[Main.maxPlayers]; - private readonly int[] MiniCD = new int[Main.maxPlayers]; + private readonly int[] MiniCD = new int[Main.maxProjectiles]; public Plugin(Main game) : base(game) @@ -47,11 +48,10 @@ private void Projectile_Damage(On.Terraria.Projectile.orig_Damage orig, Terraria { if (self.minion && Config.ProjectileReplace.TryGetValue(self.type, out ProjectileData? data) && data != null && data.IsMinion) { - if (MiniCD[self.whoAmI] == 0) + if (MiniCD[self.identity] == 0) { int id = -1; - self.Minion_FindTargetInRange(300, ref id, false); - MiniCD[self.whoAmI] += data.CD; + self.Minion_FindTargetInRange(1500, ref id, false); } } } @@ -60,7 +60,7 @@ private void Projectile_Minion_FindTargetInRange(On.Terraria.Projectile.orig_Min { if (Config.ProjectileReplace.TryGetValue(self.type, out ProjectileData? data) && data != null) { - float num = startAttackRange; + float num = 1500; float num2 = num; float num3 = num; NPC ownerMinionAttackTargetNPC = self.OwnerMinionAttackTargetNPC; @@ -77,7 +77,7 @@ private void Projectile_Minion_FindTargetInRange(On.Terraria.Projectile.orig_Min for (int i = 0; i < 200; i++) { NPC nPC = Main.npc[i]; - if (nPC.damage > 0 && nPC.CanBeChasedBy(this) && self.IsInRangeOfMeOrMyOwner(nPC, num, out var myDistance2, out var playerDistance2, out var closerIsMe2) && (!skipIfCannotHitWithOwnBody || self.CanHitWithOwnBody(nPC)) && (customEliminationCheck == null || customEliminationCheck(nPC, attackTarget))) + if (nPC.damage > 0 && nPC.CanBeChasedBy(self) && self.IsInRangeOfMeOrMyOwner(nPC, num, out var myDistance2, out var playerDistance2, out var closerIsMe2) && (!skipIfCannotHitWithOwnBody || self.CanHitWithOwnBody(nPC)) && (customEliminationCheck == null || customEliminationCheck(nPC, attackTarget))) { attackTarget = i; num = closerIsMe2 ? myDistance2 : playerDistance2; @@ -93,7 +93,7 @@ private void Projectile_Minion_FindTargetInRange(On.Terraria.Projectile.orig_Min } } } - if (attackTarget >= 0) + if (attackTarget >= 0 && MiniCD[self.identity]== 0) { for (int i = 0; i < data.ProjData.Count; i++) { @@ -105,12 +105,13 @@ private void Projectile_Minion_FindTargetInRange(On.Terraria.Projectile.orig_Min //击退 float knockback = proj.KnockBack; //速度 - var speed = self.position.RotatedBy(self.position.AngleTo(Main.npc[attackTarget].position)).ToLenOf(proj.speed); - - int index = EconomicsAPI.Utils.SpawnProjectile.NewProjectile(Terraria.Projectile.GetNoneSource(), self.position, speed, proj.ID, (int)damage, knockback, self.owner); - + + NPC npc = Main.npc[attackTarget]; + self.Distance(npc.Center); + var speed = self.DirectionTo(npc.Center).SafeNormalize(-Vector2.UnitY) * self.velocity.Length(); + int index = EconomicsAPI.Utils.SpawnProjectile.NewProjectile(Terraria.Projectile.GetNoneSource(), self.Center, speed.ToLenOf(proj.speed), proj.ID, (int)damage, knockback, self.owner); TSPlayer.All.SendData(PacketTypes.ProjectileNew, "", index); - + MiniCD[self.identity] += data.CD; } } } @@ -125,6 +126,10 @@ private void Onupdate(EventArgs args) { useCD[i]--; } + } + + for(int i = 0; i 0) { MiniCD[i]--; diff --git a/EconomicsAPI/Utils/SpawnProjectile.cs b/EconomicsAPI/Utils/SpawnProjectile.cs index 11d9600d4..3358e85e1 100644 --- a/EconomicsAPI/Utils/SpawnProjectile.cs +++ b/EconomicsAPI/Utils/SpawnProjectile.cs @@ -58,7 +58,7 @@ public static int NewProjectile(IEntitySource spawnSource, float X, float Y, flo while (projectile.velocity.X >= 16f || projectile.velocity.X <= -16f || projectile.velocity.Y >= 16f || projectile.velocity.Y < -16f) { if (projectile.velocity.HasNanOrInf()) - projectile.velocity = Vector2.One; + projectile.velocity = Vector2.One * 10; projectile.velocity.X *= 0.97f; projectile.velocity.Y *= 0.97f; }