-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DecayDrops.cs
86 lines (77 loc) · 2.63 KB
/
DecayDrops.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Oxide.Plugins
{
[Info("DecayDrops", "decay.dev", "0.1.0")]
[Description("managed supply drops, https://decay.dev/drops")]
public class DecayDrops : RustPlugin
{
private ConfigData configData;
private Queue<SupplySignal> signals;
private bool init = false;
private void OnServerInitialized()
{
signals = new Queue<SupplySignal>();
init = true;
}
void OnExplosiveThrown(BasePlayer player, BaseEntity entity)
{
if (!init || entity == null || !(entity is SupplySignal)) return;
signals.Enqueue(entity as SupplySignal);
}
void OnExplosiveDropped(BasePlayer player, BaseEntity entity)
{
if (!init || entity == null || !(entity is SupplySignal)) return;
signals.Enqueue(entity as SupplySignal);
}
void OnEntitySpawned(BaseNetworkable entity)
{
if (entity == null) return;
var b = entity.GetComponent<BaseEntity>();
if (b == null) return;
if (b is CargoPlane)
{
var plane = b as CargoPlane;
plane.secondsToTake = configData.flightDuration;
}
else if (b is SupplyDrop)
{
var drop = b as SupplyDrop;
var v = drop.GetDropVelocity();
drop.RemoveParachute();
drop.MakeLootable();
UnityEngine.Vector3 dropPosition;
if (signals.Count == 0)
{
dropPosition = drop.GetDropPosition();
}
else
{
var signal = signals.Dequeue();
dropPosition = signal.transform.position;
signal.Kill();
}
drop.transform.position = new UnityEngine.Vector3(dropPosition.x, dropPosition.y + 10f, dropPosition.z);
}
}
protected override void LoadConfig()
{
base.LoadConfig();
configData = Config.ReadObject<ConfigData>();
Config.WriteObject(configData, true);
}
protected override void LoadDefaultConfig()
{
LoadConfig();
}
private class ConfigData
{
[JsonProperty(PropertyName = "flight_duration")]
public float flightDuration { get; set; }
[JsonProperty(PropertyName = "drop_duration")]
public float dropDuration { get; set; }
}
}
}