ported from perforce

This commit is contained in:
2026-04-19 00:43:27 +02:00
commit 6c0c33f5d4
700 changed files with 19735 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record AcceptCardCommand(Guid RequestId) : Command(RequestId, typeof(DrawGlitchRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new AcceptGlitch(coreLoop.GlitchDeck[coreLoop.NextGlitch]));
intents.Add(new NextGlitch());
intents.Add(new NextPhase(ERunPhase.Improve));
}
public override string ToString()
{
return "Accept card command";
}
}

View File

@@ -0,0 +1,31 @@
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record BuyCardsCommand(Guid RequestId, int[] Cards) : Command(RequestId, typeof(ImproveRequest), typeof(GambleRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
var gamble = coreLoop.RunPhase == ERunPhase.Gamble;
foreach (var index in Cards)
{
if (index < 0)
continue;
if (gamble && index < coreLoop.BoosterPack.Count)
intents.Add(new BuyPatch(coreLoop.BoosterPack[index], true));
else if (!gamble && index < coreLoop.Shop.Count)
intents.Add(new BuyPatch(coreLoop.Shop[index], false));
}
if (coreLoop.RunPhase == ERunPhase.Gamble)
intents.Add(new NextPhase(ERunPhase.Improve));
}
public override string ToString()
{
return $"Buy cards command {string.Join(", ", Cards.Select(c => c.ToString()))}";
}
}

View File

