예제 #1
0
    public void InstantiateValuableItem(ItemScriptableObject item)
    {
        var itemGameObject = Instantiate(valuableItemPrefab, transform.position, transform.rotation);

        itemGameObject.GetComponent <ValuableItem>().Item = item;
        NetworkServer.Spawn(itemGameObject);
    }
 public void Initialize(ItemScriptableObject newItem)
 {
     item             = newItem;
     iconImage.sprite = newItem.icon;
     aspectRatioFitter.aspectRatio =
         (float)iconImage.sprite.rect.width / (float)iconImage.sprite.rect.height;
 }
예제 #3
0
 public void EmtyItem()
 {
     icon.sprite               = null;
     icon.enabled              = false;
     itemScriptableObject      = null;
     RemoveButton.interactable = false;
 }
예제 #4
0
 //新增一個方法將List的東西刪除
 public void RemoveItem(ItemScriptableObject RemoveItem)
 {
     //將物品移除但不管按哪個格子的移除都是移除第一個同樣的物品
     Items.Remove(RemoveItem);
     //同步呼叫存在onItemChangedCallBack裡的方法
     onItemChangedCallBack.Invoke();
 }
예제 #5
0
    public void Pickup(GameObject itemObject, ItemScriptableObject iso, Vector2Int position)
    {
        currentItems++;
        iso.OnPickup(this);
        itemsInEqGO.Add(itemObject.GetComponent <Item>());

        foreach (var skill in iso.SkillsToLearn)
        {
            gameManager.LearnSkill(skill);
        }

        try { MapManager.map[position.x, position.y].item = null; }
        catch {}

        if (itemObject.GetComponent <Item>().identified == true)
        {
            gameManager.UpdateMessages($"You picked up the <color={iso.I_color}>{iso.I_name}</color>.");
            gameManager.UpdateInventoryQueue($"<color={iso.I_color}>{iso.I_name}</color>");
        }
        else
        {
            gameManager.UpdateMessages($"You picked up the <color=purple>{iso.I_unInName}</color>.");
            gameManager.UpdateInventoryQueue($"<color=purple>{iso.I_unInName}</color>");
        }
        GameManager.manager.ApplyChangesInInventory(null);
        UpdateCapacity();
    }
예제 #6
0
    private void ChooseNewAvailableItem()
    {
        int index = Random.Range(0, myAvailableItems.Length);

        myCurrentItem = myAvailableItems[index];
        itemAvailable = true;
    }
예제 #7
0
 public bool addItemToInventory(ItemScriptableObject item, int amount)
 {
     if (amount > 0)
     {
         if (itemDictionary.Count < inventorySize)
         {
             if (itemDictionary.ContainsKey(item))
             {
                 itemDictionary[item] += amount;
                 ourInventoryChanged();
                 return(true);
             }
             else
             {
                 inventoryVisual.Add(item);
                 itemDictionary.Add(item, amount);
                 ourInventoryChanged();
                 return(true);
             }
         }
     }
     else
     {
         Debug.Log("Trying to add an item of amount " + amount.ToString());
     }
     return(false);
 }
예제 #8
0
 //將物品的icon和移除按鈕顯示在背包介面上的方法
 public void AddItem(ItemScriptableObject newItem)
 {
     itemScriptableObject      = newItem;
     icon.sprite               = newItem.icon;
     icon.enabled              = true;
     RemoveButton.interactable = true;
 }
예제 #9
0
    // Generates an Item
    // Pass in item taken from Open();
    public static ItemScriptableObject Generate(ItemScriptableObject iso)
    {
        GenerateSprite       generateSprite       = new GenerateSprite();
        RandomManager        randomManager        = new RandomManager();
        StatFactory          statFactory          = new ConcreteStatFactory();
        ItemScriptableObject itemScriptableObject = ScriptableObject.CreateInstance <ItemScriptableObject>();

        randomManager.SetAnimationCurve();
        itemScriptableObject.itemSprite   = iso.itemSprite;
        itemScriptableObject.itemName     = iso.itemName;
        itemScriptableObject.itemType     = iso.itemType;
        itemScriptableObject.itemTypeName = iso.itemType.ToString().ToLower();
        itemScriptableObject.rarity       = (ItemObject.Rarity)Mathf.RoundToInt(randomManager.CurveWeightedRandom(randomManager.cumulativeProbability));
        itemScriptableObject.keyword      = (ItemObject.Keywords)Mathf.RoundToInt(randomManager.CurveWeightedRandom(randomManager.cumulativeProbability));
        itemScriptableObject.statCount    = statFactory.GenerateStatAmountForObject(itemScriptableObject.rarity);
        itemScriptableObject.modifierList = new List <Stat>();
        for (int i = 0; i < itemScriptableObject.statCount; i++)
        {
            Stat.StatType statType  = statFactory.GenerateStatType();
            Stat          stat      = statFactory.GetStatObject(statType, itemScriptableObject);
            int           statIndex = DetectStatInList(itemScriptableObject.modifierList, statType);
            if (statIndex != -1)
            {
                itemScriptableObject.modifierList[statIndex].StatValue += stat.StatValue;
                itemScriptableObject.statCount--;
            }
            else
            {
                itemScriptableObject.modifierList.Add(stat);
            }
        }
        itemScriptableObject.itemBackgroundSprite = GenerateSpriteType(BackgroundSprites.backgroundSprites, itemScriptableObject.rarity);
        return(itemScriptableObject);
    }
