Example #1
0
// WritePacket write the needed object data to a Packet and returns it
func (m *TextMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint16(uint16(m.Class))
	packet.AddString(m.Message)

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *CreatureTurnMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint64(m.Creature.GetUID())
	packet.AddUint16(uint16(m.Direction))

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *DialogMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint8(uint8(m.DialogType))

	if m.DialogType != pnet.DIALOG_CLOSE {
		if m.DialogType == pnet.DIALOG_NPC || m.DialogType == pnet.DIALOG_NPCTEXT {
			packet.AddUint64(m.NpcId)
		}

		if m.DialogType != pnet.DIALOG_OPTIONS {
			packet.AddString(m.Question)
		}

		if m.DialogType != pnet.DIALOG_NPCTEXT {

			for index, answer := range m.Answers {
				packet.AddUint32(uint32(index))
				packet.AddString(answer)
			}

		}
	}

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *PlayerWarpMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint16(uint16(m.Position.X))
	packet.AddUint16(uint16(m.Position.Y))

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *FriendUpdateMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddString(m.Name)
	packet.AddUint8(uint8(m.Removed))
	packet.AddUint8(uint8(m.Online))

	return packet
}
Example #6
0
// WritePacket write the needed object data to a Packet and returns it
func (m *WalkMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint64(m.Creature.GetUID())
	packet.AddUint16(uint16(m.From.X))
	packet.AddUint16(uint16(m.From.Y))
	packet.AddUint16(uint16(m.To.X))
	packet.AddUint16(uint16(m.To.Y))

	return packet
}
Example #7
0
// WritePacket write the needed object data to a Packet and returns it
func (m *ChatMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint64(m.From.GetUID())
	packet.AddString(m.From.GetName())
	packet.AddUint8(uint8(m.SpeakType))
	packet.AddUint16(uint16(m.ChannelId))
	packet.AddString(m.Text)

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *FriendListMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint32(uint32(len(m.Friends)))

	for name, online := range m.Friends {
		packet.AddString(name)
		packet.AddUint8(uint8(online))
	}

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *QuestListMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint32(uint32(len(m.Quests)))

	for _, quest := range m.Quests {
		packet.AddUint64(uint64(quest.Id))
		packet.AddString(quest.Name)
		packet.AddString(quest.Description)
		packet.AddUint8(uint8(quest.Status))
	}

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *BattleEventMessage) WritePacket() pnet.IPacket {
	var packet pnet.IPacket = pnet.NewPacketExt(m.GetHeader())
	packet.AddUint32(m.EventType)

	switch m.EventType {
	case pnet.BATTLEEVENT_TEXT:
		packet = m.writeMessage(packet)
	case pnet.BATTLEEVENT_CHANGEPP:
		packet = m.writeChangePP(packet)
	case pnet.BATTLEEVENT_CHANGEHP:
		packet = m.writeChangeHP(packet)
	}

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *QuestUpdateMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint64(uint64(m.Id))
	packet.AddString(m.Name)
	packet.AddString(m.Description)
	packet.AddUint8(uint8(m.Status))

	if m.Removed {
		packet.AddUint8(1)
	} else {
		packet.AddUint8(0)
	}

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *SendTilesMessage) WritePacket() pnet.IPacket {
	totalTiles := uint16(len(m.Tiles))
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint16(totalTiles)

	if totalTiles == 0 {
		return packet
	}

	for _, tile := range m.Tiles {
		if tile == nil {
			continue
		}

		packet.AddUint16(uint16(tile.GetPosition().X))
		packet.AddUint16(uint16(tile.GetPosition().Y))
		packet.AddUint16(uint16(tile.GetBlocking()))

		packet.AddUint16(uint16(len(tile.GetLayers())))
		for id, layer := range tile.GetLayers() {
			if layer == nil {
				continue
			}

			packet.AddUint16(uint16(id))
			packet.AddUint32(uint32(layer.SpriteID))
		}

		// Tile Location info
		if location := tile.GetLocation(); location != nil {
			packet.AddUint16(uint16(location.GetId()))
			packet.AddString(location.GetName())
		} else {
			packet.AddUint16(0)
			packet.AddString("Unknown")
		}
	}

	m.Tiles = make(pul.TilesMap)

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *SendPlayerData) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint64(uint64(m.UID))
	packet.AddString(m.Name)
	packet.AddUint16(uint16(m.Position.X))
	packet.AddUint16(uint16(m.Position.Y))
	packet.AddUint16(uint16(m.Direction))
	packet.AddUint32(uint32(m.Money))

	packet.AddUint8(uint8(m.Outfit.GetOutfitStyle(pul.OUTFIT_UPPER)))
	packet.AddUint32(uint32(m.Outfit.GetOutfitColour(pul.OUTFIT_UPPER)))
	packet.AddUint8(uint8(m.Outfit.GetOutfitStyle(pul.OUTFIT_NEK)))
	packet.AddUint32(uint32(m.Outfit.GetOutfitColour(pul.OUTFIT_NEK)))
	packet.AddUint8(uint8(m.Outfit.GetOutfitStyle(pul.OUTFIT_HEAD)))
	packet.AddUint32(uint32(m.Outfit.GetOutfitColour(pul.OUTFIT_HEAD)))
	packet.AddUint8(uint8(m.Outfit.GetOutfitStyle(pul.OUTFIT_FEET)))
	packet.AddUint32(uint32(m.Outfit.GetOutfitColour(pul.OUTFIT_FEET)))
	packet.AddUint8(uint8(m.Outfit.GetOutfitStyle(pul.OUTFIT_LOWER)))
	packet.AddUint32(uint32(m.Outfit.GetOutfitColour(pul.OUTFIT_LOWER)))

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *CreatureAddMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint64(m.Creature.GetUID())
	packet.AddString(m.Creature.GetName())
	packet.AddUint16(uint16(m.Creature.GetPosition().X))
	packet.AddUint16(uint16(m.Creature.GetPosition().Y))
	packet.AddUint16(uint16(m.Creature.GetDirection()))

	// Outfit
	packet.AddUint8(uint8(m.Creature.GetOutfit().GetOutfitStyle(pul.OUTFIT_UPPER)))
	packet.AddUint32(uint32(m.Creature.GetOutfit().GetOutfitColour(pul.OUTFIT_UPPER)))
	packet.AddUint8(uint8(m.Creature.GetOutfit().GetOutfitStyle(pul.OUTFIT_NEK)))
	packet.AddUint32(uint32(m.Creature.GetOutfit().GetOutfitColour(pul.OUTFIT_NEK)))
	packet.AddUint8(uint8(m.Creature.GetOutfit().GetOutfitStyle(pul.OUTFIT_HEAD)))
	packet.AddUint32(uint32(m.Creature.GetOutfit().GetOutfitColour(pul.OUTFIT_HEAD)))
	packet.AddUint8(uint8(m.Creature.GetOutfit().GetOutfitStyle(pul.OUTFIT_UPPER)))
	packet.AddUint32(uint32(m.Creature.GetOutfit().GetOutfitColour(pul.OUTFIT_UPPER)))
	packet.AddUint8(uint8(m.Creature.GetOutfit().GetOutfitStyle(pul.OUTFIT_FEET)))
	packet.AddUint32(uint32(m.Creature.GetOutfit().GetOutfitColour(pul.OUTFIT_FEET)))
	packet.AddUint8(uint8(m.Creature.GetOutfit().GetOutfitStyle(pul.OUTFIT_LOWER)))
	packet.AddUint32(uint32(m.Creature.GetOutfit().GetOutfitColour(pul.OUTFIT_LOWER)))

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *CreatureRemoveMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint64(m.Creature.GetUID())

	return packet
}
Example #16
0
// WritePacket write the needed object data to a Packet and returns it
func (m *LoginMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())
	packet.AddUint32(uint32(m.Status))

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *SendPokemonData) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())

	for i := 0; i < 6; i++ {
		packet.AddUint8(uint8(i)) // Slot

		// Retreive pokemon from party
		pokemon := m.Pokemon.GetFromSlot(i)
		if pokemon == nil {
			packet.AddUint32(0) // Zero if slot is empty
		} else {
			pokemonLevel := pokemon.GetLevel()

			packet.AddUint32(uint32(pokemon.IdDb))                              // Database ID
			packet.AddUint16(uint16(pokemon.Base.Species.SpeciesId))            // Real ID
			packet.AddString(pokemon.GetNickname())                             // Name/Nickname
			packet.AddUint16(uint16(pokemonLevel))                              // Level
			packet.AddUint32(uint32(pokemon.Experience))                        // Current EXP
			packet.AddUint32(uint32(pkmn.ExperienceForLevel(pokemonLevel + 1))) // Exp for next level

			hpTotal := pokemon.GetTotalHp()
			hpLeft := hpTotal - pokemon.DamagedHp
			packet.AddUint16(uint16(hpLeft))
			packet.AddUint16(uint16(hpTotal))

			packet.AddUint16(uint16(pokemon.Base.Types[0]))
			packet.AddUint16(uint16(pokemon.Base.Types[1]))
			packet.AddUint16(uint16(pokemon.Nature))
			packet.AddUint8(uint8(pokemon.Gender))

			packet.AddUint8(uint8(pokemon.Stats[0]))
			packet.AddUint8(uint8(pokemon.Stats[1]))
			packet.AddUint8(uint8(pokemon.Stats[2]))
			packet.AddUint8(uint8(pokemon.Stats[3]))
			packet.AddUint8(uint8(pokemon.Stats[4]))
			packet.AddUint8(uint8(pokemon.Stats[5]))

			// Pokemon moves
			for j := 0; j < 4; j++ {
				packet.AddUint8(uint8(j))

				// Get pokemon move
				pokemonMove := pokemon.Moves[j]
				if pokemonMove == nil {
					packet.AddUint32(0)
				} else {
					packet.AddUint32(uint32(pokemonMove.Move.MoveId))
					packet.AddString(pokemonMove.Move.Identifier)
					packet.AddString(pokemonMove.Move.FlavorText)

					moveTypeStr := pkmn.GetTypeValueById(pokemonMove.Move.TypeId)
					packet.AddString(moveTypeStr)

					packet.AddUint8(uint8(pokemonMove.CurrentPP))
					packet.AddUint8(uint8(pokemonMove.Move.PP))
					packet.AddUint8(uint8(pokemonMove.Move.Power))
					packet.AddUint8(uint8(pokemonMove.Move.Accuracy))
					packet.AddUint8(uint8(pokemonMove.Move.TargetId))
				}
			}
		}
	}

	return packet
}
// WritePacket write the needed object data to a Packet and returns it
func (m *RefreshWorldMessage) WritePacket() pnet.IPacket {
	packet := pnet.NewPacketExt(m.GetHeader())

	return packet
}