def handleWSMessage(self,message): packet = packets.messageToPacket(message) if isinstance(packet,packets.SetTargetPacket): if self.isStopVector(packet.getTargetVector()): self.goal = None self.velocity = Vector() return goalVector = packet.getTargetVector() self.goal = Goal(self.game,goalVector) self.goal.calculatePath(self.position) if (self.recordingPath): locTuple = goalVector.toTuple() self.recordedPath.append(locTuple) elif isinstance(packet,packets.SetTargetEntityPacket): targetId = packet.targetId targetEntity = self.game.getEntityById(targetId) if targetEntity != None: self.target = targetEntity elif isinstance(packet,packets.ChatRecvPacket): message = packet.message if (message == "recordpath"): self.recordingPath = not self.recordingPath if (message == "printpath"): jsonString = json.dumps(self.recordedPath) print(jsonString) message = "%s: %s" % (self.username,message) self.game.sendPacketToAll(packets.ChatPacket(message))
def on_message(self,message): if hasattr(self,'clientId'): game.onMsg(self.clientId,message) else: packet = packets.messageToPacket(message) if isinstance(packet,packets.ReconnectPacket): player = game.entitiesById[packet.entityId] player.sendMessageFunction = self.sendFunction player.hasConnection = True if isinstance(packet,packets.LoginPacket): username = packet.name champ = packet.champ team = packet.team self.clientId = game.connectPlayer(username,team,champ,self.sendFunction) print("connected client", self.clientId, username)
def handleWSMessage(self,message): super().handleWSMessage(message) packet = packets.messageToPacket(message) if isinstance(packet,packets.CastSpell): self.performSpell(packet.spell,packet)