Beispiel #1
0
func (p *Player) loadBackpack() bool {
	var query string = "SELECT idplayer_backpack, iditem, count, slot FROM player_backpack 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])
		itemId := puh.DBGetInt64(row[1])
		count := puh.DBGetInt(row[2])
		slot := puh.DBGetInt(row[3])

		item, _ := g_game.Items.GetItemByItemId(itemId)
		newItem := item.Clone()
		newItem.DbId = dbid
		newItem.SetCount(count)

		p.Backpack.AddItemObject(newItem, slot)
	}

	return true
}
Beispiel #2
0
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
}
Beispiel #3
0
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
}
Beispiel #4
0
func (p *Player) loadQuestsProgress() bool {
	var query string = "SELECT idplayer_quests, idquest, status, created, finished FROM player_quests 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])
		questid := puh.DBGetInt64(row[1])
		status := puh.DBGetInt(row[2])
		created := puh.DBGetInt64(row[3])  // Unix seconds
		finished := puh.DBGetInt64(row[4]) // Unix seconds

		if playerQuest := NewPlayerQuestExt(dbid, questid, status, created, finished); playerQuest != nil {
			playerQuest.IsNew = false
			p.Quests[questid] = playerQuest
		}
	}

	return true
}
Beispiel #5
0
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
}
Beispiel #6
0
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
}
Beispiel #7
0
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
}
Beispiel #8
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
}
Beispiel #9
0
func (io *IOMapDB2) processRows(_map *Map) {
	for {
		row := <-io.rowChan
		if row == nil {
			break
		}
		x := puh.DBGetInt(row[0])
		y := puh.DBGetInt(row[1])
		z := puh.DBGetInt(row[2])
		position := pos.NewPositionFrom(x, y, z)
		layer := puh.DBGetInt(row[7])
		sprite := puh.DBGetInt(row[6])
		blocking := puh.DBGetInt(row[4])
		// row `idteleport` may be null sometimes.
		var tp_id = 0
		if row[5] != nil {
			tp_id = puh.DBGetInt(row[5])
		}
		idlocation := puh.DBGetInt(row[3])

		tile, found := _map.GetTileFromPosition(position)
		if found == false {
			tile = NewTile(position)
			tile.Blocking = blocking

			// Get location
			location, found := g_game.Locations.GetLocation(idlocation)
			if found {
				tile.Location = location
			}

			// Teleport event
			if tp_id > 0 {
				tp_x := puh.DBGetInt(row[8])
				tp_y := puh.DBGetInt(row[9])
				tp_z := puh.DBGetInt(row[10])
				tp_pos := pos.NewPositionFrom(tp_x, tp_y, tp_z)
				tile.AddEvent(NewWarp(tp_pos))
			}

			_map.AddTile(tile)
		}

		tile.AddLayer(layer, sprite)
	}
}
Beispiel #10
0
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
}
Beispiel #11
0
func processRows(_map *Map) {

	_map.AddMap(0, "")
	tiles := _map.tiles[0]

	for {
		row := <-rowChan
		if row == nil {
			fmt.Println("Map IO Channel closed!")
			break
		}
		x := puh.DBGetInt(row[0])
		y := puh.DBGetInt(row[1])
		z := puh.DBGetInt(row[2])
		position := pos.NewPositionFrom(x, y, z)
		layer := puh.DBGetInt(row[7])
		sprite := puh.DBGetInt(row[6])
		blocking := puh.DBGetInt(row[4])
		// row `idteleport` may be null sometimes.
		var tp_id = 0
		if row[5] != nil {
			tp_id = puh.DBGetInt(row[5])
		}
		idlocation := puh.DBGetInt(row[3])

		tile, found := _map.GetTile(position.Hash())
		if found == false {
			tile = NewTile(position)
			tile.Blocking = blocking

			// Get location
			location, found := g_game.Locations.GetLocation(idlocation)
			if found {
				tile.Location = location
			}

			// Teleport event
			if tp_id > 0 {
				tp_x := puh.DBGetInt(row[8])
				tp_y := puh.DBGetInt(row[9])
				tp_z := puh.DBGetInt(row[10])
				tp_pos := pos.NewPositionFrom(tp_x, tp_y, tp_z)
				tile.AddEvent(NewWarp(tp_pos))
			}

			tiles[tile.Position.Hash()] = tile
		}

		tile.AddLayer(layer, sprite)
	}
}