Package net.aufdemrand.denizen.objects

Examples of net.aufdemrand.denizen.objects.dEntity


    // <context.entity> returns the mob that entered the proximity
    //
    // -->
    private void callAction(String act, Entity ent) {
        Map<String, dObject> context = new HashMap<String, dObject>();
        context.put("entity", new dEntity(ent));
        dnpc.action("mob " + act + " proximity", null, context);
        dnpc.action(ent.getType().name() + " " + act + " proximity", null, context);
    }
View Full Code Here


    @SuppressWarnings("unchecked")
    @Override
    public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {

        dEntity originEntity = (dEntity) scriptEntry.getObject("originEntity");
        dLocation originLocation = scriptEntry.hasObject("originLocation") ?
                                   (dLocation) scriptEntry.getObject("originLocation") :
                                   new dLocation(originEntity.getEyeLocation()
                                               .add(originEntity.getEyeLocation().getDirection()));
        boolean no_rotate = scriptEntry.hasObject("no_rotate") && scriptEntry.getElement("no_rotate").asBoolean();

        // If there is no destination set, but there is a shooter, get a point
        // in front of the shooter and set it as the destination
        final dLocation destination = scriptEntry.hasObject("destination") ?
                                      (dLocation) scriptEntry.getObject("destination") :
                                      (originEntity != null ? new dLocation(originEntity.getEyeLocation()
                                                               .add(originEntity.getEyeLocation().getDirection()
                                                               .multiply(30)))
                                                            : null);

        // TODO: Same as PUSH -- is this the place to do this?
        if (destination == null) {
            dB.report(scriptEntry, getName(), "No destination specified!");
            return;
        }

        final List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        final dScript script = (dScript) scriptEntry.getObject("script");
        dEntity shooter = (dEntity) scriptEntry.getObject("shooter");

        Element height = scriptEntry.getElement("height");
        Element gravity = scriptEntry.getElement("gravity");
        Element speed = scriptEntry.getElement("speed");
        Element spread = scriptEntry.getElement("spread");

        dLocation lead = (dLocation) scriptEntry.getObject("lead");

        // Report to dB
        dB.report(scriptEntry, getName(), aH.debugObj("origin", originEntity != null ? originEntity : originLocation) +
                             aH.debugObj("entities", entities.toString()) +
                             destination.debug() +
                             height.debug() +
                             (gravity != null ? gravity.debug(): "") +
                             (speed != null ? speed.debug(): "") +
                             (script != null ? script.debug() : "") +
                             (shooter != null ? shooter.debug() : "") +
                             (spread != null ? spread.debug() : "") +
                             (lead != null ? lead.debug(): "") +
                             (no_rotate ? aH.debugObj("no_rotate", "true"): ""));

        // Keep a dList of entities that can be called using <entry[name].shot_entities>
        // later in the script queue

        final dList entityList = new dList();

        // Go through all the entities, spawning/teleporting and rotating them
        for (dEntity entity : entities) {
            entity.spawnAt(originLocation);

            // Only add to entityList after the entities have been
            // spawned, otherwise you'll get something like "e@skeleton"
            // instead of "e@57" on it
            entityList.add(entity.toString());

            if (!no_rotate)
                Rotation.faceLocation(entity.getBukkitEntity(), destination);

            // If the current entity is a projectile, set its shooter
            // when applicable
            if (entity.isProjectile() && (shooter != null || originEntity != null)) {
                entity.setShooter(shooter != null ? shooter : originEntity);
                // Also, watch for it hitting a target
                arrows.put(entity.getUUID(), null);
            }
        }

        // Add entities to context so that the specific entities created/spawned
        // can be fetched.
        scriptEntry.addObject("shot_entities", entityList);

        if (spread == null)
            Position.mount(Conversion.convertEntities(entities));

        // Get the entity at the bottom of the entity list, because
        // only its gravity should be affected and tracked considering
        // that the other entities will be mounted on it
        final dEntity lastEntity = entities.get(entities.size() - 1);

        if (gravity == null) {

            String entityType = lastEntity.getEntityType().name();

            for (Gravity defaultGravity : Gravity.values()) {

                if (defaultGravity.name().equals(entityType)) {

                    gravity = new Element(defaultGravity.getGravity());
                }
            }

            // If the gravity is still null, use a default value
            if (gravity == null) {
                gravity = new Element(0.115);
            }
        }

        if (speed == null) {
            Vector v1 = lastEntity.getLocation().toVector();
            Vector v2 = destination.toVector();
            Vector v3 = Velocity.calculate(v1, v2, gravity.asDouble(), height.asDouble());
            lastEntity.setVelocity(v3);
        }
        else if (lead == null) {
            Vector relative = destination.clone().subtract(originLocation).toVector();
            lastEntity.setVelocity(relative.normalize().multiply(speed.asDouble()));
        }
        else {
            double g = 20;
            double v = speed.asDouble();
            Vector relative = destination.clone().subtract(originLocation).toVector();
            double testAng = Velocity.launchAngle(originLocation, destination.toVector(), v, relative.getY(), g);
            double hangTime = Velocity.hangtime(testAng, v, relative.getY(), g);
            Vector to = destination.clone().add(lead.clone().multiply(hangTime)).toVector();
            relative = to.clone().subtract(originLocation.toVector());
            Double dist = Math.sqrt(relative.getX() * relative.getX() + relative.getZ() * relative.getZ());
            if (dist == 0) dist = 0.1d;
            testAng = Velocity.launchAngle(originLocation, to, v, relative.getY(), g);
            relative.setY(Math.tan(testAng) * dist);
            relative = relative.normalize();
            v = v + (1.188 * Math.pow(hangTime, 2));
            relative = relative.multiply(v / 20.0d);
            lastEntity.setVelocity(relative);
        }

        if (spread != null) {
            Vector base = lastEntity.getVelocity().clone();
            float sf = spread.asFloat();
            for (dEntity entity: entities) {
                Vector newvel = Velocity.spread(base, (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1: -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf),
                        (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1: -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf));
                entity.setVelocity(newvel);
            }
        }

        // A task used to trigger a script if the entity is no longer
        // being shot, when the script argument is used
        BukkitRunnable task = new BukkitRunnable() {

            boolean flying = true;
            dLocation lastLocation = null;
            Vector lastVelocity = null;

            public void run() {

                // If the entity is no longer spawned, stop the task
                if (!lastEntity.isSpawned()) {
                    flying = false;
                }

                // Otherwise, if the entity is no longer traveling through
                // the air, stop the task
                else if (lastVelocity != null) {
                    if (lastVelocity.distance
                            (lastEntity.getBukkitEntity().getVelocity()) < 0.05) {
                        flying = false;
                    }
                }

                // Stop the task and run the script if conditions
                // are met
                if (!flying) {

                    this.cancel();

                    if (script != null) {
                        // Build a queue out of the targeted script
                        List<ScriptEntry> entries = script.getContainer().getBaseEntries(scriptEntry.entryData.clone());
                        ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getContainer().getName()))
                                .addEntries(entries);

                        // Add relevant definitions
                        queue.addDefinition("location", lastLocation.identify());
                        queue.addDefinition("shot_entities", entityList.toString());
                        queue.addDefinition("last_entity", lastEntity.identify());

                        // Handle hit_entities definition
                        dList hitEntities = new dList();
                        for (dEntity entity: entities) {
                            if (arrows.containsKey(entity.getUUID())) {
                                dEntity hit = arrows.get(entity.getUUID());
                                arrows.remove(entity.getUUID());
                                if (hit != null) {
                                    hitEntities.add(hit.identify());
                                }
                            }
                        }
                        queue.addDefinition("hit_entities", hitEntities.identify());

View Full Code Here

        if (!arrows.containsKey(arrow.getUniqueId()))
            return;

        // Replace its entry with the hit entity.
        arrows.remove(arrow.getUniqueId());
        arrows.put(arrow.getUniqueId(), new dEntity(event.getEntity()));
    }
View Full Code Here

            location.getWorld().playSound(location, instrument, volume, pitch);
        }

        else if (entities != null && !entities.isEmpty()) {
            for (int i = 0; i < entities.size(); i++) {
                dEntity entity = entities.get(i);
                if (entity.isSpawned()) {
                    if (entity.isPlayer()) {
                        entity.getPlayer().playSound(entity.getLocation(), instrument, volume, pitch);
                    }
                    else {
                        entity.getWorld().playSound(entity.getLocation(), instrument, volume, pitch);
                    }
                }
                else {
                    entities.remove(i);
                    i--;
View Full Code Here

        if (!event.matches("entity") || event.replaced()) return;

        // Build a new attribute out of the raw_tag supplied in the script to be fulfilled
        Attribute attribute = event.getAttributes();

        dEntity e = null;

        // Entity tag may specify a new entity in the <entity[context]...> portion of the tag.
        if (attribute.hasContext(1))
            // Check if this is a valid entity and update the dEntity object reference.
            if (attribute.getIntContext(1) >= 1)
               e = dEntity.valueOf("e@" + attribute.getContext(1));

        if (e == null || !e.isValid()) {
            if (!event.hasAlternative()) dB.echoError("Invalid or missing entity for tag <" + event.raw_tag + ">!");
            return;
        }

        event.setReplaced(e.getAttribute(attribute.fulfill(1)));
    }
View Full Code Here

   public dEntity getEntityFrom() {
       return getEntityFrom(null, null);
   }

    public dEntity getEntityFrom(dPlayer player, dNPC npc) {
        dEntity entity = null;
        try {
            if (contains("ENTITY_TYPE")) {
                String entityType = TagManager.tag(player, npc, getString("ENTITY_TYPE"));
                entity = dEntity.valueOf(entityType);
            }

            if (entity == null || entity.isUnique())
                return null;

            entity.setEntityScript(getName());
        }
        catch (Exception e) {
            dB.echoError("Woah! An exception has been called with this entity script!");
            dB.echoError(e);
            entity = null;
View Full Code Here

TOP

Related Classes of net.aufdemrand.denizen.objects.dEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.