Exemple #1
0
//非玩家装备信息
int ProcessGetSysEquipInfo(net::session_ptr& psession, json_spirit::mObject& o, json_spirit::Object& robj)
{
   CharData* cdata = NULL;
    int ret = getSessionChar(psession, cdata);
    if (ret != HC_SUCCESS || NULL == cdata)
    {
        return ret;
    }
    int id = 1;
    READ_INT_FROM_MOBJ(id, o, "id");
    boost::shared_ptr<baseEquipment> beq = GeneralDataMgr::getInstance()->GetBaseEquipment(id);
    if (beq.get())
    {
        json_spirit::Object eq;
        eq.push_back( Pair("id", id) );
        eq.push_back( Pair("name", beq->name) );
        eq.push_back( Pair("spic", id) );
        eq.push_back( Pair("type", beq->type) );
        eq.push_back( Pair("level", 0) );

        eq.push_back( Pair("addNums", beq->baseValue) );

        if (beq->baseValue2 > 0)
        {
            eq.push_back( Pair("addNums", beq->baseValue2) );
        }
        eq.push_back( Pair("quality", beq->quality) );
        eq.push_back( Pair("price", beq->basePrice) );
        eq.push_back( Pair("memo", beq->desc) );
        eq.push_back( Pair("needLevel", beq->needLevel) );

        robj.push_back( Pair("equipVO", eq) );
        return HC_SUCCESS;
    }
    else
    {
        return HC_ERROR;
    }
}
Exemple #2
0
int Boss::getBossLogEvent(json_spirit::Object& robj)
{
    json_spirit::Array list;
    std::list<boost::shared_ptr<boss_log> >::iterator it = m_event_log.begin();
    while (it != m_event_log.end())
    {
        if ((*it).get())
        {
            json_spirit::Object o;
            std::string msg = strBossLog;
            str_replace(msg, "$A", MakeCharNameLink_other((*it)->m_name));
            str_replace(msg, "$B", _boss._name);
            str_replace(msg, "$D", LEX_CAST_STR((*it)->m_damage));
            str_replace(msg, "$S", LEX_CAST_STR((*it)->m_silver));
            o.push_back( Pair("msg", msg) );
            list.push_back(o);
        }
        ++it;
    }
    robj.push_back( Pair("list", list) );
    return HC_SUCCESS;
}
Exemple #3
0
int bossMgr::getBossHp(int id, json_spirit::Object& robj)
{
    robj.push_back( Pair("id", id) );
    boost::shared_ptr<Boss> spb = getBoss(id);
    if (spb.get())
    {
        if (spb->_boss._cur_hp <= spb->_boss._hide_hp)
        {
            robj.push_back( Pair("special", true) );
            robj.push_back( Pair("hide_hp", spb->_boss._hide_hp) );
            robj.push_back( Pair("hp", spb->_boss._cur_hp) );
        }
        else
        {
            robj.push_back( Pair("special", false) );
            robj.push_back( Pair("hide_hp", 0) );
            robj.push_back( Pair("hp", spb->_boss._cur_hp) );
        }
    }
    return HC_SUCCESS;
}
Exemple #4
0
int farmMgr::WaterFarmField(int cid, json_spirit::Object& robj)
{
    boost::shared_ptr<CharData> cdata = GeneralDataMgr::getInstance()->GetCharData(cid);
    if (!cdata.get())
        return HC_ERROR;
    int now_water = cdata->queryExtraData(char_data_type_daily, char_data_farm_water);
    if (now_water > iFarmWater)
    {
        return HC_ERROR;
    }
    int cd = cdata->queryExtraData(char_data_type_daily, char_data_farm_water_cd);
    if (cd > time(NULL))
    {
        return HC_ERROR;
    }
    int add_reward = cdata->m_level / 5;
    if (cdata->m_level % 5 > 0)
        ++add_reward;
    //军粮数值放大10倍
    if (add_reward > 0)
        add_reward *= 10;
    cdata->addTreasure(treasure_type_supply, add_reward);
    add_statistics_of_treasure_cost(cdata->m_id,cdata->m_ip_address,treasure_type_supply,add_reward,treasure_farm_water,1,cdata->m_union_id,cdata->m_server_id);
    cdata->setExtraData(char_data_type_daily, char_data_farm_water, ++now_water);
    cdata->setExtraData(char_data_type_daily, char_data_farm_water_cd, time(NULL)+1800);
    boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(treasure_type_supply);
    if (tr.get())
    {
        robj.push_back( Pair("msg", tr->name + strCounts + LEX_CAST_STR(add_reward)));
    }
    cdata->NotifyCharData();
    //act统计
    act_to_tencent(cdata.get(),act_new_water);

    //支线任务
    cdata->m_trunk_tasks.updateTask(task_farm_water, 1);
    return HC_SUCCESS;
}
bool json_decode(const json_spirit::Object& obj, sample_data_req1& sd)
{
    sd = sample_data_req1(); // empty it.
    try
    {
        for (size_t i = 0; i != obj.size(); ++i)
        {
            const json_spirit::Pair& item = obj[i];
            if (item.name_ == "email")
                sd.email = item.value_.get_str();
            else if (item.name_ == "phone")
                sd.phone = item.value_.get_str();
            else if (item.name_ == "delay")
                sd.delay = item.value_.get_uint64();
        }
    }
    catch (std::exception& e)
    {
        BOOST_LOG_TRIVIAL(error) << "json_decode(json_spirit::Object, sample_data_req1) exception " << e.what() << std::endl;
        return false;
    }
    return true;
}
Exemple #6
0
int farmMgr::rewardNourish(int cid, json_spirit::Object& robj)
{
    int reward = getNourishReward(cid);
    boost::shared_ptr<CharData> cdata = GeneralDataMgr::getInstance()->GetCharData(cid);
    if (cdata.get())
    {
        cdata->addTreasure(treasure_type_supply, reward);
        cdata->NotifyCharData();
        add_statistics_of_treasure_cost(cdata->m_id,cdata->m_ip_address,treasure_type_supply,reward,treasure_farm,1,cdata->m_union_id,cdata->m_server_id);
        clearNourishReward(cid);
        boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(treasure_type_supply);
        if (tr.get())
        {
            robj.push_back( Pair("msg", tr->name + strCounts + LEX_CAST_STR(reward)));
        }
        //act统计
        act_to_tencent(cdata.get(),act_new_nourish);

        //支线任务
        cdata->m_trunk_tasks.updateTask(task_farm_yechan, 1);
        return HC_SUCCESS;
    }
    return HC_ERROR;
}
Exemple #7
0
//军团探索完成
int ProcessCorpsExploreDone(net::session_ptr& psession, json_spirit::mObject& o, json_spirit::Object& robj)
{
    CharData* pc = NULL;
    int ret = getSessionChar(psession, pc);
    if (ret != HC_SUCCESS || NULL == pc)
    {
        return ret;
    }
    if (pc->m_corps_member.get() == NULL)
    {
        return HC_ERROR_NOT_JOIN_JT;
    }
    int nums = pc->queryExtraData(char_data_type_daily, char_data_daily_corps_explore);
    int corps_explore_times = 0;
    splsCorps* cp = corpsMgr::getInstance()->findCorps(pc->m_corps_member.get()->corps);
    if (cp)
    {
        corps_explore_times = iCorpsExploreTimesOneday[cp->_level];
    }
    int left = corps_explore_times - nums;
    if (left <= 0)
    {
        return HC_ERROR_CORPS_EXPLORE_NO_TIMES;
    }

    charCorpsExplore* c = Singleton<corpsExplore>::Instance().getChar(pc->m_id).get();
    if (c == NULL)
    {
        return HC_ERROR;
    }

    int pos = 1;
    READ_INT_FROM_MOBJ(pos,o,"pos");

    if (pos < 1 || pos > 3)
    {
        return HC_ERROR;
    }

    if (c->que[pos-1].state == 0)
    {
        return HC_ERROR;
    }

    if (!c->que[pos-1].isDone())
    {
        return HC_ERROR;
    }

    c->que[pos-1].state = 0;
    //军粮,军团经验
    int supply = pc->m_level * pc->m_level * c->que[pos-1].fac / 80;
    if (supply <= 0)
    {
        supply = 1;
    }

    int exp = 30 * c->que[pos-1].fac;
    if (c->special == c->que[pos-1].type)
    {
        supply *= 2;
        exp *= 2;
    }

#ifdef SF_SERVER
            if (supply > 0)
                supply *= 20;
#else
            //军粮数值放大10倍
            if (supply > 0)
                supply *= 10;
#endif


    //军团实际收益
    corpsRealReward(supply);
    corpsRealReward(exp);

    robj.push_back( Pair("supply", supply) );
    robj.push_back( Pair("exp", exp) );

    pc->addTreasure(treasure_type_supply, supply);
    add_statistics_of_treasure_cost(pc->m_id,pc->m_ip_address,treasure_type_supply,supply,treasure_corps_explore,1,pc->m_union_id,pc->m_server_id);

    pc->NotifyCharData();

    corpsMgr::getInstance()->addEvent(pc, corps_event_explore, c->que[pos-1].type + c->que[pos-1].quality * 10, exp);

    c->refresh(pos);

    ++nums;
    pc->setExtraData(char_data_type_daily, char_data_daily_corps_explore, nums);
    //act统计
    act_to_tencent(pc,act_new_corps_explore);

    if (nums == 10)
    {
        //第十次
        splsCorps* corps = corpsMgr::getInstance()->findCorps(pc->m_corps_member->corps);
        if (corps && corps->_level >= 2)
        {
            # if 0
            int err_code = 0;
            pc->m_bag.addGem(treasure_type_corps_lottery, 1, err_code, true);
            robj.push_back( Pair("getGem", 1) );
            #endif
            //奖励暂存
            std::list<Item> tmp_list;
            {
                Item item_p;
                item_p.type = item_type_treasure;
                item_p.id = treasure_type_corps_lottery;
                item_p.nums = 1;
                //军团实际收益
                corpsRealReward(item_p.nums);
                tmp_list.push_back(item_p);
            }
            Singleton<char_rewards_mgr>::Instance().updateCharRewards(pc->m_id,rewards_type_explore,0,tmp_list);
        }
    }
    //日常任务
    dailyTaskMgr::getInstance()->updateDailyTask(*pc,daily_task_corp_explore);

    //支线任务
    pc->m_trunk_tasks.updateTask(task_corps_explore, 1);

    //军团活动按钮
    json_spirit::Object action;
    action.push_back( Pair("cmd", "updateAction") );
    action.push_back( Pair("type", top_level_event_corp) );
    int state = 0;
    if (pc->m_corps_member->ymsj_can_get)
    {
        state = 1;
    }
    if (c->isDone() && corps_explore_times > nums)
    {
        state = 1;
    }
    action.push_back( Pair("active", state) );
    action.push_back( Pair("s", 200) );
    pc->sendObj(action);
    return HC_SUCCESS;
}
Exemple #8
0
//军团探索列表
int ProcessCorpsExplreList(net::session_ptr& psession, json_spirit::mObject& o, json_spirit::Object& robj)
{
    CharData* pc = NULL;
    int ret = getSessionChar(psession, pc);
    if (ret != HC_SUCCESS || NULL == pc)
    {
        return ret;
    }
    if (pc->m_corps_member.get() == NULL)
    {
        return HC_ERROR_NOT_JOIN_JT;
    }
    charCorpsExplore* c = Singleton<corpsExplore>::Instance().getChar(pc->m_id).get();
    if (c == NULL)
    {
        return HC_ERROR;
    }

    robj.push_back( Pair("refresh", c->refresh_time - time(NULL)) );
    robj.push_back( Pair("gold", iCorpsExploreRefreshGold) );
    robj.push_back( Pair("explore_ling", pc->m_bag.getGemCount(treasure_type_explore_ling)) );

    int nums = pc->queryExtraData(char_data_type_daily, char_data_daily_corps_explore);
    int corps_explore_times = 0;
    splsCorps* cp = corpsMgr::getInstance()->findCorps(pc->m_corps_member.get()->corps);
    if (cp)
    {
        corps_explore_times = iCorpsExploreTimesOneday[cp->_level];
    }
    int left = corps_explore_times - nums;
    if (left < 0)
    {
        left = 0;
    }
    robj.push_back( Pair("left", left) );
    json_spirit::Object special;
    special.push_back( Pair("type", c->special) );
    special.push_back( Pair("name", c->special_name) );
    robj.push_back( Pair("special", special) );

    json_spirit::Array list;
    for (int i = 0; i < 3; ++i)
    {
        json_spirit::Object obj;
        obj.push_back( Pair("pos", i+1) );
        obj.push_back( Pair("type", c->que[i].type) );
        obj.push_back( Pair("quality", c->que[i].quality) );
        obj.push_back( Pair("name", c->que[i].name) );

        if (c->que[i].state == 1)
        {
            int left_secs = c->que[i].done_time - time(NULL);
            if (left_secs <= 0)
            {
                obj.push_back( Pair("state", 2) );
            }
            else
            {
                obj.push_back( Pair("state", 1) );
                obj.push_back( Pair("time", left_secs) );
                int gold = left_secs / 60;
                if (gold % 60 > 0)
                {
                    ++gold;
                }
                obj.push_back( Pair("gold", gold) );
            }
        }
        else
        {
            obj.push_back( Pair("state", c->que[i].state) );
            obj.push_back( Pair("time", c->que[i].need_secs) );
        }
        //军粮,军团经验
        int supply = pc->m_level * pc->m_level * c->que[i].fac / 80;
        if (supply == 0)
        {
            supply = 1;
        }
#ifdef SF_SERVER
        if (supply > 0)
            supply *= 20;
#else
        //军粮数值放大10倍
        if (supply > 0)
            supply *= 10;
#endif

        int exp = 30 * c->que[i].fac;

        //军团探索收益系数
        corpsRealReward(supply);
        corpsRealReward(exp);

        if (c->special == c->que[i].type)
        {
            obj.push_back( Pair("double", 1) );
        }
        obj.push_back( Pair("supply", supply) );
        obj.push_back( Pair("exp", exp) );

        list.push_back(obj);
    }

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

    return HC_SUCCESS;
}
Exemple #9
0
//军团探索刷新
int ProcessCorpsExploreRefresh(net::session_ptr& psession, json_spirit::mObject& o, json_spirit::Object& robj)
{
    CharData* pc = NULL;
    int ret = getSessionChar(psession, pc);
    if (ret != HC_SUCCESS || NULL == pc)
    {
        return ret;
    }
    if (pc->m_corps_member.get() == NULL)
    {
        return HC_ERROR_NOT_JOIN_JT;
    }
    charCorpsExplore* c = Singleton<corpsExplore>::Instance().getChar(pc->m_id).get();
    if (c == NULL)
    {
        return HC_ERROR;
    }

    bool canrefresh = false;
    for (int i = 0; i < 3; ++i)
    {
        if (c->que[i].state == 0)
        {
            canrefresh = true;
            break;
        }
    }
    if (!canrefresh)
    {
        return HC_SUCCESS;
    }

    //优先扣道具
    if (pc->addTreasure(treasure_type_explore_ling, -1) >= 0)
    {
        //通知道具消耗
        std::string msg = treasure_expend_msg(treasure_type_explore_ling, 1);
        if (msg != "")
        {
            robj.push_back( Pair("msg", msg) );
        }
        //统计道具消耗
        add_statistics_of_treasure_cost(pc->m_id,pc->m_ip_address,treasure_type_explore_ling,1,treasure_unknow,2,pc->m_union_id,pc->m_server_id);

    }
    else if (pc->addGold(-iCorpsExploreRefreshGold) < 0)
    {
        return HC_ERROR_NOT_ENOUGH_GOLD;
    }

    //金币消耗统计
    add_statistics_of_gold_cost(pc->m_id, pc->m_ip_address, iCorpsExploreRefreshGold, gold_cost_for_corps_explore_refresh, pc->m_union_id, pc->m_server_id);
#ifdef QQ_PLAT
    gold_cost_tencent(pc,iCorpsExploreRefreshGold,gold_cost_for_corps_explore_refresh);
#endif

    c->refresh(0);

    pc->NotifyCharData();

    return HC_SUCCESS;
}
Exemple #10
0
int ProcessGetBankFeedback(net::session_ptr& psession, json_spirit::mObject& o, json_spirit::Object& robj)
{
    CharData* cdata = NULL;
    int ret = getSessionChar(psession, cdata);
    if (ret != HC_SUCCESS || NULL == cdata)
    {
        return ret;
    }
    if (!cdata->isBankOpen())
    {
        return HC_ERROR;
    }
    int case_id = 1, sid = 0;
    READ_INT_FROM_MOBJ(case_id, o, "case_id");
    READ_INT_FROM_MOBJ(sid, o, "sid");
    if (sid < 1 || sid > iBankSubCaseCount)
    {
        return HC_ERROR;
    }
    json_spirit::Array list;
    boost::shared_ptr<char_bank_list> p_cb = bankMgr::getInstance()->GetCharBankList(cdata->m_id);
    if (p_cb.get())
    {
        if (bankUnGet(*p_cb) == false)
        {
            return HC_ERROR;
        }
        for (int i = 0; i < (int)(*p_cb).size(); ++i)
        {
            //项目已经投资
            if ((*p_cb)[i].get() && (*p_cb)[i]->m_case_id == case_id && (*p_cb)[i]->m_state == 2)
            {
                if((*p_cb)[i]->m_base.get())
                {
                    char_bank_case* pb = (*p_cb)[i].get();
                    {
                        if (pb->m_feedback_state[sid-1] == 1)
                        {
                            int gold = pb->m_base->_case_map[sid-1]._feedback_gold;
                            cdata->addGold(gold, gold_get_bank, true);
                            (*p_cb)[i]->m_get_gold += gold;
                            (*p_cb)[i]->m_feedback_state[sid-1] = 2;
                            (*p_cb)[i]->save();
                            int state = bankCanGet(*p_cb);
                            if (0 == state)
                            {
                                cdata->updateTopButton(top_button_bank, 0);
                            }
                            else if (2 == state)
                            {
                                cdata->updateTopButton(top_button_bank, 0);
                            }
                            robj.push_back( Pair("gold", gold) );
                            return HC_SUCCESS;
                        }
                        else
                        {
                            return HC_ERROR;
                        }
                    }
                }
            }
        }
    }
    return HC_ERROR;
}
Exemple #11
0
int ProcessGetCaseInfo(net::session_ptr& psession, json_spirit::mObject& o, json_spirit::Object& robj)
{
    CharData* cdata = NULL;
    int ret = getSessionChar(psession, cdata);
    if (ret != HC_SUCCESS || NULL == cdata)
    {
        return ret;
    }
    if (!cdata->isBankOpen())
    {
        return HC_ERROR;
    }
    int case_id = 1;
    READ_INT_FROM_MOBJ(case_id, o, "case_id");
    json_spirit::Array list;
    boost::shared_ptr<char_bank_list> p_cb = bankMgr::getInstance()->GetCharBankList(cdata->m_id);
    if (p_cb.get())
    {
        for (int i = 0; i < (int)(*p_cb).size(); ++i)
        {
            if ((*p_cb)[i].get() && (*p_cb)[i]->m_case_id == case_id)
            {
                if((*p_cb)[i]->m_base.get())
                {
                    time_t stime = 0;
                    if ((*p_cb)[i]->m_state == 2)
                    {
                        stime = time(NULL);
                    }
                    bool btmp = false;
                    for (size_t s = 0; s < iBankSubCaseCount; ++s)
                    {
                        json_spirit::Object o;
                        o.push_back( Pair("sid", s+1) );
                        o.push_back( Pair("secs", (*p_cb)[i]->m_base->_case_map[s]._need_mins*60) );
                        o.push_back( Pair("gold", (*p_cb)[i]->m_base->_case_map[s]._feedback_gold) );
                        o.push_back( Pair("state", (*p_cb)[i]->m_feedback_state[s]) );
                        if ((*p_cb)[i]->m_feedback_state[s] == 0 && btmp == false)
                        {
                            int left = (*p_cb)[i]->m_sub_can_get_time[s] - stime;
                            if (left > 0)
                            {
                                o.push_back( Pair("left", left) );
                                btmp = true;
                            }
                        }
                        list.push_back(o);
                    }
                }
                robj.push_back( Pair("caseInfo", list) );
                robj.push_back( Pair("state", (*p_cb)[i]->m_state) );
                break;
            }
            else
            {
                INFO("case_id=" << (*p_cb)[i]->m_case_id << endl);
            }
        }
    }
    return HC_SUCCESS;
}
Exemple #12
0
//获取排行信息
int weekRankings::getRankingsInfo(CharData* pc, json_spirit::Object &robj)
{
    //排行活动信息
    json_spirit::Object event_obj;
    boost::shared_ptr<weekRankings_event> wre = getWeekRankingsEvent(m_event_type);
    if (wre.get())
    {
        event_obj.push_back( Pair("type", m_event_type) );
        event_obj.push_back( Pair("name", wre->name) );
        event_obj.push_back( Pair("memo", wre->memo) );
        json_spirit::Array reward_list;
        for (int rank = 1; rank <= 5; ++rank)
        {
            boost::shared_ptr<weekRankings_event_award> p_award = wre->rankings_list[rank];
            if (p_award.get())
            {
                json_spirit::Object o;
                o.push_back( Pair("rank", rank) );
                json_spirit::Array getlist;
                itemlistToArray(p_award->awards, getlist);
                o.push_back( Pair("get", getlist) );
                reward_list.push_back(o);
            }
        }
        event_obj.push_back( Pair("rank_get", reward_list) );
        robj.push_back( Pair("event_info", event_obj) );
    }
    //排行信息
    json_spirit::Array rank_list;
    int rank = 0;
    for (std::list<char_weekRankings>::iterator it = m_now_Rankings.begin(); it != m_now_Rankings.end(); ++it)
    {
        ++rank;
        if (rank <= iRewardMinRank)
        {
            json_spirit::Object o;
            o.push_back( Pair("rank", rank) );
            o.push_back( Pair("cid", it->cid) );
            boost::shared_ptr<CharData> cdata = GeneralDataMgr::getInstance()->GetCharData(it->cid);
            if (cdata.get())
            {
                o.push_back( Pair("name", cdata->m_name) );
                o.push_back( Pair("level", cdata->m_level) );
                if (cdata->GetGuildId())
                {
                    o.push_back( Pair("guildname", Singleton<guildMgr>::Instance().getGuildName(cdata->GetGuildId())));
                }
            }
            o.push_back( Pair("score", it->score) );
            o.push_back( Pair("refresh_time", it->refresh_time) );
            rank_list.push_back(o);
        }
    }
    robj.push_back( Pair("rank_list", rank_list) );
    //自身信息
    {
        json_spirit::Object o;
        o.push_back( Pair("cid", pc->m_id) );
        if (pc->GetGuildId())
        {
            o.push_back( Pair("guildname", Singleton<guildMgr>::Instance().getGuildName(pc->GetGuildId())));
        }
        o.push_back( Pair("score", m_score_maps[pc->m_id].score) );
        o.push_back( Pair("refresh_time", m_score_maps[pc->m_id].refresh_time) );
        robj.push_back( Pair("self_obj", o) );
    }
    return HC_SUCCESS;
}
void Printer::fillJSONObject(json_spirit::Object &obj) {
    using namespace json_spirit;
    obj.push_back(Pair("active",active));
    obj.push_back(Pair("paused",paused));
    obj.push_back(Pair("printerName",name));
    obj.push_back(Pair("slug",slugName));
    obj.push_back(Pair("device",device));
    obj.push_back(Pair("baudrate",baudrate));
    obj.push_back(Pair("xmin",xmin));
    obj.push_back(Pair("xmax",xmax));
    obj.push_back(Pair("ymin",ymin));
    obj.push_back(Pair("ymax",ymax));
    obj.push_back(Pair("zmin",zmin));
    obj.push_back(Pair("zmax",zmax));
    obj.push_back(Pair("speedx",speedx));
    obj.push_back(Pair("speedy",speedy));
    obj.push_back(Pair("speedz",speedz));
    obj.push_back(Pair("speedeExtrude",speedeExtrude));
    obj.push_back(Pair("speedeRetract",speedeRetract));
    obj.push_back(Pair("extruderCount",extruderCount));
    Array ea;
    for(int i=0;i<extruderCount;i++) {
        Object e;
        e.push_back(Pair("extruderid",i));
        e.push_back(Pair("extrudernum",i+1));
        ea.push_back(e);
    }
    obj.push_back(Pair("extruder",ea));
}
Exemple #14
0
 void create_json(json_spirit::Object &o) const
 {
     using namespace json_spirit;
     o.push_back( Pair("name", m_name) );
     o.push_back( Pair("count", m_trackCount) );        
 }
