Class: KAG::Gather::Team

Inherits:
SymbolTable
  • Object
show all
Defined in:
lib/kag/gather/team.rb

Instance Method Summary collapse

Instance Method Details

#has_player?(user) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/kag/gather/team.rb', line 47

def has_player?(user)
  if user.authname
    self.players.keys.include?(user.authname.to_sym)
  else
    false
  end
end

#kick_allObject



79
80
81
82
83
# File 'lib/kag/gather/team.rb', line 79

def kick_all
  self.players.each do |authname,user|
    self.match.server.kick(user.nick.to_s)
  end
end

#notify_of_match_startObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kag/gather/team.rb', line 27

def notify_of_match_start
  server = self.match.server
  msg = "Join \x0305#{server[:key]} - #{server[:ip]}:#{server[:port]} \x0306password #{server[:password]}\x0301 | Visit kag://#{server[:ip]}/#{server[:password]} | "
  msg = msg + " \x0303Class: " if KAG::Config.instance[:pick_classes]

  messages = {}
  self.players.each do |authname,user|
    player_msg = msg.clone
    player_msg = player_msg+cls if KAG::Config.instance[:pick_classes] and cls and !cls.empty?
    player_msg = player_msg+" #{self[:color]}#{self[:name]} with: #{self.teammates.keys.join(", ")}"
    messages[user] = player_msg
  end
  puts messages.inspect
  messages
end

#remove_player(user) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/kag/gather/team.rb', line 55

def remove_player(user)
  if has_player?(user)
    sub = {}
    sub[:cls] = self.teammates[user.authname.to_sym]
    sub[:team] = self.clone
    sub[:msg] = "Sub needed at #{self.match.server[:ip]} for #{sub[:team][:name]}, #{sub[:cls]} Class! Type !sub to claim it!"
    sub[:channel_msg] = "[[+user]] is now subbing in for #{self[:name]} at #{self.match.server[:key]}. Subs still needed: #{self.match[:subs_needed].length}"
    sub[:private_msg] = "Please #{self.match.server.text_join} | #{sub[:cls]} on the #{self[:name]} Team"
    self.players.delete(user.authname.to_sym)
    self.teammates.delete(user.authname.to_sym)

    KAG::User::User.subtract_stat(user,:matches)
    KAG::User::User.add_stat(user,:desertions)

    if self.match and self.match.server
      self.match.server.kick(user.nick)
    end

    sub
  else
    false
  end
end

#setupObject



11
12
13
14
# File 'lib/kag/gather/team.rb', line 11

def setup
  setup_classes
  self
end

#setup_classesObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/kag/gather/team.rb', line 16

def setup_classes
  classes = KAG::Config.instance[:classes].clone
  classes.shuffle!

  self.teammates = {}
  self.players.each do |authname,user|
    self.teammates[authname.to_sym] = classes.shift
  end
  self
end

#text_for_match_startObject



43
44
45
# File 'lib/kag/gather/team.rb', line 43

def text_for_match_start
  "#{self[:color]}#{self.players.keys.join(", ")} (#{self[:name]})"
end