Пример #1
0
func startGameServer() {
	port, err := configuration.GetInt(config.CONFIG_SERVER_PORT)
	if err != nil {
		port = 9001
		log.Error("main", "startGameServer", "Failed to read server port from configuration, using default 9001")
	}
	server.Listen(port)
}
Пример #2
0
func loadPokemon(_hood *hood.Hood) {
	log.Verbose("Pokemon.Manager", "loadPokemon", "Loading pokemon from database")

	var pokemon []entities.Pokemon
	if err := _hood.Find(&pokemon); err != nil {
		log.Error("Pokemon.Manager", "loadPokemon", "Error while loading pokemon: %s", err.Error())
	} else {
		for _, pokemonEntity := range pokemon {
			poke := NewPokemon(&pokemonEntity)

			if err := poke.LinkMoves(_hood); err != nil {
				log.Error("Pokemon.Manager", "loadPokemon", "Failed to link moves to Pokemon %d. Error: %s", poke.GetPokemonId(), err.Error())
			} else {
				pokemonStore[poke.GetPokemonId()] = poke
			}
		}
	}
}
Пример #3
0
func loadMoves(_hood *hood.Hood) {
	log.Verbose("Pokemon.Manager", "loadMoves", "Loading pokemon moves from database")

	var moves []entities.Move
	if err := _hood.Find(&moves); err != nil {
		log.Error("Pokemon.Manager", "loadMoves", "Error while loading moves: %s", err.Error())
	} else {
		for _, moveEntity := range moves {
			move := NewMove(&moveEntity)
			movesStore[move.GetMoveId()] = move
		}
	}
}
Пример #4
0
func (p *PlayerPokemon) loadMoves(_hood *hood.Hood) {
	var pokemonMoves []entities.PlayerPokemonMove

	if err := _hood.Where("pokemon_id", "=", p.GetPlayerPokemonId()).Find(&pokemonMoves); err != nil {
		log.Error("PlayerPokemon", "loadMoves", "Failed to load PlayerPokemonMoves for PlayerPokemon: %d. Error: %s", p.GetPlayerPokemonId(), err.Error())
	} else {
		for _, move := range pokemonMoves {
			if playerPokemonMove := NewPlayerPokemonMove(&move); playerPokemonMove != nil {
				p.moves[playerPokemonMove.GetPlayerPokemonMoveId()] = playerPokemonMove
			}
		}
	}
}
Пример #5
0
func CreateDatabaseConnection() *hood.Hood {
	username, _ := configuration.GetString(config.CONFIG_DB_USER)
	password, _ := configuration.GetString(config.CONFIG_DB_PASSWORD)
	scheme, _ := configuration.GetString(config.CONFIG_DB_SCHEME)
	connectionString := fmt.Sprintf("%v/%v/%v", scheme, username, password)

	hd, err := hood.Open("mymysql", connectionString)
	if err != nil {
		log.Error("DatabaseHelper", "CreateDatabaseConnection", "Unable to connect to database scheme '%s' with supplied credentials '%s'.\nError: %s", scheme, username, err.Error())
		return nil
	}

	return hd
}
Пример #6
0
// Player data loading
func (p *Player) loadPlayerPokemon() bool {
	var result []*entities.PlayerPokemon
	if err := p.dbConn.Where("PlayerId", "=", p.GetPlayerId()).Find(result); err != nil {
		log.Error("Player", "laodPlayerPokemon", "Failed to load pokemon for player (%d). %s", p.GetPlayerId(), err.Error())
		return false
	}

	p.pokemon = make(map[int64]*PlayerPokemon)
	for _, playerPokemonEntity := range result {
		playerPokemon := NewPlayerPokemon(p.dbConn, playerPokemonEntity)
		p.pokemon[playerPokemon.GetPlayerPokemonId()] = playerPokemon
	}

	// TODO: Maybe add extra check if pokemonList size is zero. But only if we assign a pokemon to the player when creating a character

	return true
}
Пример #7
0
func loadMap(_hood *hood.Hood, _mapId int, _tilePointTable *TilePointTable) {
	// Create select query to get all tilepoints and layers as one result
	_hood.Select("tilepoint", "tilepoint.x", "tilepoint.y", "tilepointlayer.level", "tilepointlayer.blocking", "tilepointtilelayer.layer", "tilepointtilelayer.tileId")
	_hood.Join(hood.LeftJoin, "tilepointlayer", "tilepointlayer.tilePointId", "tilepoint.tilePointId")
	_hood.Join(hood.LeftJoin, "tilepointtilelayer", "tilepointtilelayer.tilePointLayerId", "tilepointlayer.tilePointLayerId")

	var tilePointRows []TilePointRow
	if err := _hood.Find(&tilePointRows); err != nil {
		log.Error("World", "loadMap", "Error fetching tilepoints from database:\n%s", err.Error())
	} else {
		for _, row := range tilePointRows {
			processTilePoints(row, _tilePointTable)
		}
	}

	processExitChan <- true
}
Пример #8
0
func initializeDatabase() {
	log.Verbose("main", "initializeDatabase", "Creating database connection")

	username, _ := configuration.GetString(config.CONFIG_DB_USER)
	password, _ := configuration.GetString(config.CONFIG_DB_PASSWORD)
	scheme, _ := configuration.GetString(config.CONFIG_DB_SCHEME)
	connectionString := fmt.Sprintf("%v/%v/%v", scheme, username, password)

	hd, err := hood.Open("mymysql", connectionString)
	if err != nil {
		log.Error("main", "initializeDatabase", "Unable to connect to database scheme '%s' with supplied credentials '%s'", scheme, username)
		panic("Unable to connect to database")
	}
	hd.Log = DEBUG_SQL

	mainDatabase = hd

	log.Info("main", "initializeDatabase", "Database connection initialized: %s", connectionString)
}
Пример #9
0
func (p *Pokemon) LinkMoves(_hood *hood.Hood) error {
	var pokemonMoves []entities.PokemonMove
	if err := _hood.Where("pokemon_id", "=", p.GetPokemonId()).Find(&pokemonMoves); err != nil {
		return err
	}

	if len(pokemonMoves) == 0 {
		return fmt.Errorf("No moves found for pokemon %d", p.GetPokemonId())
	}

	for _, pokeMove := range pokemonMoves {
		if move, found := GetMoveById(pokeMove.MoveId); found {
			p.moves[pokeMove.Level] = move
		} else {
			log.Error("Pokemon", "LinkMoves", "Move with id %d could not be found.", pokeMove.MoveId)
		}
	}

	return nil
}