Browse Source

Class reformat

combat-2
MagicBot 7 months ago
parent
commit
0286b63a8e
  1. 86
      src/engine/gameManager/CombatManager.java

86
src/engine/gameManager/CombatManager.java

@ -12,7 +12,6 @@ import engine.job.JobContainer;
import engine.job.JobScheduler; import engine.job.JobScheduler;
import engine.jobs.AttackJob; import engine.jobs.AttackJob;
import engine.jobs.DeferredPowerJob; import engine.jobs.DeferredPowerJob;
import engine.math.Bounds;
import engine.mbEnums; import engine.mbEnums;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
@ -41,13 +40,13 @@ public enum CombatManager {
if (attacker == null || target == null || !attacker.isAlive() || !target.isAlive()) if (attacker == null || target == null || !attacker.isAlive() || !target.isAlive())
return; return;
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
if (((Mob) attacker).nextAttackTime > System.currentTimeMillis()) if (((Mob) attacker).nextAttackTime > System.currentTimeMillis())
return; return;
switch (target.getObjectType()) { switch (target.getObjectType()) {
case Building: case Building:
if (((Building) target).isVulnerable() == false) if (!((Building) target).isVulnerable())
return; return;
break; break;
case PlayerCharacter: case PlayerCharacter:
@ -66,7 +65,7 @@ public enum CombatManager {
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, mbEnums.EquipSlotType.RHELD); processAttack(attacker, target, mbEnums.EquipSlotType.RHELD);
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter))
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD); processAttack(attacker, target, mbEnums.EquipSlotType.LHELD);
return; return;
} }
@ -77,7 +76,7 @@ public enum CombatManager {
return; return;
} }
if (mainWeapon == null && offWeapon != null && offWeapon.template.item_skill_required.containsKey("Block") == false) { if (mainWeapon == null && offWeapon != null && !offWeapon.template.item_skill_required.containsKey("Block")) {
//swing left hand only //swing left hand only
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD); processAttack(attacker, target, mbEnums.EquipSlotType.LHELD);
return; return;
@ -95,12 +94,11 @@ public enum CombatManager {
return; return;
} }
if (mainWeapon != null && offWeapon != null && offWeapon.template.item_skill_required.containsKey("Block") == false) { if (mainWeapon != null && offWeapon != null && !offWeapon.template.item_skill_required.containsKey("Block")) {
//two weapons equipped, swing both hands //two weapons equipped, swing both hands
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD); processAttack(attacker, target, mbEnums.EquipSlotType.RHELD);
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter))
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD); processAttack(attacker, target, mbEnums.EquipSlotType.LHELD);
return;
} }
} }
@ -129,20 +127,20 @@ public enum CombatManager {
float distanceSquared = attacker.loc.distanceSquared(target.loc); float distanceSquared = attacker.loc.distanceSquared(target.loc);
boolean inRange = false; boolean inRange = false;
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)){ if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
attackRange += ((PlayerCharacter)attacker).getCharacterHeight() * 0.5f; attackRange += ((PlayerCharacter) attacker).getCharacterHeight() * 0.5f;
}else { } else {
attackRange += attacker.calcHitBox(); attackRange += attacker.calcHitBox();
} }
switch(target.getObjectType()){ switch (target.getObjectType()) {
case PlayerCharacter: case PlayerCharacter:
attackRange += ((PlayerCharacter)target).getCharacterHeight() * 0.5f; attackRange += ((PlayerCharacter) target).getCharacterHeight() * 0.5f;
if(distanceSquared < attackRange * attackRange) if (distanceSquared < attackRange * attackRange)
inRange = true; inRange = true;
break; break;
case Mob: case Mob:
attackRange += ((AbstractCharacter)target).calcHitBox(); attackRange += ((AbstractCharacter) target).calcHitBox();
if(distanceSquared < attackRange * attackRange) if (distanceSquared < attackRange * attackRange)
inRange = true; inRange = true;
break; break;
case Building: case Building:
@ -150,8 +148,8 @@ public enum CombatManager {
float locZ = target.loc.z - target.getBounds().getHalfExtents().y; float locZ = target.loc.z - target.getBounds().getHalfExtents().y;
float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2; float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2;
float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2; float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2;
Rectangle2D.Float rect = new Rectangle2D.Float(locX,locZ,sizeX,sizeZ); Rectangle2D.Float rect = new Rectangle2D.Float(locX, locZ, sizeX, sizeZ);
if(rect.contains(new Point2D.Float(attacker.loc.x,attacker.loc.z))) if (rect.contains(new Point2D.Float(attacker.loc.x, attacker.loc.z)))
inRange = true; inRange = true;
break; break;
} }
@ -172,19 +170,19 @@ public enum CombatManager {
if (wepSpeed < 10) if (wepSpeed < 10)
wepSpeed = 10; //Old was 10, but it can be reached lower with legit buffs,effects. wepSpeed = 10; //Old was 10, but it can be reached lower with legit buffs,effects.
delay = wepSpeed * 100; delay = wepSpeed * 100L;
} }
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
((Mob)attacker).nextAttackTime = System.currentTimeMillis() + delay; ((Mob) attacker).nextAttackTime = System.currentTimeMillis() + delay;
if (inRange) { if (inRange) {
//handle retaliate //handle retaliate
if(AbstractCharacter.IsAbstractCharacter(target)){ if (AbstractCharacter.IsAbstractCharacter(target)) {
if(((AbstractCharacter)target).combatTarget == null || ((AbstractCharacter)target).combatTarget.isAlive() == false){ if (((AbstractCharacter) target).combatTarget == null || !((AbstractCharacter) target).combatTarget.isAlive()) {
((AbstractCharacter)target).combatTarget = attacker; ((AbstractCharacter) target).combatTarget = attacker;
if(target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat()) if (target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat())
combatCycle((AbstractCharacter) target, attacker); combatCycle((AbstractCharacter) target, attacker);
} }
} }
@ -204,10 +202,10 @@ public enum CombatManager {
} }
//check if Out of Stamina //check if Out of Stamina
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) { if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
if (attacker.getStamina() < (weapon.template.item_wt / 3f)) { if (attacker.getStamina() < (weapon.template.item_wt / 3f)) {
//set auto attack job //set auto attack job
setAutoAttackJob(attacker,slot,delay); setAutoAttackJob(attacker, slot, delay);
return; return;
} }
} }
@ -271,7 +269,7 @@ public enum CombatManager {
DispatchMessage.sendToAllInRange(attacker, msg); DispatchMessage.sendToAllInRange(attacker, msg);
//set auto attack job //set auto attack job
setAutoAttackJob(attacker,slot,delay); setAutoAttackJob(attacker, slot, delay);
return; return;
} }
@ -299,7 +297,7 @@ public enum CombatManager {
passiveType = mbEnums.PassiveType.Parry; passiveType = mbEnums.PassiveType.Parry;
if (passiveType.equals(mbEnums.PassiveType.None) == false) { if (!passiveType.equals(mbEnums.PassiveType.None)) {
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value); TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value);
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter) if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
@ -308,7 +306,7 @@ public enum CombatManager {
DispatchMessage.sendToAllInRange(attacker, msg); DispatchMessage.sendToAllInRange(attacker, msg);
//set auto attack job //set auto attack job
setAutoAttackJob(attacker,slot,delay); setAutoAttackJob(attacker, slot, delay);
return; return;
} }
} }
@ -317,7 +315,7 @@ public enum CombatManager {
int damage = ThreadLocalRandom.current().nextInt(min, max + 1); int damage = ThreadLocalRandom.current().nextInt(min, max + 1);
if (damage == 0) { if (damage == 0) {
//set auto attack job //set auto attack job
setAutoAttackJob(attacker,slot,delay); setAutoAttackJob(attacker, slot, delay);
return; return;
} }
//get the damage type //get the damage type
@ -337,7 +335,7 @@ public enum CombatManager {
Resists resists; Resists resists;
if (AbstractCharacter.IsAbstractCharacter(target) == false) if (!AbstractCharacter.IsAbstractCharacter(target))
resists = ((Building) target).getResists(); //this is a building resists = ((Building) target).getResists(); //this is a building
else else
resists = ((AbstractCharacter) target).getResists(); //this is a character resists = ((AbstractCharacter) target).getResists(); //this is a character
@ -386,7 +384,7 @@ public enum CombatManager {
if (resists.immuneTo(damageType)) { if (resists.immuneTo(damageType)) {
//set auto attack job //set auto attack job
setAutoAttackJob(attacker,slot,delay); setAutoAttackJob(attacker, slot, delay);
return; return;
} }
//calculate resisted damage including fortitude //calculate resisted damage including fortitude
@ -413,7 +411,7 @@ public enum CombatManager {
} }
} }
//set auto attack job //set auto attack job
setAutoAttackJob(attacker,slot,delay); setAutoAttackJob(attacker, slot, delay);
} }
@ -474,33 +472,33 @@ public enum CombatManager {
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;
if (dpj != null) { if (dpj != null) {
token = (dpj.getPower() != null) ? dpj.getPower().getToken() : 0; token = (dpj.getPower() != null) ? dpj.getPower().getToken() : 0;
if (token == 563721004) //kick animation if (token == 563721004) //kick animation
return 79; return 79;
if(wb != null) {
if (mainHand) { if (wb != null)
if (mainHand)
return wb.weapon_attack_anim_right.get(ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_right.size()))[0]; return wb.weapon_attack_anim_right.get(ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_right.size()))[0];
} else { else
return wb.weapon_attack_anim_left.get(ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_left.size()))[0]; return wb.weapon_attack_anim_left.get(ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_left.size()))[0];
}
}
} }
if (wb == null) if (wb == null)
return 75; return 75;
if(mainHand){ if (mainHand)
return wb.weapon_attack_anim_right.get(0)[0]; return wb.weapon_attack_anim_right.get(0)[0];
} else{ else
return wb.weapon_attack_anim_left.get(0)[0]; return wb.weapon_attack_anim_left.get(0)[0];
}
} }
public static void setAutoAttackJob(AbstractCharacter attacker, mbEnums.EquipSlotType slot, long delay){ public static void setAutoAttackJob(AbstractCharacter attacker, mbEnums.EquipSlotType slot, long delay) {
//calculate next allowed attack and update the timestamp //calculate next allowed attack and update the timestamp
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay);

Loading…
Cancel
Save