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, float health)
        {
            switch (techType)
            {
            case TechType.Exosuit:
                return(new ExosuitMovementData(techType.Model(), id, position, rotation, velocity, angularVelocity, steeringWheelYaw, steeringWheelPitch, appliedThrottle, leftAimTarget, rightAimTarget, health));

            default:
                return(new VehicleMovementData(techType.Model(), id, position, rotation, velocity, angularVelocity, steeringWheelYaw, steeringWheelPitch, appliedThrottle, health));
            }
        }
Beispiel #2
0
        public void BroadcastEquip(Pickupable pickupable, GameObject owner, string slot)
        {
            NitroxId ownerId  = NitroxIdentifier.GetId(owner);
            NitroxId itemId   = NitroxIdentifier.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.Model());
            Player           player       = owner.GetComponent <Player>();

            if (player != null)
            {
                PlayerEquipmentAdded equipmentAdded = new PlayerEquipmentAdded(techType.Model(), equippedItem);
                packetSender.Send(equipmentAdded);
                pickupable.gameObject.transform.SetParent(parent);

                return;
            }

            ModuleAdded moduleAdded = new ModuleAdded(equippedItem);

            packetSender.Send(moduleAdded);
            pickupable.gameObject.transform.SetParent(parent);
        }
Beispiel #3
0
        public void PickedUp(Vector3 itemPosition, NitroxId id, TechType techType)
        {
            Log.Info("PickedUp " + id + " " + techType);
            PickupItem pickupItem = new PickupItem(itemPosition, id, techType.Model());

            packetSender.Send(pickupItem);
        }
Beispiel #4
0
        public void BroadcastUnequip(Pickupable pickupable, GameObject owner, string slot)
        {
            NitroxId itemId = NitroxIdentifier.GetId(pickupable.gameObject);
            Player   player = owner.GetComponent <Player>();

            if (player != null)
            {
                TechType techType = pickupable.GetTechType();
                PlayerEquipmentRemoved equipmentAdded = new PlayerEquipmentRemoved(techType.Model(), itemId);
                packetSender.Send(equipmentAdded);

                return;
            }

            NitroxId ownerId = NitroxIdentifier.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 BroadcastElectricalDefense(TechType techType, int slotID, SeaMoth instance)
        {
            NitroxId id = NitroxIdentifier.GetId(instance.gameObject);

            if (techType == TechType.SeamothElectricalDefense)
            {
                SeamothModulesAction Changed = new SeamothModulesAction(techType.Model(), slotID, id, Player.main.camRoot.GetAimingTransform().forward, Player.main.camRoot.GetAimingTransform().rotation);
                packetSender.Send(Changed);
            }
        }
Beispiel #6
0
        public void Dropped(GameObject gameObject, TechType techType, Vector3 dropPosition)
        {
            Optional <string> waterpark = GetCurrentWaterParkGuid();
            string            guid      = GuidHelper.GetGuid(gameObject);

            byte[] bytes = SerializationHelper.GetBytes(gameObject);

            Log.Debug("Dropping item with guid: " + guid);

            DroppedItem droppedItem = new DroppedItem(guid, waterpark, techType.Model(), dropPosition, gameObject.transform.rotation, bytes);

            packetSender.Send(droppedItem);
        }
Beispiel #7
0
        public void Dropped(GameObject gameObject, TechType techType, Vector3 dropPosition)
        {
            Optional <NitroxId> waterparkId = GetCurrentWaterParkId();
            NitroxId            id          = NitroxIdentifier.GetId(gameObject);

            byte[] bytes = SerializationHelper.GetBytes(gameObject);

            Log.Debug("Dropping item with id: " + id);

            DroppedItem droppedItem = new DroppedItem(id, waterparkId, techType.Model(), dropPosition, gameObject.transform.rotation, bytes);

            packetSender.Send(droppedItem);
        }
        public void BroadcastTorpedoLaunch(TechType techType, int slotID, SeaMoth instance)
        {
            NitroxId       id            = NitroxIdentifier.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
            {
                SeamothModulesAction Changed = new SeamothModulesAction(techType.Model(), slotID, id, Player.main.camRoot.GetAimingTransform().forward, Player.main.camRoot.GetAimingTransform().rotation);
                packetSender.Send(Changed);
            }
        }
Beispiel #9
0
        //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);
        }
Beispiel #10
0
        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.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();

                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      = "";

                if (!vehicle)
                { // Cylcops
                    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();
                }
                else if (vehicle)
                { // Seamoth & Prawn Suit
                    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);
                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!");
            }
        }
