net.sf.groovydice.plugin.builtin
Class DiceModifier

java.lang.Object
  extended by net.sf.groovydice.plugin.builtin.DiceModifier
All Implemented Interfaces:
groovy.lang.GroovyObject

public class DiceModifier
extends Object
implements groovy.lang.GroovyObject

This class is used to specify a modifier to each die of a dice rolling command. A modifier can also hold a condition object, which is used when applying the modifier in such a way that only matching dice are modified.

Since:
1.0
Version:
4
Author:
Daniel F. Martins

Constructor Summary
DiceModifier()
           
 
Method Summary
 Object apply(Object logic)
          Apply this modifier using the given logic closure.
 Object getCondition()
           
 groovy.lang.MetaClass getMetaClass()
           
 Object getModifier()
           
 Object getProperty(String name)
           
 Object invokeMethod(String name, Object args)
           
 Object negative()
          Multiply the modifier value by '-1' when the unary '-' operator is used in this object.
 void setCondition(Object condition)
          Set the condition, which restricts the modifier to be applied only to a specific set of dice.
 void setMetaClass(groovy.lang.MetaClass metaClass)
           
 void setModifier(Object value)
           
 void setProperty(String name, Object value)
           
 String toString()
          String representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DiceModifier

public DiceModifier()
Method Detail

getModifier

public Object getModifier()

setModifier

public void setModifier(Object value)

getCondition

public Object getCondition()

setCondition

public void setCondition(Object condition)
Set the condition, which restricts the modifier to be applied only to a specific set of dice.

Parameters:
condition - An object that express an condition which all dice must fit in order to be 'modified'. Any object that fit into a grep() call can be used here. You can also pass a dice rolling command object to apply this modifier only to dice equals to any dice of the given roll.

negative

public Object negative()
Multiply the modifier value by '-1' when the unary '-' operator is used in this object.

Returns:
this.

apply

public Object apply(Object logic)
Apply this modifier using the given logic closure.

Parameters:
logic - Closure which is used to apply this modifier. This closure should be a method borrowed from a dice rolling command.
Returns:
A new dice rolling command which contains the result of the operation.

toString

public String toString()
String representation of this object.

Overrides:
toString in class Object
Returns:
Modifier number and condition.

getMetaClass

public groovy.lang.MetaClass getMetaClass()
Specified by:
getMetaClass in interface groovy.lang.GroovyObject

setMetaClass

public void setMetaClass(groovy.lang.MetaClass metaClass)
Specified by:
setMetaClass in interface groovy.lang.GroovyObject

invokeMethod

public Object invokeMethod(String name,
                           Object args)
Specified by:
invokeMethod in interface groovy.lang.GroovyObject

getProperty

public Object getProperty(String name)
Specified by:
getProperty in interface groovy.lang.GroovyObject

setProperty

public void setProperty(String name,
                        Object value)
Specified by:
setProperty in interface groovy.lang.GroovyObject


Copyright © 2008-2010 Daniel F. Martins. All Rights Reserved.