Class: LZRTag::Handler::Count

Inherits:
HitArb show all
Defined in:
lib/lzrtag/handler/count_handler.rb

Overview

This class provides useful statistics about the current game and situation.

The various readable attributes contain various information on the game, such as current kill count, damage done, team and brightness composition, etc. Most of this information can be used to determine game progress

Direct Known Subclasses

Game

Instance Attribute Summary collapse

Attributes inherited from Base

#idTable, #mqtt

Instance Method Summary collapse

Methods inherited from HitArb

#_handle_hitArb, #process_raw_hit

Methods inherited from Base

#[], #add_hook, #each, #num_connected, #remove_hook, #send_event

Constructor Details

#initialize(*args, **argHash) ⇒ Count

Returns a new instance of Count.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lzrtag/handler/count_handler.rb', line 20

def initialize(*args, **argHash)
	super(*args, **argHash);

	@teamCount = Hash.new();
	7.times do |i|
		@teamCount[i] = 0;
	end

	@brightnessCount = Hash.new();
	Player::Hardware.getBrightnessKeys().each do |bKey|
		@brightnessCount[bKey] = 0;
	end
end

Instance Attribute Details

#brightnessCountObject (readonly)

Returns a Hash with keys equal to player’s brightnesses, describing how many players have which brightness



18
19
20
# File 'lib/lzrtag/handler/count_handler.rb', line 18

def brightnessCount
  @brightnessCount
end

#teamCountObject (readonly)

Returns a Hash with keys 0..7, describing which teams have how many players



15
16
17
# File 'lib/lzrtag/handler/count_handler.rb', line 15

def teamCount
  @teamCount
end

Instance Method Details

#consume_event(evtName, data) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lzrtag/handler/count_handler.rb', line 35

def consume_event(evtName, data)
	super(evtName, data);

	case evtName
	when :playerRegistered
		@teamCount[data[0].team] += 1;
		@brightnessCount[data[0].brightness] += 1;
	when :playerUnregistered
		@teamCount[data[0].team] -= 1;
		@brightnessCount[data[0].brightness] -= 1;
	when :playerTeamChanged
		@teamCount[data[1]] -= 1;
		@teamCount[data[0].team] += 1;
	when :playerBrightnessChanged
		@brightnessCount[data[1]] -= 1;
		@brightnessCount[data[0].brightness] += 1;
	end
end