/** * Обработка активации ловушки. * * @param object объект, который изменил свое положение. */ public boolean activate(TObject object) { if (!object.isCharacter()) return false; Character owner = getOwner(); Character target = object.getCharacter(); if (owner == null || owner == target || !owner.checkTarget(target)) { return false; } float dist = target.getGeomDistance(x, y); if (dist > radius) { return false; } if (lifeTask != null) { lifeTask.cancel(false); lifeTask = null; } ExecutorManager executor = ExecutorManager.getInstance(); executor.scheduleGeneral(this, 100); return true; }
@Override public boolean start() { lock(); try { if (isStarted()) { return false; } if (eventTerritory != null) { eventTerritory.addListener(this); } ObjectEventManager objectEventManager = ObjectEventManager.getInstance(); objectEventManager.addDeleteListener(this); objectEventManager.addDieListener(this); time = getRegisterTime(); EventManager eventManager = EventManager.getInstance(); eventManager.start(this); World.sendAnnounce("Запущен автоматический ивент \"" + getName() + "\""); setStarted(true); setState(EventState.REGISTER); ExecutorManager executor = ExecutorManager.getInstance(); schedule = executor.scheduleGeneralAtFixedRate(this, 60000, 60000); return true; } finally { unlock(); } }
/** * Спавн в мир ловушку. * * @param owner владелец. * @param skill скил ловушки. * @param lifeTime время жизни. * @param radius радиус активации. */ public void spawnMe(Character owner, Skill skill, int range, int lifeTime, int radius) { this.owner = owner; this.skill = skill; this.radius = radius; spawnMe( Coords.calcX(owner.getX(), range, owner.getHeading()), Coords.calcY(owner.getY(), range, owner.getHeading()), owner.getZ(), 0); LocalObjects local = LocalObjects.get(); Array<Character> chars = World.getAround(Character.class, local.getNextCharList(), this, radius); ExecutorManager executor = ExecutorManager.getInstance(); if (chars.isEmpty()) this.lifeTask = executor.scheduleGeneral(this, lifeTime * 1000); else { Character[] array = chars.array(); for (int i = 0, length = chars.size(); i < length; i++) { Character target = array[i]; if (owner.checkTarget(target)) { executor.scheduleGeneral(this, 100); return; } } this.lifeTask = executor.scheduleGeneral(this, lifeTime * 1000); } }