forked from PenisBlistashiq/Rust-plugins-236-240-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIQControllerSpawnCars.cs
More file actions
156 lines (143 loc) · 6.35 KB
/
Copy pathIQControllerSpawnCars.cs
File metadata and controls
156 lines (143 loc) · 6.35 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System.Collections.Generic;
using Newtonsoft.Json;
using Rust.Modular;
namespace Oxide.Plugins
{
[Info("IQControllerSpawnCars", "Mercury", "0.0.3")]
[Description("Хочу следовать за трендами блин")]
class IQControllerSpawnCars : RustPlugin
{
// - Исправил NRE
public bool Init = false;
#region Vars
public enum SpawnType
{
TierFull,
ElementsTier
}
#endregion
#region Configuration
private static Configuration config = new Configuration();
private class Configuration
{
[JsonProperty("Выберите тип спавна. 0 - полный спавн по тирам(настраивайте шансы и тиры в листе)(т.е все детали сразу,в разном виде качества). 1 - Спавн отдельных деталей, с ограничениями в количестве и рандомным качеством в зависимости от шанса")]
public SpawnType spawnType;
[JsonProperty("Настройки тиров. Номер тира(1-3) и шанс.")]
public Dictionary<int, int> TierRare = new Dictionary<int, int>();
[JsonProperty("Настройка деталей и их шанс спавна.Шортнейм детали и шанс ее спавна")]
public Dictionary<string, int> ElementSpawnRare = new Dictionary<string, int>();
[JsonProperty("Ограниченное количество спавна деталей. 0 - без ограничений")]
public int LimitSpawnElement;
public static Configuration GetNewConfiguration()
{
return new Configuration
{
spawnType = SpawnType.TierFull,
TierRare = new Dictionary<int, int>
{
[1] = 80,
[2] = 50,
[3] = 25,
},
ElementSpawnRare = new Dictionary<string, int>
{
["carburetor1"] = 80,
["crankshaft1"] = 80,
["sparkplug1"] = 80,
["piston1"] = 80,
["carburetor2"] = 60,
["crankshaft2"] = 60,
["sparkplug2"] = 60,
["piston2"] = 60,
["carburetor3"] = 20,
["crankshaft3"] = 20,
["sparkplug3"] = 20,
["piston3"] = 20,
},
LimitSpawnElement = 0,
};
}
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<Configuration>();
if (config == null) LoadDefaultConfig();
}
catch
{
PrintWarning($"Ошибка чтения #57 конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
protected override void LoadDefaultConfig() => config = Configuration.GetNewConfiguration();
protected override void SaveConfig() => Config.WriteObject(config);
#endregion
private void OnServerInitialized() => Init = true;
void OnEntitySpawned(BaseNetworkable entity)
{
if (!Init) return;
if (entity == null) return;
if (entity is ModularCar)
{
ModularCar Car = entity as ModularCar;
if (Car == null) return;
var CarSetting = config.spawnType;
switch(CarSetting)
{
case SpawnType.TierFull:
{
SpawnFullTier(Car);
break;
}
case SpawnType.ElementsTier:
{
SpawnElementsTier(Car);
break;
}
default: { break; }
}
}
}
#region Metods
void SpawnFullTier(ModularCar Car)
{
var CarSetting = config.TierRare;
if (Car == null) return;
foreach (var Tier in CarSetting)
{
if (!IsRare(Tier.Value)) continue;
if (Car.GetComponentInChildren<VehicleModuleEngine>() == null) continue;
Car?.GetComponentInChildren<VehicleModuleEngine>()?.AdminFixUp(Tier.Key);
}
}
void SpawnElementsTier(ModularCar Car)
{
if (Car == null) return;
var CarSetting = config.ElementSpawnRare;
int LimitElement = (int)(config.LimitSpawnElement != 0 ? config.LimitSpawnElement : Car?.GetComponentInChildren<VehicleModuleEngine>()?.GetContainer()?.inventory.capacity);
for (int j = 0; j < LimitElement; j++)
{
int SlotElemt = UnityEngine.Random.Range(0, (int)(Car?.GetComponentInChildren<VehicleModuleEngine>()?.GetContainer()?.inventory.capacity));
foreach (var TierElement in CarSetting)
{
if (!IsRare(TierElement.Value)) continue;
if (Car?.GetComponentInChildren<VehicleModuleEngine>()?.GetContainer()?.inventory.GetSlot(SlotElemt) != null) continue;
Item ElementCar = ItemManager.CreateByName(TierElement.Key, 1);
if (Car.GetComponentInChildren<EngineStorage>().ItemFilter(ElementCar, j))
ElementCar.MoveToContainer(Car?.GetComponentInChildren<VehicleModuleEngine>()?.GetContainer()?.inventory, j, false);
}
}
}
public bool IsRare(int Rare)
{
if (UnityEngine.Random.Range(0, 100) >= (100 - Rare))
return true;
else return false;
}
#endregion
}
}