func (b *Battle) receivedAbilityMessage(_packet *pnet.QTPacket, _player int) { ab := int(_packet.ReadUint16()) part := int(_packet.ReadUint8()) msgType := int(_packet.ReadUint8()) foe := int(_packet.ReadUint8()) other := int(_packet.ReadUint16()) s := pokemon.GetInstance().GetAbilityMessage((ab + 1), part) if other != -1 && strings.Contains(s, "%st") { s = strings.Replace(s, "%st", puh.GetStatById(other), 0) } s = strings.Replace(s, "%s", b.currentPoke(_player).Nick, 0) if msgType != -1 { s = strings.Replace(s, "%t", puh.GetTypeValueById(msgType), 0) } if foe != -1 { s = strings.Replace(s, "%f", b.currentPoke(foe).Nick, 0) } if other != -1 { if strings.Contains(s, "%m") { s = strings.Replace(s, "%m", pokemon.GetInstance().GetMoveNameById(other), 0) } if strings.Contains(s, "%i") { s = strings.Replace(s, "%i", pokemon.GetInstance().GetItemNameById(other), 0) } if strings.Contains(s, "%a") { s = strings.Replace(s, "%a", pokemon.GetInstance().GetAbilityNameById(other+1), 0) } if strings.Contains(s, "%p") { s = strings.Replace(s, "%p", pokemon.GetInstance().GetPokemonName(other, 0), 0) } } b.WriteToHist(s + "\n") }
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 }
func (b *Battle) receivedMoveMessage(_packet *pnet.QTPacket, _player int) { move := int(_packet.ReadUint16()) part := int(_packet.ReadUint8()) msgType := int(_packet.ReadUint8()) foe := int(_packet.ReadUint8()) other := int(_packet.ReadUint16()) q := _packet.ReadString() s := pokemon.GetInstance().GetMoveMessage(move, part) if len(s) == 0 { fmt.Printf("Could not find message %d part %d\n", move, part) return } s = strings.Replace(s, "%s", b.currentPoke(_player).Nick, 0) s = strings.Replace(s, "%ts", b.players[_player].Nick, 0) var tmp int = 0 if _player == 0 { tmp = 1 } s = strings.Replace(s, "%tf", b.players[tmp].Nick, 0) if msgType != -1 { s = strings.Replace(s, "%t", puh.GetTypeValueById(msgType), 0) } if foe != -1 { s = strings.Replace(s, "%f", b.currentPoke(foe).Nick, 0) } if other != -1 && strings.Contains(s, "%m") { s = strings.Replace(s, "%m", pokemon.GetInstance().GetMoveNameById(other), 0) } s = strings.Replace(s, "%d", string(other), 0) s = strings.Replace(s, "%q", q, 0) if other != -1 && strings.Contains(s, "%i") { s = strings.Replace(s, "%i", pokemon.GetInstance().GetItemNameById(other), 0) } if other != -1 && strings.Contains(s, "%a") { s = strings.Replace(s, "%a", pokemon.GetInstance().GetAbilityNameById(other+1), 0) } if other != -1 && strings.Contains(s, "%p") { s = strings.Replace(s, "%p", pokemon.GetInstance().GetPokemonName(other, 0), 0) } b.WriteToHist(s + "\n") }
func main() { flag.Parse() // Always use the maximum available CPU/Cores runtime.GOMAXPROCS(runtime.NumCPU()) fmt.Println("***********************************************") fmt.Println("** Pokemon Universe Server **") fmt.Println("** **") fmt.Println("** http://code.google.com/p/pokemon-universe **") fmt.Println("** GNU General Public License V2 **") fmt.Println("***********************************************") if !initConfig() { return } if !initLogger() { return } logger.Println("Initial setup complete.") logger.Println("Connecting to database.") if !initDatabase() { return } logger.Println("Loading Pokemon data") pokemonManager := pokemon.GetInstance() if !pokemonManager.Load() { return } // logger.Println("Loading game data") // g_game = NewGame() // if !g_game.Load() { // logger.Println("Failed to load game data...") // return // } logger.Println("Create new player object") p := NewPlayer("Mr_Dark") logger.Println("Start battle") p.InitializeBattle() // logger.Println("Starting server") // g_server = NewServer() // g_server.Start() for { time.Sleep(1e9) } }
func NewBattleMoveFromId(_id int) *BattleMove { move := pokemon.GetInstance().GetMoveById(_id) battleMove := BattleMove{} battleMove.CurrentPP = move.PP battleMove.TotalPP = move.PP battleMove.Num = move.MoveId battleMove.Name = move.Identifier battleMove.Type = move.TypeId battleMove.power = string(move.Power) battleMove.accuracy = string(move.Accuracy) battleMove.description = "" battleMove.effect = "" return &battleMove }
func (s *ShallowBattlePoke) getTypes() { s.Types = pokemon.GetInstance().GetPokemonTypes(s.UID.PokeNum, s.UID.SubNum) }
func (s *ShallowBattlePoke) getName() { s.PokeName = pokemon.GetInstance().GetPokemonName(s.UID.PokeNum, s.UID.SubNum) }
func main() { fmt.Println("*******************************************") fmt.Println("** Pokemon Universe - Mapserver v0.5.r1 **") fmt.Println("*******************************************") // Flags configFile := flag.String("config", "server.conf", "Name of the config file to load") flag.Parse() // Load config file fmt.Printf("Loading config file...") if initConfig(configFile) == false { fmt.Printf("[FAILED]\n") return } fmt.Printf("[Succeeded]\n") initLogger() // Connect to database fmt.Printf("Connecting to database...") if initDatabase() == false { fmt.Printf("[FAILED]\n") return } fmt.Printf("[Succeeded]\n") fmt.Printf("Loading all Pokemon data...") pokemon.G_orm = &g_orm pokemonManager := pokemon.GetInstance() if !pokemonManager.Load() { return } fmt.Printf("[Succeeded]\n") // Get maps fmt.Printf("Retrieving map names...") g_map.LoadMapList() fmt.Printf("[Succeeded] (%d maps loaded)\n", g_map.GetNumMaps()) // Retrieve all tiles fmt.Printf("Retrieving tiles...") g_map.LoadTiles() fmt.Printf("[Succeeded] (%d tiles loaded)\n", g_map.GetNumTiles()) // Retreive all NPCs fmt.Printf("Retrieving NPCs...") g_npc.LoadNpcList() fmt.Printf("[Succeeded] (%d NPCs loaded)\n", g_npc.GetNumNpcs()) // fmt.Printf("Retrieving NPC Pokemon...") // g_npc.LoadNpcPokemon() // fmt.Printf("[Succeeded] (%d Pokemons loaded)\n", g_npc.GetNumPokemons()) fmt.Printf("Retrieving Locations...") if !g_locations.LoadLocations() { return } fmt.Printf("[Succeeded] (Loaded %d pokecenters, %d music and %d locations)\n", g_locations.GetNumPokecenters(), g_locations.GetNumMusic(), g_locations.GetNumLocations()) fmt.Println("Initialisation completed!\n") // Set up server version, _ = g_config.GetString("default", "version") fmt.Println("Current server is suited for client version " + version) fmt.Printf("Running server...") serverPort, ok := g_config.GetInt("default", "port") if ok == nil || serverPort <= 0 { serverPort = 6171 } g_server = NewServer(serverPort) g_server.RunServer() }
func (b *Battle) receivedUseAttack(_packet *pnet.QTPacket, _player int) { attack := int(_packet.ReadUint16()) b.WriteToHist(fmt.Sprintf("%s used %s!\n", b.currentPoke(_player).Nick, pokemon.GetInstance().GetMoveById(attack).Identifier)) }