コード例 #1
0
ファイル: Board.cpp プロジェクト: NStockwell/Match3
void Board::checkCombos()
{
	mMatchesMade = false;
	vector<Point> comboMatches;
	for(int i = 0; i < mColumns; i++)
	{//if no matches were made in this column, ignore it
		if(mMatchingInfo.numberMatchesInColumn[i] == 0)
			continue;

		//checkmatches on the all the elements of this column above the lowest gem matched
		for(int j = 0; j <= mMatchingInfo.lowestGemPosition[i]; j++)
		{
			Point modifiedGemPoint = Point(i,j);
			Gem* g = mTiles[XYCoordinatesToIndex(modifiedGemPoint)];
			g->setVisible(true);

			mergeMatches(&comboMatches, checkForMatches(modifiedGemPoint ) );
		}
	}
	
	//clear matchingInfo
	clearNumberMatchesInColumns();
	
	//if we have matches, store and save info
	if(comboMatches.size() > 0)
		storeMatches(comboMatches);
	else
		if(mInitializing)	//if we are still initializing but haven't any more matches, finish initialization
			finishInitializing();
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Luca-PG/Match3
bool Draw()
{
		//Draw foreground
		ApplySurface( 0, 0, background, Screen(), NULL );

		//Draw cursor
		if(gameGrid->SelectedCell_1 != 0)
			ApplySurface( gameGrid->SelectedCell_1->Position.x, gameGrid->SelectedCell_1->Position.y, cursor, Screen(), NULL );

		//Draw and update gems. 
		//TODO: Update code should be separated
		for( int i=0; i < ROWS; i++ )
		{
			for( int j=0; j < COLUMNS; j++ )
			{
				Gem * g = static_cast<Gem *>( gameGrid->Cells[i][j]->Object );
				if( g != NULL )
				{
					g->UpdateMovement( elapsedTime );
					g->Show();
				}
			}
		}
		
		//Draw the foreground
		ApplySurface( 0, 0, foreground, Screen(), NULL );

		//Present the screen
		if( SDL_Flip( Screen() ) == -1 )
		{
			return 1;
		}
}
コード例 #3
0
ファイル: inputRule.cpp プロジェクト: arturh85/Renamer.NET
Gem* InputRule::getGemByPosition(int position) const {
	for (map<sqlite_int64, Gem*>::const_iterator it = mChildren.begin();
		it!=mChildren.end(); it++) {

		Gem* gem = it->second;

		if(gem->getPosition() == position )
			return gem;
	}
	return NULL;
}
コード例 #4
0
ファイル: inputRule.cpp プロジェクト: arturh85/Renamer.NET
void InputRule::updateGems(string outputFormat) {
	boost::regex r(getRegex());

	unsigned int brackets = (unsigned) r.mark_count() - 1;

	/** \todo verify:
			gems must be ordered by bracket occureance (first gem must be the one for the first bracket, etc.

	**/

    vector<Gem*> gems = getGems();
	int gemCount = gems.size();
    vector<string> gemNames =  OutputFormat::parse(outputFormat);
	unsigned int gemNameCount = gemNames.size();

    for (unsigned int n=0; n<brackets; n++) {
        Gem* newGemPtr = NULL;
		// we need to create a new gem
    	if (n >= mChildren.size() ) {
            newGemPtr = new Gem(mDb, mRow.getRowId());
            mChildren[newGemPtr->getRowId()] = newGemPtr;

			// the following should not be done, because it would f*@k up this loop
			//            gems.push_back(newGemPtr);

			if(gemNameCount > n)
				newGemPtr->setName(gemNames[n]);
			else
				newGemPtr->setName("");
    	} else {
			// if the gem does already exist, we only set the position value
			// to get values that sum up, so we can rely on them.
    	    newGemPtr = gems[n];
    	}

        newGemPtr->setPosition(n+1); // positions are starting at 1
	}

	// remove gems which have no corresponding brackets
	for(unsigned i=brackets; i<gems.size(); i++) {
		removeGem(gems[i]->getRowId());
	}
}
コード例 #5
0
ファイル: MainScene.cpp プロジェクト: hotdl/hotdl
void MainScene::update(float dt)
{
	//srand((unsigned int)time(0));
	if(CCRANDOM_0_1() < 0.02)
	{
		int type = CCRANDOM_0_1()*7;
		std::string s = "0.png";
		s[0] = type+'0';
		Gem* gem = new Gem();
		CCSprite* sprt = CCSprite::createWithSpriteFrameName(s.c_str());
		int x = CCRANDOM_0_1()*size.width;
		int y = size.height+(size.height/(ROW+2))/2;
		float scale = CCRANDOM_0_1()*0.8+0.2;
		int speed = CCRANDOM_0_1()*5;
		sprt->setPosition(ccp(x, y));
		sprt->setScale(scale);
		node->addChild(sprt);
		gem->setSprite(sprt);
		gem->setType((GemType)type);
		gem->setSpeed(speed);
		fallingGems.push_back(gem);
	}
	
	for(int i = fallingGems.size()-1; i >= 0; i--)
	{
		Gem* gem = fallingGems.at(i);
		CCPoint pos = gem->getSprite()->getPosition();
		pos.y -= gem->getSpeed();
		gem->getSprite()->setPosition(pos);
		if(pos.y < -size.height/(ROW+2)/2)
		{
			node->removeChild(gem->getSprite(), true);
			vector<Gem*>::iterator it = fallingGems.begin()+i;
			fallingGems.erase(it);
		}
	}
}
コード例 #6
0
bool GemTestCommand::execute(Gem* self, Gem* test)
{
    bool result = false;

    switch (_id)
    {
    case HasFlag:
        return (test->style() & _arg) != 0;

    case GemType:
        return test->gemType() == _arg;

    case GemFlushMode:
        return (test->gemClass().flushMode() & _arg) != 0;

    case Text:
        return (_text == test->text());

    case TextBegins:
        return test->text().startsWith(_text);

    case NthChild:
    {
        result = false;
        Gem* origin = test->parentGem();
        if (!origin) break;
        int target = qAbs(_arg);
        int i = 1; // Counts the order.
        Gem* it;
        for (it = _arg > 0? origin->firstGem()
            : origin->lastGem(); it && it != test;
            it = _arg > 0? it->nextGem() : it->prevGem(), i++)
        {
            if (i == target)
            {
                // Didn't match it == test...
                return false;
            }
        }
        if (!it) break;
        result = i == target;
        break;
    }

    case NthOrder:
    {
        result = false;
        Gem* origin = test->parentGem();
        if (!origin) break;
        int target = qAbs(_arg);
        int i = 0; // Counts the order.
        for (Gem* it = _arg > 0? origin->firstGem() : origin->finalGem();
            it && it != origin->nextGem() && it != origin;
            it = _arg > 0? it->followingGem() : it->precedingGem())
        {
            if (!it->isControl()) i++;
            if (it == test)
            {
                result = true;
                break;
            }
            if (i >= target) return false;
        }
        if (!result) break; // Not even found...
        result = i == target;
        break;
    }

    case IsTop:
        return test->parent() == NULL;

    case IsMe:
        return test == self;

    case IsMyParent:
        return test == self->parentGem();

    case IsMyAncestor:
        result = false;
        for (Gem* it = self->parentGem(); it; it = it->parentGem())
            if (it == test)
            {
                result = true;
                break;
            }
        break;

    case IsBreak:
        return test->isBreak();

    case IsLineBreak:
        return test->isLineBreak();

    case IsControl:
        return test->isControl();

    case ExclusiveFlag:
        return (test->style() & ~_arg) == 0;

    case ChildCount:
        return test->count() == _arg;

    case CellWidth:
        return test->width() == _arg;

    default:
        qFatal("GemTestCommand: Invalid test command.");
        break;
    }

    return result;
}
コード例 #7
0
ファイル: UIWepon.cpp プロジェクト: joyfish/tianxiadiyi
void UIWepon::refresh()
{
	clear();

	// 是否有装备
	if (weponManager->equipment != NULL)
	{
		// 装备预览
		const char* s = CCString::createWithFormat("png/equipment/%s.png", weponManager->equipment->attribute.tuPian)->getCString();
		equipmentFeatureImageView->loadTexture(s);
		equipmentFeatureImageView->setVisible(true);

		int v = 0;

		if (weponManager->equipment->gem != NULL)
		{
			v -= weponManager->equipment->gem->getAttributeValue();
		}

		Gem* gem = weponManager->gemFillSprite.weponGem.gem;

		if (gem != NULL)
		{
			v += gem->getAttributeValue();
			const char* s = CCString::createWithFormat("png/gem/%s.png", gem->attribute.tuPian)->getCString();
			weponManager->gemFillSprite.sprite = CCSprite::create(s);
			weponManager->gemFillSprite.sprite->setPosition(roundImageView->getPosition());
			uiLayer->addChild(weponManager->gemFillSprite.sprite);
		}

		// 名称
		const char* mingCheng = TianXiaDiYi::getTheOnlyInstance()->ansi2utf8(weponManager->equipment->attribute.name);
		// 职业
		const char* zhiYe = TianXiaDiYi::getTheOnlyInstance()->ansi2utf8(weponManager->equipment->attribute.zhiYeXuQiu);
		// 物理攻击
		const char* wuLiGongJi = CCString::createWithFormat("%d", weponManager->equipment->attribute.chuShiDianShu+v)->getCString();
		// 强化等级
		const char* qiangHuaDengJi = CCString::createWithFormat("%d", weponManager->equipment->attribute.qiangHuaDengJi)->getCString();

		const char* attribute[4] = {mingCheng, zhiYe, wuLiGongJi, qiangHuaDengJi};

		for (int i = 0; i < 4; i++)
		{
			equipmentAttributeValueLable[i]->setText(attribute[i]);
		}

		delete[] mingCheng;
		delete[] zhiYe;
	}

	if (weponManager->maxPageNum <= 0)
	{
		return;
	}

	for (int i = 0; i < 4; i++)
	{
		int j = weponManager->pageNum * 4 + i;

		// 宝石栏是否有宝石
		if (weponManager->weponGemArray[j].gem != NULL)
		{
			const char* s = CCString::createWithFormat("png/gem/%s.png", weponManager->weponGemArray[j].gem->attribute.tuPian)->getCString();
			weponManager->gemSpriteArray[i].sprite = CCSprite::create(s);
			weponManager->gemSpriteArray[i].sprite->setPosition(gemImageView[i]->getPosition());
			uiLayer->addChild(weponManager->gemSpriteArray[i].sprite);
			weponManager->gemSpriteArray[i].weponGem = weponManager->weponGemArray[i];
		}
	}
}
コード例 #8
0
ファイル: gemtest.cpp プロジェクト: cmbruns/Doomsday-Engine
bool GemTest::test(Gem *gem)
{
    Gem *test = gem;       // The test pointer.
    Gem *tryStart;
    bool result, trying = false, passed;
    int i;
    
    for(GemTestCommand *cmd = _commands.next(); !cmd->isRoot(); cmd = cmd->next())
    {
        // We can skip commands if trying is passed.
        if(trying && ((passed && cmd->id() != CheckIfPassed) ||
                      (!test && cmd->id() != CheckIfPassed && cmd->id() != GoSelf)))
            continue;

        result = true;
        switch(cmd->id())
        {
        case GoSelf:
            test = gem;
            break;

        case GoParent:
            for(i = 0; test && i < cmd->intArg(); i++) test = test->parentGem();
            break;

        case GoNext:
            for(i = 0; test && i < cmd->intArg(); i++) test = test->nextGem();
            break;

        case GoPrev:
            for(i = 0; test && i < cmd->intArg(); i++) test = test->prevGem();
            break;

        case GoFirst:
            for(i = 0; test && i < cmd->intArg(); i++) test = test->firstGem();
            break;

        case GoLast:
            for(i = 0; test && i < cmd->intArg(); i++) test = test->lastGem();
            break;

        case GoFollowing:
            for(i = 0; test && i < cmd->intArg(); i++) test = test->followingGem();
            break;
            
        case GoPreceding:
            for(i = 0; test && i < cmd->intArg(); i++) test = test->precedingGem();
            break;

        case GoFinal:
            test = gem->finalGem();
            break;

        case BeginTry:
            trying = true;
            passed = false;
            tryStart = test;
            break;

        case CheckIfPassed:
            trying = false;
            result = passed;
            test = tryStart; // Return to where the test began.
            break;

        default:
            // Are we escalating this check?
            if(cmd->escalating())
            {
                result = false;
                for(Gem* it = test->parentGem(); it; it = it->parentGem())
                {
                    if(cmd->execute(gem, it))
                    {
                        result = true;
                        break;
                    }
                }
            }
            else
            {
                result = cmd->execute(gem, test);
            }
            break;
        }

        // You can't fail the BeginTry command.
        if(cmd->id() == BeginTry) continue;

        // A null test pointer is an automatic failure.
        if(!test)
        {
            if(!trying) return false;
            result = false;
        }

        // Did it fail?
        if(trying)
        {
            if(result != cmd->negated()) passed = true; // Passed!
        }
        else
        {
            if(result == cmd->negated()) return false; // Failed!
        }
    }

    if(trying)
    {
        qCritical("A 'try..pass' is missing 'pass'.");
        exit(1);
    }

    // All commands were successful.
    return true;
}
コード例 #9
0
ファイル: equipment_make.cpp プロジェクト: lindianyin/sgbj
//打开物品
int CharData::openSlotItm(int slot, int nums, json_spirit::Object& robj)
{
    boost::shared_ptr<iItem> itm = m_bag.getItem(slot);
    if (!itm.get())
    {
        return HC_ERROR;
    }
    if (itm->getType() != iItem_type_gem)
    {
        return HC_ERROR;
    }
    int use_num = itm->getCount();
    if (nums > 0 && itm->getCount() > nums)
    {
        use_num = nums;
    }
    Gem* pg = dynamic_cast<Gem*>(itm.get());
    robj.push_back( Pair("use", pg->getUsage()) );

    switch (pg->getUsage())
    {
        //变身卡
        case ITEM_USAGE_CHANGE_CARD:
        {
            m_change_spic = itm->getSubtype() - 499;
            m_change_spic_time = time(NULL) + 7200;
            m_bag.removeItem(slot);
            itm->Clear();
            itm->Save();
            //robj.push_back( Pair("refresh", 1) );
            setExtraData(char_data_type_normal, char_data_change_spic, m_change_spic);
            setExtraData(char_data_type_normal, char_data_change_spic_time, m_change_spic_time);
            return HC_SUCCESS;
        }
        //兑换货币
        case ITEM_USAGE_SILVER_CARD:
        {
            int total = pg->getValue() * use_num;
            addSilver(total);
            //银币统计
            add_statistics_of_silver_get(m_id,m_ip_address,total,silver_get_by_treasure, m_union_id, m_server_id);
            json_spirit::Object obj;
            obj.push_back( Pair("type", item_type_silver) );
            obj.push_back( Pair("count", total) );
            obj.push_back( Pair("id", 0) );
            obj.push_back( Pair("fac", 0) );
            obj.push_back( Pair("name", strSilver) );
            robj.push_back( Pair("get", obj) );
            if (itm->getCount() > use_num)
            {
                itm->addCount(-use_num);
            }
            else
            {
                m_bag.removeItem(slot);
                itm->Clear();
            }
            itm->Save();
            NotifyCharData();
            return HC_SUCCESS;
        }
        case ITEM_USAGE_GOLD_CARD:
        {
            int total = pg->getValue() * use_num;
            addGold(total);
            //金币获得统计
            add_statistics_of_gold_get(m_id,m_ip_address,total,gold_get_treasure, m_union_id, m_server_id);
            json_spirit::Object obj;
            obj.push_back( Pair("type", item_type_gold) );
            obj.push_back( Pair("count", total) );
            obj.push_back( Pair("id", 0) );
            obj.push_back( Pair("fac", 0) );
            obj.push_back( Pair("name", strGold) );
            robj.push_back( Pair("get", obj) );
            if (itm->getCount() > use_num)
            {
                itm->addCount(-use_num);
            }
            else
            {
                m_bag.removeItem(slot);
                itm->Clear();
            }
            itm->Save();
            NotifyCharData();
            return HC_SUCCESS;
        }
        case ITEM_USAGE_YUSHI_CARD:
        {
            int total = pg->getValue() * use_num;
            addTreasure(treasure_type_yushi, total);
            json_spirit::Object obj;
            obj.push_back( Pair("type", item_type_treasure) );
            obj.push_back( Pair("count", total) );
            obj.push_back( Pair("id", treasure_type_yushi) );
            obj.push_back( Pair("fac", 0) );
            boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(treasure_type_yushi);
            if (tr.get())
            {
                obj.push_back( Pair("quality", tr->quality) );
                obj.push_back( Pair("spic", tr->spic) );
                obj.push_back( Pair("name", tr->name) );
            }
            robj.push_back( Pair("get", obj) );
            if (itm->getCount() > use_num)
            {
                itm->addCount(-use_num);
            }
            else
            {
                m_bag.removeItem(slot);
                itm->Clear();
            }
            itm->Save();
            return HC_SUCCESS;
        }
        case ITEM_USAGE_PRESTIGE_CARD:
        {
            int total = pg->getValue() * use_num;
            addPrestige(total);
            json_spirit::Object obj;
            obj.push_back( Pair("type", item_type_prestige) );
            obj.push_back( Pair("count", total) );
            obj.push_back( Pair("id", 0) );
            obj.push_back( Pair("fac", 0) );
            obj.push_back( Pair("name", strPrestige) );
            robj.push_back( Pair("get", obj) );
            if (itm->getCount() > use_num)
            {
                itm->addCount(-use_num);
            }
            else
            {
                m_bag.removeItem(slot);
                itm->Clear();
            }
            itm->Save();
            return HC_SUCCESS;
        }
        case ITEM_USAGE_SUPPLY_CARD:
        {
            int total = pg->getValue() * use_num;
            addTreasure(treasure_type_supply, total);
            json_spirit::Object obj;
            obj.push_back( Pair("type", item_type_treasure) );
            obj.push_back( Pair("count", total) );
            obj.push_back( Pair("id", treasure_type_supply) );
            obj.push_back( Pair("fac", 0) );
            boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(treasure_type_supply);
            if (tr.get())
            {
                obj.push_back( Pair("quality", tr->quality) );
                obj.push_back( Pair("spic", tr->spic) );
                obj.push_back( Pair("name", tr->name) );
            }
            robj.push_back( Pair("get", obj) );
            if (itm->getCount() > use_num)
            {
                itm->addCount(-use_num);
            }
            else
            {
                m_bag.removeItem(slot);
                itm->Clear();
            }
            itm->Save();
            NotifyCharData();
            return HC_SUCCESS;
        }
        case ITEM_USAGE_GONGXUN_CARD:
        {
            int total = pg->getValue() * use_num;
            addTreasure(treasure_type_gongxun, total);
            json_spirit::Object obj;
            obj.push_back( Pair("type", item_type_treasure) );
            obj.push_back( Pair("count", total) );
            obj.push_back( Pair("id", treasure_type_gongxun) );
            obj.push_back( Pair("fac", 0) );
            boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(treasure_type_gongxun);
            if (tr.get())
            {
                obj.push_back( Pair("quality", tr->quality) );
                obj.push_back( Pair("spic", tr->spic) );
                obj.push_back( Pair("name", tr->name) );
            }
            robj.push_back( Pair("get", obj) );
            if (itm->getCount() > use_num)
            {
                itm->addCount(-use_num);
            }
            else
            {
                m_bag.removeItem(slot);
                itm->Clear();
            }
            itm->Save();
            return HC_SUCCESS;
        }
        //卷轴
        case ITEM_USAGE_EQUIPMENT_SCROLL:
        {
            equipment_scroll* sp = Singleton<equipment_scroll_mgr>::Instance().getScroll(pg->getValue());
            if (!sp)
            {
                return HC_ERROR;
            }
            
            json_spirit::Object eq = sp->m_eqobj;

            bool canMake = true;

            json_spirit::Array mlist;

            json_spirit::Object o;
            o.push_back( Pair("name", sp->m_equipment_src->name) );
            o.push_back( Pair("type", iItem_type_equipment) );
            o.push_back( Pair("id", sp->m_equipment_src->baseid) );
            o.push_back( Pair("spic", sp->m_equipment_src->baseid) );
            o.push_back( Pair("quality", sp->m_equipment_src->quality) );
            o.push_back( Pair("need", 1) );
            if (sp->m_equipment_src->m_place.get())
            {
                bool can_sweep = false;
                o.push_back( Pair("info", sp->m_equipment_src->m_place->info) );
                if (sp->m_equipment_src->m_place->type == 1)
                {
                    can_sweep = m_tempo.check_stronghold_can_sweep(sp->m_equipment_src->m_place->mapId,sp->m_equipment_src->m_place->stageId,sp->m_equipment_src->m_place->pos);
                    boost::shared_ptr<StrongholdData> bstronghold = GeneralDataMgr::getInstance()->GetStrongholdData(sp->m_equipment_src->m_place->mapId,sp->m_equipment_src->m_place->stageId,sp->m_equipment_src->m_place->pos);
                    if (bstronghold.get())
                    {
                        o.push_back( Pair("open_level", bstronghold->m_level) );
                    }
                    o.push_back( Pair("can_sweep", can_sweep) );
                }
                else if (sp->m_equipment_src->m_place->type == 2)
                {
                    can_sweep = eliteCombatMgr::getInstance()->check_stronghold_can_attack(m_id,sp->m_equipment_src->m_place->mapId,sp->m_equipment_src->m_place->pos);
                    o.push_back( Pair("can_sweep", can_sweep) );
                }
            }

            EquipmentData* src_eq = m_bag.getDefaultEquip(sp->m_src_equipment, 999);
            if (src_eq)
            {
                robj.push_back( Pair("eid", src_eq->id) );
                o.push_back( Pair("num", 1) );

                int nextqLevel = src_eq->qLevel;
                int nextAdd = src_eq->addValue;
                int nextAdd2 = src_eq->addValue2;
                upgradeValue(sp->m_equipment->up_quality, src_eq->type, nextqLevel, nextAdd, nextAdd2);

                eq.push_back( Pair("level", nextqLevel) );
                eq.push_back( Pair("addNums", sp->m_equipment->baseValue + nextAdd) );

                if (nextAdd2 > 0)
                {
                    eq.push_back( Pair("addNums2", sp->m_equipment->baseValue2 + nextAdd2) );
                }
            }
            else
            {
                eq.push_back( Pair("level", 0) );
                eq.push_back( Pair("addNums", sp->m_equipment->baseValue) );
                if (sp->m_equipment->baseValue2 > 0)
                {
                    eq.push_back( Pair("addNums2", sp->m_equipment->baseValue2) );
                }

                o.push_back( Pair("num", 0) );
                canMake = false;
            }
            mlist.push_back(o);

            robj.push_back( Pair("eq", eq) );

            //检查材料是否足够
            canMake &= checkMaterial(sp, *this, m_bag, mlist);

            robj.push_back( Pair("mlist", mlist) );
            
            robj.push_back( Pair("canMake", canMake) );
            return HC_SUCCESS;
        }
        //VIP经验卡
        case ITEM_USAGE_VIP_EXP_80:
        case ITEM_USAGE_VIP_EXP:
        {
            if (m_vip < 0 || m_vip >= 12)
            {
                return HC_ERROR;
            }
            if (pg->getValue() <= 0)
            {
                return HC_ERROR;
            }
            int add = 0;
            int count = use_num;
            if (count >= itm->getCount())
            {
                count = itm->getCount();
            }
            else if (count <= 0)
            {
                count = 1;
            }
            int old_recharge = m_total_recharge + m_vip_exp;
            //上限限制
            if (pg->getUsage() == ITEM_USAGE_VIP_EXP_80)
            {
                //只能升级到80%
                int max_vip = iVIP_recharge[m_vip] * 4 / 5;
                if (old_recharge >= max_vip)
                {
                    return HC_ERROR_USE_VIP_CARD;
                }
                int canAdd = max_vip - old_recharge;
                int maxUsed = canAdd / pg->getValue();
                if (canAdd % pg->getValue() != 0)
                {
                    ++maxUsed;
                }
                if (count > maxUsed)
                {
                    count = maxUsed;
                }
                add = pg->getValue() * count;
                if (add > canAdd)
                {
                    add = canAdd;
                }
            }
            else if (pg->getUsage() == ITEM_USAGE_VIP_EXP)
            {
                add = pg->getValue() * count;
            }
            if (itm->getCount() == count)
            {
                m_bag.removeItem(slot);
                itm->Clear();
                itm->Save();
            }
            else
            {
                itm->addCount(-count);
                itm->Save();
            }

            m_vip_exp += add;
            InsertSaveDb("update char_data set exp=" + LEX_CAST_STR(m_vip_exp) + " where cid=" + LEX_CAST_STR(m_id));
            if (pg->getUsage() == ITEM_USAGE_VIP_EXP)
            {
                updateVip();
            }

            //通知客户端,充值条变化
            robj.push_back( Pair("rechargeFrom", old_recharge) );
            robj.push_back( Pair("rechargeAdd", add) );

            return HC_SUCCESS;
        }
        //限时增益
        case ITEM_USAGE_BUFF_BINGLI:
        case ITEM_USAGE_BUFF_WUGONG:
        case ITEM_USAGE_BUFF_WUFANG:
        case ITEM_USAGE_BUFF_CEGONG:
        case ITEM_USAGE_BUFF_CEFANG:
        {
            if (pg->getValue() <= 0)
            {
                return HC_ERROR;
            }
            if (itm->getInvalidTime() <= time(NULL))
            {
                m_bag.removeItem(slot);
                itm->Clear();
                itm->Save();
                return HC_ERROR;
            }
            int count = 1;
            if (itm->getCount() == count)
            {
                m_bag.removeItem(slot);
                itm->Clear();
                itm->Save();
            }
            else
            {
                itm->addCount(-count);
                itm->Save();
            }
            m_Buffs.addBuff(pg->getUsage()-ITEM_USAGE_BUFF_BINGLI+1,pg->getValue(),7200);
            #ifdef QQ_PLAT
            treasure_cost_tencent(this,(int)itm->getSubtype(),1);
            #endif
            return HC_SUCCESS;
        }
        //开启宝箱
        case ITEM_USAGE_BOX:
        {
            if (pg->getValue() <= 0)
            {
                return HC_ERROR;
            }
            int count = use_num;
            if (count >= itm->getCount())
            {
                count = itm->getCount();
            }
            else if (count <= 0)
            {
                count = 1;
            }
            //开启宝箱需要银币
            int need_silver = count * pg->getValue();
            if (silver() < need_silver)
            {
                if (count > 1)
                {
                    count = silver() / pg->getValue();
                    need_silver = count * pg->getValue();
                    robj.push_back( Pair("msg", getErrMsg(HC_ERROR_NOT_ENOUGH_SILVER)) );
                }
                else
                {
                    std::string msg = strBoxSilverNotEnoughMsg;
                    str_replace(msg, "$S", LEX_CAST_STR(pg->getValue()));
                    robj.push_back( Pair("msg", msg) );
                    return HC_ERROR;
                }
            }
            //开启宝箱需要位置
            if (count > 0 && (m_bag.size()-m_bag.getUsed()) < count)
                return HC_ERROR_NOT_ENOUGH_BAG_SIZE;
            if (itm->getCount() == count)
            {
                m_bag.removeItem(slot);
                itm->Clear();
                itm->Save();
            }
            else
            {
                itm->addCount(-count);
                itm->Save();
            }
            if (count == 1)
            {
                addSilver(-need_silver);
                add_statistics_of_silver_cost(m_id,m_ip_address,need_silver,silver_cost_for_open_box, m_union_id, m_server_id);
                //给奖励!
                std::list<Item> getItems;
                int notify = lootMgr::getInstance()->getBoxLoots(itm->getSubtype(), getItems, 0);
                if (notify > 0)
                {
                    std::string msg = strBoxGetMsg;
                    str_replace(msg, "$W", MakeCharNameLink(m_name));
                    boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(itm->getSubtype());
                    if (tr.get())
                    {
                        std::string name = tr->name;
                        addColor(name, tr->quality);
                        str_replace(msg, "$B", name);
                    }
                    Item& item = *(getItems.begin());
                    if (item.type == item_type_treasure)
                    {
                        tr = GeneralDataMgr::getInstance()->GetBaseTreasure(item.id);
                        if (tr.get())
                        {
                            std::string name = MakeTreasureLink(tr->name, item.id);
                            addColor(name, tr->quality);
                            str_replace(msg, "$R", name);
                        }
                    }
                    json_spirit::mObject mobj;
                    mobj["cmd"] = "broadCastMsg";
                    mobj["msg"] = msg;
                    boost::shared_ptr<splsTimer> tmsg;
                       tmsg.reset(new splsTimer(4, 1, mobj,1));
                       splsTimerMgr::getInstance()->addTimer(tmsg);
                }
                //随机列表
                std::list<Item> items_list;
                lootMgr::getInstance()->getBoxLootsInfo(itm->getSubtype(),items_list);
                json_spirit::Array alist;
                for (std::list<Item>::iterator it = items_list.begin(); it != items_list.end(); ++it)
                {
                    Item& item = *it;
                    json_spirit::Object obj;
                    if ((*(getItems.begin())).id == item.id && (*(getItems.begin())).type == item.type
                        && (*(getItems.begin())).nums == item.nums && (*(getItems.begin())).fac == item.fac)
                    {
                        obj.push_back( Pair("get", 1) );
                    }
                    item.toObj(obj);
                    alist.push_back(obj);
                }
                robj.push_back( Pair("list", alist) );
                giveLoots(this, getItems, m_area, m_level, 0, NULL, &robj, true, give_box_loot);
            }
            else
            {
                addSilver(-need_silver);
                add_statistics_of_silver_cost(m_id,m_ip_address,need_silver,silver_cost_for_open_box, m_union_id, m_server_id);
                //给奖励!
                std::list<Item> getAllItems;
                for (int i = 0; i < count; ++i)
                {
                    std::list<Item> getItems;
                    int notify = lootMgr::getInstance()->getBoxLoots(itm->getSubtype(), getItems, 0);
                    Item& item = *(getItems.begin());
                    if (notify > 0)
                    {
                        std::string msg = strBoxGetMsg;
                        str_replace(msg, "$W", MakeCharNameLink(m_name));
                        boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(itm->getSubtype());
                        if (tr.get())
                        {
                            std::string name = tr->name;
                            addColor(name, tr->quality);
                            str_replace(msg, "$B", name);
                        }
                        if (item.type == item_type_treasure)
                        {
                            tr = GeneralDataMgr::getInstance()->GetBaseTreasure(item.id);
                            if (tr.get())
                            {
                                std::string name = MakeTreasureLink(tr->name, item.id);
                                addColor(name, tr->quality);
                                str_replace(msg, "$R", name);
                            }
                        }
                        GeneralDataMgr::getInstance()->broadCastSysMsg(msg, -1);
                    }
                    getAllItems.push_back(item);
                }
                giveLoots(this, getAllItems, m_area, m_level, 0, NULL, &robj, true, give_box_loot);
            }
            #ifdef QQ_PLAT
            //treasure_cost_tencent(this,(int)itm->getSubtype(),1);
            #endif
            NotifyCharData();
            return HC_SUCCESS;
        }
    }
    return HC_ERROR;//未知类型
}
コード例 #10
0
ファイル: grid.cpp プロジェクト: FalconJ/BejeweledClone
// Check for any 3+ matches and builds a table of gems that need to be removed
bool Grid::checkMatches()
{
    bool match = false;
    // Clear matched gem list
    MatchedGems.clear();

    // Check columns for a match
    for (int x = 0; x < Width; x++)
    {
        int count = 0;
        int focus;
        int ox, oy;
        for (int y = 0; y < Height; y++)
        {
            Gem* gem = Gems[y * Width + x];
            int current = gem->getType();
            if (count == 0)
            {
                focus = current;
                count = 1;
                ox = x;
                oy = y;
            }
            else
            if (current == focus)
                count++;

            // We reached the end of a sequence or the end of the column so check for min matches
            if (current != focus || y == Height - 1)
            {
                // Remove matches in column
                if (count >= 3)
                {
                    match = true;
                    for (int i = 0; i < count; i++)
                    {
                        addGemToMatches(Gems[oy * Width + ox]);
                        oy++;
                    }
                }
                focus = current;
                ox = x;
                oy = y;
                count = 1;
            }
        }
    }

    // Check rows for a match
    for (int y = 0; y < Height; y++)
    {
        int count = 0;
        int focus;
        int ox, oy;
        for (int x = 0; x < Width; x++)
        {
            Gem* gem = Gems[y * Width + x];
            int current = gem->getType();
            if (count == 0)
            {
                focus = current;
                count = 1;
                ox = x;
                oy = y;
            }
            else
            if (current == focus)
                count++;

            // We reached the end of a sequence or the end of the row so check for min matches
            if (current != focus || x == Width - 1)
            {
                // Remove matches in row
                if (count >= 3)
                {
                    match = true;
                    for (int i = 0; i < count; i++)
                    {
                        addGemToMatches(Gems[oy * Width + ox]);
                        ox++;
                    }
                }
                focus = current;
                ox = x;
                oy = y;
                count = 1;
            }
        }
    }

    // Destroy any matched gems
    if (MatchedGems.size() > 0)
    {
        g_pAudio->PlaySound("audio/gem_destroyed.wav");
    }
    for (std::list<Gem*>::iterator it = MatchedGems.begin(); it != MatchedGems.end(); ++it)
        (*it)->explode();

    return match;
}
コード例 #11
0
ファイル: grid.cpp プロジェクト: FalconJ/BejeweledClone
// Handle falling gems
void Grid::gemsFalling(float dt)
{
    bool falling = false;
    for (int x = 0; x < Width; x++)
    {
        for (int y = Height - 1; y >= 0; y--)
        {
            Gem* g = Gems[y * Width + x];
            Gem* gem_below = Gems[(y + 1) * Width + x];
            if (g != 0 && gem_below == 0)
            {
                int old_x, old_y;
                screenToGrid((int)g->m_X, (int)g->m_Y, old_x, old_y);
                float dy = Gem::gemFallSpeed * g->m_ScaleY * dt;         // Scale fall speed to match different height displays
                if (dy > g->m_H - 1)
                    dy = g->m_H - 1;
                g->m_Y += dy;

                int new_x, new_y;
                screenToGrid((int)g->m_X, (int)g->m_Y, new_x, new_y);
                if (new_y == y)
                {
                    // Still in same block
                    falling = true;
                }
                else
                {
                    // Moved into new block below
                    if (Gems[new_y * Width + new_x] == 0)
                    {
                        // Remove from previous grid cell and insert into new empty cell below
                        Gems[old_y * Width + old_x] = 0;
                        Gems[new_y * Width + new_x] = g;
                        falling = true;
                        if (Gems[(new_y + 1) * Width + new_x] != 0)
                        {
                            // Position sprite because it may have gone over boundary
                            g->m_Y = (float)new_y * GemSize + GridOriginY;
                        }
                    }
                }
            }
        }
    }

    // Traverse removed gems and drop them back into the grid
    std::list<Gem*> removals;
    bool new_gem = false;
    if (falling == false)
    {
        if (MatchedGems.size() > 0)
        {
            Game* game = (Game*)g_pSceneManager->Find("game");
            falling = true;
            for (std::list<Gem*>::iterator it = MatchedGems.begin(); it != MatchedGems.end(); ++it)
            {
                Gem* g = *it;
                int x, y;
                screenToGrid((int)g->m_X, (int)g->m_Y, x, y);
                if (Gems[x] == 0)
                {
                    // Add new gem
                    Gems[x] = g;
                    int type = rand() % MAX_GEM_TYPES;
                    g->setType(type);
                    g->m_Y = (float)GridOriginY;

                    game->GetTweener().Tween(0.5f,
                                                FLOAT, &g->m_Alpha, 1.0f,
                                                EASING, Ease::sineOut,
                                                END);
                    removals.push_back(*it);
                    new_gem = true;
                }
            }
        }
    }
    // Cleanup removed gems in mathed gems list
    for (std::list<Gem*>::iterator it = removals.begin(); it != removals.end(); ++it)
        MatchedGems.remove(*it);

    if (new_gem == true)
    {
        g_pAudio->PlaySound("audio/gem_land.wav");
    }

    if (falling == false)
    {
        if (!checkMatches())
        {
            // Switch back to waiting for gem selection state
            Game* game = (Game*)g_pSceneManager->Find("game");
            game->changeGameState(waitingFirstGem);
        }
    }
}