smash_and_grab 0.0.5alpha → 0.0.6alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/{CHANGELOG.txt → CHANGELOG.md} +0 -0
  2. data/Gemfile.lock +8 -4
  3. data/LICENSE.txt +20 -0
  4. data/README.md +30 -14
  5. data/Rakefile +2 -2
  6. data/config/lang/objects/entities/en.yml +134 -0
  7. data/config/lang/objects/static/en.yml +8 -0
  8. data/config/lang/objects/vehicles/en.yml +11 -0
  9. data/config/map/entities.yml +42 -38
  10. data/lib/smash_and_grab.rb +5 -0
  11. data/lib/smash_and_grab/abilities.rb +1 -1
  12. data/lib/smash_and_grab/abilities/ability.rb +45 -3
  13. data/lib/smash_and_grab/abilities/drop.rb +38 -0
  14. data/lib/smash_and_grab/abilities/melee.rb +4 -6
  15. data/lib/smash_and_grab/abilities/pick_up.rb +33 -0
  16. data/lib/smash_and_grab/abilities/ranged.rb +18 -12
  17. data/lib/smash_and_grab/abilities/sprint.rb +11 -7
  18. data/lib/smash_and_grab/chingu_ext/basic_game_object.rb +26 -0
  19. data/lib/smash_and_grab/game_window.rb +5 -1
  20. data/lib/smash_and_grab/gui/entity_panel.rb +26 -10
  21. data/lib/smash_and_grab/gui/entity_summary.rb +19 -11
  22. data/lib/smash_and_grab/gui/game_log.rb +6 -2
  23. data/lib/smash_and_grab/gui/info_panel.rb +7 -4
  24. data/lib/smash_and_grab/gui/object_panel.rb +6 -2
  25. data/lib/smash_and_grab/gui/scenario_panel.rb +4 -0
  26. data/lib/smash_and_grab/history/action_history.rb +1 -1
  27. data/lib/smash_and_grab/main.rb +7 -3
  28. data/lib/smash_and_grab/map/faction.rb +26 -8
  29. data/lib/smash_and_grab/map/map.rb +21 -12
  30. data/lib/smash_and_grab/map/tile.rb +29 -2
  31. data/lib/smash_and_grab/map/wall.rb +2 -2
  32. data/lib/smash_and_grab/mixins/has_contents.rb +38 -0
  33. data/lib/smash_and_grab/mixins/line_of_sight.rb +129 -0
  34. data/lib/smash_and_grab/mixins/pathfinding.rb +145 -0
  35. data/lib/smash_and_grab/mouse_selection.rb +107 -36
  36. data/lib/smash_and_grab/objects/entity.rb +311 -260
  37. data/lib/smash_and_grab/objects/floating_text.rb +0 -1
  38. data/lib/smash_and_grab/objects/static.rb +10 -3
  39. data/lib/smash_and_grab/objects/vehicle.rb +7 -2
  40. data/lib/smash_and_grab/objects/world_object.rb +10 -3
  41. data/lib/smash_and_grab/path.rb +38 -12
  42. data/lib/smash_and_grab/players/ai.rb +91 -0
  43. data/lib/smash_and_grab/players/human.rb +9 -0
  44. data/lib/smash_and_grab/players/player.rb +16 -65
  45. data/lib/smash_and_grab/players/remote.rb +9 -0
  46. data/lib/smash_and_grab/sprite_sheet.rb +9 -0
  47. data/lib/smash_and_grab/states/edit_level.rb +15 -4
  48. data/lib/smash_and_grab/states/main_menu.rb +16 -4
  49. data/lib/smash_and_grab/states/play_level.rb +88 -28
  50. data/lib/smash_and_grab/states/world.rb +17 -9
  51. data/lib/smash_and_grab/version.rb +1 -1
  52. data/lib/smash_and_grab/z_order.rb +6 -5
  53. data/media/images/path.png +0 -0
  54. data/media/images/tile_selection.png +0 -0
  55. data/media/images/tiles_selection.png +0 -0
  56. data/smash_and_grab.gemspec +2 -2
  57. data/tasks/create_portraits.rb +39 -0
  58. data/tasks/outline_images.rb +56 -0
  59. data/test/smash_and_grab/abilities/drop_test.rb +68 -0
  60. data/test/smash_and_grab/abilities/melee_test.rb +4 -4
  61. data/test/smash_and_grab/abilities/pick_up_test.rb +68 -0
  62. data/test/smash_and_grab/abilities/ranged_test.rb +105 -0
  63. data/test/smash_and_grab/abilities/sprint_test.rb +55 -25
  64. data/test/smash_and_grab/map/faction_test.rb +18 -16
  65. data/test/smash_and_grab/map/map_test.rb +9 -4
  66. metadata +51 -19
  67. data/lib/smash_and_grab/fidgit_ext/event.rb +0 -77
