func init() { err := utils.LoadSetting(&defaultAttributes, "data/defaultAttributes.json") if err != nil { glog.Error("Can't load default attributes. Reason:", err.Error()) panic(err.Error()) } glog.Infof("Loaded default attributes: %i\n Total: %d", defaultAttributes, len(defaultAttributes)) err = utils.LoadSetting(&defaultStats, "data/defaultStats.json") if err != nil { glog.Error("Can't load default stats. Reason:", err.Error()) panic(err.Error()) } glog.Infof("Loaded default stats: %i\n Total: %d", defaultStats, len(defaultStats)) }
func GetNpcs() (npcs []*Npc) { var data []NpcInfo err := utils.LoadSetting(&data, "data/npc.json") if err != nil { panic(err.Error()) } for _, npcType := range data { for _, location := range npcType.Locations { for locName, count := range location { counter := 0 npcClass := npcType.Class npcBehavior := npcType.Behavior for i := 0; i < count; i++ { counter++ npc := &Npc{ Character{ Name: fmt.Sprintf("%s#%d", strings.ToTitle(npcBehavior), counter), Class: npcClass, CurrentLocation: locName, OwnerUid: fmt.Sprintf("%s#%d", strings.ToTitle(npcBehavior), counter), }, ai.Behavior(npcBehavior), } npc.SetDefaults() npcs = append(npcs, npc) } } } } return }
func (this *Game) LoadAssets() { err := utils.LoadSetting(&this.Items, "data/items.json") if err != nil { panic(err.Error()) } npcs := models.GetNpcs() for _, npc := range npcs { this.LoginCharacter(npc) } }
func NewWorld() *World { world := &World{Name: NewName("World", "World").String()} world.Locations = make(map[string]*Location) world.Tickers = make(map[string]*time.Ticker) err := utils.LoadSetting(&world.Locations, "data/locations.json") if err != nil { panic(err.Error()) } for _, loc := range world.Locations { loc.Creatures = make(map[string]*Creature) world.Tickers[loc.Key] = time.NewTicker(time.Millisecond) go world.Encapsulate(loc.Key, world.Tickers[loc.Key]) } return world }
func init() { ai.behaviors = make(map[string]Behavior) utils.LoadSetting(&ai.behaviors, "data/behaviors.json") glog.Infof("%i", ai.behaviors) }