Пример #1
0
    public void AddItem(Item newItem)
    {
        item = newItem;

        //removeButton.interactable = true;
        Amount.gameObject.SetActive(newItem.category == Category.Weapon ? true : false);
        Icon.sprite  = item.icon;
        Icon.enabled = true;
        if (onItemUsedCallback != null)
        {
            onItemUsedCallback.Invoke();
        }
    }
Пример #2
0
        // 아이템 사용
        public void Use(InventorySlot usedSlot, SlotItem usedItem)
        {
            // 사용아이템일 때
            if (usedItem is ICommon)        //IUsable 인터페이스를 지원하는지 확인
            {
                ICommon usableItem = usedItem as ICommon;
                //사용 이벤트가 있을 경우 실행

                if (usableItem.Usable)
                {
                    usableItem.UseEvent?.Invoke(usedItem);
                    OnItemUsed?.Invoke(usedItem);
                }
            }

            // 장비템아이일 때
            else if (usedItem is IEquipment)
            {
                IEquipment equipment = usedItem as IEquipment;

                // 장착
                if (equipment.Usable)
                {
                    if (equipment.TargetSlot.Item == null)
                    {
                        Move(usedItem, equipment.TargetSlot);   // target Slot 지정안하면 오류
                    }
                    else
                    {
                        Switch(usedItem, equipment.TargetSlot.Item);
                    }

                    equipment.UseEvent?.Invoke(usedItem);
                    equipment.TargetSlot.slotManager.Refresh(usedItem.Tab);
                    OnItemUsed?.Invoke(usedItem);
                }
            }
            // 소비아이템일 때

            else if (usedItem is Consum)
            {
                Consum consum = usedItem as Consum;

                if (consum.Usable)
                {
                    // 개수 -1
                    usedItem.Count--;
                    if (usedItem.Count < 1)
                    {
                        usedItem.Tab.Remove(usedItem);
                    }


                    consum.UseEvent?.Invoke(usedItem);
                    OnItemUsed?.Invoke(usedItem);
                }
            }
        }
Пример #3
0
        public void Receive(UseItem useItemAction)
        {
            UseItemEventArgs useItemEventArgs = new UseItemEventArgs(this, useItemAction);

            OnUseItem?.Invoke(this, useItemEventArgs);

            // TODO

            ItemUsedEventArgs itemUsedEventArgs = new ItemUsedEventArgs(this, useItemAction);

            OnItemUsed?.Invoke(this, itemUsedEventArgs);
        }
Пример #4
0
 /// <summary>
 /// Uses the item and executes its effect.
 /// </summary>
 public virtual void UseItem(AudioSource audioSource)
 {
     OnItemUsed?.Invoke(this);
     //if there is an audio source, try playing a sound.
     if (audioSource)
     {
         //attempt using the unique sound.
         if (useSound)
         {
             useSound.Play(audioSource);
             return;
         }
         //otherwise try using the item type's fallback use sound.
         var audio = _itemType.FallbackUseSound;
         if (audio)
         {
             audio.Play(audioSource);
         }
     }
 }
Пример #5
0
    protected bool UseItem(Item.Type type)
    {
        bool used       = false;
        int  amountUsed = 0;

        switch (type)
        {
        default: break;

        case Item.Type.RepairKit:
            used       = true;
            amountUsed = 1;
            break;
        }
        if (used)
        {
            TimerTracker.SetTimer(itemUseCooldownTimerID, itemUseCooldownDuration);
            OnItemUsed?.Invoke(type, amountUsed);
        }
        return(used);
    }
Пример #6
0
        public sealed override void OnActionStarted()
        {
            //Call the item used delegate
            //If this is set to perform Double/Triple Dip, this will occur after getting the number of Item turns
            //This allows the correct number of item turns to
            OnItemUsed?.Invoke();

            //Get remaining item turn count minus 1
            //Get this here, as the property will automatically be removed by the base behavior for safety
            int dipTurns = User.EntityProperties.GetAdditionalProperty <int>(AdditionalProperty.DipItemTurns) - 1;

            //Perform base behavior
            base.OnActionStarted();

            //If there are items left to use, subtract 1 from the number of turns used and adjust the dip count
            //Subtracting preserves the turn count and works well with other methods of changing turn count (Fast Status, etc.)
            if (dipTurns > 0)
            {
                User.SetTurnsUsed(User.TurnsUsed - 1);
                User.EntityProperties.AddAdditionalProperty(AdditionalProperty.DipItemTurns, dipTurns);
            }
        }