Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.ai.ext.tasks;
- import com.l2jserver.gameserver.ai.ext.AI_TaskQueue;
- import com.l2jserver.gameserver.ai.ext.struct.task.AITaskSimpleVar;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.util.Rnd;
- /**
- * ==============================================<br>
- * RandomSayTask - This task will make NPC char "talk" on chat, some message
- * we wish to. By default, task has starting random chance between 1-7%. On each task weight
- * update cycle, chance increases by another random 1-7%. Task disallows execution, if
- * other of same type, has been executed, within last 10 seconds.<br>
- * ==============================================<br>
- * @author Deedlit(piotr@angakaran.cc, http://MMOPlay.eu)
- */
- public class RandomSayTask extends AbstractAITask
- {
- private String _msg;
- public RandomSayTask(L2Character actor, String msg)
- {
- super(actor.getTaskQueue(), 0, true, false, calculateWeightForPercentage(Rnd.qget(1, 7)), actor);
- _msg = msg;
- }
- @Override
- protected void initTaskTypeName()
- {
- _name = "RandomSayTask";
- }
- @Override
- public boolean valid()
- {
- return hasAI() && !getActor().isDead() && !getAI().getIntention().isAttackingMode() && !getActor().isInPanic();
- }
- @Override
- public boolean ready()
- {
- return _msg != null && !_msg.isEmpty();
- }
- @Override
- public boolean run()
- {
- getActor().sendLongMsgAbove(_msg);
- _msg = null;
- return true;
- }
- @Override
- public boolean block_think_after_run()
- {
- return false;
- }
- @Override
- public int update_weight()
- {
- return getWeightProperLimits(weight(false) + calculateWeightForPercentage(Rnd.qget(1, 3)));
- }
- @Override
- public boolean valid_update_weight_delay()
- {
- return getLastWeightUpdateTimestamp() <= 0 || System.currentTimeMillis() - getLastWeightUpdateTimestamp() > 5000;
- }
- @Override
- public boolean removeable()
- {
- return (getTaskExecCounter(true) > 0 && execSuccess()) || !valid();
- }
- @Override
- public boolean valid_run_delay()
- {
- return getTaskLastExecTimestamp(false) <= 0 || System.currentTimeMillis() - getTaskLastExecTimestamp(false) >= 20000;
- }
- @Override
- public int max_task_instances()
- {
- return -1;
- }
- @Override
- public void on_variable_listener(AITaskSimpleVar.LISTENER_EVENTS event, AITaskSimpleVar variable)
- {
- // ignored
- }
- @Override
- public void on_added_to_queue(AI_TaskQueue queue)
- {
- // ignored
- }
- @Override
- public void on_remove_from_queue(AI_TaskQueue queue)
- {
- // ignored
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement