-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpc.go
56 lines (45 loc) · 1.26 KB
/
npc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package retropg
import (
"context"
"github.com/kralamoure/retro"
)
func (r *Db) NPCs(ctx context.Context, gameServerId int) (npcs map[string]retro.NPC, err error) {
query := "SELECT id, gameserver_id, map_id, cell_id, direction, template_id, sex, gfx, scale_x, scale_y, color_1, color_2, color_3, accessories, extra_clip, custom_artwork, dialog_id, market_id" +
" FROM retro.npcs" +
" WHERE gameserver_id = $1;"
rows, err := r.pool.Query(ctx, query, gameServerId)
if err != nil {
return
}
defer rows.Close()
npcs = make(map[string]retro.NPC)
for rows.Next() {
var npc retro.NPC
var dialogId *int
var marketId *string
var extraClip *int
var customArtwork *int
err = rows.Scan(&npc.Id, &npc.GameServerId, &npc.MapId, &npc.CellId, &npc.Direction, &npc.TemplateId,
&npc.Sex, &npc.GFX, &npc.ScaleX, &npc.ScaleY, &npc.Color1, &npc.Color2, &npc.Color3, &npc.Accessories,
&extraClip, &customArtwork, &dialogId, &marketId)
if err != nil {
return
}
if dialogId != nil {
npc.DialogId = *dialogId
}
if marketId != nil {
npc.MarketId = *marketId
}
if extraClip != nil {
npc.ExtraClip = *extraClip
} else {
npc.ExtraClip = -1
}
if customArtwork != nil {
npc.CustomArtwork = *customArtwork
}
npcs[npc.Id] = npc
}
return
}