@@ -0,0 +1,68 @@
1
+ require_relative "../../teststrap"
2
+ require_relative "helpers/ability_helper"
3
+ describe SmashAndGrab::Abilities::Drop do
4
+ before do
5
+ @entity = Object.new
6
+ @object = Object.new
7
+ @map = Object.new
8
+ @tile = SmashAndGrab::Tile.new(:grass, nil, 1, 2)
9
+ end
10
+
11
+ subject { SmashAndGrab::Abilities.ability @entity, type: :drop }
12
+
13
+ behaves_like SmashAndGrab::Abilities::Ability
14
+
15
+ should "be initialized" do
16
+ subject.owner.should.equal @entity
17
+ subject.can_be_undone?.should.be.true
18
+ subject.skill.should.equal 0
19
+ subject.action_cost.should.equal 1
20
+ end
21
+
22
+ should "serialize to json correctly" do
23
+ JSON.parse(subject.to_json).symbolize.should.equal(
24
+ type: :drop,
25
+ skill: 0,
26
+ action_cost: 1
27
+ )
28
+ end
29
+
30
+ should "generate appropriate action_data" do
31
+ stub(@entity).id.returns 12
32
+ stub(@object).id.returns 13
33
+ stub(@entity).contents.returns @object
34
+ mock(@entity).tile.stub!.adjacent_tiles(@entity).stub!.find_all(&:empty?).stub!.sample.returns @tile
35
+ subject.action_data.should.equal(
36
+ ability: :drop,
37
+ skill: 0,
38
+ action_cost: 1,
39
+
40
+ owner_id: 12,
41
+ target_id: 13,
42
+ target_position: [1, 2],
43
+ )
44
+ end
45
+
46
+ describe "#do" do
47
+ should "remove action points and drop object onto the tile" do
48
+ stub(@entity).action_points.returns 1
49
+ mock(@entity).map.stub!.tile_at_grid(1, 2).returns @tile
50
+ mock(@entity).action_points = 0
51
+ mock(@entity).drop @tile
52
+
53
+ subject.do action_cost: 1, target_id: 13, target_position: [1, 2]
54
+ end
55
+ end
56
+
57
+ describe "#undo" do
58
+ should "give give action points and pick up the object from tile" do
59
+ stub(@object).tile.returns @tile
60
+ stub(@entity).map.stub!.object_by_id(13).returns @object
61
+ stub(@entity).action_points.returns 0
62
+ mock(@entity).action_points = 1
63
+ mock(@entity).pick_up @object
64
+
65
+ subject.undo action_cost: 1, target_id: 13, target_position: [1, 2]
66
+ end
67
+ end
68
+ end
@@ -58,7 +58,7 @@ describe SmashAndGrab::Abilities::Melee do
58
58
 
59
59
  should "never give a value less than 1" do
60
60
  stub(subject).rand(is_a(Integer)) { 0 }
61
- subject.random_damage == 1
61
+ subject.random_damage == 0
62
62
  end
63
63
  end
64
64
 
@@ -67,7 +67,7 @@ describe SmashAndGrab::Abilities::Melee do
67
67
  stub(@entity).map.stub!.object_by_id(13).returns @enemy
68
68
  stub(@entity).action_points.returns 1
69
69
  mock(@entity).action_points = 0
