-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.rb
executable file
·87 lines (83 loc) · 1.93 KB
/
actions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/local/bin/ruby
module BSG
class ImmediateTurnEnd < StandardError; end
class GameObject
ObjectData = {}
ObjectCount = 1
def initialize(args = {})
args = self.class::ObjectData.merge(args)
raise "Mismatched spec building #{self.class} with args #{args}" unless self.class::Spec.sort === args.keys.sort
args.each_pair { |key, value|
self.instance_variable_set("@#{key.to_s}",value)
self.instance_eval("def #{key.to_s}; return @#{key.to_s}; end")
}
end
def gettrigger(args)
events = Hash.new
if((defined? @trigger) and (@trigger.kind_of?Hash) and (@trigger.has_key?(args[:trigger])))
events[self] = @trigger[args[:trigger]]
end
return events
end
def self.build(args = {})
objects = Array.new
case self::ObjectCount
when Fixnum
self::ObjectCount.times do
objects << self.new(args)
end
when Hash
self::ObjectCount.each_pair { |property, map|
map.each_pair { |value, count|
count.times do
objects << self.new(property => value)
end
}
}
else
raise "Unknown ObjectCount type!"
end
objects = objects[0] if objects.length == 1
return objects
end
end
class Action < GameObject
end
class SkillCheck < Action
Spec = [ :positive, :outcomes, :cards ]
def initialize(args)
args[:cards] ||= Array.new
super(args)
end
def addcard(card)
@cards << card
end
def to_s
output = "SKILL CHECK:\n"
output += @positive.to_s
output += "\n\nOutcomes:\n"
@outcomes.each_pair { |k,v|
output += "#{k} \t-\t#{v.to_s}\n"
}
return output
end
end
class GameEvent < Action
Spec = [ :text, :message, :type, :target]
def initialize(args)
args[:type] ||= :optional
args[:target] ||= :currentplayer
super(args)
end
def to_s
return @text
end
end
class GameChoice < Action
Spec = [ :options, :targetplayer ]
def initialize(args)
args[:targetplayer] ||= :currentplayer
super(args)
end
end
end