Search in sources :

Example 11 with Mechanics

use of me.deecaad.weaponmechanics.mechanics.Mechanics 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 12 with Mechanics

use of me.deecaad.weaponmechanics.mechanics.Mechanics in project MechanicsMain by WeaponMechanics.

the class ClusterBomb method serialize.

@Override
@Nonnull
public ClusterBomb serialize(SerializeData data) throws SerializerException {
    int bombs = data.of("Number_Of_Bombs").assertExists().assertPositive().getInt();
    Projectile projectileSettings = data.of("Split_Projectile").serialize(Projectile.class);
    double speed = data.of("Projectile_Speed").assertPositive().getDouble(30.0) / 20.0;
    int splits = data.of("Number_Of_Splits").assertPositive().getInt(1);
    Detonation detonation = data.of("Detonation").serialize(Detonation.class);
    Mechanics mechanics = data.of("Mechanics").serialize(Mechanics.class);
    return new ClusterBomb(projectileSettings, speed, splits, bombs, detonation, mechanics);
}
Also used : Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Projectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile) Nonnull(javax.annotation.Nonnull)

Example 13 with Mechanics

use of me.deecaad.weaponmechanics.mechanics.Mechanics in project MechanicsMain by WeaponMechanics.

the class Explosion method serialize.

@Override
@Nonnull
public Explosion serialize(SerializeData data) throws SerializerException {
    // We don't need to get the values here since we add them to the map
    // later. We should still make sure these are positive numbers, though.
    data.of("Explosion_Type_Data.Yield").assertPositive();
    data.of("Explosion_Type_Data.Angle").assertPositive();
    data.of("Explosion_Type_Data.Height").assertPositive();
    data.of("Explosion_Type_Data.Width").assertPositive();
    data.of("Explosion_Type_Data.Radius").assertPositive();
    data.of("Rays").assertPositive();
    // We always want at least one.
    if (!data.config.contains(data.key + ".Explosion_Type_Data")) {
        throw new SerializerMissingKeyException(data.serializer, "Explosion_Type_Data", data.of("Explosion_Type_Data").getLocation());
    }
    Map<String, Object> typeData = data.config.getConfigurationSection(data.key + ".Explosion_Type_Data").getValues(false);
    // most people will not understand hat it means. Vanilla MC uses 16.
    if (!typeData.containsKey("Rays"))
        typeData.put("Rays", 16);
    ExplosionExposure exposure;
    ExplosionShape shape;
    try {
        exposure = ExposureFactory.getInstance().get(data.of("Explosion_Exposure").get("DEFAULT"), typeData);
        shape = ShapeFactory.getInstance().get(data.of("Explosion_Shape").get("DEFAULT"), typeData);
    } catch (SerializerException ex) {
        // We need to manually set the file and path, since the Factory
        // class does not get enough information to fill it.
        ex.setLocation(data.of("Explosion_Type_Data").getLocation());
        throw ex;
    }
    BlockDamage blockDamage = data.of("Block_Damage").serialize(BlockDamage.class);
    RegenerationData regeneration = data.of("Regeneration").serialize(RegenerationData.class);
    // to make when copying/pasting and deleting chunks of config.
    if ((blockDamage == null || !blockDamage.isBreakBlocks()) && regeneration != null) {
        throw data.exception(null, "Found an Explosion that defines 'Regeneration' when 'Block_Damage' cannot break blocks!", "This happens when 'Block_Damage.Break_Blocks: false' or when 'Block_Damage' was not added AND you tried to add 'Regeneration'");
    }
    // This is a required argument to determine when a projectile using this
    // explosion should explode (onEntityHit, onBlockHit, after delay, etc.)
    Detonation detonation = data.of("Detonation").assertExists().serialize(Detonation.class);
    Double blockChance = data.of("Block_Damage.Spawn_Falling_Block_Chance").serializeNonStandardSerializer(new ChanceSerializer());
    if (blockChance == null)
        blockChance = 0.0;
    boolean isKnockback = !data.of("Disable_Vanilla_Knockback").getBool(false);
    // These 4 options are all nullable and not required for an explosion
    // to occur. It is very interesting when they are all used together :p
    ClusterBomb clusterBomb = data.of("Cluster_Bomb").serialize(ClusterBomb.class);
    AirStrike airStrike = data.of("Airstrike").serialize(AirStrike.class);
    Flashbang flashbang = data.of("Flashbang").serialize(Flashbang.class);
    Mechanics mechanics = data.of("Mechanics").serialize(Mechanics.class);
    return new Explosion(shape, exposure, blockDamage, regeneration, detonation, blockChance, isKnockback, clusterBomb, airStrike, flashbang, mechanics);
}
Also used : ChanceSerializer(me.deecaad.core.file.serializers.ChanceSerializer) ExplosionExposure(me.deecaad.weaponmechanics.weapon.explode.exposures.ExplosionExposure) SerializerException(me.deecaad.core.file.SerializerException) RegenerationData(me.deecaad.weaponmechanics.weapon.explode.regeneration.RegenerationData) ExplosionShape(me.deecaad.weaponmechanics.weapon.explode.shapes.ExplosionShape) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponMechanics(me.deecaad.weaponmechanics.WeaponMechanics) SerializerMissingKeyException(me.deecaad.core.file.SerializerMissingKeyException) Nonnull(javax.annotation.Nonnull)

