Exemple #1
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;
    }
 private void RemoveStackable(Stackable stackable)
 {
     if (stackable != null)
     {
         //TODO: place object on ground in front of player
     }
 }
Exemple #3
0
        /// <summary> Returns whether two stackable objects could be stacked. </summary>
        private bool CanStack(Stackable anObject, Stackable anOtherObject)
        {
            bool isNearInTime  = MeetsStackTime(anObject, anOtherObject);
            bool isNearInSpace = MeetsStackDistance(anObject, anOtherObject);

            return(isNearInTime && isNearInSpace);
        }
Exemple #4
0
        public static HaulResult Get(BaseCharacter character, Task task, int qty = 1)
        {
            Job get = new Job(
                delegate {
                return(
                    character.inventory.def == null ||
                    (character.inventory.free > 0 && character.inventory.def == task.targets.current.tilable.def)
                    );
            }
                );

            get.OnEnd = delegate {
                Stackable stack = (Stackable)Loki.map.grids[Layer.Stackable].GetTilableAt(task.targets.current.position);
                if (stack == null || stack.inventory.count == 0)
                {
                    task.state = TaskState.Failed;
                    return;
                }
                stack.inventory.TransfertTo(character.inventory, qty);
            };


            Stackable _stack = (Stackable)Loki.map.grids[Layer.Stackable].GetTilableAt(task.targets.current.position);

            if (_stack != null)
            {
                return(new HaulResult(get, _stack.inventory.count));
            }
            else
            {
                return(new HaulResult(get, 0));
            }
        }
        public void AddItem(ItemSlot fromSlot)
        {
            if (fromSlot == null || fromSlot.IsEmpty || fromSlot.ItemObject.GetComponent <Fermentable>() == null || closed)
            {
                return;
            }

            ItemSlot storageSlot = itemStorage.GetNextFreeIndexedSlot();
            bool     added       = false;
            // If there's a stackable component, add one at a time.
            Stackable stack = fromSlot.ItemObject.GetComponent <Stackable>();

            if (stack == null || stack.Amount == 1)
            {
                added = Inventory.ServerTransfer(fromSlot, storageSlot);
            }
            else
            {
                var item = stack.ServerRemoveOne();
                Inventory.ServerAdd(item, storageSlot);
            }
            if (storageSlot.ItemObject.TryGetComponent(out Fermentable fermentable))
            {
                storedFermentables.Add(storageSlot, fermentable);
            }
        }
Exemple #6
0
    public override int GetHashCode()
    {
        var hashCode = 745842380;

        hashCode = hashCode * -1521134295 + Id.GetHashCode();
        hashCode = hashCode * -1521134295 + Slot.GetHashCode();
        hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Title);

        hashCode = hashCode * -1521134295 + Value.GetHashCode();
        hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Type);

        hashCode = hashCode * -1521134295 + Power.GetHashCode();
        hashCode = hashCode * -1521134295 + Defense.GetHashCode();
        hashCode = hashCode * -1521134295 + Vitality.GetHashCode();
        hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Description);

        hashCode = hashCode * -1521134295 + Stackable.GetHashCode();
        hashCode = hashCode * -1521134295 + Rarity.GetHashCode();
        hashCode = hashCode * -1521134295 + Durability.GetHashCode();
        hashCode = hashCode * -1521134295 + DurabilityCount.GetHashCode();
        hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Slug);

        hashCode = hashCode * -1521134295 + EqualityComparer <Sprite> .Default.GetHashCode(Sprite);

        return(hashCode);
    }
Exemple #7
0
 public void SetStackable(Stackable stackable)
 {
     this._stackable    = stackable;
     this._rt.offsetMin = new Vector2(this._stackable.position.x, this._stackable.position.y);
     this._rt.offsetMax = new Vector2(this._stackable.position.x + 1, this._stackable.position.y + 1);
     this._tm.text      = this._stackable.inventory.count.ToString();
 }
Exemple #8
0
        /// <title>Saga.NpcTakeItem</title>
        /// <code>
        /// Saga.NpcTakeItem(cid, QuestID, ItemId, Count);
        /// </code>
        /// <description>
        /// Takes a npc item as with a message that the npc took it.
        /// </description>
        /// <example>
        public static int TakeItem(uint cid, uint itemid, byte count)
        {
            Character value;

            if (LifeCycle.TryGetById(cid, out value))
            {
                //HELPER VARIABLES
                DEFAULT_FACTORY_ITEMS.ItemInfo info;
                Singleton.Item.TryGetItem(itemid, out info);
                //int stackcount = 0;

                Predicate <Rag2Item> callback = delegate(Rag2Item item)
                {
                    bool result = item.info.item == itemid;
                    //if (result) stackcount += item.info.max_stack - item.count;
                    return(result);
                };

                //CHECK IF RIGHT AMOUNT OF ITEMS WAS FOUND
                List <int> FoundItems = value.ITEMS.FindAll(callback);
                //if (count > stackcount) return -1;

                //DO THE ACTUAL TAKING
                int acount = count;
                foreach (int currentInxdex in FoundItems)
                {
                    Stackable <Rag2Item> item = value.ITEMS[currentInxdex];
                    int MinCount = Math.Min(acount, Math.Min(item.Count, info.max_stack));
                    acount -= MinCount;

                    if ((item.Count -= MinCount) == 0)
                    {
                        value.ITEMS.RemoveAt(currentInxdex);
                        SMSG_DELETEITEM spkt = new SMSG_DELETEITEM();
                        spkt.Container    = 2;
                        spkt.Index        = (byte)currentInxdex;
                        spkt.UpdateReason = (byte)ITEMUPDATEREASON.GIVE_TO_NPC;
                        spkt.SessionId    = value.id;
                        value.client.Send((byte[])spkt);
                    }
                    else
                    {
                        SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM();
                        spkt.Amount       = (byte)item.Count;
                        spkt.UpdateReason = (byte)ITEMUPDATEREASON.GIVE_TO_NPC;
                        spkt.UpdateType   = 4;
                        spkt.Container    = 2;
                        spkt.SessionId    = value.id;
                        spkt.Index        = (byte)currentInxdex;
                        value.client.Send((byte[])spkt);
                        break;
                    }
                }
                return(count);
            }
            else
            {
                return(-1);
            }
        }
Exemple #9
0
 public static void ClearStackable(TilableDef def, Stackable stackable)
 {
     if (WorldUtils.stackables.ContainsKey(def))
     {
         WorldUtils.stackables[def].Remove(stackable);
     }
 }
Exemple #10
0
        /// <summary> Returns whether two stackable objects could be stacked. </summary>
        private bool CanStack(Stackable stackable, Stackable otherStackable)
        {
            bool isNearInTime  = MeetsStackTime(stackable, otherStackable);
            bool isNearInSpace = MeetsStackDistance(stackable, otherStackable);

            return(isNearInTime && isNearInSpace);
        }
        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);
        }
Exemple #12
0
        public void AddItem(ItemSlot fromSlot)
        {
            if (fromSlot == null || fromSlot.IsEmpty || ((fromSlot.ItemObject.GetComponent <Grindable>() == null && fromSlot.ItemObject.GetComponent <Juiceable>() == null) && !fromSlot.ItemAttributes.HasTrait(CommonTraits.Instance.Beaker)))
            {
                return;
            }


            if (fromSlot.ItemAttributes.HasTrait(CommonTraits.Instance.Beaker))
            {
                if (itemSlot.IsEmpty)
                {
                    Inventory.ServerTransfer(fromSlot, itemStorage.GetIndexedItemSlot(0));
                }
                return;
            }

            // If there's a stackable component, add one at a time.
            Stackable stack = fromSlot.ItemObject.GetComponent <Stackable>();

            if (stack == null || stack.Amount == 1)
            {
                Inventory.ServerTransfer(fromSlot, itemStorage.GetNextFreeIndexedSlot());
            }
            else
            {
                var item = stack.ServerRemoveOne();
                Inventory.ServerAdd(item, itemStorage.GetNextFreeIndexedSlot());
            }
        }
Exemple #13
0
 /// <summary>
 /// Returns true iff toAdd can be added to this stackable, as long as there is space for at least
 /// one item.
 /// </summary>
 /// <param name="toAdd"></param>
 /// <returns></returns>
 public bool CanAccommodate(Stackable toAdd)
 {
     if (toAdd == null)
     {
         return(false);
     }
     return(toAdd != null && StacksWith(toAdd) && amount < maxAmount);
 }
    /// <summary>
    /// Updates the players transform by moving the player above the center of the Stackable object
    /// </summary>
    /// <param name="stackable"></param>
    private void StackOnBottom(Stackable stackable)
    {
        Vector3 playerBottomCenter = this.GetBottomCenter();
        Vector3 stackableTopCenter = stackable.GetTopCenter();
        Vector3 targetTranslation  = stackableTopCenter - playerBottomCenter;

        this.transform.Translate(targetTranslation, Space.World);
    }
    /// <summary>
    /// returns tru iff toCheck is allowed to be combined with this stackable. Does not check
    /// the current stacked amount.
    /// </summary>
    /// <param name="toCheck"></param>
    /// <returns></returns>
    public bool StacksWith(Stackable toCheck)
    {
        if (toCheck == null)
        {
            return(false);
        }

        return(stacksWith.Intersect(toCheck.stacksWith).Any());
    }
Exemple #16
0
 /// <summary>
 /// OnTriggerExit is called when the Collider other has stopped touching the trigger.
 /// </summary>
 /// <param name="other">The other Collider involved in this collision.</param>
 void OnTriggerExit(Collider other)
 {
     if (other.gameObject.name.Equals("Player"))
     {
         //this.SendMessageUpwards("OnPlayerNearExit");
         Stackable parent = GetParentStackable();
         parent.OnPlayerNearExit();
     }
 }
    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);
        }
    }
Exemple #18
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);
        }
    }
    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);;
        }
    }
Exemple #20
0
        public static void AddStackable(TilableDef def, Stackable stackable)
        {
            if (!WorldUtils.stackables.ContainsKey(def))
            {
                WorldUtils.stackables.Add(def, new List <Stackable>());
                WorldUtils.stackablesCount.Add(def, 0);
            }

            WorldUtils.stackables[def].Add(stackable);
            WorldUtils.stackablesCount[def] += stackable.inventory.count;
        }
 public override string ToString()
 {
     return("Title:" + Title + "\n" +
            "value:" + Value + "\n" +
            "Stats:" + Stats + "\n" +
            "\t" + "Power:" + Stats.Power + "\n" +
            "\t" + "Defence:" + Stats.Defence + "\n" +
            "\t" + "Vitality:" + Stats.Vitality + "\n" +
            "Description:" + Description + "\n" +
            "Stackable:" + Stackable.ToString() + "\n" +
            "Rarity:" + Rarity + "\n");
 }
