Exemplo n.º 1
0
 public FBPlayerAgent(FBActor actor, behaviac.Workspace workspace)
 {
     this.actor = actor;
     behaviour  = createBehaviour(workspace);
     LogicEvent.add("onShootBallOut", this, "onShootBallOut");
     LogicEvent.add("onPlayTaunt", this, "onPlayTaunt");
 }
Exemplo n.º 2
0
    protected override Agent createBehaviour(behaviac.Workspace workspace)
    {
        var behaviour = new BTGoalKeeper();

        behaviour.Init(workspace);
        behaviour.agent = behaviour.gkAgent = this;
        return(behaviour);
    }
Exemplo n.º 3
0
    protected virtual Agent createBehaviour(behaviac.Workspace workspace)
    {
        var behaviour = new BTPlayer();

        behaviour.Init(workspace);
        behaviour.agent = this;
        return(behaviour);
    }
Exemplo n.º 4
0
    public FBGKCoachAgent(IGameInfo gameInfo, FBWorld world, FBTeam team, behaviac.Workspace workspace)
    {
        var behaviour = new BTGKCoach();

        behaviour.Init(workspace);
        behaviour.agent = this;
        base.behaviour  = behaviour;
        this.gameInfo   = gameInfo;
        this.world      = world;
        this.team       = team;
    }
Exemplo n.º 5
0
 public void Dispose()
 {
     ms_instance = null;
 }
Exemplo n.º 6
0
 public Workspace()
 {
     Debug.Check(ms_instance == null);
     ms_instance = this;
 }
Exemplo n.º 7
0
 public FBGKAgent(FBActor actor, behaviac.Workspace workspace) : base(actor, workspace)
 {
 }
