Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the gamemode to start again #423

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions .addon
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"Type": "game",
"Org": "neox",
"Ident": "tttreborn",
"Tags": "",
"Schema": 1,
"HasAssets": true,
"AssetsPath": "",
"ResourcePaths": [
"/weapons/*",
"/sounds/*",
"/materials/*"
"/materials/*",
"/lang/*"
],
"HasCode": true,
"CodePath": "code",
"RootNamespace": "TTTReborn",
"Metadata": {
"MapList": [
"tbt.minecraftcity_v4",
Expand All @@ -26,6 +27,49 @@
"RankType": 0,
"MapSelect": 0,
"GameNetworkType": 0,
"MaxPlayers": 16
"MaxPlayers": 16,
"Collision": {
"Defaults": {
"solid": "Collide",
"trigger": "Trigger",
"ladder": "Ignore",
"water": "Trigger",
"corpse": "Collide",
"debris": "Unset",
"player": "Unset"
},
"Pairs": [
{
"a": "solid",
"b": "solid",
"r": "Collide"
},
{
"a": "trigger",
"b": "playerclip",
"r": "Ignore"
},
{
"a": "trigger",
"b": "solid",
"r": "Trigger"
},
{
"a": "solid",
"b": "trigger",
"r": "Collide"
},
{
"a": "playerclip",
"b": "solid",
"r": "Collide"
},
{
"a": "corpse",
"b": "player",
"r": "Ignore"
}
]
}
}
}
}
72 changes: 72 additions & 0 deletions code/CameraMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sandbox
{
public class CameraMode : EntityComponent
{
public Vector3 Position
{
get
{
return Camera.Position;
}
set
{
Camera.Position = value;
}
}
public Rotation Rotation
{
get
{
return Camera.Rotation;
}
set
{
Camera.Rotation = value;
}
}

public float FieldOfView
{
get
{
return Camera.FieldOfView;
}
set
{
Camera.FieldOfView = value;
}
}

public Entity Viewer
{
get
{
return Camera.FirstPersonViewer as Entity;
}
set
{
Camera.FirstPersonViewer = value;
}
}
public virtual void Deactivated() { }
public virtual void Activated() { }

public virtual void Build()
{
Update();
}

public virtual void BuildInput() { }

public virtual void Update()
{

}
}
}
8 changes: 4 additions & 4 deletions code/gameevents/base/ClientGameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public partial class ClientGameEvent : NetworkableGameEvent
public string PlayerName { get; set; }

[JsonIgnore]
public Client Client
public IClient Client
{
get => Client.All.First((cl) => cl.PlayerId == PlayerId);
get => Sandbox.Game.Clients.First((cl) => cl.SteamId == PlayerId);
}

public ClientGameEvent(Client client) : base()
public ClientGameEvent(IClient client) : base()
{
if (client != null)
{
PlayerId = client.PlayerId;
PlayerId = client.SteamId;
PlayerName = client.Name;
}
}
Expand Down
8 changes: 4 additions & 4 deletions code/gameevents/base/GameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GameEvent()
Name = attribute.Name;
}

BaseRound baseRound = Gamemode.Game.Instance.Round;
BaseRound baseRound = Gamemode.TTTGame.Instance.Round;

CreatedAt = baseRound.RoundEndTime - baseRound.StartedAt - baseRound.TimeLeft;
}
Expand All @@ -54,9 +54,9 @@ protected virtual void OnRegister()

internal void ProcessRegister()
{
if (Host.IsServer)
if (Game.IsServer)
{
Gamemode.Game.Instance.Round?.GameEvents.Add(this);
Gamemode.TTTGame.Instance.Round?.GameEvents.Add(this);

OnRegister();
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public GameEventScoring(Player player)
{
if (player != null && player.Client != null)
{
PlayerId = player.Client.PlayerId;
PlayerId = player.Client.SteamId;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions code/gameevents/base/ILoggedGameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public interface ILoggedGameEvent

public float CreatedAt { get; set; }

public virtual Sandbox.UI.Panel GetEventPanel(Client client = null) => new UI.EventPanel(this);
public virtual Sandbox.UI.Panel GetEventPanel(IClient client = null) => new UI.EventPanel(this);

public virtual bool Contains(Client client) => false;
public virtual bool Contains(IClient client) => false;
}
}
2 changes: 1 addition & 1 deletion code/gameevents/base/NetworkableGameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public virtual void RunNetworked(To to)

base.Run();

if (Host.IsServer)
if (Game.IsServer)
{
ServerCallNetworked(to);
}
Expand Down
2 changes: 1 addition & 1 deletion code/gameevents/base/PlayerGameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public PlayerGameEvent(TTTReborn.Player player) : base()
{
if (player != null && player.Client != null)
{
PlayerId = player.Client.PlayerId;
PlayerId = player.Client.SteamId;
PlayerName = player.Client.Name;
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/gameevents/game/FinishEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ protected override void OnRegister()
}
}

public bool Contains(Client client) => true;
public bool Contains(IClient client) => true;
}
}
2 changes: 1 addition & 1 deletion code/gameevents/player/ConnectedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public partial class ConnectedEvent : ClientGameEvent
/// Occurs when a player connects.
/// <para>The <strong><see cref="Client"/></strong> instance of the player who connected.</para>
/// </summary>
public ConnectedEvent(Client client) : base(client) { }
public ConnectedEvent(IClient client) : base(client) { }
}
}
2 changes: 1 addition & 1 deletion code/gameevents/player/DiedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ protected override void OnRegister()
};
}

