public static void SpawnPrefab(string objectGuid, ChildGuid[] children, TechType tech, Vector3 position, Quaternion rotation) { if (tech == TechType.None) { return; } if (tech == TechType.Cyclops) { SpawnSub(objectGuid, children, position, rotation); return; } var prefab = CraftData.GetPrefabForTechType(tech); if (prefab == null) { return; } var gameObject = UnityEngine.Object.Instantiate <GameObject>(prefab, position, rotation); gameObject.SetActive(true); GuidHelper.Set(gameObject, objectGuid); GuidHelper.SetChildGuids(gameObject, children); LargeWorldEntity.Register(gameObject); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, tech); SyncedObject.ApplyTo(gameObject); }
public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent) { TechType techType = entity.TechType.Enum(); GameObject prefab; if (!PrefabDatabase.TryGetPrefab(entity.ClassId, out prefab)) { prefab = CraftData.GetPrefabForTechType(techType, false); if (prefab == null) { return(Optional <GameObject> .Of(Utils.CreateGenericLoot(techType))); } } GameObject gameObject = Utils.SpawnFromPrefab(prefab, null); gameObject.transform.position = entity.Position; gameObject.transform.localScale = entity.Scale; if (parent.IsPresent()) { gameObject.transform.SetParent(parent.Get().transform, true); } gameObject.transform.localRotation = entity.Rotation; GuidHelper.SetNewGuid(gameObject, entity.Guid); gameObject.SetActive(true); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, techType); return(Optional <GameObject> .Of(gameObject)); }
public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(entity.TechType, false); if (prefabForTechType == null && !PrefabDatabase.TryGetPrefab(entity.ClassId, out prefabForTechType)) { return(Optional <GameObject> .Of(Utils.CreateGenericLoot(entity.TechType))); } GameObject gameObject = Utils.SpawnFromPrefab(prefabForTechType, null); gameObject.transform.position = entity.Position; gameObject.transform.localScale = entity.Scale; if (parent.IsPresent()) { gameObject.transform.SetParent(parent.Get().transform, true); } gameObject.transform.localRotation = entity.Rotation; GuidHelper.SetNewGuid(gameObject, entity.Guid); gameObject.SetActive(true); // Makes movable objects movable... we can probably do this before the server sends the spawner packet? if (gameObject.GetComponent <Rigidbody>() == null) { gameObject.AddComponent <Rigidbody>(); } LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, entity.TechType); return(Optional <GameObject> .Of(gameObject)); }
private void OnVehiclePrefabLoaded(GameObject prefab, string guid, Optional <string> modulesEquipmentGuid, Vector3 spawnPosition, Quaternion spawnRotation, List <InteractiveChildObjectIdentifier> interactiveChildIdentifiers) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; GuidHelper.SetNewGuid(gameObject, guid); SetInteractiveChildrenGuids(gameObject, interactiveChildIdentifiers); //Copy From ConstructorBeginCraftingProcessor SubRoot subRoot = gameObject.GetComponent <SubRoot>(); if (subRoot != null) { if (modulesEquipmentGuid.IsPresent()) { GuidHelper.SetNewGuid(subRoot.upgradeConsole.modules.owner, modulesEquipmentGuid.Get()); Log.Info("Cyclop Modules Guid: " + GuidHelper.GetGuid(subRoot.upgradeConsole.modules.owner)); } else { Log.Info("Error Cyclop Modules Guid Missing Cyclop Guid: " + GuidHelper.GetGuid(subRoot.gameObject)); } } }
private void OnVehiclePrefabLoaded(GameObject prefab, string guid, Vector3 spawnPosition, Quaternion spawnRotation, Optional <List <InteractiveChildObjectIdentifier> > interactiveChildIdentifiers, Optional <string> dockingBayGuid) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; GuidHelper.SetNewGuid(gameObject, guid); if (interactiveChildIdentifiers.IsPresent()) { VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(gameObject, interactiveChildIdentifiers.Get()); //Copy From ConstructorBeginCraftingProcessor } if (dockingBayGuid.IsPresent()) { GameObject dockingBayBase = GuidHelper.RequireObjectFrom(dockingBayGuid.Get()); VehicleDockingBay dockingBay = dockingBayBase.GetComponentInChildren <VehicleDockingBay>(); Vehicle vehicle = gameObject.GetComponent <Vehicle>(); dockingBay.DockVehicle(vehicle); } }
public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent) { TechType techType = entity.TechType.Enum(); GameObject prefab; IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId); if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings { prefab = CraftData.GetPrefabForTechType(techType, false); if (prefab == null) { return(Optional <GameObject> .Of(Utils.CreateGenericLoot(techType))); } } GameObject gameObject = Utils.SpawnFromPrefab(prefab, null); gameObject.transform.position = entity.Position; gameObject.transform.localScale = entity.Scale; if (parent.IsPresent()) { gameObject.transform.SetParent(parent.Get().transform, true); } gameObject.transform.localRotation = entity.Rotation; gameObject.SetActive(true); NitroxIdentifier.SetNewId(gameObject, entity.Id); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, techType); return(Optional <GameObject> .Of(gameObject)); }
public override void Process(DroppedItem drop) { Optional <TechType> opTechType = ApiHelper.TechType(drop.TechType); if (opTechType.IsEmpty()) { Console.WriteLine("Attempted to drop unknown tech type: " + drop.TechType); return; } TechType techType = opTechType.Get(); GameObject techPrefab = TechTree.main.GetGamePrefab(techType); if (techPrefab != null) { GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(techPrefab, ApiHelper.Vector3(drop.ItemPosition), Quaternion.FromToRotation(Vector3.up, Vector3.up)); gameObject.SetActive(true); CrafterLogic.NotifyCraftEnd(gameObject, techType); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); GuidHelper.SetNewGuid(gameObject, drop.Guid); ItemDropAction itemDropAction = ItemDropAction.FromTechType(techType); itemDropAction.ProcessDroppedItem(gameObject); } }
private Optional <GameObject> CreateVehicle(String techTypeString, String guid) { Optional <TechType> opTechType = ApiHelper.TechType(techTypeString); if (opTechType.IsEmpty()) { Console.WriteLine("Unknown tech type: " + techTypeString); return(Optional <GameObject> .Empty()); } TechType techType = opTechType.Get(); GameObject techPrefab = TechTree.main.GetGamePrefab(techType); if (techPrefab != null) { GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(techPrefab, Vector3.zero, Quaternion.FromToRotation(Vector3.up, Vector3.up)); gameObject.SetActive(true); CrafterLogic.NotifyCraftEnd(gameObject, techType); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; GuidHelper.SetNewGuid(gameObject, guid); return(Optional <GameObject> .Of(gameObject)); } else { Console.WriteLine("No prefab for tech type: " + techType); } return(Optional <GameObject> .Empty()); }
public static bool OnConsoleCommand_spawn_Prefix(NotificationCenter.Notification n) { if (n != null && n.data != null && n.data.Count > 0) { string text = (string)n.data[0]; if (UWE.Utils.TryParseEnum <TechType>(text, out TechType techType) && techType != TechType.None) { if (CraftData.IsAllowed(techType)) { foreach (IDecorationItem item in DecorationsMod.DecorationItems) { // If item being spawned is one of our decoration items. if (techType == item.TechType) { // If item being spawned is one of our new flora. if (!string.IsNullOrEmpty(item.ClassID) && CustomFlora.AllPlants.Contains(item.ClassID)) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(techType, true); if (prefabForTechType != null) { int num = 1; int num2; if (n.data.Count > 1 && int.TryParse((string)n.data[1], out num2)) { num = num2; } float maxDist = 12f; if (n.data.Count > 2) { maxDist = float.Parse((string)n.data[2]); } Debug.LogFormat("Spawning {0} {1}", new object[] { num, techType }); for (int i = 0; i < num; i++) { GameObject gameObject = global::Utils.CreatePrefab(prefabForTechType, maxDist, i > 0); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, techType); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); // Hide plant, show seed and enable pickupable PrefabsHelper.HidePlantAndShowSeed(gameObject.transform, item.ClassID); } } else { ErrorMessage.AddDebug("Could not find prefab for TechType = " + techType); } // Dont call original function if item being spawned is one of our new flora. return(false); } break; } } } } } // Give back execution to original function. return(true); }
public override void Process(VehicleSpawned packet) { vehicles.AddVehicle(packet.VehicleModel); GameObject gameObject = SerializationHelper.GetGameObject(packet.SerializedData); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); }
public static void GivePlayerItem(Pickupable item) { if (Inventory.main.HasRoomFor(item)) { if (Inventory.main.Pickup(item)) { CrafterLogic.NotifyCraftEnd(Player.main.gameObject, item.GetTechType()); } } }
// Token: 0x0600000B RID: 11 RVA: 0x00002A8C File Offset: 0x00000C8C private void OnSubPrefabLoaded(GameObject prefab) { GameObject gameObject = global::Utils.SpawnPrefabAt(prefab, null, this.spawnPosition); gameObject.transform.localScale = new Vector3(this.x, this.y, this.z); gameObject.transform.rotation = this.spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", 1); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); }
public static bool OnConsoleCommand_item_Prefix(NotificationCenter.Notification n) { if (n != null && n.data != null && n.data.Count > 0) { string text = (string)n.data[0]; if (UWE.Utils.TryParseEnum <TechType>(text, out TechType techType) && techType != TechType.None) { if (CraftData.IsAllowed(techType)) { foreach (IDecorationItem item in DecorationsMod.DecorationItems) { // If item being spawned is one of our decoration items. if (techType == item.TechType) { // If item being spawned is one of our new flora. if (!string.IsNullOrEmpty(item.ClassID) && CustomFlora.AllPlants.Contains(item.ClassID)) { int num = 1; if (n.data.Count > 1 && int.TryParse((string)n.data[1], out int num2)) { num = num2; } for (int i = 0; i < num; i++) { GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false); if (gameObject != null) { gameObject.transform.position = MainCamera.camera.transform.position + MainCamera.camera.transform.forward * 3f; CrafterLogic.NotifyCraftEnd(gameObject, techType); Pickupable component = gameObject.GetComponent <Pickupable>(); if (component != null && !Inventory.main.Pickup(component, false)) { ErrorMessage.AddError(Language.main.Get("InventoryFull")); // Hide plant, show seed and enable pickupable PrefabsHelper.HidePlantAndShowSeed(gameObject.transform, item.ClassID); } } } // Dont call original function if item being spawned is one of our new flora. return(false); } break; } } } } } // Give back execution to original function. return(true); }
private void GiveReward(TechType techType) { GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false); if (gameObject != null) { gameObject.transform.position = MainCamera.camera.transform.position + MainCamera.camera.transform.forward * 2f; CrafterLogic.NotifyCraftEnd(gameObject, techType); Pickupable component = gameObject.GetComponent <Pickupable>(); if (component != null && !Inventory.main.Pickup(component, false)) { ErrorMessage.AddError(Language.main.Get("InventoryFull")); } } }
public static bool Prefix(ref SpawnConsoleCommand __instance, NotificationCenter.Notification n) { if (n != null && n.data != null && n.data.Count > 0) { string text = (string)n.data[0]; TechType techType; if (UWE.Utils.TryParseEnum <TechType>(text, out techType)) { if (techType == TechType.Seamoth && n.data.Count <= 2) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(techType, true); if (prefabForTechType != null) { int num = 1; int num2; if (n.data.Count > 1 && int.TryParse((string)n.data[1], out num2)) { num = num2; } float maxDist = 12f; if (n.data.Count > 2) { maxDist = float.Parse((string)n.data[2]); } Debug.LogFormat("Spawning {0} {1}", new object[] { num, techType }); for (int i = 0; i < num; i++) { GameObject gameObject = global::Utils.CreatePrefab(prefabForTechType, maxDist, i > 0); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, techType); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); } } return(false); } return(true); } else { return(true); } } return(true); }
private void OnVehiclePrefabLoaded(RemotePlayer player, GameObject prefab, string guid, Vector3 spawnPosition, Quaternion spawnRotation) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; GuidHelper.SetNewGuid(gameObject, guid); }
public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot) { TechType techType = entity.TechType.Enum(); GameObject prefab; IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId); if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings { prefab = CraftData.GetPrefabForTechType(techType, false); if (prefab == null) { return(Optional.Of(Utils.CreateGenericLoot(techType))); } } GameObject gameObject = Utils.SpawnFromPrefab(prefab, null); gameObject.transform.position = entity.Transform.Position; gameObject.transform.rotation = entity.Transform.Rotation; gameObject.transform.localScale = entity.Transform.LocalScale; NitroxEntity.SetNewId(gameObject, entity.Id); CrafterLogic.NotifyCraftEnd(gameObject, techType); if (parent.HasValue) { gameObject.transform.SetParent(parent.Value.transform, true); } if (parent.HasValue && !parent.Value.GetComponent <LargeWorldEntityCell>()) { LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject } else { gameObject.SetActive(true); } Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata); if (metadataProcessor.HasValue) { metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata); } return(Optional.Of(gameObject)); }
private void SpawnEntity(Entity entity) { if (entity.TechType != TechType.None) { GameObject gameObject = CraftData.InstantiateFromPrefab(entity.TechType); gameObject.transform.position = entity.Position; gameObject.transform.localRotation = entity.Rotation; GuidHelper.SetNewGuid(gameObject, entity.Guid); gameObject.SetActive(true); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, entity.TechType); Log.Debug("Received cell entity: " + entity.Guid + " at " + entity.Position + " of type " + entity.TechType); } alreadySpawnedGuids.Add(entity.Guid); }
private static void OnSubLoaded(GameObject prefab) { var gameObject = Utils.SpawnPrefabAt(prefab, null, setPosition); gameObject.transform.rotation = setRotation; gameObject.SetActive(true); LargeWorldEntity.Register(gameObject); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); GuidHelper.Set(gameObject, setGuid); GuidHelper.SetChildGuids(gameObject, setChildren); setGuid = null; setChildren = null; SyncedObject.ApplyTo(gameObject); }
public void AttemptToTakeItem(TechType item) { if (IsBeingDeleted == true) { return; } if (timerTillNextPickup > 0f) { return; } if (TrackedResources.ContainsKey(item)) { TrackedResource trackedResource = TrackedResources[item]; int beforeRemoveAmount = trackedResource.Amount; if (trackedResource.Containers.Count >= 1) { StorageContainer sc = trackedResource.Containers.ElementAt(0); if (sc.container.Contains(item)) { Pickupable pickup = sc.container.RemoveItem(item); if (pickup != null) { if (Inventory.main.Pickup(pickup)) { CrafterLogic.NotifyCraftEnd(Player.main.gameObject, item); if (beforeRemoveAmount == 1) { timerTillNextPickup = COOLDOWN_TIME_BETWEEN_PICKING_UP_LAST_ITEM_TYPE; } } else { // If it fails to get added to the inventory lets add it back into the storage container. sc.container.AddItem(pickup); } } } } } }
public override void Process(DroppedItem drop) { TechType techType; UWE.Utils.TryParseEnum <TechType>(drop.TechType, out techType); GameObject techPrefab = TechTree.main.GetGamePrefab(techType); if (techPrefab != null) { GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(techPrefab, ApiHelper.Vector3(drop.ItemPosition), Quaternion.FromToRotation(Vector3.up, Vector3.up)); gameObject.SetActive(true); CrafterLogic.NotifyCraftEnd(gameObject, techType); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; rigidBody.AddForce(ApiHelper.Vector3(drop.PushVelocity), ForceMode.VelocityChange); } }
public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(entity.TechType, false); if (prefabForTechType == null && !PrefabDatabase.TryGetPrefab(entity.ClassId, out prefabForTechType)) { return(Optional <GameObject> .Of(Utils.CreateGenericLoot(entity.TechType))); } GameObject gameObject = Utils.SpawnFromPrefab(prefabForTechType, null); gameObject.transform.position = entity.Position; gameObject.transform.localRotation = entity.Rotation; GuidHelper.SetNewGuid(gameObject, entity.Guid); gameObject.SetActive(true); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, entity.TechType); return(Optional <GameObject> .Of(gameObject)); }
public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot) { TechType techType = entity.TechType.ToUnity(); GameObject gameObject = CreateGameObject(techType, entity.ClassId); gameObject.transform.position = entity.Transform.Position.ToUnity(); gameObject.transform.rotation = entity.Transform.Rotation.ToUnity(); gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity(); NitroxEntity.SetNewId(gameObject, entity.Id); CrafterLogic.NotifyCraftEnd(gameObject, techType); if (parent.HasValue && !parent.Value.GetComponent <LargeWorldEntityCell>()) { LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject } else if (gameObject.GetComponent <LargeWorldEntity>() != null && gameObject.transform.parent == null) { gameObject.transform.SetParent(cellRoot.liveRoot.transform, true); LargeWorldEntity.Register(gameObject); } else { gameObject.SetActive(true); } if (parent.HasValue) { gameObject.transform.SetParent(parent.Value.transform, true); } Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata); if (metadataProcessor.HasValue) { metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata); } return(Optional.Of(gameObject)); }
public static void ConstructorCraft(ConstructorInput input, TechType tech) { if (!CrafterLogic.ConsumeResources(tech)) { return; } uGUI.main.craftingMenu.Close(input); input.cinematicController.DisengageConstructor(); Transform spawn = input.constructor.GetItemSpawnPoint(tech); var position = spawn.position; var rotation = spawn.rotation; GameObject gameObject; if (tech == TechType.Cyclops) { SubConsoleCommand.main.SpawnSub("cyclops", position, rotation); gameObject = SubConsoleCommand.main.GetLastCreatedSub(); } else { gameObject = CraftData.InstantiateFromPrefab(tech, false); Transform component = gameObject.GetComponent <Transform>(); component.position = position; component.rotation = rotation; } LargeWorldEntity.Register(gameObject); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Story.ItemGoalTracker.OnConstruct(tech); Commands.SendSpawn(gameObject, tech); }
private void DrawHostilesMenu() { if (reaper == null) { if (GUILayout.Button("Spawn Reaper")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.ReaperLeviathan, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.ReaperLeviathan); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); reaper = gameObject.GetComponentInChildren <ReaperLeviathan>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Reaper Components")) { foreach (Component c in reaper.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Reaper")) { Destroy(reaper.gameObject); } if (GUILayout.Button("AttackCyclops information")) { AttackCyclops ac = reaper.GetComponent <AttackCyclops>(); Log.Print("LastTarget: " + ac.lastTarget); Log.Print("aggressPerSecond: " + ac.aggressPerSecond); Log.Print("attackAggressionThreshold: " + ac.attackAggressionThreshold); Log.Print("attackPause: " + ac.attackPause); Log.Print("maxDistToLeash: " + ac.maxDistToLeash); Log.Print("swimVelocity: " + ac.swimVelocity); Log.Print("swimInterval: " + ac.swimInterval); Log.Print("aggressiveToNoise Falloff: " + ac.aggressiveToNoise.Falloff); Log.Print("aggressiveToNoise Value: " + ac.aggressiveToNoise.Value); } GUILayout.Space(10); } if (crabsquid == null) { if (GUILayout.Button("Spawn Crabsquid")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.CrabSquid, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.CrabSquid); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); crabsquid = gameObject.GetComponentInChildren <CrabSquid>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Crabsquid Components")) { foreach (Component c in crabsquid.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Crabsquid")) { Destroy(crabsquid.gameObject); } GUILayout.Space(10); } if (ghostlevi == null) { if (GUILayout.Button("Spawn Ghost Levi")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.GhostLeviathan, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.GhostLeviathan); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); ghostlevi = gameObject.GetComponentInChildren <GhostLeviathan>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Ghost Levi Components")) { foreach (Component c in ghostlevi.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Ghost Levi")) { Destroy(ghostlevi.gameObject); } GUILayout.Space(10); } if (seaDragon == null) { if (GUILayout.Button("Spawn Seadragon")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.SeaDragon, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.SeaDragon); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); seaDragon = gameObject.GetComponentInChildren <SeaDragon>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Seadragon Components")) { foreach (Component c in seaDragon.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Seadragon")) { Destroy(seaDragon.gameObject); } GUILayout.Space(10); } if (warper == null) { if (GUILayout.Button("Spawn warper")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.Warper, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.Warper); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); warper = gameObject.GetComponentInChildren <Warper>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Warper Components")) { foreach (Component c in warper.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Warper")) { Destroy(warper.gameObject); } GUILayout.Space(10); } }
internal static bool GivePlayerItem(TechType techType, ObjectDataTransferData itemData, Func <ObjectData, RackSlot> getServerWithObjectData) { QuickLogger.Debug($"Give Player Item: {techType}", true); bool isSuccessful = false; #if SUBNAUTICA var itemSize = CraftData.GetItemSize(techType); #elif BELOWZERO var itemSize = TechData.GetItemSize(techType); #endif if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y)) { //TODO handle null playerToolData if (itemData.Vehicle == null) { var pickup = CheckIfEggAnExtractPickable(techType); if (!itemData.IsServer) { var data = (ObjectData)itemData.data; if (data != null) { DetectDataObjectTypeAndPerformConversion(data, pickup); var result = getServerWithObjectData?.Invoke(data); result?.Remove(data); isSuccessful = true; } } else { var data = (HashSet <ObjectData>)itemData.data; var controller = pickup.gameObject.GetComponent <DSSServerController>(); controller.Initialize(); controller.FCSFilteredStorage.Items = new HashSet <ObjectData>(data); controller.FCSFilteredStorage.Filters = new List <Filter>(itemData.Filters); controller.DisplayManager.UpdateDisplay(); isSuccessful = true; } Inventory.main.Pickup(pickup); } else if (itemData.Vehicle != null) { QuickLogger.Debug("Is Vehicle Item"); var vehicleContainers = itemData.Vehicle.gameObject.GetComponentsInChildren <StorageContainer>() .Select((x) => x.container).ToList(); vehicleContainers.AddRange(GetSeamothStorage(itemData.Vehicle)); for (var index = 0; index < vehicleContainers.Count; index++) { for (var i = 0; i < vehicleContainers[index].ToList().Count; i++) { var item = vehicleContainers[index].ToList()[i]; if (item.item.GetTechType() == techType) { var passedItem = vehicleContainers[index].RemoveItem(item.item); if (passedItem) { if (Inventory.main.Pickup(item.item)) { CrafterLogic.NotifyCraftEnd(Player.main.gameObject, item.item.GetTechType()); goto _end; } } } } } _end: isSuccessful = true; } } Mod.OnBaseUpdate?.Invoke(); return(isSuccessful); }
private void DrawHostilesMenu() { if (reaper == null) { if (GUILayout.Button("Spawn Reaper")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.ReaperLeviathan, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.ReaperLeviathan); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); reaper = gameObject.GetComponentInChildren <ReaperLeviathan>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Reaper Components")) { foreach (Component c in reaper.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Reaper")) { Destroy(reaper.gameObject); } GUILayout.Space(10); } if (crabsquid == null) { if (GUILayout.Button("Spawn Crabsquid")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.CrabSquid, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.CrabSquid); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); crabsquid = gameObject.GetComponentInChildren <CrabSquid>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Crabsquid Components")) { foreach (Component c in crabsquid.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Crabsquid")) { Destroy(crabsquid.gameObject); } GUILayout.Space(10); } if (ghostlevi == null) { if (GUILayout.Button("Spawn Ghost Levi")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.GhostLeviathan, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.GhostLeviathan); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); ghostlevi = gameObject.GetComponentInChildren <GhostLeviathan>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Ghost Levi Components")) { foreach (Component c in ghostlevi.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Ghost Levi")) { Destroy(ghostlevi.gameObject); } GUILayout.Space(10); } if (seaDragon == null) { if (GUILayout.Button("Spawn Seadragon")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.SeaDragon, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.SeaDragon); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); seaDragon = gameObject.GetComponentInChildren <SeaDragon>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Seadragon Components")) { foreach (Component c in seaDragon.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Seadragon")) { Destroy(seaDragon.gameObject); } GUILayout.Space(10); } if (warper == null) { if (GUILayout.Button("Spawn warper")) { GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.Warper, true); GameObject gameObject = Utils.CreatePrefab(prefabForTechType); LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, TechType.Warper); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); warper = gameObject.GetComponentInChildren <Warper>(); gameObject.transform.position += 50f * gameObject.transform.forward; } } else { GUILayout.Space(10); if (GUILayout.Button("Warper Components")) { foreach (Component c in warper.GetComponentsInChildren(typeof(Component))) { Log.Print("Component: " + c + " on go: " + c.gameObject.name); } } if (GUILayout.Button("Delete Warper")) { Destroy(warper.gameObject); } GUILayout.Space(10); } }
private void OnVehiclePrefabLoaded(TechType techType, GameObject prefab, string guid, Vector3 spawnPosition, Quaternion spawnRotation, Optional <List <InteractiveChildObjectIdentifier> > interactiveChildIdentifiers, Optional <string> dockingBayGuid, string name, Vector3[] hsb, Vector3[] colours) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; GuidHelper.SetNewGuid(gameObject, guid); // Updates names and colours with persisted data .....yeah..... if (techType == TechType.Seamoth || techType == TechType.Exosuit) { // Seamoth & Prawn suit Vehicle vehicle = gameObject.GetComponent <Vehicle>(); if (dockingBayGuid.IsPresent()) { GameObject dockingBayBase = GuidHelper.RequireObjectFrom(dockingBayGuid.Get()); VehicleDockingBay dockingBay = dockingBayBase.GetComponentInChildren <VehicleDockingBay>(); dockingBay.DockVehicle(vehicle); } if (!string.IsNullOrEmpty(name)) { vehicle.vehicleName = name; vehicle.subName.DeserializeName(vehicle.vehicleName); } if (colours != null) { Vector3[] colour = new Vector3[5]; for (int i = 0; i < hsb.Length; i++) { colour[i] = hsb[i]; } vehicle.vehicleColors = colour; vehicle.subName.DeserializeColors(vehicle.vehicleColors); } } else if (techType == TechType.Cyclops) // Cyclops { GameObject target = GuidHelper.RequireObjectFrom(guid); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); subNameInput.OnNameChange(name); for (int i = 0; i < hsb.Length; i++) { subNameInput.SetSelected(i); Color tmpColour = new Vector4(colours[i].x, colours[i].y, colours[i].z); subNameTarget.SetColor(i, hsb[i], tmpColour); subNameTarget.DeserializeColors(hsb); } } if (interactiveChildIdentifiers.IsPresent()) { VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(gameObject, interactiveChildIdentifiers.Get()); //Copy From ConstructorBeginCraftingProcessor } }
private void OnVehiclePrefabLoaded(TechType techType, GameObject prefab, NitroxId id, Vector3 spawnPosition, Quaternion spawnRotation, IEnumerable <InteractiveChildObjectIdentifier> interactiveChildIdentifiers, Optional <NitroxId> dockingBayId, string name, Vector3[] hsb, Vector3[] colours, float health) { // Partially copied from SubConsoleCommand.OnSubPrefabLoaded GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition); gameObject.transform.rotation = spawnRotation; gameObject.SetActive(true); gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver); CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject)); Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = false; NitroxEntity.SetNewId(gameObject, id); // Updates names and colours with persisted data if (techType == TechType.Seamoth || techType == TechType.Exosuit) { Vehicle vehicle = gameObject.GetComponent <Vehicle>(); if (dockingBayId.HasValue) { GameObject dockingBayBase = NitroxEntity.RequireObjectFrom(dockingBayId.Value); VehicleDockingBay dockingBay = dockingBayBase.GetComponentInChildren <VehicleDockingBay>(); dockingBay.DockVehicle(vehicle); } else if (techType == TechType.Exosuit) { // exosuits tend to fall through the ground after spawning. This should prevent that vehicle.ReflectionSet("onGround", true); } if (!string.IsNullOrEmpty(name)) { vehicle.vehicleName = name; vehicle.subName.DeserializeName(vehicle.vehicleName); } if (colours != null) { vehicle.vehicleColors = colours; vehicle.subName.DeserializeColors(vehicle.vehicleColors); } vehicle.GetComponent <LiveMixin>().health = health; } else if (techType == TechType.Cyclops) { GameObject target = NitroxEntity.RequireObjectFrom(id); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); subNameInput.OnNameChange(name); subNameTarget.DeserializeColors(hsb); target.GetComponent <LiveMixin>().health = health; // Set internal and external lights SetCyclopsModes(id); } VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(gameObject, interactiveChildIdentifiers); // Send event after everything is created if (VehicleCreated != null) { VehicleCreated(gameObject); } }
private IEnumerator SpawnTechType(NotificationCenter.Notification n, TechType techType) { CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(techType, false); yield return(task); GameObject prefabForTechType = task.GetResult(); if (prefabForTechType != null) { this.x = 1f; this.y = 1f; this.z = 1f; int num = 6; int num2 = 1; if (n.data.Count > 1) { num2 = int.Parse((string)n.data[1]); } if (n.data.Count > 2) { this.x = float.Parse((string)n.data[2]); } if (n.data.Count > 3) { this.y = float.Parse((string)n.data[3]); } if (n.data.Count > 4) { this.z = float.Parse((string)n.data[4]); } if (n.data.Count > 5) { num = int.Parse((string)n.data[5]); } if (n.data.Count == 3) { this.y = float.Parse((string)n.data[2]); this.z = float.Parse((string)n.data[2]); } if (n.data.Count == 4) { this.z = float.Parse((string)n.data[3]); } for (int i = 0; i < num2; i++) { GameObject gameObject = global::Utils.CreatePrefab(prefabForTechType, (float)num, i > 0); UWE.Utils.GetEntityRoot(gameObject).transform.localScale = new Vector3(this.x, this.y, this.z); bool flag12 = gameObject.GetComponent <Creature>() != null; if (flag12) { gameObject.AddComponent <mono>().Setsize(this.x, this.y, this.z); } LargeWorldEntity.Register(gameObject); CrafterLogic.NotifyCraftEnd(gameObject, techType); gameObject.SendMessage("StartConstruction", 1); } } else { ErrorMessage.AddDebug("Prefab not found for " + techType); } yield break; }