2022-04-16 23:12:23 +03:00
|
|
|
package model
|
|
|
|
|
2022-04-21 17:25:35 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
2022-05-02 18:22:57 +03:00
|
|
|
"html/template"
|
2022-04-23 22:38:03 +03:00
|
|
|
"sort"
|
2022-04-21 23:01:18 +03:00
|
|
|
"strings"
|
2022-04-21 17:25:35 +03:00
|
|
|
|
|
|
|
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
|
|
|
|
)
|
2022-04-19 12:46:43 +03:00
|
|
|
|
2022-04-26 10:24:16 +03:00
|
|
|
func (w *DfWorld) AllEventTypes() []string {
|
|
|
|
types := make(map[string]bool)
|
|
|
|
for _, e := range w.HistoricalEvents {
|
|
|
|
types[e.Details.Type()] = true
|
|
|
|
}
|
|
|
|
var list = util.Keys(types)
|
|
|
|
sort.Strings(list)
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *DfWorld) EventsOfType(t string) any {
|
|
|
|
var list []*HistoricalEvent
|
|
|
|
for _, e := range w.HistoricalEvents {
|
|
|
|
if e.Details.Type() == t {
|
|
|
|
list = append(list, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(list, func(i, j int) bool { return list[i].Id_ < list[j].Id_ })
|
|
|
|
|
|
|
|
return struct {
|
|
|
|
Type string
|
|
|
|
Events []*HistoricalEvent
|
|
|
|
}{
|
|
|
|
Type: t,
|
|
|
|
Events: list,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *DfWorld) EventsMatching(f func(HistoricalEventDetails) bool) []*HistoricalEvent {
|
|
|
|
var list []*HistoricalEvent
|
|
|
|
for _, e := range w.HistoricalEvents {
|
|
|
|
if f(e.Details) {
|
|
|
|
list = append(list, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Slice(list, func(a, b int) bool { return list[a].Id_ < list[b].Id_ })
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2022-04-29 16:28:08 +03:00
|
|
|
func (w *DfWorld) SiteHistory(siteId int) []*HistoricalEvent {
|
|
|
|
var list []*HistoricalEvent
|
|
|
|
for _, e := range w.HistoricalEvents {
|
|
|
|
if e.Details.RelatedToSite(siteId) {
|
|
|
|
switch e.Details.(type) {
|
|
|
|
case *HistoricalEventCreatedSite, *HistoricalEventDestroyedSite, *HistoricalEventSiteTakenOver, *HistoricalEventHfDestroyedSite, *HistoricalEventReclaimSite:
|
|
|
|
list = append(list, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Slice(list, func(a, b int) bool { return list[a].Id_ < list[b].Id_ })
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2022-05-03 15:59:47 +03:00
|
|
|
func (c *HistoricalEventCollection) Type() string {
|
|
|
|
if c.Details == nil {
|
|
|
|
return "unk"
|
|
|
|
}
|
|
|
|
return c.Details.Type()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HistoricalEventCollection) Html(c *Context) string {
|
|
|
|
if e.Details == nil {
|
|
|
|
return "unk"
|
|
|
|
}
|
|
|
|
return e.Details.Html(e, c)
|
|
|
|
}
|
|
|
|
|
2022-04-28 22:24:55 +03:00
|
|
|
func (e *Artifact) Type() string {
|
2022-04-29 12:31:05 +03:00
|
|
|
switch e.ItemSubtype {
|
|
|
|
case "scroll":
|
|
|
|
return "scroll"
|
|
|
|
}
|
|
|
|
switch e.ItemType {
|
|
|
|
case "weapon", "tool", "book", "slab":
|
|
|
|
return e.ItemType
|
|
|
|
case "armor", "shoe", "gloves", "helm", "pants":
|
|
|
|
return "armor"
|
|
|
|
default:
|
|
|
|
return "item"
|
|
|
|
}
|
2022-04-28 22:24:55 +03:00
|
|
|
}
|
|
|
|
|
2022-04-27 22:44:39 +03:00
|
|
|
func (e *Entity) Type() string {
|
|
|
|
return e.Type_.String()
|
|
|
|
}
|
|
|
|
|
2022-04-16 23:12:23 +03:00
|
|
|
func (e *Entity) Position(id int) *EntityPosition {
|
|
|
|
for _, p := range e.EntityPosition {
|
|
|
|
if p.Id_ == id {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
}
|
2022-04-20 00:54:29 +03:00
|
|
|
return &EntityPosition{Name_: "UNKNOWN POSITION"}
|
2022-04-16 23:12:23 +03:00
|
|
|
}
|
|
|
|
|
2022-05-04 12:42:02 +03:00
|
|
|
func (e *Entity) PositionByIndex(index int) *EntityPosition {
|
|
|
|
return e.EntityPosition[len(e.EntityPosition)-1-index]
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:46:11 +03:00
|
|
|
func (p *EntityPosition) GenderName(hf *HistoricalFigure) string {
|
|
|
|
if hf.Female() && p.NameFemale != "" {
|
|
|
|
return p.NameFemale
|
|
|
|
} else if hf.Male() && p.NameMale != "" {
|
|
|
|
return p.NameMale
|
|
|
|
} else {
|
|
|
|
return p.Name_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hf *HistoricalFigure) Female() bool {
|
|
|
|
return hf.Sex == 0 || hf.Caste == "FEMALE"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hf *HistoricalFigure) Male() bool {
|
|
|
|
return hf.Sex == 1 || hf.Caste == "MALE"
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:31:23 +03:00
|
|
|
func (hf *HistoricalFigure) Pronoun() string {
|
|
|
|
if hf.Female() {
|
|
|
|
return "she"
|
|
|
|
}
|
|
|
|
return "he"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hf *HistoricalFigure) PossesivePronoun() string {
|
|
|
|
if hf.Female() {
|
|
|
|
return "her"
|
|
|
|
}
|
|
|
|
return "his"
|
|
|
|
}
|
|
|
|
|
2022-04-23 00:57:10 +03:00
|
|
|
func (hf *HistoricalFigure) FirstName() string {
|
|
|
|
return strings.Split(hf.Name_, " ")[0]
|
|
|
|
}
|
|
|
|
|
2022-04-26 10:24:16 +03:00
|
|
|
func (x *Honor) Requirement() string {
|
|
|
|
var list []string
|
|
|
|
if x.RequiresAnyMeleeOrRangedSkill {
|
|
|
|
list = append(list, "attaining sufficent skill with a weapon or technique")
|
2022-04-23 22:38:03 +03:00
|
|
|
}
|
2022-04-26 10:24:16 +03:00
|
|
|
if x.RequiredSkill != HonorRequiredSkill_Unknown {
|
|
|
|
list = append(list, "attaining enough skill with the "+x.RequiredSkill.String())
|
2022-04-23 22:38:03 +03:00
|
|
|
}
|
2022-04-26 10:24:16 +03:00
|
|
|
if x.RequiredBattles == 1 {
|
|
|
|
list = append(list, "serving in combat")
|
2022-04-23 22:38:03 +03:00
|
|
|
}
|
2022-04-26 10:24:16 +03:00
|
|
|
if x.RequiredBattles > 1 {
|
|
|
|
list = append(list, fmt.Sprintf("participating in %d battles", x.RequiredBattles))
|
2022-04-23 00:57:10 +03:00
|
|
|
}
|
2022-04-26 10:24:16 +03:00
|
|
|
if x.RequiredYears >= 1 {
|
|
|
|
list = append(list, fmt.Sprintf("%d years of membership", x.RequiredYears))
|
2022-04-22 13:34:42 +03:00
|
|
|
}
|
2022-04-26 10:24:16 +03:00
|
|
|
if x.RequiredKills >= 1 {
|
|
|
|
list = append(list, fmt.Sprintf("slaying %d enemies", x.RequiredKills))
|
2022-04-22 18:45:10 +03:00
|
|
|
}
|
|
|
|
|
2022-04-26 10:24:16 +03:00
|
|
|
return " after " + andList(list)
|
2022-04-23 00:57:10 +03:00
|
|
|
}
|
|
|
|
|
2022-04-28 22:24:55 +03:00
|
|
|
func (r *Region) Type() string {
|
|
|
|
return r.Type_.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) Type() string {
|
|
|
|
return s.Type_.String()
|
|
|
|
}
|
|
|
|
|
2022-04-29 15:21:27 +03:00
|
|
|
func (s *Structure) Type() string {
|
|
|
|
return s.Type_.String()
|
|
|
|
}
|
|
|
|
|
2022-04-28 22:24:55 +03:00
|
|
|
func (w *WorldConstruction) Type() string {
|
|
|
|
return w.Type_.String()
|
|
|
|
}
|
|
|
|
|
2022-04-26 10:24:16 +03:00
|
|
|
func (w *WrittenContent) Name() string {
|
|
|
|
return w.Title
|
2022-04-23 12:18:37 +03:00
|
|
|
}
|
2022-04-28 22:24:55 +03:00
|
|
|
|
|
|
|
func (w *WrittenContent) Type() string {
|
|
|
|
return w.Type_.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *DanceForm) Type() string {
|
|
|
|
return "dance form"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *MusicalForm) Type() string {
|
|
|
|
return "musical form"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *PoeticForm) Type() string {
|
|
|
|
return "poetic form"
|
|
|
|
}
|
2022-05-02 18:22:57 +03:00
|
|
|
|
|
|
|
func (r *Reference) Html(c *Context) template.HTML {
|
|
|
|
switch r.Type_ {
|
|
|
|
case ReferenceType_ABSTRACTBUILDING:
|
|
|
|
return template.HTML("a building")
|
|
|
|
case ReferenceType_ARTIFACT:
|
|
|
|
return template.HTML(c.artifact(r.Id_))
|
|
|
|
case ReferenceType_DANCEFORM:
|
|
|
|
return template.HTML(c.danceForm(r.Id_))
|
|
|
|
case ReferenceType_ENTITY:
|
|
|
|
return template.HTML(c.entity(r.Id_))
|
|
|
|
case ReferenceType_HISTORICALEVENT:
|
|
|
|
if e, ok := c.World.HistoricalEvents[r.Id_]; ok {
|
|
|
|
return template.HTML("how in " + Time(e.Year, e.Seconds72) + " " + e.Details.Html(c))
|
|
|
|
}
|
|
|
|
case ReferenceType_HISTORICALFIGURE:
|
|
|
|
return template.HTML(c.hf(r.Id_))
|
|
|
|
case ReferenceType_INTERACTION:
|
|
|
|
return template.HTML("an interaction")
|
|
|
|
case ReferenceType_KNOWLEDGESCHOLARFLAG:
|
|
|
|
return template.HTML("specific knowledge")
|
|
|
|
case ReferenceType_LANGUAGE:
|
|
|
|
return template.HTML("a language")
|
|
|
|
case ReferenceType_MUSICALFORM:
|
|
|
|
return template.HTML(c.musicalForm(r.Id_))
|
|
|
|
case ReferenceType_POETICFORM:
|
|
|
|
return template.HTML(c.poeticForm(r.Id_))
|
|
|
|
case ReferenceType_SITE:
|
|
|
|
return template.HTML(c.site(r.Id_, ""))
|
|
|
|
case ReferenceType_SUBREGION:
|
|
|
|
return template.HTML(c.region(r.Id_))
|
|
|
|
case ReferenceType_VALUELEVEL:
|
|
|
|
return template.HTML("a value")
|
|
|
|
case ReferenceType_WRITTENCONTENT:
|
|
|
|
return template.HTML(c.writtenContent(r.Id_))
|
|
|
|
}
|
|
|
|
return template.HTML(r.Type_.String())
|
|
|
|
}
|