Move ZS stuff into a plugin.

This commit is contained in:
UnknownShadow200 2017-07-13 13:46:38 +10:00
parent 76f1f4f01e
commit fda2e569e4
15 changed files with 143 additions and 101 deletions

View File

@ -16,6 +16,7 @@
permissions and limitations under the Licenses.
*/
using MCGalaxy.Games;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Network;
namespace MCGalaxy.Commands.Fun {
@ -30,26 +31,13 @@ namespace MCGalaxy.Commands.Fun {
public override void Use(Player p, string message) {
if (p.Game.Referee) {
Chat.MessageGlobal(p, p.ColoredName + " %Sis no longer a referee", false);
p.Game.Referee = !p.Game.Referee;
if (p.level == Server.zombie.CurLevel)
Server.zombie.PlayerJoinedLevel(p, Server.zombie.CurLevel, Server.zombie.CurLevel);
if (p.HasCpeExt(CpeExt.HackControl))
p.Send(Hacks.MakeHackControl(p));
Command.all.Find("spawn").Use(p, "");
OnPlayerActionEvent.Call(p, PlayerAction.UnReferee);
p.Game.Referee = false;
} else {
Chat.MessageGlobal(p, p.ColoredName + " %Sis now a referee", false);
Server.zombie.PlayerLeftServer(p);
Entities.GlobalDespawn(p, false, true);
p.Game.Referee = !p.Game.Referee;
if (p.HasCpeExt(CpeExt.HackControl))
p.Send(Packet.HackControl(true, true, true, true, true, -1));
Chat.MessageGlobal(p, p.ColoredName + " %Sis now a referee", false);
OnPlayerActionEvent.Call(p, PlayerAction.Referee);
p.Game.Referee = true;
}
Entities.GlobalSpawn(p, false, "");
TabList.Add(p, p, Entities.SelfID);
p.SetPrefix();
}
public override void Help(Player p) {

View File

@ -108,7 +108,7 @@ namespace MCGalaxy.Commands.Fun {
src = p == null ? "(console)" : p.name;
Logger.Log(LogType.GameActivity, "Zombie Survival stopped by " + src);
Server.zombie.ResetState();
Server.zombie.End();
}
void HandleSet(Player p, string[] args) {

View File

@ -169,7 +169,7 @@ namespace MCGalaxy.Commands.Maintenance {
Server.voteKickInProgress = false;
Server.voteKickVotesNeeded = 0;
Server.zombie.ResetState();
Server.zombie.End();
SrvProperties.GenerateSalt();
ServerConfig.RestartTime = DateTime.Now;

View File

@ -20,9 +20,9 @@ using System.Collections.Generic;
using System.Data;
using System.IO;
using MCGalaxy.Levels.IO;
using MCGalaxy.Maths;
using MCGalaxy.SQL;
using MCGalaxy.Util;
using MCGalaxy.Maths;
namespace MCGalaxy.DB {

View File

@ -15,11 +15,10 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System;
namespace MCGalaxy.Events.PlayerEvents {
public enum PlayerAction { Joker, Unjoker, AFK, UnAFK, JoinWorld, Me, Review };
public enum PlayerAction { Joker, Unjoker, AFK, UnAFK, JoinWorld, Me, Review, Referee, UnReferee };
public delegate void OnPlayerChat(Player p, string message);
/// <summary> Called whenever a player chats on the server. </summary>

View File

@ -30,11 +30,6 @@ namespace MCGalaxy.Games {
return false;
}
/// <summary> Returns whether this game handled the player moving to a new position. </summary>
public virtual bool HandlesMovement(Player p, Position pos, byte rotX, byte rotY) {
return false;
}
/// <summary> Returns whether this game handled the player sending a chat message. </summary>
public virtual bool HandlesChatMessage(Player p, string message) {
return false;
@ -43,9 +38,6 @@ namespace MCGalaxy.Games {
/// <summary> Raised when a player joins the server. </summary>
public virtual void PlayerJoinedServer(Player p) { }
/// <summary> Raised when a player leaves the server. </summary>
public virtual void PlayerLeftServer(Player p) { }
/// <summary> Raised when a player joins this game. </summary>
public virtual void PlayerJoinedGame(Player p) { }
@ -59,18 +51,10 @@ namespace MCGalaxy.Games {
return true;
}
/// <summary> Raised when a player's money amount changes. </summary>
public virtual void PlayerMoneyChanged(Player p) { }
/// <summary> Raised when the server is about to send a heartbeat. </summary>
public virtual void OnHeartbeat(ref string name) { }
/// <summary> Adjusts the prefix (e.g. title) shown before the player's name in chat. </summary>
public virtual void AdjustPrefix(Player p, ref string prefix) { }
/// <summary> Gets the player's name shown in the tab list
/// (for clients that support a separate tab list) that are in this game. </summary>
public virtual void GetTabName(Player p, Player dst,
ref string name, ref string group) { }
}
}

View File

@ -0,0 +1,119 @@
/*
Copyright 2010 MCLawl Team -
Created by Snowl (David D.) and Cazzar (Cayde D.)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.osedu.org/licenses/ECL-2.0
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using MCGalaxy.Events.EconomyEvents;
using MCGalaxy.Events.EntityEvents;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Network;
namespace MCGalaxy.Games.ZS {
public sealed class ZSPlugin : Plugin_Simple {
public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.VersionString; } }
public override string name { get { return "Core_ZSPlugin"; } }
public ZombieGame Game;
public override void Load(bool startup) {
OnTabListEntryAddedEvent.Register(HandleTabListEntryAdded, Priority.High);
OnMoneyChangedEvent.Register(HandleMoneyChanged, Priority.High);
OnPlayerConnectEvent.Register(HandlePlayerConnect, Priority.High);
OnPlayerDisconnectEvent.Register(HandlePlayerDisconnect, Priority.High);
OnPlayerMoveEvent.Register(HandlePlayerMove, Priority.High);
OnPlayerActionEvent.Register(HandlePlayerAction, Priority.High);
}
public override void Unload(bool shutdown) {
OnTabListEntryAddedEvent.Unregister(HandleTabListEntryAdded);
OnMoneyChangedEvent.Unregister(HandleMoneyChanged);
OnPlayerConnectEvent.Unregister(HandlePlayerConnect);
OnPlayerDisconnectEvent.Unregister(HandlePlayerDisconnect);
OnPlayerMoveEvent.Unregister(HandlePlayerMove);
OnPlayerActionEvent.Unregister(HandlePlayerAction);
}
void HandleTabListEntryAdded(Entity entity, ref string tabName, ref string tabGroup, Player dst) {
Player p = entity as Player;
if (p == null || p.level != Game.CurLevel) return;
if (p.Game.Referee) {
tabGroup = "&2Referees";
} else if (p.Game.Infected) {
tabGroup = "&cZombies";
if (ZSConfig.ZombieName != "" && !dst.Game.Aka) {
tabName = "&c" + ZSConfig.ZombieName;
} else {
tabName = "&c" + p.truename;
}
} else {
tabGroup = "&fHumans";
}
}
void HandleMoneyChanged(Player p) {
if (p.level != Game.CurLevel) return;
HUD.UpdateTertiary(p);
}
void HandlePlayerConnect(Player p) {
if (!ZSConfig.SetMainLevel) return;
Player.Message(p, "Zombie Survival is running! Type %T/zs go %Sto join.");
}
void HandlePlayerDisconnect(Player p, string reason) {
Game.Alive.Remove(p);
Game.Infected.Remove(p);
p.Game.Infected = false;
Game.RemoveBounties(p);
Game.AssignFirstZombie();
HUD.UpdateAllPrimary(Game);
}
void HandlePlayerMove(Player p, Position next, byte rotX, byte rotY) {
if (!Game.RoundInProgress || p.level != Game.CurLevel) return;
bool reverted = MovementCheck.DetectNoclip(p, next)
|| MovementCheck.DetectSpeedhack(p, next, ZSConfig.MaxMoveDistance);
if (reverted) p.cancelmove = true;
}
void HandlePlayerAction(Player p, PlayerAction action, string message, bool stealth) {
if (!(action == PlayerAction.Referee || action == PlayerAction.UnReferee)) return;
if (p.level != Game.CurLevel) return;
if (action == PlayerAction.UnReferee) {
Game.PlayerJoinedLevel(p, Game.CurLevel, Game.CurLevel);
Command.all.Find("spawn").Use(p, "");
if (p.HasCpeExt(CpeExt.HackControl))
p.Send(Hacks.MakeHackControl(p));
} else {
HandlePlayerDisconnect(p, null);
Entities.GlobalDespawn(p, false, true);
if (p.HasCpeExt(CpeExt.HackControl))
p.Send(Packet.HackControl(true, true, true, true, true, -1));
}
Entities.GlobalSpawn(p, false, "");
TabList.Add(p, p, Entities.SelfID);
p.SetPrefix();
}
}
}

View File

@ -18,9 +18,7 @@
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Timers;
using MCGalaxy.Games.ZS;
using MCGalaxy.Network;
@ -36,7 +34,7 @@ namespace MCGalaxy.Games {
Logger.LogError(ex);
Chat.MessageGlobal("&cZombie survival disabled due to an error.");
try {
ResetState();
End();
} catch (Exception ex2) {
Logger.LogError(ex2);
}
@ -57,17 +55,17 @@ namespace MCGalaxy.Games {
LevelPicker.ChooseNextLevel(this);
} else if (Status == ZombieGameStatus.SingleRound) {
DoRound();
ResetState(); return;
End(); return;
} else if (Status == ZombieGameStatus.VariableRounds) {
if (RoundsDone == MaxRounds) {
ResetState(); return;
End(); return;
} else {
DoRound();
if (ZSConfig.ChangeLevels)
LevelPicker.ChooseNextLevel(this);
}
} else if (Status == ZombieGameStatus.LastRound) {
ResetState(); return;
End(); return;
}
}
}

View File

@ -53,14 +53,6 @@ namespace MCGalaxy.Games {
return false;
}
public override bool HandlesMovement(Player p, Position next, byte rotX, byte rotY) {
if (!Running || !RoundInProgress) return false;
if (p.level == null || !p.level.name.CaselessEq(CurLevelName)) return false;
return MovementCheck.DetectNoclip(p, next)
|| MovementCheck.DetectSpeedhack(p, next, ZSConfig.MaxMoveDistance);
}
public override bool HandlesChatMessage(Player p, string message) {
if (!Running || (p.level == null || !p.level.name.CaselessEq(CurLevelName))) return false;
if (Server.votingforlevel && HandleVote(p, message)) return true;
@ -94,17 +86,7 @@ namespace MCGalaxy.Games {
return false;
}
public override void PlayerLeftServer(Player p) {
Alive.Remove(p);
Infected.Remove(p);
p.Game.Infected = false;
RemoveBounties(p);
AssignFirstZombie();
HUD.UpdateAllPrimary(this);
}
void RemoveBounties(Player p) {
internal void RemoveBounties(Player p) {
BountyData[] bounties = Bounties.Items;
foreach (BountyData b in bounties) {
if (!(b.Origin.CaselessEq(p.name) || b.Target.CaselessEq(p.name))) continue;
@ -118,11 +100,6 @@ namespace MCGalaxy.Games {
}
}
public override void PlayerJoinedServer(Player p) {
if (!Running || ZSConfig.SetMainLevel) return;
Player.Message(p, "Zombie Survival is running! Type %T/zs go %Sto join.");
}
public override void PlayerJoinedLevel(Player p, Level lvl, Level oldLvl) {
p.SendCpeMessage(CpeMessageType.BottomRight3, "");
p.SendCpeMessage(CpeMessageType.BottomRight2, "");
@ -177,11 +154,6 @@ namespace MCGalaxy.Games {
return true;
}
public override void PlayerMoneyChanged(Player p) {
if (!Running || !p.level.name.CaselessEq(CurLevelName)) return;
HUD.UpdateTertiary(p);
}
public override void OnHeartbeat(ref string name) {
if (!Running || !ZSConfig.IncludeMapInHeartbeat || CurLevelName == null) return;
name += " (map: " + CurLevelName + ")";
@ -195,21 +167,5 @@ namespace MCGalaxy.Games {
else if (winStreak == 3) prefix += "&6*"+ p.color;
else if (winStreak > 0) prefix += "&6" + winStreak + p.color;
}
public override void GetTabName(Player p, Player dst,
ref string name, ref string group) {
if (p.Game.Referee) {
group = "&2Referees";
} else if (p.Game.Infected) {
group = "&cZombies";
if (ZSConfig.ZombieName != "" && !dst.Game.Aka) {
name = "&c" + ZSConfig.ZombieName;
} else {
name = "&c" + p.truename;
}
} else {
group = "&fHumans";
}
}
}
}

View File

@ -91,6 +91,7 @@ namespace MCGalaxy.Games {
string lastPlayerToInfect = "";
int infectCombo = 0;
/// <summary> List of players who have a bounty on them. </summary>
public VolatileArray<BountyData> Bounties = new VolatileArray<BountyData>();

View File

@ -33,6 +33,7 @@ namespace MCGalaxy.Games {
}
public sealed partial class ZombieGame {
ZSPlugin plugin = new ZSPlugin();
public void Start(ZombieGameStatus status, Level level, int rounds) {
Status = status;
@ -42,6 +43,8 @@ namespace MCGalaxy.Games {
if (!SetStartLevel(level)) return;
HookStats();
if (plugin.Game == null) { plugin.Game = this; plugin.Load(false); }
Thread t = new Thread(MainLoop);
t.Name = "MCG_ZombieGame";
t.Start();
@ -179,14 +182,15 @@ namespace MCGalaxy.Games {
}
}
public void ResetState() {
public void End() {
Status = ZombieGameStatus.NotStarted;
MaxRounds = 0;
RoundInProgress = false;
RoundStart = DateTime.MinValue;
RoundEnd = DateTime.MinValue;
Player[] online = PlayerInfo.Online.Items;
if (plugin.Game != null) { plugin.Game = null; plugin.Unload(false); }
Player[] online = PlayerInfo.Online.Items;
Alive.Clear();
Infected.Clear();

View File

@ -511,6 +511,7 @@
<Compile Include="Games\ZombieSurvival\ZombieGame.cs" />
<Compile Include="Games\ZombieSurvival\ZombieGame.Game.cs" />
<Compile Include="Games\ZombieSurvival\ZombieGame.Props.cs" />
<Compile Include="Games\ZombieSurvival\ZSPlugin.cs" />
<Compile Include="Generator\AdvNoiseGen.cs" />
<Compile Include="Generator\fCraft\MapGenerator.cs" />
<Compile Include="Generator\fCraft\MapGeneratorArgs.cs" />

View File

@ -328,9 +328,6 @@ namespace MCGalaxy {
Position next = new Position(x, y, z);
CheckBlocks(next);
if (Server.zombie.Running && Server.zombie.HandlesMovement(this, next, yaw, pitch))
return;
OnPlayerMoveEvent.Call(this, next, yaw, pitch);
if (cancelmove) { cancelmove = false; return; }

View File

@ -184,7 +184,6 @@ namespace MCGalaxy {
Logger.Log(LogType.UserActivity, "{0} [{1}] connected using {2}.", name, ip, appName);
}
Game.InfectMessages = PlayerDB.GetInfectMessages(this);
Server.zombie.PlayerJoinedServer(this);
Server.lava.PlayerJoinedServer(this);
Pos = level.SpawnPos;

View File

@ -309,7 +309,6 @@ namespace MCGalaxy {
return;
}
Server.zombie.PlayerLeftServer(this);
if ( Game.team != null ) Game.team.RemoveMember(this);
TntWarsGame tntwarsgame = TntWarsGame.GetTntWarsGame(this);
if ( tntwarsgame != null ) {
@ -452,9 +451,6 @@ namespace MCGalaxy {
public void SetMoney(int amount) {
money = amount;
if (Server.zombie.Running) Server.zombie.PlayerMoneyChanged(this);
if (Server.lava.active) Server.lava.PlayerMoneyChanged(this);
OnMoneyChangedEvent.Call(this);
}