Skip to content

Commit

Permalink
forking epic
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed Jun 4, 2024
1 parent 1d0a8ca commit 102e550
Showing 1 changed file with 94 additions and 38 deletions.
132 changes: 94 additions & 38 deletions TSTSSESCoresAddon/Data/Scripts/ScriptsAddon/Specials/SpecBlockHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,67 +207,123 @@ public static object GetLimitedBlock(IMyTerminalBlock block)

public static IMyTerminalBlock GetLimitedBlockBlock(object block)
{
return getLimitedBlockBlock?.Invoke(block);
if (getLimitedBlockBlock == null)
{
MyLog.Default.WriteLine("SpecBlockHooks: getLimitedBlockBlock is null");
return null;
}

if (block == null)
{
MyLog.Default.WriteLine("SpecBlockHooks: block is null");
return null;
}

try
{
var limitedBlock = block as ILimitedBlock;
if (limitedBlock == null)
{
MyLog.Default.WriteLine($"SpecBlockHooks: block of type {block.GetType().FullName} does not implement ILimitedBlock");
return null;
}

return getLimitedBlockBlock.Invoke(block);
}
catch (InvalidCastException)
{
MyLog.Default.WriteLine($"SpecBlockHooks: Failed to cast block of type {block.GetType().FullName} to ILimitedBlock");
return null;
}
catch (Exception e)
{
MyLog.Default.WriteLine($"SpecBlockHooks: Error in GetLimitedBlockBlock: {e.Message}");
return null;
}
}

public static void RegisterCustomLimitConsumer(string Id, Func<IMyTerminalBlock, ILimitedBlock> creator)
{
SpecBlockHooks.RegisterCustomLimitConsumer(Id,
SpecBlockHooks.RegisterCustomLimitConsumer(Id,
creator,
(logic)=>
(logic) =>
{
((ILimitedBlock) logic).CanWork();
var limitedBlock = logic as ILimitedBlock;
if (limitedBlock != null) limitedBlock.CanWork();
},
(block, logic) =>
{
return ((ILimitedBlock) logic).CheckConditions(block);
var limitedBlock = logic as ILimitedBlock;
return limitedBlock != null && limitedBlock.CheckConditions(block);
},
(logic)=>
(logic) =>
{
return ((ILimitedBlock) logic).CanBeDisabled();
var limitedBlock = logic as ILimitedBlock;
return limitedBlock != null && limitedBlock.CanBeDisabled();
},
(logic)=>
(logic) =>
{
return ((ILimitedBlock) logic).IsDrainingPoints();
var limitedBlock = logic as ILimitedBlock;
return limitedBlock != null && limitedBlock.IsDrainingPoints();
},
(logic)=>
(logic) =>
{
((ILimitedBlock) logic).Disable();
var limitedBlock = logic as ILimitedBlock;
if (limitedBlock != null) limitedBlock.Disable();
});
}

public static Dictionary<Type, HashSet<IMyCubeBlock>> GetGridBlocksByType(IMyCubeGrid grid)
{
if (grid == null)
{
MyLog.Default.WriteLine("SpecBlockHooks: grid is null in GetGridBlocksByType");
return null;
}
return getGridBlocksByType?.Invoke(grid) ?? null;
}

public static Dictionary<MyDefinitionId, HashSet<IMyCubeBlock>> GetGridBlocksById(IMyCubeGrid grid)
{
if (grid == null)
{
MyLog.Default.WriteLine("SpecBlockHooks: grid is null in GetGridBlocksById");
return null;
}
return getGridBlocksById?.Invoke(grid) ?? null;
}

public static void HandleDamage(object target, ref MyDamageInformation damage)
{ //Paralell
try
{
var slimBlock = target as IMySlimBlock;
if (slimBlock != null)
{
var cubeGrid = slimBlock.CubeGrid;
var core = SpecBlockHooks.GetMainSpecCore(slimBlock.CubeGrid);
var stats = new Dictionary<int, float>();
SpecBlockHooks.GetSpecCoreLimits(core, stats, SpecBlockHooks.GetSpecCoreLimitsEnum.CurrentStaticOrDynamic);
if(stats.ContainsKey(-33) && stats[-33]!=0)
{
damage.Amount *= stats [-33];
}
}
}
catch(Exception e)
{

}
}

}

public static void HandleDamage(object target, ref MyDamageInformation damage)
{ //Parallel
try
{
var slimBlock = target as IMySlimBlock;
if (slimBlock == null)
{
MyLog.Default.WriteLine("SpecBlockHooks: target is not IMySlimBlock in HandleDamage");
return;
}

var cubeGrid = slimBlock.CubeGrid;
var core = SpecBlockHooks.GetMainSpecCore(cubeGrid);
if (core == null)
{
MyLog.Default.WriteLine("SpecBlockHooks: core is null in HandleDamage");
return;
}

var stats = new Dictionary<int, float>();
SpecBlockHooks.GetSpecCoreLimits(core, stats, SpecBlockHooks.GetSpecCoreLimitsEnum.CurrentStaticOrDynamic);
if (stats != null && stats.ContainsKey(-33) && stats[-33] != 0)
{
damage.Amount *= stats[-33];
}
}
catch (Exception e)
{
MyLog.Default.WriteLine($"SpecBlockHooks: Error in HandleDamage: {e.Message}");
}
}

}
}

0 comments on commit 102e550

Please sign in to comment.