Search in sources :

Example 6 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class ScopeHandler method zoomInWithoutTiming.

/**
 * @return true if successfully zoomed in or stacked
 */
private boolean zoomInWithoutTiming(ItemStack weaponStack, String weaponTitle, EntityWrapper entityWrapper, ZoomData zoomData, EquipmentSlot slot) {
    Configuration config = getConfigurations();
    LivingEntity entity = entityWrapper.getEntity();
    if (zoomData.isZooming()) {
        // zoom stack
        int increaseZoomPerStack = config.getInt(weaponTitle + ".Scope.Zoom_Stacking.Increase_Zoom_Per_Stack");
        if (increaseZoomPerStack != 0) {
            int zoomStack = zoomData.getZoomStacks() + 1;
            int zoomAmount = config.getInt(weaponTitle + ".Scope.Zoom_Amount");
            WeaponScopeEvent weaponScopeEvent = new WeaponScopeEvent(weaponTitle, weaponStack, entity, WeaponScopeEvent.ScopeType.STACK, zoomAmount + (zoomStack * increaseZoomPerStack), zoomStack);
            Bukkit.getPluginManager().callEvent(weaponScopeEvent);
            if (weaponScopeEvent.isCancelled()) {
                return false;
            }
            updateZoom(entityWrapper, zoomData, weaponScopeEvent.getZoomAmount());
            zoomData.setZoomStacks(zoomStack);
            weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot);
            Mechanics zoomStackingMechanics = config.getObject(weaponTitle + ".Scope.Zoom_Stacking.Mechanics", Mechanics.class);
            if (zoomStackingMechanics != null)
                zoomStackingMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
            WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
            if (weaponInfoDisplay != null)
                weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot);
            return true;
        } else {
            debug.log(LogLevel.WARN, "For some reason zoom in was called on entity when it shouldn't have.", "Entity was already zooming so it should have stacked zoom, but not zoom stacking wasn't used at all?", "Ignoring this call, but this shouldn't even happen...", "Are you sure you have defined both Maximum_Stacks and Increase_Zoom_Per_Stack for weapon " + weaponTitle + "?");
            return false;
        }
    }
    int zoomAmount = config.getInt(weaponTitle + ".Scope.Zoom_Amount");
    if (zoomAmount == 0)
        return false;
    // zoom stack = 0, because its not used OR this is first zoom in
    WeaponScopeEvent weaponScopeEvent = new WeaponScopeEvent(weaponTitle, weaponStack, entity, WeaponScopeEvent.ScopeType.IN, zoomAmount, 0);
    Bukkit.getPluginManager().callEvent(weaponScopeEvent);
    if (weaponScopeEvent.isCancelled()) {
        return false;
    }
    updateZoom(entityWrapper, zoomData, weaponScopeEvent.getZoomAmount());
    Mechanics zoomMechanics = config.getObject(weaponTitle + ".Scope.Mechanics", Mechanics.class);
    if (zoomMechanics != null)
        zoomMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
    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);
    if (config.getBool(weaponTitle + ".Scope.Night_Vision"))
        useNightVision(entityWrapper, zoomData);
    return true;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) CastData(me.deecaad.weaponmechanics.mechanics.CastData) Configuration(me.deecaad.core.file.Configuration) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponMechanics(me.deecaad.weaponmechanics.WeaponMechanics) WeaponScopeEvent(me.deecaad.weaponmechanics.weapon.weaponevents.WeaponScopeEvent) WeaponInfoDisplay(me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay) PlayerWrapper(me.deecaad.weaponmechanics.wrappers.PlayerWrapper)

Example 7 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class ShootHandler method burstShot.

