createContractHelpers.py (4947B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\contracts\createContractHelpers.py 2 import eve.common.lib.appConst as appConst 3 from eve.common.script.sys.idCheckers import IsCorporation, IsCharacter, IsNPC, IsStation 4 import eve.common.script.util.contractscommon as cc 5 import inventorycommon.const as invConst 6 from eveexceptions import UserError 7 from localization import GetByLabel 8 from utillib import KeyVal 9 10 def GetMaxNumContracts(forCorp, characterSkillInfo): 11 if forCorp: 12 skillLvl = characterSkillInfo[invConst.typeCorporationContracting] 13 maxNumContracts = cc.NUM_CONTRACTS_BY_SKILL_CORP[skillLvl] 14 else: 15 skillLvl = characterSkillInfo[invConst.typeContracting] 16 advSkillLvl = characterSkillInfo[invConst.typeAdvancedContracting] 17 maxNumContracts = cc.NUM_CONTRACTS_BY_SKILL[skillLvl] + cc.NUM_CONTRACTS_BY_SKILL[advSkillLvl] 18 return maxNumContracts 19 20 21 def IsInnerCorpContract(myCorpID, assignedToID, getCorporationIDForCharacterFunc): 22 if assignedToID <= 0: 23 return False 24 if IsCorporation(assignedToID): 25 if assignedToID == myCorpID: 26 return True 27 elif IsCharacter(assignedToID): 28 assigneeCorpID = getCorporationIDForCharacterFunc(assignedToID) 29 if assigneeCorpID == myCorpID and not IsNPC(myCorpID): 30 return True 31 return False 32 33 34 def VerifyCanCreateMoreContracts(forCorp, innerCorp, maxNumContractsForCharacter, numOutstandingContracts): 35 if forCorp and numOutstandingContracts.myCorpTotal >= cc.MAX_NUM_CONTRACTS: 36 raise UserError('ConTooManyContractsMax', {'max': cc.MAX_NUM_CONTRACTS}) 37 if not forCorp and numOutstandingContracts.myCharTotal >= cc.MAX_NUM_CONTRACTS: 38 raise UserError('ConTooManyContractsMax', {'max': cc.MAX_NUM_CONTRACTS}) 39 if innerCorp: 40 maxNumContracts = cc.MAX_NUM_CONTRACTS 41 else: 42 maxNumContracts = maxNumContractsForCharacter 43 if forCorp: 44 if innerCorp: 45 n = numOutstandingContracts.myCorpTotal 46 else: 47 n = numOutstandingContracts.nonCorpForMyCorp 48 elif innerCorp: 49 n = numOutstandingContracts.myCharTotal 50 else: 51 n = numOutstandingContracts.nonCorpForMyChar 52 if n + 1 > maxNumContracts >= 0: 53 raise UserError('ConTooManyContractsMax', {'max': maxNumContracts}) 54 55 56 def SanityCheckContract(contractInfo): 57 if contractInfo.contractType == appConst.conTypeAuction: 58 if contractInfo.price > contractInfo.collateral > 0: 59 raise UserError('ConAuctionBuyoutTooSmall') 60 if contractInfo.price < cc.const_conBidMinimum and contractInfo.assignedToID == 0: 61 reason = GetByLabel('UI/Contracts/ContractsWindow/ErrorMinimumBidTooLow', minimumBid=cc.const_conBidMinimum) 62 raise UserError('CustomInfo', {'info': reason}) 63 64 65 def GetBrokersFeeAndDeposit(solarSystemID, warFactionID, characterSkillInfo, contractInfo): 66 if contractInfo.isPrivate > 0: 67 brokersFee = cc.const_conBrokersFeeMinimum 68 deposit = 0.0 69 else: 70 skillLevels = KeyVal() 71 skillLevels.brokerRelations = characterSkillInfo[invConst.typeBrokerRelations] 72 skillLevels.accounting = characterSkillInfo[invConst.typeAccounting] 73 fees = cc.CalcContractFees(contractInfo.price, contractInfo.reward, contractInfo.contractType, contractInfo.isPrivate, contractInfo.minutesExpire, skillLevels, solarSystemID, warFactionID) 74 brokersFee = fees.brokersFeeAmt 75 deposit = fees.depositAmt 76 return (brokersFee, deposit) 77 78 79 def GetCrateLabel(contractInfo): 80 label = GetByLabel('UI/Contracts/CrateLabel') 81 if contractInfo.contractType == appConst.conTypeCourier: 82 if IsStation(contractInfo.destinationID): 83 label = cfg.evelocations.Get(contractInfo.destinationID).name 84 else: 85 structureInfo = sm.GetService('structureDirectory').GetStructureInfo(contractInfo.destinationID) 86 label = '%s (%s)' % (structureInfo.itemName, cfg.eveowners.Get(structureInfo.ownerID).name) 87 return label 88 89 90 def GetStartLocationIDs(_solarsystemid2, contractInfo): 91 startStationID = contractInfo.startStationID 92 startSolarSystemID = _solarsystemid2 93 startRegionID = 0 94 if contractInfo.startStationID > 0: 95 startSolarSystemID = cfg.evelocations.Get(contractInfo.startStationID).solarSystemID 96 startRegionID = cfg.mapSystemCache.Get(startSolarSystemID).regionID 97 return (startRegionID, startSolarSystemID, startStationID) 98 99 100 def GetEndDestinationIDs(contractInfo): 101 endStationID = contractInfo.startStationID 102 endSolarSystemID = 0 103 endRegionID = 0 104 if contractInfo.destinationID > 0: 105 endSolarSystemID = cfg.evelocations.Get(contractInfo.destinationID).solarSystemID 106 endRegionID = cfg.mapSystemCache.Get(endSolarSystemID).regionID 107 endStationID = contractInfo.destinationID 108 return (endRegionID, endSolarSystemID, endStationID)