From 102318aaafe60267210ab656df7c7d913d12d2fa Mon Sep 17 00:00:00 2001 From: grilledham Date: Tue, 11 Sep 2018 00:08:22 +0100 Subject: [PATCH] update to donator perks --- player_list.lua | 6 ++++-- resources/donators.lua | 27 ++++++++++++++++++++------- train_saviour.lua | 21 +++++++++++++++++++-- user_groups.lua | 12 +++++++++++- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/player_list.lua b/player_list.lua index 3af07929..3e17cc26 100644 --- a/player_list.lua +++ b/player_list.lua @@ -1,6 +1,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' local Gui = require 'utils.gui' +local Donators = require 'resources.donators' local UserGroups = require 'user_groups' local PlayerStats = require 'player_stats' local Utils = require 'utils.utils' @@ -23,6 +24,7 @@ local rank_colors = { } local inv_sprite_time_step = 1 / sprite_time_step +local rank_perk_flag = Donators.donator_perk_flags.rank local rank_names = { 'Guest', 'Regular', @@ -91,7 +93,7 @@ local function get_rank_level(player) end local name = player.name - if UserGroups.is_donator(name) then + if UserGroups.is_donator_perk(name, rank_perk_flag) then return 3 elseif UserGroups.is_regular(name) then return 2 @@ -745,6 +747,6 @@ Gui.on_click( local reporting_player = event.player local reported_player = Gui.get_data(event.element) - Report.spawn_reporting_popup (reporting_player, reported_player) + Report.spawn_reporting_popup(reporting_player, reported_player) end ) diff --git a/resources/donators.lua b/resources/donators.lua index 20b5c0f7..2c6a681a 100644 --- a/resources/donators.lua +++ b/resources/donators.lua @@ -1,8 +1,21 @@ -return { - ['robertkruijt'] = true, - ['aldldl'] = true, - ['Geostyx'] = true, - ['Linaori'] = true, - ['Terarink'] = true, - ['Xertez'] = true +local Module = {} + +Module.donator_perk_flags = { + rank = 0x1, + welcome = 0x2, -- not implemented + train = 0x4, + currency = 0x8 -- not implemented } + +local d = Module.donator_perk_flags + +Module.donators = { + ['robertkruijt'] = d.rank + d.train, + ['aldldl'] = d.rank + d.train, + ['Geostyx'] = d.rank + d.train, + ['Linaori'] = d.rank + d.train, + ['Terarink'] = d.rank + d.train, + ['Xertez'] = d.rank + d.train, +} + +return Module diff --git a/train_saviour.lua b/train_saviour.lua index 4827be44..fcb9f31e 100644 --- a/train_saviour.lua +++ b/train_saviour.lua @@ -1,11 +1,17 @@ local Event = require 'utils.event' local Market_items = require 'resources.market_items' local Global = require 'utils.global' +local Donators = require 'resources.donators' +local UserGroups = require 'user_groups' +local train_perk_flag = Donators.donator_perk_flags.train local saviour_token_name = 'small-plane' -- item name for what saves players local saviour_timeout = 180 -- number of ticks players are train immune after getting hit (roughly) -table.insert(Market_items, {price = {{Market_items.market_item, 100}}, offer = {type = 'give-item', item = saviour_token_name}}) +table.insert( + Market_items, + {price = {{Market_items.market_item, 100}}, offer = {type = 'give-item', item = saviour_token_name}} +) local remove_stack = {name = saviour_token_name, count = 1} @@ -58,6 +64,17 @@ local function on_pre_death(event) return end + local player_name = player.name + + if UserGroups.is_donator_perk(player_name, train_perk_flag) then + saved_players[player_index] = game_tick + save_player(player) + + game.print(player_name .. ' has been saved from a train death as a perk of donating to the server.') + + return + end + local saviour_tokens = player.get_item_count(saviour_token_name) if saviour_tokens < 1 then return @@ -70,7 +87,7 @@ local function on_pre_death(event) game.print( table.concat { - player.name, + player_name, ' has been saved from a train death. Their ', saviour_token_name, ' survival item has be used up.' diff --git a/user_groups.lua b/user_groups.lua index 111b6043..947f3b3a 100644 --- a/user_groups.lua +++ b/user_groups.lua @@ -1,5 +1,6 @@ global.regulars = require 'resources.regulars' -global.donators = require 'resources.donators' +local Donators = require 'resources.donators' +global.donators = Donators.donators local Event = require 'utils.event' local Utils = require 'utils.utils' @@ -71,6 +72,15 @@ function Module.is_donator(player_name) return global.donators[player_name] end +function Module.is_donator_perk(player_name, perk) + local d = global.donators[player_name] + if not d then + return false + end + + return bit32.band(d, perk) == perk +end + Event.add( defines.events.on_player_joined_game, function(event)