-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.cs
More file actions
216 lines (189 loc) · 6.71 KB
/
Session.cs
File metadata and controls
216 lines (189 loc) · 6.71 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Newtonsoft.Json;
using SlothuExtras;
namespace Slothu
{
class Session
{
public string Boss = "";
public int SessionLength = 1;
public int SessionID = 1;
public string[] Team;
public int Wealth = 0;
public bool Active = false;
public List<string> Loot = new List<string>(100);
public DateTime LastActiveChange = DateTime.Now;
private SocketGuild Guild;
private SocketUser Leader;
private List<SocketUser> Users = new List<SocketUser>();
private static readonly Color EmbedColour = new Color(54, 57, 63);
private SocketCommandContext Context = null;
private String FilePath = @"D:\DiscordBotGuilds\";
public Session()
{
}
public Session(SocketCommandContext Context, SocketUser Member, int SessionID=1, int SessionLength=1)
{
this.Context = Context;
this.SessionID = SessionID;
this.SessionLength = SessionLength;
Users.Add(Member);
Team = new string[Users.Count];
}
public Session(SocketCommandContext Context, string Boss, List<SocketUser> Users, int SessionID, int SessionLength = 1)
{
Guild = Context.Guild;
Leader = Context.Message.Author;
this.Users = Users;
this.Boss = Boss;
this.SessionLength = Math.Clamp(SessionLength, 1, 4);
Team = new string[Users.Count];
Wealth = 0;
Active = true;
this.SessionID = SessionID;
SetTeamMembers();
}
public async Task ViewSession(SocketCommandContext Context)
{
EmbedBuilder Embed = new EmbedBuilder();
Embed.AddInlineField("Boss", $"{Boss.ToUpper()}"); // ([Wiki Page](https://runescape.wiki/w/Nex))");
Embed.AddInlineField("Duration", SessionLength);
Embed.AddInlineField("Team", MentionMembers());
Embed.AddInlineField("SessionID", SessionID);
Embed.AddInlineField("Loot", ConcatLoot());
Embed.AddInlineField("Wealth", Wealth);
Embed.AddField("Active", Active.ToString());
Embed.WithColor(EmbedColour);
Embed.WithThumbnailUrl(Leader.GetAvatarUrl());
await Context.Channel.SendMessageAsync("", false, Embed);
}
public async Task ViewLoot()
{
EmbedBuilder Embed = new EmbedBuilder();
Embed.AddInlineField("Total Loot", ConcatLoot());
Embed.WithColor(EmbedColour);
Embed.WithThumbnailUrl(Leader.GetAvatarUrl());
await Context.Channel.SendMessageAsync("", false, Embed);
}
public async Task ViewWealth()
{
EmbedBuilder Embed = new EmbedBuilder();
Embed.AddInlineField("Total Wealth", String.Format("{0:n0}gp", Wealth));
Embed.WithColor(EmbedColour);
Embed.WithThumbnailUrl(Leader.GetAvatarUrl());
await Context.Channel.SendMessageAsync("", false, Embed);
}
public async Task ViewTeam()
{
EmbedBuilder Embed = new EmbedBuilder();
Embed.AddInlineField("Team Members", MentionMembers());
Embed.WithColor(EmbedColour);
Embed.WithThumbnailUrl(Leader.GetAvatarUrl());
await Context.Channel.SendMessageAsync("", false, Embed);
}
public async Task WealthSplit()
{
int TeamCount = GetTeam().Count;
int Split = (Wealth / TeamCount);
EmbedBuilder Embed = new EmbedBuilder();
Embed.AddField("Total Wealth", String.Format("{0:n0}gp", Wealth));
Embed.AddField($"Wealth Split ({TeamCount} Members)", String.Format("{0:n0}gp each", Split));
Embed.WithColor(EmbedColour);
Embed.WithThumbnailUrl(Leader.GetAvatarUrl());
await Context.Channel.SendMessageAsync("", false, Embed);
}
public async Task AddWealth(int Amount)
{
Wealth += Amount;
Save();
await ViewWealth();
}
public async Task AddLoot(string Item)
{
Loot.Add(Item);
Save();
await ViewLoot();
}
public async Task AddLoot(string[] Items)
{
foreach(string item in Items)
{
Loot.Add(item);
Save();
}
await ViewLoot();
}
public void ChangeSessionTime(int Duration)
{
if (Duration == 0)
Active = false;
SessionLength = Duration;
}
public string MentionMembers()
{
string _team = "";
foreach (SocketUser partner in Users)
{
_team += partner.Mention + "\n";
}
return _team;
}
public string ConcatLoot()
{
if (this.Loot.Count < 1) return "N/A";
string Loot = "";
foreach(string loot in this.Loot)
{
Loot += loot + "\n";
}
return Loot;
}
public void SetTeamMembers()
{
for(int i = 0; i < Users.Count; i++)
{
Team[i] = Users[i].Id.ToString();
}
}
public void Deserialize(SocketCommandContext Context)
{
Guild = Context.Guild;
FilePath += $@"{Guild.Id}\Bossing\Sessions\session{SessionID}.json";
this.Context = Context;
Users = new List<SocketUser>();
for (int i = 0; i < Team.Length; i++)
{
ulong userId = UInt64.Parse(Team[i]);
Users[i] = Guild.GetUser(userId);
}
Leader = Users[0];
}
public string Serialize()
{
return JsonConvert.SerializeObject(this);
}
public void Save()
{
string JSON = Serialize();
ExternalModule EM = new ExternalModule();
EM.WriteFile(FilePath, JSON);
}
public int GetSessionID()
{
return SessionID;
}
public List<SocketUser> GetTeam()
{
return Users;
}
public override string ToString()
{
return "Session " + SessionID.ToString();
}
}
}