package org.evilsoft.gaming.System;

import org.evilsoft.gaming.*;
import java.util.*;

public class SystemDie extends Die {

  public int timesRolled = 0;
  public int total;
  public int num;
  public int sides;
  public int modifier = 0;
  public int rolls[];
  private Random rand = new Random();

  public SystemDie(int modifier) {
    this.num = 1;
    this.sides = 20;
    this.modifier = modifier;
    rolls = new int[num];
    roll();
  }

  public SystemDie() {
    this(0);
  }

  public int roll() {
    int value = 0;
    int i;
    total = 0;
    for(i = 0; i < num; i++) {
      rolls[i] = rand.nextInt(sides) + 1 + modifier;
      if(rolls[i] == 1) {
        value = value - 10;
      }
      if(rolls[i] == 20) {
        value = value + 10;
      }
      value = rolls[i] + value;
    }
    total = value;
    timesRolled++;
    return total;
  }

  public int value() {
    return total;
  }

  public String toString() {
    if(modifier == 0) {
      return num + "d" + sides;
    }
    else {
      return num + "d" + sides + "+" + modifier;
    }
  }
}
