Skip to content

Commit

Permalink
Merge pull request #153 from Controllerdestiny/main
Browse files Browse the repository at this point in the history
修复: Economics.Projectile 召唤物攻击间隔无效,弹幕自动瞄准有误
  • Loading branch information
Controllerdestiny authored May 24, 2024
2 parents 4ca2634 + cac7e87 commit 76dfec3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions Economics.Projectile/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EconomicsAPI.Extensions;
using EconomicsAPI.Extensions;
using Microsoft.Xna.Framework;
using System.Reflection;
using Terraria;
using TerrariaApi.Server;
Expand All @@ -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)
Expand All @@ -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);
}
}
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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++)
{
Expand All @@ -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;
}
}
}
Expand All @@ -125,6 +126,10 @@ private void Onupdate(EventArgs args)
{
useCD[i]--;
}
}

for(int i = 0; i<Main.maxProjectiles; i++)
{
if (MiniCD[i] > 0)
{
MiniCD[i]--;
Expand Down
2 changes: 1 addition & 1 deletion EconomicsAPI/Utils/SpawnProjectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 76dfec3

Please sign in to comment.