func NewBasicPlayerInfoFromPacket(_packet *pnet.QTPacket) *BasicPlayerInfo {
	basicPlayerInfo := &BasicPlayerInfo{}
	basicPlayerInfo.Nick = _packet.ReadString()
	basicPlayerInfo.Info = _packet.ReadString()
	
	return basicPlayerInfo
}
Esempio n. 2
0
func NewTeamPokeFromPacket(_packet *pnet.QTPacket) *TeamPoke {
	teamPoke := TeamPoke{}
	teamPoke.UID = NewUniqueIdFromPacket(_packet)
	teamPoke.Nick = _packet.ReadString()
	teamPoke.Item = int(_packet.ReadUint16())
	teamPoke.Ability = int(_packet.ReadUint16())
	teamPoke.Nature = int(_packet.ReadUint8())
	teamPoke.Gender = int(_packet.ReadUint8())
	// teamPoke.Gen = (int)_packet.ReadByte()
	teamPoke.Shiny = _packet.ReadBool()
	teamPoke.Happiness = int(_packet.ReadUint8())
	teamPoke.Level = int(_packet.ReadUint8())

	teamPoke.Moves = make([]int, 4)
	for i := 0; i < 4; i++ {
		teamPoke.Moves[i] = int(_packet.ReadUint32())
	}
	teamPoke.DVs = make([]int, 6)
	for i := 0; i < 6; i++ {
		teamPoke.DVs[i] = int(_packet.ReadUint8())
	}
	teamPoke.EVs = make([]int, 6)
	for i := 0; i < 6; i++ {
		teamPoke.EVs[i] = int(_packet.ReadUint8())
	}

	return &teamPoke
}
Esempio n. 3
0
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")
}
Esempio n. 4
0
func NewPlayerTeamFromPacket(_packet *pnet.QTPacket) *PlayerTeam {
	playerTeam := PlayerTeam{}
	playerTeam.Nick = _packet.ReadString()
	playerTeam.Info = _packet.ReadString()
	playerTeam.LoseMessage = _packet.ReadString()
	playerTeam.WinMessage = _packet.ReadString()
	playerTeam.avatar = int(_packet.ReadUint16())
	playerTeam.DefaultTier = _packet.ReadString()
	playerTeam.Team = NewTeamFromPacket(_packet)

	return &playerTeam
}
func NewShallowBattlePokeFromPacket(_packet *pnet.QTPacket, _isMe bool) *ShallowBattlePoke {
	shallowPoke := ShallowBattlePoke{Types: make([]int, 2)}
	shallowPoke.UID = NewUniqueIdFromPacket(_packet)
	shallowPoke.RNick = _packet.ReadString()
	shallowPoke.Nick = shallowPoke.RNick
	if !_isMe {
		shallowPoke.Nick = "the foe's " + shallowPoke.Nick

		shallowPoke.getName()
		shallowPoke.getTypes()
	}

	shallowPoke.LifePercent = int(_packet.ReadUint8())
	shallowPoke.fullStatus = _packet.ReadUint32()
	shallowPoke.Gender = int(_packet.ReadUint8())
	shallowPoke.Shiny = _packet.ReadBool()
	shallowPoke.Level = int(_packet.ReadUint32())

	return &shallowPoke
}
Esempio n. 6
0
func (c *POClient) ProcessPacket(_packet *pnet.QTPacket) {
	header := int(_packet.ReadUint8())
	fmt.Printf("Received header %v\n", header)
	switch header {
	case COMMAND_Login: // 2
		c.login(_packet)
	case COMMAND_PlayersList: // 5
		c.playerList(_packet)
	case COMMAND_ChallengeStuff: // 7
		c.challengeStuff(_packet)
	case COMMAND_EngageBattle: // 8
		c.engageBattle(_packet)
	case COMMAND_BattleMessage: // 10
		c.battleMessage(_packet)
	case COMMAND_KeepAlive: // 12
		c.keepAlive()
	case COMMAND_Register: // 14
		// Do nothing
	case COMMAND_VersionControl: // 33
		// Do nothing
	case COMMAND_TierSelection: // 34
		// Do nothing
	case COMMAND_BattleList: // 43
		// Do nothin
	case COMMAND_ChannelsList: // 44
		// Do nothing
	case COMMAND_ChannelPlayers: // 45
		// Do nothing
	case COMMAND_JoinChannel: // 46
		// Do nothing
	case COMMAND_ChannelMessage: // 51
		// Do nothing
	case COMMAND_HtmlMessage: // 53
		fmt.Printf("[Message] %s\n\r", _packet.ReadString())
	case COMMAND_ServerName: // 55
		// Do nothing
	default:
		fmt.Printf("UNIMPLEMENTED PACKET: %v\n", header)
	}
}
Esempio n. 7
0
func (b *Battle) ReceiveCommand(_packet *pnet.QTPacket) {
	bc := int(_packet.ReadUint8())
	player := int(_packet.ReadUint8())
	fmt.Printf("Battle command received: %d | PlayerId: %d\n", bc, player)
	switch bc {
	case BattleCommand_SendOut: // 0
		b.receivedSendOut(_packet, player)
	case BattleCommand_SendBack: // 1
		b.receivedSendBack(player)
	case BattleCommand_UseAttack: // 2
		b.receivedUseAttack(_packet, player)
	case BattleCommand_OfferChoice: // 3
		b.receiveOfferChoice(_packet)
	case BattleCommand_BeginTurn: // 4
		b.receivedBeginTurn(_packet)
	case BattleCommand_ChangePP: // 5
		b.receivedChangePP(_packet)
	case BattleCommand_ChangeHp: // 6
		b.receivedChangeHp(_packet, player)
	case BattleCommand_Ko: // 7
		b.receivedKo(player)
	case BattleCommand_Effective: // 8
		b.receivedEffective(_packet)
	case BattleCommand_Miss: // 9
		b.receivedMiss(player)
	case BattleCommand_CriticalHit: // 10
		b.receivedCriticalHit()
	case BattleCommand_Hit: // 11
		b.receivedHit(_packet)
	case BattleCommand_StatChange: // 12
		b.receivedStatChange(_packet, player)
	case BattleCommand_StatusChange: // 13
		b.receivedStatusChange(_packet, player)
	case BattleCommand_StatusMessage: // 14
		b.receivedStatusMessage(_packet, player)
	case BattleCommand_Failed: // 15
		b.receivedFailed()
	case BattleCommand_MoveMessage: // 17
		b.receivedMoveMessage(_packet, player)
	case BattleCommand_ItemMessage: // 18
		// TODO: We don't have items yet, so do nothing for now
	case BattleCommand_NoOpponent: // 19
		b.WriteToHist("But there was no target...\n")
	case BattleCommand_Flinch: // 20
		b.WriteToHist(b.currentPoke(player).Nick + " flinched!\n")
	case BattleCommand_Recoil: // 21
		damaging := _packet.ReadBool()
		if damaging {
			b.WriteToHist(b.currentPoke(player).Nick + " is hit with recoil!\n")
		} else {
			b.WriteToHist(b.currentPoke(player).Nick + " had its energy drained!\n")
		}
	case BattleCommand_WeatherMessage: // 22
		b.receivedWeatherMesage(_packet, player)
	case BattleCommand_StraightDamage: // 23
		b.receivedStraigthDamage(_packet, player)
	case BattleCommand_AbilityMessage: // 24
		b.receivedAbilityMessage(_packet, player)
	case BattleCommand_AbsStatusChange: // 25
		b.receivedAbsStatusChange(_packet, player)
	case BattleCommand_Substitute: // 26
		b.receivedSubstitute(_packet, player)
	case BattleCommand_BattleEnd: // 27
		b.receivedBattleEnd(_packet, player)
	case BattleCommand_BlankMessage: // 28
		b.WriteToHist("\n")
	case BattleCommand_CancelMove: // 29
		b.receivedCancelMove()
	case BattleCommand_Clause: // 30
		// TODO: Do someting with this, it only writes to history so isn't that important
	case BattleCommand_DynamicInfo: // 31
		b.receiveDynamicInfo(_packet, player)
	case BattleCommand_DynamicStats: // 32
		b.receiveDynamicStats(_packet, player)
	case BattleCommand_Spectating: // 33
		// TODO: implement
	case BattleCommand_SpectatorChat: // 34
		// TODO: Implement? Or are we using our own chat (probably yes)
	case BattleCommand_AlreadyStatusMessage: // 35
		status := int(_packet.ReadUint8())
		b.WriteToHist(fmt.Sprintf("%v is already %v\n", b.currentPoke(player), puh.GetStatusById(status)))
	case BattleCommand_TempPokeChange: // 36
		b.receivedTempPokeChange(_packet, player)
	case BattleCommand_ClockStart: // 37
		b.clockStart(_packet, player)
	case BattleCommand_ClockStop: // 38
		b.clockStop(_packet, player)
	case BattleCommand_Rated: // 39
		b.receivedRated(_packet)
	case BattleCommand_TierSection: // 40
		tier := _packet.ReadString()
		b.WriteToHist("Tier: " + tier + "\n")
	case BattleCommand_EndMessage: // 41
		endMessage := _packet.ReadString()
		if len(endMessage) > 0 {
			b.WriteToHist(fmt.Sprintf("%v: %v\n", b.players[player].Nick, endMessage))
		}
	case BattleCommand_PointEstimate: // 42
		// NOT IMPLEMENTED
	case BattleCommand_MakeYourChoice: // 43
		b.receiveMakeYourCoice()
	case BattleCommand_Avoid: // 44
		b.WriteToHist(fmt.Sprintf("%v avoided the attack!\n", b.currentPoke(player).Nick))
	case BattleCommand_RearrangeTeam: // 45
		b.receivedRearrangeTeam(_packet)
	case BattleCommand_SpotShifts: // 46
		// TOOD
	default:
		fmt.Printf("Battle command unimplemented: %d\n", bc)
	}
}