{
"content": {
"costKerosene": {
"10000": 125
},
"heroVO": {
"isMain": false,
"name": "神太史慈",
"id": 137438953770,
"power": 4501,
"agile": 4911,
"intelligence": 4259,
"life": 73272,
"speed": 8704,
"nearAttack": 12452,
"nearDefense": 7139,
"strategyAttack": 12136,
"strategyDefense": 7075
},
"smallLightId": 308,
"bigIsLight": false
},
SevenHeroManager::sendHandler(SocketData *socketData)//服务器发回来的数据
Json::Value value;
Json::Reader reader;
string json = socketData->body;//获取数据包里字符串
if(!reader.parse(json, value))//字符串转为JSON格式存于VALUE
{
return;
}
Json::Value content = value["content"];//得到content的属性
void parseLight(Json::Value);
this->parseLight(content);//传入相关属性
/*解析点亮元神 9*/
void SevenHeroManager::parseLight(Json::Value content)
{
//************* 实时更新附加属性wenyu
Json::Value &js = content["heroVO"];//content属性中的herovo字段属性值
const string id = ::parseJsonString(js["id"].toStyledString());//下一级字段中ID属性值
HeroData* hero = NULL;
for( int i = 0; i < GlobalData::sharedGlobalData()->m_me->m_heroList->count(); i++ ){//找到对应的ID英雄
if(id == ((HeroData*)GlobalData::sharedGlobalData()->m_me->m_heroList->objectAtIndex(i))->getServerId()){
hero = (HeroData*)GlobalData::sharedGlobalData()->m_me->m_heroList->objectAtIndex(i);//指向英雄
break;
}
}
if( hero == NULL ){
return;
}
hero->setHeroInfo(js);//更新英雄属性
{
"content": {
"heroVOList": [
{
"isMain": true,
"name": "婷雪",
"id": 137438953576,
"level": 140,
"position": "MIDDLE",
"power": 51913,
"agile": 33933,
"intelligence": 48726,
"life": 142124,
"speed": 48479,
"quality": 7,
"exp": 733708063,
"nearAttack": 52894,
"nearDefense": 46260,
"strategyAttack": 51743,
"strategyDefense": 37162
},
{
"isMain": false,
"name": "神赵云",
"id": 137438953711,
"level": 140,
"position": "BEFORE",
"power": 79021,
"agile": 42727,
"intelligence": 71716,
"life": 319253,
"speed": 55009,
"quality": 6,
"exp": 646114934,
"nearAttack": 101010,
"nearDefense": 67365,
"strategyAttack": 85113,
"strategyDefense": 61464
}
],
"servenHeroPosition": {
"playerId": 137438953504,
"imageMap": {
"137438953576": -1
},
"postionInfo": {
"137438953709": 5,
"137438953708": 4,
"137438953711": 1,
"137438953952": 6
}
}
},
"code": 0
}
void SevenHeroManager::parseHeroChange(Json::Value value)
{
//*************实现星图互换后附加属性即时更新
HeroData* hero = NULL;
Json::Value &jsa = value["heroVOList"];
for(Json::Value::iterator iter = jsa.begin(); iter != jsa.end(); iter++){//遍历整个JSON herovolist
Json::Value &js = * iter;
const string id = ::parseJsonString(js["id"].toStyledString());
for( int i = 0; i < GlobalData::sharedGlobalData()->m_me->m_heroList->count(); i++ ){
if(id == ((HeroData*)GlobalData::sharedGlobalData()->m_me->m_heroList->objectAtIndex(i))->getServerId()){
hero = (HeroData*)GlobalData::sharedGlobalData()->m_me->m_heroList->objectAtIndex(i);
break;
}
}
if( hero == NULL ){
return;
}
hero->setHeroInfo(js); //更新客户端英雄属性
}
//********************