Example 14 with Mechanics

use of me.deecaad.weaponmechanics.mechanics.Mechanics 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)

Example 15 with Mechanics

use of me.deecaad.weaponmechanics.mechanics.Mechanics in project MechanicsMain by WeaponMechanics.

the class FirearmAction method serialize.

@Override
@Nonnull
public FirearmAction serialize(SerializeData data) throws SerializerException {
    FirearmType type = data.of("Type").assertExists().getEnum(FirearmType.class);
    // Default to 1 in order to make it easier to use
    int firearmActionFrequency = data.of("Firearm_Action_Frequency").assertRange(1, Integer.MAX_VALUE).getInt(1);
    int openTime = data.of("Open.Time").assertRange(1, Integer.MAX_VALUE).getInt(1);
    int closeTime = data.of("Close.Time").assertRange(1, Integer.MAX_VALUE).getInt(1);
    Mechanics open = data.of("Open.Mechanics").serialize(Mechanics.class);
    Mechanics close = data.of("Close.Mechanics").serialize(Mechanics.class);
    return new FirearmAction(type, firearmActionFrequency, openTime, closeTime, open, close);
}
Also used : Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) Nonnull(javax.annotation.Nonnull)

Aggregations

Mechanics (me.deecaad.weaponmechanics.mechanics.Mechanics)18 WeaponMechanics (me.deecaad.weaponmechanics.WeaponMechanics)14 CastData (me.deecaad.weaponmechanics.mechanics.CastData)10 Nonnull (javax.annotation.Nonnull)7 WeaponInfoDisplay (me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay)7 PlayerWrapper (me.deecaad.weaponmechanics.wrappers.PlayerWrapper)7 Configuration (me.deecaad.core.file.Configuration)6 LivingEntity (org.bukkit.entity.LivingEntity)6 HandData (me.deecaad.weaponmechanics.wrappers.HandData)5 Projectile (me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile)4 WeaponProjectile (me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile)4 AmmoTypes (me.deecaad.weaponmechanics.weapon.reload.ammo.AmmoTypes)2 WeaponScopeEvent (me.deecaad.weaponmechanics.weapon.weaponevents.WeaponScopeEvent)2 WeaponShootEvent (me.deecaad.weaponmechanics.weapon.weaponevents.WeaponShootEvent)2 Location (org.bukkit.Location)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 Vector (org.bukkit.util.Vector)2 HashSet (java.util.HashSet)1 SerializerException (me.deecaad.core.file.SerializerException)1