Advertisement
idiotonastic

Gazer1

Feb 7th, 2021
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.65 KB | None | 0 0
  1. Dictionary<string, string[]> CommandList = new Dictionary<string, string[]>()
  2. {
  3. ["ForceFactionDiplomacy"] = new string[]
  4. {
  5. "Boolean",
  6. "string factionTagA",
  7. "string factionTagB",
  8. "string diplomacy" // "Peace", "War"
  9. },
  10. ["ForcePlayerIntoFaction"] = new string[]
  11. {
  12. "Boolean",
  13. "string factionTag",
  14. "long entityId" // IMyCharacter
  15. },
  16. ["BroadcastNotification"] = new string[]
  17. {
  18. "Boolean",
  19. "string messageContent",
  20. "int messageDuration",
  21. "string fontColor",
  22. "double distanceToBroadcast",
  23. "string audioToPlay"
  24. },
  25. ["ChatToPlayers"] = new string[]
  26. {
  27. "Boolean",
  28. "string message",
  29. "string author",
  30. "double broadcastRange",
  31. "string audioClip"
  32. },
  33. ["CreateExplosionAtPosition"] = new string[]
  34. {
  35. "Boolean",
  36. "Vector3D position",
  37. "float radius",
  38. "int damage"
  39. },
  40. ["CutVoxelsFromProjection"] = new string[]
  41. {
  42. "Boolean",
  43. "long projectorId" // IMyProjector
  44. },
  45. ["LaserFireRequest"] = new string[]
  46. {
  47. "Boolean",
  48. "LaserFireRequest",
  49. "long firingBlockId",
  50. "double maxHitRange",
  51. "double maxTravelRange",
  52. "int tickDuration",
  53. "int tickDamageIncrement",
  54. "string audioClip",
  55. "string beamType",
  56. "string beamColor",
  57. "string damageType",
  58. "string explosionType"
  59. },
  60. ["PlayParticleEffect"] = new string[]
  61. {
  62. "Boolean",
  63. "ParticleEffectRequest",
  64. "MyParticleEffect effect",
  65. "Vector3D targetCoords"
  66. },
  67. ["ChangeBlockSharing"] = new string[]
  68. {
  69. "Boolean",
  70. "string shareMode", // "Faction", "All", default None
  71. "long entityId" // MyCubeBlock
  72. },
  73. ["ChangeFactionRequest"] = new string[]
  74. {
  75. "Boolean",
  76. "string factionTag"
  77. },
  78. ["ChangeOtherGridOwnership"] = new string[]
  79. {
  80. "Boolean",
  81. "string factionTag",
  82. "long entityId" // IMyCubeGrid
  83. },
  84. ["CreateItemInInventory"] = new string[]
  85. {
  86. "Boolean",
  87. "string type",
  88. "string subtype",
  89. "float amount",
  90. "long entityId" // IMyTerminalBlock
  91. },
  92. ["DespawnDrone"] = new string[]
  93. {
  94. "Boolean"
  95. },
  96. ["GetAmmoAndFillWeapon"] = new string[]
  97. {
  98. "Boolean",
  99. "long blockEntityId", // IMyUserControllableGun
  100. "int addUpToLimit",
  101. "string specificAmmoSubtype" // default "Any"
  102. },
  103. ["GridSetDestructable"] = new string[]
  104. {
  105. "Boolean",
  106. "bool setMode",
  107. "long entityId" // MyCubeGrid
  108. },
  109. ["GridSetEditable"] = new string[]
  110. {
  111. "Boolean",
  112. "bool setMode",
  113. "long entityId" // MyCubeGrid
  114. },
  115. ["GasTankRefill"] = new string[]
  116. {
  117. "Boolean"
  118. },
  119. ["IceRefill"] = new string[]
  120. {
  121. "Boolean"
  122. },
  123. ["InsertPlayerIntoShipMainCockpit"] = new string[]
  124. {
  125. "Boolean",
  126. "long characterId", // IMyCharacter
  127. "long shipId" // IMyCubeGrid
  128. },
  129. ["IsOwnedByNPC"] = new string[]
  130. {
  131. "Boolean"
  132. },
  133. ["ToggleBlocksContainingName"] = new string[]
  134. {
  135. "Boolean",
  136. "string blockNameSearch",
  137. "bool toggle",
  138. "long gridId" // IMyCubeGrid
  139. },
  140. ["UpdateProgramBlockScript"] = new string[]
  141. {
  142. "Boolean",
  143. "var newScript = programmableBlockScripts[sourceBlock.CustomData];"
  144. },
  145. ["SpawnReinforcements"] = new string[]
  146. {
  147. "Boolean",
  148. "string spawnType", // "Prefab", "SpawnGroup"
  149. "string spawnName",
  150. "string spawnFaction",
  151. "bool spawnAll",
  152. "Vector3D coords",
  153. "Vector3D forwardDir",
  154. "Vector3D upDir",
  155. "Vector3D velocity"
  156. },
  157. ["AltitudeDifferenceAtPosition"] = new string[]
  158. {
  159. "double",
  160. "Vector3D coords"
  161. },
  162. ["GetAllAllies"] = new string[]
  163. {
  164. "List<long>",
  165. "double distanceToCheck"
  166. },
  167. ["GetAllEnemies"] = new string[]
  168. {
  169. "List<long>",
  170. "string specificFaction", // default ""
  171. "double distanceToCheck"
  172. },
  173. ["GetDetectedEntityInfo"] = new string[]
  174. {
  175. "MyDetectedEntityInfo",
  176. "long entityId" // MyEntity
  177. },
  178. ["GetNearestAllied"] = new string[]
  179. {
  180. "long",
  181. "double distanceToCheck"
  182. },
  183. ["GetNearestEnemy"] = new string[]
  184. {
  185. "long",
  186. "string specificFaction", // default ""
  187. "double distanceToCheck"
  188. },
  189. ["GetNearestPlanetPosition"] = new string[]
  190. {
  191. "Vector3D",
  192. "Vector3D checkCoords"
  193. },
  194. ["GetTargetShipSystem"] = new string[]
  195. {
  196. "long",
  197. "long targetEntityId", // IMyCubeGrid
  198. "string systemTarget", // SlimBlock.BlockDefinition.Id.TypeId, "Clang", "Communications", "Controller", "Power", "Nuclear", "Production", "Propulsion", "Weapons"
  199. },
  200. ["IsHumanControllingTarget"] = new string[]
  201. {
  202. "Boolean",
  203. "long entityId" // Ignored?
  204. },
  205. ["IsPositionInNaturalGravity"] = new string[]
  206. {
  207. "Boolean",
  208. "Vector3D checkCoords"
  209. },
  210. ["IsOwnedByFaction"] = new string[]
  211. {
  212. "Boolean",
  213. "var factionTag"
  214. },
  215. ["TargetBlockCount"] = new string[]
  216. {
  217. "int",
  218. "long entityId" // IMyCubeGrid
  219. },
  220. ["TargetCanFly"] = new string[]
  221. {
  222. "Boolean",
  223. "long entityId" // MyCubeGrid
  224. },
  225. ["TargetIsBroadcasting"] = new string[]
  226. {
  227. "Boolean",
  228. "long entityId", // IMyCubeGrid
  229. "bool checkAntennas",
  230. "bool checkBeacons"
  231. },
  232. ["TargetIsStatic"] = new string[]
  233. {
  234. "Boolean",
  235. "long entityId" // MyCubeGrid
  236. },
  237. ["TargetPowered"] = new string[]
  238. {
  239. "Boolean",
  240. "long entityId" // MyCubeGrid
  241. },
  242. ["TrackEntity"] = new string[]
  243. {
  244. "Vector3D",
  245. "long entityId" // IMyCubeGrid
  246. },
  247.  
  248. ["CorruptionDebugPB"] = new string[]
  249. {
  250. "Boolean"
  251. },
  252. ["CorruptionDroneDespawn"] = new string[]
  253. {
  254. "Boolean"
  255. },
  256. ["CorruptionDroneChat"] = new string[]
  257. {
  258. "Boolean",
  259. "string message"
  260. },
  261. ["CorruptionOwnerCheck"] = new string[]
  262. {
  263. "Boolean"
  264. },
  265. ["CorruptionIceRefill"] = new string[]
  266. {
  267. "Boolean"
  268. },
  269. ["CorruptionTeleport"] = new string[]
  270. {
  271. "Boolean",
  272. "Vector3D teleportPosition",
  273. "Vector3D targetPosition",
  274. "Vector3D targetVelocity"
  275. },
  276. ["CorruptionHacking"] = new string[]
  277. { // "CORRUPT" must exists
  278. "Boolean",
  279. "long gridEntityId", // IMyCubeGrid
  280. "string hackingType" // "HackBlock", "DisableProduction", "DisableDefense", "DisableAutomation", "HudSpam", "OverloadShields", "CorruptNames", "GyroOverride", "ThrustOverride", "HackLights"
  281. },
  282. ["CorruptionHackingTargets"] = new string[]
  283. {
  284. "List<long>"
  285. },
  286. ["CorruptionSpawning"] = new string[]
  287. { // "CORRUPT" must exists
  288. "Boolean",
  289. "string spawnGroupName",
  290. "Vector3D coords",
  291. "Vector3D velocity",
  292. "Vector3D forwardDir",
  293. "bool successfulSpawnMandatory"
  294. },
  295. ["CorruptionShieldMod"] = new string[]
  296. {
  297. "Boolean"
  298. },
  299. ["CorruptionMeteorLaunch"] = new string[]
  300. {
  301. "Boolean",
  302. "Vector3D spawnCoords",
  303. "Vector3D launchDirection",
  304. "Vector3D inheritedVelocity"
  305. },
  306. ["CorruptionProjectorBuild"] = new string[]
  307. {
  308. "Boolean",
  309. "bool instantBuild",
  310. "int blocksToBuild"
  311. },
  312. ["CorruptionRepairBlocks"] = new string[]
  313. {
  314. "Boolean",
  315. "int blocksToBuild"
  316. },
  317. ["CorruptionInstantRotate"] = new string[]
  318. {
  319. "Boolean",
  320. "Vector3D targetCoords",
  321. "Vector3D upDir"
  322. },
  323. ["CorruptionNearestPlanet"] = new string[]
  324. {
  325. "Vector3D"
  326. },
  327. ["CorruptionGridHealth"] = new string[]
  328. {
  329. "float"
  330. },
  331. ["CorruptionSniperReload"] = new string[]
  332. { // Must have "Corruption Rocket Launcher Sniper" as IMyUserControllableGun
  333. // Must have "Medium Cargo Container" as IMyCargoContainer
  334. // Must have MyObjectBuilder_AmmoMagazine/Corruption-Missile200mm-Sniper
  335. "Boolean"
  336. },
  337. ["CorruptionTestLaser"] = new string[]
  338. {
  339. "Boolean"
  340. },
  341. ["CorruptionLaserRequest"] = new string[]
  342. {
  343. "Boolean",
  344. "long entityId" // IMyCameraBlock
  345. },
  346. ["CorruptionSecondaryDrawLaser"] = new string[]
  347. {
  348. "Boolean",
  349. "Vector3D startCoords",
  350. "Vector3D endCoords"
  351. },
  352. ["CorruptionLaserDamage"] = new string[]
  353. {
  354. "Boolean",
  355. "Vector3D startCoords", // Ignored?
  356. "Vector3D endCoords",
  357. "long entityId" // IMyCubeGrid
  358. },
  359. ["CorruptionTeslaFire"] = new string[]
  360. {
  361. "Boolean",
  362. "long sourceEntity", // IMyEntity
  363. "long targetEntity" // IMyEntity
  364. },
  365. ["CorruptionInvincibility"] = new string[]
  366. {
  367. "Boolean",
  368. "bool status"
  369. },
  370. ["CorruptionBossSpawn"] = new string[]
  371. { // "CORRUPT" must exists
  372. "Boolean"
  373. },
  374. ["CorruptionBeamEffectRequest"] = new string[]
  375. {
  376. "Boolean",
  377. "long entityId" // IMyCameraBlock
  378. },
  379. ["CorruptionTrackEntity"] = new string[]
  380. {
  381. "Vector3D",
  382. "long targetEntityId" // IMyCubeGrid
  383. },
  384. ["CorruptionNearestPlayerThreat"] = new string[]
  385. {
  386. "long"
  387. },
  388. ["CorruptionNearestShieldDrone"] = new string[]
  389. { // Grid must be named "(NPC-CPC) Shield Coordinator Drone" and owned by "CORRUPT" within 15000
  390. "long"
  391. },
  392. ["CorruptionResetTerminalNames"] = new string[]
  393. {
  394. "Boolean"
  395. },
  396. ["CorruptionClonePlayerShip"] = new string[]
  397. {
  398. "Boolean"
  399. },
  400. ["CorruptionShieldRegister"] = new string[]
  401. {
  402. "Boolean"
  403. },
  404. ["CorruptionMissileCreation"] = new string[]
  405. { // Must have MyObjectBuilder_Warhead/CorruptSeekerMissile
  406. // Must have MyObjectBuilder_BatteryBlock/CorruptDummyBattery
  407. "Boolean",
  408. "long targetId", // IMyTerminalBlock
  409. "Vector3D spawnCoords",
  410. "Vector3D forwardDir"
  411. },
  412. };
  413. List<IMyProgrammableBlock> ProgramBlocks = new List<IMyProgrammableBlock>();
  414. IMyProgrammableBlock LastBlock = null, LastNPCBlock = null;
  415.  
  416. public Program()
  417. {
  418. }
  419.  
  420. public void Save()
  421. {
  422. }
  423.  
  424. public void Main(string argument, UpdateType updateSource)
  425. {
  426. MyCommandLine commandLine = new MyCommandLine();
  427. if (commandLine.TryParse(argument))
  428. {
  429. if (commandLine.Switch("list"))
  430. {
  431. string results = "";
  432. for (int i = ProgramBlocks.Count - 1; i >= 0; i--)
  433. results += i.ToString() + ". " + ProgramBlocks[i].ToString() + "\n " + ToGPS(ProgramBlocks[i].CustomName + " " + (Vector3D.Distance(ProgramBlocks[i].GetPosition(), Me.GetPosition()) / 1000).ToString("0.###") + "km", ProgramBlocks[i].GetPosition()) + "\n";
  434. Echo(results);
  435. IMyTextSurface surface = (Me as IMyTextSurfaceProvider).GetSurface(0);
  436. surface.WriteText(results);
  437. surface.ContentType = ContentType.TEXT_AND_IMAGE;
  438. return;
  439. }
  440. IMyProgrammableBlock npcblock = Me;
  441. if (commandLine.ArgumentCount > 1)
  442. {
  443. string arg = commandLine.Argument(1);
  444. npcblock = GridTerminalSystem.GetBlockWithName(arg) as IMyProgrammableBlock;
  445. if (!(npcblock is IMyProgrammableBlock))
  446. try
  447. {
  448. npcblock = GridTerminalSystem.GetBlockWithId(Convert.ToInt64(arg, 16)) as IMyProgrammableBlock;
  449. }
  450. catch {}
  451. if (!(npcblock is IMyProgrammableBlock))
  452. try
  453. {
  454. npcblock = GridTerminalSystem.GetBlockWithId(Convert.ToInt64(arg)) as IMyProgrammableBlock;
  455. }
  456. catch {}
  457. if (npcblock is IMyProgrammableBlock)
  458. {
  459. if (commandLine.Switch("last"))
  460. {
  461. LastBlock = npcblock;
  462. Echo("Set Last: " + LastBlock.ToString());
  463. }
  464. if (!ProgramBlocks.Contains(npcblock))
  465. ProgramBlocks.Add(npcblock);
  466. }
  467. else if (commandLine.Switch("last"))
  468. {
  469. int i;
  470. if (commandLine.Switch("last", 0) != null && int.TryParse(commandLine.Switch("last", 0), out i) && i < ProgramBlocks.Count)
  471. npcblock = ProgramBlocks[i];
  472. }
  473. }
  474. else if (commandLine.Switch("last") && LastBlock is IMyProgrammableBlock)
  475. npcblock = LastBlock;
  476. if (commandLine.Switch("backup") && LastNPCBlock is IMyProgrammableBlock)
  477. npcblock = LastNPCBlock;
  478. argument = commandLine.Argument(0);
  479. IMyTerminalBlock block = GridTerminalSystem.GetBlockWithName(argument);
  480. if (!(block is IMyTerminalBlock) && argument == "Me")
  481. block = Me;
  482. if (block is IMyTerminalBlock)
  483. {
  484. StringBuilder results = new StringBuilder();
  485. string[] data = block.CustomData.Split('\n');
  486. for (int i = 0; i < data.Length; i++)
  487. {
  488. string command = data[i].Trim();
  489. if (command.Length == 0)
  490. continue;
  491. string type = "";
  492. int numparams = 0;
  493. string[] param = command.Split(':');
  494. if (param.Length > 1)
  495. {
  496. command = param[0];
  497. type = param[1];
  498. }
  499. if (CommandList.ContainsKey(command))
  500. {
  501. param = CommandList[command];
  502. type = param[0];
  503. numparams = param.Length - 1;
  504. }
  505. else
  506. {
  507. List<string> search = CommandList.Keys.Where(c => c.StartsWith(command, StringComparison.InvariantCultureIgnoreCase)).ToList();
  508. if (search.Count == 0)
  509. search = CommandList.Keys.Where(c => c.IndexOf(command, StringComparison.InvariantCultureIgnoreCase) >= 0).ToList();
  510. if (search.Count == 1)
  511. {
  512. command = search[0];
  513. param = CommandList[command];
  514. type = param[0];
  515. numparams = param.Length - 1;
  516. data[i] = command;
  517. }
  518. else
  519. {
  520. results.Append("Unknown ");
  521. numparams = data.Length - 1 - i;
  522. }
  523. }
  524. if (numparams + i >= data.Length)
  525. numparams = data.Length - 1 - i;
  526. if (numparams > 0)
  527. {
  528. List<int> argpos = null;
  529. switch (command)
  530. {
  531. case "CreateExplosionAtPosition":
  532. case "AltitudeDifferenceAtPosition":
  533. case "GetNearestPlanetPosition":
  534. case "IsPositionInNaturalGravity":
  535. case "CorruptionMeteorLaunch":
  536. case "CorruptionInstantRotate":
  537. argpos = new List<int>() {1};
  538. break;
  539. case "CorruptionSpawning":
  540. case "CorruptionMissileCreation":
  541. argpos = new List<int>() {2};
  542. break;
  543. case "PlayParticleEffect":
  544. argpos = new List<int>() {3};
  545. break;
  546. case "SpawnReinforcements":
  547. argpos = new List<int>() {5};
  548. break;
  549. case "CorruptionTeleport":
  550. case "CorruptionSecondaryDrawLaser":
  551. case "CorruptionLaserDamage":
  552. argpos = new List<int>() {1, 2};
  553. break;
  554. }
  555. if (argpos != null)
  556. {
  557. for (int j = 0; j < argpos.Count; j++)
  558. {
  559. Vector3D vector;
  560. if (numparams >= argpos[j] && !Vector3D.TryParse(data[i + argpos[j]], out vector))
  561. {
  562. if (data[i + argpos[j]].StartsWith("GPS:"))
  563. {
  564. Vector3D coords = ParseGPS(data[i + argpos[j]]);
  565. if (coords != Vector3D.Zero)
  566. data[i + argpos[j]] = coords.ToString();
  567. }
  568. else if (data[i + argpos[j]] == "Me")
  569. {
  570. data[i + argpos[j]] = Me.GetPosition().ToString();
  571. }
  572. else
  573. {
  574. IMyTerminalBlock b = GridTerminalSystem.GetBlockWithName(data[i + argpos[j]]);
  575. if (b is IMyTerminalBlock)
  576. data[i + argpos[j]] = b.GetPosition().ToString();
  577. else
  578. data[i + argpos[j]] = Vector3D.Zero.ToString();
  579. }
  580. }
  581. }
  582. }
  583. long id;
  584. int cubegrid = 0;
  585. bool multigrid = false;
  586. int cubeblock = 0;
  587. List<IMyCubeBlock> blocklist = null;
  588. switch (command)
  589. {
  590. case "CutVoxelsFromProjection":
  591. cubeblock = 1;
  592. if (numparams >= cubeblock)
  593. blocklist = GetEntityId<IMyProjector>(ref data[i + cubeblock]);
  594. break;
  595. case "ChangeBlockSharing":
  596. cubeblock = 2;
  597. if (numparams >= cubeblock)
  598. {
  599. blocklist = GetEntityId<IMyCubeBlock>(ref data[i + cubeblock]);
  600. if (blocklist != null)
  601. blocklist = blocklist.Where(b => b.OwnerId == npcblock.OwnerId).ToList();
  602. }
  603. break;
  604. case "CreateItemInInventory":
  605. if (numparams >= 4)
  606. {
  607. IMyInventory inventory = null;
  608. if (!long.TryParse(data[i + 4], out id))
  609. {
  610. IMyTerminalBlock b = GridTerminalSystem.GetBlockWithName(data[i + 4]);
  611. if (b is IMyTerminalBlock)
  612. {
  613. data[i + 4] = b.EntityId.ToString();
  614. if (b.InventoryCount > 0)
  615. inventory = b.GetInventory(0);
  616. }
  617. else
  618. try
  619. {
  620. id = Convert.ToInt64(data[i + 4], 16);
  621. data[i + 4] = id.ToString();
  622. }
  623. catch {}
  624. }
  625. if (inventory == null && id != 0)
  626. {
  627. IMyTerminalBlock b = GridTerminalSystem.GetBlockWithId(id);
  628. if (b is IMyTerminalBlock && b.InventoryCount > 0)
  629. inventory = b.GetInventory(0);
  630. }
  631. if (data[i + 1] == "BARS")
  632. {
  633. IMyTerminalBlock b = GridTerminalSystem.GetBlockWithName(data[i + 2]);
  634. if (b is IMyShipWelder && b.BlockDefinition.SubtypeId.Contains("NanobotBuildAndRepairSystem"))
  635. {
  636. Dictionary<MyDefinitionId, int> components;
  637. try
  638. {
  639. components = b.GetValue<Dictionary<MyDefinitionId, int>>("BuildAndRepair.MissingComponents");
  640. int count = 0;
  641. List<string> complist = new List<string>();
  642. foreach (var component in components)
  643. {
  644. count++;
  645. if (count == 1)
  646. {
  647. data[i + 1] = component.Key.TypeId.ToString();
  648. data[i + 2] = component.Key.SubtypeId.ToString();
  649. data[i + 3] = component.Value.ToString();
  650. }
  651. else
  652. {
  653. complist.Add(command);
  654. complist.Add(component.Key.TypeId.ToString());
  655. complist.Add(component.Key.SubtypeId.ToString());
  656. complist.Add(component.Value.ToString());
  657. complist.Add(data[i + 4]);
  658. }
  659. }
  660. if (complist.Count > 0)
  661. data = data.ToList().Concat(complist).ToArray();
  662. }
  663. catch {}
  664. }
  665. }
  666. else if (data[i + 1] == "WELDER" && inventory != null)
  667. {
  668. List<MyItemType> typelist = new List<MyItemType>();
  669. inventory.GetAcceptedItems(typelist, t => t.TypeId == "MyObjectBuilder_Component");
  670. double volume;
  671. double.TryParse(data[i + 3], out volume);
  672. volume /= 1000;
  673. int count = 0;
  674. List<string> complist = new List<string>();
  675. foreach (var itemtype in typelist)
  676. {
  677. MyItemInfo info = itemtype.GetItemInfo();
  678. double amount = Math.Max(1, Math.Ceiling(volume / info.Volume)) - (double) inventory.GetItemAmount(itemtype);
  679. if (amount > 0)
  680. {
  681. count++;
  682. if (count == 1)
  683. {
  684. data[i + 1] = itemtype.TypeId;
  685. data[i + 2] = itemtype.SubtypeId;
  686. data[i + 3] = amount.ToString();
  687. }
  688. else
  689. {
  690. complist.Add(command);
  691. complist.Add(itemtype.TypeId);
  692. complist.Add(itemtype.SubtypeId);
  693. complist.Add(amount.ToString());
  694. complist.Add(data[i + 4]);
  695. }
  696. }
  697. }
  698. if (complist.Count > 0)
  699. data = data.ToList().Concat(complist).ToArray();
  700. }
  701. else if (data[i + 1] == "" && inventory != null)
  702. {
  703. List<MyItemType> typelist = new List<MyItemType>();
  704. inventory.GetAcceptedItems(typelist);
  705. for (int j = typelist.Count - 1; j >= 0; j--)
  706. {
  707. if (typelist[j].SubtypeId.Equals(data[i + 2], StringComparison.OrdinalIgnoreCase))
  708. {
  709. data[i + 1] = typelist[j].TypeId;
  710. data[i + 2] = typelist[j].SubtypeId;
  711. break;
  712. }
  713. }
  714. }
  715. else if (!data[i + 1].StartsWith("MyObjectBuilder_"))
  716. data[i + 1] = "MyObjectBuilder_" + data[i + 1];
  717. if (inventory != null)
  718. {
  719. MyDefinitionId def = new MyDefinitionId();
  720. if (MyDefinitionId.TryParse(data[i + 1], data[i + 2], out def) && inventory.CanItemsBeAdded(-1, def))
  721. {
  722. double amount;
  723. if (double.TryParse(data[i + 3], out amount) && amount > 0)
  724. {
  725. MyItemInfo info = ((MyItemType) def).GetItemInfo();
  726. double avail = ((double) inventory.MaxVolume - Math.Max(0, (double) inventory.CurrentVolume)) / info.Volume;
  727. if (!info.UsesFractions)
  728. avail = Math.Floor(avail);
  729. if (amount > avail && avail > 0)
  730. {
  731. data[i + 3] = avail.ToString();
  732. data = data.ToList().Concat(new string[] {command, data[i + 1], data[i + 2], (amount - avail).ToString(), data[i + 4]}).ToArray();
  733. }
  734. }
  735. }
  736. }
  737. }
  738. break;
  739. case "GetAmmoAndFillWeapon":
  740. cubeblock = 1;
  741. if (numparams >= cubeblock)
  742. blocklist = GetEntityId<IMyUserControllableGun>(ref data[i + cubeblock]);
  743. break;
  744. case "CorruptionLaserRequest":
  745. case "CorruptionBeamEffectRequest":
  746. cubeblock = 1;
  747. if (numparams >= cubeblock)
  748. blocklist = GetEntityId<IMyCameraBlock>(ref data[i + cubeblock]);
  749. break;
  750. case "CorruptionLaserDamage":
  751. cubeblock = 3;
  752. if (numparams >= cubeblock)
  753. blocklist = GetEntityId<IMyCubeBlock>(ref data[i + cubeblock]);
  754. break;
  755. case "GetTargetShipSystem":
  756. case "TargetBlockCount":
  757. case "TargetCanFly":
  758. case "TargetIsBroadcasting":
  759. case "TargetIsStatic":
  760. case "TargetPowered":
  761. case "TrackEntity":
  762. cubegrid = 1;
  763. break;
  764. case "ChangeOtherGridOwnership":
  765. case "InsertPlayerIntoShipMainCockpit":
  766. cubegrid = 2;
  767. break;
  768. case "GridSetDestructable":
  769. case "GridSetEditable":
  770. cubegrid = 2;
  771. multigrid = true;
  772. break;
  773. case "ToggleBlocksContainingName":
  774. cubegrid = 3;
  775. break;
  776. }
  777. if (cubeblock > 0 && blocklist != null)
  778. {
  779. List<string> ids = new List<string>();
  780. for (int j = 0; j < blocklist.Count; j++)
  781. {
  782. ids.Add(command);
  783. for (int k = 1; k <= numparams; k++)
  784. ids.Add(k == cubeblock ? blocklist[j].EntityId.ToString() : data[i + k]);
  785. }
  786. if (ids.Count > 0)
  787. {
  788. data[i + cubeblock] = ids[cubeblock];
  789. ids.RemoveRange(0, numparams + 1);
  790. }
  791. if (ids.Count > 0)
  792. data = data.ToList().Concat(ids).ToArray();
  793. }
  794. if (cubegrid > 0 && numparams >= cubegrid && !long.TryParse(data[i + cubegrid], out id))
  795. {
  796. if (data[i + cubegrid] == "Me")
  797. data[i + cubegrid] = Me.CubeGrid.EntityId.ToString();
  798. else
  799. {
  800. IMyCubeBlock b = GridTerminalSystem.GetBlockWithName(data[i + cubegrid]);
  801. if (b is IMyCubeBlock)
  802. data[i + cubegrid] = b.CubeGrid.EntityId.ToString();
  803. else
  804. {
  805. if (multigrid && (data[i + cubegrid] == "ALL" || data[i + cubegrid] == "OTHER"))
  806. {
  807. List<IMyCubeBlock> blocks = new List<IMyCubeBlock>();
  808. if (data[i + cubegrid] == "OTHER")
  809. GridTerminalSystem.GetBlocksOfType(blocks, c => c.CubeGrid != Me.CubeGrid);
  810. else
  811. GridTerminalSystem.GetBlocksOfType(blocks);
  812. long[] grids = blocks.Concat(blocks.Where(c => c is IMyMechanicalConnectionBlock && (c as IMyMechanicalConnectionBlock).Top is IMyWheel).Select(c => (c as IMyMechanicalConnectionBlock).Top)).Select(c => c.CubeGrid.EntityId).Distinct().ToArray();
  813. if (grids.Length > 0)
  814. {
  815. data[i + cubegrid] = grids[0].ToString();
  816. if (grids.Length > 1)
  817. {
  818. List<string> ids = new List<string>();
  819. for (int j = 1; j < grids.Length; j++)
  820. {
  821. ids.Add(command);
  822. for (int k = 1; k <= numparams; k++)
  823. ids.Add(k == cubegrid ? grids[j].ToString() : data[i + k]);
  824. }
  825. data = data.ToList().Concat(ids).ToArray();
  826. }
  827. }
  828. }
  829. else
  830. {
  831. try
  832. {
  833. id = Convert.ToInt64(data[i + cubegrid], 16);
  834. b = GridTerminalSystem.GetBlockWithId(id);
  835. if (b is IMyCubeBlock)
  836. data[i + cubegrid] = b.CubeGrid.EntityId.ToString();
  837. else
  838. data[i + cubegrid] = id.ToString();
  839. }
  840. catch {}
  841. }
  842. }
  843. }
  844. }
  845. }
  846. npcblock.CustomData = numparams > 0 ? String.Join("\n", data, i + 1, numparams) : "";
  847. results.AppendLine("Command: " + command + " (" + type + ")");
  848. if (!command.StartsWith("Corruption"))
  849. command = "NpcExtender-" + command;
  850. Object result = new Object();
  851. try
  852. {
  853. switch (type)
  854. {
  855. default:
  856. case "bool":
  857. case "Boolean":
  858. result = npcblock.GetValueBool(command);
  859. if ((bool) result == true)
  860. LastNPCBlock = npcblock;
  861. break;
  862. case "Color":
  863. result = npcblock.GetValueColor(command);
  864. break;
  865. case "float":
  866. case "Single":
  867. result = npcblock.GetValueFloat(command);
  868. break;
  869. case "long":
  870. result = npcblock.GetValue<long>(command);
  871. break;
  872. case "int":
  873. result = npcblock.GetValue<int>(command);
  874. break;
  875. case "Int64":
  876. result = npcblock.GetValue<Int64>(command);
  877. break;
  878. case "double":
  879. result = npcblock.GetValue<double>(command);
  880. break;
  881. case "Vector3D":
  882. result = npcblock.GetValue<Vector3D>(command);
  883. break;
  884. case "List<long>":
  885. result = npcblock.GetValue<List<long>>(command);
  886. break;
  887. case "MyDetectedEntityInfo":
  888. result = npcblock.GetValue<MyDetectedEntityInfo>(command);
  889. break;
  890. }
  891. }
  892. catch
  893. {
  894. result = "GetValue error";
  895. }
  896. if (result is MyDetectedEntityInfo)
  897. result = ShowEntity((MyDetectedEntityInfo) result);
  898. else if (result is IList)
  899. {
  900. switch (command)
  901. {
  902. case "NpcExtender-GetAllAllies":
  903. case "NpcExtender-GetAllEnemies":
  904. foreach (Object o in result as IList)
  905. if ((long) o != 0)
  906. data = data.ToList().Concat(new string[] {"TrackEntity", o.ToString(), "GetDetectedEntityInfo", o.ToString()}).ToArray();
  907. break;
  908. }
  909. string str = "List: " + (result as IList).Count.ToString();
  910. foreach (Object o in result as IList)
  911. str += "\n" + o.ToString();
  912. result = str;
  913. }
  914. else if (result is Vector3D)
  915. {
  916. result += "\n " + ToGPS(command + " " + (Vector3D.Distance(Me.GetPosition(), (Vector3D) result) / 1000).ToString("0.###") + "km", (Vector3D) result);
  917. }
  918. else if (result is long)
  919. {
  920. switch (command)
  921. {
  922. case "NpcExtender-GetNearestAllied":
  923. case "NpcExtender-GetNearestEnemy":
  924. case "CorruptionNearestPlayerThreat":
  925. if ((long) result != 0)
  926. data = data.ToList().Concat(new string[] {"TrackEntity", result.ToString(), "GetDetectedEntityInfo", result.ToString()}).ToArray();
  927. break;
  928. }
  929. }
  930. results.AppendLine(result.ToString());
  931. i += numparams;
  932. }
  933. npcblock.CustomData = String.Join("\n", data);
  934. Echo(results.ToString());
  935. IMyTextSurface surface;
  936. if (block is IMyTextSurface)
  937. surface = block as IMyTextSurface;
  938. else if (block is IMyTextSurfaceProvider)
  939. surface = (block as IMyTextSurfaceProvider).GetSurface(0);
  940. else
  941. surface = (Me as IMyTextSurfaceProvider).GetSurface(0);
  942. if (surface is IMyTextSurface)
  943. {
  944. surface.WriteText(results.ToString());
  945. surface.ContentType = ContentType.TEXT_AND_IMAGE;
  946. }
  947. }
  948. }
  949. }
  950.  
  951. public Vector3D ParseGPS(string strGPS)
  952. {
  953. string[] listGPS = strGPS.Split(':');
  954. double x, y, z;
  955. if (listGPS.Length > 4 && double.TryParse(listGPS[2], out x) && double.TryParse(listGPS[3], out y) && double.TryParse(listGPS[4], out z))
  956. return new Vector3D(x, y, z);
  957. else
  958. return Vector3D.Zero;
  959. }
  960.  
  961. public string ToGPS(string name, Vector3D gps)
  962. {
  963. return "GPS:" + name.Replace(":", "_") + gps.ToString("0.###").Replace("{", "").Replace("}","").Replace("X", "").Replace("Y", "").Replace("Z", "").Replace(" ", "") + ":";
  964. }
  965.  
  966. public List<IMyCubeBlock> GetEntityId<T>(ref string Data) where T : class, IMyCubeBlock
  967. {
  968. long EntityId;
  969. if (!long.TryParse(Data, out EntityId))
  970. {
  971. IMyCubeBlock block = Data == "Me" ? Me : GridTerminalSystem.GetBlockWithName(Data);
  972. if (block is IMyCubeBlock)
  973. {
  974. EntityId = block.EntityId;
  975. Data = EntityId.ToString();
  976. return null;
  977. }
  978. else
  979. {
  980. try
  981. {
  982. EntityId = Convert.ToInt64(Data, 16);
  983. Data = EntityId.ToString();
  984. return null;
  985. }
  986. catch {}
  987. List<T> list = new List<T>();
  988. switch (Data)
  989. {
  990. case "ALL":
  991. GridTerminalSystem.GetBlocksOfType(list);
  992. break;
  993. case "ALL_SELF":
  994. GridTerminalSystem.GetBlocksOfType(list, b => b.CubeGrid == Me.CubeGrid);
  995. break;
  996. case "ALL_OTHER":
  997. GridTerminalSystem.GetBlocksOfType(list, b => b.CubeGrid != Me.CubeGrid);
  998. break;
  999. }
  1000. if (list.Count > 0)
  1001. return list.Cast<IMyCubeBlock>().ToList();
  1002. else
  1003. return null;
  1004. }
  1005. }
  1006. return null;
  1007. }
  1008.  
  1009. public string ShowEntity(MyDetectedEntityInfo entity = new MyDetectedEntityInfo())
  1010. {
  1011. StringBuilder result = new StringBuilder();
  1012. if (entity.IsEmpty())
  1013. return "";
  1014. if (entity.EntityId != 0)
  1015. {
  1016. if (entity.HitPosition.HasValue)
  1017. result.AppendLine("Found At: " + Vector3D.Distance(Me.GetPosition(), entity.HitPosition.Value).ToString("0.00") + " m");
  1018. String size = entity.BoundingBox.Size.ToString("0.000");
  1019. String printSize = "";
  1020. double volume = 1;
  1021. String unitName = "m3";
  1022. if (size != null || size != "")
  1023. {
  1024. size = size.Replace("{", "").Replace("}", "").Replace("X", "").Replace("Y", "").Replace("Z", "").Replace(" ", "");
  1025. size = size.Trim();
  1026. String[] sizes = size.Split(':');
  1027. double factor = 1;
  1028. if (entity.Type.ToString() == "SmallGrid")
  1029. {
  1030. factor = 4;
  1031. unitName = "blocks";
  1032. }
  1033. else if (entity.Type.ToString() == "LargeGrid")
  1034. {
  1035. factor = 16;
  1036. unitName = "blocks";
  1037. }
  1038. foreach (String measure in sizes)
  1039. {
  1040. if (measure == "")
  1041. {
  1042. // first value
  1043. continue;
  1044. }
  1045. volume = volume * Math.Round(Convert.ToDouble(measure), 0);
  1046. printSize += (Convert.ToDouble(measure)).ToString("0.00") + " X ";
  1047. }
  1048. volume = volume / factor;
  1049. }
  1050. printSize = printSize.Remove(printSize.Length - 2);
  1051. printSize += "m";
  1052. result.AppendLine("Entity ID: " + entity.EntityId);
  1053. result.AppendLine("Name: " + entity.Name);
  1054. result.AppendLine("Type: " + entity.Type);
  1055. result.AppendLine("Velocity: " + entity.Velocity.ToString("0.000"));
  1056. result.AppendLine("Relationship: " + entity.Relationship);
  1057. result.AppendLine("Size: " + printSize);
  1058. result.AppendLine("Estimated Volume: " + volume +" "+ unitName);
  1059. result.AppendLine("Position: " + entity.Position.ToString("0.000"));
  1060. result.AppendLine("Distance: " + Vector3D.Distance(entity.Position, Me.GetPosition()).ToString("0.000") + " m");
  1061. result.AppendLine("GPS:" + entity.Name + entity.Position.ToString("0.000").Replace("{", "").Replace("}","").Replace("X", "").Replace("Y", "").Replace("Z", "").Replace(" ", "") + ":");
  1062. if (entity.HitPosition.HasValue)
  1063. result.AppendLine("Hit Position: " + entity.HitPosition.Value.ToString("0.000"));
  1064. result.AppendLine("Relationship: " + entity.Relationship.ToString());
  1065. }
  1066. return result.ToString();
  1067. }
  1068.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement