public void Craft(IItemContainer itemContainer)
    {
        // if we have sufficient materials to craft the item
        if (CanCraft(itemContainer))
        {
            // loop through the materials list and remove the required materials
            foreach (ItemAmount itemAmount in materials)
            {
                for (int i = 0; i < itemAmount.amount; i++)
                {
                    sScrapItem oldItem = itemContainer.RemoveItem(itemAmount.item.ID);
                    Destroy(oldItem);
                }
            }

            // loop through the results list and add them back to the inventory
            foreach (ItemAmount itemAmount in results)
            {
                for (int i = 0; i < itemAmount.amount; i++)
                {
                    itemContainer.AddItem(Instantiate(itemAmount.item));
                }
            }
        }
    }
Exemple #2
0
        public Prefab FromPpd(IItemContainer map, string unitName, string variant, string look,
                              PrefabDescriptor ppd, Vector3 pos, Quaternion rot)
        {
            this.map       = map;
            this.ppd       = ppd;
            this.prefabPos = pos;
            this.prefabRot = rot;

            prefab = new Prefab
            {
                Model   = unitName,
                Variant = variant,
                Look    = look
            };

            // create map nodes from ppd
            CreateMapNodes();

            if (ppd.SpawnPoints.Count > 0)
            {
                CreateSlaveItems();
            }

            map.AddItem(prefab);
            return(prefab);
        }
 private void AddResults(IItemContainer itemContainer) {
     foreach (ItemAmount itemAmount in Results) {
         for (int i = 0; i < itemAmount.Amount; i++) {
             itemContainer.AddItem(itemAmount.Item.GetCopy());
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Base method for adding a new MultiNodeItem to the map.
        /// </summary>
        internal static T Add <T>(IItemContainer map, IList <Vector3> positions) where T : MultiNodeItem, new()
        {
            var item = new T();

            CreateNodes(map, positions, item);
            map.AddItem(item);
            return(item);
        }
Exemple #5
0
 public void AddItemToInvitory(IItemContainer container)
 {
     //print("can add item " + container.AddItem(item));
     if (container.AddItem(item))
     {
         Destroy(gameObject);
     }
 }
Exemple #6
0
 private void AddResults(IItemContainer itemContainer)
 {
     foreach (ItemAmount itemAmount in Results)
     {
         for (int i = 0; i < itemAmount.Amount; i++)
         {
             itemContainer.AddItem(itemAmount.Item.GetCopy());
             FindObjectOfType <AudioManager>().Play("Craft"); //CRAFTING ITEM SOUND
         }
     }
 }
Exemple #7
0
        /// <summary>
        /// Base method for adding a new SingleNodeItem to the map.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="map"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        internal static T Add <T>(IItemContainer map, Vector3 position) where T : SingleNodeItem, new()
        {
            var node = map.AddNode(position, true);

            var newItem = new T();

            newItem.Node             = node;
            newItem.Node.ForwardItem = newItem;
            map.AddItem(newItem);

            return(newItem);
        }
Exemple #8
0
 private void HandleMessage(Message message)
 {
     using (var reader = message.GetReader())
     {
         var facadeId = reader.ReadUInt16();
         if (_info.Type == CharacterType.Player && _info.IsLocal && _info.Id == facadeId)
         {
             var itemId   = reader.ReadInt16();
             var instance = _factory.Create(ItemType.Module, itemId);
             _inventory.AddItem(instance);
         }
     }
 }
Exemple #9
0
    public void Craft(IItemContainer container)
    {
        if (CanCraft(container))
        {
            if (notPuzzle)
            {
                List <Item> removed      = new List <Item>();
                int         itemsRemoved = 0;

                foreach (Item item in Pieces)
                {
                    if (container.RemoveItem(item))
                    {
                        removed.Add(item);
                        itemsRemoved++;
                    }
                }
                if (itemsRemoved != minItems)
                {
                    foreach (Item itm in removed)
                    {
                        container.AddItem(itm);
                    }
                }
                else
                {
                    container.AddItem(result);
                }
            }
            else
            {
                foreach (Item item in Pieces)
                {
                    container.RemoveItem(item);
                }
                myButton.SetActive(true);
            }
        }
    }
    void Pickup(GameObject interactor)
    {
        IItemContainer interactorContainer = interactor.GetComponent <IItemContainer>();

        if (interactorContainer == null)
        {
            return;
        }

        if (interactorContainer.AddItem(itemSlotWorld.GetItemSlot()))
        {
            GetComponentInParent <DestroySelf>().Destroy();
        }
    }
    void Pickup(GameObject interactor)
    {
        IItemContainer itemContainer = interactor.GetComponent <IItemContainer>();

        if (itemContainer == null)
        {
            return;
        }

        if (itemContainer.AddItem(itemSlot).quantity == 0)
        {
            GetComponentInParent <DestroySelf>().Destroy();
        }
    }
Exemple #12
0
 public void Craft(IItemContainer itemContainer)
 {
     if (!itemContainer.IsFull())
     {
         if (CanCraft(itemContainer))
         {
             foreach (ItemSlot item in materials)
             {
                 itemContainer.RemoveQuantity(item, item.quantity);
             }
             itemContainer.AddItem(output);
         }
     }
 }
        public void Craft(IItemContainer inventory)
        {
            if (CanCraft(inventory))
            {
                foreach (var itemAmount in materials)
                {
                    /*Item oldItem =*/
                    inventory.RemoveItem(itemAmount.item.Id, itemAmount.itemAmount);
                    //                        if (oldItem != null)
                    //                            oldItem.Destroy();
                }

                int t;
                inventory.AddItem(resault.item.GetCopy(), resault.itemAmount, out t);
                (inventory as Inventory)?.AddItemEvent?.Invoke(resault.item);
            }
        }
Exemple #14
0
        public bool GetRewards(IItemContainer inventory)
        {
            //foreach (var item in Rewards.items)
            //{
            //    int t;
            //    Debug.Log("GetRewards " + item.ItemName);
            //    inventory.AddItem(item, 1,out t);
            //    //                (inventory as Inventory)?.AddItemEvent?.Invoke(item);
            //}
            inventory.AddItem(Rewards.items);
            if (type == QuestType.Gathering)
            {
                InventoryManager.Instance.inventory.RemoveItem(QuestItem, Amount);
            }
            Status = QuestStatus.Compelete;

            return(true);
        }
Exemple #15
0
    private void InitializeInventory(CharacterSpawnParameters obj)
    {
        foreach (var id in obj.items)
        {
            _inventory.AddItem(_itemFactory.Create(ItemType.Module, id));
        }


        _modulesBuffer.Clear();
        _itemsBuffer.Clear();
        _itemsBuffer.AddRange(_inventory.Items);

        foreach (var id in obj.modules)
        {
            if (_itemsBuffer.Count == 0)
            {
                throw new ArgumentException("Requested unused module does not exist in inventory");
            }

            for (int i = 0; i < _itemsBuffer.Count; i++)
            {
                if (_itemsBuffer[i].data.itemId == id)
                {
                    var module = _itemsBuffer[i].instance as ModuleItem;
                    if (module != null)
                    {
                        _modulesBuffer.Add(module.Module);
                        _itemsBuffer.RemoveAt(i);
                        break;
                    }
                    else
                    {
                        throw new ArgumentException("Item is not a module");
                    }
                }
                if (i == _inventory.Items.Count - 1)
                {
                    throw new ArgumentException("Requested unused module does not exist in inventory");
                }
            }
        }
        _weapon.SetModules(_modulesBuffer);
        _inventory.Refresh();
    }
Exemple #16
0
 public void Craft(IItemContainer itemContainer)
 {
     if (CanCraft(itemContainer))
     {
         foreach (ItemAmount itemAmount in materials)
         {
             for (int i = 0; i < itemAmount.amount; i++)
             {
                 Item oldItem = itemContainer.RemoveItem(itemAmount.item.ID);
                 Destroy(oldItem);
             }
         }
         foreach (ItemAmount itemAmount in results)
         {
             for (int i = 0; i < itemAmount.amount; i++)
             {
                 itemContainer.AddItem(Instantiate(itemAmount.item));
             }
         }
     }
 }
    public void Craft(IItemContainer itemContainer)
    {
        if (CanCraft(itemContainer))
        {
            foreach (ItemAmount itemAmount in materials)
            {
                for (int i = 0; i < itemAmount.amount; i++)
                {
                    itemContainer.RemoveItem(itemAmount.item);
                }
            }

            foreach (ItemAmount itemAmount in result)
            {
                for (int i = 0; i < itemAmount.amount; i++)
                {
                    itemContainer.AddItem(itemAmount.item);
                }
            }
        }
    }
Exemple #18
0
    public void Craft(IItemContainer itemContainer)
    {
        if (CanCraft(itemContainer))
        {
            foreach (ItemAmount itemAmount in Materials)
            {
                for (int i = 0; i < itemAmount.Amount; i++)
                {
                    itemContainer.RemoveItem(itemAmount.Item.ItemName);
                }
            }

            foreach (ItemAmount itemAmount in Results)
            {
                for (int i = 0; i < itemAmount.Amount; i++)
                {
                    itemContainer.AddItem(itemAmount.Item);
                }
            }
        }
    }
 public void Craft(IItemContainer itemContainer)
 {
     if (CanCraft(itemContainer))
     {
         foreach (ItemAmount itemAmount in Materials)
         {
             for (int i = 0; i < itemAmount.Amount; i++)
             {
                 Item oldItem = itemContainer.RemoveItem(itemAmount.Item.ID);
                 oldItem.Destroy();
             }
         }
         foreach (ItemAmount itemAmount in Results)
         {
             for (int i = 0; i < itemAmount.Amount; i++)
             {
                 itemContainer.AddItem(Instantiate(itemAmount.Item.GetCopy()));
             }
         }
     }
 }
    public void Craft(IItemContainer itemContainer)
    {
        if (CanCraft(itemContainer))
        {
            foreach (ItemAmount itemAmount in Materials)
            {
                for (int i = 0; i < itemAmount.Amount; i++)
                {
                    GenericItem oldItem = itemContainer.RemoveItem(itemAmount.Item.ID);
                    oldItem.Destroy();
                }
            }

            foreach (ItemAmount itemAmount in Results)
            {
                for (int i = 0; i < itemAmount.Amount; i++)
                {
                    itemContainer.AddItem(itemAmount.Item.GetCopy());
                    FindObjectOfType <AudioManager>().Play("Craft"); //CRAFTING ITEM SOUND
                }
            }
        }
    }
Exemple #21
0
        /// <summary>
        /// Creates a single, unconnected item.
        /// <para>This method will create an empty item, add two new nodes to
        /// the map, update fwd/bwd references and then add the item to the map.
        /// </para>
        /// </summary>
        /// <typeparam name="T">The type of the item that will be created.</typeparam>
        /// <param name="map">The map the item will be added to.</param>
        /// <param name="backwardPos">The backward position of the item.</param>
        /// <param name="forwardPos">The forward position of the item.</param>
        /// <returns>A new, empty item which has been added to the map.</returns>
        internal static T Add <T>(IItemContainer map, Vector3 backwardPos, Vector3 forwardPos)
            where T : PolylineItem, new()
        {
            var backwardNode = map.AddNode(backwardPos, true);
            var forwardNode  = map.AddNode(forwardPos, false);

            var newItem = new T();

            backwardNode.ForwardItem = newItem;
            forwardNode.BackwardItem = newItem;
            newItem.Node             = backwardNode;
            newItem.ForwardNode      = forwardNode;

            // rotation:
            // for the first two nodes, the Rotation of the nodes is just
            // the angle formed by pos2-pos1 and the Z axis
            var rotation = MathEx.GetNodeRotation(backwardPos, forwardPos);

            newItem.Node.Rotation        = rotation;
            newItem.ForwardNode.Rotation = rotation;

            map.AddItem(newItem);
            return(newItem);
        }
        public static void PopulateInventory(this IItemContainer container, MatchCollection itemMatches, MatchCollection keyMatches, MajorModelEntities model)
        {
            container.ClearInventory();

            if (itemMatches != null)
            {
                foreach (Match match in itemMatches)
                {
                    var name     = match.Groups["name"].Value;
                    int quantity = 1;
                    if (match.Groups["quantity"].Success)
                    {
                        quantity = Int32.Parse(match.Groups["quantity"].Value);
                    }
                    if (model.Currencies.ContainsKey(match.Groups["name"].Value))
                    {
                        container.Money[name] = quantity;
                    }
                    else
                    {
                        var item = model.GetItem(name);
                        for (int i = 0; i < quantity; i++)
                        {
                            container.AddItem(item);
                        }

                        if (match.Groups["equipped"].Success)
                        {
                            int?readied = null;
                            if (match.Groups["readiedlength"].Success)
                            {
                                readied = Int32.Parse(match.Groups["readiedlength"].Value);
                            }
                            container.EquipItem(match.Groups["equipped"].Value, readied, item);
                        }
                    }
                }
            }

            if (keyMatches != null)
            {
                foreach (Match match in keyMatches)
                {
                    var name     = match.Groups["name"].Value;
                    int quantity = 1;
                    if (match.Groups["quantity"].Success)
                    {
                        quantity = Int32.Parse(match.Groups["quantity"].Value);
                    }
                    if (quantity > 1)
                    {
                        name = name.Substring(0, name.Length - 1);  // chop off the trailing "s" if there's multiple items.
                    }
                    var item = model.GetItem(name);
                    for (int i = 0; i < quantity; i++)
                    {
                        container.AddItem(item);
                    }
                }
            }
        }
    public void AddToInventory()
    {
        ItemSlot tempItemSlot = new ItemSlot(testItem, 2);

        inventory.AddItem(tempItemSlot);
    }