private boolean burstShot(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, HandData handData, EquipmentSlot slot, boolean dualWield) {
    Configuration config = getConfigurations();
    int shotsPerBurst = config.getInt(weaponTitle + ".Shoot.Burst.Shots_Per_Burst");
    int ticksBetweenEachShot = config.getInt(weaponTitle + ".Shoot.Burst.Ticks_Between_Each_Shot");
    // Not used
    if (shotsPerBurst == 0 || ticksBetweenEachShot == 0)
        return false;
    boolean mainhand = slot == EquipmentSlot.HAND;
    boolean consumeItemOnShoot = getConfigurations().getBool(weaponTitle + ".Shoot.Consume_Item_On_Shoot");
    handData.setBurstTask(new BukkitRunnable() {

        int shots = 0;

        @Override
        public void run() {
            ItemStack taskReference = mainhand ? entityWrapper.getEntity().getEquipment().getItemInMainHand() : entityWrapper.getEntity().getEquipment().getItemInOffHand();
            if (taskReference == weaponStack)
                taskReference = weaponStack;
            // START RELOAD STUFF
            ReloadHandler reloadHandler = weaponHandler.getReloadHandler();
            if (entityWrapper.getMainHandData().isReloading() || entityWrapper.getOffHandData().isReloading()) {
                handData.setBurstTask(0);
                cancel();
                return;
            }
            if (!reloadHandler.consumeAmmo(taskReference, weaponTitle, 1)) {
                handData.setBurstTask(0);
                cancel();
                reloadHandler.startReloadWithoutTrigger(entityWrapper, weaponTitle, taskReference, slot, dualWield, false);
                return;
            }
            // END RELOAD STUFF
            // Only make the first projectile of burst modify spread change if its used
            shoot(entityWrapper, weaponTitle, taskReference, getShootLocation(entityWrapper.getEntity(), dualWield, mainhand), mainhand, shots == 0, false);
            if (consumeItemOnShoot && handleConsumeItemOnShoot(taskReference)) {
                handData.setBurstTask(0);
                cancel();
                return;
            }
            if (++shots >= shotsPerBurst) {
                handData.setBurstTask(0);
                cancel();
                if (reloadHandler.getAmmoLeft(taskReference, weaponTitle) == 0) {
                    reloadHandler.startReloadWithoutTrigger(entityWrapper, weaponTitle, taskReference, slot, dualWield, false);
                } else {
                    doShootFirearmActions(entityWrapper, weaponTitle, taskReference, handData, slot);
                }
            }
        }
    }.runTaskTimer(WeaponMechanics.getPlugin(), 0, ticksBetweenEachShot).getTaskId());
    return true;
}
Also used : Configuration(me.deecaad.core.file.Configuration) ReloadHandler(me.deecaad.weaponmechanics.weapon.reload.ReloadHandler) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class ShootHandler method shoot.

/**
 * Shoots using weapon.
 * Does not use ammo nor check for it.
 * Does not apply recoil nor anything that would require EntityWrapper.
 */
public void shoot(LivingEntity livingEntity, String weaponTitle, Vector normalizedDirection) {
    Configuration config = getConfigurations();
    Mechanics shootMechanics = config.getObject(weaponTitle + ".Shoot.Mechanics", Mechanics.class);
    if (shootMechanics != null)
        shootMechanics.use(new CastData(livingEntity, weaponTitle, null));
    Projectile projectile = config.getObject(weaponTitle + ".Projectile", Projectile.class);
    if (projectile == null)
        return;
    Location shootLocation = getShootLocation(livingEntity, false, true);
    double projectileSpeed = config.getDouble(weaponTitle + ".Shoot.Projectile_Speed");
    for (int i = 0; i < config.getInt(weaponTitle + ".Shoot.Projectiles_Per_Shot"); ++i) {
        // Only create bullet first if WeaponShootEvent changes
        WeaponProjectile bullet = projectile.create(livingEntity, shootLocation, normalizedDirection.clone().multiply(projectileSpeed), null, weaponTitle);
        WeaponShootEvent shootEvent = new WeaponShootEvent(bullet);
        Bukkit.getPluginManager().callEvent(shootEvent);
        bullet = shootEvent.getProjectile();
        // Shoot the given bullet
        projectile.shoot(bullet, shootLocation);
    }
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) Configuration(me.deecaad.core.file.Configuration) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) WeaponShootEvent(me.deecaad.weaponmechanics.weapon.weaponevents.WeaponShootEvent) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponMechanics(me.deecaad.weaponmechanics.WeaponMechanics) Projectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Location(org.bukkit.Location)

Example 9 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class DamageUtil method calculateFinalDamage.

