all repos — RPG @ 5b0cc0399bcc80945ec61003fc36c07273007cad

Fully functional 3D turn based role playing game coded in C# and base Unity.

Assets/Scripts/Utility/Inventory/ItemInfo.cs (view raw)

 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5[System.Serializable]
 6public class ItemInfo : Action
 7{
 8    public Item item;
 9    public int quantity;
10
11    public ItemInfo(Item item, int quantity)
12    {
13        this.item = item;
14        this.quantity = quantity;
15    }
16
17    public override string Execute(Fighter source, Fighter target, out bool output)
18    {
19        if (item.effect != null)
20        {
21            return AbilityDB.Process(source, item.effect, target, false, out output);
22        }
23        else
24        {
25            output = false;
26            return "This item has no effect in battle!";
27        }
28    }
29
30    public override string ExecuteSafe(Fighter source, Fighter target, out bool output)
31    {
32        if (item.effect != null)
33        {
34            if (quantity == 0)
35            {
36                output = false;
37                return "You don't have any " + item.name + "!";
38            }
39            else
40            {
41                string tmp = Execute(source, target, out output);
42                if (item.consumable && output)
43                {
44                    quantity -= 1;
45                }
46                return tmp;
47            }
48        } else
49        {
50            output = false;
51            return "This item has no effect in battle!";
52        }
53        
54    }
55
56    public override string GetDescription()
57    {
58        return item.description + "\n" + item.effect.GetDescription();
59    }
60
61    public override string ToString()
62    {
63        if(quantity == -1)
64        {
65            return item.name;
66        }
67        return item.name + " : " + quantity;
68    }
69}