3
public abstract class VQDR.Expression.AbstractPoolToken : FunctionToken {
4
protected static Dice stadard_dice = new Dice.singel (10);
6
protected AbstractPoolToken () {
10
protected override void evaluate_self (Context instance) throws GLib.Error {
15
this.result_value.number = 0;
17
StringBuilder strbldr = new StringBuilder ();
18
strbldr.append (SYM_BEGIN);
20
init_sequence (instance);
22
pool_size = get_pool_size (instance);
23
if (pool_size > MAX_TOKEN_ITERATIONS) {
24
throw new Common.ParamError.OUT_OF_BOUNDS
25
(@"$(this.get_type ().name ()) Pool index: $(get_pool_size (instance))");
29
int total_roll_number = 0;
31
for (int i = 1; i <= pool_size; i++) {
32
is_roll_again = false;
34
if (strbldr.len < MAX_TOKEN_STRING_LENGTH) {
36
strbldr.append (SYM_EXPLODE);
38
strbldr.append (SYM_SEP);
42
roll_res = get_roll (instance);
44
successes = count_successes (instance, roll_res);
46
if (strbldr.len < MAX_TOKEN_STRING_LENGTH) {
47
strbldr.append (roll_res.to_string ());
51
* place a Success mark for every roll that successeeded.
53
for (var j = 0; j < successes; j++) {
54
if (strbldr.len < MAX_TOKEN_STRING_LENGTH) {
55
strbldr.append (SYM_SUCCESS);
60
* place a Failure mark for every failed roll.
62
for (var j = 0; j > successes; j--) {
63
if (strbldr.len < MAX_TOKEN_STRING_LENGTH) {
64
strbldr.append (SYM_FAILURE);
68
this.result_value.number += successes;
71
if (total_roll_number > MAX_TOKEN_ITERATIONS) {
72
throw new Common.LoopError.TO_LONG
73
(@"$(get_function_name (this.get_type ())): Loop took more than $MAX_TOKEN_ITERATIONS to complete.");
76
} while (roll_again (instance, roll_res, i));
78
end_sequence (instance);
79
if (get_max_pool_size (instance) < 1) {
80
result_max_value.number = 1;
82
result_max_value.number = get_max_pool_size (instance);
85
if (strbldr.len < MAX_TOKEN_STRING_LENGTH) {
86
strbldr.append (SYM_END);
87
result_string = strbldr.str;
89
result_string = SYM_TRUNK_BEGIN + result_value.number.to_string () + SYM_TRUNK_END;
97
* Tell if another roll is required.
99
* @param instance the instance of the context to run in.
100
* @param roll_result the result to be evaluated.
101
* @param pool_roll_number the number of rolls according to the pool size (zero base)
103
* @return ''true'' if another roll is required, ''false'' otherwise.
105
protected virtual bool roll_again (Context instance, int roll_result, int pool_roll_number) {
110
* Used to initalize a specific values.
112
protected abstract void init_sequence (Context instance);
115
* Return the pool size, or the number of rolls to performe.
117
protected abstract int get_pool_size (Context instance);
120
* Returns the index of the parameter that contains the pool_size.
122
protected abstract int get_pool_index ();
126
* Perform a roll and return the result.
128
protected abstract int get_roll (Context instance) throws GLib.Error;
131
* Count the number of successes obtained with this roll.
134
* @return the number of Successes for this roll.
136
protected abstract int count_successes (Context instance, int roll_result) throws GLib.Error;
139
* Used to evetually performe controls after the pool rolls.
141
protected virtual void end_sequence (Context instance) throws GLib.Error {
146
* Returns the maximum size of the pool.
148
* This should be equal to ''get_pool_size ()'', but the implementation is
149
* allowed to specify any pool size.
151
* @return the maximum pool size.
153
protected virtual long get_max_pool_size (Context instance) throws GLib.Error {
154
return get_pool_size (instance);