Exemple #22
0
 private void Awake()
 {
     itemAttributes = GetComponent <ItemAttributesV2>();
     stackable      = GetComponent <Stackable>();
     if (itemAttributes)
     {
         itemAttributes.AddTrait(CommonTraits.Instance.Food);
     }
     else
     {
         Logger.LogErrorFormat("{0} prefab is missing ItemAttributes", Category.ItemSpawn, name);
     }
 }
    /// <summary>
    /// Players can check the remaining microwave time or insert something into the microwave.
    /// </summary>
    public void ServerPerformInteraction(HandApply interaction)
    {
        if (microwave.MicrowaveTimer > 0)
        {
            Chat.AddExamineMsgFromServer(interaction.Performer, $"{microwave.MicrowaveTimer:0} seconds until the {microwave.meal} is cooked.");
        }
        else if (interaction.HandObject != null)
        {
            // Check if the player is holding food that can be cooked
            ItemAttributesV2 attr       = interaction.HandObject.GetComponent <ItemAttributesV2>();
            Ingredient       ingredient = new Ingredient(attr.ArticleName);

            GameObject meal = CraftingManager.Meals.FindRecipe(new List <Ingredient> {
                ingredient
            });

            if (meal)
            {
                // HACK: Currently DOES NOT check how many items are used per meal
                // Blindly assumes each single item in a stack produces a meal

                //If food item is stackable, set output amount to equal input amount.
                Stackable stck = interaction.HandObject.GetComponent <Stackable>();
                if (stck != null)
                {
                    microwave.ServerSetOutputStackAmount(stck.Amount);
                }
                else
                {
                    microwave.ServerSetOutputStackAmount(1);
                }

                microwave.ServerSetOutputMeal(meal.name);
                Despawn.ServerSingle(interaction.HandObject);
                microwave.RpcStartCooking();
                microwave.MicrowaveTimer = microwave.COOK_TIME;
                Chat.AddExamineMsgFromServer(interaction.Performer, $"You microwave the {microwave.meal} for {microwave.COOK_TIME} seconds.");
            }
            else
            {
                Chat.AddExamineMsgFromServer(interaction.Performer, $"Your {attr.ArticleName} can not be microwaved.");
                // Alternative suggestions:
                // "$"The microwave is not programmed to cook your {attr.ArticleName}."
                // "$"The microwave does not know how to cook your{attr.ArticleName}."
            }
        }
        else
        {
            Chat.AddExamineMsgFromServer(interaction.Performer, "The microwave is empty.");
        }
    }
Exemple #24
0
        /// <summary> Returns whether a stackable following a slider could be stacked under the tail
        /// (or over in case of slider and slider). </summary>
        private bool CanStackTail(Slider slider, Stackable stackable)
        {
            double distanceSq =
                Vector2.DistanceSquared(
                    stackable.UnstackedPosition,
                    slider.edgeAmount % 2 == 0 ?
                    slider.UnstackedPosition :
                    slider.UnstackedEndPosition);

            bool isNearInTime  = MeetsStackTime(slider, stackable);
            bool isNearInSpace = distanceSq < 3 * 3;

            return(isNearInTime && isNearInSpace && slider.time < stackable.time);
        }
        static void PatchedSplitStack(Stackable __instance, Interaction interaction, int quantity)
        {
            if (!GameManager.IsServer || quantity > __instance.Quantity)
            {
                return;
            }
            __instance.NetworkQuantity = __instance.Quantity - quantity;
            Human parent = interaction.SourceSlot.Parent as Human;

            if (parent == null)
            {
                return;
            }


            Stackable newStack = OnServer.Create(
                __instance.Prefab as DynamicThing,
                __instance.GetSafeDropPosition(
                    interaction.SourceSlot.Parent.CenterPosition,
                    parent.HelmetSlot.Location.forward,
                    interaction.SourceThing.Bounds.size.z + 0.6f
                    ),
                interaction.SourceThing.ThingTransform.rotation,
                __instance.OwnerSteamId,
                __instance.GridController.ParentMothership != null ? __instance.GridController.ParentMothership.RigidBody : null
                ) as Stackable;

            if (newStack != null)
            {
                if (__instance.CustomColor.IsSet)
                {
                    OnServer.SetCustomColor(newStack, __instance.CustomColor.Index);
                }
                newStack.NetworkQuantity = Mathf.Min(quantity, newStack.MaxQuantity);
                __instance.OnSplitStack(newStack);
                Slot destinationSlot   = parent.LeftHandSlot == interaction.SourceSlot ? parent.RightHandSlot : parent.LeftHandSlot;
                var  occupantStackable = destinationSlot.Occupant as Stackable;
                if (occupantStackable != null && occupantStackable.PrefabHash == newStack.PrefabHash)
                {
                    occupantStackable.Merge(newStack);
                }
                else if (destinationSlot.Occupant == null)
                {
                    // Stationeers orignal code:
                    //newStack.MoveToSlot(destinationSlot, newStack, false);
                    // Bug fix for clients not seeing stack moves:
                    OnServer.MoveToSlot(newStack, destinationSlot);
                }
            }
        }
