summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/struct/shr_character.erl')
-rw-r--r--src/shared/struct/shr_character.erl192
1 files changed, 141 insertions, 51 deletions
diff --git a/src/shared/struct/shr_character.erl b/src/shared/struct/shr_character.erl
index f82dc17..133a6c2 100644
--- a/src/shared/struct/shr_character.erl
+++ b/src/shared/struct/shr_character.erl
@@ -1,5 +1,9 @@
-module(shr_character).
+-define(NAME_FIELD, <<"nam">>).
+-define(EQUIPMENT_FIELD, <<"eq">>).
+-define(IS_USING_SECONDARY_FIELD, <<"sec">>).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -22,8 +26,9 @@
is_using_secondary :: boolean(),
statistics :: shr_statistics:type(),
attributes :: shr_attributes:type(),
- unchanging_omnimods :: shr_omnimods:type(),
- omnimods :: shr_omnimods:type()
+ extra_omnimods :: shr_omnimods:type(),
+ omnimods :: shr_omnimods:type(),
+ dirty :: boolean()
}
).
@@ -48,15 +53,18 @@
get_omnimods/1,
set_name/2,
+ ataxia_set_name/2,
set_equipment/2,
- dirty_set_equipment/2,
+ ataxia_set_equipment/3,
set_extra_omnimods/2,
- dirty_set_extra_omnimods/2,
switch_weapons/1,
- dirty_switch_weapons/1
+ ataxia_switch_weapons/1,
+
+ clean/1,
+ is_dirty/1
]
).
@@ -64,7 +72,9 @@
(
[
resolve/2,
- to_unresolved/1
+ to_unresolved/1,
+ encode/1,
+ decode/1
]
).
@@ -80,8 +90,6 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec refresh_omnimods (type()) -> type().
-refresh_omnimods (Char) -> Char.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -99,43 +107,79 @@ set_name (Name, Char) when is_record(Char, shr_char) ->
set_name (Name, Char) when is_record(Char, shr_char_ref) ->
Char#shr_char_ref{ name = Name }.
+-spec ataxia_set_name
+ (binary(), type()) -> {type(), ataxic:basic()};
+ (binary(), unresolved()) -> {unresolved(), ataxic:basic()}.
+ataxia_set_name (Name, Char) ->
+ {
+ set_name(Name, Char),
+ ataxic:update_field
+ (
+ get_name_field(),
+ ataxic:constant(Name)
+ )
+ }.
+
-spec get_equipment
(type()) -> shr_equipment:type();
(unresolved()) -> shr_equipment:unresolved().
get_equipment (#shr_char{ equipment = R }) -> R;
get_equipment (#shr_char_ref{ equipment = R }) -> R.
--spec switch_weapons
- (type()) -> type();
- (unresolved()) -> unresolved().
-switch_weapons (Char) when is_record(Char, shr_char) ->
- refresh_omnimods
+-spec set_equipment
+ (shr_equipment:type(), type()) -> type();
+ (shr_equipment:unresolved(), unresolved()) -> unresolved().
+set_equipment (Eq, Char) when is_record(Char, shr_char) ->
+ Char#shr_char
+ {
+ equipment = Eq,
+ dirty = true
+ };
+set_equipment (EqRef, CharRef) when is_record(CharRef, shr_char_ref) ->
+ CharRef#shr_char_ref{ equipment = EqRef }.
+
+-spec ataxia_set_equipment
+ (shr_equipment:type(), ataxic:basic(), type()) -> {type(), ataxic:basic()};
(
- Char#shr_char
- {
- is_using_secondary = (not Char#shr_char.is_using_secondary)
- }
- );
-switch_weapons (Char) when is_record(Char, shr_char_ref) ->
- Char#shr_char_ref
+ shr_equipment:unresolved(),
+ ataxic:basic(),
+ unresolved()
+ )
+ -> {unresolved(), ataxic:basic()}.
+ataxia_set_equipment (Eq, EqUpdate, Char) ->
{
- is_using_secondary = (not Char#shr_char_ref.is_using_secondary)
+ set_equipment(Eq, Char),
+ ataxic:update_field(get_equipment_field(), EqUpdate)
}.
--spec dirty_switch_weapons
+-spec switch_weapons
(type()) -> type();
(unresolved()) -> unresolved().
-dirty_switch_weapons (Char) when is_record(Char, shr_char) ->
+switch_weapons (Char) when is_record(Char, shr_char) ->
Char#shr_char
{
- is_using_secondary = (not Char#shr_char.is_using_secondary)
+ is_using_secondary = (not Char#shr_char.is_using_secondary),
+ dirty = true
};
-dirty_switch_weapons (Char) when is_record(Char, shr_char_ref) ->
+switch_weapons (Char) when is_record(Char, shr_char_ref) ->
Char#shr_char_ref
{
is_using_secondary = (not Char#shr_char_ref.is_using_secondary)
}.
+-spec ataxia_switch_weapons
+ (type()) -> {type(), ataxic:basic()};
+ (unresolved()) -> {unresolved(), ataxic:basic()}.
+ataxia_switch_weapons (Char) ->
+ {
+ switch_weapons(Char),
+ ataxic:update_field
+ (
+ get_is_using_secondary_field(),
+ ataxic:neg(ataxic:current_value())
+ )
+ }.
+
-spec get_active_weapon (either()) -> shr_weapon:type().
get_active_weapon (#shr_char{ is_using_secondary = B, equipment = E }) ->
case B of
@@ -171,35 +215,32 @@ get_omnimods (Char) -> Char#shr_char.omnimods.
-spec set_extra_omnimods (shr_omnimods:type(), type()) -> type().
set_extra_omnimods (O, Char) ->
- refresh_omnimods(Char#shr_char{ extra_omnimods = O }).
-
--spec dirty_set_extra_omnimods (shr_omnimods:type(), type()) -> type().
-dirty_set_extra_omnimods (O, Char) -> Char#shr_char{ extra_omnimods = O }.
+ Char#shr_char
+ {
+ extra_omnimods = O,
+ dirty = true
+ }.
--spec resolve (shr_omnimods:type(), unresolved()) -> type().
-resolve (LocalOmnimods, CharRef) ->
- ResolvedEquipment = shr_equipment:resolve(CharRef#shr_char_ref.equipment),
- UsingSecondary = CharRef#shr_char_ref.is_using_secondary,
+-spec clean (type()) -> type().
+clean (Char) when Char#shr_char.dirty ->
+ Equipment = Char#shr_char.equipment,
- UnchangingOmnimods =
+ Omnimods =
shr_omnimods:merge
(
- shr_glyph_board:get_omnimods_with_glyphs
+ shr_omnimods:merge
(
- shr_equipment:get_glyphs(ResolvedEquipment),
- shr_equipment:get_glyph_board(ResolvedEquipment)
+ shr_glyph_board:get_omnimods_with_glyphs
+ (
+ shr_equipment:get_glyphs(Equipment),
+ shr_equipment:get_glyph_board(Equipment)
+ ),
+ shr_armor:get_omnimods(shr_equipment:get_armor(Equipment))
),
- get_armor(CharRef)
- ),
-
- Omnimods =
- shr_omnimods:merge
- (
- UnchangingOmnimods,
shr_omnimods:merge
(
- get_active_weapon(CharRef),
- LocalOmnimods
+ shr_weapon:get_omnimods(get_active_weapon(Char)),
+ Char#shr_char.extra_omnimods
)
),
@@ -217,21 +258,70 @@ resolve (LocalOmnimods, CharRef) ->
Omnimods
),
+ Char#shr_char
+ {
+ dirty = false,
+ attributes = Attributes,
+ statistics = Statistics,
+ omnimods = Omnimods
+ };
+clean (Char) -> Char.
+
+-spec is_dirty (type()) -> boolean().
+is_dirty (Char) -> Char#shr_char.dirty.
+
+-spec resolve (shr_omnimods:type(), unresolved()) -> type().
+resolve (LocalOmnimods, CharRef) ->
+ Attributes = shr_attributes:default(),
+
#shr_char
{
name = CharRef#shr_char_ref.name,
- equipment = ResolvedEquipment,
- is_using_secondary = UsingSecondary,
- statistics = Statistics,
+ dirty = true,
+ equipment = shr_equipment:resolve(CharRef#shr_char_ref.equipment),
+ is_using_secondary = CharRef#shr_char_ref.is_using_secondary,
+ statistics = shr_statistics:new_raw(Attributes),
attributes = Attributes,
- unchanging_omnimods = UnchangingOmnimods,
- omnimods = Omnimods
+ omnimods = shr_omnimods:default(),
+ extra_omnimods = LocalOmnimods
}.
+-spec to_unresolved (type()) -> unresolved().
+to_unresolved (Char) ->
+ #shr_char_ref
+ {
+ name = Char#shr_char.name,
+ equipment = shr_equipment:to_unresolved(Char#shr_char.equipment),
+ is_using_secondary = Char#shr_char.is_using_secondary
+ }.
+
+-spec decode (map()) -> unresolved().
+decode (Map) ->
+ #shr_char_ref
+ {
+ name = maps:get(?NAME_FIELD, Map),
+ equipment = shr_equipment:decode(maps:get(?EQUIPMENT_FIELD, Map)),
+ is_using_secondary = maps:get(?IS_USING_SECONDARY_FIELD, Map)
+ }.
+
+-spec encode (unresolved()) -> {list({binary(), any()})}.
+encode (CharRef) ->
+ {
+ [
+ {?NAME_FIELD, CharRef#shr_char_ref.name},
+ {
+ ?EQUIPMENT_FIELD,
+ shr_equipment:encode(CharRef#shr_char_ref.equipment)
+ },
+ {?IS_USING_SECONDARY_FIELD, CharRef#shr_char_ref.is_using_secondary}
+ ]
+ }.
-spec get_name_field() -> non_neg_integer().
get_name_field () -> #shr_char_ref.name.
+
-spec get_equipment_field() -> non_neg_integer().
get_equipment_field () -> #shr_char_ref.equipment.
+
-spec get_is_using_secondary_field() -> non_neg_integer().
get_is_using_secondary_field () -> #shr_char_ref.is_using_secondary.