forked from project-redbud/FunGame-Core
抽象 ActionQueue,分离模式 (#134)
* 抽象 ActionQueue,方便继承扩展;RoundRecord 添加了记录发动技能的字典;特效添加 IsSubsidiary 属性 * 修改包名 * modify --------- Co-authored-by: yeziuku <yezi@wrss.org>
This commit is contained in:
parent
144cdd4ddd
commit
290b9fe26b
@ -55,10 +55,15 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// </summary>
|
||||
public virtual bool DurativeWithoutDuration { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否是某个特效的附属
|
||||
/// </summary>
|
||||
public virtual bool IsSubsidiary { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示在状态栏
|
||||
/// </summary>
|
||||
public bool ShowInStatusBar => Skill.Item is null || (Durative && Duration > 0) || DurationTurn > 0 || DurativeWithoutDuration;
|
||||
public bool ShowInStatusBar => Skill.Item is null || (Durative && Duration > 0) || DurationTurn > 0 || DurativeWithoutDuration || IsSubsidiary;
|
||||
|
||||
/// <summary>
|
||||
/// 特效是否生效
|
||||
|
||||
@ -19,7 +19,8 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
public Dictionary<Character, bool> IsEvaded { get; set; } = [];
|
||||
public Dictionary<Character, bool> IsImmune { get; set; } = [];
|
||||
public Dictionary<Character, double> Heals { get; set; } = [];
|
||||
public Dictionary<Character, List<EffectType>> Effects { get; set; } = [];
|
||||
public Dictionary<Character, Effect> Effects { get; set; } = [];
|
||||
public Dictionary<Character, List<EffectType>> ApplyEffects { get; set; } = [];
|
||||
public List<string> ActorContinuousKilling { get; set; } = [];
|
||||
public List<string> DeathContinuousKilling { get; set; } = [];
|
||||
public double CastTime { get; set; } = 0;
|
||||
@ -27,6 +28,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
public Dictionary<Character, double> RespawnCountdowns { get; set; } = [];
|
||||
public List<Character> Respawns { get; set; } = [];
|
||||
public List<Skill> RoundRewards { get; set; } = [];
|
||||
public List<string> OtherMessages { get; set; } = [];
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@ -37,6 +39,12 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
builder.AppendLine($"[ {Actor} ] 回合奖励 -> {string.Join(" / ", RoundRewards.Select(s => s.Description)).Trim()}");
|
||||
}
|
||||
|
||||
if (Effects.Count > 0)
|
||||
{
|
||||
builder.AppendLine($"[ {Actor} ] 发动了技能:{string.Join(",", Effects.Where(kv => kv.Key == Actor).Select(e => e.Value.Name))}");
|
||||
}
|
||||
|
||||
if (ActionType == CharacterActionType.NormalAttack || ActionType == CharacterActionType.CastSkill || ActionType == CharacterActionType.CastSuperSkill)
|
||||
{
|
||||
if (ActionType == CharacterActionType.NormalAttack)
|
||||
@ -110,7 +118,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
{
|
||||
hasHeal = $"治疗:{heals:0.##}";
|
||||
}
|
||||
if (Effects.TryGetValue(target, out List<EffectType>? effectTypes) && effectTypes != null)
|
||||
if (ApplyEffects.TryGetValue(target, out List<EffectType>? effectTypes) && effectTypes != null)
|
||||
{
|
||||
hasEffect = $"施加:{string.Join(" + ", effectTypes.Select(SkillSet.GetEffectTypeName))}";
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<DocumentationFile></DocumentationFile>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Copyright>Project Redbud and Contributors</Copyright>
|
||||
<PackageId>ProjectRedbud.$(AssemblyName)</PackageId>
|
||||
<PackageId>$(AssemblyName)</PackageId>
|
||||
<Description>FunGame.Core: A C#.NET library for turn-based games.</Description>
|
||||
<PackageTags>game;turn-based;server;framework;dotnet;csharp;gamedev</PackageTags>
|
||||
<PackageReleaseNotes>
|
||||
|
||||
3265
Model/ActionQueue.cs
3265
Model/ActionQueue.cs
File diff suppressed because it is too large
Load Diff
3049
Model/GamingQueue.cs
Normal file
3049
Model/GamingQueue.cs
Normal file
File diff suppressed because it is too large
Load Diff
120
Model/MixGamingQueue.cs
Normal file
120
Model/MixGamingQueue.cs
Normal file
@ -0,0 +1,120 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
public class MixGamingQueue : GamingQueue
|
||||
{
|
||||
/// <summary>
|
||||
/// 死亡结算后
|
||||
/// </summary>
|
||||
/// <param name="death"></param>
|
||||
/// <param name="killer"></param>
|
||||
/// <returns></returns>
|
||||
protected override async Task AfterDeathCalculation(Character death, Character killer)
|
||||
{
|
||||
if (MaxRespawnTimes != 0 && MaxScoreToWin > 0)
|
||||
{
|
||||
WriteLine($"\r\n=== 当前死亡竞赛比分 ===\r\n{string.Join("\r\n", _stats.OrderByDescending(kv => kv.Value.Kills)
|
||||
.Select(kv => $"[ {kv.Key} ] {kv.Value.Kills} 分"))}\r\n剩余存活人数:{_queue.Count}");
|
||||
}
|
||||
|
||||
if (!_queue.Where(c => c != killer).Any())
|
||||
{
|
||||
// 没有其他的角色了,游戏结束
|
||||
await EndGameInfo(killer);
|
||||
}
|
||||
|
||||
if (MaxScoreToWin > 0 && _stats[killer].Kills >= MaxScoreToWin)
|
||||
{
|
||||
await EndGameInfo(killer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏结束信息
|
||||
/// </summary>
|
||||
public async Task EndGameInfo(Character winner)
|
||||
{
|
||||
WriteLine("[ " + winner + " ] 是胜利者。");
|
||||
foreach (Character character in _stats.OrderBy(kv => kv.Value.Kills)
|
||||
.ThenByDescending(kv => kv.Value.Deaths)
|
||||
.ThenBy(kv => kv.Value.Assists).Select(kv => kv.Key))
|
||||
{
|
||||
if (character != winner && !_eliminated.Contains(character))
|
||||
{
|
||||
_eliminated.Add(character);
|
||||
}
|
||||
}
|
||||
_eliminated.Add(winner);
|
||||
_queue.Clear();
|
||||
_isGameEnd = true;
|
||||
|
||||
if (!await OnGameEndAsync(winner))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int top = 1;
|
||||
WriteLine("");
|
||||
WriteLine("=== 排名 ===");
|
||||
for (int i = _eliminated.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Character ec = _eliminated[i];
|
||||
CharacterStatistics statistics = CharacterStatistics[ec];
|
||||
string topCharacter = ec.ToString() +
|
||||
(statistics.FirstKills > 0 ? " [ 第一滴血 ]" : "") +
|
||||
(_maxContinuousKilling.TryGetValue(ec, out int kills) && kills > 1 ? $" [ {CharacterSet.GetContinuousKilling(kills)} ]" : "") +
|
||||
(_earnedMoney.TryGetValue(ec, out int earned) ? $" [ 已赚取 {earned} {GameplayEquilibriumConstant.InGameCurrency} ]" : "");
|
||||
if (top == 1)
|
||||
{
|
||||
WriteLine("冠军:" + topCharacter);
|
||||
_stats[ec].Wins += 1;
|
||||
_stats[ec].Top3s += 1;
|
||||
}
|
||||
else if (top == 2)
|
||||
{
|
||||
WriteLine("亚军:" + topCharacter);
|
||||
_stats[ec].Loses += 1;
|
||||
_stats[ec].Top3s += 1;
|
||||
}
|
||||
else if (top == 3)
|
||||
{
|
||||
WriteLine("季军:" + topCharacter);
|
||||
_stats[ec].Loses += 1;
|
||||
_stats[ec].Top3s += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine($"第 {top} 名:" + topCharacter);
|
||||
_stats[ec].Loses += 1;
|
||||
}
|
||||
_stats[ec].Plays += 1;
|
||||
_stats[ec].TotalEarnedMoney += earned;
|
||||
_stats[ec].LastRank = top;
|
||||
top++;
|
||||
}
|
||||
WriteLine("");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个混战游戏队列
|
||||
/// </summary>
|
||||
/// <param name="writer"></param>
|
||||
public MixGamingQueue(Action<string>? writer = null) : base(writer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个混战游戏队列并初始化行动顺序表
|
||||
/// </summary>
|
||||
/// <param name="characters"></param>
|
||||
/// <param name="writer"></param>
|
||||
public MixGamingQueue(List<Character> characters, Action<string>? writer = null) : base(characters, writer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
312
Model/TeamGamingQueue.cs
Normal file
312
Model/TeamGamingQueue.cs
Normal file
@ -0,0 +1,312 @@
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
public class TeamGamingQueue : GamingQueue
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前团灭的团队顺序(第一个是最早死的)
|
||||
/// </summary>
|
||||
public List<Team> EliminatedTeams => _eliminatedTeams;
|
||||
|
||||
/// <summary>
|
||||
/// 团队及其成员
|
||||
/// </summary>
|
||||
public Dictionary<string, Team> Teams => _teams;
|
||||
|
||||
/// <summary>
|
||||
/// 当前团灭的团队顺序(第一个是最早死的)
|
||||
/// </summary>
|
||||
protected readonly List<Team> _eliminatedTeams = [];
|
||||
|
||||
/// <summary>
|
||||
/// 团队及其成员
|
||||
/// </summary>
|
||||
protected readonly Dictionary<string, Team> _teams = [];
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个团队
|
||||
/// </summary>
|
||||
/// <param name="teamName"></param>
|
||||
/// <param name="characters"></param>
|
||||
public void AddTeam(string teamName, IEnumerable<Character> characters)
|
||||
{
|
||||
if (teamName != "" && characters.Any())
|
||||
{
|
||||
_teams.Add(teamName, new(teamName, characters));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色的团队
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
public Team? GetTeam(Character character)
|
||||
{
|
||||
foreach (Team team in _teams.Values)
|
||||
{
|
||||
if (team.IsOnThisTeam(character))
|
||||
{
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从已淘汰的团队中获取角色的团队
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
public Team? GetTeamFromEliminated(Character character)
|
||||
{
|
||||
foreach (Team team in _eliminatedTeams)
|
||||
{
|
||||
if (team.IsOnThisTeam(character))
|
||||
{
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某角色的团队成员
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
protected override List<Character> GetTeammates(Character character)
|
||||
{
|
||||
foreach (string team in _teams.Keys)
|
||||
{
|
||||
if (_teams[team].IsOnThisTeam(character))
|
||||
{
|
||||
return _teams[team].GetTeammates(character);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色行动后
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
protected override async Task AfterCharacterAction(Character character, CharacterActionType type)
|
||||
{
|
||||
// 如果目标都是队友,会考虑非伤害型助攻
|
||||
Team? team = GetTeam(character);
|
||||
if (team != null)
|
||||
{
|
||||
SetNotDamageAssistTime(character, LastRound.Targets.Where(team.IsOnThisTeam));
|
||||
}
|
||||
else await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 死亡结算时
|
||||
/// </summary>
|
||||
/// <param name="death"></param>
|
||||
/// <param name="killer"></param>
|
||||
/// <returns></returns>
|
||||
protected override async Task OnDeathCalculation(Character death, Character killer)
|
||||
{
|
||||
Team? team = GetTeam(killer);
|
||||
if (team != null)
|
||||
{
|
||||
team.Score++;
|
||||
}
|
||||
else await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 死亡结算后
|
||||
/// </summary>
|
||||
/// <param name="death"></param>
|
||||
/// <param name="killer"></param>
|
||||
/// <returns></returns>
|
||||
protected override async Task AfterDeathCalculation(Character death, Character killer)
|
||||
{
|
||||
Team? killTeam = GetTeam(killer);
|
||||
Team? deathTeam = GetTeam(death);
|
||||
|
||||
if (MaxRespawnTimes != 0)
|
||||
{
|
||||
string[] teamActive = [.. Teams.OrderByDescending(kv => kv.Value.Score).Select(kv =>
|
||||
{
|
||||
int activeCount = kv.Value.GetActiveCharacters(this).Count;
|
||||
if (kv.Value == killTeam)
|
||||
{
|
||||
activeCount += 1;
|
||||
}
|
||||
return kv.Key + ":" + kv.Value.Score + "(剩余存活人数:" + activeCount + ")";
|
||||
})];
|
||||
WriteLine($"\r\n=== 当前死亡竞赛比分 ===\r\n{string.Join("\r\n", teamActive)}");
|
||||
}
|
||||
|
||||
if (deathTeam != null)
|
||||
{
|
||||
List<Character> remain = deathTeam.GetActiveCharacters(this);
|
||||
int remainCount = remain.Count;
|
||||
if (remainCount == 0)
|
||||
{
|
||||
// 团灭了
|
||||
_eliminatedTeams.Add(deathTeam);
|
||||
_teams.Remove(deathTeam.Name);
|
||||
}
|
||||
else if (MaxRespawnTimes == 0)
|
||||
{
|
||||
WriteLine($"[ {deathTeam} ] 剩余成员:[ {string.Join(" ] / [ ", remain)} ]({remainCount} 人)");
|
||||
}
|
||||
}
|
||||
|
||||
if (killTeam != null)
|
||||
{
|
||||
List<Character> actives = killTeam.GetActiveCharacters(this);
|
||||
actives.Add(killer);
|
||||
int remainCount = actives.Count;
|
||||
if (remainCount > 0 && MaxRespawnTimes == 0)
|
||||
{
|
||||
WriteLine($"[ {killTeam} ] 剩余成员:[ {string.Join(" ] / [ ", actives)} ]({remainCount} 人)");
|
||||
}
|
||||
if (!_teams.Keys.Where(str => str != killTeam.Name).Any())
|
||||
{
|
||||
// 没有其他的团队了,游戏结束
|
||||
await EndGameInfo(killTeam);
|
||||
return;
|
||||
}
|
||||
if (MaxScoreToWin > 0 && killTeam.Score >= MaxScoreToWin)
|
||||
{
|
||||
List<Team> combinedTeams = [.. _eliminatedTeams, .. _teams.Values];
|
||||
combinedTeams.Remove(killTeam);
|
||||
_eliminatedTeams.Clear();
|
||||
_eliminatedTeams.AddRange(combinedTeams.OrderByDescending(t => t.Score));
|
||||
await EndGameInfo(killTeam);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏结束信息 [ 团队版 ]
|
||||
/// </summary>
|
||||
public async Task EndGameInfo(Team winner)
|
||||
{
|
||||
winner.IsWinner = true;
|
||||
WriteLine("[ " + winner + " ] 是胜利者。");
|
||||
|
||||
if (!await OnGameEndTeamAsync(winner))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int top = 1;
|
||||
WriteLine("");
|
||||
WriteLine("=== 排名 ===");
|
||||
WriteLine("");
|
||||
|
||||
_eliminatedTeams.Add(winner);
|
||||
_teams.Remove(winner.Name);
|
||||
|
||||
for (int i = _eliminatedTeams.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Team team = _eliminatedTeams[i];
|
||||
string topTeam = "";
|
||||
if (top == 1)
|
||||
{
|
||||
topTeam = "冠军";
|
||||
}
|
||||
if (top == 2)
|
||||
{
|
||||
topTeam = "亚军";
|
||||
}
|
||||
if (top == 3)
|
||||
{
|
||||
topTeam = "季军";
|
||||
}
|
||||
if (top > 3)
|
||||
{
|
||||
topTeam = $"第 {top} 名";
|
||||
}
|
||||
topTeam = $"☆--- {topTeam}团队:" + team.Name + " ---☆" + $"(得分:{team.Score})\r\n";
|
||||
foreach (Character ec in team.Members)
|
||||
{
|
||||
CharacterStatistics statistics = CharacterStatistics[ec];
|
||||
|
||||
string respawning = "";
|
||||
if (ec.HP <= 0)
|
||||
{
|
||||
respawning = "[ " + (_respawnCountdown.TryGetValue(ec, out double time) && time > 0 ? $"{time:0.##} {GameplayEquilibriumConstant.InGameTime}后复活" : "阵亡") + " ] ";
|
||||
}
|
||||
|
||||
string topCharacter = respawning + ec.ToString() +
|
||||
(statistics.FirstKills > 0 ? " [ 第一滴血 ]" : "") +
|
||||
(_maxContinuousKilling.TryGetValue(ec, out int kills) && kills > 1 ? $" [ {CharacterSet.GetContinuousKilling(kills)} ]" : "") +
|
||||
(_earnedMoney.TryGetValue(ec, out int earned) ? $" [ 已赚取 {earned} {GameplayEquilibriumConstant.InGameCurrency} ]" : "") +
|
||||
$"({statistics.Kills} / {statistics.Assists}{(MaxRespawnTimes != 0 ? " / " + statistics.Deaths : "")})";
|
||||
topTeam += topCharacter + "\r\n";
|
||||
if (top == 1)
|
||||
{
|
||||
_stats[ec].Wins += 1;
|
||||
_stats[ec].Top3s += 1;
|
||||
}
|
||||
else if (top == 2)
|
||||
{
|
||||
_stats[ec].Loses += 1;
|
||||
_stats[ec].Top3s += 1;
|
||||
}
|
||||
else if (top == 3)
|
||||
{
|
||||
_stats[ec].Loses += 1;
|
||||
_stats[ec].Top3s += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_stats[ec].Loses += 1;
|
||||
}
|
||||
_stats[ec].Plays += 1;
|
||||
_stats[ec].TotalEarnedMoney += earned;
|
||||
_stats[ec].LastRank = top;
|
||||
}
|
||||
WriteLine(topTeam);
|
||||
top++;
|
||||
}
|
||||
WriteLine("");
|
||||
_isGameEnd = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个团队游戏队列
|
||||
/// </summary>
|
||||
/// <param name="writer"></param>
|
||||
public TeamGamingQueue(Action<string>? writer = null) : base(writer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个团队游戏队列并初始化行动顺序表
|
||||
/// </summary>
|
||||
/// <param name="characters"></param>
|
||||
/// <param name="writer"></param>
|
||||
public TeamGamingQueue(List<Character> characters, Action<string>? writer = null) : base(characters, writer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public delegate Task<bool> GameEndTeamEventHandler(TeamGamingQueue queue, Team winner);
|
||||
/// <summary>
|
||||
/// 游戏结束事件(团队版)
|
||||
/// </summary>
|
||||
public event GameEndTeamEventHandler? GameEndTeam;
|
||||
/// <summary>
|
||||
/// 游戏结束事件(团队版)
|
||||
/// </summary>
|
||||
/// <param name="winner"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> OnGameEndTeamAsync(Team winner)
|
||||
{
|
||||
return await (GameEndTeam?.Invoke(this, winner) ?? Task.FromResult(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,10 +9,10 @@
|
||||
|
||||
## 安装
|
||||
|
||||
- [NuGet](https://www.nuget.org/packages/ProjectRedbud.FunGame.Core/)
|
||||
- [NuGet](https://www.nuget.org/packages/FunGame.Core/)
|
||||
|
||||
```
|
||||
dotnet add package ProjectRedbud.FunGame.Core --version 1.0.0-rc.1-0428
|
||||
dotnet add package FunGame.Core
|
||||
```
|
||||
|
||||
- 在 [Release](https://github.com/project-redbud/FunGame-Core/releases) 页面中下载最新发布版本。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user