aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-20 14:11:07 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-20 14:11:07 +0100
commit7e7268cfa4e3fbbdee71cc7200923e5b68cea796 (patch)
treeaa37b0903af8e36a7a09f2e906cebda937b2de5b
parent66046080f92a3a7686e0414de35395f47064daca (diff)
downloadtacticians-client-calc_stats.zip
tacticians-client-calc_stats.tar.bz2
Adds the SwitchWeapon action.calc_stats
-rw-r--r--src/battlemap/src/ElmModule/Update.elm4
-rw-r--r--src/battlemap/src/Struct/Character.elm22
-rw-r--r--src/battlemap/src/Struct/CharacterTurn.elm17
-rw-r--r--src/battlemap/src/Struct/Event.elm1
-rw-r--r--src/battlemap/src/Struct/Weapon.elm27
-rw-r--r--src/battlemap/src/Update/EndTurn.elm2
-rw-r--r--src/battlemap/src/Update/RequestDirection.elm2
-rw-r--r--src/battlemap/src/Update/SelectCharacter.elm10
-rw-r--r--src/battlemap/src/Update/SelectTile.elm2
-rw-r--r--src/battlemap/src/Update/SwitchWeapon.elm94
-rw-r--r--src/battlemap/src/View/Footer.elm2
11 files changed, 158 insertions, 25 deletions
diff --git a/src/battlemap/src/ElmModule/Update.elm b/src/battlemap/src/ElmModule/Update.elm
index 96fe20b..22217bf 100644
--- a/src/battlemap/src/ElmModule/Update.elm
+++ b/src/battlemap/src/ElmModule/Update.elm
@@ -16,6 +16,7 @@ import Update.SelectTab
import Update.SelectTile
import Update.SendLoadBattlemapRequest
import Update.SwitchTeam
+import Update.SwitchWeapon
update : (
Struct.Event.Type ->
@@ -56,3 +57,6 @@ update event model =
(Struct.Event.ServerReplied result) ->
(Update.HandleServerReply.apply_to model result)
+
+ Struct.Event.WeaponSwitchRequest ->
+ (Update.SwitchWeapon.apply_to new_model)
diff --git a/src/battlemap/src/Struct/Character.elm b/src/battlemap/src/Struct/Character.elm
index f836f5d..f2085d6 100644
--- a/src/battlemap/src/Struct/Character.elm
+++ b/src/battlemap/src/Struct/Character.elm
@@ -13,7 +13,9 @@ module Struct.Character exposing
get_attributes,
get_statistics,
is_enabled,
- set_enabled
+ set_enabled,
+ get_weapons,
+ set_weapons
)
-- Battlemap -------------------------------------------------------------------
@@ -115,5 +117,19 @@ get_statistics char = char.statistics
is_enabled : Type -> Bool
is_enabled char = char.enabled
-set_enabled : Type -> Bool -> Type
-set_enabled char enabled = {char | enabled = enabled}
+set_enabled : Bool -> Type -> Type
+set_enabled enabled char = {char | enabled = enabled}
+
+get_weapons : Type -> Struct.WeaponSet.Type
+get_weapons char = char.weapons
+
+set_weapons : Struct.WeaponSet.Type -> Type -> Type
+set_weapons weapons char =
+ {char |
+ weapons = weapons,
+ statistics =
+ (Struct.Statistics.new
+ char.attributes
+ weapons
+ )
+ }
diff --git a/src/battlemap/src/Struct/CharacterTurn.elm b/src/battlemap/src/Struct/CharacterTurn.elm
index 13ca342..5aa5b94 100644
--- a/src/battlemap/src/Struct/CharacterTurn.elm
+++ b/src/battlemap/src/Struct/CharacterTurn.elm
@@ -62,17 +62,16 @@ new =
try_getting_active_character : Type -> (Maybe Struct.Character.Type)
try_getting_active_character ct = ct.active_character
-
can_select_targets : Type -> Bool
can_select_targets ct =
((ct.state == MovedCharacter) || ((ct.state == ChoseTarget)))
set_active_character : (
- Type ->
Struct.Character.Type ->
+ Type ->
Type
)
-set_active_character ct char =
+set_active_character char ct =
{ct |
state = SelectedCharacter,
active_character = (Just char),
@@ -104,8 +103,8 @@ lock_path ct =
try_getting_navigator : Type -> (Maybe Struct.Navigator.Type)
try_getting_navigator ct = ct.navigator
-set_navigator : Type -> Struct.Navigator.Type -> Type
-set_navigator ct navigator =
+set_navigator : Struct.Navigator.Type -> Type -> Type
+set_navigator navigator ct =
{ct |
state = SelectedCharacter,
path = [],
@@ -113,15 +112,15 @@ set_navigator ct navigator =
navigator = (Just navigator)
}
-add_target : Type -> Struct.Character.Ref -> Type
-add_target ct target_ref =
+add_target : Struct.Character.Ref -> Type -> Type
+add_target target_ref ct =
{ct |
state = ChoseTarget,
targets = (List.append ct.targets [target_ref])
}
-remove_target : Type -> Int -> Type
-remove_target ct i =
+remove_target : Int -> Type -> Type
+remove_target i ct =
let
new_targets = (List.drop i ct.targets)
in
diff --git a/src/battlemap/src/Struct/Event.elm b/src/battlemap/src/Struct/Event.elm
index e5517c4..6231761 100644
--- a/src/battlemap/src/Struct/Event.elm
+++ b/src/battlemap/src/Struct/Event.elm
@@ -23,3 +23,4 @@ type Type =
| ServerReplied (Result Http.Error (List (List String)))
| DebugTeamSwitchRequest
| DebugLoadBattlemapRequest
+ | WeaponSwitchRequest
diff --git a/src/battlemap/src/Struct/Weapon.elm b/src/battlemap/src/Struct/Weapon.elm
index d6843ac..180b662 100644
--- a/src/battlemap/src/Struct/Weapon.elm
+++ b/src/battlemap/src/Struct/Weapon.elm
@@ -2,6 +2,8 @@ module Struct.Weapon exposing
(
Type,
new,
+ get_max_range,
+ get_min_range,
none
)
@@ -12,7 +14,9 @@ module Struct.Weapon exposing
--------------------------------------------------------------------------------
type alias Type =
{
- id : Int
+ id : Int,
+ range_min : Int,
+ range_max : Int
}
type WeaponRangeType = Ranged | Melee
@@ -26,7 +30,6 @@ type alias WeaponType =
dmg_type : WeaponDamageType
}
-
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -35,7 +38,23 @@ type alias WeaponType =
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
new : Int -> Type
-new id = { id = id }
+new id =
+ {
+ id = id,
+ range_min = 1,
+ range_max = 1
+ }
none : Type
-none = { id = 0 }
+none =
+ {
+ id = 0,
+ range_min = 0,
+ range_max = 0
+ }
+
+get_max_range : Type -> Int
+get_max_range wp = wp.range_max
+
+get_min_range : Type -> Int
+get_min_range wp = wp.range_min
diff --git a/src/battlemap/src/Update/EndTurn.elm b/src/battlemap/src/Update/EndTurn.elm
index 32237bf..4cae3ab 100644
--- a/src/battlemap/src/Update/EndTurn.elm
+++ b/src/battlemap/src/Update/EndTurn.elm
@@ -35,11 +35,11 @@ make_it_so model char nav =
(Just char) ->
(Just
(Struct.Character.set_enabled
+ False
(Struct.Character.set_location
(Struct.Navigator.get_current_location nav)
char
)
- False
)
)
Nothing -> Nothing
diff --git a/src/battlemap/src/Update/RequestDirection.elm b/src/battlemap/src/Update/RequestDirection.elm
index e9e3005..605632e 100644
--- a/src/battlemap/src/Update/RequestDirection.elm
+++ b/src/battlemap/src/Update/RequestDirection.elm
@@ -26,8 +26,8 @@ make_it_so model navigator dir =
{model |
char_turn =
(Struct.CharacterTurn.set_navigator
- model.char_turn
new_navigator
+ model.char_turn
),
ui =
(Struct.UI.set_previous_action
diff --git a/src/battlemap/src/Update/SelectCharacter.elm b/src/battlemap/src/Update/SelectCharacter.elm
index 0dbe923..2d81939 100644
--- a/src/battlemap/src/Update/SelectCharacter.elm
+++ b/src/battlemap/src/Update/SelectCharacter.elm
@@ -27,7 +27,7 @@ attack_character : (
attack_character model target_char_id target_char =
{model |
char_turn =
- (Struct.CharacterTurn.add_target model.char_turn target_char_id),
+ (Struct.CharacterTurn.add_target target_char_id model.char_turn),
ui =
(Struct.UI.set_previous_action model.ui Nothing)
}
@@ -44,10 +44,6 @@ ctrl_or_focus_character model target_char_id target_char =
{model |
char_turn =
(Struct.CharacterTurn.set_navigator
- (Struct.CharacterTurn.set_active_character
- model.char_turn
- target_char
- )
(Struct.Navigator.new
(Struct.Character.get_location target_char)
(Struct.Statistics.get_movement_points
@@ -60,6 +56,10 @@ ctrl_or_focus_character model target_char_id target_char =
(Dict.values model.characters)
)
)
+ (Struct.CharacterTurn.set_active_character
+ target_char
+ model.char_turn
+ )
),
ui = (Struct.UI.set_previous_action model.ui Nothing)
}
diff --git a/src/battlemap/src/Update/SelectTile.elm b/src/battlemap/src/Update/SelectTile.elm
index 2c0accf..9c0b136 100644
--- a/src/battlemap/src/Update/SelectTile.elm
+++ b/src/battlemap/src/Update/SelectTile.elm
@@ -92,8 +92,8 @@ go_to_tile model navigator loc_ref =
{model |
char_turn =
(Struct.CharacterTurn.set_navigator
- model.char_turn
new_navigator
+ model.char_turn
),
ui =
(Struct.UI.set_previous_action
diff --git a/src/battlemap/src/Update/SwitchWeapon.elm b/src/battlemap/src/Update/SwitchWeapon.elm
new file mode 100644
index 0000000..e958891
--- /dev/null
+++ b/src/battlemap/src/Update/SwitchWeapon.elm
@@ -0,0 +1,94 @@
+module Update.SwitchWeapon exposing (apply_to)
+-- Elm -------------------------------------------------------------------------
+import Dict
+
+-- Battlemap -------------------------------------------------------------------
+import Struct.Battlemap
+import Struct.Character
+import Struct.CharacterTurn
+import Struct.Error
+import Struct.Event
+import Struct.Model
+import Struct.Navigator
+import Struct.Statistics
+import Struct.Weapon
+import Struct.WeaponSet
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+make_it_so : Struct.Model.Type -> Struct.Model.Type
+make_it_so model =
+ case (Struct.CharacterTurn.try_getting_active_character model.char_turn) of
+ (Just char) ->
+ let
+ new_weapons =
+ (Struct.WeaponSet.switch_weapons
+ (Struct.Character.get_weapons char)
+ )
+ new_char = (Struct.Character.set_weapons new_weapons char)
+ in
+ {model |
+ char_turn =
+ (Struct.CharacterTurn.lock_path
+ (Struct.CharacterTurn.set_navigator
+ (Struct.Navigator.new
+ (Struct.Character.get_location new_char)
+ (Struct.Statistics.get_movement_points
+ (Struct.Character.get_statistics new_char)
+ )
+ (Struct.Weapon.get_max_range
+ (Struct.WeaponSet.get_active_weapon new_weapons)
+ )
+ (Struct.Battlemap.get_movement_cost_function
+ model.battlemap
+ (Struct.Character.get_location new_char)
+ (Dict.values model.characters)
+ )
+ )
+ (Struct.CharacterTurn.set_active_character
+ new_char
+ model.char_turn
+ )
+ )
+ )
+ }
+
+ _ ->
+ (Struct.Model.invalidate
+ model
+ (Struct.Error.new
+ Struct.Error.Programming
+ (
+ "CharacterTurn structure in the 'SelectedCharacter' state"
+ ++ " without character being selected."
+ )
+ )
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+apply_to : (
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+apply_to model =
+ case (Struct.CharacterTurn.get_state model.char_turn) of
+ Struct.CharacterTurn.SelectedCharacter ->
+ ((make_it_so model), Cmd.none)
+
+ _ ->
+ (
+ (Struct.Model.invalidate
+ model
+ (Struct.Error.new
+ Struct.Error.Programming
+ (
+ "Attempt to switch weapons as a secondary action or"
+ ++ " without character being selected."
+ )
+ )
+ ),
+ Cmd.none
+ )
diff --git a/src/battlemap/src/View/Footer.elm b/src/battlemap/src/View/Footer.elm
index 470d63a..b868dd7 100644
--- a/src/battlemap/src/View/Footer.elm
+++ b/src/battlemap/src/View/Footer.elm
@@ -28,7 +28,7 @@ end_turn_button =
inventory_button : (Html.Html Struct.Event.Type)
inventory_button =
(Html.button
- [ ]
+ [ (Html.Events.onClick Struct.Event.WeaponSwitchRequest) ]
[ (Html.text "Switch Weapon") ]
)