summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-04-10 13:01:12 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-04-10 13:01:12 +0200 |
commit | 1001c3f6cfefd880c1721f2b80c1795197d05365 (patch) | |
tree | 8696137b5684547b80129d308bc854a7e74fa0b0 /src/struct/character_instance.erl | |
parent | d7032b408c5f66a3cb62c44cf0953abe48c39ef9 (diff) |
Changing how the server services are organized...
Diffstat (limited to 'src/struct/character_instance.erl')
-rw-r--r-- | src/struct/character_instance.erl | 160 |
1 files changed, 0 insertions, 160 deletions
diff --git a/src/struct/character_instance.erl b/src/struct/character_instance.erl deleted file mode 100644 index 9b64f9a..0000000 --- a/src/struct/character_instance.erl +++ /dev/null @@ -1,160 +0,0 @@ --module(character_instance). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( - character_instance, - { - character :: character:struct(), - location :: {non_neg_integer(), non_neg_integer()}, - current_health :: non_neg_integer(), - active :: boolean() - } -). - --opaque struct() :: #character_instance{}. - --export_type([struct/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - new/2, - random/4 - ] -). - -%%%% Accessors --export -( - [ - get_character/1, - get_location/1, - get_current_health/1, - get_is_active/1, - - set_character/2, - set_location/2, - set_current_health/2, - set_is_active/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec find_random_location - ( - non_neg_integer(), - non_neg_integer(), - list({non_neg_integer(), non_neg_integer()}) - ) - -> {non_neg_integer(), non_neg_integer()}. -find_random_location (BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> - X = roll:between(0, (BattlemapWidth - 1)), - Y = roll:between(0, (BattlemapHeight - 1)), - - IsForbidden = lists:member({X, Y}, ForbiddenLocations), - - case IsForbidden of - true -> - find_random_location - ( - BattlemapWidth, - BattlemapHeight, - ForbiddenLocations - ); - - _ -> {X, Y} - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_character (struct()) -> character:struct(). -get_character (CharInst) -> CharInst#character_instance.character. - --spec get_location (struct()) -> {non_neg_integer(), non_neg_integer()}. -get_location (CharInst) -> CharInst#character_instance.location. - --spec get_current_health (struct()) -> non_neg_integer(). -get_current_health (CharInst) -> CharInst#character_instance.current_health. - --spec get_is_active (struct()) -> boolean(). -get_is_active (CharInst) -> - ( - CharInst#character_instance.active - and - (CharInst#character_instance.current_health > 0) - ). - --spec set_character (character:struct(), struct()) -> struct(). -set_character (Char, CharInst) -> - CharInst#character_instance - { - character = Char - }. - --spec set_location - ( - {non_neg_integer(), non_neg_integer()}, - struct() - ) - -> struct(). -set_location (Location, CharInst) -> - CharInst#character_instance - { - location = Location - }. - --spec set_current_health (non_neg_integer(), struct()) -> struct(). -set_current_health (Health, CharInst) -> - CharInst#character_instance - { - current_health = Health - }. - --spec set_is_active (boolean(), struct()) -> struct(). -set_is_active (Active, CharInst) -> - CharInst#character_instance - { - active = Active - }. - -%%%% Utils --spec new - ( - character:struct(), - {non_neg_integer(), non_neg_integer()} - ) - -> struct(). -new (Character, Location) -> - CharacterStatistics = character:get_statistics(Character), - #character_instance - { - character = Character, - location = Location, - current_health = statistics:get_health(CharacterStatistics), - active = false - }. - --spec random - ( - character:struct(), - non_neg_integer(), - non_neg_integer(), - list({non_neg_integer(), non_neg_integer()}) - ) - -> struct(). -random (Character, BattlemapWidth, BattlemapHeight, ForbiddenLocations) -> - new - ( - Character, - find_random_location(BattlemapWidth, BattlemapHeight, ForbiddenLocations) - ). |