2015-04-15 11:00:32 -04:00
|
|
|
require './environments'
|
|
|
|
|
|
|
|
set :public_folder, 'public'
|
|
|
|
|
2015-04-23 14:46:51 -04:00
|
|
|
# CONTROLLER
|
2015-04-15 11:00:32 -04:00
|
|
|
get '/' do
|
2015-04-26 09:42:23 -04:00
|
|
|
@raids = Raid.order('created_at DESC').page(params[:page])
|
2015-04-25 13:17:47 -04:00
|
|
|
leaders = Leader.all
|
|
|
|
last_update = leaders.first ? leaders.first.created_at : DateTime.new(0)
|
2015-04-26 11:42:19 -04:00
|
|
|
if last_update + 300 < DateTime.now
|
|
|
|
rebuild_leaders
|
2015-04-23 16:09:59 -04:00
|
|
|
end
|
|
|
|
|
2015-04-26 11:42:19 -04:00
|
|
|
leaders = Leader.all.includes(:last_attack, :last_defense)
|
2015-04-26 11:49:08 -04:00
|
|
|
@top20 = leaders.reject { |l| l.last_action } + leaders.select { |l| l.last_action }.sort_by { |l| l.last_action }
|
2015-04-23 16:57:54 -04:00
|
|
|
|
2015-04-15 11:00:32 -04:00
|
|
|
erb :index
|
|
|
|
end
|
|
|
|
|
|
|
|
post '/' do
|
2015-04-29 09:42:36 -04:00
|
|
|
#response['Access-Control-Allow-Origin'] = 'http://trugul.com'
|
|
|
|
|
|
|
|
#@raid = Raid.new(params[:raid])
|
|
|
|
|
|
|
|
#if @raid.save
|
|
|
|
# content_type :json
|
|
|
|
# { :message => 'Raid saved' }.to_json
|
|
|
|
#else
|
|
|
|
# content_type :json
|
|
|
|
# { :message => 'Raid failed to save' }.to_json
|
|
|
|
#end
|
|
|
|
content_type :json
|
|
|
|
{ :message => 'Raid saving no longer available' }.to_json
|
2015-04-15 11:00:32 -04:00
|
|
|
end
|
2015-04-28 10:12:01 -04:00
|
|
|
|
2015-04-28 10:41:58 -04:00
|
|
|
get '/bossfight' do
|
|
|
|
@username = params['username'] ? params['username'] : 'mafiaman'
|
2015-04-28 11:51:18 -04:00
|
|
|
user_defenses = Raid.defenses_for_user(@username)
|
|
|
|
user_attacks = Raid.attacks_for_user(@username)
|
|
|
|
|
2015-04-28 11:59:39 -04:00
|
|
|
first_negative = user_defenses.first_negative
|
|
|
|
@kill_date = first_negative ? first_negative.created_at : DateTime.now
|
|
|
|
@kill_user = first_negative ? first_negative.attacker : '<strong>UNKILLED</strong>'
|
2015-04-28 11:51:18 -04:00
|
|
|
|
2015-04-28 11:59:39 -04:00
|
|
|
@soldiers_killed = user_defenses.soldiers_lost_to_date(@kill_date)
|
2015-04-28 14:08:07 -04:00
|
|
|
@soldiers_killed += user_attacks.soldiers_lost_to_date(@kill_date)
|
2015-04-28 11:51:18 -04:00
|
|
|
|
2015-04-28 11:59:39 -04:00
|
|
|
@contributor_attacks = user_defenses.contributor_attacks(@kill_date)
|
|
|
|
@contributor_soldiers = user_defenses.contributor_soldiers(@kill_date)
|
|
|
|
|
|
|
|
@contributor_defenses = user_attacks.contributor_defenses(@kill_date)
|
|
|
|
@contributor_defenders = user_attacks.contributor_defenders(@kill_date)
|
2015-04-28 11:36:17 -04:00
|
|
|
|
|
|
|
@contributors = []
|
|
|
|
@contributor_attacks.each do |k, v|
|
2015-04-28 11:51:18 -04:00
|
|
|
attacks = @contributor_attacks[k] || 0
|
2015-04-28 12:01:22 -04:00
|
|
|
defenses = @contributor_defenses[k] || 0
|
2015-04-28 11:51:18 -04:00
|
|
|
lost = @contributor_soldiers[k] || 0
|
|
|
|
lost += @contributor_defenders[k] if @contributor_defenders[k]
|
|
|
|
@contributors << {
|
|
|
|
username: k,
|
|
|
|
attacks: attacks,
|
2015-04-28 12:01:22 -04:00
|
|
|
defenses: defenses,
|
2015-04-28 11:51:18 -04:00
|
|
|
lost: lost
|
|
|
|
}
|
2015-04-28 11:36:17 -04:00
|
|
|
end
|
2015-04-28 10:12:01 -04:00
|
|
|
|
2015-04-28 11:53:49 -04:00
|
|
|
@contributors = @contributors.sort_by { |c| c[:lost] }.reverse
|
|
|
|
|
2015-04-28 10:12:01 -04:00
|
|
|
erb :bossfight
|
|
|
|
end
|