@@ -68,7 +68,7 @@ bool MiniTreasureRoom::setup() {
6868 m_bs->ignoreAnchorPointForPosition (false );
6969 m_mainLayer->addChildAtPosition (m_bs, Anchor::Center, {0 , 0 });
7070
71- #define CREATE_CHEST (tier, menu, id, pos, costSprite, rewardType ) \
71+ #define CREATE_CHEST (tier, menu, id, pos, costSprite, rewardType, costScale, addCounter ) \
7272 { \
7373 GJChestSprite* chest = GJChestSprite::create ((int ) rewardType); \
7474 chest->setScale (.6f ); \
@@ -79,13 +79,17 @@ bool MiniTreasureRoom::setup() {
7979 menu->addChildAtPosition (chestBtn, Anchor::Center, pos); \
8080 \
8181 CCSprite* chestCost = CCSprite::createWithSpriteFrameName (costSprite); \
82- chestCost->setScale (.8f ); \
82+ chestCost->setScale (costScale); \
83+ chestCost->setID (fmt::format (" {}-cost" , id)); \
8384 tier->addChildAtPosition (chestCost, Anchor::Center, {pos.x , pos.y - 54 }); \
8485 \
85- CCLabelBMFont* chestCounter = CCLabelBMFont::create (fmt::format (" {} / {}" , GameStatsManager::get ()->countUnlockedSecretChests (rewardType), GameStatsManager::get ()->countSecretChests (rewardType)).c_str (), " bigFont.fnt" ); \
86- chestCounter->setColor (ccColor3B{187 , 122 , 107 }); \
87- chestCounter->setScale (.4f ); \
88- tier->addChildAtPosition (chestCounter, Anchor::Center, {pos.x , pos.y - 89 }); \
86+ if (addCounter) { \
87+ CCLabelBMFont* chestCounter = CCLabelBMFont::create (fmt::format (" {} / {}" , GameStatsManager::get ()->countUnlockedSecretChests (rewardType), GameStatsManager::get ()->countSecretChests (rewardType)).c_str (), " bigFont.fnt" ); \
88+ chestCounter->setColor (ccColor3B (187 , 122 , 107 )); \
89+ chestCounter->setScale (.4f ); \
90+ chestCounter->setID (fmt::format (" {}-counter" , id)); \
91+ tier->addChildAtPosition (chestCounter, Anchor::Center, {pos.x , pos.y - 89 }); \
92+ } \
8993 }
9094
9195 // tier 1 page
@@ -99,12 +103,12 @@ bool MiniTreasureRoom::setup() {
99103 tierOneMenu->setID (" chest-menu" );
100104 tierOneMenu->ignoreAnchorPointForPosition (false );
101105 tierOne->addChildAtPosition (tierOneMenu, Anchor::Center, {0 , -0 });
102- CREATE_CHEST (tierOne, tierOneMenu, " one-key-chest" , CCPoint (-100 , 10 ), " chest_03_price_001.png" , GJRewardType::SmallTreasure);
103- CREATE_CHEST (tierOne, tierOneMenu, " five-key-chest" , CCPoint (0 , 10 ), " chest_04_price_001.png" , GJRewardType::LargeTreasure);
104- CREATE_CHEST (tierOne, tierOneMenu, " ten-key-chest" , CCPoint (100 , 10 ), " chest_05_price_001.png" , GJRewardType::Key10Treasure);
106+ CREATE_CHEST (tierOne, tierOneMenu, " one-key-chest" , CCPoint (-100 , 10 ), " chest_03_price_001.png" , GJRewardType::SmallTreasure, . 8f , true )
107+ CREATE_CHEST (tierOne, tierOneMenu, " five-key-chest" , CCPoint (0 , 10 ), " chest_04_price_001.png" , GJRewardType::LargeTreasure, . 8f , true )
108+ CREATE_CHEST (tierOne, tierOneMenu, " ten-key-chest" , CCPoint (100 , 10 ), " chest_05_price_001.png" , GJRewardType::Key10Treasure, . 8f , true )
105109
106110 // tier 2 page
107- tierOne ->setID (" tier-two" );
111+ tierTwo ->setID (" tier-two" );
108112
109113 CCSprite* tierTwoTitle = CCSprite::createWithSpriteFrameName (" tier2label_001.png" );
110114 tierTwoTitle->setScale (.8f );
@@ -114,10 +118,50 @@ bool MiniTreasureRoom::setup() {
114118 tierTwoMenu->setID (" chest-menu" );
115119 tierTwoMenu->ignoreAnchorPointForPosition (false );
116120 tierTwo->addChildAtPosition (tierTwoMenu, Anchor::Center, {0 , -0 });
117- CREATE_CHEST (tierTwo, tierTwoMenu, " twenty-five-key-chest" , CCPoint (-100 , 10 ), " chest_06_price_001.png" , GJRewardType::Key25Treasure);
118- CREATE_CHEST (tierTwo, tierTwoMenu, " fifty-key-chest" , CCPoint (0 , 10 ), " chest_07_price_001.png" , GJRewardType::Key50Treasure);
119- CREATE_CHEST (tierTwo, tierTwoMenu, " hundred-key-chest" , CCPoint (100 , 10 ), " chest_08_price_001.png" , GJRewardType::Key100Treasure);
121+ CREATE_CHEST (tierTwo, tierTwoMenu, " twenty-five-key-chest" , CCPoint (-100 , 10 ), " chest_06_price_001.png" , GJRewardType::Key25Treasure, . 8f , true )
122+ CREATE_CHEST (tierTwo, tierTwoMenu, " fifty-key-chest" , CCPoint (0 , 10 ), " chest_07_price_001.png" , GJRewardType::Key50Treasure, . 8f , true )
123+ CREATE_CHEST (tierTwo, tierTwoMenu, " hundred-key-chest" , CCPoint (100 , 10 ), " chest_08_price_001.png" , GJRewardType::Key100Treasure, . 8f , true )
120124
125+ // bonus page
126+ bonuses->setID (" bonuses" );
127+
128+
129+
130+ CCMenu* bonusesMenu = CCMenu::create ();
131+ bonusesMenu->setID (" chest-menu" );
132+ bonusesMenu->ignoreAnchorPointForPosition (false );
133+ bonuses->addChildAtPosition (bonusesMenu, Anchor::Center, {0 , -0 });
134+ CREATE_CHEST (bonuses, bonusesMenu, " 50-milestone-chest" , CCPoint (-100 , 10 ), " chestSpecial_01_price_001.png" , GJRewardType::Large, 1 .f , false )
135+ CREATE_CHEST (bonuses, bonusesMenu, " 100-milestone-chest" , CCPoint (0 , 10 ), " chestSpecial_02_price_001.png" , GJRewardType::Large, 1 .f , false )
136+ CREATE_CHEST (bonuses, bonusesMenu, " 200-milestone-chest" , CCPoint (100 , 10 ), " chestSpecial_03_price_001.png" , GJRewardType::Large, 1 .f , false )
137+
138+ // bonus page
139+ event->setID (" bonuses" );
140+
141+ CCMenu* eventMenu = CCMenu::create ();
142+ eventMenu->setID (" chest-menu" );
143+ eventMenu->ignoreAnchorPointForPosition (false );
144+ event->addChildAtPosition (eventMenu, Anchor::Center, {0 , -0 });
145+
146+ GJChestSprite* chest = GJChestSprite::create ((int )GJRewardType::Gold);
147+ chest->setScale (.6f );
148+ CCMenuItemSpriteExtra* chestBtn = CCMenuItemSpriteExtra::create (chest, this , menu_selector (MiniTreasureRoom::onChest));
149+ chestBtn->setContentSize (chest->getChildByType <CCSprite*>(0 )->getContentSize ());
150+ chest->setPosition (chestBtn->getContentSize () / 2 );
151+ chestBtn->setID (" event-chest" );
152+ eventMenu->addChildAtPosition (chestBtn, Anchor::Center, CCPoint (0 , 10 ));
153+
154+ CCSprite* chestCost = CCSprite::createWithSpriteFrameName (" chest_09_price_001.png" );
155+ chestCost->setScale (.96f );
156+ chestCost->setID (" event-chest-cost" );
157+ event->addChildAtPosition (chestCost, Anchor::Center, {0 , 10 - 54 });
158+
159+ CCLabelBMFont* chestCounter = CCLabelBMFont::create (fmt::format (" {} / {}" , GameStatsManager::get ()->countUnlockedSecretChests (GJRewardType::Gold), GameStatsManager::get ()->countSecretChests (GJRewardType::Gold)).c_str (), " bigFont.fnt" );
160+ chestCounter->setColor (ccColor3B (100 , 87 , 112 ));
161+ chestCounter->setScale (.5f );
162+ chestCounter->setID (" event-chest-counter" );
163+ event->addChildAtPosition (chestCounter, Anchor::Center, {0 , 10 + 72 });
164+
121165 return true ;
122166}
123167
@@ -146,8 +190,8 @@ void MiniTreasureRoom::onChest(CCObject* sender) {
146190 auto btn = dynamic_cast <CCMenuItemSpriteExtra*>(sender);
147191 if (!btn) return ;
148192
149- if (btn->getID () == " one-key -chest" ) {
150-
193+ if (btn->getID () == " event -chest" ) {
194+ onGoldChest ();
151195 }
152196}
153197
@@ -164,4 +208,57 @@ MiniTreasureRoom* MiniTreasureRoom::create() {
164208 }
165209 delete ret;
166210 return nullptr ;
211+ }
212+
213+ void MiniTreasureRoom::onGoldChest () {
214+ GameStatsManager *statsManager = GameStatsManager::get ();
215+
216+ int goldKeyCount = statsManager->getStat (" 43" );
217+ int chestId = 6001 ;
218+
219+ while (chestId < 6021 ) {
220+ if (!statsManager->isSecretChestUnlocked (chestId)) {
221+ break ;
222+ }
223+ chestId++;
224+ }
225+
226+ if (goldKeyCount < 1 ) {
227+ DialogObject *dialog = DialogObject::create (" The Key" , " You need a <cy>Gold Key</c> to unlock this <cg>chest</c>." , 2 , 1.0 , false , ccWHITE);
228+ DialogLayer *dialogLayer = DialogLayer::createDialogLayer (dialog, nullptr , 2 );
229+ dialogLayer->addToMainScene ();
230+
231+ CCDirector *director = CCDirector::sharedDirector ();
232+ CCPoint center = director->getWinSize () * 0.5 ;
233+ dialogLayer->setPosition (center);
234+ dialogLayer->animateInRandomSide ();
235+ }
236+ else if (chestId == 0x1785 ) {
237+ DialogObject *dialog = DialogObject::create (" The Key" , " All out of <cy>Gold Chests</c> right now. Come back later." , 2 , 1.0 , false , ccWHITE);
238+ DialogLayer *dialogLayer = DialogLayer::createDialogLayer (dialog, nullptr , 2 );
239+ dialogLayer->addToMainScene ();
240+
241+ CCDirector *director = CCDirector::sharedDirector ();
242+ CCPoint center = director->getWinSize () * 0.5 ;
243+ dialogLayer->setPosition (center);
244+ dialogLayer->animateInRandomSide ();
245+ } else {
246+ auto rewardItem = statsManager->getRewardItem (GJRewardType::Gold);
247+ if (rewardItem && goldKeyCount > 0 ) {
248+ statsManager->setStat (" 43" , goldKeyCount - 1 );
249+ statsManager->preProcessReward (rewardItem);
250+ statsManager->registerRewardsFromItem (rewardItem);
251+
252+ RewardUnlockLayer *rewardLayer = RewardUnlockLayer::create (rewardItem->m_chestID , nullptr );
253+ this ->addChild (rewardLayer, 100 );
254+
255+ rewardLayer->playRewardEffect ();
256+ // FMODAudioEngine::getInstance()->fadeMusic(1.0, 100, 1.0, 0.2);
257+
258+ // CCCallFunc *callback = CCCallFunc::create(this, callfunc_selector(SecretRewardsLayer::onRewardComplete));
259+ // CCDelayTime *delay = CCDelayTime::create(3.2);
260+ // CCSequence *sequence = CCSequence::create(delay, callback, nullptr);
261+ // this->runAction(sequence);
262+ }
263+ }
167264}
0 commit comments