Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loadout restrictions (removal and donation tier) #403

Merged
merged 28 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d697a19
initial commit
larentoun Jul 17, 2024
9a95c72
donation tiers
larentoun Jul 17, 2024
3ee2856
fix giving donator items without donator
larentoun Jul 17, 2024
1e8d9a2
categorize dm files
larentoun Jul 17, 2024
d819ce3
update database
larentoun Jul 19, 2024
ab31713
rename table
larentoun Jul 20, 2024
29a0e1f
220 removal
larentoun Jul 20, 2024
2d1118b
Update SQL/bandastation/bandastation_update.sql
larentoun Jul 22, 2024
50d3e00
Update SQL/bandastation/bandastation_update.sql
larentoun Jul 22, 2024
376575a
tochat once
larentoun Jul 22, 2024
1dfba50
evade police
larentoun Jul 22, 2024
e25186c
Merge branch 'loadout-restrictions' of https://github.com/larentoun/t…
larentoun Jul 22, 2024
5479ab3
change table to a new one
larentoun Jul 22, 2024
43afbd0
give admins tier 3 for now
larentoun Jul 22, 2024
01a4c05
it is already summed
larentoun Jul 22, 2024
d563984
ladder police
larentoun Jul 22, 2024
56e5fe9
use proc to get donator levels
larentoun Jul 22, 2024
6c83ab4
admins get 3 level
larentoun Jul 22, 2024
b97bfe9
i hate deserialize
larentoun Jul 22, 2024
6b7146b
it's the best I can do
larentoun Jul 22, 2024
da4ea93
Merge branch 'master' into loadout-restrictions
larentoun Jul 23, 2024
5f5f449
review
larentoun Jul 24, 2024
b3339f1
Merge branch 'loadout-restrictions' of https://github.com/larentoun/t…
larentoun Jul 24, 2024
3842758
Merge branch 'master' into loadout-restrictions
larentoun Jul 24, 2024
84da6f4
will it fix tests?
larentoun Jul 24, 2024
ac7c953
comment
larentoun Jul 24, 2024
e3ce445
it also needs procs, alright...
larentoun Jul 24, 2024
590f587
review
larentoun Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions SQL/bandastation/bandastation_update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ CREATE TABLE `admin_wl` (
PRIMARY KEY (`id`),
KEY `ckey` (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `budget`
--
DROP TABLE IF EXISTS `budget`;
CREATE TABLE `budget` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME NOT NULL DEFAULT current_timestamp(),
`ckey` VARCHAR(32) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
`amount` INT(10) UNSIGNED NOT NULL,
`source` VARCHAR(32) NOT NULL COLLATE 'utf8mb4_general_ci',
`date_start` DATETIME NOT NULL DEFAULT current_timestamp(),
`date_end` DATETIME NULL DEFAULT (current_timestamp() + interval 1 month),
`is_valid` TINYINT(1) NOT NULL DEFAULT '1',
`discord_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;
24 changes: 21 additions & 3 deletions SQL/bandastation/database_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@ Any time you make a change to the schema files, remember to increment the databa

Make sure to also update `DB_MAJOR_VERSION_220` and `DB_MINOR_VERSION_220`, which can be found in `code/modular_bandastation/_defines220/code/defines/subsystems.dm`.

The latest database version is 1.1; The query to update the schema revision table is:
The latest database version is 1.2; The query to update the schema revision table is:

```sql
INSERT INTO `schema_revision_220` (`major`, `minor`) VALUES (1, 1);
INSERT INTO `schema_revision_220` (`major`, `minor`) VALUES (1, 2);
```
or

```sql
INSERT INTO `SS13_schema_revision_220` (`major`, `minor`) VALUES (1, 1);
INSERT INTO `SS13_schema_revision_220` (`major`, `minor`) VALUES (1, 2);
```

-----------------------------------------------------
Version 1.2, 22 July 2024, by larentoun
Created the table: budget

```sql
CREATE TABLE `budget` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME NOT NULL DEFAULT current_timestamp(),
`ckey` VARCHAR(32) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
`amount` INT(10) UNSIGNED NOT NULL,
`source` VARCHAR(32) NOT NULL COLLATE 'utf8mb4_general_ci',
`date_start` DATETIME NOT NULL DEFAULT current_timestamp(),
`date_end` DATETIME NULL DEFAULT (current_timestamp() + interval 1 month),
`is_valid` TINYINT(1) NOT NULL DEFAULT '1',
`discord_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;
```
-----------------------------------------------------
Version 1.1, 17 April 2024, by larentoun
Created the tables: schema_revision220, ckey_whitelist, admin_wl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
* make sure you add an update to the schema_version stable in the db changelog
*/
#define DB_MINOR_VERSION_220 1
#define DB_MINOR_VERSION_220 2
4 changes: 4 additions & 0 deletions modular_bandastation/loadout/_loadout.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/datum/modpack/loadout
name = "Loadout"
desc = "Изменения в loadout."
author = "larentoun"
7 changes: 7 additions & 0 deletions modular_bandastation/loadout/_loadout.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "_loadout.dm"

#include "code/client.dm"
#include "code/loadout_categories.dm"
#include "code/loadout_items.dm"
#include "code/loadout_preference.dm"
#include "code/categories/accessories.dm"
5 changes: 5 additions & 0 deletions modular_bandastation/loadout/code/categories/accessories.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/datum/loadout_item/accessory/pride/is_available()
Gaxeer marked this conversation as resolved.
Show resolved Hide resolved
return FALSE

/datum/loadout_item/accessory/maid_apron
donator_level = 1
69 changes: 69 additions & 0 deletions modular_bandastation/loadout/code/client.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#define DONATION_TIER_1 220
#define DONATION_TIER_2 440
#define DONATION_TIER_3 1000
#define DONATION_TIER_4 2220
#define DONATION_TIER_5 10000

/client
/// Call `proc/get_donator_level()` instead to get a value when possible.
var/donator_level = 0
larentoun marked this conversation as resolved.
Show resolved Hide resolved
COOLDOWN_DECLARE(db_check_cooldown)

// For unit-tests
/datum/client_interface
var/donator_level = 0

/datum/client_interface/proc/get_donator_level()
return donator_level

/client/proc/get_donator_level()
donator_level = max(donator_level, get_donator_level_from_db(), get_donator_level_from_admin())
return donator_level

/client/proc/get_donator_level_from_admin()
if(!holder)
return 0
var/rank_flags = holder.rank_flags()
if(rank_flags & R_EVERYTHING)
return 5
if(rank_flags & R_ADMIN)
return 3
return 0

/client/proc/get_donator_level_from_db()
if(!COOLDOWN_FINISHED(src, db_check_cooldown))
return 0
COOLDOWN_START(src, db_check_cooldown, 15 SECONDS)
var/datum/db_query/query_get_donator_level = SSdbcore.NewQuery({"
SELECT CAST(SUM(amount) as UNSIGNED INTEGER) FROM budget
WHERE ckey=:ckey
AND is_valid=true
AND date_start <= NOW()
AND (NOW() < date_end OR date_end IS NULL)
GROUP BY ckey
"}, list("ckey" = ckey))

var/amount = 0
if(query_get_donator_level.warn_execute() && length(query_get_donator_level.rows))
query_get_donator_level.NextRow()
amount = query_get_donator_level.item[1]
qdel(query_get_donator_level)

switch(amount)
if(DONATION_TIER_1 to (DONATION_TIER_2 - 1))
return 1
if(DONATION_TIER_2 to (DONATION_TIER_3 - 1))
return 2
if(DONATION_TIER_3 to (DONATION_TIER_4 - 1))
return 3
if(DONATION_TIER_4 to (DONATION_TIER_5 - 1))
return 4
if(DONATION_TIER_5 to INFINITY)
return 5
return 0

#undef DONATION_TIER_1
#undef DONATION_TIER_2
#undef DONATION_TIER_3
#undef DONATION_TIER_4
#undef DONATION_TIER_5
6 changes: 6 additions & 0 deletions modular_bandastation/loadout/code/loadout_categories.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/datum/loadout_category/get_items()
. = ..()
for(var/datum/loadout_item/item as anything in .)
if(item.is_available())
continue
. -= item
11 changes: 11 additions & 0 deletions modular_bandastation/loadout/code/loadout_items.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/datum/loadout_item
var/donator_level = 0

/datum/loadout_item/get_item_information()
. = ..()
if(donator_level)
. += "Tier [donator_level]"

// Removes item from the preferences menu, period. Use it only to remove stuff for ALL players.
/datum/loadout_item/proc/is_available()
return TRUE
25 changes: 25 additions & 0 deletions modular_bandastation/loadout/code/loadout_preference.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/datum/preferences/load_preferences()
. = ..()
parent.get_donator_level()

// Handles selecting from the preferences UI
/datum/preference_middleware/loadout/select_item(datum/loadout_item/selected_item)
var/donator_level = preferences.parent.get_donator_level()
if(donator_level >= selected_item.donator_level)
return ..()
to_chat(preferences.parent.mob, span_warning("У вас недостаточный уровень доната, чтобы взять [selected_item.name]!"))

// Removes donator_level items from the user if their donator_level is insufficient
/datum/preference/loadout/deserialize(input, datum/preferences/preferences)
. = ..()
// For loadout purposes, donator_level is updated in middleware on select
var/donator_level = preferences.parent.donator_level
var/removed_items = list()
for(var/path in .)
var/datum/loadout_item/item = GLOB.all_loadout_datums[path]
if(donator_level >= item.donator_level)
continue
. -= path
removed_items += item.name
if(length(removed_items) && preferences.parent.mob)
to_chat(preferences.parent.mob, span_warning("У вас недостаточный уровень доната, чтобы взять: [english_list(removed_items, and_text = " и ")]!"))
1 change: 1 addition & 0 deletions modular_bandastation/modular_bandastation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "examine_panel/_examine_panel.dme"
#include "gunhud/_gunhud.dme"
#include "keybinding/_keybinding.dme"
#include "loadout/_loadout.dme"
#include "mapping/_mapping.dme"
#include "pixel_shift/_pixel_shift.dme"
#include "ru_jobs/_ru_jobs.dme"
Expand Down
Loading