Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Named group support in DroneHelper

Minimum chance to hit setting for WeaponHelper
  • Loading branch information...
commit f3f54f6177e2043f44e92980b596b759d8c30b51 1 parent 53bad54
K. Gadd authored
3  AutoTargeter/autotargeter.py
View
@@ -247,7 +247,8 @@ def isEligible(self, cachedItem):
(getPref("TargetHostileNPCs", False) and cachedItem.flag in FlagHostileNPC) or
(getPref("TargetHostilePlayers", False) and cachedItem.flag in FlagHostilePlayer) or
(getPref("TargetNeutralPlayers", False) and cachedItem.flag in FlagNeutralPlayer) or
- (getPref("TargetFriendlyPlayers", False) and cachedItem.flag in FlagFriendlyPlayer)
+ (getPref("TargetFriendlyPlayers", False) and cachedItem.flag in FlagFriendlyPlayer) or
+ ((cachedItem.flag is None) and (getPriority(cachedItem.id) > 0))
)
def _DoBallsAdded(self, lst):
137 DroneHelper/dronehelper.py
View
@@ -88,6 +88,7 @@ def __init__(self):
self.__drones = {}
self.__pendingStateChanges = {}
self.__lastAttackOrder = None
+ self.__lastLaunchTimestamp = 0
self.__recalling = set()
self.__recalled = []
self.__numFighters = 0
@@ -106,21 +107,45 @@ def getDistance(self, targetID):
divisor = 1.0
avg = 0
- for id in drones:
+ for id in drones.iterkeys():
avg += ballpark.DistanceBetween(id, targetID)
return avg / divisor
def getDronesInLocalSpace(self):
+ result = {}
+
ballpark = eve.LocalSvc("michelle").GetBallpark()
if ballpark is None:
- return []
+ return result
drones = eve.LocalSvc("michelle").GetDrones()
- return [droneID for droneID in drones if (
- (droneID in ballpark.slimItems) and
- ((drones[droneID].ownerID == eve.session.charid) or (drones[droneID].controllerID == eve.session.shipid))
- )]
+ for droneID in drones.iterkeys():
+ drone = drones[droneID]
+
+ if not ballpark.slimItems.has_key(droneID):
+ continue
+ if drone.ownerID != eve.session.charid:
+ continue
+ if drone.controllerID != eve.session.shipid:
+ continue
+
+ result[droneID] = drone
+
+ return result
+
+ def getDronesInLocalSpaceByGroup(self):
+ dronesInSpace = self.getDronesInLocalSpace()
+ groups = self.getDroneGroups()
+
+ result = {}
+
+ for k in groups.iterkeys():
+ s = set([id for id in groups[k] if dronesInSpace.has_key(id)])
+ if len(s):
+ result[k] = s
+
+ return result
def getDroneControlRange(self):
godma = eve.LocalSvc("godma")
@@ -136,6 +161,54 @@ def getDroneControlRange(self):
) * fighterRangeMultiplier)
return result
+ def getDronesInBay(self):
+ baylist = eve.GetInventoryFromId(eve.session.shipid).ListDroneBay()
+
+ result = {}
+ for i in baylist:
+ result[i.itemID] = i
+
+ return result
+
+ def getDroneGroups(self):
+ result = {}
+
+ droneview = uicore.desktop.FindChild("droneview")
+ if not droneview:
+ return result
+
+ groups = getattr(droneview, "groups", None)
+ if not groups:
+ return result
+
+ dronesInBay = self.getDronesInBay()
+ dronesInSpace = self.getDronesInLocalSpace()
+
+ for k, v in groups.iteritems():
+ ids = v.get("droneIDs", None)
+ if ids:
+ result[k] = tuple([
+ i for i in ids if (
+ dronesInBay.has_key(i) or dronesInSpace.has_key(i)
+ )
+ ])
+ else:
+ result[k] = tuple()
+
+ return result
+
+ def launchNamedGroup(self, name):
+ groups = self.getDroneGroups()
+ ids = groups.get(name, None)
+ if ids and len(ids):
+ self.doLaunch(*ids)
+
+ def recallNamedGroup(self, name):
+ groups = self.getDronesInLocalSpaceByGroup()
+ ids = groups.get(name, None)
+ if ids and len(ids):
+ self.doRecall(*ids)
+
def getCommonTarget(self, filtered=True):
ballpark = eve.LocalSvc("michelle").GetBallpark()
@@ -237,7 +310,8 @@ def filterTargets(self, ids):
if not (id in targetSvc.targets):
continue
- if getFlagName(id) != "HostileNPC":
+ flag = getFlagName(id)
+ if (flag != "HostileNPC") and (flag is not None):
continue
if getPriority(id) < 0:
@@ -285,12 +359,12 @@ def doAttack(self, idleOnly, targetID=None, dronesToAttack=[], oldTarget=None):
else:
targetName = "Unknown"
- drones = self.getDronesInLocalSpace()
+ drones = list(self.getDronesInLocalSpace().keys())
for id in dronesToAttack:
if id not in drones:
drones.append(id)
- for id in list(drones):
+ for id in list(drones):
droneObj = self.getDroneObject(id)
if ((droneObj.state == const.entityDeparting) or
(droneObj.state == const.entityDeparting2) or
@@ -354,7 +428,24 @@ def doRecall(self, *dronesToRecall):
droneObj = self.getDroneObject(droneID)
droneObj.setState(const.entityDeparting, timestamp)
droneObj.actionTimestamp = timestamp
- self.__recalling.add(droneObj)
+ self.__recalling.add(droneObj.id)
+
+ def doLaunch(self, *dronesToLaunch):
+ if self.disabled:
+ return
+
+ dronesToLaunch = list(dronesToLaunch)
+ timestamp = blue.os.GetTime(1)
+
+ #if (timestamp - self.__lastLaunchTimestamp) < ActionThreshold:
+ # return
+
+ dronesInBay = self.getDronesInBay()
+ droneObjs = [dronesInBay[id] for id in dronesToLaunch if dronesInBay.has_key(id)]
+
+ log("Launching %d drone(s)", len(droneObjs))
+ self.__lastLaunchTimestamp = timestamp
+ sm.services["menu"].LaunchDrones(droneObjs)
def updateDrones(self):
if self.disabled:
@@ -374,7 +465,7 @@ def updateDrones(self):
self.__lastAttackOrder = None
timestamp = blue.os.GetTime(1)
- droneIDs = self.getDronesInLocalSpace()
+ droneIDs = set(self.getDronesInLocalSpace().keys())
dronesToRecall = []
dronesToAttack = []
@@ -415,24 +506,18 @@ def updateDrones(self):
redeployAfter = int(float(getPref("RedeployAfterSeconds", 30.0)) * 10000000)
dronesToRelaunch = []
- ts, obj = self.__recalled[0]
- while ts + redeployAfter <= timestamp:
- slimItem = obj.slimItem
- if not slimItem:
- log("Could not get item for id %r", obj.id)
- break
-
- dronesToRelaunch.append(slimItem)
+ ts, id = self.__recalled[0]
+ while ts + redeployAfter <= timestamp:
+ dronesToRelaunch.append(id)
self.__recalled.pop(0)
if len(self.__recalled):
- ts, obj = self.__recalled[0]
+ ts, id = self.__recalled[0]
else:
break
if len(dronesToRelaunch):
- log("Relaunching %d drone(s)", len(dronesToRelaunch))
- sm.services["menu"].LaunchDrones(dronesToRelaunch)
+ self.doLaunch(*dronesToRelaunch)
if len(dronesToRecall):
for id in dronesToRecall:
@@ -478,7 +563,7 @@ def OnDroneStateChange2(self, droneID, oldActivityState, newActivityState, times
if not timestamp:
timestamp = blue.os.GetTime(1)
- dronesInLocal = self.getDronesInLocalSpace()
+ dronesInLocal = set(self.getDronesInLocalSpace().keys())
if droneID not in dronesInLocal:
self.__pendingStateChanges[droneID] = (timestamp, oldActivityState, newActivityState)
return
@@ -512,9 +597,9 @@ def OnDroneControlLost(self, droneID):
drone = self.getDroneObject(droneID)
drone.setState(None, timestamp)
- if drone in self.__recalling:
- self.__recalling.remove(drone)
- self.__recalled.append((timestamp, drone))
+ if drone.id in self.__recalling:
+ self.__recalling.remove(drone.id)
+ self.__recalled.append((timestamp, drone.id))
self.__recalled.sort()
if self.__drones.has_key(droneID):
83 WeaponHelper/WeaponHelperConfig.Designer.cs
View
@@ -23,34 +23,99 @@ partial class WeaponHelperConfig {
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent () {
+ this.groupBox4 = new System.Windows.Forms.GroupBox();
+ this.MinimumChanceToHit = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.PreferMyTargets = new System.Windows.Forms.CheckBox();
+ this.groupBox4.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.MinimumChanceToHit)).BeginInit();
this.SuspendLayout();
//
+ // groupBox4
+ //
+ this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.groupBox4.Controls.Add(this.PreferMyTargets);
+ this.groupBox4.Controls.Add(this.label2);
+ this.groupBox4.Controls.Add(this.MinimumChanceToHit);
+ this.groupBox4.Controls.Add(this.label1);
+ this.groupBox4.Location = new System.Drawing.Point(4, 4);
+ this.groupBox4.Margin = new System.Windows.Forms.Padding(4);
+ this.groupBox4.Name = "groupBox4";
+ this.groupBox4.Padding = new System.Windows.Forms.Padding(4);
+ this.groupBox4.Size = new System.Drawing.Size(277, 82);
+ this.groupBox4.TabIndex = 2;
+ this.groupBox4.TabStop = false;
+ this.groupBox4.Text = "Target Selection";
+ //
+ // MinimumChanceToHit
+ //
+ this.MinimumChanceToHit.Enabled = false;
+ this.MinimumChanceToHit.Location = new System.Drawing.Point(171, 24);
+ this.MinimumChanceToHit.Margin = new System.Windows.Forms.Padding(4);
+ this.MinimumChanceToHit.Name = "MinimumChanceToHit";
+ this.MinimumChanceToHit.Size = new System.Drawing.Size(45, 23);
+ this.MinimumChanceToHit.TabIndex = 1;
+ this.MinimumChanceToHit.Value = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ //
// label1
//
- this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.label1.Location = new System.Drawing.Point(0, 0);
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(214, 26);
this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(300, 300);
- this.label1.TabIndex = 0;
- this.label1.Text = "This script doesn\'t work yet! :-(";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ this.label1.Size = new System.Drawing.Size(21, 16);
+ this.label1.TabIndex = 2;
+ this.label1.Text = "%";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(7, 26);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(163, 16);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "Minimum chance to hit:";
+ //
+ // PreferMyTargets
+ //
+ this.PreferMyTargets.AutoSize = true;
+ this.PreferMyTargets.Checked = true;
+ this.PreferMyTargets.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.PreferMyTargets.Location = new System.Drawing.Point(10, 54);
+ this.PreferMyTargets.Name = "PreferMyTargets";
+ this.PreferMyTargets.Size = new System.Drawing.Size(263, 20);
+ this.PreferMyTargets.TabIndex = 4;
+ this.PreferMyTargets.Text = "Prefer targets I\'m already attacking";
+ this.PreferMyTargets.UseVisualStyleBackColor = true;
//
// WeaponHelperConfig
//
- this.Controls.Add(this.label1);
+ this.Controls.Add(this.groupBox4);
this.Font = new System.Drawing.Font("MS Reference Sans Serif", 9.75F);
this.Margin = new System.Windows.Forms.Padding(2);
- this.MinimumSize = new System.Drawing.Size(200, 85);
+ this.MinimumSize = new System.Drawing.Size(285, 100);
this.Name = "WeaponHelperConfig";
- this.Size = new System.Drawing.Size(300, 300);
+ this.Size = new System.Drawing.Size(285, 100);
+ this.groupBox4.ResumeLayout(false);
+ this.groupBox4.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.MinimumChanceToHit)).EndInit();
this.ResumeLayout(false);
}
#endregion
+ private System.Windows.Forms.GroupBox groupBox4;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.NumericUpDown MinimumChanceToHit;
private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.CheckBox PreferMyTargets;
+
}
2  WeaponHelper/WeaponHelperConfig.cs
View
@@ -16,6 +16,8 @@ public WeaponHelperConfig (WeaponHelper script)
InitializeComponent();
Prefs = new IBoundMember[] {
+ BoundMember.New(() => PreferMyTargets.Checked),
+ BoundMember.New(() => MinimumChanceToHit.Value)
};
}
}
6 WeaponHelper/weaponhelper.py
View
@@ -87,19 +87,21 @@ def filterTargets(self, ids, chanceToHitGetter):
result = []
cannotHit = set()
+ minChanceToHit = float(getPref("MinimumChanceToHit", 1)) / 100.0
for id in ids:
invItem = ballpark.GetInvItem(id)
if not invItem:
continue
- if getFlagName(id) != "HostileNPC":
+ flag = getFlagName(id)
+ if (flag != "HostileNPC") and (flag is not None):
continue
if getPriority(id) < 0:
continue
- if chanceToHitGetter(id) <= 0:
+ if chanceToHitGetter(id) < minChanceToHit:
cannotHit.add(id)
continue
Please sign in to comment.
Something went wrong with that request. Please try again.