Skip to content

Commit

Permalink
Finished loot crate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Watermelon914 authored and Watermelon914 committed Apr 15, 2021
1 parent 56c2b1a commit 69cddb2
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 50 deletions.
7 changes: 7 additions & 0 deletions ColonialMarinesALPHA.dme
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "code\__DEFINES\job.dm"
#include "code\__DEFINES\keybinding.dm"
#include "code\__DEFINES\layers.dm"
#include "code\__DEFINES\loot.dm"
#include "code\__DEFINES\maps.dm"
#include "code\__DEFINES\marine.dm"
#include "code\__DEFINES\math_physics.dm"
Expand Down Expand Up @@ -157,6 +158,7 @@
#include "code\controllers\configuration\entries\game_options.dm"
#include "code\controllers\configuration\entries\general.dm"
#include "code\controllers\configuration\entries\icon_source_config.dm"
#include "code\controllers\configuration\entries\loot.dm"
#include "code\controllers\configuration\entries\nightmare.dm"
#include "code\controllers\configuration\entries\resources.dm"
#include "code\controllers\mc\admin.dm"
Expand Down Expand Up @@ -184,6 +186,7 @@
#include "code\controllers\subsystem\input.dm"
#include "code\controllers\subsystem\item_cleanup.dm"
#include "code\controllers\subsystem\lighting.dm"
#include "code\controllers\subsystem\loot.dm"
#include "code\controllers\subsystem\machinery.dm"
#include "code\controllers\subsystem\mapping.dm"
#include "code\controllers\subsystem\mapview.dm"
Expand Down Expand Up @@ -1248,6 +1251,10 @@
#include "code\modules\cm_aliens\structures\special\pylon_core.dm"
#include "code\modules\cm_aliens\structures\special\recovery_node.dm"
#include "code\modules\cm_aliens\structures\special\spawn_pool.dm"
#include "code\modules\cm_loot\loot_crate.dm"
#include "code\modules\cm_loot\loot_datum.dm"
#include "code\modules\cm_loot\loot\items.dm"
#include "code\modules\cm_loot\loot\weapons.dm"
#include "code\modules\cm_marines\anti_air.dm"
#include "code\modules\cm_marines\codebook.dm"
#include "code\modules\cm_marines\Donor_Items.dm"
Expand Down
7 changes: 7 additions & 0 deletions code/__DEFINES/loot.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define LOOT_NONE 0
#define LOOT_COMMON 1
#define LOOT_RARE 2
#define LOOT_VERY_RARE 3
#define LOOT_LEGENDARY 4

#define RARITY_COUNT 4
1 change: 1 addition & 0 deletions code/__DEFINES/subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#define SS_INIT_LANDMARK 3.2
#define SS_INIT_MACHINES 3
#define SS_INIT_TECHTREE 2.5
#define SS_INIT_LOOT 2.2
#define SS_INIT_RADIO 2
#define SS_INIT_TIMER 100
#define SS_INIT_UNSPECIFIED 0
Expand Down
13 changes: 13 additions & 0 deletions code/controllers/configuration/entries/loot.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Works on the basis that legendary rolls first, then very rare and so on.

/datum/config_entry/number/loot_common_chance
config_entry_value = 100

/datum/config_entry/number/loot_rare_chance
config_entry_value = 33

/datum/config_entry/number/loot_very_rare_chance
config_entry_value = 10

/datum/config_entry/number/loot_legendary_chance
config_entry_value = 4
41 changes: 41 additions & 0 deletions code/controllers/subsystem/loot.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

SUBSYSTEM_DEF(loot)
name = "Loot"
init_order = SS_INIT_LOOT

flags = SS_NO_FIRE

var/list/drop_chances[RARITY_COUNT]

/datum/controller/subsystem/loot/Initialize()
. = ..()
reload_drop_chances()

/datum/controller/subsystem/loot/proc/reload_drop_chances()
drop_chances[LOOT_COMMON] = CONFIG_GET(number/loot_common_chance)
drop_chances[LOOT_RARE] = CONFIG_GET(number/loot_rare_chance)
drop_chances[LOOT_VERY_RARE] = CONFIG_GET(number/loot_very_rare_chance)
drop_chances[LOOT_LEGENDARY] = CONFIG_GET(number/loot_legendary_chance)

/datum/controller/subsystem/loot/proc/generate_loot(var/datum/loot_table/loot)
RETURN_TYPE(/datum/loot_entry)

if(!loot.table)
return

var/chosen_rarity = LOOT_NONE
for(var/index in 1 to length(loot.rarities))
var/rarity = loot.rarities[index]
var/probability = drop_chances[rarity]
if(prob(probability))
chosen_rarity = rarity
break

if(chosen_rarity == LOOT_NONE)
return

if(!loot.table[chosen_rarity])
return

