-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderedDropSystem.cs
More file actions
140 lines (120 loc) · 4.24 KB
/
OrderedDropSystem.cs
File metadata and controls
140 lines (120 loc) · 4.24 KB
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
136
137
138
139
140
using System.Collections.Generic;
using UnityEngine;
using PaxDrops.Configs;
namespace PaxDrops.MrStacks
{
/// <summary>
/// Generates ordered Mr. Stacks drops from the dedicated 3x3 menu tier config.
/// </summary>
public static class OrderedDropSystem
{
public sealed class OrderedDropItem
{
public string ItemId { get; }
public int Quantity { get; }
public bool IsValuable { get; }
public OrderedDropItem(string itemId, int quantity, bool isValuable)
{
ItemId = itemId;
Quantity = quantity;
IsValuable = isValuable;
}
}
public sealed class OrderedDropPackage
{
public OrderedDropConfig.OrderedTier Tier { get; set; }
public int CashAmount { get; set; }
public List<OrderedDropItem> Items { get; } = new List<OrderedDropItem>();
public List<string> ToFlatList()
{
var flatList = new List<string>
{
$"cash:{CashAmount}"
};
foreach (var item in Items)
{
flatList.Add($"{item.ItemId}:{item.Quantity}");
}
return flatList;
}
public override string ToString()
{
var parts = new List<string>();
foreach (var item in Items)
{
parts.Add($"{item.ItemId} x{item.Quantity}");
}
return $"{OrderedDropConfig.GetTierName(Tier)} => ${CashAmount} + [{string.Join(", ", parts)}]";
}
}
private static readonly HashSet<string> MultiQuantityItems = new HashSet<string>
{
"meth",
"liquidmeth",
"babyblue",
"bikercrank",
"highqualitypseudo",
"cocaine",
"pgr",
"sourdiesel",
"m1911mag",
"cocainebase",
"phosphorus",
"liquidglass",
"granddaddypurple",
"brick",
"testweed",
"granddaddypurpleseed",
"baggie",
"cuke",
"chili",
"paracetamol",
"mouthwash"
};
public static OrderedDropPackage GenerateDropPackage(OrderedDropConfig.OrderedTier tier)
{
var package = new OrderedDropPackage
{
Tier = tier,
CashAmount = OrderedDropConfig.GetCashAmount(tier)
};
var valuableIds = TakeRandomDistinct(OrderedDropConfig.GetValuableItems(tier), UnityEngine.Random.Range(1, 3));
var fillerIds = TakeRandomDistinct(OrderedDropConfig.GetFillerItems(tier), UnityEngine.Random.Range(2, 4));
foreach (var itemId in valuableIds)
{
package.Items.Add(new OrderedDropItem(itemId, GetItemQuantity(itemId, true), true));
}
foreach (var itemId in fillerIds)
{
package.Items.Add(new OrderedDropItem(itemId, GetItemQuantity(itemId, false), false));
}
Logger.Debug($"Generated ordered Mr. Stacks package: {package}", "OrderedDropSystem");
return package;
}
private static List<string> TakeRandomDistinct(IReadOnlyList<string> pool, int count)
{
var workingPool = new List<string>(pool);
var selected = new List<string>();
int targetCount = Mathf.Min(count, workingPool.Count);
for (int i = 0; i < targetCount; i++)
{
int randomIndex = UnityEngine.Random.Range(0, workingPool.Count);
selected.Add(workingPool[randomIndex]);
workingPool.RemoveAt(randomIndex);
}
return selected;
}
private static int GetItemQuantity(string itemId, bool isValuable)
{
if (!MultiQuantityItems.Contains(itemId))
{
return 1;
}
if (isValuable)
{
return UnityEngine.Random.Range(1, 3);
}
return UnityEngine.Random.Range(1, 3);
}
}
}