summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-07-04 16:18:55 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-07-04 16:18:55 +0200 |
commit | 80bac96c93e7141ced7c2a56d9c1f236f304ea93 (patch) | |
tree | 2afbb34b4d72959e540169f4b62addb13fc8c41b | |
parent | cd6754b8b322c1a04758cfed3620abcc557f8fee (diff) |
Had determinism issues with stats.
Server and client (both running on the same machine) can apparently disagree on
the value of ceiling((X^1.8)/20.0), or maybe when calculating an average. I've
just encountered a case where the client said the character had 108 movement
points, whereas the server said they had only 107. As a result, the client
showed a path to the player that the server would not allow.
To fix this, the server's values are sent to the client. This is only
required for fields with values that affect how the client behaves,
i.e., max health and movement points.
-rw-r--r-- | src/battlemap/src/Struct/Character.elm | 33 | ||||
-rw-r--r-- | src/battlemap/src/Struct/Statistics.elm | 24 |
2 files changed, 44 insertions, 13 deletions
diff --git a/src/battlemap/src/Struct/Character.elm b/src/battlemap/src/Struct/Character.elm index f361501..5ff8a60 100644 --- a/src/battlemap/src/Struct/Character.elm +++ b/src/battlemap/src/Struct/Character.elm @@ -58,7 +58,9 @@ type alias PartiallyDecoded = att : Struct.Attributes.Type, awp : Int, swp : Int, - ar : Int + ar : Int, + mvt : Int, + mhp : Int } type Rank = @@ -109,7 +111,14 @@ finish_decoding add_char = location = add_char.lc, health = add_char.hea, attributes = add_char.att, - statistics = (Struct.Statistics.new add_char.att weapon_set armor), + statistics = + (Struct.Statistics.new + add_char.att + weapon_set + armor + add_char.mhp + add_char.mvt + ), player_ix = add_char.pla, enabled = add_char.ena, defeated = add_char.dea, @@ -194,7 +203,14 @@ set_weapons : Struct.WeaponSet.Type -> Type -> Type set_weapons weapons char = {char | weapons = weapons, - statistics = (Struct.Statistics.new char.attributes weapons char.armor) + statistics = + (Struct.Statistics.new + char.attributes + weapons + char.armor + (Struct.Statistics.get_max_health char.statistics) + (Struct.Statistics.get_movement_points char.statistics) + ) } decoder : (Json.Decode.Decoder (Type, Int, Int, Int)) @@ -217,6 +233,8 @@ decoder = |> (Json.Decode.Pipeline.required "awp" Json.Decode.int) |> (Json.Decode.Pipeline.required "swp" Json.Decode.int) |> (Json.Decode.Pipeline.required "ar" Json.Decode.int) + |> (Json.Decode.Pipeline.required "mvt" Json.Decode.int) + |> (Json.Decode.Pipeline.required "mhp" Json.Decode.int) ) ) @@ -232,7 +250,14 @@ fill_missing_equipment awp swp ar char = weapon_set = (Struct.WeaponSet.new awp swp) in {char | - statistics = (Struct.Statistics.new char.attributes weapon_set ar), + statistics = + (Struct.Statistics.new + char.attributes + weapon_set + ar + (Struct.Statistics.get_max_health char.statistics) + (Struct.Statistics.get_movement_points char.statistics) + ), weapons = weapon_set, armor = ar } diff --git a/src/battlemap/src/Struct/Statistics.elm b/src/battlemap/src/Struct/Statistics.elm index 5b7eb87..24634ac 100644 --- a/src/battlemap/src/Struct/Statistics.elm +++ b/src/battlemap/src/Struct/Statistics.elm @@ -113,9 +113,11 @@ new : ( Struct.Attributes.Type -> Struct.WeaponSet.Type -> Struct.Armor.Type -> + Int -> + Int -> Type ) -new att wp_set ar = +new att wp_set ar max_health max_mvt = let active_weapon = (Struct.WeaponSet.get_active_weapon wp_set) actual_att = @@ -132,14 +134,18 @@ new att wp_set ar = dmg_bmod = (damage_base_mod (toFloat strength)) in { - movement_points = - (gentle_squared_growth_f - (average [mind, constitution, constitution, speed, speed, speed]) - ), - max_health = - (gentle_squared_growth_f - (average [constitution, constitution, constitution, mind]) - ), + movement_points = max_mvt, + -- Operation is not deterministic, yet can't afford to differ from the + -- server's value. As a result, we have to rely on the server's value. +-- (gentle_squared_growth_f +-- (average [mind, constitution, constitution, speed, speed, speed]) +-- ), + max_health = max_health, + -- Operation is not deterministic, yet can't afford to differ from the + -- server's value. As a result, we have to rely on the server's value. +-- (gentle_squared_growth_f +-- (average [constitution, constitution, constitution, mind]) +-- ), dodges = (clamp 0 |