Ejemplo n.º 1
0
func (p *Player) saveFriends() {
	for _, friend := range p.Friends {
		if friend.DbId == 0 && !friend.IsRemoved { // New friend
			puh.DBQuery(fmt.Sprintf("INSERT INTO player_friends (idplayer, friend_name) VALUES (%d, '%s')", p.dbid, friend.Name))
		} else if friend.DbId > 0 && friend.IsRemoved { // Friend removed
			puh.DBQuery(fmt.Sprintf("DELETE FROM player_friends WHERE idplayer_friends = %d", friend.DbId))
		}
	}
}
Ejemplo n.º 2
0
func (p *Player) savePokemon() {
	for index, pokemon := range p.PokemonParty.Party {
		if pokemon != nil {
			// Save pokemon info
			saveQuery := "UPDATE player_pokemon SET "
			saveQuery += "nickname='%v', bound=%d, experience=%d, iv_hp=%d, iv_attack=%d, iv_attack_spec=%d, iv_defence=%d, iv_defence_spec=%d, iv_speed=%d, happiness=%d, in_party=%d, party_slot=%d, held_item=%d "
			saveQuery += "WHERE idplayer_pokemon=%d"
			puh.DBQuery(fmt.Sprintf(saveQuery,
				pokemon.Nickname,
				pokemon.IsBound,
				int(pokemon.Experience),
				pokemon.Stats[0],
				pokemon.Stats[1],
				pokemon.Stats[3],
				pokemon.Stats[2],
				pokemon.Stats[4],
				pokemon.Stats[5],
				pokemon.Happiness,
				pokemon.InParty,
				index,
				0,
				pokemon.IdDb))

			// Save moves
			pokemon.SaveMoves()
		}
	}
}
Ejemplo n.º 3
0
func (p *Player) savePlayerInfo() {
	var query string
	query = fmt.Sprintf("UPDATE player SET position=%d, movement=%d, money=%d, idlocation=%d WHERE idplayer=%d",
		p.GetPosition().Hash(),
		p.GetMovement(),
		p.GetMoney(),
		p.GetTile().GetLocation().GetId(),
		p.dbid)
	puh.DBQuery(query)

	// Save outfit
	query = fmt.Sprintf("UPDATE player_outfit SET head=%d, nek=%d, upper=%d, lower=%d, feet=%d WHERE idplayer=%d",
		p.GetOutfit().GetOutfitKey(pul.OUTFIT_HEAD),
		p.GetOutfit().GetOutfitKey(pul.OUTFIT_NEK),
		p.GetOutfit().GetOutfitKey(pul.OUTFIT_UPPER),
		p.GetOutfit().GetOutfitKey(pul.OUTFIT_LOWER),
		p.GetOutfit().GetOutfitKey(pul.OUTFIT_FEET),
		p.dbid)
	puh.DBQuery(query)
}
Ejemplo n.º 4
0
func (p *Player) saveQuestProgress() {
	for _, quest := range p.Quests {
		var query string = ""
		if quest.IsNew {
			tmpQuery := "INSERT INTO player_quests (idplayer, idquest, status, created, finished) VALUES (%d, %d, %d, %d, %d)"
			query = fmt.Sprintf(tmpQuery, p.dbid, quest.Quest.Dbid, quest.Status, quest.Created.Unix(), quest.Finished.Unix())
		} else if quest.IsModified {
			tmpQuery := "UPDATE player_quests SET status=%d, finished=%d WHERE idplayer_quests=%d"
			query = fmt.Sprintf(tmpQuery, quest.Status, quest.Finished.Unix(), quest.Dbid)
		}

		if len(query) > 0 {
			puh.DBQuery(query)
		}
	}
}