Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import dk.sdu.mmmi.modulemon.CommonMonster.IMonster;
import dk.sdu.mmmi.modulemon.CommonMonster.IMonsterMove;

import java.util.Random;

public class BattleMonsterProcessor implements IBattleMonsterProcessor {

@Override
Expand All @@ -22,6 +24,7 @@ public int calculateDamage(IMonster iSource, IMonsterMove iMove, IMonster iTarge
float sourceAttack = (float) source.getAttack();
float targetDefence = (float) target.getDefence();

if (!doAccuracyHit(move.getAccuracy())) { return 0; }
// Same type attack bonus. Effectively the same as STAB in that other game
boolean same_attack_type = source.getMonsterType() == move.getType();
float attack_bonus = 1;
Expand Down Expand Up @@ -92,4 +95,10 @@ public float calculateTypeAdvantage(MonsterType source, MonsterType target) {
}
}

public boolean doAccuracyHit(float factor) {
//Generates a random value
Random random = new Random();
//Ensures that the next move will always be below our factor and between(0-1)
return random.nextFloat() <= factor;
}
}
15 changes: 7 additions & 8 deletions src/main/java/dk/sdu/mmmi/modulemon/Monster/MonsterMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ public class MonsterMove implements IMonsterMove {
private MonsterType type;
private String soundPath;

public MonsterMove(String name, int damage, MonsterType type, String soundPath) {
private float accuracy = 1f;
public MonsterMove(String name, int damage, MonsterType type, String soundPath, float accuracy) {
this.name = name;
this.damage = damage;
this.type = type;
this.soundPath = soundPath;
}

public MonsterMove(String name, int damage, MonsterType type) {
this.name = name;
this.damage = damage;
this.type = type;
this.soundPath = "sounds/tackle.ogg";
this.accuracy = accuracy;
}

@Override
Expand Down Expand Up @@ -59,4 +54,8 @@ public String getSummaryScreenDescription() {
public String toString() {
return this.getName();
}

public float getAccuracy() {
return accuracy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ private static HashMap<String, IMonsterMove> instantiateMoves(JSONArray jsonMove
for (int i = 0; i < jsonMoves.length(); i++) {
JSONObject JSONMove = jsonMoves.getJSONObject(i);
String soundPath;
float accuracy = 1f;
if (JSONMove.has("sound")) {
soundPath = JSONMove.getString("sound");
}
else {
soundPath = "sounds/tackle.ogg";
}
if (JSONMove.has("accuracy")) {
accuracy = JSONMove.getFloat("accuracy");
}
IMonsterMove move = new MonsterMove(JSONMove.getString("name"),
JSONMove.getInt("damage"),
monsterTypeHashMap.get(JSONMove.getString("type").toLowerCase()),
soundPath);
soundPath, accuracy);
moves.put(JSONMove.getString("id"), move);
}
return moves;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/json/monsters.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"moves" : [
"slam",
"tornado",
"zap",
"kamikaze",
"spit"
],
"front": "/images/bird_front.png",
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/json/moves.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,13 @@
"damage": 60,
"type": "AIR",
"sound": "/sounds/screech.ogg"
},
{
"id": "kamikaze",
"name": "Kamikaze",
"damage": 120,
"type": "AIR",
"sound": "/sounds/screech.ogg",
"accuracy": 0.4
}
]