xabbo-scripts/Scripts/Obsidian Maze.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

272 lines
10 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 = 79453274;
long Room1CafeLightId = 2147418216;
TrackFurnis(Room1Id, Room1CafeLightId);
long Room2Id = 79453276;
long Room2RollerId = 130192945;
long Room2CoalId = 2147418305;
long Room2GateId = 706334702;
TrackFurnis(Room2Id, Room2RollerId, Room2CoalId, Room2GateId);
long Room3Id = 79453275;
long Room3CafeLightId = 2147418139;
TrackFurnis(Room3Id, Room3CafeLightId);
long Room4Id = 79453279;
long Room4Pod1Id = 134078972;
long Room4Pod2Id = 126470420;
TrackFurnis(Room4Id, Room4Pod1Id, Room4Pod2Id);
long Room5Id = 79453277;
long Room5CoalId = 2147418143;
TrackFurnis(Room5Id, Room5CoalId);
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()
{
{ (16, 20), new (() => Move(12, 20), () => { }, () => FloorItems.First(f => f.Id == 146087011).Direction == 4) },
{ (12, 20), new (() => Move(11, 21)) },
{ (11, 21), new (() => UseGate(706551139)) },
{ (10, 21), new (() => UseGate(706551140)) },
{ ( 8, 20), new (() => UseGate(707181347)) },
{ ( 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<Point, TileAction> Room2Actions = new()
{
{ ( 4, 5), new (() => Move(3, 7)) },
{ ( 3, 7), new (() => Move(6, 6)) },
{ ( 6, 6), new (() => Move(7, 6), () => { }, () => TrackedFurnis[Room2RollerId].XY == (13, 9) && TrackedFurnis[Room2CoalId].X > 12) },
{ ( 7, 6), new (() => Move(8, 7)) },
{ ( 8, 7), new (() => UseGate(706334703)) },
{ ( 9, 7), new (() => Move(11, 8)) },
{ (11, 8), new (() => Move(13, 9)) },
{ (13, 9), new (() => Move(15, 11)) },
{ (15, 11), new (() => UseGate(706334701), () => { }, () => TrackedFurnis[Room2GateId].XY == (14, 12)) },
{ (15, 12), new (() => UseGate(Room2GateId)) },
{ (14, 12), new (() => UseGate(706334708)) },
{ (15, 14), new (() => UseGate(706856296)) },
{ (15, 15), new (() => Move(9, 13)) },
{ ( 9, 13), new (() => UseGate(706999931)) },
{ ( 9, 14), new (() => UseFloorItem(754470180), () => Move(9, 16), () => FloorItems.First(f => f.Id == 754470180).State == 0) },
{ ( 9, 23), new (() => UseFloorItem(831488630)) }
};
Dictionary<Point, TileAction> Room3Actions = new()
{
{ (14, 13), new (() => Move(16, 12)) },
{ (16, 12), new (() => Move(14, 14), () => { }, () => TrackedFurnis[Room3CafeLightId].XY != (11, 22)) },
{ (14, 14), new (() => Move(16, 16)) },
{ (16, 16), new (() => UseGate(706784960)) },
{ (16, 17), new (() => Move(17, 18)) },
{ (17, 18), new (() => UseFloorItem(754391792), () => Move(10, 15), () => FloorItems.First(f => f.Id == 754391792).State == 0) },
{ (10, 15), new (() => Move(9, 16)) },
{ ( 9, 16), new (() => UseGate(707181351)) },
{ ( 9, 17), new (() => UseGate(159973684)) },
{ (10, 17), new (() => UseGate(707181351)) },
{ (10, 18), new (() => UseGate(159973684)) },
{ ( 9, 18), new (() => Move(8, 19)) },
{ ( 8, 19), new (() => UseFloorItem(586528822), () => Move(12, 23), () => FloorItems.First(f => f.Id == 586528822).State == 0) },
{ (12, 23), new (() => UseGate(143552728)) },
{ (13, 23), new (() => UseFloorItem(586528843), () => UseGate(706929179), () => FloorItems.First(f => f.Id == 586528843).State == 0) },
{ (15, 23), new (() => Move(14, 22)) },
{ ( 7, 26), new (() => UseFloorItem(831488635)) }
};
Dictionary<Point, TileAction> Room4Actions = new()
{
{ (10, 2), new (() => Move(12, 2)) },
{ (12, 1), new (() => Move(12, 2)) },
{ (12, 2), new (() => Move(12, 4), () => { }, () => TrackedFurnis[Room4Pod1Id].XY == (12, 7)) },
{ (12, 4), new (() => Move(13, 5)) },
{ (13, 5), new (() => UseGate(192569740)) },
{ (13, 6), new (() => Move(12, 7)) },
{ (12, 7), new (() => Move(TrackedFurnis[Room4Pod1Id].XY)) },
{ (12, 8), new (() => UseGate(706369695), () => Move(TrackedFurnis[Room4Pod1Id].XY), () => FloorItems.First(f => f.Id == 150171652).Direction == 4) },
{ (11, 8), new (() => Move(TrackedFurnis[Room4Pod1Id].XY)) },
{ (12, 9), new (() => UseGate(150171652)) },
{ (13, 9), new (() => Move(15, 13)) },
{ (15, 13), new (() => UseFloorItem(586528844), () => UseGate(706372961), () => FloorItems.First(f => f.Id == 586528844).State == 0) },
{ (14, 13), new (() => Move(TrackedFurnis[Room4Pod2Id].XY)) },
{ (10, 12), new (() => Move(TrackedFurnis[Room4Pod2Id].XY)) },
{ (11, 13), new (() => Move(TrackedFurnis[Room4Pod2Id].XY)) },
{ (10, 14), new (() => Move(TrackedFurnis[Room4Pod2Id].XY)) },
{ ( 9, 13), new (() => UseGate(706372975)) },
{ ( 8, 13), new (() => UseFloorItem(754561672), () => Move(7, 14), () => FloorItems.First(f => f.Id == 754561672).State == 0) },
{ ( 7, 14), new (() => Move(11, 16)) },
{ (11, 16), new (() => UseGate(706372960)) },
{ (11, 17), new (() => UseGate(706640231)) },
{ (12, 17), new (() => UseGate(168499719)) },
{ (13, 18), new (() => Move(14, 17)) },
{ ( 6, 19), new (() => UseFloorItem(831488633)) }
};
Dictionary<Point, TileAction> Room5Actions = new()
{
{ ( 3, 19), new (() => Move(2, 21)) },
{ ( 2, 21), new (() => Move(6, 21), () => { }, () => FloorItems.First(f => f.Id == 706457580).Direction == 6) },
{ ( 6, 21), new (() => Move(8, 19)) },
{ ( 8, 19), new (() => { UseFloorItem(140692977); Delay(100); UseFloorItem(140692977); }, () => Move(9, 20), () => FloorItems.First(f => f.Id == 140692977).State == 0) },
{ ( 9, 20), new (() => UseFloorItem(140692977), () => UseGate(706999937), () => FloorItems.First(f => f.Id == 140692977).State == 0) },
{ (10, 20), new (() => Move(12, 15)) },
{ (12, 15), new (() => UseGate(706999925)) },
{ (13, 15), new (() => UseGate(159848392)) },
{ (13, 14), new (() => Move(9, 13)) },
{ ( 9, 13), new (() => Move(8, 12)) },
{ ( 8, 12), new (() => UseGate(706334740)) },
{ ( 8, 11), new (() => UseGate(706929174)) },
{ ( 9, 11), new (() => UseGate(706632250)) },
{ ( 9, 10), new (() => UseGate(706929174), () => { UseFloorItem(757308992); Delay(100); Move(6, 13); }, () => FloorItems.First(f => f.Id == 2147418144).State != 0) },
{ ( 6, 13), new (() => UseGate(706342894)) },
{ ( 5, 13), new (() => UseGate(706457580)) },
{ ( 5, 14), new (() => UseGate(706372962)) },
{ ( 5, 15), new (() => UseGate(706457580), () => Move(4, 16), () => FloorItems.First(f => f.Id == 2147418145).State == 0) },
{ (10, 26), new (() => Done = true) },
};
Dictionary<long, Dictionary<Point, TileAction>> AllActions = new()
{
{ Room1Id, Room1Actions },
{ Room2Id, Room2Actions },
{ Room3Id, Room3Actions },
{ Room4Id, Room4Actions },
{ Room5Id, Room5Actions }
};
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");