fix some bugs

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