hlockey 4 → 6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/data/election.json +20 -0
  3. data/data/information.json +5 -0
  4. data/data/league.json +1984 -0
  5. data/data/links.json +5 -0
  6. data/data/previous_election_results.json +98 -0
  7. data/lib/hlockey/actions.rb +22 -0
  8. data/lib/hlockey/constants.rb +6 -0
  9. data/lib/hlockey/data.rb +6 -5
  10. data/lib/hlockey/game/fight.rb +35 -20
  11. data/lib/hlockey/game/weather/audacity.rb +20 -0
  12. data/lib/hlockey/game/weather/chicken.rb +57 -0
  13. data/lib/hlockey/game/weather/incline.rb +43 -0
  14. data/lib/hlockey/game/weather/stars.rb +23 -0
  15. data/lib/hlockey/game/weather/sunset.rb +23 -0
  16. data/lib/hlockey/game/weather/waves.rb +33 -0
  17. data/lib/hlockey/game/weather/weatherable.rb +63 -0
  18. data/lib/hlockey/game/weather.rb +17 -0
  19. data/lib/hlockey/game.rb +123 -89
  20. data/lib/hlockey/league.rb +68 -76
  21. data/lib/hlockey/message.rb +62 -62
  22. data/lib/hlockey/mod/fencebuilder.rb +16 -0
  23. data/lib/hlockey/mod/fencedestroyer.rb +16 -0
  24. data/lib/hlockey/mod/handholding.rb +55 -0
  25. data/lib/hlockey/mod/immaterial.rb +26 -0
  26. data/lib/hlockey/mod/locked.rb +22 -0
  27. data/lib/hlockey/mod/moddable.rb +49 -0
  28. data/lib/hlockey/mod/nonconfrontational.rb +17 -0
  29. data/lib/hlockey/mod/powernapper.rb +46 -0
  30. data/lib/hlockey/mod/punchy.rb +17 -0
  31. data/lib/hlockey/mod.rb +25 -0
  32. data/lib/hlockey/selfdescribable.rb +9 -0
  33. data/lib/hlockey/team/player.rb +58 -0
  34. data/lib/hlockey/team/stadium.rb +52 -0
  35. data/lib/hlockey/team.rb +66 -25
  36. data/lib/hlockey/utils.rb +10 -2
  37. data/lib/hlockey/version.rb +1 -1
  38. metadata +37 -19
  39. data/data/election.yaml +0 -21
  40. data/data/external/names.txt +0 -19948
  41. data/data/information.yaml +0 -24
  42. data/data/league.yaml +0 -1526
  43. data/data/links.yaml +0 -3
  44. data/data/previous_election_results.yaml +0 -59
  45. data/lib/hlockey/game/actions.rb +0 -27
  46. data/lib/hlockey/player.rb +0 -73
  47. data/lib/hlockey/weather.rb +0 -168
