Compare commits
15 Commits
1bbbc396bd
...
combat-2
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f9500a0d7 | |||
| 0d51afb737 | |||
| 60e331de1a | |||
| 4a554b0d61 | |||
| 3f3d85fb36 | |||
| d2d655a839 | |||
| 0096b8051c | |||
| 86102c8933 | |||
| f06e2c2e5c | |||
| 74b425e567 | |||
| 22c8cdcf65 | |||
| 7ed026f088 | |||
| 232c381e96 | |||
| 69ea460d5e | |||
| cbe9a30590 |
@@ -29,6 +29,8 @@ import java.util.EnumSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static java.lang.Math.pow;
|
||||
|
||||
public enum CombatManager {
|
||||
|
||||
|
||||
@@ -42,6 +44,9 @@ public enum CombatManager {
|
||||
//
|
||||
|
||||
COMBAT_MANAGER;
|
||||
public static final int COMBAT_BLOCK_ANIMATION = 298;
|
||||
public static final int COMBAT_PARRY_ANIMATION = 299;
|
||||
public static final int COMBAT_DODGE_ANIMATION = 300;
|
||||
|
||||
public static void combatCycle(AbstractCharacter attacker, AbstractWorldObject target) {
|
||||
|
||||
@@ -118,12 +123,15 @@ public enum CombatManager {
|
||||
if (!attacker.isCombat())
|
||||
return;
|
||||
|
||||
if (attacker.getTimestamps().get("Attack" + slot.name()) != null && attacker.getTimestamps().get("Attack" + slot.name()) < System.currentTimeMillis()) {
|
||||
setAutoAttackJob(attacker, slot, 1000);
|
||||
return;
|
||||
}
|
||||
//check if this slot is on attack timer, if timer has passed clear it, else early exit
|
||||
if(attacker.getTimers().containsKey("Attack"+slot.name()))
|
||||
if(attacker.getTimers().get("Attack"+slot.name()).timeToExecutionLeft() <= 0)
|
||||
attacker.getTimers().remove("Attack"+slot.name());
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check if character is in range to attack target
|
||||
|
||||
PlayerBonuses bonus = attacker.getBonuses();
|
||||
@@ -137,7 +145,7 @@ public enum CombatManager {
|
||||
if (bonus != null)
|
||||
rangeMod += bonus.getFloatPercentAll(mbEnums.ModType.WeaponRange, mbEnums.SourceType.None);
|
||||
|
||||
attackRange = weapon.template.item_weapon_max_range * rangeMod;
|
||||
attackRange += weapon.template.item_weapon_max_range * rangeMod;
|
||||
}
|
||||
|
||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
|
||||
@@ -147,11 +155,17 @@ 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;
|
||||
if (AbstractCharacter.IsAbstractCharacter(target)) {
|
||||
attackRange += ((AbstractCharacter)target).calcHitBox();
|
||||
} else {
|
||||
attackRange += attacker.calcHitBox();
|
||||
|
||||
}
|
||||
|
||||
if(attackRange > 15 && attacker.isMoving()){
|
||||
//cannot shoot bow while moving;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (target.getObjectType()) {
|
||||
case PlayerCharacter:
|
||||
attackRange += ((PlayerCharacter) target).getCharacterHeight() * 0.5f;
|
||||
@@ -216,22 +230,21 @@ public enum CombatManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//check if Out of Stamina
|
||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
||||
if (attacker.getStamina() < (weapon.template.item_wt / 3f)) {
|
||||
//set auto attack job
|
||||
setAutoAttackJob(attacker, slot, delay);
|
||||
return;
|
||||
// take stamina away from attacker if its not a mob
|
||||
if (weapon != null && !attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) {
|
||||
//check if Out of Stamina
|
||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
||||
if (attacker.getStamina() < (weapon.template.item_wt / 3f)) {
|
||||
//set auto attack job
|
||||
setAutoAttackJob(attacker, slot, delay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// take stamina away from attacker
|
||||
if (weapon != null) {
|
||||
float stam = weapon.template.item_wt / 3f;
|
||||
stam = (stam < 1) ? 1 : stam;
|
||||
attacker.modifyStamina(-(stam), attacker, true);
|
||||
} else
|
||||
attacker.modifyStamina(-0.5f, attacker, true);
|
||||
attacker.modifyStamina(1, attacker, true);
|
||||
|
||||
//cancel things that are cancelled by an attack
|
||||
|
||||
@@ -270,16 +283,7 @@ public enum CombatManager {
|
||||
|
||||
if (target.getObjectType() == mbEnums.GameObjectType.Building)
|
||||
hitChance = 100;
|
||||
int passiveAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD));
|
||||
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)){
|
||||
if (weapon != null) {
|
||||
passiveAnim = getSwingAnimation(weapon.template, null, true);
|
||||
}
|
||||
}else {
|
||||
if (attacker.charItemManager.getEquipped().get(slot) != null) {
|
||||
passiveAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, null, true);
|
||||
}
|
||||
}
|
||||
int passiveAnim = getPassiveAnimation(mbEnums.PassiveType.None); // checking for a miss due to ATR vs Def
|
||||
if (ThreadLocalRandom.current().nextInt(100) > hitChance) {
|
||||
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim);
|
||||
|
||||
@@ -288,6 +292,10 @@ public enum CombatManager {
|
||||
else
|
||||
DispatchManager.sendToAllInRange(attacker, msg);
|
||||
|
||||
//we need to send the animation even if the attacker misses
|
||||
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) 0, getSwingAnimation(weapon.template,null,slot));
|
||||
DispatchManager.sendToAllInRange(target, cmm);
|
||||
|
||||
//set auto attack job
|
||||
setAutoAttackJob(attacker, slot, delay);
|
||||
return;
|
||||
@@ -318,12 +326,11 @@ public enum CombatManager {
|
||||
|
||||
|
||||
if (!passiveType.equals(mbEnums.PassiveType.None)) {
|
||||
passiveAnim = getPassiveAnimation(passiveType);
|
||||
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value);
|
||||
|
||||
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
|
||||
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
||||
else
|
||||
DispatchManager.sendToAllInRange(attacker, msg);
|
||||
|
||||
//set auto attack job
|
||||
setAutoAttackJob(attacker, slot, delay);
|
||||
@@ -338,6 +345,9 @@ public enum CombatManager {
|
||||
setAutoAttackJob(attacker, slot, delay);
|
||||
return;
|
||||
}
|
||||
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob) && ((Mob)attacker).isPet())
|
||||
calculatePetDamage(attacker);
|
||||
|
||||
//get the damage type
|
||||
|
||||
mbEnums.DamageType damageType;
|
||||
@@ -422,13 +432,13 @@ public enum CombatManager {
|
||||
else
|
||||
((Building) target).modifyHealth(-damage, attacker);
|
||||
|
||||
int attackAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD));
|
||||
int attackAnim = getSwingAnimation(null, null, slot);
|
||||
if (attacker.charItemManager.getEquipped().get(slot) != null) {
|
||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
||||
DeferredPowerJob weaponPower = ((PlayerCharacter) attacker).getWeaponPower();
|
||||
attackAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, weaponPower, slot.equals(mbEnums.EquipSlotType.RHELD));
|
||||
attackAnim = getSwingAnimation(weapon.template, weaponPower, slot);
|
||||
} else {
|
||||
attackAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, null, slot.equals(mbEnums.EquipSlotType.RHELD));
|
||||
attackAnim = getSwingAnimation(weapon.template, null, slot);
|
||||
}
|
||||
}
|
||||
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim);
|
||||
@@ -510,7 +520,11 @@ public enum CombatManager {
|
||||
target.setCombatTarget(attacker);
|
||||
}
|
||||
|
||||
public static int getSwingAnimation(ItemTemplate wb, DeferredPowerJob dpj, boolean mainHand) {
|
||||
public static int getSwingAnimation(ItemTemplate wb, DeferredPowerJob dpj, mbEnums.EquipSlotType slot) {
|
||||
|
||||
//No weapon, return default animation
|
||||
if (wb == null)
|
||||
return 75;
|
||||
|
||||
int token;
|
||||
|
||||
@@ -520,32 +534,71 @@ public enum CombatManager {
|
||||
|
||||
if (token == 563721004) //kick animation
|
||||
return 79;
|
||||
|
||||
if (wb != null) {
|
||||
if (mainHand) {
|
||||
int random = ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_right.size());
|
||||
int anim = wb.weapon_attack_anim_right.get(random)[0];
|
||||
return anim;
|
||||
} else {
|
||||
int random = ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_left.size());
|
||||
return wb.weapon_attack_anim_left.get(random)[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wb == null)
|
||||
//Item has no equipment slots and should not try to return an animation, return default instead
|
||||
if(wb.item_eq_slots_or == null || wb.item_eq_slots_or.size() == 0){
|
||||
return 75;
|
||||
if(wb.item_skill_used.equals("Bow") || wb.obj_name.equals("Siege Bow"))
|
||||
return wb.weapon_attack_anim_left.get(0)[0];
|
||||
if (mainHand)
|
||||
return wb.weapon_attack_anim_right.get(0)[0];
|
||||
else
|
||||
return wb.weapon_attack_anim_left.get(0)[0];
|
||||
}
|
||||
|
||||
//declare variables
|
||||
int anim;
|
||||
int random;
|
||||
|
||||
//Item can only be equipped in one slot, return animation for that slot
|
||||
if(wb.item_eq_slots_or.size() == 1){
|
||||
if (wb.item_eq_slots_or.iterator().next().equals(mbEnums.EquipSlotType.RHELD)) {
|
||||
anim = wb.weapon_attack_anim_right.get(0)[0];
|
||||
if (dpj != null) {
|
||||
random = ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_right.size());
|
||||
anim = wb.weapon_attack_anim_right.get(random)[0];
|
||||
}
|
||||
}else {
|
||||
anim = wb.weapon_attack_anim_left.get(0)[0];
|
||||
if (dpj != null) {
|
||||
random = ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_left.size());
|
||||
anim = wb.weapon_attack_anim_left.get(random)[0];
|
||||
}
|
||||
}
|
||||
return anim;
|
||||
}
|
||||
|
||||
//Item can be equipped in either hand, and should have animation sets for each hand
|
||||
if (slot.equals(mbEnums.EquipSlotType.RHELD)) {
|
||||
anim = wb.weapon_attack_anim_right.get(0)[0];
|
||||
if (dpj != null) {
|
||||
random = ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_right.size());
|
||||
anim = wb.weapon_attack_anim_right.get(random)[0];
|
||||
}
|
||||
}else {
|
||||
anim = wb.weapon_attack_anim_left.get(0)[0];
|
||||
if (dpj != null) {
|
||||
random = ThreadLocalRandom.current().nextInt(wb.weapon_attack_anim_left.size());
|
||||
anim = wb.weapon_attack_anim_left.get(random)[0];
|
||||
}
|
||||
}
|
||||
return anim;
|
||||
}
|
||||
|
||||
public static int getPassiveAnimation(mbEnums.PassiveType passiveType){
|
||||
switch(passiveType){
|
||||
case Block:
|
||||
return COMBAT_BLOCK_ANIMATION;
|
||||
case Parry:
|
||||
return COMBAT_PARRY_ANIMATION;
|
||||
case Dodge:
|
||||
return COMBAT_DODGE_ANIMATION;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAutoAttackJob(AbstractCharacter attacker, mbEnums.EquipSlotType slot, long delay) {
|
||||
//calculate next allowed attack and update the timestamp
|
||||
|
||||
if(attacker.getTimestamps().containsKey("Attack" + slot.name()) && attacker.getTimestamps().get("Attack" + slot.name()) > System.currentTimeMillis())
|
||||
return;
|
||||
|
||||
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay);
|
||||
|
||||
//handle auto attack job creation
|
||||
@@ -555,9 +608,37 @@ public enum CombatManager {
|
||||
AttackJob aj = new AttackJob(attacker, slot.ordinal(), true);
|
||||
JobContainer job;
|
||||
job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue
|
||||
timers.put("Attack" + slot, job);
|
||||
timers.put("Attack" + slot.name(), job);
|
||||
} else
|
||||
Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID());
|
||||
|
||||
}
|
||||
public static int calculatePetDamage(AbstractCharacter agent) {
|
||||
//damage calc for pet
|
||||
float range;
|
||||
float damage;
|
||||
float min = 40;
|
||||
float max = 60;
|
||||
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(mbEnums.ModType.MeleeDamageModifier, mbEnums.SourceType.None);
|
||||
double minDmg = getMinDmg(min, agent);
|
||||
double maxDmg = getMaxDmg(max, agent);
|
||||
dmgMultiplier += agent.getLevel() * 0.1f;
|
||||
range = (float) (maxDmg - minDmg);
|
||||
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
|
||||
return (int) (damage * dmgMultiplier);
|
||||
}
|
||||
public static double getMinDmg(double min, AbstractCharacter agent) {
|
||||
int primary = agent.getStatStrCurrent();
|
||||
int secondary = agent.getStatDexCurrent();
|
||||
int focusLevel = 0;
|
||||
int masteryLevel = 0;
|
||||
return min * (pow(0.0048 * primary + .049 * (primary - 0.75), 0.5) + pow(0.0066 * secondary + 0.064 * (secondary - 0.75), 0.5) + +0.01 * (focusLevel + masteryLevel));
|
||||
}
|
||||
public static double getMaxDmg(double max, AbstractCharacter agent) {
|
||||
int primary = agent.getStatStrCurrent();
|
||||
int secondary = agent.getStatDexCurrent();
|
||||
int focusLevel = 0;
|
||||
int masteryLevel = 0;
|
||||
return max * (pow(0.0124 * primary + 0.118 * (primary - 0.75), 0.5) + pow(0.0022 * secondary + 0.028 * (secondary - 0.75), 0.5) + 0.0075 * (focusLevel + masteryLevel));
|
||||
}
|
||||
}
|
||||
@@ -525,6 +525,9 @@ public enum NPCManager {
|
||||
|
||||
ConcurrentHashMap.KeySetView<WorkOrder, Boolean> vendorWorkOrders = ForgeManager.vendorWorkOrderLookup.get(npc);
|
||||
|
||||
if (vendorWorkOrders == null)
|
||||
return itemList;
|
||||
|
||||
for (WorkOrder workOrder : vendorWorkOrders)
|
||||
itemList.addAll(workOrder.cooking);
|
||||
|
||||
|
||||
@@ -177,10 +177,10 @@ public enum PowersManager {
|
||||
PlayerCharacter caster = origin.getPlayerCharacter();
|
||||
PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID());
|
||||
if (pb != null && pb.isHarmful == false) {
|
||||
if (caster.guild.equals(Guild.getErrantGuild()))
|
||||
return;
|
||||
//if (caster.guild.equals(Guild.getErrantGuild()))
|
||||
// return;
|
||||
|
||||
if (target != null && caster.guild.getGuildType().equals(target.guild.getGuildType()) == false)
|
||||
if (target != null && caster.guild.getGuildType().equals(target.guild.getGuildType()) == false && target.getObjectType().equals(GameObjectType.Building) == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,12 +67,6 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
|
||||
return true; // cannot attack a null target
|
||||
}
|
||||
|
||||
// No point in setting combat target to someone you are already fighting
|
||||
|
||||
if (playerCharacter.isCombat() && playerCharacter.getCombatTarget() != null &&
|
||||
playerCharacter.getCombatTarget().equals(target))
|
||||
return true;
|
||||
|
||||
//set sources target
|
||||
|
||||
playerCharacter.setCombatTarget(target);
|
||||
|
||||
@@ -46,9 +46,6 @@ public class PetAttackMsgHandler extends AbstractClientMsgHandler {
|
||||
if (!pet.isAlive())
|
||||
return true;
|
||||
|
||||
if (pet.getCombatTarget() == null)
|
||||
return true;
|
||||
|
||||
if ((playerCharacter.inSafeZone())
|
||||
&& (msg.getTargetType() == mbEnums.GameObjectType.PlayerCharacter.ordinal()))
|
||||
return true;
|
||||
|
||||
@@ -53,16 +53,16 @@ public class OpenGatePowerAction extends AbstractPowerAction {
|
||||
if (source == null || awo == null || !(awo.getObjectType().equals(mbEnums.GameObjectType.Building)) || pb == null)
|
||||
return;
|
||||
|
||||
// Make sure building has a blueprint
|
||||
|
||||
if (targetBuilding.getBlueprintUUID() == 0)
|
||||
// Make sure target building is a runegate
|
||||
if(targetBuilding.meshUUID != 24500) // runegate
|
||||
return;
|
||||
|
||||
// Make sure building is actually a runegate.
|
||||
|
||||
if (targetBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.RUNEGATE)
|
||||
return;
|
||||
// Which runegate was clicked on?
|
||||
Runegate runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID());
|
||||
|
||||
if(runeGate == null){
|
||||
return; // mob camp prop runegate cannot be opened
|
||||
}
|
||||
// Which portal was opened?
|
||||
|
||||
token = pb.getToken();
|
||||
@@ -104,9 +104,7 @@ public class OpenGatePowerAction extends AbstractPowerAction {
|
||||
default:
|
||||
}
|
||||
|
||||
// Which runegate was clicked on?
|
||||
|
||||
Runegate runeGate = Runegate._runegates.get(targetBuilding.getObjectUUID());
|
||||
runeGate.activatePortal(portalType);
|
||||
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ public class MBServerStatics {
|
||||
public static final float COMBATRUNSPEED = 14.67f;
|
||||
public static final float RUNSPEED_MOB = 15.4f;
|
||||
public static final float MOVEMENT_DESYNC_TOLERANCE = 2f; // Distance out of
|
||||
public static final float NO_WEAPON_RANGE = 8f; // Range for attack with no
|
||||
public static final float NO_WEAPON_RANGE = 4f; // Range for attack with no
|
||||
public static final float REGEN_IDLE = .06f;
|
||||
/*
|
||||
* Base regen rates. Do NOT modify these. They must match the client %per
|
||||
|
||||
Reference in New Issue
Block a user