Files
Bubberstation/code/datums/ai/basic_mobs/basic_subtrees/maintain_distance.dm
Ben10Omintrix 032419f30f ice demon basic mobs (#78539)
## About The Pull Request
ice demons are now basic mobs. they still have their behavior where they
can teleport around the player, run away from him and shoot him. they
now also have a new ability they will only use when they are on their
last legs, they will spawn weak and slow afterimage clones of
theirselves to attack the player. damaging these clones will also damage
the original ice demons. ice demons can also now be very easily
countered as they are very afraid of fires. they will run away from you
if they see u holding a lit torch/flare/welding tool and while running
away they will freeze the floors around them to try to slip u to stop u
from chasing them. ice demons now also get a new unique trophy! this
trophy will summon 2 friendly spirits that will help you kill ur target,
but these spirits will dissappear after a very short while.


https://github.com/tgstation/tgstation/assets/138636438/6a48fb15-f447-441a-91c6-48ca120dc22c



## Why It's Good For The Game
## Changelog
🆑
refactor: ice demons have been refactored into basic mbos. please report
any bugs
add: ice demons now have a unique trophy
/🆑
2023-10-08 03:04:35 +01:00

117 lines
4.7 KiB
Plaintext

/// Step away if too close, or towards if too far
/datum/ai_planning_subtree/maintain_distance
/// Blackboard key holding atom we want to stay away from
var/target_key = BB_BASIC_MOB_CURRENT_TARGET
/// How close will we allow our target to get?
var/minimum_distance = 4
/// How far away will we allow our target to get?
var/maximum_distance = 6
/// How far do we look for our target?
var/view_distance = 10
/// the run away behavior we will use
var/run_away_behavior = /datum/ai_behavior/step_away
/datum/ai_planning_subtree/maintain_distance/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
. = ..()
var/atom/target = controller.blackboard[target_key]
if (!isliving(target) || !can_see(controller.pawn, target, view_distance))
return // Don't run away from cucumbers, they're not snakes
var/range = get_dist(controller.pawn, target)
if (range < minimum_distance)
controller.queue_behavior(run_away_behavior, target_key, minimum_distance)
return
if (range > maximum_distance)
controller.queue_behavior(/datum/ai_behavior/pursue_to_range, target_key, maximum_distance)
return
/datum/ai_planning_subtree/maintain_distance/cover_minimum_distance
run_away_behavior = /datum/ai_behavior/cover_minimum_distance
/// Take one step away
/datum/ai_behavior/step_away
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION
required_distance = 0
action_cooldown = 0.2 SECONDS
/datum/ai_behavior/step_away/setup(datum/ai_controller/controller, target_key)
. = ..()
var/atom/current_target = controller.blackboard[target_key]
if (QDELETED(current_target))
return FALSE
var/mob/living/our_pawn = controller.pawn
our_pawn.face_atom(current_target)
var/turf/next_step = get_step_away(controller.pawn, current_target)
if (!isnull(next_step) && !next_step.is_blocked_turf(exclude_mobs = TRUE))
set_movement_target(controller, target = next_step, new_movement = /datum/ai_movement/basic_avoidance/backstep)
return TRUE
var/list/all_dirs = GLOB.alldirs.Copy()
all_dirs -= get_dir(controller.pawn, next_step)
all_dirs -= get_dir(controller.pawn, current_target)
shuffle_inplace(all_dirs)
for (var/dir in all_dirs)
next_step = get_step(controller.pawn, dir)
if (!isnull(next_step) && !next_step.is_blocked_turf(exclude_mobs = TRUE))
set_movement_target(controller, target = next_step, new_movement = /datum/ai_movement/basic_avoidance/backstep)
return TRUE
return FALSE
/datum/ai_behavior/step_away/perform(seconds_per_tick, datum/ai_controller/controller)
. = ..()
finish_action(controller, succeeded = TRUE)
/datum/ai_behavior/step_away/finish_action(datum/ai_controller/controller, succeeded)
. = ..()
controller.change_ai_movement_type(initial(controller.ai_movement))
/// Pursue a target until we are within a provided range
/datum/ai_behavior/pursue_to_range
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION | AI_BEHAVIOR_MOVE_AND_PERFORM
/datum/ai_behavior/pursue_to_range/setup(datum/ai_controller/controller, target_key, range)
. = ..()
var/atom/current_target = controller.blackboard[target_key]
if (QDELETED(current_target))
return FALSE
if (get_dist(controller.pawn, current_target) <= range)
return FALSE
set_movement_target(controller, current_target)
/datum/ai_behavior/pursue_to_range/perform(seconds_per_tick, datum/ai_controller/controller, target_key, range)
var/atom/current_target = controller.blackboard[target_key]
if (!QDELETED(current_target) && get_dist(controller.pawn, current_target) > range)
return
finish_action(controller, succeeded = TRUE)
///instead of taking a single step, we cover the entire distance
/datum/ai_behavior/cover_minimum_distance
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION
required_distance = 0
action_cooldown = 0.2 SECONDS
/datum/ai_behavior/cover_minimum_distance/setup(datum/ai_controller/controller, target_key, minimum_distance)
. = ..()
var/atom/target = controller.blackboard[target_key]
if(QDELETED(target))
return FALSE
var/required_distance = minimum_distance - get_dist(controller.pawn, target) //the distance we need to move
var/distance = 0
var/turf/chosen_turf
for(var/turf/open/potential_turf in oview(required_distance, controller.pawn))
var/new_distance_from_target = get_dist(potential_turf, target)
if(potential_turf.is_blocked_turf())
continue
if(new_distance_from_target > distance)
chosen_turf = potential_turf
distance = new_distance_from_target
if(isnull(chosen_turf))
return FALSE
set_movement_target(controller, target = chosen_turf)
/datum/ai_behavior/cover_minimum_distance/perform(seconds_per_tick, datum/ai_controller/controller, target_key)
. = ..()
finish_action(controller, succeeded = TRUE)