private void OnNpcAiUpdate(NpcAiUpdateEventArgs args) { if (args.Handled) { return; } var customNpc = GetCustomNpc(args.Npc); if (customNpc == null) { return; } var definition = customNpc.Definition; try { CustomIDFunctions.CurrentID = definition.Name; var result = definition.OnAiUpdate?.Invoke(customNpc); args.Handled = result == true; } catch (Exception ex) { Utils.LogScriptRuntimeError(ex); definition.OnAiUpdate = null; } TSPlayer.All.SendData(PacketTypes.NpcUpdate, "", args.Npc.whoAmI); }
void onNPCAIUpdate(NpcAiUpdateEventArgs args) { if (args.Npc.boss && getArena() != "0") { Point point = new Point(); point.X = (int)args.Npc.position.ToTileCoordinates().X; point.Y = (int)args.Npc.position.ToTileCoordinates().Y; TShockAPI.DB.Region region = TShock.Regions.GetRegionByName(getArena()); Polygon b1 = new Polygon(); Polygon b2 = new Polygon(); Polygon boundary = new Polygon(new float[] { region.Area.X, region.Area.Y, region.Area.X + region.Area.Width, region.Area.Y, region.Area.X + region.Area.Width, region.Area.Y + region.Area.Height, region.Area.X, region.Area.Y + region.Area.Height }); Polygon p = new Polygon(new float[] { point.X, point.Y, point.X + 1, point.Y, point.X + 1, point.Y + 1, point.X, point.Y + 1 }); Intersector.MinimumTranslationVector mtv = new Intersector.MinimumTranslationVector(); if (Intersector.OverlapConvexPolygons(boundary, p, mtv)) { TSPlayer.All.SendErrorMessage($"Boss out of range (normal [{mtv.normal.X},{mtv.normal.Y}])"); args.Npc.position.X += mtv.normal.X * (mtv.depth * 2); args.Npc.position.Y += mtv.normal.Y * (mtv.depth * 2); args.Npc.netUpdate = true; args.Npc.netUpdate2 = true; } /*if (!region.Area.Contains(Main.player[args.Npc.target].position.ToTileCoordinates())) * { * args.Npc.velocity.X = 0; * args.Npc.velocity.Y = 0; * args.Npc.target = -1; * } * * int inside = 0; * * TShock.Players.ForEach((plr) => * { * if (plr.IsLoggedIn && region.Area.Contains(plr.LastNetPosition.ToTileCoordinates())) * { * inside++; * } * } * ); * * if (inside <= 0) * args.Npc.active = false;*/ } }