Advertisement
Deedlit

sample 1

Aug 8th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package com.l2jserver.gameserver.ai.ext.tasks;
  16.  
  17. import com.l2jserver.gameserver.ai.ext.AI_TaskQueue;
  18. import com.l2jserver.gameserver.ai.ext.struct.task.AITaskSimpleVar;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.util.Rnd;
  21.  
  22. /**
  23.  * ==============================================<br>
  24.  * RandomSayTask - This task will make NPC char "talk" on chat, some message
  25.  * we wish to. By default, task has starting random chance between 1-7%. On each task weight
  26.  * update cycle, chance increases by another random 1-7%. Task disallows execution, if
  27.  * other of same type, has been executed, within last 10 seconds.<br>
  28.  * ==============================================<br>
  29.  * @author Deedlit(piotr@angakaran.cc, http://MMOPlay.eu)
  30.  */
  31. public class RandomSayTask extends AbstractAITask
  32. {
  33.     private String _msg;
  34.  
  35.     public RandomSayTask(L2Character actor, String msg)
  36.     {
  37.         super(actor.getTaskQueue(), 0, true, false, calculateWeightForPercentage(Rnd.qget(1, 7)), actor);
  38.         _msg = msg;
  39.     }
  40.  
  41.     @Override
  42.     protected void initTaskTypeName()
  43.     {
  44.         _name = "RandomSayTask";
  45.     }
  46.  
  47.     @Override
  48.     public boolean valid()
  49.     {
  50.         return hasAI() && !getActor().isDead() && !getAI().getIntention().isAttackingMode() && !getActor().isInPanic();
  51.     }
  52.  
  53.     @Override
  54.     public boolean ready()
  55.     {
  56.         return _msg != null && !_msg.isEmpty();
  57.     }
  58.  
  59.     @Override
  60.     public boolean run()
  61.     {
  62.         getActor().sendLongMsgAbove(_msg);
  63.         _msg = null;
  64.         return true;
  65.     }
  66.  
  67.     @Override
  68.     public boolean block_think_after_run()
  69.     {
  70.         return false;
  71.     }
  72.  
  73.     @Override
  74.     public int update_weight()
  75.     {
  76.         return getWeightProperLimits(weight(false) + calculateWeightForPercentage(Rnd.qget(1, 3)));
  77.     }
  78.  
  79.     @Override
  80.     public boolean valid_update_weight_delay()
  81.     {
  82.         return getLastWeightUpdateTimestamp() <= 0 || System.currentTimeMillis() - getLastWeightUpdateTimestamp() > 5000;
  83.     }
  84.  
  85.     @Override
  86.     public boolean removeable()
  87.     {
  88.         return (getTaskExecCounter(true) > 0 && execSuccess()) || !valid();
  89.     }
  90.  
  91.     @Override
  92.     public boolean valid_run_delay()
  93.     {
  94.         return getTaskLastExecTimestamp(false) <= 0 || System.currentTimeMillis() - getTaskLastExecTimestamp(false) >= 20000;
  95.     }
  96.  
  97.     @Override
  98.     public int max_task_instances()
  99.     {
  100.         return -1;
  101.     }
  102.  
  103.     @Override
  104.     public void on_variable_listener(AITaskSimpleVar.LISTENER_EVENTS event, AITaskSimpleVar variable)
  105.     {
  106.         // ignored
  107.     }
  108.  
  109.     @Override
  110.     public void on_added_to_queue(AI_TaskQueue queue)
  111.     {
  112.         // ignored
  113.     }
  114.  
  115.     @Override
  116.     public void on_remove_from_queue(AI_TaskQueue queue)
  117.     {
  118.         // ignored
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement