+123
-77
@@ -18,6 +18,8 @@ var (
|
||||
skillGroupSQL string
|
||||
//go:embed sql/skill.sql
|
||||
skillSQL string
|
||||
//go:embed sql/skill-group-skills.sql
|
||||
skillGroupSkillsSQL string
|
||||
)
|
||||
|
||||
// SkillGroups retrieves all skill groups.
|
||||
@@ -35,84 +37,128 @@ func SkillGroups(ctx context.Context, db *sqlitex.Pool) ([]horse.SkillGroup, err
|
||||
|
||||
// Skills retrieves all skills.
|
||||
func Skills(ctx context.Context, db *sqlitex.Pool) ([]horse.Skill, error) {
|
||||
return load(ctx, db, nil, skillSQL, func(s *sqlite.Stmt) horse.Skill {
|
||||
return horse.Skill{
|
||||
ID: horse.SkillID(s.ColumnInt(0)),
|
||||
Name: s.ColumnText(1),
|
||||
Description: s.ColumnText(2),
|
||||
Group: horse.SkillGroupID(s.ColumnInt32(3)),
|
||||
Rarity: int8(s.ColumnInt(5)),
|
||||
GroupRate: int8(s.ColumnInt(6)),
|
||||
GradeValue: s.ColumnInt32(7),
|
||||
WitCheck: s.ColumnBool(8),
|
||||
Activations: trimActivations([]horse.Activation{
|
||||
{
|
||||
Precondition: s.ColumnText(9),
|
||||
Condition: s.ColumnText(10),
|
||||
Duration: horse.TenThousandths(s.ColumnInt(11)),
|
||||
DurScale: horse.DurScale(s.ColumnInt(12)),
|
||||
Cooldown: horse.TenThousandths(s.ColumnInt(13)),
|
||||
Abilities: trimAbilities([]horse.Ability{
|
||||
{
|
||||
Type: horse.AbilityType(s.ColumnInt(14)),
|
||||
ValueUsage: horse.AbilityValueUsage(s.ColumnInt(15)),
|
||||
Value: horse.TenThousandths(s.ColumnInt(16)),
|
||||
Target: horse.AbilityTarget(s.ColumnInt(17)),
|
||||
TargetValue: s.ColumnInt32(18),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(s.ColumnInt(19)),
|
||||
ValueUsage: horse.AbilityValueUsage(s.ColumnInt(20)),
|
||||
Value: horse.TenThousandths(s.ColumnInt(21)),
|
||||
Target: horse.AbilityTarget(s.ColumnInt(22)),
|
||||
TargetValue: s.ColumnInt32(23),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(s.ColumnInt(24)),
|
||||
ValueUsage: horse.AbilityValueUsage(s.ColumnInt(25)),
|
||||
Value: horse.TenThousandths(s.ColumnInt(26)),
|
||||
Target: horse.AbilityTarget(s.ColumnInt(27)),
|
||||
TargetValue: s.ColumnInt32(28),
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
Precondition: s.ColumnText(29),
|
||||
Condition: s.ColumnText(30),
|
||||
Duration: horse.TenThousandths(s.ColumnInt(31)),
|
||||
DurScale: horse.DurScale(s.ColumnInt(32)),
|
||||
Cooldown: horse.TenThousandths(s.ColumnInt(33)),
|
||||
Abilities: trimAbilities([]horse.Ability{
|
||||
{
|
||||
Type: horse.AbilityType(s.ColumnInt(34)),
|
||||
ValueUsage: horse.AbilityValueUsage(s.ColumnInt(35)),
|
||||
Value: horse.TenThousandths(s.ColumnInt(36)),
|
||||
Target: horse.AbilityTarget(s.ColumnInt(37)),
|
||||
TargetValue: s.ColumnInt32(38),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(s.ColumnInt(39)),
|
||||
ValueUsage: horse.AbilityValueUsage(s.ColumnInt(40)),
|
||||
Value: horse.TenThousandths(s.ColumnInt(41)),
|
||||
Target: horse.AbilityTarget(s.ColumnInt(42)),
|
||||
TargetValue: s.ColumnInt32(43),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(s.ColumnInt(44)),
|
||||
ValueUsage: horse.AbilityValueUsage(s.ColumnInt(45)),
|
||||
Value: horse.TenThousandths(s.ColumnInt(46)),
|
||||
Target: horse.AbilityTarget(s.ColumnInt(47)),
|
||||
TargetValue: s.ColumnInt32(48),
|
||||
},
|
||||
}),
|
||||
},
|
||||
}),
|
||||
UniqueOwner: s.ColumnText(52), // TODO(zeph): should be id, not name
|
||||
Tags: parseTags(s.ColumnText(54)),
|
||||
SPCost: s.ColumnInt(49),
|
||||
IconID: s.ColumnInt(53),
|
||||
// We don't use func load here because we have multiple queries to run.
|
||||
conn, err := db.Take(ctx)
|
||||
defer db.Put(conn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var sk []horse.Skill
|
||||
{
|
||||
stmt := conn.Prep(skillSQL)
|
||||
defer stmt.Reset()
|
||||
for {
|
||||
ok, err := stmt.Step()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
s := horse.Skill{
|
||||
ID: horse.SkillID(stmt.ColumnInt(0)),
|
||||
Name: stmt.ColumnText(1),
|
||||
Description: stmt.ColumnText(2),
|
||||
GroupSkills: make([]horse.GroupSkill, 0, 3),
|
||||
Group: horse.SkillGroupID(stmt.ColumnInt32(3)),
|
||||
Rarity: int8(stmt.ColumnInt(5)),
|
||||
GroupRate: int8(stmt.ColumnInt(6)),
|
||||
GradeValue: stmt.ColumnInt32(7),
|
||||
WitCheck: stmt.ColumnBool(8),
|
||||
Activations: trimActivations([]horse.Activation{
|
||||
{
|
||||
Precondition: stmt.ColumnText(9),
|
||||
Condition: stmt.ColumnText(10),
|
||||
Duration: horse.TenThousandths(stmt.ColumnInt(11)),
|
||||
DurScale: horse.DurScale(stmt.ColumnInt(12)),
|
||||
Cooldown: horse.TenThousandths(stmt.ColumnInt(13)),
|
||||
Abilities: trimAbilities([]horse.Ability{
|
||||
{
|
||||
Type: horse.AbilityType(stmt.ColumnInt(14)),
|
||||
ValueUsage: horse.AbilityValueUsage(stmt.ColumnInt(15)),
|
||||
Value: horse.TenThousandths(stmt.ColumnInt(16)),
|
||||
Target: horse.AbilityTarget(stmt.ColumnInt(17)),
|
||||
TargetValue: stmt.ColumnInt32(18),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(stmt.ColumnInt(19)),
|
||||
ValueUsage: horse.AbilityValueUsage(stmt.ColumnInt(20)),
|
||||
Value: horse.TenThousandths(stmt.ColumnInt(21)),
|
||||
Target: horse.AbilityTarget(stmt.ColumnInt(22)),
|
||||
TargetValue: stmt.ColumnInt32(23),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(stmt.ColumnInt(24)),
|
||||
ValueUsage: horse.AbilityValueUsage(stmt.ColumnInt(25)),
|
||||
Value: horse.TenThousandths(stmt.ColumnInt(26)),
|
||||
Target: horse.AbilityTarget(stmt.ColumnInt(27)),
|
||||
TargetValue: stmt.ColumnInt32(28),
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
Precondition: stmt.ColumnText(29),
|
||||
Condition: stmt.ColumnText(30),
|
||||
Duration: horse.TenThousandths(stmt.ColumnInt(31)),
|
||||
DurScale: horse.DurScale(stmt.ColumnInt(32)),
|
||||
Cooldown: horse.TenThousandths(stmt.ColumnInt(33)),
|
||||
Abilities: trimAbilities([]horse.Ability{
|
||||
{
|
||||
Type: horse.AbilityType(stmt.ColumnInt(34)),
|
||||
ValueUsage: horse.AbilityValueUsage(stmt.ColumnInt(35)),
|
||||
Value: horse.TenThousandths(stmt.ColumnInt(36)),
|
||||
Target: horse.AbilityTarget(stmt.ColumnInt(37)),
|
||||
TargetValue: stmt.ColumnInt32(38),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(stmt.ColumnInt(39)),
|
||||
ValueUsage: horse.AbilityValueUsage(stmt.ColumnInt(40)),
|
||||
Value: horse.TenThousandths(stmt.ColumnInt(41)),
|
||||
Target: horse.AbilityTarget(stmt.ColumnInt(42)),
|
||||
TargetValue: stmt.ColumnInt32(43),
|
||||
},
|
||||
{
|
||||
Type: horse.AbilityType(stmt.ColumnInt(44)),
|
||||
ValueUsage: horse.AbilityValueUsage(stmt.ColumnInt(45)),
|
||||
Value: horse.TenThousandths(stmt.ColumnInt(46)),
|
||||
Target: horse.AbilityTarget(stmt.ColumnInt(47)),
|
||||
TargetValue: stmt.ColumnInt32(48),
|
||||
},
|
||||
}),
|
||||
},
|
||||
}),
|
||||
UniqueOwner: stmt.ColumnText(52), // TODO(zeph): should be id, not name
|
||||
Tags: parseTags(stmt.ColumnText(54)),
|
||||
SPCost: stmt.ColumnInt(49),
|
||||
IconID: stmt.ColumnInt(53),
|
||||
}
|
||||
sk = append(sk, s)
|
||||
}
|
||||
})
|
||||
}
|
||||
stmt := conn.Prep(skillGroupSkillsSQL)
|
||||
defer stmt.Reset()
|
||||
cur := sk
|
||||
for {
|
||||
ok, err := stmt.Step()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
// We sort skills by ID first, so we can add group skills in a single pass.
|
||||
id := stmt.ColumnInt(0)
|
||||
for len(cur) != 0 && cur[0].ID != horse.SkillID(id) {
|
||||
cur = cur[1:]
|
||||
}
|
||||
g := horse.GroupSkill{
|
||||
ID: horse.SkillID(stmt.ColumnInt(1)),
|
||||
GroupRate: int8(stmt.ColumnInt(2)),
|
||||
Rarity: int8(stmt.ColumnInt(3)),
|
||||
}
|
||||
cur[0].GroupSkills = append(cur[0].GroupSkills, g)
|
||||
}
|
||||
return sk, nil
|
||||
}
|
||||
|
||||
func parseTags(s string) []uint16 {
|
||||
|
||||
Reference in New Issue
Block a user