コード例 #1
0
    public void Apply(ItemStack stack)
    {
        int           numItems = stack.held.Count;
        Item          toApply  = stack.held[numItems - 1];
        ApplyableItem apply    = toApply.applyable;

        if (apply == null)
        {
            Debug.LogError($"Couldn't apply item at index {stack.position}, last item has no ApplyableItem component");
            return;
        }

        apply.Apply(monster);
        monster.energy -= 100;

        //Remove the item
        Destroy(apply.gameObject);

        if (numItems <= 1) //Potential error case for 0?
        {
            //Clear the list, garbage collection should get the rest
            items[stack.position] = null;
        }
        else
        {
            //Cut last item, set new count
            stack.held.RemoveAt(numItems - 1);
            stack.count       = numItems - 1;
            stack.lastUpdated = updateCounter;
        }
    }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        if (this.type == 0)
        {
            Debug.LogError("An item is set to have no type! Please use ItemType.MISC if you have misc items.", this);
        }

        applyable  = GetComponent <ApplyableItem>();
        targetable = GetComponent <TargetableItem>();
        equipable  = GetComponent <EquipableItem>();
        melee      = GetComponent <MeleeWeapon>();
        ranged     = GetComponent <RangedWeapon>();

        //Quick check for components, better here than later
        CanEquip  = (equipable != null);
        CanApply  = (applyable != null);
        CanTarget = (targetable != null);
        CanMelee  = (melee != null);
        CanRanged = (ranged != null);

        AddEffect(effects.list.Select(x => x.Instantiate()).ToArray());
    }