def serverUpdate(self, aiWorld, entityGroup, packetUpdate): p = Weapon.serverUpdate(self, aiWorld, entityGroup, packetUpdate) if self.reloadStarted: self.addCriticalPacket(p, packetUpdate) self.reloadStarted = False self.reloadActive = self.newReloadActive self.activeSound = 0 # No sound if self.reloadActive: if engine.clock.time - self.lastReload < self.reloadTime: self.activeSound = 1 # Reload beep sound else: self.ammo = self.clipSize self.reloadActive = False self.newReloadActive = False self.activeSound = 2 # Reload ready sound self.addCriticalPacket(p, packetUpdate) p.add(net.Uint8(self.activeSound)) p.add(net.Boolean(self.selected)) self.ammo += self.ammoAdditions self.ammoAdditions = 0 if self.selected: p.add(net.Uint8(self.ammo)) return p
def serverUpdate(self, aiWorld, entityGroup, packetUpdate): p = Weapon.serverUpdate(self, aiWorld, entityGroup, packetUpdate) if self.firing and self.active: self.addCriticalPacket(p, packetUpdate) p.add(net.Uint8(1)) # 1 = We're starting to impale an entity enemy = aiWorld.getNearestEnemy(entityGroup, self.actor.getPosition(), self.actor.getTeam(), includeCloakedUnits=True) if enemy != None: vector = self.actor.controller.targetPos - base.camera.getPos() vector2 = enemy.getPosition() - base.camera.getPos() vector3 = enemy.getPosition() - self.actor.getPosition() vector.normalize() vector2.normalize() if math.acos(vector.getX() * vector2.getX() + vector.getY() * vector2.getY() + vector.getZ() * vector2.getZ() ) < math.pi / 5 and vector3.length() < 8: p.add(net.Boolean(True)) vector3.normalize() self.actor.addForce(engine.impulseToForce(vector3 * 1000)) self.impulseVector = vector3 self.impaleTarget = enemy else: p.add(net.Boolean(False)) else: p.add(net.Boolean(False)) self.firing = False elif self.active and self.impaleStart != -1 and self.impaleTarget != None and self.impaleTarget.active and ( self.actor.getPosition() - self.impaleTarget.getPosition() ).length() < self.actor.radius + self.impaleTarget.radius + 0.5: self.addCriticalPacket(p, packetUpdate) # At this point, the blade is actually in the target. p.add(net.Uint8(2)) # 2 = We're now actually damaging the entity p.add(net.Uint8(self.impaleTarget.getId())) # Stop the player from flying past the target. if self.impaleTarget.health > self.damage: # Only add force if we don't kill the target. If the target dies, the explosion will already push us away. self.actor.addForce( engine.impulseToForce(self.impulseVector * -800)) self.impaleTarget = None else: p.add(net.Uint8(0)) # 0 = Nothing's happening 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() 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 = Weapon.serverUpdate(self, aiWorld, entityGroup, packetUpdate) p.add(net.Boolean(self.firing)) if self.firing: self.addCriticalPacket(p, packetUpdate) direction = self.actor.controller.targetPos - self.actor.getPosition( ) direction.normalize() direction.setZ(direction.getZ() + 0.5) direction.normalize() origin = self.actor.getPosition() + (direction * (self.actor.radius + 0.1)) grenade = entities.Molotov(aiWorld.world, aiWorld.space) grenade.setTeam(self.actor.getTeam()) grenade.setActor(self.actor) grenade.setPosition(origin) grenade.setLinearVelocity(direction * 40) entityGroup.spawnEntity(grenade) p.add(net.Uint8(grenade.getId())) 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