2026-01-14 18:52:29 +01:00
|
|
|
package gsmaster
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bamort/database"
|
|
|
|
|
"bamort/models"
|
2026-01-14 21:13:25 +01:00
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
2026-01-14 18:52:29 +01:00
|
|
|
)
|
|
|
|
|
|
2026-01-28 07:44:17 +01:00
|
|
|
// GetMiscLookupByKey retrieves values for a key using the default game system id.
|
|
|
|
|
// Optional order parameter can be: "id", "value", "source", "source_value" (defaults to "value").
|
2026-01-14 21:58:37 +01:00
|
|
|
func GetMiscLookupByKey(key string, order ...string) ([]models.MiscLookup, error) {
|
2026-01-28 07:44:17 +01:00
|
|
|
gs := models.GetGameSystem(0, "")
|
|
|
|
|
return GetMiscLookupByKeyForSystem(key, gs.ID, order...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetMiscLookupByKeyForSystem retrieves values for a key filtered by the provided game system id.
|
|
|
|
|
// Optional order parameter can be: "id", "value", "source", "source_value" (defaults to "value").
|
|
|
|
|
func GetMiscLookupByKeyForSystem(key string, gameSystemId uint, order ...string) ([]models.MiscLookup, error) {
|
2026-01-14 18:52:29 +01:00
|
|
|
var items []models.MiscLookup
|
2026-01-14 21:58:37 +01:00
|
|
|
|
|
|
|
|
orderBy := "value ASC"
|
|
|
|
|
if len(order) > 0 && order[0] != "" {
|
|
|
|
|
switch order[0] {
|
|
|
|
|
case "id":
|
|
|
|
|
orderBy = "id ASC"
|
|
|
|
|
case "value":
|
|
|
|
|
orderBy = "value ASC"
|
|
|
|
|
case "source":
|
|
|
|
|
orderBy = "source_id ASC, value ASC"
|
|
|
|
|
case "source_value":
|
|
|
|
|
orderBy = "source_id ASC, value ASC"
|
|
|
|
|
default:
|
|
|
|
|
orderBy = "value ASC"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 07:44:17 +01:00
|
|
|
gs := models.GetGameSystem(gameSystemId, "")
|
2026-01-28 08:51:35 +01:00
|
|
|
|
|
|
|
|
query := database.DB.Where("`key` = ?", key)
|
|
|
|
|
if gs.ID != 0 {
|
|
|
|
|
query = query.Where("game_system_id = ? OR game_system_id = 0 OR game_system_id IS NULL", gs.ID)
|
|
|
|
|
} else {
|
|
|
|
|
query = query.Where("game_system_id = 0 OR game_system_id IS NULL")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := query.Order(orderBy).Find(&items).Error; err != nil {
|
|
|
|
|
return items, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if gs.ID != 0 {
|
|
|
|
|
for i := range items {
|
|
|
|
|
if items[i].GameSystemId == 0 {
|
|
|
|
|
items[i].GameSystemId = gs.ID
|
|
|
|
|
database.DB.Model(&items[i]).Update("game_system_id", gs.ID)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items, nil
|
2026-01-14 18:52:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// PopulateMiscLookupData populates initial misc lookup data if table is empty
|
|
|
|
|
func PopulateMiscLookupData() error {
|
|
|
|
|
// Check if data already exists
|
|
|
|
|
var count int64
|
|
|
|
|
if err := database.DB.Model(&models.MiscLookup{}).Count(&count).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if count > 0 {
|
|
|
|
|
return nil // Data already exists
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Define initial data
|
|
|
|
|
initialData := []struct {
|
|
|
|
|
key string
|
|
|
|
|
values []string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
key: "gender",
|
|
|
|
|
values: []string{"männlich", "weiblich", "divers"},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "races",
|
|
|
|
|
values: []string{"Mensch", "Elf", "Zwerg", "Gnom", "Halbling"},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "origins",
|
|
|
|
|
values: []string{
|
|
|
|
|
"Albai", "Aran", "Chryseia", "Clanngadarn", "Erainn",
|
|
|
|
|
"Eschar", "Fuardain", "Ikengabecken", "KanThaiPan", "Küstenstaaten",
|
|
|
|
|
"Moravod", "Nahuatlan", "Rawindra", "Twyneddin", "Valian",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "social_classes",
|
2026-01-14 21:13:25 +01:00
|
|
|
values: []string{"Unfrei", "Volk", "Mittelschicht", "Adel"},
|
2026-01-14 18:52:29 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "faiths",
|
|
|
|
|
values: []string{"Keine", "Nathir", "Deis Albai", "Mahal", "Druide"},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "handedness",
|
|
|
|
|
values: []string{"rechts", "links", "beidhändig"},
|
|
|
|
|
},
|
2026-01-14 21:13:25 +01:00
|
|
|
{
|
|
|
|
|
key: "social_class_bonus",
|
|
|
|
|
values: []string{"Unfrei|Halbwelt|2", "Volk|Alltag|2", "Mittelschicht|Wissen|2", "Adel|Sozial|2"},
|
|
|
|
|
},
|
2026-01-14 18:52:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Insert data
|
|
|
|
|
for _, item := range initialData {
|
|
|
|
|
for _, value := range item.values {
|
|
|
|
|
misc := models.MiscLookup{
|
2026-01-14 21:13:25 +01:00
|
|
|
Key: item.key,
|
|
|
|
|
Value: value,
|
|
|
|
|
SourceID: 1,
|
2026-01-14 18:52:29 +01:00
|
|
|
}
|
|
|
|
|
if err := database.DB.Create(&misc).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
*/
|
2026-01-14 21:13:25 +01:00
|
|
|
|
|
|
|
|
// GetSocialClassBonusPoints retrieves bonus learning points for a social class from database
|
|
|
|
|
func GetSocialClassBonusPoints(socialClass string) (map[string]int, error) {
|
|
|
|
|
bonuses, err := GetMiscLookupByKey("social_class_bonus")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := make(map[string]int)
|
|
|
|
|
for _, bonus := range bonuses {
|
|
|
|
|
// Parse format: "SocialClass|Category|Points"
|
|
|
|
|
parts := strings.Split(bonus.Value, "|")
|
|
|
|
|
if len(parts) == 3 && parts[0] == socialClass {
|
|
|
|
|
category := parts[1]
|
|
|
|
|
points := 0
|
|
|
|
|
fmt.Sscanf(parts[2], "%d", &points)
|
|
|
|
|
result[category] = points
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|