mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-06-02 04:27:42 +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! /🆑
94 lines
4.0 KiB
Plaintext
94 lines
4.0 KiB
Plaintext
///This component allows something to be when crossed, for example for cockroaches.
|
|
/datum/component/squashable
|
|
///Chance on crossed to be squashed
|
|
var/squash_chance = 50
|
|
///How much brute is applied when mob is squashed
|
|
var/squash_damage = 1
|
|
///Squash flags, for extra checks etcetera.
|
|
var/squash_flags = NONE
|
|
///Special callback to call on squash instead, for things like hauberoach
|
|
var/datum/callback/on_squash_callback
|
|
///signal list given to connect_loc
|
|
var/static/list/loc_connections = list(
|
|
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
|
|
)
|
|
COOLDOWN_DECLARE(squish_cooldown) // BUBBER EDIT
|
|
|
|
|
|
/datum/component/squashable/Initialize(squash_chance, squash_damage, squash_flags, squash_callback)
|
|
. = ..()
|
|
if(!isliving(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
if(squash_chance)
|
|
src.squash_chance = squash_chance
|
|
if(squash_damage)
|
|
src.squash_damage = squash_damage
|
|
if(squash_flags)
|
|
src.squash_flags = squash_flags
|
|
if(!src.on_squash_callback && squash_callback)
|
|
on_squash_callback = CALLBACK(parent, squash_callback)
|
|
|
|
AddComponent(/datum/component/connect_loc_behalf, parent, loc_connections)
|
|
if(squash_callback) // BUBBER EDIT BEGIN- NO ROACHES SQUISHING EACH OTHER FOR THE OTHER EDIT
|
|
return
|
|
RegisterSignal(parent, COMSIG_LIVING_MOB_BUMPED, PROC_REF(on_entered))// BUBBER EDIT END - MICRO BALANCE
|
|
|
|
/datum/component/squashable/Destroy(force)
|
|
on_squash_callback = null
|
|
return ..()
|
|
|
|
///Handles the squashing of the mob
|
|
/datum/component/squashable/proc/on_entered(turf/source_turf, atom/movable/crossing_movable)
|
|
SIGNAL_HANDLER
|
|
if(istype(crossing_movable, /obj)) // BUBBER EDIT - don't get knocked down by items
|
|
return
|
|
|
|
if(parent == crossing_movable)
|
|
return
|
|
|
|
var/mob/living/parent_as_living = parent
|
|
if((squash_flags & SQUASHED_DONT_SQUASH_IN_CONTENTS) && !isturf(parent_as_living.loc))
|
|
return
|
|
|
|
if((squash_flags & SQUASHED_SHOULD_BE_DOWN) && parent_as_living.body_position != LYING_DOWN)
|
|
parent_as_living.Knockdown(1 SECONDS) // BUBBER EDIT - MICRO BALANCE
|
|
return
|
|
|
|
var/should_squash = ((squash_flags & SQUASHED_ALWAYS_IF_DEAD) && parent_as_living.stat == DEAD) || prob(squash_chance)
|
|
|
|
if(should_squash && on_squash_callback)
|
|
if(on_squash_callback.Invoke(parent_as_living, crossing_movable))
|
|
return //Everything worked, we're done!
|
|
if(isliving(crossing_movable))
|
|
var/mob/living/crossing_mob = crossing_movable
|
|
if(crossing_mob.mob_size > MOB_SIZE_SMALL && !(crossing_mob.movement_type & MOVETYPES_NOT_TOUCHING_GROUND))
|
|
if(HAS_TRAIT(crossing_mob, TRAIT_PACIFISM) || (crossing_mob.move_intent == MOVE_INTENT_WALK) || HAS_TRAIT(crossing_mob, TRAIT_LIGHT_STEP)) // BUBBER EDIT
|
|
crossing_mob.visible_message(span_notice("[crossing_mob] carefully steps over [parent_as_living]."), span_notice("You carefully step over [parent_as_living] to avoid hurting [parent_as_living.p_them()].")) //BUBBER EDIT - Added pronouns
|
|
return
|
|
if(should_squash)
|
|
crossing_mob.visible_message(span_notice("[crossing_mob] squashed [parent_as_living]."), span_notice("You squashed [parent_as_living]."))
|
|
Squish(parent_as_living)
|
|
playsound(parent_as_living, 'sound/effects/blob/attackblob.ogg', 50, TRUE) // BUBBER EDIT
|
|
else
|
|
parent_as_living.visible_message(span_notice("[parent_as_living] avoids getting crushed."))
|
|
else if(isstructure(crossing_movable))
|
|
if(should_squash)
|
|
crossing_movable.visible_message(span_notice("[parent_as_living] is crushed under [crossing_movable]."))
|
|
Squish(parent_as_living)
|
|
else
|
|
parent_as_living.visible_message(span_notice("[parent_as_living] avoids getting crushed."))
|
|
|
|
/datum/component/squashable/proc/Squish(mob/living/target)
|
|
if(squash_flags & SQUASHED_SHOULD_BE_GIBBED)
|
|
target.gib(DROP_ALL_REMAINS)
|
|
else
|
|
if(COOLDOWN_FINISHED(src, squish_cooldown))// BUBBER EDIT
|
|
target.take_bodypart_damage(squash_damage, wound_bonus = 5)// BUBBER EDIT
|
|
target.AddElement(/datum/element/squish, 20 SECONDS) // BUBBER EDIT
|
|
COOLDOWN_START(src, squish_cooldown, 20 SECONDS)// BUBBER EDIT
|
|
|
|
|
|
/datum/component/squashable/UnregisterFromParent()
|
|
. = ..()
|
|
qdel(GetComponent(/datum/component/connect_loc_behalf))
|