forked from stevefan1999-personal/rustpseudo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdventCalendar.cs
188 lines (171 loc) · 4.96 KB
/
AdventCalendar.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using System;
using System.Collections.Generic;
using ConVar;
using Network;
using UnityEngine;
using UnityEngine.Assertions;
public class AdventCalendar : BaseCombatEntity
{
[Serializable]
public class DayReward
{
public ItemAmount[] rewards;
}
public int startMonth;
public int startDay;
public DayReward[] days;
public GameObject[] crosses;
public static List<AdventCalendar> all = new List<AdventCalendar>();
public static Dictionary<ulong, List<int>> playerRewardHistory = new Dictionary<ulong, List<int>>();
public static readonly Phrase CheckLater = new Phrase("adventcalendar.checklater", "You've already claimed today's gift. Come back tomorrow.");
public static readonly Phrase EventOver = new Phrase("adventcalendar.eventover", "The Advent Calendar event is over. See you next year.");
public GameObjectRef giftEffect;
public GameObjectRef boxCloseEffect;
public override bool OnRpcMessage(BasePlayer player, uint rpc, Message msg)
{
TimeWarning val = TimeWarning.New("AdventCalendar.OnRpcMessage", 0);
try
{
if (rpc == 1911254136 && (Object)(object)player != (Object)null)
{
Assert.IsTrue(player.isServer, "SV_RPC Message is using a clientside player!");
if (Global.developer > 2)
{
Debug.Log((object)string.Concat("SV_RPCMessage: ", player, " - RPC_RequestGift "));
}
TimeWarning val2 = TimeWarning.New("RPC_RequestGift", 0);
try
{
TimeWarning val3 = TimeWarning.New("Conditions", 0);
try
{
if (!RPC_Server.CallsPerSecond.Test(1911254136u, "RPC_RequestGift", this, player, 1uL))
{
return true;
}
if (!RPC_Server.IsVisible.Test(1911254136u, "RPC_RequestGift", this, player, 3f))
{
return true;
}
}
finally
{
((IDisposable)val3)?.Dispose();
}
try
{
val3 = TimeWarning.New("Call", 0);
try
{
RPCMessage rPCMessage = default(RPCMessage);
rPCMessage.connection = msg.connection;
rPCMessage.player = player;
rPCMessage.read = msg.get_read();
RPCMessage msg2 = rPCMessage;
RPC_RequestGift(msg2);
}
finally
{
((IDisposable)val3)?.Dispose();
}
}
catch (Exception ex)
{
Debug.LogException(ex);
player.Kick("RPC Error in RPC_RequestGift");
}
}
finally
{
((IDisposable)val2)?.Dispose();
}
return true;
}
}
finally
{
((IDisposable)val)?.Dispose();
}
return base.OnRpcMessage(player, rpc, msg);
}
public override void ServerInit()
{
base.ServerInit();
all.Add(this);
}
public override void DestroyShared()
{
all.Remove(this);
base.DestroyShared();
}
public void AwardGift(BasePlayer player)
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
DateTime now = DateTime.Now;
int num = now.Day - startDay;
if (now.Month == startMonth && num >= 0 && num < days.Length)
{
if (!playerRewardHistory.ContainsKey(player.userID))
{
playerRewardHistory.Add(player.userID, new List<int>());
}
playerRewardHistory[player.userID].Add(num);
Effect.server.Run(giftEffect.resourcePath, ((Component)player).get_transform().get_position());
if (num >= 0 && num < crosses.Length)
{
Effect.server.Run(boxCloseEffect.resourcePath, ((Component)this).get_transform().get_position() + Vector3.get_up() * 1.5f);
}
DayReward dayReward = days[num];
for (int i = 0; i < dayReward.rewards.Length; i++)
{
ItemAmount itemAmount = dayReward.rewards[i];
player.GiveItem(ItemManager.CreateByItemID(itemAmount.itemid, Mathf.CeilToInt(itemAmount.amount), 0uL), GiveItemReason.PickedUp);
}
}
}
public bool WasAwardedTodaysGift(BasePlayer player)
{
if (!playerRewardHistory.ContainsKey(player.userID))
{
return false;
}
DateTime now = DateTime.Now;
if (now.Month != startMonth)
{
return true;
}
int num = now.Day - startDay;
if (num < 0 || num >= days.Length)
{
return true;
}
if (playerRewardHistory[player.userID].Contains(num))
{
return true;
}
return false;
}
[RPC_Server]
[RPC_Server.IsVisible(3f)]
[RPC_Server.CallsPerSecond(1uL)]
public void RPC_RequestGift(RPCMessage msg)
{
BasePlayer player = msg.player;
if (WasAwardedTodaysGift(player))
{
player.ShowToast(1, CheckLater);
}
else
{
AwardGift(player);
}
}
}