예제 #1
0
        private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged)
        {
            Log.Debug($"Processing ConstructionAmountChanged {amountChanged.Id} {amountChanged.Amount}");

            GameObject          constructing        = NitroxEntity.RequireObjectFrom(amountChanged.Id);
            BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>();

            // Bases don't  send a deconstruct being packet.  Instead, we just make sure
            // that if we are changing the amount that we set it into deconstruction mode
            // if it still has a BaseDeconstructable object on it.
            if (baseDeconstructable != null)
            {
                baseDeconstructable.Deconstruct();

                // After we have begun the deconstructing for a base piece, we need to transfer the id
                Optional <object> opGhost = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE_GHOST);

                if (opGhost.HasValue)
                {
                    GameObject ghost = (GameObject)opGhost.Value;
                    Destroy(constructing);
                    NitroxEntity.SetNewId(ghost, amountChanged.Id);
                }
                else
                {
                    Log.Error($"Could not find newly created ghost to set deconstructed id {amountChanged.Id}");
                }
            }
            else
            {
                Constructable constructable = constructing.GetComponentInChildren <Constructable>();
                constructable.constructedAmount = amountChanged.Amount;
                constructable.Construct();
            }
        }
        private IEnumerator ConstructAsync(Constructable c, bool state)
        {
            float amount = ((!state) ? powerConsumptionDeconstruct : powerConsumptionConstruct) * Time.deltaTime;

            this.EnergyMixin.ConsumeEnergy(amount);
            bool constructed    = c.constructed;
            bool wasConstructed = c.constructed;
            bool flag;

            if (state)
            {
                flag = c.Construct();
            }
            else
            {
#if SUBNAUTICA_EXP || BZ
                TaskResult <bool> result = new TaskResult <bool>();
                yield return(c.DeconstructAsync(result));

                flag   = result.Get();
                result = null;
#elif SUBNAUTICA_STABLE
                flag = c.Deconstruct();
#endif
            }

            if (!flag && state && !wasConstructed)
            {
                Utils.PlayFMODAsset(this.completeSound, c.transform, 20f);
            }
            yield break;
        }
        public override void Process(ConstructionAmountChanged amountChanged)
        {
            Log.Debug("Processing ConstructionAmountChanged " + amountChanged.Guid + " " + amountChanged.ConstructionAmount);

            GameObject    constructing  = GuidHelper.RequireObjectFrom(amountChanged.Guid);
            Constructable constructable = constructing.GetComponent <Constructable>();

            constructable.constructedAmount = amountChanged.ConstructionAmount;

            using (packetSender.Suppress <ConstructionAmountChanged>())
            {
                constructable.Construct();
            }
        }
        public override void Process(ConstructionAmountChanged amountChanged)
        {
            Console.WriteLine("Processing ConstructionAmountChanged " + amountChanged.Guid + " " + amountChanged.PlayerId + " " + amountChanged.ConstructionAmount);

            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(amountChanged.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject    constructing  = opGameObject.Get();
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = amountChanged.ConstructionAmount;
                constructable.Construct();
            }
        }
예제 #5
0
 private bool Construct(Constructable c, bool state)
 {
     if (c != null && !c.constructed && this.EnergyMixin.charge > 0f)
     {
         float amount = ((!state) ? powerConsumptionDeconstruct : powerConsumptionConstruct) * Time.deltaTime;
         this.EnergyMixin.ConsumeEnergy(amount);
         bool constructed = c.constructed;
         _ = (!state) ? c.Deconstruct() : c.Construct();
         if (state && !constructed)
         {
             global::Utils.PlayFMODAsset(completeSound, c.transform, 20f);
         }
         return(true);
     }
     return(false);
 }
예제 #6
0
 //=====================================================================
 // Construct
 //
 // Figure out whether we're starting, ending, or continuing
 // construction and plays the appropriate sounds
 //=====================================================================
 private bool Construct(Constructable c, bool state)
 {
     if (c != null && !c.constructed)
     {
         bool constructed = c.constructed;
         bool flag        = (!state) ? c.Deconstruct() : c.Construct();
         if (flag)
         {
             this.constructable = c;
         }
         else if (state && !constructed)
         {
             global::Utils.PlayFMODAsset(this.completeSound, c.transform, 20f);
         }
         return(true);
     }
     return(false);
 }
예제 #7
0
        public override void Process(ConstructionCompleted completedPacket)
        {
            Console.WriteLine("Processing ConstructionAmountChanged " + completedPacket.Guid + " " + completedPacket.PlayerId + " " + completedPacket.NewBaseCreatedGuid);

            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(completedPacket.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject    constructing  = opGameObject.Get();
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = 1f;
                constructable.Construct();

                if (completedPacket.NewBaseCreatedGuid.IsPresent())
                {
                    String newBaseGuid = completedPacket.NewBaseCreatedGuid.Get();
                    configureNewlyConstructedBase(newBaseGuid);
                }
            }
        }
예제 #8
0
        private bool Construct(Constructable c, bool state)
        {
            float amount = ((!state) ? this.powerConsumptionDeconstruct : this.powerConsumptionConstruct) * Time.deltaTime;

            if (c != null && !c.constructed && this.energyMixin.GetPower() > amount)
            {
                float consumed;
                this.energyMixin.ConsumeEnergy(amount, out consumed);
                bool constructed = c.constructed;
                bool flag        = (!state) ? c.Deconstruct() : c.Construct();
                if (flag)
                {
                    this.constructable = c;
                }
                else if (state && !constructed)
                {
                    global::Utils.PlayFMODAsset(this.completeSound, c.transform, 20f);
                }
                return(true);
            }
            return(false);
        }
예제 #9
0
        private void ConstructionAmountChanged(ConstructionAmountChangedEvent amountChanged)
        {
            Log.Info("Processing ConstructionAmountChanged " + amountChanged.Guid + " " + amountChanged.Amount);

            GameObject          constructing        = GuidHelper.RequireObjectFrom(amountChanged.Guid);
            BaseDeconstructable baseDeconstructable = constructing.GetComponent <BaseDeconstructable>();

            // Bases don't  send a deconstruct being packet.  Instead, we just make sure
            // that if we are changing the amount that we set it into deconstruction mode
            // if it still has a BaseDeconstructable object on it.
            if (baseDeconstructable != null)
            {
                baseDeconstructable.Deconstruct();

                // After we have begun the deconstructing for a base piece, we need to transfer the guid
                Optional <object> opGhost = TransientLocalObjectManager.Get(TransientObjectType.LATEST_DECONSTRUCTED_BASE_PIECE);

                if (opGhost.IsPresent())
                {
                    GameObject ghost = (GameObject)opGhost.Get();
                    UnityEngine.Object.Destroy(constructing);
                    GuidHelper.SetNewGuid(ghost, amountChanged.Guid);
                }
                else
                {
                    Log.Info("Could not find newly created ghost to set deconstructed guid ");
                }
            }
            else
            {
                Constructable constructable = constructing.GetComponentInChildren <Constructable>();
                constructable.constructedAmount = amountChanged.Amount;

                using (packetSender.Suppress <ConstructionAmountChanged>())
                {
                    constructable.Construct();
                }
            }
        }