summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-04-19 17:58:56 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-04-19 17:58:56 +0200 |
commit | 2ed5b1f48f7784411bcb0983b3490b7c79032eb7 (patch) | |
tree | 7d037a73f9082cc341cec68f2d6c77bfb5acfbaf /src/shared/struct/inventory | |
parent | 743a88c4d2bcddbf7732343179b26f7908ed9f70 (diff) |
[Broken] Starting to add ataxia_set functions...
Diffstat (limited to 'src/shared/struct/inventory')
-rw-r--r-- | src/shared/struct/inventory/shr_equipment.erl | 201 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_inventory.erl | 237 |
2 files changed, 419 insertions, 19 deletions
diff --git a/src/shared/struct/inventory/shr_equipment.erl b/src/shared/struct/inventory/shr_equipment.erl index f5eba8f..e505d91 100644 --- a/src/shared/struct/inventory/shr_equipment.erl +++ b/src/shared/struct/inventory/shr_equipment.erl @@ -56,6 +56,13 @@ set_glyph_board/2, set_glyphs/2, + ataxia_set_primary_weapon/2, + ataxia_set_secondary_weapon/2, + ataxia_set_armor/2, + ataxia_set_portrait/2, + ataxia_set_glyph_board/2, + ataxia_set_glyphs/2, + get_primary_weapon_id/1, get_secondary_weapon_id/1, get_armor_id/1, @@ -68,16 +75,30 @@ set_armor_id/2, set_portrait_id/2, set_glyph_board_id/2, - set_glyph_ids/2 + set_glyph_ids/2, + + ataxia_set_primary_weapon_id/2, + ataxia_set_secondary_weapon_id/2, + ataxia_set_armor_id/2, + ataxia_set_portrait_id/2, + ataxia_set_glyph_board_id/2, + ataxia_set_glyph_ids/2 ] ). -%%%% Accessors +%%%% -export ( [ default/0, - default_unresolved/0 + default_unresolved/0, + + get_primary_weapon_field/0, + get_secondary_weapon_field/0, + get_armor_field/0, + get_portrait_field/0, + get_glyph_board_field/0, + get_glyphs_field/0 ] ). @@ -144,6 +165,19 @@ set_primary_weapon (V, Eq) when is_record(Eq, shr_eq) -> set_primary_weapon (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ primary = shr_weapon:get_id(V) }. +-spec ataxia_set_primary_weapon + (shr_weapon:type(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_primary_weapon (V, Eq) -> + { + set_primary_weapon(V, Eq), + ataxic:update_field + ( + get_primary_weapon_field(), + ataxic:constant(shr_weapon:get_id(V)) + ) + }. + -spec set_secondary_weapon (shr_weapon:type(), type()) -> type(); (shr_weapon:type(), unresolved()) -> unresolved(). @@ -152,6 +186,19 @@ set_secondary_weapon (V, Eq) when is_record(Eq, shr_eq) -> set_secondary_weapon (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ secondary = shr_weapon:get_id(V) }. +-spec ataxia_set_secondary_weapon + (shr_weapon:type(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_secondary_weapon (V, Eq) -> + { + set_secondary_weapon(V, Eq), + ataxic:update_field + ( + get_secondary_weapon_field(), + ataxic:constant(shr_weapon:get_id(V)) + ) + }. + -spec set_armor (shr_armor:type(), type()) -> type(); (shr_armor:type(), unresolved()) -> unresolved(). @@ -160,6 +207,19 @@ set_armor (V, Eq) when is_record(Eq, shr_eq) -> set_armor (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ armor = shr_armor:get_id(V) }. +-spec ataxia_set_armor + (shr_armor:type(), type()) -> {type(), ataxic:basic()}; + (shr_armor:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_armor (V, Eq) -> + { + set_armor(V, Eq), + ataxic:update_field + ( + get_armor_field(), + ataxic:constant(shr_armor:get_id(V)) + ) + }. + -spec set_portrait (shr_portrait:type(), type()) -> type(); (shr_portrait:type(), unresolved()) -> unresolved(). @@ -168,6 +228,19 @@ set_portrait (V, Eq) when is_record(Eq, shr_eq) -> set_portrait (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ portrait = shr_portrait:get_id(V) }. +-spec ataxia_set_portrait + (shr_portrait:type(), type()) -> {type(), ataxic:basic()}; + (shr_portrait:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_portrait (V, Eq) -> + { + set_portrait(V, Eq), + ataxic:update_field + ( + get_portrait_field(), + ataxic:constant(shr_portrait:get_id(V)) + ) + }. + -spec set_glyph_board (shr_glyph_board:type(), type()) -> type(); (shr_glyph_board:type(), unresolved()) -> unresolved(). @@ -176,6 +249,19 @@ set_glyph_board (V, Eq) when is_record(Eq, shr_eq) -> set_glyph_board (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ glyph_board = shr_glyph_board:get_id(V) }. +-spec ataxia_set_glyph_board + (shr_glyph_board:type(), type()) -> {type(), ataxic:basic()}; + (shr_glyph_board:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyph_board (V, Eq) -> + { + set_glyph_board(V, Eq), + ataxic:update_field + ( + get_glyph_board_field(), + ataxic:constant(shr_glyph_board:get_id(V)) + ) + }. + -spec set_glyphs (list(shr_glyph:type()), type()) -> type(); (list(shr_glyph:type()), unresolved()) -> unresolved(). @@ -184,6 +270,19 @@ set_glyphs (V, Eq) when is_record(Eq, shr_eq) -> set_glyphs (V, Eq) when is_record(Eq, shr_eq_ref) -> Eq#shr_eq_ref{ glyphs = lists:map(fun shr_glyph:get_id/1, V) }. +-spec ataxia_set_glyphs + (shr_glyph:type(), type()) -> {type(), ataxic:basic()}; + (shr_glyph:type(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyphs (V, Eq) -> + { + set_glyphs(V, Eq), + ataxic:update_field + ( + get_glyphs_field(), + ataxic:constant(shr_glyph:get_id(V)) + ) + }. + -spec set_primary_weapon_id (shr_weapon:id(), type()) -> type(); (shr_weapon:id(), unresolved()) -> unresolved(). @@ -192,6 +291,19 @@ set_primary_weapon_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_primary_weapon_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ primary = shr_weapon:from_id(V) }. +-spec ataxia_set_primary_weapon_id + (shr_weapon:id(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_primary_weapon_id (V, Eq) -> + { + set_primary_weapon_id(V, Eq), + ataxic:update_field + ( + get_primary_weapon_field(), + ataxic:constant(V) + ) + }. + -spec set_secondary_weapon_id (shr_weapon:id(), type()) -> type(); (shr_weapon:id(), unresolved()) -> unresolved(). @@ -200,6 +312,19 @@ set_secondary_weapon_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_secondary_weapon_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ secondary = shr_weapon:from_id(V) }. +-spec ataxia_set_secondary_weapon_id + (shr_weapon:id(), type()) -> {type(), ataxic:basic()}; + (shr_weapon:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_secondary_weapon_id (V, Eq) -> + { + set_secondary_weapon_id(V, Eq), + ataxic:update_field + ( + get_secondary_weapon_field(), + ataxic:constant(V) + ) + }. + -spec set_armor_id (shr_armor:id(), type()) -> type(); (shr_armor:id(), unresolved()) -> unresolved(). @@ -208,6 +333,19 @@ set_armor_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_armor_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ armor = shr_armor:from_id(V) }. +-spec ataxia_set_armor_id + (shr_armor:id(), type()) -> {type(), ataxic:basic()}; + (shr_armor:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_armor_id (V, Eq) -> + { + set_armor_id(V, Eq), + ataxic:update_field + ( + get_armor_field(), + ataxic:constant(V) + ) + }. + -spec set_portrait_id (shr_portrait:id(), type()) -> type(); (shr_portrait:id(), unresolved()) -> unresolved(). @@ -216,6 +354,19 @@ set_portrait_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_portrait_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ portrait = shr_portrait:from_id(V) }. +-spec ataxia_set_portrait_id + (shr_portrait:id(), type()) -> {type(), ataxic:basic()}; + (shr_portrait:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_portrait_id (V, Eq) -> + { + set_portrait_id(V, Eq), + ataxic:update_field + ( + get_portrait_field(), + ataxic:constant(V) + ) + }. + -spec set_glyph_board_id (shr_glyph_board:id(), type()) -> type(); (shr_glyph_board:id(), unresolved()) -> unresolved(). @@ -224,6 +375,19 @@ set_glyph_board_id (V, Eq) when is_record(Eq, shr_eq_ref) -> set_glyph_board_id (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ glyph_board = shr_glyph_board:from_id(V) }. +-spec ataxia_set_glyph_board_id + (shr_glyph_board:id(), type()) -> {type(), ataxic:basic()}; + (shr_glyph_board:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyph_board_id (V, Eq) -> + { + set_glyph_board_id(V, Eq), + ataxic:update_field + ( + get_glyph_board_field(), + ataxic:constant(V) + ) + }. + -spec set_glyph_ids (list(shr_glyph:id()), type()) -> type(); (list(shr_glyph:id()), unresolved()) -> unresolved(). @@ -232,6 +396,19 @@ set_glyph_ids (V, Eq) when is_record(Eq, shr_eq_ref) -> set_glyph_ids (V, Eq) when is_record(Eq, shr_eq) -> Eq#shr_eq{ glyphs = lists:map(fun shr_glyph:from_id/1, V) }. +-spec ataxia_set_glyph_ids + (shr_glyph:id(), type()) -> {type(), ataxic:basic()}; + (shr_glyph:id(), unresolved()) -> {unresolved(), ataxic:basic()}. +ataxia_set_glyph_ids (V, Eq) -> + { + set_glyph_ids(V, Eq), + ataxic:update_field + ( + get_glyphs_field(), + ataxic:constant(V) + ) + }. + -spec default () -> type(). default () -> #shr_eq @@ -255,3 +432,21 @@ default_unresolved () -> glyph_board = shr_glyph_board:default_id(), glyphs = [] }. + +-spec get_primary_weapon_field () -> non_neg_integer(). +get_primary_weapon_field () -> #shr_eq_ref.primary. + +-spec get_secondary_weapon_field () -> non_neg_integer(). +get_secondary_weapon_field () -> #shr_eq_ref.secondary. + +-spec get_armor_field () -> non_neg_integer(). +get_armor_field () -> #shr_eq_ref.armor. + +-spec get_portrait_field () -> non_neg_integer(). +get_portrait_field () -> #shr_eq_ref.portrait. + +-spec get_glyph_board_field () -> non_neg_integer(). +get_glyph_board_field () -> #shr_eq_ref.glyph_board. + +-spec get_glyphs_field () -> non_neg_integer(). +get_glyphs_field () -> #shr_eq_ref.glyphs. diff --git a/src/shared/struct/inventory/shr_inventory.erl b/src/shared/struct/inventory/shr_inventory.erl index 0670546..4f64f68 100644 --- a/src/shared/struct/inventory/shr_inventory.erl +++ b/src/shared/struct/inventory/shr_inventory.erl @@ -32,11 +32,17 @@ get_glyph_boards/1, get_glyphs/1, - set_weapons/2, - set_armors/2, - set_portraits/2, - set_glyph_boards/2, - set_glyphs/2 + add_weapon/2, + add_armor/2, + add_portrait/2, + add_glyph_board/2, + add_glyph/2, + + ataxia_add_armor/2, + ataxia_add_weapon/2, + ataxia_add_portrait/2, + ataxia_add_glyph_board/2, + ataxia_add_glyph/2 ] ). @@ -46,7 +52,8 @@ [ default/0, allows_equipment/2, - add_equipment/2 + add_equipment/2, + ataxia_add_equipment/2 ] ). @@ -72,20 +79,164 @@ get_glyph_boards (Inv) -> Inv#inventory.glyph_boards. -spec get_glyphs (type()) -> ordsets:ordset(shr_glyph:id()). get_glyphs (Inv) -> Inv#inventory.glyphs. --spec set_weapons (ordsets:ordset(shr_weapon:id()), type()) -> type(). -set_weapons (V, Inv) -> Inv#inventory{ weapons = V }. --spec set_armors (ordsets:ordset(shr_armor:id()), type()) -> type(). -set_armors (V, Inv) -> Inv#inventory{ armors = V }. +-spec add_weapon (shr_weapon:id(), type()) -> type(). +add_weapon (V, Inv) -> Inv#inventory{ weapons = V }. + +-spec add_armor (shr_armor:id(), type()) -> type(). +add_armor (V, Inv) -> Inv#inventory{ armors = V }. + +-spec add_portrait (shr_portrait:id(), type()) -> type(). +add_portrait (V, Inv) -> Inv#inventory{ portraits = V }. + +-spec add_glyph_board (shr_glyph_board:id(), type()) -> type(). +add_glyph_board (V, Inv) -> Inv#inventory{ glyph_boards = V }. + +-spec add_glyph (shr_glyph:id(), type()) -> type(). +add_glyph (V, Inv) -> Inv#inventory{ glyphs = V }. + + +-spec ataxia_add_weapon + ( + shr_weapon:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_weapon (V, Inv) -> + CurrentWeapons = Inv#inventory.weapons, --spec set_portraits (ordsets:ordset(shr_portrait:id()), type()) -> type(). -set_portraits (V, Inv) -> Inv#inventory{ portraits = V }. + case ordsets:is_element(V, CurrentWeapons) of + true -> Inv; + false -> + { + Inv#inventory{ weapons = ordsets:add_element(V, CurrentWeapons) }, + ataxic:update_field + ( + get_weapons_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. --spec set_glyph_boards (ordsets:ordset(shr_glyph_board:id()), type()) -> type(). -set_glyph_boards (V, Inv) -> Inv#inventory{ glyph_boards = V }. +-spec ataxia_add_armor + ( + shr_armor:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_armor (V, Inv) -> + CurrentArmors = Inv#inventory.armors, + + case ordsets:is_element(V, CurrentArmors) of + true -> Inv; + false -> + { + Inv#inventory{ armors = ordsets:add_element(V, CurrentArmors) }, + ataxic:update_field + ( + get_armors_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. + +-spec ataxia_add_portrait + ( + shr_portrait:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_portrait (V, Inv) -> + CurrentPortraits = Inv#inventory.portraits, + + case ordsets:is_element(V, CurrentPortraits) of + true -> Inv; + false -> + { + Inv#inventory + { + portraits = ordsets:add_element(V, CurrentPortraits) + }, + ataxic:update_field + ( + get_portraits_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. + +-spec ataxia_add_glyph_board + ( + shr_glyph_board:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_glyph_board (V, Inv) -> + CurrentGlyphBoards = Inv#inventory.glyph_boards, + + case ordsets:is_element(V, CurrentGlyphBoards) of + true -> Inv; + false -> + { + Inv#inventory + { + glyph_boards = ordsets:add_element(V, CurrentGlyphBoards) + }, + ataxic:update_field + ( + get_glyph_boards_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. + +-spec ataxia_add_glyph + ( + shr_glyph:id(), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_glyph (V, Inv) -> + CurrentGlyphs = Inv#inventory.glyphs, + + case ordsets:is_element(V, CurrentGlyphs) of + true -> Inv; + false -> + { + Inv#inventory{ glyphs = ordsets:add_element(V, CurrentGlyphs) }, + ataxic:update_field + ( + get_glyphs_field(), + ataxic:apply_function + ( + ordsets, + add_element, + [ ataxic:constant(V), ataxic:current_value() ] + ) + ) + } + end. --spec set_glyphs (ordsets:ordset(shr_glyph:id()), type()) -> type(). -set_glyphs (V, Inv) -> Inv#inventory{ glyphs = V }. -spec default () -> type(). default () -> @@ -183,3 +334,57 @@ add_equipment (Eq, Inv) -> shr_equipment:get_glyph_ids(Eq) ) }. + +-spec ataxia_add_equipment + ( + (shr_equipment:type()|shr_equipment:unresolved()), + type() + ) + -> {type(), list(ataxic:basic())}. +ataxia_add_equipment (Eq, Inv) -> + {S0Inv, Ataxic0} = + ataxia_add_weapon(shr_equipment:get_primary_weapon_id(Eq), Inv), + + {S1Inv, Ataxic1} = + ataxia_add_weapon(shr_equipment:get_secondary_weapon_id(Eq), S0Inv), + + {S2Inv, Ataxic2} = ataxia_add_armor(shr_equipment:get_armor_id(Eq), S1Inv), + + {S3Inv, Ataxic3} = + ataxia_add_glyph_board(shr_equipment:get_glyph_board_id(Eq), S2Inv), + + {S4Inv, Ataxic4s} = + lists:foldl + ( + fun (GlyphID, {PrevInv, PrevAtaxic}) -> + {NewInv, NewAtaxic} = ataxia_add_glyph(GlyphID, PrevInv), + {NewInv, [NewAtaxic|PrevAtaxic]} + end, + {S3Inv, []}, + shr_equipment:get_glyph_ids(Eq) + ), + + { + S4Inv, + lists:flatten + ( + [Ataxic0, Ataxic1, Ataxic2, Ataxic3], + lists:flatten(Ataxic4s) + ) + }. + + +-spec get_weapons_field () -> non_neg_integer(). +get_weapons_field () -> #inventory.weapons. + +-spec get_armors_field () -> non_neg_integer(). +get_armors_field () -> #inventory.armors. + +-spec get_portraits_field () -> non_neg_integer(). +get_portraits_field () -> #inventory.portraits. + +-spec get_glyph_boards_field () -> non_neg_integer(). +get_glyph_boards_field () -> #inventory.glyph_boards. + +-spec get_glyphs_field () -> non_neg_integer(). +get_glyphs_field () -> #inventory.glyphs. |