2022-04-29 15:21:27 +03:00
|
|
|
package model
|
|
|
|
|
2022-04-29 16:28:08 +03:00
|
|
|
import (
|
2022-05-05 17:55:57 +03:00
|
|
|
"sort"
|
2022-04-29 16:28:08 +03:00
|
|
|
"strings"
|
2022-04-29 16:33:21 +03:00
|
|
|
|
2022-05-03 15:59:47 +03:00
|
|
|
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
|
2022-05-06 14:11:12 +03:00
|
|
|
"golang.org/x/exp/maps"
|
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-05-07 22:17:05 +03:00
|
|
|
for id, r := range w.Rivers {
|
|
|
|
r.Id_ = id
|
|
|
|
}
|
|
|
|
|
2022-05-04 10:26:26 +03:00
|
|
|
w.addRelationshipEvents()
|
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-05-03 15:59:47 +03:00
|
|
|
w.processCollections()
|
2022-05-05 17:55:57 +03:00
|
|
|
w.processHistoricalFigures()
|
|
|
|
|
|
|
|
for _, e := range w.Entities {
|
2022-05-06 14:11:12 +03:00
|
|
|
if len(e.Sites) > 0 {
|
|
|
|
if site, ok := w.Sites[e.Sites[0]]; ok {
|
|
|
|
if site.Type_ == SiteType_Tower {
|
|
|
|
e.Necromancer = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-06 16:16:16 +03:00
|
|
|
for _, l := range e.EntityLink {
|
|
|
|
if l.Type_ == EntityEntityLinkType_PARENT {
|
|
|
|
e.Parent = l.Target
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 17:55:57 +03:00
|
|
|
idx := slices.Index(e.Child, e.Id_)
|
|
|
|
if idx != -1 {
|
|
|
|
e.Child = append(e.Child[:idx], e.Child[idx+1:]...)
|
|
|
|
}
|
|
|
|
sort.Slice(e.Wars, func(i, j int) bool { return e.Wars[i].Id_ < e.Wars[j].Id_ })
|
|
|
|
}
|
2022-04-29 16:28:08 +03:00
|
|
|
|
2022-04-29 15:21:27 +03:00
|
|
|
// check events texts
|
2022-05-07 18:08:42 +03:00
|
|
|
// for _, e := range w.HistoricalEvents {
|
|
|
|
// e.Details.Html(&Context{World: w})
|
|
|
|
// }
|
|
|
|
|
2022-04-29 15:21:27 +03:00
|
|
|
}
|
2022-04-29 16:28:08 +03:00
|
|
|
|
|
|
|
func (w *DfWorld) processEvents() {
|
2022-05-06 14:11:12 +03:00
|
|
|
list := maps.Values(w.HistoricalEvents)
|
|
|
|
sort.Slice(list, func(i, j int) bool { return list[i].Id_ < list[j].Id_ })
|
|
|
|
|
|
|
|
for _, e := range list {
|
2022-04-29 16:28:08 +03:00
|
|
|
switch d := e.Details.(type) {
|
|
|
|
case *HistoricalEventHfDoesInteraction:
|
|
|
|
if strings.HasPrefix(d.Interaction, "DEITY_CURSE_WEREBEAST_") {
|
|
|
|
w.HistoricalFigures[d.TargetHfid].Werebeast = true
|
2022-05-05 17:55:57 +03:00
|
|
|
w.HistoricalFigures[d.TargetHfid].WerebeastSince = e.Year
|
2022-04-29 16:28:08 +03:00
|
|
|
}
|
|
|
|
if strings.HasPrefix(d.Interaction, "DEITY_CURSE_VAMPIRE_") {
|
|
|
|
w.HistoricalFigures[d.TargetHfid].Vampire = true
|
2022-05-05 17:55:57 +03:00
|
|
|
w.HistoricalFigures[d.TargetHfid].VampireSince = e.Year
|
|
|
|
}
|
|
|
|
case *HistoricalEventHfLearnsSecret:
|
|
|
|
if strings.HasPrefix(d.Interaction, "SECRET_") {
|
|
|
|
w.HistoricalFigures[d.StudentHfid].Necromancer = true
|
|
|
|
w.HistoricalFigures[d.StudentHfid].NecromancerSince = e.Year
|
2022-04-29 16:28:08 +03:00
|
|
|
}
|
|
|
|
case *HistoricalEventCreatedSite:
|
|
|
|
w.addEntitySite(d.CivId, d.SiteId)
|
|
|
|
w.addEntitySite(d.SiteCivId, d.SiteId)
|
2022-05-05 13:55:33 +03:00
|
|
|
w.Sites[d.SiteId].Ruin = false
|
2022-05-07 19:11:24 +03:00
|
|
|
w.Sites[d.SiteId].Owner = d.CivId
|
2022-04-29 16:28:08 +03:00
|
|
|
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)
|
2022-05-05 13:55:33 +03:00
|
|
|
w.Sites[d.SiteId].Ruin = false
|
2022-05-07 19:11:24 +03:00
|
|
|
w.Sites[d.SiteId].Owner = d.AttackerCivId
|
2022-04-29 16:28:08 +03:00
|
|
|
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
|
2022-05-07 19:11:24 +03:00
|
|
|
w.Sites[d.SiteId].Owner = d.CivId
|
2022-05-04 12:42:02 +03:00
|
|
|
case *HistoricalEventAddHfEntityLink:
|
|
|
|
if d.Link == HistoricalEventAddHfEntityLinkLink_Position {
|
|
|
|
if hf, ok := w.HistoricalFigures[d.Hfid]; ok {
|
|
|
|
for _, l := range hf.EntityPositionLink {
|
|
|
|
if l.EntityId == d.CivId && l.StartYear == e.Year {
|
|
|
|
l.PositionProfileId = d.PositionId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, l := range hf.EntityFormerPositionLink {
|
|
|
|
if l.EntityId == d.CivId && l.StartYear == e.Year {
|
|
|
|
l.PositionProfileId = d.PositionId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-04 20:31:15 +03:00
|
|
|
case *HistoricalEventHfReachSummit:
|
|
|
|
id, _, _ := util.FindInMap(w.MountainPeaks, func(m *MountainPeak) bool { return m.Coords == d.Coords })
|
|
|
|
d.MountainPeakId = id
|
2022-05-05 13:55:33 +03:00
|
|
|
case *HistoricalEventCreatedWorldConstruction:
|
|
|
|
if master, ok := w.WorldConstructions[d.MasterWcid]; ok {
|
|
|
|
master.Parts = append(master.Parts, d.Wcid)
|
|
|
|
}
|
|
|
|
case *HistoricalEventBuildingProfileAcquired:
|
|
|
|
if site, ok := w.Sites[d.SiteId]; ok {
|
|
|
|
if property, ok := site.SiteProperties[d.BuildingProfileId]; ok {
|
|
|
|
if structure, ok := site.Structures[property.StructureId]; ok {
|
|
|
|
structure.Ruin = false
|
|
|
|
}
|
|
|
|
d.StructureId = property.StructureId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case *HistoricalEventRazedStructure:
|
|
|
|
if site, ok := w.Sites[d.SiteId]; ok {
|
|
|
|
if structure, ok := site.Structures[d.StructureId]; ok {
|
|
|
|
structure.Ruin = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case *HistoricalEventReplacedStructure:
|
|
|
|
if site, ok := w.Sites[d.SiteId]; ok {
|
|
|
|
if structure, ok := site.Structures[d.OldAbId]; ok {
|
|
|
|
structure.Ruin = true
|
|
|
|
}
|
|
|
|
}
|
2022-05-07 22:17:05 +03:00
|
|
|
case *HistoricalEventAssumeIdentity:
|
|
|
|
if hf, ok := w.HistoricalFigures[d.TricksterHfid]; ok {
|
|
|
|
if id, ok := w.Identities[d.IdentityId]; ok {
|
|
|
|
id.HistfigId = hf.Id_
|
|
|
|
}
|
|
|
|
}
|
2022-05-07 23:19:30 +03:00
|
|
|
case *HistoricalEventHfDied:
|
|
|
|
if hf, ok := w.HistoricalFigures[d.SlayerHfid]; ok {
|
|
|
|
hf.Kills = append(hf.Kills, d.Hfid)
|
|
|
|
}
|
2022-04-29 16:28:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 15:59:47 +03:00
|
|
|
func (w *DfWorld) processCollections() {
|
2022-05-06 14:11:12 +03:00
|
|
|
list := maps.Values(w.HistoricalEventCollections)
|
|
|
|
sort.Slice(list, func(i, j int) bool { return list[i].Id_ < list[j].Id_ })
|
|
|
|
|
|
|
|
for _, col := range list {
|
2022-05-03 15:59:47 +03:00
|
|
|
for _, eventId := range col.Event {
|
|
|
|
if e, ok := w.HistoricalEvents[eventId]; ok {
|
|
|
|
e.Collection = col.Id_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch cd := col.Details.(type) {
|
|
|
|
case *HistoricalEventCollectionAbduction:
|
|
|
|
targets := make(map[int]bool)
|
|
|
|
for _, eventId := range col.Event {
|
|
|
|
if e, ok := w.HistoricalEvents[eventId]; ok {
|
|
|
|
switch d := e.Details.(type) {
|
|
|
|
case *HistoricalEventHfAbducted:
|
|
|
|
targets[d.TargetHfid] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete(targets, -1)
|
|
|
|
cd.TargetHfids = util.Keys(targets)
|
|
|
|
case *HistoricalEventCollectionBeastAttack:
|
|
|
|
attackers := make(map[int]bool)
|
|
|
|
for _, eventId := range col.Event {
|
|
|
|
if e, ok := w.HistoricalEvents[eventId]; ok {
|
|
|
|
switch d := e.Details.(type) {
|
|
|
|
case *HistoricalEventHfSimpleBattleEvent:
|
|
|
|
attackers[d.Group1Hfid] = true
|
|
|
|
case *HistoricalEventHfAttackedSite:
|
|
|
|
attackers[d.AttackerHfid] = true
|
|
|
|
case *HistoricalEventHfDestroyedSite:
|
|
|
|
attackers[d.AttackerHfid] = true
|
|
|
|
case *HistoricalEventAddHfEntityLink:
|
|
|
|
attackers[d.Hfid] = true
|
|
|
|
case *HistoricalEventCreatureDevoured:
|
|
|
|
attackers[d.Eater] = true
|
|
|
|
case *HistoricalEventItemStolen:
|
|
|
|
attackers[d.Histfig] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete(attackers, -1)
|
|
|
|
cd.AttackerHfIds = util.Keys(attackers)
|
|
|
|
case *HistoricalEventCollectionJourney:
|
|
|
|
HistoricalEventCollectionJourneyLoop:
|
|
|
|
for _, eventId := range col.Event {
|
|
|
|
if e, ok := w.HistoricalEvents[eventId]; ok {
|
|
|
|
switch d := e.Details.(type) {
|
|
|
|
case *HistoricalEventHfTravel:
|
|
|
|
cd.TravellerHfIds = d.GroupHfid
|
|
|
|
break HistoricalEventCollectionJourneyLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case *HistoricalEventCollectionOccasion:
|
|
|
|
for _, eventcolId := range col.Eventcol {
|
|
|
|
if e, ok := w.HistoricalEventCollections[eventcolId]; ok {
|
|
|
|
switch d := e.Details.(type) {
|
|
|
|
case *HistoricalEventCollectionCeremony:
|
|
|
|
d.OccasionEventcol = col.Id_
|
|
|
|
case *HistoricalEventCollectionCompetition:
|
|
|
|
d.OccasionEventcol = col.Id_
|
|
|
|
case *HistoricalEventCollectionPerformance:
|
|
|
|
d.OccasionEventcol = col.Id_
|
|
|
|
case *HistoricalEventCollectionProcession:
|
|
|
|
d.OccasionEventcol = col.Id_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-05 17:55:57 +03:00
|
|
|
case *HistoricalEventCollectionWar:
|
|
|
|
if e, ok := w.Entities[cd.AggressorEntId]; ok {
|
|
|
|
e.Wars = append(e.Wars, col)
|
|
|
|
}
|
|
|
|
if e, ok := w.Entities[cd.DefenderEntId]; ok {
|
|
|
|
e.Wars = append(e.Wars, col)
|
|
|
|
}
|
2022-05-03 15:59:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 16:28:08 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-04 10:26:26 +03:00
|
|
|
|
|
|
|
func (w *DfWorld) addRelationshipEvents() {
|
|
|
|
for _, r := range w.HistoricalEventRelationships {
|
|
|
|
w.HistoricalEvents[r.Event] = &HistoricalEvent{
|
2022-05-04 20:31:15 +03:00
|
|
|
Id_: r.Event,
|
|
|
|
Year: r.Year,
|
|
|
|
Collection: -1,
|
|
|
|
Seconds72: -1,
|
2022-05-04 10:26:26 +03:00
|
|
|
Details: &HistoricalEventAddHfHfLink{
|
|
|
|
Hfid: r.SourceHf,
|
|
|
|
HfidTarget: r.TargetHf,
|
|
|
|
Relationship: r.Relationship,
|
2022-05-04 20:31:15 +03:00
|
|
|
LinkType: HistoricalEventAddHfHfLinkLinkType_Unknown,
|
2022-05-04 10:26:26 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-05 17:55:57 +03:00
|
|
|
|
|
|
|
func (w *DfWorld) processHistoricalFigures() {
|
|
|
|
// for _, hf := range w.HistoricalFigures {
|
|
|
|
// for _, i := range hf.ActiveInteraction {
|
|
|
|
// if strings.HasPrefix(i, "DEITY_CURSE_WEREBEAST_") {
|
|
|
|
// hf.Werebeast = true
|
|
|
|
// }
|
|
|
|
// if strings.HasPrefix(i, "DEITY_CURSE_VAMPIRE_") {
|
|
|
|
// hf.Vampire = true
|
|
|
|
// }
|
|
|
|
// if strings.HasPrefix(i, "SECRET_") {
|
|
|
|
// hf.Necromancer = true
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|