Browse Source

games/reveals/protocol stats in player info

Maxim Sokhatsky 11 years ago
parent
commit
a7195e6c87

+ 1 - 1
apps/face/src/protocol.erl

@@ -8,7 +8,7 @@ attach(Token) -> ws:send(enc(tuple(atom('client'),tuple(atom("session_attach"),
 join(Game) -> ws:send(enc(tuple(atom('client'),tuple(atom("join_game"), Game)))).
 logout() -> ws:send(enc(tuple(atom('client'),tuple(atom("logout"))))).
 pause(GameId, Action) -> ws:send(enc(tuple(atom('client'),tuple(atom("pause_game"),atom('undefined'),GameId,atom(Action))))).
-player_info(User,GameModule) -> ws:send(enc(tuple(atom('client'),tuple(atom("player_stats"),bin(User),atom(GameModule))))).
+player_info(User,GameModule) -> ws:send(enc(tuple(atom('client'),tuple(atom("stats_action"),bin(User),atom(GameModule))))).
 
 take(GameId,Place) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_take"),[{pile,Place}])))).
 discard(GameId, Color, Value) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_discard"),

+ 2 - 1
apps/server/include/requests.hrl

@@ -6,7 +6,7 @@
 -record(login, {username, password}).
 -record(logout, {}).
 -record(join_game, {game}).
--record(player_stats, {player_id :: 'PlayerId'() | 0, game_type}).
+-record(stats_action, {player_id :: 'PlayerId'(), game_type}).
 -record(chat, {chat_id :: 'GameId'(), message :: string()}).
 -record(game_action, {game :: 'GameId'(), action, args = []}).
 -record(social_action, {game :: 'GameId'(), type, recipient::'PlayerId'()}).
@@ -16,6 +16,7 @@
 -record(game_event, {game :: 'GameId'(), event, args = [] }).
 -record(chat_event, {chat :: 'GameId'(), content, author_id::'PlayerId'(),author_nick::string() }).
 -record(social_event, {type,game::'GameId'(),initiator::'PlayerId'(),recipient::'PlayerId'()}).
+-record(stats_event, {player_id :: 'PlayerId'(), games, reveals, protocol}).
 -record(pause_game, {table_id :: integer(),game :: 'GameId'(),action}).
 -record(game_paused, {table_id :: integer(), game :: 'GameId'(),action,who :: 'PlayerId'(),retries}).
 -record(disconnect, {reason_id,reason}).

+ 18 - 0
apps/server/src/game.erl

@@ -499,3 +499,21 @@ reveal_aggregate(#reveal_event{score = Count, user = Item}, Acc) ->
     case lists:keyfind(Item,1,Acc) of
         {Item,Sum} -> lists:keyreplace(Item,1,Acc,{Item,Count+Sum});
         false -> [{Item,Count}|Acc] end.
+
+get_player_info(_,User) ->
+    Okey = game_okey_scoring,
+    Scoring = [ begin 
+        case kvs:get(series_log,{M,S,R,User}) of
+       {ok,#series_log{type=M,speed=S,rounds=R,stats=Res}} ->
+            Win = case lists:keyfind(winner,1,Res) of {_,Num1} -> Num1; _ -> 0 end,
+            Los = case lists:keyfind(looser,1,Res) of {_,Num2} -> Num2; _ -> 0 end,
+            [{M,S,R,{Win,Los}}];
+       _ -> [] end end || M <- Okey:modes(), S <- Okey:speeds(), R <- Okey:rounds() ],
+    Games=lists:flatten(Scoring),
+    {ok,Reveals}=kvs:get(reveal_log,User),
+    {ok,Protocol}=kvs:get(protocol_log,User),
+    #stats_event{
+        player_id=User,
+        games=Games,
+        reveals=Reveals#reveal_log.stats,
+        protocol=Protocol#protocol_log.stats}.

+ 2 - 8
apps/server/src/game_session.erl

@@ -101,14 +101,8 @@ handle_client_request(#logout{}, _From, State) ->
     gas:info(?MODULE,"Logout", []),
     {stop, normal, ok, State};
 
-handle_client_request(#player_stats{player_id = PlayerId, game_type = GameModule}, _From, #state{rpc = RPC} = State) ->
-    Res = #'PlayerStats'{
-        id=PlayerId,
-        game=GameModule,
-        per_flavour=[{{lucky,standard},crypto:rand_uniform(7,108)},
-                     {{standalone,evenodd},crypto:rand_uniform(7,108)},
-                     {{standalone,color},crypto:rand_uniform(7,108)},
-                     {{elimination,color},crypto:rand_uniform(7,108)}]},
+handle_client_request(#stats_action{player_id = PlayerId, game_type = GameModule}, _From, #state{rpc = RPC} = State) ->
+    Res = game:get_player_info(GameModule, PlayerId),
     gas:info(?MODULE,"Get player stats: ~p", [Res]),
     send_message_to_player(RPC, Res),
     {reply, Res, State};

+ 2 - 1
apps/server/src/lib/known_records.erl

@@ -15,7 +15,8 @@ fields(login) ->                   record_info(fields, login);
 fields(session_attach) ->          record_info(fields, session_attach);
 fields(logout) ->                  record_info(fields, logout);
 fields(chat) ->                    record_info(fields, chat);
-fields(player_stats) ->        record_info(fields, player_stats);
+fields(stats_action) ->             record_info(fields, stats_action);
+fields(stats_event) ->            record_info(fields, stats_event);
 fields('PlayerInfo') ->            record_info(fields, 'PlayerInfo');
 fields(game_event) ->              record_info(fields, game_event);
 fields(chat_event) ->                record_info(fields, chat_event);

+ 6 - 15
apps/server/src/okey/game_okey_scoring.erl

@@ -2,22 +2,9 @@
 %% Created: Oct 23, 2012
 %% Description:
 -module(game_okey_scoring).
-
-
-%%
-%% Include files
-%%
 -include_lib("eunit/include/eunit.hrl").
-
-%%
-%% Exported Functions
-%%
--export([
-         init/3,
-         last_round_result/1,
-         chanak/1,
-         round_finished/6
-        ]).
+-compile(export_all).
+-export([init/3]).
 
 -type normal_tash() :: {integer(), integer()}.
 -type tash() :: false_okey | normal_tash().
@@ -60,6 +47,10 @@
          chanak           :: integer()  %% Defined only for evenodd and color mode
         }).
 
+modes() -> [standard,evenodd,color,countdown].
+rounds() -> [1,2,3]. %10,20,40,80,undefined].
+speeds() -> [slow,normal,fast,undefined].
+
 %%
 %% API Functions
 %%

+ 2 - 1
apps/server/src/sup/game_log.erl

@@ -103,8 +103,9 @@ update_container_stats(User,Event,Pos,GameState) ->
     C6 = setelement(#container_log.date,   C5, Date),
     C7 = setelement(#container_log.time,   C6, Time),
     C8 = setelement(#container_log.user,   C7, User),
+    C9 = setelement(#container_log.game_id,C8, GameId),
 
-    Container = C8,
+    Container = C9,
 
     ContainerStats = element(#container_log.stats, Container),
     EventName = element(Pos,Event),

+ 2 - 0
apps/server/src/sup/game_stats.erl

@@ -218,3 +218,5 @@ calc_points(KakushPerWinner, KakushPerLoser, WinGamePoints, Paid, Robot, Winner)
        Paid andalso Winner -> {KakushPerWinner, WinGamePoints};
        Paid -> {KakushPerLoser, 0}
     end.
+
+get_player_stats() -> ok.

+ 2 - 2
apps/server/src/sup/okey_sup.erl

@@ -46,7 +46,7 @@ okey_standalone_specs(GamesNum, VirtUsersPerTable) ->
                                       {set_timeout, infinity},
                                       {speed, fast},
                                       {game_type, standard},
-                                      {rounds, 1},
+                                      {rounds, lists:nth(crypto:rand_uniform(1,4),game_okey_scoring:rounds())},
                                       {reveal_confirmation, true},
                                       {next_series_confirmation, no_exit},
                                       {pause_mode, normal},
@@ -54,7 +54,7 @@ okey_standalone_specs(GamesNum, VirtUsersPerTable) ->
                                       {gosterge_finish_allowed, undefined}
                                      ],
                        CommonParams = [{speed, fast},
-                                       {rounds,1},
+                                       {rounds, lists:nth(crypto:rand_uniform(1,4),game_okey_scoring:rounds())},
                                        {double_points, 1},
                                        {game_mode,standard},
                                        {slang, false},