@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using RobotAndDonkey.Game.Execution.Results;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
using RobotAndDonkey.Game.Modifiers;
using RobotAndDonkey.Game.Pois;
namespace RobotAndDonkey.Game.Execution.Commands;
public abstract record Command(Guid RequestId, params Type[] RequestTypes)
{
protected abstract void CreateIntents(CoreLoop coreLoop, List<Intent> intents);
public List<Result> Preview(CoreLoop coreLoop)
{
var mockCoreLoop = new CoreLoop(coreLoop) { IsPreview = true };
return Execute(mockCoreLoop, false, false);
}
public List<Result> Execute(CoreLoop coreLoop, bool force, bool verbose)
{
var results = new List<Result>();
var intents = new List<Intent>();
CreateIntents(coreLoop, intents);
var modifiers = GetModifierStack(coreLoop);
modifiers.Execute(RequestId, coreLoop, intents, results, force, verbose);
return results;
}
private static ModifierStack GetModifierStack(CoreLoop coreLoop)
{
var modifiers = new ModifierStack();
modifiers.Push(coreLoop.Robot);
foreach (var cell in coreLoop.Board.Cells)
{
if (cell.Poi is Avatar)
{
modifiers.Push(cell);
}
}
return modifiers;
}
public bool IsValid(CoreLoop coreLoop, out EInvalidReason reason)
{
var results = Preview(coreLoop);
if (results.Count == 0)
{
reason = EInvalidReason.Invariant;
return false;
}
if (results is [InvalidInstructionResult])
{
reason = EInvalidReason.Invalid;
return false;
}
reason = (EInvalidReason)(-1);
return true;
}
public int EstimateEnergyCost(CoreLoop coreLoop)
{
var results = Preview(coreLoop);
if (results.Count == 0)
return 0;
var newEnergy = 0;
foreach (var result in results)
{
if (result is CurrencyResult currencyResult)
newEnergy = currencyResult.NewCurrency.Energy;
}
return coreLoop.Currency.Energy - newEnergy;
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using RobotAndDonkey.Game.Data;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record DeferCardCommand(Guid RequestId) : Command(RequestId, typeof(DrawGlitchRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new DeferGlitch(Balancing.Instance.GetDeferGlitchEnergyCost(coreLoop.DeferGlitchCount)));
intents.Add(new NextGlitch());
intents.Add(new NextPhase(ERunPhase.Improve));
}
public override string ToString()
{
return $"Defer card command";
}
}

View File

@@ -0,0 +1,22 @@
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record DestroyCardCommand(Guid RequestId, int HandIndex) : Command(RequestId, typeof(BufferOverflowRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
var handCards = coreLoop.GetHandCards();
if (HandIndex < 0 || HandIndex >= handCards.Count)
return;
intents.Add(new DestroyCard(handCards[HandIndex]));
}
public override string ToString()
{
return $"Destroy card command {HandIndex}";
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Linq;
using RobotAndDonkey.Game.Data;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record DiscardCommand(Guid RequestId, Guid[] CardIds) : Command(RequestId, typeof(ExecuteProgramRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
var cost = CardIds.Length * Balancing.Instance.DiscardEnergyCost;
intents.Add(new Discard(CardIds, cost));
}
public override string ToString()
{
return $"Discard cards command {string.Join(", ", CardIds.Select(id => id.ToString()))}";
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Linq;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record MoveCardsCommand(Guid RequestId, Guid[] OrderedCards, Guid[] TapeCardIds) : Command(RequestId, typeof(ExecuteProgramRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new MoveCards(OrderedCards, TapeCardIds));
}
public override string ToString()
{
return $"Move cards command: order={string.Join(", ", OrderedCards.Select(c => c.ToString()))}; tape={string.Join(", ", TapeCardIds.Select(c => c.ToString()))}";
}
}

View File

@@ -0,0 +1,19 @@
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record NextAssignmentCommand(Guid RequestId) : Command(RequestId, typeof(ScoringRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
coreLoop.ResetShop();
intents.Add(new NextPhase(ERunPhase.DrawGlitch));
}
public override string ToString()
{
return $"Next assignment command";
}
}

View File

@@ -0,0 +1,19 @@
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record PreviewProgramCommand(Guid RequestId) : Command(RequestId, typeof(ImproveRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new NextPhase(ERunPhase.ExecuteProgram));
intents.Add(new EnterPreview());
}
public override string ToString()
{
return "Preview program command";
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using RobotAndDonkey.Game.Data;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record RerollCommand(Guid RequestId) : Command(RequestId, typeof(ImproveRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new Reroll(Balancing.Instance.GetRerollEnergyCost(coreLoop.RerollCount)));
}
public override string ToString()
{
return "Reroll command";
}
}

View File

@@ -0,0 +1,18 @@
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record RunProgramCommand(Guid RequestId) : Command(RequestId, typeof(ExecuteProgramRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new RunProgram());
}
public override string ToString()
{
return "Run program command";
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using RobotAndDonkey.Game.Data;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record StartBufferOverflowCommand(Guid RequestId) : Command(RequestId, typeof(ImproveRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new EnterBufferOverflow(Balancing.Instance.BufferOverflowEnergyCost));
}
public override string ToString()
{
return "Start buffer overflow command";
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using RobotAndDonkey.Game.Data;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record StartGamblingCommand(Guid RequestId) : Command(RequestId, typeof(ImproveRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new EnterGamble(Balancing.Instance.GambleEnergyCost));
}
public override string ToString()
{
return "Start gambling command";
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record StopBufferOverflowCommand(Guid RequestId) : Command(RequestId, typeof(BufferOverflowRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
var handCards = coreLoop.GetHandCards();
coreLoop.PatchDeck.AddRange(handCards);
foreach (var handCard in handCards)
{
coreLoop.RemoveProgramCard(handCard);
}
coreLoop.ClearTapeSelection();
intents.Add(new NextPhase(ERunPhase.Improve));
}
public override string ToString()
{
return "Stop buffer overflow command";
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using RobotAndDonkey.Game.Execution.Requests;
using RobotAndDonkey.Game.GameState;
using RobotAndDonkey.Game.Intents;
namespace RobotAndDonkey.Game.Execution.Commands;
public sealed record StopGamblingCommand(Guid RequestId) : Command(RequestId, typeof(GambleRequest))
{
protected override void CreateIntents(CoreLoop coreLoop, List<Intent> intents)
{
intents.Add(new NextPhase(ERunPhase.Improve));
}
public override string ToString()
{
return "Stop gambling command";
}
}