Exemple #26
0
        /// <summary> Returns whether a stackable following a slider could be stacked under the tail
        /// (or over in case of slider and slider). </summary>
        private bool CanStackTail(Slider aSlider, Stackable anOtherObject)
        {
            double distanceSq =
                Vector2.DistanceSquared(
                    anOtherObject.UnstackedPosition,
                    aSlider.edgeAmount % 2 == 0 ?
                    aSlider.UnstackedPosition :
                    aSlider.UnstackedEndPosition);

            bool isNearInTime  = MeetsStackTime(aSlider, anOtherObject);
            bool isNearInSpace = distanceSq < 3 * 3;

            return(isNearInTime && isNearInSpace && aSlider.time < anOtherObject.time);
        }
        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);
            }
        }
Exemple #28
0
        private void Awake()
        {
            FoodContents   = GetComponent <ReagentContainer>();
            item           = GetComponent <RegisterItem>();
            itemAttributes = GetComponent <ItemAttributesV2>();
            stackable      = GetComponent <Stackable>();

            if (itemAttributes != null)
            {
                itemAttributes.AddTrait(CommonTraits.Instance.Food);
            }
            else
            {
                Logger.LogErrorFormat("{0} prefab is missing ItemAttributes", Category.Objects, name);
            }
        }
        /// <summary>
        /// Add a `GameObject` to the first open slot.
        /// Expects `GameObject` to have a `Draggable`
        /// component attached.
        /// </summary>
        /// <param name="item">The `GameObject` item to add to
        /// this container</param>
        public override void Add(GameObject item)
        {
            Draggable dragHandler = item.GetComponent <Draggable>();

            if (dragHandler == null)
            {
                throw new MissingComponentException("Adding to Container requires `Draggable` component");
            }

            Stackable stackHandler = item.GetComponent <Stackable>();
            Slot      emptySlot = null, stackableSlot = null;

            foreach (Slot slot in Slots)
            {
                //  retrieve the first empty slot and retain
                if (emptySlot == null && slot.Item == null)
                {
                    emptySlot = slot;

                    //  if there's an item in this slot
                    //  but the item being added is stackable
                    //  check if it can stack
                }
                else if (slot.Item && stackHandler != null)
                {
                    Stackable itemStack = slot.Item.GetComponent <Stackable>();

                    if (itemStack != null && itemStack.CanStack(stackHandler))
                    {
                        stackableSlot = slot;
                    }
                }
            }

            //  add the item to the slot
            //  will prioritize stackable slot
            if (stackableSlot != null)
            {
                stackableSlot.AddItem(dragHandler);
            }
            else if (emptySlot != null)
            {
                emptySlot.AddItem(dragHandler);
            }

            throw new NotStackableException("Unable to add item (" + dragHandler.name + ") to container ( " + name + ")");
        }
Exemple #30
0
    public bool CanAccommodate(ItemSlot ItemSlot, Stackable CheckStackable = null)
    {
        if (ItemSlot.IsEmpty)
        {
            return(true);
        }
        if (CheckStackable != null)
        {
            var Stackable = ItemSlot.Item.GetComponent <Stackable>();
            if (Stackable == null)
            {
                return(false);
            }
            return(Stackable.StacksWith(CheckStackable));
        }

        return(false);
    }