70
- mock(@entity).melee(@enemy, 5)
70
+ mock(@entity).make_melee_attack(@enemy, 5)
71
71
 
72
72
  subject.do action_cost: 1, target_id: 13, damage: 5 #, target_position: [1, 2]
73
73
  end
@@ -79,7 +79,7 @@ describe SmashAndGrab::Abilities::Melee do
79
79
  stub(@entity).map.stub!.object_by_id(13).returns @enemy
80
80
  stub(@entity).action_points.returns 0
81
81
  mock(@entity).action_points = 1
82
- mock(@entity).melee(@enemy, -5)
82
+ mock(@entity).make_melee_attack(@enemy, -5)
83
83
 
84
84
  subject.undo action_cost: 1, target_id: 13, damage: 5, target_position: [1, 2]
85
85
  end
@@ -87,7 +87,7 @@ describe SmashAndGrab::Abilities::Melee do
87
87
  should "give action points, health and return to map (if target dead)" do
88
88
  stub(@enemy).tile.returns nil
89
89
  mock(@enemy).tile = @tile
90
- mock(@entity).melee(@enemy, -5)
90
+ mock(@entity).make_melee_attack(@enemy, -5)
91
91
 
92
92
  stub(@entity).map do
93
93
  stub(@map).object_by_id(13).returns @enemy
