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 override void Process(ConstructorBeginCrafting packet) { GameObject gameObject = GuidHelper.RequireObjectFrom(packet.ConstructorGuid); Crafter crafter = gameObject.RequireComponentInChildren <Crafter>(true); vehicles.AddVehicle(VehicleModelFactory.BuildFrom(packet)); MethodInfo onCraftingBegin = typeof(Crafter).GetMethod("OnCraftingBegin", BindingFlags.NonPublic | BindingFlags.Instance); Validate.NotNull(onCraftingBegin); onCraftingBegin.Invoke(crafter, new object[] { packet.TechType.Enum(), packet.Duration }); //TODO: take into account latency for duration Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.IsPresent()) { GameObject constructedObject = (GameObject)opConstructedObject.Get(); constructedObject.AddComponent <NitroxEntity>(); GuidHelper.SetNewGuid(constructedObject, packet.ConstructedItemGuid); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(constructedObject, packet.InteractiveChildIdentifiers); } else { Log.Error("Could not find constructed object!"); } }
public void BroadcastEquip(Pickupable pickupable, GameObject owner, string slot) { NitroxId ownerId = NitroxEntity.GetId(owner); NitroxId itemId = NitroxEntity.GetId(pickupable.gameObject); TechType techType = pickupable.GetTechType(); if (techType == TechType.VehicleStorageModule) { List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(owner); VehicleChildUpdate vehicleChildInteractiveData = new VehicleChildUpdate(ownerId, childIdentifiers); packetSender.Send(vehicleChildInteractiveData); } Transform parent = pickupable.gameObject.transform.parent; pickupable.gameObject.transform.SetParent(null); byte[] bytes = SerializationHelper.GetBytes(pickupable.gameObject); EquippedItemData equippedItem = new EquippedItemData(ownerId, itemId, bytes, slot, techType.ToDto()); Player player = owner.GetComponent <Player>(); if (player != null) { PlayerEquipmentAdded equipmentAdded = new PlayerEquipmentAdded(techType.ToDto(), equippedItem); packetSender.Send(equipmentAdded); pickupable.gameObject.transform.SetParent(parent); return; } ModuleAdded moduleAdded = new ModuleAdded(equippedItem); packetSender.Send(moduleAdded); pickupable.gameObject.transform.SetParent(parent); }
public void BroadcastUnequip(Pickupable pickupable, GameObject owner, string slot) { NitroxId itemId = NitroxEntity.GetId(pickupable.gameObject); Player player = owner.GetComponent <Player>(); if (player != null) { TechType techType = pickupable.GetTechType(); PlayerEquipmentRemoved equipmentAdded = new PlayerEquipmentRemoved(techType.ToDto(), itemId); packetSender.Send(equipmentAdded); return; } NitroxId ownerId = NitroxEntity.GetId(owner); if (pickupable.GetTechType() == TechType.VehicleStorageModule) { List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(owner); VehicleChildUpdate vehicleChildInteractiveData = new VehicleChildUpdate(ownerId, childIdentifiers); packetSender.Send(vehicleChildInteractiveData); } ModuleRemoved moduleRemoved = new ModuleRemoved(ownerId, slot, itemId); packetSender.Send(moduleRemoved); }
public void BeginCrafting(GameObject constructor, TechType techType, float duration) { NitroxId constructorId = NitroxEntity.GetId(constructor); Log.Debug("Building item from constructor with id: " + constructorId); Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.HasValue) { GameObject constructedObject = (GameObject)opConstructedObject.Value; List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(constructedObject); VehicleModel vehicleModel = vehicles.BuildVehicleModelFrom(constructedObject, techType); vehicles.AddVehicle(vehicleModel); ConstructorBeginCrafting beginCrafting = VehicleConstructionFactory.BuildFrom(vehicleModel, constructorId, duration); packetSender.Send(beginCrafting); vehicles.SpawnDefaultBatteries(constructedObject, childIdentifiers); } else { Log.Error("Could not send packet because there wasn't a corresponding constructed object!"); } }
public void BeginCrafting(GameObject constructor, TechType techType, float duration) { string constructorGuid = GuidHelper.GetGuid(constructor); Log.Debug("Building item from constructor with uuid: " + constructorGuid); Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.IsPresent()) { GameObject constructedObject = (GameObject)opConstructedObject.Get(); List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(constructedObject); Vehicle vehicle = constructedObject.GetComponent <Vehicle>(); string constructedObjectGuid = GuidHelper.GetGuid(constructedObject); //Initialize some default values to serialize. Vector3[] HSB = new Vector3[5]; Vector3[] Colours = new Vector3[5]; Vector4 tmpColour = Color.white; string name = "Cyclops"; // Cant find a way to actually get the Cyclops name. getObjectAttributes(vehicle, name, HSB, Colours, tmpColour, constructedObjectGuid); ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorGuid, constructedObjectGuid, techType, duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation, name, HSB, Colours); packetSender.Send(beginCrafting); } else { Log.Error("Could not send packet because there wasn't a corresponding constructed object!"); } }
public void BroadcastEquip(Pickupable pickupable, GameObject owner, string slot) { string ownerGuid = GuidHelper.GetGuid(owner); string itemGuid = GuidHelper.GetGuid(pickupable.gameObject); // save current parent to prevent infinite oxygen when tank equipped above water #290 Transform parent = pickupable.gameObject.transform.parent; // set pickupable parent to null to prevent deserialized function throwing errors when packet get to other players pickupable.gameObject.transform.SetParent(null); byte[] bytes = SerializationHelper.GetBytes(pickupable.gameObject); if (pickupable.GetTechType() == TechType.VehicleStorageModule) { List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(owner); VehicleChildUpdate vehicleChildInteractiveData = new VehicleChildUpdate(ownerGuid, childIdentifiers); packetSender.Send(vehicleChildInteractiveData); } EquippedItemData equippedItem = new EquippedItemData(ownerGuid, itemGuid, bytes, slot); Player player = owner.GetComponent <Player>(); bool isPlayerEquipment = (player != null); EquipmentAddItem equipPacket = new EquipmentAddItem(equippedItem, isPlayerEquipment); packetSender.Send(equipPacket); // re-assign parent to prevent infinite oxygen #290 pickupable.gameObject.transform.SetParent(parent); }
public void BeginCrafting(GameObject constructor, TechType techType, float duration) { NitroxId constructorId = NitroxEntity.GetId(constructor); Log.Debug("Building item from constructor with id: " + constructorId); Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.HasValue) { GameObject constructedObject = (GameObject)opConstructedObject.Value; List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(constructedObject); VehicleModel vehicleModel = vehicles.BuildVehicleModelFrom(constructedObject, techType); vehicles.AddVehicle(vehicleModel); packetSender.Send(new ConstructorBeginCrafting(vehicleModel, constructorId, duration)); vehicles.SpawnDefaultBatteries(constructedObject, childIdentifiers); MonoBehaviour monoBehaviour = constructor.GetComponent <MonoBehaviour>(); //We want to store the fallen position of the object to avoid flying object on reload if (monoBehaviour) { monoBehaviour.StartCoroutine(vehicles.UpdateVehiclePositionAfterSpawn(vehicleModel, constructedObject, duration + 10.0f)); } } else { Log.Error("Could not send packet because there wasn't a corresponding constructed object!"); } }
public void BroadcastEquip(Pickupable pickupable, GameObject owner, string slot) { string ownerGuid = GuidHelper.GetGuid(owner); string itemGuid = GuidHelper.GetGuid(pickupable.gameObject); pickupable.gameObject.transform.SetParent(null); // On Deserialized Function Try to find non-existent Parent set null to prevent that bug byte[] bytes = SerializationHelper.GetBytes(pickupable.gameObject); if (pickupable.GetTechType() == TechType.VehicleStorageModule) { List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(owner); VehicleChildUpdate vehicleChildInteractiveData = new VehicleChildUpdate(ownerGuid, childIdentifiers); packetSender.Send(vehicleChildInteractiveData); } EquippedItemData equippedItem = new EquippedItemData(ownerGuid, itemGuid, bytes, slot); Player player = owner.GetComponent <Player>(); bool isPlayerEquipment = (player != null); EquipmentAddItem equipPacket = new EquipmentAddItem(equippedItem, isPlayerEquipment); packetSender.Send(equipPacket); }
public void UpdateVehicleChildren(NitroxId id, List <InteractiveChildObjectIdentifier> interactiveChildrenGuids) { Optional <GameObject> go = NitroxEntity.GetObjectFrom(id); Validate.IsTrue(go.HasValue, $"Tried to set children ids for vehicle but could not find it with Nitrox id '{id}'"); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(go.Value, interactiveChildrenGuids); }
public void UpdateVehicleChildren(NitroxId id, List<InteractiveChildObjectIdentifier> interactiveChildrenGuids) { Optional<GameObject> Object = NitroxIdentifier.GetObjectFrom(id); if (Object.IsPresent()) { GameObject T = Object.Get(); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(T, interactiveChildrenGuids); } }
public void BeginCrafting(GameObject constructor, TechType techType, float duration) { NitroxId constructorId = NitroxEntity.GetId(constructor); Log.Debug("Building item from constructor with id: " + constructorId); Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.HasValue) { GameObject constructedObject = (GameObject)opConstructedObject.Value; List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(constructedObject); Vehicle vehicle = constructedObject.GetComponent <Vehicle>(); NitroxId constructedObjectId = NitroxEntity.GetId(constructedObject); Vector3[] HSB = new Vector3[5]; Vector3[] Colours = new Vector3[5]; Vector4 tmpColour = Color.white; string name = ""; float health = 1; if (!vehicle) { // Cyclops GameObject target = NitroxEntity.RequireObjectFrom(constructedObjectId); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); Colours = subNameTarget.GetColors(); HSB = subNameTarget.GetColors(); name = subNameTarget.GetName(); health = target.GetComponent <LiveMixin>().health; } else if (vehicle) { // Seamoth & Prawn Suit health = vehicle.GetComponent <LiveMixin>().health; name = (string)vehicle.ReflectionCall("GetName", true); HSB = vehicle.subName.GetColors(); Colours = vehicle.subName.GetColors(); } ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorId, constructedObjectId, techType.Model(), duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation, name, HSB, Colours, health); vehicles.AddVehicle(VehicleModelFactory.BuildFrom(beginCrafting)); packetSender.Send(beginCrafting); SpawnDefaultBatteries(constructedObject, childIdentifiers); } else { Log.Error("Could not send packet because there wasn't a corresponding constructed object!"); } }
public void BeginCrafting(GameObject constructor, TechType techType, float duration) { string constructorGuid = GuidHelper.GetGuid(constructor); Log.Debug("Building item from constructor with uuid: " + constructorGuid); Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.IsPresent()) { GameObject constructedObject = (GameObject)opConstructedObject.Get(); List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(constructedObject); Vehicle vehicle = constructedObject.GetComponent <Vehicle>(); string constructedObjectGuid = GuidHelper.GetGuid(constructedObject); Vector3[] HSB = new Vector3[5]; Vector3[] Colours = new Vector3[5]; Vector4 tmpColour = Color.white; string name = ""; if (!vehicle) { // Cylcops GameObject target = GuidHelper.RequireObjectFrom(constructedObjectGuid); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); Colours = subNameTarget.GetColors(); HSB = subNameTarget.GetColors(); name = subNameTarget.GetName(); } else if (vehicle) { // Seamoth & Prawn Suit name = (string)vehicle.ReflectionCall("GetName", true); HSB = vehicle.subName.GetColors(); Colours = vehicle.subName.GetColors(); } ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorGuid, constructedObjectGuid, techType.Model(), duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation, name, HSB, Colours); vehicles.AddVehicle(VehicleModelFactory.BuildFrom(beginCrafting)); packetSender.Send(beginCrafting); // Mark vehicle as controlled by nitrox (used for sending add/remove batteries aka storage slots) constructedObject.AddComponent <NitroxEntity>(); SpawnDefaultBatteries(constructedObject, childIdentifiers); } else { Log.Error("Could not send packet because there wasn't a corresponding constructed object!"); } }
public void BroadcastUnequip(Pickupable pickupable, GameObject owner, string slot) { string itemGuid = GuidHelper.GetGuid(pickupable.gameObject); string ownerGuid = GuidHelper.GetGuid(owner); if (pickupable.GetTechType() == TechType.VehicleStorageModule) { List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(owner); VehicleChildUpdate vehicleChildInteractiveData = new VehicleChildUpdate(ownerGuid, childIdentifiers); packetSender.Send(vehicleChildInteractiveData); } Player player = owner.GetComponent <Player>(); bool isPlayerEquipment = (player != null); EquipmentRemoveItem equipPacket = new EquipmentRemoveItem(ownerGuid, slot, itemGuid, isPlayerEquipment); packetSender.Send(equipPacket); }
public void BeginCrafting(GameObject constructor, TechType techType, float duration) { string constructorGuid = GuidHelper.GetGuid(constructor); Log.Debug("Building item from constructor with uuid: " + constructorGuid); Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.IsPresent()) { GameObject constructedObject = (GameObject)opConstructedObject.Get(); List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractGuidsOfInteractiveChildren(constructedObject); string constructedObjectGuid = GuidHelper.GetGuid(constructedObject); ConstructorBeginCrafting beginCrafting = new ConstructorBeginCrafting(constructorGuid, constructedObjectGuid, techType, duration, childIdentifiers, constructedObject.transform.position, constructedObject.transform.rotation); packetSender.Send(beginCrafting); } else { Log.Error("Could not send packet because there wasn't a corresponding constructed object!"); } }
public override void Process(ConstructorBeginCrafting packet) { GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.ConstructorId); Crafter crafter = gameObject.RequireComponentInChildren <Crafter>(true); crafter.ReflectionCall("OnCraftingBegin", false, false, new object[] { packet.VehicleModel.TechType.ToUnity(), packet.Duration }); vehicles.AddVehicle(packet.VehicleModel); Optional <object> opConstructedObject = Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT); if (opConstructedObject.HasValue) { GameObject constructedObject = (GameObject)opConstructedObject.Value; NitroxEntity.SetNewId(constructedObject, packet.VehicleModel.Id); VehicleChildObjectIdentifierHelper.SetInteractiveChildrenIds(constructedObject, packet.VehicleModel.InteractiveChildIdentifiers); } else { Log.Error($"Could not find constructed object {packet.VehicleModel.Id} from constructor {packet.ConstructorId}"); } }
//We need to get TechType from parameters because CraftData can't resolve TechType.Cyclops by himself public VehicleModel BuildVehicleModelFrom(GameObject gameObject, TechType techType) { if (IsVehicle(techType)) { List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(gameObject); Optional <Vehicle> opvehicle = Optional.OfNullable(gameObject.GetComponent <Vehicle>()); NitroxId constructedObjectId = NitroxEntity.GetId(gameObject); Vector3[] Colours = new Vector3[5]; Vector3[] HSB = new Vector3[5]; string name = string.Empty; float health = 200f; if (opvehicle.HasValue) { //Seamoth & Exosuit Optional <LiveMixin> livemixin = Optional.OfNullable(opvehicle.Value.GetComponent <LiveMixin>()); if (livemixin.HasValue) { health = livemixin.Value.health; } name = opvehicle.Value.GetName(); Colours = HSB = opvehicle.Value.subName?.GetColors(); } else { //Cyclops try { GameObject target = NitroxEntity.RequireObjectFrom(constructedObjectId); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); Colours = subNameTarget?.GetColors(); name = subNameTarget?.GetName(); Optional <LiveMixin> livemixin = Optional.OfNullable(target.GetComponent <LiveMixin>()); if (livemixin.HasValue) { health = livemixin.Value.health; } } catch (Exception ex) { Log.Error($"{nameof(Vehicles)}: Error while trying to spawn a cyclops ({constructedObjectId})", ex); } } return(VehicleModelFactory.BuildFrom( techType.Model(), constructedObjectId, gameObject.transform.position, gameObject.transform.rotation, childIdentifiers, Optional.Empty, name, Colours, HSB, health )); } else { Log.Error($"{nameof(Vehicles)}: Impossible to build from a non-vehicle GameObject (Received {techType})"); } return(null); }
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); } }
public void SpawnDefaultBatteries(VehicleModel vehicleModel) { GameObject gameObject = NitroxEntity.RequireObjectFrom(vehicleModel.Id); SpawnDefaultBatteries(gameObject, VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(gameObject)); }
//We need to get TechType from parameters because CraftData can't resolve TechType.Cyclops by himself public VehicleModel BuildVehicleModelFrom(GameObject gameObject, TechType techType) { if (VehicleHelper.IsVehicle(techType)) { List <InteractiveChildObjectIdentifier> childIdentifiers = VehicleChildObjectIdentifierHelper.ExtractInteractiveChildren(gameObject); Optional <Vehicle> opvehicle = Optional.OfNullable(gameObject.GetComponent <Vehicle>()); NitroxId constructedObjectId = NitroxEntity.GetId(gameObject); NitroxVector3[] hsb = VehicleHelper.GetPrimalDefaultColours(); string name = string.Empty; float health = 200f; if (opvehicle.HasValue) { //Seamoth & Exosuit Optional <LiveMixin> livemixin = Optional.OfNullable(opvehicle.Value.GetComponent <LiveMixin>()); if (livemixin.HasValue) { health = livemixin.Value.health; } name = opvehicle.Value.GetName(); if (techType == TechType.Exosuit) { //For odd reasons the default colors aren't set yet for exosuit so we force it opvehicle.Value.ReflectionCall("RegenerateRenderInfo", false, false); } hsb = opvehicle.Value.subName.AliveOrNull()?.GetColors().ToDto(); } else { //Cyclops try { GameObject target = NitroxEntity.RequireObjectFrom(constructedObjectId); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); name = subNameTarget.GetName(); hsb = subNameTarget.AliveOrNull()?.GetColors().ToDto(); Optional <LiveMixin> livemixin = Optional.OfNullable(target.GetComponent <LiveMixin>()); if (livemixin.HasValue) { health = livemixin.Value.health; } } catch (Exception ex) { Log.Error($"{nameof(Vehicles)}: Error while trying to spawn a cyclops ({constructedObjectId})", ex); } } return(VehicleModelFactory.BuildFrom( techType.ToDto(), constructedObjectId, gameObject.transform.position.ToDto(), gameObject.transform.rotation.ToDto(), childIdentifiers, Optional.Empty, name, hsb ?? VehicleHelper.GetDefaultColours(techType), //Shouldn't be null now, but just in case health )); } else { Log.Error($"{nameof(Vehicles)}: Impossible to build from a non-vehicle GameObject (Received {techType})"); } return(null); }