mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-14 12:00:05 +00:00
33 lines
673 B
Go
33 lines
673 B
Go
|
package shard
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"log"
|
||
|
"os"
|
||
|
|
||
|
"github.com/CPunch/gopenfusion/config"
|
||
|
"github.com/CPunch/gopenfusion/core/entity"
|
||
|
)
|
||
|
|
||
|
type NPCData struct {
|
||
|
NPCs map[string]entity.NPC `json:"NPCs"`
|
||
|
}
|
||
|
|
||
|
func (server *ShardServer) LoadNPCs() {
|
||
|
log.Print("Loading NPCs...")
|
||
|
|
||
|
data, err := os.ReadFile(config.GetTDataPath() + "/NPCs.json")
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
// yes, we have to do it this way so our NPCs IDs will be incremented and unique
|
||
|
var NPCs NPCData
|
||
|
json.Unmarshal(data, &NPCs)
|
||
|
for _, npc := range NPCs.NPCs {
|
||
|
server.addEntity(entity.NewNPC(npc.X, npc.Y, npc.Z, npc.Angle, npc.NPCType))
|
||
|
}
|
||
|
|
||
|
log.Printf("Loaded %d NPCs!", len(NPCs.NPCs))
|
||
|
}
|