forked from basilnsindhu/Text-Adventure-in-the-Making
/
Monster.java
195 lines (183 loc) · 7.11 KB
/
Monster.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
import java.util.Random;
import java.util.Scanner;
public class Monster{
//monsters won't use mana/magic stats?
private String name;
private boolean boss; //?? idk if this boolean is needed
private int hp, str, def, spd, lck;
private String[] monsters = { //add more later
"Skeleton", "Slime"
};
private String[] bosses = { //add more later
"Skeleton King"
};
public Monster(String name, int dungeonLvl){
//skeleton & slime basic monsters
if (name.equals("Skeleton")){
this.name = name;
this.hp = 20 + (4*dungeonLvl);
this.str = 4 + (2*dungeonLvl);
this.def = 2 + (2*dungeonLvl);
this.spd = 1 + (2*dungeonLvl);
this.lck = 1 + (2*dungeonLvl);
}
if (name.equals("Slime")){
this.name = name;
this.hp = 20 + (2*dungeonLvl);
this.str = 2 + (2*dungeonLvl);
this.def = 4 + (2*dungeonLvl);
this.spd = 1 + (2*dungeonLvl);
this.lck = 1 + (2*dungeonLvl);
}
}
public Monster(String boss, int dungeonLvl, boolean isBoss){
if (boss.equals("Skeleton King")) {
this.boss = isBoss; //?? idk if this boolean is needed
this.name = boss;
this.hp = 60 + (4*dungeonLvl);
this.str = 6 + (2*dungeonLvl);
this.def = 6 + (2*dungeonLvl);
this.spd = 5 + (2*dungeonLvl);
this.lck = 3 + (2*dungeonLvl);
}
}
public int attack(){
return str+spd;
}
public void takeDmg(int x){
this.hp-=x;
}
public boolean critM(Monster m){
Random r = new Random();
int rand = r.nextInt(100); //initial 10% chance to crit, increases with luck
rand += (m.getLck()*3);
if (rand >= 90) return true;
else return false;
}
public boolean evadeM(Monster monster){
Random r = new Random();
int rand = r.nextInt(100); //0-99
rand += (monster.getSpd()*3);
if (rand >= 95) return true; //initial 5% chance to evade, increases with speed
else return false;
}
public boolean monsterDead(Player player, Monster monster){
Random r = new Random();
int randInt1 = r.nextInt(10) + 5; //exp
int randInt2 = r.nextInt(10) + 5; //gold
player.setGold(player.getGold() + randInt2);
System.out.println("\n" + monster.getName() + " defeated! You gain " + randInt2 + " gold and " + randInt1 + " Exp.");
player.setExp(player.getExp() + randInt1);
player.checkExp();
int randInt = r.nextInt(100); //random # 0 - 99
randInt += (player.getChar().getLck()*10);
if (randInt >= 70){ //30% chance to drop item (for now) + added chance with player's luck
Item i = new Item("Rusty Sword"); //making item first
i = i.itemDrop(); //item becomes randomized
System.out.println("\nThe " + monster.getName() + " dropped an item!\n");
Scanner sc = new Scanner(System.in);
boolean decided = false;
while (!decided) {
if (i.getType().equals("potion")){
System.out.println("Do you wish to pick up " + i.getDesc() + "?");
System.out.println("1: Yes | 2: No");
}
else {
System.out.println("Do you wish to equip " + i.getDesc() + "?");
System.out.println("1. Yes | 2. No | 3: Compare");
}
int c = sc.nextInt();
switch(c) {
case 1: //if player already has item in corresponding slot, add it to inventory
if (i.getType().equals("potion")) { //if the dropped item is a potion, add to inventory
player.getInv().addItem(i);
System.out.println("\n" + i.getDesc() + " was put in your inventory.");
}
else {
if (player.getItem(i.getType()) != null) {
System.out.println("\nYou already have " + player.getItem(i.getType()).getDesc()
+ " equipped, do you want to put " + i.getDesc() + " in your inventory?\n1. Yes | 2. No");
int c2 = sc.nextInt();
boolean decided2 = false;
while (decided2 == false) {
switch(c2) {
case 1:
if (player.getInv().isFull()) {
System.out.println("\nInventory full!\nYou leave the " + i.getDesc() + " behind.");
}
else {
player.getInv().addItem(i);
System.out.println("\n" + i.getDesc() + " was put in your inventory.");
}
decided2 = true;
break;
case 2:
System.out.println("\nYou leave the " + i.getDesc() + " behind.");
decided2 = true;
break;
default:
System.out.println("\nInvalid input.");
}
}
}
else {
player.equip(i);
System.out.println("\nYou equipped the " + i.getDesc() + ".");
}
}
decided=true;
break;
case 2:
System.out.println("\nDo you want to put the " + i.getDesc() + " into your inventory?");
System.out.println("1: Yes | 2: No");
int c3 = sc.nextInt();
boolean decided2 = false;
while (decided2 == false) {
switch(c3) {
case 1:
player.getInv().addItem(i);
if (player.getInv().isFull()) {
System.out.println("\nYou leave the " + i.getDesc() + " behind.");
}
else {
System.out.println("\n" + i.getDesc() + " was put in your inventory.");
}
decided2 = true;
break;
case 2:
System.out.println("\nYou leave the " + i.getDesc() + " behind.");
decided2 = true;
break;
default:
System.out.println("\nInvalid input.");
break;
}
}
decided=true;
break;
case 3:
player.compareItem(i);
break;
default:
System.out.println("\nInvalid input.");
break;
}
}
}
return true;
}
public int getHp(){
if (hp < 0) return 0;
else return this.hp;
}
public void setHp(int x){ this.hp = x;}
public String getName(){ return this.name; }
public int getStr() { return this.str; }
public int getDef() { return this.def; }
public int getSpd() { return this.spd; }
public int getLck(){ return this.lck; }
public void setStr(int x) {this.str = x; }
public void setDef(int x) {this.def = x; }
public void setSpd(int x) {this.spd = x; }
public void setLck(int x) {this.lck = x; }
}