public override void Process(VehicleColorChange colorPacket) { GameObject target = NitroxIdentifier.RequireObjectFrom(colorPacket.Id); SubNameInput subNameInput = target.RequireComponentInChildren <SubNameInput>(); SubName subNameTarget = (SubName)subNameInput.ReflectionGet("target"); using (packetSender.Suppress <VehicleColorChange>()) { // Switch to the currently selected tab: subNameInput.SetSelected(colorPacket.Index); // OnColorChange calls these two methods, in order to update the vehicle color and the color+text on the ingame panel, respectively: subNameTarget.SetColor(colorPacket.Index, colorPacket.HSB, colorPacket.Color); subNameInput.ReflectionCall("SetColor", args: new object[] { colorPacket.Index, colorPacket.Color }); } }
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, 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 static void Postfix(SubNameInput __instance, ColorChangeEventData eventData) { SubName subname = __instance.target; if (subname) { GameObject parentVehicle; NitroxId controllerId = null; if (subname.TryGetComponent(out Vehicle vehicle)) { parentVehicle = vehicle.gameObject; GameObject baseCell = __instance.gameObject.RequireComponentInParent <BaseCell>().gameObject; GameObject moonpool = baseCell.RequireComponentInChildren <BaseFoundationPiece>().gameObject; controllerId = NitroxEntity.GetId(moonpool); } else if (subname.TryGetComponentInParent(out SubRoot subRoot)) { parentVehicle = subRoot.gameObject; } else if (subname.TryGetComponentInParent(out Rocket rocket)) { // For some reason only the rocket has a full functioning ghost with a different NitroxId when spawning/constructing, so we are ignoring it. if (rocket.TryGetComponentInChildren(out VFXConstructing constructing) && !constructing.isDone) { return; } parentVehicle = rocket.gameObject; } else { Log.Error($"[SubNameInput_OnColorChange_Patch] The GameObject {subname.gameObject.name} doesn't have a Vehicle/SubRoot/Rocket component."); return; } NitroxId vehicleId = NitroxEntity.GetId(parentVehicle); VehicleColorChange packet = new(__instance.SelectedColorIndex, controllerId, vehicleId, eventData.hsb.ToDto(), eventData.color.ToDto()); Resolve <ThrottledPacketSender>().SendThrottled(packet); } }
public static void Postfix(SubNameInput __instance) { SubName subname = (SubName)__instance.ReflectionGet("target"); if (subname != null) { GameObject parentVehicle; Vehicle vehicle = subname.GetComponentInParent <Vehicle>(); SubRoot subRoot = subname.GetComponentInParent <SubRoot>(); if (vehicle) { parentVehicle = vehicle.gameObject; } else { parentVehicle = subRoot.gameObject; } string guid = GuidHelper.GetGuid(parentVehicle); VehicleNameChange packet = new VehicleNameChange(guid, subname.GetName()); NitroxServiceLocator.LocateService <IPacketSender>().Send(packet); } }
public static void Postfix(SubNameInput __instance, ColorChangeEventData eventData) { SubName subname = (SubName)__instance.ReflectionGet("target"); if (subname != null) { GameObject parentVehicle; Vehicle vehicle = subname.GetComponentInParent <Vehicle>(); SubRoot subRoot = subname.GetComponentInParent <SubRoot>(); if (vehicle) { parentVehicle = vehicle.gameObject; } else { parentVehicle = subRoot.gameObject; } NitroxId id = NitroxIdentifier.GetId(parentVehicle); VehicleColorChange packet = new VehicleColorChange(__instance.SelectedColorIndex, id, eventData.hsb, eventData.color); NitroxServiceLocator.LocateService <IPacketSender>().Send(packet); } }
public static void Postfix(SubNameInput __instance, ColorChangeEventData eventData) { SubName subname = (SubName)__instance.ReflectionGet("target"); if (subname != null) { GameObject parentVehicle; // This patch works for the vehicles as well as the cyclops; this has to be found for a proper and synced guid. SubRoot subRoot = subname.GetComponentInParent <SubRoot>(); if (subRoot) { parentVehicle = subRoot.gameObject; } else { parentVehicle = subname.GetComponent <Vehicle>().gameObject; } string guid = GuidHelper.GetGuid(parentVehicle); VehicleColorChange packet = new VehicleColorChange(__instance.SelectedColorIndex, guid, eventData.hsb, eventData.color); Multiplayer.PacketSender.Send(packet); } }
public static void Postfix(SubNameInput __instance) { SubName subname = (SubName)__instance.ReflectionGet("target"); if (subname != null) { GameObject parentVehicle; // This patch works for the vehicles as well as the cyclops; this has to be found for a proper and synced guid. SubRoot subRoot = subname.GetComponentInParent <SubRoot>(); if (subRoot) { parentVehicle = subRoot.gameObject; } else { parentVehicle = subname.GetComponent <Vehicle>().gameObject; } string guid = GuidHelper.GetGuid(parentVehicle); VehicleNameChange packet = new VehicleNameChange(guid, subname.GetName()); NitroxServiceLocator.LocateService <IPacketSender>().Send(packet); } }
//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, 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); } }
//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); }
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 } }