|
| 1 | +/** |
| 2 | + * A testing object used to control mobs in game tests. |
| 3 | + * |
| 4 | + * Puppeteers provide an easy way to create mobs and objects, |
| 5 | + * perform interactions in the same way that a player would, |
| 6 | + * and check the state of the mob during tests. |
| 7 | + */ |
| 8 | +/datum/test_puppeteer |
| 9 | + var/mob/living/carbon/puppet |
| 10 | + var/datum/game_test/origin_test |
| 11 | + |
| 12 | +/datum/test_puppeteer/New(datum/game_test/origin_test_, carbon_type = /mob/living/carbon/human, turf/initial_location) |
| 13 | + if(!ispath(carbon_type, /mob/living/carbon/human)) |
| 14 | + origin_test.Fail("unexpected puppeteer carbon type [carbon_type]", __FILE__, __LINE__) |
| 15 | + |
| 16 | + if(!initial_location) |
| 17 | + initial_location = locate(179, 136, 1) // Center of admin testing area |
| 18 | + origin_test = origin_test_ |
| 19 | + puppet = origin_test.allocate(carbon_type, initial_location) |
| 20 | + var/datum/mind/new_mind = new("interaction_test_[puppet.UID()]") |
| 21 | + new_mind.transfer_to(puppet) |
| 22 | + |
| 23 | +/datum/test_puppeteer/proc/spawn_puppet_nearby(carbon_type = /mob/living/carbon/human) |
| 24 | + for(var/turf/T in RANGE_TURFS(1, puppet.loc)) |
| 25 | + if(!is_blocked_turf(T, exclude_mobs = FALSE)) |
| 26 | + return new/datum/test_puppeteer(origin_test, carbon_type, T) |
| 27 | + |
| 28 | + origin_test.Fail("could not spawn puppeteer near [src]") |
| 29 | + |
| 30 | +/datum/test_puppeteer/proc/spawn_obj_in_hand(obj_type) |
| 31 | + var/obj/new_obj = origin_test.allocate(obj_type, null) |
| 32 | + if(puppet.put_in_hands(new_obj)) |
| 33 | + return new_obj |
| 34 | + |
| 35 | + origin_test.Fail("could not spawn obj [obj_type] in hand of [puppet]") |
| 36 | + |
| 37 | +/datum/test_puppeteer/proc/spawn_obj_nearby(obj_type) |
| 38 | + for(var/turf/T in RANGE_TURFS(1, puppet.loc)) |
| 39 | + if(!is_blocked_turf(T, exclude_mobs = FALSE)) |
| 40 | + return origin_test.allocate(obj_type, T) |
| 41 | + |
| 42 | + origin_test.Fail("could not spawn obj [obj_type] near [src]") |
| 43 | + |
| 44 | +/datum/test_puppeteer/proc/click_on(target, params) |
| 45 | + var/datum/test_puppeteer/puppet_target = target |
| 46 | + sleep(max(puppet.next_click, puppet.next_move) - world.time + 1) |
| 47 | + if(istype(puppet_target)) |
| 48 | + puppet.ClickOn(puppet_target.puppet, params) |
| 49 | + return |
| 50 | + |
| 51 | + puppet.ClickOn(target, params) |
| 52 | + |
| 53 | +/datum/test_puppeteer/proc/spawn_mob_nearby(mob_type) |
| 54 | + for(var/turf/T in RANGE_TURFS(1, puppet)) |
| 55 | + if(!is_blocked_turf(T, exclude_mobs = FALSE)) |
| 56 | + var/mob/new_mob = origin_test.allocate(mob_type, T) |
| 57 | + return new_mob |
| 58 | + |
| 59 | +/datum/test_puppeteer/proc/check_attack_log(snippet) |
| 60 | + for(var/log_text in puppet.attack_log_old) |
| 61 | + if(findtextEx(log_text, snippet)) |
| 62 | + return TRUE |
| 63 | + |
| 64 | +/datum/test_puppeteer/proc/set_intent(new_intent) |
| 65 | + puppet.a_intent_change(new_intent) |
| 66 | + |
| 67 | +/datum/test_puppeteer/proc/rejuvenate() |
| 68 | + puppet.rejuvenate() |
0 commit comments