baseline: OpenMU upstream b5a0961 (fresh source)
This commit is contained in:
66
src/GameLogic/GuildWar/GuildWarContext.cs
Normal file
66
src/GameLogic/GuildWar/GuildWarContext.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
// <copyright file="GuildWarContext.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameLogic.GuildWar;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the information about an ongoing guild war.
|
||||
/// </summary>
|
||||
public class GuildWarContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GuildWarContext"/> class.
|
||||
/// </summary>
|
||||
/// <param name="warType">Type of the war.</param>
|
||||
/// <param name="score">The score.</param>
|
||||
/// <param name="team">The team.</param>
|
||||
/// <param name="requester">The requester.</param>
|
||||
public GuildWarContext(GuildWarType warType, GuildWarScore score, GuildWarTeam team, Player? requester)
|
||||
{
|
||||
this.WarType = warType;
|
||||
this.Score = score;
|
||||
this.Team = team;
|
||||
this.Requester = requester;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the war.
|
||||
/// </summary>
|
||||
public GuildWarType WarType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the score.
|
||||
/// </summary>
|
||||
public GuildWarScore Score { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the team.
|
||||
/// </summary>
|
||||
public GuildWarTeam Team { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the initial requester.
|
||||
/// </summary>
|
||||
public Player? Requester { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the state.
|
||||
/// </summary>
|
||||
public GuildWarState State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the enemy team.
|
||||
/// </summary>
|
||||
public string EnemyTeamName => this.Team == GuildWarTeam.First ? this.Score.SecondGuildName : this.Score.FirstGuildName;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the score for this guild.
|
||||
/// </summary>
|
||||
public byte ThisScore => this.Team == GuildWarTeam.First ? this.Score.FirstGuildScore : this.Score.SecondGuildScore;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the score of the enemy guild.
|
||||
/// </summary>
|
||||
public byte EnemyScore => this.Team == GuildWarTeam.First ? this.Score.SecondGuildScore : this.Score.FirstGuildScore;
|
||||
}
|
||||
103
src/GameLogic/GuildWar/GuildWarScore.cs
Normal file
103
src/GameLogic/GuildWar/GuildWarScore.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
// <copyright file="GuildWarScore.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameLogic.GuildWar;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
/// <summary>
|
||||
/// The score of a guild war.
|
||||
/// </summary>
|
||||
/// <seealso cref="System.ComponentModel.INotifyPropertyChanged" />
|
||||
public class GuildWarScore : INotifyPropertyChanged
|
||||
{
|
||||
private uint _firstGuildScore;
|
||||
|
||||
private uint _secondGuildScore;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a property value changes.
|
||||
/// </summary>
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the first guild.
|
||||
/// </summary>
|
||||
public string FirstGuildName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the second guild.
|
||||
/// </summary>
|
||||
public string SecondGuildName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the score of the first guild.
|
||||
/// </summary>
|
||||
public byte FirstGuildScore => (byte)Math.Min(byte.MaxValue, this._firstGuildScore);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the score of the second guild.
|
||||
/// </summary>
|
||||
public byte SecondGuildScore => (byte)Math.Min(byte.MaxValue, this._secondGuildScore);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the guild war has ended.
|
||||
/// </summary>
|
||||
public bool HasEnded => this._firstGuildScore >= this.MaximumScore || this._secondGuildScore >= this.MaximumScore;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum score.
|
||||
/// </summary>
|
||||
public byte MaximumScore { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the winners of the guild war.
|
||||
/// </summary>
|
||||
public GuildWarTeam? Winners { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Increases the score of the first guild.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
public void IncreaseFirstGuildScore(byte value = 1)
|
||||
{
|
||||
if (!this.HasEnded)
|
||||
{
|
||||
Interlocked.Add(ref this._firstGuildScore, value);
|
||||
this.RaisePropertyChanged(nameof(this.FirstGuildScore));
|
||||
if (this.HasEnded)
|
||||
{
|
||||
this.Winners = GuildWarTeam.First;
|
||||
this.RaisePropertyChanged(nameof(this.HasEnded));
|
||||
this.PropertyChanged = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increases the score of the first guild.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
public void IncreaseSecondGuildScore(byte value = 1)
|
||||
{
|
||||
if (!this.HasEnded)
|
||||
{
|
||||
Interlocked.Add(ref this._secondGuildScore, value);
|
||||
this.RaisePropertyChanged(nameof(this.SecondGuildScore));
|
||||
if (this.HasEnded)
|
||||
{
|
||||
this.Winners = GuildWarTeam.Second;
|
||||
this.RaisePropertyChanged(nameof(this.HasEnded));
|
||||
this.PropertyChanged = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RaisePropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
26
src/GameLogic/GuildWar/GuildWarState.cs
Normal file
26
src/GameLogic/GuildWar/GuildWarState.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
// <copyright file="GuildWarState.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameLogic.GuildWar;
|
||||
|
||||
/// <summary>
|
||||
/// The state of a guild war.
|
||||
/// </summary>
|
||||
public enum GuildWarState
|
||||
{
|
||||
/// <summary>
|
||||
/// The guild war was requested.
|
||||
/// </summary>
|
||||
Requested,
|
||||
|
||||
/// <summary>
|
||||
/// The guild war was started and is ongoing.
|
||||
/// </summary>
|
||||
Started,
|
||||
|
||||
/// <summary>
|
||||
/// The guild war has ended.
|
||||
/// </summary>
|
||||
Ended,
|
||||
}
|
||||
21
src/GameLogic/GuildWar/GuildWarTeam.cs
Normal file
21
src/GameLogic/GuildWar/GuildWarTeam.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// <copyright file="GuildWarTeam.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameLogic.GuildWar;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the team of a guild war.
|
||||
/// </summary>
|
||||
public enum GuildWarTeam
|
||||
{
|
||||
/// <summary>
|
||||
/// The first team.
|
||||
/// </summary>
|
||||
First,
|
||||
|
||||
/// <summary>
|
||||
/// The second team.
|
||||
/// </summary>
|
||||
Second,
|
||||
}
|
||||
21
src/GameLogic/GuildWar/GuildWarType.cs
Normal file
21
src/GameLogic/GuildWar/GuildWarType.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// <copyright file="GuildWarType.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameLogic.GuildWar;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the type of a guild war.
|
||||
/// </summary>
|
||||
public enum GuildWarType
|
||||
{
|
||||
/// <summary>
|
||||
/// A normal guild war, where two parties fight against each other on a normal game map.
|
||||
/// </summary>
|
||||
Normal,
|
||||
|
||||
/// <summary>
|
||||
/// A battle soccer match, where two parties play against each other on a <see cref="SoccerGameMap"/>.
|
||||
/// </summary>
|
||||
Soccer,
|
||||
}
|
||||
Reference in New Issue
Block a user