M0 回合制战斗壳层:接口与单局状态、调试入口、暂停联动
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
namespace SepCore.CustomComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// 本局共享随机数接口。
|
||||
/// 同一单局的地图生成、敌人 AI、逃跑和敌人掉落依次消费同一个实例;
|
||||
/// 战斗不能根据 EncounterId、回合数或当前时间重新播种。
|
||||
/// </summary>
|
||||
public interface IRunRandomSource
|
||||
{
|
||||
/// <summary>
|
||||
/// 返回 [minInclusive, maxExclusive) 范围内的随机整数。
|
||||
/// </summary>
|
||||
int NextInt(int minInclusive, int maxExclusive);
|
||||
|
||||
/// <summary>
|
||||
/// 以千分比概率判定是否成功;RollPermille(0) 必失败,RollPermille(1000) 必成功。
|
||||
/// </summary>
|
||||
bool RollPermille(int successPermille);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e17f39494674cf08295b96df17642e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.CustomComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// 单局共享随机组件。
|
||||
/// 种子由局外(战备/部署界面玩家输入)带入,进入单局时初始化;
|
||||
/// 地图生成、物资点、敌人 AI、逃跑判定和敌人掉落依次消费同一个随机源,
|
||||
/// 战斗只沿用该随机源,不创建战斗私有随机源。
|
||||
/// 对应 Docs/GameDesign/03_RunExploration.md 的随机生成器约定。
|
||||
/// </summary>
|
||||
public class RandomComponent : GameFrameworkComponent
|
||||
{
|
||||
private int _seed;
|
||||
private IRunRandomSource _random;
|
||||
|
||||
/// <summary>
|
||||
/// 获取本局随机种子;未开始单局时为 0。
|
||||
/// </summary>
|
||||
public int Seed => _seed;
|
||||
|
||||
/// <summary>
|
||||
/// 获取本局共享随机源;未开始单局时为 null。
|
||||
/// </summary>
|
||||
public IRunRandomSource Random => _random;
|
||||
|
||||
/// <summary>
|
||||
/// 开始一局新的单局:使用局外带入的种子初始化共享随机源。
|
||||
/// </summary>
|
||||
/// <param name="seed">本局随机种子。</param>
|
||||
public void BeginRun(int seed)
|
||||
{
|
||||
_seed = seed;
|
||||
_random = new RunRandomSource(seed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 结束当前单局,清空种子与随机源。
|
||||
/// </summary>
|
||||
public void EndRun()
|
||||
{
|
||||
_seed = 0;
|
||||
_random = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 373a779ff43a4289b8e8cb23459d7bb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
|
||||
namespace SepCore.CustomComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// 以 System.Random 实现的本局共享随机源。
|
||||
/// 由 TurnBattleComponent 以单局 seed 创建,供地图生成、敌人 AI、逃跑与掉落共用。
|
||||
/// EditMode 测试使用可注入的序列随机源,不依赖本类。
|
||||
/// </summary>
|
||||
public sealed class RunRandomSource : IRunRandomSource
|
||||
{
|
||||
private readonly Random _random;
|
||||
|
||||
/// <summary>
|
||||
/// 使用指定种子创建随机源。
|
||||
/// </summary>
|
||||
public RunRandomSource(int seed)
|
||||
{
|
||||
_random = new Random(seed);
|
||||
}
|
||||
|
||||
public int NextInt(int minInclusive, int maxExclusive)
|
||||
{
|
||||
return _random.Next(minInclusive, maxExclusive);
|
||||
}
|
||||
|
||||
public bool RollPermille(int successPermille)
|
||||
{
|
||||
return NextInt(0, 1000) < successPermille;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dc1aacc472441329e01cf158f17981e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user