Skip to content

Commit

Permalink
Merge pull request #483 from nReCon/pvp-option-2
Browse files Browse the repository at this point in the history
Added PVP option to GameServerDefinition and AdminPanel
  • Loading branch information
sven-n authored Sep 3, 2024
2 parents 8a39305 + 657a1c7 commit 6f38b88
Show file tree
Hide file tree
Showing 10 changed files with 5,070 additions and 1 deletion.
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

0 comments on commit 6f38b88

Please sign in to comment.