| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-03-05 17:43:23 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-03-05 17:43:23 +0100 | 
| commit | e5bc1b2d1bfcf5f36bd4f0d567e4ec8e0fb22e85 (patch) | |
| tree | e7637ad94f05b7484baa52f3a333af124c6b293a | |
| parent | 9b73f3efa534fa4dfb8ff832550c1914342ddbb9 (diff) | |
Fixes issues I expected Dialyzer to show me.
| -rw-r--r-- | src/query/character_turn.erl | 2 | ||||
| -rw-r--r-- | src/struct/attack.erl | 7 | ||||
| -rw-r--r-- | src/struct/battle_action.erl | 25 | ||||
| -rw-r--r-- | src/struct/location.erl | 2 | ||||
| -rw-r--r-- | src/struct/turn_result.erl | 11 | 
5 files changed, 26 insertions, 21 deletions
| diff --git a/src/query/character_turn.erl b/src/query/character_turn.erl index f2c7263..c4f9883 100644 --- a/src/query/character_turn.erl +++ b/src/query/character_turn.erl @@ -157,7 +157,7 @@ generate_reply (ClientUpdate) ->        [           [              <<"raw">>, -            list_to_binary(io_lib:format("~p", [ClientUpdate])) +            lists:map(fun turn_result:encode/1, ClientUpdate)           ]        ]     ). diff --git a/src/struct/attack.erl b/src/struct/attack.erl index b27ff48..7b81adc 100644 --- a/src/struct/attack.erl +++ b/src/struct/attack.erl @@ -214,7 +214,7 @@ when     end;  apply_to_healths  ( -   {Attack, Effect}, +   Attack,     AttackerHealth,     DefenderHealth  ) @@ -227,14 +227,15 @@ when        and ((Attack#attack.order == first) or (Attack#attack.order == second))     )  ) -> -   {_Hits, _Critical, Damage} = Effect, +   Damage = Attack#attack.damage, +     case DefenderHealth of        0 ->           {nothing, AttackerHealth, DefenderHealth};        _ ->           { -            {Attack, Effect}, +            Attack,              max(0, (AttackerHealth - Damage)),              DefenderHealth           } diff --git a/src/struct/battle_action.erl b/src/struct/battle_action.erl index b55a92e..0fe780f 100644 --- a/src/struct/battle_action.erl +++ b/src/struct/battle_action.erl @@ -67,9 +67,9 @@ decode_swp_action (_JSONMap) ->     (        character_instance:struct(),        character_instance:struct(), -      list(attack:attack_order_with_pary()) +      list(attack:step())     ) -   -> {list(attack:attack_desc()), non_neg_integer(), non_neg_integer()}. +   -> {list(attack:struct()), non_neg_integer(), non_neg_integer()}.  handle_attack_sequence  (     CharacterInstance, @@ -187,10 +187,7 @@ when is_record(BattleAction, switch_weapon) ->           {character_instance, CharacterInstanceIX, wp1, PrimaryWeaponID}           % ... statistics as well.        ], -      % TODO: hide that into turn_result structs. -      [ -         {switched_weapons, CharacterInstanceIX} -      ], +      [turn_result:new_character_switched_weapons(CharacterInstanceIX)],        Battle,        UpdatedCharacterInstance     }; @@ -234,13 +231,11 @@ when is_record(BattleAction, move) ->        % TODO: hide that into database_diff structs.        [{character_instance, CharacterInstanceIX, loc, NewLocation}],        % TODO: hide that into turn_result structs. -      [ -         {moved, Path, NewLocation} -      ], +      [turn_result:new_character_moved(CharacterInstanceIX, Path, NewLocation)],        Battle,        UpdatedCharacterInstance     }; -handle (Battle, CharacterInstance, _CharacterInstanceIX, BattleAction) +handle (Battle, CharacterInstance, CharacterInstanceIX, BattleAction)  when is_record(BattleAction, attack) ->     Character = character_instance:get_character(CharacterInstance),     TargetIX = BattleAction#attack.target_ix, @@ -292,8 +287,14 @@ when is_record(BattleAction, attack) ->     {        % TODO: hide that into database_diff structs.        [], % TODO -      % TODO: hide that into turn_result structs. -      AttackEffects, +      [ +         turn_result:new_character_attacked +         ( +            CharacterInstanceIX, +            TargetIX, +            AttackEffects +         ) +      ],        UpdatedBattle,        UpdatedCharacterInstance     }. diff --git a/src/struct/location.erl b/src/struct/location.erl index 462dc46..0d5367d 100644 --- a/src/struct/location.erl +++ b/src/struct/location.erl @@ -55,5 +55,5 @@ dist ({OX, OY}, {DX, DY}) ->  -spec encode (type()) -> list(non_neg_integer()).  encode ({X, Y}) -> [X, Y]. --spec decode (list(non_neg_integer)) -> type(). +-spec decode (list(non_neg_integer())) -> type().  decode ([X, Y]) when (is_integer(X) and is_integer(Y)) -> validate({X, Y}). diff --git a/src/struct/turn_result.erl b/src/struct/turn_result.erl index d8ca2be..c5cafcd 100644 --- a/src/struct/turn_result.erl +++ b/src/struct/turn_result.erl @@ -17,7 +17,7 @@     moved,     {        character_instance_ix :: character_instance:id(), -      path :: [direction:enum()], +      path :: list(direction:enum()),        new_location :: location:type()     }  ). @@ -28,7 +28,7 @@     {        attacker_ix :: character_instance:id(),        defender_ix :: character_instance:id(), -      sequence :: list(attack:attack_desc()) +      sequence :: list(attack:struct())     }  ). @@ -85,7 +85,7 @@ new_character_moved (CharacterInstanceIX, Path, NewLocation) ->     (        character_instance:id(),        character_instance:id(), -      list(attack:attack_desc()) +      list(attack:struct())     )     -> struct().  new_character_attacked (AttackerIX, DefenderIX, AttackSequence) -> @@ -145,4 +145,7 @@ encode (TurnResult) when is_record(TurnResult, attacked) ->              {<<"seq">>, EncodedSequence}           ]        } -   ). +   ); +encode (Other) -> +   io:format("~n invalid encode param\"~p\"~n", [Other]), +   true = Other. | 


