Beispiel #1
0
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))
}
Beispiel #2
0
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
}
Beispiel #3
0
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)
	}
}
Beispiel #4
0
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
}
Beispiel #5
0
func init() {
	ai.behaviors = make(map[string]Behavior)
	utils.LoadSetting(&ai.behaviors, "data/behaviors.json")
	glog.Infof("%i", ai.behaviors)
}