public static double calculateFinalDamage(LivingEntity cause, LivingEntity victim, double damage, DamagePoint point, boolean isBackStab) {
    Configuration config = WeaponMechanics.getBasicConfigurations();
    AtomicDouble rate = new AtomicDouble(1.0);
    EntityWrapper wrapper = WeaponMechanics.getEntityWrapper(victim);
    // Apply backstab damage
    if (isBackStab)
        rate.addAndGet(config.getDouble("Damage.Back"));
    // Apply damage per potion effect
    for (PotionEffect potion : victim.getActivePotionEffects()) {
        rate.addAndGet(config.getDouble("Damage.Potions." + potion.getType().getName()));
    }
    // Apply damage per armor and attachment
    for (ItemStack armorSlot : victim.getEquipment().getArmorContents()) {
        if (armorSlot == null)
            continue;
        // We parse Material and EquipmentSlot from the given item. Note
        // that all armor names are formatted like: DIAMOND_CHESTPLATE,
        // IRON_BOOTS, LEATHER_HELMET, hence Material_Equipment slot.
        // Normally we would split at the '_', but using String#split is
        // ~50x slower than String#subString.
        String name = armorSlot.getType().name();
        int splitIndex = name.indexOf('_');
        if (splitIndex == -1)
            continue;
        // This method of parsing material and slot has issues with
        // materials like ACACIA_BOAT. In this case, it will fail silently
        // by adding 0.0 to the rate.
        String material = name.substring(0, splitIndex);
        String slot = name.substring(splitIndex + 1);
        rate.addAndGet(config.getDouble("Damage.Armor." + slot + "." + material, 0.0));
        armorSlot.getEnchantments().forEach((enchant, level) -> rate.addAndGet(level * config.getDouble("Damage.Armor.Enchantments." + enchant.getKey().getKey())));
    }
    // Apply damage based on victim movement
    if (wrapper.isInMidair())
        rate.addAndGet(config.getDouble("Damage.Movement.In_Midair"));
    if (wrapper.isWalking())
        rate.addAndGet(config.getDouble("Damage.Movement.Walking"));
    if (wrapper.isSwimming())
        rate.addAndGet(config.getDouble("Damage.Movement.Swimming"));
    if (wrapper.isSprinting())
        rate.addAndGet(config.getDouble("Damage.Movement.Sprinting"));
    if (wrapper.isSneaking())
        rate.addAndGet(config.getDouble("Damage.Movement.Sneaking"));
    // Apply damage based on the point that hit the victim
    if (point != null) {
        rate.addAndGet(config.getDouble("Damage.Critical_Points." + point.name()));
    }
    // Make sure damage is within ranges
    rate.set(Math.min(rate.get(), config.getDouble("Damage.Maximum_Rate")));
    rate.set(Math.max(rate.get(), config.getDouble("Damage.Minimum_Rate")));
    // Apply damage to victim
    return damage * rate.get();
}
Also used : Configuration(me.deecaad.core.file.Configuration) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) PotionEffect(org.bukkit.potion.PotionEffect) EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class WeaponHandler method tryUses.

/**
 * Tries all uses in this exact order
 * <pre>{@code
 * 1) Shoot
 * 2) Reload
 * 3) Scope
 * 4) Selective fire
 * 5) Ammo type switch
 * }</pre>
 *
 * @param entityWrapper the entity which caused trigger
 * @param weaponTitle the weapon title involved
 * @param weaponStack the weapon stack involved
 * @param slot the weapon slot used
 * @param triggerType the trigger which caused this
 * @param dualWield whether or not this was dual wield
 */
