Skip to content

Instantly share code, notes, and snippets.

@b1tninja
Created December 18, 2015 05:03
Show Gist options
  • Save b1tninja/66b612f02f129d0cd90a to your computer and use it in GitHub Desktop.
Save b1tninja/66b612f02f129d0cd90a to your computer and use it in GitHub Desktop.
import evetypes
import stackless
#import uthread
import service
import session
from inventorycommon import const
from eve.client.script.ui.services.menuSvcExtras.movementFunctions import WarpToItem
from eve.common.script.sys.eveCfg import GetActiveShip
from eve.client.script.ui.shared.inventory.treeData import TreeDataShip
class SpaceDroid(service.Service):
# [(item.categoryID,evetypes.GetCategoryNameByCategory(item.categoryID)) for ball,item in bp.GetBallsAndItems()]
__notifyevents__ = ['DoBallsAdded', 'OnSpecialFX', 'OnStateChange']
def DoBallsAdded(self, *args, **kwargs):
print(args,kwargs)
# TODO: detect deactivation of mining laser
def OnSpecialFX(self, shipID, moduleID, moduleTypeID, targetID, otherTypeID, guid, isOffensive, start, active, duration = -1, repeat = None, startTime = None, timeFromStart = 0, graphicInfo = None):
print(shipID,moduleID,moduleTypeID,targetID,otherTypeID,guid,isOffensive,start,active,duration,repeat,startTime,timeFromStart,graphicInfo)
# if isOffensive and targetID == eve.session.shipid:
# self.weaponsOnMe[shipID] = self.weaponsOnMe.get(shipID, 0) + (-1, +1)[start]
def OnStateChange(self, itemID, flag, true, *args):
print(itemID, flag, true, args)
# if flag == state.selected and true and self.needtarget and len(self.needtarget) > 0:
# if not self.IsTarget(itemID):
# self.HideTargetingCursor()
def GetInventory(self):
assert session.shipid
#inventory = sm.GetService('inv').GetInvLocationTreeData()
sm.GetService('michelle').GetBall(session.shipid)
shipinv = TreeDataShip(clsName='ShipCargo', itemID=ship.id, typeID=ship.typeID, cmdName='OpenCargoHoldOfActiveShip')
# >>> [container.GetLabel() for container in shipinv.GetChildren()]
# [u'Drone Bay', u'Ore Hold']
# if container.itemID == session.stationID || container.itemID == session.shipid
subcontainers = shipinv.GetChildren()
# >>> inventory = sm.GetService('inv').GetInvLocationTreeData()
# >>> inventory.children
# [<eve.client.script.ui.shared.inventory.treeData.TreeDataShip instance at 0x325C32B0>]
# >>> cap = inventory.children[0].invController.GetCapacity()
# >>> cap
# <Row capacity:450.0,used:450.0>
# >>> inventory.children[0].invController.GetItems()[0].__keys__
# ['itemID', 'typeID', 'ownerID', 'locationID', 'flagID', 'quantity', 'groupID', 'categoryID', 'customInfo', 'stacksize', 'singleton']
# >>> evetypes.GetName(inventory.children[0].invController.GetItems()[0].typeID)
# u'Dense Veldspar'
def Dock(self):
bp = sm.GetService('michelle').GetBallpark()
ship = sm.GetService('michelle').GetBall(session.shipid)
stations = sorted([(ball, item) for ball,item in bp.GetBallsAndItems() if item.categoryID == const.categoryStation and item.groupID == const.groupStation], key=lambda (ball, item): bp.DistanceBetween(ball.id, ship.id))
if stations:
(ball, item) = stations[0]
sm.GetService('menu').Dock(item.itemID)
def ApproachAsteroids(self):
bp = sm.GetService('michelle').GetBallpark()
ship = sm.GetService('michelle').GetBall(session.shipid)
# >>> evetypes.GetGroupName(ship.GetTypeID())
# u'Mining Barge'
# >>> evetypes.GetName(ship.GetTypeID())
# u'Covetor'
# >>> evetypes.GetCategoryName(ship.GetTypeID())
# u'Ship'
# >>> evetypes.GetDescription(ship.GetTypeID())
# u"The mining barge was designed by <a href=showinfo:30//500014>ORE</a> to facilitate advancing the mining profession to a new level. Each barge was created to excel at a specific function, the Covetor's being mining yield and mining laser range. This additional yield comes at a price, as the Covetor has weaker defenses and a smaller ore bay than the other mining barges.\r\nMining barges are equipped with electronic subsystems specifically designed to accommodate Strip Mining and Ice Harvesting modules."
# >>> evetypes.GetMass(ship.GetTypeID())
# 30000000.0
# >>> evetypes.GetCapacity(ship.GetTypeID())
# 350.0
# >>> evetypes.GetVolume(ship.GetTypeID())
# 200000.0
# >>> evetypes.GetBasePrice(ship.GetTypeID())
# 20000000.0
asteroids = sorted([(ball, item) for ball, item in bp.GetBallsAndItems()
if item.categoryID == const.categoryAsteroid],
key=lambda (ball, item): bp.DistanceBetween(ball.id, ship.id))
if asteroids:
# for ball, item in asteroids[:3]:
(ball, item) = asteroids[0]
sm.GetService('menu').Approach(item.itemID)
# sm.GetService('target').IsInTargetingRange(item)
# shipItem = sm.GetService('godma').GetStateManager().GetItem(eve.session.shipid)
# shipItem.maxTargetRange
# TODO: try: LockTarget
sm.GetService('target').TryLockTarget(item.itemID)
# Closest 5 asteroids
# sorted([(ball, item) for ball,item in bp.GetBallsAndItems() if item.categoryID == CATEGORY_ASTEROID], key=lambda (ball,item): bp.DistanceBetween(ball.id, ship.id))[:5]
sm.GetService('cmd').CmdActivateHighPowerSlot1()
stackless.run()
# sm.GetService('viewState').overlaysByName['shipui'].slotsContainer.slotsByOrder.get((1,0), None)
# if evetypes.GetGroupID(moduleinfo.typeID) in (const.groupMiningLaser, const.groupStripMiner):
# >>> sm.GetService('viewState').overlaysByName['shipui'].slotsContainer.slotsByOrder.get((0,0), None).sr.module.def_effect.effectName
# 'miningLaser'
# effect.Activate()
else:
asteroid_belts = sorted([(ball, item) for ball, item in bp.GetBallsAndItems()
if item.categoryID == const.categoryCelestial and item.groupID == const.groupAsteroidBelt],
key=lambda (ball, item): bp.DistanceBetween(ball.id, ship.id))
(ball, item) = asteroid_belts[0]
WarpToItem(item.itemID)
#
# def AddMiningLaserInfo(self, itemID, chargeInfoItem, *args):
# duration = self.GetDuration(itemID)
# amount = self.GetEffectiveAttributeValue(itemID, const.attributeMiningAmount)
# if chargeInfoItem is not None:
# specializationMultiplier = self.GetEffectiveAttributeValue(chargeInfoItem.itemID, const.attributeSpecialisationAsteroidYieldMultiplier)
# amount = specializationMultiplier * amount
# text = localization.GetByLabel('UI/Inflight/ModuleRacks/Tooltips/MiningAmountPerTime', duration=duration, amount=amount)
# self.AddRowWithIconAndText(text=text, texturePath='res:/ui/texture/icons/23_64_5.png')
#
# def cmd_reportdesync(self, p):
# try:
# threshold, = p.Parse('f')
# except:
# threshold = 1000.0
#
# serverTimestamp = 0
# bp = sm.GetService('michelle').GetBallpark()
# tries = 0
# while bp.currentTime != serverTimestamp and tries < 10:
# ret, serverTimestamp = sm.RemoteSvc('slash').SlashCmd('/reportdesync')
# if bp.currentTime < serverTimestamp:
# blue.pyos.synchro.SleepSim((serverTimestamp - bp.currentTime) * 1000)
# tries += 1
#
# txt += 'Location: %s - Char: %s - Ship: %s<br><br>' % (eve.session.locationid, eve.session.charid, eve.session.shipid)
# import math
# for ballID, pos in ret.iteritems():
# if ballID in bp.balls:
# b = bp.balls[ballID]
# serverVec = ret[ballID]
# clientPos = (b.x, b.y, b.z)
# clientVel = (b.vx, b.vy, b.vz)
# diff = (clientPos[0] - serverVec[0], clientPos[1] - serverVec[1], clientPos[2] - serverVec[2])
# delta = math.sqrt(diff[0] ** 2 + diff[1] ** 2 + diff[2] ** 2)
# if delta > threshold:
# diffVel = (clientVel[0] - serverVec[3], clientVel[1] - serverVec[4], clientVel[2] - serverVec[5])
# deltaVel = math.sqrt(diffVel[0] * diffVel[0] + diffVel[1] * diffVel[1] + diffVel[2] * diffVel[2])
# spdClient = math.sqrt(clientVel[0] * clientVel[0] + clientVel[1] * clientVel[1] + clientVel[2] * clientVel[2])
# spdServer = math.sqrt(serverVec[3] * serverVec[3] + serverVec[4] * serverVec[4] + serverVec[5] * serverVec[5])
# if hasattr(b, 'typeID'):
# typeName = evetypes.GetName(b.typeID)
# else:
# try:
# typeName = evetypes.GetName(bp.slimItems[ballID].typeID)
# except KeyError:
# continue
# sm.GetService('spacedroid')
# while True:
# stackless.schedule()
sm.RegisterNotify(SpaceDroid())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment