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 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 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 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) { 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!"); } }
//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); }
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); }