def ReportISKSpammer(charID, channelID): if eve.Message('ConfirmReportISKSpammer', {'name': cfg.eveowners.Get(charID).name}, uiconst.YESNO) != uiconst.ID_YES: return if charID == session.charid: raise UserError('ReportISKSpammerCannotReportYourself') lscSvc = sm.GetService('LSC') c = lscSvc.GetChannelWindow(channelID) entries = copy.copy(c.output.GetNodes()) spamEntries = [] for e in entries: if e.charid == charID: who, txt, charid, time, colorkey = e.msg spamEntries.append('[%s] %s > %s' % (util.FmtDate(time, 'nl'), who, txt)) if len(spamEntries) == 0: raise UserError('ReportISKSpammerNoEntries') spamEntries.reverse() spamEntries = spamEntries[:10] spammers = getattr(lscSvc, 'spammerList', set()) if charID in spammers: return spammers.add(charID) lscSvc.spammerList = spammers c.LoadMessages() channel = lscSvc.channels.get(channelID, None) if channel and channel.info: channelID = channel.info.displayName sm.RemoteSvc('userSvc').ReportISKSpammer(charID, channelID, spamEntries)
def AddSkillToEnd(self, skillTypeID, current, nextLevel=None): queueLength = self.GetNumberOfSkillsInQueue() if queueLength >= SKILLQUEUE_MAX_NUM_SKILLS: raise UserError('QueueTooManySkills', {'num': SKILLQUEUE_MAX_NUM_SKILLS}) totalTime = self.GetTrainingLengthOfQueue() if totalTime > self.maxSkillqueueTimeLength: raise UserError('QueueTooLong') if nextLevel is None: queue = self.GetServerQueue() nextLevel = self.FindNextLevel(skillTypeID, current, queue) if self.FindInQueue(skillTypeID, nextLevel) is not None: raise UserError('QueueSkillAlreadyPresent') self.BeginTransaction() try: self.AddSkillToQueue(skillTypeID, nextLevel) self.CommitTransaction() except Exception: self.RollbackTransaction() raise text = localization.GetByLabel( 'UI/SkillQueue/Skills/SkillNameAndLevel', skill=skillTypeID, amount=nextLevel) if self.SkillInTraining(): eve.Message('AddedToQueue', {'skillname': text}) else: eve.Message('AddedToQueueAndStarted', {'skillname': text}) sm.ScatterEvent('OnSkillQueueRefreshed')
def AddSkillToQueue(self, skillTypeID, skillLevel, position=None): if self.FindInQueue(skillTypeID, skillLevel) is not None: raise UserError('QueueSkillAlreadyPresent') skillQueueLength = len(self.skillQueue) if skillQueueLength >= SKILLQUEUE_MAX_NUM_SKILLS: raise UserError('QueueTooManySkills', {'num': SKILLQUEUE_MAX_NUM_SKILLS}) newPos = position if position is not None and position >= 0 else skillQueueLength currentSkill = self.skills.GetSkill(skillTypeID) self.CheckCanInsertSkillAtPosition(skillTypeID, skillLevel, newPos) startTime = None if newPos != 0: startTime = self.skillQueue[newPos - 1].trainingEndTime queueEntry = GetQueueEntry( skillTypeID, skillLevel, newPos, currentSkill, self.skillQueue, lambda x, y: self.GetTimeForTraining(x, y, startTime), KeyVal, self.SkillInTraining() is not None) if newPos == skillQueueLength: self.skillQueue.append(queueEntry) else: if newPos > skillQueueLength: raise UserError('QueueInvalidPosition') self.skillQueue.insert(newPos, queueEntry) for entry in self.skillQueue[newPos + 1:]: entry.queuePosition += 1 self.skillQueueCache = None self.AddToCache(skillTypeID, skillLevel, newPos) self.TrimQueue() sm.ScatterEvent('OnSkillQueueModified') return newPos
def HandleSlashCommand(self, action, ballpark, spaceComponentDB): logger.debug('Reinforce.HandleSlashCommand %d %s', self.itemID, action) if action[0].lower() == 'on': if not self.IsReinforced(): self.EnterReinforced() else: raise UserError( 'SlashError', { 'reason': 'Reinforce component %s is already reinforced!' % (self.itemID, ) }) elif action[0].lower() == 'off': if self.IsReinforced(): self.ExitReinforced() else: raise UserError( 'SlashError', { 'reason': 'Reinforce component %s is not currently reinforced!' % (self.itemID, ) }) else: raise UserError( 'SlashError', {'reason': 'Usage: /spacecomponent reinforce ITEMID on|off'})
def CheckBallForProximityRestrictions(ballID, position, radius, typeID, ballpark, groupProximityChecks, forbidOverlap=False): ballSlimItem = ballpark.slims[ballID] ballGroupID = ballSlimItem.groupID distance = GetDistanceFromBallSurface(ballID, position, radius, ballpark) if ballGroupID in groupProximityChecks: distanceToCheck = groupProximityChecks[ballGroupID] if distanceToCheck > 0 and distance < distanceToCheck: errorAttributes = { 'distance': distanceToCheck, 'typeID': typeID, 'groupName': (UE_GROUPID, ballGroupID) } raise UserError('CantDeployNearGroup', errorAttributes) elif forbidOverlap and distance <= 0.0: ball = ballpark.GetBall(ballID) if not ball.isFree: raise UserError('CantDeployTypeInWay', { 'typeID': ballSlimItem.typeID, 'deployTypeID': typeID })
def CheckCanTakeItem(self, charID, item, inventory2): if not IsActiveComponent(self.componentRegistry, self.typeID, self.itemID): raise UserError('PermissionDenied') if not self.attributes.allowFreeForAll and charID not in ( -1, item.ownerID): raise UserError('TheItemIsNotYoursToTake', {'item': item.itemID})
def CheckCanListContents(self, charID, inventory2): if not IsActiveComponent(self.componentRegistry, self.typeID, self.itemID): raise UserError('PermissionDenied') if not self.attributes.allowFreeForAll and charID not in ( -1, inventory2.GetItem(self.itemID).ownerID): raise UserError('PermissionDenied')
def CheckAccessDistance(self, ballID, ballpark): if not IsActiveComponent(self.componentRegistry, self.typeID, self.itemID): raise UserError('PermissionDenied') if not ballpark.HasBall(self.itemID): raise UserError('CargoContainerNotFound', {'item': (UE_TYPEID, self.typeID)}) dist = ballpark.DistanceBetween(self.itemID, ballID) accessRange = self.attributes.accessRange if dist > accessRange: raise UserError('NotCloseEnoughToAdd', {'maxdist': accessRange})
def _CheckCanUnlock(self, shipID): if self.ballpark.IsCloaked(shipID): raise UserError('CantAccessWhileCloaked') distance = self.ballpark.GetSurfaceDist(self.itemID, shipID) if distance > self.accessRange: raise UserError('BountyEscrowOutOfRange') unlockingCharID = self._GetUnlockingCharID() if unlockingCharID is not None: raise UserError('BountyEscrowAlreadyUnlocked', { 'typeID': self.typeID, 'charID': unlockingCharID })
def HandleSlashCommand(self, action, ballpark, spaceComponentDB): logger.debug('Activate.HandleSlashCommand %d %s', self.itemID, action) if action[0].lower() == 'makeactive': if not self.isActive: BecomeActive(self, spaceComponentDB, ballpark) else: raise UserError('SlashError', {'reason': 'Component is already active'}) else: raise UserError('SlashError', { 'reason': 'Usage: /spacecomponent activate ITEMID makeactive' })
def ConvertAbilityFailureReason(fighterID, abilitySlotID, failureReasonUserError): if failureReasonUserError.msg == 'ModuleActivationDeniedSafetyPreventsSuspect': return UserError('CannotActivateAbilitySafetyPreventsSuspect', failureReasonUserError.dict) if failureReasonUserError.msg == 'ModuleActivationDeniedSafetyPreventsCriminal': return UserError('CannotActivateAbilitySafetyPreventsCriminal', failureReasonUserError.dict) if failureReasonUserError.msg == 'ModuleActivationDeniedSafetyPreventsLimitedEngagement': return UserError( 'CannotActivateAbilitySafetyPreventsLimitedEngagement', failureReasonUserError.dict) return failureReasonUserError
def CheckCanAddItem(self, charID, item, inventory2): if not IsActiveComponent(self.componentRegistry, self.typeID, self.itemID): raise UserError('PermissionDenied') if charID not in (-1, inventory2.GetItem( self.itemID).ownerID) and not self.attributes.allowFreeForAll: raise UserError('PermissionDenied') if charID != -1 and not self.attributes.allowUserAdd: raise UserError('CannotAddToThatLocation') if hasattr(self.attributes, 'acceptedTypeIDs' ) and item.typeID not in self.attributes.acceptedTypeIDs: raise UserError('CannotStoreDestinationRestricted', {'ship': self.typeID})
def CheckCanRemoveSkillFromQueue(self, skillTypeID, skillLevel): self.PrimeCache() if skillTypeID not in self.skillQueueCache: return for cacheLevel in self.skillQueueCache[skillTypeID]: if cacheLevel > skillLevel: raise UserError( 'QueueCannotRemoveSkillsWithHigherLevelsStillInQueue') dependencies = sm.GetService('skills').GetDependentSkills(skillTypeID) for dependentTypeID, requiredLevel in dependencies.iteritems(): if skillLevel <= requiredLevel and dependentTypeID in self.skillQueueCache: raise UserError( 'QueueCannotRemoveSkillsWithDependentSkillsInQueue')
def ClassSpecificAdd(self, itemID, sourceID, qty=None, flag=None): item = self.GetItemByID(itemID) oldOwnerID = item.ownerID containerOwner = self.invItem.ownerID try: self.broker.CanTake(item, self.actor) except UserError as e: if e.msg == 'SCGeneralPasswordRequired': raise UserError('PasswordProtectedCacheInvalid') raise self.CheckVolumeRestrictions(item, qty or item.stacksize) self.CheckCloakingLimitations(sourceID) self.component.CheckCanAddItem(self.actor, item, self.broker.inventory2) if self.broker.beyonce.GetBallpark( self.broker.locationID).HasBall(sourceID): sourceBallID = sourceID else: sourceBallID = self.GetItemByID(sourceID).locationID self.CheckAccessDistance(sourceBallID) flag = self.flagID locationID = self.component.GetInventoryID() newItemID = self.broker.inventory2.MoveItem(itemID, sourceID, locationID, qty, containerOwner, flag) self.LogInventoryMovement(item, locationID, oldOwnerID, qty, sourceID) self.componentRegistry.SendMessageToItem(self.itemid, MSG_ON_PLAYER_INTERACTION) return newItemID
def LaunchSMAContents(invItem): bp = sm.GetService('michelle').GetBallpark() myShipBall = bp.GetBall(session.shipid) if myShipBall and myShipBall.mode == destiny.DSTBALL_WARP: raise UserError('ShipInWarp') sm.GetService('gameui').GetShipAccess().LaunchFromContainer( invItem.locationID, invItem.itemID)
def EngageTarget(droneIDs): michelle = sm.StartService('michelle') dronesRemoved = [] for droneID in droneIDs: item = michelle.GetItem(droneID) if not item: dronesRemoved.append(droneID) for droneID in dronesRemoved: droneIDs.remove(droneID) targetID = sm.GetService('target').GetActiveTargetID() if targetID is None: raise UserError('DroneCommandRequiresActiveTarget') crimewatchSvc = sm.GetService('crimewatchSvc') requiredSafetyLevel = crimewatchSvc.GetRequiredSafetyLevelForEngagingDrones( droneIDs, targetID) if crimewatchSvc.CheckUnsafe(requiredSafetyLevel): crimewatchSvc.SafetyActivated(requiredSafetyLevel) return entity = moniker.GetEntityAccess() if entity: ret = entity.CmdEngage(droneIDs, targetID) HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult') if droneIDs: name = sm.GetService('space').GetWarpDestinationName(targetID) eve.Message( 'CustomNotify', { 'notify': localization.GetByLabel('UI/Inflight/DronesEngaging', name=name) })
def AwardDecoration(charIDs): if not charIDs: return if not type(charIDs) == list: charIDs = [charIDs] info, graphics = sm.GetService('medals').GetAllCorpMedals(session.corpid) options = [(medal.title, medal.medalID) for medal in info] if len(options) <= 0: raise UserError('MedalCreateToAward') cfg.eveowners.Prime(charIDs) hintLen = 5 hint = ', '.join( [cfg.eveowners.Get(charID).name for charID in charIDs[:hintLen]]) if len(charIDs) > hintLen: hint += ', ...' ret = uix.ListWnd( options, 'generic', localization.GetByLabel( 'UI/Corporations/Common/AwardCorpMemberDecoration'), isModal=1, ordered=1, scrollHeaders=[ localization.GetByLabel('UI/Inventory/InvItemNameShort') ], hint=hint) if ret: medalID = ret[1] sm.StartService('medals').GiveMedalToCharacters(medalID, charIDs)
def HandleSlashCommand(self, action, ballpark, spaceComponentDB): logger.debug('Decay.HandleSlashCommand %d %s', self.itemID, action) usageString = 'Usage: /spacecomponent decay ITEMID decay now|DELAY_SECONDS' if len(action) != 2: raise UserError('SlashError', {'reason': usageString}) if action[0].lower() == 'decay': if action[1].lower() == 'now': delay = 1 else: delay = int(action[1]) if delay < 1: raise UserError('SlashError', {'reason': usageString}) decayTimestamp = self.GetSimTime() + delay * const.SEC self.SetDecayTimestamp(decayTimestamp) else: raise UserError('SlashError', {'reason': usageString})
def DeliverToCorpHangarFolder(invItemAndFlagList, invCacheSvc): if len(invItemAndFlagList) == 0: return invItems = [] itemIDs = [] for item in invItemAndFlagList: invItems.append(item[0]) itemIDs.append(item[0].itemID) CheckItemsInSamePlace(invItems) fromID = invItems[0].locationID doSplit = bool( uicore.uilib.Key(uiconst.VK_SHIFT) and len(invItemAndFlagList) == 1 and invItemAndFlagList[0][0].stacksize > 1) stationID = invCacheSvc.GetStationIDOfItem(invItems[0]) if stationID is None: raise UserError('CanOnlyDoInStations') ownerID = invItems[0].ownerID flag = invItems[0].flagID deliverToFlag = invItemAndFlagList[0][1] qty = None if doSplit: invItem = invItems[0] ret = uix.QtyPopup( invItem.stacksize, 1, 1, None, localization.GetByLabel( 'UI/Inventory/ItemActions/DivideItemStack')) if ret is not None: qty = ret['qty'] invCacheSvc.GetInventoryMgr().DeliverToCorpHangar(fromID, stationID, itemIDs, qty, ownerID, deliverToFlag) InvalidateItemLocation(ownerID, stationID, flag, invCacheSvc) if ownerID == session.corpid: sm.ScatterEvent('OnCorpAssetChange', invItems, stationID)
def DroneUnanchor(droneIDs): targetID = sm.StartService('target').GetActiveTargetID() if targetID is None: raise UserError('DroneCommandRequiresActiveTarget') entity = moniker.GetEntityAccess() if entity: ret = entity.CmdUnanchor(droneIDs, targetID) HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')
def CheckSecurityLevel(typeID, ballpark, componentAttributes): if ballpark.security > componentAttributes.maxSecurityLevel: raise UserError( 'CantDeploySecurityLevelRestrictionTooHigh', { 'typeID': typeID, 'maxSecurityLevel': componentAttributes.maxSecurityLevel, 'systemSecurity': ballpark.security })
def ActivateSkillExtractor(self, item): if util.InSpace(): raise UserError('SkillExtractorNotDockedInStation', {'extractor': const.typeSkillExtractor}) skillPoints = self.GetSkillHandler().GetSkillPoints() freeSkillPoints = self.GetSkillHandler().GetFreeSkillPoints() if skillPoints + freeSkillPoints < const.SKILL_TRADING_MINIMUM_SP_TO_EXTRACT: raise UserError( 'SkillExtractionNotEnoughSP', { 'limit': const.SKILL_TRADING_MINIMUM_SP_TO_EXTRACT, 'extractor': const.typeSkillExtractor }) if blue.pyos.packaged: token = sm.GetService('crestConnectionService').token if token is None: raise UserError('TokenRequiredForSkillExtraction') SkillExtractorWindow.OpenOrReload(itemID=item.itemID)
def CheckOwnerRestrictions(spaceComponentStaticData, typeID, corpID, allianceRegistry): componentAttributes = spaceComponentStaticData.GetAttributes( typeID, DEPLOY_CLASS) if componentAttributes.requiresAlliance and allianceRegistry.AllianceIDFromCorpID( corpID) is None: raise UserError('CannotLaunchRequiresAlliance', {'deployTypeID': typeID})
def RecoverProbes(self, probeIDs, RecoverProbes): successProbeIDs = RecoverProbes(probeIDs) for pID in successProbeIDs: self.UpdateProbeState(pID, probescanning.const.probeStateMoving, 'RecoverProbes') if len(successProbeIDs) < len(probeIDs): raise UserError('NotAllProbesReturnedSuccessfully')
def SplitStack(invItems, invCacheSvc): if len(invItems) != 1: raise UserError('CannotPerformOnMultipleItems') invItem = invItems[0] ret = uix.QtyPopup( invItem.stacksize, 1, 1, None, localization.GetByLabel('UI/Inventory/ItemActions/DivideItemStack')) if ret is not None: qty = ret['qty'] stationID = invCacheSvc.GetStationIDOfItem(invItem) if stationID is None: raise UserError('CanOnlyDoInStations') flag = invItem.flagID invCacheSvc.GetInventoryMgr().SplitStack(stationID, invItem.itemID, qty, invItem.ownerID) InvalidateItemLocation(invItem.ownerID, stationID, flag, invCacheSvc) if invItem.ownerID == session.corpid: invItem.quantity = invItem.quantity - qty sm.ScatterEvent('OnCorpAssetChange', [invItem], stationID)
def ActivateAbilitySlotsOnTarget(self, fighterIDs, abilitySlotID, targetID): if not targetID: fighterInSpace = self.shipFighterState.GetFighterInSpaceByID(fighterIDs[0]) abilityNameID = GetAbilityNameIDForSlot(fighterInSpace.typeID, abilitySlotID) raise UserError('CannotActivateAbilityRequiresTarget', {'fighterTypeID': fighterInSpace.typeID, 'abilityNameID': abilityNameID}) [ self._CheckSafetyLevelForAbility(fighterID, abilitySlotID) for fighterID in fighterIDs ] errorsByFighterID = self._ActivateAbilitySlots(fighterIDs, abilitySlotID, targetID) for fighterID, error in errorsByFighterID.iteritems(): if not error: self.shipFighterState.OnAbilityActivatedAtTarget(fighterID, abilitySlotID, targetID)
def DelegateControl(charID, droneIDs): if charID is None: targetID = sm.StartService('target').GetActiveTargetID() if targetID is None: raise UserError('DroneCommandRequiresActiveTarget') michelle = sm.StartService('michelle') targetItem = michelle.GetItem(targetID) if targetItem.categoryID != const.categoryShip or targetItem.groupID == const.groupCapsule: raise UserError('DroneCommandRequiresShipButNotCapsule') targetBall = michelle.GetBall(targetID) if not targetBall.isInteractive or not sm.GetService('fleet').IsMember( targetItem.ownerID): raise UserError('DroneCommandRequiresShipPilotedFleetMember') controllerID = targetItem.ownerID else: controllerID = charID entity = moniker.GetEntityAccess() if entity: ret = entity.CmdDelegateControl(droneIDs, controllerID) HandleMultipleCallError(droneIDs, ret, 'MultiDroneCmdResult')
def HandleMultipleCallError(droneID, ret, messageName): if not len(ret): return if len(droneID) == 1: pick = droneID[0] raise UserError(ret[pick][0], ret[pick][1]) elif len(droneID) >= len(ret): lastError = '' for error in ret.itervalues(): if error[0] != lastError and lastError != '': raise UserError( messageName, { 'succeeded': len(droneID) - len(ret), 'failed': len(ret), 'total': len(droneID) }) lastError = error[0] else: pick = ret.items()[0][1] raise UserError(pick[0], pick[1])
def _CheckSafetyLevelForAbility(self, fighterID, abilitySlotID, targetID = None): fighterInSpace = self.shipFighterState.GetFighterInSpaceByID(fighterID) if fighterInSpace is None: raise ValueError('Cannot activate ability for unknown fighter') abilityID = GetAbilityIDForSlot(fighterInSpace.typeID, abilitySlotID) effectID = GetDogmaEffectIDForAbilityID(abilityID) effect = cfg.dgmeffects.Get(effectID) requiredSafetyLevel = self.crimewatchSvc.GetRequiredSafetyLevelForEffect(effect, targetID) if not self.consider.SafetyCheckPasses(requiredSafetyLevel): abilityNameID = GetAbilityNameIDForSlot(fighterInSpace.typeID, abilitySlotID) raise UserError('CannotActivateAbilityViolatesSafety', {'fighterTypeID': fighterInSpace.typeID, 'abilityNameID': abilityNameID})
def CheckItemsInSamePlace(invItems): if len(invItems) == 0: return locationID = invItems[0].locationID flag = invItems[0].flagID ownerID = invItems[0].ownerID for item in invItems: if item.locationID != locationID or item.flagID != flag or item.ownerID != ownerID: raise UserError('ItemsMustBeInSameHangar') locationID = item.locationID ownerID = item.ownerID flag = item.flagID