-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemDrop.cs
135 lines (117 loc) · 3.77 KB
/
ItemDrop.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using SideLoader;
namespace Nm1fiOutward.Drops
{
interface IItemDrop
{
string ItemName { get; }
Item ItemRef { get; }
string DropCountText { get; }
string ToString();
}
[SL_Serialized]
public abstract class ItemDrop : IItemDrop
{
public int ItemID;
public int MinDropCount = 1;
public int MaxDropCount = 1;
public int ActualMaxDropCount => MaxDropCount > MinDropCount ? MaxDropCount : MinDropCount;
public string ItemName
=> ItemRef?.Name ?? $"<unknown {ItemID}>";
public Item ItemRef
=> ResourcesPrefabManager.Instance.GetItemPrefab(ItemID);
public string DropCountText
=> MaxDropCount > MinDropCount ? $"{MinDropCount}-{MaxDropCount}" : MinDropCount.ToString();
public override string ToString()
=> $"{DropCountText}x {ItemName} ({ItemID})";
}
public class GuaranteedDrop : ItemDrop
{
public BasicItemDrop New()
{
return new BasicItemDrop()
{
ItemID = ItemID,
ItemRef = ItemRef,
MinDropCount = MinDropCount,
MaxDropCount = ActualMaxDropCount,
};
}
public bool Modify(BasicItemDrop existing)
{
bool differs = false;
if (existing.MinDropCount != MinDropCount)
{
existing.MinDropCount = MinDropCount;
differs = true;
}
var maxDropCount = ActualMaxDropCount;
if (existing.MaxDropCount != maxDropCount)
{
existing.MaxDropCount = maxDropCount;
differs = true;
}
return differs;
}
}
public abstract class RandomDrop : ItemDrop
{
protected ItemDropChance New(int dropChance)
{
return new ItemDropChance()
{
// int DropChance;
// int ChanceReduction;
// float ChanceRegenDelay;
// int ChanceRegenQty;
ItemID = ItemID,
ItemRef = ItemRef,
MinDropCount = MinDropCount,
MaxDropCount = ActualMaxDropCount,
DropChance = dropChance > 0 ? dropChance : 1,
};
}
public abstract ItemDropChance New(float averageChance);
}
public class AbsoluteRandomDrop : RandomDrop
{
public int DropChance = 1;
public override string ToString()
=> $"Chance: {DropChance}, {base.ToString()}";
public override ItemDropChance New(float averageChance)
{
return base.New(DropChance);
}
public bool Modify(ItemDropChance existing)
{
bool differs = false;
if (existing.MinDropCount != MinDropCount)
{
existing.MinDropCount = MinDropCount;
differs = true;
}
var maxDropCount = ActualMaxDropCount;
if (existing.MaxDropCount != maxDropCount)
{
existing.MaxDropCount = maxDropCount;
differs = true;
}
if (existing.DropChance != DropChance)
{
existing.DropChance = DropChance;
differs = true;
}
return differs;
}
}
public class RelativeRandomDrop : RandomDrop
{
public float RelativeChance = 1f;
public override string ToString()
=> $"Rel.Chance: {RelativeChance:n2}, {base.ToString()}";
public override ItemDropChance New(float averageChance)
{
int chance = (int)(averageChance * RelativeChance + .5f);
return base.New(chance);
}
}
}