summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/reply/add_char.erl | 9 | ||||
-rw-r--r-- | src/type/attributes_shim.erl | 47 | ||||
-rw-r--r-- | src/type/character.erl | 12 | ||||
-rw-r--r-- | src/type/character_instance.erl | 32 | ||||
-rw-r--r-- | src/type/character_shim.erl | 11 | ||||
-rw-r--r-- | src/type/statistics.erl | 11 | ||||
-rw-r--r-- | src/type/weapon.erl | 10 | ||||
-rw-r--r-- | src/type/weapon_shim.erl (renamed from src/calc/calc_stats.erl) | 41 |
8 files changed, 121 insertions, 52 deletions
diff --git a/src/reply/add_char.erl b/src/reply/add_char.erl index 959c70f..99b1d25 100644 --- a/src/reply/add_char.erl +++ b/src/reply/add_char.erl @@ -14,6 +14,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% encode (Char, CharInstance, IsEnabled) -> {X, Y} = character_instance:get_location(CharInstance), + Stats = character_instance:get_statistics(CharInstance), + ActWeapon = character_instance:get_active_weapon(CharInstance, Char), + {_MinRg, MaxRg} = weapon:get_ranges(ActWeapon), jiffy:encode ( { @@ -23,12 +26,12 @@ encode (Char, CharInstance, IsEnabled) -> {<<"icon">>, character:get_icon(Char)}, {<<"portrait">>, character:get_portrait(Char)}, {<<"health">>, character_instance:get_current_health(CharInstance)}, - {<<"max_health">>, character:get_max_health(Char)}, {<<"loc_x">>, X}, {<<"loc_y">>, Y}, {<<"team">>, character_instance:get_owner(CharInstance)}, - {<<"mov_pts">>, character:get_movement_points(Char)}, - {<<"atk_rg">>, character:get_attack_range(Char)}, + {<<"max_health">>, statistics:get_health(Stats)}, + {<<"mov_pts">>, statistics:get_movement_points(Stats)}, + {<<"atk_rg">>, MaxRg}, {<<"enabled">>, IsEnabled} ] } diff --git a/src/type/attributes_shim.erl b/src/type/attributes_shim.erl new file mode 100644 index 0000000..6378162 --- /dev/null +++ b/src/type/attributes_shim.erl @@ -0,0 +1,47 @@ +-module(attributes_shim). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + attributes, + { + constitution, + dexterity, + intelligence, + mind, + speed, + strength + } +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + rand/0 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +random_attribute (Min, Max) -> (rand:uniform(Max - Min) - 1) + Min. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +rand () -> + #attributes + { + constitution = random_attribute(10, 100), + dexterity = random_attribute(10, 100), + intelligence = random_attribute(10, 100), + mind = random_attribute(10, 100), + speed = random_attribute(40, 100), + strength = random_attribute(10, 100) + }. diff --git a/src/type/character.erl b/src/type/character.erl index b246038..03906e3 100644 --- a/src/type/character.erl +++ b/src/type/character.erl @@ -11,9 +11,7 @@ name, icon, portrait, - health, - mov_pts, - atk_rg, + attributes, weapons, glyphs, armors @@ -31,9 +29,7 @@ get_name/1, get_icon/1, get_portrait/1, - get_max_health/1, - get_movement_points/1, - get_attack_range/1, + get_attributes/1, get_weapons/1, get_armors/1, get_glyphs/1 @@ -52,9 +48,7 @@ get_id (Char) -> Char#character.id. get_name (Char) -> Char#character.name. get_icon (Char) -> Char#character.icon. get_portrait (Char) -> Char#character.portrait. -get_max_health (Char) -> Char#character.health. -get_movement_points (Char) -> Char#character.mov_pts. -get_attack_range (Char) -> Char#character.atk_rg. +get_attributes (Char) -> Char#character.attributes. get_weapons (Char) -> Char#character.weapons. get_armors (Char) -> Char#character.armors. get_glyphs (Char) -> Char#character.glyphs. diff --git a/src/type/character_instance.erl b/src/type/character_instance.erl index 3fc7171..63045a7 100644 --- a/src/type/character_instance.erl +++ b/src/type/character_instance.erl @@ -12,10 +12,7 @@ health, team, active_wp, - min_dmg, - max_dmg, - hit_chance, - double_hit_chance + stats } ). @@ -29,6 +26,8 @@ get_location/1, get_current_health/1, get_owner/1, + get_active_weapon/2, + get_statistics/1, set_location/3, mod_health/3 ] @@ -69,6 +68,19 @@ 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) -> CharInst#character_instance { @@ -91,26 +103,24 @@ mod_health (CharInst, MaxHealth, HealthMod) -> %%%% Utils new_instance_of (Char, Owner, {X, Y}) -> + {Weapon, _} = character:get_weapons(Char), + Stats = statistics:calc_for(character:get_attributes(Char), Weapon), #character_instance { x = X, y = Y, - health = character:get_max_health(Char), + health = statistics:get_health(Stats), team = Owner, + stats = Stats, active_wp = 0 }. switch_weapon (CharInst, Char) -> {NewWpIndex, Weapon} = get_new_weapon(CharInst, Char), - WeaponProf = character:get_proficiency(Char, weapon:get_type(Weapon)), - {HitChance, DoubleHitChance} = calc_stats:weapon_hit_chances(WeaponProf), CharInst#character_instance { active_wp = NewWpIndex, - min_dmg = calc_stats:weapon_min_damage(Weapon, WeaponProf), - max_dmg = weapon:get_max_damage(Weapon), - hit_chance = HitChance, - double_hit_chance = DoubleHitChance + stats = statistics:calc_for(character:get_attributes(Char), Weapon) }. is_dead (CharInst) -> (CharInst#character_instance.health == 0). diff --git a/src/type/character_shim.erl b/src/type/character_shim.erl index f0f7744..35a0753 100644 --- a/src/type/character_shim.erl +++ b/src/type/character_shim.erl @@ -11,9 +11,7 @@ name, icon, portrait, - health, - mov_pts, - atk_rg, + attributes, weapons, glyphs, armors @@ -41,9 +39,10 @@ generate_char (N) -> name = IDAsString, % Name icon = IDAsString, % Icon portrait = IDAsString, % Portrait - health = (rand:uniform(5) + 1), - mov_pts = (rand:uniform(10) + 10), % Movement Points - atk_rg = (rand:uniform(5) - 1) % Attack Range + attributes = attributes_shim:rand(), + weapons = {weapon_shim:rand(), weapon_shim:rand()}, + glyphs = [], + armors = [] }. generate (0, Result) -> diff --git a/src/type/statistics.erl b/src/type/statistics.erl index bfdb2de..bced96f 100644 --- a/src/type/statistics.erl +++ b/src/type/statistics.erl @@ -48,7 +48,14 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -float_to_int (F) -> trunc(math:ceil(F)). +ceil (F) -> + I = trunc(F), + case (F > I) of + true -> (I + 1); + _ -> I + end. + +float_to_int (F) -> trunc(ceil(F)). min_max (Min, Max, V) -> min(Max, max(Min, V)). average ([]) -> 0; @@ -85,7 +92,7 @@ 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) -> +calc_for (Att, _Wp) -> #statistics { movement_points = gentle_squared_growth(attributes:get_speed(Att)), diff --git a/src/type/weapon.erl b/src/type/weapon.erl index 254184c..b5e5e0c 100644 --- a/src/type/weapon.erl +++ b/src/type/weapon.erl @@ -12,9 +12,7 @@ icon, type, pwr_min, - pwr_max, - prof_max, - rel_attribs + pwr_max } ). @@ -30,9 +28,7 @@ get_icon/1, get_type/1, get_max_power/1, - get_min_power/1, - get_max_prof/1, - get_rel_attribs/1 + get_min_power/1 ] ). @@ -79,8 +75,6 @@ get_icon (Wp) -> Wp#weapon.icon. get_type (Wp) -> Wp#weapon.type. get_max_power (Wp) -> Wp#weapon.pwr_max. get_min_power (Wp) -> Wp#weapon.pwr_min. -get_max_prof (Wp) -> Wp#weapon.prof_max. -get_rel_attribs (Wp) -> Wp#weapon.rel_attribs. get_ranges (Wp) -> ranges_of_type(Wp#weapon.type). get_category (Wp) -> category_of_type(Wp#weapon.type). diff --git a/src/calc/calc_stats.erl b/src/type/weapon_shim.erl index 65a3aec..52d9069 100644 --- a/src/calc/calc_stats.erl +++ b/src/type/weapon_shim.erl @@ -1,4 +1,20 @@ --module(calc_stats). +-module(weapon_shim). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + weapon, + { + id, + name, + icon, + type, + pwr_min, + pwr_max + } +). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -6,10 +22,10 @@ -export ( [ - weapon_min_damage/2, - weapon_hit_chances/1 + rand/0 ] ). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -17,13 +33,12 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -weapon_min_damage (WeaponProf) -> - -weapon_hit_chances (WeaponProf) -> - HitChance = 50 + trunc(math:ceil(WeaponProf / 2)), - case HitChance of - % Not a satisfactory way to handle double hits, as it does not allow - % the players to specialize their characters for it. - N when N > 75 -> {HitChance, 75 - HitChance}; - _ -> {HitChance, 0} - end. +rand() -> + #weapon{ + id = 0, + name = "Shim Weapon 0", + icon = "0", + type = sword, + pwr_min = 10, + pwr_max = 90 + }. |