return pick(loot.table[chosen_rarity])

1 change: 0 additions & 1 deletion code/controllers/subsystem/vox.dm

This file was deleted.

34 changes: 13 additions & 21 deletions code/game/objects/structures/crates_lockers/crates.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,28 @@

/obj/structure/closet/crate/open()
if(opened)
return 0
return FALSE
if(!can_open())
return 0

if(rigged && locate(/obj/item/device/radio/electropack) in src)
if(isliving(usr))
var/mob/living/L = usr
if(L.electrocute_act(17, src))
var/datum/effect_system/spark_spread/s = new /datum/effect_system/spark_spread
s.set_up(5, 1, src)
s.start()
return 2
return FALSE

playsound(src.loc, 'sound/machines/click.ogg', 15, 1)
for(var/obj/O in src)
O.forceMove(get_turf(src))
opened = 1
for(var/o in src)
var/atom/movable/A = o
A.forceMove(get_turf(src))
opened = TRUE
update_icon()
if(climbable)
structure_shaken()
climbable = 0 //Open crate is not a surface that works when climbing around
return 1
climbable = FALSE //Open crate is not a surface that works when climbing around
return TRUE

/obj/structure/closet/crate/close()
if(!opened)
return 0
return FALSE
if(!can_close())
return 0
return FALSE

playsound(src.loc, 'sound/machines/click.ogg', 15, 1)
playsound(loc, 'sound/machines/click.ogg', 15, 1)
var/itemcount = 0
for(var/obj/O in get_turf(src))
if(itemcount >= storage_capacity)
Expand All @@ -80,8 +72,8 @@
O.forceMove(src)
itemcount++

opened = 0
climbable = 1
opened = FALSE
climbable = TRUE
update_icon()
return 1

Expand Down
Empty file.
152 changes: 152 additions & 0 deletions code/modules/cm_loot/loot/weapons.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
GLOBAL_DATUM_INIT(loot_weapons, /datum/loot_table/weapons, new())

/obj/structure/closet/crate/loot/weapons
name = "weapons crate"

/obj/structure/closet/crate/loot/weapons/Initialize()
. = ..()
possible_items = GLOB.loot_weapons

/datum/loot_table/weapons/New()
. = ..()
for(var/i in subtypesof(/datum/loot_entry/weapon))
var/datum/loot_entry/weapon/W = i
if(initial(W.abstract_type) == i)
continue

if(!(initial(W.rarity) in rarities))
stack_trace("Invalid rarity value from [W]. Rarity not found in rarities variable.")
continue

table[initial(W.rarity)] += new W()

/datum/loot_entry/weapon
name = "weapon item"
var/item_to_spawn

/datum/loot_entry/weapon/spawn_item(var/atom/spawn_location)
if(!item_to_spawn)
return
return new item_to_spawn(spawn_location)

/*
SHOTGUN WEAPONS
Ordered from Legendary items to Common items
*/

/datum/loot_entry/weapon/marsoc_shotgun
name = "MARSOC Shotgun"
item_to_spawn = /obj/item/weapon/gun/shotgun/combat/marsoc
rarity = LOOT_LEGENDARY

/datum/loot_entry/weapon/combat_shotgun
name = "MK221 Tactical Shotgun"
item_to_spawn = /obj/item/weapon/gun/shotgun/combat
rarity = LOOT_VERY_RARE

/datum/loot_entry/weapon/sawnoff_shotgun
name = "Sawn-off Shotgun"
item_to_spawn = /obj/item/weapon/gun/shotgun/double/sawn
rarity = LOOT_RARE

/datum/loot_entry/weapon/double_barrel
name = "Double-barrel Shotgun"
item_to_spawn = /obj/item/weapon/gun/shotgun/double
rarity = LOOT_COMMON

/datum/loot_entry/weapon/hg_shotgun
name = "HG 37-12 Pump Shotgun"
item_to_spawn = /obj/item/weapon/gun/shotgun/pump/cmb
rarity = LOOT_COMMON

/*
GENERAL WEAPONS
Ordered from Legendary items to Common items
*/

/datum/loot_entry/weapon/m40_sd
name = "M40-SD pulse rifle"
item_to_spawn = /obj/item/weapon/gun/rifle/m41a/elite/m40_sd
rarity = LOOT_VERY_RARE

/datum/loot_entry/weapon/m41a_elite
name = "M41A/2 pulse rifle"
item_to_spawn = /obj/item/weapon/gun/rifle/m41a/elite
rarity = LOOT_VERY_RARE

/datum/loot_entry/weapon/m39_elite
name = "M39B/2 submachinegun"
item_to_spawn = /obj/item/weapon/gun/smg/m39/elite
rarity = LOOT_RARE

