Example #1
0
        public void Divide(float DivideAmount, bool ChangeVolume = true)
        {
            if (DivideAmount == 0)
            {
                Logger.LogError(" divide by 0 in Divide");
            }

            float GasVolume = gasMix.Volume;

            if (ChangeVolume)
            {
                GasVolume = GasVolume / DivideAmount;
            }

            Mix.Divide(DivideAmount);

            var Newone = new float[gasMix.Gases.Length];

            for (int i = 0; i < gasMix.Gases.Length; i++)
            {
                Newone[i] = gasMix.Gases[i] / DivideAmount;
            }

            gasMix = GasMix.FromTemperature(Newone, gasMix.Temperature, GasVolume);
        }
Example #2
0
 public void Divide(float DivideAmount)
 {
     if (DivideAmount == 0)
     {
         Logger.LogError(" divide by 0 in Divide");
     }
     Mix.Divide(DivideAmount);
     gasMix = gasMix / DivideAmount;
     gasMix.ChangeVolumeValue(gasMix.Volume - (gasMix.Volume / DivideAmount));
     Volume = Volume / DivideAmount;
 }
Example #3
0
 public void Divide(float DivideAmount)
 {
     Mix.Divide(DivideAmount);
     gasMix = gasMix / DivideAmount;
     gasMix.ChangeVolumeValue(gasMix.Volume - (gasMix.Volume / DivideAmount));
     Volume = Volume / DivideAmount;
     if (gasMix.Gases.Any(x => x < 0))
     {
         Logger.Log("0!!!");
     }
 }
Example #4
0
        public virtual void Eat(PlayerScript eater, PlayerScript feeder)
        {
            //TODO: Reimplement metabolism.
            AudioSourceParameters eatSoundParameters = new AudioSourceParameters(pitch: RandomPitch);

            SoundManager.PlayNetworkedAtPos(sound, eater.WorldPos, eatSoundParameters, sourceObj: eater.gameObject);

            var Stomachs = eater.playerHealth.GetStomachs();

            if (Stomachs.Count == 0)
            {
                //No stomachs?!
                return;
            }

            ReagentMix incomingFood = new ReagentMix();

            FoodContents.CurrentReagentMix.TransferTo(incomingFood, FoodContents.CurrentReagentMix.Total);

            incomingFood.Divide(Stomachs.Count);
            foreach (var Stomach in Stomachs)
            {
                Stomach.StomachContents.Add(incomingFood.Clone());
            }


            var feederSlot = feeder.DynamicItemStorage.GetActiveHandSlot();

            //If food has a stack component, decrease amount by one instead of deleting the entire stack.
            if (stackable != null)
            {
                stackable.ServerConsume(1);
            }
            else
            {
                Inventory.ServerDespawn(gameObject);
            }

            if (leavings != null)
            {
                var  leavingsInstance = Spawn.ServerPrefab(leavings).GameObject;
                var  pickupable       = leavingsInstance.GetComponent <Pickupable>();
                bool added            = Inventory.ServerAdd(pickupable, feederSlot);
                if (!added)
                {
                    //If stackable has leavings and they couldn't go in the same slot, they should be dropped
                    pickupable.CustomNetTransform.SetPosition(feeder.WorldPos);
                }
            }
        }
Example #5
0
        public virtual void Eat(PlayerScript eater, PlayerScript feeder)
        {
            //TODO: Reimplement metabolism.
            AudioSourceParameters eatSoundParameters = new AudioSourceParameters(pitch: RandomPitch);

            SoundManager.PlayNetworkedAtPos(sound, eater.WorldPos, eatSoundParameters, sourceObj: eater.gameObject);

            var Stomachs = eater.playerHealth.GetStomachs();

            if (Stomachs.Count == 0)
            {
                //No stomachs?!
                return;
            }

            float SpareSpace = 0;

            foreach (var Stomach in Stomachs)
            {
                SpareSpace += Stomach.StomachContents.SpareCapacity;
            }

            if (SpareSpace < 0.5f)
            {
                if (eater == feeder)
                {
                    Chat.AddActionMsgToChat(feeder.gameObject,
                                            "you try the stuff The food into your mouth but your stomach has no more room",
                                            "{performer} Tries to stuff food into the mouth but is unable to");
                }
                else
                {
                    Chat.AddActionMsgToChat(feeder.gameObject,
                                            "You try and stuff more food into your targets mouth but no more seems to go in",
                                            "{performer} Tries to stuff food into Their targets mouth but no more food is going in");
                }

                return;
            }

            if (SpareSpace < FoodContents.CurrentReagentMix.Total)
            {
                Chat.AddActionMsgToChat(feeder.gameObject, "You unwillingly eat the food",
                                        "{performer} Unwillingly force themselves to eat the food");
            }

            ReagentMix incomingFood = FoodContents.CurrentReagentMix.Clone();


            incomingFood.Divide(Stomachs.Count);
            foreach (var Stomach in Stomachs)
            {
                Stomach.StomachContents.Add(incomingFood.Clone());
            }


            var feederSlot = feeder.DynamicItemStorage.GetActiveHandSlot();

            //If food has a stack component, decrease amount by one instead of deleting the entire stack.
            if (stackable != null)
            {
                stackable.ServerConsume(1);
            }
            else
            {
                Inventory.ServerDespawn(gameObject);
            }

            if (leavings != null)
            {
                var  leavingsInstance = Spawn.ServerPrefab(leavings).GameObject;
                var  pickupable       = leavingsInstance.GetComponent <Pickupable>();
                bool added            = Inventory.ServerAdd(pickupable, feederSlot);
                if (!added)
                {
                    //If stackable has leavings and they couldn't go in the same slot, they should be dropped
                    pickupable.CustomNetTransform.SetPosition(feeder.WorldPos);
                }
            }
        }