-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicGameModes.cs
More file actions
152 lines (123 loc) · 4.46 KB
/
DynamicGameModes.cs
File metadata and controls
152 lines (123 loc) · 4.46 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
using BattleBitAPI.Common;
using BattleBitBaseModules;
using BBRAPIModules;
using Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using static DynamicGamemodes.GameMode;
using static DynamicGamemodes.GunGame;
using static DynamicGamemodes.TeamGunGame;
using static DynamicGamemodes.Hardcore;
using static DynamicGamemodes.LifeSteal;
using static DynamicGamemodes.Swap;
using static DynamicGamemodes.MeleeOnly;
using static DynamicGamemodes.Csgo;
using System.Threading.Tasks;
namespace DynamicGamemodes;
[RequireModule(typeof(CommandHandler)), RequireModule(typeof(RichText))]
public class DynamicGameModes: BattleBitModule
{
[ModuleReference]
public CommandHandler CommandHandler { get; set; }
private List<GameMode> mGameModes;
private GameMode mCurrentGameMode;
private bool _mCyclePlaylist;
private int _mGameModeIndex;
public DynamicGameModes()
{
_mCyclePlaylist = false;
mGameModes = new List<GameMode>
{
new GunGame(this),
new TeamGunGame(this),
new LifeSteal(this),
new Swap(this),
new Hardcore(this),
new MeleeOnly(this),
new Csgo(this)
};
_mGameModeIndex = 0;
mCurrentGameMode = mGameModes[_mGameModeIndex];
}
public override void OnModulesLoaded()
{
CommandHandler.Register(this);
}
//GAMEMODE PASSTHROUGH
public override Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments<RunnerPlayer> args)
{
mCurrentGameMode.OnAPlayerDownedAnotherPlayer(args);
return Task.CompletedTask;
}
public override Task OnPlayerGivenUp(RunnerPlayer player)
{
mCurrentGameMode.OnPlayerGivenUp(player);
return Task.CompletedTask;
}
public override Task OnPlayerConnected(RunnerPlayer player)
{
Server.SayToAllChat("<color=green>" + player.Name + " joined the game!</color>");
player.Message($"Current GameMode is: {mCurrentGameMode.Name}", 4f);
Console.Out.WriteLine("Connected: " + player);
player.JoinSquad(Squads.Alpha);
return Task.CompletedTask;
}
public override Task OnPlayerDisconnected(RunnerPlayer player)
{
Console.WriteLine($"{player.Name} disconnected");
Server.SayToAllChat($"<color=red>{player.Name} left the game!</color>");
mCurrentGameMode.OnPlayerDisconnected(player);
return Task.CompletedTask;
}
//GAMEMODE COMMANDS
[CommandCallback("nextGM", Description = "Selects the next Gamemode in Playlist and resets all Players")]
public void NextGameModeCommand(RunnerPlayer commandSource)
{
mCurrentGameMode.Reset();
_mGameModeIndex = (_mGameModeIndex + 1) % mGameModes.Count;
mCurrentGameMode = mGameModes[_mGameModeIndex];
mCurrentGameMode.Init();
Server.AnnounceShort($"GameMode is now {mCurrentGameMode.Name}");
Console.WriteLine($"GameMode is now {mCurrentGameMode.Name}");
}
[CommandCallback("SetGM", Description = "Sets the Gamemode to a specific one in Playlist and resets all Players")]
public void SetGameModeCommand(RunnerPlayer commandSource, string gamemodeName)
{
try
{
mCurrentGameMode.Reset();
}
catch (Exception ex)
{
Console.WriteLine($"ERROR resetting GM: {ex}");
}
foreach (var gameMode in mGameModes.Where(gameMode => gameMode.Name == gamemodeName))
{
mCurrentGameMode = gameMode;
_mGameModeIndex = mGameModes.IndexOf(gameMode);
}
try
{
mCurrentGameMode.Init();
}
catch (Exception ex)
{
Console.WriteLine($"ERROR initializing GM: {ex}");
}
Server.AnnounceShort($"GameMode is now {mCurrentGameMode.Name}");
}
[CommandCallback("GetGM", Description = "Announces the current selected GameMode")]
public void GetGameModeCommand(RunnerPlayer commandSource)
{
Server.AnnounceShort($"GameMode is {mCurrentGameMode.Name}");
}
[CommandCallback("togglePlaylist", Description = "Toggles the GamemodePlaylist")]
public void TogglePlaylistCommand(RunnerPlayer commandSource)
{
_mCyclePlaylist = !_mCyclePlaylist;
Server.AnnounceShort($"Playlist is now {_mCyclePlaylist}");
Console.WriteLine($"Playlist is now {_mCyclePlaylist}");
}
}