Exemplo n.º 8
0
 private static void RegisterType(Type type, bool bIsAgentType)
 {
     Attribute[] array = (Attribute[])type.GetCustomAttributes(typeof(TypeMetaInfoAttribute), false);
     if (!bIsAgentType || array.Length > 0)
     {
         TypeMetaInfoAttribute      typeMetaInfoAttribute = (array.Length > 0) ? ((TypeMetaInfoAttribute)array[0]) : null;
         Agent.CTagObjectDescriptor descriptorByName      = Agent.GetDescriptorByName(type.get_FullName());
         if (type.get_BaseType() == typeof(Agent) || type.get_BaseType().IsSubclassOf(typeof(Agent)))
         {
             Agent.CTagObjectDescriptor descriptorByName2 = Agent.GetDescriptorByName(type.get_BaseType().get_FullName());
             descriptorByName.m_parent = descriptorByName2;
         }
         descriptorByName.type        = type;
         descriptorByName.displayName = ((typeMetaInfoAttribute == null || string.IsNullOrEmpty(typeMetaInfoAttribute.DisplayName)) ? type.get_FullName() : typeMetaInfoAttribute.DisplayName);
         descriptorByName.desc        = ((typeMetaInfoAttribute == null || string.IsNullOrEmpty(typeMetaInfoAttribute.Description)) ? descriptorByName.displayName : typeMetaInfoAttribute.Description);
         if (Utils.IsEnumType(type))
         {
             return;
         }
         BindingFlags bindingFlags = 62;
         FieldInfo[]  fields       = type.GetFields(bindingFlags);
         FieldInfo[]  array2       = fields;
         for (int i = 0; i < array2.Length; i++)
         {
             FieldInfo fieldInfo       = array2[i];
             bool      flag            = false;
             MemberMetaInfoAttribute a = null;
             if (bIsAgentType)
             {
                 Attribute[] array3 = (Attribute[])fieldInfo.GetCustomAttributes(typeof(MemberMetaInfoAttribute), false);
                 if (array3.Length > 0)
                 {
                     a    = (MemberMetaInfoAttribute)array3[0];
                     flag = true;
                 }
             }
             else
             {
                 flag = true;
             }
             if (flag)
             {
                 CMemberBase cMemberBase = new CMemberBase(fieldInfo, a);
                 for (int j = 0; j < descriptorByName.ms_members.Count; j++)
                 {
                     if (cMemberBase.GetId() == descriptorByName.ms_members[j].GetId())
                     {
                         CMemberBase cMemberBase2 = descriptorByName.ms_members[j];
                         break;
                     }
                 }
                 descriptorByName.ms_members.Add(cMemberBase);
                 if ((Utils.IsCustomClassType(fieldInfo.get_FieldType()) || Utils.IsEnumType(fieldInfo.get_FieldType())) && !Agent.IsTypeRegisterd(fieldInfo.get_FieldType().get_FullName()))
                 {
                     Workspace.RegisterType(fieldInfo.get_FieldType(), false);
                 }
             }
         }
         if (bIsAgentType)
         {
             MethodInfo[] methods = type.GetMethods(bindingFlags);
             MethodInfo[] array4  = methods;
             for (int k = 0; k < array4.Length; k++)
             {
                 MethodInfo  methodInfo = array4[k];
                 Attribute[] array5     = (Attribute[])methodInfo.GetCustomAttributes(typeof(MethodMetaInfoAttribute), false);
                 if (array5.Length > 0)
                 {
                     MethodMetaInfoAttribute a2   = (MethodMetaInfoAttribute)array5[0];
                     CMethodBase             item = new CMethodBase(methodInfo, a2, null);
                     descriptorByName.ms_methods.Add(item);
                     ParameterInfo[] parameters = methodInfo.GetParameters();
                     ParameterInfo[] array6     = parameters;
                     for (int l = 0; l < array6.Length; l++)
                     {
                         ParameterInfo parameterInfo = array6[l];
                         if ((Utils.IsCustomClassType(parameterInfo.get_ParameterType()) || Utils.IsEnumType(parameterInfo.get_ParameterType())) && !Agent.IsTypeRegisterd(parameterInfo.get_ParameterType().get_FullName()))
                         {
                             Workspace.RegisterType(parameterInfo.get_ParameterType(), false);
                         }
                     }
                     if ((Utils.IsCustomClassType(methodInfo.get_ReturnType()) || Utils.IsEnumType(methodInfo.get_ReturnType())) && !Agent.IsTypeRegisterd(methodInfo.get_ReturnType().get_FullName()))
                     {
                         Workspace.RegisterType(methodInfo.get_ReturnType(), false);
                     }
                 }
             }
             Type[] nestedTypes = type.GetNestedTypes(bindingFlags);
             Type[] array7      = nestedTypes;
             for (int m = 0; m < array7.Length; m++)
             {
                 Type        type2  = array7[m];
                 Attribute[] array8 = (Attribute[])type2.GetCustomAttributes(typeof(EventMetaInfoAttribute), false);
                 if (array8.Length > 0)
                 {
                     EventMetaInfoAttribute a3     = (EventMetaInfoAttribute)array8[0];
                     MethodInfo             method = type2.GetMethod("Invoke");
                     CNamedEvent            item2  = new CNamedEvent(method, a3, type2.get_Name());
                     descriptorByName.ms_methods.Add(item2);
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
        private static void RegisterMetas(Assembly a)
        {
            ListView <Type> listView = new ListView <Type>();

            Type[] types = a.GetTypes();
            Type[] array = types;
            for (int i = 0; i < array.Length; i++)
            {
                Type type3 = array[i];
                if ((type3.IsSubclassOf(typeof(Agent)) || Utils.IsStaticType(type3)) && !Workspace.IsRegisterd(type3))
                {
                    Attribute[] array2 = (Attribute[])type3.GetCustomAttributes(typeof(TypeMetaInfoAttribute), false);
                    if (array2.Length > 0)
                    {
                        Workspace.TypeInfo_t typeInfo_t = new Workspace.TypeInfo_t();
                        typeInfo_t.type = type3;
                        Workspace.ms_agentTypes.Add(typeInfo_t);
                        if (type3.get_BaseType() != null && (type3.get_BaseType() == typeof(Agent) || type3.get_BaseType().IsSubclassOf(typeof(Agent))))
                        {
                            listView.Add(type3.get_BaseType());
                        }
                        if (Utils.IsStaticType(type3))
                        {
                            TypeMetaInfoAttribute typeMetaInfoAttribute = array2[0] as TypeMetaInfoAttribute;
                            Agent.RegisterStaticClass(type3, typeMetaInfoAttribute.DisplayName, typeMetaInfoAttribute.Description);
                        }
                    }
                }
            }
            foreach (Type type in listView)
            {
                if (!Workspace.IsRegisterd(type) && Workspace.ms_agentTypes.Find((Workspace.TypeInfo_t t) => t.type == type) == null)
                {
                    Workspace.TypeInfo_t typeInfo_t2 = new Workspace.TypeInfo_t();
                    typeInfo_t2.type         = type;
                    typeInfo_t2.bIsInherited = true;
                    Workspace.ms_agentTypes.Add(typeInfo_t2);
                }
            }
            Workspace.ms_agentTypes.Sort(delegate(Workspace.TypeInfo_t x, Workspace.TypeInfo_t y)
            {
                if (x.bIsInherited && !y.bIsInherited)
                {
                    return(-1);
                }
                if (!x.bIsInherited && y.bIsInherited)
                {
                    return(1);
                }
                if (x.type.IsSubclassOf(y.type))
                {
                    return(1);
                }
                if (y.type.IsSubclassOf(x.type))
                {
                    return(-1);
                }
                return(x.type.get_FullName().CompareTo(y.type.get_FullName()));
            });
            using (List <Workspace.TypeInfo_t> .Enumerator enumerator2 = Workspace.ms_agentTypes.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    Workspace.TypeInfo_t current = enumerator2.get_Current();
                    Type type2 = current.type;
                    Workspace.RegisterType(type2, true);
                }
            }
        }
Exemplo n.º 10
0
        private static void RegisterMetas()
        {
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            Workspace.RegisterMetas(callingAssembly);
        }
Exemplo n.º 11
0
 public static bool ExportMetas(string filePath)
 {
     return(Workspace.ExportMetas(filePath, false));
 }
Exemplo n.º 12
0
        public static void RegisterBehaviorNode()
        {
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            Workspace.RegisterBehaviorNode(callingAssembly);
        }
Exemplo n.º 13
0
 public static bool Load(string relativePath)
 {
     return(Workspace.Load(relativePath, false));
 }
Exemplo n.º 14
0
        public static bool Load(string relativePath, bool bForce)
        {
            BehaviorTree behaviorTree = null;

            if (Workspace.BehaviorTrees.ContainsKey(relativePath))
            {
                if (!bForce)
                {
                    return(true);
                }
                behaviorTree = Workspace.BehaviorTrees[relativePath];
            }
            string text = Workspace.WorkspaceExportPath;

            text += relativePath;
            string ext = string.Empty;

            Workspace.EFileFormat eFileFormat  = Workspace.FileFormat;
            Workspace.EFileFormat eFileFormat2 = eFileFormat;
            if (eFileFormat2 != Workspace.EFileFormat.EFF_xml)
            {
                if (eFileFormat2 == Workspace.EFileFormat.EFF_default)
                {
                    ext = ".xml";
                    if (FileManager.Instance.FileExist(text, ext))
                    {
                        eFileFormat = Workspace.EFileFormat.EFF_xml;
                    }
                    else
                    {
                        ext = ".bson";
                        if (FileManager.Instance.FileExist(text, ext))
                        {
                            throw new NotImplementedException("bson support has been removed!!!");
                        }
                        eFileFormat = Workspace.EFileFormat.EFF_cs;
                    }
                }
            }
            else
            {
                ext = ".xml";
            }
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            if (behaviorTree == null)
            {
                flag3        = true;
                behaviorTree = new BehaviorTree();
                Workspace.BehaviorTrees[relativePath] = behaviorTree;
            }
            if (eFileFormat == Workspace.EFileFormat.EFF_xml)
            {
                byte[] array = Workspace.ReadFileToBuffer(text, ext);
                if (array != null)
                {
                    if (!flag3)
                    {
                        flag2 = true;
                        behaviorTree.Clear();
                    }
                    if (eFileFormat == Workspace.EFileFormat.EFF_xml)
                    {
                        flag = behaviorTree.load_xml(array);
                    }
                    Workspace.PopFileFromBuffer(text, ext, array);
                }
            }
            else if (eFileFormat == Workspace.EFileFormat.EFF_cs)
            {
                if (!flag3)
                {
                    flag2 = true;
                    behaviorTree.Clear();
                }
                try
                {
                    MethodInfo methodInfo = null;
                    if (Workspace.BTCreators.ContainsKey(relativePath))
                    {
                        methodInfo = Workspace.BTCreators[relativePath];
                    }
                    else
                    {
                        string typeName = "behaviac.bt_" + relativePath.Replace("/", "_");
                        Type   type     = Utils.GetType(typeName);
                        if (type != null)
                        {
                            methodInfo = type.GetMethod("build_behavior_tree", 24);
                            if (methodInfo != null)
                            {
                                Workspace.BTCreators[relativePath] = methodInfo;
                            }
                        }
                    }
                    if (methodInfo != null)
                    {
                        object[] array2 = new object[]
                        {
                            behaviorTree
                        };
                        flag = (bool)methodInfo.Invoke(null, array2);
                    }
                }
                catch (Exception ex)
                {
                    string text2 = string.Format("The behavior {0} failed to be loaded : {1}", relativePath, ex.get_Message());
                }
            }
            if (flag)
            {
                if (!flag3)
                {
                }
            }
            else if (flag3)
            {
                bool flag4 = Workspace.BehaviorTrees.Remove(relativePath);
            }
            else if (flag2)
            {
                Workspace.BehaviorTrees.Remove(relativePath);
            }
            return(flag);
        }
Exemplo n.º 15
0
 public static bool SetWorkspaceSettings(string workspaceExportPath)
 {
     return(Workspace.SetWorkspaceSettings(workspaceExportPath, Workspace.EFileFormat.EFF_xml));
 }