dorfylegends/backend/model/process.go

67 lines
1.7 KiB
Go
Raw Normal View History

2022-04-29 15:21:27 +03:00
package model
2022-04-29 16:28:08 +03:00
import (
"strings"
2022-04-29 16:33:21 +03:00
"golang.org/x/exp/slices"
2022-04-29 16:28:08 +03:00
)
func (w *DfWorld) process() {
2022-04-29 15:21:27 +03:00
// set site in structure
for _, site := range w.Sites {
for _, structure := range site.Structures {
structure.SiteId = site.Id_
}
}
2022-04-29 16:28:08 +03:00
w.processEvents()
2022-04-29 15:21:27 +03:00
// check events texts
for _, e := range w.HistoricalEvents {
e.Details.Html(&Context{World: w})
}
}
2022-04-29 16:28:08 +03:00
func (w *DfWorld) processEvents() {
for _, e := range w.HistoricalEvents {
switch d := e.Details.(type) {
case *HistoricalEventHfDoesInteraction:
if strings.HasPrefix(d.Interaction, "DEITY_CURSE_WEREBEAST_") {
w.HistoricalFigures[d.TargetHfid].Werebeast = true
}
if strings.HasPrefix(d.Interaction, "DEITY_CURSE_VAMPIRE_") {
w.HistoricalFigures[d.TargetHfid].Vampire = true
}
case *HistoricalEventCreatedSite:
w.addEntitySite(d.CivId, d.SiteId)
w.addEntitySite(d.SiteCivId, d.SiteId)
case *HistoricalEventDestroyedSite:
w.addEntitySite(d.DefenderCivId, d.SiteId)
w.addEntitySite(d.SiteCivId, d.SiteId)
w.Sites[d.SiteId].Ruin = true
case *HistoricalEventSiteTakenOver:
w.addEntitySite(d.AttackerCivId, d.SiteId)
w.addEntitySite(d.SiteCivId, d.SiteId)
w.addEntitySite(d.DefenderCivId, d.SiteId)
w.addEntitySite(d.NewSiteCivId, d.SiteId)
case *HistoricalEventHfDestroyedSite:
w.addEntitySite(d.SiteCivId, d.SiteId)
w.addEntitySite(d.DefenderCivId, d.SiteId)
w.Sites[d.SiteId].Ruin = true
case *HistoricalEventReclaimSite:
w.addEntitySite(d.SiteCivId, d.SiteId)
w.addEntitySite(d.SiteCivId, d.SiteId)
w.Sites[d.SiteId].Ruin = false
}
}
}
func (w *DfWorld) addEntitySite(entityId, siteId int) {
if e, ok := w.Entities[entityId]; ok {
2022-04-29 16:33:21 +03:00
if !slices.Contains(e.Sites, siteId) {
e.Sites = append(e.Sites, siteId)
2022-04-29 16:28:08 +03:00
}
}
}