コード例 #1
0
        public void loadBehaviourScopes()
        {
            scopesByRole = new Dictionary <string, BehaviorVariableScope>();
            foreach (BehaviorRoleDef behaviourDef in Main.settings.behaviours)
            {
                string filePath = $"{Main.modDir}/{Main.settings.behaviourDirectory}/{behaviourDef.behaviourFile}.json";
                if (File.Exists(filePath))
                {
                    string jData = File.ReadAllText(filePath);

                    BehaviorVariableScope behaviorVariableScope = getScope(behaviourDef.roleTag);
                    if (behaviorVariableScope == null)
                    {
                        behaviorVariableScope = new BehaviorVariableScope();
                        behaviorVariableScope.FromJSON(jData);
                        scopesByRole[behaviourDef.roleTag] = behaviorVariableScope;
                        Main.modLog.LogMessage($"Loaded {behaviourDef.behaviourFile} for tag: {behaviourDef.roleTag}");
                    }

                    foreach (AIMood mood in behaviourDef.moods)
                    {
                        if (mood != AIMood.Undefined)
                        {
                            behaviorVariableScope.ScopesByMood[mood] = new BehaviorVariableScope();
                            behaviorVariableScope.ScopesByMood[mood].FromJSON(jData);
                            Main.modLog.LogMessage($"Applied {behaviourDef.behaviourFile} for tag: {behaviourDef.roleTag}, with Mood {mood.ToString()}");
                        }
                    }
                }
                else
                {
                    Main.modLog.LogError($"Missing Behaviour file: {behaviourDef.behaviourFile}");
                }
            }
        }
コード例 #2
0
        public void OnBehaviorVariableScopeLoaded(string id, string json)
        {
            ScopeDesc             scopeDescription = scopeDescriptions.Find(item => item.Name == id);
            BehaviorVariableScope scope            = null;

            switch (scopeDescription.ScopeKind)
            {
            case ScopeKind.Global:
                scope = globalBehaviorVariableScope;
                break;

            case ScopeKind.Faction:
                scope = scopesByFaction[scopeDescription.FactionValue.ID];
                break;

            case ScopeKind.UnitRole:
                scope = scopesByRole[scopeDescription.UnitRole];
                break;

            case ScopeKind.Personality:
                scope = scopesByAIPersonality[scopeDescription.AIPersonality];
                break;

            case ScopeKind.SkillBased:
                scope = scopesByAISkill[scopeDescription.AISkillID];
                break;

            default:
                Debug.LogError("unhandled scopeKind: " + scopeDescription.ScopeKind);
                break;
            }
            if (scopeDescription.Mood != AIMood.Undefined)
            {
                scope = scope.ScopesByMood[scopeDescription.Mood];
            }
            scope.FromJSON(json);
        }