Exemple #15
0
void EquipmentData::toObj(json_spirit::Object& eq)
{
    eq.push_back( Pair("id", id) );
    eq.push_back( Pair("name", name()) );
    eq.push_back( Pair("spic", baseid) );
    eq.push_back( Pair("type", type) );
    eq.push_back( Pair("level", qLevel) );
    eq.push_back( Pair("maxLevel", quality*20) );

    int cur = getvalue();
    int add2 = 0;
    int add = equipmentUpgrade::getInstance()->getUpgradeValue(up_quality, type, qLevel + 1, add2);
    eq.push_back( Pair("addNums", cur) );
    eq.push_back( Pair("nextNums", cur + add) );

    if (add2 > 0)
    {
        int cur2 = getvalue2();
        eq.push_back( Pair("addNums2", cur2) );
        eq.push_back( Pair("nextNums2", cur2 + add2) );
    }

    eq.push_back( Pair("quality", quality) );
    eq.push_back( Pair("up_quality", up_quality) );
    eq.push_back( Pair("price", sellPrice()) );
    eq.push_back( Pair("memo", memo()) );
    if (baseEq.get())
    {
        eq.push_back( Pair("needLevel", baseEq->needLevel) );
    }
}
Exemple #16
0
int farmMgr::WaterFarmFriendFieldAll(int cid, json_spirit::Object& robj)
{
    boost::shared_ptr<CharData> cdata = GeneralDataMgr::getInstance()->GetCharData(cid);
    if (!cdata.get())
        return HC_ERROR;
    int now_water = cdata->queryExtraData(char_data_type_daily, char_data_farm_friend_water);
    if (now_water >= iFarmFriendWater)
    {
        return HC_ERROR_FARM_WATER_TIMES;
    }
    int cnt = iFarmFriendWater - now_water;
    int tmp_cnt = 0;
    boost::shared_ptr<char_ralation> my_rl = Singleton<relationMgr>::Instance().getRelation(cdata->m_id);
    json_spirit::Array list;
    for (std::map<int, boost::shared_ptr<char_ralation> >::iterator it = my_rl->m_my_attentions.begin();
            it != my_rl->m_my_attentions.end();
                ++it)
    {
        if (cnt <= 0)
        {
            setWaterState(cid,it->second->m_char_id);
        }
        else if (!getWaterState(cid,it->second->m_char_id))
        {
            //json_spirit::Object o;
            //WaterFarmFriendField(cid,it->second->m_char_id,o);
            --cnt;
            ++tmp_cnt;
            setWaterState(cid,it->second->m_char_id);
            //cout << "water friend_id=" << it->second->m_char_id << endl;
        }
    }
    if (tmp_cnt == 0)
    {
        return HC_ERROR_NO_FARM_WATER_FRIEND;
    }
    int add_reward = cdata->m_level / 10;
    if (cdata->m_level % 10 > 0)
        ++add_reward;
    //军粮数值放大10倍
    if (add_reward > 0)
        add_reward *= 10;
    add_reward *= tmp_cnt;
    
    //屯田收益系数
    farmRealReward(add_reward);
    cdata->addTreasure(treasure_type_supply, add_reward);
    add_statistics_of_treasure_cost(cdata->m_id,cdata->m_ip_address,treasure_type_supply,add_reward,treasure_farm_water,1,cdata->m_union_id,cdata->m_server_id);
    cdata->NotifyCharData();
    
    //支线任务
    cdata->m_trunk_tasks.updateTask(task_farm_water, tmp_cnt);
    
    cdata->setExtraData(char_data_type_daily, char_data_farm_friend_water, now_water+tmp_cnt);
    //cout << "water_cnt=" << tmp_cnt;
    boost::shared_ptr<baseTreasure> tr = GeneralDataMgr::getInstance()->GetBaseTreasure(treasure_type_supply);
    if (tr.get())
    {
        robj.push_back( Pair("msg", tr->name + strCounts + LEX_CAST_STR(add_reward)));
    }
    return HC_SUCCESS;
}
Exemple #17
0
//升级装备
int CharData::upgradeEquipment(int eid, bool cost_gold, json_spirit::Object& robj)
{
    if (cost_gold && gold() < 50)
    {
        return HC_ERROR_NOT_ENOUGH_GOLD;
    }
    //cout<<"upgradeEquipment(), eid "<<eid<<endl;
    equipment_scroll* sp = NULL;
    EquipmentData* src_eq = m_bag.getEquipById(eid);
    if (!src_eq)
    {
        src_eq = m_generals.getEquipById(eid);
    }
    if (src_eq)
    {
        //cout<<"find scroll by src_id "<<src_eq->baseid<<endl;
        sp = Singleton<equipment_scroll_mgr>::Instance().getScrollBySrcId(src_eq->baseid);
        if (!sp)
        {
            //cout<<"not find"<<endl;
            return HC_ERROR;
        }
    }
    else
    {
        //cout<<"wrong eid"<<endl;
        return HC_ERROR;
    }
    Bag* pbag = src_eq->getContainer();
    //武将身上,判断等级是否够
    if (pbag != &m_bag && pbag && pbag->gd.get() && pbag->gd->m_level < sp->m_equipment->needLevel)
    {
        return HC_ERROR_NOT_ENOUGH_GENERAL_LEVEL;
    }
    if (m_bag.getGemCount(sp->m_gem_id) <= 0)
    {
        //cout<<"no scroll,gem id: "<<sp->m_gem_id<<endl;
        return HC_ERROR;
    }
    //扣材料
    bool success = trySubMaterial(sp, m_bag);
    if (!success)
    {
        //cout<<"trySubMaterial() return false"<<endl;
        return HC_ERROR;
    }
    //扣卷轴
    int err_code = 0;
    m_bag.addGem(sp->m_gem_id, -1, err_code);
    if (cost_gold)
    {
        if (addGold(-iUpgradeEquiptmentKeepLevelGold) < 0)
        {
            return HC_ERROR_NOT_ENOUGH_GOLD;
        }
        //金币消耗统计
        add_statistics_of_gold_cost(m_id, m_ip_address, iUpgradeEquiptmentKeepLevelGold, gold_cost_for_upgrade_equipment, m_union_id, m_server_id);
#ifdef QQ_PLAT
        gold_cost_tencent(this,iUpgradeEquiptmentKeepLevelGold,gold_cost_for_upgrade_equipment);
#endif
        NotifyCharData();
        //act统计
        act_to_tencent(this,act_new_equipt_make_special,src_eq->qLevel,src_eq->quality);
    }
    //升级装备
    src_eq->upgrade(cost_gold);

    if (src_eq->getContainer() != &m_bag)
    {
        m_weapon_attack_change = true;
        if (pbag->gd.get())
        {
            pbag->gd->updateEquipmentEffect();
        }
    }
    
    json_spirit::Object eq;
    src_eq->toObj(eq);
    robj.push_back( Pair("equipVO", eq) );

    updateEnhanceCost();
    updateEnhanceCDList();
    if (src_eq->baseEq.get())
    {
        std::string link_name = strEquipLink;
        str_replace(link_name, "$G", LEX_CAST_STR(src_eq->id));
        str_replace(link_name, "$C", LEX_CAST_STR(m_id));
        str_replace(link_name, "$N", src_eq->baseEq->name);

        addColor(link_name, src_eq->quality);
        //广播升级装备信息
        std::string notify_msg = strEquiptMakeInfo;
        str_replace(notify_msg, "$N", MakeCharNameLink(m_name));
        str_replace(notify_msg, "$G", link_name);
        GeneralDataMgr::getInstance()->broadCastSysMsg(notify_msg, -1);
    }
    
    //七日目标
    Singleton<seven_Goals_mgr>::Instance().updateGoals(*this,queryCreateDays(),goals_type_equipt,src_eq->baseid);
    
    m_trunk_tasks.updateTask(task_equipment_make, src_eq->baseid);

    
    //act统计
    act_to_tencent(this,act_new_equipt_make,src_eq->type);

    return HC_SUCCESS;
}
void PrinterState::fillJSONObject(json_spirit::Object &obj) {
    using namespace json_spirit;
    mutex::scoped_lock l(mutex);
    obj.push_back(Pair("activeExtruder",activeExtruder));
    obj.push_back(Pair("x",x));
    obj.push_back(Pair("y",y));
    obj.push_back(Pair("z",z));
    obj.push_back(Pair("fanOn",fanOn));
    obj.push_back(Pair("fanVoltage",fanVoltage));
    obj.push_back(Pair("powerOn",powerOn));
    obj.push_back(Pair("debugLevel",debugLevel));
    obj.push_back(Pair("hasXHome",hasXHome));
    obj.push_back(Pair("hasYHome",hasYHome));
    obj.push_back(Pair("hasZHome",hasZHome));
    obj.push_back(Pair("layer",layer));
    obj.push_back(Pair("sdcardMounted",sdcardMounted));
    obj.push_back(Pair("bedTempSet",bed.tempSet));
    obj.push_back(Pair("bedTempRead",bed.tempRead));
    obj.push_back(Pair("speedMultiply",speedMultiply));
    obj.push_back(Pair("flowMultiply",flowMultiply));
    obj.push_back(Pair("numExtruder",printer->extruderCount));
    obj.push_back(Pair("firmware",firmware));
    obj.push_back(Pair("firmwareURL",firmwareURL));
    Array ea;
    for(int i=0;i<printer->extruderCount;i++) {
        Object e;
        e.push_back(Pair("tempSet",extruder[i].tempSet));
        e.push_back(Pair("tempRead",extruder[i].tempRead));
        e.push_back(Pair("output",extruder[i].output));
        ea.push_back(e);
    }
    obj.push_back(Pair("extruder",ea));
}
Exemple #19
0
//打开物品
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;//未知类型
}
Exemple #20
0
//获取装备升级信息
int CharData::getUpgradeEquipmentInfo(int eid, int type, json_spirit::Object& robj)
{
    equipment_scroll* sp = NULL;

    EquipmentData* src_eq = m_bag.getEquipById(eid);
    if (!src_eq)
    {
        src_eq = m_generals.getEquipById(eid);
    }
    if (src_eq)
    {
        sp = Singleton<equipment_scroll_mgr>::Instance().getScrollBySrcId(src_eq->baseid);
        if (!sp)
        {
            return HC_ERROR;
        }
    }
    else
    {
        return HC_ERROR;
    }
    if (sp->m_equipment->needLevel > m_level)
    {
        robj.push_back( Pair("needLevel", sp->m_equipment->needLevel) );
        return HC_SUCCESS;
    }
    //直接制造结果
    json_spirit::Object eq = sp->m_eqobj;
    int nextqLevel = equipmentUpgrade::getInstance()->convertUpgradeLevel(src_eq->quality, src_eq->type, src_eq->qLevel);
    int nextAdd = 0;
    int nextAdd2 = 0;
    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) );
    eq.push_back( Pair("needLevel", sp->m_equipment->needLevel) );
    if (nextAdd2 > 0)
    {
        eq.push_back( Pair("addNums2", sp->m_equipment->baseValue2 + nextAdd2) );
    }
    //保留等级制造结果
    int nextqLevel_gold = src_eq->qLevel;
    nextAdd = 0;
    nextAdd2 = 0;
    upgradeValue(sp->m_equipment->up_quality, src_eq->type, nextqLevel_gold, nextAdd, nextAdd2);
    eq.push_back( Pair("level_gold", nextqLevel_gold) );
    eq.push_back( Pair("addNums_gold", sp->m_equipment->baseValue + nextAdd) );
    if (nextAdd2 > 0)
    {
        eq.push_back( Pair("addNums2_gold", sp->m_equipment->baseValue2 + nextAdd2) );
    }
    robj.push_back( Pair("eq", eq) );
    
    robj.push_back( Pair("eid", src_eq->id) );

    bool canMake = true;

    json_spirit::Array mlist;

    //type=1显示装备type=2显示卷轴
    if (type == 1)
    {
        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) );
        o.push_back( Pair("num", 1) );
        if (sp->m_equipment_src->m_place.get())
        {
            o.push_back( Pair("info", sp->m_equipment_src->m_place->info) );
        }
        mlist.push_back(o);
    }

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

    robj.push_back( Pair("mlist", mlist) );
    
    robj.push_back( Pair("canMake", canMake) );
    return HC_SUCCESS;
}
Exemple #21
0
 virtual void serialize(json_spirit::Object &json) {
     AE::serialize(json);
     json.push_back(json_spirit::Pair("PARAM_IDX", json_spirit::Value(m_paramIdx)));
 }
Exemple #22
0
//查询抽奖公告
int lottery_event::queryLotteryNotice(json_spirit::Object& robj)
{
    robj.push_back( Pair("list", m_notices_value.get_array()) );
    return HC_SUCCESS;
}