Пример #1
0
        private void Refill(Stackable stackable, int needAmmo)
        {
            var plasmaInStack = stackable.Amount;

            if (needAmmo >= plasmaInStack)
            {
                magazineBehaviour.ExpendAmmo(-plasmaInStack);
                stackable.ServerConsume(plasmaInStack);
            }
            else if (needAmmo < plasmaInStack)
            {
                magazineBehaviour.ExpendAmmo(-needAmmo);
                stackable.ServerConsume(needAmmo);
            }
        }
Пример #2
0
        private void Refill(Stackable stackable, int needAmmo, int ChargingWatts)
        {
            // get the amount of plasma being used to refill
            var plasmaInStack = stackable.Amount;

            toRefill = 0;
            // calculate the amount of fuel we would need to
            // refill to capacity
            for (int i = needAmmo; i > 0; i -= refilledAmmo)
            {
                toRefill++;
            }

            if (plasmaInStack < toRefill)
            {
                // dont have enough plasma to refill to capacity
                toConsume = plasmaInStack;
            }
            else
            {
                // have enough to refill to capacity
                toConsume = toRefill;
            }
            AddCharge(ChargingWatts * toConsume);
            stackable.ServerConsume(toConsume);
        }
Пример #3
0
    /// <summary>
    /// Finish cooking the microwaved meal.
    /// </summary>
    private void FinishCooking()
    {
        spriteRenderer.sprite = SPRITE_OFF;
        if (isServer)
        {
            GameObject  mealPrefab = CraftingManager.Meals.FindOutputMeal(meal);
            SpawnResult result     = Spawn.ServerPrefab(mealPrefab, GetComponent <RegisterTile>().WorldPosition, transform.parent);

            //If the resulting meal has a stackable component, set the amount to mealCount to ensure that food in = food out.
            Stackable stck = result.GameObject.GetComponent <Stackable>();

            if (stck != null && mealCount != 0)
            {
                //Get difference between new item's initial amount and the amount held by mealCount (amount of ingredient).
                int stckChanger = mealCount - stck.Amount;

                //If stckChanger is 0, do nothing.
                //If stckChanger is positive, add to stack.
                if (stckChanger > 0)
                {
                    stck.ServerIncrease(stckChanger);
                }
                else if (stckChanger < 0)
                {
                    //If stckChanger is positive, remove stack.
                    stck.ServerConsume(-stckChanger);
                }
            }
        }
        meal      = null;
        mealCount = 0;
    }
Пример #4
0
    public virtual void Eat(PlayerScript eater, PlayerScript feeder)
    {
        SoundManager.PlayNetworkedAtPos(sound, eater.WorldPos, sourceObj: eater.gameObject);

        eater.playerHealth.Metabolism
        .AddEffect(new MetabolismEffect(NutritionLevel, 0, MetabolismDuration.Food));

        var feederSlot = feeder.ItemStorage.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);
            }
        }
    }
Пример #5
0
    private void ServerApplyHeal(BodyPartBehaviour targetBodyPart)
    {
        targetBodyPart.HealDamage(40, healType);
        stackable.ServerConsume(1);

        HealthBodyPartMessage.Send(targetBodyPart.livingHealthBehaviour.gameObject, targetBodyPart.livingHealthBehaviour.gameObject,
                                   targetBodyPart.Type, targetBodyPart.livingHealthBehaviour.GetTotalBruteDamage(),
                                   targetBodyPart.livingHealthBehaviour.GetTotalBurnDamage());
    }
Пример #6
0
    private void ConvertRods(HandApply interaction)
    {
        Stackable stack = gameObject.GetComponent <Stackable>();

        if (stack.Amount >= minimumRods)
        {
            Spawn.ServerPrefab(CommonPrefabs.Instance.Metal, interaction.Performer.WorldPosServer(), count: metalSpawnCount);
            stack.ServerConsume(minimumRods);
        }
    }
Пример #7
0
    private void convertRods(HandApply interaction)
    {
        Stackable stack = gameObject.GetComponent <Stackable>();

        if (stack.Amount >= rods)
        {
            Spawn.ServerPrefab("Metal", interaction.Performer.WorldPosServer(), count: metal);
            stack.ServerConsume(rods);
        }
    }
