protected override void execute(CSteamID executorID, string parameter) { FreneticScript.CommandSystem.CommandQueue queue = ExecScript.ToQueue(UnturnedFreneticMod.Instance.CommandSystem.System); MapTag map = new MapTag(); if (executorID == CSteamID.Nil) { map.Internal["is_server"] = new BooleanTag(true); } else { map.Internal["player"] = new PlayerTag(PlayerTool.getSteamPlayer(executorID)); map.Internal["is_server"] = new BooleanTag(false); } map.Internal["raw_arguments"] = new TextTag(parameter); queue.SetVariable("context", map); queue.CommandStack.Peek().Debug = DebugMode.MINIMAL; // Just in case queue.Execute(); }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { try { TemplateObject spawned = null; LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1)); if (loc == null) { queue.HandleError(entry, "Invalid location!"); return; } string targetAssetType = entry.GetArgument(queue, 0).ToLowerFast(); EntityType etype = EntityType.ValueOf(targetAssetType); if (etype == null) { queue.HandleError(entry, "Invalid entity type!"); return; } if (etype.Type == EntityAssetType.ZOMBIE) { Vector3 vec3 = loc.ToVector3(); byte reg = 0; // TODO: Optionally specifiable float closest = float.MaxValue; for (int r = 0; r < LevelZombies.zombies.Length; r++) { for (int i = 0; i < LevelZombies.zombies[r].Count; i++) { float dist = (LevelZombies.zombies[r][i].point - vec3).sqrMagnitude; if (dist < closest) { closest = dist; reg = (byte)r; } } } ZombieManager.manager.addZombie(reg, 0, 0, 0, 0, 0, 0, 0, 0, vec3, 0, false); Zombie zombie = ZombieManager.regions[reg].zombies[ZombieManager.regions[reg].zombies.Count - 1]; // TODO: Make this actually work! (See complaints file!) /* * foreach (SteamPlayer player in PlayerTool.getSteamPlayers()) * { * ZombieManager.manager.channel.openWrite(); * ZombieManager.manager.channel.write(reg); * ZombieManager.manager.channel.write((ushort)1); * ZombieManager.manager.channel.write(new object[] * { * zombie.type, * (byte)zombie.speciality, * zombie.shirt, * zombie.pants, * zombie.hat, * zombie.gear, * zombie.move, * zombie.idle, * zombie.transform.position, * MeasurementTool.angleToByte(zombie.transform.rotation.eulerAngles.y), * zombie.isDead * }); * ZombieManager.manager.channel.closeWrite("tellZombies", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); * } */ if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a zombie at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)"); } spawned = new ZombieTag(zombie); } else if (etype.Type == EntityAssetType.ANIMAL) { AnimalAssetTag asset = AnimalAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid animal type!"); return; } // TODO: Make this bit optional! RaycastHit rch; while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5)) { loc.Y += 3; } // END TODO AnimalManager.manager.addAnimal(asset.Internal.id, loc.ToVector3(), 0, false); Animal animal = AnimalManager.animals[AnimalManager.animals.Count - 1]; foreach (SteamPlayer player in PlayerTool.getSteamPlayers()) { AnimalManager.manager.channel.openWrite(); AnimalManager.manager.channel.write((ushort)1); AnimalManager.manager.channel.write(new object[] { animal.id, animal.transform.position, MeasurementTool.angleToByte(animal.transform.rotation.eulerAngles.y), animal.isDead }); AnimalManager.manager.channel.closeWrite("tellAnimals", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); } if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (" + animal.gameObject.GetInstanceID() + ")"); } spawned = new AnimalTag(animal); } else if (etype.Type == EntityAssetType.VEHICLE) { VehicleAssetTag asset = VehicleAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid vehicle type!"); return; } // TODO: Make this bit optional! RaycastHit rch; while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5)) { loc.Y += 3; } // END TODO VehicleManager.spawnVehicle(asset.Internal.id, loc.ToVector3(), Quaternion.identity); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the vehicle entity! } else if (etype.Type == EntityAssetType.WORLD_OBJECT) { WorldObjectAssetTag asset = WorldObjectAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid world object type!"); return; } LevelObjects.addObject(loc.ToVector3(), Quaternion.identity, Vector3.one, asset.Internal.id, asset.Internal.name, asset.Internal.GUID, ELevelObjectPlacementOrigin.MANUAL); // TODO: Network! entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)"); // TODO: Get the world entity! } else if (etype.Type == EntityAssetType.ITEM) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType); if (asset == null) { queue.HandleError(entry, "Invalid item type!"); return; } byte x; byte y; if (Regions.tryGetCoordinate(loc.ToVector3(), out x, out y)) { Item item = new Item(asset.Internal.id, 1, asset.Internal.quality); ItemData data = new ItemData(item, ++ItemManager.instanceCount, loc.ToVector3(), Dedicator.isDedicated); ItemManager.regions[x, y].items.Add(data); ItemModelTracker.Track(data, loc.ToVector3()); ItemManager.manager.channel.send("tellItem", ESteamCall.CLIENTS, x, y, ItemManager.ITEM_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { x, y, item.id, item.amount, item.quality, item.state, loc.ToVector3() }); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the item entity! } else { queue.HandleError(entry, "Trying to spawn item outside any valid item regions!"); } } else if (etype.Type == EntityAssetType.BARRICADE) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("barricade_".Length)); if (asset == null || !(asset.Internal is ItemBarricadeAsset)) { queue.HandleError(entry, "Invalid item barricade type!"); return; } Barricade barric = new Barricade(asset.Internal.id); BarricadeManager.dropBarricade(barric, null, loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the game object! } else if (etype.Type == EntityAssetType.STRUCTURE) { ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("structure_".Length)); if (asset == null || !(asset.Internal is ItemStructureAsset)) { queue.HandleError(entry, "Invalid item structure type!"); return; } StructureManager.dropStructure(new Structure(asset.Internal.id), loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!"); } // TODO: Get the game object! } else { queue.HandleError(entry, "Invalid or unspawnable entity type!"); return; } if (spawned != null) { queue.SetVariable("spawned", spawned); } } catch (Exception ex) // TODO: Necessity? { queue.HandleError(entry, "Failed to spawn entity: " + ex.ToString()); } }