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

Added PVP option to GameServerDefinition and AdminPanel #483

Merged
merged 3 commits into from
Sep 3, 2024
Merged
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
3 changes: 3 additions & 0 deletions src/Dapr/GameServer.Host/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<span class="badge badge-primary">
Experience Rate: <span class="badge badge-light">@_gameServerContext.ExperienceRate</span>
</span>
<span class="badge badge-primary">
PVP Enabled: <span class="badge badge-light">@_gameServerContext.PvpEnabled</span>
</span>
</h3>
</p>

Expand Down
5 changes: 5 additions & 0 deletions src/DataModel/Configuration/GameServerDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public partial class GameServerDefinition
/// </summary>
public float ExperienceRate { get; set; }

/// <summary>
/// Gets or sets a value indicating whether PVP is enabled on this server.
/// </summary>
public bool PvpEnabled { get; set; } = true;

/// <summary>
/// Gets or sets the server configuration.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/GameLogic/GameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public GameContext(GameConfiguration configuration, IPersistenceContextProvider
/// <inheritdoc />
public virtual float ExperienceRate => this.Configuration.ExperienceRate;

/// <inheritdoc />
public virtual bool PvpEnabled { get; }

/// <inheritdoc/>
public GameConfiguration Configuration { get; }

Expand Down
5 changes: 5 additions & 0 deletions src/GameLogic/IGameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public interface IGameContext
/// Gets the global experience rate.
/// </summary>
float ExperienceRate { get; }

/// <summary>
/// Gets a value indicating whether PVP is enabled.
/// </summary>
bool PvpEnabled { get; }

/// <summary>
/// Gets the repository provider. Used to retrieve data, e.g. from a database.
Expand Down
6 changes: 6 additions & 0 deletions src/GameLogic/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ public bool IsAnySelfDefenseActive()
throw new InvalidOperationException("AttributeSystem not set.");
}

if (!this.GameContext.PvpEnabled && this.CurrentMap?.Definition.BattleZone == null &&
this.CurrentMiniGame?.AllowPlayerKilling is false)
{
return null;
}

var hitInfo = await attacker.CalculateDamageAsync(this, skill, isCombo, damageFactor).ConfigureAwait(false);

if (hitInfo.HealthDamage == 0)
Expand Down
3 changes: 3 additions & 0 deletions src/GameServer/GameServerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public GameServerContext(
/// <inheritdoc />
public override float ExperienceRate => base.ExperienceRate * this._gameServerDefinition.ExperienceRate;

/// <inheritdoc />
public override bool PvpEnabled => this._gameServerDefinition.PvpEnabled;

/// <inheritdoc />
public override string ToString()
{
Expand Down
5 changes: 4 additions & 1 deletion src/Persistence/EntityFramework/EntityDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<ConnectServerDefinition>();
modelBuilder.Entity<ChatServerDefinition>();
modelBuilder.Entity<MiniGameRankingEntry>();
modelBuilder.Entity<GameServerDefinition>();
modelBuilder.Entity<GameServerDefinition>(entity =>
{
entity.Property(e => e.PvpEnabled).HasDefaultValue(true);
});
modelBuilder.Entity<ConfigurationUpdate>();
modelBuilder.Entity<ConfigurationUpdateState>();
modelBuilder.Entity<SystemConfiguration>();
Expand Down
Loading