class ScottKit::Game::Action
Public Instance Methods
decompile(f)
click to toggle source
# File lib/scottkit/decompile.rb, line 96 def decompile(f) emitted_noun_or_condition = false if self.verb == 0 then f << "occur" f << " " << self.noun << "%" if self.noun != 100 else f << "action #{quote @game.verbs[self.verb]}" if self.noun != 0 f << " #{quote @game.nouns[self.noun]}" emitted_noun_or_condition = true end end self.conds.each.with_index do |cond, i| f << (i == 0 ? " when " : " and ") << cond.render emitted_noun_or_condition = true end f << ":" if self.verb != 0 && !emitted_noun_or_condition f.puts args = @args.clone self.instructions.each do |instruction| f.puts "\t" + instruction.render(args) end if (self.comment != "") f.puts "\tcomment \"#{self.comment}\"" end f.puts end
execute(test_chance)
click to toggle source
# File lib/scottkit/play.rb, line 490 def execute(test_chance) all_conds_true = @conds.map { |x| t = x.evaluate @game.dputs(:show_conditions, " #{x.render()} -> #{t}"); t }. reduce(true) { |acc, val| acc && val } @game.dputs :show_conditions, " #{all_conds_true}" return :failconds if !all_conds_true if (test_chance && @verb == 0) # It's an occurrence and may be random dice = Integer(rand()*100) if dice >= @noun @game.dputs :show_random, " #{dice} >= #{@noun}% -> nop" return :success else @game.dputs :show_random, " #{dice} < #{@noun}%" end end args = @args.clone seen_continue = @instructions.reduce(false) do |acc, x| tmp = x.execute(args) acc || tmp end seen_continue ? :continue : :success end
quote(*args)
click to toggle source
# File lib/scottkit/decompile.rb, line 94 def quote(*args); @game.quote(*args); end