mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Improve /ctf - move blue/red spawn to set sub-command, add add/remove sub-command.
This commit is contained in:
parent
ba6b80fa44
commit
acede04292
@ -16,6 +16,7 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MCGalaxy.Games;
|
||||
|
||||
@ -30,41 +31,100 @@ namespace MCGalaxy.Commands.Fun {
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (message.CaselessEq("start")) {
|
||||
if (Server.ctf == null) {
|
||||
Player.Message(p, "Initialising CTF..");
|
||||
Server.ctf = new CTFGame();
|
||||
}
|
||||
|
||||
if (!Server.ctf.Start(p)) return;
|
||||
Chat.MessageGlobal("A CTF GAME IS STARTING AT CTF! TYPE /goto CTF to join!");
|
||||
} else if (message.CaselessEq("stop")) {
|
||||
if (Server.ctf == null || !Server.ctf.started) {
|
||||
Player.Message(p, "No CTF game is active."); return;
|
||||
}
|
||||
Server.ctf.Stop();
|
||||
} else if (message.CaselessEq("bluespawn")) {
|
||||
CTFConfig cfg = Retrieve(p);
|
||||
cfg.BlueSpawnX = p.Pos.X; cfg.BlueSpawnY = p.Pos.Y; cfg.BlueSpawnZ = p.Pos.Z;
|
||||
|
||||
Update(p, cfg);
|
||||
Player.Message(p, "Set spawn of blue team to your position.");
|
||||
} else if (message.CaselessEq("redspawn")) {
|
||||
CTFConfig cfg = Retrieve(p);
|
||||
cfg.RedSpawnX = p.Pos.X; cfg.RedSpawnY = p.Pos.Y; cfg.RedSpawnZ = p.Pos.Z;
|
||||
|
||||
Update(p, cfg);
|
||||
Player.Message(p, "Set spawn of red team to your position.");
|
||||
HandleStart(p);
|
||||
} else if (message.CaselessEq("stop")) {
|
||||
HandleStop(p);
|
||||
} else if (message.CaselessEq("add")) {
|
||||
HandleAdd(p);
|
||||
} else if (message.CaselessEq("remove")) {
|
||||
HandleRemove(p);
|
||||
} else if (message.CaselessStarts("set ")) {
|
||||
string[] args = message.SplitSpaces(2);
|
||||
HandleSet(p, args[1]);
|
||||
} else {
|
||||
Help(p);
|
||||
}
|
||||
}
|
||||
|
||||
static CTFConfig Retrieve(Player p) {
|
||||
static void HandleStart(Player p) {
|
||||
if (Server.ctf == null) {
|
||||
Player.Message(p, "Initialising CTF..");
|
||||
Server.ctf = new CTFGame();
|
||||
}
|
||||
|
||||
if (!Server.ctf.Start(p)) return;
|
||||
Chat.MessageGlobal("A CTF GAME IS STARTING AT CTF! TYPE /goto CTF to join!");
|
||||
}
|
||||
|
||||
static void HandleStop(Player p) {
|
||||
if (Server.ctf == null || !Server.ctf.started) {
|
||||
Player.Message(p, "No CTF game is active."); return;
|
||||
}
|
||||
Server.ctf.Stop();
|
||||
}
|
||||
|
||||
|
||||
static void HandleAdd(Player p) {
|
||||
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||
List<string> maps = GetCtfMaps();
|
||||
|
||||
if (maps.CaselessContains(p.level.name)) {
|
||||
Player.Message(p, "{0} %Sis already in the list of CTF maps.", p.level.ColoredName);
|
||||
} else {
|
||||
Player.Message(p, "Added {0} %Sto the list of CTF maps.", p.level.ColoredName);
|
||||
maps.Add(p.level.name);
|
||||
UpdateCtfMaps(maps);
|
||||
}
|
||||
}
|
||||
|
||||
static void HandleRemove(Player p) {
|
||||
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||
List<string> maps = GetCtfMaps();
|
||||
|
||||
if (!maps.CaselessRemove(p.level.name)) {
|
||||
Player.Message(p, "{0} %Swas not in the list of CTF maps.", p.level.ColoredName);
|
||||
} else {
|
||||
Player.Message(p, "Removed {0} %Sfrom the list of CTF maps.", p.level.ColoredName);
|
||||
UpdateCtfMaps(maps);
|
||||
}
|
||||
}
|
||||
|
||||
static List<string> GetCtfMaps() {
|
||||
if (!File.Exists("CTF/maps.config")) return new List<string>();
|
||||
string[] lines = File.ReadAllLines("CTF/maps.config");
|
||||
return new List<string>(lines);
|
||||
}
|
||||
|
||||
static void UpdateCtfMaps(List<string> maps) {
|
||||
File.WriteAllLines("CTF/maps.config", maps.ToArray());
|
||||
if (Server.ctf != null) Server.ctf.UpdateMapList();
|
||||
}
|
||||
|
||||
|
||||
void HandleSet(Player p, string property) {
|
||||
CTFConfig cfg = RetrieveConfig(p);
|
||||
|
||||
if (property.CaselessEq("bluespawn")) {
|
||||
cfg.BlueSpawnX = p.Pos.X; cfg.BlueSpawnY = p.Pos.Y; cfg.BlueSpawnZ = p.Pos.Z;
|
||||
Player.Message(p, "Set spawn of blue team to your position.");
|
||||
UpdateConfig(p, cfg);
|
||||
} else if (property.CaselessEq("redspawn")) {
|
||||
cfg.RedSpawnX = p.Pos.X; cfg.RedSpawnY = p.Pos.Y; cfg.RedSpawnZ = p.Pos.Z;
|
||||
Player.Message(p, "Set spawn of red team to your position.");
|
||||
UpdateConfig(p, cfg);
|
||||
} else {
|
||||
Help(p, "set");
|
||||
}
|
||||
}
|
||||
|
||||
static CTFConfig RetrieveConfig(Player p) {
|
||||
CTFConfig cfg = new CTFConfig();
|
||||
cfg.SetDefaults(p.level);
|
||||
cfg.Retrieve(p.level.name);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
static void Update(Player p, CTFConfig cfg) {
|
||||
static void UpdateConfig(Player p, CTFConfig cfg) {
|
||||
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||
cfg.Save(p.level.name);
|
||||
if (Server.ctf != null && p.level == Server.ctf.map) Server.ctf.UpdateConfig();
|
||||
@ -73,8 +133,19 @@ namespace MCGalaxy.Commands.Fun {
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/ctf start/stop");
|
||||
Player.Message(p, "%HStarts/stops the CTF game.");
|
||||
Player.Message(p, "%T/ctf redspawn/bluespawn");
|
||||
Player.Message(p, "%HSets spawn of red/blue team to your position.");
|
||||
Player.Message(p, "%T/ctf add/remove");
|
||||
Player.Message(p, "%HAdds or removes current map from list of CTF maps.");
|
||||
Player.Message(p, "%T/ctf set [property]");
|
||||
Player.Message(p, "%HSets a CTF game property, see %T/help ctf set");
|
||||
}
|
||||
|
||||
public override void Help(Player p, string message) {
|
||||
if (message.CaselessEq("set")) {
|
||||
Player.Message(p, "%T/ctf set redspawn/bluespawn");
|
||||
Player.Message(p, "%HSets spawn of red/blue team to your position.");
|
||||
} else {
|
||||
Help(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,12 +38,8 @@ namespace MCGalaxy.Games {
|
||||
public sealed partial class CTFGame {
|
||||
public System.Timers.Timer tagging = new System.Timers.Timer(500);
|
||||
public bool voting = false;
|
||||
int vote1 = 0;
|
||||
int vote2 = 0;
|
||||
int vote3 = 0;
|
||||
string map1 = "";
|
||||
string map2 = "";
|
||||
string map3 = "";
|
||||
int vote1 = 0, vote2 = 0, vote3 = 0;
|
||||
string map1 = "", map2 = "", map3 = "";
|
||||
public bool started = false;
|
||||
|
||||
CtfTeam2 red;
|
||||
@ -111,7 +107,7 @@ namespace MCGalaxy.Games {
|
||||
blue.SpawnPos = new Position(cfg.BlueSpawnX, cfg.BlueSpawnY, cfg.BlueSpawnZ);
|
||||
}
|
||||
|
||||
bool LoadConfig() {
|
||||
public bool UpdateMapList() {
|
||||
//Load some configs
|
||||
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||
if (!File.Exists("CTF/maps.config")) return false;
|
||||
@ -185,7 +181,7 @@ namespace MCGalaxy.Games {
|
||||
if (started) {
|
||||
Player.Message(p, "CTF game already running."); return false;
|
||||
}
|
||||
if (!LoadConfig()) {
|
||||
if (!UpdateMapList()) {
|
||||
Player.Message(p, "No CTF maps were found."); return false;
|
||||
}
|
||||
|
||||
|
@ -297,10 +297,6 @@ namespace MCGalaxy {
|
||||
buffer[7] = raw;
|
||||
Send(buffer);
|
||||
}
|
||||
|
||||
public void SendExtAddPlayerName(byte id, string listName, string displayName, string grp, byte grpRank) {
|
||||
Send(Packet.ExtAddPlayerName(id, listName, displayName, grp, grpRank, hasCP437));
|
||||
}
|
||||
|
||||
internal void CloseSocket() {
|
||||
socket.Close();
|
||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy {
|
||||
|
||||
string name, group;
|
||||
GetEntry(p, dst, out name, out group);
|
||||
dst.SendExtAddPlayerName(id, p.truename, name, group, grpPerm);
|
||||
dst.Send(Packet.ExtAddPlayerName(id, p.truename, name, group, grpPerm, dst.hasCP437));
|
||||
}
|
||||
|
||||
/// <summary> Gets the name and the group name for the given player. </summary>
|
||||
@ -53,7 +53,7 @@ namespace MCGalaxy {
|
||||
/// <summary> Adds the given bot to that player's tab list (if their client support it). </summary>
|
||||
public static void Add(Player dst, PlayerBot b) {
|
||||
if (!dst.hasExtList) return;
|
||||
dst.SendExtAddPlayerName(b.id, b.SkinName, b.color + b.name, "Bots", 0);
|
||||
dst.Send(Packet.ExtAddPlayerName(b.id, b.SkinName, b.color + b.name, "Bots", 0, dst.hasCP437));
|
||||
}
|
||||
|
||||
/// <summary> Removes the given player from player's tab list (if their client supports it). </summary>
|
||||
|
@ -55,9 +55,9 @@ namespace MCGalaxy {
|
||||
public static INetworkListen Listener;
|
||||
|
||||
//Other
|
||||
public static bool UseCTF = false;
|
||||
public static bool ServerSetupFinished = false;
|
||||
public static CTFGame ctf = null;
|
||||
public static CTFGame ctf;
|
||||
|
||||
public static PlayerList bannedIP, whiteList, ircControllers, invalidIds;
|
||||
public static PlayerList ignored, hidden, agreed, vip, noEmotes, lockdown;
|
||||
public static PlayerExtList models, skins, reach, rotations;
|
||||
|
Loading…
x
Reference in New Issue
Block a user