Skip to content
Newer
Older
100644 71 lines (62 sloc) 2.77 KB
eb4b7b8 @clanehin Package move to Roguestar.Lib.
authored
1 module Roguestar.Lib.CharacterAdvancement
045473d @clanehin Major restructuring of the location system, which doesn't seem to be …
authored
2 (CharacterBumpResult(..),
6c7cb3f @clanehin Make leveling-up work, after touching a planetary anchor or monolith.
authored
3 characterFitness,
4 bumpCharacter,
5 characterLevel,
6 newCharacterLevel,
7 newCharacterClass)
8 where
9
10 import qualified Data.Map as Map
eb4b7b8 @clanehin Package move to Roguestar.Lib.
authored
11 import Roguestar.Lib.CreatureData
12 import Roguestar.Lib.PowerUpData
9195ff6 @clanehin Getting to be a fairly acceptable web game.
authored
13 import Roguestar.Lib.PersistantData
6c7cb3f @clanehin Make leveling-up work, after touching a planetary anchor or monolith.
authored
14
15 data CharacterBumpResult =
16 CharacterAwarded { character_points_awarded :: Integer,
17 character_new :: Creature }
18 | CharacterAdvanced { character_new_level :: Integer,
19 character_new :: Creature }
20 | CharacterForced { character_new_character_class :: CharacterClass,
21 character_new :: Creature }
22
23 -- |
24 -- Increases the character score by the set amount.
25 -- If the score is high enough that the character can advance to the next level,
26 -- this function will apply that advancement.
27 --
045473d @clanehin Major restructuring of the location system, which doesn't seem to be …
authored
28 bumpCharacter :: PowerUpData -> Creature -> CharacterBumpResult
6c7cb3f @clanehin Make leveling-up work, after touching a planetary anchor or monolith.
authored
29 bumpCharacter (ForceCharacter character_class) c =
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
30 if CharacterClass character_class `elem` Map.keys (creature_traits c)
6c7cb3f @clanehin Make leveling-up work, after touching a planetary anchor or monolith.
authored
31 then bumpCharacter (AwardCharacter $ characterFitness new_character - characterFitness c) c
32 else CharacterForced {
33 character_new_character_class = character_class,
34 character_new = new_character }
35 where new_character = applyToCreature character_class c
36 bumpCharacter (AwardCharacter n) c =
37 if fitness_gain >= bumped_score
38 then CharacterAdvanced {
39 character_new_level = characterLevel new_character,
40 character_new = new_character { creature_points = bumped_score - fitness_gain } }
41 else CharacterAwarded {
42 character_points_awarded = n,
43 character_new = c { creature_points = bumped_score } }
44 where bumped_score = creature_points c + n
45 fitness_gain = characterFitness new_character - characterFitness c
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
46 new_character = applyToCreature (Map.keys $ creature_traits c) c
6c7cb3f @clanehin Make leveling-up work, after touching a planetary anchor or monolith.
authored
47
48 newCharacterClass :: CharacterBumpResult -> Maybe CharacterClass
49 newCharacterClass (CharacterForced character_class _) = Just character_class
50 newCharacterClass _ = Nothing
51
52 newCharacterLevel :: CharacterBumpResult -> Maybe Integer
53 newCharacterLevel (CharacterAdvanced new_level _) = Just new_level
54 newCharacterLevel _ = Nothing
55
56 -- |
57 -- Answers the character level. This is the maximum of the number
58 -- of levels the Character has in any class.
59 -- A rather arbitrary (non-representative of game balance)
60 -- measure of Character power.
61 --
62 characterLevel :: Creature -> Integer
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
63 characterLevel = maximum . Map.elems . creature_traits
6c7cb3f @clanehin Make leveling-up work, after touching a planetary anchor or monolith.
authored
64
65 -- |
66 -- Answers the estimated fitness (powerfulness) of the Character.
67 --
68 characterFitness :: Creature -> Integer
392d240 @clanehin Various changes to gameplay and UI for 0.8.
authored
69 characterFitness c = sum $ (Map.elems $ creature_traits c)
6c7cb3f @clanehin Make leveling-up work, after touching a planetary anchor or monolith.
authored
70
Something went wrong with that request. Please try again.