/*
 * This file is Open Game Content, covered by the OGL.
 */
package org.evilsoft.gaming.System;

import org.evilsoft.gaming.*;

public class SystemHP {

  private SystemAttribute attribute;
  private int max;
  private int current;
  private String state = "";
  private int regenAmount = 0;
  private int regenFrequency = 0;
  private int regenRounds = 0;

  public SystemHP(SystemAttribute attribute, int hpmax, int current) {
      this.attribute = attribute;
      this.max = hpmax;
      this.current = current;
  }

  public SystemHP(SystemAttribute attribute, int hpmax) {
      this(attribute, hpmax, hpmax);
  }

  public SystemHP(int hpmax) {
      this(new SystemAttribute("Attribute", 10), hpmax, hpmax);
  }

  public String damage(int damage) {
      current = current - damage;
      if(current < 0) {
          state = "Bleeding";
      }
      
      if(current < (-1 * attribute.getValue())) {
          state = "Dead";
          current = 0;
      }
      return state;
  }
  
  public String heal(int heal) {
      if(!state.equals("Dead")) {
          current = current + heal;
          if(current > max) {
              current = max;
          }
          if(state.equals("Bleeding")) {
              state = "Stable";
          }
          if(current > 0) {
              state = "";
          }
      }
      return state;
  }
  
  public String stabilize() {
      if(state.equals("Bleeding")) {
          state = "Stable";
      }
      return state;
  }
  
  public String raise() {
      if(state.equals("Dead")) {
          state = "";
          current = 1;
      }
      return state;
  }
  
  public String bleed() {
      if(state.equals("Bleeding")) {
          damage(1);
      }
      return state;
  }

  public String kill() {
      state = "Dead";
      current = 0;
      return state;
  }

  public SystemAttribute getAttribute() {
    return attribute;
  }

  public int getMax() {
      return max;
  }
  
  public int getCurrent() {
      return current;
  }
  
  public String getState() {
      return state;
  }

  public void setAttribute(SystemAttribute attribute) {
    this.attribute = attribute;
  }

  public void setMax(int hpmax) {
      this.max = hpmax;
      if(max > current) {
          current = max;
      }
  }
  
  public void setCurrent(int current) {
      if(current > max) {
          current = max;
      }
      
      if(current > this.current) {
          heal(current - this.current);
      }
      else if(current < this.current) {
          damage(this.current - current);
      }
  }

  public void setState(String state) {
      this.state = state;
  }
}
