-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultishot.java
More file actions
52 lines (47 loc) · 1.38 KB
/
Multishot.java
File metadata and controls
52 lines (47 loc) · 1.38 KB
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
import java.util.ArrayList;
public class Multishot extends Move
{
private int power;
private int numHits;
public Multishot(String n, int p, int num)
{
isSingleTarget = false;
moveName = n;
power = p;
numHits = num;
description = "Attack "+ num +" random enemies with " + power + " base damage and a 0.5x multiplier. Lowers the user's defense by 5.";
}
public int getPower()
{
return power;
}
public void use(Character user, Character target, ArrayList<Character> team)
{
System.out.println(user.getName() + " used " + getName() + "!");
ArrayList<Character> targetables = new ArrayList<Character>();
for(Character enemy : team)
{
if(enemy.getHP() > 0)
targetables.add(enemy);
}
int index = 0;
for(int i = 0; i < numHits; i++)
{
//calculates a pseudorandom enemy.
index = (int)(Math.random() * targetables.size());
int damage = (int)(((user.getAtk() + power) - targetables.get(index).getDef()) * 0.5) ;
if(damage < 1)
{
damage = 1;
}
targetables.get(index).alterHP(damage * -1);
if(targetables.get(index).getHP() <= 0)
{
targetables.remove(index);
if(targetables.size() == 0)
break;
}
}
user.addDef(-5);
}
}