Wednesday, September 30, 2009

rpg_char.java

public class rpg_char
{
private String name = "Default";
private int money = 0;
private int health = 10;
private int maxhealth = 10;
private int exp = 0;
private int nextlevel = 10;
private int level = 1;
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
private int defence = 0;
private int attack = 0;

public rpg_char(String name2, int money2, int exp2, int nextlevel2, int level, int health2, int maxhealth2, int defence2, int attack2)
{
name = name2;
money = money2;
exp = exp2;
nextlevel = nextlevel2;
health = health2;
maxhealth = maxhealth2;
defence = defence2;
attack = attack2;
}
public void set_name(String newname) { name = newname; }
public void set_health(int s_health) { health = s_health; }
public void set_maxhealth(int s_maxhealth) { maxhealth = s_maxhealth; }
public void set_exp(int s_exp) { exp = s_exp; }
public void set_nextlevel(int s_nxtlvl) { nextlevel = s_nxtlvl; }
public void set_money(int s_money) { money = s_money; }
public void set_att(int s_att) { attack = s_att; }
public void set_def(int s_def) { defence = s_def; }
public void update_H(int newMax, int regen_percent)
{
int regen_amount = maxhealth*(regen_percent/100);
maxhealth = newMax;
if( (health + regen_amount) < maxhealth)
{
health += regen_amount;
}
else
{
health = maxhealth;
}
}
public void update_E(int addExp)
{
if( (exp + addExp) < nextlevel)
{
exp += addExp;
}
else
{
addExp = (exp+addExp) - nextlevel;
levelup(addExp);
}
}
public void update_M(int addMoney)
{
money += addMoney;
}
public void update_A(int addAtt)
{
attack += addAtt;
}
public void update_D(int addDef)
{
defence += addDef;
}
public void levelup(int expleft)
{
int statsup1 = (int)(Math.random()*3);
int statsup2 = (int)(Math.random()*3);
if(statsup1 == 3)statsup1 = (int)(Math.random()*3);
if(statsup2 == 3)statsup2 = (int)(Math.random()*3);
attack += statsup1;
defence += statsup2;
update_H( (maxhealth + statsup1), (int)(Math.random()*maxhealth) );
nextlevel += (int)(Math.random()*nextlevel);
update_E(expleft);
}
public String get_name() {return name;}
public int getMoney() {return money;}
public int getHealth() {return health;}
public int getMaxHealth() {return maxhealth;}
public int getExp() {return exp;}
public int getNextLevel() {return nextlevel;}
public int getDef() {return defence;}
public int getAtt() {return attack;}
}

No comments:

Post a Comment