Class: Fools::Sheet::Semantics
- Inherits:
-
CARPS::Sheet::UserVerifier
- Object
- CARPS::Sheet::UserVerifier
- Fools::Sheet::Semantics
- Defined in:
- lib/fools/sheet/semantics.rb
Overview
Semantic verifier for Fools character sheets
Instance Method Summary collapse
-
#produce_errors(sheet) ⇒ Object
Verify a sheet, produce errors if they occur.
Instance Method Details
#produce_errors(sheet) ⇒ Object
Verify a sheet, produce errors if they occur
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 88 89 90 91 |
# File 'lib/fools/sheet/semantics.rb', line 30 def produce_errors sheet errors = [] lims = field_limits # Verify all values are within bounds lims.each do |key, valid| attr = sheet[key] if attr if not valid.include? attr errors.push "Damnit man, #{key} must be between #{valid.min} and #{valid.max}!" end end end # Verify that no more than the limited number of character points has been spent total = 0 advts = [ "The Readies", "The Old Grey Matter", "The Outer Crust", "Vim & Vigour", "Tolerance for Alcohol", "Luck", "Conscience" ] advts.each do |key| val = sheet[key] if val gain = cost(val.abs) if val < 0 gain = -gain end total += gain end end car = sheet["Sports Car"] if car == "Basic" total += 1 elsif car == "Flashy" total += 3 end valet = sheet["Gentleman's Gentleman"] if valet == "Good" total += 1 elsif valet == "Superior" total += 3 end limit = sheet["Character Points"] if total > limit errors.push "Don't you know that you used #{total} character points, yet you only had #{limit}?" elsif total < limit CARPS::UI::highlight "Chin up old bean, you still have #{limit - total} points to spend." end if errors.empty? nil else errors end end |