コード例 #1
0
ファイル: playerio.go プロジェクト: gasperko/pokemon-universe
func (p *Player) loadFriends() bool {
	var query string = "SELECT idplayer_friends, friend_name FROM player_friends WHERE idplayer=%d"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()

	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		dbid := puh.DBGetInt64(row[0])
		name := puh.DBGetString(row[1])

		_, online := g_game.GetPlayerByName(name)

		friend := &Friend{DbId: dbid,
			Name:   name,
			Online: online}
		p.Friends[name] = friend
	}

	return true
}
コード例 #2
0
ファイル: server.go プロジェクト: gasperko/pokemon-universe
func (s *Server) LoadPlayerProfile(_playerId int64) (ret bool, p *Player) {
	p = nil
	ret = false

	var queryString string = fmt.Sprintf("SELECT idplayer, name FROM player WHERE idplayer=%d", _playerId)
	result, err := puh.DBQuerySelect(queryString)
	if err != nil {
		return
	}

	row := result.FetchMap()
	if row == nil {
		puh.DBFree()
		return
	}
	idPlayer := puh.DBGetInt(row["idplayer"])
	name := puh.DBGetString(row["name"])
	puh.DBFree()

	value, found := g_game.GetPlayerByName(name)
	if found {
		p = value
		ret = true
	} else {
		p = NewPlayer(name)
		p.dbid = idPlayer
		ret = p.LoadData()
	}

	return
}
コード例 #3
0
ファイル: location.go プロジェクト: gasperko/pokemon-universe
func (store *LocationStore) Load() error {
	var query string = "SELECT t.idlocation, t.name, t.idmusic, p.position FROM location t LEFT JOIN pokecenter p ON p.idpokecenter = t.idpokecenter"
	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return err
	}

	defer puh.DBFree()
	for {
		row := result.FetchMap()
		if row == nil {
			break
		}

		idlocation := puh.DBGetInt(row["idlocation"])
		name := puh.DBGetString(row["name"])
		music := puh.DBGetInt(row["idmusic"])
		pokecenter := puh.DBGetInt64(row["position"]) // Hash
		pcposition := pos.NewPositionFromHash(pokecenter)

		location := &Location{ID: idlocation,
			Name:       name,
			Music:      music,
			PokeCenter: pcposition}
		store.addLocation(location)
	}

	return nil
}
コード例 #4
0
ファイル: npc.go プロジェクト: gasperko/pokemon-universe
func (n *Npc) Load(_data []interface{}) bool {
	id := puh.DBGetInt(_data[0])
	name := puh.DBGetString(_data[1])
	script_name := puh.DBGetString(_data[2])
	position := puh.DBGetInt64(_data[3])

	n.dbid = id
	n.name = name
	n.script_name = script_name

	tile, ok := g_map.GetTile(position)
	if !ok {
		logger.Printf("[Error] Could not load position info for npc %s (%d)\n", n.name, n.dbid)
		return false
	}
	n.Position = tile
	n.moveCenter = tile.GetPosition()

	return true
}
コード例 #5
0
ファイル: quest.go プロジェクト: gasperko/pokemon-universe
func (s *QuestStore) Load() bool {
	result, err := puh.DBQuerySelect("SELECT idquests, name, description FROM quests")
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		quest := &Quest{Dbid: puh.DBGetInt64(row[0]),
			Name:        puh.DBGetString(row[1]),
			Description: puh.DBGetString(row[2])}
		s.AddQuest(quest)
	}

	return true
}
コード例 #6
0
ファイル: playerio.go プロジェクト: gasperko/pokemon-universe
func (p *Player) loadPlayerInfo() bool {
	var query string = "SELECT p.idplayer, p.name, p.position, p.movement, p.idpokecenter, p.money, p.idlocation," +
		" g.group_idgroup, o.head, o.nek, o.upper, o.lower, o.feet FROM player `p`" +
		" INNER JOIN player_outfit `o` ON o.idplayer = p.idplayer" +
		" INNER JOIN player_group `g` ON g.player_idplayer = p.idplayer" +
		" WHERE p.idplayer=%d"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()
	row := result.FetchRow()
	if row == nil {
		logger.Printf("[Error] No player data for %s (DB ID: %d)\n", p.name, p.dbid)
		return false
	}

	p.dbid = puh.DBGetInt(row[0])
	p.name = puh.DBGetString(row[1])
	tile, ok := g_map.GetTile(puh.DBGetInt64(row[2]))
	if !ok {
		logger.Printf("[Warning] Could not load position info for player %s (%d)\n", p.name, p.dbid)
		//tile, _ = g_map.GetTileFrom(-510, -236, 0)
		tile, _ = g_map.GetTileFrom(38, 15, 1)
		if tile == nil {
			logger.Println("[Error] Could not load default position")
			return false
		}
	}
	p.Position = tile
	p.SetDirection(DIR_SOUTH)
	p.Movement = puh.DBGetInt(row[3])
	// TODO: p.LastPokeCenter = row[4].(int)
	p.Money = puh.DBGetInt(row[5])
	location, ok := g_game.Locations.GetLocation(puh.DBGetInt(row[6]))
	if !ok {
		logger.Printf("[Error] Could not load location info for player %s (%d)\n", p.name, p.dbid)
		return false
	}
	p.Location = location

	// Group/Right stuff : row[7].(int)

	p.SetOutfitKey(pul.OUTFIT_HEAD, puh.DBGetInt(row[8]))
	p.SetOutfitKey(pul.OUTFIT_NEK, puh.DBGetInt(row[9]))
	p.SetOutfitKey(pul.OUTFIT_UPPER, puh.DBGetInt(row[10]))
	p.SetOutfitKey(pul.OUTFIT_LOWER, puh.DBGetInt(row[11]))
	p.SetOutfitKey(pul.OUTFIT_FEET, puh.DBGetInt(row[12]))

	return true
}
コード例 #7
0
ファイル: playerio.go プロジェクト: gasperko/pokemon-universe
func (p *Player) loadPokemon() bool {
	var query string = "SELECT idpokemon, nickname, bound, experience, iv_hp, iv_attack, iv_attack_spec, iv_defence, iv_defence_spec," +
		" iv_speed, happiness, gender, in_party, party_slot, idplayer_pokemon, shiny, idability, damaged_hp FROM player_pokemon WHERE idplayer='%d' AND in_party=1"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		pokemon := pkmn.NewPlayerPokemon(p.dbid)
		pokemon.IdDb = puh.DBGetInt(row[14])
		pokemonId := puh.DBGetInt(row[0])
		pokemon.Base = pkmn.GetInstance().GetPokemon(pokemonId)
		pokemon.Nickname = puh.DBGetString(row[1])
		pokemon.IsBound = puh.DBGetInt(row[2])
		pokemon.Experience = float64(puh.DBGetUint64(row[3]))
		pokemon.Stats[pkmn.POKESTAT_HP] = puh.DBGetInt(row[4])             // HP
		pokemon.Stats[pkmn.POKESTAT_ATTACK] = puh.DBGetInt(row[5])         // Attack
		pokemon.Stats[pkmn.POKESTAT_DEFENSE] = puh.DBGetInt(row[7])        // Defence
		pokemon.Stats[pkmn.POKESTAT_SPECIALATTACK] = puh.DBGetInt(row[6])  // Spec Attack
		pokemon.Stats[pkmn.POKESTAT_SPECIALDEFENCE] = puh.DBGetInt(row[8]) // Spec Defence
		pokemon.Stats[pkmn.POKESTAT_SPEED] = puh.DBGetInt(row[9])          // Speed
		pokemon.Happiness = puh.DBGetInt(row[10])
		pokemon.Gender = puh.DBGetInt(row[11])
		pokemon.InParty = puh.DBGetInt(row[12])
		pokemon.Slot = puh.DBGetInt(row[13])
		pokemon.IsShiny = puh.DBGetInt(row[15])
		abilityId := puh.DBGetInt(row[16])
		pokemon.DamagedHp = puh.DBGetInt(row[17])

		pokemon.Ability = pkmn.GetInstance().GetAbilityById(abilityId)
		if pokemon.Ability == nil {
			logger.Printf("[Warning] Pokemon (%d) has an invalid abilityId (%d)\n", pokemon.IdDb, abilityId)
			pokemon.Ability = pkmn.GetInstance().GetAbilityById(96)
		}

		// Add to party if needed
		if pokemon.InParty == 1 {
			p.PokemonParty.AddSlot(pokemon, pokemon.Slot)
		}
	}

	return true
}
コード例 #8
0
ファイル: server.go プロジェクト: gasperko/pokemon-universe
func (s *Server) CheckAccountInfo(_username string, _password string) (bool, int64) {
	_username = puh.Escape(_username)
	_password = puh.Escape(_password)

	var queryString string = "SELECT idplayer, password, password_salt FROM player WHERE name='" + _username + "'"
	result, err := puh.DBQuerySelect(queryString)
	if err != nil {
		return false, 0
	}

	row := result.FetchMap()
	defer puh.DBFree()
	if row == nil {
		return false, 0
	}

	idplayer := puh.DBGetInt64(row["idplayer"])
	password := puh.DBGetString(row["password"])
	salt := puh.DBGetString(row["password_salt"])
	_password = _password + salt

	passCheck := s.PasswordTest(_password, password)
	return passCheck, idplayer
}
コード例 #9
0
ファイル: item.go プロジェクト: gasperko/pokemon-universe
func (s *ItemStore) Load() bool {
	var query string = "SELECT id, identifier, category_id, cost, fling_power, fling_effect_id FROM items"
	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		itemId := puh.DBGetInt64(row[0])
		identifier := puh.DBGetString(row[1])
		category := puh.DBGetInt(row[2])
		cost := puh.DBGetInt(row[3])
		flingPower := puh.DBGetInt(row[4])
		flingEffectId := puh.DBGetInt(row[5])

		item := &Item{Id: itemId,
			Identifier:    identifier,
			CategoryId:    category,
			Cost:          cost,
			FlingPower:    flingPower,
			FlingEffectId: flingEffectId,
			MaxStack:      0,
			CanBeSold:     true,
			CanBeTraded:   true}

		// Add item to store
		s.Items[itemId] = item
	}

	return true
}
コード例 #10
0
func (io *IOMapDB2) loadMapList(_map *Map) error {
	var query string = "SELECT idmap, name FROM map"

	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return err
	}
	defer puh.DBFree()

	logger.Printf(" - Processing map list")
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		idmap := puh.DBGetInt(row[0])
		name := puh.DBGetString(row[1])

		_map.AddMap(idmap, name)
	}

	return nil
}