Skip to content

Commit

Permalink
There should be no way these cones don't work
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyfyter committed Apr 29, 2024
1 parent 8577188 commit 36ed71d
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions Tiles/Other/Traffic_Cone.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Origins.Buffs;
using Origins.Items.Materials;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
Expand All @@ -10,6 +11,7 @@

namespace Origins.Tiles.Other {
public class Traffic_Cone : ModTile {
public static int ID { get; private set; }
public override void SetStaticDefaults() {
Main.tileFrameImportant[Type] = true;
Main.tileLavaDeath[Type] = true;
Expand All @@ -22,6 +24,7 @@ public override void SetStaticDefaults() {
TileObjectData.newTile.CopyFrom(TileObjectData.Style1x2);
TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(ModContent.GetInstance<Traffic_Cone_TE>().Hook_AfterPlacement, -1, 0, false);
TileObjectData.addTile(Type);
ID = Type;
}
}
public class Traffic_Cone_TE : ModTileEntity {
Expand All @@ -35,20 +38,54 @@ public override void OnNetPlace() {
public override int Hook_AfterPlacement(int i, int j, int type, int style, int direction, int alternate) {
return Place(i, j);
}
public static HashSet<Point16> coneLocations;
public static void UpdateCones() {
const float range = 12 * 16; // 12 tiles
if (Main.netMode == NetmodeID.MultiplayerClient) return;
if (ID == -1) ID = ModContent.TileEntityType<Traffic_Cone_TE>();
coneLocations ??= new();
foreach (TileEntity entity in ByID.Values) {
if (entity.type == ID) {
Vector2 pos = entity.Position.ToWorldCoordinates();
for (int i = 0; i < Main.maxNPCs; i++) {
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(entity) && npc.DistanceSQ(pos) < range * range) {
npc.AddBuff(Slow_Debuff.ID, 10);
}
if (!coneLocations.Contains(entity.Position)) {
Projectile.NewProjectile(
Entity.GetSource_None(),
entity.Position.ToWorldCoordinates(),
default,
Traffic_Cone_Projectile.ID,
0,
0
);
}
}
}
coneLocations.Clear();
}
}
public class Traffic_Cone_Projectile : ModProjectile {
public override string Texture => typeof(Traffic_Cone_Item).GetDefaultTMLName();
public static int ID { get; private set; }
public override void SetStaticDefaults() {
ID = Type;
}
public override void SetDefaults() {
Projectile.width = 0;
Projectile.height = 0;
Projectile.tileCollide = false;
}
public override void AI() {
const float range = 12 * 16; // 12 tiles
for (int i = 0; i < Main.maxNPCs; i++) {
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile) && npc.DistanceSQ(Projectile.position) < range * range) {
npc.AddBuff(Slow_Debuff.ID, 10);
}
}
Point16 tilePos = Projectile.position.ToTileCoordinates16();
if (Main.tile[tilePos.X, tilePos.Y].TileIsType(Traffic_Cone.ID)) {
Traffic_Cone_TE.coneLocations.Add(tilePos);
Projectile.timeLeft = 60;
} else {
Projectile.Kill();
}
}
}
public class Traffic_Cone_Item : ModItem {
Expand Down

0 comments on commit 36ed71d

Please sign in to comment.