Esempio n. 1
0
func LoadWorldmap(_hood *hood.Hood) {
	if loaded {
		panic("Worldmap has already been loaded!")
	}

	// Load maps
	var maps []entities.Map
	if err := _hood.Find(&maps); err != nil {
		panic(err)
	}

	if len(maps) > 0 {
		for _, mapEntity := range maps {
			mapId := int(mapEntity.MapId)
			worldmap[mapId] = NewTilePointTable(mapEntity.Name)
		}

		numOfProcessRoutines = len(maps)
		go internalLoadWorldmap(_hood)

		waitForLoadComplete()
	} else {
		log.Warning("World", "LoadWorldmap", "No maps found in the database")
	}

	loaded = true
}
Esempio n. 2
0
/***********************
	Private Methods
************************/
func internalAddCreature(_creature interfaces.ICreature) bool {
	_, found := g.creatures[_creature.GetUID()]

	if !found {
		g.creatures[_creature.GetUID()] = _creature
	} else {
		log.Warning("Game", "AddCreature", "Could not add creature. Creature with UID '%d' already exists", _creature.GetUID())
	}

	return !found
}
Esempio n. 3
0
// Entrance method for new websocket connections
func clientConnection(clientsock *websocket.Conn) {
	packet := pnet.NewPacket()
	buffer := make([]uint8, pnet.PACKET_MAXSIZE)
	recv, err := clientsock.Read(buffer)
	if err == nil {
		copy(packet.Buffer[0:recv], buffer[0:recv])
		packet.GetHeader()
		parseFirstMessage(clientsock, packet)
	} else {
		if err.Error() != "EOF" {
			log.Warning("GameServer", "clientConnection", "Client connection error: %v", err.Error())
		}
	}
}
Esempio n. 4
0
func NewPlayerPokemon(_hood *hood.Hood, _entity *entities.PlayerPokemon) *PlayerPokemon {
	p := &PlayerPokemon{}
	p.Entity = _entity

	if basePokemon, found := pokemon.GetPokemonById(_entity.PokemonId); found {
		p.BasePokemon = basePokemon
	} else {
		log.Warning("PlayerPokemon", "NewPlayerPokemon", "Unable to find Pokemon with id %d, for PlayerPokemon entity: %d", _entity.PokemonId, _entity.PlayerPokemonId)
		p = nil
	}

	if p != nil {
		p.loadMoves(_hood)
	}

	return p
}
Esempio n. 5
0
func (p *Player) netReceiveMessages() {
	for {
		netmessage := <-p.rxChan
		if netmessage == nil {
			break
		}

		switch netmessage.GetHeader() {
		case pnet.HEADER_LOGIN:
			p.netSendPlayerData()
		case pnet.HEADER_WALK:
			p.netHeaderWalk(netmessage.(*netmsg.WalkMessage))
		case pnet.HEADER_TURN:
			p.netHeaderTurn(netmessage.(*netmsg.TurnMessage))
		default:
			log.Warning("Player", "netReceiveMessages", "No handler for messages with header %d", netmessage.GetHeader())
		}
	}
}
Esempio n. 6
0
func (cw *ConnectionWrapper) processPacket(_packet pnet.IPacket) {
	header, err := _packet.ReadUint8()
	if err != nil {
		return
	}

	var netmessage pnet.INetMessageReader
	if header == pnet.HEADER_WALK {
		netmessage = netmsg.NewWalkMessage(nil)
		netmessage.ReadPacket(_packet)
	} else {
		log.Warning("ConnectionWrapper", "processPacket", "Received packet with unknown header: %d", header)
	}

	// Push netmessage on rxChan
	if netmessage != nil {
		cw.rxChan <- netmessage
	}
}