summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2020-01-15 17:24:41 +0100
committernsensfel <SpamShield0@noot-noot.org>2020-01-15 17:24:41 +0100
commit959e82eafece7d355b2ffdc2a6fec55afd6f35db (patch)
tree37db1a350168fa95aeb75e48800454bbf98dfd02 /src/battle
parent83543758b9682f0e476809f207957471fcbbff5b (diff)
parent55b9f93a08a70c14fc8a55b97b131aedf26b2490 (diff)
...
Diffstat (limited to 'src/battle')
-rw-r--r--src/battle/src/Struct/Battle.elm4
-rw-r--r--src/battle/src/Struct/Model.elm12
-rw-r--r--src/battle/src/Struct/Puppeteer.elm20
-rw-r--r--src/battle/src/Struct/PuppeteerAction.elm145
-rw-r--r--src/battle/src/Struct/TurnResult.elm36
-rw-r--r--src/battle/src/Update/HandleServerReply.elm2
6 files changed, 134 insertions, 85 deletions
diff --git a/src/battle/src/Struct/Battle.elm b/src/battle/src/Struct/Battle.elm
index 84d08ba..a689f7a 100644
--- a/src/battle/src/Struct/Battle.elm
+++ b/src/battle/src/Struct/Battle.elm
@@ -24,6 +24,7 @@ module Struct.Battle exposing
set_map,
get_id,
+ set_id,
get_own_player_index
)
@@ -251,6 +252,9 @@ set_map map battle = {battle | map = map}
get_id : Type -> String
get_id battle = battle.id
+set_id : String -> Type -> Type
+set_id id battle = {battle | id = id}
+
--------------------------
---- Own Player Index ----
--------------------------
diff --git a/src/battle/src/Struct/Model.elm b/src/battle/src/Struct/Model.elm
index 989f66d..2924ed3 100644
--- a/src/battle/src/Struct/Model.elm
+++ b/src/battle/src/Struct/Model.elm
@@ -3,8 +3,7 @@ module Struct.Model exposing
Type,
new,
invalidate,
- clear,
- clear_error
+ clear
)
-- Shared ----------------------------------------------------------------------
@@ -17,6 +16,7 @@ import BattleCharacters.Struct.DataSet
import BattleMap.Struct.DataSet
-- Local Module ----------------------------------------------------------------
+import Struct.Battle
import Struct.CharacterTurn
import Struct.Error
import Struct.MessageBoard
@@ -51,7 +51,7 @@ type alias Type =
--------------------------------------------------------------------------------
new : Struct.Flags.Type -> Type
new flags =
- let maybe_battle_id =
+ let
model =
{
flags = flags,
@@ -66,7 +66,7 @@ new flags =
battle = (Struct.Battle.new)
}
in
- case maybe_battle_id of
+ case (Struct.Flags.maybe_get_param "id" flags) of
Nothing ->
(invalidate
(Struct.Error.new
@@ -78,13 +78,13 @@ new flags =
(Just id) ->
{model |
- battle = (Struct.Battle.set_battle_id id model.battle)
+ battle = (Struct.Battle.set_id id model.battle)
}
clear : Type -> Type
clear model =
{model |
- message_board = (Struct.MessageBoard.clear),
+ message_board = (Struct.MessageBoard.clear model.message_board),
ui =
(Struct.UI.reset_displayed_nav
(Struct.UI.set_previous_action Nothing model.ui)
diff --git a/src/battle/src/Struct/Puppeteer.elm b/src/battle/src/Struct/Puppeteer.elm
index 76447b2..df0221d 100644
--- a/src/battle/src/Struct/Puppeteer.elm
+++ b/src/battle/src/Struct/Puppeteer.elm
@@ -50,35 +50,35 @@ new =
append_forward : (List Struct.PuppeteerAction.Type) -> Type -> Type
append_forward actions puppeteer =
{puppeteer |
- forward_actions = (List.concat puppeteer.forward_actions actions)
+ forward_actions = (puppeteer.forward_actions ++ actions)
}
append_backward : (List Struct.PuppeteerAction.Type) -> Type -> Type
append_backward actions puppeteer =
{puppeteer |
- backward_actions = (List.concat actions puppeteer.backward_actions)
+ backward_actions = (actions ++ puppeteer.backward_actions)
}
forward : Type -> Type
forward puppeteer =
case (Util.List.pop puppeteer.forward_actions) of
- ([], Nothing) -> puppeteer
- (forward_actions, (Just action)) ->
+ Nothing -> puppeteer
+ (Just (action, forward_actions)) ->
{puppeteer |
forward_actions = forward_actions,
- backward_actions = [action|puppeteer.backward_actions],
- is_playing_forward = true
+ backward_actions = (action :: puppeteer.backward_actions),
+ is_playing_forward = True
}
backward : Type -> Type
backward puppeteer =
case (Util.List.pop puppeteer.backward_actions) of
- ([], Nothing) -> puppeteer
- (backward_actions, (Just action)) ->
+ Nothing -> puppeteer
+ (Just (action, backward_actions)) ->
{puppeteer |
- forward_actions = [action|forward_actions],
+ forward_actions = (action :: puppeteer.forward_actions),
backward_actions = backward_actions,
- is_playing_forward = false
+ is_playing_forward = False
}
step : Type -> Type
diff --git a/src/battle/src/Struct/PuppeteerAction.elm b/src/battle/src/Struct/PuppeteerAction.elm
index c8207b0..f1f975d 100644
--- a/src/battle/src/Struct/PuppeteerAction.elm
+++ b/src/battle/src/Struct/PuppeteerAction.elm
@@ -1,8 +1,8 @@
module Struct.PuppeteerAction exposing
(
Type(..),
- Group(..),
- from_turn_result
+ Effect(..),
+ from_turn_results
)
-- Elm -------------------------------------------------------------------------
@@ -40,60 +40,70 @@ type Type =
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-from_attacked : Struct.Attack.Type -> (List Type)
+from_attacked : Struct.TurnResult.Attack -> (List Type)
from_attacked attack =
let
- attacker_ix = (Struct.TurnResult.get_actor_index turn_result)
- defender_ix = (Struct.TurnResult.get_attack_defender_index attack)
+ attacker_ix = (Struct.TurnResult.get_attack_actor_index attack)
+ defender_ix = (Struct.TurnResult.get_attack_target_index attack)
in
- [
- (Perform
- [
- (RefreshCharacter (False, attacker_ix)),
- (RefreshCharacter (False, defender_ix))
- ]
- ),
- (PerformFor (2.0, [(Focus attacker_ix)])),
- (PerformFor (2.0, [(Focus defender_ix)])),
+ (
+ [
+ (Perform
+ [
+ (RefreshCharacter (False, attacker_ix)),
+ (RefreshCharacter (False, defender_ix))
+ ]
+ ),
+ (PerformFor (2.0, [(Focus attacker_ix)])),
+ (PerformFor (2.0, [(Focus defender_ix)]))
+ ]
+ ++
(List.map
- (PerformFor (5.0, (Hit attack)))
- ),
- (Perform
- [
- (RefreshCharacter (True, attacker_ix)),
- (RefreshCharacter (True, defender_ix))
- ]
+ (\hit->
+ (PerformFor (5.0, [(Hit hit)]))
+ )
+ (Struct.TurnResult.get_attack_sequence attack)
)
- ]
+ ++
+ [
+ (Perform
+ [
+ (RefreshCharacter (True, attacker_ix)),
+ (RefreshCharacter (True, defender_ix))
+ ]
+ )
+ ]
+ )
from_moved : Struct.TurnResult.Movement -> (List Type)
from_moved movement =
- let actor_ix = (Struct.TurnResult.get_movement_actor movement) in
+ let actor_ix = (Struct.TurnResult.get_movement_actor_index movement) in
(
[
(PerformFor (1.0, [(Focus actor_ix)])),
(Perform [(RefreshCharacter (False, actor_ix))])
]
++
- [
- (List.map
- (\dir ->
- (PerformFor
- (
- 0.5,
- [(Move (actor_ix, dir))]
- )
+ (List.map
+ (\dir ->
+ (PerformFor
+ (
+ 0.5,
+ [(Move (actor_ix, dir))]
)
)
)
- ]
+ (Struct.TurnResult.get_movement_path movement)
+ )
++
[ (Perform [(RefreshCharacter (True, actor_ix))]) ]
)
from_switched_weapon : Struct.TurnResult.WeaponSwitch -> (List Type)
from_switched_weapon weapon_switch =
- let actor_ix = (Struct.TurnResult.get_weapon_switch_actor weapon_switch) in
+ let
+ actor_ix = (Struct.TurnResult.get_weapon_switch_actor_index weapon_switch)
+ in
[
(PerformFor (1.0, [(Focus actor_ix)])),
(PerformFor
@@ -101,7 +111,7 @@ from_switched_weapon weapon_switch =
2.0,
[
(RefreshCharacter (False, actor_ix)),
- (SwapWeapons actor_ix)
+ (SwapWeapons actor_ix),
(RefreshCharacter (True, actor_ix))
]
)
@@ -109,55 +119,54 @@ from_switched_weapon weapon_switch =
]
from_player_won : Struct.TurnResult.PlayerVictory -> (List Type)
-from_player_won player_victory =
+from_player_won victory =
[
(PerformFor
(
2.0,
[
(AnnounceVictory
- (Struct.TurnResult.get_player_victory_index player_victory)
+ (Struct.TurnResult.get_victory_player_index victory)
)
]
)
)
]
-from_player_lost : Struct.TurnResult.PlayerLoss -> (List Type)
-from_player_lost player_loss =
- [
- (PerformFor
- (
- 2.0,
- [
- (RefreshCharactersOf (False, player_ix)),
- (AnnounceLoss
- (Struct.TurnResult.get_player_loss_index player_loss)
- ),
- (RefreshCharactersOf (True, player_ix))
- ]
+from_player_lost : Struct.TurnResult.PlayerDefeat -> (List Type)
+from_player_lost loss =
+ let player_ix = (Struct.TurnResult.get_loss_player_index loss) in
+ [
+ (PerformFor
+ (
+ 2.0,
+ [
+ (RefreshCharactersOf (False, player_ix)),
+ (AnnounceLoss player_ix),
+ (RefreshCharactersOf (True, player_ix))
+ ]
+ )
)
- )
- ]
+ ]
from_player_turn_started : Struct.TurnResult.PlayerTurnStart -> (List Type)
-from_player_turn_started player_turn_started =
- [
- (PerformFor
- (
- 2.0,
- [
- (RefreshCharactersOf (False, player_ix)),
- (StartPlayerTurn
- (Struct.TurnResult.get_player_start_of_turn_index
- player_turn_started
- )
- ),
- (RefreshCharactersOf (True, player_ix))
- ]
+from_player_turn_started turn_started =
+ let
+ player_ix =
+ (Struct.TurnResult.get_start_of_turn_player_index turn_started)
+ in
+ [
+ (PerformFor
+ (
+ 2.0,
+ [
+ (RefreshCharactersOf (False, player_ix)),
+ (StartTurn player_ix),
+ (RefreshCharactersOf (True, player_ix))
+ ]
+ )
)
- )
- ]
+ ]
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
@@ -168,7 +177,7 @@ from_turn_results turn_result =
(Struct.TurnResult.Moved movement) -> (from_moved movement)
(Struct.TurnResult.Attacked attack) -> (from_attacked attack)
(Struct.TurnResult.SwitchedWeapon weapon_switch) ->
- (from_switched_weapon movement)
+ (from_switched_weapon weapon_switch)
(Struct.TurnResult.PlayerWon player_victory) ->
(from_player_won player_victory)
diff --git a/src/battle/src/Struct/TurnResult.elm b/src/battle/src/Struct/TurnResult.elm
index b0d7d09..fe49c2a 100644
--- a/src/battle/src/Struct/TurnResult.elm
+++ b/src/battle/src/Struct/TurnResult.elm
@@ -7,6 +7,15 @@ module Struct.TurnResult exposing
PlayerVictory,
PlayerDefeat,
PlayerTurnStart,
+ get_start_of_turn_player_index,
+ get_victory_player_index,
+ get_loss_player_index,
+ get_weapon_switch_actor_index,
+ get_movement_actor_index,
+ get_movement_path,
+ get_attack_actor_index,
+ get_attack_target_index,
+ get_attack_sequence,
decoder
)
@@ -185,3 +194,30 @@ decoder : (Json.Decode.Decoder Type)
decoder =
(Json.Decode.field "t" Json.Decode.string)
|> (Json.Decode.andThen internal_decoder)
+
+get_start_of_turn_player_index : PlayerTurnStart -> Int
+get_start_of_turn_player_index start_of_turn = start_of_turn.player_index
+
+get_victory_player_index : PlayerVictory -> Int
+get_victory_player_index player_victory = player_victory.player_index
+
+get_loss_player_index : PlayerDefeat -> Int
+get_loss_player_index player_loss = player_loss.player_index
+
+get_weapon_switch_actor_index : WeaponSwitch -> Int
+get_weapon_switch_actor_index weapon_switch = weapon_switch.character_index
+
+get_movement_actor_index : Movement -> Int
+get_movement_actor_index movement = movement.character_index
+
+get_movement_path : Movement -> (List BattleMap.Struct.Direction.Type)
+get_movement_path movement = movement.path
+
+get_attack_actor_index : Attack -> Int
+get_attack_actor_index attack = attack.attacker_index
+
+get_attack_target_index : Attack -> Int
+get_attack_target_index attack = attack.defender_index
+
+get_attack_sequence : Attack -> (List Struct.Attack.Type)
+get_attack_sequence attack = attack.sequence
diff --git a/src/battle/src/Update/HandleServerReply.elm b/src/battle/src/Update/HandleServerReply.elm
index c72d165..31b3318 100644
--- a/src/battle/src/Update/HandleServerReply.elm
+++ b/src/battle/src/Update/HandleServerReply.elm
@@ -37,9 +37,9 @@ import Struct.Error
import Struct.Event
import Struct.Model
import Struct.Player
+import Struct.Puppeteer
import Struct.ServerReply
import Struct.TurnResult
-import Struct.UI
import Update.Puppeteer