/
Axes.java
219 lines (184 loc) · 8.44 KB
/
Axes.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package com.gmail.nossr50.skills.combat;
import java.util.Random;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class Axes {
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
private static Random random = new Random();
/**
* Apply bonus to damage done by axes.
*
* @param attacker The attacking player
* @param event The event to modify
*/
public static void axesBonus(Player attacker, EntityDamageByEntityEvent event) {
if(attacker == null)
return;
final int MAX_BONUS = advancedConfig.getBonusDamageAxesBonusMax();
final int MAX_LEVEL = advancedConfig.getBonusDamageAxesMaxBonusLevel();
final int INCREASE_LEVEL = MAX_LEVEL / MAX_BONUS;
/* Add 1 DMG for every 50 skill levels (default value) */
int bonus = (int) ((double) Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / (double) INCREASE_LEVEL);
if (bonus > MAX_BONUS) {
bonus = MAX_BONUS;
}
event.setDamage(event.getDamage() + bonus);
}
/**
* Check for critical chances on axe damage.
*
* @param attacker The attacking player
* @param event The event to modify
*/
public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) {
if(attacker == null)
return;
Entity entity = event.getEntity();
if (entity instanceof Tameable) {
Tameable pet = (Tameable) entity;
if (pet.isTamed()) {
AnimalTamer tamer = pet.getOwner();
if (tamer instanceof Player) {
Player owner = (Player) tamer;
if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
return;
}
}
}
}
final int MAX_BONUS_LEVEL = advancedConfig.getAxesCriticalMaxBonusLevel();
final double MAX_CHANCE = advancedConfig.getAxesCriticalChance();
final double PVP_MODIFIER = advancedConfig.getAxesCriticalPVPModifier();
final int PVE_MODIFIER = advancedConfig.getAxesCriticalPVEModifier();
PlayerProfile attackerProfile = Users.getProfile(attacker);
int skillLevel = attackerProfile.getSkillLevel(SkillType.AXES);
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
int randomChance = 100;
double chance = (MAX_CHANCE / MAX_BONUS_LEVEL) * skillCheck;
if (chance > MAX_CHANCE) chance = MAX_CHANCE;
if (attacker.hasPermission("mcmmo.perks.lucky.axes")) {
randomChance = (int) (randomChance * 0.75);
}
if (chance > random.nextInt(randomChance) && !entity.isDead()){
// if (random.nextInt(randomChance) <= skillCheck && !entity.isDead()){
int damage = event.getDamage();
if (entity instanceof Player){
event.setDamage((int) (damage * PVP_MODIFIER));
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
}
else {
event.setDamage(damage * PVE_MODIFIER);
}
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
}
}
/**
* Check for Impact ability.
*
* @param attacker The attacking player
* @param target The defending entity
* @param event The event to modify
*/
@SuppressWarnings("deprecation")
public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
if(attacker == null)
return;
/*
* TODO: Finish this skill. The idea is you will greatly damage an opponents armor.
* When they are unarmored, you have a proc that will stun them and deal additional damage.
*/
if (target instanceof Player) {
Player targetPlayer = (Player) target;
short durabilityDamage = 1; //Start with 1 durability damage
/* Every 50 Skill Levels you gain 1 durability damage (default values) */
int impactIncreaseLevel = advancedConfig.getArmorImpactIncreaseLevel();
float impactMaxDamage = (float) advancedConfig.getArmorImpactMaxDurabilityDamage() / 100F;
short maxDurability;
durabilityDamage += (int) ((double) Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / (double) impactIncreaseLevel);
if (!hasArmor(targetPlayer)) {
applyGreaterImpact(attacker, target, event);
}
else {
for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) {
if(Math.random() * 100 > 75) {
int lowerdamage = 0;
for (int i = 0; i <= durabilityDamage; i ++) {
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
int level = armor.getEnchantmentLevel(Enchantment.DURABILITY);
if (random.nextInt(level + 1) > 0) {
lowerdamage++;
}
}
}
int newDurabilityDamage = durabilityDamage - lowerdamage;
maxDurability = (short) (armor.getType().getMaxDurability() * impactMaxDamage);
if (newDurabilityDamage > maxDurability) newDurabilityDamage = (short) maxDurability;
armor.setDurability((short) (armor.getDurability() + newDurabilityDamage)); //Damage armor piece
}
}
targetPlayer.updateInventory();
}
}
else {
applyGreaterImpact(attacker, target, event); //Since mobs are technically unarmored, this will always trigger
}
}
/**
* Apply Greater Impact ability.
*
* @param attacker The attacking player
* @param target The defending entity
* @param event The event to modify
*/
private static void applyGreaterImpact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
if(attacker == null)
return;
final int GREATER_IMPACT_CHANCE = advancedConfig.getGreaterImpactChance();
final double GREATER_IMPACT_MULTIPLIER = advancedConfig.getGreaterImpactModifier();
final int GREATER_IMPACT_DAMAGE = advancedConfig.getGreaterImpactBonusDamage();
if (!Permissions.getInstance().greaterImpact(attacker)) {
return;
}
int randomChance = 100;
if (attacker.hasPermission("mcmmo.perks.lucky.axes")) {
randomChance = (int) (randomChance * 0.75);
}
if (random.nextInt(randomChance) <= GREATER_IMPACT_CHANCE) {
event.setDamage(event.getDamage() + GREATER_IMPACT_DAMAGE);
target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
}
}
/**
* Check if a player has armor.
*
* @param player Player whose armor to check
* @return true if the player has armor, false otherwise
*/
private static boolean hasArmor(Player player) {
if(player == null)
return false;
PlayerInventory inventory = player.getInventory();
if (inventory.getBoots() != null || inventory.getChestplate() != null || inventory.getHelmet() != null || inventory.getLeggings() != null) {
return true;
}
else {
return false;
}
}
}