-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBattles.js
97 lines (85 loc) · 2.27 KB
/
Battles.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
95
96
97
/**
* Commands
* BotStuff - https://github.com/CheeseMuffin/BotStuff
*
* This file contains battling information for BotStuff.
*
* @license MIT license
*/
'use strict';
class Battle {
constructor(room) {
this.room = room;
this.myPokemon = [];
this.num = 0;
this.moves = [];
this.oppMon = null;
}
say(message) {
this.room.say(message);
}
handleRequest(message) {
if (message.side) this.myPokemon = message.side.pokemon;
this.myMon = Math.floor(Math.random() * this.myPokemon.length) + 1;
let order = [1, 2, 3, 4, 5, 6];
order[0] = this.myMon;
order[this.myMon - 1] = 1;
let mon1 = this.myPokemon[this.myMon - 1];
for (let thing in mon1) {
console.log(thing + ":" + mon1[thing]);
}
this.moves = mon1.moves;
this.say("/team " + order.join("") + "|1");
}
move(turn) {
let bestMoveIndex = 0;
let bestpower = this.effectiveBasePower(this.moves[0]);
console.log(this.moves[0] + " " + bestpower);
for (let i = 1; i < this.moves.length; i++) {
let curEffect = this.effectiveBasePower(this.moves[i]);
if (curEffect > bestpower) {
bestpower = curEffect;
bestMoveIndex = i;
}
console.log(this.moves[i] + " " + bestpower + " " + curEffect);
}
this.say("/choose move " + (bestMoveIndex + 1) + "| " + (Math.floor(turn) + 1));
}
effectiveBasePower(move) {
let realMove = Tools.data.moves[Tools.toId(move)];
let realMon = this.myPokemon[this.myMon - 1];
realMon = Tools.data.pokedex[Tools.toId(realMon.ident.substr(4))];
let effectiveness = Tools.effectiveness(realMove.id, this.oppMon);
let basePower = realMove.basePower;
for (let i = 0; i < realMon.types.length; i++) {
if (realMove.type === realMon.types[i]) {
basePower *= 1.5;
break;
}
}
return basePower * effectiveness;
}
handleSwitch(stuff) {
if (stuff.charAt(1) === '2') {
this.oppMon = stuff.substr(5);
console.log(this.oppMon);
}
}
}
class Battles {
constructor() {
this.battles = {};
}
handleRequest(message, room) {
console.log(room.id);
if (!(room.id in this.battles)) this.battles[room.id] = new Battle(room);
this.battles[room.id].handleRequest(message);
}
move(room, turn) {
this.battles[room.id].move(turn);
}
handleSwitch(room, stuff) {
this.battles[room.id].handleSwitch(stuff);
}
}
module.exports = new Battles();