summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-01-16 00:08:14 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-01-16 00:08:14 +0100
commit545be2964873423280fae2cb1c211b746a37b562 (patch)
tree9096f6c329e4ed5e3470f02ae3256cdbedda6ee3 /src/battle
parent1ebb5eaa2edc601bed405f8f7733412b0378a185 (diff)
...
Diffstat (limited to 'src/battle')
-rw-r--r--src/battle/query/btl_join.erl48
-rw-r--r--src/battle/struct/btl_pending_battle.erl46
2 files changed, 82 insertions, 12 deletions
diff --git a/src/battle/query/btl_join.erl b/src/battle/query/btl_join.erl
index 587f555..c38cfde 100644
--- a/src/battle/query/btl_join.erl
+++ b/src/battle/query/btl_join.erl
@@ -14,6 +14,7 @@
player_id :: shr_player:id(),
session_token :: binary(),
mode :: mode(),
+ summary_ix :: non_neg_integer(),
size :: non_neg_integer(),
roster_ixs :: list(non_neg_integer()),
map_id :: ataxia_id:type()
@@ -38,6 +39,7 @@ parse_input (Req) ->
JSONReqMap = jiffy:decode(Req, [return_maps]),
PlayerID = maps:get(<<"pid">>, JSONReqMap),
SessionToken = maps:get(<<"stk">>, JSONReqMap),
+ SummaryIX = maps:get(<<"six">>, JSONReqMap),
Mode =
case maps:get(<<"m">>, JSONReqMap) of
@@ -65,6 +67,7 @@ parse_input (Req) ->
session_token = SessionToken,
mode = Mode,
size = Size,
+ summary_ix = SummaryIX,
roster_ixs = Roster,
map_id = MapID
}.
@@ -85,6 +88,7 @@ authenticate_user (Input) ->
handle_attack (Input) ->
PlayerID = Input#input.player_id,
SelectedCharacterIXs = Input#input.roster_ixs,
+ SummaryIX = Input#input.summary_ix,
PlayerDBUser = ataxia_security:user_from_id(PlayerID),
PartySize = length(SelectedCharacterIXs),
@@ -106,25 +110,46 @@ handle_attack (Input) ->
]
)
),
- ataxic:ge
+ ataxic:land
(
- ataxic:field
- (
- ataxia_entry:get_value_field(),
- ataxic:field
+ [
+ ataxic:ge
+ (
+ ataxic:field
+ (
+ ataxia_entry:get_value_field(),
+ ataxic:field
+ (
+ btl_pending_battle:get_free_slots_field(),
+ ataxic:current_value()
+ )
+ ),
+ ataxic:constant(PartySize)
+ ),
+ ataxic:neg
(
- btl_pending_battle:get_free_slots_field(),
- ataxic:current_value()
+ ataxic:field
+ (
+ btl_pending_battle:get_player_ids_field(),
+ ataxic:apply_function
+ (
+ lists,
+ member,
+ [
+ ataxic:constant(PlayerID),
+ ataxic:current_value()
+ ]
+ )
+ )
)
- ),
- ataxic:constant(PartySize)
+ ]
)
- % missing: test that user isn't already a participant.
),
bnt_join_battle:attempt
(
PlayerID,
+ SummaryIX,
SelectedCharacterIXs,
AvailablePendingBattleID,
AvailablePendingBattle
@@ -135,9 +160,10 @@ handle_attack (Input) ->
handle_defend (Input) ->
PlayerID = Input#input.player_id,
SelectedCharacterIXs = Input#input.roster_ixs,
+ SummaryIX = Input#input.summary_ix,
MapID = Input#input.map_id,
- bnt_join_battle:generate(PlayerID, MapID, SelectedCharacterIXs),
+ bnt_join_battle:generate(PlayerID, SummaryIX, MapID, SelectedCharacterIXs),
ok.
diff --git a/src/battle/struct/btl_pending_battle.erl b/src/battle/struct/btl_pending_battle.erl
index a69e6ce..ab0e67d 100644
--- a/src/battle/struct/btl_pending_battle.erl
+++ b/src/battle/struct/btl_pending_battle.erl
@@ -10,6 +10,9 @@
pending_battle,
{
free_slots :: non_neg_integer(),
+ player_ids :: list(shr_player:id()),
+ player_summary_ixs :: list(non_neg_integer()),
+ battle_id :: btl_battle:id(),
battle :: btl_battle:type()
}
).
@@ -30,12 +33,21 @@
[
get_battle/1,
get_free_slots/1,
+ get_battle_id/1,
+ get_player_ids/1,
+ get_player_summary_ixs/1,
set_battle/2,
set_free_slots/2,
+ set_battle_id/2,
+ set_player_ids/2,
+ set_player_summary_ixs/2,
get_battle_field/0,
- get_free_slots_field/0
+ get_free_slots_field/0,
+ get_battle_id_field/0,
+ get_player_ids_field/0,
+ get_player_summary_ixs_field/0
]
).
@@ -58,24 +70,56 @@ new (FreeSlots, Battle) ->
#pending_battle
{
free_slots = FreeSlots,
+ player_ids = [],
+ player_summary_ixs = [],
+ battle_id = ataxia_id:null(),
battle = Battle
}.
%%%% Accessors
+-spec get_battle_id (type()) -> btl_battle:id().
+get_battle_id (PBattle) -> PBattle#pending_battle.battle_id.
+
-spec get_battle (type()) -> btl_battle:type().
get_battle (PBattle) -> PBattle#pending_battle.battle.
-spec get_free_slots (type()) -> non_neg_integer().
get_free_slots (PBattle) -> PBattle#pending_battle.free_slots.
+-spec get_player_ids (type()) -> list(shr_player:id()).
+get_player_ids (PBattle) -> PBattle#pending_battle.player_ids.
+
+-spec get_player_summary_ixs (type()) -> list(non_neg_integer()).
+get_player_summary_ixs (PBattle) -> PBattle#pending_battle.player_summary_ixs.
+
-spec set_battle (btl_battle:type(), type()) -> type().
set_battle (Battle, PBattle) -> PBattle#pending_battle{ battle = Battle }.
+-spec set_battle_id (btl_battle:id(), type()) -> type().
+set_battle_id (BattleID, PBattle) ->
+ PBattle#pending_battle{ battle_id = BattleID }.
+
-spec set_free_slots (non_neg_integer(), type()) -> type().
set_free_slots (Val, PBattle) -> PBattle#pending_battle{ free_slots = Val }.
+-spec set_player_summary_ixs (list(non_neg_integer()), type()) -> type().
+set_player_summary_ixs (Val, PBattle) ->
+ PBattle#pending_battle{ player_summary_ixs = Val }.
+
+-spec set_player_ids (list(shr_player:id()), type()) -> type().
+set_player_ids (Val, PBattle) -> PBattle#pending_battle{ player_ids = Val }.
+
+-spec get_battle_id_field () -> non_neg_integer().
+get_battle_id_field () -> #pending_battle.battle_id.
+
-spec get_battle_field () -> non_neg_integer().
get_battle_field () -> #pending_battle.battle.
-spec get_free_slots_field () -> non_neg_integer().
get_free_slots_field () -> #pending_battle.free_slots.
+
+-spec get_player_ids_field () -> non_neg_integer().
+get_player_ids_field () -> #pending_battle.player_ids.
+
+-spec get_player_summary_ixs_field () -> non_neg_integer().
+get_player_summary_ixs_field () -> #pending_battle.player_summary_ixs.