Equipment slot refactor started.

This commit is contained in:
2024-03-08 12:19:57 -05:00
parent 7d1d8891ff
commit d8d017669a
15 changed files with 163 additions and 443 deletions
+21 -20
View File
@@ -9,7 +9,6 @@
package engine.gameManager;
import engine.Enum.*;
import engine.exception.MsgSendException;
import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.AttackJob;
@@ -46,8 +45,8 @@ public enum CombatManager {
//check my weapon can I do an offhand attack
Item weaponOff = playerCharacter.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_OFFHAND);
Item weaponMain = playerCharacter.getCharItemManager().getEquipped().get(MBServerStatics.SLOT_MAINHAND);
Item weaponOff = playerCharacter.getCharItemManager().getEquipped().get(EquipSlotType.LHELD);
Item weaponMain = playerCharacter.getCharItemManager().getEquipped().get(EquipSlotType.RHELD);
// if you carry something in the offhand thats a weapon you get to swing it
@@ -63,12 +62,12 @@ public enum CombatManager {
//we always swing our mainhand if we are not on timer
JobContainer main = playerCharacter.getTimers().get("Attack" + MBServerStatics.SLOT_MAINHAND);
JobContainer main = playerCharacter.getTimers().get("Attack" + EquipSlotType.RHELD.ordinal());
// no timers on the mainhand, lets submit a job to swing
if (main == null)
CombatManager.createTimer(playerCharacter, MBServerStatics.SLOT_MAINHAND, 1, true); // attack in 0.1 of a second
CombatManager.createTimer(playerCharacter, EquipSlotType.RHELD.ordinal(), 1, true); // attack in 0.1 of a second
/*
only swing offhand if we have a weapon in it or are unarmed in both hands
@@ -77,14 +76,14 @@ public enum CombatManager {
if (swingOffhand) {
JobContainer off = playerCharacter.getTimers().get("Attack" + MBServerStatics.SLOT_OFFHAND);
JobContainer off = playerCharacter.getTimers().get("Attack" + EquipSlotType.LHELD.ordinal());
if (off == null)
CombatManager.createTimer(playerCharacter, MBServerStatics.SLOT_OFFHAND, 1, true); // attack in 0.1 of a second
CombatManager.createTimer(playerCharacter, EquipSlotType.LHELD.ordinal(), 1, true); // attack in 0.1 of a second
}
}
public static void setAttackTarget(PetAttackMsg msg, ClientConnection origin) throws MsgSendException {
public static void setAttackTarget(PetAttackMsg msg, ClientConnection origin) {
PlayerCharacter player;
Mob pet;
@@ -150,18 +149,18 @@ public enum CombatManager {
if (ac == null)
return;
main = ac.getTimers().get("Attack" + MBServerStatics.SLOT_MAINHAND);
off = ac.getTimers().get("Attack" + MBServerStatics.SLOT_OFFHAND);
main = ac.getTimers().get("Attack" + EquipSlotType.RHELD.ordinal());
off = ac.getTimers().get("Attack" + EquipSlotType.LHELD.ordinal());
if (main != null)
JobScheduler.getInstance().cancelScheduledJob(main);
ac.getTimers().remove("Attack" + MBServerStatics.SLOT_MAINHAND);
ac.getTimers().remove("Attack" + EquipSlotType.RHELD.ordinal());
if (off != null)
JobScheduler.getInstance().cancelScheduledJob(off);
ac.getTimers().remove("Attack" + MBServerStatics.SLOT_OFFHAND);
ac.getTimers().remove("Attack" + EquipSlotType.LHELD.ordinal());
ac.setCombatTarget(null);
@@ -220,6 +219,8 @@ public enum CombatManager {
*/
private static int attemptCombat(AbstractCharacter abstractCharacter, int slot) {
EquipSlotType weaponSlot = EquipSlotType.RHELD.values()[slot];
if (abstractCharacter == null)
return 0;
@@ -294,7 +295,7 @@ public enum CombatManager {
if (((PlayerCharacter) abstractCharacter).inSafeZone() || ((PlayerCharacter) target).inSafeZone())
return 0;
if (!(slot == MBServerStatics.SLOT_MAINHAND || slot == MBServerStatics.SLOT_OFFHAND))
if (!(weaponSlot == EquipSlotType.RHELD || weaponSlot == EquipSlotType.LHELD))
return 0;
if (abstractCharacter.getCharItemManager() == null)
@@ -302,7 +303,7 @@ public enum CombatManager {
//get equippment
ConcurrentHashMap<Integer, Item> equipped = abstractCharacter.getCharItemManager().getEquipped();
ConcurrentHashMap<EquipSlotType, Item> equipped = abstractCharacter.getCharItemManager().getEquipped();
boolean hasNoWeapon = false;
if (equipped == null)
@@ -328,11 +329,11 @@ public enum CombatManager {
//no weapon, see if other hand has a weapon
if (!isWeapon)
if (slot == MBServerStatics.SLOT_MAINHAND) {
if (weaponSlot == EquipSlotType.RHELD) {
//make sure offhand has weapon, not shield
Item weaponOff = equipped.get(MBServerStatics.SLOT_OFFHAND);
Item weaponOff = equipped.get(EquipSlotType.RHELD);
if (weaponOff != null) {
ItemBase ib = weaponOff.getItemBase();
@@ -345,7 +346,7 @@ public enum CombatManager {
} else
hasNoWeapon = true;
} else if (equipped.get(MBServerStatics.SLOT_MAINHAND) == null)
} else if (equipped.get(EquipSlotType.RHELD) == null)
return 1; //no need to attack with this hand
//Source can attack.
@@ -406,7 +407,7 @@ public enum CombatManager {
Mob mob = (Mob) abstractCharacter;
if (mob.isPet()) {
attack(abstractCharacter, target, weapon, wb, slot == MBServerStatics.SLOT_MAINHAND);
attack(abstractCharacter, target, weapon, wb, slot == EquipSlotType.RHELD.ordinal());
return 2;
}
}
@@ -432,7 +433,7 @@ public enum CombatManager {
createTimer(abstractCharacter, slot, wepSpeed, true);
}
attack(abstractCharacter, target, weapon, wb, slot == MBServerStatics.SLOT_MAINHAND);
attack(abstractCharacter, target, weapon, wb, slot == EquipSlotType.RHELD.ordinal());
} else
createTimer(abstractCharacter, slot, 5, false); // changed this to half a second to make combat attempts more aggressive than movement sync
@@ -1200,7 +1201,7 @@ public enum CombatManager {
pc.setLastTarget(attacker.getObjectType(), attacker.getObjectUUID());
if (target.getTimers() != null)
if (!target.getTimers().containsKey("Attack" + MBServerStatics.SLOT_MAINHAND))
if (!target.getTimers().containsKey("Attack" + EquipSlotType.RHELD.ordinal()))
CombatManager.AttackTarget((PlayerCharacter) target, target.getCombatTarget());
}