mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-06-22 06:35:12 +01:00
7a3ad79506
## About The Pull Request It's just a partial cleanup of anti-[STYLE](https://github.com/tgstation/tgstation/blob/master/.github/guides/STYLE.md) code from /tg/'s ancient history. I compiled & tested with my helpful assistant and damage is still working. <img width="1920" height="1040" alt="image" src="https://github.com/user-attachments/assets/26dabc17-088f-4008-b299-3ff4c27142c3" /> I'll upload the .cs script I used to do it shortly. ## Why It's Good For The Game Just minor code cleanup. Script used is located at https://metek.tech/camelTo-Snake.7z EDIT 11/23/25: Updated the script to use multithreading and sequential scan so it works a hell of a lot faster ``` /* // Copyright 2025 Joshua 'Joan Metekillot' Kidder This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. // */ using System.Text.RegularExpressions; class Program { static async Task Main(string[] args) { var readFile = new FileStreamOptions { Access = FileAccess.Read, Share = FileShare.ReadWrite, Options = FileOptions.Asynchronous | FileOptions.SequentialScan }; FileStreamOptions writeFile = new FileStreamOptions { Share = FileShare.ReadWrite, Access = FileAccess.ReadWrite, Mode = FileMode.Truncate, Options = FileOptions.Asynchronous }; RegexOptions regexOptions = RegexOptions.Multiline | RegexOptions.Compiled; Dictionary<string, int> changedProcs = new(); string regexPattern = @"(?<=\P{L})([a-z]+)([A-Z]{1,2}[a-z]+)*(Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss)([A-Z]{1,2}[a-z]+)*"; Regex camelCaseProcRegex = new(regexPattern, regexOptions); string snakeify(Match matchingRegex) { var vals = matchingRegex.Groups.Cast<Group>().SelectMany(_ => _.Captures).Select(_ => _.Value).ToArray(); var newVal = string.Join("_", vals.Skip(1).ToArray()).ToLower(); string logString = $"{vals[0]} => {newVal}"; if (changedProcs.TryGetValue(logString, out int value)) { changedProcs[logString] = value + 1; } else { changedProcs.Add(logString, 1); } return newVal; } var dmFiles = Directory.EnumerateFiles(".", "*.dm", SearchOption.AllDirectories).ToAsyncEnumerable<string>(); // uses default ParallelOptions // https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.paralleloptions?view=net-10.0#main await Parallel.ForEachAsync(dmFiles, async (filePath, UnusedCancellationToken) => { var reader = new StreamReader(filePath, readFile); string oldContent = await reader.ReadToEndAsync(); string newContent = camelCaseProcRegex.Replace(oldContent, new MatchEvaluator((Func<Match, string>)snakeify)); if (oldContent != newContent) { var writer = new StreamWriter(filePath, writeFile); await writer.WriteAsync(newContent); await writer.DisposeAsync(); } reader.Dispose(); }); var logToList = changedProcs.Cast<KeyValuePair<string, int>>().ToList(); foreach (var pair in logToList) { Console.WriteLine($"{pair.Key}: {pair.Value} locations"); } } } ``` ## Changelog 🆑 Bisar code: All (Brute|Burn|Fire|Tox|Oxy|Organ|Stamina)(Loss) procs now use snake_case, in-line with the STYLE guide. Underscores rule! /🆑
156 lines
7.5 KiB
Plaintext
156 lines
7.5 KiB
Plaintext
/datum/unit_test/harm_punch/Run()
|
|
var/mob/living/carbon/human/puncher = allocate(/mob/living/carbon/human/consistent)
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
|
|
// Avoid all randomness in tests
|
|
ADD_TRAIT(puncher, TRAIT_PERFECT_ATTACKER, INNATE_TRAIT)
|
|
|
|
puncher.set_combat_mode(TRUE)
|
|
victim.attack_hand(puncher, list(RIGHT_CLICK = FALSE))
|
|
|
|
TEST_ASSERT(victim.get_brute_loss() > 0, "Victim took no brute damage after being punched")
|
|
|
|
/datum/unit_test/harm_melee/Run()
|
|
var/mob/living/carbon/human/tider = allocate(/mob/living/carbon/human/consistent)
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
var/obj/item/storage/toolbox/toolbox = allocate(/obj/item/storage/toolbox)
|
|
|
|
tider.put_in_active_hand(toolbox, forced = TRUE)
|
|
tider.set_combat_mode(TRUE)
|
|
victim.attackby(toolbox, tider)
|
|
|
|
TEST_ASSERT(victim.get_brute_loss() > 0, "Victim took no brute damage after being hit by a toolbox")
|
|
|
|
/datum/unit_test/harm_different_damage/Run()
|
|
var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human/consistent)
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
var/obj/item/weldingtool/welding_tool = allocate(/obj/item/weldingtool)
|
|
|
|
attacker.put_in_active_hand(welding_tool, forced = TRUE)
|
|
attacker.set_combat_mode(TRUE)
|
|
|
|
welding_tool.attack_self(attacker) // Turn it on
|
|
victim.attackby(welding_tool, attacker)
|
|
|
|
TEST_ASSERT_EQUAL(victim.get_brute_loss(), 0, "Victim took brute damage from a lit welding tool")
|
|
TEST_ASSERT(victim.get_fire_loss() > 0, "Victim took no burn damage after being hit by a lit welding tool")
|
|
|
|
/datum/unit_test/attack_chain
|
|
var/attack_hit
|
|
var/post_attack_hit
|
|
var/pre_attack_hit
|
|
|
|
/datum/unit_test/attack_chain/proc/attack_hit()
|
|
SIGNAL_HANDLER
|
|
attack_hit = TRUE
|
|
|
|
/datum/unit_test/attack_chain/proc/post_attack_hit()
|
|
SIGNAL_HANDLER
|
|
post_attack_hit = TRUE
|
|
|
|
/datum/unit_test/attack_chain/proc/pre_attack_hit()
|
|
SIGNAL_HANDLER
|
|
pre_attack_hit = TRUE
|
|
|
|
/datum/unit_test/attack_chain/Run()
|
|
var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human/consistent)
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
var/obj/item/storage/toolbox/toolbox = allocate(/obj/item/storage/toolbox)
|
|
|
|
RegisterSignal(toolbox, COMSIG_ITEM_PRE_ATTACK, PROC_REF(pre_attack_hit))
|
|
RegisterSignal(toolbox, COMSIG_ITEM_ATTACK, PROC_REF(attack_hit))
|
|
RegisterSignal(toolbox, COMSIG_ITEM_AFTERATTACK, PROC_REF(post_attack_hit))
|
|
|
|
attacker.put_in_active_hand(toolbox, forced = TRUE)
|
|
attacker.set_combat_mode(TRUE)
|
|
toolbox.melee_attack_chain(attacker, victim)
|
|
|
|
TEST_ASSERT(pre_attack_hit, "Pre-attack signal was not fired")
|
|
TEST_ASSERT(attack_hit, "Attack signal was not fired")
|
|
TEST_ASSERT(post_attack_hit, "Post-attack signal was not fired")
|
|
|
|
/datum/unit_test/disarm/Run()
|
|
var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human/consistent)
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
var/obj/item/storage/toolbox/toolbox = allocate(/obj/item/storage/toolbox)
|
|
|
|
victim.put_in_active_hand(toolbox, forced = TRUE)
|
|
|
|
var/obj/structure/barricade/dense_object = allocate(/obj/structure/barricade)
|
|
|
|
// Attacker --> Victim --> Empty space --> Wall
|
|
attacker.forceMove(run_loc_floor_bottom_left)
|
|
victim.forceMove(locate(run_loc_floor_bottom_left.x + 1, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
|
dense_object.forceMove(locate(run_loc_floor_bottom_left.x + 3, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
|
|
|
// First disarm, world should now look like:
|
|
// Attacker --> Empty space --> Victim --> Wall
|
|
victim.attack_hand(attacker, list(RIGHT_CLICK = TRUE))
|
|
|
|
TEST_ASSERT_EQUAL(victim.loc.x, run_loc_floor_bottom_left.x + 2, "Victim wasn't moved back after being pushed")
|
|
TEST_ASSERT(!victim.has_status_effect(/datum/status_effect/incapacitating/knockdown), "Victim was knocked down despite not being against a wall")
|
|
TEST_ASSERT_EQUAL(victim.get_active_held_item(), toolbox, "Victim dropped toolbox despite not being against a wall")
|
|
|
|
attacker.forceMove(get_step(attacker, EAST))
|
|
|
|
// Second disarm, victim was against wall and should be down
|
|
victim.attack_hand(attacker, list(RIGHT_CLICK = TRUE))
|
|
|
|
TEST_ASSERT_EQUAL(victim.loc.x, run_loc_floor_bottom_left.x + 2, "Victim was moved after being pushed against a wall")
|
|
TEST_ASSERT(victim.has_status_effect(/datum/status_effect/incapacitating/knockdown), "Victim was not knocked down after being pushed against a wall")
|
|
TEST_ASSERT_EQUAL(victim.get_active_held_item(), null, "Victim didn't drop toolbox after being pushed against a wall")
|
|
|
|
/// Tests you can punch yourself
|
|
/datum/unit_test/self_punch
|
|
|
|
/datum/unit_test/self_punch/Run()
|
|
var/mob/living/carbon/human/dummy = allocate(/mob/living/carbon/human/consistent)
|
|
ADD_TRAIT(dummy, TRAIT_PERFECT_ATTACKER, TRAIT_SOURCE_UNIT_TESTS)
|
|
dummy.set_combat_mode(TRUE)
|
|
dummy.ClickOn(dummy)
|
|
TEST_ASSERT_NOTEQUAL(dummy.get_brute_loss(), 0, "Dummy took no brute damage after self-punching")
|
|
|
|
/// Tests handcuffed (HANDS_BLOCKED) mobs cannot punch
|
|
/datum/unit_test/handcuff_punch
|
|
|
|
/datum/unit_test/handcuff_punch/Run()
|
|
var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human/consistent)
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
ADD_TRAIT(attacker, TRAIT_PERFECT_ATTACKER, TRAIT_SOURCE_UNIT_TESTS)
|
|
ADD_TRAIT(attacker, TRAIT_HANDS_BLOCKED, TRAIT_SOURCE_UNIT_TESTS)
|
|
attacker.set_combat_mode(TRUE)
|
|
attacker.ClickOn(victim)
|
|
TEST_ASSERT_EQUAL(victim.get_brute_loss(), 0, "Victim took brute damage from being punched by a handcuffed attacker")
|
|
attacker.next_move = -1
|
|
attacker.next_click = -1
|
|
attacker.ClickOn(attacker)
|
|
TEST_ASSERT_EQUAL(attacker.get_brute_loss(), 0, "Attacker took brute damage from self-punching while handcuffed")
|
|
|
|
/// Tests handcuffed (HANDS_BLOCKED) monkeys can still bite despite being cuffed
|
|
/datum/unit_test/handcuff_bite
|
|
|
|
/datum/unit_test/handcuff_bite/Run()
|
|
var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human/consistent)
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
ADD_TRAIT(attacker, TRAIT_PERFECT_ATTACKER, TRAIT_SOURCE_UNIT_TESTS)
|
|
ADD_TRAIT(attacker, TRAIT_HANDS_BLOCKED, TRAIT_SOURCE_UNIT_TESTS)
|
|
attacker.set_combat_mode(TRUE)
|
|
attacker.set_species(/datum/species/monkey)
|
|
attacker.ClickOn(victim)
|
|
TEST_ASSERT_NOTEQUAL(victim.get_brute_loss(), 0, "Victim took no brute damage from being bit by a handcuffed monkey, which is incorrect, as it's a bite attack")
|
|
|
|
/// Tests that soundbang_act (and therefore sound_damage) works correctly
|
|
/datum/unit_test/soundbang
|
|
|
|
/datum/unit_test/soundbang/Run()
|
|
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent)
|
|
victim.soundbang_act(intensity = SOUNDBANG_NORMAL, damage_pwr = 10, deafen_pwr = 20 SECONDS)
|
|
TEST_ASSERT_EQUAL(victim.get_organ_loss(ORGAN_SLOT_EARS), 10, "victim didn't take the right amount of ears damage")
|
|
TEST_ASSERT(HAS_TRAIT_FROM(victim, TRAIT_DEAF, EAR_DAMAGE), "victim wasn't temporarily deafened")
|
|
var/obj/item/organ/ears/ears = victim.get_organ_slot(ORGAN_SLOT_EARS)
|
|
ears.adjust_temporary_deafness(-20 SECONDS)
|
|
TEST_ASSERT(!HAS_TRAIT_FROM(victim, TRAIT_DEAF, EAR_DAMAGE), "victim hasn't recovered from temprorary deafness")
|
|
victim.equip_to_slot_if_possible(new /obj/item/clothing/ears/earmuffs, ITEM_SLOT_EARS)
|
|
victim.soundbang_act(intensity = SOUNDBANG_NORMAL, deafen_pwr = 20 SECONDS)
|
|
TEST_ASSERT(!HAS_TRAIT_FROM(victim, TRAIT_DEAF, EAR_DAMAGE), "victim has been deafened despite wearing earmuffs")
|