| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Threading;
|
|---|
| 4 | using UnityEngine;
|
|---|
| 5 |
|
|---|
| 6 | namespace CoppisAdditions.CustomCommands
|
|---|
| 7 | {
|
|---|
| 8 | public class SpawnMultipleEntity : ConsoleCmdAbstract
|
|---|
| 9 | {
|
|---|
| 10 | public override string GetDescription ()
|
|---|
| 11 | {
|
|---|
| 12 | return "spawn multiple entities around some coordinate or player";
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | public override string GetHelp ()
|
|---|
| 16 | {
|
|---|
| 17 | return "Spawn multiple entities around some coordinate. Type \"sme\" to see all entity types\n" +
|
|---|
| 18 | "Usage:\n" +
|
|---|
| 19 | " sme <x> <y> <z> <spawn radius> @ [<list of entities>]\n" +
|
|---|
| 20 | "or\n" +
|
|---|
| 21 | " sme <x> <z> <spawn radius> @ [<list of entities>]>\n" +
|
|---|
| 22 | "or\n" +
|
|---|
| 23 | " sme <steam id/player name/entity id> <spawn radius> @ [<list of entities>]\n" +
|
|---|
| 24 | "Example\n" +
|
|---|
| 25 | " sme -1520 860 15 @ 1 1 18 18 21 21 21\n";
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | public override string[] GetCommands ()
|
|---|
| 29 | {
|
|---|
| 30 | return new string[] { "spawnmultipleentity", "sme" };
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | private void PrintEntities ()
|
|---|
| 34 | {
|
|---|
| 35 | SdtdConsole.Instance.Output ("The entities need to be in the list bellow:");
|
|---|
| 36 | Dictionary<int, EntityClass>.KeyCollection entityTypesCollectionPrint = EntityClass.list.Keys;
|
|---|
| 37 | int interationVal = 1;
|
|---|
| 38 | foreach (int i in entityTypesCollectionPrint) {
|
|---|
| 39 | EntityClass eClass = EntityClass.list [i];
|
|---|
| 40 | if (!eClass.bAllowUserInstantiate) {
|
|---|
| 41 | continue;
|
|---|
| 42 | }
|
|---|
| 43 | SdtdConsole.Instance.Output (" " + interationVal + " - " + eClass.entityClassName);
|
|---|
| 44 | ;
|
|---|
| 45 | interationVal++;
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
|
|---|
| 51 | {
|
|---|
| 52 | try {
|
|---|
| 53 | if (_params.Count < 2) {
|
|---|
| 54 | SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3 or more, found " + _params.Count + ".");
|
|---|
| 55 | SdtdConsole.Instance.Output (" ");
|
|---|
| 56 | SdtdConsole.Instance.Output (GetHelp ());
|
|---|
| 57 | PrintEntities ();
|
|---|
| 58 | return;
|
|---|
| 59 | }
|
|---|
| 60 | int paramType = 0;
|
|---|
| 61 | for (int n = 0; n < _params.Count; n++) {
|
|---|
| 62 | if (_params [n] == "@") {
|
|---|
| 63 | if (n == 2 || n == 3 || n == 4) {
|
|---|
| 64 | paramType = n;
|
|---|
| 65 | break;
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | if (paramType == 0) {
|
|---|
| 70 | SdtdConsole.Instance.Output ("Wrong pattern of arguments.");
|
|---|
| 71 | SdtdConsole.Instance.Output (" ");
|
|---|
| 72 | SdtdConsole.Instance.Output (GetHelp ());
|
|---|
| 73 | PrintEntities ();
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | int x = int.MinValue;
|
|---|
| 78 | int y = int.MinValue;
|
|---|
| 79 | int z = int.MinValue;
|
|---|
| 80 | int radius = int.MinValue;
|
|---|
| 81 |
|
|---|
| 82 | if (paramType == 2) {
|
|---|
| 83 | ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
|---|
| 84 | if (ci1 == null) {
|
|---|
| 85 | SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
|
|---|
| 86 | return;
|
|---|
| 87 | }
|
|---|
| 88 | EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
|
|---|
| 89 | Vector3 pos = ep1.GetPosition ();
|
|---|
| 90 | x = (int)pos.x;
|
|---|
| 91 | y = (int)pos.y;
|
|---|
| 92 | z = (int)pos.z;
|
|---|
| 93 | } else if (paramType == 3 || paramType == 4) {
|
|---|
| 94 | int.TryParse (_params [0], out x);
|
|---|
| 95 | if (paramType == 3) {
|
|---|
| 96 | y = 150;
|
|---|
| 97 | int.TryParse (_params [1], out z);
|
|---|
| 98 | } else if (paramType == 4) {
|
|---|
| 99 | int.TryParse (_params [1], out y);
|
|---|
| 100 | int.TryParse (_params [2], out z);
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
|
|---|
| 104 | SdtdConsole.Instance.Output ("x:" + x);
|
|---|
| 105 | SdtdConsole.Instance.Output ("y:" + y);
|
|---|
| 106 | SdtdConsole.Instance.Output ("z:" + z);
|
|---|
| 107 | SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
|
|---|
| 108 | return;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | int.TryParse (_params [(paramType - 1)], out radius);
|
|---|
| 112 | if (radius < 0) {
|
|---|
| 113 | SdtdConsole.Instance.Output ("radius is not a valid integer. It must be an integer greater than 0.");
|
|---|
| 114 | return;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | Dictionary<int, EntityClass>.KeyCollection entityTypesCollection = EntityClass.list.Keys;
|
|---|
| 118 | for (int n = (paramType + 1); n < _params.Count; n++) {
|
|---|
| 119 | int type = 0;
|
|---|
| 120 | int.TryParse (_params [n], out type);
|
|---|
| 121 |
|
|---|
| 122 | int interationNum = 1;
|
|---|
| 123 | bool result = false;
|
|---|
| 124 |
|
|---|
| 125 | foreach (int i in entityTypesCollection) {
|
|---|
| 126 | EntityClass eClass = EntityClass.list [i];
|
|---|
| 127 | if (!eClass.bAllowUserInstantiate) {
|
|---|
| 128 | continue;
|
|---|
| 129 | }
|
|---|
| 130 | if (interationNum == type) {
|
|---|
| 131 | int realX, realY, realZ;
|
|---|
| 132 | bool posFound = GameManager.Instance.World.FindRandomSpawnPointNearPosition (new Vector3 ((float)x, (float)y, (float)z), 15, out realX, out realY, out realZ, new Vector3 ((float)radius, (float)radius, (float)radius), true);
|
|---|
| 133 | if (!posFound) {
|
|---|
| 134 | posFound = GameManager.Instance.World.FindRandomSpawnPointNearPosition (new Vector3 ((float)x, (float)y, (float)z), 15, out realX, out realY, out realZ, new Vector3 ((float)radius, (float)150, (float)radius), true);
|
|---|
| 135 | }
|
|---|
| 136 | if (posFound) {
|
|---|
| 137 | Entity entity = EntityFactory.CreateEntity (i, new Vector3 ((float)realX, (float)realY, (float)realZ));
|
|---|
| 138 | GameManager.Instance.World.SpawnEntityInWorld (entity);
|
|---|
| 139 | result = true;
|
|---|
| 140 | SdtdConsole.Instance.Output ("Spawned " + eClass.entityClassName + " at " + realX + " " + realY + " " + realZ);
|
|---|
| 141 | } else {
|
|---|
| 142 | SdtdConsole.Instance.Output ("No spawn point found near coordinate " + x + " " + y + " " + z);
|
|---|
| 143 | result = true;
|
|---|
| 144 | }
|
|---|
| 145 | break;
|
|---|
| 146 | }
|
|---|
| 147 | interationNum++;
|
|---|
| 148 | }
|
|---|
| 149 | if (!result) {
|
|---|
| 150 | SdtdConsole.Instance.Output ("Ignoring the invalid entity [" + type + "]");
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 | } catch (Exception e) {
|
|---|
| 154 | Log.Out ("Error in SpawnMultipleEntity: " + e);
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|