-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpposition.js
94 lines (83 loc) · 2.64 KB
/
Opposition.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var opposition = {};
function Opposition() {
this.slimes = [];
this.items = [];
this.randomMonsters = function(tile, dangerLevel) {
const OOD_DOWN_TRESHOLD = 20;
const OOD_UP_TRESHOLD = 10;
marked = [];
for (let i in monstersData) {
if ((monstersData[i].foundIn.indexOf(tile) != -1 || monstersData[i].foundIn.indexOf("any") != -1) &&
monstersData[i].level >= dangerLevel - OOD_DOWN_TRESHOLD &&
monstersData[i].level <= dangerLevel + OOD_UP_TRESHOLD) {
marked.push(i);
}
}
// failover - no monster selected
if (marked.length === 0) {
for (let i in monstersData) {
marked.push(i);
}
}
var monsters = [];
for (let i = 4; i < 7; i += 1) {
monster = new Slime(marked[Math.floor(Math.random()*marked.length)]);
// assign dice to slimes
/*
if (monster.name === "slime") {
// calculate number of dice assigned
let assignedDice = Math.floor(Math.random() * dangerLevel);
assignedDice = Math.floor(assignedDice / 10);
if (assignedDice > 3) {
assignedDice = 3;
}
// assign dice
if (assignedDice > 0) {
let markedDice = [];
for (let i in itemsData) {
if (itemsData[i].type.indexOf("dice") != -1 &&
itemsData[i].level >= dangerLevel - OOD_DOWN_TRESHOLD &&
itemsData[i].level <= dangerLevel + OOD_UP_TRESHOLD) {
markedDice.push(i);
}
}
for (let i = 0; i < assignedDice; i += 1) {
dice = new Item(marked[Math.floor(Math.random()*markedDice.length)]);
let freeSlots = slime.dice;
}
}
}
*/
monster.id = i;
monsters.push(monster);
}
this.slimes = monsters;
return monsters;
};
this.randomItems = function() {
var items = [];
for (let monster of this.slimes) {
totalChanceSum = 0;
for (let drop of monster.drops) {
totalChanceSum += drop[1]; // should be 100, but for being sure...
}
randomNumber = Math.floor(Math.random() * totalChanceSum);
for (let drop of monster.drops) {
if (randomNumber <= drop[1]) {
newItem = new Item(drop[0]);
items.push(newItem);
break;
}
}
}
this.items = items;
return items;
};
// switch position of two slimes
this.switchSlimes = function(switchPositions, callback) {
var transient = this.slimes[switchPositions[1]];
this.slimes[switchPositions[1]] = this.slimes[switchPositions[0]];
this.slimes[switchPositions[0]] = transient;
callback();
};
}