Class: ESM::Exile::Territory
- Inherits:
-
Object
- Object
- ESM::Exile::Territory
- Defined in:
- lib/esm/model/exile/territory.rb
Constant Summary collapse
- VALID_FLAGS =
So I don't build a bad URL
%w[ flag_blue_co flag_country_at_co flag_country_au_co flag_country_be_co flag_country_by_co flag_country_cn_co flag_country_cz_co flag_country_de_co flag_country_dk_co flag_country_ee_co flag_country_fi_co flag_country_fr_co flag_country_ir_co flag_country_it_co flag_country_nl_co flag_country_pl2_co flag_country_pl_co flag_country_pt_co flag_country_ru_co flag_country_sct_co flag_country_se_co flag_cp_co flag_exile_city_co flag_green_co flag_mate_21dmd_co flag_mate_bis_co flag_mate_commandermalc_co flag_mate_hollow_co flag_mate_jankon_co flag_mate_legion_ca flag_mate_secretone_co flag_mate_spawny_co flag_mate_stitchmoonz_co flag_mate_vish_co flag_mate_zanders_streched_co flag_misc_alkohol_co flag_misc_battleye_co flag_misc_beardageddon_co flag_misc_brunswik_co flag_misc_bss_co flag_misc_dickbutt_co flag_misc_dorset_co flag_misc_dream_cat_co flag_misc_eraser1_co flag_misc_exile_co flag_misc_kickass_co flag_misc_kiwifern_co flag_misc_knuckles_co flag_misc_lazerkiwi_co flag_misc_lemonparty_co flag_misc_nuclear_co flag_misc_pedobear_co flag_misc_petoria_co flag_misc_pirate_co flag_misc_privateproperty_co flag_misc_rainbow_co flag_misc_rma_co flag_misc_skippy_co flag_misc_smashing_co flag_misc_snake_co flag_misc_svarog_co flag_misc_trololol_co flag_misc_utcity_co flag_misc_weeb_co flag_misc_willbeeaten_co flag_red_co flag_trouble2_co flag_uk_co flag_us_co flag_white_co ].freeze
Instance Method Summary collapse
- #builders ⇒ Object
- #days_left_until_payment_due ⇒ Object
- #flag_path ⇒ Object
- #flag_status ⇒ Object
- #id ⇒ Object
-
#initialize(server:, territory:) ⇒ Territory
constructor
A new instance of Territory.
- #last_paid_at ⇒ Object
- #level ⇒ Object
- #max_object_count ⇒ Object
- #moderators ⇒ Object
- #name ⇒ Object
- #next_due_date ⇒ Object
- #object_count ⇒ Object
- #owner ⇒ Object
- #payment_reminder_message ⇒ Object
- #radius ⇒ Object
- #renew_price ⇒ Object
- #status_color ⇒ Object
- #stolen? ⇒ Boolean
- #to_embed ⇒ Object
- #upgrade_level ⇒ Object
- #upgrade_object_count ⇒ Object
- #upgrade_price ⇒ Object
- #upgrade_radius ⇒ Object
- #upgradeable? ⇒ Boolean
Constructor Details
#initialize(server:, territory:) ⇒ Territory
Returns a new instance of Territory.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/esm/model/exile/territory.rb', line 22 def initialize(server:, territory:) @server = server @server_settings = server.server_setting @territory = if @server.v2? transform_territory(territory) else territory end @current_level_territory = @server.territories.find_by( territory_level: @territory.level ) @next_level_territory = @server.territories.find_by( territory_level: @territory.level + 1 ) end |
Instance Method Details
#builders ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/esm/model/exile/territory.rb', line 154 def builders if @server.v2? @territory.build_rights .join_map("\n") do |account| next if account.owner || account.moderator "#{account.name} (#{account.uid})" end else # V1 @territory.build_rights.map { |name, uid| "#{name} (#{uid})" } end end |
#days_left_until_payment_due ⇒ Object
168 169 170 |
# File 'lib/esm/model/exile/territory.rb', line 168 def days_left_until_payment_due @days_left_until_payment_due ||= (next_due_date.to_date - ::Time.zone.today).to_i end |
#flag_path ⇒ Object
66 67 68 |
# File 'lib/esm/model/exile/territory.rb', line 66 def flag_path @flag_path ||= convert_flag_path(@territory.flag_texture) end |
#flag_status ⇒ Object
74 75 76 |
# File 'lib/esm/model/exile/territory.rb', line 74 def flag_status stolen? ? "Stolen!" : "Secure" end |
#id ⇒ Object
41 42 43 |
# File 'lib/esm/model/exile/territory.rb', line 41 def id @territory.esm_custom_id.presence || @territory.id end |
#last_paid_at ⇒ Object
88 89 90 |
# File 'lib/esm/model/exile/territory.rb', line 88 def last_paid_at @last_paid_at ||= ESM::Time.parse(@territory.last_paid_at) end |
#level ⇒ Object
53 54 55 |
# File 'lib/esm/model/exile/territory.rb', line 53 def level @territory.level end |
#max_object_count ⇒ Object
96 97 98 |
# File 'lib/esm/model/exile/territory.rb', line 96 def max_object_count @current_level_territory.territory_object_count end |
#moderators ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/esm/model/exile/territory.rb', line 139 def moderators if @server.v2? @territory.moderators .sort_by { |a| a.name.downcase } .join_map("\n") do |account| next if account.owner "#{account.name} (#{account.uid})" end else # V1 @territory.moderators.map { |name, uid| "#{name} (#{uid})" } end end |
#name ⇒ Object
45 46 47 |
# File 'lib/esm/model/exile/territory.rb', line 45 def name @territory.territory_name end |
#next_due_date ⇒ Object
92 93 94 |
# File 'lib/esm/model/exile/territory.rb', line 92 def next_due_date @next_due_date ||= last_paid_at + @server_settings.territory_lifetime.days end |
#object_count ⇒ Object
57 58 59 |
# File 'lib/esm/model/exile/territory.rb', line 57 def object_count @territory.object_count end |
#owner ⇒ Object
49 50 51 |
# File 'lib/esm/model/exile/territory.rb', line 49 def owner "#{@territory.owner_name} (#{@territory.owner_uid})" end |
#payment_reminder_message ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/esm/model/exile/territory.rb', line 172 def = "You have `#{ESM::Time.distance_of_time_in_words(next_due_date, precise: false)}` until your next payment is due." case days_left_until_payment_due when 0..2 # 0 to 2 days left ":alarm_clock: **You should make a base payment ASAP to avoid losing your base!**\n#{}" when 3..5 # 3 to 5 days left ":warning: **You should consider making a base payment soon.**\n#{}" else # Don't show anything "" end end |
#radius ⇒ Object
61 62 63 64 |
# File 'lib/esm/model/exile/territory.rb', line 61 def radius # Radius comes in as a decimal @territory.radius.to_i end |
#renew_price ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/esm/model/exile/territory.rb', line 104 def renew_price price = @territory.level * @territory.object_count * @server_settings.territory_price_per_object return "#{price.to_delimitated_s} poptabs" if @server_settings.territory_payment_tax.zero? # If the server has tax, add it to the price price += (price * (@server_settings.territory_payment_tax.to_f / 100)).round "#{price.to_delimitated_s} poptabs (#{@server_settings.territory_payment_tax}% tax added)" end |
#status_color ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/esm/model/exile/territory.rb', line 78 def status_color if stolen? || days_left_until_payment_due <= 2 ESM::Color::Toast::RED elsif days_left_until_payment_due <= 5 ESM::Color::Toast::YELLOW else ESM::Color::Toast::GREEN end end |
#stolen? ⇒ Boolean
70 71 72 |
# File 'lib/esm/model/exile/territory.rb', line 70 def stolen? @territory.flag_stolen end |
#to_embed ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/esm/model/exile/territory.rb', line 188 def ESM::Embed.build do |e| e.title = "#{I18n.t(:territory)} \"#{name}\"" e.thumbnail = flag_path e.color = status_color e.description = e.add_field(name: I18n.t(:territory_id), value: "```#{id}```", inline: true) e.add_field(name: I18n.t(:flag_status), value: "```#{flag_status}```", inline: true) e.add_field( name: I18n.t(:next_due_date), value: "```#{next_due_date.strftime(ESM::Time::Format::TIME)}```" ) e.add_field( name: I18n.t(:last_paid), value: "```#{last_paid_at.strftime(ESM::Time::Format::TIME)}```" ) e.add_field(name: I18n.t(:price_to_renew_protection), value: renew_price, inline: true) e.add_field(value: I18n.t("commands.territories.current_territory_stats")) e.add_field(name: I18n.t(:level), value: level, inline: true) e.add_field(name: I18n.t(:radius), value: "#{radius}m", inline: true) e.add_field( name: "#{I18n.t(:current)} / #{I18n.t(:max_objects)}", value: "#{object_count}/#{max_object_count}", inline: true ) if upgradeable? e.add_field(value: I18n.t("commands.territories.next_territory_stats")) e.add_field(name: I18n.t(:level), value: upgrade_level, inline: true) e.add_field(name: I18n.t(:radius), value: "#{upgrade_radius}m", inline: true) e.add_field(name: I18n.t(:max_objects), value: upgrade_object_count, inline: true) e.add_field(name: I18n.t(:price), value: upgrade_price, inline: true) end e.add_field(value: I18n.t("commands.territories.territory_members")) e.add_field(name: ":crown: #{I18n.t(:owner)}", value: owner) if (value = moderators) && value.present? e.add_field(name: ":shield: #{I18n.t(:moderators)}", value:) end if (value = builders) && value.present? e.add_field(name: ":construction_site: #{I18n.t(:build_rights)}", value:) end end end |
#upgrade_level ⇒ Object
100 101 102 |
# File 'lib/esm/model/exile/territory.rb', line 100 def upgrade_level @next_level_territory.territory_level end |
#upgrade_object_count ⇒ Object
135 136 137 |
# File 'lib/esm/model/exile/territory.rb', line 135 def upgrade_object_count @next_level_territory.territory_object_count end |
#upgrade_price ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/esm/model/exile/territory.rb', line 121 def upgrade_price price = @next_level_territory.territory_purchase_price return "#{price.to_delimitated_s} poptabs" if @server_settings.territory_upgrade_tax.zero? # If the server has tax, add it to the price price += (price * (@server_settings.territory_upgrade_tax.to_f / 100)).round "#{price.to_delimitated_s} poptabs (#{@server_settings.territory_upgrade_tax}% tax added)" end |
#upgrade_radius ⇒ Object
131 132 133 |
# File 'lib/esm/model/exile/territory.rb', line 131 def upgrade_radius @next_level_territory.territory_radius end |
#upgradeable? ⇒ Boolean
117 118 119 |
# File 'lib/esm/model/exile/territory.rb', line 117 def upgradeable? !@next_level_territory.nil? end |