Last active
December 15, 2021 20:42
-
-
Save Rplus/f918ea71462560a893050ccece138d7f to your computer and use it in GitHub Desktop.
Orna GPS RPG view distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Orna RPG view distance formula: | |
1. base view distance: 180m | |
2. base factor per item: x1.2 | |
3. base factor per adornment: x1.02 | |
*/ | |
// There are two methods to calculate with factor(1.2): | |
// Method 1: 180 * Math.pow(1.2, N) | |
// Method 2: 1.2 * D(N - 1) | |
// The dfferent are when to use `Math.round` | |
// arr = new Array(11).fill(1).map((i, index) => index) | |
// arr = [0,1,2,3,4,5,6,7,8,9,10]; | |
// method 1 | |
arr.map(i => `${i}: ${~~(180 * Math.pow(1.2, i))}`) | |
/* | |
[ | |
"0: 180", | |
"1: 216", | |
"2: 259", | |
"3: 311", | |
"4: 373", | |
"5: 447", | |
"6: 537", | |
"7: 644", | |
"8: 773", | |
"9: 928", | |
"10: 1114" | |
] | |
*/ | |
// method 2 | |
function getS(n) { | |
if (!n) return 180; | |
n--; | |
return ~~(1.2 * getS(n)); | |
} | |
arr.map(i => `${i}: ${getS(i)}`) | |
/* | |
[ | |
"0: 180", | |
"1: 216", | |
"2: 259", | |
"3: 310", | |
"4: 372", | |
"5: 446", | |
"6: 535", | |
"7: 642", | |
"8: 770", | |
"9: 924", | |
"10: 1108" | |
] | |
*/ | |
// It use method 2 in Orna RPG game to show view distance. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Math.pow
(N-1)*1.2