Skip to content

Commit

Permalink
Transforming weapons refactor (shiptest-ss13#3459)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request
refacotr!
transforming weapons now use a component for reusablity and adds code
for charged transforming weapons that function like a baton.
port of tgstation/tgstation#60761
atomization of shiptest-ss13#3391
<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game
Better and reusable code
<!-- Please add a short description of why you think these changes would
benefit the game. If you can't justify it in words, it might not be
worth adding. -->

## Changelog

:cl: FalloutFalcon, Melbert
refactor: transforming weapons are easier to add
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

---------

Signed-off-by: FalloutFalcon <[email protected]>
  • Loading branch information
FalloutFalcon authored and zimon9 committed Oct 29, 2024
1 parent df116e2 commit 6445642
Show file tree
Hide file tree
Showing 91 changed files with 815 additions and 524 deletions.
2 changes: 1 addition & 1 deletion _maps/RandomRuins/BeachRuins/beach_treasure_cove.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@
pixel_x = -6;
pixel_y = 10
},
/obj/item/melee/transforming/energy/sword/saber/pirate/red{
/obj/item/melee/energy/sword/saber/pirate/red{
pixel_y = 8;
pixel_x = 10
},
Expand Down
2 changes: 1 addition & 1 deletion _maps/RandomRuins/JungleRuins/jungle_cavecrew.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@
pixel_y = -8;
pixel_x = 5
},
/obj/item/melee/transforming/energy/sword/saber/pirate/red,
/obj/item/melee/energy/sword/saber/pirate/red,
/turf/open/floor/wood,
/area/ruin/jungle/cavecrew/dormitories)
"Dh" = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2480,7 +2480,7 @@
icon_state = "gib3-old";
pixel_x = -6
},
/obj/item/melee/transforming/energy/sword/saber/pirate/yellow{
/obj/item/melee/energy/sword/saber/pirate/yellow{
pixel_x = -5;
pixel_y = 16
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@
/area/overmap_encounter/planetoid/lava/explored)
"zb" = (
/mob/living/simple_animal/hostile/megafauna/blood_drunk_miner{
loot = list(/obj/item/melee/transforming/cleaving_saw,/obj/item/gun/energy/kinetic_accelerator,/obj/item/keycard/gatedrop/lavacanyon)
loot = list(/obj/item/melee/cleaving_saw,/obj/item/gun/energy/kinetic_accelerator,/obj/item/keycard/gatedrop/lavacanyon)
},
/turf/open/floor/plating/asteroid/basalt/lava_land_surface,
/area/overmap_encounter/planetoid/cave/explored)
Expand Down
12 changes: 6 additions & 6 deletions _maps/map_files/generic/CentCom.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,7 @@
/obj/item/clothing/suit/armor/tdome/red,
/obj/item/clothing/head/helmet/thunderdome,
/obj/item/melee/baton/loaded,
/obj/item/melee/transforming/energy/sword/saber/red,
/obj/item/melee/energy/sword/saber/red,
/obj/effect/turf_decal/industrial/warning{
dir = 4
},
Expand Down Expand Up @@ -3948,7 +3948,7 @@
/obj/item/clothing/suit/armor/tdome/green,
/obj/item/clothing/head/helmet/thunderdome,
/obj/item/melee/baton/loaded,
/obj/item/melee/transforming/energy/sword/saber/green,
/obj/item/melee/energy/sword/saber/green,
/obj/effect/turf_decal/industrial/warning{
dir = 8
},
Expand Down Expand Up @@ -6908,7 +6908,7 @@
/obj/effect/turf_decal/corner/opaque/blue{
dir = 8
},
/obj/item/melee/transforming/energy/ctf,
/obj/item/melee/energy/ctf,
/turf/open/floor/plasteel/dark,
/area/ctf)
"cEn" = (
Expand Down Expand Up @@ -7836,7 +7836,7 @@
/obj/effect/turf_decal/corner/opaque/red{
dir = 8
},
/obj/item/melee/transforming/energy/ctf,
/obj/item/melee/energy/ctf,
/turf/open/floor/plasteel/dark,
/area/ctf)
"eDS" = (
Expand Down Expand Up @@ -8387,7 +8387,7 @@
/obj/item/clothing/suit/armor/tdome/green,
/obj/item/clothing/head/helmet/thunderdome,
/obj/item/melee/baton/loaded,
/obj/item/melee/transforming/energy/sword/saber/green,
/obj/item/melee/energy/sword/saber/green,
/obj/effect/turf_decal/industrial/warning{
dir = 8
},
Expand Down Expand Up @@ -14402,7 +14402,7 @@
/obj/item/clothing/suit/armor/tdome/red,
/obj/item/clothing/head/helmet/thunderdome,
/obj/item/melee/baton/loaded,
/obj/item/melee/transforming/energy/sword/saber/red,
/obj/item/melee/energy/sword/saber/red,
/obj/effect/turf_decal/industrial/warning{
dir = 4
},
Expand Down
2 changes: 1 addition & 1 deletion _maps/shuttles/pirate/pirate_noderider.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@
/obj/item/storage/box/handcuffs,
/obj/item/clothing/glasses/meson,
/obj/item/megaphone,
/obj/item/melee/transforming/energy/sword/saber/red,
/obj/item/melee/energy/sword/saber/red,
/obj/item/pinpointer/crew,
/obj/item/clothing/mask/gas/atmos,
/obj/item/clothing/mask/whistle,
Expand Down
2 changes: 1 addition & 1 deletion _maps/shuttles/roumain/srm_elder.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@
/obj/vehicle/ridden/wheelchair{
dir = 4
},
/obj/item/melee/transforming/cleaving_saw/old,
/obj/item/melee/cleaving_saw/old,
/turf/open/floor/ship/dirt/dark,
/area/ship/bridge)
"rj" = (
Expand Down
6 changes: 0 additions & 6 deletions code/__DEFINES/dcs/signals/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,6 @@
#define COMSIG_TRY_STORAGE_RETURN_INVENTORY "storage_return_inventory" //(list/list_to_inject_results_into, recursively_search_inside_storages = TRUE)
#define COMSIG_TRY_STORAGE_CAN_INSERT "storage_can_equip" //(obj/item/insertion_candidate, mob/user, silent) - returns bool

// /datum/component/two_handed signals
#define COMSIG_TWOHANDED_WIELD "twohanded_wield" //from base of datum/component/two_handed/proc/wield(mob/living/carbon/user): (/mob/user)
#define COMPONENT_TWOHANDED_BLOCK_WIELD 1
#define COMSIG_TWOHANDED_UNWIELD "twohanded_unwield" //from base of datum/component/two_handed/proc/unwield(mob/living/carbon/user): (/mob/user)


// /datum/action signals
#define COMSIG_ACTION_TRIGGER "action_trigger" //from base of datum/action/proc/Trigger(): (datum/action)
#define COMPONENT_ACTION_BLOCK_TRIGGER 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define COMPONENT_BLOCK_SHARPEN_ALREADY 4
#define COMPONENT_BLOCK_SHARPEN_MAXED 8

#define COMSIG_ITEM_USE_CELL "item_use_cell"

#define COMSIG_TOOL_IN_USE "tool_in_use" ///from base of [/obj/item/proc/tool_check_callback]: (mob/living/user)
#define COMSIG_TOOL_START_USE "tool_start_use" ///from base of [/obj/item/proc/tool_start_check]: (mob/living/user)
#define COMSIG_ITEM_DISABLE_EMBED "item_disable_embed" ///from [/obj/item/proc/disableEmbedding]:
Expand Down Expand Up @@ -66,3 +68,8 @@
#define COMSIG_ITEM_SPLIT_VALUE 1
#define COMSIG_ITEM_SPLIT_PROFIT "item_split_profits" //Called when getting the item's exact ratio for cargo's profit.
#define COMSIG_ITEM_SPLIT_PROFIT_DRY "item_split_profits_dry" //Called when getting the item's exact ratio for cargo's profit, without selling the item.

// /datum/component/two_handed signals
#define COMSIG_TWOHANDED_WIELD "twohanded_wield" //from base of datum/component/two_handed/proc/wield(mob/living/carbon/user): (/mob/user)
#define COMPONENT_TWOHANDED_BLOCK_WIELD 1
#define COMSIG_TWOHANDED_UNWIELD "twohanded_unwield" //from base of datum/component/two_handed/proc/unwield(mob/living/carbon/user): (/mob/user)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// /datum/component/transforming signals

/// From /datum/component/transforming/proc/on_attack_self(obj/item/source, mob/user): (obj/item/source, mob/user, active)
#define COMSIG_TRANSFORMING_PRE_TRANSFORM "transforming_pre_transform"
/// Return COMPONENT_BLOCK_TRANSFORM to prevent the item from transforming.
#define COMPONENT_BLOCK_TRANSFORM (1<<0)
/// From /datum/component/transforming/proc/do_transform(obj/item/source, mob/user): (obj/item/source, mob/user, active)
#define COMSIG_TRANSFORMING_ON_TRANSFORM "transforming_on_transform"
/// Return COMPONENT_NO_DEFAULT_MESSAGE to prevent the transforming component from displaying the default transform message / sound.
#define COMPONENT_NO_DEFAULT_MESSAGE (1<<0)

#define COMSIG_ITEM_FORCE_TRANSFORM "item_force_transform"
5 changes: 5 additions & 0 deletions code/__DEFINES/dcs/signals/signals_obj/signals_object.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
#define COMSIG_OBJ_HIDE "obj_hide"
/// from base of [/atom/proc/obj_destruction]: (damage_flag)
#define COMSIG_OBJ_DESTRUCTION "obj_destruction"

/// Sent from /obj/item/update_weight_class(). (old_w_class, new_w_class)
#define COMSIG_ITEM_WEIGHT_CLASS_CHANGED "item_weight_class_changed"
/// Sent from /obj/item/update_weight_class(), to its loc. (obj/item/changed_item, old_w_class, new_w_class)
#define COMSIG_ATOM_CONTENTS_WEIGHT_CLASS_CHANGED "atom_contents_weight_class_changed"
2 changes: 2 additions & 0 deletions code/__DEFINES/traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
#define TRAIT_NO_STORAGE_INSERT "no_storage_insert" //cannot be inserted in a storage.
#define TRAIT_T_RAY_VISIBLE "t-ray-visible" // Visible on t-ray scanners if the atom/var/level == 1
#define TRAIT_NO_TELEPORT "no-teleport" //you just can't
/// A transforming item that is actively extended / transformed
#define TRAIT_TRANSFORM_ACTIVE "active_transform"
#define TRAIT_WIELDED "wielded" //The item is currently being wielded

//quirk traits
Expand Down
127 changes: 127 additions & 0 deletions code/datums/components/melee/charged.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Charged weapon component. For weapons that swap between states but require a cell for function.
* For example: Stun batons.
*
* Used to easily make an item that can be attack_self'd to gain force or change mode.
*
* Only values passed on initialize will update when the item is activated (except the icon_state).
* The icon_state of the item will swap between "[icon_state]" and "[icon_state]_on".
*/
/datum/component/transforming/charged
var/obj/item/stock_parts/cell/cell
var/allowed_cells
var/preload_cell_type
var/cell_hit_cost
var/can_remove_cell
var/no_cell_icon

/datum/component/transforming/charged/Initialize(
start_transformed = FALSE,
transform_cooldown_time = 0 SECONDS,
force_on = 0,
throwforce_on = 0,
throw_speed_on = 2,
sharpness_on = NONE,
hitsound_on = 'sound/weapons/blade1.ogg',
w_class_on = WEIGHT_CLASS_BULKY,
list/attack_verb_on,
inhand_icon_change = TRUE,
_allowed_cells = list(),
_preload_cell_type = /obj/item/stock_parts/cell,
_cell_hit_cost = 1000,
_can_remove_cell = FALSE,
_no_cell_icon = FALSE
)
. = ..()

allowed_cells = _allowed_cells
preload_cell_type = _preload_cell_type
cell_hit_cost = _cell_hit_cost
can_remove_cell = _can_remove_cell
no_cell_icon = _no_cell_icon

if(preload_cell_type in allowed_cells)
cell = new preload_cell_type(parent)

/datum/component/transforming/charged/RegisterWithParent()
. = ..()
RegisterSignal(parent, COMSIG_ATOM_SCREWDRIVER_ACT, PROC_REF(on_screwdriver_act))
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, PROC_REF(on_attackby))
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, PROC_REF(on_examine))
RegisterSignal(parent, COMSIG_ITEM_USE_CELL, PROC_REF(deduct_charge))