Beispiel #11
0
        private Entity SpawnChild(Entity parentEntity, DeterministicBatchGenerator deterministicBatchGenerator, TechType techType, string classId)
        {
            NitroxId id = deterministicBatchGenerator.NextId();

            return(new Entity(parentEntity.Position, parentEntity.Rotation, new UnityEngine.Vector3(1, 1, 1), techType.Model(), parentEntity.Level, classId, true, id));
        }
Beispiel #12
0
        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.Model(), parentEntity.Level, classId, true, id, null, parentEntity));
        }
Beispiel #13
0
        public void PlaceFurniture(GameObject gameObject, TechType techType, Vector3 itemPosition, Quaternion quaternion)
        {
            if (!Builder.isPlacing) //prevent possible echoing
            {
                return;
            }

            NitroxId id = NitroxEntity.GetId(gameObject);

            Optional <NitroxId> subId = Optional <NitroxId> .Empty();

            SubRoot sub = Player.main.currentSub;

            if (sub != null)
            {
                subId = Optional <NitroxId> .Of(NitroxEntity.GetId(sub.gameObject));
            }

            Transform camera = Camera.main.transform;
            Optional <RotationMetadata> rotationMetadata = Optional <RotationMetadata> .Empty();

            BasePiece      basePiece       = new BasePiece(id, itemPosition, quaternion, camera.position, camera.rotation, techType.Model(), subId, true, rotationMetadata);
            PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece);

            packetSender.Send(placedBasePiece);
        }
Beispiel #14
0
        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   = (targetBase == null) ? null : NitroxEntity.GetId(targetBase.gameObject);
            Vector3   placedPosition = constructableBase.gameObject.transform.position;
            Transform camera         = Camera.main.transform;
            Optional <RotationMetadata> rotationMetadata = rotationMetadataFactory.From(baseGhost);

            BasePiece      basePiece       = new BasePiece(id, placedPosition, quaternion, camera.position, camera.rotation, techType.Model(), Optional <NitroxId> .OfNullable(parentBaseId), false, rotationMetadata);
            PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece);

            packetSender.Send(placedBasePiece);
        }
Beispiel #15
0
        public void FabricatorCrafingStarted(GameObject crafter, TechType techType, float duration)
        {
            NitroxId crafterId = NitroxIdentifier.GetId(crafter);
            FabricatorBeginCrafting fabricatorBeginCrafting = new FabricatorBeginCrafting(crafterId, techType.Model(), duration);

            packetSender.Send(fabricatorBeginCrafting);
        }
Beispiel #16
0
        public void FabricatorItemPickedUp(GameObject gameObject, TechType techType)
        {
            NitroxId crafterId = NitroxIdentifier.GetId(gameObject);

            FabricatorItemPickup fabricatorItemPickup = new FabricatorItemPickup(crafterId, techType.Model());

            packetSender.Send(fabricatorItemPickup);
            Log.Debug(fabricatorItemPickup);
        }
Beispiel #17
0
        //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);
                Vector3[] 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?.GetColors();
                }
                else
                { //Cyclops
                    try
                    {
                        GameObject   target        = NitroxEntity.RequireObjectFrom(constructedObjectId);
                        SubNameInput subNameInput  = target.RequireComponentInChildren <SubNameInput>();
                        SubName      subNameTarget = (SubName)subNameInput.ReflectionGet("target");

                        name = subNameTarget?.GetName();
                        HSB  = subNameTarget?.GetColors();

                        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,
                           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);
        }
Beispiel #18
0
        public void Add(TechType techType, bool verbose)
        {
            KnownTechEntryAdd EntryAdd = new KnownTechEntryAdd(techType.Model(), verbose);

            packetSender.Send(EntryAdd);
        }
Beispiel #19
0
        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, quaternion, camera.position, camera.rotation, techType.Model(), Optional.OfNullable(parentId), true, Optional.Empty);
            PlaceBasePiece placedBasePiece = new PlaceBasePiece(basePiece);

            packetSender.Send(placedBasePiece);
        }
Beispiel #20
0
        public void FabricatorItemPickedUp(GameObject gameObject, TechType techType)
        {
            string crafterGuid = GuidHelper.GetGuid(gameObject);

            FabricatorItemPickup fabricatorItemPickup = new FabricatorItemPickup(crafterGuid, techType.Model());

            packetSender.Send(fabricatorItemPickup);
            Log.Debug(fabricatorItemPickup);
        }
Beispiel #21
0
        public void FabricatorCrafingStarted(GameObject crafter, TechType techType, float duration)
        {
            string crafterGuid = GuidHelper.GetGuid(crafter);
            FabricatorBeginCrafting fabricatorBeginCrafting = new FabricatorBeginCrafting(crafterGuid, techType.Model(), duration);

            packetSender.Send(fabricatorBeginCrafting);
        }