mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-20 23:47:16 -05:00
* WIP refactor of d2map stuff * more d2map refactor adding realm init to game client passing map engine from client and server into realm at init change `generate map packet` to have act and level index as data * client explodes, but getting there * realm now initializes, networking works, but map generators dont currently do anything * changed the way that level type records are loaded * fixed funcs for level data lookups * started implementing level generator, currently crashing * client no longer exploding * d2networking refactor put exports into d2client.go and d2server.go kept GameClient and GameServer methods into their respective files made methods for packet handlers instead of the giant switch statements * bugfix: getting first level id by act * minor refactor of gamescreen for readability * towns now generate on server start, create player takes act and level id as args, levels have their own map engine
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package d2mapengine
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
|
// "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
)
|
|
|
|
type MapAct struct {
|
|
realm *MapRealm
|
|
id int
|
|
levels map[int]*MapLevel
|
|
}
|
|
|
|
func (act *MapAct) isActive() bool {
|
|
for _, level := range act.levels {
|
|
if level.isActive() {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (act *MapAct) Advance(elapsed float64) {
|
|
if !act.isActive() {
|
|
return
|
|
}
|
|
for _, level := range act.levels {
|
|
level.Advance(elapsed)
|
|
}
|
|
}
|
|
|
|
func (act *MapAct) Init(realm *MapRealm, actIndex int) {
|
|
act.realm = realm
|
|
act.levels = make(map[int]*MapLevel)
|
|
act.id = actIndex
|
|
|
|
actLevelRecords := d2datadict.GetLevelDetailsByActId(actIndex)
|
|
|
|
log.Printf("Initializing Act %d", actIndex)
|
|
for _, record := range actLevelRecords {
|
|
level := &MapLevel{}
|
|
levelId := record.Id
|
|
level.Init(act, levelId)
|
|
act.levels[levelId] = level
|
|
}
|
|
|
|
act.GenerateTown() // ensures that starting point is known for first player
|
|
}
|
|
|
|
func (act *MapAct) GenerateTown() {
|
|
townId := d2datadict.GetFirstLevelIdByActId(act.id)
|
|
act.levels[townId].GenerateMap()
|
|
}
|
|
|
|
func (act *MapAct) GenerateMap(levelId int) {
|
|
log.Printf("Generating map in Act %d", act.id)
|
|
act.levels[levelId].GenerateMap()
|
|
}
|