/datum/component/transforming/charged/Destroy(force, silent)
if(cell)
QDEL_NULL(cell)
. = ..()

/datum/component/transforming/charged/on_attack_self(obj/item/source, mob/user)
if(cell && cell.charge > cell_hit_cost)
return ..()
else
set_inactive(source)
if(!cell)
to_chat(user, span_warning("[source] does not have a power source!"))
else
to_chat(user, span_warning("[source] is out of charge."))

/datum/component/transforming/charged/proc/on_screwdriver_act(obj/item/source, mob/user, obj/item/screwdriver)
if(cell && can_remove_cell)
cell.update_appearance()
cell.forceMove(get_turf(parent))
cell = null
to_chat(user, span_notice("You remove the cell from [parent]."))
set_inactive(source)
source.update_appearance()
return COMPONENT_CANCEL_ATTACK_CHAIN

/datum/component/transforming/charged/proc/on_attackby(obj/item/source, obj/item/attacking_item, mob/user, params)
SIGNAL_HANDLER

if(attacking_item.type in allowed_cells)
var/obj/item/stock_parts/cell/attacking_cell = attacking_item
if(cell)
to_chat(user, span_notice("[parent] already has a cell!"))
else
if(attacking_cell.maxcharge < cell_hit_cost)
to_chat(user, span_notice("[parent] requires a higher capacity cell."))
return
if(!user.transferItemToLoc(attacking_item, parent))
return
cell = attacking_item
to_chat(user, span_notice("You install a cell in [parent]."))
source.update_appearance()
return COMPONENT_CANCEL_ATTACK_CHAIN

/datum/component/transforming/charged/proc/on_examine(obj/item/source, mob/user, list/examine_list)
SIGNAL_HANDLER

if(cell)
examine_list += span_notice("\The [source] is [round(cell.percent())]% charged.")
else
examine_list += span_warning("\The [source] does not have a power source installed.")

/datum/component/transforming/charged/proc/deduct_charge(obj/item/source)
SIGNAL_HANDLER
if(cell)
. = cell.use(cell_hit_cost)
if(active && cell.charge < cell_hit_cost)
playsound(src, SFX_SPARKS, 75, TRUE, -1)
set_inactive(source)

/datum/component/transforming/charged/proc/set_active_state(active_state = -1)
switch(active_state)
//We didnt pass a specific state to set it to so just toggle it
if(-1)
toggle_active(parent)
if(FALSE)
set_inactive(parent)
if(TRUE)
set_active(parent)

/datum/component/transforming/charged/set_inactive(obj/item/source)
. = ..()
if(!cell)
source.icon_state = "[initial(source.icon_state)]_nocell"
source.item_state = "[initial(source.icon_state)]_nocell"
source.update_appearance()
Loading

0 comments on commit 6445642

Please sign in to comment.