예제 #10
0
    void Deliver(ItemScriptableObject item)
    {
        if (CanDeliver() && money >= 20)
        {
            money -= 20;

            Pult palette = null;
            int  index   = -1;

            foreach (var p in palettes)
            {
                for (int i = 0; i < p.items.Length; i++)
                {
                    if (p.items[i] == null)
                    {
                        palette = p;
                        index   = i;
                    }
                }
            }

            if (palette == null)
            {
                return;
            }

            palette.items[index] = new Package(item, 6);
            palette.RefreshVisuals();

            moneyText.text = "Money: $" + money.ToString();
        }
    }
예제 #11
0
 public Item(ItemScriptableObject unsafeCopy) : base(unsafeCopy)
 {
     if (data.rottable)
     {
         spoilageTime   = Time.time + data.rotTime;
         returnableTime = Time.time + data.rotTimeReturnable;
     }
 }
예제 #12
0
 public void PickUp(ItemScriptableObject item)
 {
     items.Add(item);
     if (CurrentItem == null)
     {
         nextItem();
     }
 }
예제 #13
0
    private void OnItemAdded(ItemScriptableObject item)
    {
        //Create item
        GameObject newItem = Instantiate(itemInventoryPrefab, inventoryContainer.transform.position, Quaternion.identity);

        newItem.transform.SetParent(inventoryContainer.transform);
        newItem.transform.localScale = Vector3.one;
        newItem.GetComponent <ItemInventoryUI>().SetData(item);
    }
예제 #14
0
    public void AddItemFromChest(ItemScriptableObject iso)
    {
        GameObject g = Instantiate(gameManager.itemSpawner.itemPrefab);

        g.GetComponent <Item>().iso        = iso;
        g.GetComponent <Item>().identified = iso.normalIdentifState;

        itemsInEqGO.Add(g.GetComponent <Item>());
    }
예제 #15
0
 public void SetButton(ItemScriptableObject item, string price, string quantity)
 {
     this.item             = item;
     this.name.text        = item.name;
     this.image.sprite     = item.image;
     this.description.text = item.description;
     this.price.text       = price;
     this.quantity.text    = quantity;
 }
예제 #16
0
    public Package(ItemScriptableObject unsafeCopy, int maxItems) : base(unsafeCopy)
    {
        ItemScriptableObject item = (ItemScriptableObject)DatabaseManager.GetItem(unsafeCopy.id);

        this.data          = item;
        this.data.model    = DatabaseManager.Instance.packagePrefab.GetComponent <ModelSetup>();
        this.data.rottable = false;
        this.maxItems      = this.itemsCount = maxItems;
    }
예제 #17
0
    public Tray(ItemScriptableObject unsafeCopy, Transform[] itemLocations, Carryable[] items)
    {
        ItemScriptableObject item = (ItemScriptableObject)DatabaseManager.GetItem(unsafeCopy.id);

        /*
         * this.data = item;
         * this.data.model = DatabaseManager.Instance.packagePrefab.GetComponent<ModelSetup>();
         * this.data.rottable = false;*/
    }
예제 #18
0
    internal void SetData(ItemScriptableObject item)
    {
        //this.item = Instantiate(item);
        this.item = item;

        if (itemImage != null)
        {
            itemImage.sprite = this.item?.itemSprite;
        }
    }
예제 #19
0
    /// <summary>
    /// Sets item on the tray while spawning it. Returns item that was just removed. Null if no item or null input.
    /// </summary>
    /// <param name="newItem"></param>
    /// <returns></returns>
    public Carryable SetItem(ItemScriptableObject newItemData)
    {
        if (newItemData == null)
        {
            Debug.LogError("New item data is null.");
            return(null);
        }

        return(SetItem(new Carryable(newItemData)));
    }
