-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTower.js
More file actions
50 lines (44 loc) · 1.37 KB
/
Tower.js
File metadata and controls
50 lines (44 loc) · 1.37 KB
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
'use strict';
StructureTower.prototype.run = function (localDefense) {
let target = localDefense.getBestTarget();
if(target){
this.attack(target);
return;
}
let healTarget = this.room.find(FIND_MY_CREEPS, {
filter: (c) => c.hits < c.hitsMax
})[0];
if(healTarget){
this.heal(healTarget);
return;
}
let emergent = require('creep.utilities').emergentRepair;
let repTarget = this.room.find(FIND_STRUCTURES, {
filter: (s) => emergent(s)
})[0];
if(repTarget){
this.repair(repTarget);
}
};
/**
* Calculates the power of tower on a specific object or location
* @param x {RoomPosition | Object} A Room Object or an object containing one
* @param basePower {number} Constants
* TOWER_POWER_ATTACK, TOWER_POWER_HEAL or TOWER_POWER_REPAIR
* @return {number} Attack, Heal or Repair power on x
*/
StructureTower.prototype.getTowerPower = function (x, basePower) {
let pos = x;
if(!x instanceof RoomPosition){
pos = x.pos;
}
const range = this.pos.getRangeTo(x);
if(range <= TOWER_OPTIMAL_RANGE){
return basePower;
}
if(range >= TOWER_FALLOFF_RANGE){
return (1 - TOWER_FALLOFF) * basePower;
}
return Math.round((1 - TOWER_FALLOFF * (range - TOWER_OPTIMAL_RANGE) /
(TOWER_FALLOFF_RANGE - TOWER_OPTIMAL_RANGE)) * basePower);
};