Inheritance: ScriptableObject
    /**
     * Add the given item to the slot
     */
    public void AddItem(Pickable pickable)
    {
        _pickable                = pickable;
        _currentItem             = _pickable.GetScriptableItem();
        _icon.sprite             = _pickable.GetScriptableItem().GetRegularIcon();
        _icon.enabled            = true;
        _itemButton.interactable = true;

        if (_removeButton != null && _pickable is Ingestible)
        {
            _removeButton.interactable = true;
        }
        if (pickable is Weapon)
        {
            Color color = _itemButton.image.color;
            color.a = _WEAPON_SLOT_FILLED_ALPHA;
            _itemButton.image.color = color;

            if (((Weapon)pickable).IsCurrent())
            {
                MarkAsCurrent();
            }
            else
            {
                UnmarkAsCurrent();
            }
        }
    }
Exemplo n.º 2
0
    public bool Add(List <ContainerItem> itemsToAdd)
    {
        if (!CanAdd(itemsToAdd))
        {
            return(false);
        }

        foreach (var addItem in itemsToAdd)
        {
            ScriptableItem key = addItem.Key;

            // Add to existing stack
            if (!addItem.item.IsUnique && Items.ContainsKey(key))
            {
                ContainerItem cItem;
                Items.TryGetValue(key, out cItem);
                cItem.count += addItem.count;
                Items[key]   = cItem;
            }
            else
            { // Add a new stack
                Items.Add(addItem.Key, addItem);
            }
        }
        return(true);
    }
Exemplo n.º 3
0
 private void OnPillsGrab(ScriptableItem item)
 {
     if (inventory.Bag.Contains(item) && item.ID == ListOfItems.PillBottle)
     {
         Victory();
     }
 }
Exemplo n.º 4
0
    public static void CreateItems()
    {
        string[] languages = { "deu", "eng", "fra", "ita", "rus", "spa" };

        string[] xItems = Directory.GetFiles("Assets/Xml/deu/items", "*.xml");

        Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath("Assets/Sprites/objects.png").OfType <Sprite>().ToArray();

        for (int i = 0; i < xItems.Length; i++)
        {
            ScriptableItem newItem = new ScriptableItem();
            // ID
            newItem.ID = Path.GetFileNameWithoutExtension(xItems[i]);

            // Sprite and SpriteViewer
            for (int j = 0; j < sprites.Length; j++)
            {
                //Sprite
                if (sprites[j].name == newItem.ID)
                {
                    newItem.sprite = sprites[j];
                }
                //SpriteViewer
                if (sprites[j].name == (newItem.ID + "_v"))
                {
                    newItem.spriteViewer = sprites[j];
                }
            }

            // Names and Descriptions
            for (int j = 0; j < languages.Length; j++)
            {
                string[] xLanguageItems = Directory.GetFiles("Assets/Xml/" + languages[j] + "/items", "*.xml");

                XmlDocument xData = new XmlDocument();
                xData.Load(xLanguageItems[i]);

                // Name
                XmlNode xObject = xData.SelectSingleNode("object");
                newItem.names.Add(xObject.Attributes["name"].Value);

                // Description
                string      description   = "";
                XmlNodeList xDescriptions = xData.SelectNodes("object/description/command");

                foreach (XmlNode xCommand in xDescriptions)
                {
                    string[] commandTokens = xCommand.InnerText.Split('"');
                    if (commandTokens[0] == "text ")
                    {
                        description += (commandTokens[1] + " ");
                    }
                }
                newItem.descriptions.Add(description);
            }

            AssetDatabase.CreateAsset(newItem, "Assets/Resources/ScriptableObjects/" + newItem.ID + ".asset");
            AssetDatabase.Refresh();
        }
    }
Exemplo n.º 5
0
    public void Equip(ScriptableItem itemToEquip)
    {
        // Instantiate graphic
        equippedItemGameObject = GameObject.Instantiate(itemToEquip.graphic);

        // Attach to parent bone
        equippedItemGameObject.transform.SetParent(m_boneReference);

        // Apply local position, rotation and scale
        equippedItemGameObject.transform.localPosition    = itemToEquip.instantiatedPosition;
        equippedItemGameObject.transform.localEulerAngles = new Vector3(
            itemToEquip.instantiatedRotation.x,
            itemToEquip.instantiatedRotation.y,
            itemToEquip.instantiatedRotation.z
            );
        equippedItemGameObject.transform.localScale = itemToEquip.instantiatedScale;

        equippedItem = itemToEquip;

        // @ If equipment is a weapon, update Weapon_ID parameter
        ScriptableWeapon weapon = (ScriptableWeapon)equippedItem;

        if (weapon != null && weapon.weaponType != null)
        {
            m_owner.GetComponent <Animator>().SetInteger(Constants.WEAPON_ID, (int)weapon.weaponType);
        }
    }
Exemplo n.º 6
0
    public bool Remove(List <ContainerItem> itemsToRemove)
    {
        if (!CanRemove(itemsToRemove))
        {
            return(false);
        }

        foreach (var removeItem in itemsToRemove)
        {
            ScriptableItem key = removeItem.Key;

            ContainerItem cItem;
            Items.TryGetValue(key, out cItem);
            cItem.count -= removeItem.count;

            if (cItem.count == 0)
            {
                Items.Remove(key);
            }
            else
            {
                Items[key] = cItem;
            }
        }
        return(true);
    }
    // Set our rarity outline color from scriptable item.
    private void SetRarityColor(ScriptableItem slot)
    {
        switch (slot.rarity)
        {
        case ScriptableItem.ItemRarity.Poor:
            raritySlot.rarityOutline.color = Color.grey;
            break;

        case ScriptableItem.ItemRarity.Common:
            raritySlot.rarityOutline.color = Color.white;
            break;

        case ScriptableItem.ItemRarity.Uncommon:
            raritySlot.rarityOutline.color = Color.green;
            break;

        case ScriptableItem.ItemRarity.Rare:
            raritySlot.rarityOutline.color = Color.blue;
            break;

        case ScriptableItem.ItemRarity.Epic:
            raritySlot.rarityOutline.color = Color.magenta;
            break;

        case ScriptableItem.ItemRarity.Legendary:
            raritySlot.rarityOutline.color = Color.yellow;
            break;
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Atributes the necessary properties to the item to be examined and
    /// positions it relatively to the camera that will render it
    /// </summary>
    /// <param name="item">Item to be examined</param>
    /// <param name="examineCamera">Camera that will render the item</param>
    private void SetExamineItem(ScriptableItem item, Camera examineCamera)
    {
        // Instantiates the item that player will interact with
        itemObject      = MonoBehaviour.Instantiate(item.Prefab);
        itemObject.name = "Item In Examine";
        // Sets the object and its children to the layer that must be
        // rendered by the camera

        RecursivelySetLayer(itemObject, 12);


        // Puts the item in front of the camera
        // The item's Z axis point towards the camera
        itemObject.transform.position = examineCamera.transform.position +
                                        examineCamera.transform.forward;
        parent        = new GameObject();
        parent.name   = "Examine Set";
        itemTransform = itemObject.transform;
        // Makes the item parent position the same as the item position
        parent.transform.position = itemTransform.position;
        itemTransform.parent      = parent.transform;
        light.transform.parent    = parent.transform;
        // Points parent to the camera
        itemTransform.parent.LookAt(examineCamera.transform);
        light.transform.position  = itemTransform.position;
        light.transform.position += itemTransform.parent.forward * 5;
        light.transform.position += itemTransform.parent.up * -4;
        light.transform.LookAt(itemTransform);
    }
Exemplo n.º 9
0
    public void Cmd_UCE_Admin_GiveItem(string adminTargets, string adminTargetName, int adminValue, string adminItemName)
    {
        if (player.UCE_adminLevel <= 0)
        {
            return;
        }

        ScriptableItem item = getItem(adminItemName);

        if (item == null)
        {
            return;
        }

        List <Player> players = new List <Player>();

        players = getPlayerTargets(adminTargets, adminTargetName);

        foreach (Player plyr in players)
        {
            if (plyr.InventoryCanAdd(new Item(item), adminValue) &&
                plyr.InventoryAdd(new Item(item), adminValue))
            {
                plyr.UCE_TargetAddMessage("[Admin] You just received " + item.name + " x" + adminValue.ToString());
            }
        }
    }
Exemplo n.º 10
0
    void Update()
    {
        Player player = Player.localPlayer;

        // use collider point(s) to also work with big entities
        if (player != null &&
            player.target != null &&
            player.target is Npc npc &&
            Utils.ClosestDistance(player, player.target) <= player.interactionRange)
        {
            // instantiate/destroy enough slots
            List <ScriptableQuest> questsAvailable = npc.quests.QuestsVisibleFor(player);
            UIUtils.BalancePrefabs(slotPrefab.gameObject, questsAvailable.Count, content);

            // refresh all
            for (int i = 0; i < questsAvailable.Count; ++i)
            {
                ScriptableQuest npcQuest = questsAvailable[i];
                UINpcQuestSlot  slot     = content.GetChild(i).GetComponent <UINpcQuestSlot>();

                // find quest index in original npc quest list (unfiltered)
                int npcIndex = npc.quests.GetIndexByName(questsAvailable[i].name);

                // find quest index in player quest list
                int questIndex = player.quests.GetIndexByName(npcQuest.name);
                if (questIndex != -1)
                {
                    // running quest: shows description with current progress
                    // instead of static one
                    Quest          quest    = player.quests.quests[questIndex];
                    ScriptableItem reward   = npcQuest.rewardItem;
                    bool           hasSpace = reward == null || player.inventory.CanAdd(new Item(reward), 1);

                    // description + not enough space warning (if needed)
                    slot.descriptionText.text = quest.ToolTip(player);
                    if (!hasSpace)
                    {
                        slot.descriptionText.text += "\n<color=red>Not enough inventory space!</color>";
                    }

                    slot.actionButton.interactable = player.quests.CanComplete(quest.name);
                    slot.actionButton.GetComponentInChildren <Text>().text = "Complete";
                    slot.actionButton.onClick.SetListener(() => {
                        player.quests.CmdComplete(npcIndex);
                        panel.SetActive(false);
                    });
                }
                else
                {
                    // new quest
                    slot.descriptionText.text      = new Quest(npcQuest).ToolTip(player);
                    slot.actionButton.interactable = true;
                    slot.actionButton.GetComponentInChildren <Text>().text = "Accept";
                    slot.actionButton.onClick.SetListener(() => {
                        player.quests.CmdAccept(npcIndex);
                    });
                }
            }
        }
Exemplo n.º 11
0
 // -----------------------------------------------------------------------------------
 // UCE_checkHasItem
 // -----------------------------------------------------------------------------------
 public bool UCE_checkHasItem(Player player, ScriptableItem item)
 {
     if (item == null)
     {
         return(true);
     }
     return(player.inventory.Count(new Item(item)) >= 1);
 }
Exemplo n.º 12
0
    public long           summonedExperience; // stored in item while summonable unsummoned

    // constructors
    public Item(ScriptableItem data)
    {
        hash               = data.name.GetStableHashCode();
        summoned           = null;
        summonedHealth     = data is SummonableItem ? ((SummonableItem)data).summonPrefab.healthMax : 0;
        summonedLevel      = data is SummonableItem ? 1 : 0;
        summonedExperience = 0;
    }
Exemplo n.º 13
0
    /// <summary>
    /// Coroutine that shows an image of an obtained item
    /// </summary>
    /// <param name="item">Item to display the image</param>
    /// <returns>Returns a new waitforseconds</returns>
    private IEnumerator ShowImageCoroutine(ScriptableItem item)
    {
        image.sprite = item.Icon;
        canvas.SetActive(true);
        yield return(new WaitForSeconds(2f));

        canvas.SetActive(false);
    }
    public long           petExperience; // stored in item while pet unsummoned

    // constructors
    public Item(ScriptableItem data)
    {
        hash          = data.name.GetStableHashCode();
        petSummoned   = null;
        petHealth     = data is PetItem ? ((PetItem)data).petPrefab.healthMax : 0;
        petLevel      = data is PetItem ? 1 : 0;
        petExperience = 0;
    }
Exemplo n.º 15
0
 // -----------------------------------------------------------------------------------
 // UCE_checkHasItem
 // -----------------------------------------------------------------------------------
 public bool UCE_checkHasItem(ScriptableItem item)
 {
     if (item == null)
     {
         return(true);
     }
     return(InventoryCount(new Item(item)) >= 1);
 }
Exemplo n.º 16
0
    public long            summonedExperience; // stored in item while summonable unsummoned

    // constructors
    public Item(ScriptableItem data)
    {
        hash               = data.name.GetStableHashCode();
        durability         = data.maxDurability;
        summoned           = null;
        summonedHealth     = data is SummonableItem summonable ? summonable.summonPrefab.health.max : 0;
        summonedLevel      = data is SummonableItem ? 1 : 0;
        summonedExperience = 0;
    }
    // -----------------------------------------------------------------------------------
    // MaxBuyAmount
    // -----------------------------------------------------------------------------------
    private int MaxBuyAmount(Player player, ScriptableItem item)
    {
        if (item.maxStack == 1)
        {
            return(1);
        }

        return(Mathf.Min((int)(player.gold / item.buyPrice), item.maxStack));
    }
Exemplo n.º 18
0
 /// <summary>
 /// Constructor, that creates a new instance of ItemExaminer and
 /// initializes its fields
 /// </summary>
 /// <param name="speed">Speen of rotation of the object</param>
 /// <param name="item">Object to be examined</param>
 /// <param name="examineCamera">Camera used to render the object</param>
 public ItemExaminer(float speed, ScriptableItem item, Camera examineCamera)
 {
     SetLights();
     SetExamineItem(item, examineCamera);
     // Set the speed rotation value
     this.speed         = speed;
     verticalRotation   = 0f;
     horizontalRotation = 0f;
 }
Exemplo n.º 19
0
    public void Equip(EquipmentSlotType slotType, ScriptableItem itemToEquip)
    {
        GetSlot(slotType).equipmentSlot.Equip(itemToEquip);

        // @ Animator Updates
        GetComponent <Animator>().SetBool(Constants.IS_DUAL_WIELDING, IsDualWielding());

        // @ Notify subscribed scripts
        EquipEvent.Invoke();
    }
Exemplo n.º 20
0
    void OnEquipmentChanged(SyncListItemSlot.Operation op, int index, ItemSlot oldSlot, ItemSlot newSlot)
    {
        ScriptableItem oldItem = oldSlot.amount > 0 ? oldSlot.item.data : null;
        ScriptableItem newItem = newSlot.amount > 0 ? newSlot.item.data : null;

        if (oldItem != newItem)
        {
            RefreshLocation(index);
        }
    }
Exemplo n.º 21
0
 private void Start()
 {
     for (int i = 0; i < itemList.Count - 1; i++)
     {
         scriptable = (ScriptableItem)AssetDatabase.LoadAssetAtPath("Assets/Resources/ScriptableObjects/" + itemList[i] + ".asset", typeof(ScriptableItem));
         GameObject item = new GameObject();
         item.name = itemList[i];
         item.AddComponent <SpriteRenderer>().sprite = scriptable.sprite;
         item.transform.SetParent(this.transform);
     }
 }
Exemplo n.º 22
0
        public static void Open(Object obj)
        {
            if (window != null)
            {
                window.Close();
            }

            window = null;

            scriptable = new ScriptableItem(AssetDatabase.GetAssetPath(obj));
            window     = GetWindow <EditorNodeCanvas>(obj.name);
        }
Exemplo n.º 23
0
    // -----------------------------------------------------------------------------------
    // UCE_getTotalItemCount
    // -----------------------------------------------------------------------------------
    public int UCE_getTotalItemCount(ScriptableItem itemT)
    {
        int totalCount = 0;

        for (int i = 0; i < inventory.Count; ++i)
        {
            if (inventory[i].amount > 0 && inventory[i].item.data == itemT)
            {
                totalCount += inventory[i].amount;
            }
        }
        return(totalCount);
    }
Exemplo n.º 24
0
    private void AddWeaponIfExists(EquipmentSlotType slotType)
    {
        ScriptableItem item = equipmentManager.GetEquippedItem(slotType);

        if (item is ScriptableWeapon)
        {
            weapons.Add(new Weapon(
                            this.gameObject,
                            (ScriptableWeapon)item,
                            equipmentManager.GetEquippedItemGameObject(slotType)
                            ));
        }
    }
Exemplo n.º 25
0
    // -----------------------------------------------------------------------------------
    // UCE_getTotalItemCount
    // -----------------------------------------------------------------------------------
    public int UCE_getTotalItemCount(Player player, ScriptableItem itemT)
    {
        int totalCount = 0;

        for (int i = 0; i < player.inventory.slots.Count; ++i)
        {
            if (player.inventory.slots[i].amount > 0 && player.inventory.slots[i].item.data == itemT)
            {
                totalCount += player.inventory.slots[i].amount;
            }
        }
        return(totalCount);
    }
Exemplo n.º 26
0
    // -----------------------------------------------------------------------------------
    // UCE_removeEquipment
    // Delete a equipped item, just like a inventory item can be deleted by default
    // -----------------------------------------------------------------------------------
    public void UCE_removeEquipment(ScriptableItem item)
    {
        for (int i = 0; i < equipment.slots.Count; ++i)
        {
            ItemSlot slot = equipment.slots[i];

            if (slot.amount > 0 && slot.item.data == item)
            {
                slot.amount--;
                equipment.slots[i] = slot;
                return;
            }
        }
    }
Exemplo n.º 27
0
        static void Edit()
        {
            if (window != null)
            {
                window.Close();
            }

            window = null;


            Object asset = Selection.activeObject;

            scriptable = new ScriptableItem(AssetDatabase.GetAssetPath(asset));
            window     = GetWindow <EditorNodeCanvas>(asset.name);
        }
Exemplo n.º 28
0
    // -----------------------------------------------------------------------------------
    // UCE_checkHasEquipment
    // -----------------------------------------------------------------------------------
    public bool UCE_checkHasEquipment(ScriptableItem item)
    {
        if (item == null)
        {
            return(true);
        }

        foreach (ItemSlot slot in equipment)
        {
            if (slot.amount > 0 && slot.item.data == item)
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 29
0
    // -----------------------------------------------------------------------------------
    // UCE_checkDepletableEquipment
    // -----------------------------------------------------------------------------------
    public bool UCE_checkDepletableEquipment(ScriptableItem item, int amount = 1)
    {
        if (item == null)
        {
            return(true);
        }

        foreach (ItemSlot slot in equipment.slots)
        {
            if (slot.amount > 0 && slot.item.data.maxStack > 1 && slot.amount >= amount && slot.item.data == item)
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 30
0
    // -----------------------------------------------------------------------------------
    // Cmd_UCE_Admin_GiveItem
    // @Client -> @Server
    // -----------------------------------------------------------------------------------
    public void UCE_Admin_GiveItem(string[] parsedArgs)
    {
        string adminTargets    = parsedArgs[0];
        string adminTargetName = parsedArgs[1];
        int    adminValue      = int.Parse(parsedArgs[2]);
        string adminItemName   = parsedArgs[3];

        ScriptableItem item = getItem(adminItemName);

        if (item == null)
        {
            return;
        }

        Cmd_UCE_Admin_GiveItem(adminTargets, adminTargetName, adminValue, adminItemName);

        player.UCE_AddMessage("[Sys] Target(s) received " + item.name + " x" + adminValue.ToString());
    }