Line data Source code
1 : package components
2 :
3 : import (
4 : "errors"
5 : "fmt"
6 :
7 : "github.com/kijimaD/ruins/internal/i18n"
8 :
9 : "github.com/kijimaD/ruins/internal/rawschema"
10 : )
11 :
12 : // ErrInvalidEnumType はinvalid enum value場合のエラー
13 : var ErrInvalidEnumType = errors.New("invalid enum value")
14 :
15 : // ================
16 :
17 : // BodyPart は体の部位を表す
18 : type BodyPart int
19 :
20 : // 体の部位定数
21 : const (
22 : BodyPartHead BodyPart = iota // 頭
23 : BodyPartTorso // 胴体
24 : BodyPartArms // 腕
25 : BodyPartHands // 手
26 : BodyPartLegs // 脚
27 : BodyPartFeet // 足
28 : BodyPartWholeBody // 全身。体温異常など全身に影響する状態を管理する
29 : BodyPartCount // 部位数
30 : )
31 :
32 : // String は raw の bodyParts の id を返す。表示名は query.BodyPartName で引く
33 : func (bp BodyPart) String() string {
34 1 : return bodyPartMetas[bp].id
35 1 : }
36 :
37 : // ID は raw の bodyParts の id を返す
38 : func (bp BodyPart) ID() string {
39 1 : return bodyPartMetas[bp].id
40 1 : }
41 :
42 : // BodyPartByID は raw の bodyParts の id から部位を返す。該当が無ければ ok=false
43 : func BodyPartByID(id string) (BodyPart, bool) {
44 1 : for bp := range BodyPartCount {
45 1 : if bodyPartMetas[bp].id == id {
46 1 : return bp, true
47 1 : }
48 : }
49 1 : return 0, false
50 : }
51 :
52 : // ================
53 :
54 : // RangeParams は遠距離武器の射程パラメータ。raw の attackTypes の行から組み立てる
55 : type RangeParams struct {
56 : OptimalRange int // 最適射程。この距離内はペナルティなし
57 : MaxRange int // 最大射程。超過で射撃不可
58 : PenaltyPerTile int // 最適射程超過時の1タイルあたり命中率ペナルティ(%)
59 : }
60 :
61 : // ================
62 :
63 : // EquipmentCategoryName は防具の部位の表示名 msgid を返す
64 : func EquipmentCategoryName(c rawschema.EquipmentCategory) i18n.Msgid {
65 1 : switch c {
66 : case rawschema.EquipmentCategoryHEAD:
67 1 : return "Head"
68 : case rawschema.EquipmentCategoryTORSO:
69 1 : return "Torso"
70 : case rawschema.EquipmentCategoryARMS:
71 1 : return "Arms"
72 : case rawschema.EquipmentCategoryHANDS:
73 1 : return "Hands"
74 : case rawschema.EquipmentCategoryLEGS:
75 1 : return "Legs"
76 : case rawschema.EquipmentCategoryFEET:
77 1 : return "Feet"
78 : case rawschema.EquipmentCategoryJEWELRY:
79 1 : return "Accessory"
80 : }
81 0 : panic(fmt.Sprintf("invalid EquipmentCategory value: %s", string(c)))
82 : }
83 :
84 : // ================
85 :
86 : // ElementName は攻撃属性の表示名 msgid を返す
87 : func ElementName(e rawschema.Element) i18n.Msgid {
88 1 : switch e {
89 : case rawschema.ElementNONE:
90 1 : return "None"
91 : case rawschema.ElementFIRE:
92 1 : return "Fire"
93 : case rawschema.ElementTHUNDER:
94 1 : return "Thunder"
95 : case rawschema.ElementCHILL:
96 1 : return "Ice"
97 : case rawschema.ElementPHOTON:
98 1 : return "Light"
99 : }
100 1 : panic(fmt.Sprintf("invalid Element value: %s", string(e)))
101 : }
|