Пример #8
0
    private void convertGlass(HandApply interaction)
    {
        Stackable stack = gameObject.GetComponent <Stackable>();

        if (stack.Amount >= sheetsGlass)
        {
            Spawn.ServerPrefab("ReinforcedGlassSheet", interaction.Performer.WorldPosServer(), count: sheetsReinforcedGlass);
            stack.ServerConsume(sheetsGlass);
            interaction.HandObject.GetComponent <Stackable>().ServerConsume(rods);;
        }
    }
Пример #9
0
 private void ServerApplyHeal(LivingHealthMasterBase targetBodyPart, HandApply interaction)
 {
     targetBodyPart.HealDamage(null, 40, healType, interaction.TargetBodyPart);
     if (StopsExternalBleeding)
     {
         RemoveLimbLossBleed(targetBodyPart, interaction);
     }
     if (HealsTraumaDamage)
     {
         HealTraumaDamage(targetBodyPart, interaction);
     }
     stackable.ServerConsume(1);
 }
Пример #10
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);
                }
            }
        }
Пример #11
0
    public void ServerCombine(Stackable toAdd)
    {
        if (!StacksWith(toAdd))
        {
            Logger.LogErrorFormat("toAdd {0} doesn't stack with this {2}, cannot combine. Consider adding" +
                                  " this prefab to stacksWith if these really should be stackable.",
                                  Category.Inventory, toAdd, this);
            return;
        }
        var amountToConsume = Math.Min(toAdd.amount, maxAmount - amount);

        if (amountToConsume <= 0)
        {
            return;
        }
        Logger.LogTraceFormat("Combining {0} <- {1}", Category.Inventory, GetInstanceID(), toAdd.GetInstanceID());
        toAdd.ServerConsume(amountToConsume);
        SyncAmount(amount + amountToConsume);
    }
Пример #12
0
    public int ServerCombine(Stackable toAdd)
    {
        if (!StacksWith(toAdd))
        {
            Logger.LogErrorFormat($"{toAdd} doesn't stack with {this}, cannot combine. Consider adding" +
                                  " this prefab to stacksWith if these really should be stackable.",
                                  Category.Objects);
            return(0);
        }
        var amountToConsume = Math.Min(toAdd.amount, SpareCapacity);

        if (amountToConsume <= 0)
        {
            return(0);
        }
        Logger.LogTraceFormat("Combining {0} <- {1}", Category.Objects, GetInstanceID(), toAdd.GetInstanceID());
        toAdd.ServerConsume(amountToConsume);
        SyncAmount(amount, amount + amountToConsume);
        return(amountToConsume);
    }
Пример #13
0
    /// <summary>
    /// Finish cooking the microwaved meal.
    /// </summary>
    private void FinishCooking()
    {
        spriteRenderer.sprite = SPRITE_OFF;

        if (isServer && mealCount > 0)
        {
            GameObject mealPrefab    = CraftingManager.Meals.FindOutputMeal(meal);
            Vector3Int spawnPosition = GetComponent <RegisterTile>().WorldPosition;

            SpawnResult result = Spawn.ServerPrefab(mealPrefab, spawnPosition, transform.parent);
            Stackable   stck   = result.GameObject.GetComponent <Stackable>();

            if (stck != null)               // If the meal has a stackable component, set the correct number of meals
            {
                int mealDeficit = mealCount - stck.InitialAmount;

                while (mealDeficit > 0)
                {
                    mealDeficit = stck.ServerIncrease(mealDeficit);

                    if (mealDeficit > 0)
                    {
                        result       = Spawn.ServerPrefab(mealPrefab, spawnPosition, transform.parent);
                        stck         = result.GameObject.GetComponent <Stackable>();
                        mealDeficit -= stck.InitialAmount;
                    }
                }

                if (mealDeficit < 0)                 // Reduce the stack if our last spawned stackable results in too many meals
                {
                    stck.ServerConsume(-mealDeficit);
                }
            }
            else if (mealCount > 1)             // Spawn non-stackable meals
            {
                Spawn.ServerPrefab(mealPrefab, spawnPosition, transform.parent, count: mealCount - 1);
            }
        }
        meal      = null;
        mealCount = 0;
    }