@@ -0,0 +1,68 @@
1
+ require_relative "../../teststrap"
2
+ require_relative "helpers/ability_helper"
3
+ describe SmashAndGrab::Abilities::PickUp do
4
+ before do
5
+ @entity = Object.new
6
+ @object = Object.new
7
+ @map = Object.new
8
+ @tile = SmashAndGrab::Tile.new(:grass, nil, 1, 2)
9
+ end
10
+
11
+ subject { SmashAndGrab::Abilities.ability @entity, type: :pick_up }
12
+
13
+ behaves_like SmashAndGrab::Abilities::Ability
14
+
15
+ should "be initialized" do
16
+ subject.owner.should.equal @entity
17
+ subject.can_be_undone?.should.be.true
18
+ subject.skill.should.equal 0
19
+ subject.action_cost.should.equal 1
20
+ end
21
+
22
+ should "serialize to json correctly" do
23
+ JSON.parse(subject.to_json).symbolize.should.equal(
24
+ type: :pick_up,
25
+ skill: 0,
26
+ action_cost: 1
27
+ )
28
+ end
29
+
30
+ should "generate appropriate action_data" do
31
+ stub(@entity).id.returns 12
32
+ stub(@object).id.returns 13
33
+ stub(@object).tile.returns @tile
34
+ stub(@tile).object.returns @object
35
+ stub(subject).random_damage.returns 5
36
+ subject.action_data(@object).should.equal(
37
+ ability: :pick_up,
38
+ skill: 0,
39
+ action_cost: 1,
40
+
41
+ owner_id: 12,
42
+ target_id: 13,
43
+ target_position: [1, 2],
44
+ )
45
+ end
46
+
47
+ describe "#do" do
48
+ should "remove action points and pick up" do
49
+ stub(@entity).map.stub!.object_by_id(13).returns @object
50
+ stub(@entity).action_points.returns 1
51
+ mock(@entity).action_points = 0
52
+ mock(@entity).pick_up @object
53
+
54
+ subject.do action_cost: 1, target_id: 13, target_position: [1, 2]
55
+ end
56
+ end
57
+
58
+ describe "#undo" do
59
+ should "give give action points and drop" do
60
+ stub(@entity).action_points.returns 0
61
+ mock(@entity).map.stub!.tile_at_grid(1, 2).returns @tile
62
+ mock(@entity).action_points = 1
63
+ mock(@entity).drop @tile
64
+
65
+ subject.undo action_cost: 1, target_id: 13, target_position: [1, 2]
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,105 @@
1
+ require_relative "../../teststrap"
2
+ require_relative "helpers/ability_helper"
3
+
4
+ describe SmashAndGrab::Abilities::Ranged do
5
+ before do
6
+ @entity = Object.new
7
+ @enemy = Object.new
8
+ @map = Object.new
9
+ @tile = SmashAndGrab::Tile.new(:grass, nil, 1, 2)
10
+ end
11
+
12
+ subject { SmashAndGrab::Abilities.ability @entity, type: :ranged, skill: 5, max_range: 5 }
13
+
14
+ behaves_like SmashAndGrab::Abilities::Ability
15
+
16
+ should "fail if not given the required arguments" do
17
+ ->{ SmashAndGrab::Abilities.ability @entity, type: :ranged }.should.raise(ArgumentError).message.should.match /no :max_range specified/
18
+ end
19
+
20
+ should "be initialized" do
21
+ subject.owner.should.equal @entity
22
+ subject.can_be_undone?.should.be.false
23
+ subject.skill.should.equal 5
24
+ subject.action_cost.should.equal 1
25
+ end
26
+
27
+ should "serialize to json correctly" do
28
+ JSON.parse(subject.to_json).symbolize.should.equal(
29
+ type: :ranged,
30
+ skill: 5,
31
+ action_cost: 1,
32
+ min_range: 2,
33
+ max_range: 5
34
+ )
35
+ end
36
+
37
+ should "generate appropriate action_data" do
38
+ stub(@entity).id.returns 12
39
+ stub(@enemy).id.returns 13
40
+ stub(@enemy).tile.returns @tile
41
+ stub(@tile).object.returns @enemy
42
+ stub(subject).random_damage.returns 5
43
+ subject.action_data(@enemy).should.equal(
44
+ ability: :ranged,
45
+ skill: 5,
46
+ action_cost: 1,
47
+
48
+ owner_id: 12,
49
+ target_id: 13,
50
+ target_position: [1, 2],
51
+ damage: 5
52
+ )
53
+ end
54
+
55
+ describe "#random_damage" do
56
+ should "never give a value greater than skill" do
57
+ stub(subject).rand(is_a(Integer)) {|x| x - 1 }
58
+ subject.random_damage == 5
59
+ end
60
+
61
+ should "never give a value less than 1" do
62
+ stub(subject).rand(is_a(Integer)) { 0 }
63
+ subject.random_damage == 0
64
+ end
65
+ end
66
+
67
+ describe "#do" do
68
+ should "remove action points and health" do
69
+ stub(@entity).map.stub!.object_by_id(13).returns @enemy
70
+ stub(@entity).action_points.returns 1
71
+ mock(@entity).action_points = 0
72
+ mock(@entity).make_ranged_attack(@enemy, 5)
73
+
74
+ subject.do action_cost: 1, target_id: 13, damage: 5 #, target_position: [1, 2]
75
+ end
76
+ end
77
+
78
+ describe "#undo" do
79
+ should "give action points and health (if target alive)" do
80
+ stub(@enemy).tile.returns @tile
81
+ stub(@entity).map.stub!.object_by_id(13).returns @enemy
82
+ stub(@entity).action_points.returns 0
83
+ mock(@entity).action_points = 1
84
+ mock(@entity).make_ranged_attack(@enemy, -5)
85
+
86
+ subject.undo action_cost: 1, target_id: 13, damage: 5, target_position: [1, 2]
87
+ end
88
+
89
+ should "give action points, health and return to map (if target dead)" do
90
+ stub(@enemy).tile.returns nil
91
+ mock(@enemy).tile = @tile
92
+ mock(@entity).make_ranged_attack(@enemy, -5)
93
+
94
+ stub(@entity).map do
95
+ stub(@map).object_by_id(13).returns @enemy
96
+ stub(@map).tile_at_grid([1, 2]).returns @tile
97
+ @map
98
+ end
99
+ stub(@entity).action_points.returns 0
100
+ mock(@entity).action_points = 1
101
+
102
+ subject.undo action_cost: 1, target_id: 13, damage: 5, target_position: [1, 2]
103
+ end
104
+ end
105
+ end
@@ -2,22 +2,32 @@ require_relative "../../teststrap"
2
2
  require_relative "helpers/ability_helper"
3
3
 
4
4
  describe SmashAndGrab::Abilities::Sprint do
