Roster
一支最多容纳 6 只 MonsterInstance 怪物、可用于战斗的队伍。它是 IPlayerData.PlayerRoster 返回的类型,因此是你读取和修改玩家队伍的入口。
命名空间:OpenMon.MCE.Monster
Roster 是一个具体的 ScriptableObject(SavableObject),而非 OpenMon.MCE.SDK 接口。下面列出的成员是大多数买家会用到的主要接口面;该类还包含额外成员(模板管理、存档/读档序列化、病毒扩散、随机填充)。完整 API 请参阅源代码(Source 版和 Studio 版)。
定义
[CreateAssetMenu(menuName = "MCE/Roster", fileName = "Roster")]
public class Roster : SavableObject, IEnumerable
{
public event Action OnRosterUpdated;
public MonsterInstance[] RosterData = new MonsterInstance[6];
public MCESettings Settings;
public MonsterDatabaseInstance Database;
public int RosterSize { get; }
public int NumberThatCanBattle { get; }
public MonsterInstance this[int index] { get; set; }
public IEnumerator GetEnumerator();
public bool IsMonsterNull(int index);
public void AddMonster(MonsterEntry species, Form form, byte level, /* ...many optional overrides... */);
public int AddMonster(MonsterInstance monster);
public void RemoveMonster(int index);
public void RemoveMonster(MonsterInstance monster);
public void Exchange(int firstIndex, int secondIndex);
public MonsterInstance ReplaceMonsterAt(int index, MonsterInstance newMonster);
public void CompletelyHeal();
public bool AnyHasMove(Move move);
public void CopyFrom(Roster other);
}
事件
OnRosterUpdated
每当队伍被修改时触发(添加、移除、交换、替换怪物等)。
签名:event Action OnRosterUpdated
字段与属性
RosterData
存放怪物实例的底层数组。长度始终为 6;空槽位保存一个空条目。
类型:MonsterInstance[]
RosterSize日常读取时,请使用 roster[i] 索引器和 RosterSize,而不要直接遍历 RosterData —— 尾部槽位可能为 null 或空条目。
Settings
对 MCE 设置的引用。
类型:MCESettings
Database
对怪物数据库的引用。
类型:MonsterDatabaseInstance
RosterSize
获取此队伍的大小 —— 已填充的前导槽位数量(在第一个空条目处停止计数)。
类型:int(只读,0–6)
NumberThatCanBattle
获取当前能够战斗的怪物数量(非空条目且 CanBattle == true)。
类型:int(只读)
方法
this[int index]
按槽 位快速访问一个怪物实例。
| 参数 | 类型 | 说明 |
|---|---|---|
index | int | 该怪物实例的索引(0–5) |
类型:MonsterInstance(get/set)
GetEnumerator()
快速访问数据枚举器(实现了 IEnumerable,因此你可以对队伍使用 foreach)。
返回:遍历 RosterData 的 IEnumerator。
IsMonsterNull(int index)
检查某个怪物槽位是否为空(无论是真正的 null 还是空条目)。
| 参数 | 类型 | 说明 |
|---|---|---|
index | int | 要检查的索引 |
返回:bool —— 若为空则为 true。
AddMonster(species, form, level, ...)
向队伍添加一只怪物,并替你构建 MonsterInstance。只有 species、form 和 level 是必需的;其余参数都有默认值(随机性格/特性、无昵称、默认来源等)。
| 参数 | 类型 | 说明 |
|---|---|---|
species | MonsterEntry | 这只怪物的物种 |
form | Form | 这只怪物的形态(无效形态回退为默认值) |
level | byte | 这只怪物的等级 |
| (众多可选参数) | 性格、特性、性别、个体值/努力值、招式、昵称、训练家、精灵球、缎带、持有道具、isEgg 等等 |
AddMonster(MonsterInstance monster)
将一只已构建好的怪物添加到队伍。
| 参数 | 类型 | 说明 |
|---|---|---|
monster | MonsterInstance | 要添加的怪物 |
返回:int —— 被添加到的索引,若所有槽位都已填满则返回 -1。
RemoveMonster(int index)
移除指定槽位的怪物,然后压紧队伍使其没有空隙。
| 参数 | 类型 | 说明 |
|---|---|---|
index | int | 要移除的索引 |
RemoveMonster(MonsterInstance monster)
从队伍中移除指定的怪物实例。
| 参数 | 类型 | 说明 |
|---|---|---|
monster | MonsterInstance | 要移除的怪物 |
Exchange(int firstIndex, int secondIndex)
交换队伍中的两只怪物(互换它们的槽位)。
| 参数 | 类型 | 说明 |
|---|---|---|
firstIndex | int | 要交换的第一个索引 |
secondIndex | int | 要交换的第二个索引 |
ReplaceMonsterAt(int index, MonsterInstance newMonster)
用另一只怪物替换指定索引处的怪物。
| 参数 | 类型 | 说明 |
|---|---|---|
index | int | 要替换的索引 |
newMonster | MonsterInstance | 要放到该处的怪物 |
返回:MonsterInstance —— 被替换掉的那只怪物。
CompletelyHeal()
完全治疗队伍中的每一只怪物(HP、PP 与异常状态)。
AnyHasMove(Move move)
此队伍中是否有任何怪物会某个指定招式?(用于场地/秘传招式类的检查很方便。)
| 参数 | 类型 | 说明 |
|---|---|---|
move | Move | 要检查的招式 |
返回:bool —— 若任何成员会该招式则为 true。
CopyFrom(Roster other)
将另一支队伍的怪物克隆到此队伍中。
| 参数 | 类型 | 说明 |
|---|---|---|
other | Roster | 要复制来源的队伍 |
用法示例
using OpenMon.MCE.SDK;
using OpenMon.MCE.Monster;
using Zenject;
public class PartyManager : MonoBehaviour
{
[Inject] private IMonsterCaptureEngine engine;
private void Start()
{
Roster roster = engine.Player.PlayerRoster;
// React to any party change.
roster.OnRosterUpdated += () =>
Debug.Log($"Party changed — size {roster.RosterSize}, "
+ $"{roster.NumberThatCanBattle} able to battle");
// Iterate the current party.
foreach (MonsterInstance monster in roster)
{
if (monster is { IsNullEntry: false })
Debug.Log($"- {monster.Species.name} (Lv {monster.StatData.Level})");
}
// Swap the lead with the second slot.
if (roster.RosterSize >= 2)
roster.Exchange(0, 1);
// Heal the whole party after a rough battle.
roster.CompletelyHeal();
}
}