跳到主要内容

IMonsterDatabase

用于查询怪物数据库的只读契约。这是所有数据库查询的公开 API 接口面。

命名空间:OpenMon.MCE.SDK

定义​

public interface IMonsterDatabase
{
MonsterEntry GetMonster(uint dexNumber);
MonsterEntry GetMonster(string name);
IReadOnlyList<MonsterEntry> GetAllMonsters();

Move GetMove(string name);
IReadOnlyList<Move> GetAllMoves();

Ability GetAbility(string name);
IReadOnlyList<Ability> GetAllAbilities();

Item GetItem(string name);
IReadOnlyList<Item> GetAllItems();

IReadOnlyList<MonsterType> GetAllTypes();
float GetTypeEffectiveness(MonsterType attackingType, MonsterType defendingType);

IReadOnlyList<Form> GetAllForms();

int MonsterCount { get; }
}

方法​

GetMonster(uint dexNumber)​

按全国图鉴编号获取一个怪物条目。

参数类型说明
dexNumberuint唯一的图鉴编号

返回:MonsterEntry,未找到时返回 null。

GetMonster(string name)​

按物种名称获取一个怪物条目。

参数类型说明
namestring物种名称(区分大小写)

返回:MonsterEntry,未找到时返回 null。

GetAllMonsters()​

获取数据库中所有已注册的怪物条目。

返回:IReadOnlyList<MonsterEntry> —— 所有物种,按图鉴编号排序。

GetMove(string name)​

按名称获取一个招式。

返回:Move,未找到时返回 null。

GetAllMoves()​

获取所有已注册的招式。

返回:IReadOnlyList<Move> —— 全部 640+ 个招式。

GetAbility(string name)​

按名称获取一个特性。

返回:Ability,未找到时返回 null。

GetAllAbilities()​

获取所有已注册的特性。

返回:IReadOnlyList<Ability>。

GetItem(string name)​

按名称获取一个道具。

返回:Item,未找到时返回 null。

GetAllItems()​

获取所有已注册的道具。

返回:IReadOnlyList<Item>。

GetAllTypes()​

获取所有已注册的怪物属性。

返回:IReadOnlyList<MonsterType> —— 18 种标准属性(若经修改则为自定义属性)。

GetTypeEffectiveness(MonsterType, MonsterType)​

获取一种属性攻击另一种属性时的属性相性倍率。

参数类型说明
attackingTypeMonsterType招式的属性
defendingTypeMonsterType目标的属性(单一属性)

返回:float —— 0.0(无效)、0.5(效果不佳)、1.0(一般)或 2.0(效果绝佳)。

双属性

此方法检查一种攻击属性对一种防御属性。对于双属性防御方,请调用两次并将结果相乘:

float effectiveness = db.GetTypeEffectiveness(moveType, defenderType1)
* db.GetTypeEffectiveness(moveType, defenderType2);

GetAllForms()​

获取所有已注册的形态。

返回:IReadOnlyList<Form>。

属性​

MonsterCount​

数据库中怪物条目的总数。

类型:int

用法示例​

using System.Linq;

[Inject] private IMonsterCaptureEngine engine;

void Example()
{
IMonsterDatabase db = engine.Database;

// Find a specific monster — by name, or by National Dex number.
MonsterEntry sparkbit = db.GetMonster("Sparkbit");
MonsterEntry starter = db.GetMonster(1u);

// Types are ScriptableObjects, not an enum — fetch them from the database.
MonsterType fire = db.GetAllTypes().FirstOrDefault(t => t.name == "Fire");
MonsterType water = db.GetAllTypes().FirstOrDefault(t => t.name == "Water");

// Check a type matchup.
float eff = db.GetTypeEffectiveness(water, fire);
Debug.Log($"Water vs Fire: {eff}x"); // 2.0x

// Count all Fire-type species. A monster's types live on its per-form data
// (DataByFormEntry), reached through the MonsterEntry[form] indexer.
int fireCount = db.GetAllMonsters().Count(m =>
{
if (m.AvailableForms == null || m.AvailableForms.Count == 0) return false;
var data = m[m.AvailableForms[0]];
return data != null && (data.FirstType == fire || data.SecondType == fire);
});
Debug.Log($"Fire-type species: {fireCount}");
}