5
- helper(:entity) { @entity ||= Object.new }
5
+ before do
6
+ @entity = Object.new
7
+ mock(@entity).subscribe :ended_turn
8
+ end
6
9
 
7
- subject { SmashAndGrab::Abilities.ability entity, type: :sprint, skill: 3 }
10
+ subject { SmashAndGrab::Abilities.ability @entity, type: :sprint, skill: 3 }
8
11
 
9
12
  behaves_like SmashAndGrab::Abilities::Ability
10
13
 
11
14
  should "fail if not given the required arguments" do
12
- ->{ SmashAndGrab::Abilities.ability entity, type: :sprint }.should.raise(ArgumentError).message.should.match /No skill value for/
15
+ ->{ SmashAndGrab::Abilities.ability @entity, type: :sprint }.should.raise(ArgumentError).message.should.match /No skill value for/
13
16
  end
14
17
 
15
18
  should "be initialized" do
16
- subject.owner.should.equal entity
19
+ stub(@entity).max_action_points.returns 2
20
+ stub(@entity).action_points.returns 2
21
+ stub(@entity).max_movement_points.returns 5
22
+ stub(@entity).movement_points.returns 5
23
+
24
+ subject.owner.should.equal @entity
17
25
  subject.can_be_undone?.should.be.true
18
26
  subject.skill.should.equal 3
27
+ subject.active?.should.equal false
28
+ subject.activate?.should.equal true
29
+ subject.deactivate?.should.equal false
19
30
 
20
- stub(entity).max_action_points.returns 2
21
31
  subject.action_cost.should.equal 2
22
32
  end
23
33
 
@@ -30,9 +40,9 @@ describe SmashAndGrab::Abilities::Sprint do
30
40
  end
31
41
 
32
42
  should "generate appropriate action_data" do
