public static VehicleMovementData GetVehicleMovementData(TechType techType, NitroxId id, Vector3 position, Quaternion rotation, Vector3 velocity, Vector3 angularVelocity, float steeringWheelYaw, float steeringWheelPitch, bool appliedThrottle, Vector3 leftAimTarget, Vector3 rightAimTarget) { switch (techType) { case TechType.Exosuit: return(new ExosuitMovementData(techType.ToDto(), id, position.ToDto(), rotation.ToDto(), velocity.ToDto(), angularVelocity.ToDto(), steeringWheelYaw, steeringWheelPitch, appliedThrottle, leftAimTarget.ToDto(), rightAimTarget.ToDto())); default: return(new VehicleMovementData(techType.ToDto(), id, position.ToDto(), rotation.ToDto(), velocity.ToDto(), angularVelocity.ToDto(), steeringWheelYaw, steeringWheelPitch, appliedThrottle)); } }
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 PickedUp(Vector3 itemPosition, NitroxId id, TechType techType) { Log.Info("PickedUp " + id + " " + techType); PickupItem pickupItem = new PickupItem(itemPosition.ToDto(), id, techType.ToDto()); packetSender.Send(pickupItem); }
public void BroadcastElectricalDefense(TechType techType, int slotID, SeaMoth instance) { NitroxId id = NitroxEntity.GetId(instance.gameObject); if (techType == TechType.SeamothElectricalDefense) { Transform aimingTransform = Player.main.camRoot.GetAimingTransform(); SeamothModulesAction changed = new SeamothModulesAction(techType.ToDto(), slotID, id, aimingTransform.forward.ToDto(), aimingTransform.rotation.ToDto()); packetSender.Send(changed); } }
public void Dropped(GameObject gameObject, TechType techType, Vector3 dropPosition) { Optional <NitroxId> waterparkId = GetCurrentWaterParkId(); NitroxId id = NitroxEntity.GetId(gameObject); byte[] bytes = SerializationHelper.GetBytes(gameObject); Log.Debug("Dropping item with id: " + id); DroppedItem droppedItem = new DroppedItem(id, waterparkId, techType.ToDto(), dropPosition.ToDto(), gameObject.transform.rotation.ToDto(), bytes); packetSender.Send(droppedItem); }
public void PickedUp(GameObject gameObject, TechType techType) { // We want to remove any remote tracking immediately on pickup as it can cause weird behavior like holding a ghost item still in the world. RemoveAnyRemoteControl(gameObject); NitroxId id = NitroxEntity.GetId(gameObject); Vector3 itemPosition = gameObject.transform.position; Log.Info("PickedUp " + id + " " + techType); PickupItem pickupItem = new PickupItem(itemPosition.ToDto(), id, techType.ToDto()); packetSender.Send(pickupItem); }
public void Dropped(GameObject gameObject, TechType techType, Vector3 dropPosition) { // there is a theoretical possibility of a stray remote tracking packet that re-adds the monobehavior, this is purely a safety call. RemoveAnyRemoteControl(gameObject); Optional <NitroxId> waterparkId = GetCurrentWaterParkId(); NitroxId id = NitroxEntity.GetId(gameObject); byte[] bytes = SerializationHelper.GetBytesWithoutParent(gameObject); Log.Debug("Dropping item with id: " + id); DroppedItem droppedItem = new DroppedItem(id, waterparkId, techType.ToDto(), dropPosition.ToDto(), gameObject.transform.rotation.ToDto(), bytes); packetSender.Send(droppedItem); }
public void BroadcastTorpedoLaunch(TechType techType, int slotID, SeaMoth instance) { NitroxId id = NitroxEntity.GetId(instance.gameObject); TorpedoType torpedoType = null; ItemsContainer storageInSlot = instance.GetStorageInSlot(slotID, TechType.SeamothTorpedoModule); for (int i = 0; i < instance.torpedoTypes.Length; i++) { if (storageInSlot.Contains(instance.torpedoTypes[i].techType)) { torpedoType = instance.torpedoTypes[i]; break; } } if (torpedoType != null) // Dont send packet if torpedo storage is empty { Transform aimingTransform = Player.main.camRoot.GetAimingTransform(); SeamothModulesAction changed = new SeamothModulesAction(techType.ToDto(), slotID, id, aimingTransform.forward.ToDto(), aimingTransform.rotation.ToDto()); packetSender.Send(changed); } }
public void AddAnalyzed(TechType techType, bool verbose) { packetSender.Send(new KnownTechEntryAdd(KnownTechEntryAdd.EntryCategory.ANALYZED, techType.ToDto(), verbose)); }
public void AddKnown(TechType techType, bool verbose) { packetSender.Send(new KnownTechEntryAdd(KnownTechEntryAdd.EntryCategory.KNOWN, techType.ToDto(), verbose)); }
//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); }
public void BroadcastAddHealth(TechType techType, NitroxId id, float healthAdded, float totalHealth) { LiveMixinHealthChanged packet = new LiveMixinHealthChanged(techType.ToDto(), id, healthAdded, totalHealth); multiplayerSession.Send(packet); }
public void FabricatorItemPickedUp(GameObject gameObject, TechType techType) { NitroxId crafterId = NitroxEntity.GetId(gameObject); FabricatorItemPickup fabricatorItemPickup = new FabricatorItemPickup(crafterId, techType.ToDto()); packetSender.Send(fabricatorItemPickup); Log.Debug(fabricatorItemPickup); }
public void GhostCrafterItemPickedUp(GameObject gameObject, TechType techType) { NitroxId crafterId = NitroxEntity.GetId(gameObject); GhostCrafterItemPickup ghostCrafterItemPickup = new GhostCrafterItemPickup(crafterId, techType.ToDto()); packetSender.Send(ghostCrafterItemPickup); }
public void PlaceFurniture(GameObject gameObject, TechType techType, Vector3 itemPosition, Quaternion quaternion) { if (!Builder.isPlacing) //prevent possible echoing { return; } NitroxId id = NitroxEntity.GetId(gameObject); NitroxId parentId = null; SubRoot sub = Player.main.currentSub; if (sub != null) { parentId = NitroxEntity.GetId(sub.gameObject); } else { Base playerBase = gameObject.GetComponentInParent <Base>(); if (playerBase != null) { parentId = NitroxEntity.GetId(playerBase.gameObject); } } // Leverage local position when in a cyclops as items must be relative. bool inCyclops = (sub != null && sub.isCyclops); Vector3 position = (inCyclops) ? gameObject.transform.localPosition : itemPosition; Quaternion rotation = (inCyclops) ? gameObject.transform.localRotation : quaternion; Transform camera = Camera.main.transform; BasePiece basePiece = new BasePiece(id, position.ToDto(), rotation.ToDto(), camera.position.ToDto(), camera.rotation.ToDto(), techType.ToDto(), Optional.OfNullable(parentId), true, Optional.Empty); PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece); packetSender.Send(placedBasePiece); }
public void PlaceBasePiece(BaseGhost baseGhost, ConstructableBase constructableBase, Base targetBase, TechType techType, Quaternion quaternion) { if (!Builder.isPlacing) //prevent possible echoing { return; } NitroxId id = NitroxEntity.GetId(constructableBase.gameObject); NitroxId parentBaseId = null; if (baseGhost != null) { if (baseGhost.TargetBase != null) { parentBaseId = NitroxEntity.GetId(baseGhost.TargetBase.gameObject); } else if (baseGhost.GhostBase != null) { parentBaseId = NitroxEntity.GetId(baseGhost.GhostBase.gameObject); } } if (parentBaseId == null) { Base aBase = constructableBase.gameObject.GetComponentInParent <Base>(); if (aBase != null) { parentBaseId = NitroxEntity.GetId(aBase.gameObject); } } Vector3 placedPosition = constructableBase.gameObject.transform.position; Transform camera = Camera.main.transform; Optional <RotationMetadata> rotationMetadata = rotationMetadataFactory.From(baseGhost); BasePiece basePiece = new BasePiece(id, placedPosition.ToDto(), quaternion.ToDto(), camera.position.ToDto(), camera.rotation.ToDto(), techType.ToDto(), Optional.OfNullable(parentBaseId), false, rotationMetadata); PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece); packetSender.Send(placedBasePiece); }
public void Add(TechType techType, bool verbose) { KnownTechEntryAdd EntryAdd = new KnownTechEntryAdd(techType.ToDto(), verbose); packetSender.Send(EntryAdd); }
public void PlaceFurniture(GameObject gameObject, TechType techType, Vector3 itemPosition, Quaternion quaternion) { if (!Builder.isPlacing) //prevent possible echoing { return; } NitroxId id = NitroxEntity.GetId(gameObject); NitroxId parentId = null; SubRoot sub = Player.main.currentSub; if (sub != null) { parentId = NitroxEntity.GetId(sub.gameObject); } else { Base playerBase = gameObject.GetComponentInParent <Base>(); if (playerBase != null) { parentId = NitroxEntity.GetId(playerBase.gameObject); } } Transform camera = Camera.main.transform; BasePiece basePiece = new BasePiece(id, itemPosition.ToDto(), quaternion.ToDto(), camera.position.ToDto(), camera.rotation.ToDto(), techType.ToDto(), Optional.OfNullable(parentId), true, Optional.Empty); PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece); packetSender.Send(placedBasePiece); }
public void GhostCrafterCrafingStarted(GameObject crafter, TechType techType, float duration) { NitroxId crafterId = NitroxEntity.GetId(crafter); GhostCrafterBeginCrafting ghostCrafterBeginCrafting = new GhostCrafterBeginCrafting(crafterId, techType.ToDto(), duration); packetSender.Send(ghostCrafterBeginCrafting); }
public void BroadcastTakeDamage(TechType techType, NitroxId id, float originalDamage, Vector3 position, DamageType damageType, Optional <NitroxId> dealerId, float totalHealth) { LiveMixinHealthChanged packet = new LiveMixinHealthChanged(techType.ToDto(), id, -originalDamage, totalHealth, position.ToDto(), (ushort)damageType, dealerId); multiplayerSession.Send(packet); }
private Entity SpawnChild(Entity parentEntity, DeterministicBatchGenerator deterministicBatchGenerator, TechType techType, string classId) { NitroxId id = deterministicBatchGenerator.NextId(); return(new Entity(new NitroxVector3(0, 0, 0), new NitroxQuaternion(0, 0, 0, 1), new NitroxVector3(1, 1, 1), techType.ToDto(), parentEntity.Level, classId, true, id, null, parentEntity)); }
public void FabricatorCrafingStarted(GameObject crafter, TechType techType, float duration) { NitroxId crafterId = NitroxEntity.GetId(crafter); FabricatorBeginCrafting fabricatorBeginCrafting = new FabricatorBeginCrafting(crafterId, techType.ToDto(), duration); packetSender.Send(fabricatorBeginCrafting); }