Class Behavior
- All Implemented Interfaces:
IBehavior
,IBehaviorEvaluator
,IBehaviorExecutor
A single behavior object, containing an executor and an evaluator, with the behavior object delegating their methods
-
Field Summary
Modifier and TypeFieldDescriptionprotected IBehaviorEvaluator
protected IBehaviorExecutor
protected final int
protected final int
protected final int
Fields inherited from class cn.nukkit.entity.ai.behavior.AbstractBehavior
behaviorState
-
Constructor Summary
ConstructorDescriptionBehavior
(IBehaviorExecutor executor, IBehaviorEvaluator evaluator) Behavior
(IBehaviorExecutor executor, IBehaviorEvaluator evaluator, int priority) Behavior
(IBehaviorExecutor executor, IBehaviorEvaluator evaluator, int priority, int weight) Behavior
(IBehaviorExecutor executor, IBehaviorEvaluator evaluator, int priority, int weight, int period) -
Method Summary
Modifier and TypeMethodDescriptionboolean
evaluate
(EntityIntelligent entity) 是否需要激活与其绑定的执行器boolean
execute
(EntityIntelligent entity) 调度器将会持续执行此执行器,直到返回false,或者执行器被中断
此方法每gt都会调用int
返回此行为的刷新周期,小的刷新周期会使得评估器被更频繁的调用。注意此方法只会影响评估器的调用,而不会影响执行器的调用。int
返回此行为的优先级,高优先级的行为会覆盖低优先级的行为int
返回此行为的权重值,高权重的行为有更大几率被选中void
onInterrupt
(EntityIntelligent entity) 行为非正常中断时(例如被更高级行为覆盖)调用void
onStart
(EntityIntelligent entity) 行为评估成功后,进入激活状态前调用void
onStop
(EntityIntelligent entity) 行为正常结束时(execute()方法返回false)调用toString()
Methods inherited from class cn.nukkit.entity.ai.behavior.AbstractBehavior
getBehaviorState, setBehaviorState
-
Field Details
-
priority
protected final int priority -
weight
protected final int weight -
period
protected final int period -
executor
-
evaluator
-
-
Constructor Details
-
Behavior
-
Behavior
-
Behavior
-
Behavior
public Behavior(IBehaviorExecutor executor, IBehaviorEvaluator evaluator, int priority, int weight, int period)
-
-
Method Details
-
evaluate
Description copied from interface:IBehaviorEvaluator
是否需要激活与其绑定的执行器这个方法对一个行为只会评估一次,评估通过则开始运行执行器执行行为,直到行为中断或者完成,下一次评估才会开始
Whether the executor bound to it needs to be activated
This method evaluates a behavior only once, and if the evaluation passes, the executor execution behavior will start running until the behavior is interrupted or completed, and the next evaluation will not begin
- Parameters:
entity
- 评估目标实体
Assess the targetEntity- Returns:
- 是否需要激活
Do you need to activate
-
execute
Description copied from interface:IBehaviorExecutor
调度器将会持续执行此执行器,直到返回false,或者执行器被中断
此方法每gt都会调用The scheduler will continue to execute this executor until it returns false or the executor is interrupted
This method will be called every gt- Parameters:
entity
- 执行目标实体- Returns:
- boolean
-
onStart
Description copied from interface:IBehaviorExecutor
行为评估成功后,进入激活状态前调用After the behavior evaluation is successful, it is called before entering the active state
- Parameters:
entity
- 目标实体
-
onInterrupt
Description copied from interface:IBehaviorExecutor
行为非正常中断时(例如被更高级行为覆盖)调用Called when behavior breaks abnormally (e.g. overridden by higher-level behavior)
- Parameters:
entity
- 目标实体
-
onStop
Description copied from interface:IBehaviorExecutor
行为正常结束时(execute()方法返回false)调用Called when the behavior ends normally (the execute() method returns false)
- Parameters:
entity
- 目标实体
-
toString
-
getPriority
public int getPriority()Description copied from interface:IBehavior
返回此行为的优先级,高优先级的行为会覆盖低优先级的行为Returns the priority of this behavior, with higher-priority behaviors overriding lower-priority ones
- Returns:
- 优先级
-
getWeight
public int getWeight()Description copied from interface:IBehavior
返回此行为的权重值,高权重的行为有更大几率被选中Returns the weight value of the behavior, with higher weights having a higher chance of being selected
- Returns:
- 权重值
-
getPeriod
public int getPeriod()Description copied from interface:IBehavior
返回此行为的刷新周期,小的刷新周期会使得评估器被更频繁的调用。注意此方法只会影响评估器的调用,而不会影响执行器的调用。Returns the refresh period for this behavior, a small refresh period will cause the evaluator to be called more often. Note that this method only affects evaluator calls, not executor calls.
- Returns:
- 刷新周期
Refresh period
-
getExecutor
-
getEvaluator
-