/datum/loot_entry/weapon/fp9000
name = "FP9000 submachinegun"
item_to_spawn = /obj/item/weapon/gun/smg/fp9000
rarity = LOOT_RARE

/datum/loot_entry/weapon/m46c
name = "M46C pulse rifle"
item_to_spawn = /obj/item/weapon/gun/rifle/m46c
rarity = LOOT_RARE

/datum/loot_entry/weapon/m4ra
name = "M4RA battle rifle"
item_to_spawn = /obj/item/weapon/gun/rifle/m4ra
rarity = LOOT_COMMON

/datum/loot_entry/weapon/mateba
name = "Mateba autorevolver"
item_to_spawn = /obj/item/weapon/gun/revolver/mateba
rarity = LOOT_COMMON

/*
SPECIAL WEAPONS
Ordered from Legendary items to Common items
*/

/datum/loot_entry/weapon/minigun
name = "Minigun"
item_to_spawn = /obj/item/weapon/gun/minigun
rarity = LOOT_LEGENDARY

/datum/loot_entry/weapon/rpg
name = "M5 RPG"
item_to_spawn = /obj/item/weapon/gun/launcher/rocket
rarity = LOOT_LEGENDARY

/datum/loot_entry/weapon/m60
name = "M60 Machinegun"
item_to_spawn = /obj/item/weapon/gun/m60
rarity = LOOT_VERY_RARE

/datum/loot_entry/weapon/grenade_launcher
name = "Grenade Launcher"
item_to_spawn = /obj/item/weapon/gun/launcher/grenade/m92
rarity = LOOT_RARE

#define TESTING
#ifdef TESTING
/client/verb/do_loot_table_test(var/amount as num)
set name = "Do Weapon Loot Table Test"
set category = "Debug"

var/legendary = 0
var/very_rare = 0
var/rare = 0
var/common = 0
for(var/i in 1 to amount)
var/datum/loot_entry/L = SSloot.generate_loot(GLOB.loot_weapons)
switch(L.rarity)
if(LOOT_COMMON)
common++
if(LOOT_RARE)
rare++
if(LOOT_VERY_RARE)
very_rare++
if(LOOT_LEGENDARY)
legendary++

to_chat(usr, "Got [legendary] legendaries, [very_rare] very rares, [rare] rares, [common] commons.")

#endif

32 changes: 32 additions & 0 deletions code/modules/cm_loot/loot_crate.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/obj/structure/closet/crate/loot
name = "debug loot crate"
icon_state = "secure_locked_weapons"
icon_opened = "secure_open_weapons"
icon_closed = "secure_locked_weapons"
wrenchable = FALSE
anchored = TRUE

/// Loot table used to determine what a box can give depending on what the dice roll comes out on.
var/datum/loot_table/possible_items

// Can't close loot crates, they stay open once open.
/obj/structure/closet/crate/loot/can_close()
return FALSE

/obj/structure/closet/crate/loot/open()
if(!possible_items)
return

. = ..()
if(!.)
return

var/datum/loot_entry/item = SSloot.generate_loot(possible_items)
if(!item)
return

item.spawn_item(get_turf(src))

/obj/structure/closet/crate/loot/Destroy()
possible_items = null
return ..()
31 changes: 31 additions & 0 deletions code/modules/cm_loot/loot_datum.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/datum/loot_table
/// The list of rarities that this loot table includes. Used for probability calculations.
/// The order in which the probabilities are checked depend on the order of the rarities.
var/list/rarities = list(
LOOT_LEGENDARY,
LOOT_VERY_RARE,
LOOT_RARE,
LOOT_COMMON
)
var/list/datum/loot_entry/table

/datum/loot_table/New()
. = ..()
var/highest_value = 0
for(var/i in rarities)
if(i > highest_value)
highest_value = i

table = new(highest_value)
for(var/i in rarities)
table[i] = list()

/datum/loot_entry
var/name
var/abstract_type = /datum/loot_entry
var/rarity = LOOT_COMMON

/// Returns the item to spawn, whilst also spawning at the desired spawn location. Can return null.
/datum/loot_entry/proc/spawn_item(var/atom/spawn_location)
return

2 changes: 1 addition & 1 deletion code/modules/projectiles/guns/rifles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
item_state = "m41a2"

current_mag = /obj/item/ammo_magazine/rifle/ap
flags_gun_features = GUN_AUTO_EJECTOR|GUN_CAN_POINTBLANK|GUN_AMMO_COUNTER|GUN_WY_RESTRICTED
flags_gun_features = GUN_AUTO_EJECTOR|GUN_CAN_POINTBLANK|GUN_AMMO_COUNTER
aim_slowdown = SLOWDOWN_ADS_SMG
wield_delay = WIELD_DELAY_FAST
map_specific_decoration = FALSE
Expand Down
Loading

0 comments on commit 69cddb2

Please sign in to comment.