33
- mock(entity).id.returns 12
34
- mock(entity).max_movement_points.returns 11
35
- mock(entity).max_action_points.returns 2
43
+ mock(@entity).id.returns 12
44
+ mock(@entity).max_movement_points.returns 11
45
+ mock(@entity).max_action_points.returns 2
36
46
  subject.action_data.should.equal(
37
47
  ability: :sprint,
38
48
  skill: 3,
@@ -46,30 +56,50 @@ describe SmashAndGrab::Abilities::Sprint do
46
56
  describe "owner has max_mp == 100" do
47
57
  { 1 => 1, 2 => 25, 3 => 50, 4 => 75, 5 => 100 }.each do |skill, expected_bonus|
48
58
  should "have #movement_bonus == #{expected_bonus} with #skill == #{skill}" do
49
- mock(entity).max_movement_points.returns 100
59
+ mock(@entity).max_movement_points.returns 100
50
60
  mock(subject).skill.returns skill
51
61
  subject.movement_bonus.should.equal expected_bonus
52
62
  end
53
63
  end
54
64
  end
55
65
 
56
- describe "#do" do
57
- should "increase movement points and decrease action points" do
58
- stub(entity).action_points.returns 2
59
- mock(entity, :action_points=).with 0
60
- mock(entity).movement_points.returns 5
61
- mock(entity, :movement_points=).with 10
62
- subject.do action_cost: 2, movement_bonus: 5
63
- end
64
- end
66
+ # Do and undo operate the same; they toggle on/off based on whether the ability is active?
67
+ [:do, :undo].each do |meth|
68
+ describe "##{meth}" do
69
+ should "toggle on to increase movement points and decrease action points" do
70
+ stub(@entity).max_action_points.returns 2
71
+ stub(@entity).action_points.returns 2
72
+ stub(@entity).max_movement_points.returns 5
73
+ stub(@entity).movement_points.returns 5
74
+
75
+ mock(@entity).action_points = 0
76
+ mock(@entity).movement_points = 10
77
+ subject.send meth, action_cost: 2, movement_bonus: 5
78
+
79
+ subject.activate?.should.equal false
80
+ subject.deactivate?.should.equal true
81
+ end
82
+
83
+ should "toggle off to decrease movement points and increase action points" do
84
+ # Activate first.
85
+ subject.instance_variable_set :@active, true
86
+
87
+ # Now deactivate.
88
+ stub(@entity).max_action_points.returns 2
89
+ stub(@entity).action_points.returns 0
90
+ stub(@entity).max_movement_points.returns 5
91
+ stub(@entity).movement_points.returns 10
65
92
 
66
- describe "#undo" do
67
- should "decrease movement points and increase action points" do
68
- stub(entity).action_points.returns 0
69
- mock(entity, :action_points=).with 2
70
- stub(entity).movement_points.returns 10
71
- mock(entity, :movement_points=).with 5
72
- subject.undo action_cost: 2, movement_bonus: 5
93
+ mock(@entity).action_points = 2
94
+ mock(@entity).movement_points = 5
95
+ subject.send meth, action_cost: 2, movement_bonus: 5
96
+
97
+ stub(@entity).action_points.returns 2
98
+ stub(@entity).movement_points.returns 5
99
+
100
+ subject.activate?.should.equal true
101
+ subject.deactivate?.should.equal false
102
+ end
73
103
  end
74
104
  end
75
105
  end
@@ -12,23 +12,25 @@ shared SmashAndGrab::Factions::Faction do
12
12
  end
13
13
 
14
14
  describe SmashAndGrab::Factions::Faction do
15
- helper(:baddies) { SmashAndGrab::Factions::Baddies.new nil }
16
- helper(:goodies) { SmashAndGrab::Factions::Goodies.new nil }
17
- helper(:bystanders) { SmashAndGrab::Factions::Bystanders.new nil }
15
+ before do
16
+ @baddies = SmashAndGrab::Factions::Baddies.new
17
+ @goodies = SmashAndGrab::Factions::Goodies.new
18
+ @bystanders = SmashAndGrab::Factions::Bystanders.new
19
+ end
18
20
 
19
- subject { described.new nil }
21
+ subject { described.new }
20
22
 
21
23
  describe SmashAndGrab::Factions::Goodies do
22
24
  behaves_like SmashAndGrab::Factions::Faction
23
25
 
24
26
  should "dislike baddies" do
25
- subject.should.be.enemy? baddies
26
- subject.should.not.be.friend? baddies
27
+ subject.should.be.enemy? @baddies
28
+ subject.should.not.be.friend? @baddies
27
29
  end
28
30
 
29
31
  should "like bystanders" do
30
- subject.should.not.be.enemy? bystanders
31
- subject.should.be.friend? bystanders
32
+ subject.should.not.be.enemy? @bystanders
33
+ subject.should.be.friend? @bystanders
32
34
  end
33
35
  end
34
36
 
@@ -36,13 +38,13 @@ describe SmashAndGrab::Factions::Faction do
36
38
  behaves_like SmashAndGrab::Factions::Faction
37
39
 
38
40
  should "dislike goodies" do
39
- subject.should.be.enemy? goodies
40
- subject.should.not.be.friend? goodies
41
+ subject.should.be.enemy? @goodies
42
+ subject.should.not.be.friend? @goodies
41
43
  end
42
44
 
43
45
  should "dislike bystanders" do
44
- subject.should.be.enemy? bystanders
45
- subject.should.not.be.friend? bystanders
46
+ subject.should.be.enemy? @bystanders
47
+ subject.should.not.be.friend? @bystanders
46
48
  end
47
49
  end
48
50
 
@@ -50,13 +52,13 @@ describe SmashAndGrab::Factions::Faction do
50
52
  behaves_like SmashAndGrab::Factions::Faction
51
53
 
52
54
  should "like goodies" do
53
- subject.should.not.be.enemy? goodies
54
- subject.should.be.friend? goodies
55
+ subject.should.not.be.enemy? @goodies
56
+ subject.should.be.friend? @goodies
55
57
  end
56
58
 
57
59
  should "dislike baddies" do
58
- subject.should.be.enemy? baddies
59
- subject.should.not.be.friend? baddies
60
+ subject.should.be.enemy? @baddies
61
+ subject.should.not.be.friend? @baddies
60
62
  end
61
63
  end
62
64
  end