-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCustomRole.cs
316 lines (289 loc) · 16.2 KB
/
CustomRole.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using AmongUs.GameOptions;
using Hazel;
using UnityEngine;
// the idea here is that you'll instiate this class for your own purposes
// example for this:
// CustomRole.createRole("Jester", "Get voted out to win. You're a real trickster!", true, new Color32(90, 50, 200), false, LoneWolf, false, false);
namespace DillyzRoleApi_Rewritten
{
public class CustomRole
{
public static List<string> allRoleNames {
get {
List<string> strlist = new List<string>();
foreach (CustomRole role in allRoles)
strlist.Add(role.name);
return strlist;
}
}
public static List<CustomRole> allRoles = new List<CustomRole>();
public static void appendRole(CustomRole yourRole) => allRoles.Add(yourRole);
public static CustomRole createRole(string name, string subtext, bool nameColor, bool nameColorPublic, Color32 roleColor, bool canSeeTeam, CustomRoleSide side,
VentPrivilege ventPrivilege, bool canKill, bool showEjectText) {
foreach (CustomRole role in allRoles)
if (role.name == name)
{
DillyzRoleApiMain.Instance.Log.LogError($"Role by name \"{role.name}\" already exists!");
return role;
}
CustomRole rolee = new CustomRole(name, subtext, nameColor, nameColorPublic, roleColor, canSeeTeam, side, ventPrivilege, canKill, showEjectText);
CustomRole.appendRole(rolee);
return rolee;
}
public static CustomRole getByName(string name)
{
foreach (CustomRole role in allRoles)
if (role.name == name)
return role;
return null;
}
// player id to role name
public static Dictionary<byte, string> roleNameMap = new Dictionary<byte, string>();
public static string getRoleName(byte playerId) => roleNameMap.ContainsKey(playerId) ? roleNameMap[playerId] : "";
public static void setRoleName(byte playerId, string roleName) {
PlayerControl player = DillyzUtil.findPlayerControl(playerId);
string role = DillyzUtil.getRoleName(player);
if (playerId == PlayerControl.LocalPlayer.PlayerId)
CustomButton.ResetAllButtons();
/*if (PlayerTask.DestroyTasksOfType<ImportantTextTask>(PlayerControl.LocalPlayer) && !PlayerTask.PlayerHasTaskOfType<NormalPlayerTask>(PlayerControl.LocalPlayer))
ShipStatus.Instance.Begin();*/
switch (roleName) {
case "Impostor":
if (player.Data.IsDead) {
player.Data.RoleType = RoleTypes.ImpostorGhost;
player.Data.Role = new ImpostorGhostRole();
player.SetRole(RoleTypes.ImpostorGhost);
}
else {
player.Data.RoleType = RoleTypes.Impostor;
player.Data.Role = new ImpostorRole();
player.SetRole(RoleTypes.Impostor);
}
break;
case "ShapeShifter":
if (player.Data.IsDead)
{
player.Data.RoleType = RoleTypes.ImpostorGhost;
player.Data.Role = new ImpostorGhostRole();
player.SetRole(RoleTypes.ImpostorGhost);
}
else
{
player.Data.RoleType = RoleTypes.Shapeshifter;
player.Data.Role = new ShapeshifterRole();
player.SetRole(RoleTypes.Shapeshifter);
}
break;
case "Scientist":
if (player.Data.IsDead)
{
player.Data.RoleType = RoleTypes.CrewmateGhost;
player.Data.Role = new CrewmateGhostRole();
player.SetRole(RoleTypes.CrewmateGhost);
}
else
{
player.Data.RoleType = RoleTypes.Scientist;
player.Data.Role = new ScientistRole();
player.SetRole(RoleTypes.Scientist);
}
break;
case "Engineer":
if (player.Data.IsDead)
{
player.Data.RoleType = RoleTypes.CrewmateGhost;
player.Data.Role = new CrewmateGhostRole();
player.SetRole(RoleTypes.CrewmateGhost);
}
else
{
player.Data.RoleType = RoleTypes.Engineer;
player.Data.Role = new EngineerRole();
player.SetRole(RoleTypes.Engineer);
}
break;
case "GuardianAngel":
if (player.Data.IsDead)
{
player.Data.RoleType = RoleTypes.GuardianAngel;
player.Data.Role = new GuardianAngelRole();
player.SetRole(RoleTypes.GuardianAngel);
}
else {
player.Data.RoleType = RoleTypes.Crewmate;
player.Data.Role = new CrewmateRole();
player.SetRole(RoleTypes.Crewmate);
}
break;
case "Crewmate":
if (player.Data.IsDead)
{
player.Data.RoleType = RoleTypes.CrewmateGhost;
player.Data.Role = new CrewmateGhostRole();
player.SetRole(RoleTypes.CrewmateGhost);
}
else
{
player.Data.RoleType = RoleTypes.Crewmate;
player.Data.Role = new CrewmateRole();
player.SetRole(RoleTypes.Crewmate);
}
break;
case "":
break;
default:
CustomRole roleee = CustomRole.getByName(roleName);
//DillyzRoleApiMain.Instance.Log.LogInfo((roleee == null) + " " + player.name);
bool funnyt = (roleee != null && roleee.switchToImpostor);
//DillyzRoleApiMain.Instance.Log.LogInfo(funnyt + " that " + player.name + " is an imp");
player.SetRole(roleee.ghostRole ? (funnyt ? RoleTypes.ImpostorGhost : RoleTypes.CrewmateGhost) : (funnyt ? RoleTypes.Impostor : RoleTypes.Crewmate));
//player.Data.IsDead = roleee.ghostRole;
roleNameMap[playerId] = roleName;
//DillyzRoleApiMain.Instance.Log.LogInfo("role " + roleNameMap[playerId]);
return;
}
roleNameMap[playerId] = "";
//DillyzRoleApiMain.Instance.Log.LogInfo("roleE " + roleName + " " + roleNameMap[playerId]);
}
public List<PlayerControl> AllPlayersWithRole {
get
{
List<PlayerControl> bbbb = PlayerControl.AllPlayerControls.ToArray().ToList();
bbbb.RemoveAll(x => getRoleName(x.PlayerId) != this.name);
return bbbb;
}
}
public int curActive = 0; // USED FOR GRAMMAR CHECKS, PLEASE IGNORE THIS!
public string name = "Role Text"; // Your role's name.
public string subtext; // The text that appears under.
public string blurb; // A brief description of your role shown in host settings.
public bool nameColorChanges; // Determines if your name color is your role color or just red/white.
public bool nameColorPublic; // Determines if your name color is public to all or not.
public Color32 roleColor; // The current color of your role.
public bool teamCanSeeYou; // Determines if your team can see you.
public CustomRoleSide side; // Determines who you work with.
public VentPrivilege ventPrivilege; // Your vent privelege level.
public bool canKill; // Are you seriously this blind?
public string ejectionText; // "DillyzThe1 was The Jester"
public bool switchToImpostor = false; // Will switch a crewmate role to an Impostor role.
public string a_or_an = "an"; // "DillyzThe1 was a Jester" vs "DillyzThe1 was an Jester"
public Func<WinConditionState> returnWinConditionState;// You can return a WinConditionState here. Can set to "delegate() { return WinConditionState.None; }".
public Func<PlayerControl> rwcsPlayer; // A player return for the above just incase.
private List<CustomSetting> _advancedSettings; // A list of custom setting data to use.
[Obsolete("Variable \"decoy\" is obselete! Please use \"roleSelected\" and \"hasSettings\"!")]
public bool decoy = false; // If this role isn't actaully meant for gameplay. Use this if you have no real roles to make.
public bool roleSeleciton = true;
public bool hasSettings = true;
public bool hiddenFromFreeplay = false;
public string roletoGhostInto = ""; // turns into this role on death
public bool ghostRole = false; // marks the role as a ghost
// settings stuff
private int _countMin = 0, _countMax = 15;
private int _chanceMin = 0, _chanceMax = 100;
public int countMin { get { return _countMin; } set { _countMin = Math.Min(Math.Max(value, 0),countMax); } }
public int countMax { get { return _countMax; } set { _countMax = Math.Min(Math.Max(value, 1), countMin); } }
public int chanceMin { get { return _chanceMin; } set { _chanceMin = Math.Min(Math.Max(value, 0), chanceMax); } }
public int chanceMax { get { return _chanceMax; } set { _chanceMax = Math.Min(Math.Max(value, 10), chanceMin); } }
public List<CustomSetting> advancedSettings => _advancedSettings;
// LOBBY SETTINGS (GET & SET)
public int setting_countPerGame { get { return settingsForRole.roleCount; } set { settingsForRole.roleCount = Math.Min(Math.Max(value, countMin), countMax); } }
public int setting_chancePerGame { get { return settingsForRole.roleChance; } set { settingsForRole.roleChance = Math.Min(Math.Max(value, chanceMin), chanceMax); } }
private LobbyRoleSetting settingsForRole;
private Assembly settingsSpriteAssembly = Assembly.GetExecutingAssembly();
private string settingsSpritePath = "DillyzRoleApi_Rewritten.Assets.settings_genericrole.png";
public Sprite settingsSprite => DillyzUtil.getSprite(settingsSpriteAssembly, settingsSpritePath);
public void SetSprite(Assembly assembly, string assetPath) { settingsSpriteAssembly = assembly; settingsSpritePath = assetPath; }
public CustomRole(string name, string subtext, bool nameColor, bool nameColorPublic, Color32 roleColor, bool canSeeTeam,
CustomRoleSide side, VentPrivilege ventPrivilege, bool canKill, bool showEjectText) {
this.name = name;
this.subtext = subtext;
this.blurb = $"The {this.name} is a role created using DillyzRoleAPI v2\n\ngithub.com/DillyzThe1";
this.nameColorChanges = nameColor;
this.nameColorPublic = nameColorPublic;
this.roleColor = roleColor;
this.teamCanSeeYou = canSeeTeam;
this.side = side;
this.ventPrivilege = ventPrivilege;
this.canKill = canKill;
this.ejectionText = "[0] was ";
//this.ejectionText_bad = "[0] was not ";
this.switchToImpostor = (this.side == CustomRoleSide.Impostor);
// vs woudn't let me use turnary operators this time >:/
if (showEjectText)
ejectionText += $"The {name}.";
else
ejectionText += $"{(side == CustomRoleSide.Impostor ? "" : "not ")}The Impostor.";
foreach (LobbyRoleSetting setting in LobbyConfigManager.lobbyRoleSettings)
if (setting.roleName == this.name)
{
settingsForRole = setting;
return;
}
settingsForRole = new LobbyRoleSetting() { roleName = name, roleCount = 1, roleChance = 50 };
LobbyConfigManager.lobbyRoleSettings.Add(settingsForRole);
rwcsPlayer = delegate() { return null; };
_advancedSettings = new List<CustomSetting>();
}
public override string ToString() {
return $"DillyzRoleApi_Rewritten.CustomRole [name: {this.name}, subtext: {this.subtext}, nameColorChanges: {this.nameColorChanges}, " +
$"roleColor: [{this.roleColor.r}, {this.roleColor.g}, {this.roleColor.b}, teamCanSeeYou: {this.teamCanSeeYou}, side: {this.side}, " +
$"ventPrivilege: {this.ventPrivilege}, canKill: {this.canKill}]";
}
public CustomFloatSetting AddAdvancedSetting_Float(string name, float defaultValue, float minimum, float maximum, float increment, Action<float> onChanged) {
CustomFloatSetting setting = new CustomFloatSetting(name, defaultValue, minimum, maximum, increment, onChanged);
_advancedSettings.Add(setting);
return setting;
}
public CustomStringSetting AddAdvancedSetting_String(string name, string defaultValue, string[] allValues, Action<string> onChanged) {
CustomStringSetting setting = new CustomStringSetting(name, defaultValue, allValues.ToList(), onChanged);
_advancedSettings.Add(setting);
return setting;
}
public CustomBooleanSetting AddAdvancedSetting_Boolean(string name, bool defaultValue, Action<bool> onChanged) {
CustomBooleanSetting setting = new CustomBooleanSetting(name, defaultValue, onChanged);
_advancedSettings.Add(setting);
return setting;
}
public void WinGame(PlayerControl cause) {
if (this.side == CustomRoleSide.Crewmate)
{
GameManager.Instance.RpcEndGame(GameOverReason.HumansByTask, false);
return;
}
if (this.side == CustomRoleSide.Impostor)
{
GameManager.Instance.RpcEndGame(GameOverReason.ImpostorByKill, false);
return;
}
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRpc.CustomRoleWin, Hazel.SendOption.None, -1);
writer.Write(this.name);
writer.Write(cause != null ? cause.PlayerId : 255);
AmongUsClient.Instance.FinishRpcImmediately(writer);
GameOverPatch.SetAllToWin(this.name, cause, true);
GameManager.Instance.RpcEndGame(GameOverReason.ImpostorByKill, false);
}
}
public enum CustomRoleSide {
Impostor = 0, // You work alongside the Impostors.
Crewmate = 1, // You work alongside the Crewmates.
Independent = 2, // You work upon your own team.
LoneWolf = 3 // You work by yourself.
}
public enum VentPrivilege
{
None = 0, // You possess an inability to use vents.
Impostor = 1, // You inheret the venting power of an Impostor.
[Obsolete("Engineer vents do NOT work at the moment! Please do not attempt to use them! 🤓", true)]
Engineer = 2 // You inheret the venting power of an Engineer.
}
public enum WinConditionState
{
None = 0, // Nothing happens.
GameOver = 1, // You win the game.
Hold = 2 // You hold off the game. (does not override sabotages)
}
}