Skip to content

Instantly share code, notes, and snippets.

@Rplus
Last active Dec 15, 2021
Embed
What would you like to do?
Orna GPS RPG view distance
/*
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.
@Rplus
Copy link
Author

Rplus commented Jul 30, 2021

Math.pow (N-1)*1.2
0 180 180
1 216 216
2 259 259
3 311 310
4 373 372
5 447 446
6 537 535
7 644 642
8 773 770
9 928 924
10 1114 1108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment