Start rearranging stuff for ZS

This commit is contained in:
UnknownShadow200 2018-06-12 21:57:11 +10:00
parent 6ef826c5ec
commit 4fa19ed577
15 changed files with 174 additions and 151 deletions

View File

@ -25,7 +25,7 @@ namespace MCGalaxy.Commands.Fun {
public override string type { get { return CommandTypes.Games; } }
public override void Use(Player p, string message) {
ZSData data = Server.zombie.Get(p);
ZSData data = ZSGame.Get(p);
data.AkaMode = !data.AkaMode;
Player[] players = PlayerInfo.Online.Items;
Player.Message(p, "AKA mode is now: " + (data.AkaMode ? "&aOn" : "&cOff"));

View File

@ -15,6 +15,8 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Games;
namespace MCGalaxy.Commands.Fun {
public sealed class CmdDisInfect : Command {
public override string name { get { return "DisInfect"; } }
@ -27,7 +29,7 @@ namespace MCGalaxy.Commands.Fun {
Player who = message.Length == 0 ? p : PlayerInfo.FindMatches(p, message);
if (who == null) return;
if (!Server.zombie.RoundInProgress || !Server.zombie.Get(who).Infected) {
if (!Server.zombie.RoundInProgress || !ZSGame.Get(who).Infected) {
Player.Message(p, "Cannot disinfect player");
} else if (!who.Game.Referee) {
Server.zombie.DisinfectPlayer(who);

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Fun {
if (p.Game.PledgeSurvive) {
Player.Message(p, "You cannot un-pledge that you will be infected."); return;
}
if (Server.zombie.Get(p).Infected) {
if (ZSGame.Get(p).Infected) {
Player.Message(p, "You cannot use %T/human %Sas you are currently infected."); return;
}

View File

@ -15,6 +15,8 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Games;
namespace MCGalaxy.Commands.Fun {
public sealed class CmdInfect : Command {
public override string name { get { return "Infect"; } }
@ -26,7 +28,7 @@ namespace MCGalaxy.Commands.Fun {
Player who = message.Length == 0 ? p : PlayerInfo.FindMatches(p, message);
if (who == null) return;
if (!Server.zombie.RoundInProgress || Server.zombie.Get(who).Infected) {
if (!Server.zombie.RoundInProgress || ZSGame.Get(who).Infected) {
Player.Message(p, "Cannot infect player");
} else if (!who.Game.Referee) {
Server.zombie.InfectPlayer(who, p);

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Eco {
"when a round of zombie survival is in progress."); return;
}
ZSData data = Server.zombie.Get(p);
ZSData data = ZSGame.Get(p);
if (!data.Infected) {
Player.Message(p, "You are already a human."); return;
}

View File

@ -43,7 +43,7 @@ namespace MCGalaxy.Eco {
Name, count * 10, ServerConfig.Currency); return;
}
ZSData data = Server.zombie.Get(p);
ZSData data = ZSGame.Get(p);
data.BlocksLeft += 10 * count;
Economy.MakePurchase(p, Price * count, "%310Blocks: " + (10 * count));
}
@ -105,7 +105,7 @@ namespace MCGalaxy.Eco {
"and/or a \"{1}\" (placeholder for human player) in the infect message."); return;
}
ZSData data = Server.zombie.Get(p);
ZSData data = ZSGame.Get(p);
if (data.InfectMessages == null) data.InfectMessages = new List<string>();
data.InfectMessages.Add(text);
@ -138,7 +138,7 @@ namespace MCGalaxy.Eco {
"when a round of zombie survival is in progress."); return;
}
ZSData data = Server.zombie.Get(p);
ZSData data = ZSGame.Get(p);
if (data.Invisible) { Player.Message(p, "You are already invisible."); return; }
if (data.InvisibilityPotions >= MaxPotions) {

View File

@ -331,7 +331,7 @@ namespace MCGalaxy {
// flip head when infected, but doesn't support model
if (!p.hasChangeModel) {
ZSData data = Server.zombie.TryGet(p);
ZSData data = ZSGame.TryGet(p);
if (data != null && data.Infected) pitch = FlippedPitch(pitch);
}

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Games {
/// <summary> Whether the current level name should be shown in the heartbeats sent. </summary>
[ConfigBool("zombie-map-inheartbeat", "Zombie", false)]
public static bool IncludeMapInHeartbeat = false;
public static bool IncludeMapInHeartbeat;
[ConfigBool("no-pillaring-during-zombie", "Zombie", true)]
public static bool NoPillaring = true;

View File

@ -0,0 +1,139 @@
/*
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 System.Data;
using MCGalaxy.DB;
using MCGalaxy.SQL;
namespace MCGalaxy.Games {
public sealed partial class ZSGame : RoundsGame {
TopStat statMostInfected, statMaxInfected, statMostSurvived, statMaxSurvived;
OfflineStatPrinter offlineZSStats;
OnlineStatPrinter onlineZSStats;
ChatToken infectedToken, survivedToken;
void HookStats() {
if (TopStat.Stats.Contains(statMostInfected)) return; // don't duplicate
statMostInfected = new TopStat("Infected", "ZombieStats", "TotalInfected",
() => "Most players infected", TopStat.FormatInteger);
statMaxInfected = new TopStat("Survived", "ZombieStats", "TotalRounds",
() => "Most rounds survived", TopStat.FormatInteger);
statMostSurvived = new TopStat("ConsecutiveInfected", "ZombieStats", "MaxInfected",
() => "Most consecutive infections", TopStat.FormatInteger);
statMaxSurvived = new TopStat("ConsecutiveSurvived", "ZombieStats", "MaxRounds",
() => "Most consecutive rounds survived", TopStat.FormatInteger);
infectedToken = new ChatToken("$infected", "Total number of players infected",
p => Get(p).TotalInfected.ToString());
survivedToken = new ChatToken("$survived", "Total number of rounds survived",
p => Get(p).TotalRoundsSurvived.ToString());
offlineZSStats = PrintOfflineZSStats;
onlineZSStats = PrintOnlineZSStats;
OfflineStat.Stats.Add(offlineZSStats);
OnlineStat.Stats.Add(onlineZSStats);
ChatTokens.Standard.Add(infectedToken);
ChatTokens.Standard.Add(survivedToken);
TopStat.Stats.Add(statMostInfected);
TopStat.Stats.Add(statMostSurvived);
TopStat.Stats.Add(statMaxInfected);
TopStat.Stats.Add(statMaxSurvived);
}
void UnhookStats() {
OfflineStat.Stats.Remove(offlineZSStats);
OnlineStat.Stats.Remove(onlineZSStats);
ChatTokens.Standard.Remove(infectedToken);
ChatTokens.Standard.Remove(survivedToken);
TopStat.Stats.Remove(statMostInfected);
TopStat.Stats.Remove(statMostSurvived);
TopStat.Stats.Remove(statMaxInfected);
TopStat.Stats.Remove(statMaxSurvived);
}
void PrintOnlineZSStats(Player p, Player who) {
ZSData data = Get(who);
PrintZSStats(p, data.TotalRoundsSurvived, data.TotalInfected,
data.MaxRoundsSurvived, data.MaxInfected);
}
void PrintOfflineZSStats(Player p, PlayerData who) {
ZombieStats stats = LoadStats(who.Name);
PrintZSStats(p, stats.TotalRounds, stats.TotalInfected,
stats.MaxRounds, stats.MaxInfected);
}
static void PrintZSStats(Player p, int rounds, int infected, int roundsMax, int infectedMax) {
Player.Message(p, " Survived &a{0} %Srounds (max &e{1}%S)", rounds, roundsMax);
Player.Message(p, " Infected &a{0} %Splayers (max &e{1}%S)", infected, infectedMax);
}
static ColumnDesc[] createSyntax = new ColumnDesc[] {
new ColumnDesc("ID", ColumnType.Integer, priKey: true, autoInc: true, notNull: true),
new ColumnDesc("Name", ColumnType.Char, 20),
new ColumnDesc("TotalRounds", ColumnType.Int32),
new ColumnDesc("MaxRounds", ColumnType.Int32),
new ColumnDesc("TotalInfected", ColumnType.Int32),
new ColumnDesc("MaxInfected", ColumnType.Int32),
// reserve space for possible future additions
new ColumnDesc("Additional1", ColumnType.Int32),
};
static ZombieStats LoadStats(string name) {
DataTable table = Database.Backend.GetRows("ZombieStats", "*", "WHERE Name=@0", name);
ZombieStats stats = default(ZombieStats);
if (table.Rows.Count > 0) {
DataRow row = table.Rows[0];
stats.TotalRounds = PlayerData.ParseInt(row["TotalRounds"].ToString());
stats.MaxRounds = PlayerData.ParseInt(row["MaxRounds"].ToString());
stats.TotalInfected = PlayerData.ParseInt(row["TotalInfected"].ToString());
stats.MaxInfected = PlayerData.ParseInt(row["MaxInfected"].ToString());
}
table.Dispose();
return stats;
}
static void SaveStats(Player p) {
ZSData data = TryGet(p);
if (data == null || data.TotalRoundsSurvived == 0 && data.TotalInfected == 0) return;
int count = 0;
using (DataTable table = Database.Backend.GetRows("ZombieStats", "*", "WHERE Name=@0", p.name)) {
count = table.Rows.Count;
}
if (count == 0) {
Database.Backend.AddRow("ZombieStats", "TotalRounds, MaxRounds, TotalInfected, MaxInfected, Name",
data.TotalRoundsSurvived, data.MaxRoundsSurvived,
data.TotalInfected, data.MaxInfected, p.name);
} else {
Database.Backend.UpdateRows("ZombieStats", "TotalRounds=@0, MaxRounds=@1, TotalInfected=@2, MaxInfected=@3",
"WHERE Name=@4", data.TotalRoundsSurvived, data.MaxRoundsSurvived,
data.TotalInfected, data.MaxInfected, p.name);
}
}
}
}

View File

@ -49,7 +49,7 @@ namespace MCGalaxy.Games {
OnJoinedLevelEvent.Register(HandleJoinedLevel, Priority.High);
OnPlayerChatEvent.Register(HandlePlayerChat, Priority.High);
OnSQLSaveEvent.Register(SavePlayerStats, Priority.High);
OnSQLSaveEvent.Register(SaveStats, Priority.High);
}
void UnhookEventHandlers() {
@ -68,7 +68,7 @@ namespace MCGalaxy.Games {
OnJoinedLevelEvent.Unregister(HandleJoinedLevel);
OnPlayerChatEvent.Unregister(HandlePlayerChat);
OnSQLSaveEvent.Unregister(SavePlayerStats);
OnSQLSaveEvent.Unregister(SaveStats);
}
@ -277,26 +277,5 @@ namespace MCGalaxy.Games {
}
return false;
}
void SavePlayerStats(Player p) {
ZSData data = TryGet(p);
if (data == null || data.TotalRoundsSurvived == 0 && data.TotalInfected == 0) return;
int count = 0;
using (DataTable table = Database.Backend.GetRows("ZombieStats", "*", "WHERE Name=@0", p.name)) {
count = table.Rows.Count;
}
if (count == 0) {
Database.Backend.AddRow("ZombieStats", "TotalRounds, MaxRounds, TotalInfected, MaxInfected, Name",
data.TotalRoundsSurvived, data.MaxRoundsSurvived,
data.TotalInfected, data.MaxInfected, p.name);
} else {
Database.Backend.UpdateRows("ZombieStats", "TotalRounds=@0, MaxRounds=@1, TotalInfected=@2, MaxInfected=@3",
"WHERE Name=@4", data.TotalRoundsSurvived, data.MaxRoundsSurvived,
data.TotalInfected, data.MaxInfected, p.name);
}
}
}
}

View File

@ -16,15 +16,13 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Threading;
using MCGalaxy.DB;
using MCGalaxy.Commands.World;
using MCGalaxy.Games.ZS;
using MCGalaxy.SQL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using MCGalaxy.DB;
using MCGalaxy.Games.ZS;
using MCGalaxy.SQL;
namespace MCGalaxy.Games {
@ -82,26 +80,26 @@ namespace MCGalaxy.Games {
List<string> infectMessages = new List<string>();
const string zsExtrasKey = "MCG_ZS_DATA";
internal ZSData Get(Player p) {
internal static ZSData Get(Player p) {
object data;
if (!p.Extras.TryGet("MCG_ZS_DATA", out data)) {
if (!p.Extras.TryGet(zsExtrasKey, out data)) {
data = new ZSData();
// TODO: Is this even thread-safe
InitData((ZSData)data, p);
p.Extras.Put("MCG_ZS_DATA", data);
p.Extras.Put(zsExtrasKey, data);
}
return (ZSData)data;
}
internal ZSData TryGet(Player p) {
internal static ZSData TryGet(Player p) {
object data;
bool success = p.Extras.TryGet("MCG_ZS_DATA", out data);
bool success = p.Extras.TryGet(zsExtrasKey, out data);
return success ? (ZSData)data : null;
}
void InitData(ZSData data, Player p) {
static void InitData(ZSData data, Player p) {
data.InfectMessages = PlayerDB.GetInfectMessages(p);
ZombieStats stats = LoadZombieStats(p.name);
ZombieStats stats = LoadStats(p.name);
data.MaxInfected = stats.MaxInfected; data.TotalInfected = stats.TotalInfected;
data.MaxRoundsSurvived = stats.MaxRounds; data.TotalRoundsSurvived = stats.TotalRounds;
}
@ -144,6 +142,7 @@ namespace MCGalaxy.Games {
HookStats();
Running = true;
Database.Backend.CreateTable("ZombieStats", createSyntax);
HookEventHandlers();
Thread t = new Thread(RunGame);
@ -332,105 +331,6 @@ namespace MCGalaxy.Games {
return ZSConfig.LevelList.Count == 0 || ZSConfig.LevelList.CaselessContains(name);
}
#region Database
static ColumnDesc[] createSyntax = new ColumnDesc[] {
new ColumnDesc("ID", ColumnType.Integer, priKey: true, autoInc: true, notNull: true),
new ColumnDesc("Name", ColumnType.Char, 20),
new ColumnDesc("TotalRounds", ColumnType.Int32),
new ColumnDesc("MaxRounds", ColumnType.Int32),
new ColumnDesc("TotalInfected", ColumnType.Int32),
new ColumnDesc("MaxInfected", ColumnType.Int32),
// reserve space for possible future additions
new ColumnDesc("Additional1", ColumnType.Int32),
new ColumnDesc("Additional2", ColumnType.Int32),
new ColumnDesc("Additional3", ColumnType.Int32),
new ColumnDesc("Additional4", ColumnType.Int32),
};
public void CheckTableExists() {
Database.Backend.CreateTable("ZombieStats", createSyntax);
}
public ZombieStats LoadZombieStats(string name) {
DataTable table = Database.Backend.GetRows("ZombieStats", "*", "WHERE Name=@0", name);
ZombieStats stats = default(ZombieStats);
if (table.Rows.Count > 0) {
DataRow row = table.Rows[0];
stats.TotalRounds = PlayerData.ParseInt(row["TotalRounds"].ToString());
stats.MaxRounds = PlayerData.ParseInt(row["MaxRounds"].ToString());
stats.TotalInfected = PlayerData.ParseInt(row["TotalInfected"].ToString());
stats.MaxInfected = PlayerData.ParseInt(row["MaxInfected"].ToString());
}
table.Dispose();
return stats;
}
TopStat statMostInfected, statMaxInfected, statMostSurvived, statMaxSurvived;
OfflineStatPrinter offlineZSStats;
OnlineStatPrinter onlineZSStats;
ChatToken infectedToken, survivedToken;
void HookStats() {
if (TopStat.Stats.Contains(statMostInfected)) return; // don't duplicate
statMostInfected = new TopStat("Infected", "ZombieStats", "TotalInfected",
() => "Most players infected", TopStat.FormatInteger);
statMaxInfected = new TopStat("Survived", "ZombieStats", "TotalRounds",
() => "Most rounds survived", TopStat.FormatInteger);
statMostSurvived = new TopStat("ConsecutiveInfected", "ZombieStats", "MaxInfected",
() => "Most consecutive infections", TopStat.FormatInteger);
statMaxSurvived = new TopStat("ConsecutiveSurvived", "ZombieStats", "MaxRounds",
() => "Most consecutive rounds survived", TopStat.FormatInteger);
infectedToken = new ChatToken("$infected", "Total number of players infected",
p => Get(p).TotalInfected.ToString());
survivedToken = new ChatToken("$survived", "Total number of rounds survived",
p => Get(p).TotalRoundsSurvived.ToString());
offlineZSStats = PrintOfflineZSStats;
onlineZSStats = PrintOnlineZSStats;
OfflineStat.Stats.Add(offlineZSStats);
OnlineStat.Stats.Add(onlineZSStats);
ChatTokens.Standard.Add(infectedToken);
ChatTokens.Standard.Add(survivedToken);
TopStat.Stats.Add(statMostInfected);
TopStat.Stats.Add(statMostSurvived);
TopStat.Stats.Add(statMaxInfected);
TopStat.Stats.Add(statMaxSurvived);
}
void UnhookStats() {
OfflineStat.Stats.Remove(offlineZSStats);
OnlineStat.Stats.Remove(onlineZSStats);
ChatTokens.Standard.Remove(infectedToken);
ChatTokens.Standard.Remove(survivedToken);
TopStat.Stats.Remove(statMostInfected);
TopStat.Stats.Remove(statMostSurvived);
TopStat.Stats.Remove(statMaxInfected);
TopStat.Stats.Remove(statMaxSurvived);
}
void PrintOnlineZSStats(Player p, Player who) {
ZSData data = Get(who);
PrintZSStats(p, data.TotalRoundsSurvived, data.TotalInfected,
data.MaxRoundsSurvived, data.MaxInfected);
}
void PrintOfflineZSStats(Player p, PlayerData who) {
ZombieStats stats = LoadZombieStats(who.Name);
PrintZSStats(p, stats.TotalRounds, stats.TotalInfected,
stats.MaxRounds, stats.MaxInfected);
}
static void PrintZSStats(Player p, int rounds, int infected, int roundsMax, int infectedMax) {
Player.Message(p, " Survived &a{0} %Srounds (max &e{1}%S)", rounds, roundsMax);
Player.Message(p, " Infected &a{0} %Splayers (max &e{1}%S)", infected, infectedMax);
}
#endregion
}
internal class ZSLevelPicker : LevelPicker {

View File

@ -506,6 +506,7 @@
<Compile Include="Games\TntWars\TntWars.cs" />
<Compile Include="Games\TntWars\TntWarsConfig.cs" />
<Compile Include="Games\ZombieSurvival\HUD.cs" />
<Compile Include="Games\ZombieSurvival\ZSGame.DB.cs" />
<Compile Include="Games\ZombieSurvival\ZSGame.Round.cs" />
<Compile Include="Games\ZombieSurvival\ZSGame.cs" />
<Compile Include="Games\ZombieSurvival\ZSGame.Plugin.cs" />

View File

@ -251,13 +251,14 @@ namespace MCGalaxy {
while (alts.CaselessRemove(p.name)) { }
if (alts.Count == 0) return;
LevelPermission rank = Chat.OpchatPerm;
LevelPermission rank = Chat.OpchatPerm;
string altsMsg = "λNICK %Sis lately known as: " + alts.Join();
Chat.MessageFrom(p, altsMsg,
(pl, obj) => Entities.CanSee(pl, p) && pl.Rank >= rank);
//IRCBot.Say(temp, true); //Tells people in op channel on IRC
altsMsg = altsMsg.Replace("λNICK", name);
Logger.Log(LogType.UserActivity, altsMsg);
}
}

View File

@ -105,7 +105,7 @@ namespace MCGalaxy {
}
if (!Server.zombie.Running || Game.Referee) return true;
ZSData data = Server.zombie.TryGet(target);
ZSData data = ZSGame.TryGet(target);
return data == null || !(target.Game.Referee || data.Invisible);
}

View File

@ -108,7 +108,6 @@ namespace MCGalaxy {
InitDatabase();
Economy.LoadDatabase();
Server.zombie.CheckTableExists();
Background.QueueOnce(UpgradeTasks.CombineEnvFiles);
Background.QueueOnce(LoadMainLevel);