예제 #20
0
 public override void OnInteract()
 {
     if (VerifyPlayerHasDoll())
     {
         ItemScriptableObject doll           = ItemHandler.instance.useItem();
         GameObject           dollGameObject = Instantiate(doll.prefab, transform.position + new Vector3(0, .1f), transform.rotation * Quaternion.Euler(180, 0, 0));
         Destroy(dollGameObject.GetComponent <ItemPickup>());
         animacao.Init();
     }
 }
 public void RemoveItemByData(ItemScriptableObject data)
 {
     for (int i = 0; i < items.Count; i++)
     {
         if (items[i].ItemData() == data)
         {
             items[i].OnDropItem();
             items.Remove(items[i]);
         }
     }
 }
예제 #22
0
    protected override void Start()
    {
        base.Start();

        for (int i = 0; i < items.Length; i++)
        {
            if (items[i].item == null)
            {
                continue;
            }
            ItemScriptableObject copy = DatabaseManager.GetItem(items[i].item.id) as ItemScriptableObject;
            items[i].item = copy;
        }
    }
예제 #23
0
    public bool AddItem(ItemScriptableObject item)
    {
        if (items.Contains(item))
        {
            return(false);
        }
        if (item.IsValuableItem && this.HasValuableItem)
        {
            return(false);
        }

        this.Items.Add(item);
        return(true);
    }
예제 #24
0
 public bool transferItemFromInventory(ItemScriptableObject item)
 {
     if (weaponGameObjectList.Count < TOOLBAR_SIZE)
     {
         Debug.Log("Trying to remove item from inventory: " + item.itemName);
         if (inventory.removeItemsFromInventory(item, 1))
         {
             Equippable instantiatedItem = Instantiate(item.prefab, weaponSpawnLocation.position, weaponSpawnLocation.rotation, transform).GetComponent <Equippable>();
             weaponGameObjectList.Add(instantiatedItem);
             instantiatedItem.gameObject.SetActive(false);
             return(true);
         }
     }
     return(false);
 }
예제 #25
0
    public ItemScriptableObject useItem()
    {
        if (items.Count < 1)
        {
            return(null);
        }

        ItemScriptableObject currentItem = items[itemIndex];

        items.RemoveAt(itemIndex--);
        Destroy(CurrentItem);
        nextItem();

        return(currentItem);
    }
예제 #26
0
    public override bool Spoil()
    {
        if (data.rottable && Time.time > spoilageTime)
        {
            int garbage = data.garbageValue;
            ItemScriptableObject item = (ItemScriptableObject)DatabaseManager.GetItem("rot");

            data = item;
            data.garbageValue = garbage;

            return(true);
        }

        return(false);
    }
예제 #27
0
 public void putItemIntoHotBar(ItemScriptableObject item)
 {
     Debug.Log("Freaking work " + item);
     Debug.Log("Item " + item.itemName + " made it to visual.");
     if (item.itemType == ItemTypeEnum.USABLE)
     {
         Debug.Log("Trying to equip usable item: " + item.itemName);
         equippedItems.transferItemFromInventory(item);
         displayItemsFromInventory();
     }
     else
     {
         Debug.Log("This item is not equippable " + item.name);
     }
 }
 private void EquipItem()
 {
     equippedItem = InventoryManager.instance.EquipItem();
     if (equippedItem != null)
     {
         firearmEquipped = equippedItem.isFireArm;
         heldItem.GetComponent <MeshFilter>().mesh = equippedItem.itemMesh;
         GetComponent <Animator>().SetInteger("Item", equippedItem.idNum);
     }
     else
     {
         firearmEquipped = false;
         heldItem.GetComponent <MeshFilter>().mesh = null;
         GetComponent <Animator>().SetInteger("Item", -1);
     }
 }
예제 #29
0
    public void DropItem(ItemScriptableObject item)
    {
        switch (item.Type)
        {
        case ItemScriptableObject.ItemType.NORMAL_ITEM:
            break;

        case ItemScriptableObject.ItemType.VALUABLE_ITEM:
            this.InstantiateValuableItem(item);
            this.RemoveItem(item);
            break;

        default:
            break;
        }
    }
예제 #30
0
 public bool removeItemsFromInventory(ItemScriptableObject item, int amount)
 {
     Debug.Log("Looking for " + item.itemName + " in the dictionary");
     if (itemDictionary.ContainsKey(item))
     {
         Debug.Log("Found the item in the dictionary removing " + amount);
         itemDictionary[item] -= amount;
         if (itemDictionary[item] <= 0)
         {
             itemDictionary.Remove(item);
             inventoryVisual.Remove(item);
             ourInventoryChanged();
         }
         return(true);
     }
     return(false);
 }