From def5ceee46b803badac94bd1734588304bbeb81d Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 27 Mar 2024 17:31:04 -0500 Subject: [PATCH] remove ItemBase form absChar and Mob --- src/engine/objects/AbstractCharacter.java | 50 +-- src/engine/objects/Mob.java | 381 +--------------------- 2 files changed, 27 insertions(+), 404 deletions(-) diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 072e377a..360e2f4a 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -668,15 +668,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject { /** * @ Calculates Atr, and Damage for each weapon */ - private static void calculateAtrDamageForWeapon(AbstractCharacter playerCharacter, Item weapon, boolean mainHand, Item otherHand) { + public static void calculateAtrDamageForWeapon(AbstractCharacter playerCharacter, Item weapon, boolean mainHand, Item otherHand) { // make sure weapon exists boolean noWeapon = false; - ItemBase wb = null; + ItemTemplate wb = null; if (weapon == null) noWeapon = true; else { - ItemBase ib = weapon.getItemBase(); + ItemTemplate ib = weapon.template; if (ib == null) noWeapon = true; else if (!weapon.template.item_type.equals(ItemType.WEAPON)) { @@ -691,14 +691,14 @@ public abstract class AbstractCharacter extends AbstractWorldObject { float speed = 20f; boolean strBased = false; - ItemBase wbMain = (weapon != null) ? weapon.getItemBase() : null; - ItemBase wbOff = (otherHand != null) ? otherHand.getItemBase() : null; + ItemTemplate wbMain = (weapon != null) ? weapon.template : null; + ItemTemplate wbOff = (otherHand != null) ? otherHand.template : null; // get skill percentages and min and max damage for weapons if (noWeapon) { if (mainHand) { Item off = playerCharacter.charItemManager.getEquipped().get(EquipSlotType.LHELD); - if (off != null && off.getItemBase() != null && off.template.item_type.equals(ItemType.WEAPON)) + if (off != null && off.template != null && off.template.item_type.equals(ItemType.WEAPON)) playerCharacter.rangeHandOne = 10 * (1 + (playerCharacter.statStrBase / 600)); // Set // to // no @@ -720,9 +720,9 @@ public abstract class AbstractCharacter extends AbstractWorldObject { max = 3; } else { if (mainHand) - playerCharacter.rangeHandOne = weapon.getItemBase().getRange() * (1 + (playerCharacter.statStrBase / 600)); + playerCharacter.rangeHandOne = weapon.template.item_weapon_max_range * (1 + (playerCharacter.statStrBase / 600)); else - playerCharacter.rangeHandTwo = weapon.getItemBase().getRange() * (1 + (playerCharacter.statStrBase / 600)); + playerCharacter.rangeHandTwo = weapon.template.item_weapon_max_range * (1 + (playerCharacter.statStrBase / 600)); if (playerCharacter.bonuses != null) { float range_bonus = 1 + playerCharacter.bonuses.getFloatPercentAll(ModType.WeaponRange, SourceType.NONE); @@ -734,15 +734,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject { } skillPercentage = getModifiedAmount(playerCharacter.skills.get(weapon.template.item_skill_used)); - masteryPercentage = getModifiedAmount(playerCharacter.skills.get(wb.getMastery())); + masteryPercentage = getModifiedAmount(playerCharacter.skills.get(wb.item_skill_mastery_used)); if (masteryPercentage == 0f) mastDam = 0f; // mastDam = CharacterSkill.getQuickMastery(this, wb.getMastery()); else mastDam = masteryPercentage; - min = (float) wb.getMinDamage(); - max = (float) wb.getMaxDamage(); - strBased = wb.isStrBased(); + min = (float) wb.item_weapon_damage.values().toArray()[0]; + max = (float) wb.item_weapon_damage.values().toArray()[1]; + strBased = wb.item_primary_attr.equals(AttributeType.Strength); // // Add parry bonus for weapon and allow parry if needed @@ -803,7 +803,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { //calculate speed if (wb != null) - speed = wb.getSpeed(); + speed = wb.item_weapon_wepspeed; else speed = 20f; //unarmed attack speed if (weapon != null) @@ -839,7 +839,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { //if duel wielding, cut damage by 30% if (otherHand != null) { - ItemBase ibo = otherHand.getItemBase(); + ItemTemplate ibo = otherHand.template; if (ibo != null && otherHand.template.equals(ItemType.WEAPON)) { min *= 0.7f; max *= 0.7f; @@ -909,7 +909,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { if (ItemTemplate.isShield(shield) == false) return 0; - ItemBase ab = shield.getItemBase(); + ItemTemplate ab = shield.template; if (ab == null) return 0; @@ -923,7 +923,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { } else skillMod = blockSkill.getModifiedAmount(); - float def = ab.getDefense(); + float def = ab.item_defense_rating; //apply item defense bonuses if (shield != null) { @@ -944,7 +944,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { if (armor == null) return 0; - ItemBase ib = armor.getItemBase(); + ItemTemplate ib = armor.template; if (ib == null) return 0; @@ -953,16 +953,16 @@ public abstract class AbstractCharacter extends AbstractWorldObject { return 0; if (armor.template.item_skill_used.isEmpty()) - return ib.getDefense(); + return ib.item_defense_rating; CharacterSkill armorSkill = playerCharacter.skills.get(armor.template.item_skill_used); if (armorSkill == null) { Logger.error("Player " + playerCharacter.getObjectUUID() + " has armor equipped without the nescessary skill to equip it"); - return ib.getDefense(); + return ib.item_defense_rating; } - float def = ib.getDefense(); + float def = ib.item_defense_rating; //apply item defense bonuses if (armor != null) { def += armor.getBonus(ModType.DR, SourceType.NONE); @@ -978,7 +978,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { */ private static float getWeaponDefense(AbstractCharacter playerCharacter, ConcurrentHashMap equipped) { Item weapon = equipped.get(EquipSlotType.RHELD); - ItemBase wb = null; + ItemTemplate wb = null; CharacterSkill skill, mastery; float val = 0; boolean unarmed = false; @@ -987,9 +987,9 @@ public abstract class AbstractCharacter extends AbstractWorldObject { if (weapon == null || ItemTemplate.isShield(weapon)) unarmed = true; else - wb = weapon.getItemBase(); + wb = weapon.template; } else - wb = weapon.getItemBase(); + wb = weapon.template; if (wb == null) unarmed = true; if (unarmed) { @@ -997,7 +997,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { mastery = playerCharacter.skills.get("Unarmed Combat Mastery"); } else { skill = playerCharacter.skills.get(weapon.template.item_skill_used); - mastery = playerCharacter.skills.get(wb.getMastery()); + mastery = playerCharacter.skills.get(wb.item_skill_mastery_used); } if (skill != null) val += (int) skill.getModifiedAmount() / 2f; @@ -1029,7 +1029,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { return; ConcurrentHashMap equipped = playerCharacter.charItemManager.getEquipped(); for (Item item : equipped.values()) { - ItemBase ib = item.getItemBase(); + ItemTemplate ib = item.template; if (ib == null) continue; //TODO add effect bonuses in here for equipped items diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index b41aff90..d1767e5c 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1046,7 +1046,8 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { } else { try { - calculateAtrDefenseDamage(); + AbstractCharacter.calculateAtrDamageForWeapon(this,this.charItemManager.equipped.get(EquipSlotType.RHELD),true,this.charItemManager.equipped.get(EquipSlotType.LHELD)); + AbstractCharacter.calculateAtrDefenseDamage(this); } catch (Exception e) { Logger.error(this.getMobBaseID() + " /" + e.getMessage()); } @@ -1122,384 +1123,6 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { } - public void calculateAtrDefenseDamage() { - - if (this.charItemManager == null || this.charItemManager.equipped == null) { - Logger.error("Player " + currentID + " missing skills or equipment"); - defaultAtrAndDamage(true); - defaultAtrAndDamage(false); - this.defenseRating = 0; - return; - } - this.atrHandOne = (short) this.mobBase.getAttackRating(); - this.minDamageHandOne = (short) this.mobBase.getDamageMin(); - this.maxDamageHandOne = (short) this.mobBase.getDamageMax(); - this.rangeHandOne = 6.5f; - this.speedHandOne = 20; - - this.atrHandTwo = (short) this.mobBase.getAttackRating(); - this.minDamageHandTwo = (short) this.mobBase.getDamageMin(); - this.maxDamageHandTwo = (short) this.mobBase.getDamageMax(); - this.rangeHandTwo = 6.5f; - this.speedHandTwo = 20; - - if (this.charItemManager.equipped.get(EquipSlotType.RHELD) != null) - calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), true); //has mainhand weapon to calculate - - - if (this.charItemManager.equipped.get(EquipSlotType.LHELD) != null && !ItemTemplate.isShield(this.charItemManager.equipped.get(EquipSlotType.LHELD).template)) - calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), false); //has offhand weapon to calculate - - - try { - calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.RHELD), true); - } catch (Exception e) { - - this.atrHandOne = (short) this.mobBase.getAttackRating(); - this.minDamageHandOne = (short) this.mobBase.getDamageMin(); - this.maxDamageHandOne = (short) this.mobBase.getDamageMax(); - this.rangeHandOne = 6.5f; - this.speedHandOne = 20; - Logger.info("Mobbase ID " + this.getMobBaseID() + " returned an error. setting to default ATR and Damage." + e.getMessage()); - } - - try { - calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), false); - - } catch (Exception e) { - - this.atrHandTwo = (short) this.mobBase.getAttackRating(); - this.minDamageHandTwo = (short) this.mobBase.getDamageMin(); - this.maxDamageHandTwo = (short) this.mobBase.getDamageMax(); - this.rangeHandTwo = 6.5f; - this.speedHandTwo = 20; - Logger.info("Mobbase ID " + this.getMobBaseID() + " returned an error. setting to default ATR and Damage." + e.getMessage()); - } - - try { - float defense = this.mobBase.getDefenseRating(); - defense += getShieldDefense(charItemManager.equipped.get(EquipSlotType.LHELD)); - defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.HELM)); - defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.CHEST)); - defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.UPARM)); - defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.HANDS)); - defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.LEGS)); - defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.FEET)); - defense += getWeaponDefense(charItemManager.equipped); - - // TODO add error log here - if (this.bonuses != null) { - - // add any bonuses - - defense += (short) this.bonuses.getFloat(ModType.DCV, SourceType.NONE); - - // Finally, multiply any percent modifiers. DO THIS LAST! - - float pos_Bonus = 1 + this.bonuses.getFloatPercentPositive(ModType.DCV, SourceType.NONE); - - - defense = (short) (defense * pos_Bonus); - - //Lucky rune applies next - - float neg_Bonus = this.bonuses.getFloatPercentNegative(ModType.DCV, SourceType.NONE); - defense = (short) (defense * (1 + neg_Bonus)); - - - } else - Logger.error("Error: missing bonuses"); - - defense = (defense < 1) ? 1 : defense; - this.defenseRating = (short) (defense + 0.5f); - } catch (Exception e) { - Logger.info("Mobbase ID " + this.getMobBaseID() + " returned an error. Setting to Default Defense." + e.getMessage()); - this.defenseRating = (short) this.mobBase.getDefenseRating(); - } - // calculate defense for equipment - } - - private float getWeaponDefense(ConcurrentHashMap equipped) { - - Item weapon = equipped.get(EquipSlotType.RHELD); - ItemBase wb = null; - CharacterSkill skill, mastery; - float val = 0; - boolean unarmed = false; - - if (weapon == null) { - weapon = equipped.get(EquipSlotType.LHELD); - - if (weapon == null) - unarmed = true; - else - wb = weapon.getItemBase(); - - } else - wb = weapon.getItemBase(); - - if (wb == null) - unarmed = true; - - if (unarmed) { - skill = null; - mastery = null; - } else { - skill = this.skills.get(weapon.template.item_skill_used); - mastery = this.skills.get(wb.getMastery()); - } - - if (skill != null) - val += (int) skill.getModifiedAmount() / 2f; - - if (mastery != null) - val += (int) mastery.getModifiedAmount() / 2f; - - return val; - } - - private float getShieldDefense(Item shield) { - - if (shield == null) - return 0; - - ItemBase ab = shield.getItemBase(); - - if (!ItemTemplate.isShield(shield.template)) - return 0; - - CharacterSkill blockSkill = this.skills.get("Block"); - float skillMod; - - if (blockSkill == null) { - skillMod = CharacterSkill.getQuickMastery(this, "Block"); - - if (skillMod == 0f) - return 0; - - } else - skillMod = blockSkill.getModifiedAmount(); - - float def = ab.getDefense(); - - //apply item defense bonuses - - return (def * (1 + ((int) skillMod / 100f))); - } - - private float getArmorDefense(Item armor) { - - if (armor == null) - return 0; - - ItemBase ib = armor.getItemBase(); - - if (ib == null) - return 0; - - if (!armor.template.item_type.equals(ItemType.ARMOR)) - return 0; - - if (armor.template.item_skill_used.isEmpty()) - return ib.getDefense(); - - CharacterSkill armorSkill = this.skills.get(armor.template.item_skill_used); - - if (armorSkill == null) - return ib.getDefense(); - - float def = ib.getDefense(); - - //apply item defense bonuses - - return (def * (1 + ((int) armorSkill.getModifiedAmount() / 50f))); - } - - private void calculateAtrDamageForWeapon(Item weapon, boolean mainHand) { - - int baseStrength = 0; - - float skillPercentage, masteryPercentage; - float mastDam; - - // make sure weapon exists - - boolean noWeapon = false; - ItemBase wb = null; - - if (weapon == null) - noWeapon = true; - - else { - - ItemBase ib = weapon.getItemBase(); - - if (ib == null) - noWeapon = true; - else if (weapon.template.item_type.equals(ItemType.WEAPON) == false) { - defaultAtrAndDamage(mainHand); - return; - } else - wb = ib; - } - - float min, max; - float speed; - boolean strBased = false; - - // get skill percentages and min and max damage for weapons - - if (noWeapon) { - - if (mainHand) - this.rangeHandOne = this.mobBase.getAttackRange(); - else - this.rangeHandTwo = -1; // set to do not attack - - skillPercentage = getModifiedAmount(this.skills.get("Unarmed Combat")); - masteryPercentage = getModifiedAmount(this.skills.get("Unarmed Combat Mastery")); - - if (masteryPercentage == 0f) - mastDam = CharacterSkill.getQuickMastery(this, "Unarmed Combat Mastery"); - else - mastDam = masteryPercentage; - - // TODO Correct these - min = this.mobBase.getDamageMin(); - max = this.mobBase.getDamageMax(); - } else { - - if (mainHand) - this.rangeHandOne = weapon.getItemBase().getRange() * (1 + (baseStrength / 600.0f)); - else - this.rangeHandTwo = weapon.getItemBase().getRange() * (1 + (baseStrength / 600.0f)); - - skillPercentage = getModifiedAmount(this.skills.get(weapon.template.item_skill_used)); - masteryPercentage = getModifiedAmount(this.skills.get(wb.getMastery())); - - if (masteryPercentage == 0f) - mastDam = 0f; - else - mastDam = masteryPercentage; - - min = wb.getMinDamage(); - max = wb.getMaxDamage(); - strBased = wb.isStrBased(); - } - - // calculate atr - float atr = this.mobBase.getAttackRating(); - - if (this.statStrCurrent > this.statDexCurrent) - atr += statStrCurrent * .5; - else - atr += statDexCurrent * .5; - - // add in any bonuses to atr - - if (this.bonuses != null) { - atr += this.bonuses.getFloat(ModType.OCV, SourceType.NONE); - - // Finally use any multipliers. DO THIS LAST! - float pos_Bonus = 1 + this.bonuses.getFloatPercentPositive(ModType.OCV, SourceType.NONE); - - atr *= pos_Bonus; - - //and negative percent modifiers - //TODO DO DEBUFFS AFTER?? wILL TEst when finished - float neg_Bonus = this.bonuses.getFloatPercentNegative(ModType.OCV, SourceType.NONE); - - atr *= (1 + neg_Bonus); - } - - atr = (atr < 1) ? 1 : atr; - - // set atr - - if (mainHand) - this.atrHandOne = (short) (atr + 0.5f); - else - this.atrHandTwo = (short) (atr + 0.5f); - - //calculate speed - - if (wb != null) - speed = wb.getSpeed(); - else - speed = 20f; //unarmed attack speed - - if (this.bonuses != null && this.bonuses.getFloat(ModType.AttackDelay, SourceType.NONE) != 0f) //add effects speed bonus - speed *= (1 + this.bonuses.getFloatPercentAll(ModType.AttackDelay, SourceType.NONE)); - - if (speed < 10) - speed = 10; - - //add min/max damage bonuses for weapon **REMOVED - - //if duel wielding, cut damage by 30% - // calculate damage - - float minDamage; - float maxDamage; - float pri = (strBased) ? (float) this.statStrCurrent : (float) this.statDexCurrent; - float sec = (strBased) ? (float) this.statDexCurrent : (float) this.statStrCurrent; - - minDamage = (float) (min * ((0.0315f * Math.pow(pri, 0.75f)) + (0.042f * Math.pow(sec, 0.75f)) + (0.01f * ((int) skillPercentage + (int) mastDam)))); - maxDamage = (float) (max * ((0.0785f * Math.pow(pri, 0.75f)) + (0.016f * Math.pow(sec, 0.75f)) + (0.0075f * ((int) skillPercentage + (int) mastDam)))); - - minDamage = (float) ((int) (minDamage + 0.5f)); //round to nearest decimal - maxDamage = (float) ((int) (maxDamage + 0.5f)); //round to nearest decimal - - //add Base damage last. - float minDamageMod = this.mobBase.getDamageMin(); - float maxDamageMod = this.mobBase.getDamageMax(); - - minDamage += minDamageMod; - maxDamage += maxDamageMod; - - // add in any bonuses to damage - - if (this.bonuses != null) { - // Add any base bonuses - minDamage += this.bonuses.getFloat(ModType.MinDamage, SourceType.NONE); - maxDamage += this.bonuses.getFloat(ModType.MaxDamage, SourceType.NONE); - - // Finally use any multipliers. DO THIS LAST! - minDamage *= (1 + this.bonuses.getFloatPercentAll(ModType.MinDamage, SourceType.NONE)); - maxDamage *= (1 + this.bonuses.getFloatPercentAll(ModType.MaxDamage, SourceType.NONE)); - } - - // set damages - - if (mainHand) { - this.minDamageHandOne = (short) minDamage; - this.maxDamageHandOne = (short) maxDamage; - this.speedHandOne = 30; - } else { - this.minDamageHandTwo = (short) minDamage; - this.maxDamageHandTwo = (short) maxDamage; - this.speedHandTwo = 30; - } - } - - private void defaultAtrAndDamage(boolean mainHand) { - - if (mainHand) { - this.atrHandOne = 0; - this.minDamageHandOne = 0; - this.maxDamageHandOne = 0; - this.rangeHandOne = -1; - this.speedHandOne = 20; - } else { - this.atrHandTwo = 0; - this.minDamageHandTwo = 0; - this.maxDamageHandTwo = 0; - this.rangeHandTwo = -1; - this.speedHandTwo = 20; - } - } - - @Override public void runAfterLoad() {