From 0ea3dfd98a044d86699fb4058b2b291eb952d181 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 13 Sep 2018 14:12:04 +0900 Subject: [PATCH] Minor fixes/changes --- .../common/AttackEventHandler.java | 5 +-- .../TurnBasedMinecraft/common/Battle.java | 8 ++++ .../common/BattleManager.java | 18 ++++----- .../TurnBasedMinecraft/common/Combatant.java | 2 +- .../TurnBasedMinecraft/common/Config.java | 12 +++--- .../TurnBasedMinecraft/common/EntityInfo.java | 38 +------------------ .../assets/TurnBasedMinecraft/TBM_Config.xml | 8 ++-- 7 files changed, 32 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java index fccbce5..485e8ee 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java @@ -10,7 +10,6 @@ public class AttackEventHandler { if(event.getEntity().world.isRemote) { - TurnBasedMinecraftMod.logger.debug("isRemote"); return; } else if(TurnBasedMinecraftMod.battleManager == null) @@ -20,12 +19,12 @@ public class AttackEventHandler if(!(event.getSource().getTrueSource() == null || event.getSource().getTrueSource().equals(TurnBasedMinecraftMod.attackingEntity)) && TurnBasedMinecraftMod.battleManager.checkAttack(event)) { - TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.attackingEntity + " and " + event.getEntity()); +// TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.attackingEntity + " and " + event.getEntity()); event.setCanceled(true); } else { - TurnBasedMinecraftMod.logger.debug("Did not cancel attack"); +// TurnBasedMinecraftMod.logger.debug("Did not cancel attack"); } if(TurnBasedMinecraftMod.attackingDamage < (int) event.getAmount()) { diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java index 242cc8e..3e9ba40 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java @@ -580,6 +580,10 @@ public class Battle { hitChance -= target.entityInfo.evasion; } + if(hitChance < 1) + { + hitChance = 1; + } if((int)(Math.random() * 100) < hitChance) { if(target.remainingDefenses <= 0) @@ -663,6 +667,10 @@ public class Battle { hitChance -= target.entityInfo.evasion; } + if(hitChance < 1) + { + hitChance = 1; + } if((int)(Math.random() * 100) < hitChance) { if(target.remainingDefenses <= 0) diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java index aa6a026..d0a902a 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java @@ -52,11 +52,11 @@ public class BattleManager { if(b.hasCombatant(event.getSource().getTrueSource().getEntityId())) { - logger.debug("Attack Canceled: attacked ignores battle but attacker in battle"); +// logger.debug("Attack Canceled: attacked ignores battle but attacker in battle"); return true; } } - logger.debug("Attack Not Canceled: attacked ignores battle"); +// logger.debug("Attack Not Canceled: attacked ignores battle"); return false; } entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(event.getSource().getTrueSource()); @@ -67,11 +67,11 @@ public class BattleManager { if(b.hasCombatant(event.getEntity().getEntityId())) { - logger.debug("Attack Canceled: attacker ignores battle but attacked in battle"); +// logger.debug("Attack Canceled: attacker ignores battle but attacked in battle"); return true; } } - logger.debug("Attack Not Canceled: attacker ignores battle"); +// logger.debug("Attack Not Canceled: attacker ignores battle"); return false; } @@ -87,7 +87,7 @@ public class BattleManager if(inBattle != null) { // both combatants are in battle - logger.debug("Attack Canceled: both are in battle"); +// logger.debug("Attack Canceled: both are in battle"); return true; } else @@ -102,7 +102,7 @@ public class BattleManager if(inBattle != null) { // both combatants are in battle - logger.debug("Attack Canceled: both are in battle"); +// logger.debug("Attack Canceled: both are in battle"); return true; } else @@ -125,11 +125,11 @@ public class BattleManager sideA.add(event.getEntity()); sideB.add(event.getSource().getTrueSource()); createBattle(sideA, sideB); - logger.debug("Attack Not Canceled: new battle created"); +// logger.debug("Attack Not Canceled: new battle created"); } else { - logger.debug("Attack Not Canceled: neither are in battle or players"); +// logger.debug("Attack Not Canceled: neither are in battle or players"); } return false; } @@ -144,7 +144,7 @@ public class BattleManager battle.addCombatantToSideA(notInBattle); } - logger.debug("Attack Canceled: one is in battle"); +// logger.debug("Attack Canceled: one is in battle"); return true; } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Combatant.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Combatant.java index 9092485..6490e26 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Combatant.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Combatant.java @@ -50,7 +50,7 @@ public class Combatant boolean isSlow = false; for(PotionEffect e : c0Entity.getActivePotionEffects()) { - if(e.getEffectName().equals(MobEffects.HASTE.getName())) + if(e.getEffectName().equals(MobEffects.HASTE.getName()) || e.getEffectName().equals(MobEffects.SPEED.getName())) { isHaste = true; } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java index 41c3a5f..e3534c8 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java @@ -20,12 +20,10 @@ import javax.xml.stream.XMLStreamReader; import org.apache.logging.log4j.Logger; -import com.seodisparate.TurnBasedMinecraft.common.EntityInfo.Category; - public class Config { private Map entityInfoMap; - private Set ignoreBattleTypes; + private Set ignoreBattleTypes; private Logger logger; private int playerSpeed = 50; private int playerHasteSpeed = 80; @@ -39,7 +37,7 @@ public class Config public Config(Logger logger) { entityInfoMap = new HashMap(); - ignoreBattleTypes = new HashSet(); + ignoreBattleTypes = new HashSet(); this.logger = logger; int internalVersion = 0; @@ -162,7 +160,7 @@ public class Config xmlReader.next(); if(xmlReader.isStartElement()) { - ignoreBattleTypes.add(Category.fromString(xmlReader.getLocalName())); + ignoreBattleTypes.add(xmlReader.getLocalName().toLowerCase()); } } while(!(xmlReader.isEndElement() && xmlReader.getLocalName().equals("IgnoreBattleTypes"))); } @@ -272,7 +270,7 @@ public class Config } else if(xmlReader.getLocalName().equals("Category")) { - eInfo.category = Category.fromString(xmlReader.getElementText()); + eInfo.category = xmlReader.getElementText().toLowerCase(); } else if(xmlReader.getLocalName().equals("Conflicts")) { @@ -453,7 +451,7 @@ public class Config return configVersion; } - public boolean isIgnoreBattleType(Category type) + public boolean isIgnoreBattleType(String type) { return ignoreBattleTypes.contains(type); } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java index 1928629..1124068 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java @@ -21,45 +21,11 @@ public class EntityInfo public int defenseDamageProbability; public int evasion; public int speed; - public Category category; + public String category; public int decisionAttack; public int decisionDefend; public int decisionFlee; - public enum Category - { - MONSTER, - PASSIVE, - ANIMAL, - BOSS, - UNKNOWN; - - public static Category fromString(String c) - { - c = c.toLowerCase(); - if(c.equals("monster")) - { - return MONSTER; - } - else if(c.equals("passive")) - { - return PASSIVE; - } - else if(c.equals("animal")) - { - return ANIMAL; - } - else if(c.equals("boss")) - { - return BOSS; - } - else - { - return UNKNOWN; - } - } - } - public enum Effect { SPEED, @@ -355,7 +321,7 @@ public class EntityInfo defenseDamageProbability = 0; evasion = 15; speed = 50; - category = Category.UNKNOWN; + category = "unknown"; decisionAttack = 70; decisionDefend = 20; decisionFlee = 10; diff --git a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml b/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml index 68dd900..39d328b 100644 --- a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml +++ b/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml @@ -1,15 +1,16 @@ 1 - + 50 - 80 - 20 + 80 + 20 90 10 @@ -24,6 +25,7 @@ +