Skip to content

Commit

Permalink
Fix self defense: no outlaw for kills under self defense
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-n committed Nov 5, 2024
1 parent 4ebe956 commit cc4f14b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/GameLogic/IGameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public interface IGameContext
DuelRoomManager DuelRoomManager { get; }

/// <summary>
/// Gets the state of the active self defenses.
/// Gets the state of the active self defenses. The datetime holds the timestamp when self-defense ends.
/// </summary>
ConcurrentDictionary<(Player Attacker, Player Defender), DateTime> SelfDefenseState { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/GameLogic/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public bool IsAnySelfDefenseActive()

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

if (hitInfo.HealthDamage == 0)
if (hitInfo is { HealthDamage: 0, ShieldDamage: 0 })
{
await this.InvokeViewPlugInAsync<IShowHitPlugIn>(p => p.ShowHitAsync(this, hitInfo)).ConfigureAwait(false);
if (attacker is IWorldObserver observer)
Expand Down
11 changes: 5 additions & 6 deletions src/GameLogic/PlugIns/SelfDefensePlugIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public class SelfDefensePlugIn : IPeriodicTaskPlugIn, IAttackableGotHitPlugIn, I
/// <inheritdoc />
public async ValueTask ExecuteTaskAsync(GameContext gameContext)
{
var configuration = this.Configuration ??= CreateDefaultConfiguration();
var timedOut = gameContext.SelfDefenseState.Where(s => DateTime.UtcNow.Subtract(s.Value) >= configuration.SelfDefenseTimeOut).ToList();
foreach (var (pair, lastAttack) in timedOut)
var timedOut = gameContext.SelfDefenseState.Where(s => s.Value < DateTime.UtcNow).ToList();
foreach (var (pair, _) in timedOut)
{
if (gameContext.SelfDefenseState.Remove(pair, out _))
{
Expand Down Expand Up @@ -80,16 +79,16 @@ public void AttackableGotHit(IAttackable attackable, IAttacker attacker, HitInfo
return;
}

var now = DateTime.UtcNow;
var timeout = DateTime.UtcNow.Add(this.Configuration?.SelfDefenseTimeOut ?? TimeSpan.FromMinutes(1));
var gameContext = defender.GameContext;
gameContext.SelfDefenseState.AddOrUpdate(
(attackerPlayer, defender),
tuple =>
{
_ = this.BeginSelfDefenseAsync(attackerPlayer, defender);
return now;
return timeout;
},
(_, _) => now);
(_, _) => timeout);
}

/// <inheritdoc />
Expand Down

0 comments on commit cc4f14b

Please sign in to comment.