summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-04-25 23:39:08 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-04-25 23:39:08 +0200
commit7d428bac2f9d62c5a0e704eb32be869c10fec72e (patch)
tree1c862670601886581cba94a9c31c59ada8020026 /src
parentfa540d6d07e430789809435741e6cd1d98111c50 (diff)
...
Diffstat (limited to 'src')
-rw-r--r--src/battle/mechanic/turn_action/btl_turn_actions_stats_change.erl85
-rw-r--r--src/battle/struct/btl_battle.erl116
-rw-r--r--src/battle/struct/btl_character.erl240
-rw-r--r--src/shared/struct/shr_character.erl1
4 files changed, 238 insertions, 204 deletions
diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_stats_change.erl b/src/battle/mechanic/turn_action/btl_turn_actions_stats_change.erl
deleted file mode 100644
index 5fe5444..0000000
--- a/src/battle/mechanic/turn_action/btl_turn_actions_stats_change.erl
+++ /dev/null
@@ -1,85 +0,0 @@
--module(btl_turn_actions_stats_change).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export
-(
- [
- handle_max_health_changes/2
- ]
-).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec mod_current_health
- (
- non_neg_integer(),
- non_neg_integer(),
- btl_character_turn_update:type()
- )
- -> btl_character_turn_update:type().
-mod_current_health (CurrentMaxHealth, PreviousMaxHealth, Update) ->
- Data = btl_character_turn_update:get_data(Update),
- Character = btl_character_turn_data:get_character(Data),
- CharacterIX = btl_character_turn_data:get_character_ix(Data),
- PreviousHealth = btl_character:get_current_health(Character),
-
- PreviousHealthRatio = (PreviousHealth / PreviousMaxHealth),
- NewHealth =
- min
- (
- CurrentMaxHealth,
- max(1, round(PreviousHealthRatio * CurrentMaxHealth))
- ),
-
- UpdatedCharacter = btl_character:set_current_health(NewHealth, Character),
- UpdatedData = btl_character_turn_data:set_character(UpdatedCharacter, Data),
- S0Update = btl_character_turn_update:set_data(UpdatedData, Update),
-
- DBQuery =
- ataxic:update_field
- (
- btl_battle:get_characters_field(),
- ataxic_sugar:update_orddict_element
- (
- CharacterIX,
- ataxic:update_field
- (
- btl_character:get_current_health_field(),
- ataxic:constant(NewHealth)
- )
- )
- ),
-
- S1Update = btl_character_turn_update:add_to_db(DBQuery, S0Update),
-
- S1Update.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec handle_max_health_changes
- (
- btl_character_current_data:type(),
- btl_character_turn_update:type()
- )
- -> btl_character_turn_update:type().
-handle_max_health_changes (PreviousData, Update) ->
- Data = btl_character_turn_update:get_data(Update),
- CurrentData = btl_character_turn_data:get_character_current_data(Data),
- CurrentStats = btl_character_current_data:get_statistics(CurrentData),
- PreviousStats = btl_character_current_data:get_statistics(PreviousData),
-
- CurrentMaxHealth = shr_statistics:get_health(CurrentStats),
- PreviousMaxHealth = shr_statistics:get_health(PreviousStats),
-
- case (CurrentMaxHealth == PreviousMaxHealth) of
- true -> Update;
- _ -> mod_current_health(CurrentMaxHealth, PreviousMaxHealth, Update)
- end.
diff --git a/src/battle/struct/btl_battle.erl b/src/battle/struct/btl_battle.erl
index 61152cb..01ab65b 100644
--- a/src/battle/struct/btl_battle.erl
+++ b/src/battle/struct/btl_battle.erl
@@ -160,26 +160,7 @@ set_map (Map, Battle) ->
-spec ataxia_set_map (shr_map:type(), type()) -> {type(), ataxic:basic()}.
ataxia_set_map (Map, Battle) ->
- OldRelatedTileIds = Battle#battle.related_tile_ids,
- NewRelatedTileIds = shr_map:get_related_tile_ids(Map),
-
- OrdsetUpdate =
- ataxic_sugar:update_ordset(OldRelatedTileIds, NewRelatedTileIds),
-
- {
- Battle#battle
- {
- map = Map,
- related_tile_ids = NewRelatedTileIds
- },
- ataxic:sequence
- (
- [
- ataxic:update_field(get_map_field(), ataxic:constant(Map)),
- ataxic:update_field(get_related_tile_ids_field(), OrdsetUpdate)
- ]
- )
- }.
+ ataxia_set_map(Map, ataxic:constant(Map), Battle).
-spec ataxia_set_map
(
@@ -230,14 +211,7 @@ set_characters (Characters, Battle) ->
)
-> {type(), ataxic:basic()}.
ataxia_set_characters (Characters, Battle) ->
- {
- Battle#battle { characters = Characters },
- ataxic:update_field
- (
- get_characters_field(),
- ataxic:constant(Characters)
- )
- }.
+ ataxia_set_characters(Characters, ataxic:constant(Characters), Battle).
-spec ataxia_set_characters
(
@@ -248,7 +222,7 @@ ataxia_set_characters (Characters, Battle) ->
-> {type(), ataxic:basic()}.
ataxia_set_characters (Characters, CharactersUpdate, Battle) ->
{
- Battle#battle { characters = Characters },
+ set_characters(Characters, Battle),
ataxic:update_field
(
get_characters_field(),
@@ -277,17 +251,7 @@ set_character (IX, Character, Battle) ->
)
-> {type(), ataxic:basic()}.
ataxia_set_character (IX, Character, Battle) ->
- {
- Battle#battle
- {
- characters = orddict:store(IX, Character, Battle#battle.characters)
- },
- ataxic:update_field
- (
- get_characters_field(),
- ataxic_sugar:update_orddict_element(IX, ataxic:constant(Character))
- )
- }.
+ ataxia_set_character(IX, Character, ataxic:constant(Character), Battle).
-spec ataxia_set_character
(
@@ -299,10 +263,7 @@ ataxia_set_character (IX, Character, Battle) ->
-> {type(), ataxic:basic()}.
ataxia_set_character (IX, Character, CharacterUpdate, Battle) ->
{
- Battle#battle
- {
- characters = orddict:store(IX, Character, Battle#battle.characters)
- },
+ set_character(IX, Character, Battle),
ataxic:update_field
(
get_characters_field(),
@@ -329,17 +290,7 @@ set_players (Players, Battle) ->
)
-> {type(), ataxic:basic()}.
ataxia_set_players (Players, Battle) ->
- {
- Battle#battle
- {
- players = Players
- },
- ataxic:update_field
- (
- get_players_field(),
- ataxic:constant(Players)
- )
- }.
+ ataxia_set_players(Players, ataxic:constant(Players), Battle).
-spec ataxia_set_players
(
@@ -350,10 +301,7 @@ ataxia_set_players (Players, Battle) ->
-> {type(), ataxic:basic()}.
ataxia_set_players (Players, PlayersUpdate, Battle) ->
{
- Battle#battle
- {
- players = Players
- },
+ set_players(Players, Battle),
ataxic:update_field
(
get_players_field(),
@@ -375,14 +323,7 @@ set_related_inventory (Inv, Battle) ->
)
-> {type(), ataxic:basic()}.
ataxia_set_related_inventory (Inv, Battle) ->
- {
- Battle#battle{ related_inventory = Inv },
- ataxic:update_field
- (
- get_related_inventory_field(),
- ataxic:constant(Inv)
- )
- }.
+ ataxia_set_related_inventory(Inv, ataxic:constant(Inv), Battle).
-spec ataxia_set_related_inventory
(
@@ -393,7 +334,7 @@ ataxia_set_related_inventory (Inv, Battle) ->
-> {type(), ataxic:basic()}.
ataxia_set_related_inventory (Inv, InvUpdate, Battle) ->
{
- Battle#battle{ related_inventory = Inv },
+ set_related_inventory(Inv, Battle),
ataxic:update_field(get_related_inventory_field(), InvUpdate)
}.
@@ -412,17 +353,7 @@ set_player (IX, Player, Battle) ->
)
-> {type(), ataxic:basic()}.
ataxia_set_player (IX, Player, Battle) ->
- {
- Battle#battle
- {
- players = orddict:store(IX, Player, Battle#battle.players)
- },
- ataxic:update_field
- (
- get_players_field(),
- ataxic_sugar:update_orddict_element(IX, ataxic:constant(Player))
- )
- }.
+ ataxia_set_player(IX, Player, ataxic:constant(Player), Battle).
-spec ataxia_set_player
(
@@ -434,10 +365,7 @@ ataxia_set_player (IX, Player, Battle) ->
-> {type(), ataxic:basic()}.
ataxia_set_player (IX, Player, PlayerUpdate, Battle) ->
{
- Battle#battle
- {
- players = orddict:store(IX, Player, Battle#battle.players)
- },
+ set_player(IX, Player, Battle),
ataxic:update_field
(
get_players_field(),
@@ -459,17 +387,12 @@ set_current_player_turn (PlayerTurn, Battle) ->
)
-> {type(), ataxic:basic()}.
ataxia_set_current_player_turn (PlayerTurn, Battle) ->
- {
- Battle#battle
- {
- current_player_turn = PlayerTurn
- },
- ataxic:update_field
- (
- get_current_player_turn_field(),
- ataxic:constant(PlayerTurn)
- )
- }.
+ ataxia_set_current_player_turn
+ (
+ PlayerTurn,
+ ataxic:constant(PlayerTurn),
+ Battle
+ ).
-spec ataxia_set_current_player_turn
(
@@ -480,10 +403,7 @@ ataxia_set_current_player_turn (PlayerTurn, Battle) ->
-> {type(), ataxic:basic()}.
ataxia_set_current_player_turn (PlayerTurn, PlayerTurnUpdate, Battle) ->
{
- Battle#battle
- {
- current_player_turn = PlayerTurn
- },
+ set_current_player_turn(PlayerTurn, Battle),
ataxic:update_field
(
get_current_player_turn_field(),
diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl
index ce0b3aa..8ee0169 100644
--- a/src/battle/struct/btl_character.erl
+++ b/src/battle/struct/btl_character.erl
@@ -63,14 +63,14 @@
get_base_character/1,
set_rank/2,
- set_location/2,
+ set_location/3,
set_current_health/2,
set_is_active/2,
set_is_defeated/2,
set_base_character/2,
ataxia_set_rank/2,
- ataxia_set_location/2,
+ ataxia_set_location/3,
ataxia_set_current_health/2,
ataxia_set_is_active/2,
ataxia_set_is_defeated/2,
@@ -101,14 +101,41 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec handle_max_health_change
+ (
+ shr_character:type(),
+ shr_character:type(),
+ integer()
+ )
+ -> {boolean(), integer()}.
+handle_max_health_change (OldBaseChar, NewBaseChar, OldHealth) ->
+ OldMaxHealth =
+ shr_statistics:get_health(shr_character:get_statistics(OldBaseChar)),
+
+ NewMaxHealth =
+ shr_statistics:get_health(shr_character:get_statistics(NewBaseChar)),
+
+ case (OldMaxHealth == NewMaxHealth) of
+ true -> {false, OldMaxHealth, OldHealth};
+ false ->
+ OldHealthRatio = (OldHealth / OldMaxHealth),
+ NewHealth =
+ min
+ (
+ NewMaxHealth,
+ shr_math_util:ceil(OldHealthRatio * NewMaxHealth)
+ ),
+
+ {true, NewHealth}
+ end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-spec get_player_index (either()) -> non_neg_integer().
-get_player_index (#btl_char{ player_ix = R}) -> R;
-get_player_index (#btl_char_ref{ player_ix = R}) -> R.
+get_player_index (#btl_char{ player_ix = R }) -> R;
+get_player_index (#btl_char_ref{ player_ix = R }) -> R.
-spec get_rank (either()) -> rank().
get_rank (#btl_char{ rank = R }) -> R;
@@ -158,23 +185,90 @@ set_rank (Rank, Char) when is_record(Char, btl_char) ->
set_rank (Rank, Char) when is_record(Char, btl_char_ref) ->
Char#btl_char_ref{ rank = Rank }.
-% TODO: This can change current_health.
-% FIXME: Can't do this without giving the new tile omnimods.
+-spec ataxia_set_rank
+ (rank(), type()) -> {type(), ataxic:basic()};
+ (rank(), unresolved()) -> {unresolved(), ataxic:basic()}.
+ataxia_set_rank (Rank, Char) ->
+ {
+ set_rank(Rank, Char),
+ ataxic:update_field
+ (
+ get_rank_field(),
+ ataxic:constant(Rank)
+ )
+ }.
+
-spec set_location
(
{non_neg_integer(), non_neg_integer()},
shr_omnimods:type(),
type()
)
- -> type();
+ -> type().
set_location (Location, LocOmnimods, Char) ->
- BaseCharacter =
- CurrentMaxHealth =
- shr_statistics:get_health
+ CurrentBaseCharacter = Char#btl_char.base,
+ UpdatedBaseCharacter = shr_character:set_extra_omnimods(LocOmnimods),
+
+ case
+ handle_max_health_change
(
- shr_character:get_statistics
+ CurrentBaseCharacter,
+ UpdatedBaseCharacter,
+ Char#btl_char.current_health
)
- Char#btl_char{ location = Location }.
+ of
+ {false, _, _} ->
+ Char#btl_char
+ {
+ location = Location,
+ base = UpdatedBaseCharacter
+ };
+
+ {true, NewHealth} ->
+ Char#btl_char
+ {
+ location = Location,
+ base = UpdatedBaseCharacter,
+ current_health = NewHealth
+ }
+ end.
+
+-spec ataxia_set_location
+ (
+ {non_neg_integer(), non_neg_integer()},
+ shr_omnimods:type(),
+ type()
+ )
+ -> {type(), ataxic:basic()}.
+ataxia_set_location (Location, LocOmnimods, Char) ->
+ CurrentHealth = Char#btl_char.current_health,
+ UpdatedChar = set_location(Location, LocOmnimods, Char),
+ UpdatedCharHealth = UpdatedChar#btl_char.current_health,
+ LocationUpdate =
+ ataxic:update_field
+ (
+ get_location_field(),
+ ataxic:constant(Location)
+ ),
+
+ {
+ UpdatedChar,
+ case (CurrentHealth == UpdatedChar) of
+ true -> LocationUpdate;
+ false ->
+ ataxic:sequence
+ (
+ [
+ ataxic:update_field
+ (
+ get_current_health_field(),
+ ataxic:constant(UpdatedCharHealth)
+ ),
+ LocationUpdate
+ ]
+ )
+ end
+ }.
-spec set_current_health
(integer(), type()) -> type();
@@ -184,6 +278,19 @@ set_current_health (Health, Char) when is_record(Char, btl_char) ->
set_current_health (Health, Char) when is_record(Char, btl_char_ref) ->
Char#btl_char_ref{ current_health = Health }.
+-spec ataxia_set_current_health
+ (integer(), type()) -> {type(), ataxic:basic()};
+ (integer(), unresolved()) -> {unresolved(), ataxic:basic()}.
+ataxia_set_current_health (Health, Char) ->
+ {
+ set_current_health(Health, Char),
+ ataxic:update_field
+ (
+ get_current_health_field(),
+ ataxic:constant(Health)
+ )
+ }.
+
-spec set_is_active
(boolean(), type()) -> type();
(boolean(), unresolved()) -> unresolved().
@@ -192,6 +299,19 @@ set_is_active (Active, Char) when is_record(Char, btl_char) ->
set_is_active (Active, Char) when is_record(Char, btl_char_ref) ->
Char#btl_char_ref{ is_active = Active }.
+-spec ataxia_set_is_active
+ (boolean(), type()) -> {type(), ataxic:basic()};
+ (boolean(), unresolved()) -> {unresolved(), ataxic:basic()}.
+ataxia_set_is_active (Active, Char) ->
+ {
+ set_is_active(Active, Char),
+ ataxic:update_field
+ (
+ get_is_active_field(),
+ ataxic:constant(Active)
+ )
+ }.
+
-spec set_is_defeated
(boolean(), type()) -> type();
(boolean(), unresolved()) -> unresolved().
@@ -200,14 +320,94 @@ set_is_defeated (Defeated, Char) when is_record(Char, btl_char) ->
set_is_defeated (Defeated, Char) when is_record(Char, btl_char_ref) ->
Char#btl_char_ref{ is_defeated = Defeated }.
-% TODO: This can change current_health.
--spec set_base_character
- (shr_character:type(), type()) -> type();
- (shr_character:unresolved(), unresolved()) -> unresolved().
-set_base_character (Base, Char) when is_record(Char, btl_char) ->
- Char#btl_char{ base = Base };
-set_base_character (Base, Char) when is_record(Char, btl_char_ref) ->
- Char#btl_char_ref{ base = Base }.
+-spec ataxia_set_is_defeated
+ (boolean(), type()) -> {type(), ataxic:basic()};
+ (boolean(), unresolved()) -> {unresolved(), ataxic:basic()}.
+ataxia_set_is_defeated (Defeated, Char) ->
+ {
+ set_is_defeated(Defeated, Char),
+ ataxic:update_field
+ (
+ get_is_defeated_field(),
+ ataxic:constant(Defeated)
+ )
+ }.
+
+-spec set_base_character (shr_character:type(), type()) -> type().
+set_base_character (NewBaseCharacter, Char) ->
+ CurrentBaseCharacter = Char#btl_char.base,
+ case
+ handle_max_health_change
+ (
+ CurrentBaseCharacter,
+ NewBaseCharacter,
+ Char#btl_char.current_health
+ )
+ of
+ {false, _, _} ->
+ Char#btl_char
+ {
+ base = NewBaseCharacter
+ };
+
+ {true, NewHealth} ->
+ Char#btl_char
+ {
+ base = NewBaseCharacter,
+ current_health = NewHealth
+ }
+ end.
+
+-spec ataxia_set_base_character
+ (
+ shr_character:type(),
+ ataxic:basic(),
+ type()
+ )
+ -> {type(), ataxic:basic()}.
+ataxia_set_base_character (NewBaseCharacter, BaseCharacterAtaxicUpdate, Char) ->
+ CurrentHealth = Char#btl_char.current_health,
+ UpdatedChar = set_base_character(NewBaseCharacter, Char),
+ UpdatedCharHealth = UpdatedChar#btl_char.current_health,
+ BattleCharacterAtaxicUpdate =
+ ataxic:update_field
+ (
+ get_base_character_field(),
+ BaseCharacterAtaxicUpdate
+ ),
+
+ {
+ UpdatedChar,
+ case (CurrentHealth == UpdatedChar) of
+ true -> BattleCharacterAtaxicUpdate;
+ false ->
+ ataxic:sequence
+ (
+ [
+ ataxic:update_field
+ (
+ get_current_health_field(),
+ ataxic:constant(UpdatedCharHealth)
+ ),
+ BattleCharacterAtaxicUpdate
+ ]
+ )
+ end
+ }.
+
+-spec ataxia_set_base_character
+ (
+ shr_character:type(),
+ type()
+ )
+ -> {type(), ataxic:basic()}.
+ataxia_set_base_character (NewBaseCharacter, Char) ->
+ ataxia_set_base_character
+ (
+ NewBaseCharacter,
+ ataxic:constant(NewBaseCharacter),
+ Char
+ ).
%%%% Utils
-spec new
diff --git a/src/shared/struct/shr_character.erl b/src/shared/struct/shr_character.erl
index 939b502..d5dec75 100644
--- a/src/shared/struct/shr_character.erl
+++ b/src/shared/struct/shr_character.erl
@@ -27,7 +27,6 @@
statistics :: shr_statistics:type(),
attributes :: shr_attributes:type(),
equipment_but_weapons_omnimods :: shr_omnimods:type(),
- % TODO: move this to btl_character instead.
extra_omnimods :: shr_omnimods:type(),
omnimods :: shr_omnimods:type()
}