Files

1.4 KiB
Raw Permalink Blame History

MercanRey3.js — loop() (satır 166)

← MercanRey3.js · ← Master

function loop(c, key, runId)
{
    var state = mappet.get(key);

    if (state == null || Number(state.runId) !== Number(runId))
    {
        return;
    }

    var caster = c.getServer().getEntity(String(state.caster));

    if (caster == null || !caster.isPlayer())
    {
        mappet.set(key, null);
        return;
    }

    var world = c.getServer().getWorld(Number(state.dimension));
    var current = findAffected(world, state);
    var previous = state.affected || {};

    for (var uuid in previous)
    {
        if (!Object.prototype.hasOwnProperty.call(previous, uuid))
        {
            continue;
        }

        if (current[uuid])
        {
            continue;
        }

        var oldEntity = c.getServer().getEntity(String(uuid));

        if (oldEntity != null && oldEntity.isLivingBase())
        {
            punishLeaving(oldEntity, caster.getName());
        }
    }

    state.affected = current;
    state.age = Number(state.age || 0) + INTERVAL;

    if (state.age >= DURATION)
    {
        caster.send("Insignia de Caballero soldu.");
        mappet.set(key, null);
        return;
    }

    mappet.set(key, state);
    c.scheduleScript(INTERVAL, function (context)
    {
        loop(context, key, runId);
    });
}