public override void Process(ConstructorBeginCrafting packet, NitroxServer.Player player) { VehicleModel vehicleModel = VehicleModelFactory.BuildFrom(packet); vehicleData.AddVehicle(vehicleModel); playerManager.SendPacketToOtherPlayers(packet, player); }
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 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!"); } }
//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); }
//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); }