-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter.java
202 lines (177 loc) · 4.53 KB
/
Character.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
Author: Marcello de Paula Ferreira Costa
#USP: 7960690
Author: Jessika Darambaris
#USP: 7961026
Universidade de São Paulo
Trabalho para o Curso de Programação Orientada à Objetos
Character class
*/
import Items.*;
import java.util.Random;
public abstract class Character implements Name{
private String alias;
private String type;
private Inventory myitems = new Inventory();
private int hp;
private int mp;
protected int xp;
protected int strenght;
protected int speed;
protected int dexterity;
protected int constitution;
public Character (String alias) {
this.alias = alias;
xp = (int)(Math.random()*80);
hp = 10000;
mp = 100;
}
public Character (Character Base){
this.xp = Base.xp;
this.hp = Base.hp;
this.mp = Base.mp;
this.alias = Base.alias;
this.type = Base.type;
this.strenght = Base.strenght;
this.speed = Base.speed;
this.dexterity = Base.dexterity;
this.constitution = Base.constitution;
this.myitems = new Inventory();
this.myitems.setSpaces(Base.getMyItems().getAvailableSpace());
}
public String getName(){
return this.alias;
}
public void setType(String type){
this.type = type;
}
protected int getAttackPoints () {
int item_att_pts = 0;
double true_speed = 0;
for (int i = 0 ; i < getMyItems().size() ; i++) {
if (getMyItems().items.get(i).getEquiped()) {
item_att_pts = item_att_pts + myitems.items.get(i).getAttackPts();
true_speed = true_speed + getMyItems().items.get(i).getWeight();
}
}
true_speed = this.speed/(Math.exp((true_speed*true_speed)));
return (int)((this.strenght*0.5+this.dexterity*0.3+true_speed*0.2+(double)item_att_pts)*(xp/3.0));
}
protected int getDefensePoints () {
int item_def_pts = 0;
double true_speed = 0;
for (int i = 0 ; i < getMyItems().size() ; i++) {
if (getMyItems().items.get(i).getEquiped()) {
item_def_pts = item_def_pts + getMyItems().items.get(i).getDefensePts();
true_speed = true_speed + getMyItems().items.get(i).getWeight();
}
}
true_speed = this.speed/(Math.exp((true_speed*true_speed)));
return (int)((this.constitution*0.5+this.dexterity*0.3+true_speed*0.2+(double)item_def_pts)*(xp/2.0));
}
public abstract void attack(Character target);
public void addXP (int xp) {
this.xp = this.xp + xp;
if (xp >= 0){
System.out.println("You have gained "+xp+"XP.");
}
else{
System.out.println("You have lost "+xp+"XP.");
}
}
public int controlAttributes () {
int temp = this.strenght+this.constitution+this.dexterity+this.speed;
if (temp > 100)
return 101;
else
return temp;
}
/*********************** Setters *********************/
public void setStrenght (int strenght) {
int temp = controlAttributes();
if (temp < 100) {
temp = temp - this.strenght;
temp = temp + strenght;
if (temp <= 100) {
this.strenght = strenght;
}
else {
temp = temp - strenght;
this.strenght = 100-temp;
}
}
else this.strenght = strenght;
}
public void setSpeed (int speed) {
int temp = controlAttributes();
if (temp < 100) {
temp = temp - this.speed;
temp = temp + speed;
if (temp <= 100) {
this.speed = speed;
}
else {
temp = temp - speed;
this.speed = 100-temp;
}
}
else this.speed = speed;
}
public void setDexterity (int dexterity) {
int temp = controlAttributes();
if (temp < 100) {
temp = temp - this.dexterity;
temp = temp + dexterity;
if (temp <= 100) {
this.dexterity = dexterity;
}
else {
temp = temp - dexterity;
this.dexterity = 100-temp;
}
}
else this.dexterity = dexterity;
}
public void setConstitution (int constitution) {
int temp = controlAttributes();
if (temp < 100) {
temp = temp - this.constitution;
temp = temp + constitution;
if (temp <= 100) {
this.constitution = constitution;
}
else {
temp = temp - constitution;
this.constitution = 100-temp;
}
}
else this.constitution = constitution;
}
public void addHP (int hp) {
this.hp = this.hp + hp;
if (this.hp < 0) {
this.hp = 0;
}
}
/* Usada somente para consumível.
A intenção é que quando uma poção for usada, a função seja chamada como "HealthPotion" no argumento */
public void addHP (String name) {
addHP(myitems.equip(name));
}
public void addMP(int mp) {
this.mp = this.mp + mp;
if (this.mp < 0) {
this.mp = 0;
}
}
public void addMP (String name) {
addMP(myitems.equip(name));
}
public int getHP () {
return this.hp;
}
/* Returns this classes' ArrayList so it can be used from outside */
public Inventory getMyItems () {
return myitems;
}
};