コード例 #1
0
ファイル: playerio.go プロジェクト: gasperko/pokemon-universe
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
}
コード例 #2
0
ファイル: playerio.go プロジェクト: gasperko/pokemon-universe
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
}
コード例 #3
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
}
コード例 #4
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
}
コード例 #5
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
}
コード例 #6
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
}
コード例 #7
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
}
コード例 #8
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
}
コード例 #9
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
}