summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/query/character_turn.erl | 37 | ||||
-rw-r--r-- | src/query/character_turn/handle_character_instance_attacking_2.erl | 7 | ||||
-rw-r--r-- | src/struct/armor.erl | 51 | ||||
-rw-r--r-- | src/struct/attributes.erl | 12 | ||||
-rw-r--r-- | src/struct/battlemap.erl | 25 | ||||
-rw-r--r-- | src/struct/battlemap_instance.erl | 14 | ||||
-rw-r--r-- | src/struct/character.erl | 33 | ||||
-rw-r--r-- | src/struct/character_instance.erl | 126 | ||||
-rw-r--r-- | src/struct/statistics.erl | 92 |
9 files changed, 162 insertions, 235 deletions
diff --git a/src/query/character_turn.erl b/src/query/character_turn.erl index 19b6cff..39154eb 100644 --- a/src/query/character_turn.erl +++ b/src/query/character_turn.erl @@ -142,20 +142,37 @@ handle_character_instance_switching_weapons (QueryState) -> ControlledCharacterInstance = QueryState#query_state.character_instance, ControlledCharacter = character_instance:get_character(ControlledCharacterInstance), + ControlledCharacterAttributes = + character:get_attributes(ControlledCharacter), {PrimaryWeapon, SecondaryWeapon} = character:get_weapons(ControlledCharacter), - QueryState#query_state - { - character_instance = - character_instance:set_character + + UpdatedWeapons = {SecondaryWeapon, PrimaryWeapon}, + UpdatedControlledCharacterStatistics = + statistics:new + ( + ControlledCharacterAttributes, + UpdatedWeapons + ), + UpdatedControlledCharacter = + character:set_statistics + ( + UpdatedControlledCharacterStatistics, + character:set_weapons ( - character:set_weapons - ( - {SecondaryWeapon, PrimaryWeapon}, - ControlledCharacter - ), - ControlledCharacterInstance + ControlledCharacter ) + ), + UpdatedControlledCharacterInstance = + character_instance:set_character + ( + UpdatedControlledCharacter, + ControlledCharacterInstance + ), + + QueryState#query_state + { + character_instance = UpdatedControlledCharacterInstance }. -include("character_turn/handle_character_instance_attacking_2.erl"). diff --git a/src/query/character_turn/handle_character_instance_attacking_2.erl b/src/query/character_turn/handle_character_instance_attacking_2.erl index be2ac99..ecb2a95 100644 --- a/src/query/character_turn/handle_character_instance_attacking_2.erl +++ b/src/query/character_turn/handle_character_instance_attacking_2.erl @@ -58,6 +58,7 @@ handle_parry (AttackerStatistics, DefenderStatistics) -> [] end. +%% FIXME: parry not working as intended handle_attacks ([], _AttackerStatistics, _DefenderStatistics, Results) -> Results; handle_attacks @@ -323,11 +324,11 @@ handle_character_instance_attacking (QueryState, Input) -> Actions = case {CanDefend, CanParry} of {true, true} -> - [second, counter, parry, first]; + [{second, parry}, counter, {first, parry}]; {true, false} -> - [second, counter, first]; + [{second, no_parry}, counter, {fist, no_parry}]; {false, _} -> - [second, first] + [{second, no_parry}, {first, no_parry}] end, Effects = handle_attacks diff --git a/src/struct/armor.erl b/src/struct/armor.erl deleted file mode 100644 index 89df653..0000000 --- a/src/struct/armor.erl +++ /dev/null @@ -1,51 +0,0 @@ --module(armor). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( - armor, - { - id, - name, - icon, - type, - prof_max, - pos_stat_mods, - neg_stat_mods - } -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_id/1, - get_name/1, - get_icon/1, - get_type/1, - get_max_prof/1, - get_pos_stat_mods/1, - get_neg_stat_mods/1 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors -get_id (Ar) -> Ar#armor.id. -get_name (Ar) -> Ar#armor.name. -get_icon (Ar) -> Ar#armor.icon. -get_type (Ar) -> Ar#armor.type. -get_max_prof (Ar) -> Ar#armor.prof_max. -get_pos_stat_mods (Ar) -> Ar#armor.pos_stat_mods. -get_neg_stat_mods (Ar) -> Ar#armor.neg_stat_mods. diff --git a/src/struct/attributes.erl b/src/struct/attributes.erl index b4395cb..022cad2 100644 --- a/src/struct/attributes.erl +++ b/src/struct/attributes.erl @@ -54,15 +54,15 @@ get_mind (Att) -> Att#attributes.mind. get_speed (Att) -> Att#attributes.speed. get_strength (Att) -> Att#attributes.strength. -set_constitution (Att, Val) -> +set_constitution (Val, Att) -> Att#attributes{ constitution = Val }. -set_dexterity (Att, Val) -> +set_dexterity (Val, Att) -> Att#attributes{ dexterity = Val }. -set_intelligence (Att, Val) -> +set_intelligence (Val, Att) -> Att#attributes{ intelligence = Val }. -set_mind (Att, Val) -> +set_mind (Val, Att) -> Att#attributes{ mind = Val }. -set_speed (Att, Val) -> +set_speed (Val, Att) -> Att#attributes{ speed = Val }. -set_strength (Att, Val) -> +set_strength (Val, Att) -> Att#attributes{ strength = Val }. diff --git a/src/struct/battlemap.erl b/src/struct/battlemap.erl index f55aadb..b0eb5fb 100644 --- a/src/struct/battlemap.erl +++ b/src/struct/battlemap.erl @@ -10,8 +10,7 @@ id, width, height, - content, - instances + tile_ids } ). @@ -25,20 +24,9 @@ get_id/1, get_width/1, get_height/1, - list_tiles/1, - get_instances/1 + get_tile_ids/1 ] ). - -%%%% Utils --export -( - [ - cross/5, - dist/2 - ] -). - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -50,11 +38,4 @@ get_id (Battlemap) -> Battlemap#battlemap.id. get_width (Battlemap) -> Battlemap#battlemap.width. get_height (Battlemap) -> Battlemap#battlemap.height. -list_tiles (Battlemap) -> array:sparse_to_list(Battlemap#battlemap.content). -get_instances (Battlemap) -> Battlemap#battlemap.instances. - -%%%% Utils --include("battlemap/cross_5.erl"). - -dist ({OX, OY}, {DX, DY}) -> - (abs(OX - DX) + abs(OY - DY)). +get_tile_ids (Battlemap) -> Battlemap#battlemap.tile_ids. diff --git a/src/struct/battlemap_instance.erl b/src/struct/battlemap_instance.erl index c219a07..9a57d09 100644 --- a/src/struct/battlemap_instance.erl +++ b/src/struct/battlemap_instance.erl @@ -12,7 +12,7 @@ character_instances, players, current_player_turn, - last_player_turn + last_turns_effects } ). @@ -28,13 +28,13 @@ get_character_instances/1, get_players/1, get_current_player_turn/1, - get_last_player_turn/1, + get_last_turns_effects/1, set_battlemap/2, set_character_instances/2, set_players/2, set_current_player_turn/2, - set_last_player_turn/2 + set_last_turns_effects/2 ] ). @@ -60,8 +60,8 @@ get_players (BattlemapInstance) -> get_current_player_turn (BattlemapInstance) -> BattlemapInstance#battlemap_instance.current_player_turn. -get_last_player_turn (BattlemapInstance) -> - BattlemapInstance#battlemap_instance.last_player_turn. +get_last_turns_effects (BattlemapInstance) -> + BattlemapInstance#battlemap_instance.last_turns_effects. set_battlemap (Battlemap, BattlemapInstance) -> BattlemapInstance#battlemap_instance @@ -87,8 +87,8 @@ set_current_player_turn (PlayerTurn, BattlemapInstance) -> current_player_turn = PlayerTurn }. -set_last_player_turn (PlayerTurn, BattlemapInstance) -> +set_last_turns_effects (Effects, BattlemapInstance) -> BattlemapInstance#battlemap_instance { - last_player_turn = PlayerTurn + last_turns_effects = Effects }. diff --git a/src/struct/character.erl b/src/struct/character.erl index 03906e3..0459214 100644 --- a/src/struct/character.erl +++ b/src/struct/character.erl @@ -8,13 +8,14 @@ character, { id, + owner_id, name, icon, portrait, attributes, - weapons, + statistics, glyphs, - armors + weapon_ids } ). @@ -26,13 +27,17 @@ ( [ get_id/1, + get_owner_id/1, get_name/1, get_icon/1, get_portrait/1, get_attributes/1, - get_weapons/1, - get_armors/1, - get_glyphs/1 + get_statistics/1, + get_weapon_ids/1, + get_glyphs/1, + + set_weapon_ids/2, + set_statistics/2 ] ). @@ -45,10 +50,24 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors get_id (Char) -> Char#character.id. +get_owner_id (Char) -> Char#character.owner_id. get_name (Char) -> Char#character.name. get_icon (Char) -> Char#character.icon. get_portrait (Char) -> Char#character.portrait. get_attributes (Char) -> Char#character.attributes. -get_weapons (Char) -> Char#character.weapons. -get_armors (Char) -> Char#character.armors. +get_weapon_ids (Char) -> Char#character.weapon_ids. get_glyphs (Char) -> Char#character.glyphs. + +get_statistics (Char) -> Char#character.statistics. + +set_weapon_ids (WeaponIDs, Char) -> + Char#character + { + weapon_ids = WeaponIDs + }. + +set_statistics (Stats, Char) -> + Char#character + { + statistics = Stats + }. diff --git a/src/struct/character_instance.erl b/src/struct/character_instance.erl index 63045a7..c530424 100644 --- a/src/struct/character_instance.erl +++ b/src/struct/character_instance.erl @@ -7,120 +7,88 @@ ( character_instance, { - x, - y, - health, - team, - active_wp, - stats + character, + location, + current_health, + active } ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors -export ( [ - get_location/1, - get_current_health/1, - get_owner/1, - get_active_weapon/2, - get_statistics/1, - set_location/3, - mod_health/3 + new/2 ] ). -%%%% Utils +%%%% Accessors -export ( [ - new_instance_of/3, - switch_weapon/2, - is_dead/1 % is_alive is reserved. + 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -get_new_weapon(CharInst, Char) -> - case CharInst#character_instance.active_wp of - 0 -> - {_, Weapon} = character:get_weapons(Char), - {1, Weapon}; - - 1 -> - {Weapon, _} = character:get_weapons(Char), - {0, Weapon} - end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Accessors -get_location (CharInst) -> - {CharInst#character_instance.x, CharInst#character_instance.y}. - -get_current_health (CharInst) -> CharInst#character_instance.health. - -get_owner (CharInst) -> CharInst#character_instance.team. - -get_active_weapon (CharInst, Char) -> - case CharInst#character_instance.active_wp of - 0 -> - {_, Weapon} = character:get_weapons(Char), - Weapon; - - 1 -> - {Weapon, _} = character:get_weapons(Char), - Weapon - end. - -get_statistics (CharInst) -> CharInst#character_instance.stats. - -set_location (CharInst, X, Y) -> +get_character (CharInst) -> CharInst#character_instance.character. +get_location (CharInst) -> CharInst#character_instance.location. +get_current_health (CharInst) -> CharInst#character_instance.current_health. +get_is_active (CharInst) -> + ( + CharInst#character_instance.active + and + (CharInst#character_instance.current_health > 0) + ). + +set_character (Char, CharInst) -> CharInst#character_instance { - x = X, - y = Y + character = Char }. -mod_health (CharInst, MaxHealth, HealthMod) -> - NewHealth = (CharInst#character_instance.health + HealthMod), - if - (NewHealth < 0) -> - CharInst#character_instance{ health = 0 }; - - (NewHealth > MaxHealth) -> - CharInst#character_instance{ health = MaxHealth }; - - true -> - CharInst#character_instance{ health = NewHealth } - end. +set_location (Location, CharInst) -> + CharInst#character_instance + { + location = Location + }. -%%%% Utils -new_instance_of (Char, Owner, {X, Y}) -> - {Weapon, _} = character:get_weapons(Char), - Stats = statistics:calc_for(character:get_attributes(Char), Weapon), - #character_instance +set_current_health (Health, CharInst) -> + CharInst#character_instance { - x = X, - y = Y, - health = statistics:get_health(Stats), - team = Owner, - stats = Stats, - active_wp = 0 + current_health = Health }. -switch_weapon (CharInst, Char) -> - {NewWpIndex, Weapon} = get_new_weapon(CharInst, Char), +set_is_active (Active, CharInst) -> CharInst#character_instance { - active_wp = NewWpIndex, - stats = statistics:calc_for(character:get_attributes(Char), Weapon) + active = Active }. -is_dead (CharInst) -> (CharInst#character_instance.health == 0). +%%%% Utils +new (Char, Location) -> + Stats = character:get_statistics(Char), + #character_instance + { + character = Char, + location = Location, + current_health = statistics:get_health(Stats), + active = false + }. diff --git a/src/struct/statistics.erl b/src/struct/statistics.erl index 0668fea..f5a4650 100644 --- a/src/struct/statistics.erl +++ b/src/struct/statistics.erl @@ -34,14 +34,16 @@ get_damage_max/1, get_accuracy/1, get_double_hits/1, - get_critical_hits/1 + get_critical_hits/1, + + get_damages/1 ] ). -export ( [ - calc_for/2 + new/2 ] ). @@ -78,6 +80,12 @@ sudden_exp_growth (V) -> float_to_int(math:pow(4, V / 25)). % Seems too generous, values for attributes below 50 should dip faster and % lower. already_high_slow_growth (V) -> float_to_int(30 * math:log((V + 5)/4)). + +damage_base_modifier (Strength) -> ((math:pow(Strength, 1.8) / 2000.0) - 0.75). + +apply_damage_base_modifier (Modifier, BaseValue) -> + max(0, float_to_int(BaseValue + (BaseValue * Modifier))). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -92,28 +100,36 @@ get_accuracy (Stats) -> Stats#statistics.accuracy. get_double_hits (Stats) -> Stats#statistics.double_hits. get_critical_hits (Stats) -> Stats#statistics.critical_hits. -calc_for (Att, _Wp) -> +get_damages (Stats) -> + { + Stats#statistics.damage_min, + Stats#statistics.damage_max + }. + +new (BaseAttributes, WeaponIDs) -> + {ActiveWeaponID, _} = WeaponIDs, + ActiveWeapon = weapon:from_id(ActiveWeaponID), + {MinDamage, MaxDamage} = weapon:get_damages(ActiveWeapon), + Attributes = weapon:apply_to_attributes(ActiveWeapon, BaseAttributes), + Constitution = attributes:get_constitution(Attributes), + Dexterity = attributes:get_dexterity(Attributes), + Intelligence = attributes:get_intelligence(Attributes), + Mind = attributes:get_mind(Attributes), + Speed = attributes:get_speed(Attributes), + Strength = attributes:get_strength(Attributes), + DamageBaseModifier = damage_base_modifier(Strength), + #statistics { - movement_points = gentle_squared_growth(attributes:get_speed(Att)), - health = gentle_squared_growth(attributes:get_constitution(Att)), - dodges = - min_max + movement_points = + gentle_squared_growth ( - 0, - 100, - sudden_exp_growth - ( - average - ( - [ - attributes:get_dexterity(Att), - attributes:get_mind(Att), - attributes:get_speed(Att) - ] - ) - ) + average([Mind, Constitution, Constitution, Speed, Speed, Speed]) ), + health = + gentle_squared_growth(average([Mind, Constitution, Constitution])), + dodges = + min_max(0, 100, sudden_exp_growth(average([Dexterity, Mind, Speed]))), parries = min_max ( @@ -121,37 +137,13 @@ calc_for (Att, _Wp) -> 75, sudden_exp_growth ( - average - ( - [ - attributes:get_dexterity(Att), - attributes:get_speed(Att), - attributes:get_strength(Att) - ] - ) + average([Dexterity, Intelligence, Speed, Strength]) ) ), - damage_min = 0, - damage_max = 100, - accuracy = - % Hitting should involve this stat (not with this formula though), but - % also the target's dodge stat, with three possible results: - % - Missed - % - Grazed (Halved damage) - % - Hit - % Stat = (target.dodge - char.accuracy) - % Roll = RAND(0, 100) - % if (Roll >= (Stat * 2)): Hit - % else if (Roll >= Stat): Grazed - % else: Missed. - min_max - ( - 0, - 100, - sudden_squared_growth(attributes:get_dexterity(Att)) - ), + damage_min = apply_damage_base_modifier(DamageBaseModifier, MinDamage), + damage_max = apply_damage_base_modifier(DamageBaseModifier, MaxDamage), + accuracy = min_max(0, 100, sudden_squared_growth(Dexterity)), double_hits = - min_max(0, 100, sudden_squared_growth(attributes:get_speed(Att))), - critical_hits = - min_max(0, 100, sudden_squared_growth(attributes:get_intelligence(Att))) + min_max(0, 100, sudden_squared_growth(average([Mind, Speed]))), + critical_hits = min_max(0, 100, sudden_squared_growth(Intelligence)) }. |