use of me.deecaad.weaponmechanics.mechanics.CastData in project MechanicsMain by WeaponMechanics.
the class DamageHandler method tryUse.
/**
* @return false if damaging was cancelled
*/
public boolean tryUse(LivingEntity victim, double damage, DamagePoint point, boolean isBackstab, LivingEntity shooter, String weaponTitle, ItemStack weaponStack, double distanceTravelled) {
Configuration config = getConfigurations();
boolean isFriendlyFire = config.getBool(weaponTitle + ".Damage.Enable_Friendly_Fire");
if (!isFriendlyFire && !DamageUtil.canHarm(shooter, victim)) {
return false;
}
boolean isOwnerImmune = config.getBool(weaponTitle + ".Damage.Enable_Owner_Immunity");
if (isOwnerImmune && victim.equals(shooter)) {
return false;
}
// Critical Hit chance
double chance = config.getDouble(weaponTitle + ".Damage.Critical_Hit.Chance", -1);
boolean isCritical = chance != -1 && NumberUtil.chance((chance / 100));
int armorDamage = config.getInt(weaponTitle + ".Damage.Armor_Damage");
int fireTicks = config.getInt(weaponTitle + ".Damage.Fire_Ticks");
WeaponDamageEntityEvent damageEntityEvent = new WeaponDamageEntityEvent(weaponTitle, weaponStack, shooter, victim, damage, isBackstab, isCritical, point, armorDamage, fireTicks, distanceTravelled);
Bukkit.getPluginManager().callEvent(damageEntityEvent);
if (damageEntityEvent.isCancelled())
return false;
fireTicks = damageEntityEvent.getFireTicks();
point = damageEntityEvent.getPoint();
if (DamageUtil.apply(shooter, victim, damageEntityEvent.getFinalDamage())) {
WeaponMechanics.debug.debug("Damage was cancelled");
// Damage was cancelled
return false;
}
DamageUtil.damageArmor(victim, damageEntityEvent.getArmorDamage(), point);
// Fire ticks
if (fireTicks > 0) {
victim.setFireTicks(fireTicks);
}
EntityWrapper shooterWrapper = WeaponMechanics.getEntityWrapper(shooter, true);
CastData shooterCast;
if (shooterWrapper != null) {
shooterCast = new CastData(shooterWrapper, weaponTitle, weaponStack);
} else {
shooterCast = new CastData(shooter, weaponTitle, weaponStack);
}
shooterCast.setData(CommonDataTags.TARGET_LOCATION.name(), victim.getLocation());
shooterCast.setData(CommonDataTags.SHOOTER_NAME.name(), shooter.getName());
shooterCast.setData(CommonDataTags.VICTIM_NAME.name(), victim.getName());
EntityWrapper victimWrapper = WeaponMechanics.getEntityWrapper(victim, true);
CastData victimCast;
if (victimWrapper != null) {
victimCast = new CastData(victimWrapper, weaponTitle, weaponStack);
} else {
victimCast = new CastData(victim, weaponTitle, weaponStack);
}
victimCast.setData(CommonDataTags.TARGET_LOCATION.name(), shooter.getLocation());
victimCast.setData(CommonDataTags.SHOOTER_NAME.name(), shooter.getName());
victimCast.setData(CommonDataTags.VICTIM_NAME.name(), victim.getName());
// On all damage
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage");
// On point
if (point != null)
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage." + point.getReadable());
// On backstab
if (damageEntityEvent.isBackstab()) {
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage.Backstab");
}
// On critical
if (damageEntityEvent.isCritical()) {
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage.Critical_Hit");
}
if (victim.isDead() || victim.getHealth() <= 0.0) {
Bukkit.getPluginManager().callEvent(new WeaponKillEntityEvent(weaponTitle, weaponStack, shooter, victim, damageEntityEvent));
// On kill
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage.Kill");
}
return true;
}
use of me.deecaad.weaponmechanics.mechanics.CastData in project MechanicsMain by WeaponMechanics.
the class AirStrike method trigger.
public void trigger(Location flareLocation, LivingEntity shooter, WeaponProjectile projectile) {
if (mechanics != null)
mechanics.use(new CastData(shooter, projectile.getWeaponTitle(), projectile.getWeaponStack()));
new BukkitRunnable() {
int count = 0;
@Override
public void run() {
int bombs = NumberUtil.random(min, max);
int checks = bombs * bombs;
// Used to make sure we don't spawn bombs too close to
// each other. Uses distanceBetweenSquared
List<Vector2d> spawnLocations = new ArrayList<>(bombs);
locationFinder: for (int i = 0; i < checks && spawnLocations.size() < bombs; i++) {
double x = flareLocation.getX() + NumberUtil.random(-radius, radius);
double z = flareLocation.getZ() + NumberUtil.random(-radius, radius);
Vector2d vector = new Vector2d(x, z);
for (Vector2d spawnLocation : spawnLocations) {
if (vector.distanceSquared(spawnLocation) < distanceBetweenSquared) {
continue locationFinder;
}
}
spawnLocations.add(vector);
double y = flareLocation.getY() + height + NumberUtil.random(-yVariation, yVariation);
Location location = new Location(flareLocation.getWorld(), x, y, z);
// Either use the projectile settings from the "parent" projectile,
// or use the projectile settings for this airstrike
Projectile projectileHandler = getProjectile() != null ? getProjectile() : getConfigurations().getObject(projectile.getWeaponTitle() + ".Projectile", Projectile.class);
if (projectileHandler != null) {
WeaponProjectile newProjectile = getProjectile() != null ? projectileHandler.create(shooter, location, new Vector(0, 0, 0), projectile.getWeaponStack(), projectile.getWeaponTitle()) : projectile.clone(location, new Vector(0, 0, 0));
newProjectile.setIntTag("airstrike-bomb", 1);
projectileHandler.shoot(newProjectile, location);
}
}
if (++count >= loops) {
cancel();
}
}
}.runTaskTimerAsynchronously(WeaponMechanics.getPlugin(), 0, delay);
}
use of me.deecaad.weaponmechanics.mechanics.CastData in project MechanicsMain by WeaponMechanics.
the class WeaponListeners method equip.
@EventHandler
public void equip(EntityEquipmentEvent e) {
if (e.isArmor())
return;
LivingEntity entity = (LivingEntity) e.getEntity();
EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(entity);
ItemStack weaponStack = e.getEquipped();
// Also try auto converting to weapon
String weaponTitle = weaponHandler.getInfoHandler().getWeaponTitle(weaponStack, true);
boolean alreadyUsedEquipMechanics = false;
boolean mainhand = e.getSlot() == EquipmentSlot.HAND;
HandData handData = mainhand ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
handData.setCurrentWeaponTitle(weaponTitle);
if (weaponTitle != null) {
if (e.getEntityType() == EntityType.PLAYER) {
WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
if (weaponInfoDisplay != null)
weaponInfoDisplay.send((PlayerWrapper) entityWrapper, e.getSlot());
}
weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, e.getSlot());
Mechanics equipMechanics = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Equip_Mechanics", Mechanics.class);
if (equipMechanics != null) {
equipMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
alreadyUsedEquipMechanics = true;
}
handData.setLastEquipTime(System.currentTimeMillis());
if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Weapon_Equip_Delay") && e.getEntityType() == EntityType.PLAYER) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entity, weaponStack.getType(), getConfigurations().getInt(weaponTitle + ".Info.Weapon_Equip_Delay") / 50);
} else if (CompatibilityAPI.getEntityCompatibility().hasCooldown((Player) entity, weaponStack.getType())) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entity, weaponStack.getType(), 0);
}
Bukkit.getPluginManager().callEvent(new WeaponEquipEvent(weaponTitle, weaponStack, entity, e.getSlot() == EquipmentSlot.HAND));
}
ItemStack dequipped = e.getDequipped();
String dequippedWeapon = weaponHandler.getInfoHandler().getWeaponTitle(dequipped, false);
if (dequippedWeapon != null) {
// Don't use holster mechanics is equip mechanics were already used
if (!alreadyUsedEquipMechanics) {
Mechanics holsterMechanics = getConfigurations().getObject(dequippedWeapon + ".Info.Weapon_Holster_Mechanics", Mechanics.class);
if (holsterMechanics != null)
holsterMechanics.use(new CastData(entityWrapper, dequippedWeapon, dequipped));
}
if (weaponTitle == null && CompatibilityAPI.getEntityCompatibility().hasCooldown((Player) entity, dequipped.getType())) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entity, dequipped.getType(), 0);
}
}
}
use of me.deecaad.weaponmechanics.mechanics.CastData in project MechanicsMain by WeaponMechanics.
the class Projectile method shoot.
/**
* Shoots created projectile object
*
* @param projectile the created projectile object
* @param location the location containing pitch and yaw
*/
public WeaponProjectile shoot(WeaponProjectile projectile, Location location) {
WeaponMechanics.getProjectilesRunnable().addProjectile(projectile);
if (mechanics != null)
mechanics.use(new CastData(projectile));
EntityType type = projectileSettings.getProjectileDisguise();
if (type != null) {
FakeEntity fakeEntity;
Object data = projectileSettings.getDisguiseData();
if (type == EntityType.ARMOR_STAND && data != null) {
// Armor stand height * eye height multiplier
// 1.975 * 0.85 = 1.67875
Location offset = new Location(location.getWorld(), 0, -1.67875, 0);
// Add the first offset before actually spawning
location.add(offset);
fakeEntity = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(location, type, data);
fakeEntity.setEquipment(EquipmentSlot.HEAD, (ItemStack) data);
fakeEntity.setInvisible(true);
// Set the offset for new packets
fakeEntity.setOffset(offset);
} else {
fakeEntity = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(location, type, data);
}
projectile.spawnDisguise(fakeEntity);
}
// Handle explosions
Explosion explosion = getConfigurations().getObject(projectile.getWeaponTitle() + ".Explosion", Explosion.class);
if (explosion != null)
explosion.handleExplosion(projectile.getShooter(), projectile, ExplosionTrigger.SPAWN);
return projectile;
}
use of me.deecaad.weaponmechanics.mechanics.CastData in project MechanicsMain by WeaponMechanics.
the class ReloadHandler method getCloseTask.
private ChainTask getCloseTask(int firearmCloseTime, FirearmAction firearmAction, ItemStack weaponStack, HandData handData, EntityWrapper entityWrapper, String weaponTitle, boolean mainhand, EquipmentSlot slot) {
return new ChainTask(firearmCloseTime) {
@Override
public void task() {
ItemStack taskReference = mainhand ? entityWrapper.getEntity().getEquipment().getItemInMainHand() : entityWrapper.getEntity().getEquipment().getItemInOffHand();
if (taskReference == weaponStack) {
taskReference = weaponStack;
} else {
handData.setReloadData(weaponTitle, taskReference);
}
firearmAction.changeState(taskReference, FirearmState.READY);
finishReload(entityWrapper, weaponTitle, taskReference, handData, slot);
}
@Override
public void setup() {
handData.addReloadTask(getTaskId());
firearmAction.changeState(weaponStack, FirearmState.CLOSE);
CastData castData = new CastData(entityWrapper, weaponTitle, weaponStack);
// Set the extra data so SoundMechanic knows to save task id to hand's reload tasks
castData.setData(ReloadSound.getDataKeyword(), mainhand ? ReloadSound.MAIN_HAND.getId() : ReloadSound.OFF_HAND.getId());
firearmAction.useMechanics(castData, false);
if (entityWrapper instanceof PlayerWrapper) {
WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
if (weaponInfoDisplay != null)
weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot);
}
weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot);
}
};
}
Aggregations