Exemple #1
0
int Vip::make_vip_turntable_data(Turntable_Config &data, std::vector<uint32_t> &id_list) {//更新物品组内容
	data.reset();
	data.max_open = 8;
	data.list_size = 18;
	//生成3个中奖次在1的;
	//生成3个中奖次在2的;
	//生成2个中奖次在3的;
	//生成2个中奖次在4的;
	//生成2个中奖次在5的;
	//生成2个中奖次在6的;
	//生成2个中奖次在7的;
	//生成2个中奖次在8的;
	for(int j = 1; j <= 8; ++j) {//第几次中奖的物品
		const Turntable_Item_Config_Vec *conf = CONFIG_CACHE_VIP->turntable_item_conf_vec_by_type(j);
		if(!conf){
			return ERROR_CONFIG_NOT_EXIST;
		}
		int n = 3;
		if(j > 2) {//第一第二次有3个; 剩余的2个
			n = 2;
		}
		for(int i = 0;  i < n; ++i) {//个数
			UInt_Vec tem_item_list;//临时抽取的物品id列表
			tem_item_list.clear();
			Int_Vec weight;
			weight.clear();
			for(Turntable_Item_Config_Vec::const_iterator it = conf->begin(); it != conf->end(); ++it) {
				if(data.item_list.find(it->id) == data.item_list.end()) {//物品组 不允许重复id
					tem_item_list.push_back(it->id);
					weight.push_back(it->rate);
				}
			}
			if(tem_item_list.empty() || weight.empty()) {//有可能出现在配置不合理的情况下 如配置的物品不住够概率的抽取
				return ERROR_CONFIG_NOT_EXIST;
			}
			int index = Utility_Func::lottery_one(weight);
			data.item_list.insert(tem_item_list[index]);
			id_list.push_back(tem_item_list[index]);
		}
	}
	return 0;
}
void Kruskal( K_Chart *K, P_Chart& E )
{
    /*构造最小生成树的Kruskal算法
    输入:加权连通图 K
    输出:E ,组成 G 的最小生成树的边的集合 */
    for (int i=0; i < E.points; i++)
    {
        E.flag[i] = false;
        for (int j=i; j< E.points; j++)
        {
            E.A[j][i] = E.A[i][j] = INT_MAX;
        }
    }
    MSort( K, K, 0, K_i-1);

    int		k = 0,  counter = 0;
    int		P1;
    int		P2;
    do
    {
        P1 = K[k].point.P1;
        P2 = K[k].point.P2;

        if ( E.flag[P1]==false && E.flag[P2]==false)
        {
            E.flag[P1] = true;
            E.flag[P2] = true;

            int_vec.clear();
            int_vec.push_back(P1);
            int_vec.push_back(P2);
            int_vec_vec.push_back(int_vec);

            counter++;
            distance_K += E.A[P1][P2] = E.A[P2][P1] = K[k].value;
            //continue;
        }
        else
        {
            if ( E.flag[P1 ]==false || E.flag[P2]==false)
            {
                int		i;

                if ( E.flag[P1]==false )
                {
                    E.flag[P1] = true;
                    //
                    i  = Find_i(P2);
                    int_vec_vec[i].push_back(P1);
                }
                else//if ( E.flag[P2]==false )
                {
                    E.flag[P2] = true;
                    //
                    i  = Find_i(P1);
                    int_vec_vec[i].push_back(P2);
                }
                distance_K += E.A[P1][P2] = E.A[P2][P1] = K[k].value;
                counter++;
            }

            else//if ( E.flag[P1 ]==true && E.flag[P2]==true)
            {
                int		P1_i = Find_i(P1);
                int		P2_i = Find_i(P2);
                if (P1_i != P2_i )
                {
                    if (int_vec_vec[P1_i].size() > int_vec_vec[P2_i].size() )
                    {
                        for (int i=0; i < int_vec_vec[P2_i].size(); i++)
                        {
                            int_vec_vec[P1_i].push_back( int_vec_vec[P2_i][i] );
                        }
                        int_vec_vec.erase(int_vec_vec.begin()+P2_i);//删除点集
                    }
                    else
                    {
                        for (int i=0; i < int_vec_vec[P1_i].size(); i++)
                        {
                            int_vec_vec[P2_i].push_back( int_vec_vec[P1_i][i] );
                        }
                        int_vec_vec.erase(int_vec_vec.begin()+P1_i);//删除点集
                    }

                    distance_K += E.A[P1][P2] = E.A[P2][P1] = K[k].value;
                    counter++;
                }
            }
        }
        k++;
    }
    while( counter < E.points-1 );

    return;
}
Exemple #3
0
int Vip::vip_turntable_lottery(int32_t &id, uint8_t type) {
	id = 0;
	//判断次数
	uint8_t use_num = vip_detail_->turntable_data.list_size - vip_detail_->turntable_data.item_list.size();
	if(use_num >= vip_detail_->turntable_data.max_open) {
		if(type == VIP_TURNTABLE_LOTTERY_ALL) {
			return -1;
		}
		return ERROR_VIP_TURNTABLE_NUM;
	}

	const Turntable_Cost_Config *tc_conf = CONFIG_CACHE_VIP->get_turntable_cost_config(use_num + 1);
	{	//验证VIP币
		if(!tc_conf) {
			return ERROR_INNER_SERVER;
		}
		int return_status = player_self()->pack_try_erase_item(PACK_T_PACKAGE_INDEX,Id_Amount(VIP_CURRENCY_ITEM_ID, vip_detail_->turntable_cost + tc_conf->cost));
		if(return_status != 0) {
			return return_status;
		}
	}
	unsigned int index = 0;
	int32_t tmp_id = 0;
	{//按物品权重求概率
		UInt_Vec list;
		Int_Vec weight;
		weight.clear();
		for(UInt_Mset::iterator iter = vip_detail_->turntable_data.item_list.begin(); iter != vip_detail_->turntable_data.item_list.end(); ++iter) {
			const Turntable_Item_Config *conf = CONFIG_CACHE_VIP->get_turntable_item_config(*iter);
			if(!conf){
				return ERROR_INNER_SERVER;
			}
			if(conf->type.find(use_num + 1) != conf->type.end()) {
				weight.push_back(conf->rate);
				list.push_back(conf->id);
			}
		}
		index = Utility_Func::lottery_one(weight);
		if(list.size() <= index) {
			return ERROR_INNER_SERVER;
		}
		tmp_id = list[index];
	}
	//验证背包放物品
	const Turntable_Item_Config *conf = CONFIG_CACHE_VIP->get_turntable_item_config(tmp_id);
	if(!conf) {
		return ERROR_INNER_SERVER;
	}
	Item_Detail item(conf->item_id, conf->num, Item_Detail::BIND);
	vip_detail_->turntable_reward.push_back(item);//记录转盘得到的物品
	vip_detail_->turntable_cost += tc_conf->cost; //记录转盘共消耗VIP币数量
	if(conf->ann) {
		//发送广播
		Chat_Item_Info item_;
		item_.reset();
		item_.item_base_info.id = conf->item_id;
		item_.item_base_info.amount = conf->num;
		player_self()->create_vip_turntable_announce(item_);
	}
//	{
//		int return_status = player_self()->pack_try_insert_item(PACK_T_PACKAGE_INDEX,item);
//		if(return_status != 0) {
//			return return_status;
//		}
//	}
	//都通过验证
	{	//删除一个
		vip_detail_->turntable_data.item_list.erase(vip_detail_->turntable_data.item_list.find(tmp_id));
	}
//	{//减少VIP币
//		int return_status = player_self()->pack_erase_item(PACK_T_PACKAGE_INDEX, Id_Amount(VIP_CURRENCY_ITEM_ID, 1), Lose_Item_DM_Info(ITEM_LOSE_VIP_TURNTABLE));
//		if(return_status != 0) {
//			return return_status;
//		}
//	}
//	{//增加获得奖品
//		int return_status = player_self()->pack_insert_item(PACK_T_PACKAGE_INDEX, item, Gain_Item_DM_Info(ITEM_GAIN_VIP_TURNTABLE));
//		if(return_status != 0) {
//			return return_status;
//		}
//	}
	id = tmp_id;
	return 0;
}
Exemple #4
0
int Alchemy::req_souls_alchemy(uint8_t tabs, uint8_t pay_type) {
	Cards_info *card;
	switch(tabs) {
		case 0: {
			if(alchemy_detail_->current_souls_hero_gold.heroID == 0) {
				//是否已经招募
				return ERROR_CLIENT_PARAM;
			} else {
				card = &alchemy_detail_->current_souls_hero_gold;
			}
		break;
		}
		case 1: {
			if(alchemy_detail_->current_souls_hero_critical.heroID == 0) {
				//是否已经招募
				return ERROR_CLIENT_PARAM;
			} else {
				card = &alchemy_detail_->current_souls_hero_critical;
			}
		break;
		}
		default:
			return ERROR_CLIENT_PARAM;
	}

	bool need_pay = true;
	//判断次数
	if(get_alchemy_souls_chances_free() - alchemy_detail_->used_souls_free_bout <= 0 ) {
		need_pay = true;
	} else {
		need_pay = false;
	}
	if(need_pay && CONFIG_CACHE_ALCHEMY->get_chances_souls_pay_by_vip_level(player_self()->vip())
			<= alchemy_detail_->used_souls_pay_bout) {
		//次数不够
		return ERROR_ALCHEMY_NUM;
	}
	//判断是否免费
	if(need_pay){
		//收费,判断是否足够的钻石
		int pay_amount = CONFIG_CACHE_ALCHEMY->get_pay_souls_num_by_count(alchemy_detail_->used_souls_pay_bout + 1);
		int pay_type_c = CONFIG_CACHE_ALCHEMY->get_pay_souls_type_by_count(alchemy_detail_->used_souls_pay_bout + 1);
		if(pay_type_c == BIND_GOLD_FIRST) {
			pay_type_c = (pay_type==1)?BIND_GOLD_FIRST:BIND_GOLD_ONLY;
		}
		int return_status = pack_try_sub_money(Money_Sub_Info(Money_Sub_Type(pay_type_c), pay_amount, MONEY_SUB_ALCHEMY));
//		if(CONFIG_CACHE->server_maintainer_cache().game_ver_type == 0) {	//判断国内
//			return_status = pack_try_sub_money(Money_Sub_Info(Money_Sub_Type(GOLD_ONLY), pay_amount, MONEY_SUB_ALCHEMY));
//		} else {//国外
//			return_status = pack_try_sub_money(Money_Sub_Info(Money_Sub_Type((pay_type==1)?BIND_GOLD_FIRST:BIND_GOLD_ONLY), pay_amount, MONEY_SUB_ALCHEMY));
//		}
		if(return_status != 0) {
			return return_status;
		}
	}

	//算出倍率
	int critical = 0;
	Int_Vec weight;
	weight.clear();
	weight.push_back(card->critical_1);
	weight.push_back(card->critical_3);
	weight.push_back(card->critical_6);
	int index = Utility_Func::lottery_one(weight);
	switch(index) {
		case 0: {
			critical = 1; //1倍
			break;
		}
		case 1: {
			critical = 3;//3倍
			break;
		}
		case 2: {
			critical = 6;//6倍
			++alchemy_detail_->six_critical_souls_num;
			break;
		}
		default :
			return ERROR_INNER_SERVER;
	}

	//限制6倍每天最多次数
	if(critical == 6 && alchemy_detail_->six_critical_souls_num > SIX_CRITICAL_MAX) {
		critical = 3;
	}

	//计算获得的钱
	int init_gold = CONFIG_CACHE_ALCHEMY->get_initial_souls_gold_by_level(player_self()->level());
	int get_gold = (init_gold + init_gold*card->gold_added/100) * critical;
	//实际操作,扣钻石或加钱
	if(need_pay) {
		//收费,扣钻石
		int pay_amount = CONFIG_CACHE_ALCHEMY->get_pay_souls_num_by_count(alchemy_detail_->used_souls_pay_bout + 1);
		int pay_type_c = CONFIG_CACHE_ALCHEMY->get_pay_souls_type_by_count(alchemy_detail_->used_souls_pay_bout + 1);
		if(pay_type_c == BIND_GOLD_FIRST) {
			pay_type_c = (pay_type==1)?BIND_GOLD_FIRST:BIND_GOLD_ONLY;
		}
		int return_status =  pack_sub_money(Money_Sub_Info(Money_Sub_Type(pay_type_c), pay_amount, MONEY_SUB_ALCHEMY));;
//		if(CONFIG_CACHE->server_maintainer_cache().game_ver_type == 0) {	//判断国内
//			return_status = pack_sub_money(Money_Sub_Info(Money_Sub_Type(GOLD_ONLY), pay_amount, MONEY_SUB_ALCHEMY));
//		} else {//国外
//			return_status = pack_sub_money(Money_Sub_Info(Money_Sub_Type((pay_type==1)?BIND_GOLD_FIRST:BIND_GOLD_ONLY), pay_amount, MONEY_SUB_ALCHEMY));
//		}
		if(return_status != 0) {
			return return_status;
		}
	}
	int return_status = pack_add_money(Money_Add_Info(Money_Type(SOULS), get_gold, MONEY_ADD_ALCHEMY));
	if(return_status != 0) {
		return return_status;
	}
	if(need_pay) {
		alchemy_detail_->used_souls_pay_bout++;
	} else {
		alchemy_detail_->used_souls_free_bout++;
	}
	alchemy_detail_->last_souls_tabs = tabs;
	alchemy_detail_->detail_change();
	//返回信息到客户端
	MSG_50152001 msg;
	msg.reset();
	msg.over_free_bout = get_over_alchemy_souls_free_about();
	msg.over_pay_bout = CONFIG_CACHE_ALCHEMY->get_chances_souls_pay_by_vip_level(player_self()->vip()) - alchemy_detail_->used_souls_pay_bout;
	msg.next_pay_diamond = CONFIG_CACHE_ALCHEMY->get_pay_souls_num_by_count(alchemy_detail_->used_souls_pay_bout + 1);
	msg.critical = critical;
	msg.get_gold = get_gold;
	msg.mtype = 1;
	THIS_SEND_TO_CLIENT(msg);

//	player_self()->daily_helper_listen(DAILY_FULFILL_LISTEN_ALCHEMY); //TOD助手日常监听
//	player_self()->task_listen_alchemy_num();  //炼金调用这个接口
	player_self()->active_content_listen_alchemy_num();
	return 0;
}