From 70964517f6f2d3bc04a999358215ef8b8d5bd63d Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 2 Nov 2019 22:41:50 +0100 Subject: ... --- src/battle/mechanic/condition/btl_cond_heal.erl | 2 +- src/battle/reply/btl_add_char.erl | 29 +--------- src/battle/struct/btl_character.erl | 8 +-- src/battle/struct/btl_conditions.erl | 71 ++++++++++++------------- 4 files changed, 39 insertions(+), 71 deletions(-) diff --git a/src/battle/mechanic/condition/btl_cond_heal.erl b/src/battle/mechanic/condition/btl_cond_heal.erl index c677d32..d1f6853 100644 --- a/src/battle/mechanic/condition/btl_cond_heal.erl +++ b/src/battle/mechanic/condition/btl_cond_heal.erl @@ -32,4 +32,4 @@ apply (S0Context, _SelfRef, S0Update) -> {_Trigger, _ReadOnlyData, VolatileData} = S0Context, - {VolatileData, S0Update, none}. + {VolatileData, S0Update}. diff --git a/src/battle/reply/btl_add_char.erl b/src/battle/reply/btl_add_char.erl index 556975c..4f0b107 100644 --- a/src/battle/reply/btl_add_char.erl +++ b/src/battle/reply/btl_add_char.erl @@ -12,13 +12,6 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec rank_to_string (btl_character:rank()) -> binary(). -rank_to_string (Rank) -> - case Rank of - optional -> <<"o">>; - target -> <<"t">>; - commander -> <<"c">> - end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -31,30 +24,10 @@ rank_to_string (Rank) -> ) -> {list(any())}. generate (IX, Character, PlayerIX) -> - CharacterPlayerIX = btl_character:get_player_index(Character), - { [ {<<"msg">>, <<"add_char">>}, {<<"ix">>, IX}, - {<<"rnk">>, rank_to_string(btl_character:get_rank(Character))}, - { - <<"hea">>, - btl_character:get_current_health(Character) - }, - {<<"lc">>, shr_location:encode(btl_character:get_location(Character))}, - {<<"pla">>, CharacterPlayerIX}, - { - <<"ena">>, - ( - btl_character:get_is_active(Character) - and (CharacterPlayerIX == PlayerIX) - ) - }, - {<<"dea">>, btl_character:get_is_defeated(Character)}, - { - <<"bas">>, - shr_character:encode(btl_character:get_base_character(Character)) - } + {<<"cha">>, btl_character:encode_for(PlayerIX, Character)} ] }. diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index 30dac93..fa1fcde 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -109,7 +109,7 @@ resolve/2, is_unresolved/1, to_unresolved/1, - encode/2 + encode_for/2 ] ). @@ -583,8 +583,8 @@ get_base_character_field () -> #btl_char_ref.base. -spec get_conditions_field() -> non_neg_integer(). get_conditions_field () -> #btl_char_ref.conditions. --spec encode (non_neg_integer(), unresolved()) -> {list({binary(), any()})}. -encode (RequestingPlayerIX, CharRef) -> +-spec encode_for (non_neg_integer(), unresolved()) -> {list({binary(), any()})}. +encode_for (RequestingPlayerIX, CharRef) -> { [ {?PLAYER_IX_FIELD, CharRef#btl_char_ref.player_ix}, @@ -597,7 +597,7 @@ encode (RequestingPlayerIX, CharRef) -> {?BASE_CHAR_FIELD, shr_character:encode(CharRef#btl_char_ref.base)}, { ?CONDITIONS_FIELD, - btl_conditions:encode + btl_conditions:encode_for ( RequestingPlayerIX, CharRef#btl_char_ref.conditions diff --git a/src/battle/struct/btl_conditions.erl b/src/battle/struct/btl_conditions.erl index d9703fb..564f559 100644 --- a/src/battle/struct/btl_conditions.erl +++ b/src/battle/struct/btl_conditions.erl @@ -191,12 +191,7 @@ compute_next_index (Conditions) -> Result. --spec encode_single - ( - non_neg_integer(), - single() - ) - -> list({binary(), any()}). +-spec encode_single (non_neg_integer(), single()) -> {list({binary(), any()})}. encode_single (IX, Condition) -> Module = shr_condition:get_module @@ -240,15 +235,12 @@ get_relevant_condition_indices(Trigger, Conditions) -> %%%% Accessors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec get_condition (ref(), btl_character_turn_update:type()) -> single(). get_condition ({battle, IX}, Update) -> - orddict:find - ( - IX, - btl_battle:get_conditions(btl_character_turn_update:get_battle(Update)) - ); + Conditions = + btl_battle:get_conditions(btl_character_turn_update:get_battle(Update)), + + orddict:fetch(IX, Conditions#btl_conds.collection); get_condition ({char, CharIX, CondIX}, Update) -> - orddict:find - ( - CondIX, + Conditions = btl_character:get_conditions ( btl_battle:get_character @@ -256,8 +248,9 @@ get_condition ({char, CharIX, CondIX}, Update) -> CharIX, btl_character_turn_update:get_battle(Update) ) - ) - ). + ), + + orddict:fetch(CondIX, Conditions#btl_conds.collection). %%%%%%%%%%%%%%%%%%%% %%%% Visibility %%%% @@ -321,8 +314,8 @@ get_triggers (Condition) -> Condition#btl_cond.triggers. set_triggers (IX, NewTriggers, Conditions) -> CurrentCondition = orddict:fetch(IX, Conditions#btl_conds.collection), CurrentTriggers = CurrentCondition#btl_cond.triggers, - AddedTriggers = ordsets:substract(NewTriggers, CurrentTriggers), - RemovedTriggers = ordsets:substract(CurrentTriggers, NewTriggers), + AddedTriggers = ordsets:subtract(NewTriggers, CurrentTriggers), + RemovedTriggers = ordsets:subtract(CurrentTriggers, NewTriggers), S0FromTrigger = ordsets:fold @@ -380,8 +373,8 @@ set_triggers (IX, NewTriggers, Conditions) -> ataxia_set_triggers (IX, NewTriggers, Conditions) -> CurrentCondition = orddict:fetch(IX, Conditions#btl_conds.collection), CurrentTriggers = CurrentCondition#btl_cond.triggers, - AddedTriggers = ordsets:substract(NewTriggers, CurrentTriggers), - RemovedTriggers = ordsets:substract(CurrentTriggers, NewTriggers), + AddedTriggers = ordsets:subtract(NewTriggers, CurrentTriggers), + RemovedTriggers = ordsets:subtract(CurrentTriggers, NewTriggers), AtaxicFromTriggerParams = [ataxic:constant(IX), ataxic:current_value()], {S0FromTrigger, S0FromTriggerAtaxicUpdates} = @@ -480,7 +473,7 @@ ataxia_set_triggers (IX, NewTriggers, Conditions) -> ataxic:apply_function ( ordsets, - substract, + subtract, [ ataxic:current_value(), ataxic:constant(RemovedTriggers) @@ -599,8 +592,8 @@ apply_to_character {Trigger, ReadOnlyData, S0VolatileData}, fun (IX) -> {char, ActorIX, IX} end, S1Update, - CharacterConditions, - MatchingConditionIndices + MatchingConditionIndices, + CharacterConditions ), {S1VolatileContext, S2Update} @@ -832,20 +825,22 @@ ataxia_remove (IX, S0Conditions) -> S2Conditions, ataxic:sequence ( - ConditionsAtaxicUpdate1, - ataxic:update_field - ( - #btl_conds.collection, - ataxic:apply_function + [ + ConditionsAtaxicUpdate1, + ataxic:update_field ( - orddict, - erase, - [ - ataxic:constant(IX), - ataxic:current_value() - ] + #btl_conds.collection, + ataxic:apply_function + ( + orddict, + erase, + [ + ataxic:constant(IX), + ataxic:current_value() + ] + ) ) - ) + ] ) }. @@ -858,14 +853,14 @@ new () -> from_trigger = orddict:new() }. --spec encode_for (non_neg_integer(), type()) -> list({binary(), any()}). +-spec encode_for (non_neg_integer(), type()) -> list(any()). encode_for (PlayerIX, Conditions) -> lists:filtermap ( fun ({IX, Condition}) -> case Condition#btl_cond.visibility of none -> false; - any -> encode_single(IX, Condition); + all -> encode_single(IX, Condition); {limited, AllowedPlayerIXs} -> case ordsets:is_element(PlayerIX, AllowedPlayerIXs) of false -> false; @@ -873,5 +868,5 @@ encode_for (PlayerIX, Conditions) -> end end end, - orddict:to_list(Conditions) + orddict:to_list(Conditions#btl_conds.collection) ). -- cgit v1.2.3-70-g09d2