Compare commits
5 Commits
d2d655a839
...
combat-2
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f9500a0d7 | |||
| 0d51afb737 | |||
| 60e331de1a | |||
| 4a554b0d61 | |||
| 3f3d85fb36 |
@@ -29,6 +29,8 @@ import java.util.EnumSet;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
import static java.lang.Math.pow;
|
||||||
|
|
||||||
public enum CombatManager {
|
public enum CombatManager {
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +44,9 @@ public enum CombatManager {
|
|||||||
//
|
//
|
||||||
|
|
||||||
COMBAT_MANAGER;
|
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) {
|
public static void combatCycle(AbstractCharacter attacker, AbstractWorldObject target) {
|
||||||
|
|
||||||
@@ -225,8 +230,8 @@ public enum CombatManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// take stamina away from attacker
|
// take stamina away from attacker if its not a mob
|
||||||
if (weapon != null) {
|
if (weapon != null && !attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) {
|
||||||
//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)) {
|
||||||
@@ -278,23 +283,18 @@ public enum CombatManager {
|
|||||||
|
|
||||||
if (target.getObjectType() == mbEnums.GameObjectType.Building)
|
if (target.getObjectType() == mbEnums.GameObjectType.Building)
|
||||||
hitChance = 100;
|
hitChance = 100;
|
||||||
int passiveAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD));
|
int passiveAnim = getPassiveAnimation(mbEnums.PassiveType.None); // checking for a miss due to ATR vs Def
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ThreadLocalRandom.current().nextInt(100) > hitChance) {
|
if (ThreadLocalRandom.current().nextInt(100) > hitChance) {
|
||||||
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim);
|
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim);
|
||||||
|
|
||||||
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
|
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
|
||||||
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
||||||
//else
|
else
|
||||||
// DispatchManager.sendToAllInRange(attacker, msg);
|
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
|
//set auto attack job
|
||||||
setAutoAttackJob(attacker, slot, delay);
|
setAutoAttackJob(attacker, slot, delay);
|
||||||
@@ -326,12 +326,11 @@ public enum CombatManager {
|
|||||||
|
|
||||||
|
|
||||||
if (!passiveType.equals(mbEnums.PassiveType.None)) {
|
if (!passiveType.equals(mbEnums.PassiveType.None)) {
|
||||||
|
passiveAnim = getPassiveAnimation(passiveType);
|
||||||
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)
|
||||||
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
||||||
else
|
|
||||||
DispatchManager.sendToAllInRange(attacker, msg);
|
|
||||||
|
|
||||||
//set auto attack job
|
//set auto attack job
|
||||||
setAutoAttackJob(attacker, slot, delay);
|
setAutoAttackJob(attacker, slot, delay);
|
||||||
@@ -346,6 +345,9 @@ public enum CombatManager {
|
|||||||
setAutoAttackJob(attacker, slot, delay);
|
setAutoAttackJob(attacker, slot, delay);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob) && ((Mob)attacker).isPet())
|
||||||
|
calculatePetDamage(attacker);
|
||||||
|
|
||||||
//get the damage type
|
//get the damage type
|
||||||
|
|
||||||
mbEnums.DamageType damageType;
|
mbEnums.DamageType damageType;
|
||||||
@@ -430,13 +432,13 @@ public enum CombatManager {
|
|||||||
else
|
else
|
||||||
((Building) target).modifyHealth(-damage, attacker);
|
((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.charItemManager.getEquipped().get(slot) != null) {
|
||||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
||||||
DeferredPowerJob weaponPower = ((PlayerCharacter) attacker).getWeaponPower();
|
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 {
|
} 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);
|
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim);
|
||||||
@@ -518,7 +520,11 @@ public enum CombatManager {
|
|||||||
target.setCombatTarget(attacker);
|
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;
|
int token;
|
||||||
|
|
||||||
@@ -528,28 +534,63 @@ public enum CombatManager {
|
|||||||
|
|
||||||
if (token == 563721004) //kick animation
|
if (token == 563721004) //kick animation
|
||||||
return 79;
|
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;
|
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) {
|
public static void setAutoAttackJob(AbstractCharacter attacker, mbEnums.EquipSlotType slot, long delay) {
|
||||||
@@ -572,4 +613,32 @@ public enum CombatManager {
|
|||||||
Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID());
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user