Exemplo n.º 1
0
Arquivo: room.go Projeto: beoran/woe
// Load a room from a sitef file.
func LoadRoom(dirname string, id string) (room *Room, err error) {

	path := SavePathFor(dirname, "room", id)

	records, err := sitef.ParseFilename(path)
	if err != nil {
		return nil, err
	}

	if len(records) < 1 {
		return nil, errors.New("No room found!")
	}

	record := records[0]
	monolog.Info("Loading Room record: %s %v", path, record)

	room = new(Room)
	room.Entity.LoadSitef(*record)
	/*
	   account.Name            = record.Get("name")
	   account.Hash            = record.Get("hash")
	   account.Algo            = record.Get("algo")
	   account.Email           = record.Get("email")
	   account.Points          = record.GetIntDefault("points", 0)
	   account.Privilege       = Privilege(record.GetIntDefault("privilege",
	                               int(PRIVILEGE_NORMAL)))

	   var nchars int
	   nchars                  = record.GetIntDefault("characters", 0)
	   _ = nchars
	*/
	monolog.Info("Loaded Room: %s %v", path, room)
	return room, nil
}
Exemplo n.º 2
0
// Load an account from a sitef file.
func LoadAccount(dirname string, name string) (account *Account, err error) {

	path := SavePathFor(dirname, "account", name)

	records, err := sitef.ParseFilename(path)
	if err != nil {
		return nil, err
	}

	if len(records) < 1 {
		return nil, errors.New("No record found!")
	}

	record := records[0]
	monolog.Info("Loading Account record: %s %v", path, record)

	account = new(Account)
	account.Name = record.Get("name")
	account.Hash = record.Get("hash")
	account.Algo = record.Get("algo")
	account.Email = record.Get("email")
	account.Points = record.GetIntDefault("points", 0)
	account.Privilege = Privilege(record.GetIntDefault("privilege",
		int(PRIVILEGE_NORMAL)))

	nchars := record.GetIntDefault("characters", 0)
	account.characters = make([]*Character, 0, nchars)
	monolog.Info("Try to load %d characters:\n", nchars)
	for index := 0; index < nchars; index++ {

		chid := record.GetArrayIndex("characters", index)
		monolog.Info("Loading character: %d %s\n", index, chid)

		ch, err := account.LoadCharacter(dirname, chid)
		if err != nil {
			monolog.Error("Could not load character %s: %s", chid, err.Error())
			// return nil, err
		} else {
			account.characters = append(account.characters, ch)
		}
	}

	/* Todo: load characters here... */
	monolog.Info("Loaded Account: %s %v", path, account)
	return account, nil
}
Exemplo n.º 3
0
Arquivo: world.go Projeto: beoran/woe
// Load a world from a sitef file.
func LoadWorld(dirname string, name string) (world *World, err error) {

	path := SavePathFor(dirname, "world", name)

	records, err := sitef.ParseFilename(path)
	if err != nil {
		return nil, err
	}

	if len(records) < 1 {
		return nil, errors.New("No record found!")
	}

	record := records[0]
	monolog.Info("Loading World record: %s %v", path, record)

	world = NewWorld(record.Get("name"), record.Get("motd"), dirname)
	monolog.Info("Loaded World: %s %v", path, world)
	return world, nil
}
Exemplo n.º 4
0
// Load a character from a sitef file. Does no account checking, but returns the account name.
func LoadCharacter(dirname string, id string) (character *Character, aname string, err error) {

	path := SavePathFor(dirname, "character", id)

	records, err := sitef.ParseFilename(path)
	if err != nil {
		return nil, "", err
	}

	if len(records) < 1 {
		return nil, "", fmt.Errorf("No sitef record found for %s!", id)
	}

	record := records[0]
	monolog.Info("Loading Character record: %s %v", path, record)

	character = new(Character)
	aname = record.Get("accountname")
	character.Being.LoadSitef(*record)

	return character, aname, nil
}
Exemplo n.º 5
0
Arquivo: item.go Projeto: beoran/woe
// Load an item from a sitef file.
func LoadItem(dirname string, id string) (item *Item, err error) {

	path := SavePathFor(dirname, "item", id)

	records, err := sitef.ParseFilename(path)
	if err != nil {
		return nil, err
	}

	if len(records) < 1 {
		return nil, errors.New("No item found!")
	}

	record := records[0]
	monolog.Info("Loading Item record: %s %v", path, record)

	item = new(Item)
	item.Entity.LoadSitef(*record)
	item.Quality = record.GetIntDefault("quality", 0)
	item.Price = record.GetIntDefault("price", -1)
	item.Level = record.GetIntDefault("level", -1)
	item.Kind = ItemKind(record.Get("kind"))
	item.Damage = DamageKind(record.Get("damage"))
	item.Equip = EquipWhere(record.Get("equip"))
	item.Upgrade = record.Get("upgrade")
	item.Degrade = record.Get("degrade")
	item.Teaches = record.Get("teaches")
	item.Craft = record.Get("craft")

	ningredients := record.GetIntDefault("ingredients", 0)

	for i := 0; i < ningredients; i++ {
		ingr := record.GetArrayIndex("ingredients", i)
		item.Ingredients = append(item.Ingredients, ingr)
	}

	monolog.Info("Loaded Item: %s %v", path, item)
	return item, nil
}