fix some bugs
This commit is contained in:
@@ -29,6 +29,7 @@ public abstract class Enemy implements Entity {
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
setSuccessfulAction(true);
|
||||
if (getMP() >= weapon.getManaCost()) {
|
||||
System.out.println(this.getClass().getSimpleName() + ": attacking " + target.getClass().getSimpleName());
|
||||
double damage = getAttackMultiplier() * weapon.getDamage();
|
||||
@@ -49,12 +50,14 @@ public abstract class Enemy implements Entity {
|
||||
|
||||
@Override
|
||||
public void defend(){
|
||||
setSuccessfulAction(true);
|
||||
System.out.println(this.getClass().getSimpleName() + " is defending");
|
||||
setDefending(true);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
setSuccessfulAction(true);
|
||||
System.out.println(this.getClass().getSimpleName() + " is healing " + health + " HPs");
|
||||
setHP(getHP() + health);
|
||||
}
|
||||
@@ -62,8 +65,8 @@ public abstract class Enemy implements Entity {
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
if (isDefending()) {
|
||||
setHP(getHP() - (int) ((1 - getDefendRate())) * damage);
|
||||
System.out.println(this.getClass().getSimpleName() + " took " + (int) ((1 - getDefendRate())) * damage + " damages!");
|
||||
setHP(getHP() - (int) ((1 - getDefendRate()) * damage));
|
||||
System.out.println(this.getClass().getSimpleName() + " took " + (int) ((1 - getDefendRate()) * damage) + " damages!");
|
||||
}
|
||||
else {
|
||||
System.out.println(this.getClass().getSimpleName() + " took " + damage + " damages!");
|
||||
@@ -87,6 +90,11 @@ public abstract class Enemy implements Entity {
|
||||
@Override
|
||||
public void setHP(int hp) {
|
||||
this.hp = hp;
|
||||
if (this.hp > maxHP) {
|
||||
this.hp = maxHP;
|
||||
} else if (this.hp < 0) {
|
||||
this.hp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,12 +17,10 @@ public class Vampire extends Enemy{
|
||||
double damage = weapon.getDamage() * getAttackMultiplier();
|
||||
setAttackMultiplier(1);
|
||||
if (target.isDefending()) {
|
||||
heal( (int) (.3 * (damage * (1 - target.getDefendRate()))));
|
||||
setMP(getMP() + 12);
|
||||
super.heal( (int) (.3 * (damage * (1 - target.getDefendRate()))));
|
||||
}
|
||||
else {
|
||||
heal( (int) (.3 * damage));
|
||||
setMP(getMP() + 12);
|
||||
super.heal( (int) (.3 * damage));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public interface combatOptions {
|
||||
public interface CombatOptions {
|
||||
|
||||
void lightAttack(Entity target);
|
||||
void heavyAttack(Entity target);
|
||||
@@ -78,7 +78,7 @@ public class Knight extends Player {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage, Entity attacker) {
|
||||
super.takeDamage(damage);
|
||||
if (!getArmor().checkBrake()) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
|
||||
public abstract class Player implements Entity, combatOptions {
|
||||
public abstract class Player implements Entity, CombatOptions {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
Armor armor;
|
||||
@@ -36,6 +36,7 @@ public abstract class Player implements Entity, combatOptions {
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
setSuccessfulAction(true);
|
||||
double damage = getAttackMultiplier() * weapon.getDamage();
|
||||
if (target.isDefending()) {
|
||||
target.takeDamage( (int) (damage * (1 - target.getDefendRate())));
|
||||
@@ -58,12 +59,13 @@ public abstract class Player implements Entity, combatOptions {
|
||||
|
||||
@Override
|
||||
public void defend(){
|
||||
setSuccessfulAction(true);
|
||||
System.out.println(this.getClass().getSimpleName() + " is defending");
|
||||
setDefending(true);
|
||||
};
|
||||
|
||||
@Override
|
||||
public abstract void specialAbility(Entity target);
|
||||
public void specialAbility(Entity target){setSuccessfulAction(true);}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -88,6 +90,7 @@ public abstract class Player implements Entity, combatOptions {
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
setSuccessfulAction(true);
|
||||
System.out.println(this.getClass().getSimpleName() + " is healing " + health + " HPs");
|
||||
setHP(getHP() + health);
|
||||
}
|
||||
@@ -184,9 +187,9 @@ public abstract class Player implements Entity, combatOptions {
|
||||
attackMultiplier = multiplier;
|
||||
}
|
||||
|
||||
public boolean HasGoblinKey() { return hasGoblinKey; }
|
||||
public boolean HasSkeletonKey() { return hasSkeletonKey; }
|
||||
public boolean HasVampireKey() { return hasVampireKey; }
|
||||
public boolean hasGoblinKey() { return hasGoblinKey; }
|
||||
public boolean hasSkeletonKey() { return hasSkeletonKey; }
|
||||
public boolean hasVampireKey() { return hasVampireKey; }
|
||||
|
||||
public void achieveKey(Entity target) {
|
||||
if ( target instanceof Goblin) { hasGoblinKey = true; }
|
||||
|
||||
@@ -3,13 +3,12 @@ package org.project.item.weapons;
|
||||
public class Dagger extends Weapon{
|
||||
|
||||
private static final int CRIT_CHANCE = 30;
|
||||
private boolean isCrit = (int)(Math.random() * 100) < CRIT_CHANCE;
|
||||
|
||||
public Dagger() {
|
||||
super("Dagger",8,15);
|
||||
}
|
||||
|
||||
public Dagger() {super("Dagger",8,15);}
|
||||
|
||||
public boolean critical() {
|
||||
boolean isCrit = (int)(Math.random() * 100) < CRIT_CHANCE;
|
||||
if (isCrit) System.out.println("Critical Hit");
|
||||
return isCrit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user