-
Notifications
You must be signed in to change notification settings - Fork 5
/
activetanker.py
106 lines (89 loc) · 3.07 KB
/
activetanker.py
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
98
99
100
101
102
103
104
105
106
import shootblues
from shootblues.common import log
from shootblues.common.eve import SafeTimer, findModule, getModuleAttributes, activateModule
from shootblues.common.service import forceStart, forceStop
import service
import json
import base
import uix
import blue
prefs = {}
serviceInstance = None
serviceRunning = False
def getPref(key, default):
global prefs
return prefs.get(key, default)
def notifyPrefsChanged(newPrefsJson):
global prefs
prefs = json.loads(newPrefsJson)
RepairTypes = {
"shield": {
"groupName": "Shield Booster",
"attributeName": "shieldBonus"
},
"armor": {
"groupName": "Armor Repair Unit",
"attributeName": "armorDamageAmount"
},
"structure": {
"groupName": "Hull Repair Unit",
"attributeName": "structureDamageAmount"
}
}
class ActiveTankerSvc(service.Service):
__guid__ = "svc.activetanker"
__update_on_reload__ = 0
__exportedcalls__ = {}
__notifyevents__ = [
]
def __init__(self):
service.Service.__init__(self)
self.disabled = False
self.__updateTimer = SafeTimer(500, self.updateHealth)
self.__lastAction = 0
def updateHealth(self):
if self.disabled:
self.__updateTimer = None
return
ship = eve.LocalSvc("godma").GetItem(eve.session.shipid)
if not ship:
return
self.shieldMax = ship.shieldCapacity
self.shield = ship.shieldCharge
self.armorMax = ship.armorHP
self.armor = ship.armorHP - ship.armorDamage
self.structureMax = ship.hp
self.structure = ship.hp - ship.damage
if getPref("KeepShieldsFull", False):
self.repairIfNeeded("shield")
if getPref("KeepArmorFull", False):
self.repairIfNeeded("armor")
if getPref("KeepStructureFull", False):
self.repairIfNeeded("structure")
def repairIfNeeded(self, repairType):
module = self.findRepairModule(repairType)
if module:
attributeName = RepairTypes[repairType]["attributeName"]
repairAmount = getModuleAttributes(module)[attributeName]
threshold = getattr(self, repairType + "Max") - repairAmount
current = getattr(self, repairType)
if current < threshold:
activateModule(module, pulse=True)
def findRepairModule(self, repairType):
groupName = RepairTypes.get(repairType, {}).get("groupName", None)
if not groupName:
log("Invalid repair module type: %r", repairType)
return None
return findModule(groupName=groupName)
def initialize():
global serviceRunning, serviceInstance
serviceRunning = True
serviceInstance = forceStart("activetanker", ActiveTankerSvc)
def __unload__():
global serviceRunning, serviceInstance
if serviceInstance:
serviceInstance.disabled = True
serviceInstance = None
if serviceRunning:
forceStop("activetanker")
serviceRunning = False