From aa0d0673b69019e2d5363e5535a9c8c28c8ad0e1 Mon Sep 17 00:00:00 2001 From: jamal Date: Sat, 11 Oct 2014 15:50:06 -0400 Subject: [PATCH] Change Gather style to volunteer captains This will change the gather format to allow for players to volunteer to be captain / commander. The gather will not change from the running state until 2 commanders have volunteered. Once commanders have volunteered the gather will switch to the picking state. The voting state is no longer used. Also, added a new sound alert that will be played when the gather is full but doesn't have 2 captains. This alert will loop every 10 seconds unless you're the commander. And changed the music to play once the gather switches to the picking state and only if the player doesn't have the gather page on focus. --- app/controllers/gathers_controller.rb | 16 +++++++++++ app/helpers/gathers_helper.rb | 8 ++++-- app/models/gather.rb | 22 ++++++++++++-- app/models/gatherer.rb | 8 +++++- app/models/shoutmsg.rb | 1 - app/views/gathers/_running.html.erb | 7 +++++ app/views/gathers/_status.html.erb | 19 ++++++++++-- app/views/gathers/show.html.erb | 40 ++++++++++++++++++++------ config/locales/en.yml | 1 + public/sounds/gather-alert.mp3 | Bin 0 -> 8747 bytes 10 files changed, 103 insertions(+), 19 deletions(-) create mode 100644 public/sounds/gather-alert.mp3 diff --git a/app/controllers/gathers_controller.rb b/app/controllers/gathers_controller.rb index d8f4a87..3f7d949 100644 --- a/app/controllers/gathers_controller.rb +++ b/app/controllers/gathers_controller.rb @@ -63,6 +63,22 @@ class GathersController < ApplicationController redirect_to @gather end + def captain + raise AccessError unless @gatherer + + if @gather.captain1.nil? and @gather.captain2 != @gatherer + @gather.update_attribute :captain1, @gatherer + elsif @gather.captain2.nil? and @gather.captain1 != @gatherer + @gather.update_attribute :captain2, @gatherer + elsif @gatherer == @gather.captain1 + @gather.update_attribute :captain1, nil + elsif @gatherer == @gather.captain2 + @gather.update_attribute :captain2, nil + end + + redirect_to @gather + end + private def get_gather diff --git a/app/helpers/gathers_helper.rb b/app/helpers/gathers_helper.rb index 90dbaee..44274de 100644 --- a/app/helpers/gathers_helper.rb +++ b/app/helpers/gathers_helper.rb @@ -1,8 +1,12 @@ module GathersHelper def render_gather if @gather.status == Gather::STATE_RUNNING - headers['Gather'] = 'running' - + if @gather.is_full? and !@gather.is_ready? and @gather.captain1 != @gatherer and @gather.captain2 != @gatherer + headers['Gather'] = 'full' + else + headers['Gather'] = 'running' + end + render partial: 'running', layout: false elsif @gather.status == Gather::STATE_VOTING if @gatherer and @gather.gatherer_votes.first(conditions: { user_id: cuser.id }) diff --git a/app/models/gather.rb b/app/models/gather.rb index 21507a2..ac1e4ae 100644 --- a/app/models/gather.rb +++ b/app/models/gather.rb @@ -89,6 +89,17 @@ class Gather < ActiveRecord::Base 5 end + def is_full? + return gatherers.count == Gather::FULL + end + + def is_ready? + if is_full? and !captain1.nil? and !captain2.nil? + return true + end + false + end + def first Gather.where(:category_id => category_id).order("id ASC").first end @@ -124,8 +135,6 @@ class Gather < ActiveRecord::Base g = Gather.new g.category = self.category g.save - self.captain1 = self.gatherers.most_voted[1] - self.captain2 = self.gatherers.most_voted[0] if self.gather_maps.count > 1 self.map1 = self.gather_maps.ordered[0] self.map2 = self.gather_maps.ordered[1] @@ -139,7 +148,7 @@ class Gather < ActiveRecord::Base end def check_captains - if captain1_id_changed? or captain2_id_changed? or admin + if status == STATE_RUNNING and is_ready? or admin self.turn = 1 self.status = STATE_PICKING gatherers.each do |gatherer| @@ -151,6 +160,13 @@ class Gather < ActiveRecord::Base gatherer.update_attributes(:team => nil, :skip_callbacks => true) end end + + # Create a new shout msgs when the gather is full + Shoutmsg.new({ + :shoutable_type => self.class.to_s, + :shoutable_id => self.id, + :text => I18n.t(:gather_start_shout) + }).save end end diff --git a/app/models/gatherer.rb b/app/models/gatherer.rb index 0b49f1b..45133c8 100644 --- a/app/models/gatherer.rb +++ b/app/models/gatherer.rb @@ -70,7 +70,7 @@ class Gatherer < ActiveRecord::Base validates :confirm, :acceptance => true, :unless => Proc.new {|gatherer| gatherer.user.gatherers.count >= 5} validate :validate_username - after_create :start_gather, :if => Proc.new {|gatherer| gatherer.gather.gatherers.count == Gather::FULL} + after_create :start_gather, :if => Proc.new {|gatherer| gatherer.gather.is_ready?} after_create :notify_gatherers, :if => Proc.new {|gatherer| gatherer.gather.gatherers.count == Gather::NOTIFY} after_update :change_turn, :unless => Proc.new {|gatherer| gatherer.skip_callbacks == true} after_destroy :cleanup_votes @@ -118,6 +118,12 @@ class Gatherer < ActiveRecord::Base end def cleanup_votes + if gather.captain1_id == id + gather.update_attribute :captain1, nil + elsif gather.captain2_id == id + gather.update_attribute :captain2, nil + end + gather.map_votes.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } gather.server_votes.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } gather.gatherer_votes.all(:conditions => {:user_id => user_id}).each { |g| g.destroy } diff --git a/app/models/shoutmsg.rb b/app/models/shoutmsg.rb index 60e0d59..45d7a47 100644 --- a/app/models/shoutmsg.rb +++ b/app/models/shoutmsg.rb @@ -17,7 +17,6 @@ class Shoutmsg < ActiveRecord::Base attr_protected :id, :created_at, :updated_at, :user_id validates_length_of :text, :in => 1..100 - validates_presence_of :user scope :recent, :include => :user, diff --git a/app/views/gathers/_running.html.erb b/app/views/gathers/_running.html.erb index de2d68f..3971c18 100644 --- a/app/views/gathers/_running.html.erb +++ b/app/views/gathers/_running.html.erb @@ -9,6 +9,13 @@ 0 %> class="away"<% end %>> <%= flag gatherer.user.country %> <%= namelink gatherer.user %> + + <% if gatherer == @gather.captain1 or gatherer == @gather.captain2 %> + + <%= icon('star') %> + + <% end %> + <% if cuser and cuser.admin? %> <%= link_to gatherer, method: :delete, class: 'delete' do %> <%= icon 'times' %> diff --git a/app/views/gathers/_status.html.erb b/app/views/gathers/_status.html.erb index 50a508d..12177c0 100644 --- a/app/views/gathers/_status.html.erb +++ b/app/views/gathers/_status.html.erb @@ -2,15 +2,28 @@ <% if @gather.status == Gather::STATE_RUNNING %> <% if @gatherer and @gatherer.can_destroy? cuser %> -

Gather running, <%= Gather::FULL - @gather.gatherers.length %> more needed.

- <%= link_to 'Leave Gather', @gatherer, confirm: 'Are you sure?', method: :delete, class: 'button tiny' %> + <% if Gather::FULL == @gather.gatherers.length %> +

Gather is full but we are waiting on commanders. If you would like to command, please use the button below.

+ <% else %> +

Gather running, <%= Gather::FULL - @gather.gatherers.length %> more needed.

+ <% end %> + + <%= form_tag "/gathers/captain/#{@gather.id}" do %> + <%= submit_tag (@gather.captain1 == @gatherer or @gather.captain2 == @gatherer) ? 'Stop Commanding' : 'Command a Team', class: 'button tiny' %> + <% end %> + + <%= link_to 'Leave Gather', @gatherer, confirm: 'Are you sure?', method: :delete, class: 'button tiny leave-gather' %> <% elsif (g = Gatherer.new(gather: @gather, user: cuser)).can_create?(cuser) %> <%= form_for g do |f| %> <%= f.hidden_field :gather_id %> <%= f.hidden_field :user_id %> -

Gather running, <%= Gather::FULL - @gather.gatherers.length %> more needed.

+ <% if Gather::FULL == @gather.gatherers.length %> +

Gather is full but we are waiting on commanders. If you would like to command, please use the button below.

+ <% else %> +

Gather running, <%= Gather::FULL - @gather.gatherers.length %> more needed.

+ <% end %>

You can download custom maps via the <%= link_to "Steam Workshop", "http://steamcommunity.com/workshop/browse?searchtext=&childpublishedfileid=0§ion=items&appid=4920&browsesort=trend&requiredtags%5B%5D=level" %>. diff --git a/app/views/gathers/show.html.erb b/app/views/gathers/show.html.erb index 509c9d1..463415c 100644 --- a/app/views/gathers/show.html.erb +++ b/app/views/gathers/show.html.erb @@ -1,5 +1,6 @@