forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
/datum/preferences/load_preferences() | ||
. = ..() | ||
parent.get_donator_level() | ||
/datum/preference_middleware/loadout/on_new_character(mob/user) | ||
preferences.loadout_points = preferences.get_loadout_points() | ||
.=..() | ||
|
||
// 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) | ||
if(preferences.loadout_points >= selected_item.cost && donator_level >= selected_item.donator_level) | ||
return ..() | ||
to_chat(preferences.parent.mob, span_warning("У вас недостаточный уровень доната, чтобы взять [selected_item.name]!")) | ||
else if(donator_level < selected_item.donator_level) | ||
to_chat(preferences.parent.mob, span_warning("У вас недостаточный уровень доната, чтобы взять [selected_item.name]!")) | ||
else | ||
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/total_cost = 0 | ||
var/removed_items = list() | ||
var/left_points = preferences.get_loadout_points() | ||
|
||
// Подсчёт общей стоимости всех предметов в лодауте | ||
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 | ||
total_cost += item.cost | ||
|
||
// Если общая стоимость превышает доступные очки, очищаем весь лодаут | ||
if (total_cost > left_points) | ||
. = list() // Полностью очищаем список | ||
removed_items = . // Добавляем все элементы в список удалённых предметов | ||
to_chat(preferences.parent.mob, span_warning("У вас недостаточно очков, для вашего набора. Он был отчищен.")) | ||
else | ||
// Если всё в порядке, выполняем стандартные проверки | ||
left_points -= total_cost | ||
for(var/path in .) | ||
var/datum/loadout_item/item = GLOB.all_loadout_datums[path] | ||
if(donator_level <= item.donator_level) | ||
//Убираем предметы, на которые не хватает донат-уровня | ||
. -= path | ||
removed_items += item.name | ||
|
||
preferences.loadout_points = left_points | ||
// Сообщение пользователю о том, какие предметы были удалены | ||
if(length(removed_items) && preferences.parent.mob) | ||
to_chat(preferences.parent.mob, span_warning("У вас недостаточный уровень доната, чтобы взять: [english_list(removed_items, and_text = " и ")]!")) |
34 changes: 34 additions & 0 deletions
34
modular_bandastation/preferences/code/modules/client/preferences.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
#define BASE_LOADOUT_POINTS 5 | ||
#define ADD_LOADOUT_POINTS 3 | ||
|
||
/datum/preferences | ||
max_save_slots = 5 | ||
var/loadout_points = 0 | ||
|
||
/datum/preferences/load_preferences() | ||
. = ..() | ||
get_loadout_points() | ||
|
||
/datum/preferences/proc/get_loadout_points() | ||
var/donation_level = parent.donator_level | ||
loadout_points = BASE_LOADOUT_POINTS + donation_level * ADD_LOADOUT_POINTS | ||
return loadout_points | ||
|
||
/datum/preferences/load_preferences() | ||
. = ..() // Вызов базовой загрузки | ||
|
||
// Загрузка донаторского уровня из префов | ||
var/donation_level = savefile.get_entry("donator_level", BASIC_DONATOR_LEVEL) | ||
parent.donator_level = donation_level | ||
|
||
return TRUE | ||
|
||
/datum/preferences/save_preferences() | ||
. = ..() // Вызов базового сохранения | ||
|
||
// Костыль 2 - проверка что это не первый вызов (ибо первый приходится на проверку кейбиндов) | ||
if(!parent.can_save_donator_level) | ||
return TRUE | ||
|
||
// Сохранение донаторского уровня в префы | ||
var/donation_level = parent.donator_level | ||
savefile.set_entry("donator_level", donation_level) | ||
savefile.save() | ||
return TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters