// ------------------------------------------------------------------------------- // THIS FILE IS ORIGINALLY GENERATED BY THE DESIGNER. // YOU ARE ONLY ALLOWED TO MODIFY CODE BETWEEN '///<<< BEGIN' AND '///<<< END'. // PLEASE MODIFY AND REGENERETE IT IN THE DESIGNER FOR CLASS/MEMBERS/METHODS, ETC. // ------------------------------------------------------------------------------- #include "RedBehaviacTree.h" ///<<< BEGIN WRITING YOUR CODE FILE_INIT #include "ReboltRedManager.h" #include #include #include "ReboltRunDelegate.hpp" #include "InterstitialAdWaiter.hpp" #include "RewardedAdWaiter.hpp" #include "LoopWaiter.hpp" #include "PlayTimelineWaiter.hpp" #include "SubTreeWaiter.hpp" #include "LoopWaiter.hpp" #include "NotifyDevelopmentWaiter.hpp" #include "NodeAnimWaiter.hpp" #include "NodeAnimAsyncWaiter.hpp" #include "PlayTimeLineAsyncWaiter.hpp" ///<<< END WRITING YOUR CODE namespace red { ///<<< BEGIN WRITING YOUR CODE NAMESPACE_INIT ///<<< END WRITING YOUR CODE RedBehaviacTree::RedBehaviacTree() { temporaryVariablesBool = false; temporaryVariablesFloat = 0.0f; temporaryVariablesInt = 0; temporaryVariablesString = ""; videoIsSuccess = false; ///<<< BEGIN WRITING YOUR CODE CONSTRUCTOR _isRunning = false; _localTreeFloatMap.clear(); _localTreeStringMap.clear(); _treeName = ""; _reboltRunDelegate = nullptr; _runningSubtreeName = ""; _getTreeStateSubtreeName = ""; _getTreeStateRedPath = ""; _argumentsBoolMap.clear(); _argumentsStringMap.clear(); _funLocalBoolMap.clear(); _funLocalStringMap.clear(); _runingAnimTag = 0; _canUpdateBySubTree = false; _waitableStateBase = nullptr; ///<<< END WRITING YOUR CODE } RedBehaviacTree::~RedBehaviacTree() { ///<<< BEGIN WRITING YOUR CODE DESTRUCTOR CC_SAFE_RELEASE_NULL(_waitableStateBase); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::addCustomDataVar(behaviac::string blockId, behaviac::string dataName, float content) { ///<<< BEGIN WRITING YOUR CODE addCustomDataVar onTreeStepStart(blockId, "addCustomDataVar"); ReboltErrorInfo errorInfo; float lf = _reboltRedManager->getCustomFloat(dataName, errorInfo); processError(blockId, errorInfo); lf += content; lf = ((long long)(lf * 1000000)) / 1000000.0; _reboltRedManager->setCustomDataVar(dataName, to_string(lf)); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::addFunLocalBoolToMap(behaviac::string stringKey, bool content) { ///<<< BEGIN WRITING YOUR CODE addFunLocalBoolToMap _funLocalBoolMap[stringKey] = content; ///<<< END WRITING YOUR CODE } void RedBehaviacTree::addFunLocalStringToMap(behaviac::string stringKey, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE addFunLocalStringToMap _funLocalStringMap[stringKey] = content; ///<<< END WRITING YOUR CODE } void RedBehaviacTree::clearFunLocalMap() { ///<<< BEGIN WRITING YOUR CODE clearFunLocalMap _funLocalBoolMap.clear(); _funLocalStringMap.clear(); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::customFunc(behaviac::string blockId, behaviac::string funName) { ///<<< BEGIN WRITING YOUR CODE customFunc onTreeStepStart(blockId, "customFunc"); _canUpdateBySubTree = false; auto waiter = redream::SubTreeWaiter::create(_reboltRedManager, this, _funLocalBoolMap, _funLocalStringMap, funName, _reboltRedManager); setWaitableStateBase(waiter); waiter->run(); ///<<< END WRITING YOUR CODE } bool RedBehaviacTree::findSubString(behaviac::string stringKey1, behaviac::string stringKey2) { ///<<< BEGIN WRITING YOUR CODE findSubString std::string string1 = getLocalTreeString(stringKey1); std::string string2 = getLocalTreeString(stringKey2); if(string1.find(string2) == std::string::npos){ return false; } else { return true; } ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::floatFormat(float number, int format) { ///<<< BEGIN WRITING YOUR CODE floatFormat std::string numberStr = to_string(number); std::string::size_type position = numberStr.find("."); std::string ret; int buwei = 0; if ( position != std::string::npos ){ if (format == 0) { ret = numberStr.substr(0, position); } else { int decimalLenovo = (int)(numberStr.size() - (position + 1)); if(decimalLenovo >= format){ ret = numberStr.substr(0, position + format + 1); } else { ret = numberStr; buwei = format - decimalLenovo; } } } else { //没找到. if (format == 0) { ret = numberStr; } else { ret = numberStr + "."; buwei = format; } } if (buwei > 0){ string bu(buwei,'0'); ret = ret + bu; } // CCLOG("floatFormat [%f] [%d] [%s]", number, format, ret.c_str()); return ret; ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::floatToString(float num) { ///<<< BEGIN WRITING YOUR CODE floatToString return to_string(num); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::getCoderFloat(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getCoderFloat ReboltErrorInfo errorInfo; float ret = _reboltRedManager->getCoderFloat(key, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::getCoderString(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getCoderString ReboltErrorInfo errorInfo; behaviac::string ret = _reboltRedManager->getCoderString(key, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } float RedBehaviacTree::getCustomFloat(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getCustomFloat ReboltErrorInfo errorInfo; float ret = _reboltRedManager->getCustomFloat(key, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::getCustomString(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getCustomString ReboltErrorInfo errorInfo; behaviac::string ret = _reboltRedManager->getCustomString(key, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } bool RedBehaviacTree::getFunBoolVar(behaviac::string funcVarKey) { ///<<< BEGIN WRITING YOUR CODE getFunBoolVar auto it = _argumentsBoolMap.find(funcVarKey); if(it != _argumentsBoolMap.end()){ return it->second; } else { ReboltErrorInfo errorInfo; errorInfo.errorType = ReboltErrorTypeWarn; errorInfo.errorDes = StringUtils::format("Bool函数参数[%s]没有被储存", funcVarKey.c_str()); processError("", errorInfo); return false; } ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::getFunStringVar(behaviac::string funcVarKey) { ///<<< BEGIN WRITING YOUR CODE getFunStringVar auto it = _argumentsStringMap.find(funcVarKey); if(it != _argumentsStringMap.end()){ return it->second; }else { ReboltErrorInfo errorInfo; errorInfo.errorType = ReboltErrorTypeWarn; errorInfo.errorDes = StringUtils::format("字符串函数参数[%s]没有被储存", funcVarKey.c_str()); processError("", errorInfo); return ""; } ///<<< END WRITING YOUR CODE } float RedBehaviacTree::getGlobalFloat(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getGlobalFloat ReboltErrorInfo errorInfo; float ret = _reboltRedManager->getGlobalFloat(key, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::getGlobalString(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getGlobalString ReboltErrorInfo errorInfo; behaviac::string ret = _reboltRedManager->getGlobalString(key, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getInterstitialAdsState(behaviac::string adName) { ///<<< BEGIN WRITING YOUR CODE getInterstitialAdsState return getWaitableState(); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::getLocalTreeFloat(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getLocalTreeFloat auto it = _localTreeFloatMap.find(key); if(it != _localTreeFloatMap.end()){ return it->second; } else { ReboltErrorInfo errorInfo; errorInfo.errorType = ReboltErrorTypeWarn; errorInfo.errorDes = StringUtils::format("数字临时变量[%s]没有被储存", key.c_str()); processError("", errorInfo); return 0.0; } ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::getLocalTreeString(behaviac::string dataKey) { ///<<< BEGIN WRITING YOUR CODE getLocalTreeString auto it = _localTreeStringMap.find(dataKey); if(it != _localTreeStringMap.end()){ return it->second; } else { ReboltErrorInfo errorInfo; errorInfo.errorType = ReboltErrorTypeWarn; errorInfo.errorDes = StringUtils::format("字符串临时变量[%s]没有被储存", dataKey.c_str()); processError("", errorInfo); return ""; } ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getLoopState(behaviac::string blockId) { ///<<< BEGIN WRITING YOUR CODE getLoopState return getWaitableState(); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::getLoopTimes() { ///<<< BEGIN WRITING YOUR CODE getLoopTimes return _reboltLoopManager->getLoopTimes(); ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getNodeAnimState(behaviac::string nodeId, behaviac::string animPath) { ///<<< BEGIN WRITING YOUR CODE getNodeAnimState return getWaitableState(); ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getNotifyDevelopmentState(behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE getNotifyDevelopmentState return getWaitableState(); ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getRewardVideoAdsState(behaviac::string adName) { ///<<< BEGIN WRITING YOUR CODE getRewardVideoAdsState behaviac::EBTStatus result = (behaviac::EBTStatus)(_waitableStateBase->getRunningState().btState); if (result == behaviac::EBTStatus::BT_SUCCESS) { if ((redream::RewardedAdResult)(_waitableStateBase->getRunningState().customState) == redream::RewardedAdResult::GotReward) { videoIsSuccess = true; } else { videoIsSuccess = false; } setWaitableStateBase(nullptr); } return result; ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getSubredTimeLineState(behaviac::string redPath, behaviac::string timeLineId) { ///<<< BEGIN WRITING YOUR CODE getSubredTimeLineState return getWaitableState(); ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getSubRedTreeState(behaviac::string redPath) { ///<<< BEGIN WRITING YOUR CODE getSubRedTreeState return getWaitableState(); ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getTimeLineState(behaviac::string timeLineId) { ///<<< BEGIN WRITING YOUR CODE getTimeLineState onTreeStepStart("", "getTimeLineState"); return getWaitableState(); ///<<< END WRITING YOUR CODE } behaviac::EBTStatus RedBehaviacTree::getTreeState() { ///<<< BEGIN WRITING YOUR CODE getTreeState onTreeStepStart("", "getTreeState"); return getWaitableState(); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::globalListVarAdd(behaviac::string blockId, behaviac::string dataName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE globalListVarAdd onTreeStepStart(blockId, "globalListVarAdd"); _reboltRedManager->listVarAdd(dataName, content); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::globalListVarCount(behaviac::string dataName) { ///<<< BEGIN WRITING YOUR CODE globalListVarCount return _reboltRedManager->listVarCount(dataName); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::globalListVarDeleteAll(behaviac::string blockId, behaviac::string dataName) { ///<<< BEGIN WRITING YOUR CODE globalListVarDeleteAll onTreeStepStart(blockId, "globalListVarDeleteAll"); _reboltRedManager->listVarDeleteAll(dataName); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::globalListVarDeleteOne(behaviac::string blockId, behaviac::string dataName, int index) { ///<<< BEGIN WRITING YOUR CODE globalListVarDeleteOne onTreeStepStart(blockId, "globalListVarDeleteOne"); ReboltErrorInfo errorInfo; _reboltRedManager->listVarDeleteOne(dataName, index, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::globalListVarFindValueID(behaviac::string dataName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE globalListVarFindValueID ReboltErrorInfo errorInfo; int ret = _reboltRedManager->listVarFindValueID(dataName, content, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } bool RedBehaviacTree::globalListVarHasValue(behaviac::string dataName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE globalListVarHasValue return _reboltRedManager->listVarHasValue(dataName, content); ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::globalListVarIndexValue(behaviac::string dataName, int index) { ///<<< BEGIN WRITING YOUR CODE globalListVarIndexValue ReboltErrorInfo errorInfo; std::string ret = _reboltRedManager->listVarIndexValue(dataName, index, errorInfo); processError("", errorInfo); return ret; ///<<< END WRITING YOUR CODE } void RedBehaviacTree::globalListVarInsertBefore(behaviac::string blockId, behaviac::string dataName, int index, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE globalListVarInsertBefore onTreeStepStart(blockId, "globalListVarInsertBefore"); ReboltErrorInfo errorInfo; _reboltRedManager->listVarInsertBefore(dataName, index, content, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::globalListVarReplace(behaviac::string blockId, behaviac::string dataName, int index, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE globalListVarReplace onTreeStepStart(blockId, "globalListVarReplace"); ReboltErrorInfo errorInfo; _reboltRedManager->listVarReplace(dataName, index, content, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::hiddenNode(behaviac::string blockId, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE hiddenNode onTreeStepStart(blockId, "hiddenNode"); ReboltErrorInfo errorInfo; Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); if(node != nullptr){ node->setVisible(false); } processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::hiddenRedNode(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE hiddenRedNode onTreeStepStart(blockId, "hiddenRedNode"); ReboltErrorInfo errorInfo; Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); if(node != nullptr){ node->setVisible(false); } processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::hiddenSelf(behaviac::string blockId) { ///<<< BEGIN WRITING YOUR CODE hiddenSelf onTreeStepStart(blockId, "hiddenSelf"); _reboltRedManager->getRootNode()->setVisible(false); ///<<< END WRITING YOUR CODE } bool RedBehaviacTree::isHiddenNode(behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE isHiddenNode ReboltErrorInfo errorInfo; Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); processError("", errorInfo); if(node != nullptr){ return !node->isVisible(); } else { return false; } ///<<< END WRITING YOUR CODE } bool RedBehaviacTree::isHiddenRedNode(behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE isHiddenRedNode ReboltErrorInfo errorInfo; Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); processError("", errorInfo); if(node != nullptr){ return !node->isVisible(); } else { return false; } ///<<< END WRITING YOUR CODE } void RedBehaviacTree::messageSend(behaviac::string blockId, behaviac::string messageName, behaviac::string messageValue) { ///<<< BEGIN WRITING YOUR CODE messageSend onTreeStepStart(blockId, "messageSend"); string messValue = getLocalTreeString(messageValue); _reboltRedManager->messageSend(messageName, messValue); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::nodeGetGlobalPosX(behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE nodeGetGlobalPosX ReboltErrorInfo errorInfo; float posX = _reboltRedManager->getNodeGlobalPostionX(nodeId, errorInfo); processError("", errorInfo); return posX; ///<<< END WRITING YOUR CODE } float RedBehaviacTree::nodeGetGlobalPosY(behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE nodeGetGlobalPosY ReboltErrorInfo errorInfo; float posY = _reboltRedManager->getNodeGlobalPostionY(nodeId, errorInfo); processError("", errorInfo); return posY; ///<<< END WRITING YOUR CODE } float RedBehaviacTree::nodeGetPosX(behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE nodeGetPosX ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); processError("", errorInfo); if(node != nullptr){ return node->getPositionX(); } else { return 0; } ///<<< END WRITING YOUR CODE } float RedBehaviacTree::nodeGetPosY(behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE nodeGetPosY ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); processError("", errorInfo); if(node != nullptr){ return node->getPositionY(); } else { return 0; } ///<<< END WRITING YOUR CODE } void RedBehaviacTree::nodeSetAnimAction(behaviac::string blockId, behaviac::string nodeId, behaviac::string animPath, behaviac::string posXKey, behaviac::string posYKey, behaviac::string posXKey2, behaviac::string posYKey2) { ///<<< BEGIN WRITING YOUR CODE nodeSetAnimAction onTreeStepStart(blockId, "nodeSetAnimAction"); ReboltErrorInfo errorInfo; cocos2d::Vec2 startPos = Vec2(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey)); cocos2d::Vec2 endPos = Vec2(getLocalTreeFloat(posXKey2), getLocalTreeFloat(posYKey2)); _reboltRedManager->nodeSetAnimAction(nodeId, animPath, startPos, endPos, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } 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) { ///<<< BEGIN WRITING YOUR CODE nodeSetAnimActionWithCallBack onTreeStepStart(blockId, "nodeSetAnimActionWithCallBack"); ReboltErrorInfo errorInfo; cocos2d::Vec2 startPos = Vec2(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey)); cocos2d::Vec2 endPos = Vec2(getLocalTreeFloat(posXKey2), getLocalTreeFloat(posYKey2)); cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); redream::NodeAnimAsyncWaiter* waiter = redream::NodeAnimAsyncWaiter::create(_reboltRedManager, this, callbacktreeId, node, animPath, startPos, endPos); waiter->addToContainer(_reboltRedManager); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::nodeSetAnimWaitAction(behaviac::string blockId, behaviac::string nodeId, behaviac::string animPath, behaviac::string posXKey, behaviac::string posYKey, behaviac::string posXKey2, behaviac::string posYKey2) { ///<<< BEGIN WRITING YOUR CODE nodeSetAnimWaitAction onTreeStepStart(blockId, "nodeSetAnimWaitAction"); _canUpdateBySubTree = false; ReboltErrorInfo errorInfo; cocos2d::Vec2 startPos = Vec2(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey)); cocos2d::Vec2 endPos = Vec2(getLocalTreeFloat(posXKey2), getLocalTreeFloat(posYKey2)); std::string key = _reboltRedManager->getAnimFileKey(nodeId, animPath); cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); if (node) { redream::NodeAnimWaiter* waiter = redream::NodeAnimWaiter::create(_reboltRedManager, this, node, animPath, startPos, endPos); setWaitableStateBase(waiter); waiter->run(errorInfo); } processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::nodeSetPos(behaviac::string blockId, behaviac::string nodeId, behaviac::string posXKey, behaviac::string posYKey) { ///<<< BEGIN WRITING YOUR CODE nodeSetPos onTreeStepStart(blockId, "nodeSetPos"); ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); if(node != nullptr){ node->setPosition(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey)); } processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopment(behaviac::string blockId, behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopment onTreeStepStart(blockId, "notifyDevelopment"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); ReboltErrorInfo errorInfo; redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, "", false, nullptr); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopmentWait(behaviac::string blockId, behaviac::string key) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWait onTreeStepStart(blockId, "notifyDevelopmentWait"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); ReboltErrorInfo errorInfo; redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, "", true, nullptr); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopmentWithParam(behaviac::string blockId, behaviac::string key, behaviac::string paramKey) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParam onTreeStepStart(blockId, "notifyDevelopmentWithParam"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); std::string param = getLocalTreeString(paramKey); ReboltErrorInfo errorInfo; redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, false, nullptr); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopmentWithParamAndNode(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndNode onTreeStepStart(blockId, "notifyDevelopmentWithParamAndNode"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); std::string param = getLocalTreeString(paramKey); ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, false, node); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopmentWithParamAndNodeWait(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndNodeWait onTreeStepStart(blockId, "notifyDevelopmentWithParamAndNodeWait"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); std::string param = getLocalTreeString(paramKey); ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, true, node); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopmentWithParamAndSubredNode(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndSubredNode onTreeStepStart(blockId, "notifyDevelopmentWithParamAndSubredNode"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); std::string param = getLocalTreeString(paramKey); ReboltErrorInfo errorInfo; auto redManger = _reboltRedManager->getReboltRedManagerByPath(redPath, errorInfo); Node* node = nullptr; if(redManger){ node = redManger->getNodeByKey(nodeId, errorInfo); } redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, false, node); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopmentWithParamAndSubredNodeWait(behaviac::string blockId, behaviac::string key, behaviac::string paramKey, behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamAndSubredNodeWait onTreeStepStart(blockId, "notifyDevelopmentWithParamAndSubredNodeWait"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); std::string param = getLocalTreeString(paramKey); ReboltErrorInfo errorInfo; auto redManger = _reboltRedManager->getReboltRedManagerByPath(redPath, errorInfo); Node* node = nullptr; if(redManger){ node = redManger->getNodeByKey(nodeId, errorInfo); } redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, true, node); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::notifyDevelopmentWithParamWait(behaviac::string blockId, behaviac::string key, behaviac::string paramKey) { ///<<< BEGIN WRITING YOUR CODE notifyDevelopmentWithParamWait onTreeStepStart(blockId, "notifyDevelopmentWithParamWait"); _canUpdateBySubTree = false; std::string notify = getLocalTreeString(key); std::string param = getLocalTreeString(paramKey); ReboltErrorInfo errorInfo; redream::NotifyDevelopmentWaiter* waiter = redream::NotifyDevelopmentWaiter::create(_reboltRedManager, this, notify, param, true, nullptr); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::numberOperator(behaviac::string floatKey1, int type) { ///<<< BEGIN WRITING YOUR CODE numberOperator float f = getLocalTreeFloat(floatKey1); switch (type) { case NumOperatorType::NOT_abs: return fabs(f); case NumOperatorType::NOT_floor: return floor(f); case NumOperatorType::NOT_ceil: return ceil(f); case NumOperatorType::NOT_sqrt: return sqrt(f); case NumOperatorType::NOT_sin: return sin(f); case NumOperatorType::NOT_cos: return cos(f); case NumOperatorType::NOT_tan: return tan(f); case NumOperatorType::NOT_asin: return asin(f); case NumOperatorType::NOT_acos: return acos(f); case NumOperatorType::NOT_atan: return atan(f); case NumOperatorType::NOT_ln: return log(f); case NumOperatorType::NOT_log10: return log10(f); case NumOperatorType::NOT_exp: return exp(f); case NumOperatorType::NOT_pow10: return pow(10, f); default: ReboltErrorInfo errorInfo; errorInfo.errorType = ReboltErrorTypeWarn; errorInfo.errorDes = StringUtils::format("数学处理类型[%d],我不认识", type); processError("", errorInfo); break; } return 0.0f; ///<<< END WRITING YOUR CODE } float RedBehaviacTree::numModOperator(behaviac::string floatKey1, behaviac::string floatKey2) { ///<<< BEGIN WRITING YOUR CODE numModOperator float f2 = getLocalTreeFloat(floatKey2); //被除数 if(f2 == 0){ ReboltErrorInfo errorInfo; errorInfo.errorType = ReboltErrorTypeWarn; errorInfo.errorDes = StringUtils::format("被除数不能是0,亲"); processError("", errorInfo); return 0.0f; } float f1 = getLocalTreeFloat(floatKey1); // 除数 return fmod(f1, f2); ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::numRandOperator(behaviac::string floatKey1) { ///<<< BEGIN WRITING YOUR CODE numRandOperator // 四舍五入取整 float f1 = getLocalTreeFloat(floatKey1); int ret = int(f1 + 0.5); return to_string(ret); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::onLoopEnd() { ///<<< BEGIN WRITING YOUR CODE onLoopEnd _reboltLoopManager->onLoopEnd(); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::playSubredTimeLine(behaviac::string blockId, behaviac::string redPath, behaviac::string actionName) { ///<<< BEGIN WRITING YOUR CODE playSubredTimeLine onTreeStepStart(blockId, "playSubredTimeLine"); ReboltErrorInfo errorInfo; _reboltRedManager->playSubredTimeLine(redPath, actionName, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::playSubredTimeLineWait(behaviac::string blockId, behaviac::string redPath, behaviac::string actionName) { ///<<< BEGIN WRITING YOUR CODE playSubredTimeLineWait onTreeStepStart(blockId, "playSubredTimeLineWait"); _canUpdateBySubTree = false; redream::PlayTimelineWaiter* waiter = redream::PlayTimelineWaiter::create(_reboltRedManager, this, std::stoi(actionName), _reboltRedManager->getSubREDAnimationManager(redPath)); setWaitableStateBase(waiter); waiter->run(); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::playSubredTimeLineWithCallBack(behaviac::string blockId, behaviac::string redPath, behaviac::string actionName, behaviac::string callbacktreeId) { ///<<< BEGIN WRITING YOUR CODE playSubredTimeLineWithCallBack onTreeStepStart(blockId, "playSubredTimeLineWithCallBack"); ReboltErrorInfo errorInfo; redream::PlayTimeLineAsyncWaiter* waiter = redream::PlayTimeLineAsyncWaiter::create(_reboltRedManager, this, callbacktreeId, std::stoi(actionName), _reboltRedManager->getSubREDAnimationManager(redPath)); waiter->addToContainer(_reboltRedManager); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::playTimeLine(behaviac::string blockId, behaviac::string actionName) { ///<<< BEGIN WRITING YOUR CODE playTimeLine onTreeStepStart(blockId, "playTimeLine"); ReboltErrorInfo errorInfo; _reboltRedManager->playTimeLine(actionName, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::playTimeLineWait(behaviac::string blockId, behaviac::string actionName) { ///<<< BEGIN WRITING YOUR CODE playTimeLineWait onTreeStepStart(blockId, "playTimeLineWait"); _canUpdateBySubTree = false; redream::PlayTimelineWaiter* waiter = redream::PlayTimelineWaiter::create(_reboltRedManager, this, std::stoi(actionName), _reboltRedManager->getREDAnimationManager()); setWaitableStateBase(waiter); waiter->run(); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::playTimeLineWithCallBack(behaviac::string blockId, behaviac::string actionName, behaviac::string callbacktreeId) { ///<<< BEGIN WRITING YOUR CODE playTimeLineWithCallBack onTreeStepStart(blockId, "playTimeLineWithCallBack"); ReboltErrorInfo errorInfo; redream::PlayTimeLineAsyncWaiter* waiter = redream::PlayTimeLineAsyncWaiter::create(_reboltRedManager, this, callbacktreeId, std::stoi(actionName), _reboltRedManager->getREDAnimationManager()); waiter->addToContainer(_reboltRedManager); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::playWiseSound(behaviac::string blockId, behaviac::string bnkPathKey, behaviac::string eventNameKey) { ///<<< BEGIN WRITING YOUR CODE playWiseSound onTreeStepStart(blockId, "playWiseSound"); std::string bnkPath = getLocalTreeString(bnkPathKey); std::string eventName = getLocalTreeString(eventNameKey); ReboltErrorInfo errorInfo; _reboltRedManager->playWiseSound(bnkPath, eventName, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::randOperator(behaviac::string floatKey1, behaviac::string floatKey2) { ///<<< BEGIN WRITING YOUR CODE randOperator // 随机数 float min = getLocalTreeFloat(floatKey1); float max = getLocalTreeFloat(floatKey2); if(min > max){ float local = min; min = max; max = local; } float ret = min + ((1.0 * rand() / RAND_MAX)* (max - min)); return ret; ///<<< END WRITING YOUR CODE } void RedBehaviacTree::redCustomFunc(behaviac::string blockId, behaviac::string redPath, behaviac::string funName) { ///<<< BEGIN WRITING YOUR CODE redCustomFunc onTreeStepStart(blockId, "redCustomFunc"); _canUpdateBySubTree = false; ReboltErrorInfo errorInfo; auto waiter = redream::SubTreeWaiter::create(_reboltRedManager, this, _funLocalBoolMap, _funLocalStringMap, funName, _reboltRedManager->getReboltRedManagerByPath(redPath, errorInfo)); processError(blockId, errorInfo); setWaitableStateBase(waiter); waiter->run(); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::redProgressBar(behaviac::string blockId, behaviac::string barName, float number) { ///<<< BEGIN WRITING YOUR CODE redProgressBar onTreeStepStart(blockId, "redProgressBar"); ReboltErrorInfo errorInfo; _reboltRedManager->redProgressBar(barName, number, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } bool RedBehaviacTree::rewardVideoIsLoad(behaviac::string adName) { ///<<< BEGIN WRITING YOUR CODE rewardVideoIsLoad return _reboltRedManager->rewardVideoIsLoad(adName); ///<<< END WRITING YOUR CODE } float RedBehaviacTree::sceneNodeGetGlobalPosX(behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE sceneNodeGetGlobalPosX ReboltErrorInfo errorInfo; float posX = _reboltRedManager->getSubredNodeGlobalPostionX(redPath, nodeId, errorInfo); processError("", errorInfo); return posX; ///<<< END WRITING YOUR CODE } float RedBehaviacTree::sceneNodeGetGlobalPosY(behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE sceneNodeGetGlobalPosY ReboltErrorInfo errorInfo; float posY = _reboltRedManager->getSubredNodeGlobalPostionY(redPath, nodeId, errorInfo); processError("", errorInfo); return posY; ///<<< END WRITING YOUR CODE } float RedBehaviacTree::sceneNodeGetPosX(behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE sceneNodeGetPosX ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); processError("", errorInfo); if(node != nullptr){ return node->getPositionX(); } else { return 0; } ///<<< END WRITING YOUR CODE } float RedBehaviacTree::sceneNodeGetPosY(behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE sceneNodeGetPosY ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); processError("", errorInfo); if(node != nullptr){ return node->getPositionY(); } else { return 0; } ///<<< END WRITING YOUR CODE } void RedBehaviacTree::sceneNodeSetPos(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string posXKey, behaviac::string posYKey) { ///<<< BEGIN WRITING YOUR CODE sceneNodeSetPos onTreeStepStart(blockId, "sceneNodeSetPos"); ReboltErrorInfo errorInfo; cocos2d::Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); if(node != nullptr){ node->setPosition(getLocalTreeFloat(posXKey), getLocalTreeFloat(posYKey)); } processError("", errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::sceneProgressBar(behaviac::string blockId, behaviac::string redPath, behaviac::string barName, float number) { ///<<< BEGIN WRITING YOUR CODE sceneProgressBar onTreeStepStart(blockId, "sceneProgressBar"); ReboltErrorInfo errorInfo; _reboltRedManager->subredProgressBar(redPath, barName, number, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setButtonEnable(behaviac::string blockId, behaviac::string nodeId, bool isEnable) { ///<<< BEGIN WRITING YOUR CODE setButtonEnable onTreeStepStart(blockId, "setButtonEnable"); ReboltErrorInfo errorInfo; auto button = _reboltRedManager->getControlByKey(nodeId, errorInfo); if(button) button->setEnabled(isEnable); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setCoderDataVar(behaviac::string blockId, behaviac::string dataName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE setCoderDataVar onTreeStepStart(blockId, "setCoderDataVar"); _reboltRedManager->setCoderDataVar(dataName, content); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setCustomDataVar(behaviac::string blockId, behaviac::string dataName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE setCustomDataVar onTreeStepStart(blockId, "setCustomDataVar"); _reboltRedManager->setCustomDataVar(dataName, content); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setGlobalDataVar(behaviac::string blockId, behaviac::string dataName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE setGlobalDataVar onTreeStepStart(blockId, "setGlobalDataVar"); _reboltRedManager->setGlobalDataVar(dataName, content); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setLabelTitle(behaviac::string blockId, behaviac::string labelName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE setLabelTitle onTreeStepStart(blockId, "setLabelTitle"); ReboltErrorInfo errorInfo; _reboltRedManager->setLabelTitle(labelName, content, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setNodeRotation(behaviac::string blockId, behaviac::string nodeId, float rotation) { ///<<< BEGIN WRITING YOUR CODE setNodeRotation onTreeStepStart(blockId, "setNodeRotation"); ReboltErrorInfo errorInfo; auto node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); if(node) node->setRotation(rotation); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setNodeScale(behaviac::string blockId, behaviac::string nodeId, behaviac::string scaleXKey, behaviac::string scaleYKey) { ///<<< BEGIN WRITING YOUR CODE setNodeScale onTreeStepStart(blockId, "setNodeScale"); ReboltErrorInfo errorInfo; auto node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); if(node) node->setScale(getLocalTreeFloat(scaleXKey), getLocalTreeFloat(scaleYKey)); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSceneLabelTitle(behaviac::string blockId, behaviac::string redPath, behaviac::string labelName, behaviac::string content) { ///<<< BEGIN WRITING YOUR CODE setSceneLabelTitle onTreeStepStart(blockId, "setSceneLabelTitle"); ReboltErrorInfo errorInfo; _reboltRedManager->setSubredLabelTitle(redPath, labelName, content, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSpriteImage(behaviac::string blockId, behaviac::string nodeId, behaviac::string imagePath) { ///<<< BEGIN WRITING YOUR CODE setSpriteImage onTreeStepStart(blockId, "setSpriteImage"); ReboltErrorInfo errorInfo; std::string image = getLocalTreeString(imagePath); _reboltRedManager->setSpriteImage(nodeId, image, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSpritePlist(behaviac::string blockId, behaviac::string nodeId, behaviac::string plistPath, behaviac::string frameName) { ///<<< BEGIN WRITING YOUR CODE setSpritePlist onTreeStepStart(blockId, "setSpritePlist"); ReboltErrorInfo errorInfo; std::string plist = getLocalTreeString(plistPath); std::string frame = getLocalTreeString(frameName); _reboltRedManager->setSpritePlist(nodeId, plist, frame, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSubredButtonEnable(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, bool isEnable) { ///<<< BEGIN WRITING YOUR CODE setSubredButtonEnable onTreeStepStart(blockId, "setSubredButtonEnable"); ReboltErrorInfo errorInfo; auto button = _reboltRedManager->getSubredControlByKey(redPath, nodeId, errorInfo); if(button) button->setEnabled(isEnable); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSubredNodeRotation(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, float rotation) { ///<<< BEGIN WRITING YOUR CODE setSubredNodeRotation onTreeStepStart(blockId, "setSubredNodeRotation"); ReboltErrorInfo errorInfo; auto node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); if(node) node->setRotation(rotation); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSubredNodeScale(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string scaleXKey, behaviac::string scaleYKey) { ///<<< BEGIN WRITING YOUR CODE setSubredNodeScale onTreeStepStart(blockId, "setSubredNodeRotation"); ReboltErrorInfo errorInfo; auto node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); if(node) node->setScale(getLocalTreeFloat(scaleXKey), getLocalTreeFloat(scaleYKey)); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSubredSpriteImage(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string imagePath) { ///<<< BEGIN WRITING YOUR CODE setSubredSpriteImage onTreeStepStart(blockId, "setSubredSpriteImage"); ReboltErrorInfo errorInfo; std::string image = getLocalTreeString(imagePath); _reboltRedManager->setSubredSpriteImage(redPath, nodeId, image, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::setSubredSpritePlist(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId, behaviac::string plistPath, behaviac::string frameName) { ///<<< BEGIN WRITING YOUR CODE setSubredSpritePlist onTreeStepStart(blockId, "setSubredSpritePlist"); ReboltErrorInfo errorInfo; std::string plist = getLocalTreeString(plistPath); std::string frame = getLocalTreeString(frameName); _reboltRedManager->setSubredSpritePlist(redPath, nodeId, plist, frame, errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::showInterstitialAds(behaviac::string blockId, behaviac::string adName) { ///<<< BEGIN WRITING YOUR CODE showInterstitialAds onTreeStepStart(blockId, "showInterstitialAds"); _canUpdateBySubTree = false; ReboltErrorInfo errorInfo; redream::InterstitialAdWaiter* waiter = redream::InterstitialAdWaiter::create(_reboltRedManager, this, adName); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::showNode(behaviac::string blockId, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE showNode onTreeStepStart(blockId, "showNode"); ReboltErrorInfo errorInfo; Node* node = _reboltRedManager->getNodeByKey(nodeId, errorInfo); if(node != nullptr){ node->setVisible(true); } processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::showRedNode(behaviac::string blockId, behaviac::string redPath, behaviac::string nodeId) { ///<<< BEGIN WRITING YOUR CODE showRedNode onTreeStepStart(blockId, "showRedNode"); ReboltErrorInfo errorInfo; Node* node = _reboltRedManager->getSubredNodeByKey(redPath, nodeId, errorInfo); if(node != nullptr){ node->setVisible(true); } processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::showRewardVideoAds(behaviac::string blockId, behaviac::string adName) { ///<<< BEGIN WRITING YOUR CODE showRewardVideoAds onTreeStepStart(blockId, "showRewardVideoAds"); _canUpdateBySubTree = false; ReboltErrorInfo errorInfo; redream::RewardedAdWaiter* waiter = redream::RewardedAdWaiter::create(_reboltRedManager, this, adName); setWaitableStateBase(waiter); waiter->run(errorInfo); processError(blockId, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::showSelf(behaviac::string blockId) { ///<<< BEGIN WRITING YOUR CODE showSelf onTreeStepStart(blockId, "showSelf"); _reboltRedManager->getRootNode()->setVisible(true); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::startLoop(behaviac::string blockId) { ///<<< BEGIN WRITING YOUR CODE startLoop onTreeStepStart(blockId, "startLoop"); _canUpdateBySubTree = false; redream::LoopWaiter* rlm = redream::LoopWaiter::create(_reboltRedManager, this, _funLocalBoolMap, _funLocalStringMap, blockId); setWaitableStateBase(rlm); rlm->run(); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::stopSubredTimeLine(behaviac::string blockId, behaviac::string redPath) { ///<<< BEGIN WRITING YOUR CODE stopSubredTimeLine onTreeStepStart(blockId, "stopSubredTimeLine"); ReboltErrorInfo errorInfo; _reboltRedManager->stopSubredTimeLine(redPath, errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::stopTimeLine(behaviac::string blockId) { ///<<< BEGIN WRITING YOUR CODE stopTimeLine onTreeStepStart(blockId, "stopTimeLine"); ReboltErrorInfo errorInfo; _reboltRedManager->stopTimeLine(errorInfo); ///<<< END WRITING YOUR CODE } void RedBehaviacTree::storageTemporaryVariables(behaviac::string keyVariables, float number) { ///<<< BEGIN WRITING YOUR CODE storageTemporaryVariables _localTreeFloatMap[keyVariables] = number; ///<<< END WRITING YOUR CODE } void RedBehaviacTree::storageTemporaryVariablesString(behaviac::string dataKey, behaviac::string v) { ///<<< BEGIN WRITING YOUR CODE storageTemporaryVariablesString _localTreeStringMap[dataKey] = v; ///<<< END WRITING YOUR CODE } bool RedBehaviacTree::stringEqual(behaviac::string stringKey1, behaviac::string stringKey2) { ///<<< BEGIN WRITING YOUR CODE stringEqual std::string string1 = getLocalTreeString(stringKey1); std::string string2 = getLocalTreeString(stringKey2); if(string1 == string2){ return true; } else { return false; } ///<<< END WRITING YOUR CODE } float RedBehaviacTree::stringLen(behaviac::string stringKey1) { ///<<< BEGIN WRITING YOUR CODE stringLen std::string string1 = getLocalTreeString(stringKey1); return string1.size(); ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::stringLink(behaviac::string stringKey1, behaviac::string stringKey2) { ///<<< BEGIN WRITING YOUR CODE stringLink std::string string1 = getLocalTreeString(stringKey1); std::string string2 = getLocalTreeString(stringKey2); return string1 + string2; ///<<< END WRITING YOUR CODE } behaviac::string RedBehaviacTree::stringLinkMoreOperator(behaviac::string stringKeyA, behaviac::string stringKeyB, behaviac::string stringKeyC, behaviac::string stringKeyD, behaviac::string stringKeyE) { ///<<< BEGIN WRITING YOUR CODE stringLinkMoreOperator std::string stringA = getLocalTreeString(stringKeyA); std::string stringB = getLocalTreeString(stringKeyB); std::string stringC = getLocalTreeString(stringKeyC); std::string stringD = getLocalTreeString(stringKeyD); std::string stringE = getLocalTreeString(stringKeyE); return stringA + stringB + stringC + stringD + stringE; ///<<< END WRITING YOUR CODE } float RedBehaviacTree::stringToFloat(behaviac::string str) { ///<<< BEGIN WRITING YOUR CODE stringToFloat float ret; try { ret = std::stof(str); } catch (std::invalid_argument) { ret = 0; } catch (std::out_of_range){ ret = 0; } return ret; ///<<< END WRITING YOUR CODE } ///<<< BEGIN WRITING YOUR CODE NAMESPACE_UNINIT void RedBehaviacTree::onTreeStepStart(std::string blockId, std::string blockName){ // CCLOG("zml RedBehaviacTree treeId :%s blockId %s, blockName: %s",_treeName.c_str(), blockId.c_str(), blockName.c_str()); if(_reboltRunDelegate != nullptr){ _reboltRunDelegate->onTreeStepStart(_treeName, blockId); } } void RedBehaviacTree::processError(std::string blockId, ReboltErrorInfo& errorInfo){ if(_reboltRunDelegate != nullptr){ if(errorInfo.errorType != ReboltErrorTypeNone){ json11::Json errorJson = json11::Json::object{ { "treeName", _treeName}, { "blockId", blockId}, { "errorType", (int)errorInfo.errorType}, { "errorDes", errorInfo.errorDes} }; std::string jsonStr = errorJson.dump(); _reboltRunDelegate->onError(jsonStr); } } else{ switch (errorInfo.errorType) { case ReboltErrorTypeWarn: CCLOG("Treename [%s] blockId [%s] error info: %s", _treeName.c_str(), blockId.c_str(), errorInfo.errorDes.c_str()); break; case ReboltErrorTypeError: CCLOG("Treename [%s] blockId [%s] error info: %s", _treeName.c_str(), blockId.c_str(), errorInfo.errorDes.c_str()); CCASSERT(false, ""); break; default: break; } } } void RedBehaviacTree::runBehaviacTree(){ if(_reboltRunDelegate != nullptr){ _reboltRunDelegate->onTreePlayStart(_treeName); } // CCLOG("RedBehaviacTree runBehaviacTree %s", _treeName.c_str()); _isRunning = true; update(); } void RedBehaviacTree::updateBySubTree(){ if(_canUpdateBySubTree){ update(); } } void RedBehaviacTree::update(){ if(_isRunning){ behaviac::EBTStatus status = btexec(); // CCLOG("RedBehaviacTree tree: %s status %d", _treeName.c_str(), (int)status); if(status != behaviac::EBTStatus::BT_RUNNING){ if(_reboltRunDelegate != nullptr){ _reboltRunDelegate->onTreePlayFinished(_treeName, status); } _isRunning = false; _reboltRedManager->onTreeRunEnd(status, _treeName); for(int i = 0; i < _delegateVer.size(); i++){ RedBehaviacTreeDelegate* del = _delegateVer[i]; del->onTreeRunningEnd(this, status, _treeName); } } } } void RedBehaviacTree::setWaitableStateBase(redream::WaitableStateBase* wsb) { CC_SAFE_RELEASE_NULL(_waitableStateBase); _waitableStateBase = wsb; CC_SAFE_RETAIN(wsb); } behaviac::EBTStatus RedBehaviacTree::getWaitableState(){ behaviac::EBTStatus result = (behaviac::EBTStatus)(_waitableStateBase->getRunningState().btState); _canUpdateBySubTree = true; if (result == behaviac::EBTStatus::BT_SUCCESS) { setWaitableStateBase(nullptr); } return result; } void RedBehaviacTree::addRedBehaviacTreeDelegate(RedBehaviacTreeDelegate* delegate){ _delegateVer.push_back(delegate); } void RedBehaviacTree::removeRedBehaviacTreeDelegate(RedBehaviacTreeDelegate* delegate){ auto it = std::find(_delegateVer.begin(), _delegateVer.end(), delegate); if (it != _delegateVer.end()) { _delegateVer.erase(it); } } void RedBehaviacTree::removeAllRedBehaviacTreeDelegate(){ _delegateVer.clear(); } ///<<< END WRITING YOUR CODE } ///<<< BEGIN WRITING YOUR CODE FILE_UNINIT ///<<< END WRITING YOUR CODE