44
55using Intersect . Collections ;
66using Intersect . Extensions ;
7+ using Intersect . GameObjects ;
8+ using Intersect . GameObjects . Switches_and_Variables ;
79using Intersect . Models ;
10+ using MessagePack . Resolvers ;
811
912namespace Intersect . Enums
1013{
@@ -45,6 +48,11 @@ public static DatabaseObjectLookup GetLookup(this GameObjectType gameObjectType)
4548 return LookupUtils . GetLookup ( GetObjectType ( gameObjectType ) ) ;
4649 }
4750
51+ public static dynamic Get ( this GameObjectType gameObjectType , Guid id )
52+ {
53+ return LookupUtils . GetLookup ( GetObjectType ( gameObjectType ) ) . Get ( id ) ;
54+ }
55+
4856 public static IDatabaseObject CreateNew ( this GameObjectType gameObjectType )
4957 {
5058 var instance = Activator . CreateInstance (
@@ -54,5 +62,78 @@ public static IDatabaseObject CreateNew(this GameObjectType gameObjectType)
5462
5563 return instance as IDatabaseObject ;
5664 }
65+
66+ public static int ListIndex ( this GameObjectType gameObjectType , Guid id , VariableDataType dataTypeFilter = 0 )
67+ {
68+ var lookup = gameObjectType . GetLookup ( ) ;
69+
70+ if ( dataTypeFilter == 0 )
71+ {
72+ return lookup . KeyList . OrderBy ( pairs => lookup [ pairs ] ? . Name ) . ToList ( ) . IndexOf ( id ) ;
73+ }
74+
75+ return lookup
76+ . OrderBy ( kv => kv . Value ? . Name )
77+ . Select ( kv => kv . Value )
78+ . OfType < IVariableBase > ( )
79+ . Where ( desc => desc . Type == dataTypeFilter )
80+ . Select ( desc => desc . Id )
81+ . ToList ( )
82+ . IndexOf ( id ) ;
83+ }
84+
85+ public static VariableDataType GetVariableType ( this GameObjectType gameObjectType , Guid variableDescriptorId )
86+ {
87+ var lookup = gameObjectType . GetLookup ( ) ;
88+
89+ return lookup . ValueList
90+ . OfType < IVariableBase > ( )
91+ . FirstOrDefault ( var => var . Id == variableDescriptorId ) ? . Type ?? 0 ;
92+ }
93+
94+ public static Guid IdFromList ( this GameObjectType gameObjectType , int listIndex , VariableDataType dataTypeFilter = 0 )
95+ {
96+ var lookup = gameObjectType . GetLookup ( ) ;
97+
98+ if ( listIndex < 0 || listIndex >= lookup . KeyList . Count )
99+ {
100+ return Guid . Empty ;
101+ }
102+
103+ if ( dataTypeFilter == 0 )
104+ {
105+ return lookup . KeyList . OrderBy ( pairs => lookup [ pairs ] ? . Name ) . ToArray ( ) [ listIndex ] ;
106+ }
107+
108+ return lookup
109+ . OrderBy ( kv => kv . Value ? . Name )
110+ . Select ( kv => kv . Value )
111+ . OfType < IVariableBase > ( )
112+ . Where ( desc => desc . Type == dataTypeFilter )
113+ . Select ( desc => desc . Id )
114+ . Skip ( listIndex )
115+ . FirstOrDefault ( ) ;
116+ }
117+
118+ public static string [ ] Names ( this GameObjectType gameObjectType , VariableDataType dataTypeFilter = 0 )
119+ {
120+ if ( dataTypeFilter == 0 )
121+ {
122+ return gameObjectType
123+ . GetLookup ( )
124+ . OrderBy ( p => p . Value ? . Name )
125+ . Select ( pair => pair . Value ? . Name ?? PlayerVariableBase . Deleted )
126+ . ToArray ( ) ;
127+ }
128+
129+ return gameObjectType
130+ . GetLookup ( )
131+ . Select ( kv => kv . Value )
132+ . OfType < IVariableBase > ( )
133+ . Where ( desc => desc . Type == dataTypeFilter )
134+ . OrderBy ( p => p ? . Name )
135+ . Select ( pair => pair ? . Name ?? PlayerVariableBase . Deleted )
136+ . ToArray ( ) ;
137+ }
57138 }
58139}
0 commit comments