游戏掉落算法

不知道这个算不算是算法把,本人对算法不是很精通的(程序员中的屌丝,妈蛋的)

目标:自己用erlang写一个游戏服务器的框架,有没有感兴趣的同学,欢迎私信的。

实现语言: erlang

掉落规则配表

drop(DropId)->
	Proto = sys_drop_ets:get_proto(DropId),
	%% ItemsPro = [{100001,10}, {100002,10}, {100001,20}]
	ItemsPro = sys_drop_ets:get_items_pro(Proto),
	TotalPro = 
		lists:foldl(fun(ItemPro, Acc)->
				{_, Pro} = ItemPro,
				Pro + Acc
			end, 0, ItemsPro),
	random:seed(now()),
	Random = random:uniform(TotalPro),
	{Items, TPro} = 
		lists:foldl(fun({Item, Pro}, {TItem, TPro})->
			if
				TPro >= Random->
					{TItem, TPro};
				Pro + TPro >= Random->
					{Item, Pro + TPro};
				true->
					{[], Pro + TPro}
			end
		end, {[], 0}, ItemsPro),
	Items.



从一个列表里面,随即的得到指定数量的列表

random_player_id_list1(PlayerIdList)->
    Len = length(PlayerIdList),
    random:seed(now()),
    Random = random:uniform(Len),
    {L1, L2} = lists:split(Random, PlayerIdList),
    Len2 = length(L2),
    if
        L2 > ?ONE_PAGE_PLAYER_NUM->
            lists:sublist(L2, ?ONE_PAGE_PLAYER_NUM);
        Len2 =:= ?ONE_PAGE_PLAYER_NUM->
            L2;
        true->
            Len2 ++ lists:sublist(L1, ?ONE_PAGE_PLAYER_NUM - L2)
    end.

你可能感兴趣的:(erlang)