RedBehaviacTree.cpp 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. // -------------------------------------------------------------------------------
  2. // THIS FILE IS ORIGINALLY GENERATED BY THE DESIGNER.
  3. // YOU ARE ONLY ALLOWED TO MODIFY CODE BETWEEN '///<<< BEGIN' AND '///<<< END'.
  4. // PLEASE MODIFY AND REGENERETE IT IN THE DESIGNER FOR CLASS/MEMBERS/METHODS, ETC.
  5. // -------------------------------------------------------------------------------
  6. #include "RedBehaviacTree.h"
  7. ///<<< BEGIN WRITING YOUR CODE FILE_INIT
  8. #include "ReboltRedManager.h"
  9. #include <sstream>
  10. #include <iomanip>
  11. #include "ReboltRunDelegate.hpp"
  12. #include "InterstitialAdWaiter.hpp"
  13. #include "RewardedAdWaiter.hpp"
  14. #include "LoopWaiter.hpp"
  15. #include "PlayTimelineWaiter.hpp"
  16. #include "SubTreeWaiter.hpp"
  17. #include "LoopWaiter.hpp"
  18. #include "NotifyDevelopmentWaiter.hpp"
  19. #include "NodeAnimWaiter.hpp"
  20. #include "NodeAnimAsyncWaiter.hpp"
  21. #include "PlayTimeLineAsyncWaiter.hpp"
  22. ///<<< END WRITING YOUR CODE
  23. namespace red
  24. {
  25. ///<<< BEGIN WRITING YOUR CODE NAMESPACE_INIT
  26. ///<<< END WRITING YOUR CODE
  27. RedBehaviacTree::RedBehaviacTree()
  28. {
  29. temporaryVariablesBool = false;
  30. temporaryVariablesFloat = 0.0f;
  31. temporaryVariablesInt = 0;
  32. temporaryVariablesString = "";
  33. videoIsSuccess = false;
  34. ///<<< BEGIN WRITING YOUR CODE CONSTRUCTOR
  35. _isRunning = false;
  36. _localTreeFloatMap.clear();
  37. _localTreeStringMap.clear();
  38. _treeName = "";
  39. _reboltRunDelegate = nullptr;
  40. _runningSubtreeName = "";
  41. _getTreeStateSubtreeName = "";
  42. _getTreeStateRedPath = "";
  43. _argumentsBoolMap.clear();
  44. _argumentsStringMap.clear();
  45. _funLocalBoolMap.clear();
  46. _funLocalStringMap.clear();
  47. _runingAnimTag = 0;
  48. _canUpdateBySubTree = false;
  49. _waitableStateBase = nullptr;
  50. ///<<< END WRITING YOUR CODE
  51. }
  52. RedBehaviacTree::~RedBehaviacTree()
  53. {
  54. ///<<< BEGIN WRITING YOUR CODE DESTRUCTOR
  55. CC_SAFE_RELEASE_NULL(_waitableStateBase);
  56. ///<<< END WRITING YOUR CODE
  57. }
  58. void RedBehaviacTree::addCustomDataVar(behaviac::string blockId, behaviac::string dataName, float content)
  59. {
  60. ///<<< BEGIN WRITING YOUR CODE addCustomDataVar
  61. onTreeStepStart(blockId, "addCustomDataVar");
  62. ReboltErrorInfo errorInfo;
  63. float lf = _reboltRedManager->getCustomFloat(dataName, errorInfo);
  64. processError(blockId, errorInfo);
  65. lf += content;
  66. lf = ((long long)(lf * 1000000)) / 1000000.0;
  67. _reboltRedManager->setCustomDataVar(dataName, to_string(lf));
  68. ///<<< END WRITING YOUR CODE
  69. }
  70. void RedBehaviacTree::addFunLocalBoolToMap(behaviac::string stringKey, bool content)
  71. {
  72. ///<<< BEGIN WRITING YOUR CODE addFunLocalBoolToMap
  73. _funLocalBoolMap[stringKey] = content;
  74. ///<<< END WRITING YOUR CODE
  75. }
  76. void RedBehaviacTree::addFunLocalStringToMap(behaviac::string stringKey, behaviac::string content)
  77. {
  78. ///<<< BEGIN WRITING YOUR CODE addFunLocalStringToMap
  79. _funLocalStringMap[stringKey] = content;
  80. ///<<< END WRITING YOUR CODE
  81. }
  82. void RedBehaviacTree::clearFunLocalMap()
  83. {
  84. ///<<< BEGIN WRITING YOUR CODE clearFunLocalMap
  85. _funLocalBoolMap.clear();
  86. _funLocalStringMap.clear();
  87. ///<<< END WRITING YOUR CODE
  88. }
  89. void RedBehaviacTree::customFunc(behaviac::string blockId, behaviac::string funName)
  90. {
  91. ///<<< BEGIN WRITING YOUR CODE customFunc
  92. onTreeStepStart(blockId, "customFunc");
  93. _canUpdateBySubTree = false;
  94. auto waiter = redream::SubTreeWaiter::create(_reboltRedManager, this, _funLocalBoolMap, _funLocalStringMap, funName, _reboltRedManager);
  95. setWaitableStateBase(waiter);
  96. waiter->run();
  97. ///<<< END WRITING YOUR CODE
  98. }
  99. bool RedBehaviacTree::findSubString(behaviac::string stringKey1, behaviac::string stringKey2)
  100. {
  101. ///<<< BEGIN WRITING YOUR CODE findSubString
  102. std::string string1 = getLocalTreeString(stringKey1);
  103. std::string string2 = getLocalTreeString(stringKey2);
  104. if(string1.find(string2) == std::string::npos){
  105. return false;
  106. } else {
  107. return true;
  108. }
  109. ///<<< END WRITING YOUR CODE
  110. }
  111. behaviac::string RedBehaviacTree::floatFormat(float number, int format)
  112. {
  113. ///<<< BEGIN WRITING YOUR CODE floatFormat
  114. std::string numberStr = to_string(number);
  115. std::string::size_type position = numberStr.find(".");
  116. std::string ret;
  117. int buwei = 0;
  118. if ( position != std::string::npos ){
  119. if (format == 0) {
  120. ret = numberStr.substr(0, position);
  121. } else {
  122. int decimalLenovo = (int)(numberStr.size() - (position + 1));
  123. if(decimalLenovo >= format){
  124. ret = numberStr.substr(0, position + format + 1);
  125. } else {
  126. ret = numberStr;
  127. buwei = format - decimalLenovo;
  128. }
  129. }
  130. } else {
  131. //没找到.
  132. if (format == 0) {
  133. ret = numberStr;
  134. } else {
  135. ret = numberStr + ".";
  136. buwei = format;
  137. }
  138. }
  139. if (buwei > 0){
  140. string bu(buwei,'0');
  141. ret = ret + bu;
  142. }
  143. // CCLOG("floatFormat [%f] [%d] [%s]", number, format, ret.c_str());
  144. return ret;
  145. ///<<< END WRITING YOUR CODE
  146. }
  147. behaviac::string RedBehaviacTree::floatToString(float num)
  148. {
  149. ///<<< BEGIN WRITING YOUR CODE floatToString
  150. return to_string(num);
  151. ///<<< END WRITING YOUR CODE
  152. }
  153. float RedBehaviacTree::getCoderFloat(behaviac::string key)
  154. {
  155. ///<<< BEGIN WRITING YOUR CODE getCoderFloat
  156. ReboltErrorInfo errorInfo;
  157. float ret = _reboltRedManager->getCoderFloat(key, errorInfo);
  158. processError("", errorInfo);
  159. return ret;
  160. ///<<< END WRITING YOUR CODE
  161. }
  162. behaviac::string RedBehaviacTree::getCoderString(behaviac::string key)
  163. {
  164. ///<<< BEGIN WRITING YOUR CODE getCoderString
  165. ReboltErrorInfo errorInfo;
  166. behaviac::string ret = _reboltRedManager->getCoderString(key, errorInfo);
  167. processError("", errorInfo);
  168. return ret;
  169. ///<<< END WRITING YOUR CODE
  170. }
  171. float RedBehaviacTree::getCustomFloat(behaviac::string key)
  172. {
  173. ///<<< BEGIN WRITING YOUR CODE getCustomFloat
  174. ReboltErrorInfo errorInfo;
  175. float ret = _reboltRedManager->getCustomFloat(key, errorInfo);
  176. processError("", errorInfo);
  177. return ret;
  178. ///<<< END WRITING YOUR CODE
  179. }
  180. behaviac::string RedBehaviacTree::getCustomString(behaviac::string key)
  181. {
  182. ///<<< BEGIN WRITING YOUR CODE getCustomString
  183. ReboltErrorInfo errorInfo;
  184. behaviac::string ret = _reboltRedManager->getCustomString(key, errorInfo);
  185. processError("", errorInfo);
  186. return ret;
  187. ///<<< END WRITING YOUR CODE
  188. }
  189. bool RedBehaviacTree::getFunBoolVar(behaviac::string funcVarKey)
  190. {
  191. ///<<< BEGIN WRITING YOUR CODE getFunBoolVar
  192. auto it = _argumentsBoolMap.find(funcVarKey);
  193. if(it != _argumentsBoolMap.end()){
  194. return it->second;
  195. } else {
  196. ReboltErrorInfo errorInfo;
  197. errorInfo.errorType = ReboltErrorTypeWarn;
  198. errorInfo.errorDes = StringUtils::format("Bool函数参数[%s]没有被储存", funcVarKey.c_str());
  199. processError("", errorInfo);
  200. return false;
  201. }
  202. ///<<< END WRITING YOUR CODE
  203. }
  204. behaviac::string RedBehaviacTree::getFunStringVar(behaviac::string funcVarKey)
  205. {
  206. ///<<< BEGIN WRITING YOUR CODE getFunStringVar
  207. auto it = _argumentsStringMap.find(funcVarKey);
  208. if(it != _argumentsStringMap.end()){
  209. return it->second;
  210. }else {
  211. ReboltErrorInfo errorInfo;
  212. errorInfo.errorType = ReboltErrorTypeWarn;
  213. errorInfo.errorDes = StringUtils::format("字符串函数参数[%s]没有被储存", funcVarKey.c_str());
  214. processError("", errorInfo);
  215. return "";
  216. }
  217. ///<<< END WRITING YOUR CODE
  218. }
  219. float RedBehaviacTree::getGlobalFloat(behaviac::string key)
  220. {
  221. ///<<< BEGIN WRITING YOUR CODE getGlobalFloat
  222. ReboltErrorInfo errorInfo;
  223. float ret = _reboltRedManager->getGlobalFloat(key, errorInfo);
  224. processError("", errorInfo);
  225. return ret;
  226. ///<<< END WRITING YOUR CODE
  227. }
  228. behaviac::string RedBehaviacTree::getGlobalString(behaviac::string key)
  229. {
  230. ///<<< BEGIN WRITING YOUR CODE getGlobalString
  231. ReboltErrorInfo errorInfo;
  232. behaviac::string ret = _reboltRedManager->getGlobalString(key, errorInfo);
  233. processError("", errorInfo);
  234. return ret;
  235. ///<<< END WRITING YOUR CODE
  236. }
  237. behaviac::EBTStatus RedBehaviacTree::getInterstitialAdsState(behaviac::string adName)
  238. {
  239. ///<<< BEGIN WRITING YOUR CODE getInterstitialAdsState
  240. return getWaitableState();
  241. ///<<< END WRITING YOUR CODE
  242. }
  243. float RedBehaviacTree::getLocalTreeFloat(behaviac::string key)
  244. {
  245. ///<<< BEGIN WRITING YOUR CODE getLocalTreeFloat
  246. auto it = _localTreeFloatMap.find(key);
  247. if(it != _localTreeFloatMap.end()){
  248. return it->second;
  249. } else {
  250. ReboltErrorInfo errorInfo;
  251. errorInfo.errorType = ReboltErrorTypeWarn;
  252. errorInfo.errorDes = StringUtils::format("数字临时变量[%s]没有被储存", key.c_str());
  253. processError("", errorInfo);
  254. return 0.0;
  255. }
  256. ///<<< END WRITING YOUR CODE
  257. }
  258. behaviac::string RedBehaviacTree::getLocalTreeString(behaviac::string dataKey)
  259. {
  260. ///<<< BEGIN WRITING YOUR CODE getLocalTreeString
  261. auto it = _localTreeStringMap.find(dataKey);
  262. if(it != _localTreeStringMap.end()){
  263. return it->second;
  264. } else {
  265. ReboltErrorInfo errorInfo;
  266. errorInfo.errorType = ReboltErrorTypeWarn;
  267. errorInfo.errorDes = StringUtils::format("字符串临时变量[%s]没有被储存", dataKey.c_str());
  268. processError("", errorInfo);
  269. return "";
  270. }
  271. ///<<< END WRITING YOUR CODE
  272. }
  273. behaviac::EBTStatus RedBehaviacTree::getLoopState(behaviac::string blockId)
  274. {
  275. ///<<< BEGIN WRITING YOUR CODE getLoopState
  276. return getWaitableState();
  277. ///<<< END WRITING YOUR CODE
  278. }
  279. float RedBehaviacTree::getLoopTimes()
  280. {
  281. ///<<< BEGIN WRITING YOUR CODE getLoopTimes
  282. return _reboltLoopManager->getLoopTimes();
  283. ///<<< END WRITING YOUR CODE
  284. }
  285. behaviac::EBTStatus RedBehaviacTree::getNodeAnimState(behaviac::string nodeId, behaviac::string animPath)
  286. {
  287. ///<<< BEGIN WRITING YOUR CODE getNodeAnimState
  288. return getWaitableState();
  289. ///<<< END WRITING YOUR CODE
  290. }
  291. behaviac::EBTStatus RedBehaviacTree::getNotifyDevelopmentState(behaviac::string key)
  292. {
  293. ///<<< BEGIN WRITING YOUR CODE getNotifyDevelopmentState
  294. return getWaitableState();
  295. ///<<< END WRITING YOUR CODE
  296. }
  297. behaviac::EBTStatus RedBehaviacTree::getRewardVideoAdsState(behaviac::string adName)
  298. {
  299. ///<<< BEGIN WRITING YOUR CODE getRewardVideoAdsState
  300. behaviac::EBTStatus result = (behaviac::EBTStatus)(_waitableStateBase->getRunningState().btState);
  301. if (result == behaviac::EBTStatus::BT_SUCCESS) {
  302. if ((redream::RewardedAdResult)(_waitableStateBase->getRunningState().customState) == redream::RewardedAdResult::GotReward) {
  303. videoIsSuccess = true;
  304. } else {
  305. videoIsSuccess = false;
  306. }
  307. setWaitableStateBase(nullptr);
  308. }
  309. return result;
  310. ///<<< END WRITING YOUR CODE
  311. }
  312. behaviac::EBTStatus RedBehaviacTree::getSubredTimeLineState(behaviac::string redPath, behaviac::string timeLineId)
  313. {
  314. ///<<< BEGIN WRITING YOUR CODE getSubredTimeLineState
  315. return getWaitableState();
  316. ///<<< END WRITING YOUR CODE
  317. }
  318. behaviac::EBTStatus RedBehaviacTree::getSubRedTreeState(behaviac::string redPath)
  319. {
  320. ///<<< BEGIN WRITING YOUR CODE getSubRedTreeState
  321. return getWaitableState();
  322. ///<<< END WRITING YOUR CODE
  323. }
  324. behaviac::EBTStatus RedBehaviacTree::getTimeLineState(behaviac::string timeLineId)
  325. {
  326. ///<<< BEGIN WRITING YOUR CODE getTimeLineState
  327. onTreeStepStart("", "getTimeLineState");
  328. return getWaitableState();
  329. ///<<< END WRITING YOUR CODE
  330. }
  331. behaviac::EBTStatus RedBehaviacTree::getTreeState()
  332. {
  333. ///<<< BEGIN WRITING YOUR CODE getTreeState
  334. onTreeStepStart("", "getTreeState");
  335. return getWaitableState();
  336. ///<<< END WRITING YOUR CODE
  337. }
  338. void RedBehaviacTree::globalListVarAdd(behaviac::string blockId, behaviac::string dataName, behaviac::string content)
  339. {
  340. ///<<< BEGIN WRITING YOUR CODE globalListVarAdd
  341. onTreeStepStart(blockId, "globalListVarAdd");
  342. _reboltRedManager->listVarAdd(dataName, content);
  343. ///<<< END WRITING YOUR CODE
  344. }
  345. float RedBehaviacTree::globalListVarCount(behaviac::string dataName)
  346. {
  347. ///<<< BEGIN WRITING YOUR CODE globalListVarCount
  348. return _reboltRedManager->listVarCount(dataName);
  349. ///<<< END WRITING YOUR CODE
  350. }
  351. void RedBehaviacTree::globalListVarDeleteAll(behaviac::string blockId, behaviac::string dataName)
  352. {
  353. ///<<< BEGIN WRITING YOUR CODE globalListVarDeleteAll
  354. onTreeStepStart(blockId, "globalListVarDeleteAll");
  355. _reboltRedManager->listVarDeleteAll(dataName);
  356. ///<<< END WRITING YOUR CODE
  357. }
  358. void RedBehaviacTree::globalListVarDeleteOne(behaviac::string blockId, behaviac::string dataName, int index)
  359. {
  360. ///<<< BEGIN WRITING YOUR CODE globalListVarDeleteOne
  361. onTreeStepStart(blockId, "globalListVarDeleteOne");
  362. ReboltErrorInfo errorInfo;
  363. _reboltRedManager->listVarDeleteOne(dataName, index, errorInfo);
  364. processError(blockId, errorInfo);
  365. ///<<< END WRITING YOUR CODE
  366. }
  367. float RedBehaviacTree::globalListVarFindValueID(behaviac::string dataName, behaviac::string content)
  368. {
  369. ///<<< BEGIN WRITING YOUR CODE globalListVarFindValueID
  370. ReboltErrorInfo errorInfo;
  371. int ret = _reboltRedManager->listVarFindValueID(dataName, content, errorInfo);
  372. processError("", errorInfo);
  373. return ret;
  374. ///<<< END WRITING YOUR CODE
  375. }
  376. bool RedBehaviacTree::globalListVarHasValue(behaviac::string dataName, behaviac::string content)
  377. {
  378. ///<<< BEGIN WRITING YOUR CODE globalListVarHasValue
  379. return _reboltRedManager->listVarHasValue(dataName, content);
  380. ///<<< END WRITING YOUR CODE
  381. }
  382. behaviac::string RedBehaviacTree::globalListVarIndexValue(behaviac::string dataName, int index)
  383. {
  384. ///<<< BEGIN WRITING YOUR CODE globalListVarIndexValue
  385. ReboltErrorInfo errorInfo;
  386. std::string ret = _reboltRedManager->listVarIndexValue(dataName, index, errorInfo);
  387. processError("", errorInfo);
  388. return ret;
  389. ///<<< END WRITING YOUR CODE
  390. }
  391. void RedBehaviacTree::globalListVarInsertBefore(behaviac::string blockId, behaviac::string dataName, int index, behaviac::string content)
  392. {
  393. ///<<< BEGIN WRITING YOUR CODE globalListVarInsertBefore
  394. onTreeStepStart(blockId, "globalListVarInsertBefore");
  395. ReboltErrorInfo errorInfo;
  396. _reboltRedManager->listVarInsertBefore(dataName, index, content, errorInfo);
  397. processError(blockId, errorInfo);
  398. ///<<< END WRITING YOUR CODE
  399. }
  400. void RedBehaviacTree::globalListVarReplace(behaviac::string blockId, behaviac::string dataName, int index, behaviac::string content)
  401. {
  402. ///<<< BEGIN WRITING YOUR CODE globalListVarReplace
  403. onTreeStepStart(blockId, "globalListVarReplace");
  404. ReboltErrorInfo errorInfo;
  405. _reboltRedManager->listVarReplace(dataName, index, content, errorInfo);
  406. processError(blockId, errorInfo);
  407. ///<<< END WRITING YOUR CODE
  408. }
  409. void RedBehaviacTree::hiddenNode(behaviac::string blockId, behaviac::string nodeId)
  410. {
  411. ///<<< BEGIN WRITING YOUR CODE hiddenNode
  412. onTreeStepStart(blockId, "hiddenNode");
  413. ReboltErrorInfo errorInfo;
  414. Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  415. if(node != nullptr){
  416. node->setVisible(false);
  417. }
  418. processError(blockId, errorInfo);
  419. ///<<< END WRITING YOUR CODE
  420. }
  421. void RedBehaviacTree::hiddenRedNode(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId)
  422. {
  423. ///<<< BEGIN WRITING YOUR CODE hiddenRedNode
  424. onTreeStepStart(blockId, "hiddenRedNode");
  425. ReboltErrorInfo errorInfo;
  426. Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  427. if(node != nullptr){
  428. node->setVisible(false);
  429. }
  430. processError(blockId, errorInfo);
  431. ///<<< END WRITING YOUR CODE
  432. }
  433. void RedBehaviacTree::hiddenSelf(behaviac::string blockId)
  434. {
  435. ///<<< BEGIN WRITING YOUR CODE hiddenSelf
  436. onTreeStepStart(blockId, "hiddenSelf");
  437. _reboltRedManager->getRootNode()->setVisible(false);
  438. ///<<< END WRITING YOUR CODE
  439. }
  440. bool RedBehaviacTree::isHiddenNode(behaviac::string nodeId)
  441. {
  442. ///<<< BEGIN WRITING YOUR CODE isHiddenNode
  443. ReboltErrorInfo errorInfo;
  444. Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  445. processError("", errorInfo);
  446. if(node != nullptr){
  447. return !node->isVisible();
  448. } else {
  449. return false;
  450. }
  451. ///<<< END WRITING YOUR CODE
  452. }
  453. bool RedBehaviacTree::isHiddenRedNode(behaviac::string redPath, behaviac::string nodeId)
  454. {
  455. ///<<< BEGIN WRITING YOUR CODE isHiddenRedNode
  456. ReboltErrorInfo errorInfo;
  457. Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  458. processError("", errorInfo);
  459. if(node != nullptr){
  460. return !node->isVisible();
  461. } else {
  462. return false;
  463. }
  464. ///<<< END WRITING YOUR CODE
  465. }
  466. void RedBehaviacTree::messageSend(behaviac::string blockId, behaviac::string messageName, behaviac::string messageValue)
  467. {
  468. ///<<< BEGIN WRITING YOUR CODE messageSend
  469. onTreeStepStart(blockId, "messageSend");
  470. string messValue = getLocalTreeString(messageValue);
  471. _reboltRedManager->messageSend(messageName, messValue);
  472. ///<<< END WRITING YOUR CODE
  473. }
  474. float RedBehaviacTree::nodeGetGlobalPosX(behaviac::string nodeId)
  475. {
  476. ///<<< BEGIN WRITING YOUR CODE nodeGetGlobalPosX
  477. ReboltErrorInfo errorInfo;
  478. float posX = _reboltRedManager->getNodeGlobalPostionX(nodeId, errorInfo);
  479. processError("", errorInfo);
  480. return posX;
  481. ///<<< END WRITING YOUR CODE
  482. }
  483. float RedBehaviacTree::nodeGetGlobalPosY(behaviac::string nodeId)
  484. {
  485. ///<<< BEGIN WRITING YOUR CODE nodeGetGlobalPosY
  486. ReboltErrorInfo errorInfo;
  487. float posY = _reboltRedManager->getNodeGlobalPostionY(nodeId, errorInfo);
  488. processError("", errorInfo);
  489. return posY;
  490. ///<<< END WRITING YOUR CODE
  491. }
  492. float RedBehaviacTree::nodeGetPosX(behaviac::string nodeId)
  493. {
  494. ///<<< BEGIN WRITING YOUR CODE nodeGetPosX
  495. ReboltErrorInfo errorInfo;
  496. cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  497. processError("", errorInfo);
  498. if(node != nullptr){
  499. return node->getPositionX();
  500. } else {
  501. return 0;
  502. }
  503. ///<<< END WRITING YOUR CODE
  504. }
  505. float RedBehaviacTree::nodeGetPosY(behaviac::string nodeId)
  506. {
  507. ///<<< BEGIN WRITING YOUR CODE nodeGetPosY
  508. ReboltErrorInfo errorInfo;
  509. cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  510. processError("", errorInfo);
  511. if(node != nullptr){
  512. return node->getPositionY();
  513. } else {
  514. return 0;
  515. }
  516. ///<<< END WRITING YOUR CODE
  517. }
  518. void RedBehaviacTree::nodeSetAnimAction(behaviac::string blockId, behaviac::string nodeId, behaviac::string animPath, behaviac::string posXKey, behaviac::string posYKey, behaviac::string posXKey2, behaviac::string posYKey2)
  519. {
  520. ///<<< BEGIN WRITING YOUR CODE nodeSetAnimAction
  521. onTreeStepStart(blockId, "nodeSetAnimAction");
  522. ReboltErrorInfo errorInfo;
  523. cocos2d::Vec2 startPos = Vec2(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey));
  524. cocos2d::Vec2 endPos = Vec2(getLocalTreeFloat(posXKey2), getLocalTreeFloat(posYKey2));
  525. _reboltRedManager->nodeSetAnimAction(nodeId, animPath, startPos, endPos, errorInfo);
  526. processError(blockId, errorInfo);
  527. ///<<< END WRITING YOUR CODE
  528. }
  529. void RedBehaviacTree::nodeSetAnimActionWithCallBack(behaviac::string blockId, behaviac::string nodeId, behaviac::string animPath, behaviac::string callbacktreeId, behaviac::string posXKey, behaviac::string posYKey, behaviac::string posXKey2, behaviac::string posYKey2)
  530. {
  531. ///<<< BEGIN WRITING YOUR CODE nodeSetAnimActionWithCallBack
  532. onTreeStepStart(blockId, "nodeSetAnimActionWithCallBack");
  533. ReboltErrorInfo errorInfo;
  534. cocos2d::Vec2 startPos = Vec2(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey));
  535. cocos2d::Vec2 endPos = Vec2(getLocalTreeFloat(posXKey2), getLocalTreeFloat(posYKey2));
  536. cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  537. redream::NodeAnimAsyncWaiter* waiter = redream::NodeAnimAsyncWaiter::create(_reboltRedManager, this, callbacktreeId, node, animPath, startPos, endPos);
  538. waiter->addToContainer(_reboltRedManager);
  539. waiter->run(errorInfo);
  540. processError(blockId, errorInfo);
  541. ///<<< END WRITING YOUR CODE
  542. }
  543. void RedBehaviacTree::nodeSetAnimWaitAction(behaviac::string blockId, behaviac::string nodeId, behaviac::string animPath, behaviac::string posXKey, behaviac::string posYKey, behaviac::string posXKey2, behaviac::string posYKey2)
  544. {
  545. ///<<< BEGIN WRITING YOUR CODE nodeSetAnimWaitAction
  546. onTreeStepStart(blockId, "nodeSetAnimWaitAction");
  547. _canUpdateBySubTree = false;
  548. ReboltErrorInfo errorInfo;
  549. cocos2d::Vec2 startPos = Vec2(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey));
  550. cocos2d::Vec2 endPos = Vec2(getLocalTreeFloat(posXKey2), getLocalTreeFloat(posYKey2));
  551. std::string key = _reboltRedManager->getAnimFileKey(nodeId, animPath);
  552. cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  553. if (node) {
  554. redream::NodeAnimWaiter* waiter = redream::NodeAnimWaiter::create(_reboltRedManager, this, node, animPath, startPos, endPos);
  555. setWaitableStateBase(waiter);
  556. waiter->run(errorInfo);
  557. }
  558. processError(blockId, errorInfo);
  559. ///<<< END WRITING YOUR CODE
  560. }
  561. void RedBehaviacTree::nodeSetPos(behaviac::string blockId, behaviac::string nodeId, behaviac::string posXKey, behaviac::string posYKey)
  562. {
  563. ///<<< BEGIN WRITING YOUR CODE nodeSetPos
  564. onTreeStepStart(blockId, "nodeSetPos");
  565. ReboltErrorInfo errorInfo;
  566. cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  567. if(node != nullptr){
  568. node->setPosition(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey));
  569. }
  570. processError(blockId, errorInfo);
  571. ///<<< END WRITING YOUR CODE
  572. }
  573. void RedBehaviacTree::notifyDevelopment(behaviac::string blockId, behaviac::string key)
  574. {
  575. ///<<< BEGIN WRITING YOUR CODE notifyDevelopment
  576. onTreeStepStart(blockId, "notifyDevelopment");
  577. _canUpdateBySubTree = false;
  578. std::string notify = getLocalTreeString(key);
  579. ReboltErrorInfo errorInfo;
  580. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, "", false, nullptr);
  581. setWaitableStateBase(waiter);
  582. waiter->run(errorInfo);
  583. processError(blockId, errorInfo);
  584. ///<<< END WRITING YOUR CODE
  585. }
  586. void RedBehaviacTree::notifyDevelopmentWait(behaviac::string blockId, behaviac::string key)
  587. {
  588. ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWait
  589. onTreeStepStart(blockId, "notifyDevelopmentWait");
  590. _canUpdateBySubTree = false;
  591. std::string notify = getLocalTreeString(key);
  592. ReboltErrorInfo errorInfo;
  593. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, "", true, nullptr);
  594. setWaitableStateBase(waiter);
  595. waiter->run(errorInfo);
  596. processError(blockId, errorInfo);
  597. ///<<< END WRITING YOUR CODE
  598. }
  599. void RedBehaviacTree::notifyDevelopmentWithParam(behaviac::string blockId, behaviac::string key, behaviac::string paramKey)
  600. {
  601. ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParam
  602. onTreeStepStart(blockId, "notifyDevelopmentWithParam");
  603. _canUpdateBySubTree = false;
  604. std::string notify = getLocalTreeString(key);
  605. std::string param = getLocalTreeString(paramKey);
  606. ReboltErrorInfo errorInfo;
  607. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, false, nullptr);
  608. setWaitableStateBase(waiter);
  609. waiter->run(errorInfo);
  610. processError(blockId, errorInfo);
  611. ///<<< END WRITING YOUR CODE
  612. }
  613. void RedBehaviacTree::notifyDevelopmentWithParamAndNode(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string nodeId)
  614. {
  615. ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndNode
  616. onTreeStepStart(blockId, "notifyDevelopmentWithParamAndNode");
  617. _canUpdateBySubTree = false;
  618. std::string notify = getLocalTreeString(key);
  619. std::string param = getLocalTreeString(paramKey);
  620. ReboltErrorInfo errorInfo;
  621. cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  622. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, false, node);
  623. setWaitableStateBase(waiter);
  624. waiter->run(errorInfo);
  625. processError(blockId, errorInfo);
  626. ///<<< END WRITING YOUR CODE
  627. }
  628. void RedBehaviacTree::notifyDevelopmentWithParamAndNodeWait(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string nodeId)
  629. {
  630. ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndNodeWait
  631. onTreeStepStart(blockId, "notifyDevelopmentWithParamAndNodeWait");
  632. _canUpdateBySubTree = false;
  633. std::string notify = getLocalTreeString(key);
  634. std::string param = getLocalTreeString(paramKey);
  635. ReboltErrorInfo errorInfo;
  636. cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  637. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, true, node);
  638. setWaitableStateBase(waiter);
  639. waiter->run(errorInfo);
  640. processError(blockId, errorInfo);
  641. ///<<< END WRITING YOUR CODE
  642. }
  643. void RedBehaviacTree::notifyDevelopmentWithParamAndSubredNode(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string redPath, behaviac::string nodeId)
  644. {
  645. ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndSubredNode
  646. onTreeStepStart(blockId, "notifyDevelopmentWithParamAndSubredNode");
  647. _canUpdateBySubTree = false;
  648. std::string notify = getLocalTreeString(key);
  649. std::string param = getLocalTreeString(paramKey);
  650. ReboltErrorInfo errorInfo;
  651. auto redManger = _reboltRedManager->getReboltRedManagerByPath(redPath, errorInfo);
  652. Node* node = nullptr;
  653. if(redManger){
  654. node = redManger->getNodeByKey(nodeId, errorInfo);
  655. }
  656. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, false, node);
  657. setWaitableStateBase(waiter);
  658. waiter->run(errorInfo);
  659. processError(blockId, errorInfo);
  660. ///<<< END WRITING YOUR CODE
  661. }
  662. void RedBehaviacTree::notifyDevelopmentWithParamAndSubredNodeWait(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string redPath, behaviac::string nodeId)
  663. {
  664. ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndSubredNodeWait
  665. onTreeStepStart(blockId, "notifyDevelopmentWithParamAndSubredNodeWait");
  666. _canUpdateBySubTree = false;
  667. std::string notify = getLocalTreeString(key);
  668. std::string param = getLocalTreeString(paramKey);
  669. ReboltErrorInfo errorInfo;
  670. auto redManger = _reboltRedManager->getReboltRedManagerByPath(redPath, errorInfo);
  671. Node* node = nullptr;
  672. if(redManger){
  673. node = redManger->getNodeByKey(nodeId, errorInfo);
  674. }
  675. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, true, node);
  676. setWaitableStateBase(waiter);
  677. waiter->run(errorInfo);
  678. processError(blockId, errorInfo);
  679. ///<<< END WRITING YOUR CODE
  680. }
  681. void RedBehaviacTree::notifyDevelopmentWithParamWait(behaviac::string blockId, behaviac::string key, behaviac::string paramKey)
  682. {
  683. ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamWait
  684. onTreeStepStart(blockId, "notifyDevelopmentWithParamWait");
  685. _canUpdateBySubTree = false;
  686. std::string notify = getLocalTreeString(key);
  687. std::string param = getLocalTreeString(paramKey);
  688. ReboltErrorInfo errorInfo;
  689. redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, true, nullptr);
  690. setWaitableStateBase(waiter);
  691. waiter->run(errorInfo);
  692. processError(blockId, errorInfo);
  693. ///<<< END WRITING YOUR CODE
  694. }
  695. float RedBehaviacTree::numberOperator(behaviac::string floatKey1, int type)
  696. {
  697. ///<<< BEGIN WRITING YOUR CODE numberOperator
  698. float f = getLocalTreeFloat(floatKey1);
  699. switch (type) {
  700. case NumOperatorType::NOT_abs:
  701. return fabs(f);
  702. case NumOperatorType::NOT_floor:
  703. return floor(f);
  704. case NumOperatorType::NOT_ceil:
  705. return ceil(f);
  706. case NumOperatorType::NOT_sqrt:
  707. return sqrt(f);
  708. case NumOperatorType::NOT_sin:
  709. return sin(f);
  710. case NumOperatorType::NOT_cos:
  711. return cos(f);
  712. case NumOperatorType::NOT_tan:
  713. return tan(f);
  714. case NumOperatorType::NOT_asin:
  715. return asin(f);
  716. case NumOperatorType::NOT_acos:
  717. return acos(f);
  718. case NumOperatorType::NOT_atan:
  719. return atan(f);
  720. case NumOperatorType::NOT_ln:
  721. return log(f);
  722. case NumOperatorType::NOT_log10:
  723. return log10(f);
  724. case NumOperatorType::NOT_exp:
  725. return exp(f);
  726. case NumOperatorType::NOT_pow10:
  727. return pow(10, f);
  728. default:
  729. ReboltErrorInfo errorInfo;
  730. errorInfo.errorType = ReboltErrorTypeWarn;
  731. errorInfo.errorDes = StringUtils::format("数学处理类型[%d],我不认识", type);
  732. processError("", errorInfo);
  733. break;
  734. }
  735. return 0.0f;
  736. ///<<< END WRITING YOUR CODE
  737. }
  738. float RedBehaviacTree::numModOperator(behaviac::string floatKey1, behaviac::string floatKey2)
  739. {
  740. ///<<< BEGIN WRITING YOUR CODE numModOperator
  741. float f2 = getLocalTreeFloat(floatKey2); //被除数
  742. if(f2 == 0){
  743. ReboltErrorInfo errorInfo;
  744. errorInfo.errorType = ReboltErrorTypeWarn;
  745. errorInfo.errorDes = StringUtils::format("被除数不能是0,亲");
  746. processError("", errorInfo);
  747. return 0.0f;
  748. }
  749. float f1 = getLocalTreeFloat(floatKey1); // 除数
  750. return fmod(f1, f2);
  751. ///<<< END WRITING YOUR CODE
  752. }
  753. behaviac::string RedBehaviacTree::numRandOperator(behaviac::string floatKey1)
  754. {
  755. ///<<< BEGIN WRITING YOUR CODE numRandOperator
  756. // 四舍五入取整
  757. float f1 = getLocalTreeFloat(floatKey1);
  758. int ret = int(f1 + 0.5);
  759. return to_string(ret);
  760. ///<<< END WRITING YOUR CODE
  761. }
  762. void RedBehaviacTree::onLoopEnd()
  763. {
  764. ///<<< BEGIN WRITING YOUR CODE onLoopEnd
  765. _reboltLoopManager->onLoopEnd();
  766. ///<<< END WRITING YOUR CODE
  767. }
  768. void RedBehaviacTree::playSubredTimeLine(behaviac::string blockId, behaviac::string redPath, behaviac::string actionName)
  769. {
  770. ///<<< BEGIN WRITING YOUR CODE playSubredTimeLine
  771. onTreeStepStart(blockId, "playSubredTimeLine");
  772. ReboltErrorInfo errorInfo;
  773. _reboltRedManager->playSubredTimeLine(redPath, actionName, errorInfo);
  774. processError(blockId, errorInfo);
  775. ///<<< END WRITING YOUR CODE
  776. }
  777. void RedBehaviacTree::playSubredTimeLineWait(behaviac::string blockId, behaviac::string redPath, behaviac::string actionName)
  778. {
  779. ///<<< BEGIN WRITING YOUR CODE playSubredTimeLineWait
  780. onTreeStepStart(blockId, "playSubredTimeLineWait");
  781. _canUpdateBySubTree = false;
  782. redream::PlayTimelineWaiter* waiter = redream::PlayTimelineWaiter::create(_reboltRedManager, this, std::stoi(actionName), _reboltRedManager->getSubREDAnimationManager(redPath));
  783. setWaitableStateBase(waiter);
  784. waiter->run();
  785. ///<<< END WRITING YOUR CODE
  786. }
  787. void RedBehaviacTree::playSubredTimeLineWithCallBack(behaviac::string blockId, behaviac::string redPath, behaviac::string actionName, behaviac::string callbacktreeId)
  788. {
  789. ///<<< BEGIN WRITING YOUR CODE playSubredTimeLineWithCallBack
  790. onTreeStepStart(blockId, "playSubredTimeLineWithCallBack");
  791. ReboltErrorInfo errorInfo;
  792. redream::PlayTimeLineAsyncWaiter* waiter = redream::PlayTimeLineAsyncWaiter::create(_reboltRedManager, this, callbacktreeId, std::stoi(actionName), _reboltRedManager->getSubREDAnimationManager(redPath));
  793. waiter->addToContainer(_reboltRedManager);
  794. waiter->run(errorInfo);
  795. processError(blockId, errorInfo);
  796. ///<<< END WRITING YOUR CODE
  797. }
  798. void RedBehaviacTree::playTimeLine(behaviac::string blockId, behaviac::string actionName)
  799. {
  800. ///<<< BEGIN WRITING YOUR CODE playTimeLine
  801. onTreeStepStart(blockId, "playTimeLine");
  802. ReboltErrorInfo errorInfo;
  803. _reboltRedManager->playTimeLine(actionName, errorInfo);
  804. processError(blockId, errorInfo);
  805. ///<<< END WRITING YOUR CODE
  806. }
  807. void RedBehaviacTree::playTimeLineWait(behaviac::string blockId, behaviac::string actionName)
  808. {
  809. ///<<< BEGIN WRITING YOUR CODE playTimeLineWait
  810. onTreeStepStart(blockId, "playTimeLineWait");
  811. _canUpdateBySubTree = false;
  812. redream::PlayTimelineWaiter* waiter = redream::PlayTimelineWaiter::create(_reboltRedManager, this, std::stoi(actionName), _reboltRedManager->getREDAnimationManager());
  813. setWaitableStateBase(waiter);
  814. waiter->run();
  815. ///<<< END WRITING YOUR CODE
  816. }
  817. void RedBehaviacTree::playTimeLineWithCallBack(behaviac::string blockId, behaviac::string actionName, behaviac::string callbacktreeId)
  818. {
  819. ///<<< BEGIN WRITING YOUR CODE playTimeLineWithCallBack
  820. onTreeStepStart(blockId, "playTimeLineWithCallBack");
  821. ReboltErrorInfo errorInfo;
  822. redream::PlayTimeLineAsyncWaiter* waiter = redream::PlayTimeLineAsyncWaiter::create(_reboltRedManager, this, callbacktreeId, std::stoi(actionName), _reboltRedManager->getREDAnimationManager());
  823. waiter->addToContainer(_reboltRedManager);
  824. waiter->run(errorInfo);
  825. processError(blockId, errorInfo);
  826. ///<<< END WRITING YOUR CODE
  827. }
  828. void RedBehaviacTree::playWiseSound(behaviac::string blockId, behaviac::string bnkPathKey, behaviac::string eventNameKey)
  829. {
  830. ///<<< BEGIN WRITING YOUR CODE playWiseSound
  831. onTreeStepStart(blockId, "playWiseSound");
  832. std::string bnkPath = getLocalTreeString(bnkPathKey);
  833. std::string eventName = getLocalTreeString(eventNameKey);
  834. ReboltErrorInfo errorInfo;
  835. _reboltRedManager->playWiseSound(bnkPath, eventName, errorInfo);
  836. processError(blockId, errorInfo);
  837. ///<<< END WRITING YOUR CODE
  838. }
  839. float RedBehaviacTree::randOperator(behaviac::string floatKey1, behaviac::string floatKey2)
  840. {
  841. ///<<< BEGIN WRITING YOUR CODE randOperator
  842. // 随机数
  843. float min = getLocalTreeFloat(floatKey1);
  844. float max = getLocalTreeFloat(floatKey2);
  845. if(min > max){
  846. float local = min;
  847. min = max;
  848. max = local;
  849. }
  850. float ret = min + ((1.0 * rand() / RAND_MAX)* (max - min));
  851. return ret;
  852. ///<<< END WRITING YOUR CODE
  853. }
  854. void RedBehaviacTree::redCustomFunc(behaviac::string blockId, behaviac::string redPath, behaviac::string funName)
  855. {
  856. ///<<< BEGIN WRITING YOUR CODE redCustomFunc
  857. onTreeStepStart(blockId, "redCustomFunc");
  858. _canUpdateBySubTree = false;
  859. ReboltErrorInfo errorInfo;
  860. auto waiter = redream::SubTreeWaiter::create(_reboltRedManager, this, _funLocalBoolMap, _funLocalStringMap, funName, _reboltRedManager->getReboltRedManagerByPath(redPath, errorInfo));
  861. processError(blockId, errorInfo);
  862. setWaitableStateBase(waiter);
  863. waiter->run();
  864. ///<<< END WRITING YOUR CODE
  865. }
  866. void RedBehaviacTree::redProgressBar(behaviac::string blockId, behaviac::string barName, float number)
  867. {
  868. ///<<< BEGIN WRITING YOUR CODE redProgressBar
  869. onTreeStepStart(blockId, "redProgressBar");
  870. ReboltErrorInfo errorInfo;
  871. _reboltRedManager->redProgressBar(barName, number, errorInfo);
  872. processError(blockId, errorInfo);
  873. ///<<< END WRITING YOUR CODE
  874. }
  875. bool RedBehaviacTree::rewardVideoIsLoad(behaviac::string adName)
  876. {
  877. ///<<< BEGIN WRITING YOUR CODE rewardVideoIsLoad
  878. return _reboltRedManager->rewardVideoIsLoad(adName);
  879. ///<<< END WRITING YOUR CODE
  880. }
  881. float RedBehaviacTree::sceneNodeGetGlobalPosX(behaviac::string redPath, behaviac::string nodeId)
  882. {
  883. ///<<< BEGIN WRITING YOUR CODE sceneNodeGetGlobalPosX
  884. ReboltErrorInfo errorInfo;
  885. float posX = _reboltRedManager->getSubredNodeGlobalPostionX(redPath, nodeId, errorInfo);
  886. processError("", errorInfo);
  887. return posX;
  888. ///<<< END WRITING YOUR CODE
  889. }
  890. float RedBehaviacTree::sceneNodeGetGlobalPosY(behaviac::string redPath, behaviac::string nodeId)
  891. {
  892. ///<<< BEGIN WRITING YOUR CODE sceneNodeGetGlobalPosY
  893. ReboltErrorInfo errorInfo;
  894. float posY = _reboltRedManager->getSubredNodeGlobalPostionY(redPath, nodeId, errorInfo);
  895. processError("", errorInfo);
  896. return posY;
  897. ///<<< END WRITING YOUR CODE
  898. }
  899. float RedBehaviacTree::sceneNodeGetPosX(behaviac::string redPath, behaviac::string nodeId)
  900. {
  901. ///<<< BEGIN WRITING YOUR CODE sceneNodeGetPosX
  902. ReboltErrorInfo errorInfo;
  903. cocos2d::Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  904. processError("", errorInfo);
  905. if(node != nullptr){
  906. return node->getPositionX();
  907. } else {
  908. return 0;
  909. }
  910. ///<<< END WRITING YOUR CODE
  911. }
  912. float RedBehaviacTree::sceneNodeGetPosY(behaviac::string redPath, behaviac::string nodeId)
  913. {
  914. ///<<< BEGIN WRITING YOUR CODE sceneNodeGetPosY
  915. ReboltErrorInfo errorInfo;
  916. cocos2d::Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  917. processError("", errorInfo);
  918. if(node != nullptr){
  919. return node->getPositionY();
  920. } else {
  921. return 0;
  922. }
  923. ///<<< END WRITING YOUR CODE
  924. }
  925. void RedBehaviacTree::sceneNodeSetPos(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string posXKey, behaviac::string posYKey)
  926. {
  927. ///<<< BEGIN WRITING YOUR CODE sceneNodeSetPos
  928. onTreeStepStart(blockId, "sceneNodeSetPos");
  929. ReboltErrorInfo errorInfo;
  930. cocos2d::Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  931. if(node != nullptr){
  932. node->setPosition(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey));
  933. }
  934. processError("", errorInfo);
  935. ///<<< END WRITING YOUR CODE
  936. }
  937. void RedBehaviacTree::sceneProgressBar(behaviac::string blockId, behaviac::string redPath, behaviac::string barName, float number)
  938. {
  939. ///<<< BEGIN WRITING YOUR CODE sceneProgressBar
  940. onTreeStepStart(blockId, "sceneProgressBar");
  941. ReboltErrorInfo errorInfo;
  942. _reboltRedManager->subredProgressBar(redPath, barName, number, errorInfo);
  943. processError(blockId, errorInfo);
  944. ///<<< END WRITING YOUR CODE
  945. }
  946. void RedBehaviacTree::setButtonEnable(behaviac::string blockId, behaviac::string nodeId, bool isEnable)
  947. {
  948. ///<<< BEGIN WRITING YOUR CODE setButtonEnable
  949. onTreeStepStart(blockId, "setButtonEnable");
  950. ReboltErrorInfo errorInfo;
  951. auto button = _reboltRedManager->getControlByKey(nodeId, errorInfo);
  952. if(button) button->setEnabled(isEnable);
  953. processError(blockId, errorInfo);
  954. ///<<< END WRITING YOUR CODE
  955. }
  956. void RedBehaviacTree::setCoderDataVar(behaviac::string blockId, behaviac::string dataName, behaviac::string content)
  957. {
  958. ///<<< BEGIN WRITING YOUR CODE setCoderDataVar
  959. onTreeStepStart(blockId, "setCoderDataVar");
  960. _reboltRedManager->setCoderDataVar(dataName, content);
  961. ///<<< END WRITING YOUR CODE
  962. }
  963. void RedBehaviacTree::setCustomDataVar(behaviac::string blockId, behaviac::string dataName, behaviac::string content)
  964. {
  965. ///<<< BEGIN WRITING YOUR CODE setCustomDataVar
  966. onTreeStepStart(blockId, "setCustomDataVar");
  967. _reboltRedManager->setCustomDataVar(dataName, content);
  968. ///<<< END WRITING YOUR CODE
  969. }
  970. void RedBehaviacTree::setGlobalDataVar(behaviac::string blockId, behaviac::string dataName, behaviac::string content)
  971. {
  972. ///<<< BEGIN WRITING YOUR CODE setGlobalDataVar
  973. onTreeStepStart(blockId, "setGlobalDataVar");
  974. _reboltRedManager->setGlobalDataVar(dataName, content);
  975. ///<<< END WRITING YOUR CODE
  976. }
  977. void RedBehaviacTree::setLabelTitle(behaviac::string blockId, behaviac::string labelName, behaviac::string content)
  978. {
  979. ///<<< BEGIN WRITING YOUR CODE setLabelTitle
  980. onTreeStepStart(blockId, "setLabelTitle");
  981. ReboltErrorInfo errorInfo;
  982. _reboltRedManager->setLabelTitle(labelName, content, errorInfo);
  983. processError(blockId, errorInfo);
  984. ///<<< END WRITING YOUR CODE
  985. }
  986. void RedBehaviacTree::setNodeRotation(behaviac::string blockId, behaviac::string nodeId, float rotation)
  987. {
  988. ///<<< BEGIN WRITING YOUR CODE setNodeRotation
  989. onTreeStepStart(blockId, "setNodeRotation");
  990. ReboltErrorInfo errorInfo;
  991. auto node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  992. if(node) node->setRotation(rotation);
  993. processError(blockId, errorInfo);
  994. ///<<< END WRITING YOUR CODE
  995. }
  996. void RedBehaviacTree::setNodeScale(behaviac::string blockId, behaviac::string nodeId, behaviac::string scaleXKey, behaviac::string scaleYKey)
  997. {
  998. ///<<< BEGIN WRITING YOUR CODE setNodeScale
  999. onTreeStepStart(blockId, "setNodeScale");
  1000. ReboltErrorInfo errorInfo;
  1001. auto node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  1002. if(node) node->setScale(getLocalTreeFloat(scaleXKey), getLocalTreeFloat(scaleYKey));
  1003. processError(blockId, errorInfo);
  1004. ///<<< END WRITING YOUR CODE
  1005. }
  1006. void RedBehaviacTree::setSceneLabelTitle(behaviac::string blockId, behaviac::string redPath, behaviac::string labelName, behaviac::string content)
  1007. {
  1008. ///<<< BEGIN WRITING YOUR CODE setSceneLabelTitle
  1009. onTreeStepStart(blockId, "setSceneLabelTitle");
  1010. ReboltErrorInfo errorInfo;
  1011. _reboltRedManager->setSubredLabelTitle(redPath, labelName, content, errorInfo);
  1012. processError(blockId, errorInfo);
  1013. ///<<< END WRITING YOUR CODE
  1014. }
  1015. void RedBehaviacTree::setSpriteImage(behaviac::string blockId, behaviac::string nodeId, behaviac::string imagePath)
  1016. {
  1017. ///<<< BEGIN WRITING YOUR CODE setSpriteImage
  1018. onTreeStepStart(blockId, "setSpriteImage");
  1019. ReboltErrorInfo errorInfo;
  1020. std::string image = getLocalTreeString(imagePath);
  1021. _reboltRedManager->setSpriteImage(nodeId, image, errorInfo);
  1022. processError(blockId, errorInfo);
  1023. ///<<< END WRITING YOUR CODE
  1024. }
  1025. void RedBehaviacTree::setSpritePlist(behaviac::string blockId, behaviac::string nodeId, behaviac::string plistPath, behaviac::string frameName)
  1026. {
  1027. ///<<< BEGIN WRITING YOUR CODE setSpritePlist
  1028. onTreeStepStart(blockId, "setSpritePlist");
  1029. ReboltErrorInfo errorInfo;
  1030. std::string plist = getLocalTreeString(plistPath);
  1031. std::string frame = getLocalTreeString(frameName);
  1032. _reboltRedManager->setSpritePlist(nodeId, plist, frame, errorInfo);
  1033. processError(blockId, errorInfo);
  1034. ///<<< END WRITING YOUR CODE
  1035. }
  1036. void RedBehaviacTree::setSubredButtonEnable(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, bool isEnable)
  1037. {
  1038. ///<<< BEGIN WRITING YOUR CODE setSubredButtonEnable
  1039. onTreeStepStart(blockId, "setSubredButtonEnable");
  1040. ReboltErrorInfo errorInfo;
  1041. auto button = _reboltRedManager->getSubredControlByKey(redPath, nodeId, errorInfo);
  1042. if(button) button->setEnabled(isEnable);
  1043. processError(blockId, errorInfo);
  1044. ///<<< END WRITING YOUR CODE
  1045. }
  1046. void RedBehaviacTree::setSubredNodeRotation(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, float rotation)
  1047. {
  1048. ///<<< BEGIN WRITING YOUR CODE setSubredNodeRotation
  1049. onTreeStepStart(blockId, "setSubredNodeRotation");
  1050. ReboltErrorInfo errorInfo;
  1051. auto node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  1052. if(node) node->setRotation(rotation);
  1053. processError(blockId, errorInfo);
  1054. ///<<< END WRITING YOUR CODE
  1055. }
  1056. void RedBehaviacTree::setSubredNodeScale(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string scaleXKey, behaviac::string scaleYKey)
  1057. {
  1058. ///<<< BEGIN WRITING YOUR CODE setSubredNodeScale
  1059. onTreeStepStart(blockId, "setSubredNodeRotation");
  1060. ReboltErrorInfo errorInfo;
  1061. auto node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  1062. if(node) node->setScale(getLocalTreeFloat(scaleXKey), getLocalTreeFloat(scaleYKey));
  1063. processError(blockId, errorInfo);
  1064. ///<<< END WRITING YOUR CODE
  1065. }
  1066. void RedBehaviacTree::setSubredSpriteImage(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string imagePath)
  1067. {
  1068. ///<<< BEGIN WRITING YOUR CODE setSubredSpriteImage
  1069. onTreeStepStart(blockId, "setSubredSpriteImage");
  1070. ReboltErrorInfo errorInfo;
  1071. std::string image = getLocalTreeString(imagePath);
  1072. _reboltRedManager->setSubredSpriteImage(redPath, nodeId, image, errorInfo);
  1073. processError(blockId, errorInfo);
  1074. ///<<< END WRITING YOUR CODE
  1075. }
  1076. void RedBehaviacTree::setSubredSpritePlist(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string plistPath, behaviac::string frameName)
  1077. {
  1078. ///<<< BEGIN WRITING YOUR CODE setSubredSpritePlist
  1079. onTreeStepStart(blockId, "setSubredSpritePlist");
  1080. ReboltErrorInfo errorInfo;
  1081. std::string plist = getLocalTreeString(plistPath);
  1082. std::string frame = getLocalTreeString(frameName);
  1083. _reboltRedManager->setSubredSpritePlist(redPath, nodeId, plist, frame, errorInfo);
  1084. processError(blockId, errorInfo);
  1085. ///<<< END WRITING YOUR CODE
  1086. }
  1087. void RedBehaviacTree::showInterstitialAds(behaviac::string blockId, behaviac::string adName)
  1088. {
  1089. ///<<< BEGIN WRITING YOUR CODE showInterstitialAds
  1090. onTreeStepStart(blockId, "showInterstitialAds");
  1091. _canUpdateBySubTree = false;
  1092. ReboltErrorInfo errorInfo;
  1093. redream::InterstitialAdWaiter* waiter = redream::InterstitialAdWaiter::create(_reboltRedManager, this, adName);
  1094. setWaitableStateBase(waiter);
  1095. waiter->run(errorInfo);
  1096. processError(blockId, errorInfo);
  1097. ///<<< END WRITING YOUR CODE
  1098. }
  1099. void RedBehaviacTree::showNode(behaviac::string blockId, behaviac::string nodeId)
  1100. {
  1101. ///<<< BEGIN WRITING YOUR CODE showNode
  1102. onTreeStepStart(blockId, "showNode");
  1103. ReboltErrorInfo errorInfo;
  1104. Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo);
  1105. if(node != nullptr){
  1106. node->setVisible(true);
  1107. }
  1108. processError(blockId, errorInfo);
  1109. ///<<< END WRITING YOUR CODE
  1110. }
  1111. void RedBehaviacTree::showRedNode(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId)
  1112. {
  1113. ///<<< BEGIN WRITING YOUR CODE showRedNode
  1114. onTreeStepStart(blockId, "showRedNode");
  1115. ReboltErrorInfo errorInfo;
  1116. Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo);
  1117. if(node != nullptr){
  1118. node->setVisible(true);
  1119. }
  1120. processError(blockId, errorInfo);
  1121. ///<<< END WRITING YOUR CODE
  1122. }
  1123. void RedBehaviacTree::showRewardVideoAds(behaviac::string blockId, behaviac::string adName)
  1124. {
  1125. ///<<< BEGIN WRITING YOUR CODE showRewardVideoAds
  1126. onTreeStepStart(blockId, "showRewardVideoAds");
  1127. _canUpdateBySubTree = false;
  1128. ReboltErrorInfo errorInfo;
  1129. redream::RewardedAdWaiter* waiter = redream::RewardedAdWaiter::create(_reboltRedManager, this, adName);
  1130. setWaitableStateBase(waiter);
  1131. waiter->run(errorInfo);
  1132. processError(blockId, errorInfo);
  1133. ///<<< END WRITING YOUR CODE
  1134. }
  1135. void RedBehaviacTree::showSelf(behaviac::string blockId)
  1136. {
  1137. ///<<< BEGIN WRITING YOUR CODE showSelf
  1138. onTreeStepStart(blockId, "showSelf");
  1139. _reboltRedManager->getRootNode()->setVisible(true);
  1140. ///<<< END WRITING YOUR CODE
  1141. }
  1142. void RedBehaviacTree::startLoop(behaviac::string blockId)
  1143. {
  1144. ///<<< BEGIN WRITING YOUR CODE startLoop
  1145. onTreeStepStart(blockId, "startLoop");
  1146. _canUpdateBySubTree = false;
  1147. redream::LoopWaiter* rlm = redream::LoopWaiter::create(_reboltRedManager, this, _funLocalBoolMap, _funLocalStringMap, blockId);
  1148. setWaitableStateBase(rlm);
  1149. rlm->run();
  1150. ///<<< END WRITING YOUR CODE
  1151. }
  1152. void RedBehaviacTree::stopSubredTimeLine(behaviac::string blockId, behaviac::string redPath)
  1153. {
  1154. ///<<< BEGIN WRITING YOUR CODE stopSubredTimeLine
  1155. onTreeStepStart(blockId, "stopSubredTimeLine");
  1156. ReboltErrorInfo errorInfo;
  1157. _reboltRedManager->stopSubredTimeLine(redPath, errorInfo);
  1158. ///<<< END WRITING YOUR CODE
  1159. }
  1160. void RedBehaviacTree::stopTimeLine(behaviac::string blockId)
  1161. {
  1162. ///<<< BEGIN WRITING YOUR CODE stopTimeLine
  1163. onTreeStepStart(blockId, "stopTimeLine");
  1164. ReboltErrorInfo errorInfo;
  1165. _reboltRedManager->stopTimeLine(errorInfo);
  1166. ///<<< END WRITING YOUR CODE
  1167. }
  1168. void RedBehaviacTree::storageTemporaryVariables(behaviac::string keyVariables, float number)
  1169. {
  1170. ///<<< BEGIN WRITING YOUR CODE storageTemporaryVariables
  1171. _localTreeFloatMap[keyVariables] = number;
  1172. ///<<< END WRITING YOUR CODE
  1173. }
  1174. void RedBehaviacTree::storageTemporaryVariablesString(behaviac::string dataKey, behaviac::string v)
  1175. {
  1176. ///<<< BEGIN WRITING YOUR CODE storageTemporaryVariablesString
  1177. _localTreeStringMap[dataKey] = v;
  1178. ///<<< END WRITING YOUR CODE
  1179. }
  1180. bool RedBehaviacTree::stringEqual(behaviac::string stringKey1, behaviac::string stringKey2)
  1181. {
  1182. ///<<< BEGIN WRITING YOUR CODE stringEqual
  1183. std::string string1 = getLocalTreeString(stringKey1);
  1184. std::string string2 = getLocalTreeString(stringKey2);
  1185. if(string1 == string2){
  1186. return true;
  1187. } else {
  1188. return false;
  1189. }
  1190. ///<<< END WRITING YOUR CODE
  1191. }
  1192. float RedBehaviacTree::stringLen(behaviac::string stringKey1)
  1193. {
  1194. ///<<< BEGIN WRITING YOUR CODE stringLen
  1195. std::string string1 = getLocalTreeString(stringKey1);
  1196. return string1.size();
  1197. ///<<< END WRITING YOUR CODE
  1198. }
  1199. behaviac::string RedBehaviacTree::stringLink(behaviac::string stringKey1, behaviac::string stringKey2)
  1200. {
  1201. ///<<< BEGIN WRITING YOUR CODE stringLink
  1202. std::string string1 = getLocalTreeString(stringKey1);
  1203. std::string string2 = getLocalTreeString(stringKey2);
  1204. return string1 + string2;
  1205. ///<<< END WRITING YOUR CODE
  1206. }
  1207. behaviac::string RedBehaviacTree::stringLinkMoreOperator(behaviac::string stringKeyA, behaviac::string stringKeyB, behaviac::string stringKeyC, behaviac::string stringKeyD, behaviac::string stringKeyE)
  1208. {
  1209. ///<<< BEGIN WRITING YOUR CODE stringLinkMoreOperator
  1210. std::string stringA = getLocalTreeString(stringKeyA);
  1211. std::string stringB = getLocalTreeString(stringKeyB);
  1212. std::string stringC = getLocalTreeString(stringKeyC);
  1213. std::string stringD = getLocalTreeString(stringKeyD);
  1214. std::string stringE = getLocalTreeString(stringKeyE);
  1215. return stringA + stringB + stringC + stringD + stringE;
  1216. ///<<< END WRITING YOUR CODE
  1217. }
  1218. float RedBehaviacTree::stringToFloat(behaviac::string str)
  1219. {
  1220. ///<<< BEGIN WRITING YOUR CODE stringToFloat
  1221. float ret;
  1222. try {
  1223. ret = std::stof(str);
  1224. } catch (std::invalid_argument) {
  1225. ret = 0;
  1226. } catch (std::out_of_range){
  1227. ret = 0;
  1228. }
  1229. return ret;
  1230. ///<<< END WRITING YOUR CODE
  1231. }
  1232. ///<<< BEGIN WRITING YOUR CODE NAMESPACE_UNINIT
  1233. void RedBehaviacTree::onTreeStepStart(std::string blockId, std::string blockName){
  1234. // CCLOG("zml RedBehaviacTree treeId :%s blockId %s, blockName: %s",_treeName.c_str(), blockId.c_str(), blockName.c_str());
  1235. if(_reboltRunDelegate != nullptr){
  1236. _reboltRunDelegate->onTreeStepStart(_treeName, blockId);
  1237. }
  1238. }
  1239. void RedBehaviacTree::processError(std::string blockId, ReboltErrorInfo& errorInfo){
  1240. if(_reboltRunDelegate != nullptr){
  1241. if(errorInfo.errorType != ReboltErrorTypeNone){
  1242. json11::Json errorJson = json11::Json::object{
  1243. { "treeName", _treeName},
  1244. { "blockId", blockId},
  1245. { "errorType", (int)errorInfo.errorType},
  1246. { "errorDes", errorInfo.errorDes}
  1247. };
  1248. std::string jsonStr = errorJson.dump();
  1249. _reboltRunDelegate->onError(jsonStr);
  1250. }
  1251. } else{
  1252. switch (errorInfo.errorType) {
  1253. case ReboltErrorTypeWarn:
  1254. CCLOG("Treename [%s] blockId [%s] error info: %s", _treeName.c_str(), blockId.c_str(), errorInfo.errorDes.c_str());
  1255. break;
  1256. case ReboltErrorTypeError:
  1257. CCLOG("Treename [%s] blockId [%s] error info: %s", _treeName.c_str(), blockId.c_str(), errorInfo.errorDes.c_str());
  1258. CCASSERT(false, "");
  1259. break;
  1260. default:
  1261. break;
  1262. }
  1263. }
  1264. }
  1265. void RedBehaviacTree::runBehaviacTree(){
  1266. if(_reboltRunDelegate != nullptr){
  1267. _reboltRunDelegate->onTreePlayStart(_treeName);
  1268. }
  1269. // CCLOG("RedBehaviacTree runBehaviacTree %s", _treeName.c_str());
  1270. _isRunning = true;
  1271. update();
  1272. }
  1273. void RedBehaviacTree::updateBySubTree(){
  1274. if(_canUpdateBySubTree){
  1275. update();
  1276. }
  1277. }
  1278. void RedBehaviacTree::update(){
  1279. if(_isRunning){
  1280. behaviac::EBTStatus status = btexec();
  1281. // CCLOG("RedBehaviacTree tree: %s status %d", _treeName.c_str(), (int)status);
  1282. if(status != behaviac::EBTStatus::BT_RUNNING){
  1283. if(_reboltRunDelegate != nullptr){
  1284. _reboltRunDelegate->onTreePlayFinished(_treeName, status);
  1285. }
  1286. _isRunning = false;
  1287. _reboltRedManager->onTreeRunEnd(status, _treeName);
  1288. for(int i = 0; i < _delegateVer.size(); i++){
  1289. RedBehaviacTreeDelegate* del = _delegateVer[i];
  1290. del->onTreeRunningEnd(this, status, _treeName);
  1291. }
  1292. }
  1293. }
  1294. }
  1295. void RedBehaviacTree::setWaitableStateBase(redream::WaitableStateBase* wsb) {
  1296. CC_SAFE_RELEASE_NULL(_waitableStateBase);
  1297. _waitableStateBase = wsb;
  1298. CC_SAFE_RETAIN(wsb);
  1299. }
  1300. behaviac::EBTStatus RedBehaviacTree::getWaitableState(){
  1301. behaviac::EBTStatus result = (behaviac::EBTStatus)(_waitableStateBase->getRunningState().btState);
  1302. _canUpdateBySubTree = true;
  1303. if (result == behaviac::EBTStatus::BT_SUCCESS) {
  1304. setWaitableStateBase(nullptr);
  1305. }
  1306. return result;
  1307. }
  1308. void RedBehaviacTree::addRedBehaviacTreeDelegate(RedBehaviacTreeDelegate* delegate){
  1309. _delegateVer.push_back(delegate);
  1310. }
  1311. void RedBehaviacTree::removeRedBehaviacTreeDelegate(RedBehaviacTreeDelegate* delegate){
  1312. auto it = std::find(_delegateVer.begin(), _delegateVer.end(), delegate);
  1313. if (it != _delegateVer.end()) {
  1314. _delegateVer.erase(it);
  1315. }
  1316. }
  1317. void RedBehaviacTree::removeAllRedBehaviacTreeDelegate(){
  1318. _delegateVer.clear();
  1319. }
  1320. ///<<< END WRITING YOUR CODE
  1321. }
  1322. ///<<< BEGIN WRITING YOUR CODE FILE_UNINIT
  1323. ///<<< END WRITING YOUR CODE