data/data/links.yaml DELETED
@@ -1,3 +0,0 @@
1
- :Website: https://hlockey.onrender.com
2
- :GitHub: https://github.com/Hlockey
3
- :Discord: https://discord.gg/2N8VN8Q69E
@@ -1,59 +0,0 @@
1
- ---
2
- :vote_amt: 182
3
- :categories:
4
- :Bribery (77 votes):
5
- :Winning bribe:
6
- :winner: Flavor Text (39 votes)
7
- :Treasure (65 votes):
8
- :Vengabus:
9
- :winner: Pompei Eruptions (1 vote / 16 total)
10
- :most_votes: Stony Brook Reapers (4 votes)
11
- :Dave:
12
- :winner: Orcadas Base Fog (1 vote / 29 total)
13
- :most_votes: Pompei Eruptions (9 votes)
14
- :Nice:
15
- :winner: Kópavogur Seals (1 vote / 15 total)
16
- :most_votes: Pica Acid (3 votes)
17
- :Convenient Math Error:
18
- :winner: Jakarta Architects (1 vote / 5 total)
19
- :Coaching (40 votes):
20
- :Antalya Pirates:
21
- :winner: Please Win Faceoffs (1 vote / 1 total)
22
- :Baden Hallucinations:
23
- :winner: Small Gamble (1 vote / 2 total)
24
- :Kópavogur Seals:
25
- :winner: Please Block Shots (1 vote / 4 total)
26
- :Lagos Soup:
27
- :winner: Big Gamble (4 votes / 8 total)
28
- :Pica Acid:
29
- :winner: Please Block Shots (1 vote / 2 total)
30
- :Dawson City Impostors:
31
- :winner: Please Win Faceoffs (3 votes / 5 total)
32
- :Erlangen Ohms:
33
- :winner: Draft (1 vote / 1 total)
34
- :Pompei Eruptions:
35
- :winner: Please Block Shots (1 vote / 1 total)
36
- :Rio de Janeiro Directors:
37
- :winner: Please Block Shots (1 vote / 1 total)
38
- :Wyrzysk Rockets:
39
- :winner: Please Win Faceoffs (1 vote / 1 total)
40
- :Cape Town Transplants:
41
- :winner: Small Gamble (1 vote / 1 total)
42
- :Manbij Fish:
43
- :winner: Big Gamble (0 votes / 0 total)
44
- :Nagqu Paint:
45
- :winner: Pleaase Win Faceoffs (1 vote / 1 total)
46
- :Nice Backflippers:
47
- :winner: Draft (1 vote / 1 total)
48
- :Orcadas Base Fog:
49
- :winner: Big Gamble (1 vote / 1 total)
50
- :Baghdad Abacuses:
51
- :winner: Small Gamble (0 votes / 0 total)
52
- :Jakarta Architects:
53
- :winner: Big Gamble (1 vote / 1 total)
54
- :Kyoto Payphones:
55
- :winner: Please Win Faceoffs (1 vote / 2 total)
56
- :Stony Brook Reapers:
57
- :winner: Draft (5 votes / 7 total)
58
- :Sydney Thinkers:
59
- :winner: Please Block Shots (1 vote / 1 total)
@@ -1,27 +0,0 @@
1
- module Hlockey
2
- class Game
3
- ##
4
- # For classes that deal with actions within a Hlockey game.
5
- # Any class including this must have instance variables indicated by the readers
6
- module Actions
7
- # @return [Team] the teams in the game
8
- attr_reader(:home, :away)
9
-
10
- # @return [Random] should be the same as the league's
11
- attr_reader(:prng)
12
-
13
- # @return [Hash<Symbol => Integer>] the score of each team
14
- attr_reader(:score)
15
-
16
- # @return [Boolean] if the sequence of actions is still in progress
17
- attr_reader(:in_progress)
18
-
19
- # @param succeed_boost [Numeric] increases chance of action succeeding
20
- # @param fail_boost [Numeric] decreases chance of action succeeding
21
- # @return [Boolean] if the action succeeded
22
- def action_succeeds?(succeed_boost, fail_boost)
23
- @prng.rand(20) + (succeed_boost - fail_boost) > 9
24
- end
25
- end
26
- end
27
- end
@@ -1,73 +0,0 @@
1
- require("hlockey/utils")
2
-
3
- module Hlockey
4
- class Player
5
- attr_accessor(:team, :stats)
6
- attr_reader(:to_s)
7
-
8
- @cached_chain = nil
9
-
10
- # @param team [Team]
11
- # @param prng [#rand]
12
- def initialize(team, prng = Random)
13
- @to_s = make_name(prng)
14
- @team = team
15
- # Generate stats
16
- @stats = {}
17
- %i[offense defense agility].each { |stat| @stats[stat] = prng.rand * 5 }
18
- end
19
-
20
- # @return [Hash<Symbol => String>]
21
- def stat_strings
22
- @stats.transform_values do |stat|
23
- stat.instance_of?(String) ? stat : stat.round(2).to_s.ljust(4, "0")
24
- end
25
- end
26
-
27
- private
28
-
29
- def make_name(prng)
30
- Array.new(2) do
31
- combination = "__"
32
- next_letter = ""
33
- result = ""
34
-
35
- 10.times do
36
- next_letters = name_chain[combination]
37
- break if next_letters.nil?
38
-
39
- cumulative_weights = []
40
- next_letters.each_value do |v|
41
- cumulative_weights << v + (cumulative_weights.last or 0)
42
- end
43
-
44
- next_letter = Utils.weighted_random(next_letters, prng)
45
- break if next_letter == "_"
46
-
47
- result += next_letter
48
- combination = combination[1] + next_letter
49
- end
50
-
51
- result
52
- end.join(" ")
53
- end
54
-
55
- def name_chain
56
- if @cached_chain.nil?
57
- @cached_chain = {}
58
- File.open(File.expand_path("../../data/external/names.txt", __dir__)).each do |n|
59
- name = "__#{n.chomp}__"
60
- (name.length - 3).times do |i|
61
- combination = name[i, 2]
62
- next_letter = name[i + 2]
63
- @cached_chain[combination] ||= {}
64
- @cached_chain[combination][next_letter] ||= 0
65
- @cached_chain[combination][next_letter] += 1
66
- end
67
- end
68
- end
69
-
70
- @cached_chain
71
- end
72
- end
73
- end
@@ -1,168 +0,0 @@
1
- require("hlockey/game")
2
- require("hlockey/message")
3
- require("hlockey/player")
4
-
5
- module Hlockey
6
- class Weather
7
- def initialize(game)
8
- @game = game
9
- @home = @game.home
10
- @away = @game.away
11
- @prng = @game.prng
12
- end
13
-
14
- def to_s
15
- self.class.to_s.split("::").last
16
- end
17
-
18
- def on_game_start() end
19
-
20
- def on_game_end() end
21
-
22
- def on_period_end() end
23
-
24
- def on_action() end
25
-
26
- def on_goal(scoring_team) end
27
-
28
- private
29
-
30
- # Swaps roster & shadows player, used for Chicken & Waves weather
31
- # @param team_sym [:home, :away]
32
- # @param pos [Symbol] position of player swapped out
33
- # @param shadows_idx [Integer] index of shadows player swapped in
34
- # @return [Array<Player>] the players that were swapped
35
- def swap(team_sym, pos, shadows_idx)
36
- team = @game.send(team_sym)
37
-
38
- prev_player = team.roster[pos]
39
- next_player = team.shadows[shadows_idx]
40
- team.roster[pos] = next_player
41
- team.shadows[shadows_idx] = prev_player
42
-
43
- unless @game.fight.nil?
44
- player_array = @game.fight.players[team_sym]
45
- player_idx = player_array.index(prev_player)
46
-
47
- player_array[player_idx] = next_player unless player_idx.nil?
48
- end
49
-
50
- [prev_player, next_player]
51
- end
52
-
53
- # @return [:home, :away]
54
- def rand_team
55
- @prng.rand(2).zero? ? :home : :away
56
- end
57
- end
58
-
59
- class Audacity < Weather
60
- def on_action
61
- @game.shoot(audacity: true) if @prng.rand(Game::NON_OT_ACTIONS / 10).zero?
62
- end
63
- end
64
-
65
- class Chicken < Weather
66
- def on_game_start
67
- @chickened_out = { home: {}, away: {} }
68
- end
69
-
70
- def on_action
71
- return unless @prng.rand(Game::NON_OT_ACTIONS / 5).zero?
72
-
73
- team = rand_team
74
- pos, shadows_idx = get_swap(team)
75
- if pos.nil? || shadows_idx.nil?
76
- team = team == :home ? :away : :home
77
- pos, shadows_idx = get_swap(team)
78
- return if pos.nil? || shadows_idx.nil?
79
- end
80
-
81
- @chickened_out[team][pos] = shadows_idx
82
-
83
- @game.stream << Message.ChickenedOut(*swap(team, pos, shadows_idx))
84
- end
85
-
86
- def on_game_end
87
- @chickened_out.each do |team, swaps|
88
- swaps.each { |pos, shadows_idx| swap(team, pos, shadows_idx) }
89
- end
90
- end
91
-
92
- private
93
-
94
- # @param team_sym [:home, :away]
95
- # @return [Array<Symbol, Integer>]
96
- def get_swap(team_sym)
97
- team = @game.send(team_sym)
98
-
99
- [
100
- (team.roster.keys - @chickened_out[team_sym].keys).sample(random: @prng),
101
- (team.shadows.each_index.to_a - @chickened_out[team_sym].values)
102
- .sample(random: @prng)
103
- ]
104
- end
105
- end
106
-
107
- class Inclines < Weather
108
- def on_game_start
109
- make_incline
110
- end
111
-
112
- def on_goal(scoring_team)
113
- return unless scoring_team == @favored_team
114
-
115
- @game.score[scoring_team] += @prng.rand(0.1..0.5)
116
- make_incline
117
- end
118
-
119
- private
120
-
121
- def make_incline
122
- new_favored_team = rand_team
123
- return unless new_favored_team != @favored_team
124
-
125
- @favored_team = new_favored_team
126
- @game.stream << Message.InclineFavors(@game.send(@favored_team))
127
- end
128
- end
129
-
130
- class Stars < Weather
131
- def on_period_end
132
- team = %i[home away].find { |sym| @game.send(sym).to_s == "Sleepers" }
133
- if team.nil?
134
- return if @game.score[:home] == @game.score[:away]
135
-
136
- team = @game.score.min_by { |_, v| v }.first
137
- end
138
-
139
- @game.score[team] += 0.5
140
- @game.stream << Message.StarsAlign(@game.send(team))
141
- end
142
- end
143
-
144
- class Sunset < Weather
145
- def on_game_start
146
- @score_amt = { home: 0, away: 0 }
147
- end
148
-
149
- def on_goal(scoring_team)
150
- @score_amt[scoring_team] += 1
151
- @game.score[scoring_team] -= @score_amt[scoring_team] * 0.2
152
- end
153
- end
154
-
155
- class Waves < Weather
156
- def on_action
157
- return unless @prng.rand(Game::NON_OT_ACTIONS).zero?
158
-
159
- team_sym = rand_team
160
- team = @game.send(team_sym)
161
- @game.stream << Message.WavesWashedAway(*swap(team_sym,
162
- team.worst_player_pos,
163
- @prng.rand(team.shadows.length)))
164
- end
165
- end
166
-
167
- Weather::WEATHERS = [Audacity, Chicken, Inclines, Stars, Sunset, Waves].freeze
168
- end