public void tryUses(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, EquipmentSlot slot, TriggerType triggerType, boolean dualWield, @Nullable LivingEntity victim) {
    if (!weaponStack.hasItemMeta())
        return;
    // Try shooting (and melee)
    if (shootHandler.tryUse(entityWrapper, weaponTitle, weaponStack, slot, triggerType, dualWield, victim)) {
        if (triggerType.isSprintType())
            getSkinHandler().tryUse(triggerType, entityWrapper, weaponTitle, weaponStack, slot);
        return;
    }
    // Shooting wasn't valid, try reloading
    if (reloadHandler.tryUse(entityWrapper, weaponTitle, weaponStack, slot, triggerType, dualWield)) {
        if (triggerType.isSprintType())
            getSkinHandler().tryUse(triggerType, entityWrapper, weaponTitle, weaponStack, slot);
        return;
    }
    // Reloading wasn't valid, try scoping
    if (scopeHandler.tryUse(entityWrapper, weaponTitle, weaponStack, slot, triggerType, dualWield)) {
        if (triggerType.isSprintType())
            getSkinHandler().tryUse(triggerType, entityWrapper, weaponTitle, weaponStack, slot);
        return;
    }
    if (triggerType.isSprintType())
        getSkinHandler().tryUse(triggerType, entityWrapper, weaponTitle, weaponStack, slot);
    // Scoping wasn't valid, try selective fire
    Configuration config = getConfigurations();
    Trigger selectiveFireTrigger = config.getObject(weaponTitle + ".Shoot.Selective_Fire.Trigger", Trigger.class);
    if (selectiveFireTrigger != null && selectiveFireTrigger.check(triggerType, slot, entityWrapper)) {
        boolean hasBurst = config.getInt(weaponTitle + ".Shoot.Burst.Shots_Per_Burst") != 0 && config.getInt(weaponTitle + ".Shoot.Burst.Ticks_Between_Each_Shot") != 0;
        boolean hasAuto = config.getInt(weaponTitle + ".Shoot.Fully_Automatic_Shots_Per_Second") != 0;
        // 3) Auto
        if (!CustomTag.SELECTIVE_FIRE.hasInteger(weaponStack)) {
            if (hasBurst) {
                CustomTag.SELECTIVE_FIRE.setInteger(weaponStack, BURST.getId());
            } else if (hasAuto) {
                CustomTag.SELECTIVE_FIRE.setInteger(weaponStack, AUTO.getId());
            }
        } else {
            int currentSelectiveFire = CustomTag.SELECTIVE_FIRE.getInteger(weaponStack);
            switch(currentSelectiveFire) {
                case // 1 = burst, can't use SelectiveFireState.BURST.getId() here
                (1):
                    if (hasAuto) {
                        CustomTag.SELECTIVE_FIRE.setInteger(weaponStack, AUTO.getId());
                    } else {
                        CustomTag.SELECTIVE_FIRE.setInteger(weaponStack, SINGLE.getId());
                    }
                    break;
                case // 2 = auto, can't use SelectiveFireState.AUTO.getId() here
                (2):
                    CustomTag.SELECTIVE_FIRE.setInteger(weaponStack, SINGLE.getId());
                    break;
                default:
                    if (hasBurst) {
                        CustomTag.SELECTIVE_FIRE.setInteger(weaponStack, BURST.getId());
                    } else if (hasAuto) {
                        CustomTag.SELECTIVE_FIRE.setInteger(weaponStack, AUTO.getId());
                    }
                    break;
            }
        }
        Mechanics selectiveFireMechanics = config.getObject(weaponTitle + ".Shoot.Selective_Fire.Mechanics", Mechanics.class);
        if (selectiveFireMechanics != null)
            selectiveFireMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
        WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
        if (weaponInfoDisplay != null)
            weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot);
        entityWrapper.getMainHandData().cancelTasks();
        entityWrapper.getOffHandData().cancelTasks();
        return;
    }
    // Selective fire wasn't valid, try ammo type switch
    Trigger ammoTypeSwitchTrigger = config.getObject(weaponTitle + ".Reload.Ammo.Ammo_Type_Switch.Trigger", Trigger.class);
    if (ammoTypeSwitchTrigger != null && entityWrapper instanceof PlayerWrapper && ammoTypeSwitchTrigger.check(triggerType, slot, entityWrapper)) {
        AmmoTypes ammoTypes = config.getObject(weaponTitle + ".Reload.Ammo.Ammo_Types", AmmoTypes.class);
        if (ammoTypes != null) {
            // First empty the current ammo
            int ammoLeft = CustomTag.AMMO_LEFT.getInteger(weaponStack);
            if (ammoLeft > 0) {
                ammoTypes.giveAmmo(weaponStack, (PlayerWrapper) entityWrapper, ammoLeft, config.getInt(weaponTitle + ".Reload.Magazine_Size"));
                CustomTag.AMMO_LEFT.setInteger(weaponStack, 0);
            }
            // Then do the switch
            ammoTypes.updateToNextAmmoType(weaponStack);
            Mechanics ammoTypeSwitchMechanics = getConfigurations().getObject(weaponTitle + ".Reload.Ammo.Ammo_Type_Switch.Mechanics", Mechanics.class);
            if (ammoTypeSwitchMechanics != null)
                ammoTypeSwitchMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
            WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
            if (weaponInfoDisplay != null)
                weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot);
            entityWrapper.getMainHandData().cancelTasks();
            entityWrapper.getOffHandData().cancelTasks();
        // Here has to be return if new triggers gets added
        }
    }
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) AmmoTypes(me.deecaad.weaponmechanics.weapon.reload.ammo.AmmoTypes) Trigger(me.deecaad.weaponmechanics.weapon.trigger.Trigger) Configuration(me.deecaad.core.file.Configuration) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponInfoDisplay(me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay) PlayerWrapper(me.deecaad.weaponmechanics.wrappers.PlayerWrapper)

Aggregations

Configuration (me.deecaad.core.file.Configuration)19 CastData (me.deecaad.weaponmechanics.mechanics.CastData)7 Mechanics (me.deecaad.weaponmechanics.mechanics.Mechanics)6 LivingEntity (org.bukkit.entity.LivingEntity)6 WeaponMechanics (me.deecaad.weaponmechanics.WeaponMechanics)5 PlayerWrapper (me.deecaad.weaponmechanics.wrappers.PlayerWrapper)5 Location (org.bukkit.Location)5 WeaponInfoDisplay (me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay)4 HandData (me.deecaad.weaponmechanics.wrappers.HandData)4 ItemStack (org.bukkit.inventory.ItemStack)4 Vector (org.bukkit.util.Vector)4 ReloadHandler (me.deecaad.weaponmechanics.weapon.reload.ReloadHandler)3 Trigger (me.deecaad.weaponmechanics.weapon.trigger.Trigger)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 IOException (java.io.IOException)2 JarFile (java.util.jar.JarFile)2 FileReader (me.deecaad.core.file.FileReader)2 IValidator (me.deecaad.core.file.IValidator)2 LinkedConfig (me.deecaad.core.file.LinkedConfig)2 FirearmAction (me.deecaad.weaponmechanics.weapon.firearm.FirearmAction)2