コード例 #1
0
// TODO: Do something with the _FormId variable
func (m *PokemonManager) GetPokemonTypes(_pokemonId, _formId int) PokemonTypeArray {
	pokemon := m.GetPokemon(_pokemonId)
	if pokemon == nil {
		log.Error("PokemonManager", "GetPokemonTypes", "Could not find pokemon with id: %d", _pokemonId)
		return nil
	}
	return pokemon.Types
}
コード例 #2
0
func (m *PokemonManager) GetMoveById(_moveId int) *Move {
	move, found := m.moves[_moveId]

	if !found {
		log.Error("PokeManager", "GetMoveById", "Could not find move with id: %d", _moveId)
		return nil
	}

	return move
}
コード例 #3
0
func (p *NpcPokemon) Delete() bool {
	entity := models.NpcPokemon{IdnpcPokemon: int(p.DbId)}
	if _, err := g_orm.Delete(&entity); err != nil {
		log.Error("NpcPokemon", "Delete", "Failed to remove pokemon: %v", err.Error())
		return false
	}

	p.IsRemoved = true
	return true
}
コード例 #4
0
ファイル: map.go プロジェクト: gasperko/pokemon-universe
func (m *Map) DeleteMap(_id int) {
	mapEntity := models.Map{Idmap: _id}
	if _, err := g_orm.Delete(&mapEntity); err != nil {
		log.Error("Map", "DeleteMap", "Failed to remove map. Id: %d, Error: %s", _id, err.Error())
	} else {
		// Remove all tiles
		delete(m.tileMap, _id)

		// Remove map name
		delete(m.mapNames, _id)
	}
}
コード例 #5
0
ファイル: location.go プロジェクト: gasperko/pokemon-universe
func (l *LocationsList) LoadPokecenters() bool {
	var pokec []models.Pokecenter
	if err := g_orm.FindAll(&pokec); err != nil {
		log.Error("location", "LoadPokecenters", "Error while loading pokecenters: %v", err.Error())
		return false
	}

	for _, pokecenterEntity := range pokec {
		l.pokecenters[pokecenterEntity.Idpokecenter] = pokecenterEntity
	}
	return true
}
コード例 #6
0
ファイル: location.go プロジェクト: gasperko/pokemon-universe
func (l *LocationsList) LoadMusic() bool {
	var mus []models.Music
	if err := g_orm.FindAll(&mus); err != nil {
		log.Error("location", "LoadPokecenters", "Error while loading music: %v", err.Error())
		return false
	}

	for _, musicEntity := range mus {
		l.musics[musicEntity.Idmusic] = musicEntity
	}
	return true
}
コード例 #7
0
ファイル: client.go プロジェクト: gasperko/pokemon-universe
func (c *Client) ReceiveRemoveMap(_packet *Packet) {
	mapId := int(_packet.ReadUint16())

	mapEntity := models.Map{}
	mapEntity.Idmap = mapId
	_, err := g_orm.Delete(&mapEntity)
	if err != nil {
		log.Error("Client", "ReceiveRemoveMap", "Error removing map: %v", err.Error())
		return
	}
	g_map.DeleteMap(mapId)
	g_server.SendMapListUpdateToClients()
}
コード例 #8
0
ファイル: client.go プロジェクト: gasperko/pokemon-universe
func (c *Client) ReceiveAddMap(_packet *Packet) {
	mapName := _packet.ReadString()
	if len(mapName) > 0 {
		mapEntity := models.Map{Idmap: 0,
			Name: mapName}
		err := g_orm.Save(&mapEntity)
		if err != nil {
			log.Error("Client", "ReceiveAddMap", "Error adding map: %v", err.Error())
			return
		}
		g_map.AddMap(mapEntity.Idmap, mapName)
		g_server.SendMapListUpdateToClients()
	}
}
コード例 #9
0
ファイル: pokemon.go プロジェクト: gasperko/pokemon-universe
func (p *Pokemon) loadStats() bool {
	var base_stats []models.PokemonStats
	err := G_orm.Where(fmt.Sprintf("%v = %d", models.PokemonStats_PokemonId, p.PokemonId)).FindAll(&base_stats)
	if err != nil {
		log.Error("Pokemon", "loadStats", "Failed to load stats. Error: %v", err.Error())
		return false
	}

	for _, row := range base_stats {
		stat := NewPokemonStatFromEntity(row)
		p.Stats[stat.StatType-1] = stat
	}

	return true
}
コード例 #10
0
ファイル: pokemon.go プロジェクト: gasperko/pokemon-universe
func (p *Pokemon) loadTypes() bool {
	var types []models.PokemonTypes
	err := G_orm.Where(fmt.Sprintf("%v = %d", models.PokemonTypes_PokemonId, p.PokemonId)).OrderBy(models.PokemonTypes_Slot).FindAll(&types)
	if err != nil {
		log.Error("Pokemon", "loadTypes", "Failed to load pokemon types. Error: %v", err.Error())
		return false
	}

	for _, row := range types {
		slot := row.Slot
		p.Types[slot-1] = row.TypeId
	}

	return true
}
コード例 #11
0
ファイル: warp.go プロジェクト: gasperko/pokemon-universe
func (e *Warp) Delete() bool {
	//	query := fmt.Sprintf(QUERY_DELETE_EVENT, e.dbid)
	//	if err := puh.DBQuery(query); err != nil {
	//		return false
	//	}

	entity := models.TileEvents{IdtileEvents: int(e.dbid)}
	if _, err := g_orm.Delete(&entity); err != nil {
		log.Error("Warp", "Save", "Error deleting: %s", err.Error())
		return false
	}

	e.IsRemoved = true
	return true
}
コード例 #12
0
ファイル: pokemon.go プロジェクト: gasperko/pokemon-universe
func (p *Pokemon) loadForms() bool {
	var forms []models.PokemonForms
	err := G_orm.Where(fmt.Sprintf("%v = %d", models.PokemonForms_PokemonId, p.PokemonId)).FindAll(&forms)
	if err != nil {
		log.Error("Pokemon", "loadForms", "Failed to load forms. Error: %v", err.Error())
		return false
	}

	for _, row := range forms {
		form := NewPokemonFormFromEntity(row)
		p.Forms.PushBack(form)
	}

	return true
}
コード例 #13
0
func (m *PokemonManager) loadMoves() bool {
	var moves []models.MovesJoinMoveFlavorText
	err := G_orm.SetTable("moves").Join("LEFT", "move_flavor_text", fmt.Sprintf("%v = %v", models.MoveFlavorText_IdMove, models.Moves_Id)).FindAll(&moves)
	if err != nil {
		log.Error("PokeManager", "loadMoves", "Failed to load moves. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadMoves", "Processing moves")
	for _, row := range moves {
		move := NewMoveFromEntity(row)
		m.moves[move.MoveId] = move
	}

	return true
}
コード例 #14
0
ファイル: location.go プロジェクト: gasperko/pokemon-universe
func (l *LocationsList) LoadLocations() bool {
	if !l.LoadPokecenters() || !l.LoadMusic() {
		return false
	}

	var locats []models.Location
	if err := g_orm.FindAll(&locats); err != nil {
		log.Error("location", "LoadLocations", "Error while loading locations: %v", err.Error())
		return false
	}

	for _, locationEntity := range locats {
		l.locations[locationEntity.Idlocation] = locationEntity
	}
	return true
}
コード例 #15
0
func (m *PokemonManager) loadPokemonSpecies() bool {
	var pokes []models.PokemonSpeciesJoinPokemonEvolution
	err := G_orm.SetTable("pokemon_species").Join("LEFT", "pokemon_evolution", "pokemon_evolution.evolved_species_id = (SELECT `ps2`.id FROM pokemon_species AS `ps2` WHERE `ps2`.evolves_from_species_id = pokemon_species.id LIMIT 1)").FindAll(&pokes)
	if err != nil {
		log.Error("PokeManager", "loadPokemonSpecies", "Failed to load pokemon species. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadPokemonSpecies", "Processing pokemon species")
	for _, row := range pokes {
		pokemon := NewPokemonSpecesFromEntity(row)
		m.pokemonSpecies[pokemon.SpeciesId] = pokemon
	}

	return true
}
コード例 #16
0
func (m *PokemonManager) loadAbilities() bool {
	var abilities []models.Abilities
	err := G_orm.FindAll(&abilities)
	if err != nil {
		log.Error("PokeManager", "loadAbilities", "Failed to load abilities. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadAbilities", "Processing abiliites")
	for _, row := range abilities {
		ability := NewAbilityFromEntity(row)
		m.abilities[ability.AbilityId] = ability
	}

	return true
}
コード例 #17
0
func (p *PlayerPokemon) LoadMoves() {
	pokemonEntities := []models.PlayerPokemonMove{}
	err := G_orm.FindAll(&pokemonEntities)
	if err != nil {
		log.Error("PlayerPokemon", "LoadMoves", "Error loading pokemon moves. IdplayerPokemon: %d, Error: %s", p.IdDb, err.Error())
	} else {
		index := 0
		for _, entity := range pokemonEntities {
			p.Moves[index] = NewPlayerPokemonMove(entity.IdplayerPokemonMove, entity.Idmove, entity.PpUsed)
			index++
		}

		if index == 0 {
			log.Warning("PlayerPokemon", "LoadMoves", "Pokemon has zero moves. IdPlayerPokemon: %d", p.IdDb)
		}
	}
}
コード例 #18
0
ファイル: main.go プロジェクト: gasperko/pokemon-universe
func initDatabase() bool {
	// Fetch database info from conf file
	username, _ := g_config.GetString("database", "user")
	password, _ := g_config.GetString("database", "pass")
	scheme, _ := g_config.GetString("database", "db")

	// Connect
	db, err := sql.Open("mymysql", fmt.Sprintf("%v/%v/%v", scheme, username, password))
	if err != nil {
		log.Error("main", "setupDatabase", "Error when opening sql connection: %v", err.Error())
	} else {
		g_orm = beedb.New(db)
		beedb.OnDebug, _ = g_config.GetBool("database", "debug_mode")
	}

	return (err == nil)
}
コード例 #19
0
ファイル: pokemon.go プロジェクト: gasperko/pokemon-universe
func (p *Pokemon) loadAbilities() bool {
	var abilities []models.PokemonAbilities
	err := G_orm.Where(fmt.Sprintf("%v = %d", models.PokemonAbilities_PokemonId, p.PokemonId)).FindAll(&abilities)
	if err != nil {
		log.Error("Pokemon", "loadAbilities", "Failed to load stats. Error: %v", err.Error())
		return false
	}

	for _, row := range abilities {
		ability := NewPokemonAbilityFromEntity(row)

		if ability.Ability != nil {
			p.Abilities[ability.Ability.AbilityId] = ability
		}
	}

	return true
}
コード例 #20
0
func (m *PokemonManager) loadPokemon() bool {
	var pokes []models.Pokemon
	err := G_orm.FindAll(&pokes)
	if err != nil {
		log.Error("PokeManager", "loadPokemon", "Failed to load pokemon. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadPokemon", "Processing pokemon")
	for _, row := range pokes {
		pokemon := NewPokemonFromEntity(row)

		// Add to map
		m.pokemon[pokemon.PokemonId] = pokemon
	}

	return true
}
コード例 #21
0
ファイル: pokemon.go プロジェクト: gasperko/pokemon-universe
func (p *Pokemon) loadMoves() bool {
	var moves []models.PokemonMoves
	err := G_orm.Where(fmt.Sprintf("%v = %d AND version_group_id=11", models.PokemonMoves_PokemonId, p.PokemonId)).FindAll(&moves)
	if err != nil {
		log.Error("Pokemon", "loadMoves", "Failed to load pokemon moves. Error: %v", err.Error())
		return false
	}

	for _, row := range moves {
		pmove := NewPokemonMoveFromEntity(p, row)

		if pmove.Move != nil {
			p.Moves[pmove.Move.MoveId] = pmove
		}
	}

	return true
}
コード例 #22
0
func (m *PokemonManager) loadAbilityMessages() bool {
	var ability_messages []models.AbilityMessages
	err := G_orm.FindAll(&ability_messages)
	if err != nil {
		log.Error("PokeManager", "loadAbilityMessages", "Failed to load ability messages. Error: %v", err.Error())
		return false
	}

	log.Verbose("PokeManager", "loadAbilityMessagess", "Processing ability messages")
	for _, row := range ability_messages {
		messages := strings.Split(row.Message, "|")
		messageMap := make(map[int]string)
		for index, msg := range messages {
			messageMap[index] = msg
		}

		m.abilityMessages[row.AbilityId] = messageMap
	}

	return true
}
コード例 #23
0
ファイル: map.go プロジェクト: gasperko/pokemon-universe
func (m *Map) LoadTiles() bool {
	start := time.Now().UnixNano()
	var allTiles []TileRow

	//Init the tile id to 1
	g_newTileId = 1

	err := g_orm.SetTable("tile").Join("INNER", "tile_layer", "tile_layer.tileid = tile.idtile").Join(" LEFT", "tile_events", "tile_events.idtile_events = tile.idtile_event").OrderBy("tile.idtile DESC").FindAll(&allTiles)
	if err != nil {
		log.Error("map", "loadTiles", "Error while loading tiles: %v", err.Error())
		return false
	}

	log.Info("Map", "loadTiles", "%d tiles fetched in %dms", len(allTiles), (time.Now().UnixNano()-start)/1e6)

	if len(allTiles) > 0 {
		log.Verbose("Map", "loadTiles", "Processing tiles with %d goroutines", m.numOfProcessRoutines)

		// Start process goroutine
		for i := 1; i <= m.numOfProcessRoutines; i++ {
			go m.processTiles()
		}

		// Send rows to channel
		for key, row := range allTiles {
			//First tile has highest ID
			if key == 0 {
				g_newTileId = (row.Idtile + 1)
				log.Verbose("Map", "loadTiles", "Determined next tile ID: %d", g_newTileId)
			}

			m.processChan <- row
		}

		// Close channel so the process goroutine(s) will shutdown
		close(m.processChan)
	}
	return true
}
コード例 #24
0
ファイル: warp.go プロジェクト: gasperko/pokemon-universe
func (e *Warp) Save() bool {
	//	var query string
	//	if e.IsNew { // Update
	//		query = fmt.Sprintf(QUERY_INSERT_EVENT, e.GetEventType(), e.destination.X, e.destination.Y, e.destination.Z, "", "", "", "", "")
	//	} else if e.IsModified { // Insert
	//		query = fmt.Sprintf(QUERY_UPDATE_EVENT, e.GetEventType(), e.destination.X, e.destination.Y, e.destination.Z, "", "", "", "", "", e.dbid)
	//	}
	//
	//	if len(query) > 0 {
	//		if err := puh.DBQuery(query); err != nil {
	//			return false
	//		}
	//
	//		if e.IsNew {
	//			e.dbid = int64(puh.DBGetLastInsertId())
	//		}
	//	}

	entity := models.TileEvents{IdtileEvents: int(e.dbid),
		Eventtype: e.GetEventType(),
		Param1:    fmt.Sprintf("%d", e.destination.X),
		Param2:    fmt.Sprintf("%d", e.destination.Y),
		Param3:    fmt.Sprintf("%d", e.destination.Z)}
	if err := g_orm.Save(&entity); err != nil {
		log.Error("Warp", "Save", "Error saving: %s", err.Error())
		return false
	}

	if e.IsNew {
		e.dbid = int64(entity.IdtileEvents)
	}

	e.IsNew = false
	e.IsModified = false

	return true
}