def strike(instance): # Check that we can reach the target with our weapon extraReach = 0.0 if instance.tool.props.reach: extraReach = instance.tool.props.reach # If there's a cooldown we need to mark the actor Usage.set_cooldown_on_attached(instance.tool, instance.actor) # Send sight even if we miss instance.actor.send_world(Operation("sight", instance.op)) # Melee weapons only handles one target target = instance.get_arg("targets", 0) if target: # Ignore pos if instance.actor.can_reach(target, extraReach): damage = 0 if instance.tool.props.damage: damage = instance.tool.props.damage hit_op = Operation('hit', Entity(damage=damage, hit_type=instance.op.id), to=target.entity) return (server.OPERATION_BLOCKED, hit_op, Operation('sight', hit_op)) else: return (server.OPERATION_BLOCKED, instance.actor.client_error(instance.op, "Too far away")) else: return (server.OPERATION_BLOCKED)
def shoot_in_direction(direction, instance, res): Usage.set_cooldown_on_attached(instance.tool, instance.actor) arrows = instance.actor.find_in_contains(arrow_filter) if len(arrows): direction.normalize() # Adjust the start position of the arrow, so it's outside of the actor, at mid height start_adjust = Vector3D(direction) start_adjust.y = 0 start_adjust.normalize() start_adjust.y = instance.actor.location.bbox.high_corner.y * 0.8 new_loc = instance.actor.location.copy() new_loc.pos += start_adjust new_loc.orientation = Quaternion(Vector3D(0, 0, 1), direction, Vector3D(1, 0, 0)) mode_data = {"mode": "projectile", "$eid": instance.actor.id, "extra": {"damage": 20}} # TODO: match with animation in client res.append(instance.actor.start_action("bow/releasing", 1)) res.append(Operation("move", Entity(arrows[0].id, location=new_loc, velocity=direction * 60, mode="projectile", mode_data=mode_data), to=arrows[0].id))
def do_strike(self): self.usage.actor.send_world(Operation("sight", self.usage.op)) # If there's a cooldown we need to mark the actor Usage.set_cooldown_on_attached(self.usage.tool, self.usage.actor) target = self.usage.get_arg("targets", 0) if target: # Take a swing # Check that we can reach the target with our weapon extra_reach = 0.0 if self.usage.tool.props.reach: extra_reach = self.usage.tool.props.reach if self.usage.actor.can_reach(target, extra_reach): damage = 0 if self.usage.tool.props.damage: damage = self.usage.tool.props.damage hit_op = Operation('hit', Entity(damage=damage, hit_type=self.usage.op.parent, id=self.usage.actor.id), to=target.entity) return server.OPERATION_BLOCKED, hit_op else: return server.OPERATION_BLOCKED, self.usage.actor.client_error(self.usage.op, "Too far away") else: print("No target") return server.OPERATION_BLOCKED
def strike(instance): # Check that we can reach the target with our weapon extra_reach = 0.0 if instance.tool.props.reach: extra_reach = instance.tool.props.reach # If there's a cooldown we need to mark the actor Usage.set_cooldown_on_attached(instance.tool, instance.actor) # Send sight even if we miss instance.actor.send_world(Operation("sight", instance.op)) # Melee weapons only handles one target target = instance.get_arg("targets", 0) if target: # Ignore pos if instance.actor.can_reach(target, extra_reach): damage = 0 if instance.tool.props.damage: damage = instance.tool.props.damage hit_op = Operation('hit', Entity(damage=damage, hit_type=instance.op.id), to=target.entity) return server.OPERATION_BLOCKED, hit_op, Operation('sight', hit_op) else: return server.OPERATION_BLOCKED, instance.actor.client_error(instance.op, "Too far away") else: return server.OPERATION_BLOCKED
def shoot_poison_in_direction(direction, instance, res): Usage.set_cooldown_on_attached(instance.tool, instance.actor) direction.normalize() # Adjust the start position of the projectile, so it's outside of the actor, at mid height start_adjust = Vector3D(direction) start_adjust.y = 0 start_adjust.normalize() start_adjust.y = instance.actor.location.bbox.high_corner.y * 0.8 new_loc = instance.actor.location.copy() new_loc.pos += start_adjust new_loc.orientation = Quaternion(Vector3D(0, 0, 1), direction, Vector3D(1, 0, 0)) mode_data = {"mode": "projectile", "$eid": instance.actor.id} res.append( Operation("create", Entity(parent="poisonball", location=new_loc, velocity=direction * 60, mode="projectile", mode_data=mode_data, damage_poison=instance.tool.props.damage), to=instance.tool.id))
def ignite(instance): Usage.set_cooldown_on_attached(instance.tool, instance.actor) target = instance.get_arg("targets", 0) if instance.actor.can_reach(target): return server.OPERATION_BLOCKED, Operation("create", Entity(parent='fire', status=0.05, location=Location(target.entity), pos=[0, 0, 0]), to=target.entity) else: return server.OPERATION_BLOCKED, instance.actor.client_error(instance.op, "Too far away")
def sow(instance): Usage.set_cooldown_on_attached(instance.tool, instance.actor) task = Cultivate(instance, duration=11, tick_interval=1, name="Cultivate") instance.actor.send_world(Operation("sight", instance.op)) return (server.OPERATION_BLOCKED, instance.actor.start_task('cultivate', task))
def sow(instance): Usage.set_cooldown_on_attached(instance.tool, instance.actor) task = Cultivate(instance, duration=11, tick_interval=1, name="Cultivate") instance.actor.send_world(Operation("sight", instance.op)) return server.OPERATION_BLOCKED, instance.actor.start_task( 'cultivate', task)
def ignite(instance): Usage.set_cooldown_on_attached(instance.tool, instance.actor) target = instance.get_arg("targets", 0) if instance.actor.can_reach(target): return server.OPERATION_BLOCKED, \ Operation("create", Entity(parent='fire', status=0.05, location=Location(target.entity), pos=[0, 0, 0]), to=target.entity) else: return server.OPERATION_BLOCKED, instance.actor.client_error( instance.op, "Too far away")
def strike(instance): """Strike another entity with your body (fists, fangs, talons etc.).""" tick_interval = getattr(instance.tool.props, "cooldown_" + instance.op.parent) if tick_interval is not None: task = Usage.delay_task_if_needed( Fight(instance, tick_interval=tick_interval, name="Unarmed")) else: task = Usage.delay_task_if_needed(Fight(instance, name="Unarmed")) task_op = instance.actor.start_task('melee', task) return server.OPERATION_BLOCKED, task_op
def strike(instance): """Strike another entity with a weapon.""" # Melee weapons only handles one target tick_interval = instance.tool.get_prop_float("cooldown") if tick_interval is not None: task = Usage.delay_task_if_needed( Melee(instance, tick_interval=tick_interval, name="Melee")) else: task = Usage.delay_task_if_needed(Melee(instance, name="Melee")) task_op = instance.actor.start_task('melee', task) return server.OPERATION_BLOCKED, task_op
def use(instance): usage_name = instance.op.parent task = Usage.delay_task_if_needed( Use(instance, duration=5, tick_interval=1, name=usage_name.capitalize())) Usage.set_cooldown_on_attached(instance.tool, instance.actor) instance.actor.send_world(Operation("sight", instance.op)) return server.OPERATION_BLOCKED, instance.actor.start_task( usage_name, task)
def draw(instance): usage_name = instance.op.parent task = Usage.delay_task_if_needed(DrawBow(instance, tick_interval=1, name="Draw")) instance.actor.send_world(Operation("sight", instance.op)) return server.OPERATION_BLOCKED, instance.actor.start_task(usage_name, task)
def draw(instance): usage_name = instance.op.parent warmup = instance.tool.get_prop_float("warmup", 1.0) task = Usage.delay_task_if_needed(DrawBow(instance, tick_interval=warmup, name="Draw")) instance.actor.send_world(Operation("sight", instance.op)) return server.OPERATION_BLOCKED, instance.actor.start_task(usage_name, task)
def fish(instance): usage_name = instance.op.parent task = Usage.delay_task_if_needed( Fishing(instance, tick_interval=2, name="Fishing")) instance.actor.send_world(Operation("sight", instance.op)) return server.OPERATION_BLOCKED, instance.actor.start_task( usage_name, task)
def strike(instance): """Strike another entity with a weapon.""" # Check that we can reach the target with our weapon extra_reach = 0.0 if instance.tool.props.reach: extra_reach = instance.tool.props.reach # If there's a cooldown we need to mark the actor Usage.set_cooldown_on_attached(instance.tool, instance.actor) # Send sight even if we miss instance.actor.send_world(Operation("sight", instance.op)) # Melee weapons only handles one target target = instance.get_arg("targets", 0) if target: cooldown_prop = instance.tool.props.cooldown if cooldown_prop: task = Melee(instance, tick_interval=cooldown_prop, name="Melee") task_op = instance.actor.start_task('melee', task) else: task_op = None # Ignore pos if instance.actor.can_reach(target, extra_reach): damage = 0 if instance.tool.props.damage: damage = instance.tool.props.damage hit_op = Operation('hit', Entity(damage=damage, hit_type=instance.op.parent, id=instance.actor.id), to=target.entity) return server.OPERATION_BLOCKED, hit_op, task_op else: return server.OPERATION_BLOCKED, instance.actor.client_error( instance.op, "Too far away"), task_op else: return server.OPERATION_BLOCKED