public bool Contains(Client client) => PlayerName == client.Name || LastAttackerName == client.Name;
public bool Contains(IClient client) => PlayerName == client.Name || LastAttackerName == client.Name;
}
}
4 changes: 2 additions & 2 deletions code/gameevents/player/InitialSpawnEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public partial class InitialSpawnEvent : ClientGameEvent
{
/// <summary>
/// Occurs when a player initializes.
/// <para>The <strong><see cref="Client"/></strong> instance of the player who spawned initially.</para>
/// <para>The <strong><see cref="IClient"/></strong> instance of the player who spawned initially.</para>
/// </summary>
public InitialSpawnEvent(Client client) : base(client) { }
public InitialSpawnEvent(IClient client) : base(client) { }
}
}
2 changes: 1 addition & 1 deletion code/gameevents/player/SpawnEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public partial class SpawnEvent : PlayerGameEvent, ILoggedGameEvent
/// </summary>
public SpawnEvent(TTTReborn.Player player) : base(player) { }

public bool Contains(Client client) => PlayerName == client.Name;
public bool Contains(IClient client) => PlayerName == client.Name;
}
}
6 changes: 3 additions & 3 deletions code/gameevents/player/TakeDamageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TakeDamageEvent(TTTReborn.Player player, float damage, Entity attacker) :
if (attacker is TTTReborn.Player)
{
AttackerName = attacker.Client.Name;
AttackerPlayerId = attacker.Client.PlayerId;
AttackerPlayerId = attacker.Client.SteamId;
}
else
{
Expand Down Expand Up @@ -121,7 +121,7 @@ public static void OnLoggedGameEventEvaluate(List<ILoggedGameEvent> gameEvents)
}
}

public bool Contains(Client client) => PlayerName == client.Name || AttackerName == client.Name;
public bool Contains(IClient client) => PlayerName == client.Name || AttackerName == client.Name;

protected override void OnRegister()
{
Expand All @@ -136,7 +136,7 @@ protected override void OnRegister()
{
new(attacker)
{
Karma = Gamemode.Game.Instance.Karma.CalculatePenalty(Math.Min(Damage, Player.Health))
Karma = Gamemode.TTTGame.Instance.Karma.CalculatePenalty(Math.Min(Damage, Player.Health))
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion code/gameevents/player/role/SelectEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public SelectEvent(TTTReborn.Player player) : base(player)
}
}

public bool Contains(Client client) => PlayerName == client.Name;
public bool Contains(IClient client) => PlayerName == client.Name;
}
}
6 changes: 3 additions & 3 deletions code/gamemode/Karma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class KarmaSystem
// [ServerVar("ttt_karma_penalty_max", Help = "The maximum amount of karma loss per player.")]
// public static int TTTKarmaPenaltyMax { get; set; } = 100;

public void RegisterPlayer(Client client)
public void RegisterPlayer(IClient client)
{
client.SetInt("karma", 1000);
}
Expand All @@ -47,7 +47,7 @@ public void RegisterPlayerDamage(Player attacker, Player victim, float damage)

public void UpdatePlayerKarma(Player player, int delta)
{
UpdatePlayerIdKarma(player.Client.PlayerId, delta);
UpdatePlayerIdKarma(player.Client.SteamId, delta);
}

public void UpdatePlayerIdKarma(long playerId, int delta)
Expand Down Expand Up @@ -84,7 +84,7 @@ public void ResolveKarma()
// DamageRecords = new();
}

public bool IsBanned(Client client)
public bool IsBanned(IClient client)
{
// TODO: Once network dictionaries are supported, implement. Return false meanwhile...
// return (KarmaRecords[player.PlayerId] < TTTKarmaMin && TTTKarmaBan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace TTTReborn.Gamemode
{
public partial class Game
public partial class TTTGame
{
public static void PrecacheFiles()
{
Host.AssertServer();
Game.AssertServer();

Precache.Add("particles/impact.generic.vpcf");
Precache.Add("particles/impact.flesh.vpcf");
Expand Down
Loading