예제 #1
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")
}
예제 #2
0
func (b *Battle) receivedStatusMessage(_packet *pnet.QTPacket, _player int) {
	status := int(_packet.ReadUint8())
	var statusStr string
	switch status {
	case STATUSFEELING_FEELCONFUSION:
		statusStr = fmt.Sprintf("%s is confused!\n", b.currentPoke(_player))
	case STATUSFEELING_HURTCONFUSION:
		statusStr = "It hurt itself in its confusion!\n"
	case STATUSFEELING_FREECONFUSION:
		statusStr = fmt.Sprintf("%s snapped out of its confusion!\n", b.currentPoke(_player))
	case STATUSFEELING_PREVPARALYSED:
		statusStr = fmt.Sprintf("%s is paralyzed! It can't move!\n", b.currentPoke(_player))
	case STATUSFEELING_FEELASLEEP:
		statusStr = fmt.Sprintf("%s is fast asleep!\n", b.currentPoke(_player))
	case STATUSFEELING_FREEASLEEP:
		statusStr = fmt.Sprintf("%s woke up!\n", b.currentPoke(_player))
	case STATUSFEELING_HURTBURN:
		statusStr = fmt.Sprintf("%s is hurt by its burn!\n", b.currentPoke(_player))
	case STATUSFEELING_HURTPOISON:
		statusStr = fmt.Sprintf("%s is hurt by poison!\n", b.currentPoke(_player))
	case STATUSFEELING_PREVFROZEN:
		statusStr = fmt.Sprintf("%s if frozen solid!\n", b.currentPoke(_player))
	case STATUSFEELING_FREEFROZEN:
		statusStr = fmt.Sprintf("%s thawed out!\n", b.currentPoke(_player))
	}
	b.WriteToHist(statusStr)
}
예제 #3
0
func (c *POClient) battleMessage(_packet *pnet.QTPacket) {
	if c.battle != nil {
		_packet.ReadUint32() // Supporting only one battle, unneeded
		_packet.ReadUint32() // Discard the size, unneeded
		c.battle.ReceiveCommand(_packet)
	}
}
예제 #4
0
func NewBasicPlayerInfoFromPacket(_packet *pnet.QTPacket) *BasicPlayerInfo {
	basicPlayerInfo := &BasicPlayerInfo{}
	basicPlayerInfo.Nick = _packet.ReadString()
	basicPlayerInfo.Info = _packet.ReadString()
	
	return basicPlayerInfo
}
예제 #5
0
func NewShallowShownPokeFromPacket(_packet *pnet.QTPacket) *ShallowShownPoke {
	shallowShownPoke := ShallowShownPoke{UID: NewUniqueIdFromPacket(_packet),
		Level:  int(_packet.ReadUint8()),
		Gender: int(_packet.ReadUint8()),
		Item:   _packet.ReadBool()}
	return &shallowShownPoke
}
예제 #6
0
func NewTeamFromPacket(_packet *pnet.QTPacket) *Team {
	team := Team{Pokes: make([]*TeamPoke, 6)}
	team.Gen = int(_packet.ReadUint8())
	for i := 0; i < 6; i++ {
		team.Pokes[i] = NewTeamPokeFromPacket(_packet)
	}
	return &team
}
예제 #7
0
func (b *Battle) receivedHit(_packet *pnet.QTPacket) {
	number := _packet.ReadUint8()
	extraStr := "!"
	if number > 1 {
		extraStr = "s!"
	}
	b.WriteToHist(fmt.Sprintf("Hit %d time%s\n", number, extraStr))
}
예제 #8
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))
	}
}
예제 #9
0
func (b *Battle) receivedChangePP(_packet *pnet.QTPacket) {
	moveNum := int(_packet.ReadUint8())
	newPP := int(_packet.ReadUint8())
	b.displayedMoves[moveNum].CurrentPP = newPP
	b.myTeam.Pokes[0].Moves[moveNum].CurrentPP = newPP

	// Send updateMovePP to PUClient
	SendBattleEvent_ChangePP(b.owner.player, 0, moveNum, newPP)
}
예제 #10
0
func (b *Battle) receivedSubstitute(_packet *pnet.QTPacket, _player int) {
	isSub := _packet.ReadBool()
	b.currentPoke(_player).Sub = isSub
	if _player == b.me {
		// TODO: Send updateMyPoke to PU client
	} else {
		// TODO: Send updateOppPoke to PU client
	}
}
예제 #11
0
func (b *Battle) receivedRated(_packet *pnet.QTPacket) {
	rated := "Unrated"
	if _packet.ReadBool() {
		rated = "Rated"
	}
	b.WriteToHist("Rule: " + rated + "\n")

	// TODO: Print clauses
}
예제 #12
0
func NewRearrangeChoiceFromPacket(_packet *pnet.QTPacket) *RearrangeChoice {
	rearrangeChoice := RearrangeChoice{}
	rearrangeChoice.PokeIndexes = make([]int, 6)
	for i := 0; i < 6; i++ {
		rearrangeChoice.PokeIndexes[i] = int(_packet.ReadUint8())
	}

	return &rearrangeChoice
}
예제 #13
0
func NewBattleDynamicInfoFromPacket(_packet *pnet.QTPacket) *BattleDynamicInfo {
	battleDynamicInfo := BattleDynamicInfo{}
	battleDynamicInfo.Boosts = make([]byte, 7)
	for i := 0; i < 7; i++ {
		battleDynamicInfo.Boosts[i] = _packet.ReadUint8()
	}
	battleDynamicInfo.Flags = _packet.ReadUint8()

	return &battleDynamicInfo
}
예제 #14
0
func NewFullPlayerInfoFromPacket(_packet *pnet.QTPacket) *FullPlayerInfo {
	fullPlayerInfo := &FullPlayerInfo{}
	fullPlayerInfo.Team = NewPlayerTeamFromPacket(_packet)
	fullPlayerInfo.IsDefault = true
	fullPlayerInfo.ladderEnabled = _packet.ReadBool()
	fullPlayerInfo.showTeam = _packet.ReadBool()
	fullPlayerInfo.nameColor = NewQColorFromPacket(_packet)

	return fullPlayerInfo
}
예제 #15
0
func (c *POClient) engageBattle(_packet *pnet.QTPacket) {
	c.bID = int(_packet.ReadUint32())
	pID1 := int(_packet.ReadUint32())
	pID2 := int(_packet.ReadUint32())
	if pID1 == 0 { // This is us!
		battleConf := NewBattleConfFromPacket(_packet)
		// Start the battle
		c.battle = NewBattle(c, battleConf, _packet, c.players[battleConf.GetId(0)], c.players[battleConf.GetId(1)], c.mePlayer.Id, c.bID)

		fmt.Printf("Battle between %s and %s started!\n", c.mePlayer.Nick, c.players[pID2].Nick)
	}
}
예제 #16
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
}
예제 #17
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)
}
예제 #18
0
func (b *Battle) receivedBattleEnd(_packet *pnet.QTPacket, _player int) {
	result := int(_packet.ReadUint8())
	if result == BATTLERESULT_TIE {
		b.WriteToHist(fmt.Sprintf("Tie between %v and %v.\n", b.players[0].Nick, b.players[1].Nick))
	} else {
		b.WriteToHist(fmt.Sprintf("%v won the battle!\n", b.players[_player].Nick))
	}
	b.gotEnd = true

	// Update pokemon data of player
	b.owner.UpdatePokemonData()

	// TODO: Send endBattle to PU client
}
예제 #19
0
func (b *Battle) receivedEffective(_packet *pnet.QTPacket) {
	eff := _packet.ReadUint8()
	switch eff {
	case 0:
		b.WriteToHist("It had no effect!\n")
	case 1:
		fallthrough
	case 2:
		b.WriteToHist("It's not very effective...\n")
	case 8:
		fallthrough
	case 16:
		b.WriteToHist("It's super effective!\n")
	}
}
예제 #20
0
func NewBattleChoiceFromPacket(_packet *pnet.QTPacket) *BattleChoice {
	battleChoice := BattleChoice{}
	battleChoice.PlayerSlot = int(_packet.ReadUint8())
	battleChoice.ChoiceType = int(_packet.ReadUint8())

	switch battleChoice.ChoiceType {
	case CHOICETYPE_SWITCHTYPE:
		battleChoice.Choice = NewSwitchChoiceFromPacket(_packet)
	case CHOICETYPE_ATTACKTYPE:
		battleChoice.Choice = NewAttackChoiceFromPacket(_packet)
	case CHOICETYPE_REARRANGETYPE:
		battleChoice.Choice = NewRearrangeChoiceFromPacket(_packet)
	}

	return &battleChoice
}
예제 #21
0
func (b *Battle) receivedAbsStatusChange(_packet *pnet.QTPacket, _player int) {
	poke := int(_packet.ReadUint8())
	status := uint(_packet.ReadUint8())

	if (poke >= 0 || poke < 6) && status != STATUS_CONFUSED {
		b.pokes[_player][poke].ChangeStatus(status)
		if _player == b.me {
			b.myTeam.Pokes[poke].ChangeStatus(status)
		}

		// if b.isOut(poke) {
		// TODO: Send updatePokes to PU client
		// }
		// TODO: Send updatePokeballs to PU client
	}
}
예제 #22
0
func (b *Battle) receivedWeatherMesage(_packet *pnet.QTPacket, _player int) {
	wstatus := int(_packet.ReadUint8())
	weather := int(_packet.ReadUint8())
	if weather == WEATHER_NORMALWEATHER {
		return
	}

	var message string = ""
	if wstatus == WEATHERSTATE_ENDWEATHER {
		switch weather {
		case WEATHER_HAIL:
			message = "The hail subsided!"
		case WEATHER_SANDSTORM:
			message = "The sandstorm subsided!"
		case WEATHER_SUNNY:
			message = "The sunglight faded!"
		case WEATHER_RAIN:
			message = "The rain stopped!"
		}
	} else if wstatus == WEATHERSTATE_HURTWEATHER {
		switch weather {
		case WEATHER_HAIL:
			message = fmt.Sprintf("%v is buffeted by the hail!", b.currentPoke(_player).Nick)
		case WEATHER_SANDSTORM:
			message = fmt.Sprintf("%v is buffeted by the sandstorm!", b.currentPoke(_player).Nick)
		}
	} else if wstatus == WEATHERSTATE_CONTINUEWEATHER {
		switch weather {
		case WEATHER_HAIL:
			message = "Hail continues to fall!"
		case WEATHER_SANDSTORM:
			message = "The sandstorm rages!"
		case WEATHER_SUNNY:
			message = "The sunlight is strong!"
		case WEATHER_RAIN:
			message = "Rain continues to fall!"
		}
	}

	b.WriteToHist(message + "\n")
}
예제 #23
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)
	}
}
예제 #24
0
func NewBattleMoveFromPacket(_packet *pnet.QTPacket) *BattleMove {
	battleMove := NewBattleMoveFromId(int(_packet.ReadUint16()))
	battleMove.CurrentPP = int(_packet.ReadUint8())
	battleMove.TotalPP = int(_packet.ReadUint8())

	return battleMove
}
예제 #25
0
func (b *Battle) receivedStatusChange(_packet *pnet.QTPacket, player int) {
	status := int(_packet.ReadUint8())
	multipleTurns := _packet.ReadBool()
	if status > STATUS_FINE && status <= STATUS_POISONED {
		statusChangeMessages := make([]string, 6)
		statusChangeMessages[0] = "is paralyzed! It may be unable to move!"
		statusChangeMessages[1] = "fell asleep!"
		statusChangeMessages[2] = "was frozen solid!"
		statusChangeMessages[3] = "was burned!"
		statusChangeMessages[4] = "was poisoned!"
		statusChangeMessages[5] = "was badly poisoned!"

		statusIndex := status - 1
		if status == STATUS_POISONED && multipleTurns {
			statusIndex += 1
		}

		b.WriteToHist(fmt.Sprintf("%s %s\n", b.currentPoke(player).Nick, statusChangeMessages[statusIndex]))
	} else if status == STATUS_CONFUSED {
		b.WriteToHist(fmt.Sprintf("%s became confused!\n", b.currentPoke(player).Nick))
	}
}
예제 #26
0
func (b *Battle) receivedStatChange(_packet *pnet.QTPacket, _player int) {
	stat := int(_packet.ReadUint8())
	boost := int(_packet.ReadUint8())
	var statStr string
	if stat == 0 {
		statStr = STAT_HP
	} else if stat == 1 {
		statStr = STAT_ATTACK
	} else if stat == 2 {
		statStr = STAT_DEFENSE
	} else if stat == 3 {
		statStr = STAT_SPATTACK
	} else if stat == 4 {
		statStr = STAT_SPDEFENSE
	} else if stat == 5 {
		statStr = STAT_SPEED
	} else if stat == 6 {
		statStr = STAT_ACCURACY
	} else if stat == 7 {
		statStr = STAT_EVASION
	} else if stat == 8 {
		statStr = STAT_ALLSTATS
	}

	var boostStr string
	if boost > 0 {
		boostStr = "rose!"
	} else {
		boostStr = "fell!"
	}

	boostStrExt := ""
	if boost > 1 {
		boostStr = "sharply"
	}

	b.WriteToHist(fmt.Sprintf("%s's %s %s%s\n", b.currentPoke(_player).Nick, statStr, boostStrExt, boostStr))
}
예제 #27
0
// -------------------- Received Messages ----------------------
func (b *Battle) receivedSendOut(_packet *pnet.QTPacket, _player int) {
	isSilent := _packet.ReadBool()
	fromSpot := int(_packet.ReadUint8())

	if _player == b.me {
		// tmp := b.myTeam.Pokes[0]
		b.myTeam.Pokes[0], b.myTeam.Pokes[fromSpot] = b.myTeam.Pokes[fromSpot], b.myTeam.Pokes[0]
		for i := 0; i < 4; i++ {
			b.displayedMoves[i] = NewBattleMoveFromBattleMove(b.myTeam.Pokes[0].Moves[i])
		}
	}

	b.pokes[_player][0], b.pokes[_player][fromSpot] = b.pokes[_player][fromSpot], b.pokes[_player][0]
	if _packet.GetMsgSize() > _packet.GetReadPos() { // this is the first time you've seen it
		b.pokes[_player][0] = NewShallowBattlePokeFromPacket(_packet, (_player == b.me))
	}

	// TOOD: Send updatePokes to PU client
	// TODO: Send updatePokeballs to PU client

	if !isSilent {
		b.WriteToHist(fmt.Sprintf("%s sent out %s!\n", b.players[_player].Nick, b.currentPoke(_player).RNick))
	}
}
예제 #28
0
func (b *Battle) receiveOfferChoice(_packet *pnet.QTPacket) {
	_packet.ReadUint8() // We don't need it (numSlot)
	b.allowSwitch = _packet.ReadBool()
	b.allowAttack = _packet.ReadBool()
	canDoAttack := false
	for i := 0; i < 4; i++ {
		b.allowAttacks[i] = _packet.ReadBool()
		if b.allowAttacks[i] {
			canDoAttack = true
		}
	}

	if b.allowAttack && !canDoAttack {
		b.shouldStruggle = true
	} else {
		b.shouldStruggle = false
	}

	// TODO: Send updateButtons to PU client
}
예제 #29
0
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
}
예제 #30
0
func NewSwitchChoiceFromPacket(_packet *pnet.QTPacket) *SwitchChoice {
	return NewSwitchChoice(int(_packet.ReadUint8()))
}