Esempio n. 1
0
        private bool IsEffectable(ConsumableData consumableData)
        {
            switch (consumableData)
            {
            case HealingKitData healingKitData:
                float restorableHealth = MaximumHealth - CurrentHealth;
                float restorableShield = MaximumShield - CurrentShield;
                if (restorableHealth > 0 && healingKitData.HealthRestoreAmount > 0 ||
                    restorableShield > 0 && healingKitData.ShieldRestoreAmount > 0)
                {
                    return(true);
                }
                break;

            default:
                Debug.LogError($"관리되지 않고 있는 {nameof(ConsumableData)}입니다, {consumableData.GetType().Name}");
                break;
            }

            return(false);
        }
Esempio n. 2
0
        private void ConsumeItem(ConsumableData consumableData)
        {
            if (consumableData == null)
            {
                Debug.LogError($"사용하려고 하는 {nameof(ConsumableData)}가 null입니다");
                return;
            }

            // 아이템 사용이 의미 있는지 검사
            if (IsEffectable(consumableData) == false)
            {
                // TODO: 사용할 수 없는 아이템 사운드 재생, UI 텍스트 안내
                Debug.LogWarning($"Not effectable");
                return;
            }

            // ItemContainer에 사용하려는 아이템이 있는지 검사
            int targetSlot = ItemContainer.FindMatchItemSlotFromLast(consumableData.ItemName);

            if (targetSlot == -1)
            {
                Debug.LogWarning($"사용하려고 하는 아이템이 {nameof(ItemContainer)}에 없습니다, {nameof(consumableData.ItemName)}: {consumableData.ItemName}");
                return;
            }
            ItemContainer.SubtrackItemAtSlot(targetSlot);

            // 사용 효과 적용
            switch (consumableData)
            {
            case HealingKitData healingKit:
                CurrentHealth += healingKit.HealthRestoreAmount;
                CurrentShield += healingKit.ShieldRestoreAmount;
                break;

            default:
                Debug.LogWarning($"관리되지 않고 있는 {nameof(ConsumableData)}입니다, {consumableData.GetType().Name}");
                return;
            }
        }