Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dictionary<string, string[]> CommandList = new Dictionary<string, string[]>()
- {
- ["ForceFactionDiplomacy"] = new string[]
- {
- "Boolean",
- "string factionTagA",
- "string factionTagB",
- "string diplomacy" // "Peace", "War"
- },
- ["ForcePlayerIntoFaction"] = new string[]
- {
- "Boolean",
- "string factionTag",
- "long entityId" // IMyCharacter
- },
- ["BroadcastNotification"] = new string[]
- {
- "Boolean",
- "string messageContent",
- "int messageDuration",
- "string fontColor",
- "double distanceToBroadcast",
- "string audioToPlay"
- },
- ["ChatToPlayers"] = new string[]
- {
- "Boolean",
- "string message",
- "string author",
- "double broadcastRange",
- "string audioClip"
- },
- ["CreateExplosionAtPosition"] = new string[]
- {
- "Boolean",
- "Vector3D position",
- "float radius",
- "int damage"
- },
- ["CutVoxelsFromProjection"] = new string[]
- {
- "Boolean",
- "long projectorId" // IMyProjector
- },
- ["LaserFireRequest"] = new string[]
- {
- "Boolean",
- "LaserFireRequest",
- "long firingBlockId",
- "double maxHitRange",
- "double maxTravelRange",
- "int tickDuration",
- "int tickDamageIncrement",
- "string audioClip",
- "string beamType",
- "string beamColor",
- "string damageType",
- "string explosionType"
- },
- ["PlayParticleEffect"] = new string[]
- {
- "Boolean",
- "ParticleEffectRequest",
- "MyParticleEffect effect",
- "Vector3D targetCoords"
- },
- ["ChangeBlockSharing"] = new string[]
- {
- "Boolean",
- "string shareMode", // "Faction", "All", default None
- "long entityId" // MyCubeBlock
- },
- ["ChangeFactionRequest"] = new string[]
- {
- "Boolean",
- "string factionTag"
- },
- ["ChangeOtherGridOwnership"] = new string[]
- {
- "Boolean",
- "string factionTag",
- "long entityId" // IMyCubeGrid
- },
- ["CreateItemInInventory"] = new string[]
- {
- "Boolean",
- "string type",
- "string subtype",
- "float amount",
- "long entityId" // IMyTerminalBlock
- },
- ["DespawnDrone"] = new string[]
- {
- "Boolean"
- },
- ["GetAmmoAndFillWeapon"] = new string[]
- {
- "Boolean",
- "long blockEntityId", // IMyUserControllableGun
- "int addUpToLimit",
- "string specificAmmoSubtype" // default "Any"
- },
- ["GridSetDestructable"] = new string[]
- {
- "Boolean",
- "bool setMode",
- "long entityId" // MyCubeGrid
- },
- ["GridSetEditable"] = new string[]
- {
- "Boolean",
- "bool setMode",
- "long entityId" // MyCubeGrid
- },
- ["GasTankRefill"] = new string[]
- {
- "Boolean"
- },
- ["IceRefill"] = new string[]
- {
- "Boolean"
- },
- ["InsertPlayerIntoShipMainCockpit"] = new string[]
- {
- "Boolean",
- "long characterId", // IMyCharacter
- "long shipId" // IMyCubeGrid
- },
- ["IsOwnedByNPC"] = new string[]
- {
- "Boolean"
- },
- ["ToggleBlocksContainingName"] = new string[]
- {
- "Boolean",
- "string blockNameSearch",
- "bool toggle",
- "long gridId" // IMyCubeGrid
- },
- ["UpdateProgramBlockScript"] = new string[]
- {
- "Boolean",
- "var newScript = programmableBlockScripts[sourceBlock.CustomData];"
- },
- ["SpawnReinforcements"] = new string[]
- {
- "Boolean",
- "string spawnType", // "Prefab", "SpawnGroup"
- "string spawnName",
- "string spawnFaction",
- "bool spawnAll",
- "Vector3D coords",
- "Vector3D forwardDir",
- "Vector3D upDir",
- "Vector3D velocity"
- },
- ["AltitudeDifferenceAtPosition"] = new string[]
- {
- "double",
- "Vector3D coords"
- },
- ["GetAllAllies"] = new string[]
- {
- "List<long>",
- "double distanceToCheck"
- },
- ["GetAllEnemies"] = new string[]
- {
- "List<long>",
- "string specificFaction", // default ""
- "double distanceToCheck"
- },
- ["GetDetectedEntityInfo"] = new string[]
- {
- "MyDetectedEntityInfo",
- "long entityId" // MyEntity
- },
- ["GetNearestAllied"] = new string[]
- {
- "long",
- "double distanceToCheck"
- },
- ["GetNearestEnemy"] = new string[]
- {
- "long",
- "string specificFaction", // default ""
- "double distanceToCheck"
- },
- ["GetNearestPlanetPosition"] = new string[]
- {
- "Vector3D",
- "Vector3D checkCoords"
- },
- ["GetTargetShipSystem"] = new string[]
- {
- "long",
- "long targetEntityId", // IMyCubeGrid
- "string systemTarget", // SlimBlock.BlockDefinition.Id.TypeId, "Clang", "Communications", "Controller", "Power", "Nuclear", "Production", "Propulsion", "Weapons"
- },
- ["IsHumanControllingTarget"] = new string[]
- {
- "Boolean",
- "long entityId" // Ignored?
- },
- ["IsPositionInNaturalGravity"] = new string[]
- {
- "Boolean",
- "Vector3D checkCoords"
- },
- ["IsOwnedByFaction"] = new string[]
- {
- "Boolean",
- "var factionTag"
- },
- ["TargetBlockCount"] = new string[]
- {
- "int",
- "long entityId" // IMyCubeGrid
- },
- ["TargetCanFly"] = new string[]
- {
- "Boolean",
- "long entityId" // MyCubeGrid
- },
- ["TargetIsBroadcasting"] = new string[]
- {
- "Boolean",
- "long entityId", // IMyCubeGrid
- "bool checkAntennas",
- "bool checkBeacons"
- },
- ["TargetIsStatic"] = new string[]
- {
- "Boolean",
- "long entityId" // MyCubeGrid
- },
- ["TargetPowered"] = new string[]
- {
- "Boolean",
- "long entityId" // MyCubeGrid
- },
- ["TrackEntity"] = new string[]
- {
- "Vector3D",
- "long entityId" // IMyCubeGrid
- },
- ["CorruptionDebugPB"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionDroneDespawn"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionDroneChat"] = new string[]
- {
- "Boolean",
- "string message"
- },
- ["CorruptionOwnerCheck"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionIceRefill"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionTeleport"] = new string[]
- {
- "Boolean",
- "Vector3D teleportPosition",
- "Vector3D targetPosition",
- "Vector3D targetVelocity"
- },
- ["CorruptionHacking"] = new string[]
- { // "CORRUPT" must exists
- "Boolean",
- "long gridEntityId", // IMyCubeGrid
- "string hackingType" // "HackBlock", "DisableProduction", "DisableDefense", "DisableAutomation", "HudSpam", "OverloadShields", "CorruptNames", "GyroOverride", "ThrustOverride", "HackLights"
- },
- ["CorruptionHackingTargets"] = new string[]
- {
- "List<long>"
- },
- ["CorruptionSpawning"] = new string[]
- { // "CORRUPT" must exists
- "Boolean",
- "string spawnGroupName",
- "Vector3D coords",
- "Vector3D velocity",
- "Vector3D forwardDir",
- "bool successfulSpawnMandatory"
- },
- ["CorruptionShieldMod"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionMeteorLaunch"] = new string[]
- {
- "Boolean",
- "Vector3D spawnCoords",
- "Vector3D launchDirection",
- "Vector3D inheritedVelocity"
- },
- ["CorruptionProjectorBuild"] = new string[]
- {
- "Boolean",
- "bool instantBuild",
- "int blocksToBuild"
- },
- ["CorruptionRepairBlocks"] = new string[]
- {
- "Boolean",
- "int blocksToBuild"
- },
- ["CorruptionInstantRotate"] = new string[]
- {
- "Boolean",
- "Vector3D targetCoords",
- "Vector3D upDir"
- },
- ["CorruptionNearestPlanet"] = new string[]
- {
- "Vector3D"
- },
- ["CorruptionGridHealth"] = new string[]
- {
- "float"
- },
- ["CorruptionSniperReload"] = new string[]
- { // Must have "Corruption Rocket Launcher Sniper" as IMyUserControllableGun
- // Must have "Medium Cargo Container" as IMyCargoContainer
- // Must have MyObjectBuilder_AmmoMagazine/Corruption-Missile200mm-Sniper
- "Boolean"
- },
- ["CorruptionTestLaser"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionLaserRequest"] = new string[]
- {
- "Boolean",
- "long entityId" // IMyCameraBlock
- },
- ["CorruptionSecondaryDrawLaser"] = new string[]
- {
- "Boolean",
- "Vector3D startCoords",
- "Vector3D endCoords"
- },
- ["CorruptionLaserDamage"] = new string[]
- {
- "Boolean",
- "Vector3D startCoords", // Ignored?
- "Vector3D endCoords",
- "long entityId" // IMyCubeGrid
- },
- ["CorruptionTeslaFire"] = new string[]
- {
- "Boolean",
- "long sourceEntity", // IMyEntity
- "long targetEntity" // IMyEntity
- },
- ["CorruptionInvincibility"] = new string[]
- {
- "Boolean",
- "bool status"
- },
- ["CorruptionBossSpawn"] = new string[]
- { // "CORRUPT" must exists
- "Boolean"
- },
- ["CorruptionBeamEffectRequest"] = new string[]
- {
- "Boolean",
- "long entityId" // IMyCameraBlock
- },
- ["CorruptionTrackEntity"] = new string[]
- {
- "Vector3D",
- "long targetEntityId" // IMyCubeGrid
- },
- ["CorruptionNearestPlayerThreat"] = new string[]
- {
- "long"
- },
- ["CorruptionNearestShieldDrone"] = new string[]
- { // Grid must be named "(NPC-CPC) Shield Coordinator Drone" and owned by "CORRUPT" within 15000
- "long"
- },
- ["CorruptionResetTerminalNames"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionClonePlayerShip"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionShieldRegister"] = new string[]
- {
- "Boolean"
- },
- ["CorruptionMissileCreation"] = new string[]
- { // Must have MyObjectBuilder_Warhead/CorruptSeekerMissile
- // Must have MyObjectBuilder_BatteryBlock/CorruptDummyBattery
- "Boolean",
- "long targetId", // IMyTerminalBlock
- "Vector3D spawnCoords",
- "Vector3D forwardDir"
- },
- };
- List<IMyProgrammableBlock> ProgramBlocks = new List<IMyProgrammableBlock>();
- IMyProgrammableBlock LastBlock = null, LastNPCBlock = null;
- public Program()
- {
- }
- public void Save()
- {
- }
- public void Main(string argument, UpdateType updateSource)
- {
- MyCommandLine commandLine = new MyCommandLine();
- if (commandLine.TryParse(argument))
- {
- if (commandLine.Switch("list"))
- {
- string results = "";
- for (int i = ProgramBlocks.Count - 1; i >= 0; i--)
- 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";
- Echo(results);
- IMyTextSurface surface = (Me as IMyTextSurfaceProvider).GetSurface(0);
- surface.WriteText(results);
- surface.ContentType = ContentType.TEXT_AND_IMAGE;
- return;
- }
- IMyProgrammableBlock npcblock = Me;
- if (commandLine.ArgumentCount > 1)
- {
- string arg = commandLine.Argument(1);
- npcblock = GridTerminalSystem.GetBlockWithName(arg) as IMyProgrammableBlock;
- if (!(npcblock is IMyProgrammableBlock))
- try
- {
- npcblock = GridTerminalSystem.GetBlockWithId(Convert.ToInt64(arg, 16)) as IMyProgrammableBlock;
- }
- catch {}
- if (!(npcblock is IMyProgrammableBlock))
- try
- {
- npcblock = GridTerminalSystem.GetBlockWithId(Convert.ToInt64(arg)) as IMyProgrammableBlock;
- }
- catch {}
- if (npcblock is IMyProgrammableBlock)
- {
- if (commandLine.Switch("last"))
- {
- LastBlock = npcblock;
- Echo("Set Last: " + LastBlock.ToString());
- }
- if (!ProgramBlocks.Contains(npcblock))
- ProgramBlocks.Add(npcblock);
- }
- else if (commandLine.Switch("last"))
- {
- int i;
- if (commandLine.Switch("last", 0) != null && int.TryParse(commandLine.Switch("last", 0), out i) && i < ProgramBlocks.Count)
- npcblock = ProgramBlocks[i];
- }
- }
- else if (commandLine.Switch("last") && LastBlock is IMyProgrammableBlock)
- npcblock = LastBlock;
- if (commandLine.Switch("backup") && LastNPCBlock is IMyProgrammableBlock)
- npcblock = LastNPCBlock;
- argument = commandLine.Argument(0);
- IMyTerminalBlock block = GridTerminalSystem.GetBlockWithName(argument);
- if (!(block is IMyTerminalBlock) && argument == "Me")
- block = Me;
- if (block is IMyTerminalBlock)
- {
- StringBuilder results = new StringBuilder();
- string[] data = block.CustomData.Split('\n');
- for (int i = 0; i < data.Length; i++)
- {
- string command = data[i].Trim();
- if (command.Length == 0)
- continue;
- string type = "";
- int numparams = 0;
- string[] param = command.Split(':');
- if (param.Length > 1)
- {
- command = param[0];
- type = param[1];
- }
- if (CommandList.ContainsKey(command))
- {
- param = CommandList[command];
- type = param[0];
- numparams = param.Length - 1;
- }
- else
- {
- List<string> search = CommandList.Keys.Where(c => c.StartsWith(command, StringComparison.InvariantCultureIgnoreCase)).ToList();
- if (search.Count == 0)
- search = CommandList.Keys.Where(c => c.IndexOf(command, StringComparison.InvariantCultureIgnoreCase) >= 0).ToList();
- if (search.Count == 1)
- {
- command = search[0];
- param = CommandList[command];
- type = param[0];
- numparams = param.Length - 1;
- data[i] = command;
- }
- else
- {
- results.Append("Unknown ");
- numparams = data.Length - 1 - i;
- }
- }
- if (numparams + i >= data.Length)
- numparams = data.Length - 1 - i;
- if (numparams > 0)
- {
- List<int> argpos = null;
- switch (command)
- {
- case "CreateExplosionAtPosition":
- case "AltitudeDifferenceAtPosition":
- case "GetNearestPlanetPosition":
- case "IsPositionInNaturalGravity":
- case "CorruptionMeteorLaunch":
- case "CorruptionInstantRotate":
- argpos = new List<int>() {1};
- break;
- case "CorruptionSpawning":
- case "CorruptionMissileCreation":
- argpos = new List<int>() {2};
- break;
- case "PlayParticleEffect":
- argpos = new List<int>() {3};
- break;
- case "SpawnReinforcements":
- argpos = new List<int>() {5};
- break;
- case "CorruptionTeleport":
- case "CorruptionSecondaryDrawLaser":
- case "CorruptionLaserDamage":
- argpos = new List<int>() {1, 2};
- break;
- }
- if (argpos != null)
- {
- for (int j = 0; j < argpos.Count; j++)
- {
- Vector3D vector;
- if (numparams >= argpos[j] && !Vector3D.TryParse(data[i + argpos[j]], out vector))
- {
- if (data[i + argpos[j]].StartsWith("GPS:"))
- {
- Vector3D coords = ParseGPS(data[i + argpos[j]]);
- if (coords != Vector3D.Zero)
- data[i + argpos[j]] = coords.ToString();
- }
- else if (data[i + argpos[j]] == "Me")
- {
- data[i + argpos[j]] = Me.GetPosition().ToString();
- }
- else
- {
- IMyTerminalBlock b = GridTerminalSystem.GetBlockWithName(data[i + argpos[j]]);
- if (b is IMyTerminalBlock)
- data[i + argpos[j]] = b.GetPosition().ToString();
- else
- data[i + argpos[j]] = Vector3D.Zero.ToString();
- }
- }
- }
- }
- long id;
- int cubegrid = 0;
- bool multigrid = false;
- int cubeblock = 0;
- List<IMyCubeBlock> blocklist = null;
- switch (command)
- {
- case "CutVoxelsFromProjection":
- cubeblock = 1;
- if (numparams >= cubeblock)
- blocklist = GetEntityId<IMyProjector>(ref data[i + cubeblock]);
- break;
- case "ChangeBlockSharing":
- cubeblock = 2;
- if (numparams >= cubeblock)
- {
- blocklist = GetEntityId<IMyCubeBlock>(ref data[i + cubeblock]);
- if (blocklist != null)
- blocklist = blocklist.Where(b => b.OwnerId == npcblock.OwnerId).ToList();
- }
- break;
- case "CreateItemInInventory":
- if (numparams >= 4)
- {
- IMyInventory inventory = null;
- if (!long.TryParse(data[i + 4], out id))
- {
- IMyTerminalBlock b = GridTerminalSystem.GetBlockWithName(data[i + 4]);
- if (b is IMyTerminalBlock)
- {
- data[i + 4] = b.EntityId.ToString();
- if (b.InventoryCount > 0)
- inventory = b.GetInventory(0);
- }
- else
- try
- {
- id = Convert.ToInt64(data[i + 4], 16);
- data[i + 4] = id.ToString();
- }
- catch {}
- }
- if (inventory == null && id != 0)
- {
- IMyTerminalBlock b = GridTerminalSystem.GetBlockWithId(id);
- if (b is IMyTerminalBlock && b.InventoryCount > 0)
- inventory = b.GetInventory(0);
- }
- if (data[i + 1] == "BARS")
- {
- IMyTerminalBlock b = GridTerminalSystem.GetBlockWithName(data[i + 2]);
- if (b is IMyShipWelder && b.BlockDefinition.SubtypeId.Contains("NanobotBuildAndRepairSystem"))
- {
- Dictionary<MyDefinitionId, int> components;
- try
- {
- components = b.GetValue<Dictionary<MyDefinitionId, int>>("BuildAndRepair.MissingComponents");
- int count = 0;
- List<string> complist = new List<string>();
- foreach (var component in components)
- {
- count++;
- if (count == 1)
- {
- data[i + 1] = component.Key.TypeId.ToString();
- data[i + 2] = component.Key.SubtypeId.ToString();
- data[i + 3] = component.Value.ToString();
- }
- else
- {
- complist.Add(command);
- complist.Add(component.Key.TypeId.ToString());
- complist.Add(component.Key.SubtypeId.ToString());
- complist.Add(component.Value.ToString());
- complist.Add(data[i + 4]);
- }
- }
- if (complist.Count > 0)
- data = data.ToList().Concat(complist).ToArray();
- }
- catch {}
- }
- }
- else if (data[i + 1] == "WELDER" && inventory != null)
- {
- List<MyItemType> typelist = new List<MyItemType>();
- inventory.GetAcceptedItems(typelist, t => t.TypeId == "MyObjectBuilder_Component");
- double volume;
- double.TryParse(data[i + 3], out volume);
- volume /= 1000;
- int count = 0;
- List<string> complist = new List<string>();
- foreach (var itemtype in typelist)
- {
- MyItemInfo info = itemtype.GetItemInfo();
- double amount = Math.Max(1, Math.Ceiling(volume / info.Volume)) - (double) inventory.GetItemAmount(itemtype);
- if (amount > 0)
- {
- count++;
- if (count == 1)
- {
- data[i + 1] = itemtype.TypeId;
- data[i + 2] = itemtype.SubtypeId;
- data[i + 3] = amount.ToString();
- }
- else
- {
- complist.Add(command);
- complist.Add(itemtype.TypeId);
- complist.Add(itemtype.SubtypeId);
- complist.Add(amount.ToString());
- complist.Add(data[i + 4]);
- }
- }
- }
- if (complist.Count > 0)
- data = data.ToList().Concat(complist).ToArray();
- }
- else if (data[i + 1] == "" && inventory != null)
- {
- List<MyItemType> typelist = new List<MyItemType>();
- inventory.GetAcceptedItems(typelist);
- for (int j = typelist.Count - 1; j >= 0; j--)
- {
- if (typelist[j].SubtypeId.Equals(data[i + 2], StringComparison.OrdinalIgnoreCase))
- {
- data[i + 1] = typelist[j].TypeId;
- data[i + 2] = typelist[j].SubtypeId;
- break;
- }
- }
- }
- else if (!data[i + 1].StartsWith("MyObjectBuilder_"))
- data[i + 1] = "MyObjectBuilder_" + data[i + 1];
- if (inventory != null)
- {
- MyDefinitionId def = new MyDefinitionId();
- if (MyDefinitionId.TryParse(data[i + 1], data[i + 2], out def) && inventory.CanItemsBeAdded(-1, def))
- {
- double amount;
- if (double.TryParse(data[i + 3], out amount) && amount > 0)
- {
- MyItemInfo info = ((MyItemType) def).GetItemInfo();
- double avail = ((double) inventory.MaxVolume - Math.Max(0, (double) inventory.CurrentVolume)) / info.Volume;
- if (!info.UsesFractions)
- avail = Math.Floor(avail);
- if (amount > avail && avail > 0)
- {
- data[i + 3] = avail.ToString();
- data = data.ToList().Concat(new string[] {command, data[i + 1], data[i + 2], (amount - avail).ToString(), data[i + 4]}).ToArray();
- }
- }
- }
- }
- }
- break;
- case "GetAmmoAndFillWeapon":
- cubeblock = 1;
- if (numparams >= cubeblock)
- blocklist = GetEntityId<IMyUserControllableGun>(ref data[i + cubeblock]);
- break;
- case "CorruptionLaserRequest":
- case "CorruptionBeamEffectRequest":
- cubeblock = 1;
- if (numparams >= cubeblock)
- blocklist = GetEntityId<IMyCameraBlock>(ref data[i + cubeblock]);
- break;
- case "CorruptionLaserDamage":
- cubeblock = 3;
- if (numparams >= cubeblock)
- blocklist = GetEntityId<IMyCubeBlock>(ref data[i + cubeblock]);
- break;
- case "GetTargetShipSystem":
- case "TargetBlockCount":
- case "TargetCanFly":
- case "TargetIsBroadcasting":
- case "TargetIsStatic":
- case "TargetPowered":
- case "TrackEntity":
- cubegrid = 1;
- break;
- case "ChangeOtherGridOwnership":
- case "InsertPlayerIntoShipMainCockpit":
- cubegrid = 2;
- break;
- case "GridSetDestructable":
- case "GridSetEditable":
- cubegrid = 2;
- multigrid = true;
- break;
- case "ToggleBlocksContainingName":
- cubegrid = 3;
- break;
- }
- if (cubeblock > 0 && blocklist != null)
- {
- List<string> ids = new List<string>();
- for (int j = 0; j < blocklist.Count; j++)
- {
- ids.Add(command);
- for (int k = 1; k <= numparams; k++)
- ids.Add(k == cubeblock ? blocklist[j].EntityId.ToString() : data[i + k]);
- }
- if (ids.Count > 0)
- {
- data[i + cubeblock] = ids[cubeblock];
- ids.RemoveRange(0, numparams + 1);
- }
- if (ids.Count > 0)
- data = data.ToList().Concat(ids).ToArray();
- }
- if (cubegrid > 0 && numparams >= cubegrid && !long.TryParse(data[i + cubegrid], out id))
- {
- if (data[i + cubegrid] == "Me")
- data[i + cubegrid] = Me.CubeGrid.EntityId.ToString();
- else
- {
- IMyCubeBlock b = GridTerminalSystem.GetBlockWithName(data[i + cubegrid]);
- if (b is IMyCubeBlock)
- data[i + cubegrid] = b.CubeGrid.EntityId.ToString();
- else
- {
- if (multigrid && (data[i + cubegrid] == "ALL" || data[i + cubegrid] == "OTHER"))
- {
- List<IMyCubeBlock> blocks = new List<IMyCubeBlock>();
- if (data[i + cubegrid] == "OTHER")
- GridTerminalSystem.GetBlocksOfType(blocks, c => c.CubeGrid != Me.CubeGrid);
- else
- GridTerminalSystem.GetBlocksOfType(blocks);
- 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();
- if (grids.Length > 0)
- {
- data[i + cubegrid] = grids[0].ToString();
- if (grids.Length > 1)
- {
- List<string> ids = new List<string>();
- for (int j = 1; j < grids.Length; j++)
- {
- ids.Add(command);
- for (int k = 1; k <= numparams; k++)
- ids.Add(k == cubegrid ? grids[j].ToString() : data[i + k]);
- }
- data = data.ToList().Concat(ids).ToArray();
- }
- }
- }
- else
- {
- try
- {
- id = Convert.ToInt64(data[i + cubegrid], 16);
- b = GridTerminalSystem.GetBlockWithId(id);
- if (b is IMyCubeBlock)
- data[i + cubegrid] = b.CubeGrid.EntityId.ToString();
- else
- data[i + cubegrid] = id.ToString();
- }
- catch {}
- }
- }
- }
- }
- }
- npcblock.CustomData = numparams > 0 ? String.Join("\n", data, i + 1, numparams) : "";
- results.AppendLine("Command: " + command + " (" + type + ")");
- if (!command.StartsWith("Corruption"))
- command = "NpcExtender-" + command;
- Object result = new Object();
- try
- {
- switch (type)
- {
- default:
- case "bool":
- case "Boolean":
- result = npcblock.GetValueBool(command);
- if ((bool) result == true)
- LastNPCBlock = npcblock;
- break;
- case "Color":
- result = npcblock.GetValueColor(command);
- break;
- case "float":
- case "Single":
- result = npcblock.GetValueFloat(command);
- break;
- case "long":
- result = npcblock.GetValue<long>(command);
- break;
- case "int":
- result = npcblock.GetValue<int>(command);
- break;
- case "Int64":
- result = npcblock.GetValue<Int64>(command);
- break;
- case "double":
- result = npcblock.GetValue<double>(command);
- break;
- case "Vector3D":
- result = npcblock.GetValue<Vector3D>(command);
- break;
- case "List<long>":
- result = npcblock.GetValue<List<long>>(command);
- break;
- case "MyDetectedEntityInfo":
- result = npcblock.GetValue<MyDetectedEntityInfo>(command);
- break;
- }
- }
- catch
- {
- result = "GetValue error";
- }
- if (result is MyDetectedEntityInfo)
- result = ShowEntity((MyDetectedEntityInfo) result);
- else if (result is IList)
- {
- switch (command)
- {
- case "NpcExtender-GetAllAllies":
- case "NpcExtender-GetAllEnemies":
- foreach (Object o in result as IList)
- if ((long) o != 0)
- data = data.ToList().Concat(new string[] {"TrackEntity", o.ToString(), "GetDetectedEntityInfo", o.ToString()}).ToArray();
- break;
- }
- string str = "List: " + (result as IList).Count.ToString();
- foreach (Object o in result as IList)
- str += "\n" + o.ToString();
- result = str;
- }
- else if (result is Vector3D)
- {
- result += "\n " + ToGPS(command + " " + (Vector3D.Distance(Me.GetPosition(), (Vector3D) result) / 1000).ToString("0.###") + "km", (Vector3D) result);
- }
- else if (result is long)
- {
- switch (command)
- {
- case "NpcExtender-GetNearestAllied":
- case "NpcExtender-GetNearestEnemy":
- case "CorruptionNearestPlayerThreat":
- if ((long) result != 0)
- data = data.ToList().Concat(new string[] {"TrackEntity", result.ToString(), "GetDetectedEntityInfo", result.ToString()}).ToArray();
- break;
- }
- }
- results.AppendLine(result.ToString());
- i += numparams;
- }
- npcblock.CustomData = String.Join("\n", data);
- Echo(results.ToString());
- IMyTextSurface surface;
- if (block is IMyTextSurface)
- surface = block as IMyTextSurface;
- else if (block is IMyTextSurfaceProvider)
- surface = (block as IMyTextSurfaceProvider).GetSurface(0);
- else
- surface = (Me as IMyTextSurfaceProvider).GetSurface(0);
- if (surface is IMyTextSurface)
- {
- surface.WriteText(results.ToString());
- surface.ContentType = ContentType.TEXT_AND_IMAGE;
- }
- }
- }
- }
- public Vector3D ParseGPS(string strGPS)
- {
- string[] listGPS = strGPS.Split(':');
- double x, y, z;
- if (listGPS.Length > 4 && double.TryParse(listGPS[2], out x) && double.TryParse(listGPS[3], out y) && double.TryParse(listGPS[4], out z))
- return new Vector3D(x, y, z);
- else
- return Vector3D.Zero;
- }
- public string ToGPS(string name, Vector3D gps)
- {
- return "GPS:" + name.Replace(":", "_") + gps.ToString("0.###").Replace("{", "").Replace("}","").Replace("X", "").Replace("Y", "").Replace("Z", "").Replace(" ", "") + ":";
- }
- public List<IMyCubeBlock> GetEntityId<T>(ref string Data) where T : class, IMyCubeBlock
- {
- long EntityId;
- if (!long.TryParse(Data, out EntityId))
- {
- IMyCubeBlock block = Data == "Me" ? Me : GridTerminalSystem.GetBlockWithName(Data);
- if (block is IMyCubeBlock)
- {
- EntityId = block.EntityId;
- Data = EntityId.ToString();
- return null;
- }
- else
- {
- try
- {
- EntityId = Convert.ToInt64(Data, 16);
- Data = EntityId.ToString();
- return null;
- }
- catch {}
- List<T> list = new List<T>();
- switch (Data)
- {
- case "ALL":
- GridTerminalSystem.GetBlocksOfType(list);
- break;
- case "ALL_SELF":
- GridTerminalSystem.GetBlocksOfType(list, b => b.CubeGrid == Me.CubeGrid);
- break;
- case "ALL_OTHER":
- GridTerminalSystem.GetBlocksOfType(list, b => b.CubeGrid != Me.CubeGrid);
- break;
- }
- if (list.Count > 0)
- return list.Cast<IMyCubeBlock>().ToList();
- else
- return null;
- }
- }
- return null;
- }
- public string ShowEntity(MyDetectedEntityInfo entity = new MyDetectedEntityInfo())
- {
- StringBuilder result = new StringBuilder();
- if (entity.IsEmpty())
- return "";
- if (entity.EntityId != 0)
- {
- if (entity.HitPosition.HasValue)
- result.AppendLine("Found At: " + Vector3D.Distance(Me.GetPosition(), entity.HitPosition.Value).ToString("0.00") + " m");
- String size = entity.BoundingBox.Size.ToString("0.000");
- String printSize = "";
- double volume = 1;
- String unitName = "m3";
- if (size != null || size != "")
- {
- size = size.Replace("{", "").Replace("}", "").Replace("X", "").Replace("Y", "").Replace("Z", "").Replace(" ", "");
- size = size.Trim();
- String[] sizes = size.Split(':');
- double factor = 1;
- if (entity.Type.ToString() == "SmallGrid")
- {
- factor = 4;
- unitName = "blocks";
- }
- else if (entity.Type.ToString() == "LargeGrid")
- {
- factor = 16;
- unitName = "blocks";
- }
- foreach (String measure in sizes)
- {
- if (measure == "")
- {
- // first value
- continue;
- }
- volume = volume * Math.Round(Convert.ToDouble(measure), 0);
- printSize += (Convert.ToDouble(measure)).ToString("0.00") + " X ";
- }
- volume = volume / factor;
- }
- printSize = printSize.Remove(printSize.Length - 2);
- printSize += "m";
- result.AppendLine("Entity ID: " + entity.EntityId);
- result.AppendLine("Name: " + entity.Name);
- result.AppendLine("Type: " + entity.Type);
- result.AppendLine("Velocity: " + entity.Velocity.ToString("0.000"));
- result.AppendLine("Relationship: " + entity.Relationship);
- result.AppendLine("Size: " + printSize);
- result.AppendLine("Estimated Volume: " + volume +" "+ unitName);
- result.AppendLine("Position: " + entity.Position.ToString("0.000"));
- result.AppendLine("Distance: " + Vector3D.Distance(entity.Position, Me.GetPosition()).ToString("0.000") + " m");
- result.AppendLine("GPS:" + entity.Name + entity.Position.ToString("0.000").Replace("{", "").Replace("}","").Replace("X", "").Replace("Y", "").Replace("Z", "").Replace(" ", "") + ":");
- if (entity.HitPosition.HasValue)
- result.AppendLine("Hit Position: " + entity.HitPosition.Value.ToString("0.000"));
- result.AppendLine("Relationship: " + entity.Relationship.ToString());
- }
- return result.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement