Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
    public void Start()
    {
        if (slot_category != Category.Equipment)
        {
            Amount = transform.Find("Amount").GetComponent <Text>();
        }

        Icon = transform.Find("Icon").GetComponent <Image>();

        onItemUsedCallback += UpdateSlot;

        ClearSlot();
    }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
    }
Exemplo n.º 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);
            }
        }