@esengine/behavior-tree 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.es5.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var e,t,o,r,n,i,s=require("@esengine/ecs-framework");function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=Array(t);o<t;o++)r[o]=e[o];return r}function d(e,t,o,r,n,i,s){try{var a=e[i](s),d=a.value}catch(e){return void o(e)}a.done?t(d):Promise.resolve(d).then(r,n)}function u(e){return function(){var t=this,o=arguments;return new Promise((function(r,n){var i=e.apply(t,o);function s(e){d(i,r,n,s,a,"next",e)}function a(e){d(i,r,n,s,a,"throw",e)}s(void 0)}))}}function c(e,t){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return(o=o.call(e)).next.bind(o);if(Array.isArray(e)||(o=function(e,t){if(e){if("string"==typeof e)return a(e,t);var o={}.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?a(e,t):void 0}}(e))||t){o&&(e=o);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)({}).hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},p.apply(null,arguments)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,m(e,t)}function f(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(f=function(){return!!e})()}function v(){
1
+ "use strict";var e,t=require("@esengine/ecs-framework");exports.TaskStatus=void 0,(e=exports.TaskStatus||(exports.TaskStatus={}))[e.Invalid=0]="Invalid",e[e.Success=1]="Success",e[e.Failure=2]="Failure",e[e.Running=3]="Running";var r,n,o,a,i={Composite:"composite",Decorator:"decorator",Action:"action",Condition:"condition"};function s(){return{status:exports.TaskStatus.Invalid,currentChildIndex:0}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function c(e,t,r,n,o,a,i){try{var s=e[a](i),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,o)}function d(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function i(e){c(a,n,o,i,s,"next",e)}function s(e){c(a,n,o,i,s,"throw",e)}i(void 0)}))}}function l(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return u(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e))||t){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},p.apply(null,arguments)}function f(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,m(e,t)}function h(){
2
2
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
- var e,t,o="function"==typeof Symbol?Symbol:{},r=o.iterator||"@@iterator",n=o.toStringTag||"@@toStringTag";function i(o,r,n,i){var d=r&&r.prototype instanceof a?r:a,u=Object.create(d.prototype);return y(u,"_invoke",function(o,r,n){var i,a,d,u=0,c=n||[],p=!1,l={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(t,o){return i=t,a=0,d=e,l.n=o,s}};function h(o,r){for(a=o,d=r,t=0;!p&&u&&!n&&t<c.length;t++){var n,i=c[t],h=l.p,f=i[2];o>3?(n=f===r)&&(d=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=h&&((n=o<2&&h<i[1])?(a=0,l.v=r,l.n=i[1]):h<f&&(n=o<3||i[0]>r||r>f)&&(i[4]=o,i[5]=r,l.n=f,a=0))}if(n||o>1)return s;throw p=!0,r}return function(n,c,f){if(u>1)throw TypeError("Generator is already running");for(p&&1===c&&h(c,f),a=c,d=f;(t=a<2?e:d)||!p;){i||(a?a<3?(a>1&&(l.n=-1),h(a,d)):l.n=d:l.v=d);try{if(u=2,i){if(a||(n="next"),t=i[n]){if(!(t=t.call(i,d)))throw TypeError("iterator result is not an object");if(!t.done)return t;d=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(d=TypeError("The iterator does not provide a '"+n+"' method"),a=1);i=e}else if((t=(p=l.n<0)?d:o.call(r,l))!==s)break}catch(t){i=e,a=1,d=t}finally{u=1}}return{value:t,done:p}}}(o,n,i),!0),u}var s={};function a(){}function d(){}function u(){}t=Object.getPrototypeOf;var c=[][r]?t(t([][r]())):(y(t={},r,(function(){return this})),t),p=u.prototype=a.prototype=Object.create(c);function l(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,y(e,n,"GeneratorFunction")),e.prototype=Object.create(p),e}return d.prototype=u,y(p,"constructor",u),y(u,"constructor",d),d.displayName="GeneratorFunction",y(u,n,"GeneratorFunction"),y(p),y(p,n,"Generator"),y(p,r,(function(){return this})),y(p,"toString",(function(){return"[object Generator]"})),(v=function(){return{w:i,m:l}})()}function y(e,t,o,r){var n=Object.defineProperty;try{n({},"",{})}catch(e){n=0}y=function(e,t,o,r){function i(t,o){y(e,t,(function(e){return this._invoke(t,o,e)}))}t?n?n(e,t,{value:o,enumerable:!r,configurable:!r,writable:!r}):e[t]=o:(i("next",0),i("throw",1),i("return",2))},y(e,t,o,r)}function m(e,t){return m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},m(e,t)}function g(e){var t="function"==typeof Map?new Map:void 0;return g=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return function(e,t,o){if(f())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var n=new(e.bind.apply(e,r));return o&&m(n,o.prototype),n}(e,arguments,l(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),m(o,e)},g(e)}function x(e,t,o,r){var n,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(i<3?n(s):i>3?n(t,o,s):n(t,o))||s);return i>3&&s&&Object.defineProperty(t,o,s),s}function b(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError,exports.TaskStatus=void 0,(e=exports.TaskStatus||(exports.TaskStatus={}))[e.Invalid=0]="Invalid",e[e.Success=1]="Success",e[e.Failure=2]="Failure",e[e.Running=3]="Running",exports.NodeType=void 0,(t=exports.NodeType||(exports.NodeType={})).Composite="composite",t.Decorator="decorator",t.Action="action",t.Condition="condition",exports.CompositeType=void 0,(o=exports.CompositeType||(exports.CompositeType={})).Sequence="sequence",o.Selector="selector",o.Parallel="parallel",o.ParallelSelector="parallel-selector",o.RandomSequence="random-sequence",o.RandomSelector="random-selector",exports.DecoratorType=void 0,(r=exports.DecoratorType||(exports.DecoratorType={})).Inverter="inverter",r.Repeater="repeater",r.UntilSuccess="until-success",r.UntilFail="until-fail",r.AlwaysSucceed="always-succeed",r.AlwaysFail="always-fail",r.Conditional="conditional",r.Cooldown="cooldown",r.Timeout="timeout",exports.AbortType=void 0,(n=exports.AbortType||(exports.AbortType={})).None="none",n.Self="self",n.LowerPriority="lower-priority",n.Both="both",exports.BlackboardValueType=void 0,(i=exports.BlackboardValueType||(exports.BlackboardValueType={})).String="string",i.Number="number",i.Boolean="boolean",i.Vector2="vector2",i.Vector3="vector3",i.Object="object",i.Array="array";var C=function(){function e(){}return e.registerNodeClass=function(e,t){var o=t.category+":"+t.displayName;this.nodeClasses.set(o,{metadata:t,constructor:e})},e.getAllNodeClasses=function(){return Array.from(this.nodeClasses.values())},e.getNodeClass=function(e,t){var o,r=e+":"+t;return null===(o=this.nodeClasses.get(r))||void 0===o?void 0:o.constructor},e.clear=function(){this.nodeClasses.clear()},e}();function T(e){return function(t){var o=p({},e,{className:t.name});return C.registerNodeClass(t,o),t}}function S(e){return function(t,o){t.constructor.__nodeProperties||(t.constructor.__nodeProperties=[]),t.constructor.__nodeProperties.push(p({name:o},e))}}C.nodeClasses=new Map;var N,w,k=S;function B(){return C.getAllNodeClasses().map((function(e){var t=e.metadata,o=e.constructor,r=o.__nodeProperties||[],n={nodeType:t.type.toLowerCase()},i=new o,s=r.map((function(e){var t=i[e.name];return void 0!==t&&(n[e.name]=t),p({},e,{defaultValue:void 0!==t?t:e.defaultValue})}));switch(t.type){case exports.NodeType.Composite:n.compositeType=t.displayName;break;case exports.NodeType.Decorator:n.decoratorType=t.displayName;break;case exports.NodeType.Action:n.actionType=t.displayName;break;case exports.NodeType.Condition:n.conditionType=t.displayName}return{type:t.type,displayName:t.displayName,category:t.category,icon:t.icon,description:t.description,color:t.color,className:t.className,requiresChildren:t.requiresChildren,defaultConfig:n,properties:s}}))}exports.ExecuteAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).actionCode="return TaskStatus.Success;",t.parameters={},t}h(t,e);var o=t.prototype;return o.getFunction=function(){var e=this;if(!this.compiledFunction&&this.actionCode)try{var t=new Function("entity","blackboard","deltaTime","parameters","TaskStatus","\n const { Success, Failure, Running, Invalid } = TaskStatus;\n try {\n "+this.actionCode+"\n } catch (error) {\n return TaskStatus.Failure;\n }\n ");this.compiledFunction=function(o,r,n){return t(o,r,n,e.parameters,exports.TaskStatus)||exports.TaskStatus.Success}}catch(e){return}return this.compiledFunction},o.setFunction=function(e){this.compiledFunction=e},t}(s.Component),x([S({label:"动作代码",type:"code",description:"JavaScript 代码,返回 TaskStatus",required:!0}),s.Serialize(),b("design:type",String)],exports.ExecuteAction.prototype,"actionCode",void 0),x([s.Serialize(),b("design:type",Object)],exports.ExecuteAction.prototype,"parameters",void 0),x([s.IgnoreSerialization(),b("design:type",Function)],exports.ExecuteAction.prototype,"compiledFunction",void 0),exports.ExecuteAction=x([T({displayName:"自定义动作",category:"动作",type:exports.NodeType.Action,icon:"Code",description:"执行自定义代码",color:"#FFC107"}),s.ECSComponent("ExecuteAction"),s.Serializable({version:1})],exports.ExecuteAction),exports.WaitAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).waitTime=1,t.elapsedTime=0,t}return h(t,e),t.prototype.reset=function(){this.elapsedTime=0},t}(s.Component),x([S({label:"等待时间",type:"number",min:0,step:.1,description:"等待时间(秒)",required:!0}),s.Serialize(),b("design:type",Number)],exports.WaitAction.prototype,"waitTime",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.WaitAction.prototype,"elapsedTime",void 0),exports.WaitAction=x([T({displayName:"等待",category:"动作",type:exports.NodeType.Action,icon:"Clock",description:"等待指定时间",color:"#9E9E9E"}),s.ECSComponent("WaitAction"),s.Serializable({version:1})],exports.WaitAction),exports.LogAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).message="Hello",t.level="log",t.includeEntityInfo=!1,t}return h(t,e),t}(s.Component),x([S({label:"消息",type:"string",required:!0}),s.Serialize(),b("design:type",String)],exports.LogAction.prototype,"message",void 0),x([S({label:"级别",type:"select",options:[{label:"Log",value:"log"},{label:"Info",value:"info"},{label:"Warn",value:"warn"},{label:"Error",value:"error"}]}),s.Serialize(),b("design:type",String)],exports.LogAction.prototype,"level",void 0),x([S({label:"包含实体信息",type:"boolean"}),s.Serialize(),b("design:type",Boolean)],exports.LogAction.prototype,"includeEntityInfo",void 0),exports.LogAction=x([T({displayName:"日志",category:"动作",type:exports.NodeType.Action,icon:"FileText",description:"输出日志消息",color:"#673AB7"}),s.ECSComponent("LogAction"),s.Serializable({version:1})],exports.LogAction),exports.SetBlackboardValueAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.value="",t.force=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.SetBlackboardValueAction.prototype,"variableName",void 0),x([S({label:"值",type:"string",description:"可以使用 {{varName}} 引用其他变量"}),s.Serialize(),b("design:type",Object)],exports.SetBlackboardValueAction.prototype,"value",void 0),x([s.Serialize(),b("design:type",String)],exports.SetBlackboardValueAction.prototype,"sourceVariable",void 0),x([s.Serialize(),b("design:type",Boolean)],exports.SetBlackboardValueAction.prototype,"force",void 0),exports.SetBlackboardValueAction=x([T({displayName:"设置变量",category:"动作",type:exports.NodeType.Action,icon:"Edit",description:"设置黑板变量的值",color:"#3F51B5"}),s.ECSComponent("SetBlackboardValueAction"),s.Serializable({version:1})],exports.SetBlackboardValueAction),exports.ModifyOperation=void 0,(N=exports.ModifyOperation||(exports.ModifyOperation={})).Add="add",N.Subtract="subtract",N.Multiply="multiply",N.Divide="divide",N.Modulo="modulo",N.Append="append",N.Remove="remove",exports.ModifyBlackboardValueAction=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.operation=exports.ModifyOperation.Add,t.operand=0,t.force=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.ModifyBlackboardValueAction.prototype,"variableName",void 0),x([S({label:"操作类型",type:"select",options:[{label:"加法",value:"add"},{label:"减法",value:"subtract"},{label:"乘法",value:"multiply"},{label:"除法",value:"divide"},{label:"取模",value:"modulo"},{label:"追加",value:"append"},{label:"移除",value:"remove"}]}),s.Serialize(),b("design:type",String)],exports.ModifyBlackboardValueAction.prototype,"operation",void 0),x([S({label:"操作数",type:"string",description:"可以是固定值或变量引用 {{varName}}"}),s.Serialize(),b("design:type",Object)],exports.ModifyBlackboardValueAction.prototype,"operand",void 0),x([s.Serialize(),b("design:type",Boolean)],exports.ModifyBlackboardValueAction.prototype,"force",void 0),exports.ModifyBlackboardValueAction=x([T({displayName:"修改变量",category:"动作",type:exports.NodeType.Action,icon:"Calculator",description:"对黑板变量执行数学或逻辑操作",color:"#FF9800"}),s.ECSComponent("ModifyBlackboardValueAction"),s.Serializable({version:1})],exports.ModifyBlackboardValueAction),exports.CompareOperator=void 0,(w=exports.CompareOperator||(exports.CompareOperator={})).Equal="equal",w.NotEqual="notEqual",w.Greater="greater",w.GreaterOrEqual="greaterOrEqual",w.Less="less",w.LessOrEqual="lessOrEqual",w.Contains="contains",w.Matches="matches",exports.BlackboardCompareCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.operator=exports.CompareOperator.Equal,t.compareValue=null,t.invertResult=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.BlackboardCompareCondition.prototype,"variableName",void 0),x([S({label:"运算符",type:"select",options:[{label:"等于",value:"equal"},{label:"不等于",value:"notEqual"},{label:"大于",value:"greater"},{label:"大于等于",value:"greaterOrEqual"},{label:"小于",value:"less"},{label:"小于等于",value:"lessOrEqual"},{label:"包含",value:"contains"},{label:"正则匹配",value:"matches"}]}),s.Serialize(),b("design:type",String)],exports.BlackboardCompareCondition.prototype,"operator",void 0),x([S({label:"比较值",type:"string",description:"可以是固定值或变量引用 {{varName}}"}),s.Serialize(),b("design:type",Object)],exports.BlackboardCompareCondition.prototype,"compareValue",void 0),x([S({label:"反转结果",type:"boolean"}),s.Serialize(),b("design:type",Boolean)],exports.BlackboardCompareCondition.prototype,"invertResult",void 0),exports.BlackboardCompareCondition=x([T({displayName:"比较变量",category:"条件",type:exports.NodeType.Condition,icon:"Scale",description:"比较黑板变量与指定值",color:"#2196F3"}),s.ECSComponent("BlackboardCompareCondition"),s.Serializable({version:1})],exports.BlackboardCompareCondition),exports.BlackboardExistsCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variableName="",t.checkNotNull=!1,t.invertResult=!1,t}return h(t,e),t}(s.Component),x([S({label:"变量名",type:"variable",required:!0}),s.Serialize(),b("design:type",String)],exports.BlackboardExistsCondition.prototype,"variableName",void 0),x([S({label:"检查非空",type:"boolean",description:"检查值不为 null/undefined"}),s.Serialize(),b("design:type",Boolean)],exports.BlackboardExistsCondition.prototype,"checkNotNull",void 0),x([S({label:"反转结果",type:"boolean",description:"检查不存在"}),s.Serialize(),b("design:type",Boolean)],exports.BlackboardExistsCondition.prototype,"invertResult",void 0),exports.BlackboardExistsCondition=x([T({displayName:"检查变量存在",category:"条件",type:exports.NodeType.Condition,icon:"Search",description:"检查黑板变量是否存在",color:"#00BCD4"}),s.ECSComponent("BlackboardExistsCondition"),s.Serializable({version:1})],exports.BlackboardExistsCondition),exports.RandomProbabilityCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).probability=.5,t.alwaysRandomize=!0,t}h(t,e);var o=t.prototype;return o.evaluate=function(){return(this.alwaysRandomize||void 0===this.cachedResult)&&(this.cachedResult=Math.random()<this.probability),this.cachedResult},o.reset=function(){this.cachedResult=void 0},t}(s.Component),x([S({label:"成功概率",type:"number",min:0,max:1,step:.1,description:"0.0 - 1.0",required:!0}),s.Serialize(),b("design:type",Number)],exports.RandomProbabilityCondition.prototype,"probability",void 0),x([S({label:"总是重新随机",type:"boolean",description:"false则第一次随机后固定结果"}),s.Serialize(),b("design:type",Boolean)],exports.RandomProbabilityCondition.prototype,"alwaysRandomize",void 0),exports.RandomProbabilityCondition=x([T({displayName:"随机概率",category:"条件",type:exports.NodeType.Condition,icon:"Dice",description:"根据概率返回成功或失败",color:"#E91E63"}),s.ECSComponent("RandomProbabilityCondition"),s.Serializable({version:1})],exports.RandomProbabilityCondition),exports.ExecuteCondition=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).parameters={},t.invertResult=!1,t}h(t,e);var o=t.prototype;return o.getFunction=function(){var e=this;if(!this.compiledFunction&&this.conditionCode)try{var t=new Function("entity","blackboard","deltaTime","parameters","\n try {\n "+this.conditionCode+"\n } catch (error) {\n return false;\n }\n ");this.compiledFunction=function(o,r,n){return Boolean(t(o,r,n,e.parameters))}}catch(e){return}return this.compiledFunction},o.setFunction=function(e){this.compiledFunction=e},t}(s.Component),x([S({label:"条件代码",type:"code",description:"JavaScript 代码,返回 boolean",required:!0}),s.Serialize(),b("design:type",String)],exports.ExecuteCondition.prototype,"conditionCode",void 0),x([s.Serialize(),b("design:type",Object)],exports.ExecuteCondition.prototype,"parameters",void 0),x([S({label:"反转结果",type:"boolean"}),s.Serialize(),b("design:type",Boolean)],exports.ExecuteCondition.prototype,"invertResult",void 0),x([s.IgnoreSerialization(),b("design:type",Function)],exports.ExecuteCondition.prototype,"compiledFunction",void 0),exports.ExecuteCondition=x([T({displayName:"自定义条件",category:"条件",type:exports.NodeType.Condition,icon:"Code",description:"执行自定义条件代码",color:"#9C27B0"}),s.ECSComponent("ExecuteCondition"),s.Serializable({version:1})],exports.ExecuteCondition),exports.CompositeNodeComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).compositeType=exports.CompositeType.Sequence,t.shuffledIndices=[],t.reshuffleOnRestart=!0,t}h(t,e);var o=t.prototype;return o.getNextChildIndex=function(e,t){return this.compositeType===exports.CompositeType.RandomSequence||this.compositeType===exports.CompositeType.RandomSelector?((0===this.shuffledIndices.length||0===e&&this.reshuffleOnRestart)&&this.shuffleIndices(t),e<this.shuffledIndices.length?this.shuffledIndices[e]:t):e},o.shuffleIndices=function(e){this.shuffledIndices=Array.from({length:e},(function(e,t){return t}));for(var t=this.shuffledIndices.length-1;t>0;t--){var o=Math.floor(Math.random()*(t+1)),r=[this.shuffledIndices[o],this.shuffledIndices[t]];this.shuffledIndices[t]=r[0],this.shuffledIndices[o]=r[1]}},o.resetShuffle=function(){this.shuffledIndices=[]},t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.CompositeNodeComponent.prototype,"compositeType",void 0),exports.CompositeNodeComponent=x([s.ECSComponent("CompositeNode"),s.Serializable({version:1})],exports.CompositeNodeComponent),exports.SequenceNode=function(e){function t(){var t;return(t=e.call(this)||this).abortType=exports.AbortType.None,t.compositeType=exports.CompositeType.Sequence,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"中止类型",type:"select",description:"条件变化时的中止行为",options:[{label:"无",value:"none"},{label:"自身",value:"self"},{label:"低优先级",value:"lower-priority"},{label:"两者",value:"both"}]}),s.Serialize(),b("design:type",String)],exports.SequenceNode.prototype,"abortType",void 0),exports.SequenceNode=x([T({displayName:"序列",category:"组合",type:exports.NodeType.Composite,icon:"List",description:"按顺序执行子节点,全部成功才成功",color:"#4CAF50"}),s.ECSComponent("SequenceNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.SequenceNode),exports.SelectorNode=function(e){function t(){var t;return(t=e.call(this)||this).abortType=exports.AbortType.None,t.compositeType=exports.CompositeType.Selector,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"中止类型",type:"select",description:"条件变化时的中止行为",options:[{label:"无",value:"none"},{label:"自身",value:"self"},{label:"低优先级",value:"lower-priority"},{label:"两者",value:"both"}]}),s.Serialize(),b("design:type",String)],exports.SelectorNode.prototype,"abortType",void 0),exports.SelectorNode=x([T({displayName:"选择",category:"组合",type:exports.NodeType.Composite,icon:"GitBranch",description:"按顺序执行子节点,任一成功则成功",color:"#8BC34A"}),s.ECSComponent("SelectorNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.SelectorNode),exports.ParallelNode=function(e){function t(){var t;return(t=e.call(this)||this).successPolicy="all",t.failurePolicy="one",t.compositeType=exports.CompositeType.Parallel,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"成功策略",type:"select",description:"多少个子节点成功时整体成功",options:[{label:"全部成功",value:"all"},{label:"任意一个成功",value:"one"}]}),s.Serialize(),b("design:type",String)],exports.ParallelNode.prototype,"successPolicy",void 0),x([S({label:"失败策略",type:"select",description:"多少个子节点失败时整体失败",options:[{label:"任意一个失败",value:"one"},{label:"全部失败",value:"all"}]}),s.Serialize(),b("design:type",String)],exports.ParallelNode.prototype,"failurePolicy",void 0),exports.ParallelNode=x([T({displayName:"并行",category:"组合",type:exports.NodeType.Composite,icon:"Layers",description:"同时执行所有子节点",color:"#CDDC39"}),s.ECSComponent("ParallelNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.ParallelNode),exports.ParallelSelectorNode=function(e){function t(){var t;return(t=e.call(this)||this).failurePolicy="all",t.compositeType=exports.CompositeType.ParallelSelector,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"失败策略",type:"select",description:"多少个子节点失败时整体失败",options:[{label:"任意一个失败",value:"one"},{label:"全部失败",value:"all"}]}),s.Serialize(),b("design:type",String)],exports.ParallelSelectorNode.prototype,"failurePolicy",void 0),exports.ParallelSelectorNode=x([T({displayName:"并行选择",category:"组合",type:exports.NodeType.Composite,icon:"Sparkles",description:"并行执行子节点,任一成功则成功",color:"#FFC107"}),s.ECSComponent("ParallelSelectorNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.ParallelSelectorNode),exports.RandomSequenceNode=function(e){function t(){var t;return(t=e.call(this)||this).reshuffleOnRestart=!0,t.compositeType=exports.CompositeType.RandomSequence,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"重启时重新洗牌",type:"boolean",description:"每次重启时是否重新随机子节点顺序"}),s.Serialize(),b("design:type",Boolean)],exports.RandomSequenceNode.prototype,"reshuffleOnRestart",void 0),exports.RandomSequenceNode=x([T({displayName:"随机序列",category:"组合",type:exports.NodeType.Composite,icon:"Shuffle",description:"随机顺序执行子节点序列",color:"#FF5722"}),s.ECSComponent("RandomSequenceNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RandomSequenceNode),exports.RandomSelectorNode=function(e){function t(){var t;return(t=e.call(this)||this).reshuffleOnRestart=!0,t.compositeType=exports.CompositeType.RandomSelector,t}return h(t,e),t}(exports.CompositeNodeComponent),x([S({label:"重启时重新洗牌",type:"boolean",description:"每次重启时是否重新随机子节点顺序"}),s.Serialize(),b("design:type",Boolean)],exports.RandomSelectorNode.prototype,"reshuffleOnRestart",void 0),exports.RandomSelectorNode=x([T({displayName:"随机选择",category:"组合",type:exports.NodeType.Composite,icon:"Dices",description:"随机顺序执行子节点选择",color:"#F44336"}),s.ECSComponent("RandomSelectorNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RandomSelectorNode),exports.SubTreeNode=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).assetId="",t.inheritParentBlackboard=!0,t.propagateFailure=!0,t.preload=!0,t.subTreeCompleted=!1,t.subTreeResult=exports.TaskStatus.Invalid,t}h(t,e);var o=t.prototype;return o.getSubTreeRoot=function(){return this.subTreeRoot},o.setSubTreeRoot=function(e){this.subTreeRoot=e,this.subTreeCompleted=!1,this.subTreeResult=exports.TaskStatus.Invalid},o.markSubTreeCompleted=function(e){this.subTreeCompleted=!0,this.subTreeResult=e},o.isSubTreeCompleted=function(){return this.subTreeCompleted},o.getSubTreeResult=function(){return this.subTreeResult},o.reset=function(){this.subTreeRoot=void 0,this.subTreeCompleted=!1,this.subTreeResult=exports.TaskStatus.Invalid},o.resetCompletionState=function(){this.subTreeCompleted=!1,this.subTreeResult=exports.TaskStatus.Invalid},o.validate=function(){var e=[];return this.assetId&&""!==this.assetId.trim()||e.push("SubTree 节点必须指定资产ID"),e},t}(exports.CompositeNodeComponent),x([S({label:"资产ID",type:"asset",description:"要引用的行为树资产ID"}),s.Serialize(),b("design:type",String)],exports.SubTreeNode.prototype,"assetId",void 0),x([S({label:"继承父黑板",type:"boolean",description:"子树是否可以访问父树的黑板变量"}),s.Serialize(),b("design:type",Boolean)],exports.SubTreeNode.prototype,"inheritParentBlackboard",void 0),x([S({label:"传播失败",type:"boolean",description:"子树失败时是否传播失败状态"}),s.Serialize(),b("design:type",Boolean)],exports.SubTreeNode.prototype,"propagateFailure",void 0),x([S({label:"预加载",type:"boolean",description:"在行为树启动时预加载子树,避免运行时加载延迟"}),s.Serialize(),b("design:type",Boolean)],exports.SubTreeNode.prototype,"preload",void 0),exports.SubTreeNode=x([T({displayName:"子树",category:"组合",type:exports.NodeType.Composite,icon:"GitBranch",description:"引用并执行外部行为树文件(不支持静态子节点)",color:"#FF9800",requiresChildren:!1}),s.ECSComponent("SubTreeNode"),s.Serializable({version:1})],exports.SubTreeNode),exports.DecoratorNodeComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).decoratorType=exports.DecoratorType.Inverter,t}return h(t,e),t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.DecoratorNodeComponent.prototype,"decoratorType",void 0),exports.DecoratorNodeComponent=x([s.ECSComponent("DecoratorNode"),s.Serializable({version:1})],exports.DecoratorNodeComponent),exports.InverterNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.Inverter,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.InverterNode=x([T({displayName:"反转",category:"装饰器",type:exports.NodeType.Decorator,icon:"RotateCcw",description:"反转子节点的执行结果",color:"#607D8B"}),s.ECSComponent("InverterNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.InverterNode),exports.RepeaterNode=function(e){function t(){var t;return(t=e.call(this)||this).repeatCount=1,t.endOnFailure=!1,t.currentRepeatCount=0,t.decoratorType=exports.DecoratorType.Repeater,t}h(t,e);var o=t.prototype;return o.incrementRepeat=function(){this.currentRepeatCount++},o.shouldContinueRepeat=function(){return-1===this.repeatCount||this.currentRepeatCount<this.repeatCount},o.reset=function(){this.currentRepeatCount=0},t}(exports.DecoratorNodeComponent),x([S({label:"重复次数",type:"number",min:-1,step:1,description:"-1表示无限重复",required:!0}),s.Serialize(),b("design:type",Number)],exports.RepeaterNode.prototype,"repeatCount",void 0),x([S({label:"失败时停止",type:"boolean",description:"子节点失败时是否停止重复"}),s.Serialize(),b("design:type",Boolean)],exports.RepeaterNode.prototype,"endOnFailure",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.RepeaterNode.prototype,"currentRepeatCount",void 0),exports.RepeaterNode=x([T({displayName:"重复",category:"装饰器",type:exports.NodeType.Decorator,icon:"Repeat",description:"重复执行子节点指定次数",color:"#9E9E9E"}),s.ECSComponent("RepeaterNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RepeaterNode),exports.UntilSuccessNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.UntilSuccess,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.UntilSuccessNode=x([T({displayName:"直到成功",category:"装饰器",type:exports.NodeType.Decorator,icon:"CheckCircle",description:"重复执行子节点直到成功",color:"#4CAF50"}),s.ECSComponent("UntilSuccessNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.UntilSuccessNode),exports.UntilFailNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.UntilFail,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.UntilFailNode=x([T({displayName:"直到失败",category:"装饰器",type:exports.NodeType.Decorator,icon:"XCircle",description:"重复执行子节点直到失败",color:"#F44336"}),s.ECSComponent("UntilFailNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.UntilFailNode),exports.AlwaysSucceedNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.AlwaysSucceed,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.AlwaysSucceedNode=x([T({displayName:"总是成功",category:"装饰器",type:exports.NodeType.Decorator,icon:"ThumbsUp",description:"无论子节点结果如何都返回成功",color:"#8BC34A"}),s.ECSComponent("AlwaysSucceedNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.AlwaysSucceedNode),exports.AlwaysFailNode=function(e){function t(){var t;return(t=e.call(this)||this).decoratorType=exports.DecoratorType.AlwaysFail,t}return h(t,e),t}(exports.DecoratorNodeComponent),exports.AlwaysFailNode=x([T({displayName:"总是失败",category:"装饰器",type:exports.NodeType.Decorator,icon:"ThumbsDown",description:"无论子节点结果如何都返回失败",color:"#FF5722"}),s.ECSComponent("AlwaysFailNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.AlwaysFailNode),exports.ConditionalNode=function(e){function t(){var t;return(t=e.call(this)||this).shouldReevaluate=!0,t.decoratorType=exports.DecoratorType.Conditional,t}h(t,e);var o=t.prototype;return o.evaluateCondition=function(e,t){if(!this.conditionCode)return!1;if(!this.compiledCondition)try{var o=new Function("entity","blackboard","\n try {\n return Boolean("+this.conditionCode+");\n } catch (error) {\n return false;\n }\n ");this.compiledCondition=function(e,t){return Boolean(o(e,t))}}catch(e){return!1}return this.compiledCondition(e,t)},o.setConditionFunction=function(e){this.compiledCondition=e},t}(exports.DecoratorNodeComponent),x([S({label:"条件代码",type:"code",description:"JavaScript 代码,返回 boolean",required:!0}),s.Serialize(),b("design:type",String)],exports.ConditionalNode.prototype,"conditionCode",void 0),x([S({label:"重新评估条件",type:"boolean",description:"每次执行时是否重新评估条件"}),s.Serialize(),b("design:type",Boolean)],exports.ConditionalNode.prototype,"shouldReevaluate",void 0),x([s.IgnoreSerialization(),b("design:type",Function)],exports.ConditionalNode.prototype,"compiledCondition",void 0),exports.ConditionalNode=x([T({displayName:"条件装饰器",category:"装饰器",type:exports.NodeType.Decorator,icon:"Filter",description:"基于条件判断是否执行子节点",color:"#3F51B5"}),s.ECSComponent("ConditionalNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.ConditionalNode),exports.CooldownNode=function(e){function t(){var t;return(t=e.call(this)||this).cooldownTime=1,t.lastExecutionTime=0,t.decoratorType=exports.DecoratorType.Cooldown,t}h(t,e);var o=t.prototype;return o.canExecute=function(e){return 0===this.lastExecutionTime||e-this.lastExecutionTime>=this.cooldownTime},o.recordExecution=function(e){this.lastExecutionTime=e},o.reset=function(){this.lastExecutionTime=0},t}(exports.DecoratorNodeComponent),x([S({label:"冷却时间",type:"number",min:0,step:.1,description:"冷却时间(秒)",required:!0}),s.Serialize(),b("design:type",Number)],exports.CooldownNode.prototype,"cooldownTime",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.CooldownNode.prototype,"lastExecutionTime",void 0),exports.CooldownNode=x([T({displayName:"冷却",category:"装饰器",type:exports.NodeType.Decorator,icon:"Timer",description:"在冷却时间内阻止子节点执行",color:"#00BCD4"}),s.ECSComponent("CooldownNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.CooldownNode),exports.TimeoutNode=function(e){function t(){var t;return(t=e.call(this)||this).timeoutDuration=5,t.startTime=0,t.decoratorType=exports.DecoratorType.Timeout,t}h(t,e);var o=t.prototype;return o.recordStartTime=function(e){0===this.startTime&&(this.startTime=e)},o.isTimeout=function(e){return 0!==this.startTime&&e-this.startTime>=this.timeoutDuration},o.reset=function(){this.startTime=0},t}(exports.DecoratorNodeComponent),x([S({label:"超时时间",type:"number",min:0,step:.1,description:"超时时间(秒)",required:!0}),s.Serialize(),b("design:type",Number)],exports.TimeoutNode.prototype,"timeoutDuration",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.TimeoutNode.prototype,"startTime",void 0),exports.TimeoutNode=x([T({displayName:"超时",category:"装饰器",type:exports.NodeType.Decorator,icon:"Clock",description:"子节点执行超时则返回失败",color:"#FF9800"}),s.ECSComponent("TimeoutNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.TimeoutNode),exports.BehaviorTreeNode=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).nodeType=exports.NodeType.Action,t.nodeName="Node",t.status=exports.TaskStatus.Invalid,t.currentChildIndex=0,t}h(t,e);var o=t.prototype;return o.reset=function(){this.status=exports.TaskStatus.Invalid,this.currentChildIndex=0},o.invalidate=function(){this.reset()},t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeNode.prototype,"nodeType",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeNode.prototype,"nodeName",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.BehaviorTreeNode.prototype,"status",void 0),x([s.IgnoreSerialization(),b("design:type",Number)],exports.BehaviorTreeNode.prototype,"currentChildIndex",void 0),exports.BehaviorTreeNode=x([s.ECSComponent("BehaviorTreeNode"),s.Serializable({version:1})],exports.BehaviorTreeNode);var A=function(){function e(){this.variables=new Map}var t=e.prototype;return t.dispose=function(){this.variables.clear()},t.defineVariable=function(e,t,o,r){var n;this.variables.set(e,{name:e,type:t,value:o,readonly:null!==(n=null==r?void 0:r.readonly)&&void 0!==n&&n,description:null==r?void 0:r.description})},t.getValue=function(e){var t=this.variables.get(e);return null==t?void 0:t.value},t.setValue=function(e,t,o){void 0===o&&(o=!1);var r=this.variables.get(e);return!!r&&(!(r.readonly&&!o)&&(r.value=t,!0))},t.hasVariable=function(e){return this.variables.has(e)},t.removeVariable=function(e){return this.variables.delete(e)},t.getVariableNames=function(){return Array.from(this.variables.keys())},t.getAllVariables=function(){return Array.from(this.variables.values())},t.clear=function(){this.variables.clear()},t.setVariables=function(e){for(var t=0,o=Object.entries(e);t<o.length;t++){var r=o[t],n=r[0],i=r[1],s=this.variables.get(n);s&&!s.readonly&&(s.value=i)}},t.getVariables=function(e){for(var t,o={},r=c(e);!(t=r()).done;){var n=t.value,i=this.getValue(n);void 0!==i&&(o[n]=i)}return o},t.exportConfig=function(){return{version:"1.0",variables:Array.from(this.variables.values())}},t.importConfig=function(e){this.variables.clear();for(var t,o=c(e.variables);!(t=o()).done;){var r=t.value;this.variables.set(r.name,r)}},t.toJSON=function(){return JSON.stringify(this.exportConfig(),null,2)},e.fromJSON=function(e){return JSON.parse(e)},e}();exports.BlackboardComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).variables=new Map,t.useGlobalBlackboard=!0,t}h(t,e);var o=t.prototype;return o.defineVariable=function(e,t,o,r){var n;this.variables.set(e,{name:e,type:t,value:o,readonly:null!==(n=null==r?void 0:r.readonly)&&void 0!==n&&n,description:null==r?void 0:r.description})},o.getValue=function(e){var t=this.variables.get(e);return void 0!==t?t.value:this.useGlobalBlackboard?s.Core.services.resolve(A).getValue(e):void 0},o.getLocalValue=function(e){var t=this.variables.get(e);return null==t?void 0:t.value},o.setValue=function(e,t,o){void 0===o&&(o=!1);var r=this.variables.get(e);return r?!(r.readonly&&!o)&&(r.value=t,!0):!!this.useGlobalBlackboard&&s.Core.services.resolve(A).setValue(e,t,o)},o.setLocalValue=function(e,t,o){void 0===o&&(o=!1);var r=this.variables.get(e);return!!r&&(!(r.readonly&&!o)&&(r.value=t,!0))},o.hasVariable=function(e){return!!this.variables.has(e)||!!this.useGlobalBlackboard&&s.Core.services.resolve(A).hasVariable(e)},o.hasLocalVariable=function(e){return this.variables.has(e)},o.removeVariable=function(e){return this.variables.delete(e)},o.getVariableNames=function(){return Array.from(this.variables.keys())},o.clear=function(){this.variables.clear()},o.setUseGlobalBlackboard=function(e){this.useGlobalBlackboard=e},o.isUsingGlobalBlackboard=function(){return this.useGlobalBlackboard},o.getAllVariables=function(){var e=Array.from(this.variables.values());if(this.useGlobalBlackboard){var t=s.Core.services.resolve(A).getAllVariables(),o=new Set(this.variables.keys()),r=t.filter((function(e){return!o.has(e.name)}));return[].concat(e,r)}return e},t.getGlobalBlackboard=function(){return s.Core.services.resolve(A)},t}(s.Component),x([s.Serialize(),b("design:type",Map)],exports.BlackboardComponent.prototype,"variables",void 0),exports.BlackboardComponent=x([s.ECSComponent("Blackboard"),s.Serializable({version:1})],exports.BlackboardComponent),exports.ActiveNode=function(e){function t(){return e.apply(this,arguments)||this}return h(t,e),t}(s.Component),exports.ActiveNode=x([s.ECSComponent("ActiveNode")],exports.ActiveNode);var E=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).bindings=new Map,t}h(t,e);var o=t.prototype;return o.addBinding=function(e,t){this.bindings.set(e,t)},o.getBinding=function(e){return this.bindings.get(e)},o.hasBinding=function(e){return this.bindings.has(e)},o.clearBindings=function(){this.bindings.clear()},t}(s.Component);exports.LogOutput=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).messages=[],t}h(t,e);var o=t.prototype;return o.addMessage=function(e,t){void 0===t&&(t="log"),this.messages.push({timestamp:Date.now(),message:e,level:t})},o.clear=function(){this.messages=[]},t}(s.Component),exports.LogOutput=x([s.ECSComponent("LogOutput")],exports.LogOutput),exports.BehaviorTreeAssetMetadata=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).assetId="",t.assetVersion="",t.assetName="",t.loadedAt=0,t.description="",t}return h(t,e),t.prototype.initialize=function(e,t,o){this.assetId=e,this.assetVersion=t,this.assetName=o||e,this.loadedAt=Date.now()},t}(s.Component),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"assetId",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"assetVersion",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"assetName",void 0),x([s.Serialize(),b("design:type",Number)],exports.BehaviorTreeAssetMetadata.prototype,"loadedAt",void 0),x([s.Serialize(),b("design:type",String)],exports.BehaviorTreeAssetMetadata.prototype,"description",void 0),exports.BehaviorTreeAssetMetadata=x([s.ECSComponent("BehaviorTreeAssetMetadata"),s.Serializable({version:1})],exports.BehaviorTreeAssetMetadata),exports.RootNode=function(e){function t(){var t;return(t=e.call(this)||this).compositeType=exports.CompositeType.Sequence,t}return h(t,e),t}(exports.CompositeNodeComponent),exports.RootNode=x([T({displayName:"根节点",category:"根节点",type:exports.NodeType.Composite,icon:"TreePine",description:"行为树的根节点",color:"#FFD700"}),s.ECSComponent("RootNode"),s.Serializable({version:1}),b("design:paramtypes",[])],exports.RootNode);const R=new TextEncoder;function I(e,t,o){e.length>50?function(e,t,o){R.encodeInto(e,t.subarray(o))}(e,t,o):function(e,t,o){const r=e.length;let n=o,i=0;for(;i<r;){let o=e.charCodeAt(i++);if(4294967168&o){if(4294965248&o){if(o>=55296&&o<=56319&&i<r){const t=e.charCodeAt(i);56320==(64512&t)&&(++i,o=((1023&o)<<10)+(1023&t)+65536)}4294901760&o?(t[n++]=o>>18&7|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128):(t[n++]=o>>12&15|224,t[n++]=o>>6&63|128)}else t[n++]=o>>6&31|192;t[n++]=63&o|128}else t[n++]=o}}(e,t,o)}function L(e,t,o){let r=t;const n=r+o,i=[];let s="";for(;r<n;){const t=e[r++];if(128&t)if(192==(224&t)){const o=63&e[r++];i.push((31&t)<<6|o)}else if(224==(240&t)){const o=63&e[r++],n=63&e[r++];i.push((31&t)<<12|o<<6|n)}else if(240==(248&t)){let o=(7&t)<<18|(63&e[r++])<<12|(63&e[r++])<<6|63&e[r++];o>65535&&(o-=65536,i.push(o>>>10&1023|55296),o=56320|1023&o),i.push(o)}else i.push(t);else i.push(t);i.length>=4096&&(s+=String.fromCharCode(...i),i.length=0)}return i.length>0&&(s+=String.fromCharCode(...i)),s}const F=new TextDecoder;function U(e,t,o){return o>200?function(e,t,o){const r=e.subarray(t,t+o);return F.decode(r)}(e,t,o):L(e,t,o)}class z{constructor(e,t){this.type=e,this.data=t}}class P extends Error{constructor(e){super(e);const t=Object.create(P.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:P.name})}}const M=4294967295;function D(e,t,o){const r=Math.floor(o/4294967296),n=o;e.setUint32(t,r),e.setUint32(t+4,n)}function O(e,t){return 4294967296*e.getInt32(t)+e.getUint32(t+4)}const V={type:-1,encode:function(e){if(e instanceof Date){return function({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=17179869183){if(0===t&&e<=4294967295){const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}{const o=e/4294967296,r=4294967295&e,n=new Uint8Array(8),i=new DataView(n.buffer);return i.setUint32(0,t<<2|3&o),i.setUint32(4,r),n}}{const o=new Uint8Array(12),r=new DataView(o.buffer);return r.setUint32(0,t),D(r,4,e),o}}(function(e){const t=e.getTime(),o=Math.floor(t/1e3),r=1e6*(t-1e3*o),n=Math.floor(r/1e9);return{sec:o+n,nsec:r-1e9*n}}(e))}return null},decode:function(e){const t=function(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{const e=t.getUint32(0);return{sec:4294967296*(3&e)+t.getUint32(4),nsec:e>>>2}}case 12:return{sec:O(t,4),nsec:t.getUint32(0)};default:throw new P(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}(e);return new Date(1e3*t.sec+t.nsec/1e6)}};class q{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(V)}register({type:e,encode:t,decode:o}){if(e>=0)this.encoders[e]=t,this.decoders[e]=o;else{const r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=o}}tryToEncode(e,t){for(let o=0;o<this.builtInEncoders.length;o++){const r=this.builtInEncoders[o];if(null!=r){const n=r(e,t);if(null!=n){return new z(-1-o,n)}}}for(let o=0;o<this.encoders.length;o++){const r=this.encoders[o];if(null!=r){const n=r(e,t);if(null!=n){return new z(o,n)}}}return e instanceof z?e:null}decode(e,t,o){const r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,o):new z(t,e)}}function j(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):function(e){return e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer}(e)?new Uint8Array(e):Uint8Array.from(e)}q.defaultCodec=new q;class W{constructor(e){this.entered=!1,this.extensionCodec=e?.extensionCodec??q.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??100,this.initialBufferSize=e?.initialBufferSize??2048,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new W({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered){return this.clone().encodeSharedRef(e)}try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered){return this.clone().encode(e)}try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);null==e?this.encodeNil():"boolean"==typeof e?this.encodeBoolean(e):"number"==typeof e?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):"string"==typeof e?this.encodeString(e):this.useBigInt64&&"bigint"==typeof e?this.encodeBigInt64(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){const t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(2*t)}resizeBuffer(e){const t=new ArrayBuffer(e),o=new Uint8Array(t),r=new DataView(t);o.set(this.bytes),this.view=r,this.bytes=o}encodeNil(){this.writeU8(192)}encodeBoolean(e){!1===e?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else{if(!(e<4294967296))throw new Error(`Too long string: ${e} bytes in UTF-8`);this.writeU8(219),this.writeU32(e)}}encodeString(e){const t=function(e){const t=e.length;let o=0,r=0;for(;r<t;){let n=e.charCodeAt(r++);if(4294967168&n)if(4294965248&n){if(n>=55296&&n<=56319&&r<t){const t=e.charCodeAt(r);56320==(64512&t)&&(++r,n=((1023&n)<<10)+(1023&t)+65536)}o+=4294901760&n?4:3}else o+=2;else o++}return o}(e);this.ensureBufferSizeToWrite(5+t),this.writeStringHeader(t),I(e,this.bytes,this.pos),this.pos+=t}encodeObject(e,t){const o=this.extensionCodec.tryToEncode(e,this.context);if(null!=o)this.encodeExtension(o);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else{if("object"!=typeof e)throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`);this.encodeMap(e,t)}}encodeBinary(e){const t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else{if(!(t<4294967296))throw new Error(`Too large binary: ${t}`);this.writeU8(198),this.writeU32(t)}const o=j(e);this.writeU8a(o)}encodeArray(e,t){const o=e.length;if(o<16)this.writeU8(144+o);else if(o<65536)this.writeU8(220),this.writeU16(o);else{if(!(o<4294967296))throw new Error(`Too large array: ${o}`);this.writeU8(221),this.writeU32(o)}for(const o of e)this.doEncode(o,t+1)}countWithoutUndefined(e,t){let o=0;for(const r of t)void 0!==e[r]&&o++;return o}encodeMap(e,t){const o=Object.keys(e);this.sortKeys&&o.sort();const r=this.ignoreUndefined?this.countWithoutUndefined(e,o):o.length;if(r<16)this.writeU8(128+r);else if(r<65536)this.writeU8(222),this.writeU16(r);else{if(!(r<4294967296))throw new Error(`Too large map object: ${r}`);this.writeU8(223),this.writeU32(r)}for(const r of o){const o=e[r];this.ignoreUndefined&&void 0===o||(this.encodeString(r),this.doEncode(o,t+1))}}encodeExtension(e){if("function"==typeof e.data){const t=e.data(this.pos+6),o=t.length;if(o>=4294967296)throw new Error(`Too large extension object: ${o}`);return this.writeU8(201),this.writeU32(o),this.writeI8(e.type),void this.writeU8a(t)}const t=e.data.length;if(1===t)this.writeU8(212);else if(2===t)this.writeU8(213);else if(4===t)this.writeU8(214);else if(8===t)this.writeU8(215);else if(16===t)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else{if(!(t<4294967296))throw new Error(`Too large extension object: ${t}`);this.writeU8(201),this.writeU32(t)}this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){const t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),function(e,t,o){const r=o/4294967296,n=o;e.setUint32(t,r),e.setUint32(t+4,n)}(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),D(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}}function _(e){return`${e<0?"-":""}0x${Math.abs(e).toString(16).padStart(2,"0")}`}const $="array",G="map_key",J="map_value",H=e=>{if("string"==typeof e||"number"==typeof e)return e;throw new P("The type of key must be string or number but "+typeof e)};class K{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){const t=this.getUninitializedStateFromPool();t.type=$,t.position=0,t.size=e,t.array=new Array(e)}pushMapState(e){const t=this.getUninitializedStateFromPool();t.type=G,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){const e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===$){const t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===G||e.type===J){const t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}const X=new DataView(new ArrayBuffer(0)),Z=new Uint8Array(X.buffer);try{X.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}const Q=new RangeError("Insufficient data"),Y=new class{constructor(e=16,t=16){this.hit=0,this.miss=0,this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,o){const r=this.caches[o-1];e:for(const n of r){const r=n.bytes;for(let n=0;n<o;n++)if(r[n]!==e[t+n])continue e;return n.str}return null}store(e,t){const o=this.caches[e.length-1],r={bytes:e,str:t};o.length>=this.maxLengthPerKey?o[Math.random()*o.length|0]=r:o.push(r)}decode(e,t,o){const r=this.find(e,t,o);if(null!=r)return this.hit++,r;this.miss++;const n=L(e,t,o),i=Uint8Array.prototype.slice.call(e,t,t+o);return this.store(i,n),n}};class ee{constructor(e){this.totalPos=0,this.pos=0,this.view=X,this.bytes=Z,this.headByte=-1,this.stack=new K,this.entered=!1,this.extensionCodec=e?.extensionCodec??q.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??M,this.maxBinLength=e?.maxBinLength??M,this.maxArrayLength=e?.maxArrayLength??M,this.maxMapLength=e?.maxMapLength??M,this.maxExtLength=e?.maxExtLength??M,this.keyDecoder=void 0!==e?.keyDecoder?e.keyDecoder:Y,this.mapKeyConverter=e?.mapKeyConverter??H}clone(){return new ee({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=-1,this.stack.reset()}setBuffer(e){const t=j(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(-1!==this.headByte||this.hasRemaining(1)){const t=this.bytes.subarray(this.pos),o=j(e),r=new Uint8Array(t.length+o.length);r.set(t),r.set(o,t.length),this.setBuffer(r)}else this.setBuffer(e)}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){const{view:t,pos:o}=this;return new RangeError(`Extra ${t.byteLength-o} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered){return this.clone().decode(e)}try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);const t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){const t=this.clone();yield*t.decodeMulti(e)}else try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered){return this.clone().decodeAsync(e)}try{this.entered=!0;let t,o=!1;for await(const r of e){if(o)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{t=this.doDecodeSync(),o=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(o){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return t}const{headByte:r,pos:n,totalPos:i}=this;throw new RangeError(`Insufficient data in parsing ${_(r)} at ${i} (${n} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){const o=this.clone();yield*o.decodeMultiAsync(e,t)}else try{this.entered=!0;let o=t,r=-1;for await(const n of e){if(t&&0===r)throw this.createExtraByteError(this.totalPos);this.appendBuffer(n),o&&(r=this.readArraySize(),o=!1,this.complete());try{for(;yield this.doDecodeSync(),0!==--r;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){const e=this.readHeadByte();let t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){const o=e-128;if(0!==o){this.pushMapState(o),this.complete();continue e}t={}}else if(e<160){const o=e-144;if(0!==o){this.pushArrayState(o),this.complete();continue e}t=[]}else{const o=e-160;t=this.decodeString(o,0)}else if(192===e)t=null;else if(194===e)t=!1;else if(195===e)t=!0;else if(202===e)t=this.readF32();else if(203===e)t=this.readF64();else if(204===e)t=this.readU8();else if(205===e)t=this.readU16();else if(206===e)t=this.readU32();else if(207===e)t=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(208===e)t=this.readI8();else if(209===e)t=this.readI16();else if(210===e)t=this.readI32();else if(211===e)t=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(217===e){const e=this.lookU8();t=this.decodeString(e,1)}else if(218===e){const e=this.lookU16();t=this.decodeString(e,2)}else if(219===e){const e=this.lookU32();t=this.decodeString(e,4)}else if(220===e){const e=this.readU16();if(0!==e){this.pushArrayState(e),this.complete();continue e}t=[]}else if(221===e){const e=this.readU32();if(0!==e){this.pushArrayState(e),this.complete();continue e}t=[]}else if(222===e){const e=this.readU16();if(0!==e){this.pushMapState(e),this.complete();continue e}t={}}else if(223===e){const e=this.readU32();if(0!==e){this.pushMapState(e),this.complete();continue e}t={}}else if(196===e){const e=this.lookU8();t=this.decodeBinary(e,1)}else if(197===e){const e=this.lookU16();t=this.decodeBinary(e,2)}else if(198===e){const e=this.lookU32();t=this.decodeBinary(e,4)}else if(212===e)t=this.decodeExtension(1,0);else if(213===e)t=this.decodeExtension(2,0);else if(214===e)t=this.decodeExtension(4,0);else if(215===e)t=this.decodeExtension(8,0);else if(216===e)t=this.decodeExtension(16,0);else if(199===e){const e=this.lookU8();t=this.decodeExtension(e,1)}else if(200===e){const e=this.lookU16();t=this.decodeExtension(e,2)}else{if(201!==e)throw new P(`Unrecognized type byte: ${_(e)}`);{const e=this.lookU32();t=this.decodeExtension(e,4)}}this.complete();const o=this.stack;for(;o.length>0;){const e=o.top();if(e.type===$){if(e.array[e.position]=t,e.position++,e.position!==e.size)continue e;t=e.array,o.release(e)}else{if(e.type===G){if("__proto__"===t)throw new P("The key __proto__ is not allowed");e.key=this.mapKeyConverter(t),e.type=J;continue e}if(e.map[e.key]=t,e.readCount++,e.readCount!==e.size){e.key=null,e.type=G;continue e}t=e.map,o.release(e)}}return t}}readHeadByte(){return-1===this.headByte&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=-1}readArraySize(){const e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new P(`Unrecognized array type byte: ${_(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new P(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new P(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new P(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw Q;const o=this.pos+t;let r;return r=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,o,e):U(this.bytes,o,e),this.pos+=t+e,r}stateIsMapKey(){if(this.stack.length>0){return this.stack.top().type===G}return!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new P(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw Q;const o=this.pos+t,r=this.bytes.subarray(o,o+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new P(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);const o=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,o,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){const e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){const e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){const e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){const e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){const e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){const e=(t=this.view,o=this.pos,4294967296*t.getUint32(o)+t.getUint32(o+4));var t,o;return this.pos+=8,e}readI64(){const e=O(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){const e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){const e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){const e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){const e=this.view.getFloat64(this.pos);return this.pos+=8,e}}function te(e,t){return new ee(t).decode(e)}var oe,re=function(){function e(){}return e.validate=function(e){var t=[],o=[];if(e.version||t.push("Missing version field"),e.metadata&&e.metadata.name||t.push("Missing or invalid metadata"),e.rootNodeId||t.push("Missing rootNodeId"),e.nodes&&Array.isArray(e.nodes)){var r=new Set;e.nodes.find((function(t){return t.id===e.rootNodeId}))||t.push("Root node '"+e.rootNodeId+"' not found in nodes array");for(var n,i=c(e.nodes);!(n=i()).done;){var s=n.value;if(s.id){if(r.has(s.id)&&t.push("Duplicate node id: "+s.id),r.add(s.id),s.nodeType||t.push("Node "+s.id+" missing nodeType"),s.children)for(var a,d=function(){var o=a.value;e.nodes.find((function(e){return e.id===o}))||t.push("Node "+s.id+" references non-existent child: "+o)},u=c(s.children);!(a=u()).done;)d()}else t.push("Node missing id field")}var p=new Set([e.rootNodeId]),l=function(t){var o=e.nodes.find((function(e){return e.id===t}));if(o&&o.children)for(var r,n=c(o.children);!(r=n()).done;){var i=r.value;p.add(i),l(i)}};l(e.rootNodeId);for(var h,f=c(e.nodes);!(h=f()).done;){var v=h.value;p.has(v.id)||o.push("Orphaned node detected: "+v.id+" ("+v.name+")")}}else t.push("Missing or invalid nodes array");if(e.blackboard&&Array.isArray(e.blackboard))for(var y,m=new Set,g=c(e.blackboard);!(y=g()).done;){var x=y.value;x.name?(m.has(x.name)&&t.push("Duplicate blackboard variable: "+x.name),m.add(x.name),x.type||t.push("Blackboard variable "+x.name+" missing type")):t.push("Blackboard variable missing name")}if(e.propertyBindings&&Array.isArray(e.propertyBindings))for(var b,C,T=new Set(e.nodes.map((function(e){return e.id}))),S=new Set((null===(b=e.blackboard)||void 0===b?void 0:b.map((function(e){return e.name})))||[]),N=c(e.propertyBindings);!(C=N()).done;){var w=C.value;T.has(w.nodeId)||t.push("Property binding references non-existent node: "+w.nodeId),S.has(w.variableName)||t.push("Property binding references non-existent variable: "+w.variableName),w.propertyName||t.push("Property binding missing propertyName")}return{valid:0===t.length,errors:t.length>0?t:void 0,warnings:o.length>0?o:void 0}},e.getStats=function(e){for(var t,o,r,n=0,i=0,s=0,a=0,d=c(e.nodes);!(r=d()).done;){switch(r.value.nodeType){case exports.NodeType.Action:n++;break;case exports.NodeType.Condition:i++;break;case exports.NodeType.Composite:s++;break;case exports.NodeType.Decorator:a++}}var u=function(t,o){void 0===o&&(o=0);var r=e.nodes.find((function(e){return e.id===t}));if(!r||!r.children||0===r.children.length)return o;for(var n,i=o,s=c(r.children);!(n=s()).done;){var a=n.value,d=u(a,o+1);i=Math.max(i,d)}return i};return{nodeCount:e.nodes.length,actionCount:n,conditionCount:i,compositeCount:s,decoratorCount:a,blackboardVariableCount:(null===(t=e.blackboard)||void 0===t?void 0:t.length)||0,propertyBindingCount:(null===(o=e.propertyBindings)||void 0===o?void 0:o.length)||0,maxDepth:u(e.rootNodeId)}},e}(),ne=s.createLogger("EditorFormatConverter"),ie=function(){function e(){}return e.toAsset=function(e,t){var o,r,n;ne.info("开始转换编辑器格式到资产格式");var i=this.findRootNode(e.nodes);if(!i)throw new Error("未找到根节点");var s={name:(null==t?void 0:t.name)||(null===(o=e.metadata)||void 0===o?void 0:o.name)||"Untitled Behavior Tree",description:(null==t?void 0:t.description)||(null===(r=e.metadata)||void 0===r?void 0:r.description),version:(null==t?void 0:t.version)||e.version||"1.0.0",createdAt:(null==t?void 0:t.createdAt)||(null===(n=e.metadata)||void 0===n?void 0:n.createdAt),modifiedAt:(null==t?void 0:t.modifiedAt)||(new Date).toISOString()},a=this.convertNodes(e.nodes),d=this.convertBlackboard(e.blackboard),u=this.convertPropertyBindings(e.connections,e.nodes,d),c={version:"1.0.0",metadata:s,rootNodeId:i.id,nodes:a,blackboard:d,propertyBindings:u.length>0?u:void 0};return ne.info("转换完成: "+a.length+"个节点, "+d.length+"个黑板变量, "+u.length+"个属性绑定"),c},e.findRootNode=function(e){return e.find((function(e){return"根节点"===e.template.category||"root"===e.data.nodeType}))||null},e.convertNodes=function(e){var t=this;return e.map((function(e){return t.convertNode(e)}))},e.convertNode=function(e){var t=p({},e.data);return delete t.nodeType,{id:e.id,name:e.template.displayName||e.data.name||"Node",nodeType:e.template.type,data:t,children:e.children||[]}},e.convertBlackboard=function(e){for(var t=[],o=0,r=Object.entries(e);o<r.length;o++){var n=r[o],i=n[0],s=n[1],a=this.inferBlackboardType(s);t.push({name:i,type:a,defaultValue:s})}return t},e.inferBlackboardType=function(e){return"number"==typeof e?exports.BlackboardValueType.Number:"string"==typeof e?exports.BlackboardValueType.String:"boolean"==typeof e?exports.BlackboardValueType.Boolean:exports.BlackboardValueType.Object},e.convertPropertyBindings=function(e,t,o){for(var r,n=[],i=new Set(o.map((function(e){return e.name}))),s=function(){var e,o=r.value,s=t.find((function(e){return e.id===o.from})),a=t.find((function(e){return e.id===o.to}));return s&&a&&o.toProperty?("blackboard-variable"===s.data.nodeType?e=s.data.variableName:o.fromProperty&&(e=o.fromProperty),e?i.has(e)?void n.push({nodeId:a.id,propertyName:o.toProperty,variableName:e}):(ne.warn("属性绑定引用了不存在的黑板变量: "+e),0):(ne.warn("无法确定变量名: from节点="+s.template.displayName),0)):(ne.warn("跳过无效的属性连接: from="+o.from+", to="+o.to),0)},a=c(e.filter((function(e){return"property"===e.connectionType})));!(r=a()).done;)s();return n},e.fromAsset=function(e){ne.info("开始转换资产格式到编辑器格式");for(var t,o=this.convertNodesFromAsset(e.nodes),r={},n=c(e.blackboard);!(t=n()).done;){var i=t.value;r[i.name]=i.defaultValue}var s=this.convertPropertyBindingsToConnections(e.propertyBindings||[],e.nodes),a=this.buildNodeConnections(e.nodes);s.push.apply(s,a);var d={version:e.metadata.version,metadata:{name:e.metadata.name,description:e.metadata.description,createdAt:e.metadata.createdAt,modifiedAt:e.metadata.modifiedAt},nodes:o,connections:s,blackboard:r,canvasState:{offset:{x:0,y:0},scale:1}};return ne.info("转换完成: "+o.length+"个节点, "+s.length+"个连接"),d},e.convertNodesFromAsset=function(e){var t=this;return e.map((function(e,o){var r={x:100+o%5*250,y:100+150*Math.floor(o/5)};return{id:e.id,template:{displayName:e.name,category:t.inferCategory(e.nodeType),type:e.nodeType},data:p({},e.data),position:r,children:e.children}}))},e.inferCategory=function(e){switch(e){case exports.NodeType.Action:return"动作";case exports.NodeType.Condition:return"条件";case exports.NodeType.Composite:return"组合";case exports.NodeType.Decorator:return"装饰器";default:return"其他"}},e.convertPropertyBindingsToConnections=function(e,t){for(var o,r=[],n=c(e);!(o=n()).done;){var i=o.value;r.push({from:"blackboard",to:i.nodeId,toProperty:i.propertyName,connectionType:"property"})}return r},e.buildNodeConnections=function(e){for(var t,o=[],r=c(e);!(t=r()).done;)for(var n,i=t.value,s=c(i.children);!(n=s()).done;){var a=n.value;o.push({from:i.id,to:a,connectionType:"node"})}return o},e}(),se=s.createLogger("BehaviorTreeAssetSerializer"),ae=function(){function e(){}return e.serialize=function(e,t){if(void 0===t&&(t={format:"json",pretty:!0}),!1!==t.validate){var o=re.validate(e);if(!o.valid){var r,n=(null===(r=o.errors)||void 0===r?void 0:r.join(", "))||"Unknown error";throw new Error("资产验证失败: "+n)}o.warnings&&o.warnings.length>0&&se.warn("资产验证警告: "+o.warnings.join(", "))}return"json"===t.format?this.serializeToJSON(e,t.pretty):this.serializeToBinary(e)},e.serializeToJSON=function(e,t){void 0===t&&(t=!0);try{var o=t?JSON.stringify(e,null,2):JSON.stringify(e);return se.info("已序列化为JSON: "+o.length+" 字符"),o}catch(e){throw new Error("JSON序列化失败: "+e)}},e.serializeToBinary=function(e){try{var t=(o=e,new W(r).encodeSharedRef(o));return se.info("已序列化为二进制: "+t.length+" 字节"),t}catch(e){throw new Error("二进制序列化失败: "+e)}var o,r},e.deserialize=function(e,t){var o;void 0===t&&(t={validate:!0,strict:!0});try{o="string"==typeof e?this.deserializeFromJSON(e):this.deserializeFromBinary(e)}catch(e){throw new Error("反序列化失败: "+e)}if(!1!==t.validate){var r=re.validate(o);if(!r.valid){var n,i=(null===(n=r.errors)||void 0===n?void 0:n.join(", "))||"Unknown error";if(t.strict)throw new Error("资产验证失败: "+i);se.error("资产验证失败: "+i)}r.warnings&&r.warnings.length>0&&se.warn("资产验证警告: "+r.warnings.join(", "))}return o},e.deserializeFromJSON=function(e){try{var t=JSON.parse(e);if(!t.rootNodeId&&t.nodes&&t.connections){se.info("检测到编辑器格式,正在转换为运行时资产格式...");var o=t,r=ie.toAsset(o);return se.info("已从编辑器格式转换: "+r.nodes.length+" 个节点"),r}var n=t;return se.info("已从运行时资产格式反序列化: "+n.nodes.length+" 个节点"),n}catch(e){throw new Error("JSON解析失败: "+e)}},e.deserializeFromBinary=function(e){try{var t=te(e);return se.info("已从二进制反序列化: "+t.nodes.length+" 个节点"),t}catch(e){throw new Error("二进制解码失败: "+e)}},e.detectFormat=function(e){return"string"==typeof e?"json":"binary"},e.getInfo=function(e){try{var t,o=this.detectFormat(e);t="json"===o?JSON.parse(e):te(e);var r=e.length;return{format:o,name:t.metadata.name,version:t.version,nodeCount:t.nodes.length,blackboardVariableCount:t.blackboard.length,size:r}}catch(e){return se.error("获取资产信息失败: "+e),null}},e.convert=function(e,t,o){void 0===o&&(o=!0);var r=this.deserialize(e,{validate:!1});return this.serialize(r,{format:t,pretty:o,validate:!1})},e.compareSize=function(e,t){var o=e.length,r=t.length,n=o-r;return{jsonSize:o,binarySize:r,compressionRatio:n/o*100,savedBytes:n}},e}(),de=s.createLogger("FileSystemAssetLoader"),ue=function(){function e(e){var t;this.cache=new Map,this.config={basePath:e.basePath,format:e.format,extension:e.extension||("json"===e.format?".btree.json":".btree.bin"),enableCache:null===(t=e.enableCache)||void 0===t||t,readFile:e.readFile||this.defaultReadFile.bind(this)},this.config.basePath=this.config.basePath.replace(/\\/g,"/").replace(/\/$/,"")}var t=e.prototype;return t.loadBehaviorTree=function(){var e=u(v().m((function e(t){var o,r,n,i,s;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if(!this.config.enableCache||!this.cache.has(t)){e.n=1;break}return de.debug("从缓存加载资产: "+t),e.a(2,this.cache.get(t));case 1:return de.info("加载行为树资产: "+t),e.p=2,o=this.resolveAssetPath(t),e.n=3,this.config.readFile(o);case 3:return r=e.v,n={validate:!0,strict:!0},i=ae.deserialize(r,n),this.config.enableCache&&this.cache.set(t,i),de.info("成功加载资产: "+t),e.a(2,i);case 4:throw e.p=4,s=e.v,de.error("加载资产失败: "+t,s),new Error("Failed to load behavior tree asset '"+t+"': "+s);case 5:return e.a(2)}}),e,this,[[2,4]])})));return function(t){return e.apply(this,arguments)}}(),t.exists=function(){var e=u(v().m((function e(t){var o;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if(!this.config.enableCache||!this.cache.has(t)){e.n=1;break}return e.a(2,!0);case 1:return e.p=1,o=this.resolveAssetPath(t),e.n=2,this.config.readFile(o);case 2:return e.a(2,!0);case 3:return e.p=3,e.v,e.a(2,!1)}}),e,this,[[1,3]])})));return function(t){return e.apply(this,arguments)}}(),t.preload=function(){var e=u(v().m((function e(t){var o,r=this;return v().w((function(e){for(;;)switch(e.n){case 0:return de.info("预加载 "+t.length+" 个资产..."),o=t.map((function(e){return r.loadBehaviorTree(e).catch((function(t){de.warn("预加载资产失败: "+e,t)}))})),e.n=1,Promise.all(o);case 1:de.info("预加载完成");case 2:return e.a(2)}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.unload=function(e){this.cache.has(e)&&(this.cache.delete(e),de.debug("卸载资产: "+e))},t.clearCache=function(){this.cache.clear(),de.info("缓存已清空")},t.getCacheSize=function(){return this.cache.size},t.dispose=function(){this.clearCache()},t.resolveAssetPath=function(e){var t=e.replace(/^\/+/,"");return this.config.basePath+"/"+t+this.config.extension},t.defaultReadFile=function(){var e=u(v().m((function e(t){var o,r,n,i,s;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if("undefined"==typeof window||"undefined"==typeof fetch){e.n=7;break}return e.n=1,fetch(t);case 1:if((o=e.v).ok){e.n=2;break}throw new Error("HTTP "+o.status+": "+o.statusText);case 2:if("binary"!==this.config.format){e.n=4;break}return e.n=3,o.arrayBuffer();case 3:return r=e.v,e.a(2,new Uint8Array(r));case 4:return e.n=5,o.text();case 5:case 11:return e.a(2,e.v);case 6:case 14:e.n=16;break;case 7:if("undefined"==typeof require){e.n=15;break}if(e.p=8,n=require("fs").promises,"binary"!==this.config.format){e.n=10;break}return e.n=9,n.readFile(t);case 9:return i=e.v,e.a(2,new Uint8Array(i));case 10:return e.n=11,n.readFile(t,"utf-8");case 12:e.n=14;break;case 13:throw e.p=13,s=e.v,new Error("Failed to read file '"+t+"': "+s);case 15:throw new Error("No default file reading implementation available. Please provide a custom readFile function in the config.");case 16:return e.a(2)}}),e,this,[[8,13]])})));return function(t){return e.apply(this,arguments)}}(),e}(),ce=s.createLogger("BehaviorTreeAssetLoader"),pe=function(){function e(){}return e.instantiate=function(e,t,o){void 0===o&&(o={}),ce.info("开始实例化行为树: "+e.metadata.name);for(var r,n=new Map,i=c(e.nodes);!(r=i()).done;){var s=r.value;n.set(s.id,s)}var a=n.get(e.rootNodeId);if(!a)throw new Error("未找到根节点: "+e.rootNodeId);var d=new Map,u=this.createEntityTree(a,n,d,t,o.namePrefix,o.asSubTree);return this.setupBlackboard(u,e.blackboard,o.blackboardOverrides),e.propertyBindings&&e.propertyBindings.length>0&&this.setupPropertyBindings(e.propertyBindings,d),ce.info("行为树实例化完成: "+e.nodes.length+" 个节点"),u},e.createEntityTree=function(e,t,o,r,n,i,s){void 0===s&&(s=!0);var a=n?n+"_"+e.name:e.name,d=r.createEntity(a);o.set(e.id,d);var u=d.addComponent(new exports.BehaviorTreeNode);u.nodeType=e.nodeType,u.nodeName=e.name,this.addNodeComponents(d,e,i&&s);for(var p,l=c(e.children);!(p=l()).done;){var h=p.value,f=t.get(h);if(f){var v=this.createEntityTree(f,t,o,r,n,i,!1);d.addChild(v)}else ce.warn("子节点未找到: "+h)}return d},e.addNodeComponents=function(e,t,o){void 0===o&&(o=!1);var r=t.nodeType,n=t.data,i=t.name;ce.debug("addNodeComponents: name="+i+", data.nodeType="+n.nodeType+", skipRootNode="+o),"root"===n.nodeType||"根节点"===i||"Root"===i?o?(ce.debug("跳过为子树根节点添加 RootNode: "+i),this.addCompositeComponent(e,"序列",n)):(ce.debug("添加 RootNode 组件: "+i),e.addComponent(new exports.RootNode)):r===exports.NodeType.Composite?this.addCompositeComponent(e,i,n):r===exports.NodeType.Decorator?this.addDecoratorComponent(e,i,n):r===exports.NodeType.Action?this.addActionComponent(e,i,n):r===exports.NodeType.Condition&&this.addConditionComponent(e,i,n)},e.addCompositeComponent=function(e,t,o){var r,n=t.toLowerCase();if(n.includes("sequence")||n.includes("序列"))e.addComponent(new exports.SequenceNode).abortType=null!==(r=o.abortType)&&void 0!==r?r:exports.AbortType.None;else if(n.includes("selector")||n.includes("选择")){var i;e.addComponent(new exports.SelectorNode).abortType=null!==(i=o.abortType)&&void 0!==i?i:exports.AbortType.None}else if(n.includes("parallelselector")||n.includes("并行选择")){var s;e.addComponent(new exports.ParallelSelectorNode).failurePolicy=null!==(s=o.failurePolicy)&&void 0!==s?s:"one"}else if(n.includes("parallel")||n.includes("并行")){var a,d,u=e.addComponent(new exports.ParallelNode);u.successPolicy=null!==(a=o.successPolicy)&&void 0!==a?a:"all",u.failurePolicy=null!==(d=o.failurePolicy)&&void 0!==d?d:"one"}else n.includes("randomsequence")||n.includes("随机序列")?e.addComponent(new exports.RandomSequenceNode):n.includes("randomselector")||n.includes("随机选择")?e.addComponent(new exports.RandomSelectorNode):ce.warn("未知的组合节点类型: "+t)},e.addDecoratorComponent=function(e,t,o){var r=t.toLowerCase();if(r.includes("inverter")||r.includes("反转"))e.addComponent(new exports.InverterNode);else if(r.includes("repeater")||r.includes("重复")){var n,i,s=e.addComponent(new exports.RepeaterNode);s.repeatCount=null!==(n=o.repeatCount)&&void 0!==n?n:-1,s.endOnFailure=null!==(i=o.endOnFailure)&&void 0!==i&&i}else if(r.includes("untilsuccess")||r.includes("直到成功"))e.addComponent(new exports.UntilSuccessNode);else if(r.includes("untilfail")||r.includes("直到失败"))e.addComponent(new exports.UntilFailNode);else if(r.includes("alwayssucceed")||r.includes("总是成功"))e.addComponent(new exports.AlwaysSucceedNode);else if(r.includes("alwaysfail")||r.includes("总是失败"))e.addComponent(new exports.AlwaysFailNode);else if(r.includes("conditional")||r.includes("条件装饰")){var a,d,u=e.addComponent(new exports.ConditionalNode);u.conditionCode=null!==(a=o.conditionCode)&&void 0!==a?a:"",u.shouldReevaluate=null===(d=o.shouldReevaluate)||void 0===d||d}else if(r.includes("cooldown")||r.includes("冷却")){var c;e.addComponent(new exports.CooldownNode).cooldownTime=null!==(c=o.cooldownTime)&&void 0!==c?c:1}else if(r.includes("timeout")||r.includes("超时")){var p;e.addComponent(new exports.TimeoutNode).timeoutDuration=null!==(p=o.timeoutDuration)&&void 0!==p?p:1}else ce.warn("未知的装饰器类型: "+t)},e.addActionComponent=function(e,t,o){var r,n=t.toLowerCase();if(n.includes("wait")||n.includes("等待"))e.addComponent(new exports.WaitAction).waitTime=null!==(r=o.waitTime)&&void 0!==r?r:1;else if(n.includes("log")||n.includes("日志")){var i,s,a=e.addComponent(new exports.LogAction);a.message=null!==(i=o.message)&&void 0!==i?i:"",a.level=null!==(s=o.level)&&void 0!==s?s:"log"}else if(n.includes("setblackboard")||n.includes("setvalue")||n.includes("设置变量")){var d,u=e.addComponent(new exports.SetBlackboardValueAction);u.variableName=null!==(d=o.variableName)&&void 0!==d?d:"",u.value=o.value}else if(n.includes("modifyblackboard")||n.includes("modifyvalue")||n.includes("修改变量")){var c,p,l,h=e.addComponent(new exports.ModifyBlackboardValueAction);h.variableName=null!==(c=o.variableName)&&void 0!==c?c:"",h.operation=null!==(p=o.operation)&&void 0!==p?p:"add",h.operand=null!==(l=o.operand)&&void 0!==l?l:0}else if(n.includes("execute")||n.includes("自定义")){var f;e.addComponent(new exports.ExecuteAction).actionCode=null!==(f=o.actionCode)&&void 0!==f?f:"return TaskStatus.Success;"}else ce.warn("未知的动作类型: "+t)},e.addConditionComponent=function(e,t,o){var r=t.toLowerCase();if(r.includes("compare")||r.includes("比较变量")){var n,i,s,a=e.addComponent(new exports.BlackboardCompareCondition);a.variableName=null!==(n=o.variableName)&&void 0!==n?n:"",a.operator=null!==(i=o.operator)&&void 0!==i?i:exports.CompareOperator.Equal,a.compareValue=o.compareValue,a.invertResult=null!==(s=o.invertResult)&&void 0!==s&&s}else if(r.includes("exists")||r.includes("变量存在")){var d,u,c,p=e.addComponent(new exports.BlackboardExistsCondition);p.variableName=null!==(d=o.variableName)&&void 0!==d?d:"",p.checkNotNull=null!==(u=o.checkNotNull)&&void 0!==u&&u,p.invertResult=null!==(c=o.invertResult)&&void 0!==c&&c}else if(r.includes("random")||r.includes("概率")){var l;e.addComponent(new exports.RandomProbabilityCondition).probability=null!==(l=o.probability)&&void 0!==l?l:.5}else if(r.includes("execute")||r.includes("执行条件")){var h,f,v=e.addComponent(new exports.ExecuteCondition);v.conditionCode=null!==(h=o.conditionCode)&&void 0!==h?h:"",v.invertResult=null!==(f=o.invertResult)&&void 0!==f&&f}else ce.warn("未知的条件类型: "+t)},e.setupBlackboard=function(e,t,o){for(var r,n=e.addComponent(new exports.BlackboardComponent),i=c(t);!(r=i()).done;){var s=r.value,a=o&&void 0!==o[s.name]?o[s.name]:s.defaultValue;n.defineVariable(s.name,s.type,a,{readonly:s.readonly,description:s.description})}ce.info("已设置黑板: "+t.length+" 个变量")},e.setupPropertyBindings=function(e,t){for(var o,r=c(e);!(o=r()).done;){var n=o.value,i=t.get(n.nodeId);if(i){var s=i.getComponent(E);s||(s=i.addComponent(new E)),s.addBinding(n.propertyName,n.variableName)}else ce.warn("属性绑定引用的节点不存在: "+n.nodeId)}ce.info("已设置属性绑定: "+e.length+" 个绑定")},e}();!function(e){e[e.NotStarted=0]="NotStarted",e[e.Loading=1]="Loading",e[e.Completed=2]="Completed",e[e.Failed=3]="Failed"}(oe||(oe={}));var le,he=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode))||this).preloadStates=new Map,t.preloadTasks=new Map,t.updateOrder=350,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);n.nodeType===exports.NodeType.Composite&&(r.hasComponent(exports.RootNode)&&this.executeRoot(r,n))}},o.executeRoot=function(e,t){var o=this.preloadStates.get(e.id)||oe.NotStarted;if(o!==oe.NotStarted)if(o!==oe.Loading){if(o===oe.Failed)return t.status=exports.TaskStatus.Failure,void e.removeComponentByType(exports.ActiveNode);var r=e.children;if(0!==r.length){var n=r[0],i=n.getComponent(exports.BehaviorTreeNode);if(i)return n.hasComponent(exports.ActiveNode)?void(i.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:i.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,e.removeComponentByType(exports.ActiveNode)):i.status===exports.TaskStatus.Failure&&(t.status=exports.TaskStatus.Failure,e.removeComponentByType(exports.ActiveNode))):(n.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running));t.status=exports.TaskStatus.Failure}else t.status=exports.TaskStatus.Success}else t.status=exports.TaskStatus.Running;else this.startPreload(e,t)},o.startPreload=function(e,t){var o=this,r=this.scanSubTreeNodes(e);if(0===r.length)return this.preloadStates.set(e.id,oe.Completed),void this.outputLog(e,"没有需要预加载的子树","info");this.preloadStates.set(e.id,oe.Loading),t.status=exports.TaskStatus.Running,this.outputLog(e,"开始预加载 "+r.length+" 个子树...","info");var n=this.preloadAllSubTrees(e,r);this.preloadTasks.set(e.id,n),n.then((function(){o.preloadStates.set(e.id,oe.Completed),o.outputLog(e,"所有子树预加载完成","info")})).catch((function(t){o.preloadStates.set(e.id,oe.Failed),o.outputLog(e,"子树预加载失败: "+t.message,"error")}))},o.scanSubTreeNodes=function(e){var t=[],o=e.getComponent(exports.SubTreeNode);o&&o.preload&&t.push({entity:e,subTree:o});for(var r,n=c(e.children);!(r=n()).done;){var i=r.value;t.push.apply(t,this.scanSubTreeNodes(i))}return t},o.preloadAllSubTrees=function(){var e=u(v().m((function e(t,o){var r=this;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:if(this.assetLoader){e.n=3;break}e.p=1,this.assetLoader=s.Core.services.resolve(ue),e.n=3;break;case 2:throw e.p=2,e.v,new Error("AssetLoader 未配置,无法预加载子树");case 3:return e.n=4,Promise.all(o.map((function(e){var o=e.entity,n=e.subTree;return r.preloadSingleSubTree(t,o,n)})));case 4:return e.a(2)}}),e,this,[[1,2]])})));return function(t,o){return e.apply(this,arguments)}}(),o.preloadSingleSubTree=function(){var e=u(v().m((function e(t,o,r){var n,i,s;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,this.outputLog(t,"预加载子树: "+r.assetId,"info"),e.n=1,this.assetLoader.loadBehaviorTree(r.assetId);case 1:n=e.v,i=pe.instantiate(n,this.scene,{asSubTree:!0}),r.setSubTreeRoot(i),o.addChild(i),i.addComponent(new exports.BehaviorTreeAssetMetadata).initialize(r.assetId,"1.0.0"),r.inheritParentBlackboard&&this.setupBlackboardInheritance(o,i),this.outputLog(t,"=== 预加载子树 "+r.assetId+" 的内部结构 ===","info"),this.logSubTreeStructure(t,i,0),this.outputLog(t,"=== 预加载子树结构结束 ===","info"),this.outputLog(t,"✓ 子树 "+r.assetId+" 预加载完成","info"),e.n=3;break;case 2:throw e.p=2,s=e.v,this.outputLog(t,"✗ 子树 "+r.assetId+" 预加载失败: "+s.message,"error"),s;case 3:return e.a(2)}}),e,this,[[0,2]])})));return function(t,o,r){return e.apply(this,arguments)}}(),o.setupBlackboardInheritance=function(e,t){if(this.findBlackboard(e)){var o=t.getComponent(exports.BlackboardComponent);o&&o.setUseGlobalBlackboard(!0)}},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.logSubTreeStructure=function(e,t,o){var r=this,n=" ".repeat(o);t.getComponent(exports.BehaviorTreeNode);var i=t.components.map((function(e){return e.constructor.name})).find((function(e){return"BehaviorTreeNode"!==e&&"ActiveNode"!==e&&"BlackboardComponent"!==e&&"LogOutput"!==e&&"PropertyBindings"!==e&&"BehaviorTreeAssetMetadata"!==e}))||"Unknown",s=t.name;"Unknown"!==i&&(s=s+" ["+i+"]"),this.outputLog(e,n+"└─ "+s,"info"),t.children.length>0&&(this.outputLog(e,n+" 子节点数: "+t.children.length,"info"),t.children.forEach((function(t){r.logSubTreeStructure(e,t,o+1)})))},o.onDestroy=function(){this.preloadStates.clear(),this.preloadTasks.clear(),e.prototype.onDestroy.call(this)},o.getLoggerName=function(){return"RootExecutionSystem"},t}(s.EntitySystem),fe=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode))||this).updateOrder=100,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);n.nodeType===exports.NodeType.Action?this.executeAction(r,n):n.nodeType===exports.NodeType.Condition&&this.executeCondition(r,n)}},o.executeAction=function(e,t){var o=exports.TaskStatus.Failure,r=this.getNodeInfo(e),n=r.displayName,i=r.nodeIdShort;e.hasComponent(exports.WaitAction)?o=this.executeWaitAction(e):e.hasComponent(exports.LogAction)?o=this.executeLogAction(e):e.hasComponent(exports.SetBlackboardValueAction)?o=this.executeSetBlackboardValue(e):e.hasComponent(exports.ModifyBlackboardValueAction)?o=this.executeModifyBlackboardValue(e):e.hasComponent(exports.ExecuteAction)?o=this.executeCustomAction(e):this.outputLog(e,"动作节点没有找到任何已知的动作组件","warn"),t.status=o;var s=o===exports.TaskStatus.Success?"Success":o===exports.TaskStatus.Failure?"Failure":o===exports.TaskStatus.Running?"Running":"Unknown";o!==exports.TaskStatus.Running&&this.outputLog(e,"["+n+"#"+i+"] 执行完成 -> "+s,o===exports.TaskStatus.Success?"info":"warn"),o!==exports.TaskStatus.Running&&(this.deactivateNode(e),this.notifyParent(e))},o.executeWaitAction=function(e){var t=e.getComponent(exports.WaitAction);e.getComponent(exports.BehaviorTreeNode);var o=this.getNodeInfo(e),r=o.displayName,n=o.nodeIdShort,i=this.resolvePropertyValue(e,"waitTime",t.waitTime);return t.elapsedTime+=s.Time.deltaTime,this.outputLog(e,"["+r+"#"+n+"] deltaTime="+s.Time.deltaTime.toFixed(3)+"s, elapsed="+t.elapsedTime.toFixed(3)+"s/"+i.toFixed(3)+"s","info"),t.elapsedTime>=i?(t.reset(),this.outputLog(e,"["+r+"#"+n+"] 等待完成,返回成功","info"),exports.TaskStatus.Success):exports.TaskStatus.Running},o.executeLogAction=function(e){var t=e.getComponent(exports.LogAction),o=e.getComponent(exports.BehaviorTreeNode),r=this.resolvePropertyValue(e,"message",t.message),n=this.getNodeInfo(e),i=n.displayName,s=n.nodeIdShort;switch(o&&(r="["+i+"#"+s+"] "+r),t.includeEntityInfo&&(r="[Entity: "+e.name+"] "+r),t.level){case"info":console.info(r);break;case"warn":console.warn(r);break;case"error":console.error(r);break;default:console.log(r)}var a=this.findRootEntity(e);if(a){var d=a.getComponent(exports.LogOutput);d&&d.addMessage(r,t.level)}return exports.TaskStatus.Success},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.executeSetBlackboardValue=function(e){var t,o=e.getComponent(exports.SetBlackboardValueAction),r=this.findBlackboard(e);if(!r)return this.outputLog(e,"未找到黑板组件","warn"),exports.TaskStatus.Failure;if(o.sourceVariable){if(!r.hasVariable(o.sourceVariable))return this.outputLog(e,"源变量不存在: "+o.sourceVariable,"warn"),exports.TaskStatus.Failure;t=r.getValue(o.sourceVariable)}else t=this.resolvePropertyValue(e,"value",o.value);return r.setValue(o.variableName,t,o.force)?exports.TaskStatus.Success:exports.TaskStatus.Failure},o.executeModifyBlackboardValue=function(e){var t=e.getComponent(exports.ModifyBlackboardValueAction),o=this.findBlackboard(e);if(!o)return this.outputLog(e,"未找到黑板组件","warn"),exports.TaskStatus.Failure;if(!o.hasVariable(t.variableName))return this.outputLog(e,"变量不存在: "+t.variableName,"warn"),exports.TaskStatus.Failure;var r,n=o.getValue(t.variableName),i=this.resolvePropertyValue(e,"operand",t.operand);switch(t.operation){case exports.ModifyOperation.Add:r=Number(n)+Number(i);break;case exports.ModifyOperation.Subtract:r=Number(n)-Number(i);break;case exports.ModifyOperation.Multiply:r=Number(n)*Number(i);break;case exports.ModifyOperation.Divide:if(0===Number(i))return this.outputLog(e,"除数不能为0","warn"),exports.TaskStatus.Failure;r=Number(n)/Number(i);break;case exports.ModifyOperation.Modulo:r=Number(n)%Number(i);break;case exports.ModifyOperation.Append:if(Array.isArray(n))r=[].concat(n,[i]);else{if("string"!=typeof n)return this.outputLog(e,"变量 "+t.variableName+" 不支持 append 操作","warn"),exports.TaskStatus.Failure;r=n+i}break;case exports.ModifyOperation.Remove:if(!Array.isArray(n))return this.outputLog(e,"变量 "+t.variableName+" 不是数组,不支持 remove 操作","warn"),exports.TaskStatus.Failure;r=n.filter((function(e){return e!==i}));break;default:return exports.TaskStatus.Failure}return o.setValue(t.variableName,r,t.force)?exports.TaskStatus.Success:exports.TaskStatus.Failure},o.executeCustomAction=function(e){var t=e.getComponent(exports.ExecuteAction).getFunction();return t?t(e,this.findBlackboard(e),s.Time.deltaTime):exports.TaskStatus.Failure},o.executeCondition=function(e,t){var o=!1,r=this.getNodeInfo(e),n=r.displayName,i=r.nodeIdShort;e.hasComponent(exports.BlackboardCompareCondition)?o=this.evaluateBlackboardCompare(e):e.hasComponent(exports.BlackboardExistsCondition)?o=this.evaluateBlackboardExists(e):e.hasComponent(exports.RandomProbabilityCondition)?o=this.evaluateRandomProbability(e):e.hasComponent(exports.ExecuteCondition)?o=this.evaluateCustomCondition(e):this.outputLog(e,"条件节点没有找到任何已知的条件组件","warn"),t.status=o?exports.TaskStatus.Success:exports.TaskStatus.Failure;var s=o?"Success (true)":"Failure (false)";this.outputLog(e,"["+n+"#"+i+"] 条件评估 -> "+s,o?"info":"warn"),this.deactivateNode(e),this.notifyParent(e)},o.evaluateBlackboardCompare=function(e){var t=e.getComponent(exports.BlackboardCompareCondition),o=this.findBlackboard(e);if(!o||!o.hasVariable(t.variableName))return!1;var r=o.getValue(t.variableName),n=this.resolvePropertyValue(e,"compareValue",t.compareValue),i=!1;switch(t.operator){case exports.CompareOperator.Equal:i=r===n;break;case exports.CompareOperator.NotEqual:i=r!==n;break;case exports.CompareOperator.Greater:i=r>n;break;case exports.CompareOperator.GreaterOrEqual:i=r>=n;break;case exports.CompareOperator.Less:i=r<n;break;case exports.CompareOperator.LessOrEqual:i=r<=n;break;case exports.CompareOperator.Contains:("string"==typeof r||Array.isArray(r))&&(i=r.includes(n));break;case exports.CompareOperator.Matches:if("string"==typeof r&&"string"==typeof n)i=new RegExp(n).test(r)}return t.invertResult?!i:i},o.evaluateBlackboardExists=function(e){var t=e.getComponent(exports.BlackboardExistsCondition),o=this.findBlackboard(e);if(!o)return!1;var r=o.hasVariable(t.variableName);if(r&&t.checkNotNull){var n=o.getValue(t.variableName);r=null!=n}return t.invertResult?!r:r},o.evaluateRandomProbability=function(e){var t=e.getComponent(exports.RandomProbabilityCondition),o=this.resolvePropertyValue(e,"probability",t.probability);return(t.alwaysRandomize||void 0===t.cachedResult)&&(t.cachedResult=Math.random()<o),t.cachedResult},o.evaluateCustomCondition=function(e){var t=e.getComponent(exports.ExecuteCondition),o=t.getFunction();if(!o)return!1;var r=o(e,this.findBlackboard(e),s.Time.deltaTime);return t.invertResult?!r:r},o.resolvePropertyValue=function(e,t,o){var r=e.getComponent(E);if(!r||!r.hasBinding(t))return o;var n=r.getBinding(t),i=this.findBlackboard(e);return i?i.hasVariable(n)?i.getValue(n):(this.outputLog(e,"[属性绑定] 黑板变量不存在: "+n,"warn"),o):(this.outputLog(e,"[属性绑定] 未找到黑板组件,实体: "+e.name,"warn"),o)},o.deactivateNode=function(e){e.removeComponentByType(exports.ActiveNode)},o.notifyParent=function(e){e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.getNodeInfo=function(e){var t="Node",o="";if(e.name&&e.name.includes("#")){var r=e.name.split("#");t=r[0],o=r[1]}else o=e.id.toString().substring(0,8);return{displayName:t,nodeIdShort:o}},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.getLoggerName=function(){return"LeafExecutionSystem"},t}(s.EntitySystem),ve=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode))||this).updateOrder=200,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);if(n.nodeType===exports.NodeType.Decorator){var i=r.getComponentByType(exports.DecoratorNodeComponent);i&&this.executeDecorator(r,n,i)}}},o.executeDecorator=function(e,t,o){var r=e.children;if(0===r.length)return this.logger.warn("装饰器节点没有子节点"),t.status=exports.TaskStatus.Failure,void this.completeNode(e);var n=r[0],i=n.getComponent(exports.BehaviorTreeNode);if(!i)return t.status=exports.TaskStatus.Failure,void this.completeNode(e);switch(o.decoratorType){case exports.DecoratorType.Inverter:this.handleInverter(e,t,n,i);break;case exports.DecoratorType.Repeater:this.handleRepeater(e,t,o,n,i);break;case exports.DecoratorType.UntilSuccess:this.handleUntilSuccess(e,t,n,i);break;case exports.DecoratorType.UntilFail:this.handleUntilFail(e,t,n,i);break;case exports.DecoratorType.AlwaysSucceed:this.handleAlwaysSucceed(e,t,n,i);break;case exports.DecoratorType.AlwaysFail:this.handleAlwaysFail(e,t,n,i);break;case exports.DecoratorType.Conditional:this.handleConditional(e,t,o,n,i);break;case exports.DecoratorType.Cooldown:this.handleCooldown(e,t,o,n,i);break;case exports.DecoratorType.Timeout:this.handleTimeout(e,t,o,n,i);break;default:t.status=exports.TaskStatus.Failure,this.completeNode(e)}},o.handleInverter=function(e,t,o,r){o.hasComponent(exports.ActiveNode)||o.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running,r.status!==exports.TaskStatus.Success&&r.status!==exports.TaskStatus.Failure||(t.status=r.status===exports.TaskStatus.Success?exports.TaskStatus.Failure:exports.TaskStatus.Success,this.completeNode(e))},o.handleRepeater=function(e,t,o,r,n){var i=o,s=this.resolvePropertyValue(e,"repeatCount",i.repeatCount),a=this.resolvePropertyValue(e,"endOnFailure",i.endOnFailure);if(!r.hasComponent(exports.ActiveNode))return r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);if(n.status!==exports.TaskStatus.Running){if(n.status===exports.TaskStatus.Failure&&a)return t.status=exports.TaskStatus.Failure,i.reset(),void this.completeNode(e);i.incrementRepeat(),-1===s||i.currentRepeatCount<s?(n.invalidate(),r.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running):(t.status=exports.TaskStatus.Success,i.reset(),this.completeNode(e))}else t.status=exports.TaskStatus.Running},o.handleUntilSuccess=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status!==exports.TaskStatus.Running?r.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,this.completeNode(e)):(r.invalidate(),o.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running):t.status=exports.TaskStatus.Running},o.handleUntilFail=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status!==exports.TaskStatus.Running?r.status===exports.TaskStatus.Failure?(t.status=exports.TaskStatus.Success,this.completeNode(e)):(r.invalidate(),o.addComponent(new exports.ActiveNode),t.status=exports.TaskStatus.Running):t.status=exports.TaskStatus.Running},o.handleAlwaysSucceed=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:(t.status=exports.TaskStatus.Success,this.completeNode(e))},o.handleAlwaysFail=function(e,t,o,r){if(!o.hasComponent(exports.ActiveNode))return o.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running);r.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:(t.status=exports.TaskStatus.Failure,this.completeNode(e))},o.handleConditional=function(e,t,o,r,n){return o.evaluateCondition(e,this.findBlackboard(e))?r.hasComponent(exports.ActiveNode)?(t.status=n.status,void(n.status!==exports.TaskStatus.Running&&this.completeNode(e))):(r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.handleCooldown=function(e,t,o,r,n){var i=o,a=this.resolvePropertyValue(e,"cooldownTime",i.cooldownTime),d=s.Time.totalTime-i.lastExecutionTime,u=0===i.lastExecutionTime||d>=a;return this.outputLog(e,"[冷却检查] Time.totalTime="+s.Time.totalTime.toFixed(3)+", lastExecution="+i.lastExecutionTime.toFixed(3)+", cooldownTime="+a+", timeSince="+d.toFixed(3)+", canExecute="+u+", childStatus="+n.status,"info"),u?n.status!==exports.TaskStatus.Invalid&&n.status!==exports.TaskStatus.Running?(t.status=n.status,i.recordExecution(s.Time.totalTime),this.outputLog(e,"[冷却记录] 记录执行时间: "+s.Time.totalTime.toFixed(3)+", 下次可执行时间: "+(s.Time.totalTime+a).toFixed(3),"info"),void this.completeNode(e)):(r.hasComponent(exports.ActiveNode)||r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.handleTimeout=function(e,t,o,r,n){var i=o,a=this.resolvePropertyValue(e,"timeoutDuration",i.timeoutDuration);return i.recordStartTime(s.Time.totalTime),i.startTime>0&&s.Time.totalTime-i.startTime>=a?(t.status=exports.TaskStatus.Failure,i.reset(),r.removeComponentByType(exports.ActiveNode),void this.completeNode(e)):r.hasComponent(exports.ActiveNode)?(t.status=n.status,void(n.status!==exports.TaskStatus.Running&&(i.reset(),this.completeNode(e)))):(r.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running))},o.completeNode=function(e){e.removeComponentByType(exports.ActiveNode),e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.resolvePropertyValue=function(e,t,o){var r=e.getComponent(E);if(!r||!r.hasBinding(t))return o;var n=r.getBinding(t),i=this.findBlackboard(e);return i&&i.hasVariable(n)?i.getValue(n):o},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.getLoggerName=function(){return"DecoratorExecutionSystem"},t}(s.EntitySystem),ye=function(e){function t(){var t;return(t=e.call(this,s.Matcher.empty().all(exports.BehaviorTreeNode,exports.ActiveNode).exclude(exports.RootNode,exports.SubTreeNode))||this).updateOrder=300,t}h(t,e);var o=t.prototype;return o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);if(n.nodeType===exports.NodeType.Composite){var i=r.getComponentByType(exports.CompositeNodeComponent);if(i)this.executeComposite(r,n,i);else{this.logger.warn("复合节点 "+r.name+" 没有找到复合节点组件");var s=r.components.map((function(e){return e.constructor.name})).join(", ");this.logger.warn(" 组件列表: "+s)}}}},o.executeComposite=function(e,t,o){var r=e.children;if(0===r.length)return t.status=exports.TaskStatus.Success,void this.completeNode(e);switch(o.compositeType){case exports.CompositeType.Sequence:this.handleSequence(e,t,r);break;case exports.CompositeType.Selector:this.handleSelector(e,t,r);break;case exports.CompositeType.Parallel:this.handleParallel(e,t,r);break;case exports.CompositeType.ParallelSelector:this.handleParallelSelector(e,t,r);break;case exports.CompositeType.RandomSequence:this.handleRandomSequence(e,t,o,r);break;case exports.CompositeType.RandomSelector:this.handleRandomSelector(e,t,o,r);break;default:t.status=exports.TaskStatus.Failure,this.completeNode(e)}},o.handleSequence=function(e,t,o){var r=e.getComponentByType(exports.SequenceNode);if(!r||r.abortType===exports.AbortType.None||!this.shouldAbort(e,t,o,r.abortType)){if(t.currentChildIndex>=o.length)return t.status=exports.TaskStatus.Success,t.currentChildIndex=0,void this.completeNode(e);var n=o[t.currentChildIndex],i=n.getComponent(exports.BehaviorTreeNode);return i?i.status===exports.TaskStatus.Invalid?(n.hasComponent(exports.ActiveNode)||n.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(i.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:i.status===exports.TaskStatus.Failure?(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,this.completeNode(e)):i.status===exports.TaskStatus.Success&&(i.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))}this.abortExecution(e,t,o)},o.handleSelector=function(e,t,o){var r=e.getComponentByType(exports.SelectorNode);if(!r||r.abortType===exports.AbortType.None||!this.shouldAbort(e,t,o,r.abortType)){if(t.currentChildIndex>=o.length)return t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,void this.completeNode(e);var n=o[t.currentChildIndex],i=n.getComponent(exports.BehaviorTreeNode);return i?i.status===exports.TaskStatus.Invalid?(n.hasComponent(exports.ActiveNode)||n.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(i.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:i.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,t.currentChildIndex=0,this.completeNode(e)):i.status===exports.TaskStatus.Failure&&(i.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))}this.abortExecution(e,t,o)},o.handleParallel=function(e,t,o){for(var r,n=!1,i=!1,s=c(o);!(r=s()).done;){var a=r.value;a.hasComponent(exports.ActiveNode)||a.addComponent(new exports.ActiveNode);var d=a.getComponent(exports.BehaviorTreeNode);d&&(d.status===exports.TaskStatus.Running?n=!0:d.status===exports.TaskStatus.Failure&&(i=!0))}n?t.status=exports.TaskStatus.Running:i?(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,this.completeNode(e)):(t.status=exports.TaskStatus.Success,t.currentChildIndex=0,this.completeNode(e))},o.handleParallelSelector=function(e,t,o){for(var r,n=!1,i=!1,s=c(o);!(r=s()).done;){var a=r.value;a.hasComponent(exports.ActiveNode)||a.addComponent(new exports.ActiveNode);var d=a.getComponent(exports.BehaviorTreeNode);d&&(d.status===exports.TaskStatus.Running?n=!0:d.status===exports.TaskStatus.Success&&(i=!0))}if(i){t.status=exports.TaskStatus.Success,t.currentChildIndex=0;for(var u,p=c(o);!(u=p()).done;){u.value.removeComponentByType(exports.ActiveNode)}this.completeNode(e)}else n?t.status=exports.TaskStatus.Running:(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,this.completeNode(e))},o.handleRandomSequence=function(e,t,o,r){var n=o.getNextChildIndex(t.currentChildIndex,r.length);if(n>=r.length)return t.status=exports.TaskStatus.Success,t.currentChildIndex=0,o.resetShuffle(),void this.completeNode(e);var i=r[n],s=i.getComponent(exports.BehaviorTreeNode);return s?s.status===exports.TaskStatus.Invalid?(i.hasComponent(exports.ActiveNode)||i.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(s.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:s.status===exports.TaskStatus.Failure?(t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,o.resetShuffle(),this.completeNode(e)):s.status===exports.TaskStatus.Success&&(s.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.handleRandomSelector=function(e,t,o,r){var n=o.getNextChildIndex(t.currentChildIndex,r.length);if(n>=r.length)return t.status=exports.TaskStatus.Failure,t.currentChildIndex=0,o.resetShuffle(),void this.completeNode(e);var i=r[n],s=i.getComponent(exports.BehaviorTreeNode);return s?s.status===exports.TaskStatus.Invalid?(i.hasComponent(exports.ActiveNode)||i.addComponent(new exports.ActiveNode),void(t.status=exports.TaskStatus.Running)):void(s.status===exports.TaskStatus.Running?t.status=exports.TaskStatus.Running:s.status===exports.TaskStatus.Success?(t.status=exports.TaskStatus.Success,t.currentChildIndex=0,o.resetShuffle(),this.completeNode(e)):s.status===exports.TaskStatus.Failure&&(s.reset(),t.currentChildIndex++,t.status=exports.TaskStatus.Running)):(t.status=exports.TaskStatus.Failure,void this.completeNode(e))},o.shouldAbort=function(e,t,o,r){var n=t.currentChildIndex;if(0===n)return!1;if(r===exports.AbortType.Self||r===exports.AbortType.Both)for(var i=0;i<n;i++){var s=o[i].getComponent(exports.BehaviorTreeNode);if(s&&s.nodeType===exports.NodeType.Condition&&s.status===exports.TaskStatus.Failure)return!0}if(r===exports.AbortType.LowerPriority||r===exports.AbortType.Both)for(var a=0;a<n;a++){var d=o[a],u=d.getComponent(exports.BehaviorTreeNode);if(u)if(u.nodeType===exports.NodeType.Condition){if(this.evaluateCondition(d,u))return!0}else if(u.nodeType===exports.NodeType.Composite&&d.children.length>0){var c=d.children[0],p=c.getComponent(exports.BehaviorTreeNode);if(p&&p.nodeType===exports.NodeType.Condition&&this.evaluateCondition(c,p))return!0}}return!1},o.evaluateCondition=function(e,t){if(t.nodeType!==exports.NodeType.Condition)return!1;var o=!1;return e.hasComponent(exports.BlackboardCompareCondition)?o=this.evaluateBlackboardCompare(e):e.hasComponent(exports.BlackboardExistsCondition)?o=this.evaluateBlackboardExists(e):e.hasComponent(exports.RandomProbabilityCondition)?o=this.evaluateRandomProbability(e):e.hasComponent(exports.ExecuteCondition)&&(o=this.evaluateCustomCondition(e)),o},o.evaluateBlackboardCompare=function(e){var t=e.getComponent(exports.BlackboardCompareCondition),o=this.findBlackboard(e);if(!o||!o.hasVariable(t.variableName))return!1;var r=o.getValue(t.variableName),n=t.compareValue;"string"==typeof n&&(n=this.resolveVariableReferences(n,o));var i=!1;switch(t.operator){case exports.CompareOperator.Equal:i=r===n;break;case exports.CompareOperator.NotEqual:i=r!==n;break;case exports.CompareOperator.Greater:i=r>n;break;case exports.CompareOperator.GreaterOrEqual:i=r>=n;break;case exports.CompareOperator.Less:i=r<n;break;case exports.CompareOperator.LessOrEqual:i=r<=n;break;case exports.CompareOperator.Contains:("string"==typeof r||Array.isArray(r))&&(i=r.includes(n));break;case exports.CompareOperator.Matches:if("string"==typeof r&&"string"==typeof n)i=new RegExp(n).test(r)}return t.invertResult?!i:i},o.evaluateBlackboardExists=function(e){var t=e.getComponent(exports.BlackboardExistsCondition),o=this.findBlackboard(e);if(!o)return!1;var r=o.hasVariable(t.variableName);if(r&&t.checkNotNull){var n=o.getValue(t.variableName);r=null!=n}return t.invertResult?!r:r},o.evaluateRandomProbability=function(e){return e.getComponent(exports.RandomProbabilityCondition).evaluate()},o.evaluateCustomCondition=function(e){var t=e.getComponent(exports.ExecuteCondition),o=t.getFunction();if(!o)return!1;var r=o(e,this.findBlackboard(e),0);return t.invertResult?!r:r},o.resolveVariableReferences=function(e,t){var o=e.match(/^{{\s*(\w+)\s*}}$/);if(o){var r=o[1];return t.hasVariable(r)?t.getValue(r):e}return e.replace(/\{\{(\w+)\}\}/g,(function(e,o){if(t.hasVariable(o)){var r=t.getValue(o);return void 0!==r?String(r):e}return e}))},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.abortExecution=function(e,t,o){var r=t.currentChildIndex;if(r<o.length){var n=o[r];this.deactivateNode(n)}t.currentChildIndex=0,t.status=exports.TaskStatus.Running},o.deactivateNode=function(e){e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&t.reset();for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.deactivateNode(n)}},o.resetAllChildren=function(e){for(var t,o=c(e.children);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.BehaviorTreeNode);n&&n.reset(),this.resetAllChildren(r)}},o.completeNode=function(e){e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&t.nodeType===exports.NodeType.Composite&&this.resetAllChildren(e),e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.getLoggerName=function(){return"CompositeExecutionSystem"},t}(s.EntitySystem);exports.LoadingState=void 0,(le=exports.LoadingState||(exports.LoadingState={})).Idle="idle",le.Pending="pending",le.Loading="loading",le.Loaded="loaded",le.Failed="failed",le.Timeout="timeout",le.Cancelled="cancelled";var me,ge=function(e){function t(t){var o;return(o=e.call(this,t)||this).name="TimeoutError",o}return h(t,e),t}(g(Error)),xe=function(e){function t(t){var o;return(o=e.call(this,t)||this).name="CircularDependencyError",o}return h(t,e),t}(g(Error)),be=function(e){function t(t){var o;return(o=e.call(this,t)||this).name="EntityDestroyedError",o}return h(t,e),t}(g(Error)),Ce=s.createLogger("AssetLoadingManager"),Te=function(){function e(){this.tasks=new Map,this.loadingStack=new Set,this.defaultOptions={timeoutMs:5e3,maxRetries:3,retryDelayBase:100,maxRetryDelay:2e3}}var t=e.prototype;return t.startLoading=function(e,t,o,r){void 0===r&&(r={});var n=p({},this.defaultOptions,r);if(r.parentAssetId&&this.detectCircularDependency(e,r.parentAssetId)){var i=new xe("检测到循环引用: "+r.parentAssetId+" → "+e+"\n加载栈: "+Array.from(this.loadingStack).join(" → "));throw Ce.error(i.message),i}var s=this.tasks.get(e);if(s)return Ce.debug("资产 "+e+" 已在加载中,返回现有任务"),this.createHandle(s);var a={assetId:e,promise:null,startTime:Date.now(),lastRetryTime:0,retryCount:0,maxRetries:n.maxRetries,timeoutMs:n.timeoutMs,state:exports.LoadingState.Pending,parentEntityId:t.id,parentEntity:t,parentAssetId:r.parentAssetId};return this.loadingStack.add(e),a.promise=this.loadWithTimeoutAndRetry(a,o,n),a.state=exports.LoadingState.Loading,this.tasks.set(e,a),Ce.info("开始加载资产: "+e,{timeoutMs:n.timeoutMs,maxRetries:n.maxRetries,parentAssetId:r.parentAssetId}),this.createHandle(a)},t.loadWithTimeoutAndRetry=function(){var e=u(v().m((function e(t,o,r){var n,i,s,a,d,u;return v().w((function(e){for(;;)switch(e.p=e.n){case 0:n=null,i=0;case 1:if(!(i<=t.maxRetries)){e.n=10;break}if(!t.parentEntity.isDestroyed){e.n=2;break}throw s=new be("父实体已销毁,取消加载: "+t.assetId),t.state=exports.LoadingState.Cancelled,this.cleanup(t.assetId),Ce.warn(s.message),s;case 2:return e.p=2,t.retryCount=i,t.lastRetryTime=Date.now(),Ce.debug("加载尝试 "+(i+1)+"/"+(t.maxRetries+1)+": "+t.assetId),e.n=3,this.withTimeout(o(),t.timeoutMs,"加载资产 "+t.assetId+" 超时("+t.timeoutMs+"ms)");case 3:return a=e.v,t.state=exports.LoadingState.Loaded,t.result=a,this.cleanup(t.assetId),Ce.info("资产加载成功: "+t.assetId,{attempts:i+1,elapsedMs:Date.now()-t.startTime}),e.a(2,a);case 4:if(e.p=4,u=e.v,n=u,!(u instanceof ge)){e.n=5;break}t.state=exports.LoadingState.Timeout,Ce.warn("资产加载超时: "+t.assetId+" (尝试 "+(i+1)+")"),e.n=7;break;case 5:if(!(u instanceof be)){e.n=6;break}throw u;case 6:Ce.warn("资产加载失败: "+t.assetId+" (尝试 "+(i+1)+")",u);case 7:if(i!==t.maxRetries){e.n=8;break}throw t.state=exports.LoadingState.Failed,t.error=n,this.cleanup(t.assetId),Ce.error("资产加载最终失败: "+t.assetId,{attempts:i+1,error:n.message}),n;case 8:return d=Math.min(Math.pow(2,i)*r.retryDelayBase,r.maxRetryDelay),Ce.debug("等待 "+d+"ms 后重试..."),e.n=9,this.delay(d);case 9:i++,e.n=1;break;case 10:throw n;case 11:return e.a(2)}}),e,this,[[2,4]])})));return function(t,o,r){return e.apply(this,arguments)}}(),t.withTimeout=function(e,t,o){var r,n=new Promise((function(e,n){r=setTimeout((function(){n(new ge(o))}),t)}));return Promise.race([e.then((function(e){return clearTimeout(r),e})),n]).catch((function(e){throw clearTimeout(r),e}))},t.detectCircularDependency=function(e,t){return!!this.loadingStack.has(t)},t.getTaskState=function(e){var t,o;return null!==(t=null===(o=this.tasks.get(e))||void 0===o?void 0:o.state)&&void 0!==t?t:exports.LoadingState.Idle},t.getTask=function(e){return this.tasks.get(e)},t.cancelLoading=function(e){var t=this.tasks.get(e);t&&(t.state=exports.LoadingState.Cancelled,this.cleanup(e),Ce.info("取消加载: "+e))},t.cleanup=function(e){var t=this.tasks.get(e);t&&(t.parentEntity=null),this.tasks.delete(e),this.loadingStack.delete(e)},t.delay=function(e){return new Promise((function(t){return setTimeout(t,e)}))},t.createHandle=function(e){var t=this;return{assetId:e.assetId,getState:function(){return e.state},getError:function(){return e.error},getProgress:function(){var t=Date.now()-e.startTime,o=Math.max(0,e.timeoutMs-t);return{state:e.state,elapsedMs:t,remainingTimeoutMs:o,retryCount:e.retryCount,maxRetries:e.maxRetries}},cancel:function(){return t.cancelLoading(e.assetId)},promise:e.promise}},t.getLoadingAssets=function(){return Array.from(this.tasks.keys())},t.getStats=function(){var e=Array.from(this.tasks.values());return{totalTasks:e.length,loadingTasks:e.filter((function(e){return e.state===exports.LoadingState.Loading})).length,failedTasks:e.filter((function(e){return e.state===exports.LoadingState.Failed})).length,timeoutTasks:e.filter((function(e){return e.state===exports.LoadingState.Timeout})).length}},t.clear=function(){Ce.info("清空所有加载任务",this.getStats()),this.tasks.clear(),this.loadingStack.clear()},t.dispose=function(){this.clear()},e}(),Se=function(e){function t(t){var o;return(o=e.call(this,s.Matcher.empty().all(exports.SubTreeNode,exports.ActiveNode,exports.BehaviorTreeNode))||this).assetLoaderInitialized=!1,o.hasLoggedMissingAssetLoader=!1,o.loadingTasks=new Map,o.updateOrder=300,o.loadingManager=t||new Te,o}h(t,e);var o=t.prototype;return o.onInitialize=function(){},o.process=function(e){for(var t,o=c(e);!(t=o()).done;){var r=t.value,n=r.getComponent(exports.SubTreeNode),i=r.getComponent(exports.BehaviorTreeNode);this.executeSubTree(r,n,i)}},o.executeSubTree=function(e,t,o){var r=t.validate();if(r.length>0)return this.logger.error("SubTree 节点配置错误: "+r.join(", ")),o.status=exports.TaskStatus.Failure,void this.completeNode(e);var n=t.getSubTreeRoot();if(n){var i=n.getComponent(exports.BehaviorTreeNode);if(i){var s=exports.TaskStatus[i.status],a=n.hasComponent(exports.ActiveNode);if(this.outputLog(e,"检查预加载子树 "+t.assetId+": status="+s+", hasActive="+a,"info"),i.status===exports.TaskStatus.Invalid){if(this.outputLog(e,"使用预加载的子树: "+t.assetId,"info"),this.outputLog(e,"激活前:子树根节点 "+n.name+" 有 "+n.children.length+" 个子节点","info"),n.children.length>0){var d=n.children[0];this.outputLog(e," 第一个子节点: "+d.name,"info")}n.hasComponent(exports.ActiveNode)||(n.addComponent(new exports.ActiveNode),this.outputLog(e,"为子树根节点添加 ActiveNode: "+n.name,"info"));var u=n.getComponent(exports.BehaviorTreeNode);return u&&(this.outputLog(e,"设置子树根节点状态: "+n.name+" -> Running","info"),u.status=exports.TaskStatus.Running),this.outputLog(e,"激活后:子树根节点 "+n.name+" 有 "+n.children.length+" 个子节点","info"),this.outputLog(e,"激活预加载的子树: "+t.assetId,"info"),void(o.status=exports.TaskStatus.Running)}}this.updateSubTree(e,t,o)}else this.outputLog(e,"子树未预加载,开始运行时加载: "+t.assetId,"info"),this.loadAndInstantiateSubTree(e,t,o)},o.ensureAssetLoaderInitialized=function(){if(!this.assetLoaderInitialized)try{this.assetLoader=s.Core.services.resolve(ue),this.assetLoaderInitialized=!0,this.logger.debug("AssetLoader 已初始化")}catch(e){return this.assetLoaderInitialized=!0,this.assetLoader=void 0,this.hasLoggedMissingAssetLoader||(this.logger.warn("AssetLoader 未配置。SubTree 节点需要 AssetLoader 来加载子树资产。\n如果您在编辑器中,请确保已打开项目并配置了项目路径。\n如果您在运行时环境,请确保已正确注册 FileSystemAssetLoader 服务。"),this.hasLoggedMissingAssetLoader=!0),!1}return void 0!==this.assetLoader},o.loadAndInstantiateSubTree=function(e,t,o){if(!this.ensureAssetLoaderInitialized())return this.logger.debug("AssetLoader 不可用,SubTree 节点执行失败"),o.status=exports.TaskStatus.Failure,void this.completeNode(e);var r=t.assetId,n=this.loadingTasks.get(e.id);if(n)switch(n.getState()){case exports.LoadingState.Loading:case exports.LoadingState.Pending:o.status=exports.TaskStatus.Running;var i=n.getProgress();return void(i.elapsedMs>1e3&&this.logger.debug("子树加载中: "+r+" (已耗时: "+Math.round(i.elapsedMs/1e3)+"s, 重试: "+i.retryCount+"/"+i.maxRetries+")"));case exports.LoadingState.Loaded:return void this.onLoadingComplete(e,t,o,n);case exports.LoadingState.Failed:case exports.LoadingState.Timeout:var s=n.getError();return this.outputLog(e,"子树加载失败: "+r+" - "+((null==s?void 0:s.message)||"未知错误"),"error"),o.status=exports.TaskStatus.Failure,this.loadingTasks.delete(e.id),void this.completeNode(e);case exports.LoadingState.Cancelled:return void this.loadingTasks.delete(e.id)}this.startNewLoading(e,t,o)},o.startNewLoading=function(e,t,o){var r=this,n=t.assetId,i=this.getParentTreeAssetId(e);try{var s=this.loadingManager.startLoading(n,e,(function(){return r.loadAsset(n)}),{timeoutMs:5e3,maxRetries:2,parentAssetId:i});this.loadingTasks.set(e.id,s),o.status=exports.TaskStatus.Running,this.outputLog(e,"开始加载子树: "+n+" (父树: "+(i||"none")+")","info")}catch(t){t instanceof xe?this.outputLog(e,"检测到循环引用: "+t.message,"error"):this.outputLog(e,"启动加载失败: "+n,"error"),o.status=exports.TaskStatus.Failure,this.completeNode(e)}},o.onLoadingComplete=function(e,t,o,r){var n=this;r.promise.then((function(o){if(e.isDestroyed)return n.logger.warn("父实体已销毁,丢弃加载结果: "+r.assetId),void o.destroy();t.setSubTreeRoot(o),e.addChild(o),o.addComponent(new exports.BehaviorTreeAssetMetadata).initialize(r.assetId,"1.0.0"),t.inheritParentBlackboard&&n.setupBlackboardInheritance(e,o),n.outputLog(e,"子树 "+r.assetId+" 加载成功并激活","info"),n.outputLog(e,"=== 子树 "+r.assetId+" 内部结构 ===","info"),n.logSubTreeStructure(e,o,0),n.outputLog(e,"=== 子树结构结束 ===","info"),n.startSubTreeExecution(o,e),n.loadingTasks.delete(e.id)})).catch((function(e){e instanceof be||n.logger.error("意外错误:",e)}))},o.loadAsset=function(){var e=u(v().m((function e(t){var o,r;return v().w((function(e){for(;;)switch(e.n){case 0:if(this.scene){e.n=1;break}throw new Error("Scene 不存在");case 1:return e.n=2,this.assetLoader.loadBehaviorTree(t);case 2:return o=e.v,r=pe.instantiate(o,this.scene,{asSubTree:!0}),e.a(2,r)}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),o.setupBlackboardInheritance=function(e,t){if(this.findBlackboard(e)){var o=t.getComponent(exports.BlackboardComponent);o&&o.setUseGlobalBlackboard(!0)}},o.findBlackboard=function(e){for(var t=e;t;){var o=t.getComponent(exports.BlackboardComponent);if(o)return o;t=t.parent}},o.startSubTreeExecution=function(e,t){t&&this.outputLog(t,"子树根节点 "+e.name+" 有 "+e.children.length+" 个子节点","info"),e.hasComponent(exports.ActiveNode)||(e.addComponent(new exports.ActiveNode),t&&this.outputLog(t,"为子树根节点添加 ActiveNode: "+e.name,"info"));var o=e.getComponent(exports.BehaviorTreeNode);o&&(t&&this.outputLog(t,"设置子树根节点状态: "+e.name+" -> Running","info"),o.status=exports.TaskStatus.Running)},o.updateSubTree=function(e,t,o){var r=t.getSubTreeRoot();if(r){var n=r.getComponent(exports.BehaviorTreeNode);if(n){var i=exports.TaskStatus[n.status];this.outputLog(e,"子树 "+t.assetId+" 当前状态: "+i,"info"),n.status!==exports.TaskStatus.Running?this.onSubTreeCompleted(e,t,o,n.status):o.status=exports.TaskStatus.Running}}},o.onSubTreeCompleted=function(e,t,o,r){this.outputLog(e,"子树完成,状态: "+exports.TaskStatus[r],"info"),this.outputLog(e,"完成前:SubTreeNode "+e.name+" 有 "+e.children.length+" 个子节点","info"),t.markSubTreeCompleted(r),r===exports.TaskStatus.Success?o.status=exports.TaskStatus.Success:r===exports.TaskStatus.Failure?t.propagateFailure?o.status=exports.TaskStatus.Failure:o.status=exports.TaskStatus.Success:o.status=r,this.cleanupSubTree(t),this.outputLog(e,"清理后:SubTreeNode "+e.name+" 有 "+e.children.length+" 个子节点","info"),this.completeNode(e)},o.cleanupSubTree=function(e){var t=e.getSubTreeRoot();t&&(e.preload?(this.logger.debug("重置预加载子树以便复用: "+e.assetId),this.resetSubTreeRecursively(t),e.resetCompletionState()):(this.logger.debug("销毁运行时加载的子树: "+e.assetId),t.destroy(),e.setSubTreeRoot(void 0),e.reset()))},o.resetSubTreeRecursively=function(e){e.hasComponent(exports.ActiveNode)&&e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&(t.status=exports.TaskStatus.Invalid);for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.resetSubTreeRecursively(n)}},o.completeNode=function(e){e.removeComponentByType(exports.ActiveNode),e.parent&&e.parent.hasComponent(exports.BehaviorTreeNode)&&(e.parent.hasComponent(exports.ActiveNode)||e.parent.addComponent(new exports.ActiveNode))},o.getParentTreeAssetId=function(e){for(var t=e;t;){var o=t.getComponent(exports.BehaviorTreeAssetMetadata);if(o&&o.assetId)return o.assetId;t=t.parent}},o.onDestroy=function(){for(var t,o=c(this.loadingTasks.values());!(t=o()).done;){t.value.cancel()}this.loadingTasks.clear(),e.prototype.onDestroy.call(this)},o.findRootEntity=function(e){for(var t=e;t;){if(!t.parent)return t;t=t.parent}return null},o.outputLog=function(e,t,o){switch(void 0===o&&(o="info"),o){case"info":default:this.logger.info(t);break;case"warn":this.logger.warn(t);break;case"error":this.logger.error(t)}var r=this.findRootEntity(e);if(r){var n=r.getComponent(exports.LogOutput);n&&n.addMessage(t,o)}},o.logSubTreeStructure=function(e,t,o){var r=this,n=" ".repeat(o);t.getComponent(exports.BehaviorTreeNode);var i=t.components.map((function(e){return e.constructor.name})).find((function(e){return"BehaviorTreeNode"!==e&&"ActiveNode"!==e&&"BlackboardComponent"!==e&&"LogOutput"!==e&&"PropertyBindings"!==e&&"BehaviorTreeAssetMetadata"!==e}))||"Unknown",s=t.name;"Unknown"!==i&&(s=s+" ["+i+"]"),this.outputLog(e,n+"└─ "+s,"info"),t.children.length>0&&(this.outputLog(e,n+" 子节点数: "+t.children.length,"info"),t.children.forEach((function(t){r.logSubTreeStructure(e,t,o+1)})))},o.getLoggerName=function(){return"SubTreeExecutionSystem"},t}(s.EntitySystem);exports.AssetType=void 0,(me=exports.AssetType||(exports.AssetType={})).BehaviorTree="behavior-tree",me.Blackboard="blackboard",me.Unknown="unknown";var Ne=function(){function e(){this.config=null,this.assetMap=new Map,this.assetPathMap=new Map}var t=e.prototype;return t.initialize=function(e){this.config=e,this.rebuildAssetMaps()},t.rebuildAssetMaps=function(){if(this.assetMap.clear(),this.assetPathMap.clear(),this.config)for(var e,t=c(this.config.assets);!(e=t()).done;){var o=e.value;this.assetMap.set(o.id,o),this.assetPathMap.set(o.path,o)}},t.getConfig=function(){return this.config},t.updateConfig=function(e){this.config=e,this.rebuildAssetMaps()},t.registerAsset=function(e){if(!this.config)throw new Error("工作区未初始化");var t=this.config.assets.find((function(t){return t.id===e.id}));t?Object.assign(t,e):this.config.assets.push(e),this.rebuildAssetMaps()},t.unregisterAsset=function(e){if(this.config){var t=this.config.assets.findIndex((function(t){return t.id===e}));-1!==t&&(this.config.assets.splice(t,1),this.rebuildAssetMaps())}},t.getAssetById=function(e){return this.assetMap.get(e)},t.getAssetByPath=function(e){return this.assetPathMap.get(e)},t.getAllAssets=function(){var e;return(null===(e=this.config)||void 0===e?void 0:e.assets)||[]},t.getAssetsByType=function(e){return this.getAllAssets().filter((function(t){return t.type===e}))},t.getBehaviorTreeAssets=function(){return this.getAssetsByType(exports.AssetType.BehaviorTree)},t.getBlackboardAssets=function(){return this.getAssetsByType(exports.AssetType.Blackboard)},t.getAssetDependencies=function(e,t){if(void 0===t&&(t=new Set),t.has(e))return[];t.add(e);var o=this.getAssetById(e);if(!o)return[];for(var r,n=[],i=c(o.dependencies);!(r=i()).done;){var s=r.value,a=this.getAssetById(s);a&&(n.push(a),n.push.apply(n,this.getAssetDependencies(s,t)))}return n},t.detectCircularDependency=function(e){var t=this,o=new Set,r=[],n=function(e){if(r.includes(e))return r.push(e),!0;if(o.has(e))return!1;o.add(e),r.push(e);var i=t.getAssetById(e);if(i)for(var s,a=c(i.dependencies);!(s=a()).done;){var d=s.value;if(n(d))return!0}return r.pop(),!1};return n(e)?r:null},t.canAddDependency=function(e,t){var o=this.getAssetById(e);if(!o)return!1;var r=[].concat(o.dependencies);o.dependencies.push(t);var n=null!==this.detectCircularDependency(e);return o.dependencies=r,!n},t.addAssetDependency=function(e,t){if(!this.canAddDependency(e,t))return!1;var o=this.getAssetById(e);return!!o&&(o.dependencies.includes(t)||o.dependencies.push(t),!0)},t.removeAssetDependency=function(e,t){var o=this.getAssetById(e);if(o){var r=o.dependencies.indexOf(t);-1!==r&&o.dependencies.splice(r,1)}},t.resolveAssetPath=function(e){return this.config?e.startsWith("/")||e.match(/^[A-Za-z]:/)?e:(this.config.rootPath+"/"+e).replace(/\\/g,"/"):e},t.getRelativePath=function(e){if(!this.config)return e;var t=this.config.rootPath.replace(/\\/g,"/"),o=e.replace(/\\/g,"/");return o.startsWith(t)?o.substring(t.length+1):e},t.dispose=function(){this.config=null,this.assetMap.clear(),this.assetPathMap.clear()},e}(),we=function(){function e(){this.name="@esengine/behavior-tree",this.version="1.0.0",this.worldManager=null,this.services=null}var t=e.prototype;return t.install=function(){var e=u(v().m((function e(t,o){return v().w((function(e){for(;;)switch(e.n){case 0:this.services=o,o.registerSingleton(A),this.worldManager=o.resolve(s.WorldManager);case 1:return e.a(2)}}),e,this)})));return function(t,o){return e.apply(this,arguments)}}(),t.uninstall=function(){var e=u(v().m((function e(){return v().w((function(e){for(;;)switch(e.n){case 0:this.services&&this.services.unregister(A),this.worldManager=null,this.services=null;case 1:return e.a(2)}}),e,this)})));return function(){return e.apply(this,arguments)}}(),t.setupScene=function(e){e.addSystem(new fe),e.addSystem(new ve),e.addSystem(new ye),e.addSystem(new Se)},t.setupAllScenes=function(){if(!this.worldManager)throw new Error("Plugin not installed");for(var e,t=c(this.worldManager.getAllWorlds());!(e=t()).done;)for(var o,r=c(e.value.getAllScenes());!(o=r()).done;){var n=o.value;this.setupScene(n)}},e}(),ke=function(){function e(){}return e.start=function(e){if(!e.hasComponent(exports.BehaviorTreeNode))throw new Error("Entity must have BehaviorTreeNode component");e.hasComponent(exports.ActiveNode)||e.addComponent(new exports.ActiveNode)},e.stop=function(e){this.stopRecursive(e)},e.stopRecursive=function(e){e.hasComponent(exports.ActiveNode)&&e.removeComponentByType(exports.ActiveNode);var t=e.getComponent(exports.BehaviorTreeNode);t&&t.reset();for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.stopRecursive(n)}},e.pause=function(e){this.pauseRecursive(e)},e.pauseRecursive=function(e){e.hasComponent(exports.ActiveNode)&&e.removeComponentByType(exports.ActiveNode);for(var t,o=c(e.children);!(t=o()).done;){var r=t.value;this.pauseRecursive(r)}},e.resume=function(e){this.resumeRecursive(e)},e.resumeRecursive=function(e){var t=e.getComponent(exports.BehaviorTreeNode);if(t){t.status===exports.TaskStatus.Running&&(e.hasComponent(exports.ActiveNode)||e.addComponent(new exports.ActiveNode));for(var o,r=c(e.children);!(o=r()).done;){var n=o.value;this.resumeRecursive(n)}}},e.restart=function(e){this.stop(e),this.start(e)},e.isRunning=function(e){return e.hasComponent(exports.ActiveNode)},e}(),Be=function(){function e(e,t){this.entityStack=[],this.scene=e,this.currentEntity=e.createEntity(t)}e.create=function(t,o){return void 0===o&&(o="BehaviorTreeRoot"),new e(t,o)};var t=e.prototype;return t.blackboard=function(){return this.blackboardEntity=this.currentEntity,this.currentEntity.addComponent(new exports.BlackboardComponent),this},t.defineVariable=function(e,t,o,r){if(!this.blackboardEntity)throw new Error("Must call blackboard() first");var n=this.blackboardEntity.getComponent(exports.BlackboardComponent);return n&&n.defineVariable(e,t,o,r),this},t.endBlackboard=function(){return this.blackboardEntity=void 0,this},t.sequence=function(e){return void 0===e&&(e="Sequence"),this.composite(e,exports.CompositeType.Sequence)},t.selector=function(e){return void 0===e&&(e="Selector"),this.composite(e,exports.CompositeType.Selector)},t.parallel=function(e){return void 0===e&&(e="Parallel"),this.composite(e,exports.CompositeType.Parallel)},t.parallelSelector=function(e){return void 0===e&&(e="ParallelSelector"),this.composite(e,exports.CompositeType.ParallelSelector)},t.randomSequence=function(e){return void 0===e&&(e="RandomSequence"),this.composite(e,exports.CompositeType.RandomSequence)},t.randomSelector=function(e){return void 0===e&&(e="RandomSelector"),this.composite(e,exports.CompositeType.RandomSelector)},t.composite=function(e,t){this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);r.nodeType=exports.NodeType.Composite,r.nodeName=e;var n=o.addComponent(new exports.CompositeNodeComponent);return n.compositeType=t,this.currentEntity=o,this},t.inverter=function(e){void 0===e&&(e="Inverter"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.InverterNode),this.currentEntity=t,this},t.repeater=function(e,t,o){void 0===e&&(e="Repeater"),void 0===t&&(t=-1),void 0===o&&(o=!1),this.entityStack.push(this.currentEntity);var r=this.scene.createEntity(e);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Decorator,n.nodeName=e;var i=r.addComponent(new exports.RepeaterNode);return i.repeatCount=t,i.endOnFailure=o,this.currentEntity=r,this},t.untilSuccess=function(e){void 0===e&&(e="UntilSuccess"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.UntilSuccessNode),this.currentEntity=t,this},t.untilFail=function(e){void 0===e&&(e="UntilFail"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.UntilFailNode),this.currentEntity=t,this},t.alwaysSucceed=function(e){void 0===e&&(e="AlwaysSucceed"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.AlwaysSucceedNode),this.currentEntity=t,this},t.alwaysFail=function(e){void 0===e&&(e="AlwaysFail"),this.entityStack.push(this.currentEntity);var t=this.scene.createEntity(e);this.currentEntity.addChild(t);var o=t.addComponent(new exports.BehaviorTreeNode);return o.nodeType=exports.NodeType.Decorator,o.nodeName=e,t.addComponent(new exports.AlwaysFailNode),this.currentEntity=t,this},t.conditional=function(e,t){this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Decorator,r.nodeName=e,o.addComponent(new exports.ConditionalNode).conditionCode=t,this.currentEntity=o,this},t.cooldown=function(e,t){void 0===e&&(e="Cooldown"),void 0===t&&(t=1),this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Decorator,r.nodeName=e,o.addComponent(new exports.CooldownNode).cooldownTime=t,this.currentEntity=o,this},t.timeout=function(e,t){void 0===e&&(e="Timeout"),void 0===t&&(t=5),this.entityStack.push(this.currentEntity);var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Decorator,r.nodeName=e,o.addComponent(new exports.TimeoutNode).timeoutDuration=t,this.currentEntity=o,this},t.wait=function(e,t){void 0===t&&(t="Wait");var o=this.scene.createEntity(t);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Action,r.nodeName=t,o.addComponent(new exports.WaitAction).waitTime=e,this},t.log=function(e,t,o){void 0===t&&(t="log"),void 0===o&&(o="Log");var r=this.scene.createEntity(o);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Action,n.nodeName=o;var i=r.addComponent(new exports.LogAction);return i.message=e,i.level=t,this},t.setBlackboardValue=function(e,t,o){void 0===o&&(o="SetValue");var r=this.scene.createEntity(o);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Action,n.nodeName=o;var i=r.addComponent(new exports.SetBlackboardValueAction);return i.variableName=e,i.value=t,this},t.modifyBlackboardValue=function(e,t,o,r){void 0===r&&(r="ModifyValue");var n=this.scene.createEntity(r);this.currentEntity.addChild(n);var i=n.addComponent(new exports.BehaviorTreeNode);i.nodeType=exports.NodeType.Action,i.nodeName=r;var s=n.addComponent(new exports.ModifyBlackboardValueAction);return s.variableName=e,s.operation=t,s.operand=o,this},t.action=function(e,t){var o=this.scene.createEntity(e);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);r.nodeType=exports.NodeType.Action,r.nodeName=e;var n=o.addComponent(new exports.ExecuteAction);return n.setFunction(t),this},t.compareBlackboardValue=function(e,t,o,r){void 0===r&&(r="Compare");var n=this.scene.createEntity(r);this.currentEntity.addChild(n);var i=n.addComponent(new exports.BehaviorTreeNode);i.nodeType=exports.NodeType.Condition,i.nodeName=r;var s=n.addComponent(new exports.BlackboardCompareCondition);return s.variableName=e,s.operator=t,s.compareValue=o,this},t.checkBlackboardExists=function(e,t,o){void 0===t&&(t=!1),void 0===o&&(o="Exists");var r=this.scene.createEntity(o);this.currentEntity.addChild(r);var n=r.addComponent(new exports.BehaviorTreeNode);n.nodeType=exports.NodeType.Condition,n.nodeName=o;var i=r.addComponent(new exports.BlackboardExistsCondition);return i.variableName=e,i.checkNotNull=t,this},t.randomProbability=function(e,t){void 0===t&&(t="Random");var o=this.scene.createEntity(t);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);return r.nodeType=exports.NodeType.Condition,r.nodeName=t,o.addComponent(new exports.RandomProbabilityCondition).probability=e,this},t.condition=function(e,t){void 0===t&&(t="Condition");var o=this.scene.createEntity(t);this.currentEntity.addChild(o);var r=o.addComponent(new exports.BehaviorTreeNode);r.nodeType=exports.NodeType.Condition,r.nodeName=t;var n=o.addComponent(new exports.ExecuteCondition);return n.setFunction(e),this},t.end=function(){if(0===this.entityStack.length)throw new Error("No parent node to return to");return this.currentEntity=this.entityStack.pop(),this},t.build=function(){for(;this.entityStack.length>0;)this.currentEntity=this.entityStack.pop();return this.currentEntity},e}(),Ae=function(){function e(){}return e.serialize=function(e,t){if(void 0===t&&(t=!0),!e.hasComponent(exports.BehaviorTreeNode))throw new Error("Entity must have BehaviorTreeNode component");if(!e.scene)throw new Error("Entity must be attached to a scene");return s.SceneSerializer.serialize(e.scene,{format:"json",pretty:t,includeMetadata:!0})},e.deserialize=function(e,t){s.SceneSerializer.deserialize(e,t,{strategy:"merge"})},e.toJSON=function(e,t){void 0===t&&(t=!0);var o=this.serialize(e,t);return JSON.stringify(o,null,t?2:0)},e.fromJSON=function(e,t){this.deserialize(e,t)},e.saveToFile=function(){var e=u(v().m((function e(t,o){return v().w((function(e){for(;;)switch(e.n){case 0:throw this.toJSON(t,!0),new Error("saveToFile requires Tauri environment. Use toJSON() for manual saving.");case 1:return e.a(2)}}),e,this)})));return function(t,o){return e.apply(this,arguments)}}(),e.loadFromFile=function(){var e=u(v().m((function e(t,o){return v().w((function(e){for(;;)switch(e.n){case 0:throw new Error("loadFromFile requires Tauri environment. Use fromJSON() for manual loading.");case 1:return e.a(2)}}),e)})));return function(t,o){return e.apply(this,arguments)}}(),e.validate=function(e){try{var t=JSON.parse(e);return!(!t||"object"!=typeof t)&&(!!(t.name&&"number"==typeof t.version&&Array.isArray(t.entities)&&Array.isArray(t.componentTypeRegistry))&&t.entities.some((function(e){return e.components.some((function(e){return"BehaviorTreeNode"===e.type}))})))}catch(e){return!1}},e.clone=function(e,t){var o=this.serialize(t),r=e.entities.count;this.deserialize(e,o);for(var n=Array.from(e.entities.buffer),i=n.length-1;i>=r;i--){var s=n[i];if(s.hasComponent(exports.BehaviorTreeNode)&&!s.parent)return s}throw new Error("Failed to find cloned root entity")},e}(),Ee=function(){function e(){}return e.getAllTemplates=function(){return B()},e.getTemplate=function(e,t){return this.getAllTemplates().find((function(o){if(o.type!==e)return!1;var r=o.defaultConfig;switch(e){case exports.NodeType.Composite:return r.compositeType===t;case exports.NodeType.Decorator:return r.decoratorType===t;case exports.NodeType.Action:return r.actionType===t;case exports.NodeType.Condition:return r.conditionType===t;default:return!1}}))},e}();exports.AssetLoadingManager=Te,exports.BehaviorNode=T,exports.BehaviorProperty=S,exports.BehaviorTreeAssetLoader=pe,exports.BehaviorTreeAssetSerializer=ae,exports.BehaviorTreeAssetValidator=re,exports.BehaviorTreeBuilder=Be,exports.BehaviorTreePersistence=Ae,exports.BehaviorTreePlugin=we,exports.BehaviorTreeStarter=ke,exports.CircularDependencyError=xe,exports.CompositeExecutionSystem=ye,exports.DecoratorExecutionSystem=ve,exports.EditorFormatConverter=ie,exports.EntityDestroyedError=be,exports.FileSystemAssetLoader=ue,exports.GlobalBlackboardService=A,exports.LeafExecutionSystem=fe,exports.NodeClassRegistry=C,exports.NodeProperty=k,exports.NodeTemplates=Ee,exports.PropertyBindings=E,exports.RootExecutionSystem=he,exports.SubTreeExecutionSystem=Se,exports.TimeoutError=ge,exports.WorkspaceService=Ne,exports.clearRegisteredNodes=function(){C.clear()},exports.getRegisteredNodeTemplates=B;
3
+ var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function a(r,n,o,a){var u=n&&n.prototype instanceof s?n:s,c=Object.create(u.prototype);return v(c,"_invoke",function(r,n,o){var a,s,u,c=0,d=o||[],l=!1,p={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,r){return a=t,s=0,u=e,p.n=r,i}};function f(r,n){for(s=r,u=n,t=0;!l&&c&&!o&&t<d.length;t++){var o,a=d[t],f=p.p,h=a[2];r>3?(o=h===n)&&(u=a[(s=a[4])?5:(s=3,3)],a[4]=a[5]=e):a[0]<=f&&((o=r<2&&f<a[1])?(s=0,p.v=n,p.n=a[1]):f<h&&(o=r<3||a[0]>n||n>h)&&(a[4]=r,a[5]=n,p.n=h,s=0))}if(o||r>1)return i;throw l=!0,n}return function(o,d,h){if(c>1)throw TypeError("Generator is already running");for(l&&1===d&&f(d,h),s=d,u=h;(t=s<2?e:u)||!l;){a||(s?s<3?(s>1&&(p.n=-1),f(s,u)):p.n=u:p.v=u);try{if(c=2,a){if(s||(o="next"),t=a[o]){if(!(t=t.call(a,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,s<2&&(s=0)}else 1===s&&(t=a.return)&&t.call(a),s<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),s=1);a=e}else if((t=(l=p.n<0)?u:r.call(n,p))!==i)break}catch(t){a=e,s=1,u=t}finally{c=1}}return{value:t,done:l}}}(r,o,a),!0),c}var i={};function s(){}function u(){}function c(){}t=Object.getPrototypeOf;var d=[][n]?t(t([][n]())):(v(t={},n,(function(){return this})),t),l=c.prototype=s.prototype=Object.create(d);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,c):(e.__proto__=c,v(e,o,"GeneratorFunction")),e.prototype=Object.create(l),e}return u.prototype=c,v(l,"constructor",c),v(c,"constructor",u),u.displayName="GeneratorFunction",v(c,o,"GeneratorFunction"),v(l),v(l,o,"Generator"),v(l,n,(function(){return this})),v(l,"toString",(function(){return"[object Generator]"})),(h=function(){return{w:a,m:p}})()}function v(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}v=function(e,t,r,n){function a(t,r){v(e,t,(function(e){return this._invoke(t,r,e)}))}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(a("next",0),a("throw",1),a("return",2))},v(e,t,r,n)}function m(e,t){return m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},m(e,t)}function g(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}function y(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}exports.CompositeType=void 0,(r=exports.CompositeType||(exports.CompositeType={})).Sequence="sequence",r.Selector="selector",r.Parallel="parallel",r.ParallelSelector="parallel-selector",r.RandomSequence="random-sequence",r.RandomSelector="random-selector",exports.DecoratorType=void 0,(n=exports.DecoratorType||(exports.DecoratorType={})).Inverter="inverter",n.Repeater="repeater",n.UntilSuccess="until-success",n.UntilFail="until-fail",n.AlwaysSucceed="always-succeed",n.AlwaysFail="always-fail",n.Conditional="conditional",n.Cooldown="cooldown",n.Timeout="timeout",exports.AbortType=void 0,(o=exports.AbortType||(exports.AbortType={})).None="none",o.Self="self",o.LowerPriority="lower-priority",o.Both="both",exports.BlackboardValueType=void 0,(a=exports.BlackboardValueType||(exports.BlackboardValueType={})).String="string",a.Number="number",a.Boolean="boolean",a.Vector2="vector2",a.Vector3="vector3",a.Object="object",a.Array="array","function"==typeof SuppressedError&&SuppressedError,exports.BehaviorTreeRuntimeComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).treeAssetId="",t.autoStart=!0,t.isRunning=!1,t.nodeStates=new Map,t.blackboard=new Map,t.blackboardObservers=new Map,t.activeNodeIds=new Set,t.needsReset=!1,t.nodesToAbort=new Set,t}f(t,e);var r=t.prototype;return r.getNodeState=function(e){return this.nodeStates.has(e)||this.nodeStates.set(e,s()),this.nodeStates.get(e)},r.resetNodeState=function(e){var t=this.getNodeState(e);t.status=exports.TaskStatus.Invalid,t.currentChildIndex=0,delete t.startTime,delete t.lastExecutionTime,delete t.repeatCount,delete t.cachedResult,delete t.shuffledIndices,delete t.isAborted,delete t.lastConditionResult,delete t.observedKeys},r.resetAllStates=function(){this.nodeStates.clear(),this.activeNodeIds.clear()},r.getBlackboardValue=function(e){return this.blackboard.get(e)},r.setBlackboardValue=function(e,t){var r=this.blackboard.get(e);this.blackboard.set(e,t),r!==t&&this.notifyBlackboardChange(e,t,r)},r.hasBlackboardKey=function(e){return this.blackboard.has(e)},r.initializeBlackboard=function(e){var t=this;e&&e.forEach((function(e,r){t.blackboard.has(r)||t.blackboard.set(r,e)}))},r.clearBlackboard=function(){this.blackboard.clear()},r.start=function(){this.isRunning=!0,this.resetAllStates()},r.stop=function(){this.isRunning=!1,this.activeNodeIds.clear()},r.pause=function(){this.isRunning=!1},r.resume=function(){this.isRunning=!0},r.observeBlackboard=function(e,t,r){for(var n,o={nodeId:e,keys:new Set(t),callback:r},a=l(t);!(n=a()).done;){var i=n.value;this.blackboardObservers.has(i)||this.blackboardObservers.set(i,[]),this.blackboardObservers.get(i).push(o)}},r.unobserveBlackboard=function(e){for(var t,r=l(this.blackboardObservers.values());!(t=r()).done;){var n=t.value,o=n.findIndex((function(t){return t.nodeId===e}));-1!==o&&n.splice(o,1)}},r.notifyBlackboardChange=function(e,t,r){var n=this.blackboardObservers.get(e);if(n)for(var o,a=l(n);!(o=a()).done;){var i=o.value;try{i.callback(e,t,r)}catch(e){console.error("黑板观察者回调错误 (节点: "+i.nodeId+"):",e)}}},r.requestAbort=function(e){this.nodesToAbort.add(e)},r.shouldAbort=function(e){return this.nodesToAbort.has(e)},r.clearAbortRequest=function(e){this.nodesToAbort.delete(e)},r.clearAllAbortRequests=function(){this.nodesToAbort.clear()},t}(t.Component),g([t.Serialize(),y("design:type",String)],exports.BehaviorTreeRuntimeComponent.prototype,"treeAssetId",void 0),g([t.Serialize(),y("design:type",Boolean)],exports.BehaviorTreeRuntimeComponent.prototype,"autoStart",void 0),g([t.IgnoreSerialization(),y("design:type",Boolean)],exports.BehaviorTreeRuntimeComponent.prototype,"isRunning",void 0),g([t.IgnoreSerialization(),y("design:type",Map)],exports.BehaviorTreeRuntimeComponent.prototype,"nodeStates",void 0),g([t.IgnoreSerialization(),y("design:type",Map)],exports.BehaviorTreeRuntimeComponent.prototype,"blackboard",void 0),g([t.IgnoreSerialization(),y("design:type",Map)],exports.BehaviorTreeRuntimeComponent.prototype,"blackboardObservers",void 0),g([t.IgnoreSerialization(),y("design:type",Set)],exports.BehaviorTreeRuntimeComponent.prototype,"activeNodeIds",void 0),g([t.IgnoreSerialization(),y("design:type",Boolean)],exports.BehaviorTreeRuntimeComponent.prototype,"needsReset",void 0),g([t.IgnoreSerialization(),y("design:type",Set)],exports.BehaviorTreeRuntimeComponent.prototype,"nodesToAbort",void 0),exports.BehaviorTreeRuntimeComponent=g([t.ECSComponent("BehaviorTreeRuntime"),t.Serializable({version:1})],exports.BehaviorTreeRuntimeComponent);var x=t.createLogger("BehaviorTreeAssetManager"),S=function(){function e(){this.assets=new Map}var t=e.prototype;return t.loadAsset=function(e){this.assets.has(e.id)&&x.warn("行为树资产已存在,将被覆盖: "+e.id),this.assets.set(e.id,e),x.info("行为树资产已加载: "+e.name+" ("+e.nodes.size+"个节点)")},t.getAsset=function(e){return this.assets.get(e)},t.hasAsset=function(e){return this.assets.has(e)},t.unloadAsset=function(e){var t=this.assets.delete(e);return t&&x.info("行为树资产已卸载: "+e),t},t.clearAll=function(){this.assets.clear(),x.info("所有行为树资产已清空")},t.getAssetCount=function(){return this.assets.size},t.getAllAssetIds=function(){return Array.from(this.assets.keys())},t.dispose=function(){this.clearAll()},e}(),T=function(){function e(){}return e.getValue=function(e,t,r){var n=e.nodeData,o=e.runtime;if(n.bindings&&n.bindings[t]){var a=n.bindings[t],i=o.getBlackboardValue(a);return void 0!==i?i:r}var s=n.config[t];return void 0!==s?s:r},e.hasBinding=function(e,t){return!(!e.nodeData.bindings||!e.nodeData.bindings[t])},e.getBindingKey=function(e,t){var r;return null===(r=e.nodeData.bindings)||void 0===r?void 0:r[t]},e}(),b=function(){function e(){this.executors=new Map}var t=e.prototype;return t.register=function(e,t){this.executors.has(e)&&console.warn("执行器已存在,将被覆盖: "+e),this.executors.set(e,t)},t.get=function(e){return this.executors.get(e)},t.has=function(e){return this.executors.has(e)},t.unregister=function(e){return this.executors.delete(e)},t.clear=function(){this.executors.clear()},e}(),k=function(){function e(){}return e.register=function(e,t){this.metadataMap.set(t.implementationType,t),this.executorClassMap.set(e,t.implementationType),this.executorConstructors.set(t.implementationType,e)},e.getMetadata=function(e){return this.metadataMap.get(e)},e.getAllMetadata=function(){return Array.from(this.metadataMap.values())},e.getByCategory=function(e){return this.getAllMetadata().filter((function(t){return t.category===e}))},e.getByNodeType=function(e){return this.getAllMetadata().filter((function(t){return t.nodeType===e}))},e.getImplementationType=function(e){return this.executorClassMap.get(e)},e.getExecutorConstructor=function(e){return this.executorConstructors.get(e)},e.getAllExecutorConstructors=function(){return new Map(this.executorConstructors)},e}();function C(e){return function(t){k.register(t,e)}}k.metadataMap=new Map,k.executorClassMap=new Map,k.executorConstructors=new Map,exports.SequenceExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state;if(!t.children||0===t.children.length)return exports.TaskStatus.Success;for(;r.currentChildIndex<t.children.length;){var n=t.children[r.currentChildIndex],o=e.executeChild(n);if(o===exports.TaskStatus.Running)return exports.TaskStatus.Running;if(o===exports.TaskStatus.Failure)return r.currentChildIndex=0,exports.TaskStatus.Failure;r.currentChildIndex++}return r.currentChildIndex=0,exports.TaskStatus.Success},t.reset=function(e){e.state.currentChildIndex=0},e}(),exports.SequenceExecutor=g([C({implementationType:"Sequence",nodeType:i.Composite,displayName:"序列",description:"按顺序执行子节点,全部成功才成功",category:"Composite"})],exports.SequenceExecutor),exports.SelectorExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;for(;r.currentChildIndex<t.children.length;){var n=t.children[r.currentChildIndex],o=e.executeChild(n);if(o===exports.TaskStatus.Running)return exports.TaskStatus.Running;if(o===exports.TaskStatus.Success)return r.currentChildIndex=0,exports.TaskStatus.Success;r.currentChildIndex++}return r.currentChildIndex=0,exports.TaskStatus.Failure},t.reset=function(e){e.state.currentChildIndex=0},e}(),exports.SelectorExecutor=g([C({implementationType:"Selector",nodeType:i.Composite,displayName:"选择器",description:"按顺序执行子节点,任一成功则成功",category:"Composite"})],exports.SelectorExecutor),exports.ParallelExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=T.getValue(e,"successPolicy","all"),n=T.getValue(e,"failurePolicy","one");if(!t.children||0===t.children.length)return exports.TaskStatus.Success;for(var o,a=!1,i=0,s=0,u=l(t.children);!(o=u()).done;){var c=o.value,d=e.executeChild(c);d===exports.TaskStatus.Running?a=!0:d===exports.TaskStatus.Success?i++:d===exports.TaskStatus.Failure&&s++}return"one"===r&&i>0?(this.stopAllChildren(e),exports.TaskStatus.Success):"all"===r&&i===t.children.length?exports.TaskStatus.Success:"one"===n&&s>0?(this.stopAllChildren(e),exports.TaskStatus.Failure):"all"===n&&s===t.children.length?exports.TaskStatus.Failure:a?exports.TaskStatus.Running:exports.TaskStatus.Success},t.stopAllChildren=function(e){var t=e.nodeData,r=e.runtime;if(t.children)for(var n,o=l(t.children);!(n=o()).done;){var a=n.value;r.activeNodeIds.delete(a),r.resetNodeState(a)}},t.reset=function(e){var t=e.nodeData,r=e.runtime;if(t.children)for(var n,o=l(t.children);!(n=o()).done;){var a=n.value;r.resetNodeState(a)}},e}(),exports.ParallelExecutor=g([C({implementationType:"Parallel",nodeType:i.Composite,displayName:"并行",description:"同时执行所有子节点",category:"Composite",configSchema:{successPolicy:{type:"string",default:"all",description:"成功策略",options:["all","one"]},failurePolicy:{type:"string",default:"one",description:"失败策略",options:["all","one"]}}})],exports.ParallelExecutor),exports.ParallelSelectorExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=T.getValue(e,"failurePolicy","all");if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;for(var n,o=!1,a=0,i=0,s=l(t.children);!(n=s()).done;){var u=n.value,c=e.executeChild(u);c===exports.TaskStatus.Running?o=!0:c===exports.TaskStatus.Success?a++:c===exports.TaskStatus.Failure&&i++}return a>0?(this.stopAllChildren(e),exports.TaskStatus.Success):"one"===r&&i>0?(this.stopAllChildren(e),exports.TaskStatus.Failure):"all"===r&&i===t.children.length?exports.TaskStatus.Failure:o?exports.TaskStatus.Running:exports.TaskStatus.Failure},t.stopAllChildren=function(e){var t=e.nodeData,r=e.runtime;if(t.children)for(var n,o=l(t.children);!(n=o()).done;){var a=n.value;r.activeNodeIds.delete(a),r.resetNodeState(a)}},t.reset=function(e){var t=e.nodeData,r=e.runtime;if(t.children)for(var n,o=l(t.children);!(n=o()).done;){var a=n.value;r.resetNodeState(a)}},e}(),exports.ParallelSelectorExecutor=g([C({implementationType:"ParallelSelector",nodeType:i.Composite,displayName:"并行选择器",description:"并行执行子节点,任一成功则成功",category:"Composite",configSchema:{failurePolicy:{type:"string",default:"all",description:"失败策略",options:["all","one"]}}})],exports.ParallelSelectorExecutor),exports.RandomSequenceExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state;if(!t.children||0===t.children.length)return exports.TaskStatus.Success;for(r.shuffledIndices&&0!==r.shuffledIndices.length||(r.shuffledIndices=this.shuffleIndices(t.children.length));r.currentChildIndex<r.shuffledIndices.length;){var n=r.shuffledIndices[r.currentChildIndex],o=t.children[n],a=e.executeChild(o);if(a===exports.TaskStatus.Running)return exports.TaskStatus.Running;if(a===exports.TaskStatus.Failure)return r.currentChildIndex=0,delete r.shuffledIndices,exports.TaskStatus.Failure;r.currentChildIndex++}return r.currentChildIndex=0,delete r.shuffledIndices,exports.TaskStatus.Success},t.shuffleIndices=function(e){for(var t=Array.from({length:e},(function(e,t){return t})),r=t.length-1;r>0;r--){var n=Math.floor(Math.random()*(r+1)),o=t[r];t[r]=t[n],t[n]=o}return t},t.reset=function(e){e.state.currentChildIndex=0,delete e.state.shuffledIndices},e}(),exports.RandomSequenceExecutor=g([C({implementationType:"RandomSequence",nodeType:i.Composite,displayName:"随机序列",description:"随机顺序执行子节点,全部成功才成功",category:"Composite"})],exports.RandomSequenceExecutor),exports.RandomSelectorExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;for(r.shuffledIndices&&0!==r.shuffledIndices.length||(r.shuffledIndices=this.shuffleIndices(t.children.length));r.currentChildIndex<r.shuffledIndices.length;){var n=r.shuffledIndices[r.currentChildIndex],o=t.children[n],a=e.executeChild(o);if(a===exports.TaskStatus.Running)return exports.TaskStatus.Running;if(a===exports.TaskStatus.Success)return r.currentChildIndex=0,delete r.shuffledIndices,exports.TaskStatus.Success;r.currentChildIndex++}return r.currentChildIndex=0,delete r.shuffledIndices,exports.TaskStatus.Failure},t.shuffleIndices=function(e){for(var t=Array.from({length:e},(function(e,t){return t})),r=t.length-1;r>0;r--){var n=Math.floor(Math.random()*(r+1)),o=t[r];t[r]=t[n],t[n]=o}return t},t.reset=function(e){e.state.currentChildIndex=0,delete e.state.shuffledIndices},e}(),exports.RandomSelectorExecutor=g([C({implementationType:"RandomSelector",nodeType:i.Composite,displayName:"随机选择器",description:"随机顺序执行子节点,任一成功则成功",category:"Composite"})],exports.RandomSelectorExecutor),exports.InverterExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;var r=t.children[0],n=e.executeChild(r);return n===exports.TaskStatus.Running?exports.TaskStatus.Running:n===exports.TaskStatus.Success?exports.TaskStatus.Failure:n===exports.TaskStatus.Failure?exports.TaskStatus.Success:exports.TaskStatus.Failure},t.reset=function(e){e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.InverterExecutor=g([C({implementationType:"Inverter",nodeType:i.Decorator,displayName:"反转",description:"反转子节点的执行结果",category:"Decorator"})],exports.InverterExecutor),exports.RepeaterExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state,n=e.runtime,o=T.getValue(e,"repeatCount",1),a=T.getValue(e,"endOnFailure",!1);if(!t.children||0===t.children.length)return exports.TaskStatus.Success;var i=t.children[0];r.repeatCount||(r.repeatCount=0);var s=e.executeChild(i);return s===exports.TaskStatus.Running?exports.TaskStatus.Running:s===exports.TaskStatus.Failure&&a?(r.repeatCount=0,exports.TaskStatus.Failure):(r.repeatCount++,n.resetNodeState(i),-1===o||r.repeatCount<o?exports.TaskStatus.Running:(r.repeatCount=0,exports.TaskStatus.Success))},t.reset=function(e){delete e.state.repeatCount,e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.RepeaterExecutor=g([C({implementationType:"Repeater",nodeType:i.Decorator,displayName:"重复",description:"重复执行子节点指定次数",category:"Decorator",configSchema:{repeatCount:{type:"number",default:1,description:"重复次数(-1表示无限循环)",supportBinding:!0},endOnFailure:{type:"boolean",default:!1,description:"子节点失败时是否结束"}}})],exports.RepeaterExecutor),exports.AlwaysSucceedExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData;if(!t.children||0===t.children.length)return exports.TaskStatus.Success;var r=t.children[0];return e.executeChild(r)===exports.TaskStatus.Running?exports.TaskStatus.Running:exports.TaskStatus.Success},t.reset=function(e){e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.AlwaysSucceedExecutor=g([C({implementationType:"AlwaysSucceed",nodeType:i.Decorator,displayName:"总是成功",description:"无论子节点结果如何都返回成功",category:"Decorator"})],exports.AlwaysSucceedExecutor),exports.AlwaysFailExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;var r=t.children[0];return e.executeChild(r)===exports.TaskStatus.Running?exports.TaskStatus.Running:exports.TaskStatus.Failure},t.reset=function(e){e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.AlwaysFailExecutor=g([C({implementationType:"AlwaysFail",nodeType:i.Decorator,displayName:"总是失败",description:"无论子节点结果如何都返回失败",category:"Decorator"})],exports.AlwaysFailExecutor),exports.UntilSuccessExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.runtime;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;var n=t.children[0],o=e.executeChild(n);return o===exports.TaskStatus.Running?exports.TaskStatus.Running:o===exports.TaskStatus.Success?exports.TaskStatus.Success:(r.resetNodeState(n),exports.TaskStatus.Running)},t.reset=function(e){e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.UntilSuccessExecutor=g([C({implementationType:"UntilSuccess",nodeType:i.Decorator,displayName:"直到成功",description:"重复执行子节点直到成功",category:"Decorator"})],exports.UntilSuccessExecutor),exports.UntilFailExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.runtime;if(!t.children||0===t.children.length)return exports.TaskStatus.Success;var n=t.children[0],o=e.executeChild(n);return o===exports.TaskStatus.Running?exports.TaskStatus.Running:o===exports.TaskStatus.Failure?exports.TaskStatus.Failure:(r.resetNodeState(n),exports.TaskStatus.Running)},t.reset=function(e){e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.UntilFailExecutor=g([C({implementationType:"UntilFail",nodeType:i.Decorator,displayName:"直到失败",description:"重复执行子节点直到失败",category:"Decorator"})],exports.UntilFailExecutor),exports.ConditionalExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.runtime,n=e.state;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;var o=T.getValue(e,"blackboardKey",""),a=T.getValue(e,"expectedValue"),i=T.getValue(e,"operator","equals"),s=t.abortType||exports.AbortType.None;if(!o)return exports.TaskStatus.Failure;var u=r.getBlackboardValue(o),c=this.evaluateCondition(u,a,i),d=n.status===exports.TaskStatus.Running;if(s!==exports.AbortType.None&&(n.observedKeys&&0!==n.observedKeys.length||(n.observedKeys=[o],this.setupObserver(e,o,a,i,s)),void 0!==n.lastConditionResult&&n.lastConditionResult!==c&&(c?this.handleConditionBecameTrue(e,s):d&&this.handleConditionBecameFalse(e,s))),n.lastConditionResult=c,!c)return exports.TaskStatus.Failure;var l=t.children[0];return e.executeChild(l)},t.evaluateCondition=function(e,t,r){switch(r){case"equals":return e===t;case"notEquals":return e!==t;case"greaterThan":return e>t;case"lessThan":return e<t;case"greaterOrEqual":return e>=t;case"lessOrEqual":return e<=t;default:return!1}},t.setupObserver=function(e,t,r,n,o){var a=this,i=e.nodeData;e.runtime.observeBlackboard(i.id,[t],(function(t,i){var s=a.evaluateCondition(i,r,n),u=e.state.lastConditionResult;void 0!==u&&u!==s&&(s?a.handleConditionBecameTrue(e,o):a.handleConditionBecameFalse(e,o)),e.state.lastConditionResult=s}))},t.handleConditionBecameTrue=function(e,t){t!==exports.AbortType.LowerPriority&&t!==exports.AbortType.Both||this.requestAbortLowerPriority(e)},t.handleConditionBecameFalse=function(e,t){var r=e.nodeData,n=e.runtime;t!==exports.AbortType.Self&&t!==exports.AbortType.Both||r.children&&r.children.length>0&&n.requestAbort(r.children[0])},t.requestAbortLowerPriority=function(e){e.runtime.requestAbort("__lower_priority__")},t.reset=function(e){var t=e.nodeData,r=e.runtime,n=e.state;n.observedKeys&&n.observedKeys.length>0&&(r.unobserveBlackboard(t.id),delete n.observedKeys),delete n.lastConditionResult,t.children&&t.children.length>0&&r.resetNodeState(t.children[0])},e}(),exports.ConditionalExecutor=g([C({implementationType:"Conditional",nodeType:i.Decorator,displayName:"条件",description:"根据条件决定是否执行子节点",category:"Decorator",configSchema:{blackboardKey:{type:"string",default:"",description:"黑板变量名"},expectedValue:{type:"object",description:"期望值",supportBinding:!0},operator:{type:"string",default:"equals",description:"比较运算符",options:["equals","notEquals","greaterThan","lessThan","greaterOrEqual","lessOrEqual"]},abortType:{type:"string",default:"none",description:"中止类型",options:["none","self","lower-priority","both"]}}})],exports.ConditionalExecutor),exports.CooldownExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state,n=e.totalTime;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;var o=T.getValue(e,"cooldownTime",1);if(void 0!==r.lastExecutionTime&&n-r.lastExecutionTime<o)return exports.TaskStatus.Failure;var a=t.children[0],i=e.executeChild(a);return i===exports.TaskStatus.Running?exports.TaskStatus.Running:i===exports.TaskStatus.Success?(r.lastExecutionTime=n,exports.TaskStatus.Success):exports.TaskStatus.Failure},t.reset=function(e){delete e.state.lastExecutionTime,e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.CooldownExecutor=g([C({implementationType:"Cooldown",nodeType:i.Decorator,displayName:"冷却",description:"子节点执行成功后进入冷却时间",category:"Decorator",configSchema:{cooldownTime:{type:"number",default:1,description:"冷却时间(秒)",min:0,supportBinding:!0}}})],exports.CooldownExecutor),exports.TimeoutExecutor=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state,n=e.totalTime;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;var o=T.getValue(e,"timeout",1);if(void 0===r.startTime&&(r.startTime=n),n-r.startTime>=o)return delete r.startTime,exports.TaskStatus.Failure;var a=t.children[0],i=e.executeChild(a);return i===exports.TaskStatus.Running?exports.TaskStatus.Running:(delete r.startTime,i)},t.reset=function(e){delete e.state.startTime,e.nodeData.children&&e.nodeData.children.length>0&&e.runtime.resetNodeState(e.nodeData.children[0])},e}(),exports.TimeoutExecutor=g([C({implementationType:"Timeout",nodeType:i.Decorator,displayName:"超时",description:"限制子节点的执行时间",category:"Decorator",configSchema:{timeout:{type:"number",default:1,description:"超时时间(秒)",min:0,supportBinding:!0}}})],exports.TimeoutExecutor);var N=function(){function e(){}return e.register=function(e,t){this.services.set(e,t)},e.get=function(e){return this.services.get(e)},e.has=function(e){return this.services.has(e)},e.unregister=function(e){return this.services.delete(e)},e}();N.services=new Map,exports.ServiceDecorator=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.nodeData,r=e.state,n=e.totalTime;if(!t.children||0===t.children.length)return exports.TaskStatus.Failure;var o=T.getValue(e,"serviceName",""),a=T.getValue(e,"tickInterval",0);if(!o)return exports.TaskStatus.Failure;var i=N.get(o);if(!i)return console.warn("未找到Service: "+o),exports.TaskStatus.Failure;r.status!==exports.TaskStatus.Running&&(r.startTime=n,r.lastExecutionTime=n,i.onServiceStart&&i.onServiceStart(e)),(0===a||void 0!==r.lastExecutionTime&&n-r.lastExecutionTime>=a)&&(i.onServiceTick(e),r.lastExecutionTime=n);var s=t.children[0],u=e.executeChild(s);return u!==exports.TaskStatus.Running&&i.onServiceEnd&&i.onServiceEnd(e),u},t.reset=function(e){var t=e.nodeData,r=e.runtime,n=e.state,o=T.getValue(e,"serviceName","");if(o){var a=N.get(o);a&&a.onServiceEnd&&a.onServiceEnd(e)}delete n.startTime,delete n.lastExecutionTime,t.children&&t.children.length>0&&r.resetNodeState(t.children[0])},e}(),exports.ServiceDecorator=g([C({implementationType:"Service",nodeType:i.Decorator,displayName:"Service",description:"在子节点执行期间持续运行后台逻辑",category:"Decorator",configSchema:{serviceName:{type:"string",default:"",description:"Service名称"},tickInterval:{type:"number",default:0,description:"Service更新间隔(秒,0表示每帧更新)",supportBinding:!0}}})],exports.ServiceDecorator),exports.WaitAction=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.state,r=e.totalTime,n=T.getValue(e,"duration",1);return t.startTime?r-t.startTime>=n?exports.TaskStatus.Success:exports.TaskStatus.Running:(t.startTime=r,exports.TaskStatus.Running)},t.reset=function(e){delete e.state.startTime},e}(),exports.WaitAction=g([C({implementationType:"Wait",nodeType:i.Action,displayName:"等待",description:"等待指定时间后返回成功",category:"Action",configSchema:{duration:{type:"number",default:1,description:"等待时长(秒)",min:0,supportBinding:!0}}})],exports.WaitAction),exports.LogAction=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.runtime,r=T.getValue(e,"message",""),n=T.getValue(e,"logLevel","info"),o=this.replaceBlackboardVariables(r,t);return this.log(o,n),exports.TaskStatus.Success},t.replaceBlackboardVariables=function(e,t){return e.includes("{")&&e.includes("}")?e.replace(/\{([\w.]{1,100})\}/g,(function(e,r){var n=t.getBlackboardValue(r.trim());return void 0!==n?String(n):"{"+r+"}"})):e},t.log=function(e,t){switch(t){case"error":console.error(e);break;case"warn":console.warn(e);break;default:console.log(e)}},e}(),exports.LogAction=g([C({implementationType:"Log",nodeType:i.Action,displayName:"日志",description:"输出日志信息",category:"Action",configSchema:{message:{type:"string",default:"",description:"日志消息,支持{key}占位符引用黑板变量",supportBinding:!0},logLevel:{type:"string",default:"info",description:"日志级别",options:["info","warn","error"]}}})],exports.LogAction),exports.SetBlackboardValue=function(){function e(){}return e.prototype.execute=function(e){var t=e.runtime,r=T.getValue(e,"key",""),n=T.getValue(e,"value");return r?(t.setBlackboardValue(r,n),exports.TaskStatus.Success):exports.TaskStatus.Failure},e}(),exports.SetBlackboardValue=g([C({implementationType:"SetBlackboardValue",nodeType:i.Action,displayName:"设置黑板值",description:"设置黑板中的变量值",category:"Action",configSchema:{key:{type:"string",default:"",description:"黑板变量名"},value:{type:"object",description:"要设置的值",supportBinding:!0}}})],exports.SetBlackboardValue),exports.ModifyBlackboardValue=function(){function e(){}return e.prototype.execute=function(e){var t=e.runtime,r=T.getValue(e,"key",""),n=T.getValue(e,"operation","add"),o=T.getValue(e,"value",0);if(!r)return exports.TaskStatus.Failure;var a,i=t.getBlackboardValue(r)||0;switch(n){case"add":a=i+o;break;case"subtract":a=i-o;break;case"multiply":a=i*o;break;case"divide":a=0!==o?i/o:i;break;case"set":a=o;break;default:return exports.TaskStatus.Failure}return t.setBlackboardValue(r,a),exports.TaskStatus.Success},e}(),exports.ModifyBlackboardValue=g([C({implementationType:"ModifyBlackboardValue",nodeType:i.Action,displayName:"修改黑板值",description:"对黑板中的数值进行运算",category:"Action",configSchema:{key:{type:"string",default:"",description:"黑板变量名"},operation:{type:"string",default:"add",description:"运算类型",options:["add","subtract","multiply","divide","set"]},value:{type:"number",default:0,description:"操作数",supportBinding:!0}}})],exports.ModifyBlackboardValue),exports.ExecuteAction=function(){function e(){}return e.prototype.execute=function(e){var t=e.runtime,r=e.entity,n=T.getValue(e,"actionName","");if(!n)return exports.TaskStatus.Failure;var o=t.getBlackboardValue("action_"+n);if(!o||"function"!=typeof o)return exports.TaskStatus.Failure;try{return o(r)}catch(e){return console.error("ExecuteAction failed: "+e),exports.TaskStatus.Failure}},e}(),exports.ExecuteAction=g([C({implementationType:"ExecuteAction",nodeType:i.Action,displayName:"执行动作",description:"执行自定义动作逻辑",category:"Action",configSchema:{actionName:{type:"string",default:"",description:"动作名称(黑板中action_前缀的函数)"}}})],exports.ExecuteAction),exports.SubTreeExecutor=function(){function e(){this.assetManager=null}var r=e.prototype;return r.getAssetManager=function(){return this.assetManager||(this.assetManager=t.Core.services.resolve(S)),this.assetManager},r.execute=function(e){var t=this,r=e.runtime,n=e.state,o=e.entity,a=T.getValue(e,"treeAssetId",""),i=T.getValue(e,"shareBlackboard",!0);if(!a)return exports.TaskStatus.Failure;var s=this.getAssetManager().getAsset(a);if(!s)return console.warn("未找到子树资产: "+a),exports.TaskStatus.Failure;var u=s.nodes.get(s.rootNodeId);if(!u)return console.warn("子树根节点未找到: "+s.rootNodeId),exports.TaskStatus.Failure;if(!i&&n.status!==exports.TaskStatus.Running&&s.blackboardVariables)for(var c,d=l(s.blackboardVariables.entries());!(c=d()).done;){var p=c.value,f=p[0],h=p[1];r.hasBlackboardKey(f)||r.setBlackboardValue(f,h)}var v={entity:o,nodeData:u,state:r.getNodeState(u.id),runtime:r,treeData:s,deltaTime:e.deltaTime,totalTime:e.totalTime,executeChild:function(n){var a=s.nodes.get(n);if(!a)return console.warn("子树节点未找到: "+n),exports.TaskStatus.Failure;var i={entity:o,nodeData:a,state:r.getNodeState(n),runtime:r,treeData:s,deltaTime:e.deltaTime,totalTime:e.totalTime,executeChild:v.executeChild};return t.executeSubTreeNode(i)}};return this.executeSubTreeNode(v)},r.executeSubTreeNode=function(e){var t=e.nodeData,r=e.runtime.getNodeState(t.id);if(!t.children||0===t.children.length)return exports.TaskStatus.Success;var n=t.children[r.currentChildIndex],o=e.executeChild(n);return o===exports.TaskStatus.Running?exports.TaskStatus.Running:o===exports.TaskStatus.Failure?(r.currentChildIndex=0,exports.TaskStatus.Failure):(r.currentChildIndex++,r.currentChildIndex>=t.children.length?(r.currentChildIndex=0,exports.TaskStatus.Success):exports.TaskStatus.Running)},r.reset=function(e){var t=T.getValue(e,"treeAssetId","");if(t){var r=this.getAssetManager().getAsset(t);if(r){var n=r.nodes.get(r.rootNodeId);if(n&&(e.runtime.resetNodeState(n.id),n.children))for(var o,a=l(n.children);!(o=a()).done;){var i=o.value;e.runtime.resetNodeState(i)}}}},e}(),exports.SubTreeExecutor=g([C({implementationType:"SubTree",nodeType:i.Action,displayName:"子树",description:"引用并执行其他行为树",category:"Special",configSchema:{treeAssetId:{type:"string",default:"",description:"要执行的行为树资产ID",supportBinding:!0},shareBlackboard:{type:"boolean",default:!0,description:"是否共享黑板数据"}}})],exports.SubTreeExecutor),exports.BlackboardCompare=function(){function e(){}var t=e.prototype;return t.execute=function(e){var t=e.runtime,r=T.getValue(e,"key",""),n=T.getValue(e,"compareValue"),o=T.getValue(e,"operator","equals");if(!r)return exports.TaskStatus.Failure;var a=t.getBlackboardValue(r);return this.compare(a,n,o)?exports.TaskStatus.Success:exports.TaskStatus.Failure},t.compare=function(e,t,r){switch(r){case"equals":return e===t;case"notEquals":return e!==t;case"greaterThan":return e>t;case"lessThan":return e<t;case"greaterOrEqual":return e>=t;case"lessOrEqual":return e<=t;default:return!1}},e}(),exports.BlackboardCompare=g([C({implementationType:"BlackboardCompare",nodeType:i.Condition,displayName:"黑板比较",description:"比较黑板中的值",category:"Condition",configSchema:{key:{type:"string",default:"",description:"黑板变量名"},compareValue:{type:"object",description:"比较值",supportBinding:!0},operator:{type:"string",default:"equals",description:"比较运算符",options:["equals","notEquals","greaterThan","lessThan","greaterOrEqual","lessOrEqual"]}}})],exports.BlackboardCompare),exports.BlackboardExists=function(){function e(){}return e.prototype.execute=function(e){var t=e.runtime,r=T.getValue(e,"key",""),n=T.getValue(e,"checkNull",!1);if(!r)return exports.TaskStatus.Failure;var o=t.getBlackboardValue(r);return void 0===o||n&&null===o?exports.TaskStatus.Failure:exports.TaskStatus.Success},e}(),exports.BlackboardExists=g([C({implementationType:"BlackboardExists",nodeType:i.Condition,displayName:"黑板存在",description:"检查黑板中是否存在指定的键",category:"Condition",configSchema:{key:{type:"string",default:"",description:"黑板变量名"},checkNull:{type:"boolean",default:!1,description:"检查是否为null"}}})],exports.BlackboardExists),exports.RandomProbability=function(){function e(){}return e.prototype.execute=function(e){var t=T.getValue(e,"probability",.5),r=Math.max(0,Math.min(1,t));return Math.random()<r?exports.TaskStatus.Success:exports.TaskStatus.Failure},e}(),exports.RandomProbability=g([C({implementationType:"RandomProbability",nodeType:i.Condition,displayName:"随机概率",description:"根据概率返回成功或失败",category:"Condition",configSchema:{probability:{type:"number",default:.5,description:"成功概率(0-1)",min:0,max:1,supportBinding:!0}}})],exports.RandomProbability),exports.ExecuteCondition=function(){function e(){}return e.prototype.execute=function(e){var t=e.runtime,r=e.entity,n=T.getValue(e,"conditionName","");if(!n)return exports.TaskStatus.Failure;var o=t.getBlackboardValue("condition_"+n);if(!o||"function"!=typeof o)return exports.TaskStatus.Failure;try{return o(r)?exports.TaskStatus.Success:exports.TaskStatus.Failure}catch(e){return console.error("ExecuteCondition failed: "+e),exports.TaskStatus.Failure}},e}(),exports.ExecuteCondition=g([C({implementationType:"ExecuteCondition",nodeType:i.Condition,displayName:"执行条件",description:"执行自定义条件逻辑",category:"Condition",configSchema:{conditionName:{type:"string",default:"",description:"条件名称(黑板中condition_前缀的函数)"}}})],exports.ExecuteCondition),exports.BehaviorTreeExecutionSystem=function(e){function r(){var r;return(r=e.call(this,t.Matcher.empty().all(exports.BehaviorTreeRuntimeComponent))||this).assetManager=t.Core.services.resolve(S),r.executorRegistry=new b,r.registerBuiltInExecutors(),r}f(r,e);var n=r.prototype;return n.registerBuiltInExecutors=function(){for(var e,t=l(k.getAllExecutorConstructors());!(e=t()).done;){var r=e.value,n=r[0],o=r[1];try{var a=new o;this.executorRegistry.register(n,a)}catch(e){this.logger.error("注册执行器失败: "+n,e)}}},n.getExecutorRegistry=function(){return this.executorRegistry},n.process=function(e){for(var t,r=l(e);!(t=r()).done;){var n=t.value,o=n.getComponent(exports.BehaviorTreeRuntimeComponent);if(o.isRunning){var a=this.assetManager.getAsset(o.treeAssetId);a?(o.needsReset&&(o.resetAllStates(),o.needsReset=!1),this.executeTree(n,o,a)):this.logger.warn("未找到行为树资产: "+o.treeAssetId)}}},n.executeTree=function(e,t,r){var n=r.nodes.get(r.rootNodeId);n?this.executeNode(e,t,n,r)!==exports.TaskStatus.Running?t.needsReset=!0:t.needsReset=!1:this.logger.error("未找到根节点: "+r.rootNodeId)},n.executeNode=function(e,t,r,n){var o=t.getNodeState(r.id);if(t.shouldAbort(r.id)){t.clearAbortRequest(r.id),o.isAborted=!0;var a=this.executorRegistry.get(r.implementationType);if(a&&a.reset){var i=this.createContext(e,t,r,n);a.reset(i)}return t.activeNodeIds.delete(r.id),o.status=exports.TaskStatus.Failure,exports.TaskStatus.Failure}t.activeNodeIds.add(r.id),o.isAborted=!1;var s=this.executorRegistry.get(r.implementationType);if(!s)return this.logger.error("未找到执行器: "+r.implementationType),o.status=exports.TaskStatus.Failure,exports.TaskStatus.Failure;var u=this.createContext(e,t,r,n);try{var c=s.execute(u);return o.status=c,c!==exports.TaskStatus.Running&&(t.activeNodeIds.delete(r.id),s.reset&&s.reset(u)),c}catch(e){return this.logger.error("执行节点时发生错误: "+r.name,e),o.status=exports.TaskStatus.Failure,t.activeNodeIds.delete(r.id),exports.TaskStatus.Failure}},n.createContext=function(e,r,n,o){var a=this;return{entity:e,nodeData:n,state:r.getNodeState(n.id),runtime:r,treeData:o,deltaTime:t.Time.deltaTime,totalTime:t.Time.totalTime,executeChild:function(t){var n=o.nodes.get(t);return n?a.executeNode(e,r,n,o):(a.logger.warn("未找到子节点: "+t),exports.TaskStatus.Failure)}}},n.executeChildren=function(e,t){var r=e.nodeData,n=e.treeData,o=e.entity,a=e.runtime;if(!r.children||0===r.children.length)return[];for(var i,s=[],u=l(t||Array.from({length:r.children.length},(function(e,t){return t})));!(i=u()).done;){var c=i.value;if(!(c>=r.children.length)){var d=r.children[c],p=n.nodes.get(d);if(p){var f=this.executeNode(o,a,p,n);s.push(f)}else this.logger.warn("未找到子节点: "+d),s.push(exports.TaskStatus.Failure)}}return s},r}(t.EntitySystem),exports.BehaviorTreeExecutionSystem=g([t.ECSSystem("BehaviorTreeExecution"),y("design:paramtypes",[])],exports.BehaviorTreeExecutionSystem);var A=function(){function e(){}return e.start=function(e,r,n){void 0===n&&(n=!0),t.Core.services.resolve(S).loadAsset(r);var o=e.getComponent(exports.BehaviorTreeRuntimeComponent);if(o||(o=new exports.BehaviorTreeRuntimeComponent,e.addComponent(o)),o.treeAssetId=r.id,o.autoStart=n,r.blackboardVariables)for(var a,i=l(r.blackboardVariables.entries());!(a=i()).done;){var s=a.value,u=s[0],c=s[1];o.setBlackboardValue(u,c)}n&&(o.isRunning=!0)},e.stop=function(e){var t=e.getComponent(exports.BehaviorTreeRuntimeComponent);t&&(t.isRunning=!1,t.resetAllStates())},e.pause=function(e){var t=e.getComponent(exports.BehaviorTreeRuntimeComponent);t&&(t.isRunning=!1)},e.resume=function(e){var t=e.getComponent(exports.BehaviorTreeRuntimeComponent);t&&(t.isRunning=!0)},e.restart=function(e){var t=e.getComponent(exports.BehaviorTreeRuntimeComponent);t&&(t.resetAllStates(),t.isRunning=!0)},e}(),B=function(){function e(e){this.nodeStack=[],this.nodeIdCounter=0,this.treeData={id:"tree_"+Date.now(),name:e,rootNodeId:"",nodes:new Map,blackboardVariables:new Map}}e.create=function(t){return void 0===t&&(t="BehaviorTree"),new e(t)};var t=e.prototype;return t.defineBlackboardVariable=function(e,t){return this.treeData.blackboardVariables||(this.treeData.blackboardVariables=new Map),this.treeData.blackboardVariables.set(e,t),this},t.sequence=function(e){return this.addCompositeNode("Sequence",e||"Sequence")},t.selector=function(e){return this.addCompositeNode("Selector",e||"Selector")},t.parallel=function(e,t){return this.addCompositeNode("Parallel",e||"Parallel",t)},t.parallelSelector=function(e,t){return this.addCompositeNode("ParallelSelector",e||"ParallelSelector",t)},t.randomSequence=function(e){return this.addCompositeNode("RandomSequence",e||"RandomSequence")},t.randomSelector=function(e){return this.addCompositeNode("RandomSelector",e||"RandomSelector")},t.inverter=function(e){return this.addDecoratorNode("Inverter",e||"Inverter")},t.repeater=function(e,t){return this.addDecoratorNode("Repeater",t||"Repeater",{repeatCount:e})},t.alwaysSucceed=function(e){return this.addDecoratorNode("AlwaysSucceed",e||"AlwaysSucceed")},t.alwaysFail=function(e){return this.addDecoratorNode("AlwaysFail",e||"AlwaysFail")},t.untilSuccess=function(e){return this.addDecoratorNode("UntilSuccess",e||"UntilSuccess")},t.untilFail=function(e){return this.addDecoratorNode("UntilFail",e||"UntilFail")},t.conditional=function(e,t,r,n){return this.addDecoratorNode("Conditional",n||"Conditional",{blackboardKey:e,expectedValue:t,operator:r||"equals"})},t.cooldown=function(e,t){return this.addDecoratorNode("Cooldown",t||"Cooldown",{cooldownTime:e})},t.timeout=function(e,t){return this.addDecoratorNode("Timeout",t||"Timeout",{timeout:e})},t.wait=function(e,t){return this.addActionNode("Wait",t||"Wait",{duration:e})},t.log=function(e,t){return this.addActionNode("Log",t||"Log",{message:e})},t.setBlackboardValue=function(e,t,r){return this.addActionNode("SetBlackboardValue",r||"SetBlackboardValue",{key:e,value:t})},t.modifyBlackboardValue=function(e,t,r,n){return this.addActionNode("ModifyBlackboardValue",n||"ModifyBlackboardValue",{key:e,operation:t,value:r})},t.executeAction=function(e,t){return this.addActionNode("ExecuteAction",t||"ExecuteAction",{actionName:e})},t.blackboardCompare=function(e,t,r,n){return this.addConditionNode("BlackboardCompare",n||"BlackboardCompare",{key:e,compareValue:t,operator:r||"equals"})},t.blackboardExists=function(e,t){return this.addConditionNode("BlackboardExists",t||"BlackboardExists",{key:e})},t.randomProbability=function(e,t){return this.addConditionNode("RandomProbability",t||"RandomProbability",{probability:e})},t.executeCondition=function(e,t){return this.addConditionNode("ExecuteCondition",t||"ExecuteCondition",{conditionName:e})},t.end=function(){return this.nodeStack.length>0&&this.nodeStack.pop(),this},t.build=function(){if(!this.treeData.rootNodeId)throw new Error("No root node defined. Add at least one node to the tree.");return this.treeData},t.addCompositeNode=function(e,t,r){void 0===r&&(r={});var n=this.generateNodeId(),o={id:n,name:t,nodeType:i.Composite,implementationType:e,children:[],config:r};if(this.treeData.nodes.set(n,o),this.treeData.rootNodeId||(this.treeData.rootNodeId=n),this.nodeStack.length>0){var a=this.nodeStack[this.nodeStack.length-1],s=this.treeData.nodes.get(a);s&&s.children&&s.children.push(n)}return this.nodeStack.push(n),this},t.addDecoratorNode=function(e,t,r){void 0===r&&(r={});var n=this.generateNodeId(),o={id:n,name:t,nodeType:i.Decorator,implementationType:e,children:[],config:r};if(this.treeData.nodes.set(n,o),this.treeData.rootNodeId||(this.treeData.rootNodeId=n),this.nodeStack.length>0){var a=this.nodeStack[this.nodeStack.length-1],s=this.treeData.nodes.get(a);s&&s.children&&s.children.push(n)}return this.nodeStack.push(n),this},t.addActionNode=function(e,t,r){void 0===r&&(r={});var n=this.generateNodeId(),o={id:n,name:t,nodeType:i.Action,implementationType:e,config:r};if(this.treeData.nodes.set(n,o),this.treeData.rootNodeId||(this.treeData.rootNodeId=n),this.nodeStack.length>0){var a=this.nodeStack[this.nodeStack.length-1],s=this.treeData.nodes.get(a);s&&s.children&&s.children.push(n)}return this},t.addConditionNode=function(e,t,r){void 0===r&&(r={});var n=this.generateNodeId(),o={id:n,name:t,nodeType:i.Condition,implementationType:e,config:r};if(this.treeData.nodes.set(n,o),this.treeData.rootNodeId||(this.treeData.rootNodeId=n),this.nodeStack.length>0){var a=this.nodeStack[this.nodeStack.length-1],s=this.treeData.nodes.get(a);s&&s.children&&s.children.push(n)}return this},t.generateNodeId=function(){return"node_"+this.nodeIdCounter++},e}(),w={String:"string",Number:"number",Boolean:"boolean",Select:"select",Blackboard:"blackboard",Code:"code",Variable:"variable",Asset:"asset"},I=function(){function e(){}return e.getAllTemplates=function(){var e=this;return k.getAllMetadata().map((function(t){return e.convertMetadataToTemplate(t)}))},e.getTemplate=function(e,t){return this.getAllTemplates().find((function(r){if(r.type!==e)return!1;var n=r.defaultConfig;switch(e){case i.Composite:return n.compositeType===t;case i.Decorator:return n.decoratorType===t;case i.Action:return n.actionType===t;case i.Condition:return n.conditionType===t;default:return!1}}))},e.convertMetadataToTemplate=function(e){var t=this.convertConfigSchemaToProperties(e.configSchema||{}),r={nodeType:this.nodeTypeToString(e.nodeType)};switch(e.nodeType){case i.Composite:r.compositeType=e.implementationType;break;case i.Decorator:r.decoratorType=e.implementationType;break;case i.Action:r.actionType=e.implementationType;break;case i.Condition:r.conditionType=e.implementationType}if(e.configSchema)for(var n=0,o=Object.entries(e.configSchema);n<o.length;n++){var a=o[n],s=a[0],u=a[1];void 0!==u.default&&(r[s]=u.default)}var c=this.getIconAndColorByType(e.nodeType,e.category||""),d=c.icon,l=c.color;return{type:e.nodeType,displayName:e.displayName,category:e.category||this.getCategoryByNodeType(e.nodeType),description:e.description||"",className:e.implementationType,icon:d,color:l,defaultConfig:r,properties:t}},e.convertConfigSchemaToProperties=function(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],i=o[1],s={name:a,type:this.mapFieldTypeToPropertyType(i),label:a};void 0!==i.description&&(s.description=i.description),void 0!==i.default&&(s.defaultValue=i.default),void 0!==i.min&&(s.min=i.min),void 0!==i.max&&(s.max=i.max),void 0!==i.allowMultipleConnections&&(s.allowMultipleConnections=i.allowMultipleConnections),i.options&&(s.options=i.options.map((function(e){return{label:e,value:e}}))),i.supportBinding&&(s.renderConfig={component:"BindableInput",props:{supportBinding:!0}}),t.push(s)}return t},e.mapFieldTypeToPropertyType=function(e){if(e.options&&e.options.length>0)return w.Select;switch(e.type){case"string":case"array":case"object":default:return w.String;case"number":return w.Number;case"boolean":return w.Boolean}},e.nodeTypeToString=function(e){switch(e){case i.Composite:return"composite";case i.Decorator:return"decorator";case i.Action:return"action";case i.Condition:return"condition";default:return"unknown"}},e.getCategoryByNodeType=function(e){switch(e){case i.Composite:return"组合";case i.Decorator:return"装饰器";case i.Action:return"动作";case i.Condition:return"条件";default:return"其他"}},e.getIconAndColorByType=function(e,t){switch(e){case i.Composite:return{icon:"GitBranch",color:"#1976d2"};case i.Decorator:return{icon:"Settings",color:"#fb8c00"};case i.Action:return{icon:"Play",color:"#388e3c"};case i.Condition:return{icon:"HelpCircle",color:"#d32f2f"};default:return{icon:"Circle",color:"#757575"}}},e}(),R=function(){function e(){}return e.validate=function(e){var t=[],r=[];if(e.version||t.push("Missing version field"),e.metadata&&e.metadata.name||t.push("Missing or invalid metadata"),e.rootNodeId||t.push("Missing rootNodeId"),e.nodes&&Array.isArray(e.nodes)){var n=new Set;e.nodes.find((function(t){return t.id===e.rootNodeId}))||t.push("Root node '"+e.rootNodeId+"' not found in nodes array");for(var o,a=l(e.nodes);!(o=a()).done;){var i=o.value;if(i.id){if(n.has(i.id)&&t.push("Duplicate node id: "+i.id),n.add(i.id),i.nodeType||t.push("Node "+i.id+" missing nodeType"),i.children)for(var s,u=function(){var r=s.value;e.nodes.find((function(e){return e.id===r}))||t.push("Node "+i.id+" references non-existent child: "+r)},c=l(i.children);!(s=c()).done;)u()}else t.push("Node missing id field")}var d=new Set([e.rootNodeId]),p=function(t){var r=e.nodes.find((function(e){return e.id===t}));if(r&&r.children)for(var n,o=l(r.children);!(n=o()).done;){var a=n.value;d.add(a),p(a)}};p(e.rootNodeId);for(var f,h=l(e.nodes);!(f=h()).done;){var v=f.value;d.has(v.id)||r.push("Orphaned node detected: "+v.id+" ("+v.name+")")}}else t.push("Missing or invalid nodes array");if(e.blackboard&&Array.isArray(e.blackboard))for(var m,g=new Set,y=l(e.blackboard);!(m=y()).done;){var x=m.value;x.name?(g.has(x.name)&&t.push("Duplicate blackboard variable: "+x.name),g.add(x.name),x.type||t.push("Blackboard variable "+x.name+" missing type")):t.push("Blackboard variable missing name")}if(e.propertyBindings&&Array.isArray(e.propertyBindings))for(var S,T,b=new Set(e.nodes.map((function(e){return e.id}))),k=new Set((null===(S=e.blackboard)||void 0===S?void 0:S.map((function(e){return e.name})))||[]),C=l(e.propertyBindings);!(T=C()).done;){var N=T.value;b.has(N.nodeId)||t.push("Property binding references non-existent node: "+N.nodeId),k.has(N.variableName)||t.push("Property binding references non-existent variable: "+N.variableName),N.propertyName||t.push("Property binding missing propertyName")}var A={valid:0===t.length};return t.length>0&&(A.errors=t),r.length>0&&(A.warnings=r),A},e.getStats=function(e){for(var t,r,n,o=0,a=0,s=0,u=0,c=l(e.nodes);!(n=c()).done;){switch(n.value.nodeType){case i.Action:o++;break;case i.Condition:a++;break;case i.Composite:s++;break;case i.Decorator:u++}}var d=function(t,r){void 0===r&&(r=0);var n=e.nodes.find((function(e){return e.id===t}));if(!n||!n.children||0===n.children.length)return r;for(var o,a=r,i=l(n.children);!(o=i()).done;){var s=o.value,u=d(s,r+1);a=Math.max(a,u)}return a};return{nodeCount:e.nodes.length,actionCount:o,conditionCount:a,compositeCount:s,decoratorCount:u,blackboardVariableCount:(null===(t=e.blackboard)||void 0===t?void 0:t.length)||0,propertyBindingCount:(null===(r=e.propertyBindings)||void 0===r?void 0:r.length)||0,maxDepth:d(e.rootNodeId)}},e}(),D=t.createLogger("EditorFormatConverter"),E=function(){function e(){}return e.toAsset=function(e,t){var r,n,o;D.info("开始转换编辑器格式到资产格式");var a=this.findRootNode(e.nodes);if(!a)throw new Error("未找到根节点");var i={name:(null==t?void 0:t.name)||(null===(r=e.metadata)||void 0===r?void 0:r.name)||"Untitled Behavior Tree",version:(null==t?void 0:t.version)||e.version||"1.0.0"},s=(null==t?void 0:t.description)||(null===(n=e.metadata)||void 0===n?void 0:n.description);s&&(i.description=s);var u=(null==t?void 0:t.createdAt)||(null===(o=e.metadata)||void 0===o?void 0:o.createdAt);u&&(i.createdAt=u);var c=(null==t?void 0:t.modifiedAt)||(new Date).toISOString();c&&(i.modifiedAt=c);var d=this.convertNodes(e.nodes),l=this.convertBlackboard(e.blackboard),p=this.convertPropertyBindings(e.connections,e.nodes,l),f={version:"1.0.0",metadata:i,rootNodeId:a.id,nodes:d,blackboard:l};return p.length>0&&(f.propertyBindings=p),D.info("转换完成: "+d.length+"个节点, "+l.length+"个黑板变量, "+p.length+"个属性绑定"),f},e.findRootNode=function(e){return e.find((function(e){return"根节点"===e.template.category||"root"===e.data.nodeType}))||null},e.convertNodes=function(e){var t=this;return e.map((function(e){return t.convertNode(e)}))},e.convertNode=function(e){var t=p({},e.data);return delete t.nodeType,e.template.className&&(t.className=e.template.className),{id:e.id,name:e.template.displayName||e.data.name||"Node",nodeType:e.template.type,data:t,children:e.children||[]}},e.convertBlackboard=function(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],i=o[1],s=this.inferBlackboardType(i);t.push({name:a,type:s,defaultValue:i})}return t},e.inferBlackboardType=function(e){return"number"==typeof e?exports.BlackboardValueType.Number:"string"==typeof e?exports.BlackboardValueType.String:"boolean"==typeof e?exports.BlackboardValueType.Boolean:exports.BlackboardValueType.Object},e.convertPropertyBindings=function(e,t,r){for(var n,o=[],a=new Set(r.map((function(e){return e.name}))),i=function(){var e,r=n.value,i=t.find((function(e){return e.id===r.from})),s=t.find((function(e){return e.id===r.to}));return i&&s&&r.toProperty?("blackboard-variable"===i.data.nodeType?e=i.data.variableName:r.fromProperty&&(e=r.fromProperty),e?a.has(e)?void o.push({nodeId:s.id,propertyName:r.toProperty,variableName:e}):(D.warn("属性绑定引用了不存在的黑板变量: "+e),0):(D.warn("无法确定变量名: from节点="+i.template.displayName),0)):(D.warn("跳过无效的属性连接: from="+r.from+", to="+r.to),0)},s=l(e.filter((function(e){return"property"===e.connectionType})));!(n=s()).done;)i();return o},e.fromAsset=function(e){D.info("开始转换资产格式到编辑器格式");for(var t,r=this.convertNodesFromAsset(e.nodes),n={},o=l(e.blackboard);!(t=o()).done;){var a=t.value;n[a.name]=a.defaultValue}var i=this.convertPropertyBindingsToConnections(e.propertyBindings||[]),s=this.buildNodeConnections(e.nodes);i.push.apply(i,s);var u={name:e.metadata.name};e.metadata.description&&(u.description=e.metadata.description),e.metadata.createdAt&&(u.createdAt=e.metadata.createdAt),e.metadata.modifiedAt&&(u.modifiedAt=e.metadata.modifiedAt);var c={version:e.metadata.version,metadata:u,nodes:r,connections:i,blackboard:n,canvasState:{offset:{x:0,y:0},scale:1}};return D.info("转换完成: "+r.length+"个节点, "+i.length+"个连接"),c},e.convertNodesFromAsset=function(e){var t=this;return e.map((function(e,r){var n={x:100+r%5*250,y:100+150*Math.floor(r/5)},o={displayName:e.name,category:t.inferCategory(e.nodeType),type:e.nodeType};return e.data.className&&(o.className=e.data.className),{id:e.id,template:o,data:p({},e.data),position:n,children:e.children}}))},e.inferCategory=function(e){switch(e){case i.Action:return"动作";case i.Condition:return"条件";case i.Composite:return"组合";case i.Decorator:return"装饰器";default:return"其他"}},e.convertPropertyBindingsToConnections=function(e){for(var t,r=[],n=l(e);!(t=n()).done;){var o=t.value;r.push({from:"blackboard",to:o.nodeId,toProperty:o.propertyName,connectionType:"property"})}return r},e.buildNodeConnections=function(e){for(var t,r=[],n=l(e);!(t=n()).done;)for(var o,a=t.value,i=l(a.children);!(o=i()).done;){var s=o.value;r.push({from:a.id,to:s,connectionType:"node"})}return r},e}(),F=t.createLogger("BehaviorTreeAssetSerializer"),V=function(){function e(){}return e.serialize=function(e,t){if(void 0===t&&(t={format:"json",pretty:!0}),!1!==t.validate){var r=R.validate(e);if(!r.valid){var n,o=(null===(n=r.errors)||void 0===n?void 0:n.join(", "))||"Unknown error";throw new Error("资产验证失败: "+o)}r.warnings&&r.warnings.length>0&&F.warn("资产验证警告: "+r.warnings.join(", "))}return"json"===t.format?this.serializeToJSON(e,t.pretty):this.serializeToBinary(e)},e.serializeToJSON=function(e,t){void 0===t&&(t=!0);try{var r=t?JSON.stringify(e,null,2):JSON.stringify(e);return F.info("已序列化为JSON: "+r.length+" 字符"),r}catch(e){throw new Error("JSON序列化失败: "+e)}},e.serializeToBinary=function(e){try{var r=t.BinarySerializer.encode(e);return F.info("已序列化为二进制: "+r.length+" 字节"),r}catch(e){throw new Error("二进制序列化失败: "+e)}},e.deserialize=function(e,t){var r;void 0===t&&(t={validate:!0,strict:!0});try{r="string"==typeof e?this.deserializeFromJSON(e):this.deserializeFromBinary(e)}catch(e){throw new Error("反序列化失败: "+e)}if(!1!==t.validate){var n=R.validate(r);if(!n.valid){var o,a=(null===(o=n.errors)||void 0===o?void 0:o.join(", "))||"Unknown error";if(t.strict)throw new Error("资产验证失败: "+a);F.error("资产验证失败: "+a)}n.warnings&&n.warnings.length>0&&F.warn("资产验证警告: "+n.warnings.join(", "))}return r},e.deserializeFromJSON=function(e){try{var t=JSON.parse(e);if(!t.rootNodeId&&t.nodes&&t.connections){F.info("检测到编辑器格式,正在转换为运行时资产格式...");var r=t,n=E.toAsset(r);return F.info("已从编辑器格式转换: "+n.nodes.length+" 个节点"),n}var o=t;return F.info("已从运行时资产格式反序列化: "+o.nodes.length+" 个节点"),o}catch(e){throw new Error("JSON解析失败: "+e)}},e.deserializeFromBinary=function(e){try{var r=t.BinarySerializer.decode(e);return F.info("已从二进制反序列化: "+r.nodes.length+" 个节点"),r}catch(e){throw new Error("二进制解码失败: "+e)}},e.detectFormat=function(e){return"string"==typeof e?"json":"binary"},e.getInfo=function(e){try{var r,n=this.detectFormat(e);r="json"===n?JSON.parse(e):t.BinarySerializer.decode(e);var o=e.length;return{format:n,name:r.metadata.name,version:r.version,nodeCount:r.nodes.length,blackboardVariableCount:r.blackboard.length,size:o}}catch(e){return F.error("获取资产信息失败: "+e),null}},e.convert=function(e,t,r){void 0===r&&(r=!0);var n=this.deserialize(e,{validate:!1});return this.serialize(n,{format:t,pretty:r,validate:!1})},e.compareSize=function(e,t){var r=e.length,n=t.length,o=r-n;return{jsonSize:r,binarySize:n,compressionRatio:o/r*100,savedBytes:o}},e}(),M=function(){function e(){this.variables=new Map}var t=e.prototype;return t.dispose=function(){this.variables.clear()},t.defineVariable=function(e,t,r,n){var o,a={name:e,type:t,value:r,readonly:null!==(o=null==n?void 0:n.readonly)&&void 0!==o&&o};void 0!==(null==n?void 0:n.description)&&(a.description=n.description),this.variables.set(e,a)},t.getValue=function(e){var t=this.variables.get(e);return null==t?void 0:t.value},t.setValue=function(e,t,r){void 0===r&&(r=!1);var n=this.variables.get(e);return!!n&&(!(n.readonly&&!r)&&(n.value=t,!0))},t.hasVariable=function(e){return this.variables.has(e)},t.removeVariable=function(e){return this.variables.delete(e)},t.getVariableNames=function(){return Array.from(this.variables.keys())},t.getAllVariables=function(){return Array.from(this.variables.values())},t.clear=function(){this.variables.clear()},t.setVariables=function(e){for(var t=0,r=Object.entries(e);t<r.length;t++){var n=r[t],o=n[0],a=n[1],i=this.variables.get(o);i&&!i.readonly&&(i.value=a)}},t.getVariables=function(e){for(var t,r={},n=l(e);!(t=n()).done;){var o=t.value,a=this.getValue(o);void 0!==a&&(r[o]=a)}return r},t.exportConfig=function(){return{version:"1.0",variables:Array.from(this.variables.values())}},t.importConfig=function(e){this.variables.clear();for(var t,r=l(e.variables);!(t=r()).done;){var n=t.value;this.variables.set(n.name,n)}},t.toJSON=function(){return JSON.stringify(this.exportConfig(),null,2)},e.fromJSON=function(e){return JSON.parse(e)},e}(),O=function(){function e(){this.name="@esengine/behavior-tree",this.version="1.0.0",this.worldManager=null,this.services=null}var r=e.prototype;return r.install=function(){var e=d(h().m((function e(r,n){return h().w((function(e){for(;;)switch(e.n){case 0:this.services=n,n.registerSingleton(M),n.registerSingleton(S),this.worldManager=n.resolve(t.WorldManager);case 1:return e.a(2)}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),r.uninstall=function(){var e=d(h().m((function e(){return h().w((function(e){for(;;)switch(e.n){case 0:this.services&&(this.services.unregister(M),this.services.unregister(S)),this.worldManager=null,this.services=null;case 1:return e.a(2)}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.setupScene=function(e){e.addSystem(new exports.BehaviorTreeExecutionSystem)},r.setupAllScenes=function(){if(!this.worldManager)throw new Error("Plugin not installed");for(var e,t=l(this.worldManager.getAllWorlds());!(e=t()).done;)for(var r,n=l(e.value.getAllScenes());!(r=n()).done;){var o=r.value;this.setupScene(o)}},e}();exports.BehaviorTreeAssetManager=S,exports.BehaviorTreeAssetSerializer=V,exports.BehaviorTreeAssetValidator=R,exports.BehaviorTreeBuilder=B,exports.BehaviorTreePlugin=O,exports.BehaviorTreeStarter=A,exports.BindingHelper=T,exports.EditorFormatConverter=E,exports.GlobalBlackboardService=M,exports.NodeExecutorMetadata=C,exports.NodeExecutorRegistry=b,exports.NodeMetadataRegistry=k,exports.NodeTemplates=I,exports.NodeType=i,exports.PropertyType=w,exports.ServiceRegistry=N,exports.createDefaultRuntimeState=s;
4
4
  //# sourceMappingURL=index.es5.js.map