Skip to content

Commit

Permalink
ZS/CTF: Allow configuring collision detection interval, and reduce de…
Browse files Browse the repository at this point in the history
…fault collisions check interval to 150 milliseconds
  • Loading branch information
UnknownShadow200 committed Jun 28, 2023
1 parent 030b5a3 commit bf7372a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion MCGalaxy/Commands/Moderation/ModActionCmd.cs
Expand Up @@ -212,7 +212,8 @@ public static class ModActionCmd {
// TODO ip.ToString()
if (PlayerDB.FindName(account) == null) return message;

// Some classicube.net accounts can be parsed as valid IPs, so warn in this case.
// ClassiCube.net used to allow registering accounts with . anywhere in name,
// so some older names can be parsed as valid IPs. Warn in this case
p.Message("Note: \"{0}\" is both an IP and an account name. "
+ "If you meant the account, use &T/{1} @{0}", message, cmd);
return message;
Expand Down
4 changes: 3 additions & 1 deletion MCGalaxy/Modules/Games/CTF/CtfConfig.cs
Expand Up @@ -31,8 +31,10 @@ public sealed class CTFConfig : RoundsGameConfig
public override bool AllowAutoload { get { return false; } }
protected override string GameName { get { return "CTF"; } }

[ConfigFloat("tag-distance", "Player", 1f)]
[ConfigFloat("tag-distance", "Collisions", 1f)]
public float TagDistance = 1f;
[ConfigInt("collisions-check-interval", "Collisions", 150, 20, 2000)]
public int CollisionsCheckInterval = 150;
}

public sealed class CTFMapConfig : RoundsGameMapConfig
Expand Down
14 changes: 8 additions & 6 deletions MCGalaxy/Modules/Games/CTF/CtfGame.Round.cs
Expand Up @@ -32,9 +32,10 @@ public sealed partial class CTFGame : RoundsGame
if (!Running) return;

RoundInProgress = true;
while (Running && RoundInProgress && !HasSomeoneWon()) {
while (Running && RoundInProgress && !HasSomeoneWon())
{
Tick();
Thread.Sleep(300);
Thread.Sleep(Config.CollisionsCheckInterval);
}
}

Expand All @@ -46,27 +47,28 @@ public sealed partial class CTFGame : RoundsGame
int dist = (int)(Config.TagDistance * 32);
Player[] online = PlayerInfo.Online.Items;

foreach (Player p in online) {
foreach (Player p in online)
{
if (p.level != Map) continue;
CtfTeam team = TeamOf(p);
CtfData data = Get(p);

// Draw flag above player head
if (data.HasFlag) DrawPlayerFlag(p, data);

if (team == null || data.TagCooldown) continue;
if (team == null || data.TagCooldown) continue;
if (!OnOwnTeamSide(p.Pos.BlockZ, team)) continue;
CtfTeam opposing = Opposing(team);

Player[] opponents = opposing.Members.Items;
foreach (Player other in opponents) {
foreach (Player other in opponents)
{
if (!InRange(p, other, dist)) continue;
CtfData otherData = Get(other);

otherData.TagCooldown = true;
other.Message(p.ColoredName + " &Stagged you!");
PlayerActions.Respawn(other);
Thread.Sleep(300); // TODO: get rid of this

if (otherData.HasFlag) DropFlag(p, opposing);
data.Points += cfg.Tag_PointsGained;
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Games/CTF/CtfGame.cs
Expand Up @@ -190,7 +190,7 @@ public sealed partial class CTFGame : RoundsGame
}

CtfTeam TeamOf(Player p) {
if (Red.Members.Contains(p)) return Red;
if (Red.Members.Contains(p)) return Red;
if (Blue.Members.Contains(p)) return Blue;
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions MCGalaxy/Modules/Games/ZombieSurvival/ZSConfig.cs
Expand Up @@ -29,10 +29,12 @@ public sealed class ZSConfig : RoundsGameConfig
[ConfigInt("infection-start-countdown", "Round", 30, 0)]
public int InfectionCountdown = 30;

[ConfigFloat("zombie-hitbox-distance", "Zombie", 1f)]
[ConfigFloat("zombie-hitbox-distance", "Collisions", 1f)]
public float HitboxDist = 1f;
[ConfigFloat("zombie-max-move-distance", "Zombie", 1.5625f)]
[ConfigFloat("zombie-max-move-distance", "Collisions", 1.5625f)]
public float MaxMoveDist = 1.5625f;
[ConfigInt("collisions-check-interval", "Collisions", 150, 20, 2000)]
public int CollisionsCheckInterval = 150;

[ConfigString("human-tablist-group", "Human", "&fHumans")]
public string HumanTabListGroup = "&fHumans";
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Games/ZombieSurvival/ZSGame.Round.cs
Expand Up @@ -103,7 +103,7 @@ public sealed partial class ZSGame : RoundsGame

DoCollisions(alive, infected, random);
CheckInvisibilityTime();
Thread.Sleep(200);
Thread.Sleep(Config.CollisionsCheckInterval);
alive = Alive.Items;
}
}
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/Modules/Games/ZombieSurvival/ZSGame.cs
Expand Up @@ -118,7 +118,8 @@ public sealed partial class ZSGame : RoundsGame
Player[] players = PlayerInfo.Online.Items;
List<Player> playing = new List<Player>();

foreach (Player pl in players) {
foreach (Player pl in players)
{
if (pl.level != Map || pl.Game.Referee) continue;
playing.Add(pl);
}
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/Player/PlayerInfo.cs
Expand Up @@ -89,7 +89,8 @@ public static class PlayerInfo
Player[] players = PlayerInfo.Online.Items;
name = Server.ToRawUsername(name);

foreach (Player p in players) {
foreach (Player p in players)
{
if (p.truename.CaselessEq(name)) return p;
}
return null;
Expand Down

0 comments on commit bf7372a

Please sign in to comment.