Skip to content

Commit

Permalink
ZS: Move pledged state to ZSData rather than GameProps
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Dec 13, 2022
1 parent 56e8d45 commit 566ca7e
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 34 deletions.
11 changes: 6 additions & 5 deletions MCGalaxy/Commands/Fun/ZombieSurvival/CmdHuman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public sealed class CmdHuman : Command2 {
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
public override bool SuperUseable { get { return false; } }

public override void Use(Player p, string message, CommandData data) {
if (p.Game.PledgeSurvive) {
public override void Use(Player p, string message, CommandData data_) {
ZSData data = ZSGame.Get(p);
if (data.PledgeSurvive) {
p.Message("You cannot un-pledge that you will be infected."); return;
}
if (ZSGame.IsInfected(p)) {
Expand All @@ -45,9 +46,9 @@ public sealed class CmdHuman : Command2 {
TimeSpan delta = ZSGame.Instance.RoundEnd - DateTime.UtcNow;
if (delta < TimeSpan.FromMinutes(3)) {
p.Message("Cannot use &T/human &Sin last three minutes of a round."); return;
}
p.Game.PledgeSurvive = true;
}

data.PledgeSurvive = true;
ZSGame.Instance.Map
.Message(p.ColoredName + " &Spledges that they will not succumb to the infection!");
}
Expand Down
5 changes: 1 addition & 4 deletions MCGalaxy/CorePlugin/CorePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
using System;
using MCGalaxy.Events;
using MCGalaxy.Events.EconomyEvents;
using MCGalaxy.Events.GroupEvents;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Events.ServerEvents;
using MCGalaxy.Tasks;

namespace MCGalaxy.Core {

public sealed class CorePlugin : Plugin {
public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.Version; } }
public override string MCGalaxy_Version { get { return null; } }
public override string name { get { return "CorePlugin"; } }

public override void Load(bool startup) {
Expand Down
3 changes: 0 additions & 3 deletions MCGalaxy/Games/GameProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class GameProps {

/// <summary> Whether the player has liked or disliked the map in this round. </summary>
internal bool RatedMap = false, LikedMap = false;

/// <summary> Whether the player has pledged that they will survive/win in this round. </summary>
internal bool PledgeSurvive = false;

//Zombie
public bool Referee = false;
Expand Down
10 changes: 4 additions & 6 deletions MCGalaxy/Games/RoundsGame/RoundsGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
using System;
using System.Collections.Generic;
using System.Threading;
using MCGalaxy.Commands.World;
using MCGalaxy.Events.GameEvents;

namespace MCGalaxy.Games {

public abstract partial class RoundsGame : IGame {
namespace MCGalaxy.Games
{
public abstract partial class RoundsGame : IGame
{
public int RoundsLeft;
public bool RoundInProgress;
public DateTime RoundStart;
Expand Down Expand Up @@ -217,7 +217,6 @@ public abstract partial class RoundsGame : IGame {

foreach (Player pl in online) {
pl.Game.RatedMap = false;
pl.Game.PledgeSurvive = false;
if (pl.level != Map && pl.level == lastMap) transfers.Add(pl);
}

Expand Down Expand Up @@ -254,7 +253,6 @@ public abstract partial class RoundsGame : IGame {
foreach (Player pl in players) {
if (pl.level != Map) continue;
pl.Game.RatedMap = false;
pl.Game.PledgeSurvive = false;
PlayerLeftGame(pl);

TabList.Update(pl, true);
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ public sealed partial class ZSGame : RoundsGame {
HandleJoinedCommon(p, prevLevel, level, ref announce);
p.SetPrefix(); // TODO: Kinda hacky, not sure if needed
if (level != Map) return;

ZSData data = Get(p);
data.PledgeSurvive = false;
p.SetPrefix();

if (RoundInProgress) {
Expand Down
23 changes: 17 additions & 6 deletions MCGalaxy/Games/ZombieSurvival/ZSGame.Round.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public sealed partial class ZSGame : RoundsGame

protected override void DoRound() {
if (!Running) return;

ResetPledges();
List<Player> players = DoRoundCountdown(Config.InfectionCountdown);
if (players == null) return;

Expand All @@ -39,6 +41,13 @@ public sealed partial class ZSGame : RoundsGame
if (!Running) return;
DoCoreGame();
}

void ResetPledges() {
foreach (Player pl in GetPlayers())
{
Get(pl).PledgeSurvive = false;
}
}

void StartRound(List<Player> players) {
TimeSpan duration = Map.Config.RoundTime;
Expand All @@ -53,7 +62,7 @@ public sealed partial class ZSGame : RoundsGame
Infected.Clear();

Random rnd = new Random();
Player first = null;
Player first;
do {
first = QueuedZombie != null ? PlayerInfo.FindExact(QueuedZombie) : players[rnd.Next(players.Count)];
QueuedZombie = null;
Expand Down Expand Up @@ -170,8 +179,9 @@ public sealed partial class ZSGame : RoundsGame
}

void CheckHumanPledge(Player p, Player killer) {
if (!p.Game.PledgeSurvive) return;
p.Game.PledgeSurvive = false;
ZSData data = Get(p);
if (!data.PledgeSurvive) return;
data.PledgeSurvive = false;
Map.Message("&c" + p.DisplayName + " &Sbroke their pledge of not being infected.");

if (killer == null) {
Expand Down Expand Up @@ -264,13 +274,14 @@ public sealed partial class ZSGame : RoundsGame
}

void IncreaseAliveStats(Player p) {
if (p.Game.PledgeSurvive) {
ZSData data = Get(p);

if (data.PledgeSurvive) {
p.Message("You received &a5 &3" + Server.Config.Currency +
" &Sfor successfully pledging that you would survive.");
p.SetMoney(p.money + 5);
}

ZSData data = Get(p);
data.CurrentRoundsSurvived++;
data.TotalRoundsSurvived++;
data.MaxRoundsSurvived = Math.Max(data.CurrentRoundsSurvived, data.MaxRoundsSurvived);
Expand All @@ -296,7 +307,7 @@ public sealed partial class ZSGame : RoundsGame

pl.SetMoney(pl.money + reward);
ResetRoundState(pl, data);
pl.Game.PledgeSurvive = false;
data.PledgeSurvive = false;

if (pl.Game.Referee) {
pl.Message("You gained one " + Server.Config.Currency + " because you're a ref. Would you like a medal as well?");
Expand Down
3 changes: 3 additions & 0 deletions MCGalaxy/Games/ZombieSurvival/ZSGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal sealed class ZSData

public DateTime LastPillarWarn;
public bool PillarFined;
/// <summary> Whether the player has pledged that they will survive this round. </summary>
public bool PledgeSurvive;

public void ResetInvisibility() {
Invisible = false;
Expand Down Expand Up @@ -78,6 +80,7 @@ public sealed partial class ZSGame : RoundsGame
data = new ZSData();

// TODO: Is this even thread-safe
// TODO don't load here, add a LoadInfectMessages method
data.InfectMessages = ZSConfig.LoadPlayerInfectMessages(p.name);
ZombieStats s = LoadStats(p.name);
data.MaxInfected = s.MaxInfected; data.TotalInfected = s.TotalInfected;
Expand Down
4 changes: 3 additions & 1 deletion MCGalaxy/MCGalaxy_.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Modules\Games\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
3 changes: 1 addition & 2 deletions MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace MCGalaxy.Modules.Moderation.Notes
{
public sealed class NotesPlugin : Plugin
{
public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.Version; } }
public override string MCGalaxy_Version { get { return null; } }
public override string name { get { return "Core_NotesPlugin"; } }

Command notesCmd = new CmdNotes();
Expand Down
3 changes: 1 addition & 2 deletions MCGalaxy/Modules/Relay/Discord/DiscordPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public enum PresenceActivity { Playing = 0, Listening = 2, Watching = 3, Competi

public sealed class DiscordPlugin : Plugin
{
public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.Version; } }
public override string MCGalaxy_Version { get { return null; } }
public override string name { get { return "DiscordRelay"; } }

public static DiscordConfig Config = new DiscordConfig();
Expand Down
3 changes: 1 addition & 2 deletions MCGalaxy/Modules/Relay/IRC/IRCPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace MCGalaxy.Modules.Relay.IRC
{
public sealed class IRCPlugin : Plugin
{
public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.Version; } }
public override string MCGalaxy_Version { get { return null; } }
public override string name { get { return "IRCRelay"; } }

public static IRCBot Bot = new IRCBot();
Expand Down
3 changes: 1 addition & 2 deletions MCGalaxy/Modules/Security/IPThrottler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ namespace MCGalaxy.Modules.Security
{
public sealed class IPThrottler : Plugin
{
public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.Version; } }
public override string MCGalaxy_Version { get { return null; } }
public override string name { get { return "IPThrottler"; } }

SchedulerTask clearTask;
Expand Down

0 comments on commit 566ca7e

Please sign in to comment.