Added finaldamage calculation to API.
This commit is contained in:
parent
1de22e0664
commit
ecbe7f9d2b
Binary file not shown.
@ -58,16 +58,28 @@ public class NewCombat {
|
|||||||
* Returns the amount of damage dealt to target.
|
* Returns the amount of damage dealt to target.
|
||||||
*/
|
*/
|
||||||
public static double applyDamage(LivingEntity target, Entity damager) {
|
public static double applyDamage(LivingEntity target, Entity damager) {
|
||||||
|
return applyDamage(0,target,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double applyDamage(double basedmg, LivingEntity target, Entity damager) {
|
||||||
|
return applyDamage(basedmg, target,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double applyDamage(double basedmg, LivingEntity target, Entity damager, boolean isCriticalStrike) {
|
||||||
|
return applyDamage(basedmg, target,damager,false,"Attack Base Damage");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double applyDamage(double basedmg, LivingEntity target, Entity damager, boolean isCriticalStrike, String reason) {
|
||||||
switch (DamageType.DetectType(target, damager)) {
|
switch (DamageType.DetectType(target, damager)) {
|
||||||
case MOBVSMOB:
|
case MOBVSMOB:
|
||||||
case MOBPROJECTILEVSMOB:
|
case MOBPROJECTILEVSMOB:
|
||||||
case MOBPROJECTILEVSPLAYER:
|
case MOBPROJECTILEVSPLAYER:
|
||||||
case MOBVSPLAYER: {
|
case MOBVSPLAYER: {
|
||||||
return calculateMobDamage(target, damager);
|
return calculateMobDamage(basedmg, target, damager, isCriticalStrike);
|
||||||
}
|
}
|
||||||
case PLAYERPROJECTILEVSMOB:
|
case PLAYERPROJECTILEVSMOB:
|
||||||
case PLAYERVSMOB: {
|
case PLAYERVSMOB: {
|
||||||
return calculatePlayerDamage(target, damager);
|
return calculatePlayerDamage(basedmg, target, damager, isCriticalStrike, reason);
|
||||||
}
|
}
|
||||||
case OTHER:
|
case OTHER:
|
||||||
default: {
|
default: {
|
||||||
@ -85,13 +97,25 @@ public class NewCombat {
|
|||||||
}
|
}
|
||||||
ev.setDamage(0);
|
ev.setDamage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double calculatePlayerDamage(LivingEntity target, Entity damager) {
|
public static double calculatePlayerDamage(LivingEntity target, Entity damager) {
|
||||||
|
return calculatePlayerDamage(0,target,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double calculatePlayerDamage(double basedmg,LivingEntity target, Entity damager) {
|
||||||
|
return calculatePlayerDamage(basedmg,target,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double calculatePlayerDamage(double basedmg,LivingEntity target, Entity damager, boolean isCriticalStrike) {
|
||||||
|
return calculatePlayerDamage(basedmg,target,damager,isCriticalStrike,"Attack Base Damage");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double calculatePlayerDamage(double basedmg,LivingEntity target, Entity damager, boolean isCriticalStrike, String reason) {
|
||||||
LivingEntity shooter = getDamagerEntity(damager);
|
LivingEntity shooter = getDamagerEntity(damager);
|
||||||
|
|
||||||
double finaldmg = 0.0;
|
double finaldmg = 0.0;
|
||||||
if (shooter!=null) {
|
if (shooter!=null) {
|
||||||
finaldmg += calculateTotalDamage(target, damager);
|
finaldmg += calculateTotalDamage(basedmg, target, damager, isCriticalStrike, reason);
|
||||||
if (shooter instanceof Player) {
|
if (shooter instanceof Player) {
|
||||||
Player p = (Player)shooter;
|
Player p = (Player)shooter;
|
||||||
playerPerformMiscActions(p,target);
|
playerPerformMiscActions(p,target);
|
||||||
@ -113,6 +137,14 @@ public class NewCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double calculateMobDamage(LivingEntity target, Entity damager) {
|
public static double calculateMobDamage(LivingEntity target, Entity damager) {
|
||||||
|
return calculateMobDamage(0,target,damager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double calculateMobDamage(double basedmg, LivingEntity target, Entity damager) {
|
||||||
|
return calculateMobDamage(basedmg,target,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double calculateMobDamage(double basedmg, LivingEntity target, Entity damager, boolean isCriticalStrike) {
|
||||||
double totaldmg = 0.0;
|
double totaldmg = 0.0;
|
||||||
double bonusmult = 1.0;
|
double bonusmult = 1.0;
|
||||||
|
|
||||||
@ -120,8 +152,9 @@ public class NewCombat {
|
|||||||
|
|
||||||
if (shooter!=null) {
|
if (shooter!=null) {
|
||||||
totaldmg += calculateMobBaseDamage((LivingEntity)shooter, target);
|
totaldmg += calculateMobBaseDamage((LivingEntity)shooter, target);
|
||||||
totaldmg += CalculateWeaponDamage(shooter, target);
|
totaldmg += CalculateWeaponDamage(basedmg, shooter, target);
|
||||||
//bonusmult *= calculateMonsterDifficultyMultiplier(shooter);
|
//bonusmult *= calculateMonsterDifficultyMultiplier(shooter);
|
||||||
|
bonusmult *= (isCriticalStrike)?2.0:1.0;
|
||||||
} else {
|
} else {
|
||||||
totaldmg = 1.0;
|
totaldmg = 1.0;
|
||||||
}
|
}
|
||||||
@ -136,6 +169,18 @@ public class NewCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static double calculateTotalDamage(LivingEntity target, Entity damager) {
|
static double calculateTotalDamage(LivingEntity target, Entity damager) {
|
||||||
|
return calculateTotalDamage(0, target,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double calculateTotalDamage(double basedmg, LivingEntity target, Entity damager) {
|
||||||
|
return calculateTotalDamage(basedmg, target,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double calculateTotalDamage(double basedmg, LivingEntity target, Entity damager, boolean isCriticalStrike) {
|
||||||
|
return calculateTotalDamage(basedmg,target,damager,isCriticalStrike,"Attack Base Damage");
|
||||||
|
}
|
||||||
|
|
||||||
|
static double calculateTotalDamage(double basedmg, LivingEntity target, Entity damager, boolean isCriticalStrike, String reason) {
|
||||||
double totaldmg = 0.0; //Final damage dealt. It will be multiplied by mult at the end.
|
double totaldmg = 0.0; //Final damage dealt. It will be multiplied by mult at the end.
|
||||||
double bonusmult = 1.0; //Bonus multiplier for damage dealt.
|
double bonusmult = 1.0; //Bonus multiplier for damage dealt.
|
||||||
double armorpendmg = 0.0;
|
double armorpendmg = 0.0;
|
||||||
@ -147,8 +192,8 @@ public class NewCombat {
|
|||||||
Player p = (Player)shooter;
|
Player p = (Player)shooter;
|
||||||
ItemStack weapon = p.getEquipment().getItemInMainHand();
|
ItemStack weapon = p.getEquipment().getItemInMainHand();
|
||||||
|
|
||||||
totaldmg+=CalculateWeaponDamage(damager, target);
|
totaldmg+=CalculateWeaponDamage(basedmg, damager, target, false, reason);
|
||||||
double mult1 = calculatePlayerCriticalStrike(weapon,damager);
|
double mult1 = calculatePlayerCriticalStrike(weapon,damager,isCriticalStrike);
|
||||||
addMultiplierToPlayerLogger(damager,"Critical Strike Mult",mult1);
|
addMultiplierToPlayerLogger(damager,"Critical Strike Mult",mult1);
|
||||||
if (mult1>1.0) {
|
if (mult1>1.0) {
|
||||||
aPlugin.API.critEntity(target, 15);
|
aPlugin.API.critEntity(target, 15);
|
||||||
@ -487,10 +532,22 @@ public class NewCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double CalculateWeaponDamage(Entity damager, LivingEntity target) {
|
public static double CalculateWeaponDamage(Entity damager, LivingEntity target) {
|
||||||
return CalculateWeaponDamage(damager,target,false);
|
return CalculateWeaponDamage(0,damager,target,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double CalculateWeaponDamage(Entity damager, LivingEntity target, boolean useBow) {
|
public static double CalculateWeaponDamage(Entity damager, LivingEntity target,boolean useBow) {
|
||||||
|
return CalculateWeaponDamage(0,damager,target,useBow,"Attack Base Damage");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double CalculateWeaponDamage(double basedmg, Entity damager, LivingEntity target) {
|
||||||
|
return CalculateWeaponDamage(basedmg, damager,target,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double CalculateWeaponDamage(double basedmg, Entity damager, LivingEntity target, boolean useBow) {
|
||||||
|
return CalculateWeaponDamage(basedmg, damager,target,false,"Attack Base Damage");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double CalculateWeaponDamage(double suppliedDmg, Entity damager, LivingEntity target, boolean useBow, String reason) {
|
||||||
|
|
||||||
double basedmg = 0.0;
|
double basedmg = 0.0;
|
||||||
double basemult = 1.0;
|
double basemult = 1.0;
|
||||||
@ -503,14 +560,19 @@ public class NewCombat {
|
|||||||
LivingEntity ent = shooter;
|
LivingEntity ent = shooter;
|
||||||
ItemStack weapon = ent.getEquipment().getItemInMainHand();
|
ItemStack weapon = ent.getEquipment().getItemInMainHand();
|
||||||
|
|
||||||
if (GenericFunctions.isArtifactEquip(weapon)) {
|
if (suppliedDmg!=0) {
|
||||||
double dmg = getBaseArtifactDamageByType(weapon);
|
basedmg += suppliedDmg;
|
||||||
addToPlayerLogger(ent,"Weapon Base Damage",dmg);
|
addToPlayerLogger(ent,reason,basedmg);
|
||||||
basedmg += dmg;
|
|
||||||
} else {
|
} else {
|
||||||
double dmg = getBaseDamageByType(weapon);
|
if (GenericFunctions.isArtifactEquip(weapon)) {
|
||||||
addToPlayerLogger(ent,"Weapon Base Damage",dmg);
|
double dmg = getBaseArtifactDamageByType(weapon);
|
||||||
basedmg += dmg;
|
addToPlayerLogger(ent,"Weapon Base Damage",dmg);
|
||||||
|
basedmg += dmg;
|
||||||
|
} else {
|
||||||
|
double dmg = getBaseDamageByType(weapon);
|
||||||
|
addToPlayerLogger(ent,"Weapon Base Damage",dmg);
|
||||||
|
basedmg += dmg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0;i<GenericFunctions.getEquipment(shooter).length;i++) {
|
for (int i=0;i<GenericFunctions.getEquipment(shooter).length;i++) {
|
||||||
@ -600,7 +662,11 @@ public class NewCombat {
|
|||||||
setPlayerTarget(damager,target,headshot,preemptive);
|
setPlayerTarget(damager,target,headshot,preemptive);
|
||||||
|
|
||||||
if (shooter instanceof Monster) {
|
if (shooter instanceof Monster) {
|
||||||
basedmg = 1.0 *calculateMonsterDifficultyMultiplier(shooter);
|
if (suppliedDmg!=0) {
|
||||||
|
basedmg = suppliedDmg;
|
||||||
|
} else {
|
||||||
|
basedmg = 1.0 *calculateMonsterDifficultyMultiplier(shooter);
|
||||||
|
}
|
||||||
TwosideKeeper.log("New Base damage is "+basedmg, 4);
|
TwosideKeeper.log("New Base damage is "+basedmg, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -857,17 +923,20 @@ public class NewCombat {
|
|||||||
mult*=mult1;
|
mult*=mult1;
|
||||||
return mult;
|
return mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double calculatePlayerCriticalStrike(ItemStack weapon, Entity damager) {
|
static double calculatePlayerCriticalStrike(ItemStack weapon, Entity damager) {
|
||||||
|
return calculatePlayerCriticalStrike(weapon,damager,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double calculatePlayerCriticalStrike(ItemStack weapon, Entity damager, boolean isCriticalStrike) {
|
||||||
boolean criticalstrike=false;
|
boolean criticalstrike=false;
|
||||||
double critchance = 0.0;
|
double critchance = 0.0;
|
||||||
critchance += calculateCriticalStrikeChance(weapon, damager);
|
critchance += calculateCriticalStrikeChance(weapon, damager);
|
||||||
TwosideKeeper.log("Crit Strike chance is "+critchance,4);
|
TwosideKeeper.log("Crit Strike chance is "+critchance,4);
|
||||||
criticalstrike = isCriticalStrike(critchance);
|
criticalstrike = isCriticalStrike(critchance,isCriticalStrike);
|
||||||
if (damager instanceof Player && criticalstrike) {
|
if (damager instanceof Player && criticalstrike) {
|
||||||
Player p = (Player)damager;
|
Player p = (Player)damager;
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f);
|
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f);
|
||||||
|
|
||||||
}
|
}
|
||||||
return criticalstrike?(calculateCriticalStrikeMultiplier(weapon)):1.0;
|
return criticalstrike?(calculateCriticalStrikeMultiplier(weapon)):1.0;
|
||||||
}
|
}
|
||||||
@ -889,7 +958,11 @@ public class NewCombat {
|
|||||||
|
|
||||||
//Chance is between 0.0-1.0. 1.0 is 100%.
|
//Chance is between 0.0-1.0. 1.0 is 100%.
|
||||||
static boolean isCriticalStrike(double chance) {
|
static boolean isCriticalStrike(double chance) {
|
||||||
return (Math.random()<=chance);
|
return isCriticalStrike(chance,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isCriticalStrike(double chance, boolean isCriticalStrike) {
|
||||||
|
return (Math.random()<=chance || isCriticalStrike);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double calculateCriticalStrikeMultiplier(ItemStack weapon) {
|
static double calculateCriticalStrikeMultiplier(ItemStack weapon) {
|
||||||
|
@ -57,7 +57,7 @@ public class PartyManager {
|
|||||||
Player p = partymembers.get(i);
|
Player p = partymembers.get(i);
|
||||||
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
|
PlayerStructure pd = PlayerStructure.GetPlayerStructure(p);
|
||||||
pd.partybonus = (partymembers.size()>=2)?partymembers.size()-1:0;
|
pd.partybonus = (partymembers.size()>=2)?partymembers.size()-1:0;
|
||||||
TwosideKeeper.log("Party bonus is "+pd.partybonus, 2);
|
TwosideKeeper.log("Party bonus is "+pd.partybonus, 5);
|
||||||
TwosideKeeper.log("Adding Player "+p.getName()+" to Scoreboard..", 5);
|
TwosideKeeper.log("Adding Player "+p.getName()+" to Scoreboard..", 5);
|
||||||
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard players set "+p.getName().toLowerCase()+" Party"+party+" "+((i+1)*-1));
|
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard players set "+p.getName().toLowerCase()+" Party"+party+" "+((i+1)*-1));
|
||||||
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams option "+p.getName().toLowerCase()+" color "+color);
|
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams option "+p.getName().toLowerCase()+" color "+color);
|
||||||
|
@ -209,6 +209,9 @@ public class RecyclingCenter {
|
|||||||
if (itemmap.containsKey(m)) {
|
if (itemmap.containsKey(m)) {
|
||||||
int amt = itemmap.get(m);
|
int amt = itemmap.get(m);
|
||||||
double chance = (amt/(double)totalitems*100d);
|
double chance = (amt/(double)totalitems*100d);
|
||||||
|
if (totalitems<200) {
|
||||||
|
chance=1.00;
|
||||||
|
}
|
||||||
if (totalitems>0 && chance>=TwosideKeeper.COMMONITEMPCT) {
|
if (totalitems>0 && chance>=TwosideKeeper.COMMONITEMPCT) {
|
||||||
DecimalFormat df = new DecimalFormat("0.00");
|
DecimalFormat df = new DecimalFormat("0.00");
|
||||||
TwosideKeeper.log(df.format(chance)+"% of items in nodes are "+GenericFunctions.UserFriendlyMaterialName(m)+". Common item detected...", 3);
|
TwosideKeeper.log(df.format(chance)+"% of items in nodes are "+GenericFunctions.UserFriendlyMaterialName(m)+". Common item detected...", 3);
|
||||||
|
@ -2060,6 +2060,9 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
},1);
|
},1);
|
||||||
}
|
}
|
||||||
|
/*if (ev.getRightClicked() instanceof Monster) {
|
||||||
|
TwosideKeeperAPI.DealDamageToEntity(TwosideKeeperAPI.getFinalDamage(500.0, ev.getPlayer(), (Monster)ev.getRightClicked(), true, "ROFL"), (Monster)ev.getRightClicked(), ev.getPlayer());
|
||||||
|
}*/
|
||||||
///if (ev.getHand()==EquipmentSlot.OFF_HAND) {aPlugin.API.swingOffHand(ev.getPlayer());};
|
///if (ev.getHand()==EquipmentSlot.OFF_HAND) {aPlugin.API.swingOffHand(ev.getPlayer());};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +169,32 @@ public final class TwosideKeeperAPI {
|
|||||||
public static void DealDamageToEntity(double dmg, LivingEntity target, Entity damager, String reason) {
|
public static void DealDamageToEntity(double dmg, LivingEntity target, Entity damager, String reason) {
|
||||||
GenericFunctions.DealDamageToMob(dmg, target, damager, null, reason);
|
GenericFunctions.DealDamageToMob(dmg, target, damager, null, reason);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Gets the final calculated damage with all offensive and defensive multipliers applied. This is a comprehensive
|
||||||
|
* damage calculation with the entire game's formula packed in.
|
||||||
|
* @param dmg The amount of base damage to provide. Using 0 uses the weapon the damager is carrying as the source damage.
|
||||||
|
* @param damager The damager entity. This can include projectiles with a valid shooter, which is later identified as the damager.
|
||||||
|
* @param target The targeted entity. This is the entity that all defensive calculations and on-hit effects will be applied to.
|
||||||
|
* @param isCriticalStrike Whether or not this is a forced critical strike.
|
||||||
|
* @return Returns the final calculated damage with all modifications applied, using the base damage, if provided. Unlike the
|
||||||
|
* version of this method with the "reason" argument, it will use a generic "Attack Base Damage" reason.
|
||||||
|
*/
|
||||||
|
public static double getFinalDamage(double dmg, Entity damager, LivingEntity target, boolean isCriticalStrike) {
|
||||||
|
return NewCombat.applyDamage(dmg, target, damager, isCriticalStrike);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Gets the final calculated damage with all offensive and defensive multipliers applied. This is a comprehensive
|
||||||
|
* damage calculation with the entire game's formula packed in.
|
||||||
|
* @param dmg The amount of base damage to provide. Using 0 uses the weapon the damager is carrying as the source damage.
|
||||||
|
* @param damager The damager entity. This can include projectiles with a valid shooter, which is later identified as the damager.
|
||||||
|
* @param target The targeted entity. This is the entity that all defensive calculations and on-hit effects will be applied to.
|
||||||
|
* @param isCriticalStrike Whether or not this is a forced critical strike.
|
||||||
|
* @param reason The name of the base damage that will be displayed in the DPS logger.
|
||||||
|
* @return Returns the final calculated damage with all modifications applied, using the base damage, if provided.
|
||||||
|
*/
|
||||||
|
public static double getFinalDamage(double dmg, Entity damager, LivingEntity target, boolean isCriticalStrike, String reason) {
|
||||||
|
return NewCombat.applyDamage(dmg, target, damager, isCriticalStrike, reason);
|
||||||
|
}
|
||||||
|
|
||||||
//Message COMMANDS.
|
//Message COMMANDS.
|
||||||
public static void playMessageNotification(Player sender) {
|
public static void playMessageNotification(Player sender) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user