mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-21 04:57:57 +01:00
[MIRROR] Monkey subtree breakup refactor! [MDB IGNORE] (#8748)
* Monkey subtree breakup refactor! (#61741) Splitting up monkey ai into subtrees allows me to make a punpun ai after this pr is merged, makes stopping planning matter for the AI subtrees, and more generic subtrees that can be used by most ais It also gets rid of bad practices like setting blackboards in the ai controller. * Monkey subtree breakup refactor! Co-authored-by: tralezab <40974010+tralezab@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/datum/ai_planning_subtree/cursed/SelectBehaviors(datum/ai_controller/controller, delta_time)
|
||||
var/obj/item/item_pawn = controller.pawn
|
||||
|
||||
//make sure we have a target
|
||||
var/mob/living/carbon/curse_target = controller.blackboard[BB_ITEM_TARGET]
|
||||
|
||||
if(curse_target && get_dist(curse_target, item_pawn) > ITEM_AGGRO_VIEW_RANGE)
|
||||
controller.blackboard[BB_ITEM_TARGET] = null
|
||||
return
|
||||
|
||||
if(!controller.blackboard[BB_ITEM_TARGET])
|
||||
controller.queue_behavior(/datum/ai_behavior/find_and_set/item_target, BB_ITEM_TARGET, /mob/living/carbon, ITEM_AGGRO_VIEW_RANGE)
|
||||
|
||||
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/ghostly, BB_ITEM_TARGET, BB_ITEM_THROW_ATTEMPT_COUNT)
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
///This behavior is for obj/items, it is used to free themselves out of the hands of whoever is holding them
|
||||
/datum/ai_behavior/item_escape_grasp
|
||||
|
||||
/datum/ai_behavior/item_escape_grasp/perform(delta_time, datum/ai_controller/controller)
|
||||
. = ..()
|
||||
var/obj/item/item_pawn = controller.pawn
|
||||
var/mob/item_holder = item_pawn.loc
|
||||
if(!istype(item_holder))
|
||||
finish_action(controller, FALSE) //We're no longer beind held. abort abort!!
|
||||
item_pawn.visible_message(span_warning("[item_pawn] slips out of the hands of [item_holder]!"))
|
||||
item_holder.dropItemToGround(item_pawn, TRUE)
|
||||
finish_action(controller, TRUE)
|
||||
|
||||
///This behavior is for obj/items, it is used to move closer to a target and throw themselves towards them.
|
||||
/datum/ai_behavior/item_move_close_and_attack
|
||||
required_distance = 3
|
||||
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT
|
||||
action_cooldown = 20
|
||||
///Sound to use
|
||||
var/attack_sound
|
||||
///Max attempts to make
|
||||
var/max_attempts = 3
|
||||
|
||||
|
||||
/datum/ai_behavior/item_move_close_and_attack/setup(datum/ai_controller/controller, aggro_list_key, target_key, throw_count_key)
|
||||
. = ..()
|
||||
controller.current_movement_target = controller.blackboard[target_key]
|
||||
|
||||
|
||||
/datum/ai_behavior/item_move_close_and_attack/perform(delta_time, datum/ai_controller/controller, aggro_list_key, target_key, throw_count_key)
|
||||
. = ..()
|
||||
var/obj/item/item_pawn = controller.pawn
|
||||
var/atom/throw_target = controller.blackboard[target_key]
|
||||
|
||||
item_pawn.visible_message(span_warning("[item_pawn] hurls towards [throw_target]!"))
|
||||
item_pawn.throw_at(throw_target, rand(4,5), 9)
|
||||
playsound(item_pawn.loc, attack_sound, 100, TRUE)
|
||||
controller.blackboard[throw_count_key]++
|
||||
if(controller.blackboard[throw_count_key] >= max_attempts)
|
||||
finish_action(controller, TRUE, target_key, throw_count_key)
|
||||
|
||||
/datum/ai_behavior/item_move_close_and_attack/finish_action(datum/ai_controller/controller, succeeded, aggro_list_key, target_key, throw_count_key)
|
||||
. = ..()
|
||||
var/atom/throw_target = controller.blackboard[target_key]
|
||||
|
||||
controller.blackboard -= target_key
|
||||
controller.blackboard[throw_count_key] = 0
|
||||
if(aggro_list_key)
|
||||
var/list/aggro_list = controller.blackboard[aggro_list_key]
|
||||
aggro_list[throw_target]--
|
||||
|
||||
/datum/ai_behavior/item_move_close_and_attack/ghostly
|
||||
attack_sound = 'sound/items/haunted/ghostitemattack.ogg'
|
||||
max_attempts = 4
|
||||
Reference in New Issue
Block a user