summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-04-19 19:00:57 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-04-19 19:00:57 +0200
commit7ad856639b0d8470728d4e5436c3b1152959fd99 (patch)
tree0ccb9f855f0e10182977c03dbff0d908b598ebad /src/shared/struct
parent2ed5b1f48f7784411bcb0983b3490b7c79032eb7 (diff)
[Broken] ...
Diffstat (limited to 'src/shared/struct')
-rw-r--r--src/shared/struct/inventory/shr_equipment.erl17
-rw-r--r--src/shared/struct/inventory/shr_inventory.erl36
-rw-r--r--src/shared/struct/shr_character.erl192
3 files changed, 193 insertions, 52 deletions
diff --git a/src/shared/struct/inventory/shr_equipment.erl b/src/shared/struct/inventory/shr_equipment.erl
index e505d91..11dc19e 100644
--- a/src/shared/struct/inventory/shr_equipment.erl
+++ b/src/shared/struct/inventory/shr_equipment.erl
@@ -91,8 +91,23 @@
(
[
default/0,
- default_unresolved/0,
+ default_unresolved/0
+ ]
+).
+-export
+(
+ [
+ resolve/1,
+ to_unresolved/1,
+ encode/1,
+ decode/1
+ ]
+).
+
+-export
+(
+ [
get_primary_weapon_field/0,
get_secondary_weapon_field/0,
get_armor_field/0,
diff --git a/src/shared/struct/inventory/shr_inventory.erl b/src/shared/struct/inventory/shr_inventory.erl
index 4f64f68..4ea3e7b 100644
--- a/src/shared/struct/inventory/shr_inventory.erl
+++ b/src/shared/struct/inventory/shr_inventory.erl
@@ -1,5 +1,11 @@
-module(shr_inventory).
+-define(WEAPONS_FIELD, <<"wp">>).
+-define(ARMORS_FIELD, <<"ar">>).
+-define(PORTRAITS_FIELD, <<"pt">>).
+-define(GLYPH_BOARDS_FIELD, <<"gb">>).
+-define(GLYPHS_FIELD, <<"gl">>).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -50,6 +56,14 @@
-export
(
[
+ encode/1,
+ decode/1
+ ]
+).
+
+-export
+(
+ [
default/0,
allows_equipment/2,
add_equipment/2,
@@ -373,6 +387,28 @@ ataxia_add_equipment (Eq, Inv) ->
)
}.
+-spec decode (map()) -> type().
+decode (Map) ->
+ #inventory
+ {
+ weapons = ordsets:from_list(maps:get(?WEAPONS_FIELD, Map)),
+ armors = ordsets:from_list(maps:get(?ARMORS_FIELD, Map)),
+ portraits = ordsets:from_list(maps:get(?PORTRAITS_FIELD, Map)),
+ glyph_boards = ordsets:from_list(maps:get(?GLYPH_BOARDS_FIELD, Map)),
+ glyphs = ordsets:from_list(maps:get(?GLYPHS_FIELD, Map))
+ }.
+
+-spec encode (type()) -> {list({binary(), any()})}.
+encode (Inv) ->
+ {
+ [
+ {?WEAPONS_FIELD, ordsets:to_list(Inv#inventory.weapons)},
+ {?ARMORS_FIELD, ordsets:to_list(Inv#inventory.armors)},
+ {?PORTRAITS_FIELD, ordsets:to_list(Inv#inventory.portraits)},
+ {?GLYPH_BOARDS_FIELD, ordsets:to_list(Inv#inventory.glyph_boards)},
+ {?GLYPHS_FIELD, ordsets:to_list(Inv#inventory.glyphs)}
+ ]
+ }.
-spec get_weapons_field () -> non_neg_integer().
get_weapons_field () -> #inventory.weapons.
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.