def on_weapon_input_recieved(self, contained: loaders.WeaponInput) -> None: if not self.hp: return primary = contained.primary secondary = contained.secondary if self.world_object.primary_fire != primary: # player has pressed or released primary fire if self.tool == WEAPON_TOOL: self.weapon_object.set_shoot(primary) if self.tool == WEAPON_TOOL or self.tool == SPADE_TOOL: self.on_shoot_set(primary) if self.world_object.secondary_fire != secondary: # player has pressed or released secondary fire self.on_secondary_fire_set(secondary) if secondary and self.tool == BLOCK_TOOL: # hook into here to save the start location of the line build. # This is needed so we can check if the player was actually at # the starting location of the line build when it was started. # this is inspired by 1AmYF's fbpatch2.py script position = self.world_object.position self.line_build_start_pos = position.copy() self.on_line_build_start() # remember the current state of the mouse buttons self.world_object.primary_fire = primary self.world_object.secondary_fire = secondary if self.filter_weapon_input: return contained.player_id = self.player_id self.protocol.send_contained(contained, sender=self)
def flush_input(self): input = self.input world_object = self.world_object z_vel = world_object.velocity.z if "jump" in input and not (z_vel >= 0.0 and z_vel < 0.017): input.discard("jump") input_changed = not (("up" in input) == world_object.up and ("down" in input) == world_object.down and ("left" in input) == world_object.left and ("right" in input) == world_object.right and ("jump" in input) == world_object.jump and ("crouch" in input) == world_object.crouch and ("sneak" in input) == world_object.sneak and ("sprint" in input) == world_object.sprint) if input_changed: if not self.freeze_animation: world_object.set_walk( "up" in input, "down" in input, "left" in input, "right" in input, ) world_object.set_animation( "jump" in input, "crouch" in input, "sneak" in input, "sprint" in input, ) if not self.filter_visibility_data and not self.filter_animation_data: input_data = InputData() input_data.player_id = self.player_id input_data.up = world_object.up input_data.down = world_object.down input_data.left = world_object.left input_data.right = world_object.right input_data.jump = world_object.jump input_data.crouch = world_object.crouch input_data.sneak = world_object.sneak input_data.sprint = world_object.sprint self.protocol.send_contained(input_data) primary = "primary_fire" in input secondary = "secondary_fire" in input shoot_changed = not (primary == world_object.primary_fire and secondary == world_object.secondary_fire) if shoot_changed: if primary != world_object.primary_fire: if self.tool == WEAPON_TOOL: self.weapon_object.set_shoot(primary) if self.tool == WEAPON_TOOL or self.tool == SPADE_TOOL: self.on_shoot_set(primary) world_object.primary_fire = primary world_object.secondary_fire = secondary if not self.filter_visibility_data: weapon_input = WeaponInput() weapon_input.player_id = self.player_id weapon_input.primary = primary weapon_input.secondary = secondary self.protocol.send_contained(weapon_input) input.clear()
def on_weapon_input_recieved(self, contained: loaders.WeaponInput) -> None: if not self.hp: return primary = contained.primary secondary = contained.secondary if self.world_object.primary_fire != primary: if self.tool == WEAPON_TOOL: self.weapon_object.set_shoot(primary) if self.tool == WEAPON_TOOL or self.tool == SPADE_TOOL: self.on_shoot_set(primary) if self.world_object.secondary_fire != secondary: self.on_secondary_fire_set(secondary) self.world_object.primary_fire = primary self.world_object.secondary_fire = secondary if self.filter_weapon_input: return contained.player_id = self.player_id self.protocol.send_contained(contained, sender=self)