Line data Source code
1 : package query
2 :
3 : import (
4 : gc "github.com/kijimaD/ruins/internal/components"
5 : "github.com/kijimaD/ruins/internal/consts"
6 : "github.com/kijimaD/ruins/internal/rawschema"
7 : w "github.com/kijimaD/ruins/internal/world"
8 : "github.com/mlange-42/ark/ecs"
9 : )
10 :
11 : // proficiencyInputs は効果倍率の導出に使う入力を集める。Skills が無ければ nil を返す。
12 : // bodyFuncs は疲労・空腹による意識低下を畳んだ実効身体機能で、命中の畳み込みが読む
13 : func proficiencyInputs(world w.World, entity ecs.Entity) (skills *gc.Skills, abils *gc.Abilities, bodyFuncs gc.BodyFuncs) {
14 1 : if world.Components.Skills.Has(entity) {
15 1 : skills = world.Components.Skills.Get(entity)
16 1 : }
17 1 : if world.Components.Abilities.Has(entity) {
18 1 : abils = world.Components.Abilities.Get(entity)
19 1 : }
20 1 : bodyFuncs = EffectiveBodyFuncs(world, entity)
21 1 : return skills, abils, bodyFuncs
22 : }
23 :
24 : // ProficiencyValue は key の効果倍率を都度計算して返す。保存済みの値ではなく
25 : // Skills・Abilities・実効身体機能から読み取り時に導出する。
26 : // 適用と表示の両方がこの1関数を読むので、両者は同じ値になる。
27 : // Skills が無ければ等倍を返し、呼び出し側の存在ガードは不要
28 : func ProficiencyValue(world w.World, entity ecs.Entity, key rawschema.ProficiencyId) consts.Percent {
29 1 : skills, abils, bodyFuncs := proficiencyInputs(world, entity)
30 1 : if skills == nil {
31 1 : return consts.PercentBase
32 1 : }
33 1 : return world.Resources.SkillDefs.ProficiencyValue(skills, abils, bodyFuncs, key)
34 : }
35 :
36 : // ProficiencySources は key の効果倍率の内訳を都度計算して返す。詳細モーダルの表示用。
37 : // Skills が無ければ空を返す
38 : func ProficiencySources(world w.World, entity ecs.Entity, key rawschema.ProficiencyId) []gc.ProficiencySource {
39 1 : skills, abils, bodyFuncs := proficiencyInputs(world, entity)
40 1 : if skills == nil {
41 1 : return nil
42 1 : }
43 1 : return world.Resources.SkillDefs.ProficiencySources(skills, abils, bodyFuncs, key)
44 : }
45 :
46 : // AttackTypeName は攻撃の種類の訳した表示名を返す。表に無ければ id をそのまま返す
47 : func AttackTypeName(world w.World, at rawschema.AttackCategory) string {
48 0 : if weapon, ok := world.Resources.SkillDefs.Weapon(at); ok {
49 0 : return T(world, weapon.Name)
50 0 : }
51 0 : return string(at)
52 : }
53 :
54 : // SkillName はスキルの訳した表示名を返す
55 : func SkillName(world w.World, id rawschema.SkillId) string {
56 0 : return T(world, world.Resources.SkillDefs.Name(id))
57 0 : }
|