contractscommon.py (8548B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\common\script\util\contractscommon.py 2 import eveformat 3 import evetypes 4 import localization 5 import utillib 6 from eve.common.lib import appConst as const 7 from eve.common.lib.appConst import corpRoleContractManager 8 from eve.common.script.util import facwarCommon 9 CONTYPE_AUCTIONANDITEMECHANGE = 10 10 CONTYPE_ALL = 11 11 CREATECONTRACT_CONFIRM_CHARGESTOHANGAR = 1 12 const_conSalesTax = 0.01 13 const_conSalesTaxMinimum = 10000 14 const_conSalesTaxMaximum = 1000000000 15 const_conBrokersFee = 0.004 16 const_conBrokersFeeMinimum = 10000 17 const_conBrokersFeeMaximum = 100000000 18 const_conDeposit = 0.01 19 const_conDepositMinimum = 100000 20 const_conDepositMaximum = 100000000 21 const_conBidMinimum = 1000000 22 MAX_AMOUNT = 10000000000000L 23 SECOND = const.SEC 24 MINUTE = const.MIN 25 HOUR = const.HOUR 26 DAY = const.DAY 27 WEEK = const.WEEK 28 NUM_CONTRACTS_BY_SKILL = [1, 29 5, 30 9, 31 13, 32 17, 33 21] 34 NUM_CONTRACTS_BY_ADVSKILL = [0, 35 4, 36 8, 37 12, 38 16, 39 20] 40 NUM_CONTRACTS_BY_SKILL_CORP = [10, 41 20, 42 30, 43 40, 44 50, 45 60] 46 MAX_NUM_ITEMS = 500 47 MAX_NUM_ITEMS_TOTAL = 2000 48 MAX_NUM_CONTRACTS = 500 49 const_conCourierMaxVolume = 1200000 50 const_conCourierWarningVolume = 20000 51 MAX_DESC_LENGTH = 4000 52 MAX_TITLE_LENGTH = 50 53 MAX_NOTES_LENGTH = 1000 54 DAY_IN_MINUTES = 1440 55 EXPIRE_TIMES = [DAY_IN_MINUTES, 56 3 * DAY_IN_MINUTES, 57 7 * DAY_IN_MINUTES, 58 14 * DAY_IN_MINUTES, 59 28 * DAY_IN_MINUTES] 60 MAX_DURATION_DAYS = int(max(EXPIRE_TIMES) / DAY_IN_MINUTES) 61 MAX_NUM_CONTRACTS = 500 62 SORT_ID = 0 63 SORT_PRICE = 1 64 SORT_EXPIRED = 2 65 SORT_STATION_ID = 3 66 SORT_SOLARSYSTEM_ID = 4 67 SORT_REGION_ID = 5 68 SORT_CONSTELLATION_ID = 6 69 SORT_CONTRACT_TYPE = 7 70 SORT_REWARD = 8 71 SORT_COLLATERAL = 9 72 SORT_VOLUME = 10 73 SORT_ASSIGNEEID = 11 74 CONTRACTS_PER_PAGE = 100 75 MAX_CONTRACTS_PER_SEARCH = 1000 76 NUMJUMPS_UNREACHABLE = 100 77 SEARCHHINT_BPO = 1 78 SEARCHHINT_BPC = 2 79 BASE_COST_MULTIPLIERS = {const.conTypeAuction: 1.0, 80 const.conTypeItemExchange: 1.0, 81 const.conTypeCourier: 0.1, 82 const.conTypeLoan: 1.0} 83 84 def CalculateDeposit(contractType, availability, price, reward): 85 if availability == 0: 86 base = max(price, reward) 87 minDeposit = const_conDepositMinimum if not contractType == const.conTypeCourier else const_conDepositMinimum / 10 88 percentage = const_conDeposit * BASE_COST_MULTIPLIERS[contractType] 89 amount = int(min(max(base * percentage, minDeposit), const_conDepositMaximum)) 90 else: 91 amount = 0 92 percentage = 0 93 return utillib.KeyVal(amount=amount, percentage=percentage) 94 95 96 def CalcContractFees(price, reward, type, availability, time, skillLevels, solarSystemID = None, factionID = None): 97 base = max(price, reward) 98 numAdditionalDays = int(float(time) / 1440.0) - 1 99 costMult = BASE_COST_MULTIPLIERS[type] 100 ret = utillib.KeyVal() 101 tax = const_conSalesTax - float(skillLevels.accounting) * 0.001 102 taxMinimum = const_conSalesTaxMinimum 103 tax *= costMult 104 ret.salesTax = tax 105 maxSalesTax = const_conSalesTaxMaximum * (1.0 - float(skillLevels.accounting) * 0.1) 106 ret.salesTaxAmt = int(min(max(base * tax, taxMinimum), maxSalesTax)) 107 brokersFee = const_conBrokersFee - float(skillLevels.brokerRelations) * 0.0002 108 if solarSystemID is not None: 109 brokersFee = facwarCommon.GetAdjustedFeePercentage(solarSystemID, factionID, brokersFee) 110 brokersFeeMininum = const_conBrokersFeeMinimum 111 brokersFee *= costMult 112 ret.brokersFee = brokersFee 113 ret.brokersFee += numAdditionalDays * 0.0005 114 maxBrokersFee = const_conBrokersFeeMaximum * (1.0 - float(skillLevels.brokerRelations) * 0.05) 115 ret.brokersFeeAmt = int(min(max(base * brokersFee, brokersFeeMininum), maxBrokersFee)) 116 ret.brokersFeeAmt *= 1.0 + numAdditionalDays * 0.05 117 deposit = CalculateDeposit(type, availability, price, reward) 118 ret.deposit = deposit.percentage 119 ret.depositAmt = deposit.amount 120 return ret 121 122 123 def GetContractTypeText(id): 124 typesTxt = {const.conTypeItemExchange: localization.GetByLabel('UI/Contracts/ContractsWindow/ItemExchange'), 125 const.conTypeAuction: localization.GetByLabel('UI/Contracts/ContractsWindow/Auction'), 126 const.conTypeCourier: localization.GetByLabel('UI/Contracts/ContractsWindow/Courier'), 127 const.conTypeLoan: localization.GetByLabel('UI/Contracts/ContractsWindow/Loan')} 128 return typesTxt.get(id, localization.GetByLabel('UI/Common/Unknown')) 129 130 131 def GetContractStatusText(id, typ = None): 132 statusTxt = {const.conStatusOutstanding: localization.GetByLabel('UI/Contracts/ContractsWindow/Outstanding'), 133 const.conStatusInProgress: localization.GetByLabel('UI/Contracts/ContractsWindow/InProgress'), 134 const.conStatusFinishedIssuer: localization.GetByLabel('UI/Contracts/ContractsWindow/ItemsNotYetClaimed'), 135 const.conStatusFinishedContractor: localization.GetByLabel('UI/Contracts/ContractsWindow/UnclaimedBySeller'), 136 const.conStatusFinished: localization.GetByLabel('UI/Contracts/ContractsWindow/Finished'), 137 const.conStatusCancelled: localization.GetByLabel('UI/Contracts/ContractsWindow/Cancelled'), 138 const.conStatusRejected: localization.GetByLabel('UI/Contracts/ContractsWindow/Rejected'), 139 const.conStatusFailed: localization.GetByLabel('UI/Contracts/ContractsWindow/Failed'), 140 const.conStatusDeleted: localization.GetByLabel('UI/Contracts/ContractsWindow/Deleted'), 141 const.conStatusReversed: localization.GetByLabel('UI/Contracts/ContractsWindow/Reversal')} 142 return statusTxt.get(id, localization.GetByLabel('UI/Contracts/ContractsWindow/QuestionMark')) 143 144 145 def GetContractTitle(r, items): 146 MAX_COL_LENGTH = 60 147 MAX_TITLE_LEN = 100 148 txt = '' 149 if (r.type == const.conTypeItemExchange or r.type == const.conTypeAuction) and len(items) > 0: 150 l = len([ e for e in items if e.inCrate ]) 151 lgive = len(items) - l 152 if r.type == const.conTypeItemExchange and lgive > 0 and l > 0: 153 txt = localization.GetByLabel('UI/Contracts/ContractsWindow/WantToTrade') 154 elif l > 1: 155 txt = localization.GetByLabel('UI/Contracts/ContractsWindow/MultipleItems') 156 elif l == 1: 157 if items[0].quantity > 1: 158 txt = localization.GetByLabel('UI/Contracts/ContractsWindow/TypeNameWithQuantity', typeID=items[0].itemTypeID, quantity=items[0].quantity) 159 else: 160 txt = localization.GetByLabel('UI/Contracts/ContractsWindow/TypeName', typeID=items[0].itemTypeID) 161 elif r.type == const.conTypeItemExchange: 162 if r.reward == 0: 163 txt = localization.GetByLabel('UI/Contracts/ContractsWindow/WantAGift') 164 else: 165 txt = localization.GetByLabel('UI/Contracts/ContractEntry/WantToBuy') 166 elif r.type == const.conTypeCourier: 167 txt = localization.GetByLabel('UI/Contracts/ContractsWindow/CourierContractTitleWIthVolume', startSolarSystem=r.startSolarSystemID, endSolarSystem=r.endSolarSystemID, volume=r.volume) 168 else: 169 txt = r.title 170 txt = eveformat.truncate_text_ignoring_tags(txt, length=MAX_COL_LENGTH, trail=localization.GetByLabel('UI/Common/MoreTrail')) 171 if len(txt) == 0: 172 txt = localization.GetByLabel('UI/Common/Unknown') 173 return txt 174 175 176 def GetCurrentBid(contract, bids): 177 currentBid = contract.price 178 if len(bids) > 0: 179 currentBid = bids[0].amount 180 return currentBid 181 182 183 def GetCorpRoleAtLocation(session, locationID): 184 hqID = session.hqID 185 baseID = session.baseID 186 rolesAtAll = session.rolesAtAll 187 rolesAtHQ = session.rolesAtHQ 188 rolesAtBase = session.rolesAtBase 189 rolesAtOther = session.rolesAtOther 190 corprole = 0 191 if locationID == hqID: 192 corprole = rolesAtAll | rolesAtHQ 193 elif locationID == baseID: 194 corprole = rolesAtAll | rolesAtBase 195 else: 196 corprole = rolesAtAll | rolesAtOther 197 return corprole 198 199 200 def CanRequestType(typeID): 201 cannotRequestGroups = [const.groupLivestock, 202 const.groupMiscellaneous, 203 const.groupCommodities, 204 const.groupGeneral, 205 const.groupFrozen] 206 groupID = evetypes.GetGroupID(typeID) 207 if groupID in cannotRequestGroups: 208 return False 209 return True 210 211 212 def IsPlayerAllowedToRejectContract(contract, actorID, actorCorpID, actorAllianceID, actorCorpRole): 213 assigneeID = contract.assigneeID 214 if assigneeID == actorID: 215 return True 216 if not actorCorpRole & corpRoleContractManager: 217 return False 218 if assigneeID == actorCorpID: 219 return True 220 if actorAllianceID and assigneeID == actorAllianceID and contract.issuerCorpID == actorCorpID: 221 return True 222 return False