LCOV - code coverage report
Current view: top level - states - character_info.go Coverage Total Hit
Test: coverage.lcov Lines: 93.9 % 261 245
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package states
       2              : 
       3              : import (
       4              :         "fmt"
       5              : 
       6              :         "github.com/kijimaD/ruins/internal/i18n"
       7              : 
       8              :         gc "github.com/kijimaD/ruins/internal/components"
       9              :         "github.com/kijimaD/ruins/internal/raw"
      10              :         "github.com/kijimaD/ruins/internal/rawschema"
      11              :         "github.com/kijimaD/ruins/internal/resources"
      12              :         "github.com/kijimaD/ruins/internal/widgets/menuframe"
      13              :         "github.com/kijimaD/ruins/internal/widgets/styled"
      14              :         "github.com/kijimaD/ruins/internal/widgets/uicore"
      15              :         w "github.com/kijimaD/ruins/internal/world"
      16              : 
      17              :         "github.com/kijimaD/ruins/internal/world/query"
      18              :         "github.com/mlange-42/ark/ecs"
      19              : )
      20              : 
      21              : // キャラクター情報の読み取り専用タブ、能力・スキル・効果・健康・基本、の構築を担う。
      22              : // 装備タブと同じ CharacterState が持ち、装備の編集フローと1画面に統合する。
      23              : 
      24              : // 読み取り専用タブの ID
      25              : const (
      26              :         tabAbilities = "abilities"
      27              :         tabSkills    = "skills"
      28              :         tabEffects   = "effects"
      29              :         tabHealth    = "health"
      30              :         tabBasic     = "basic"
      31              : )
      32              : 
      33              : type statusTabData struct {
      34              :         ID    string
      35              :         Label string
      36              :         Items []statusItemData
      37              : }
      38              : 
      39              : type statusItemData struct {
      40              :         // Label は行の表示ラベル
      41              :         Label string
      42              :         // Value は行の右に出す値。数値や倍率の文字列
      43              :         Value string
      44              :         // Modifier は能力値への補正表示。装備やバフによる増減を +N 形式で持つ
      45              :         Modifier string
      46              :         // Description は詳細モーダルやヘッダーの説明文
      47              :         Description string
      48              :         // IsHeader はカテゴリヘッダー行かどうか。真なら選択不可の見出し
      49              :         IsHeader bool
      50              :         // Indent は menuframe.Row.Indent へ渡す字下げの段数
      51              :         Indent int
      52              :         // BodyPart は健康タブの症状エントリが属する部位
      53              :         BodyPart gc.BodyPart
      54              :         // Condition は症状エントリが指す不調の実体。保存不調も導出不調も同じ形で載せる。症状でない行は nil
      55              :         Condition *gc.HealthCondition
      56              :         // Details は詳細モーダルに表示する内訳
      57              :         Details []statusDetailRow
      58              : }
      59              : 
      60              : type statusDetailRow struct {
      61              :         Label string
      62              :         Value string
      63              : }
      64              : 
      65              : // fetchInfoTabs は能力・スキル・効果・健康・基本の読み取り専用タブを構築する
      66              : func (st *CharacterState) fetchInfoTabs(world w.World, player ecs.Entity) []statusTabData {
      67            1 :         professionName := ""
      68            1 :         if query.AliveHas(world, world.Components.Profession, player) {
      69            1 :                 profComp := world.Components.Profession.Get(player)
      70            1 :                 if prof, err := raw.GetProfession(world.Resources.RawMaster, profComp.ID); err == nil {
      71            1 :                         professionName = query.T(world, i18n.Msgid(prof.Name))
      72            1 :                 }
      73              :         }
      74              : 
      75            1 :         return []statusTabData{
      76            1 :                 {ID: tabAbilities, Label: query.T(world, "Abilities"), Items: st.createAbilityItems(world, player)},
      77            1 :                 {ID: tabSkills, Label: query.T(world, "Skills"), Items: st.createSkillItems(world, player)},
      78            1 :                 {ID: tabEffects, Label: query.T(world, "Effects"), Items: st.createEffectItems(world, player)},
      79            1 :                 {ID: tabHealth, Label: query.T(world, "Health"), Items: st.createHealthItems(world, player)},
      80            1 :                 {ID: tabBasic, Label: query.T(world, "Basic"), Items: st.createBasicItems(world, player, professionName)},
      81            1 :         }
      82              : }
      83              : 
      84              : func (st *CharacterState) createBasicItems(world w.World, playerEntity ecs.Entity, professionName string) []statusItemData {
      85            1 :         items := []statusItemData{}
      86            1 : 
      87            1 :         if professionName != "" {
      88            1 :                 items = append(items, statusItemData{Label: query.T(world, "Profession"), Value: professionName, Description: query.T(world, "Profession")})
      89            1 :         }
      90            1 :         if query.AliveHas(world, world.Components.HP, playerEntity) {
      91            1 :                 hp := world.Components.HP.Get(playerEntity)
      92            1 :                 items = append(items, statusItemData{Label: query.T(world, "HP"), Value: fmt.Sprintf("%d", hp.Max), Description: query.T(world, "HP. You die at 0")})
      93            1 :         }
      94            1 :         if query.AliveHas(world, world.Components.WeightCapacity, playerEntity) {
      95            1 :                 cw := world.Components.WeightCapacity.Get(playerEntity)
      96            1 :                 items = append(items, statusItemData{Label: query.T(world, "Max weight"), Value: cw.Max.KgString(), Description: query.T(world, "Maximum weight you can carry")})
      97            1 :         }
      98            1 :         if query.AliveHas(world, world.Components.Hunger, playerEntity) {
      99            1 :                 hunger := world.Components.Hunger.Get(playerEntity)
     100            1 :                 // 空腹は量から導出した意識低下として命中・速度・回復へ効く。段階を値に出し、効き目は
     101              :                 // Effects タブの意識と各出力に出る
     102            1 :                 items = append(items, statusItemData{
     103            1 :                         Label:       query.T(world, "Hunger"),
     104            1 :                         Value:       query.HungerName(world, hunger.GetLevel(world.Resources.NeedDefs)),
     105            1 :                         Description: query.T(world, "Hunger. High hunger hinders actions and recovery"),
     106            1 :                 })
     107            1 :         }
     108              :         // 疲労は空腹と並ぶ生理値。量から導出した意識低下として命中・速度・回復へ効く
     109            1 :         if query.AliveHas(world, world.Components.Fatigue, playerEntity) {
     110            1 :                 fatigue := world.Components.Fatigue.Get(playerEntity)
     111            1 :                 items = append(items, statusItemData{
     112            1 :                         Label:       query.T(world, "Fatigue"),
     113            1 :                         Value:       query.FatigueName(world, fatigue.GetLevel(world.Resources.NeedDefs)),
     114            1 :                         Description: query.T(world, "Fatigue. High fatigue hinders actions and recovery"),
     115            1 :                 })
     116            1 :         }
     117            1 :         return items
     118              : }
     119              : 
     120              : func (st *CharacterState) createAbilityItems(world w.World, playerEntity ecs.Entity) []statusItemData {
     121            1 :         items := []statusItemData{}
     122            1 :         if query.AliveHas(world, world.Components.Abilities, playerEntity) {
     123            1 :                 abils := world.Components.Abilities.Get(playerEntity)
     124            1 :                 items = append(items,
     125            1 :                         statusItemData{Label: query.T(world, "Vitality"), Value: fmt.Sprintf("%d", abils.Vitality.Total), Modifier: fmt.Sprintf("(%+d)", abils.Vitality.Modifier), Description: query.T(world, "Vitality. Affects max HP and SP")},
     126            1 :                         statusItemData{Label: query.T(world, "Strength"), Value: fmt.Sprintf("%d", abils.Strength.Total), Modifier: fmt.Sprintf("(%+d)", abils.Strength.Modifier), Description: query.T(world, "Strength. Affects melee attack damage")},
     127            1 :                         statusItemData{Label: query.T(world, "Sensation"), Value: fmt.Sprintf("%d", abils.Sensation.Total), Modifier: fmt.Sprintf("(%+d)", abils.Sensation.Modifier), Description: query.T(world, "Sensation. Affects ranged attack damage")},
     128            1 :                         statusItemData{Label: query.T(world, "Dexterity"), Value: fmt.Sprintf("%d", abils.Dexterity.Total), Modifier: fmt.Sprintf("(%+d)", abils.Dexterity.Modifier), Description: query.T(world, "Dexterity. Affects accuracy")},
     129            1 :                         statusItemData{Label: query.T(world, "Agility"), Value: fmt.Sprintf("%d", abils.Agility.Total), Modifier: fmt.Sprintf("(%+d)", abils.Agility.Modifier), Description: query.T(world, "Agility. Affects evasion and action speed")},
     130            1 :                         statusItemData{Label: query.T(world, "Defense"), Value: fmt.Sprintf("%d", abils.Defense.Total), Modifier: fmt.Sprintf("(%+d)", abils.Defense.Modifier), Description: query.T(world, "Defense. Reduces damage taken")},
     131            1 :                 )
     132            1 :         }
     133            1 :         return items
     134              : }
     135              : 
     136              : // indentUnderHeaders は見出し以外の行を1段字下げして、カテゴリ配下のエントリを見出しと
     137              : // 見分けやすくする。見出しと子が交互に並ぶタブでだけ呼ぶ。
     138              : func indentUnderHeaders(items []statusItemData) []statusItemData {
     139            1 :         for i := range items {
     140            1 :                 if !items[i].IsHeader {
     141            1 :                         items[i].Indent = 1
     142            1 :                 }
     143              :         }
     144            1 :         return items
     145              : }
     146              : 
     147              : func (st *CharacterState) createSkillItems(world w.World, playerEntity ecs.Entity) []statusItemData {
     148            1 :         items := []statusItemData{}
     149            1 :         if !query.AliveHas(world, world.Components.Skills, playerEntity) {
     150            0 :                 return items
     151            0 :         }
     152            1 :         skills := world.Components.Skills.Get(playerEntity)
     153            1 :         for _, cat := range world.Resources.SkillDefs.Categories {
     154            1 :                 items = append(items, statusItemData{Label: query.T(world, cat.Name), IsHeader: true, Description: query.T(world, "%s category skills", query.T(world, cat.Name))})
     155            1 :                 for _, id := range cat.IDs {
     156            1 :                         s := skills.Get(id)
     157            1 :                         expFrac := 0
     158            1 :                         if s.Exp.Max > 0 {
     159            1 :                                 expFrac = s.Exp.Current * 1000 / s.Exp.Max
     160            1 :                         }
     161            1 :                         info := world.Resources.SkillDefs.Skills[id]
     162            1 :                         items = append(items, statusItemData{
     163            1 :                                 Label:       query.T(world, info.Name),
     164            1 :                                 Value:       fmt.Sprintf("%d.%03d", s.Value, expFrac),
     165            1 :                                 Description: query.T(world, info.Summary),
     166            1 :                                 Details: []statusDetailRow{
     167            1 :                                         {Label: query.T(world, "Gained by"), Value: query.T(world, info.GainedBy)},
     168            1 :                                         {Label: query.T(world, "Effect"), Value: query.T(world, info.Effect)},
     169            1 :                                 },
     170            1 :                         })
     171              :                 }
     172              :         }
     173            1 :         return indentUnderHeaders(items)
     174              : }
     175              : 
     176              : func (st *CharacterState) createEffectItems(world w.World, playerEntity ecs.Entity) []statusItemData {
     177            1 :         items := []statusItemData{}
     178            1 :         if !world.ECS.Alive(playerEntity) {
     179            0 :                 return items
     180            0 :         }
     181            1 :         val := func(key rawschema.ProficiencyId) string {
     182            1 :                 return fmt.Sprintf("%d%%", query.ProficiencyValue(world, playerEntity, key))
     183            1 :         }
     184            1 :         details := func(key rawschema.ProficiencyId) []statusDetailRow {
     185            1 :                 return sourceToDetails(world, query.ProficiencySources(world, playerEntity, key))
     186            1 :         }
     187              :         // 実効身体機能。怪我・病気に加え疲労・空腹の意識低下を畳んだ値
     188            1 :         bodyFuncs := query.EffectiveBodyFuncs(world, playerEntity)
     189            1 : 
     190            1 :         items = append(items, statusItemData{Label: query.T(world, "Combat"), IsHeader: true, Description: query.T(world, "Combat effects")})
     191            1 :         weapons := world.Resources.SkillDefs.Weapons
     192            1 :         for _, w := range weapons {
     193            1 :                 name := query.SkillName(world, w.Skill)
     194            1 :                 items = append(items, statusItemData{Label: query.T(world, "%s attack power", name), Value: val(w.Damage), Description: query.T(world, "%s weapon damage multiplier", name), Details: details(w.Damage)})
     195            1 :         }
     196            1 :         for _, w := range weapons {
     197            1 :                 name := query.SkillName(world, w.Skill)
     198            1 :                 items = append(items, statusItemData{Label: query.T(world, "%s accuracy", name), Value: val(w.Accuracy), Description: query.T(world, "%s weapon accuracy multiplier", name), Details: details(w.Accuracy)})
     199            1 :         }
     200            1 :         for _, r := range world.Resources.SkillDefs.Resists {
     201            1 :                 name := query.T(world, gc.ElementName(r.Element))
     202            1 :                 items = append(items, statusItemData{Label: query.T(world, "%s resistance", name), Value: val(r.Proficiency), Description: query.T(world, "%s element damage multiplier. Lower reduces more", name), Details: details(r.Proficiency)})
     203            1 :         }
     204              : 
     205              :         // 血液量が危険域まで落ちると失血で HP が減る。一覧は % だけにし、減少量は詳細モーダルの内訳に出す
     206            1 :         bloodDesc := query.T(world, "Blood volume. Bleeding and severe conditions lower it")
     207            1 :         var bloodDetails []statusDetailRow
     208            1 :         if world.Components.HealthStatus.Has(playerEntity) {
     209            1 :                 if drain, _ := world.Components.HealthStatus.Get(playerEntity).BloodLossHPDrain(world.Resources.ConditionDefs); drain > 0 {
     210            0 :                         bloodDesc = query.T(world, "Critically low. Bleeding out and losing HP")
     211            0 :                         bloodDetails = []statusDetailRow{{Label: query.T(world, "HP loss"), Value: fmt.Sprintf("-%d", drain)}}
     212            0 :                 }
     213              :         }
     214              : 
     215            1 :         items = append(items, statusItemData{Label: query.T(world, "Body function"), IsHeader: true, Description: query.T(world, "Body capacities lowered by injuries, illness, hunger and fatigue")})
     216            1 :         items = append(items,
     217            1 :                 statusItemData{Label: query.T(world, "Pain"), Value: fmt.Sprintf("%d%%", bodyFuncs.Pain), Description: query.T(world, "Pain from conditions. Lowers consciousness")},
     218            1 :                 statusItemData{Label: query.T(world, "Blood"), Value: fmt.Sprintf("%d%%", bodyFuncs.Blood), Description: bloodDesc, Details: bloodDetails},
     219            1 :                 statusItemData{Label: query.T(world, "Consciousness"), Value: fmt.Sprintf("%d%%", bodyFuncs.Consciousness), Description: query.T(world, "Overall alertness. Pain, illness, hunger and fatigue lower it. It slows actions"), Details: consciousnessDrops(world, playerEntity)},
     220            1 :                 statusItemData{Label: query.T(world, "Manipulation"), Value: fmt.Sprintf("%d%%", bodyFuncs.Manipulation), Description: query.T(world, "Affects melee accuracy and crafting"), Details: limbDrops(world, playerEntity, bodyFuncs, gc.BodyFuncManipulation)},
     221            1 :                 statusItemData{Label: query.T(world, "Moving"), Value: fmt.Sprintf("%d%%", bodyFuncs.Moving), Description: query.T(world, "Affects move speed"), Details: limbDrops(world, playerEntity, bodyFuncs, gc.BodyFuncMoving)},
     222            1 :                 statusItemData{Label: query.T(world, "Sight"), Value: fmt.Sprintf("%d%%", bodyFuncs.Sight), Description: query.T(world, "Affects ranged accuracy and vision"), Details: limbDrops(world, playerEntity, bodyFuncs, gc.BodyFuncSight)},
     223            1 :                 statusItemData{Label: query.T(world, "Metabolism"), Value: fmt.Sprintf("%d%%", bodyFuncs.Metabolism), Description: query.T(world, "Affects recovery speed. Hunger and fatigue lower it"), Details: fatigueHungerDrops(world, playerEntity)},
     224            1 :         )
     225            1 : 
     226            1 :         items = append(items, statusItemData{Label: query.T(world, "Survival"), IsHeader: true, Description: query.T(world, "Survival effects")})
     227            1 :         items = append(items,
     228            1 :                 statusItemData{Label: query.T(world, "Hypothermia progress"), Value: val(rawschema.ProficiencyIdColdProgress), Description: query.T(world, "Hypothermia progress rate. Lower is slower"), Details: details(rawschema.ProficiencyIdColdProgress)},
     229            1 :                 statusItemData{Label: query.T(world, "Hunger progress"), Value: val(rawschema.ProficiencyIdHungerProgress), Description: query.T(world, "Hunger progress rate. Lower is slower"), Details: details(rawschema.ProficiencyIdHungerProgress)},
     230            1 :                 statusItemData{Label: query.T(world, "Healing effect"), Value: val(rawschema.ProficiencyIdHealingEffect), Description: query.T(world, "Healing item effect multiplier. Higher heals more"), Details: details(rawschema.ProficiencyIdHealingEffect)},
     231            1 :                 statusItemData{Label: query.T(world, "Recovery"), Value: fmt.Sprintf("%d%%", query.Metabolism(world, playerEntity)), Description: query.T(world, "Natural recovery speed. VIT and sleep raise it, hunger and fatigue lower it"), Details: sourceToDetails(world, query.RecoverySources(world, playerEntity))},
     232            1 :         )
     233            1 : 
     234            1 :         items = append(items, statusItemData{Label: query.T(world, "Action"), IsHeader: true, Description: query.T(world, "Action effects")})
     235            1 :         items = append(items,
     236            1 :                 statusItemData{Label: query.T(world, "Move speed"), Value: val(rawschema.ProficiencyIdMoveCost), Description: query.T(world, "AP cost multiplier when moving. Lower moves with less AP"), Details: details(rawschema.ProficiencyIdMoveCost)},
     237            1 :                 statusItemData{Label: query.T(world, "Discovery"), Value: val(rawschema.ProficiencyIdExploration), Description: query.T(world, "Item discovery rate multiplier. Higher finds more"), Details: details(rawschema.ProficiencyIdExploration)},
     238            1 :                 statusItemData{Label: query.T(world, "Detection"), Value: val(rawschema.ProficiencyIdEnemyVision), Description: query.T(world, "Enemy detection distance multiplier. Lower is harder to find"), Details: details(rawschema.ProficiencyIdEnemyVision)},
     239            1 :                 statusItemData{Label: query.T(world, "Night vision"), Value: val(rawschema.ProficiencyIdNightVision), Description: query.T(world, "Vision multiplier in dark. Higher sees more"), Details: details(rawschema.ProficiencyIdNightVision)},
     240            1 :         )
     241            1 : 
     242            1 :         items = append(items, statusItemData{Label: query.T(world, "Production"), IsHeader: true, Description: query.T(world, "Production and trade effects")})
     243            1 :         items = append(items,
     244            1 :                 statusItemData{Label: query.T(world, "Material cost"), Value: val(rawschema.ProficiencyIdCraftCost), Description: query.T(world, "Material consumption multiplier when crafting. Lower saves materials"), Details: details(rawschema.ProficiencyIdCraftCost)},
     245            1 :                 statusItemData{Label: query.T(world, "Craft quality"), Value: val(rawschema.ProficiencyIdSmithQuality), Description: query.T(world, "Quality multiplier when crafting. Higher makes better goods"), Details: details(rawschema.ProficiencyIdSmithQuality)},
     246            1 :                 statusItemData{Label: query.T(world, "Buy price"), Value: val(rawschema.ProficiencyIdBuyPrice), Description: query.T(world, "Purchase price multiplier. Lower buys cheaper"), Details: details(rawschema.ProficiencyIdBuyPrice)},
     247            1 :                 statusItemData{Label: query.T(world, "Sell price"), Value: val(rawschema.ProficiencyIdSellPrice), Description: query.T(world, "Sell price multiplier. Higher sells higher"), Details: details(rawschema.ProficiencyIdSellPrice)},
     248            1 :                 statusItemData{Label: query.T(world, "Max weight"), Value: val(rawschema.ProficiencyIdMaxWeight), Description: query.T(world, "Max carry weight multiplier"), Details: details(rawschema.ProficiencyIdMaxWeight)},
     249            1 :                 statusItemData{Label: query.T(world, "Max load"), Value: val(rawschema.ProficiencyIdHeavyArmor), Description: query.T(world, "Max load multiplier"), Details: details(rawschema.ProficiencyIdHeavyArmor)},
     250            1 :         )
     251            1 :         return indentUnderHeaders(items)
     252              : }
     253              : 
     254              : // translatedConditionName は不調の種類名を訳して返す。重症度は進行度%で表すため名前に付けない
     255              : func translatedConditionName(world w.World, ct gc.ConditionType) string {
     256            1 :         return query.ConditionName(world, ct)
     257            1 : }
     258              : 
     259              : // treatmentStatus は不調の治療状態を表す。未治療か、治療済みならその質を出す
     260              : func treatmentStatus(world w.World, cond gc.HealthCondition) string {
     261            1 :         if cond.TendQuality <= 0 {
     262            0 :                 return query.T(world, "Untreated")
     263            0 :         }
     264            1 :         return fmt.Sprintf("%s %d%%", query.T(world, "Tended"), int(cond.TendQuality))
     265              : }
     266              : 
     267              : func (st *CharacterState) createHealthItems(world w.World, playerEntity ecs.Entity) []statusItemData {
     268            1 :         var items []statusItemData
     269            1 :         var hs *gc.HealthStatus
     270            1 :         if query.AliveHas(world, world.Components.HealthStatus, playerEntity) {
     271            1 :                 hs = world.Components.HealthStatus.Get(playerEntity)
     272            1 :         }
     273            1 :         for i := range int(gc.BodyPartCount) {
     274            1 :                 part := gc.BodyPart(i)
     275            1 :                 // 部位はカテゴリ見出し。カーソルは見出しを飛ばす
     276            1 :                 items = append(items, statusItemData{Label: query.BodyPartName(world, part), IsHeader: true, BodyPart: part})
     277            1 : 
     278            1 :                 var conds []gc.HealthCondition
     279            1 :                 if hs != nil {
     280            1 :                         conds = append(conds, hs.Parts[i].Conditions...)
     281            1 :                 }
     282              :                 // 全身は過労・栄養失調の受け皿。量から組み立てた不調を怪我と同じ列に並べる
     283            1 :                 if part == gc.BodyPartWholeBody {
     284            1 :                         conds = append(conds, query.DerivedConditions(world, playerEntity)...)
     285            1 :                 }
     286            1 :                 if len(conds) == 0 {
     287              :                         // 症状の無い部位は健康の1エントリを置く。見出しと区別するため字下げする
     288            1 :                         items = append(items, statusItemData{Label: query.T(world, "Normal"), BodyPart: part})
     289            1 :                         continue
     290              :                 }
     291              :                 // 症状ごとに1エントリ。見出しと区別するため字下げする
     292            1 :                 for _, cond := range conds {
     293              :                         // 各行が自分の不調を指すよう反復ごとにコピーを確保する
     294            1 :                         c := cond
     295            1 :                         // 過労・栄養失調は Timer を持たず量から導出される。進行度でなく重症度を出し、治療状態は付けない
     296            1 :                         if world.Resources.ConditionDefs.IsDerived(cond.Type) {
     297            1 :                                 items = append(items, statusItemData{
     298            1 :                                         Label:     translatedConditionName(world, cond.Type),
     299            1 :                                         Value:     query.T(world, cond.Severity.Name()),
     300            1 :                                         BodyPart:  part,
     301            1 :                                         Condition: &c,
     302            1 :                                 })
     303            1 :                                 continue
     304              :                         }
     305              :                         // 怪我・病気は名前の右に治療状態、値に進行度を出す
     306            1 :                         name := translatedConditionName(world, cond.Type) + "  " + treatmentStatus(world, cond)
     307            1 :                         items = append(items, statusItemData{
     308            1 :                                 Label:     name,
     309            1 :                                 Value:     fmt.Sprintf("%d%%", int(cond.Timer)),
     310            1 :                                 BodyPart:  part,
     311            1 :                                 Condition: &c,
     312            1 :                         })
     313              :                 }
     314              :         }
     315            1 :         return indentUnderHeaders(items)
     316              : }
     317              : 
     318              : // sourceToDetails はProficiencySourceのスライスから内訳表示用の行を生成する。変化量が0のソースは表示しない。
     319              : // 計算側は事実だけを持つので、ラベルの整形と翻訳はここで行う
     320              : func sourceToDetails(world w.World, srcs []gc.ProficiencySource) []statusDetailRow {
     321            1 :         var rows []statusDetailRow
     322            1 :         for _, s := range srcs {
     323            1 :                 if s.Value == 0 {
     324            1 :                         continue
     325              :                 }
     326            1 :                 rows = append(rows, statusDetailRow{Label: sourceLabel(world, s), Value: fmt.Sprintf("%+d%%", s.Value)})
     327              :         }
     328            1 :         return rows
     329              : }
     330              : 
     331              : // fatigueHungerDrops は過労・栄養失調による低下ぶんを内訳にする。意識と代謝の両方がこの低下を受ける
     332              : func fatigueHungerDrops(world w.World, playerEntity ecs.Entity) []statusDetailRow {
     333            1 :         var rows []statusDetailRow
     334            1 :         for _, c := range query.DerivedConditions(world, playerEntity) {
     335            1 :                 if _, _, drop := world.Resources.ConditionDefs.BodyFuncImpact(&c, gc.BodyPartWholeBody); drop != 0 {
     336            1 :                         rows = append(rows, statusDetailRow{Label: query.ConditionName(world, c.Type), Value: fmt.Sprintf("-%d%%", drop)})
     337            1 :                 }
     338              :         }
     339            1 :         return rows
     340              : }
     341              : 
     342              : // consciousnessDrops は意識の低下要因を内訳にする。怪我・病気・痛みは不調から、疲労・空腹は量から。
     343              : // 行の合計は意識の低下ぶんに一致する
     344              : func consciousnessDrops(world w.World, playerEntity ecs.Entity) []statusDetailRow {
     345            1 :         var rows []statusDetailRow
     346            1 :         if query.AliveHas(world, world.Components.HealthStatus, playerEntity) {
     347            1 :                 systemic, pain := world.Components.HealthStatus.Get(playerEntity).ConsciousnessDrops(world.Resources.ConditionDefs)
     348            1 :                 if systemic != 0 {
     349            0 :                         rows = append(rows, statusDetailRow{Label: query.T(world, "Injury and illness"), Value: fmt.Sprintf("-%d%%", systemic)})
     350            0 :                 }
     351            1 :                 if pain != 0 {
     352            1 :                         rows = append(rows, statusDetailRow{Label: query.T(world, "Pain"), Value: fmt.Sprintf("-%d%%", pain)})
     353            1 :                 }
     354              :         }
     355            1 :         return append(rows, fatigueHungerDrops(world, playerEntity)...)
     356              : }
     357              : 
     358              : // limbDrops は局所身体機能の低下要因を内訳にする。局所の怪我と、意識を全体乗数で掛けた減少を分けて出す。
     359              : // 意識の行を開けば疲労・空腹・痛みまで辿れる。行の合計は局所機能の値と一致する
     360              : func limbDrops(world w.World, playerEntity ecs.Entity, bodyFuncs gc.BodyFuncs, bf gc.BodyFuncKind) []statusDetailRow {
     361            1 :         local := 0
     362            1 :         if query.AliveHas(world, world.Components.HealthStatus, playerEntity) {
     363            1 :                 local = world.Components.HealthStatus.Get(playerEntity).LocalDrop(world.Resources.ConditionDefs, bf)
     364            1 :         }
     365            1 :         var rows []statusDetailRow
     366            1 :         if local != 0 {
     367            1 :                 rows = append(rows, statusDetailRow{Label: query.T(world, "Injury and illness"), Value: fmt.Sprintf("%+d%%", -local)})
     368            1 :         }
     369              :         // 局所を引いた後に意識を全体乗数で掛けた減少ぶん。意識自体の内訳は意識の行に出る
     370            1 :         afterLocal := max(0, min(100, 100-local))
     371            1 :         if d := afterLocal*int(bodyFuncs.Consciousness)/100 - afterLocal; d != 0 {
     372            1 :                 rows = append(rows, statusDetailRow{Label: query.T(world, "Consciousness"), Value: fmt.Sprintf("%+d%%", d)})
     373            1 :         }
     374            1 :         return rows
     375              : }
     376              : 
     377              : // sourceLabel は内訳1件の表示ラベルを現在言語で整形する
     378              : func sourceLabel(world w.World, s gc.ProficiencySource) string {
     379            1 :         switch s.Kind {
     380              :         case gc.SourceSkill:
     381            0 :                 return fmt.Sprintf("%s Lv%d", query.SkillName(world, s.Skill), s.Amount)
     382              :         case gc.SourceAbility:
     383            1 :                 return fmt.Sprintf("%s %d", query.T(world, gc.AbilityName(s.Ability)), s.Amount)
     384              :         case gc.SourceBodyFunc:
     385            1 :                 return fmt.Sprintf("%s %d%%", query.T(world, s.BodyFunc.Name()), s.Amount)
     386              :         case gc.SourceFatigue:
     387            0 :                 return query.FatigueName(world, s.Fatigue)
     388              :         case gc.SourceHunger:
     389            0 :                 return query.HungerName(world, s.Hunger)
     390              :         case gc.SourceSleeping:
     391            0 :                 return query.T(world, "Sleeping")
     392              :         }
     393            0 :         panic("unknown ProficiencySourceKind: " + string(s.Kind))
     394              : }
     395              : 
     396              : // buildInfoTableUI は情報タブの表とフッタ右端のページ表示を返す。
     397              : func buildInfoTableUI(world w.World, tab statusTabData, itemIndex int, res resources.UIResources) ([]uicore.Drawable, string) {
     398            1 :         hasModifier := tab.ID == tabAbilities
     399            1 :         // 能力タブは 名前・値・修正値 の3列、他は 名前・値 の2列。値と修正値は右寄せ
     400            1 :         cols := styled.Cols(styled.Name(), styled.Num())
     401            1 :         if hasModifier {
     402            1 :                 cols = styled.Cols(styled.Name(), styled.Num(), styled.Num())
     403            1 :         }
     404            1 :         rows := make([]menuframe.Row, len(tab.Items))
     405            1 :         for i, it := range tab.Items {
     406            1 :                 cells := make([]string, len(cols))
     407            1 :                 cells[0] = it.Label
     408            1 :                 if !it.IsHeader {
     409            1 :                         cells[1] = it.Value
     410            1 :                         if hasModifier {
     411            1 :                                 cells[2] = it.Modifier
     412            1 :                         }
     413              :                 }
     414            1 :                 rows[i] = menuframe.Row{Cells: styled.TextCells(cells...), Header: it.IsHeader, Indent: it.Indent}
     415              :         }
     416            1 :         return menuframe.RenderList(itemIndex, rows, cols, menuframe.ListOpts{EmptyText: query.T(world, "No entries"), ItemsPerPage: menuframe.ListCapacity(world, true, true)}, res)
     417              : }
        

Generated by: LCOV version 2.0-1