Class: BCDice::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/result.rb

Overview

ダイスロールの結果を表すクラス

コマンドの結果の文字列や、成功/失敗/クリティカル/ファンブルの情報を保持する。 成功/失敗は同時に発生しないこととする。 成功/失敗のペアとクリティカル、ファンブルの三者は独立した要素とし、 「クリティカルだが失敗」や「ファンブルだが成功でも失敗でもない」を許容する。

Direct Known Subclasses

CommonCommand::BarabaraDice::Result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = nil) ⇒ Result

Returns a new instance of Result.

Parameters:

  • text (String | nil) (defaults to: nil)


67
68
69
70
71
72
73
74
75
76
# File 'lib/bcdice/result.rb', line 67

def initialize(text = nil)
  @text = text
  @rands = nil
  @detailed_rands = nil
  @secret = false
  @success = false
  @failure = false
  @critical = false
  @fumble = false
end

Instance Attribute Details

#critical=(value) ⇒ Object (writeonly)

Sets the attribute critical

Parameters:

  • value

    the value to set the attribute critical to.



79
80
81
# File 'lib/bcdice/result.rb', line 79

def critical=(value)
  @critical = value
end

#detailed_randsObject

Returns the value of attribute detailed_rands.



78
79
80
# File 'lib/bcdice/result.rb', line 78

def detailed_rands
  @detailed_rands
end

#failure=(value) ⇒ Object (writeonly)

Sets the attribute failure

Parameters:

  • value

    the value to set the attribute failure to.



79
80
81
# File 'lib/bcdice/result.rb', line 79

def failure=(value)
  @failure = value
end

#fumble=(value) ⇒ Object (writeonly)

Sets the attribute fumble

Parameters:

  • value

    the value to set the attribute fumble to.



79
80
81
# File 'lib/bcdice/result.rb', line 79

def fumble=(value)
  @fumble = value
end

#randsObject

Returns the value of attribute rands.



78
79
80
# File 'lib/bcdice/result.rb', line 78

def rands
  @rands
end

#secret=(value) ⇒ Object (writeonly)

Sets the attribute secret

Parameters:

  • value

    the value to set the attribute secret to.



79
80
81
# File 'lib/bcdice/result.rb', line 79

def secret=(value)
  @secret = value
end

#success=(value) ⇒ Object (writeonly)

Sets the attribute success

Parameters:

  • value

    the value to set the attribute success to.



79
80
81
# File 'lib/bcdice/result.rb', line 79

def success=(value)
  @success = value
end

#textObject

Returns the value of attribute text.



78
79
80
# File 'lib/bcdice/result.rb', line 78

def text
  @text
end

Class Method Details

.critical(text) ⇒ Result

successcritical が設定された Result を作成する

Parameters:

  • text (String)

Returns:



38
39
40
41
42
43
44
# File 'lib/bcdice/result.rb', line 38

def critical(text)
  new.tap do |r|
    r.text = text
    r.critical = true
    r.success = true
  end
end

.failure(text) ⇒ Result

failure が設定された Result を作成する

Parameters:

  • text (String)

Returns:



27
28
29
30
31
32
# File 'lib/bcdice/result.rb', line 27

def failure(text)
  new.tap do |r|
    r.text = text
    r.failure = true
  end
end

.fumble(text) ⇒ Result

failurefumble が設定された Result を作成する

Parameters:

  • text (String)

Returns:



50
51
52
53
54
55
56
# File 'lib/bcdice/result.rb', line 50

def fumble(text)
  new.tap do |r|
    r.text = text
    r.fumble = true
    r.failure = true
  end
end

.nothing:nothing

その後の判定で何もすることがないことを示すために利用する

Returns:

  • (:nothing)


61
62
63
# File 'lib/bcdice/result.rb', line 61

def nothing
  :nothing
end

.success(text) ⇒ Result

success が設定された Result を作成する

Parameters:

  • text (String)

Returns:



16
17
18
19
20
21
# File 'lib/bcdice/result.rb', line 16

def success(text)
  new.tap do |r|
    r.text = text
    r.success = true
  end
end

Instance Method Details

#condition=(condition) ⇒ void

This method returns an undefined value.

Parameters:

  • condition (Boolean)


108
109
110
111
# File 'lib/bcdice/result.rb', line 108

def condition=(condition)
  @success = condition
  @failure = !condition
end

#critical?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/bcdice/result.rb', line 97

def critical?
  @critical
end

#failure?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/bcdice/result.rb', line 92

def failure?
  @failure
end

#fumble?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/bcdice/result.rb', line 102

def fumble?
  @fumble
end

#secret?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/bcdice/result.rb', line 82

def secret?
  @secret
end

#success?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/bcdice/result.rb', line 87

def success?
  @success
end