Exemplo n.º 1
0
bool SkillAttackManager::initWithID(int ID)
{
    bool bRet = false;
    
    do {
        
        CC_BREAK_IF(ID <= 0);
        
        
        SqliteResolver* resolver = SqliteResolver::create(TABLE_ATTACKS, ID);
        CC_BREAK_IF(!resolver);
        
        m_skillAttackArray = Array::create();
        m_skillAttackArray->retain();

        setSkillLastDelay(resolver->getFloat("SkillLastDelay"));
        //log("SkillLastDelay:%f", m_skillLastDelay);
        
        Array* skillArray = resolver->getArray("TimeAndSkillPropertyID");
        CC_BREAK_IF(skillArray == NULL);
        
        Object* obj;
        CCARRAY_FOREACH(skillArray, obj)
        {
            Point point = PointFromString( ((String*)obj)->getCString() );
            float attackRate = point.x;
            int skillPropertyID = (int)point.y;
            
           //log("SkillAttackManager::%f %d",attackRate,skillPropertyID);
            SkillProperty* pSkillProperty = SkillProperty::create(skillPropertyID);
            if(!pSkillProperty)
                continue;
            
            SkillAttack* skillAttack = SkillAttack::create(pSkillProperty);
            skillAttack->setAttackRate(attackRate);
            

            m_skillAttackArray->addObject(skillAttack);
        
        }
        
        
               
        bRet = true;
    } while (0);
Exemplo n.º 2
0
void ShapeCache::addShapeWithFileToSprite(std::string plist, cocos2d::Sprite *s){
    FileUtils *fu = FileUtils::getInstance();
    ValueMap root = fu->getValueMapFromFile(plist);
    
    auto bodies = root["bodies"].asValueMap();
    ValueMap fixtureDef;
    for (auto iter=bodies.begin(); iter!=bodies.end(); iter++) {
        fixtureDef = iter->second.asValueMap();
    }
    
    ValueMap item = fixtureDef["fixtures"].asValueVector()[0].asValueMap();
    s->setPhysicsBody(PhysicsBody::create());
    for (auto iter=item.begin(); iter!=item.end(); iter++) {
        std::string key = iter->first;
        auto type = iter->second;
        if (key == "polygons") {
            auto value = type.asValueVector();
            for (int i=0; i<value.size(); i++) {
                auto _item = value[i].asValueVector();
                Vec2 *vec = new Vec2[_item.size()];
                for (int j=0; j<_item.size(); j++) {
                    Point p = PointFromString(_item[j].asString().c_str());
                    vec[j] = Vec2(p.x, p.y);
                }
                s->getPhysicsBody()->addShape(PhysicsShapePolygon::create(vec, _item.size()));
            }
        }else if (key == "mass"){
            s->getPhysicsBody()->setMass(type.asInt());
        }else if (key == "friction"){
            auto shapes = s->getPhysicsBody()->getShapes();
            for (int i=0; i<shapes.size(); i++) {
                shapes.at(i)->setFriction(type.asInt());
            }
        }
        
    }
    
}
Exemplo n.º 3
0
bool LHBodyShape::initWithDictionary(ValueMap& dict, ValueVector& shapePoints, b2Body* body, Node* node, LHScene* scene, float scaleX, float scaleY)
{
    {
        shapeName   = dict["name"].asString();
        shapeID     = dict["shapeID"].asInt();
        
        int flipx = scaleX < 0 ? -1 : 1;
        int flipy = scaleY < 0 ? -1 : 1;
        
        
        for(int f = 0; f < shapePoints.size(); ++f)
        {
            Value fixPointsValue = shapePoints[f];;
            ValueVector fixPoints = fixPointsValue.asValueVector();
            
            int count = (int)fixPoints.size();
            if(count > 2)
            {
                b2Vec2 *verts = new b2Vec2[count];
                b2PolygonShape shapeDef;
                
                int i = 0;
                for(int j = count-1; j >=0; --j)
                {
                    const int idx = (flipx < 0 && flipy >= 0) || (flipx >= 0 && flipy < 0) ? count - i - 1 : i;
                    
                    std::string pointStr = fixPoints[j].asString();
                    Point point = PointFromString(pointStr);
                    
                    point.x *= scaleX;
                    point.y *= scaleY;
                    
                    point.y = -point.y;
                    
                    b2Vec2 vec = scene->metersFromPoint(point);
                    
                    verts[idx] = vec;
                    ++i;
                }
                
                if(LHValidateCentroid(verts, count))
                {
                    shapeDef.Set(verts, count);
                    
                    b2FixtureDef fixture;
                    
                    LHSetupb2FixtureWithInfo(&fixture, dict);
                    
                    fixture.userData = this;
                    fixture.shape = &shapeDef;
                    body->CreateFixture(&fixture);
                }
                
                delete[] verts;
            }
        }
        
        
        return true;
    }
    return false;
}
Exemplo n.º 4
0
bool LHBodyShape::initWithValueMap(ValueMap& dict, b2Body* body, Node* node, LHScene* scene, float scaleX, float scaleY)
{
    {
        shapeName   = dict["name"].asString();
        shapeID     = dict["shapeID"].asInt();
        
        int flipx = scaleX < 0 ? -1 : 1;
        int flipy = scaleY < 0 ? -1 : 1;
        
        Value fixturesPointsValue = dict["points"];
        
        
        float ratio = Director::getInstance()->getContentScaleFactor();
        
        
        if(!fixturesPointsValue.isNull())
        {
            ValueVector fixtures = fixturesPointsValue.asValueVector();
            
            for(int s = 0; s < fixtures.size(); ++s)
            {
                ValueVector fixPoints = fixtures[s].asValueVector();
                
                int count = (int)fixPoints.size();
                if(count > 2)
                {
                    
                    b2Vec2 *verts = new b2Vec2[count];
                    b2PolygonShape shapeDef;
                    
                    int i = 0;
                    for(int j = count-1; j >=0; --j)
                    {
                        const int idx = (flipx < 0 && flipy >= 0) || (flipx >= 0 && flipy < 0) ? count - i - 1 : i;
                        
                        std::string ptStr = fixPoints[j].asString();
                        Point point = PointFromString(ptStr);
                        
                        point.x /= ratio;
                        point.y /= ratio;
                        
                        point.x *= scaleX;
                        point.y *= scaleY;
                        
                        point.y = -point.y;
                        
                        b2Vec2 vec = scene->metersFromPoint(point);
                        
                        verts[idx] = vec;
                        ++i;
                    }
                    
                    if(LHValidateCentroid(verts, count))
                    {
                        shapeDef.Set(verts, count);
                        
                        b2FixtureDef fixture;
                        
                        LHSetupb2FixtureWithInfo(&fixture, dict);
                        
                        fixture.userData = this;
                        fixture.shape = &shapeDef;
                        body->CreateFixture(&fixture);
                    }
                    
                    delete[] verts;
                }
            }
        }
        else{
            
            float radius = dict["radius"].asFloat();
            std::string centerStr = dict["center"].asString();
            Point point = PointFromString(centerStr);
            
            radius /= ratio;
            
            point.x /= ratio;
            point.y /= ratio;
            
            point.x *= scaleX;
            point.y *= scaleY;
            
            point.y = -point.y;
            
            
            b2CircleShape* shape = new b2CircleShape();
            shape->m_radius = scene->metersFromValue(radius);
            shape->m_p = scene->metersFromPoint(point);
            
            b2FixtureDef fixture;
            LHSetupb2FixtureWithInfo(&fixture, dict);
            
            fixture.userData = this;
            fixture.shape = shape;
            body->CreateFixture(&fixture);
            
        }
        
        return true;
    }
    return false;
}
Exemplo n.º 5
0
void ShapeCacher::addShapesWithDictionary(ValueMap &dictionary, PhysicsBody *body)
{
	//decode the plist file
	int format = 0;
	// get the format
	if (dictionary.find("metadata") != dictionary.end())
	{
		ValueMap& metadataDict = dictionary["metadata"].asValueMap();
		format = metadataDict["format"].asInt();
	}
	// check the format
	CCASSERT(format == 1, "format is not supported for #addShapesWithDictionary#:");

	ValueMap& bodyDict = dictionary["bodies"].asValueMap();

	for (auto iter = bodyDict.begin(); iter != bodyDict.end(); ++iter)
	{
		ValueMap& dataDict = iter->second.asValueMap();

		/****************not used yet!***********************/
		//set anchorpoint	
		//Point anchorPoint = PointFromString(dataDict["anchorpoint"].asString());
	
		ValueVector& fixtureVector = dataDict["fixtures"].asValueVector();

		for (auto iter = fixtureVector.begin(); iter != fixtureVector.end(); ++iter)
		{
			ValueMap& fixtureDict =(ValueMap&)(*iter).asValueMap();

			/****************not used yet!***********************/

			/* //body->setCategoryBitmask(fixtureDict["filter_categoryBits"].asInt);
			/* //body->setCollisionBitmask(fixtureDict["filter_maskBits"].asInt);
			/* //body->setGroup(fixtureDict["filter_groupIndex"].asInt);

			/* //float friction    = fixtureDict["friction"].asFloat;
			/* //float density     = fixtureDict["density"].asFloat;
			/* //float restitution = fixtureDict["restitution"].asFloat;
			/* //int   isSensor    = fixtureDict["isSensor"].asInt;
			/* //std::string userdata = fixtureDict["userdataCbValue"].asString;
			/* 
			/* //std::string fixtureType = fixtureDict["fixture_type"].asString();
			/* 
			/* if (fixtureType == "POLYGON") 
			{*/
			/****************not used yet!***********************/
			ValueVector& polygonsVector = (fixtureDict["polygons"].asValueVector());

			for (auto iter = polygonsVector.begin(); iter != polygonsVector.end(); ++iter) 
			{
				int vertexNum = (*iter).asValueVector().size();;
				ValueVector polygonArray = (*iter).asValueVector();
				Point *polyVertex = new Point[vertexNum];
				int i = 0;
				for (auto piter = polygonArray.begin(); piter != polygonArray.end(), i < vertexNum; ++piter ,i++)
				{
					Point vertex = PointFromString((*piter).asString());
					polyVertex[i] = vertex;
				}
				body->addShape(PhysicsShapePolygon::create(polyVertex, vertexNum));
				CC_SAFE_DELETE_ARRAY(polyVertex);
			}

		}
		//	else if (fixtureType == "CIRCLE") 
		//	{

		//		continue;
		//		//ObjectDict *circleData = (ObjectDict *)fixtureData->objectForKey("circle");

		//		//b2CircleShape *circleShape = new b2CircleShape();

		//		//circleShape->m_radius = static_cast<CCString *>(circleData->objectForKey("radius"))->toFloat() / ptmRatio;
		//		//CCPoint p = CCPointFromString(static_cast<CCString *>(circleData->objectForKey("position"))->toStdString().c_str());
		//		//circleShape->m_p = b2Vec2(p.x / ptmRatio, p.y / ptmRatio);
		//		//fix->fixture.shape = circleShape;

		//		//// create a list
		//		//*nextFixtureDef = fix;
		//		//nextFixtureDef = &(fix->next);

		//	}
		//	else 
		//	{
		//		CCAssert(0, "Unknown fixtureType");
		//	}
		//}
	}
}
Exemplo n.º 6
0
Altar::Altar()
{
	/*ValueMap modell;
	ValueVector formsl;
	int i = 0,j = 0,k = 0;
	for(int i = 0; i < 5; i++)
	{

		ValueMap forml;
		ValueVector rewardl;
		rewardl.push_back(cocos2d::Value("target:detect|type:add~~~typeId:2001001|site:{5,1}"));
		rewardl.push_back(cocos2d::Value("sdfsfsfsfsfsf"));
		ValueVector mapl;

		for(int j = 0; j < 7;j++)
		{
			ValueVector rowsl;
			for(int k = 0; k < 7; k++)
			{
				rowsl.push_back(cocos2d::Value(0));
			}
			mapl.push_back(cocos2d::Value(rowsl));
		}

		forml["map"] = mapl;
		forml["reward"] = rewardl;

		formsl.push_back(cocos2d::Value(forml));
	}
	modell["forms"] = formsl;
	ValueVector switchsl;
	for(int i = 2;i < 9; i++)
	{
		for(int j = 4; j < 11;j ++)
		{
			ValueMap smodel;
			smodel["typeId"] = 2005006;
			smodel["site"] = pointToString(Vec2(i,j));
			smodel["towerId"] = 6;
			smodel["floorId"] = 4;
			switchsl.push_back(cocos2d::Value(smodel));
		}
	}
	modell["switchs"] = switchsl;

	FileUtils::getInstance()->writeToFile(modell,"altar.plist");*/




	_model = FileUtils::getInstance()->getValueMapFromFile("altar.plist");
	forms = _model["forms"].asValueVector();

	int fromNum = 0;
	for(auto pair:forms)
	{
		std::vector<std::vector<int>> formTemp;

		auto form = pair.asValueMap();
		for(auto i:form["map"].asValueVector())
		{
			std::vector<int> rowTemp;
			for(auto j:i.asValueVector())
			{
				rowTemp.push_back(j.asInt());
			}
			formTemp.push_back(rowTemp);
		}
		maps.insert(std::make_pair(fromNum, formTemp));
		fromNum++;
	}

	

	ValueVector switchsm = _model["switchs"].asValueVector();
	for(auto pair:switchsm)
	{
		auto switchModel = pair.asValueMap();
		auto cell = CellFactory::getInstance()->createCell(switchModel);
		Detect::shareDetect()->addCell(cell,PointFromString(switchModel["site"].asString()),1,switchModel["floorId"].asInt(),switchModel["towerId"].asInt());
		_switchs.push_back(cell->getName());
	}

	//_listener = EventListenerCustom::create(getName(), CC_CALLBACK_1(World::onTrigger, this));
	_listener = EventListenerCustom::create("altar1", [=](EventCustom *event){onTrigger(event);});
	CC_SAFE_RETAIN(_listener);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this);
}
Exemplo n.º 7
0
bool HudPanel::onTrigger(EventCustom *event)
{
	auto data = static_cast<ValueMap*>(event->getUserData());
	auto effect = (*data)["effect"].asValueMap();
	auto senderName = (*data)["senderName"].asString();
	auto type = (*data)["type"].asString();

	if(type == "curtain")
	{
		auto action = effect["action"].asString();
		auto delay = effect["delay"].asFloat();
		if(action == "fadeIn")
		{
			_layerColor->runAction(FadeIn::create(delay));
		}
		else if(action == "fadeOut")
		{
			_layerColor->runAction(FadeOut::create(delay));
		}
	}
	else if(type == "plotBlock")
	{
		auto action = effect["action"].asString();
		if(action == "in")
		{
			_plotBlock = true;
		}
		else if(action == "out")
		{
			_plotBlock = false;
		}
	}
	auto player = Detect::shareDetect()->getPlayer();
	if(player != nullptr && senderName == player->getName())
	{
		if(type == "setHp")
		{
			auto hp = effect["num"].asInt();
			/*auto maxHp = effect["maxHp"].asInt();
			auto loadingBar = static_cast<LoadingBar*>(Helper::seekWidgetByName(_root, "ProgressBar_hp"));
			loadingBar->setPercent(hp * 1.00 / maxHp * 100);*/
			auto text = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_hp"));
			text->setString(StringUtils::format("%d",hp));
		}
		else if(type == "setXp")
		{
			auto xp = effect["num"].asInt();
			auto lastXp = effect["lastXp"].asInt();
			auto nextXp = effect["nextXp"].asInt();
			auto loadingBar = static_cast<LoadingBar*>(Helper::seekWidgetByName(_root, "ProgressBar_xp"));
			auto cur = xp - lastXp;
			auto max = nextXp - lastXp;
			//loadingBar->setPercent(cur * 1.00 / max * 100);
			auto text = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_xp"));
			text->setString(StringUtils::format("%d/%d",xp,nextXp));
		}
		else if(type == "setStr")
		{
			auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_str_num"));
			widget->setString(effect["num"].asString());
		}
		else if(type == "setDef")
		{
			auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_def_num"));
			widget->setString(effect["num"].asString());
		}
		else if(type == "setLevel")
		{
			auto widget = static_cast<TextAtlas*>(Helper::seekWidgetByName(_root, "Label_level_num"));
			widget->setString(effect["num"].asString());
		}
		else if(type == "setGold")
		{
			auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_gold_num"));
			widget->setString(effect["num"].asString());
		}

		else if(type == "addHp")
		{
			std::string str = "{0,0}";
			if(!effect["site"].isNull()) str = effect["site"].asString();
			Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(str));
			std::string add = (effect["num"].asInt()>0?"+":"") + effect["num"].asString();
			_bubbleLabel->addLabel(GETSTRING("hp") + add,site);

			if(effect["num"].asInt() > 0)
			{
				auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_hp"));
				widget->setScale(1.0f);
				//widget->runAction(_stress1->clone());
			}
		}
		else if(type == "addXp")
		{
			std::string str = "{0,0}";
			if(!effect["site"].isNull()) str = effect["site"].asString();
			Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(str));
			std::string add = (effect["num"].asInt()>0?"+":"") + effect["num"].asString();
			_bubbleLabel->addLabel(GETSTRING("xp") + add,site);

			if(effect["num"].asInt() > 0)
			{
				auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_xp"));
				widget->setScale(1.0f);
				//widget->runAction(_stress1->clone());
			}
		}
		else if(type == "addStr")
		{
			std::string str = "{0,0}";
			if(!effect["site"].isNull()) str = effect["site"].asString();
			Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(str));
			std::string add = (effect["num"].asInt()>0?"+":"") + effect["num"].asString();
			_bubbleLabel->addLabel(GETSTRING("str") + add,site);

			if(effect["num"].asInt() > 0)
			{
				auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_str_num"));
				widget->setScale(1.0f);
				//widget->runAction(_stress1->clone());
			}
		}
		else if(type == "addDef")
		{
			std::string def = "{0,0}";
			if(!effect["site"].isNull()) def = effect["site"].asString();
			Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(def));
			std::string add = (effect["num"].asInt()>0?"+":"") + effect["num"].asString();
			_bubbleLabel->addLabel(GETSTRING("def") + add,site);

			if(effect["num"].asInt() > 0)
			{
				auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_def_num"));
				widget->setScale(1.0f);
				//widget->runAction(_stress1->clone());
			}
		}
		else if(type == "addLevel")
		{
			std::string level = "{0,0}";
			if(!effect["site"].isNull()) level = effect["site"].asString();
			Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(level));
			std::string add = (effect["num"].asInt()>0?"+":"") + effect["num"].asString();
			_bubbleLabel->addLabel(GETSTRING("level") + add,site);

			if(effect["num"].asInt() > 0)
			{
				auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_level_num"));
				widget->setScale(1.0f);
				//widget->runAction(_stress1->clone());
			}
		}
		else if(type == "addGold")
		{
			std::string gold = "{0,0}";
			if(!effect["site"].isNull()) gold = effect["site"].asString();
			Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(gold));
			std::string add = (effect["num"].asInt()>0?"+":"") + effect["num"].asString();
			_bubbleLabel->addLabel(GETSTRING("gold") + add,site);

			if(effect["num"].asInt() > 0)
			{
				auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_gold_num"));
				widget->setScale(1.0f);
				//widget->runAction(_stress1->clone());
			}
		}
		else if(type == "otherNote")
		{
			std::string str = "{0,0}";
			if(!effect["site"].isNull()) str = effect["site"].asString();
			Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(str));
			std::string text = effect["text"].asString();
			_bubbleLabel->addLabel(text,site);
		}
		else if(type == "addProp")
		{
			auto propType = effect["propType"].asInt();
			auto addPropNum = effect["addPropNum"].asInt();
			auto propNum = effect["propNum"].asInt();

			if(addPropNum != 0)
			{
				switch (propType)
				{
				case 2002002:case 2002001:case 2002003:
					std::string str = "{0,0}";
					if(!effect["site"].isNull()) str = effect["site"].asString();
					Vec2 site = Detect::shareDetect()->getWorld()->convertToWorldSpace(PointFromString(str));
					std::string add = GETSTRING("get")+ effect["propName"].asString() + (effect["addPropNum"].asInt()>0?"+":"") + effect["addPropNum"].asString();
					_bubbleLabel->addLabel(add,site);
					break;
				}
			}


			switch (propType)
			{
			case 2002002:
				{
					auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_key_1_num"));
					widget->setString(effect["propNum"].asString());
					widget->setScaleX(1.0f);
					widget->setScaleY(1.0f);
					//widget->runAction(_stress1->clone());

				}
				break;
			case 2002001:
				{
					auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_key_2_num"));
					widget->setString(effect["propNum"].asString());
					widget->setScaleX(1.0f);
					widget->setScaleY(1.0f);
					//widget->runAction(_stress1->clone());
				}
				break;
			case 2002003:
				{
					auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_key_3_num"));
					widget->setString(effect["propNum"].asString());
					widget->setScaleX(1.0f);
					widget->setScaleY(1.0f);
					//widget->runAction(_stress1->clone());
				}
				break;
			default:
				break;
			}
		}
		else if(type == "removeProp")
		{
			auto propType = effect["propType"].asInt();
			auto addPropNum = effect["addPropNum"].asInt();
			auto propNum = effect["propNum"].asInt();

			switch (propType)
			{
			case 2002002:
				{
					auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_key_1_num"));
					widget->setString(effect["propNum"].asString());
				}
				break;
			case 2002001:
				{
					auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_key_2_num"));
					widget->setString(effect["propNum"].asString());
				}
				break;
			case 2002003:
				{
					auto widget = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_key_3_num"));
					widget->setString(effect["propNum"].asString());
				}
				break;
			default:
				break;
			}
		}

	}

	if(type == "setCurFloor")
	{
		auto widget1 = static_cast<TextAtlas*>(Helper::seekWidgetByName(_root, "Label_floor_num"));
		widget1->setString(effect["floorId"].asString());
		auto widget2 = static_cast<Text*>(Helper::seekWidgetByName(_root, "Label_tower_name"));
		widget2->setString(effect["towerName"].asString());
	}
	return false;
}