Пример #14
0
    private void TryToEat(PlayerScript feeder, PlayerScript eater)
    {
        var feederSlot = feeder.ItemStorage.GetActiveHandSlot();

        if (feederSlot.Item == null)
        {               //Already been eaten or the food is no longer in hand
            return;
        }

        var eaterHungerState = eater.playerHealth.Metabolism.HungerState;

        if (feeder == eater)         //If you're eating it yourself.
        {
            switch (eaterHungerState)
            {
            case HungerState.Full:
                Chat.AddActionMsgToChat(eater.gameObject, $"You cannot force any more of the {Name} to go down your throat!",
                                        $"{eater.playerName} cannot force any more of the {Name} to go down {eater.characterSettings.PossessivePronoun()} throat!");
                return;                         //Not eating!

            case HungerState.Normal:
                Chat.AddActionMsgToChat(eater.gameObject, $"You unwillingly {EatVerb} the {Name}.",        //"a bit of"
                                        $"{eater.playerName} unwillingly {EatVerb}s the {Name}.");         //"a bit of"
                break;

            case HungerState.Hungry:
                Chat.AddActionMsgToChat(eater.gameObject, $"You {EatVerb} the {Name}.",
                                        $"{eater.playerName} {EatVerb}s the {Name}.");
                break;

            case HungerState.Malnourished:
                Chat.AddActionMsgToChat(eater.gameObject, $"You hungrily {EatVerb} the {Name}.",
                                        $"{eater.playerName} hungrily {EatVerb}s the {Name}.");
                break;

            case HungerState.Starving:
                Chat.AddActionMsgToChat(eater.gameObject, $"You hungrily {EatVerb} the {Name}, gobbling it down!",
                                        $"{eater.playerName} hungrily {EatVerb}s the {Name}, gobbling it down!");
                break;
            }
        }
        else         //If you're feeding it to someone else.
        {
            if (eaterHungerState == HungerState.Full)
            {
                Chat.AddActionMsgToChat(eater.gameObject,
                                        $"{feeder.playerName} cannot force any more of {Name} down your throat!",
                                        $"{feeder.playerName} cannot force any more of {Name} down {eater.playerName}'s throat!");
                return;                 //Not eating!
            }
            else
            {
                Chat.AddActionMsgToChat(eater.gameObject,
                                        $"{feeder.playerName} attempts to feed you {Name}.",
                                        $"{feeder.playerName} attempts to feed {eater.playerName} {Name}.");
            }

            //Wait 3 seconds before you can feed
            StandardProgressAction.Create(ProgressConfig, () =>
            {
                Chat.AddActionMsgToChat(eater.gameObject,
                                        $"{feeder.playerName} forces you to eat {Name}!",
                                        $"{feeder.playerName} forces {eater.playerName} to eat {Name}!");
                Eat();
            }).ServerStartProgress(eater.registerTile, 3f, feeder.gameObject);
            return;
        }

        Eat();

        void Eat()
        {
            SoundManager.PlayNetworkedAtPos(isDrink ? "Slurp" : "EatFood", eater.WorldPos);

            eater.playerHealth.Metabolism
            .AddEffect(new MetabolismEffect(NutritionLevel, 0, MetabolismDuration.Food));

            //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(feederSlot);
            }

            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);
                }
            }
        }
    }
Пример #15
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);
                }
            }
        }
Пример #16
0
 private void ServerApplyHeal(BodyPartBehaviour targetBodyPart)
 {
     targetBodyPart.HealDamage(40, healType);
     stackable.ServerConsume(1);
 }
Пример #17
0
 private void ServerApplyHeal(LivingHealthMasterBase targetBodyPart, HandApply interaction)
 {
     targetBodyPart.HealDamage(null, 40, healType, interaction.TargetBodyPart);
     stackable.ServerConsume(1);
 }