Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 8beb4f3

Browse files
committed
Use KSH mod API to repair protected items.
1 parent 099a488 commit 8beb4f3

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//2392
1+
//2399
22
//
33
// This code was generated by a tool. Any changes made manually will be lost
44
// the next time this code is regenerated.
55
//
66

77
using System.Reflection;
88

9-
[assembly: AssemblyFileVersion("1.12.0.2392")]
10-
[assembly: AssemblyVersion("1.12.0.2392")]
9+
[assembly: AssemblyFileVersion("1.12.0.2399")]
10+
[assembly: AssemblyVersion("1.12.0.2399")]

EssentialsPlugin/ProcessHandlers/ProcessProtection.cs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
namespace EssentialsPlugin.ProcessHandlers
22
{
33
using System.Collections.Generic;
4-
using System.Threading;
54
using EssentialsPlugin.Settings;
65
using EssentialsPlugin.Utility;
76
using Sandbox.Common.ObjectBuilders;
87
using Sandbox.ModAPI;
9-
using SEModAPIInternal.API.Common;
10-
using SEModAPIInternal.API.Entity.Sector.SectorObject;
118

129
public class ProcessProtection : ProcessHandlerBase
1310
{
14-
public ProcessProtection()
11+
public ProcessProtection( )
1512
{
1613
}
1714

18-
public override int GetUpdateResolution()
15+
public override int GetUpdateResolution( )
1916
{
2017
return 1000;
2118
}
2219

23-
public override void Handle()
20+
public override void Handle( )
2421
{
25-
if (!PluginSettings.Instance.ProtectedEnabled)
22+
if ( !PluginSettings.Instance.ProtectedEnabled )
2623
return;
2724

28-
HashSet<IMyEntity> entities = new HashSet<IMyEntity>();
29-
Wrapper.GameAction(() =>
25+
HashSet<IMyEntity> entities = new HashSet<IMyEntity>( );
26+
Wrapper.GameAction( ( ) =>
3027
{
31-
MyAPIGateway.Entities.GetEntities(entities);
32-
});
28+
MyAPIGateway.Entities.GetEntities( entities );
29+
} );
3330

34-
foreach(IMyEntity entity in entities)
31+
foreach ( IMyEntity entity in entities )
3532
{
36-
if (!(entity is IMyCubeGrid))
33+
if ( !( entity is IMyCubeGrid ) )
3734
continue;
3835

39-
foreach(ProtectedItem item in PluginSettings.Instance.ProtectedItems)
36+
foreach ( ProtectedItem item in PluginSettings.Instance.ProtectedItems )
4037
{
41-
if (!item.Enabled)
38+
if ( !item.Enabled )
4239
continue;
4340

44-
if (entity.EntityId == item.EntityId)
41+
if ( entity.EntityId == item.EntityId )
4542
{
46-
ProtectedEntity(entity, item);
43+
ProtectedEntity( entity );
4744
}
4845
}
4946
}
5047

51-
base.Handle();
48+
base.Handle( );
5249
}
5350

54-
private void ProtectedEntity(IMyEntity entity, ProtectedItem item)
51+
private static void ProtectedEntity( IMyEntity entity )
5552
{
56-
//Log.Info(string.Format("Protecting: {0}", entity.EntityId));
57-
//CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity);
58-
CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(entity.EntityId);
59-
MyObjectBuilder_CubeGrid grid = (MyObjectBuilder_CubeGrid)entity.GetObjectBuilder();
60-
61-
int count = 0;
62-
while (gridEntity.IsLoading)
63-
{
64-
if (count >= 20)
65-
return;
66-
67-
Thread.Sleep(100);
68-
count++;
69-
}
53+
if ( !entity.InScene )
54+
return;
55+
Essentials.Log.Info( "Protecting: {0}", entity.EntityId );
56+
IMyCubeGrid cubeGridEntity = entity as IMyCubeGrid;
57+
if ( cubeGridEntity == null )
58+
return;
7059

60+
List<IMySlimBlock> blocks = new List<IMySlimBlock>( );
61+
cubeGridEntity.GetBlocks( blocks, block => true );
7162
bool found = false;
72-
/*
73-
foreach(CubeBlockEntity block in gridEntity.CubeBlocks)
63+
foreach ( IMySlimBlock block in blocks )
7464
{
75-
if (block.IntegrityPercent != item.IntegrityIncrease || block.BuildPercent != item.IntegrityIncrease || block.BoneDamage > 0f)
65+
MyObjectBuilder_CubeBlock objectBuilderCubeBlock = block.GetObjectBuilder( );
66+
if ( objectBuilderCubeBlock.BuildPercent < 1f )
67+
{
68+
found = true;
69+
objectBuilderCubeBlock.BuildPercent = 1f;
70+
}
71+
if ( objectBuilderCubeBlock.IntegrityPercent < 1f )
7672
{
7773
found = true;
78-
block.FixBones(0, 100);
79-
block.IntegrityPercent = item.IntegrityIncrease;
80-
block.BuildPercent = item.IntegrityIncrease;
74+
objectBuilderCubeBlock.IntegrityPercent = 1f;
8175
}
76+
if ( objectBuilderCubeBlock.DeformationRatio > 0f )
77+
{
78+
found = true;
79+
objectBuilderCubeBlock.DeformationRatio = 0;
80+
}
81+
8282
}
83-
*/
84-
if(found)
85-
Log.Info(string.Format("Repaired Grid: {0}", gridEntity.EntityId));
83+
84+
if ( found )
85+
Essentials.Log.Info( "Repaired Grid: {0}", entity.EntityId );
8686
}
8787
}
8888
}

0 commit comments

Comments
 (0)