Skip to content

Commit

Permalink
Bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Mar 15, 2024
1 parent a6603da commit 9cf725d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void Update()
else
{
//throw Exception;
HeartLoad.I.UnloadDataConditional();
MyAPIGateway.Session.Unload(); // This might cause improver unloading
MyAPIGateway.Session.UnloadDataComponents();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal class HeartData
public ulong SteamId = 0;
public List<IMyPlayer> Players = new List<IMyPlayer>();
public bool DegradedMode = false;
public int DegradedModeTicks = 30;
public Action<IMyCubeGrid> OnGridAdd = (a) => { };
public Action<IMyCubeGrid> OnGridRemove = (a) => { };
public GuiBlockCategoryHelper OrreryBlockCategory = new GuiBlockCategoryHelper("[Orrery Combat Framework]", "OrreryBlockCategory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ namespace Heart_Module.Data.Scripts.HeartModule
[MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation, priority: int.MaxValue)]
internal class HeartLoad : MySessionComponentBase
{
private static HeartLoad I;
public static HeartLoad I;

CriticalHandle handle;
ApiSender apiSender;
DefinitionReciever definitionReciever;
CommandHandler commands;
int remainingDegradedModeTicks = 30;

public override void LoadData()
{
Expand Down Expand Up @@ -112,30 +111,30 @@ public override void UpdateAfterSimulation()
{
if (!HeartData.I.DegradedMode)
{
if (remainingDegradedModeTicks >= 60) // Wait 300 ticks before engaging degraded mode
if (HeartData.I.DegradedModeTicks >= 60) // Wait 300 ticks before engaging degraded mode
{
HeartData.I.DegradedMode = true;
if (MyAPIGateway.Session.IsServer)
MyAPIGateway.Utilities.SendMessage("[OCF] Entering degraded mode!");
MyAPIGateway.Utilities.ShowMessage("[OCF]", "Entering client degraded mode!");
remainingDegradedModeTicks = 600;
MyAPIGateway.Utilities.SendMessage("[OCF] Entering degraded mode for 10s!");
MyAPIGateway.Utilities.ShowMessage("[OCF]", "Entering client degraded mode for 10s!");
HeartData.I.DegradedModeTicks = 600;
}
else
remainingDegradedModeTicks++;
HeartData.I.DegradedModeTicks++;
}
}
else if (MyAPIGateway.Physics.SimulationRatio > 0.87)
{
if (remainingDegradedModeTicks <= 0 && HeartData.I.DegradedMode)
if (HeartData.I.DegradedModeTicks <= 0 && HeartData.I.DegradedMode)
{
HeartData.I.DegradedMode = false;
if (MyAPIGateway.Session.IsServer)
MyAPIGateway.Utilities.SendMessage("[OCF] Exiting degraded mode.");
MyAPIGateway.Utilities.ShowMessage("[OCF]", "Exiting client degraded mode.");
remainingDegradedModeTicks = 0;
HeartData.I.DegradedModeTicks = 0;
}
else if (remainingDegradedModeTicks > 0)
remainingDegradedModeTicks--;
else if (HeartData.I.DegradedModeTicks > 0)
HeartData.I.DegradedModeTicks--;
}
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void Update()
{
DeltaTick += ProjectileManager.DeltaTick;

MyAPIGateway.Utilities.ShowNotification("PPT Sim: " + Math.Round(1/60d/DeltaTick, 2), 1000/60);

if (thisTask.IsComplete)
{
// Update thread-safe buffer lists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public override void UpdateAfterSimulation()

foreach (var projectile in QueuedCloseProjectiles)
{
if (projectile == null)
continue;
ActiveProjectiles.Remove(projectile.Id);
ProjectilesWithHealth.Remove(projectile);
projectile.OnClose.Invoke(projectile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public void ConsumeResources()
}

// Update resource status after consumption
if (MyAPIGateway.Multiplayer.IsServer)
{
ShowResourceStatus();
}
//if (MyAPIGateway.Multiplayer.IsServer)
//{
// ShowResourceStatus();
//}
}

public void RegenerateResources(float deltaTime)
Expand All @@ -125,10 +125,10 @@ public void RegenerateResources(float deltaTime)
}

// Update resource status after regeneration
if (MyAPIGateway.Multiplayer.IsServer)
{
ShowResourceStatus();
}
//if (MyAPIGateway.Multiplayer.IsServer)
//{
// ShowResourceStatus();
//}
}

// Call this method every update tick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class CommandHandler
["debug.fillammo"] = new Command("HeartMod.Debug", "Fills all magazines on your current grid.", (message) => I.FillGridWeapons()),
["debug.reloadammo"] = new Command("HeartMod.Debug", "Forces all weapons on your current grid to reload.", (message) => I.ReloadGridWeapons()),
["debug.reloaddefs"] = new Command("HeartMod.Debug", "Clears and refreshes all weapon definitions.", (message) => { HeartLoad.ResetDefinitions(); MyAPIGateway.Utilities.ShowMessage("[OCF]", "All definitions cleared. Good luck fixing the bug!"); }),
["degraded"] = new Command("HeartMod", "Enter degraded mode for [arg1] seconds.", (message) => I.EnterDegradedMode(message)),
};

private void ShowHelp()
Expand Down Expand Up @@ -99,15 +100,23 @@ private void ReloadGridWeapons()
//weapon.Magazines.UpdateReload();
ct++;
}
MyAPIGateway.Utilities.ShowMessage($"[HeartMod.Debug]", $"Force-reloaded {ct} weapons.");
MyAPIGateway.Utilities.ShowMessage("[HeartMod.Debug]", $"Force-reloaded {ct} weapons.");
}
else
{
MyAPIGateway.Utilities.ShowMessage($"[HeartMod.Debug]", "No grid found!");
MyAPIGateway.Utilities.ShowMessage("[HeartMod.Debug]", "No grid found!");
}
}


