summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2017-11-22 16:45:05 +0100
committernsensfel <SpamShield0@noot-noot.org>2017-11-22 16:45:05 +0100
commit9dd67cd5c63ac2a050a517c313f2e343f008421b (patch)
tree44d774f751b82cb09996625c3eb2c9aaecb1330f
parent15515f36d7bbd53c7049c597ea2c6f942dc39ded (diff)
Got the player turns to work... I think.
-rw-r--r--src/battlemap_instance.erl10
-rw-r--r--src/character_instance.erl5
-rw-r--r--src/database_shim.erl15
-rw-r--r--www/handler/battlemap/character_turn.yaws10
4 files changed, 33 insertions, 7 deletions
diff --git a/src/battlemap_instance.erl b/src/battlemap_instance.erl
index 37811b3..3f4b6cd 100644
--- a/src/battlemap_instance.erl
+++ b/src/battlemap_instance.erl
@@ -26,7 +26,15 @@ can_play_char_instance
CharInstID
) ->
(
- (array:get(BattlemapInstance#battlemap_instance.curr_player) =:= PlayerID)
+ (
+ array:get
+ (
+ BattlemapInstance#battlemap_instance.curr_player,
+ BattlemapInstance#battlemap_instance.players
+ )
+ =:=
+ PlayerID
+ )
and
lists:member(CharInstID, BattlemapInstance#battlemap_instance.rem_chars)
).
diff --git a/src/character_instance.erl b/src/character_instance.erl
index d8d7455..a38be5d 100644
--- a/src/character_instance.erl
+++ b/src/character_instance.erl
@@ -3,7 +3,8 @@
(
[
set_location/3,
- get_location/1
+ get_location/1,
+ get_owner/1
]
).
@@ -18,3 +19,5 @@ set_location (CharInst, X, Y) ->
get_location (CharInst) ->
{CharInst#character_instance.x, CharInst#character_instance.y}.
+
+get_owner (CharInst) -> CharInst#character_instance.team.
diff --git a/src/database_shim.erl b/src/database_shim.erl
index 0a46c00..8d97298 100644
--- a/src/database_shim.erl
+++ b/src/database_shim.erl
@@ -53,8 +53,19 @@ generate_map_instance (CharInts) ->
{
id = <<"0">>,
chars = dict:from_list(CharInts),
- curr_player = <<"0">>,
- rem_chars = [],
+ curr_player = 0,
+ players = array:from_list([<<"0">>, <<"1">>]),
+ rem_chars =
+ lists:filtermap
+ (
+ fun ({K, V}) ->
+ case character_instance:get_owner(V) of
+ 0 -> {true, K};
+ _ -> false
+ end
+ end,
+ CharInts
+ ),
last_turn = []
}.
diff --git a/www/handler/battlemap/character_turn.yaws b/www/handler/battlemap/character_turn.yaws
index e0a60a8..83a3570 100644
--- a/www/handler/battlemap/character_turn.yaws
+++ b/www/handler/battlemap/character_turn.yaws
@@ -51,8 +51,8 @@ handle (Req) ->
battlemap_instance:can_play_char_instance
(
BattlemapInstance,
- Input#input.char_id,
- Input#input.player_id
+ Input#input.player_id,
+ Input#input.char_id
),
{X, Y} =
battlemap:cross
@@ -66,7 +66,11 @@ handle (Req) ->
NewBattlemapInstance =
battlemap_instance:set_char_instance
(
- BattlemapInstance,
+ battlemap_instance:post_play_char_instance
+ (
+ BattlemapInstance,
+ Input#input.char_id
+ ),
Input#input.char_id,
character_instance:set_location(CharInst, X, Y)
),