Browse Source

Update to passive logic

combat-2
MagicBot 8 months ago
parent
commit
2bb414fc33
  1. 13
      src/engine/Enum.java
  2. 122
      src/engine/gameManager/FinalCombatManager.java

13
src/engine/Enum.java

@ -2839,4 +2839,17 @@ public class Enum {
Intelligence, Intelligence,
Spirit, Spirit,
} }
public enum PassiveType {
None(0),
Dodge(20),
Block(21),
Parry(22);
public int value;
PassiveType(int value) {
this.value = value;
}
}
} }

122
src/engine/gameManager/FinalCombatManager.java

@ -15,12 +15,15 @@ import engine.powers.effectmodifiers.AbstractEffectModifier;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.EnumSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class FinalCombatManager { public class FinalCombatManager {
public static void combatCycle(AbstractCharacter attacker, AbstractWorldObject target) { public static void combatCycle(AbstractCharacter attacker, AbstractWorldObject target) {
//early exit checks //early exit checks
if (attacker == null || target == null || !attacker.isAlive() || !target.isAlive()) if (attacker == null || target == null || !attacker.isAlive() || !target.isAlive())
return; return;
@ -41,6 +44,7 @@ public class FinalCombatManager {
Item mainWeapon = attacker.charItemManager.getEquipped().get(Enum.EquipSlotType.RHELD); Item mainWeapon = attacker.charItemManager.getEquipped().get(Enum.EquipSlotType.RHELD);
Item offWeapon = attacker.charItemManager.getEquipped().get(Enum.EquipSlotType.LHELD); Item offWeapon = attacker.charItemManager.getEquipped().get(Enum.EquipSlotType.LHELD);
if (mainWeapon == null && offWeapon == null) { if (mainWeapon == null && offWeapon == null) {
//no weapons equipped, punch with both fists //no weapons equipped, punch with both fists
processAttack(attacker, target, Enum.EquipSlotType.RHELD); processAttack(attacker, target, Enum.EquipSlotType.RHELD);
@ -62,64 +66,80 @@ public class FinalCombatManager {
} }
public static void processAttack(AbstractCharacter attacker, AbstractWorldObject target, Enum.EquipSlotType slot) { public static void processAttack(AbstractCharacter attacker, AbstractWorldObject target, Enum.EquipSlotType slot) {
//check if character can even attack yet
// heck if character can even attack yet
if (attacker.getTimestamps().containsKey("Attack" + slot.name())) if (attacker.getTimestamps().containsKey("Attack" + slot.name()))
if (System.currentTimeMillis() < attacker.getTimestamps().get("Attack" + slot.name())) if (System.currentTimeMillis() < attacker.getTimestamps().get("Attack" + slot.name()))
return; return;
// check if character is in range to attack target // check if character is in range to attack target
PlayerBonuses bonus = attacker.getBonuses(); PlayerBonuses bonus = attacker.getBonuses();
float rangeMod = 1.0f; float rangeMod = 1.0f;
float attackRange = MBServerStatics.NO_WEAPON_RANGE; float attackRange = MBServerStatics.NO_WEAPON_RANGE;
Item weapon = attacker.charItemManager.getEquipped(slot); Item weapon = attacker.charItemManager.getEquipped(slot);
if (weapon != null) { if (weapon != null) {
if (bonus != null) if (bonus != null)
rangeMod += bonus.getFloatPercentAll(Enum.ModType.WeaponRange, Enum.SourceType.NONE); rangeMod += bonus.getFloatPercentAll(Enum.ModType.WeaponRange, Enum.SourceType.NONE);
attackRange = weapon.template.item_weapon_max_range * rangeMod; attackRange = weapon.template.item_weapon_max_range * rangeMod;
} }
if (attacker.getObjectType().equals(Enum.GameObjectType.Mob)) if (attacker.getObjectType().equals(Enum.GameObjectType.Mob))
if (((Mob) attacker).isSiege()) if (((Mob) attacker).isSiege())
attackRange = 300; attackRange = 300;
float distanceSquared = attacker.loc.distanceSquared(target.loc); float distanceSquared = attacker.loc.distanceSquared(target.loc);
if (distanceSquared > attackRange * attackRange) if (distanceSquared > attackRange * attackRange)
return; return;
// take stamina away from attacker // take stamina away from attacker
if (weapon == null)
attacker.modifyStamina(-0.5f, attacker, true); if (weapon != null) {
else {
float stam = weapon.template.item_wt / 3f; float stam = weapon.template.item_wt / 3f;
stam = (stam < 1) ? 1 : stam; stam = (stam < 1) ? 1 : stam;
attacker.modifyStamina(-(stam), attacker, true); attacker.modifyStamina(-(stam), attacker, true);
} } else
attacker.modifyStamina(-0.5f, attacker, true);
//cancel things that are cancelled by an attack //cancel things that are cancelled by an attack
attacker.cancelOnAttackSwing(); attacker.cancelOnAttackSwing();
//declare relevant variables //declare relevant variables
int min = attacker.minDamageHandOne; int min = attacker.minDamageHandOne;
int max = attacker.maxDamageHandOne; int max = attacker.maxDamageHandOne;
int atr = attacker.atrHandOne; int atr = attacker.atrHandOne;
//get the proper stats based on which slot is attacking //get the proper stats based on which slot is attacking
if (slot == Enum.EquipSlotType.LHELD) { if (slot == Enum.EquipSlotType.LHELD) {
min = attacker.minDamageHandTwo; min = attacker.minDamageHandTwo;
max = attacker.maxDamageHandTwo; max = attacker.maxDamageHandTwo;
atr = attacker.atrHandTwo; atr = attacker.atrHandTwo;
} }
int def = 0; int def = 0;
if (AbstractCharacter.IsAbstractCharacter(target)) if (AbstractCharacter.IsAbstractCharacter(target))
def = ((AbstractCharacter) target).defenseRating; def = ((AbstractCharacter) target).defenseRating;
//calculate hit chance based off ATR and DEF //calculate hit chance based off ATR and DEF
int hitChance; int hitChance;
float dif = atr / def; float dif = atr / def;
if (dif <= 0.8f) if (dif <= 0.8f)
hitChance = 4; hitChance = 4;
else else
hitChance = ((int) (450 * (dif - 0.8f)) + 4); hitChance = ((int) (450 * (dif - 0.8f)) + 4);
if (target.getObjectType() == Enum.GameObjectType.Building) if (target.getObjectType() == Enum.GameObjectType.Building)
hitChance = 100; hitChance = 100;
@ -137,13 +157,25 @@ public class FinalCombatManager {
} }
//calculate passive chances only if target is AbstractCharacter //calculate passive chances only if target is AbstractCharacter
if(AbstractCharacter.IsAbstractCharacter(target)){
if (EnumSet.of(Enum.GameObjectType.PlayerCharacter, Enum.GameObjectType.NPC, Enum.GameObjectType.Mob).contains(target.getObjectType())) {
Enum.PassiveType passiveType = Enum.PassiveType.None;
int hitRoll = ThreadLocalRandom.current().nextInt(100); int hitRoll = ThreadLocalRandom.current().nextInt(100);
float dodgeChance = ((AbstractCharacter) target).getPassiveChance("Dodge", attacker.getLevel(), true); float dodgeChance = ((AbstractCharacter) target).getPassiveChance("Dodge", attacker.getLevel(), true);
float blockChance = ((AbstractCharacter) target).getPassiveChance("Block", attacker.getLevel(), true); float blockChance = ((AbstractCharacter) target).getPassiveChance("Block", attacker.getLevel(), true);
float parryChance = ((AbstractCharacter) target).getPassiveChance("Parry", attacker.getLevel(), true); float parryChance = ((AbstractCharacter) target).getPassiveChance("Parry", attacker.getLevel(), true);
if(hitRoll > dodgeChance || hitRoll > parryChance || hitRoll > blockChance){
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, MBServerStatics.COMBAT_SEND_BLOCK); if (hitRoll < dodgeChance)
passiveType = Enum.PassiveType.Dodge;
else if (hitRoll < blockChance)
passiveType = Enum.PassiveType.Block;
else if (hitRoll < parryChance)
passiveType = Enum.PassiveType.Parry;
if (passiveType.equals(Enum.PassiveType.None) == false) {
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value);
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter) if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); DispatchMessage.dispatchMsgToInterestArea(target, msg, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
@ -160,7 +192,9 @@ public class FinalCombatManager {
return; return;
//get the damage type //get the damage type
Enum.SourceType damageType; Enum.SourceType damageType;
if (attacker.charItemManager.getEquipped().get(slot) == null) { if (attacker.charItemManager.getEquipped().get(slot) == null) {
damageType = Enum.SourceType.CRUSHING; damageType = Enum.SourceType.CRUSHING;
if (attacker.getObjectType().equals(Enum.GameObjectType.Mob)) if (attacker.getObjectType().equals(Enum.GameObjectType.Mob))
@ -171,18 +205,19 @@ public class FinalCombatManager {
} }
//get resists //get resists
Resists resists; Resists resists;
if(AbstractCharacter.IsAbstractCharacter(target) == false){
//this is a building if (AbstractCharacter.IsAbstractCharacter(target) == false)
resists = ((Building) target).getResists(); resists = ((Building) target).getResists(); //this is a building
}else{ else
//this is a character resists = ((AbstractCharacter) target).getResists(); //this is a character
resists = ((AbstractCharacter) target).getResists();
}
if (AbstractCharacter.IsAbstractCharacter(target)) { if (AbstractCharacter.IsAbstractCharacter(target)) {
AbstractCharacter absTarget = (AbstractCharacter) target; AbstractCharacter absTarget = (AbstractCharacter) target;
//check damage shields //check damage shields
PlayerBonuses bonuses = absTarget.getBonuses(); PlayerBonuses bonuses = absTarget.getBonuses();
if (bonuses != null) { if (bonuses != null) {
@ -193,13 +228,16 @@ public class FinalCombatManager {
for (DamageShield ds : damageShields.values()) { for (DamageShield ds : damageShields.values()) {
//get amount to damage back //get amount to damage back
float amount; float amount;
if (ds.usePercent()) if (ds.usePercent())
amount = damage * ds.getAmount() / 100; amount = damage * ds.getAmount() / 100;
else else
amount = ds.getAmount(); amount = ds.getAmount();
//get resisted damage for damagetype //get resisted damage for damagetype
if (resists != null) if (resists != null)
amount = resists.getResistedDamage(absTarget, attacker, ds.getDamageType(), amount, 0); amount = resists.getResistedDamage(absTarget, attacker, ds.getDamageType(), amount, 0);
total += amount; total += amount;
@ -212,29 +250,39 @@ public class FinalCombatManager {
DispatchMessage.sendToAllInRange(target, cmm); DispatchMessage.sendToAllInRange(target, cmm);
} }
} }
if (resists != null) { if (resists != null) {
//check for damage type immunities //check for damage type immunities
if (resists.immuneTo(damageType)) if (resists.immuneTo(damageType))
return; return;
//calculate resisted damage including fortitude //calculate resisted damage including fortitude
damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0); damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0);
} }
} }
//remove damage from target health //remove damage from target health
if (damage > 0) { if (damage > 0) {
if(AbstractCharacter.IsAbstractCharacter(target)){
if (AbstractCharacter.IsAbstractCharacter(target))
((AbstractCharacter) target).modifyHealth(-damage, attacker, true); ((AbstractCharacter) target).modifyHealth(-damage, attacker, true);
}else{ else
((Building) target).setCurrentHitPoints(target.getCurrentHitpoints() - damage); ((Building) target).setCurrentHitPoints(target.getCurrentHitpoints() - damage);
}
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, 0); TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, 0);
DispatchMessage.sendToAllInRange(target, cmm); DispatchMessage.sendToAllInRange(target, cmm);
} }
//calculate next allowed attack and update the timestamp //calculate next allowed attack and update the timestamp
long delay = 20 * 100; long delay = 20 * 100;
if (weapon != null) { if (weapon != null) {
int wepSpeed = (int) (weapon.template.item_weapon_wepspeed); int wepSpeed = (int) (weapon.template.item_weapon_wepspeed);
if (weapon.getBonusPercent(Enum.ModType.WeaponSpeed, Enum.SourceType.NONE) != 0f) //add weapon speed bonus if (weapon.getBonusPercent(Enum.ModType.WeaponSpeed, Enum.SourceType.NONE) != 0f) //add weapon speed bonus
@ -248,9 +296,11 @@ public class FinalCombatManager {
delay = wepSpeed * 100; delay = wepSpeed * 100;
} }
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay);
//handle auto attack job creation //handle auto attack job creation
ConcurrentHashMap<String, JobContainer> timers = attacker.getTimers(); ConcurrentHashMap<String, JobContainer> timers = attacker.getTimers();
if (timers != null) { if (timers != null) {
@ -258,41 +308,46 @@ public class FinalCombatManager {
JobContainer job; JobContainer job;
job = JobScheduler.getInstance().scheduleJob(aj, (delay + 1)); // offset 1 millisecond so no overlap issue job = JobScheduler.getInstance().scheduleJob(aj, (delay + 1)); // offset 1 millisecond so no overlap issue
timers.put("Attack" + slot, job); timers.put("Attack" + slot, job);
} else { } else
Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID()); Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID());
}
} }
public static void toggleCombat(boolean toggle, ClientConnection origin) { public static void toggleCombat(boolean toggle, ClientConnection origin) {
PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin);
if (pc == null)
if (playerCharacter == null)
return; return;
pc.setCombat(toggle); playerCharacter.setCombat(toggle);
if (!toggle) // toggle is move it to false so clear combat target if (!toggle) // toggle is move it to false so clear combat target
pc.setCombatTarget(null); //clear last combat target playerCharacter.setCombatTarget(null); //clear last combat target
UpdateStateMsg rwss = new UpdateStateMsg(); UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(pc); rwss.setPlayer(playerCharacter);
DispatchMessage.dispatchMsgToInterestArea(pc, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); DispatchMessage.dispatchMsgToInterestArea(playerCharacter, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
} }
public static void toggleSit(boolean toggle, ClientConnection origin) { public static void toggleSit(boolean toggle, ClientConnection origin) {
PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin);
if (pc == null)
if (playerCharacter == null)
return; return;
pc.setSit(toggle); playerCharacter.setSit(toggle);
UpdateStateMsg rwss = new UpdateStateMsg(); UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(pc); rwss.setPlayer(playerCharacter);
DispatchMessage.dispatchMsgToInterestArea(pc, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); DispatchMessage.dispatchMsgToInterestArea(playerCharacter, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
} }
//Called when character takes damage.
public static void handleRetaliate(AbstractCharacter target, AbstractCharacter attacker) { public static void handleRetaliate(AbstractCharacter target, AbstractCharacter attacker) {
//Called when character takes damage.
if (attacker == null || target == null) if (attacker == null || target == null)
return; return;
@ -308,11 +363,13 @@ public class FinalCombatManager {
boolean isCombat = target.isCombat(); boolean isCombat = target.isCombat();
//If target in combat and has no target, then attack back //If target in combat and has no target, then attack back
if (isCombat && target.combatTarget == null) if (isCombat && target.combatTarget == null)
target.setCombatTarget(attacker); target.setCombatTarget(attacker);
} }
public static int getSwingAnimation(ItemTemplate wb, DeferredPowerJob dpj, boolean mainHand) { public static int getSwingAnimation(ItemTemplate wb, DeferredPowerJob dpj, boolean mainHand) {
int token = 0; int token = 0;
if (dpj != null) if (dpj != null)
@ -356,6 +413,7 @@ public class FinalCombatManager {
} }
} else { } else {
if (template.weapon_attack_anim_left.size() > 0) { if (template.weapon_attack_anim_left.size() > 0) {
int animation; int animation;
int random = ThreadLocalRandom.current().nextInt(template.weapon_attack_anim_left.size()); int random = ThreadLocalRandom.current().nextInt(template.weapon_attack_anim_left.size());

Loading…
Cancel
Save