NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

scopes.py (3229B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\blackboards\scopes.py
      2 import collections
      3 from brennivin.itertoolsext import Bundle
      4 try:
      5     from eve.common.script.sys.idCheckers import IsPlayerItem
      6 except ImportError:
      7 
      8     def IsPlayerItem(_):
      9         return False
     10 
     11 
     12 Scope = collections.namedtuple('Scope', ['scopeType', 'id'])
     13 ScopeTypes = Bundle(Item='item', EntityGroup='entity_group', Dungeon='dungeon', Tale='tale', SpawnPointPool='spawn_point_pool', NodeGraph='node_graph')
     14 CONTEXT_ID_BY_SCOPE = {ScopeTypes.Item: 'myItemId',
     15  ScopeTypes.EntityGroup: 'myEntityGroupId',
     16  ScopeTypes.Dungeon: 'myDungeonSpawnId',
     17  ScopeTypes.Tale: 'myTaleId',
     18  ScopeTypes.SpawnPointPool: 'mySpawnPointPoolId',
     19  ScopeTypes.NodeGraph: 'myNodeGraphInstanceId'}
     20 SCOPE_DISPLAY_INFO = [(ScopeTypes.Item, 'Item Blackboard: %s'),
     21  (ScopeTypes.EntityGroup, 'Entity Group Blackboard: %s'),
     22  (ScopeTypes.Dungeon, 'Dungeon Blackboard (spawn): %s'),
     23  (ScopeTypes.Tale, 'Tale Blackboard: %s'),
     24  (ScopeTypes.SpawnPointPool, 'Spawn Point Pool Blackboard: %s'),
     25  (ScopeTypes.NodeGraph, 'Node Graph Blackboard: %s')]
     26 
     27 class BlackboardContextIdNotInBehaviorContextError(Exception):
     28     pass
     29 
     30 
     31 def ItemScope(itemID):
     32     return Scope(ScopeTypes.Item, itemID)
     33 
     34 
     35 def EntityGroupScope(groupID):
     36     return Scope(ScopeTypes.EntityGroup, groupID)
     37 
     38 
     39 def DungeonScope(spawnID):
     40     return Scope(ScopeTypes.Dungeon, spawnID)
     41 
     42 
     43 def TaleScope(taleID):
     44     return Scope(ScopeTypes.Tale, taleID)
     45 
     46 
     47 def SpawnPointPoolScope(spawnPointPoolID):
     48     return Scope(ScopeTypes.SpawnPointPool, spawnPointPoolID)
     49 
     50 
     51 def NodeGraphScope(instanceID):
     52     return Scope(ScopeTypes.NodeGraph, instanceID)
     53 
     54 
     55 def GetBlackboardFromContext(context, blackboardScope):
     56     scope = GetBlackboardIdFromScopeAndContext(blackboardScope, context)
     57     return context.blackboardManager.GetBlackboard(scope)
     58 
     59 
     60 def GetBlackboardIdFromScopeAndContext(blackboardScope, context):
     61     scope = Scope(blackboardScope, GetIdFromContextByScope(blackboardScope, context))
     62     return scope
     63 
     64 
     65 def GetIdFromContextByScope(blackboardScope, context):
     66     context_id = CONTEXT_ID_BY_SCOPE[blackboardScope]
     67     try:
     68         return context[context_id]
     69     except KeyError:
     70         raise BlackboardContextIdNotInBehaviorContextError()
     71 
     72 
     73 def GetChannelFromAddress(context, blackboardAddress):
     74     blackboardScope, messageName = blackboardAddress
     75     blackboard = GetBlackboardFromContext(context, blackboardScope)
     76     return blackboard.GetMessageChannel(messageName)
     77 
     78 
     79 def IsItemScope(scope):
     80     return scope.scopeType == ScopeTypes.Item
     81 
     82 
     83 def IsEntityGroupScope(scope):
     84     return scope.scopeType == ScopeTypes.EntityGroup
     85 
     86 
     87 def IsDungeonScope(scope):
     88     return scope.scopeType == ScopeTypes.Dungeon
     89 
     90 
     91 def IsTaleScope(scope):
     92     return scope.scopeType == ScopeTypes.Tale
     93 
     94 
     95 def IsSpawnPointPoolScope(scope):
     96     return scope.scopeType == ScopeTypes.SpawnPointPool
     97 
     98 
     99 def IsNodeGraphScope(scope):
    100     return scope.scopeType == ScopeTypes.NodeGraph
    101 
    102 
    103 def IsReusableScope(scope):
    104     return IsItemScope(scope) and IsPlayerItem(scope.id)
    105 
    106 
    107 def GetBlackboardScopeFromAddress(address):
    108     return address[0]
    109 
    110 
    111 def GetBlackboardChannelNameFromAddress(address):
    112     return address[1]