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 = 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())) vector = entity.getPosition() - self.getPosition() range = self.range if self.zoomed: range *= 1.5 p.add( net.Uint16(self.damage * max( 0, 1 - (vector.length() / range) * max(0, normal.dot(-direction) * 1.25)))) 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() 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