Quick actions

cmd+k|ctrl+k

Navigation

Languages

LifeRPG: Mission Payout Calculator

Snippet info

Language

Haskell

Visibility

public

Author

robjameswhitaker

Created

2016-12-01T17:06:20Z

Updated

2016-12-05T22:09:00Z

import Control.Monad.State
--------------------------------------------------------------------------------
-- LifeRPG: Mission Payout Calculator
--
-- A simple calculator to help decide on mission payouts since
-- Difficulty, Urgency, and Fear seem arbitrary. This calculator
-- is based on how long it will take to complete a mission, with
-- small multipliers for difficulty and aversion to the task.
--
-- INSTRUCTIONS:
-- The values for Difficulty and Aversion are:
data Scale = 
  None | Low | Medium | High | VeryHigh | Extreme
-- The values for Time intervals are:
data Time  = 
  Minutes | Hours | Days | Weeks | Months
-- Fill in your own values below, then press Run.  
defineYourMissionBelow                                                     = do
    thisMissionWillTake 20 Minutes
    itsDifficultyIs Low  
    andMyAversionToDoingItIs Medium
--
-- Output: The experience and RP your mission should reward.
--
-- NOTE: Conversion functions can be found at the bottom. These are the
--       functions that handle the scaling of values based on Time, Difficulty,
--       and Aversion. Change them if you want the calculator to scale the
--       results differently.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- PROGRAM START: DO NOT EDIT BELOW THIS POINT, EXCEPT FOR CONVERSION FUNCS.
--------------------------------------------------------------------------------
main = do
  let experience = round $ experience_ $ snd $ runState defineYourMissionBelow empty
  let rp = expToRp experience
  putStr $ "This mission is worth " ++ (show $ min 1462009 experience) ++ " experience "
  putStr $ "and " ++ (show rp) ++ " RP."

data Model = Model
  { experience_ :: Float
  , difficulty_ :: Scale
  , aversion_   :: Scale
  }
  
empty :: Model
empty = Model
  { experience_ = 0
  , difficulty_ = None
  , aversion_ = None
  }

thisMissionWillTake :: Float -> Time -> State Model ()
thisMissionWillTake duration timeInterval = 
    put $  
      empty { experience_ = 
        max baseExp $ duration * minutesConversion * timeMultiplier 
      }
  where 
    baseExp = 80
    minutesConversion =
        case timeInterval of
          Minutes -> 1
          Hours   -> 60
          Days    -> 60 * 24
          Weeks   -> 60 * 24 * 7
          Months  -> 60 * 24 * 30.5

itsDifficultyIs :: Scale -> State Model ()
itsDifficultyIs scale = modify $ \m -> m { experience_ = (experience_ m) * (scaleMultiplier scale) }

andMyAversionToDoingItIs :: Scale -> State Model ()
andMyAversionToDoingItIs = itsDifficultyIs

--------------------------------------------------------------------------------
-- CONVERSION FUNCTIONS
--   
-- Change these if you want to alter how the program scales stuff
--
--------------------------------------------------------------------------------

-- This function converts some Exp value to some RP value
expToRp :: Int -> Int
expToRp experience 
  | experience <= 100     = 2
  | experience <= 250     = 5
  | experience <= 1000    = 10
  | experience <= 10000   = 25
  | experience <= 100000  = 100
  | experience <= 300000  = 250
  | experience <= 1000000 = 500
  | otherwise             = 1000 + expToRp (experience - 1000000)

-- This is the value the number of minutes is multiplied by to get the Exp
-- before Difficulty and Aversion multipliers are applied
timeMultiplier :: Float
timeMultiplier = 6

-- This maps a Difficulty or Aversion value to a multiplier
scaleMultiplier :: Scale -> Float
scaleMultiplier scale = 
    case scale of
        None -> 0.9
        Low -> 1
        Medium -> 1.2
        High -> 1.4
        VeryHigh -> 1.8
        Extreme -> 2
        
INFO