1- /**
2- * @param {Object } data
3- * @return {Object }
4- */
5- function work ( data ) {
6- return idrinth . calculate (
7- new idrinth . StatSet ( data . attack , data . defense , data . perception , data . level , data . stats ) ,
8- new idrinth . PremiumSet ( data . utym , data . mirele , data . kraken ) ,
9- new idrinth . MultiplierSet ( data . legion , data . mount , data . critchance )
10- ) ;
11- }
121/**
132 * @type {Object }
143 */
154var idrinth = {
5+ /**
6+ * @param {Object } data
7+ * @return {Object }
8+ */
9+ work : function ( data ) {
10+ let calc = new idrinth . Calculator (
11+ new idrinth . StatSet ( data . attack , data . defense , data . perception , data . level , data . stats ) ,
12+ new idrinth . PremiumSet ( data . utym , data . mirele , data . kraken ) ,
13+ new idrinth . MultiplierSet ( data . legion , data . mount , data . critchance )
14+ ) ;
15+ return calc . calculate ( ) ;
16+ } ,
1617 /**
1718 * @class Container for premium
1819 * @constructs {idrinth.PremiumSet}
@@ -30,20 +31,6 @@ var idrinth = {
3031 this . mirele = mirele ;
3132 this . kraken = kraken ;
3233 }
33- /**
34- * @param {Number } damage
35- * @param {String } stat
36- * @param {idrinth.StatSet } stats
37- * @return {Number }
38- */
39- modifyBase ( damage , stat , stats ) { }
40- /**
41- * @param {Number } damage
42- * @param {String } stat
43- * @param {idrinth.StatSet } stats
44- * @return {Number }
45- */
46- modifyTotal ( damage , stat , stats ) { }
4734 } ,
4835 /**
4936 * @class Container for damage multipliers
@@ -62,14 +49,6 @@ var idrinth = {
6249 this . mount = mount ;
6350 this . critchance = critchance ;
6451 }
65- /**
66- * @param {Number } base
67- * @param {String } stat
68- * @param {idrinth.StatSet } stats
69- * @param {idrinth.PremiumSet } premiums
70- * @return {idrinth.StatSet }
71- */
72- modifyTotal ( base , stat , stats , premiums ) { }
7352 } ,
7453 /**
7554 * @class Container for attributes
@@ -92,6 +71,10 @@ var idrinth = {
9271 this . stats = stats ;
9372 this . level = level ;
9473 }
74+ increase ( property ) {
75+ this . stats -= this . getCost ( this [ property ] ) ;
76+ this [ property ] ++ ;
77+ }
9578 /**
9679 * @param {Number } value
9780 * @return {Number }
@@ -105,7 +88,7 @@ var idrinth = {
10588 return Math . max ( number , 0 ) ;
10689 } ;
10790 let modifier = 10000 + Math . floor ( toPositive ( this . level / 500 - 2 ) ) * 1500 ;
108- return 1 + Math . ceil ( toPositive ( value - modifier ) / 1500 ) ;
91+ return 1 + Math . ceil ( toPositive ( value - modifier ) / 1500 ) ;
10992 }
11093 /**
11194 * @return {Array }
@@ -125,16 +108,106 @@ var idrinth = {
125108 }
126109 } ,
127110 /**
128- * @param {StatSet } stat
129- * @param {PremiumSet } premium
130- * @param {MultiplierSet } multiplier
131- * @return {StatSet }
111+ * @class Actual logic for stat calculation
112+ * @constructs {idrinth.Calculator}
132113 */
133- calculate ( stat , premium , multiplier ) {
134- let modified = false ;
135- do {
136- stat . getIncreaseableStats ( ) . forEach ( ) ;
137- } while ( modified )
138- return stat ;
114+ Calculator : class Calculator {
115+ /**
116+ * @constructor
117+ * @param {idrinth.StatSet } stat
118+ * @param {idrinth.PremiumSet } premium
119+ * @param {idrinth.MultiplierSet } multiplier
120+ * @return {StatSet }
121+ */
122+ construct ( stat , premium , multiplier ) {
123+ this . stat = stat ;
124+ this . premium = premium ;
125+ this . multiplier = multiplier ;
126+ }
127+ /**
128+ * @returns {Number }
129+ */
130+ addOnePerc ( ) {
131+ if ( ! this . premium . mirele ) {
132+ return 0 ;
133+ }
134+ return 1.8 * ( this . stats . perception <= 10000 ? 10 : 35 ) * this . multipliers . legion ;
135+ }
136+ /**
137+ * @returns {Number }
138+ */
139+ addOneAttack ( ) {
140+ let base = 4 ;
141+ if ( this . premium . utym ) {
142+ base += ( this . stats . attack <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this . multiplier . legion ;
143+ }
144+ return base ;
145+ }
146+ /**
147+ * @returns {Number }
148+ */
149+ addOneDefense ( ) {
150+ let base = 1 ;
151+ if ( this . premium . utym ) {
152+ base += ( this . stats . defense <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this . multiplier . legion ;
153+ }
154+ if ( this . premium . kraken ) {
155+ base += ( this . stats . defense <= 10000 ? 0.2 : 0.01 ) * 1.8 * this . multiplier . legion ;
156+ }
157+ return base ;
158+ }
159+ /**
160+ * @param {Number } value
161+ * @param {string } added
162+ * @returns {Number }
163+ */
164+ addProcs ( value ) {
165+ let perc = this . stats . perception + 1 ;
166+ return value * ( 1 + this . multiplier . mount + this . multiplier . critchance * 0.01 * Math . floor ( perc < 500000 ? perc / 5000 : 50 + perc / 10000 ) ) ;
167+ }
168+ /**
169+ * @param {Number } value
170+ * @param {string } added
171+ * @returns {Number }
172+ */
173+ addPercProcs ( value ) {
174+ if ( this . premium . utym ) {
175+ value += this . stat . perception <= 10000 ? 0.4 : 0.2 ;
176+ }
177+ if ( this . premium . kraken ) {
178+ value += this . stat . perception <= 10000 ? 1 : 0.1 ;
179+ }
180+ return value ;
181+ }
182+ /**
183+ * @return {Boolean } was modified
184+ */
185+ increase ( ) {
186+ let perc = this . addPercProcs ( this . addProcs ( this . addOnePerc ( ) ) ) / this . stat . getCost ( this . stat . perception ) ;
187+ let defense = this . addProcs ( this . addOneDefense ( ) ) / this . stat . getCost ( this . stat . defense ) ;
188+ let attack = this . addProcs ( this . addOneAttack ( ) ) / this . stat . getCost ( this . stat . attack ) ;
189+ let stat = null ;
190+ if ( perc >= attack && perc >= defense && this . stats . getCost ( this . stats . perception ) < this . stats . stats ) {
191+ stat = "perception" ;
192+ } else if ( attack >= perc && attack >= defense && this . stats . getCost ( this . stats . attack ) < this . stats . stats ) {
193+ stat = "attack" ;
194+ } else if ( defense >= attack && defense >= perc && this . stats . getCost ( this . stats . defense ) < this . stats . stats ) {
195+ stat = "defense" ;
196+ } else {
197+ return false ;
198+ }
199+ this . stats . increase ( stat ) ;
200+ return true ;
201+ }
202+ /**
203+ * @return {StatSet }
204+ */
205+ calculate ( ) {
206+ let modified = false ;
207+ do {
208+ modified = this . increase ( ) ;
209+ } while ( modified )
210+ return stat ;
211+ }
139212 }
140213} ;
0 commit comments