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

Commit c8de3a1

Browse files
committed
Docking
1 parent b3d6f19 commit c8de3a1

File tree

3 files changed

+37
-60
lines changed

3 files changed

+37
-60
lines changed

EssentialsPlugin/ChatHandlers/Dock/HandleDockDock.cs

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
using EssentialsPlugin.UtilityClasses;
1010
using Microsoft.Xml.Serialization.GeneratedAssembly;
1111
using Sandbox.Common.ObjectBuilders;
12+
using Sandbox.Game.Entities;
1213
using Sandbox.ModAPI;
1314
using SEModAPIInternal.API.Common;
14-
using SEModAPIInternal.API.Entity;
1515
using VRage.Game;
1616
using VRage.Game.ModAPI;
1717
using VRage.ModAPI;
@@ -32,17 +32,7 @@ public override string GetCommandText()
3232
{
3333
return "/dock dock";
3434
}
35-
36-
public override Communication.ServerDialogItem GetHelpDialog( )
37-
{
38-
Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem( );
39-
DialogItem.title = "Help";
40-
DialogItem.header = "";
41-
DialogItem.content = GetHelp( );
42-
DialogItem.buttonText = "close";
43-
return DialogItem;
44-
}
45-
35+
4636
public override bool IsAdminCommand()
4737
{
4838
return false;
@@ -73,7 +63,7 @@ public override bool HandleCommand(ulong userId, string[] words)
7363
m_docking = true;
7464
try
7565
{
76-
String pylonName = String.Join(" ", words);
66+
string pylonName = string.Join(" ", words);
7767

7868
/*
7969
int timeLeft;
@@ -86,13 +76,13 @@ public override bool HandleCommand(ulong userId, string[] words)
8676

8777
if (PlayerMap.Instance.GetPlayerIdsFromSteamId(userId).Count < 1)
8878
{
89-
Communication.SendPrivateInformation(userId, string.Format("Unable to find player Id: {0}", userId));
79+
Communication.SendPrivateInformation(userId, $"Unable to find player Id: {userId}" );
9080
return true;
9181
}
9282

9383
long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(userId).First();
9484

95-
Dictionary<String, List<IMyCubeBlock>> testList;
85+
Dictionary<string, List<IMyCubeBlock>> testList;
9686
List<IMyCubeBlock> beaconList;
9787
DockingZone.FindByName(pylonName, out testList, out beaconList, playerId);
9888
if (beaconList.Count == 4)
@@ -103,7 +93,7 @@ public override bool HandleCommand(ulong userId, string[] words)
10393
IMyTerminalBlock terminal = (IMyTerminalBlock)entityBlock;
10494
if (!terminal.HasPlayerAccess(playerId))
10595
{
106-
Communication.SendPrivateInformation(userId, string.Format("You do not have permission to use '{0}'. You must either own all the beacons or they must be shared with faction.", pylonName));
96+
Communication.SendPrivateInformation(userId, $"You do not have permission to use '{pylonName}'. You must either own all the beacons or they must be shared with faction." );
10797
return true;
10898
}
10999
}
@@ -112,7 +102,7 @@ public override bool HandleCommand(ulong userId, string[] words)
112102
int intersectElement = 0;
113103
if (Entity.CheckForIntersection(testList, beaconList, out intersectElement))
114104
{
115-
Communication.SendPrivateInformation(userId, string.Format("The docking zone '{0}' intersects with docking zone '{1}'. Make sure you place your docking zones so they don't overlap.", pylonName, testList.ElementAt(intersectElement).Key));
105+
Communication.SendPrivateInformation(userId, $"The docking zone '{pylonName}' intersects with docking zone '{testList.ElementAt( intersectElement ).Key}'. Make sure you place your docking zones so they don't overlap." );
116106
return true;
117107
}
118108

@@ -124,7 +114,7 @@ public override bool HandleCommand(ulong userId, string[] words)
124114
List<DockingItem> checkItems = Docking.Instance.Find(d => d.PlayerId == ownerId && d.TargetEntityId == parent.EntityId && d.DockingBeaconIds.Intersect(beaconListIds).Count() == 4);
125115
if (checkItems.Count >= PluginSettings.Instance.DockingShipsPerZone)
126116
{
127-
Communication.SendPrivateInformation(userId, string.Format("Docking zone '{0}' already contains the maximum capacity of ships.", pylonName));
117+
Communication.SendPrivateInformation(userId, $"Docking zone '{pylonName}' already contains the maximum capacity of ships." );
128118
return true;
129119
}
130120

@@ -175,13 +165,13 @@ public override bool HandleCommand(ulong userId, string[] words)
175165
// Make sure the docking zone contains the docking ship. If they intersect or are disjointed, then fail
176166
if (!Entity.GreaterThan(dockingBounding.HalfExtent * 2, targetBounding.HalfExtent * 2))
177167
{
178-
Communication.SendPrivateInformation(userId, string.Format("The ship '{0}' is too large for it's carrier. The ship's bounding box must fit inside the docking zone bounding box!", dockingEntity.DisplayName));
168+
Communication.SendPrivateInformation(userId, $"The ship '{dockingEntity.DisplayName}' is too large for it's carrier. The ship's bounding box must fit inside the docking zone bounding box!" );
179169
return true;
180170
}
181171

182172
if (targetBounding.Contains(ref dockingBounding) != ContainmentType.Contains)
183173
{
184-
Communication.SendPrivateInformation(userId, string.Format("The ship '{0}' is not fully inside the docking zone '{1}'. Make sure the ship is fully contained inside the docking zone", dockingEntity.DisplayName, pylonName));
174+
Communication.SendPrivateInformation(userId, $"The ship '{dockingEntity.DisplayName}' is not fully inside the docking zone '{pylonName}'. Make sure the ship is fully contained inside the docking zone" );
185175
return true;
186176
}
187177

@@ -190,20 +180,21 @@ public override bool HandleCommand(ulong userId, string[] words)
190180
float dockingMass = Entity.CalculateMass(dockingEntity);
191181
if (dockingMass > parentMass)
192182
{
193-
Communication.SendPrivateInformation(userId, string.Format("The ship you're trying to dock is too heavy for it's carrier. The ship mass must be less than half the large ship / stations mass! (DM={0}kg CM={1}kg)", dockingMass, parentMass));
183+
Communication.SendPrivateInformation(userId, $"The ship you're trying to dock is too heavy for it's carrier. The ship mass must be less than half the large ship / stations mass! (DM={dockingMass}kg CM={parentMass}kg)" );
194184
return true;
195185
}
196186

197187
// Check to see if the ship is piloted, if it is, error out.
198188
// TODO: Check to see if we can get a real time copy of this entity?
199189
List<IMySlimBlock> blocks = new List<IMySlimBlock>();
200-
dockingEntity.GetBlocks(blocks, x => x.FatBlock != null && x.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Cockpit));
201-
foreach (IMySlimBlock slim_cbe in blocks)
190+
dockingEntity.GetBlocks(blocks, x => x.FatBlock is MyCockpit);
191+
foreach (IMySlimBlock slim in blocks)
202192
{
203-
MyObjectBuilder_Cockpit c = (MyObjectBuilder_Cockpit)slim_cbe.FatBlock.GetObjectBuilderCubeBlock();
193+
//MyObjectBuilder_Cockpit c = (MyObjectBuilder_Cockpit)slim.FatBlock.GetObjectBuilderCubeBlock();
194+
var c = (MyShipController)slim.FatBlock;
204195
if (c.Pilot != null)
205196
{
206-
Communication.SendPrivateInformation(userId, string.Format("Ship in docking zone '{0}' has a pilot! Please exit the ship before trying to dock. (Sometimes this can lag a bit. Wait 10 seconds and try again)", pylonName));
197+
Communication.SendPrivateInformation(userId, $"Ship in docking zone '{pylonName}' has a pilot! Please exit the ship before trying to dock. (Sometimes this can lag a bit. Wait 10 seconds and try again)" );
207198
return true;
208199
}
209200
}
@@ -217,16 +208,16 @@ public override bool HandleCommand(ulong userId, string[] words)
217208
saveQuat = Quaternion.Inverse(saveQuat) * Quaternion.CreateFromRotationMatrix(dockingEntity.WorldMatrix.GetOrientation());
218209

219210
// Save ship to file and remove
220-
FileInfo info = new FileInfo( Path.Combine( Essentials.PluginPath, "Docking", string.Format( "docked_{0}_{1}_{2}.sbc", ownerId, parent.EntityId, dockingEntity.EntityId ) ) );
211+
FileInfo info = new FileInfo( Path.Combine( Essentials.PluginPath, "Docking", $"docked_{ownerId}_{parent.EntityId}_{dockingEntity.EntityId}.sbc" ) );
221212
if ( !Directory.Exists( info.DirectoryName ) )
222213
{
223214
Directory.CreateDirectory( info.DirectoryName );
224215
}
225216
//CubeGridEntity dockingGrid = new CubeGridEntity((MyObjectBuilder_CubeGrid)dockingEntity.GetObjectBuilder(), dockingEntity);
226-
MyObjectBuilder_CubeGrid gridBuilder=null;// = CubeGrids.SafeGetObjectBuilder(dockingEntity);
217+
MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(dockingEntity);
227218
if (gridBuilder == null)
228219
{
229-
Communication.SendPrivateInformation(userId, string.Format("Failed to load entity for export: {0}", dockingEntity.DisplayName));
220+
Communication.SendPrivateInformation(userId, $"Failed to load entity for export: {dockingEntity.DisplayName}" );
230221
return true;
231222
}
232223

@@ -245,11 +236,9 @@ public override bool HandleCommand(ulong userId, string[] words)
245236

246237
// Serialize and save ship to file
247238
MyObjectBuilderSerializer.SerializeXML( info.FullName, false, gridBuilder );
248-
//BaseObjectManager.SaveContentFile<MyObjectBuilder_CubeGrid, MyObjectBuilder_CubeGridSerializer>(gridBuilder, info);
249-
BaseEntityNetworkManager.BroadcastRemoveEntity(dockingEntity);
250-
//dockingEntity.Close();
239+
Wrapper.BeginGameAction( ( ) => dockingEntity.Close( ) );
251240

252-
Communication.SendPrivateInformation(userId, string.Format("Docked ship '{0}' in docking zone '{1}'.", dockItem.DockedName, pylonName));
241+
Communication.SendPrivateInformation(userId, $"Docked ship '{dockItem.DockedName}' in docking zone '{pylonName}'." );
253242
Log.Info( "Docked ship \"{0}\" in docking zone \"{1}\". Saved to {2}", dockItem.DockedName, pylonName, info.FullName );
254243
/*
255244
// Add a cool down
@@ -261,12 +250,12 @@ public override bool HandleCommand(ulong userId, string[] words)
261250
}
262251
else
263252
{
264-
Communication.SendPrivateInformation(userId, string.Format("No ships in docking zone '{0}'.", pylonName));
253+
Communication.SendPrivateInformation(userId, $"No ships in docking zone '{pylonName}'." );
265254
}
266255
}
267256
else if (beaconList.Count > 4)
268257
{
269-
Communication.SendPrivateInformation(userId, string.Format("Too many beacons with the name or another zone with the name '{0}'. Place only 4 beacons to create a zone or try a different zone name.", pylonName));
258+
Communication.SendPrivateInformation(userId, $"Too many beacons with the name or another zone with the name '{pylonName}'. Place only 4 beacons to create a zone or try a different zone name." );
270259
}
271260
else
272261
{

EssentialsPlugin/ChatHandlers/Dock/HandleDockUndock.cs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Sandbox.Game.Replication;
1212
using Sandbox.ModAPI;
1313
using SEModAPIInternal.API.Common;
14-
using SEModAPIInternal.API.Entity;
1514
using VRage;
1615
using VRage.Game;
1716
using VRage.Game.ModAPI;
@@ -33,17 +32,7 @@ public override string GetCommandText()
3332
{
3433
return "/dock undock";
3534
}
36-
37-
public override Communication.ServerDialogItem GetHelpDialog( )
38-
{
39-
Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem( );
40-
DialogItem.title = "Help";
41-
DialogItem.header = "";
42-
DialogItem.content = GetHelp( );
43-
DialogItem.buttonText = "close";
44-
return DialogItem;
45-
}
46-
35+
4736
public override bool IsAdminCommand()
4837
{
4938
return false;
@@ -67,23 +56,23 @@ public override bool HandleCommand(ulong userId, string[] words)
6756

6857
if (m_undocking)
6958
{
70-
Communication.SendPrivateInformation(userId, string.Format("Server is busy, try again"));
59+
Communication.SendPrivateInformation(userId, "Server is busy, try again");
7160
return true;
7261
}
7362

7463
m_undocking = true;
7564
try
7665
{
77-
String pylonName = String.Join( " ", words );
66+
string pylonName = string.Join( " ", words );
7867
if ( PlayerMap.Instance.GetPlayerIdsFromSteamId( userId ).Count < 1 )
7968
{
80-
Communication.SendPrivateInformation( userId, string.Format( "Unable to find player Id: {0}", userId ) );
69+
Communication.SendPrivateInformation( userId, $"Unable to find player Id: {userId}" );
8170
return true;
8271
}
8372

8473
long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId( userId ).First( );
8574

86-
Dictionary<String, List<IMyCubeBlock>> testList;
75+
Dictionary<string, List<IMyCubeBlock>> testList;
8776
List<IMyCubeBlock> beaconList;
8877
DockingZone.FindByName( pylonName, out testList, out beaconList, playerId );
8978

@@ -93,7 +82,7 @@ public override bool HandleCommand(ulong userId, string[] words)
9382
{
9483
if ( !Entity.CheckOwnership( entity, playerId ) )
9584
{
96-
Communication.SendPrivateInformation( userId, string.Format( "You do not have permission to use '{0}'. You must either own all the beacons or they must be shared with faction.", pylonName ) );
85+
Communication.SendPrivateInformation( userId, $"You do not have permission to use '{pylonName}'. You must either own all the beacons or they must be shared with faction." );
9786
return true;
9887
}
9988
}
@@ -106,7 +95,7 @@ public override bool HandleCommand(ulong userId, string[] words)
10695
List<DockingItem> dockingItems = Docking.Instance.Find( d => d.PlayerId == ownerId && d.TargetEntityId == parent.EntityId && d.DockingBeaconIds.Intersect( beaconListIds ).Count( ) == 4 );
10796
if ( dockingItems.Count < 1 )
10897
{
109-
Communication.SendPrivateInformation( userId, string.Format( "You have no ships docked in docking zone '{0}'.", pylonName ) );
98+
Communication.SendPrivateInformation( userId, $"You have no ships docked in docking zone '{pylonName}'." );
11099
return true;
111100
}
112101

@@ -150,7 +139,7 @@ public override bool HandleCommand(ulong userId, string[] words)
150139
}
151140
}
152141

153-
String dockedShipFileName = Essentials.PluginPath + String.Format( "\\Docking\\docked_{0}_{1}_{2}.sbc", ownerId, dockingItem.TargetEntityId, dockingItem.DockedEntityId );
142+
string dockedShipFileName = Essentials.PluginPath + $"\\Docking\\docked_{ownerId}_{dockingItem.TargetEntityId}_{dockingItem.DockedEntityId}.sbc";
154143

155144
// Load Entity From File and add to game
156145
FileInfo fileInfo = new FileInfo( dockedShipFileName );
@@ -169,7 +158,7 @@ public override bool HandleCommand(ulong userId, string[] words)
169158
cubeGrid.PositionAndOrientation = new MyPositionAndOrientation( rotatedPos + parent.GetPosition( ), cubeGrid.PositionAndOrientation.Value.Forward, cubeGrid.PositionAndOrientation.Value.Up );
170159

171160
// Add object to world
172-
cubeGrid.EntityId = BaseEntity.GenerateEntityId( );
161+
cubeGrid.EntityId = MyEntityIdentifier.AllocateId( );
173162
cubeGrid.LinearVelocity = Vector3.Zero;
174163
cubeGrid.AngularVelocity = Vector3.Zero;
175164

@@ -179,12 +168,12 @@ public override bool HandleCommand(ulong userId, string[] words)
179168
try
180169
{
181170
IMyEntity entitiy = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd( cubeGrid );
182-
MyMultiplayer.ReplicateImmediatelly( MyExternalReplicable.FindByObject( entitiy ) );
171+
//MyMultiplayer.ReplicateImmediatelly( MyExternalReplicable.FindByObject( entitiy ) );
183172
undock = true;
184173
}
185174
catch ( Exception Ex )
186175
{
187-
Log.Info( string.Format( "Error undocking ship: {0}", Ex.ToString( ) ) );
176+
Log.Info( $"Error undocking ship: {Ex.ToString( )}" );
188177
Communication.SendPrivateInformation( userId, string.Format( "Unable to undock ship due to error." ) );
189178
}
190179
} );
@@ -198,7 +187,7 @@ public override bool HandleCommand(ulong userId, string[] words)
198187
File.Delete( dockedShipFileName );
199188
Docking.Instance.Remove( dockingItem );
200189

201-
Communication.SendPrivateInformation( userId, string.Format( "The ship '{0}' has been undocked from docking zone '{1}'", dockingItem.DockedName, pylonName ) );
190+
Communication.SendPrivateInformation( userId, $"The ship '{dockingItem.DockedName}' has been undocked from docking zone '{pylonName}'" );
202191

203192
/*
204193
// Queue for cooldown
@@ -248,8 +237,7 @@ public override bool HandleCommand(ulong userId, string[] words)
248237
else if ( beaconList.Count > 4 ) // Too many beacons, must be 4
249238
{
250239
Communication.SendPrivateInformation( userId,
251-
string.Format( "Too many beacons with the name or another zone with the name '{0}'. Place only 4 beacons to create a zone or try a different zone name.",
252-
pylonName ) );
240+
$"Too many beacons with the name or another zone with the name '{pylonName}'. Place only 4 beacons to create a zone or try a different zone name." );
253241
}
254242
else // Can't find docking zone
255243
{

EssentialsPlugin/Utility/Wrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void GameAction( Action action )
1313
SandboxGameAssemblyWrapper.Instance.GameAction(action);
1414
}
1515

16-
public static void BeginGameAction(Action action, SandboxGameAssemblyWrapper.GameActionCallback callback, Object state)
16+
public static void BeginGameAction(Action action, SandboxGameAssemblyWrapper.GameActionCallback callback = null, Object state = null)
1717
{
1818
SandboxGameAssemblyWrapper.Instance.BeginGameAction(action, callback, state);
1919
}

0 commit comments

Comments
 (0)