Ejemplo n.º 1
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
}
Ejemplo n.º 2
0
func NewBattleMoveFromPacket(_packet *pnet.QTPacket) *BattleMove {
	battleMove := NewBattleMoveFromId(int(_packet.ReadUint16()))
	battleMove.CurrentPP = int(_packet.ReadUint8())
	battleMove.TotalPP = int(_packet.ReadUint8())

	return battleMove
}
Ejemplo n.º 3
0
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")
}
Ejemplo n.º 4
0
func (b *Battle) receivedStraigthDamage(_packet *pnet.QTPacket, _player int) {
	damage := int(_packet.ReadUint16())
	if _player == b.me {
		b.WriteToHist(fmt.Sprintf("%v lost %d HP! (%d%% of its health)", b.currentPoke(_player).Nick, (damage*100)/b.myTeam.Pokes[0].TotalHP))
	} else {
		b.WriteToHist(fmt.Sprintf("%v lost %d%% of its health!", b.currentPoke(_player).Nick, damage))
	}
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
0
func NewQColorFromPacket(_packet *pnet.QTPacket) *QColor {
	color := QColor{}
	color.Spec = _packet.ReadUint8()
	color.Alpha = _packet.ReadUint16()
	color.Red = _packet.ReadUint16()
	color.Green = _packet.ReadUint16()
	color.Blue = _packet.ReadUint16()
	color.Pad = _packet.ReadUint16()
	color.Html = ">"

	return &color
}
Ejemplo n.º 7
0
func (b *Battle) receivedChangeHp(_packet *pnet.QTPacket, _player int) {
	newHp := int(_packet.ReadUint16())
	if _player == b.me {
		b.myTeam.Pokes[0].CurrentHP = newHp
		b.currentPoke(_player).LastKnownPercent = newHp
		b.currentPoke(_player).LifePercent = (newHp * 100) / b.myTeam.Pokes[0].TotalHP
	} else {
		b.currentPoke(_player).LastKnownPercent = newHp
		b.currentPoke(_player).LifePercent = newHp
	}

	// Send HP update to PU Client
	SendBattleEvent_ChangeHP(b.owner.player, 0, newHp)
}
Ejemplo n.º 8
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")
}
Ejemplo n.º 9
0
func (b *Battle) receivedTempPokeChange(_packet *pnet.QTPacket, _player int) {
	id := int(_packet.ReadUint8())
	switch id {
	case TEMPPOKECHANGE_TEMPMOVE:
		fallthrough
	case TEMPPOKECHANGE_DEFMOVE:
		slot := int(_packet.ReadUint8())
		newMove := NewBattleMoveFromId(int(_packet.ReadUint16()))
		b.displayedMoves[slot] = newMove
		if id == TEMPPOKECHANGE_DEFMOVE {
			b.myTeam.Pokes[0].Moves[slot] = newMove
		}

		// TODO: Send updatePokes(player) to PU client
	case TEMPPOKECHANGE_TEMPPP:
		slot := int(_packet.ReadUint8())
		pp := int(_packet.ReadUint8())
		b.displayedMoves[slot].CurrentPP = pp

		// TODO: Send updateMovePP(slot) to PU client
	case TEMPPOKECHANGE_TEMPSPRITE:
		// TODO: Implement
	case TEMPPOKECHANGE_DEFINITEFORME:
		poke := int(_packet.ReadUint8())
		newForm := int(_packet.ReadUint16())
		if b.isOut(poke) {
			b.currentPoke(b.slot(_player, poke)).UID.PokeNum = newForm

			// TODO: Send updatePokes(player) to PU client
		}
	case TEMPPOKECHANGE_AESTHETICFORME:
		newForm := int(_packet.ReadUint16())
		b.currentPoke(_player).UID.SubNum = newForm

		// TODO: Send updatePokes(player) to PU client
	}
}
Ejemplo n.º 10
0
func (b *Battle) clockStop(_packet *pnet.QTPacket, _player int) {
	index := _player % 2
	b.remainingTime[index] = int(_packet.ReadUint16())
	b.ticking[index] = false
}
Ejemplo n.º 11
0
func (b *Battle) clockStart(_packet *pnet.QTPacket, _player int) {
	index := _player % 2
	b.remainingTime[index] = int(_packet.ReadUint16())
	b.startingTime[index] = time.Now().UnixNano()
	b.ticking[index] = true
}
Ejemplo n.º 12
0
func (b *Battle) receiveDynamicStats(_packet *pnet.QTPacket, _player int) {
	for i := 0; i < 5; i++ {
		b.myTeam.Pokes[_player/2].Stats[i] = int(_packet.ReadUint16())
	}
}
Ejemplo n.º 13
0
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))
}