void SecondLayer::updateOnce(float x) { CCString* sData = CCString::create("HelloWorldScene's data"); sData->retain(); CCNotificationCenter::sharedNotificationCenter()->postNotification("test", sData); }
void CCBReader::readStringCacheEntry() { int b0 = this->readByte(); int b1 = this->readByte(); int numBytes = b0 << 8 | b1; const unsigned char * src = (const unsigned char *) (this->mBytes + this->mCurrentByte); CCString * string = CCString::createWithData(src, (unsigned long)numBytes); string->retain(); this->mCurrentByte += numBytes; this->mStringCache.push_back(string); }
void ParseFile::downloadFile(const char* url, const char* savePathName) { CCString* strSavePathName = CCString::create(savePathName); strSavePathName->retain(); ParseManager::instance()->request(CCHttpRequest::kHttpGet, url, 0, 0, this, (SEL_CallFuncND)&ParseFile::downloadFileFinished, 0, false, (void*)strSavePathName); }
void GamePan::initWordList() { _wordList = CCArray::create(); _wordList->retain(); //if(_pinyinStr.size()>0) // _targetStr = DBManager::sharedDBManager()->getRandomWordByLetter(_pinyinStr,_targetStr); //else _targetStr = DBManager::sharedDBManager()->getRandomWord();//GET_STRING(TEXT_JUQING_SPLASH_BEGIN2); //CCLog("Target is %s",_targetStr.c_str()); std::string wordList = _targetStr;//DBManager::sharedDBManager()->getRandomWord();//GET_STRING(TEXT_JUQING_SPLASH_BEGIN2); int maxWord = (MAX_LINE*MAX_ROW)/4+((MAX_LINE*MAX_ROW)%4 ==0 ? 0:1); for (int i =1;i<maxWord;i++) { string temp = DBManager::sharedDBManager()->getRandomWord();//GET_STRING(50+i); if(temp.compare(_targetStr) == 0) { i--; } else { wordList += temp; } } int length = MAX_LINE*MAX_ROW;//wordList->count(); int srcLength = wordList.size(); CCLog("%s",wordList.c_str()); if(_pinyinStr.empty()) { std::string pinyinStr = Utils::getPinyinStr(wordList);//GET_STRING(TEXT_JUQING_SPLASH_BEGIN2); vector<string> arrTotal= Utils::split(Utils::getPinyinLetter(pinyinStr)); vector<string>::iterator iter; vector<string> arr; for (iter = arrTotal.begin(); iter != arrTotal.end(); iter++) { if((*iter).compare("ch") == 0 || (*iter).compare("zh") == 0 || (*iter).compare("sh") == 0) { } else { arr.push_back((*iter)); } } string doublePinyin[] ={"ch","sh","zh"}; string singlePinyin[] ={"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","w","x","y","z"}; _pinyinStr = doublePinyin[(int)(CCRANDOM_0_1()*2)]; for(int i =0;i<3;i++) { _pinyinStr+= ","+arr.at((int)(CCRANDOM_0_1()*arr.size())); } CCLog("Target is %s,%s,%s",_targetStr.c_str(),_pinyinStr.c_str(),pinyinStr.c_str()); } for(int i = 0;i<srcLength;i=i+3) { CCString* c = CCString::create(wordList.substr(i,3)); c->retain(); _wordList->addObject(c); } }
void MCItemManager::loadEffectiveItems() { JsonBox::Value v; JsonBox::Object root; JsonBox::Object::iterator rootIterator; MCEffectiveItem *item; MCEffectManager *effectManager = MCEffectManager::sharedEffectManager(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCString* pstrFileContent = CCString::createWithContentsOfFile(kMCEffectiveItemFilepath); if (pstrFileContent) { v.loadFromString(pstrFileContent->getCString()); } #else v.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(kMCEffectiveItemFilepath).c_str()); #endif root = v.getObject(); for (rootIterator = root.begin(); rootIterator != root.end(); ++rootIterator) { const char *c_str_o_id = rootIterator->first.c_str(); JsonBox::Object object = rootIterator->second.getObject(); mc_object_id_t o_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; if (o_id.class_ == 'P') { item = MCEffectiveItem::create(); } else { MCTrap *trap = new MCTrap; trap->init(o_id); trap->autorelease(); item = trap; } CCString *ccstring; item->setID(o_id); ccstring = CCString::create(object["name"].getString().c_str()); item->setName(ccstring); ccstring->retain(); ccstring = CCString::create(object["description"].getString().c_str()); item->setDescription(ccstring); ccstring->retain(); ccstring = CCString::create(object["icon"].getString().c_str()); item->setIcon(ccstring); ccstring->retain(); /* effect-id */ c_str_o_id = object["effect-id"].getString().c_str(); mc_object_id_t e_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEffect *effect = effectManager->effectForObjectId(e_id); item->effect = effect; effect->retain(); item->setPrice(object["price"].getInt()); item->radius = object["radius"].getInt() * 24 / CC_CONTENT_SCALE_FACTOR(); /* 24为一个单位 */ item->hp = object["hp"].getInt(); item->pp = object["pp"].getInt(); item->positive_state = object["positive-state"].getInt(); item->lasting_time = object["lasting-time"].isDouble() ? (float) object["lasting-time"].getDouble() : (float) object["lasting-time"].getInt(); effectiveItems_->setObject(item, MCObjectIdToDickKey(o_id)); } }
void MCItemManager::loadEquipmentItems() { JsonBox::Value weapon; JsonBox::Value armor; JsonBox::Object root; JsonBox::Object::iterator rootIterator; MCOreManager *oreManager = MCOreManager::sharedOreManager(); /* 读取武器 */ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCString* pstrFileContent = CCString::createWithContentsOfFile(kMCEquipmentItemWeaponFilepath); if (pstrFileContent) { weapon.loadFromString(pstrFileContent->getCString()); } #else weapon.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(kMCEquipmentItemWeaponFilepath).c_str()); #endif root = weapon.getObject(); for (rootIterator = root.begin(); rootIterator != root.end(); ++rootIterator) { const char *c_str_o_id = rootIterator->first.c_str(); JsonBox::Object object = rootIterator->second.getObject(); mc_object_id_t o_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEquipmentItem *item = MCEquipmentItem::create(MCEquipment::MCWeapon); CCString *ccstring; item->setID(o_id); ccstring = CCString::create(object["name"].getString().c_str()); item->setName(ccstring); ccstring->retain(); ccstring = CCString::create(object["icon"].getString().c_str()); item->setIcon(ccstring); ccstring->retain(); item->setPrice(object["price"].getInt()); JsonBox::Object damage = object["damage"].getObject(); MCWeapon *equipment = dynamic_cast<MCWeapon *>(item->equipment_); /* effect-id */ c_str_o_id = object["effect-id"].getString().c_str(); mc_object_id_t e_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEffectManager *effectManager = MCEffectManager::sharedEffectManager(); MCEffect *effect = effectManager->effectForObjectId(e_id); equipment->attackEffect = effect; effect->retain(); equipment->damage = MCMakeDiceType(damage["count"].getInt(), damage["size"].getInt()); equipment->criticalHit = object["critical-hit"].getInt(); JsonBox::Object diceRange = object["critical-hit-visible"].getObject(); JsonBox::Object diceRangeDice = diceRange["dice"].getObject(); equipment->criticalHitVisible.min = diceRange["min"].getInt(); equipment->criticalHitVisible.max = diceRange["max"].getInt(); equipment->criticalHitVisible.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); diceRange = object["critical-hit-invisible"].getObject(); diceRangeDice = diceRange["dice"].getObject(); equipment->criticalHitInvisible.min = diceRange["min"].getInt(); equipment->criticalHitInvisible.max = diceRange["max"].getInt(); equipment->criticalHitInvisible.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); equipment->distance = object["distance"].getInt(); if (object["effect"].isInteger()) { equipment->effect = object["effect"].getInt(); diceRange = object["effect-check"].getObject(); diceRangeDice = diceRange["dice"].getObject(); equipment->effectCheck.min = diceRange["min"].getInt(); equipment->effectCheck.max = diceRange["max"].getInt(); equipment->effectCheck.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); } else { equipment->effect = MCNormalState; } /* consume Double */ equipment->consume = object["consume"].isDouble() ? (float) object["consume"].getDouble() : (float) object["consume"].getInt(); equipment->dexterity = object["dexterity"].getInt(); /* action-effect String */ equipment->actionEffect.assign(object["action-effect"].getString()); /* 读取默认矿石,加载背包的时候更新为正确矿石 */ item->ore_ = oreManager->defaultOre(); equipmentItems_->setObject(item, MCObjectIdToDickKey(o_id)); } /* 读取防具 */ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) pstrFileContent = CCString::createWithContentsOfFile(kMCEquipmentItemArmorFilepath); if (pstrFileContent) { armor.loadFromString(pstrFileContent->getCString()); } #else armor.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(kMCEquipmentItemArmorFilepath).c_str()); #endif root = armor.getObject(); for (rootIterator = root.begin(); rootIterator != root.end(); ++rootIterator) { const char *c_str_o_id = rootIterator->first.c_str(); JsonBox::Object object = rootIterator->second.getObject(); mc_object_id_t o_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEquipmentItem *item = MCEquipmentItem::create(MCEquipment::MCArmor); CCString *ccstring; item->setID(o_id); ccstring = CCString::create(object["name"].getString().c_str()); item->setName(ccstring); ccstring->retain(); ccstring = CCString::create(object["description"].getString().c_str()); item->setDescription(ccstring); ccstring->retain(); ccstring = CCString::create(object["icon"].getString().c_str()); item->setIcon(ccstring); ccstring->retain(); item->setPrice(object["price"].getInt()); MCArmor *equipment = dynamic_cast<MCArmor *>(item->equipment_); equipment->defense = object["defense"].getInt(); equipment->dexterity = object["dexterity"].getInt(); equipment->armorCheckPenalty = object["armor-check-penalty"].getInt(); /* 读取默认矿石,加载背包的时候更新为正确矿石 */ item->ore_ = oreManager->defaultOre(); equipmentItems_->setObject(item, MCObjectIdToDickKey(o_id)); } }
void MCMercenaryManager::loadMercenaries() { JsonBox::Value v; JsonBox::Object mercenaries; JsonBox::Object::iterator mercenariesIterator; MCDiceMaker *diceMaker = MCDiceMaker::sharedDiceMaker(); CCString *ccstring; MCEffectManager *effectManager = MCEffectManager::sharedEffectManager(); MCSkillManager *skillManager = MCSkillManager::sharedSkillManager(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCString* pstrFileContent = CCString::createWithContentsOfFile(kMCMercenariesFilepath); if (pstrFileContent) { v.loadFromString(pstrFileContent->getCString()); } #else v.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(kMCMercenariesFilepath).c_str()); #endif mercenaries = v.getObject(); for (mercenariesIterator = mercenaries.begin(); mercenariesIterator != mercenaries.end(); ++mercenariesIterator) { const char *c_str_o_id = mercenariesIterator->first.c_str(); mc_object_id_t m_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; JsonBox::Object mercenaryObject = mercenariesIterator->second.getObject(); MCMercenary *mercenary; if (m_id.sub_class_ == '9') { mercenary = new MCMercenary; } else if (m_id.sub_class_ == '8') { mercenary = new MCNervousMercenary; } else { CCAssert(false, "数据错误!"); continue; } mercenary->init(); mercenary->autorelease(); mercenary->setID(m_id); /* name String */ ccstring = CCString::create(mercenaryObject["name"].getString().c_str()); mercenary->setName(ccstring); ccstring->retain(); /* face String */ ccstring = CCString::create(mercenaryObject["face"].getString().c_str()); mercenary->setFace(ccstring); ccstring->retain(); /* build sprite sheet file path */ ccstring = CCString::createWithFormat("%s/%c-%s", kMCSpriteSheetBaseDirectory, c_str_o_id[0] | 32, c_str_o_id + 1); mercenary->setSpriteSheet(ccstring); ccstring->retain(); /* effect-id */ c_str_o_id = mercenaryObject["effect-id"].getString().c_str(); mc_object_id_t e_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEffect *effect = effectManager->effectForObjectId(e_id); mercenary->setAttackEffect(effect); effect->retain(); /* cost Integer */ mercenary->cost_ = mercenaryObject["cost"].getInt(); /* HP Integer */ mercenary->setHP(mercenaryObject["HP"].getInt()); mercenary->setMaxHP(mercenary->getHP()); /* dying Integer 胆怯佣兵独有 */ if (mercenary->mercenaryType_ == MCMercenary::MCNervousMercenary) { dynamic_cast<MCNervousMercenary *>(mercenary)->setDying(mercenaryObject["dying"].getInt()); } /* PP Integer */ mercenary->setPP(mercenaryObject["PP"].getInt()); mercenary->setMaxPP(mercenary->getPP()); /* consume Double */ mercenary->setConsume(mercenaryObject["consume"].isDouble() ? (float) mercenaryObject["consume"].getDouble() : (float) mercenaryObject["consume"].getInt()); /* exhaustion Integer */ mercenary->setExhaustion(mercenaryObject["exhaustion"].getInt()); /* tired Integer */ mercenary->setTired(mercenaryObject["tired"].getInt()); /* dexterity Integer */ mercenary->setDexterity(mercenaryObject["dexterity"].getInt()); /* AC Integer */ mercenary->setAC(mercenaryObject["AC"].getInt()); /* armor-check-penalty Integer */ mercenary->setArmorCheckPenalty(mercenaryObject["armor-check-penalty"].getInt()); /* damage Object */ /* damage.count Integer */ /* damage.size Integer */ JsonBox::Object damage = mercenaryObject["damage"].getObject(); mercenary->setDamage(diceMaker->diceWithType(MCMakeDiceType(damage["count"].getInt(), damage["size"].getInt()))); /* damage-bonus Integer */ mercenary->setDamageBonus(mercenaryObject["damage-bonus"].getInt()); /* critical-hit-visible Object */ /* critical-hit-visible.min Integer */ /* critical-hit-visible.max Integer */ /* critical-hit-visible.dice Object */ /* critical-hit-visible.dice.count Integer */ /* critical-hit-visible.dice.size Integer */ JsonBox::Object diceRange = mercenaryObject["critical-hit-visible"].getObject(); JsonBox::Object diceRangeDice = diceRange["dice"].getObject(); mercenary->criticalHitVisible_.min = diceRange["min"].getInt(); mercenary->criticalHitVisible_.max = diceRange["max"].getInt(); mercenary->criticalHitVisible_.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); /* critical-hit-invisible Object */ /* critical-hit-invisible.min Integer */ /* critical-hit-invisible.max Integer */ /* critical-hit-invisible.dice Object */ /* critical-hit-invisible.dice.count Integer */ /* critical-hit-invisible.dice.size Integer */ diceRange = mercenaryObject["critical-hit-invisible"].getObject(); diceRangeDice = diceRange["dice"].getObject(); mercenary->criticalHitInvisible_.min = diceRange["min"].getInt(); mercenary->criticalHitInvisible_.max = diceRange["max"].getInt(); mercenary->criticalHitInvisible_.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); /* critical-hit Double */ float floatValue = mercenaryObject["critical-hit"].isDouble() ? (float) mercenaryObject["critical-hit"].getDouble() : (float) mercenaryObject["critical-hit"].getInt(); mercenary->setCriticalHit(floatValue); /* distance Integer */ mercenary->setDistance(mercenaryObject["distance"].getInt()); /* skills Object */ JsonBox::Object skillsObject = mercenaryObject["skills"].getObject(); if (skillsObject["A"].isString()) { const char *c_str_s_id = skillsObject["A"].getString().c_str(); mc_object_id_t s_id = { c_str_s_id[0], c_str_s_id[1], c_str_s_id[2], c_str_s_id[3] }; mercenary->skills_->addObject(skillManager->skillForObjectId(s_id)); } if (skillsObject["B"].isString()) { const char *c_str_s_id = skillsObject["B"].getString().c_str(); mc_object_id_t s_id = { c_str_s_id[0], c_str_s_id[1], c_str_s_id[2], c_str_s_id[3] }; mercenary->skills_->addObject(skillManager->skillForObjectId(s_id)); }if (skillsObject["C"].isString()) { const char *c_str_s_id = skillsObject["C"].getString().c_str(); mc_object_id_t s_id = { c_str_s_id[0], c_str_s_id[1], c_str_s_id[2], c_str_s_id[3] }; mercenary->skills_->addObject(skillManager->skillForObjectId(s_id)); } if (skillsObject["D"].isString()) { const char *c_str_s_id = skillsObject["D"].getString().c_str(); mc_object_id_t s_id = { c_str_s_id[0], c_str_s_id[1], c_str_s_id[2], c_str_s_id[3] }; mercenary->skills_->addObject(skillManager->skillForObjectId(s_id)); } /* effect Integer */ if (mercenaryObject["effect"].isInteger()) { mercenary->setEffect(mercenaryObject["effect"].getInt()); /* effect-check Object */ /* effect-check.min Integer */ /* effect-check.max Integer */ /* effect-check.dice Object */ /* effect-check.dice.count Integer */ /* effect-check.dice.size Integer */ diceRange = mercenaryObject["effect-check"].getObject(); diceRangeDice = diceRange["dice"].getObject(); mercenary->effectCheck_.min = diceRange["min"].getInt(); mercenary->effectCheck_.max = diceRange["max"].getInt(); mercenary->effectCheck_.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); } else { mercenary->setEffect(MCNormalState); } /* description String */ ccstring = CCString::create(mercenaryObject["description"].getString().c_str()); mercenary->setDescription(ccstring); ccstring->retain(); /* action-effect String */ ccstring = CCString::create(mercenaryObject["action-effect"].getString().c_str()); mercenary->setActionEffect(ccstring); ccstring->retain(); mercenaries_->setObject(mercenary, MCObjectIdToDickKey(m_id)); } }
bool MCRoleBaseInfo::init(MCRole *aRole) { if (CCLayer::init()) { CCPoint anchorPoint = ccp(0, 1); CCPoint labelAnchorPoint = ccp(0, 0.05); CCSize labelSize; CCPoint labelPosition; CCLabelTTF *separatorLabel; float y; float contentScaleFactor = CC_CONTENT_SCALE_FACTOR(); CCSize faceBoxSize = CCSizeMake(72 / contentScaleFactor, 72 / contentScaleFactor); CCRect faceBoxSourceRect = CCRectMake(0, 0, 34, 34); CCRect faceBoxInseRect = CCRectMake(4, 4, 30, 30); faceBox_ = CCScale9Sprite::create(kMCRoleBaseInfoFaceBoxFilepath, faceBoxSourceRect, faceBoxInseRect); addChild(faceBox_); faceBox_->setContentSize(faceBoxSize); faceBox_->setAnchorPoint(anchorPoint); faceBox_->setPosition(ccp(0, 0)); face_ = CCSprite::create(aRole->getFace()->getCString()); addChild(face_); face_->setAnchorPoint(anchorPoint); face_->setScale(64 / contentScaleFactor / face_->getContentSize().height); face_->setPosition(ccp(4 / contentScaleFactor, -4 / contentScaleFactor)); faceBoxSelected_ = CCScale9Sprite::create(kMCRoleBaseInfoFaceBoxSelectedFilepath, faceBoxSourceRect, faceBoxInseRect); addChild(faceBoxSelected_); faceBoxSelected_->setContentSize(faceBoxSize); faceBoxSelected_->setAnchorPoint(anchorPoint); faceBoxSelected_->setPosition(ccp(0, 0)); faceBoxSelected_->setVisible(false); CCSprite *valueBox = CCSprite::create(kMCRoleBaseInfoValueBoxFilepath); addChild(valueBox); valueBox->setOpacity(196); valueBox->setAnchorPoint(anchorPoint); valueBox->setPosition(ccp(faceBox_->getPositionX() + faceBoxSize.width, 0)); /* PP */ CCString *ccstring = CCString::createWithFormat("%-03.0f", aRole->getPP()); ppLabel_ = CCLabelTTF::create(ccstring->getCString(), "Marker Felt", kMCFontSize); addChild(ppLabel_); labelSize = ppLabel_->getContentSize(); ppLabel_->setColor(ccc3(240, 240, 240)); ppLabel_->setAnchorPoint(labelAnchorPoint); y = labelSize.height / 2 - faceBoxSelected_->getContentSize().height; ppLabel_->setPosition(ccp(96 / contentScaleFactor, y)); ccstring->retain(); separatorLabel = CCLabelTTF::create(" / ", "Marker Felt", kMCFontSize); addChild(separatorLabel); separatorLabel->setColor(ccc3(240, 240, 240)); separatorLabel->setAnchorPoint(labelAnchorPoint); separatorLabel->setPosition(ccp(96 / contentScaleFactor + labelSize.width, y)); labelPosition = separatorLabel->getPosition(); ccstring = CCString::createWithFormat("%03.0f", aRole->getMaxPP()); maxPPLabel_ = CCLabelTTF::create(ccstring->getCString(), "Marker Felt", kMCFontSize); addChild(maxPPLabel_); maxPPLabel_->setColor(ccc3(240, 240, 240)); maxPPLabel_->setAnchorPoint(labelAnchorPoint); maxPPLabel_->setPosition(ccp(labelPosition.x + separatorLabel->getContentSize().width, y)); ccstring->retain(); /* HP */ ccstring = CCString::createWithFormat("%-03hu", aRole->getHP()); hpLabel_ = CCLabelTTF::create(ccstring->getCString(), "Marker Felt", kMCFontSize); addChild(hpLabel_); labelSize = hpLabel_->getContentSize(); hpLabel_->setColor(ccc3(51, 153, 51)); hpLabel_->setAnchorPoint(labelAnchorPoint); y += labelSize.height; hpLabel_->setPosition(ccp(96 / contentScaleFactor, y)); ccstring->retain(); separatorLabel = CCLabelTTF::create(" / ", "Marker Felt", kMCFontSize); addChild(separatorLabel); separatorLabel->setColor(ccc3(51, 153, 51)); separatorLabel->setAnchorPoint(labelAnchorPoint); separatorLabel->setPosition(ccp(96 / contentScaleFactor + labelSize.width, y)); labelPosition = separatorLabel->getPosition(); ccstring = CCString::createWithFormat("%03hu", aRole->getMaxHP()); maxHPLabel_ = CCLabelTTF::create(ccstring->getCString(), "Marker Felt", kMCFontSize); addChild(maxHPLabel_); maxHPLabel_->setColor(ccc3(51, 153, 51)); maxHPLabel_->setAnchorPoint(labelAnchorPoint); maxHPLabel_->setPosition(ccp(labelPosition.x + separatorLabel->getContentSize().width, y)); ccstring->retain(); role_ = aRole; aRole->retain(); width_ = faceBox_->getContentSize().width + valueBox->getContentSize().width; height_ = faceBox_->getContentSize().height; touched_ = false; return true; } return false; }