本文整理汇总了C#中Terraria.NPC.TargetClosest方法的典型用法代码示例。如果您正苦于以下问题:C# NPC.TargetClosest方法的具体用法?C# NPC.TargetClosest怎么用?C# NPC.TargetClosest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terraria.NPC
的用法示例。
在下文中一共展示了NPC.TargetClosest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NPCAiStyles
public static void NPCAiStyles(NPC npc, int aiStyle)
{
if (npc.aiStyle == 102)
{
npc.ai[11]++;
if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
{
npc.TargetClosest(false); //Change Target in Multiplayer if current Target is dead
}
if (!Main.player[npc.target].dead && Main.player[npc.target].active) //If the target is alive then:
{
float distance = Vector2.Distance(npc.Center, Main.player[npc.target].Center); //Distance from player
float num248 = 0.5f;
if (Main.expertMode)
{
num248 = 0.60f;
}
if ((float)npc.life < (float)npc.lifeMax * num248)
{
npc.ai[0] = 1f;
npc.ai[1] = 0f;
npc.ai[2] = 0f;
npc.ai[3] = 0f;
npc.ai[9] = 0f;
if (npc.ai[4] == 0f)
{
for (int k = 0; k < 20; k++)
{
int dust = Dust.NewDust(new Vector2(npc.position.X + Main.rand.Next(-2, 2), npc.position.Y + Main.rand.Next(-2, 2)), npc.width, npc.height, 270, (float)Main.rand.Next(-3, 3), (float)Main.rand.Next(-3, 3), 0, default(Color), 1.3f);
Main.dust[dust].velocity *= npc.velocity;
}
npc.ai[4]++;
}
npc.netUpdate = true;
if (npc.netSpam > 10)
{
npc.netSpam = 10;
return;
}
}
if (distance > 750f && npc.ai[11] > 180 && npc.ai[9] < 600f && npc.ai[8] < 600f)
{
float sp = 30f;
Vector2 pos = new Vector2(Main.player[npc.target].Center.X, Main.player[npc.target].Center.Y - 200f) - npc.Center;
float mag = (float)Math.Sqrt(Math.Pow(pos.X, 2) + Math.Pow(pos.Y, 2));
if (mag > sp)
{
pos *= sp / mag;
}
npc.velocity = pos;
}
else if (npc.ai[0] == 0f)
{
npc.ai[9]++;
if (npc.ai[9] < 600f)
{
if (npc.ai[1] == 0f)
{
float num243 = 10f;
if (Main.expertMode)
{
num243 = 11f;
}
Vector2 vector28 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
float num244 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - vector28.X;
float num245 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - vector28.Y;
float num246 = (float)Math.Sqrt((double)(num244 * num244 + num245 * num245));
num246 = num243 / num246;
npc.velocity.X = num244 * num246;
npc.velocity.Y = num245 * num246;
npc.ai[1] = 1f;
npc.netUpdate = true;
if (npc.netSpam > 10)
{
npc.netSpam = 10;
}
}
else if (npc.ai[1] == 1f)
{
npc.ai[2] += 1f;
if (npc.ai[2] >= 20f)
{
npc.velocity *= 0.97f;
if (Main.expertMode)
{
npc.velocity *= 0.98f;
}
if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1)
{
npc.velocity.X = 0f;
}
if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1)
{
npc.velocity.Y = 0f;
}
}
int num247 = 30;
if (Main.expertMode)
{
num247 = 45;
//.........这里部分代码省略.........