def serverUpdate(self, aiWorld, entityGroup, packetUpdate): p = Gun.serverUpdate(self, aiWorld, entityGroup, packetUpdate) if self.active and self.firing: self.addCriticalPacket(p, packetUpdate) p.add(net.Boolean(True)) vector = self.actor.controller.targetPos - self.actor.getPosition() pos = vector.cross(Vec3(0, 0, 1)) pos.normalize() origin = self.actor.getPosition() + (pos * (self.actor.radius + 0.1)) direction = self.actor.controller.targetPos - origin direction.normalize() if self.zoomed: angleX = uniform(-0.5, 0.5) angleY = uniform(-0.5, 0.5) else: angleX = uniform(-2, 2) angleY = uniform(-2, 2) mat = Mat3() mat.setRotateMatNormaxis( angleX, render.getRelativeVector(self.node, Vec3(0, 0, 1))) direction = mat.xformVec(direction) mat = Mat3() mat.setRotateMatNormaxis( angleY, render.getRelativeVector(self.node, Vec3(1, 0, 0))) direction = mat.xformVec(direction) p.add(net2.StandardVec3(direction)) entity = None hitPos = None if direction.length() > 0: entity, hitPos, normal, queue = self.bulletTest( aiWorld, entityGroup, origin, direction) if hitPos == None: p.add(net.Boolean(False)) # Bullet didn't hit anything else: p.add(net.Boolean(True)) # Bullet hit something p.add(net2.StandardVec3(hitPos)) if entity != None: p.add(net.Boolean(True)) p.add(net.Uint8(entity.getId())) p.add( net.Uint16(self.damage * max(0, 1 - (vector.length() / 70)) * max(0, normal.dot(-direction) + 0.1))) else: p.add(net.Boolean(False)) else: p.add(net.Boolean(False)) self.firing = False return p
def serverUpdate(self, aiWorld, entityGroup, packetUpdate): p = Gun.serverUpdate(self, aiWorld, entityGroup, packetUpdate) if self.active and self.firing: self.addCriticalPacket(p, packetUpdate) p.add(net.Boolean(True)) vector = self.actor.controller.targetPos - self.actor.getPosition() pos = vector.cross(Vec3(0, 0, 1)) pos.normalize() origin = self.actor.getPosition() + (pos * (self.actor.radius + 0.1)) direction = self.actor.controller.targetPos - origin direction.normalize() p.add(net2.StandardVec3(direction)) entity, hitPos, normal, queue = self.bulletTest( aiWorld, entityGroup, origin, direction) if hitPos == None: p.add(net.Boolean(False)) # Bullet didn't hit anything else: p.add(net.Boolean(True)) # Bullet hit something p.add(net2.StandardVec3(hitPos)) if entity != None: p.add(net.Boolean(True)) p.add(net.Uint8(entity.getId())) dot = normal.dot(-direction) if dot > 0.95: p.add(net.Uint16(self.damage * 4)) else: p.add(net.Uint16(self.damage * max(0, dot * 1.5))) else: p.add(net.Boolean(False)) else: p.add(net.Boolean(False)) self.firing = False return p
def connectTo(ip, port=None): if port == None: if ip.find(":") != -1: ip, port = ip.split(":") else: port = 1337 port = int(port) engine.log.info("Notifying lobby server of intention to connect to " + ip + ":" + str(port)) p = net.Packet() p.add(net.Uint8(net.PACKET_CLIENTCONNECTNOTIFICATION)) p.add(net.String(ip)) p.add(net.Uint16(port)) net.context.send(p, address)
def serverUpdate(self, aiWorld, entityGroup, packetUpdate): p = Gun.serverUpdate(self, aiWorld, entityGroup, packetUpdate) if self.active and self.firing: self.addCriticalPacket(p, packetUpdate) p.add(net.Boolean(True)) vector = self.actor.controller.targetPos - self.actor.getPosition() pos = vector.cross(Vec3(0, 0, 1)) pos.normalize() origin = self.actor.getPosition() + (pos * (self.actor.radius + 0.1)) direction = self.actor.controller.targetPos - origin direction.normalize() inaccuracy = 0.5 if self.zoomed else 1.5 angleX = uniform(-inaccuracy, inaccuracy) angleY = uniform(-inaccuracy, inaccuracy) mat = Mat3() mat.setRotateMatNormaxis( angleX, render.getRelativeVector(self.node, Vec3(0, 0, 1))) direction = mat.xformVec(direction) mat = Mat3() mat.setRotateMatNormaxis( angleY, render.getRelativeVector(self.node, Vec3(1, 0, 0))) direction = mat.xformVec(direction) p.add(net2.StandardVec3(direction)) entity = None hitPos = None if direction.length() > 0: entity, hitPos, normal, queue = self.bulletTest( aiWorld, entityGroup, origin, direction) if hitPos == None: p.add(net.Boolean(False)) # Bullet didn't hit anything else: p.add(net.Boolean(True)) # Bullet hit something p.add(net2.StandardVec3(hitPos)) if entity != None: p.add(net.Boolean(True)) p.add(net.Uint8(entity.getId())) totalDamage = self.damage * max( 0, 1 - (vector.length() / 200)) * max( 0, normal.dot(-direction) + 0.1) p.add(net.Uint16(totalDamage)) pinned = False if isinstance(entity, entities.BasicDroid): for i in range(queue.getNumEntries()): entry = queue.getEntry(i) pos = entry.getSurfacePoint(render) testEntity = entityGroup.getEntityFromEntry(entry) if testEntity == None and (pos - hitPos).length() < 5: p.add(net.Boolean(True)) p.add(net2.HighResVec3(pos)) pinned = True break if not pinned: p.add(net.Boolean(False)) p.add(net2.HighResVec3(hitPos)) else: p.add(net.Boolean(False)) else: p.add(net.Boolean(False)) self.firing = False return p