Browse Source

Class reformat

combat-2
MagicBot 8 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; @@ -12,7 +12,6 @@ import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.AttackJob;
import engine.jobs.DeferredPowerJob;
import engine.math.Bounds;
import engine.mbEnums;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
@ -41,13 +40,13 @@ public enum CombatManager { @@ -41,13 +40,13 @@ public enum CombatManager {
if (attacker == null || target == null || !attacker.isAlive() || !target.isAlive())
return;
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
if (((Mob) attacker).nextAttackTime > System.currentTimeMillis())
return;
switch (target.getObjectType()) {
case Building:
if (((Building) target).isVulnerable() == false)
if (!((Building) target).isVulnerable())
return;
break;
case PlayerCharacter:
@ -66,7 +65,7 @@ public enum CombatManager { @@ -66,7 +65,7 @@ public enum CombatManager {
if (mainWeapon == null && offWeapon == null) {
//no weapons equipped, punch with both fists
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);
return;
}
@ -77,7 +76,7 @@ public enum CombatManager { @@ -77,7 +76,7 @@ public enum CombatManager {
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
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD);
return;
@ -95,12 +94,11 @@ public enum CombatManager { @@ -95,12 +94,11 @@ public enum CombatManager {
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
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);
return;
}
}
@ -129,20 +127,20 @@ public enum CombatManager { @@ -129,20 +127,20 @@ public enum CombatManager {
float distanceSquared = attacker.loc.distanceSquared(target.loc);
boolean inRange = false;
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)){
attackRange += ((PlayerCharacter)attacker).getCharacterHeight() * 0.5f;
}else {
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
attackRange += ((PlayerCharacter) attacker).getCharacterHeight() * 0.5f;
} else {
attackRange += attacker.calcHitBox();
}
switch(target.getObjectType()){
switch (target.getObjectType()) {
case PlayerCharacter:
attackRange += ((PlayerCharacter)target).getCharacterHeight() * 0.5f;
if(distanceSquared < attackRange * attackRange)
attackRange += ((PlayerCharacter) target).getCharacterHeight() * 0.5f;
if (distanceSquared < attackRange * attackRange)
inRange = true;
break;
case Mob:
attackRange += ((AbstractCharacter)target).calcHitBox();
if(distanceSquared < attackRange * attackRange)
attackRange += ((AbstractCharacter) target).calcHitBox();
if (distanceSquared < attackRange * attackRange)
inRange = true;
break;
case Building:
@ -150,8 +148,8 @@ public enum CombatManager { @@ -150,8 +148,8 @@ public enum CombatManager {
float locZ = target.loc.z - target.getBounds().getHalfExtents().y;
float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2;
float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2;
Rectangle2D.Float rect = new Rectangle2D.Float(locX,locZ,sizeX,sizeZ);
if(rect.contains(new Point2D.Float(attacker.loc.x,attacker.loc.z)))
Rectangle2D.Float rect = new Rectangle2D.Float(locX, locZ, sizeX, sizeZ);
if (rect.contains(new Point2D.Float(attacker.loc.x, attacker.loc.z)))
inRange = true;
break;
}
@ -172,19 +170,19 @@ public enum CombatManager { @@ -172,19 +170,19 @@ public enum CombatManager {
if (wepSpeed < 10)
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))
((Mob)attacker).nextAttackTime = System.currentTimeMillis() + delay;
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
((Mob) attacker).nextAttackTime = System.currentTimeMillis() + delay;
if (inRange) {
//handle retaliate
if(AbstractCharacter.IsAbstractCharacter(target)){
if(((AbstractCharacter)target).combatTarget == null || ((AbstractCharacter)target).combatTarget.isAlive() == false){
((AbstractCharacter)target).combatTarget = attacker;
if(target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat())
if (AbstractCharacter.IsAbstractCharacter(target)) {
if (((AbstractCharacter) target).combatTarget == null || !((AbstractCharacter) target).combatTarget.isAlive()) {
((AbstractCharacter) target).combatTarget = attacker;
if (target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat())
combatCycle((AbstractCharacter) target, attacker);
}
}
@ -204,10 +202,10 @@ public enum CombatManager { @@ -204,10 +202,10 @@ public enum CombatManager {
}
//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)) {
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
setAutoAttackJob(attacker, slot, delay);
return;
}
}
@ -271,7 +269,7 @@ public enum CombatManager { @@ -271,7 +269,7 @@ public enum CombatManager {
DispatchMessage.sendToAllInRange(attacker, msg);
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
setAutoAttackJob(attacker, slot, delay);
return;
}
@ -299,7 +297,7 @@ public enum CombatManager { @@ -299,7 +297,7 @@ public enum CombatManager {
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);
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
@ -308,7 +306,7 @@ public enum CombatManager { @@ -308,7 +306,7 @@ public enum CombatManager {
DispatchMessage.sendToAllInRange(attacker, msg);
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
setAutoAttackJob(attacker, slot, delay);
return;
}
}
@ -317,7 +315,7 @@ public enum CombatManager { @@ -317,7 +315,7 @@ public enum CombatManager {
int damage = ThreadLocalRandom.current().nextInt(min, max + 1);
if (damage == 0) {
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
setAutoAttackJob(attacker, slot, delay);
return;
}
//get the damage type
@ -337,7 +335,7 @@ public enum CombatManager { @@ -337,7 +335,7 @@ public enum CombatManager {
Resists resists;
if (AbstractCharacter.IsAbstractCharacter(target) == false)
if (!AbstractCharacter.IsAbstractCharacter(target))
resists = ((Building) target).getResists(); //this is a building
else
resists = ((AbstractCharacter) target).getResists(); //this is a character
@ -386,7 +384,7 @@ public enum CombatManager { @@ -386,7 +384,7 @@ public enum CombatManager {
if (resists.immuneTo(damageType)) {
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
setAutoAttackJob(attacker, slot, delay);
return;
}
//calculate resisted damage including fortitude
@ -413,7 +411,7 @@ public enum CombatManager { @@ -413,7 +411,7 @@ public enum CombatManager {
}
}
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
setAutoAttackJob(attacker, slot, delay);
}
@ -474,33 +472,33 @@ public enum CombatManager { @@ -474,33 +472,33 @@ public enum CombatManager {
public static int getSwingAnimation(ItemTemplate wb, DeferredPowerJob dpj, boolean mainHand) {
int token = 0;
int token;
if (dpj != null) {
token = (dpj.getPower() != null) ? dpj.getPower().getToken() : 0;
if (token == 563721004) //kick animation
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];
} else {
else
return wb.weapon_attack_anim_left.get(ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_left.size()))[0];
}
}
}
if (wb == null)
return 75;
if(mainHand){
if (mainHand)
return wb.weapon_attack_anim_right.get(0)[0];
} else{
else
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
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay);

Loading…
Cancel
Save