Class WeightedMultiBehavior
- All Implemented Interfaces:
IBehavior
,IBehaviorEvaluator
,IBehaviorExecutor
IBehavior
组成的组(注意和行为组IBehaviorGroup
区分)调用方法
execute(EntityIntelligent)
前,必须调用此对象的评估函数以确认激活的是哪个行为在评估时,会评估所有包含的子行为
筛选出返回成功的行为后,会选取最高优先级的那一组
如果到这一步依然存在多个行为,则会根据行为的
IBehavior.getWeight()
方法的返回值随机选取其中一个作为执行行为
A group consisting of multiple behaviors IBehavior
(note the distinction with behavior groups IBehaviorGroup
)
Before calling the method execute(EntityIntelligent)
, the evaluation function of this object must be called to confirm which behavior is activated
During evaluation, all contained child behaviors are evaluated
After filtering out the behaviors that return success, the group with the highest priority is selected
If there are still multiple behaviors at this point, one of them is randomly selected for execution based on the return value of the IBehavior.getWeight()
method of the behavior
-
Field Summary
Modifier and TypeFieldDescriptionprotected IBehavior
protected final int
此组的优先级。在BehaviorGroup中,获取优先级将会返回此值指代整个组的优先级Fields inherited from class cn.nukkit.entity.ai.behavior.AbstractBehavior
behaviorState
-
Constructor Summary
ConstructorDescriptionWeightedMultiBehavior
(int priority, IBehavior... behaviors) WeightedMultiBehavior
(int priority, Set<IBehavior> behaviors) -
Method Summary
Modifier and TypeMethodDescriptionboolean
evaluate
(EntityIntelligent entity) 是否需要激活与其绑定的执行器evaluateBehaviors
(EntityIntelligent entity) boolean
execute
(EntityIntelligent entity) 调度器将会持续执行此执行器,直到返回false,或者执行器被中断
此方法每gt都会调用int
此组的优先级。在BehaviorGroup中,获取优先级将会返回此值指代整个组的优先级void
onInterrupt
(EntityIntelligent entity) 行为非正常中断时(例如被更高级行为覆盖)调用void
onStart
(EntityIntelligent entity) 行为评估成功后,进入激活状态前调用void
onStop
(EntityIntelligent entity) 行为正常结束时(execute()方法返回false)调用void
setCurrentBehavior
(IBehavior currentBehavior) Methods inherited from class cn.nukkit.entity.ai.behavior.AbstractBehavior
getBehaviorState, setBehaviorState
-
Field Details
-
priority
protected final int priority此组的优先级。在BehaviorGroup中,获取优先级将会返回此值指代整个组的优先级The priority of this group. In Behavior Group, getting the priority will return this value to refer to the priority of the entire group
-
behaviors
-
currentBehavior
-
-
Constructor Details
-
WeightedMultiBehavior
-
WeightedMultiBehavior
-
-
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
-
onInterrupt
Description copied from interface:IBehaviorExecutor
行为非正常中断时(例如被更高级行为覆盖)调用Called when behavior breaks abnormally (e.g. overridden by higher-level behavior)
- Parameters:
entity
- 目标实体
-
onStart
Description copied from interface:IBehaviorExecutor
行为评估成功后,进入激活状态前调用After the behavior evaluation is successful, it is called before entering the active state
- Parameters:
entity
- 目标实体
-
onStop
Description copied from interface:IBehaviorExecutor
行为正常结束时(execute()方法返回false)调用Called when the behavior ends normally (the execute() method returns false)
- Parameters:
entity
- 目标实体
-
evaluateBehaviors
- Parameters:
entity
- 实体- Returns:
- 最高优先级且评估成功的一组行为(包含评估结果)
-
getPriority
public int getPriority()此组的优先级。在BehaviorGroup中,获取优先级将会返回此值指代整个组的优先级The priority of this group. In Behavior Group, getting the priority will return this value to refer to the priority of the entire group
- Returns:
- 优先级
-
getBehaviors
-
getCurrentBehavior
-
setCurrentBehavior
-