private void EnterDegradedMode(string[] message)
{
HeartData.I.DegradedMode = true;
float seconds = 10;
if (message.Length > 1)
float.TryParse(message[1], out seconds);
MyAPIGateway.Utilities.ShowMessage("[HeartMod]", $"Entering client degraded mode for {seconds} seconds!");
HeartData.I.DegradedModeTicks = (int)(seconds * 60);
}



Expand All @@ -127,19 +136,32 @@ public void Init()

private void Command_MessageEnteredSender(ulong sender, string messageText, ref bool sendToOthers)
{
// Only register for commands
if (messageText.Length == 0 || !messageText.ToLower().StartsWith("/ocf"))
return;
try
{
// Only register for commands
if (messageText.Length == 0 || !messageText.ToLower().StartsWith("/ocf"))
return;

sendToOthers = false;
sendToOthers = false;

string[] parts = messageText.Substring(5).Split(' '); // Convert commands to be more parseable
string[] parts = messageText.Substring(4).Trim(' ').Split(' '); // Convert commands to be more parseable

// Really basic command handler
if (commands.ContainsKey(parts[0].ToLower()))
commands[parts[0].ToLower()].action.Invoke(parts);
else
MyAPIGateway.Utilities.ShowMessage("[OCF]", $"Unrecognized command \"{messageText}\" ({sender})");
if (parts[0] == "")
{
ShowHelp();
return;
}

// Really basic command handler
if (commands.ContainsKey(parts[0].ToLower()))
commands[parts[0].ToLower()].action.Invoke(parts);
else
MyAPIGateway.Utilities.ShowMessage("[OCF]", $"Unrecognized command \"{messageText}\" ({sender})");
}
catch (Exception ex)
{
SoftHandle.RaiseException(ex, typeof(CommandHandler));
}
}

public void Close()
Expand Down

0 comments on commit 9cf725d

Please sign in to comment.