xabbo-scripts/Scripts/ObsidianMazeEasy.csx
Administrator 7a548130a3 Move all scripts into Scripts/ subfolder
Keeps the repo root clean - only README.md visible on landing page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 09:49:37 +01:00

189 lines
4.9 KiB
C#

/// @group Bots
public class TrackedFurni
{
public Tile Location { get; set; }
public Point XY => Location.XY;
public int X => Location.X;
public int Y => Location.Y;
public float Z => Location.Z;
public int Direction { get; set; }
}
public class WiredMovement
{
public int FromX { get; set; }
public int FromY { get; set; }
public int ToX { get; set; }
public int ToY { get; set; }
public string FromHeight { get; set; }
public string ToHeight { get; set; }
public int Id { get; set; }
public int Interval { get; set; }
}
OnIntercept(In["WiredMovements"], e =>
{
var movements = new WiredMovement[e.Packet.ReadInt()];
for (int i = 0; i < movements.Length; i++)
{
e.Packet.ReadInt(); // ignore 1
movements[i] = new();
movements[i].FromX = e.Packet.ReadInt();
movements[i].FromY = e.Packet.ReadInt();
movements[i].ToX = e.Packet.ReadInt();
movements[i].ToY = e.Packet.ReadInt();
movements[i].FromHeight = e.Packet.ReadString();
movements[i].ToHeight = e.Packet.ReadString();
movements[i].Id = e.Packet.ReadInt();
movements[i].Interval = e.Packet.ReadInt();
e.Packet.ReadInt(); // ignore 0
if (AllTrackedFurnis.ContainsKey(RoomId) && AllTrackedFurnis[RoomId].ContainsKey(movements[i].Id))
{
AllTrackedFurnis[RoomId][movements[i].Id].Location = (movements[i].ToX, movements[i].ToY, float.Parse(movements[i].ToHeight));
}
}
});
OnEnteredRoom(e =>
{
if (AllTrackedFurnis.ContainsKey(e.Room.Id))
{
foreach (var key in AllTrackedFurnis[e.Room.Id].Keys)
{
var item = FloorItems.First(f => f.Id == key);
AllTrackedFurnis[e.Room.Id][key] = new TrackedFurni { Location = item.Location, Direction = item.Direction };
}
}
});
private Dictionary<long, Dictionary<long, TrackedFurni>> AllTrackedFurnis = new();
public void TrackFurnis(long roomId, params long[] furniIds)
{
if (!AllTrackedFurnis.ContainsKey(roomId))
{
AllTrackedFurnis.Add(roomId, new Dictionary<long, TrackedFurni>());
}
foreach (var furniId in furniIds)
{
if (!AllTrackedFurnis[roomId].ContainsKey(furniId))
{
if (RoomId == roomId)
{
var item = FloorItems.First(f => f.Id == furniId);
AllTrackedFurnis[roomId].Add(furniId, new TrackedFurni { Location = item.Location, Direction = item.Direction });
}
else
{
AllTrackedFurnis[roomId].Add(furniId, new());
}
}
}
}
private Dictionary<long, TrackedFurni> TrackedFurnis => AllTrackedFurnis[RoomId];
public Point RealPos => (Self.CurrentUpdate.MovingTo ?? Self.Location).XY;
long Room1Id = 79450151;
long Room1CafeLightId = 2147418112;
long Room1CoalId = 2147418121;
TrackFurnis(Room1Id, Room1CafeLightId,Room1CoalId);
public class TileAction
{
private readonly Action MainAction;
private readonly Action ElseAction;
private readonly Func<bool> Condition;
public TileAction(Action mainAction) => MainAction = mainAction;
public TileAction(Action mainAction, Action elseAction, Func<bool> condition) : this(mainAction)
{
ElseAction = elseAction;
Condition = condition;
}
public void Execute()
{
if (Condition == null || Condition())
{
MainAction();
}
else
{
ElseAction();
}
}
}
Dictionary<Point, TileAction> Room1Actions = new()
{
{ (8, 5), new (() => Move(10, 8)) },
{ (10, 8), new (() => Move(9, 9)) },
{ (9, 9), new (() => {
var targetFurni = FloorItems.FirstOrDefault(f => f.Id == 138797726);
if (targetFurni != null && targetFurni.Location.XY == (10, 10))
{
Move(10, 10);
}
else
{
Move(10, 8);
}
}) },
{ (10, 11), new (() => {
Delay(500);
Move(12, 13);
}) },
{ (12, 13), new (() => {
var targetFurnii = FloorItems.FirstOrDefault(f => f.Id == 2147418121);
if (targetFurnii != null && targetFurnii.Location.XY == (15, 14))
{
UseGate(706784982);
Delay(500);
Move(14, 16);
}
else
{
Move(11, 12);
}
}) },
{ ( 11, 12), new (() => Move(12, 13)) },
{ ( 9, 15), new (() => Move(8, 16)) },
{ (8, 16), new (() => Move(TrackedFurnis[Room1CafeLightId].XY)) },
{ ( 7, 20), new (() => Move(6, 16)) },
{ ( 6, 16), new (() => Move(7, 15)) },
{ ( 7, 15), new (() => UseFloorItem(754376865), () => UseGate(707181350), () => FloorItems.First(f => f.Id == 754376865).State == 0) },
{ ( 7, 13), new (() => Move(9, 11)) },
{ ( 9, 11), new (() => Move(12, 12)) },
{ (12, 12), new (() => UseGate(707181349)) },
{ (13, 12), new (() => Move(TrackedFurnis[Room1CafeLightId].XY)) },
{ (14, 8), new (() => UseFloorItem(831488628)) }
};
Dictionary<long, Dictionary<Point, TileAction>> AllActions = new()
{
{ Room1Id, Room1Actions },
};
bool Done = false;
while (Run && !Done)
{
try
{
if (AllActions.TryGetValue(RoomId, out var actions) && actions.TryGetValue(RealPos, out var result))
{
result.Execute();
}
}
catch { }
Delay(100);
}
Log("Done");