2023-04-19 05:06:57 +00:00
import { _ as e , c as a , o as s , N as o } from "./chunks/framework.0799945b.js" ; const f = JSON . parse ( '{"title":"Formulas","description":"","frontmatter":{},"headers":[],"relativePath":"guide/important-concepts/formulas.md","lastUpdated":1681880763000}' ) , n = { name : "guide/important-concepts/formulas.md" } , t = o ( ` <h1 id="formulas" tabindex="-1">Formulas <a class="header-anchor" href="#formulas" aria-label="Permalink to "Formulas""> </a></h1><p>Profectus utilizes formulas for various features, such as increasing requirements for repeatables and challenges or determining resource gains in conversions. These formulas often need to be inverted or integrated to enable features like buying multiple levels of a repeatable at once or determining when a conversion will increase resource gains. The Formula class can handle these operations, supporting every function Decimal does, while tracking the operations internally.</p><p>For example, a cost function like <code>Decimal.pow(this.amount, 1.05).times(100)</code> can be represented using a Formula: <code>Formula.variable(this.amount).pow(1.05).times(100)</code>.</p><div class="language-ts"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> myRepeatable </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">createRepeatable</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=></span><span style="color:#A6ACCD;"> (</span><span style="color:#89DDFF;">{</span></span>
2023-04-19 01:05:55 +00:00
< span class = "line" > < span style = "color:#A6ACCD;" > < / s p a n > < s p a n s t y l e = " c o l o r : # F 0 7 1 7 8 ; " > r e q u i r e m e n t s < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > : < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > < / s p a n > < s p a n s t y l e = " c o l o r : # 8 2 A A F F ; " > c r e a t e C o s t R e q u i r e m e n t < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ( < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > ( ) < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > < / s p a n > < s p a n s t y l e = " c o l o r : # C 7 9 2 E A ; " > = & g t ; < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ( < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > { < / s p a n > < / s p a n >
< span class = "line" > < span style = "color:#A6ACCD;" > < / s p a n > < s p a n s t y l e = " c o l o r : # F 0 7 1 7 8 ; " > r e s o u r c e < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > : < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > p o i n t s < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > , < / s p a n > < / s p a n >
< span class = "line" > < span style = "color:#A6ACCD;" > < / s p a n > < s p a n s t y l e = " c o l o r : # F 0 7 1 7 8 ; " > c o s t < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > : < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > F o r m u l a < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > . < / s p a n > < s p a n s t y l e = " c o l o r : # 8 2 A A F F ; " > v a r i a b l e < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ( m y R e p e a t a b l e < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > . < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > a m o u n t ) < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > . < / s p a n > < s p a n s t y l e = " c o l o r : # 8 2 A A F F ; " > p o w < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ( < / s p a n > < s p a n s t y l e = " c o l o r : # F 7 8 C 6 C ; " > 1 . 0 5 < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ) < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > . < / s p a n > < s p a n s t y l e = " c o l o r : # 8 2 A A F F ; " > t i m e s < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ( < / s p a n > < s p a n s t y l e = " c o l o r : # F 7 8 C 6 C ; " > 1 0 0 < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ) < / s p a n > < / s p a n >
< span class = "line" > < span style = "color:#A6ACCD;" > < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > } < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ) ) < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > , < / s p a n > < / s p a n >
< span class = "line" > < span style = "color:#A6ACCD;" > < / s p a n > < s p a n s t y l e = " c o l o r : # F 0 7 1 7 8 ; " > m a x i m i z e < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > : < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > < / s p a n > < s p a n s t y l e = " c o l o r : # F F 9 C A C ; " > t r u e < / s p a n > < / s p a n >
< span class = "line" > < span style = "color:#89DDFF;" > } < / s p a n > < s p a n s t y l e = " c o l o r : # A 6 A C C D ; " > ) ) < / s p a n > < s p a n s t y l e = " c o l o r : # 8 9 D D F F ; " > ; < / s p a n > < / s p a n > < / c o d e > < / p r e > < / d i v > < h 2 i d = " l i m i t a t i o n s " t a b i n d e x = " - 1 " > L i m i t a t i o n s < a c l a s s = " h e a d e r - a n c h o r " h r e f = " # l i m i t a t i o n s " a r i a - l a b e l = " P e r m a l i n k t o & q u o t ; L i m i t a t i o n s & q u o t ; " > < / a > < / h 2 > < h 3 i d = " s i n g l e - v a r i a b l e " t a b i n d e x = " - 1 " > S i n g l e V a r i a b l e < a c l a s s = " h e a d e r - a n c h o r " h r e f = " # s i n g l e - v a r i a b l e " a r i a - l a b e l = " P e r m a l i n k t o & q u o t ; S i n g l e V a r i a b l e & q u o t ; " > < / a > < / h 3 > < p > F o r i n v e r t i n g a n d i n t e g r a t i n g , f o r m u l a s s h o u l d h a v e a s i n g l e v a r i a b l e , w h i c h s e r v e s a s t h e i n p u t . A l t h o u g h o t h e r p a r t s o f t h e f o r m u l a c a n b e c o m p u t e d v a l u e s , t h e y m u s t n o t b e d e p e n d e n t o n t h e i n p u t v a r i a b l e f o r i n v e r t i n g o r i n t e g r a t i n g p u r p o s e s . F o r m u l a s w o r k c o r r e c t l y a s l o n g a s c h a n g i n g o t h e r p a r t s o f t h e f o r m u l a d o e s n & # 3 9 ; t a f f e c t t h e i n p u t v a r i a b l e . < / p > < h 3 i d = " i n v e r t i b i l i t y - a n d - i n t e g r a b i l i t y " t a b i n d e x = " - 1 " > I n v e r t i b i l i t y a n d I n t e g r a b i l i t y < a c l a s s = " h e a d e r - a n c h o r " h r e f = " # i n v e r t i b i l i t y - a n d - i n t e g r a b i l i t y " a r i a - l a b e l = " P e r m a l i n k t o & q u o t ; I n v e r t i b i l i t y a n d I n t e g r a b i l i t y & q u o t ; " > < / a > < / h 3 > < p > C e r t a i n o p e r a t i o n s m a y n o t s u p p o r t i n v e r t i n g o r i n t e g r a t i n g . F u n c t i o n s s u c h a s r o u n d i n g o r c l a m p i n g a r e n o n - i n v e r t i b l e , w h i l e o t h e r s l i k e s u p e r - l o g a r e n o n - i n t e g r a b l e . Y o u m a y o n l y u s e a s i n g l e c o m p l e x o p e r a t i o n i n a d d i t i o n t o a d d , s u b , m u l t , a n d d i v o p e r a t i o n s . F o r f o r m u l a s w i t h t w o c o m p l e x o p e r a t i o n s , a < a h r e f = " # c u s t o m - f o r m u l a s " > c u s t o m f o r m u l a < / a > i s r e q u i r e d . < / p > < h 3 i d = " s p e n d i n g - r e s o u r c e s " t a b i n d e x = " - 1 " > S p e n d i n g R e s o u r c e s < a c l a s s = " h e a d e r - a n c h o r " h r e f = " # s p e n d i n g - r e s o u r c e s " a r i a - l a b e l = " P e r m a l i n k t o & q u o t ; S p e n d i n g R e s o u r c e s & q u o t ; " > < / a > < / h 3 > < p > W h e n w o r k i n g w i t h f o r m u l a s , t h e < c o d e > s p e n d R e s o u r c e s < / c o d e > p r o p e r t y d e t e r m i n e s w h e t h e r t h e f o r m u l a n e e d s t o b e i n v e r t i b l e o r i n t e g r a b l e . T h e p r o p e r t y i s u s e d i n t w o u t i l i t i e s : < a h r e f = " / a p i / m o d u l e s / g a m e / f o r m u l a s / f o r m u l a s # c a l c u l a t e m a x a f f o r d a b l e " > c a l c u l a t e M a x A f f o r d a b l e < / a > a n d < a h r e f = " / a p i / m o d u l e s / g a m e / f o r m u l a s / f o r m u l a s # c a l c u l a t e c o s t " > c a l c u l a t e C o s t < / a > . T h e s e u t i l i t i e s a r e u l t i m a t e l y e m p l o y e d w h e r e v e r f o r m u l a s a r e u s e d , s u c h a s i n c o s t r e q u i r e m e n t s o r c o n v e r s i o n s . < / p > < p > S p e n d i n g r e s o u r c e s r e f e r s t o w h e t h e r m a x a f f o r d a b i l i t y a n d c o s t c a l c u l a t i o n s s h o u l d a c c o u n t f o r r e s o u r c e s s p e n t . I f s p e n d i n g r e s o u r c e s i s s e t t o t r u e , t h e f o r m u l a w i l l b e i n t e g r a t e d a n d i n v e r t e d , a l b e i t w i t h c e r t a i n l i m i t a t i o n s . F o r e x a m p l e , e x p o n e n t i a l m o d i f i e r s a n d s o f t c a p s c a n m a k e a f o r m u l a n o n - i n t e g r a b l e . < / p > < p > C o n s i d e r a s i m p l e f o r m u l a t h a t r e t u r n s t h e i n p u t v a l u e a s t h e c o s t . F o r e x a m p l e , t o m a k e t h r e e s e q u e n t i a l p u r c h a s e s , t h e c o s t s w o u l d b e 1 , 2 , a n d 3 , t o t a l i n g 6 . W h e n r e s o u r c e s a r e s p e n t , m a k i n g t h r e e p u r c h a s e s i n a s i n g l e o p e r a t i o n w i l l c o s t a t o t a l o f 6 . H o w e v e r , i f r e s o u r c e s a r e n o t s p e n t , t h e c o s t w o u l d o n l y b e 3 , t h e c o s t o f t h e l a s t p u r c h a s e . A c c o u n t i n g f o r r e s o u r c e s b e i n g s p e n t m e a n s t h a t t h e o v e r a l l c o s t c a l c u l a t i o n r e f l e c t s t h e c u m u l a t i v e c o s t s o f m u l t i p l e p u r c h a s e s . < / p > < p > I n t e g r a t i o n i n t h i s c o n t e x t i s a n e s t i m a t i o n , a s i t c a l c u l a t e s t h e a r e a u n d e r a c o n t i n u o u s c u r v e , w h i l e a c t u a l p u r c h a s e s o c c u r a t i n t e g e r v a l u e s . T h i s m e a n s t h a t c a l c u l a t i n g m a x a f f o r d a b l e m i g h t o v e r s h o o t a n d t h e c o s t a t t h a t a m o u n t m i g h t u n d e r s h o o t . T o h e l p a d d r e s s t h i s , t h e < c o d e > s u m m e d P u r c h a s e s < / c o d e > p r o p e r t y c a n b e u s e d , w h i c h m a n u a l l y s u m s t h e l a s t X p u r c h a s e s , r e d u c i n g t h e e r r o r m a r g i n . T h i s a l s o e n s u r e s h i g h e r a c c u r a c y w h e n t h e p l a y e r m a k e s f e w e r p u r c h a s e s a t o n c e , w h i c h i s w h e n a c c u r a c y i s m o s t r e l e v a n t . F o r l a r g e r n u m b e r s o f p u r c h a s e s , a s l i g h t o v e r s h o o t o r u n d e r s h o o t i s t y p i c a l l y a c c e p t a b l e . < / p > < h 3 i d = " m o d i f i e r s " t a b i n d e x = " - 1 " > M o d i f i e r s < a c l a s s = " h e a d e r - a n c h o r " h r e f = " # m o d i f i e r s " a r i a - l a b e l = " P e r m a l i n k t o & q u o t ; M o d i f i e r s & q u o t ; " > < / a > < / h 3 > < p > W h e n a p p l y i n g c h a n g e s t o a f o r m u l a u s i n g < a h r e f = " / a p i / m o d u l e s / g a m e / m o d i f i e r s " > m o d i f i e r s < / a > , u s e t h e < c o d e > m o d i f i e r T o F o r m u l a < / c o d e > u t i l i t y t o a p p l y t h e m o d i f i e r w h i l e p r e s e r v i n g i n v e r t i b i l i t y i f t h e m o d i f i e r i s i n v e r t i b l e . < / p > < h 3 i d = " c u s t o m - f o r m u l a s " t a b i n d e x = " - 1 " > C u s t o m F o r m u l a s < a c l a s s = " h e a d e r - a n c h o r " h r e f = " # c u s t o m - f o r m u l a s " a r i a - l a b e l = " P e r m a l i n k t o & q u o t ; C u s t o m F o r m u l a s & q u o t ; " > < / a > < / h 3 > < p > I f t h e e x i s t i n g f u