Пример #1
0
        // Extract from Laalys actions' name the associated ComponentMonitoring and game action
        private static List <KeyValuePair <ComponentMonitoring, string> > extractTuplesFromActionsName(string [] actions)
        {
            List <KeyValuePair <ComponentMonitoring, string> > results = new List <KeyValuePair <ComponentMonitoring, string> >();

            // extract Monitoring id from actions' name
            foreach (string action in actions)
            {
                string[] tokens = action.Split('_');
                // last token is id
                int id;
                if (tokens.Length > 2 && Int32.TryParse(tokens[tokens.Length - 1], out id))
                {
                    ComponentMonitoring cm = MonitoringManager.getMonitorById(id);
                    if (cm != null)
                    {
                        // second to last is game action name => Add pair
                        results.Add(new KeyValuePair <ComponentMonitoring, string>(cm, tokens[tokens.Length - 2]));
                    }
                    else
                    {
                        UnityEngine.Debug.LogError("No MonitoringComponent with id: " + id);
                    }
                }
                else
                {
                    UnityEngine.Debug.LogError("Action name malformed: " + action);
                }
            }
            return(results);
        }
Пример #2
0
 internal void unregisterMonitor(ComponentMonitoring cm)
 {
     if (cm is FamilyMonitoring)
     {
         f_monitors.Remove((FamilyMonitoring)cm);
     }
     else
     {
         c_monitors.Remove(cm);
     }
 }
Пример #3
0
 internal void clone(ComponentMonitoring template)
 {
     this.PnmlFile = template.PnmlFile;
     this.comments = template.comments;
     this.PetriNet = new PetriNet(template.petriNet); // this set init transitionLinks (see setter defined before)
     this.PetriNet.attachID(this.id);                 // propagate local id
     for (int i = 0; i < template.transitionLinks.Count; i++)
     {
         this.transitionLinks[i].import(template.transitionLinks[i]);
     }
     this.fullPnSelected = template.fullPnSelected;
 }
Пример #4
0
 internal void registerMonitor(ComponentMonitoring cm)
 {
     if (cm is FamilyMonitoring)
     {
         if (!f_monitors.Contains((FamilyMonitoring)cm))
         {
             f_monitors.Add((FamilyMonitoring)cm);
         }
     }
     else
     {
         if (!c_monitors.Contains(cm))
         {
             c_monitors.Add(cm);
         }
     }
 }
Пример #5
0
        /// <summary>
        ///     Trace game action.
        /// </summary>
        /// <param name="monitor">The ComponentMonitoring to use to build trace.</param>
        /// <param name="actionName">Action name you want to trace, this name has to match with a transition defined into associated Petri Net of the "monitor" parameter <see cref="ComponentMonitoring.PnmlFile"/>.</param>
        /// <param name="performedBy">Specify who perform this action, the player or the system. <see cref="MonitoringManager.Source"/></param>
        /// <param name="processLinks">Set to false if the logic expression associated to the action include "+" operators AND the action performed by the player is not allowed by the system. In this case fourth parameters will not be processed. True (default) means fourth parameter will be analysed.</param>
        /// <param name="linksConcerned">links label concerned by this action. You can leave empty if only "*" operators are used in logic expression. Must be defined if logic expression associated to the action include "+" operators. For instance, if logic expression is "(l0+l1)*l3" you have to indicate which links to use to build the trace: l0 and l3 OR l1 and l3 => <code>MonitoringManager.trace(..., "l0", "l3");</code> OR <code>MonitoringManager.trace(..., "l1", "l3");</code></param>
        /// <returns> labels found for this game action if in game analysis is enabled (see: MonitoringManager). return empty Array else </returns>
        public static string[] trace(ComponentMonitoring monitor, string actionName, string performedBy, bool processLinks = true, params string[] linksConcerned)
        {
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1, true);                                                      // get caller stackFrame with informations
            string exceptionStackTrace = "(at " + stackFrame.GetFileName() + ":" + stackFrame.GetFileLineNumber().ToString() + ")";                     // to point where this function was called

            if (MonitoringManager.Instance == null)
            {
                throw new TraceAborted("No MonitoringManager found. You must add MonitoringManager component to one of your GameObject first (the Main_Loop for instance).", null);
            }

            string internalName = monitor.getInternalName(actionName, exceptionStackTrace, processLinks, linksConcerned);

            if (monitor.fullPnSelected >= MonitoringManager.Instance.PetriNetsName.Count)
            {
                monitor.fullPnSelected = 1;
            }
            string pnName = MonitoringManager.Instance.PetriNetsName[monitor.fullPnSelected];

            return(MonitoringManager.processTrace(pnName, internalName, performedBy));
        }
Пример #6
0
        private void ActionProcessing(GameObject go)
        {
            if (!this.Pause)
            {
                ActionPerformed[] listAP = go.GetComponents <ActionPerformed>();
                int             nb       = listAP.Length;
                ActionPerformed ap;
                for (int j = 0; j < nb; j++)
                {
                    ap = listAP[j];
                    ComponentMonitoring cMonitoring = null;
                    string tmpActionName            = "";
                    if (ap.name != "" && ap.overrideName != "")
                    {
                        //look for the ComponentMonitoring corresponding to name and overridename
                        int matched = 0;
                        foreach (ComponentMonitoring cm in go.GetComponents <ComponentMonitoring>())
                        {
                            foreach (TransitionLink tl in cm.transitionLinks)
                            {
                                if (tl.transition.label == ap.name && tl.transition.overridedLabel == ap.overrideName)
                                {
                                    if (matched == 0)
                                    {
                                        cMonitoring   = cm;
                                        tmpActionName = ap.name;
                                        tmpString     = cm.id.ToString();
                                    }
                                    else
                                    {
                                        tmpString = string.Concat(tmpString, ", ", cm.id);
                                    }
                                    matched++;
                                }
                            }
                            if (matched > 1)
                            {
                                Debug.LogException(new WarningException(string.Concat("Several ComponentMonitoring on ", go.name, " are matching the name \"", ap.name, "\" and the overrideName \"", ap.overrideName, "\". By default, the first one found is used to trace.",
                                                                                      Environment.NewLine, "The ", matched, " corresponding are: ", tmpString), ap.exceptionStackTrace));
                                break;
                            }
                        }
                        if (matched == 0 && ap.family == null)
                        {
                            throw new InvalidTraceException(string.Concat("Unable to trace action on \"", go.name, "\" because the name \"", ap.name, "\" and the overrideName \"", ap.overrideName, "\" in its ActionPerformed don't correspond to any ComponentMonitoring."), ap.exceptionStackTrace);
                        }
                    }
                    else if (ap.name != "")
                    {
                        //look for the ComponentMonitoring corresponding to the name
                        int matched = 0;
                        foreach (ComponentMonitoring cm in go.GetComponents <ComponentMonitoring>())
                        {
                            foreach (TransitionLink tl in cm.transitionLinks)
                            {
                                if (tl.transition.label == ap.name)
                                {
                                    if (matched == 0)
                                    {
                                        cMonitoring   = cm;
                                        tmpActionName = ap.name;
                                        tmpString     = cm.id.ToString();
                                    }
                                    else
                                    {
                                        tmpString = string.Concat(tmpString, ", ", cm.id);
                                    }
                                    matched++;
                                }
                            }
                            if (matched > 1)
                            {
                                Debug.LogException(new WarningException(string.Concat("Several ComponentMonitoring on ", go.name, " are matching the name \"", ap.name, "\". By default, the first one found is used to trace.",
                                                                                      Environment.NewLine, "The ", matched, " corresponding are: ", tmpString), ap.exceptionStackTrace));
                                break;
                            }
                        }
                        if (matched == 0 && ap.family == null)
                        {
                            throw new InvalidTraceException(string.Concat("Unable to trace action on \"", go.name, "\" because the name \"", ap.name, "\" in its ActionPerformed doesn't correspond to any ComponentMonitoring."), ap.exceptionStackTrace);
                        }
                    }
                    else if (ap.overrideName != "")
                    {
                        //look for the ComponentMonitoring corresponding to the overridename
                        int matched = 0;
                        foreach (ComponentMonitoring cm in go.GetComponents <ComponentMonitoring>())
                        {
                            foreach (TransitionLink tl in cm.transitionLinks)
                            {
                                if (tl.transition.overridedLabel == ap.overrideName)
                                {
                                    if (matched == 0)
                                    {
                                        cMonitoring   = cm;
                                        tmpActionName = tl.transition.label;
                                        tmpString     = cm.id.ToString();
                                    }
                                    else
                                    {
                                        tmpString = string.Concat(tmpString, ", ", cm.id);
                                    }
                                    matched++;
                                }
                            }
                            if (matched > 1)
                            {
                                Debug.LogException(new WarningException(string.Concat("Several ComponentMonitoring on ", go.name, " are matching the overrideName \"", ap.overrideName, "\". By default, the first one found is used to trace.",
                                                                                      Environment.NewLine, "The ", matched, " corresponding are: ", tmpString), ap.exceptionStackTrace));
                                break;
                            }
                        }
                        if (matched == 0 && ap.family == null)
                        {
                            throw new InvalidTraceException(string.Concat("Unable to trace action on \"", go.name, "\" because the overrideName \"", ap.overrideName, "\" in its ActionPerformed don't correspond to any ComponentMonitoring."), ap.exceptionStackTrace);
                        }
                    }
                    else
                    {
                        throw new InvalidTraceException(string.Concat("Unable to trace action on \"", go.name, "\" because no name given in its ActionPerformed component."), ap.exceptionStackTrace);
                    }

                    if (cMonitoring)
                    {
                        if (ap.performedBy == "system")
                        {
                            tmpPerformer = ap.performedBy;
                        }
                        else
                        {
                            tmpPerformer = "player";
                        }
                        if (ap.orLabels == null)
                        {
                            tmpLabels = MonitoringManager.trace(cMonitoring, tmpActionName, tmpPerformer);
                        }
                        else
                        {
                            tmpLabels = MonitoringManager.trace(cMonitoring, tmpActionName, tmpPerformer, true, ap.orLabels);
                        }
                        GameObjectManager.addComponent <Trace>(traces, new
                        {
                            actionName          = tmpActionName,
                            componentMonitoring = cMonitoring,
                            performedBy         = tmpPerformer,
                            time     = Time.time,
                            orLabels = ap.orLabels,
                            labels   = tmpLabels
                        });
                        // if (tmpLabels.Length != 0)
                        // tmpString = tmpLabels[0];
                        // for (int i = 1; i < tmpLabels.Length; i++)
                        // {
                        // tmpString = string.Concat(tmpString, " ", tmpLabels[i]);
                        // }
                        //Debug.Log(string.Concat(tmpPerformer, " ", tmpActionName, " ", go.name, System.Environment.NewLine, tmpString));
                        //File.AppendAllText("Data/UnityLogs.txt", string.Concat(System.Environment.NewLine, "[", DateTime.Now.ToString("yyyy.MM.dd.hh.mm"), "] Log - ", tmpPerformer, " ", tmpActionName, " ", go.name, System.Environment.NewLine, tmpString));
                    }
                    else if (ap.family != null)
                    {
                        try
                        {
                            tmpActionName = ap.name;
                            if (ap.performedBy == "system")
                            {
                                tmpPerformer = ap.performedBy;
                            }
                            else
                            {
                                tmpPerformer = "player";
                            }
                            if (ap.orLabels == null)
                            {
                                tmpLabels = MonitoringManager.trace(ap.family, tmpActionName, tmpPerformer);
                            }
                            else
                            {
                                tmpLabels = MonitoringManager.trace(ap.family, tmpActionName, tmpPerformer, true, ap.orLabels);
                            }
                            GameObjectManager.addComponent <Trace>(traces, new
                            {
                                actionName  = tmpActionName,
                                family      = ap.family,
                                performedBy = tmpPerformer,
                                time        = Time.time,
                                orLabels    = ap.orLabels,
                                labels      = tmpLabels
                            });
                            // if (tmpLabels.Length != 0)
                            // tmpString = tmpLabels[0];
                            // for (int i = 1; i < tmpLabels.Length; i++)
                            // {
                            // tmpString = string.Concat(tmpString, " ", tmpLabels[i]);
                            // }
                            //Debug.Log(string.Concat(tmpPerformer, " ", tmpActionName, " ", go.name, System.Environment.NewLine, tmpString));
                            //File.AppendAllText("Data/UnityLogs.txt", string.Concat(System.Environment.NewLine, "[", DateTime.Now.ToString("yyyy.MM.dd.hh.mm"), "] Log - ", tmpPerformer, " ", tmpActionName, " ", go.name, System.Environment.NewLine, tmpString));
                        }
                        catch (global::System.Exception)
                        {
                            throw new InvalidTraceException(string.Concat("Unable to trace action \"", tmpActionName, "\" on the family because of invalid arguments in the ActionPerformed component or the family is not monitored."), ap.exceptionStackTrace);
                        }
                    }
                }
                for (int j = nb - 1; j > -1; j--)
                {
                    GameObjectManager.removeComponent(listAP[j]);
                }
            }
        }
Пример #7
0
        /// <summary>
        ///     Get next actions to perform in order to reach targeted game action.
        /// </summary>
        /// <param name="monitor">The ComponentMonitoring on which you want reach action.</param>
        /// <param name="targetedActionName">Action name you want to reach, this name has to match with a transition defined into associated Petri Net of the "monitor" parameter <see cref="ComponentMonitoring.PnmlFile"/>. The special key word "##playerObjectives##" enable to target all player objective actions defined inside full Petri Net from which the monitor is part of (in this special case, "linksConcerned" parameter will be ignore).</param>
        /// <param name="maxActions">Maximum number of actions returned.</param>
        /// <param name="linksConcerned">links label concerned by this action. You can leave empty if only "*" operators are used in logic expression. Must be defined if logic expression associated to the action include "+" operators. For instance, if logic expression is "(l0+l1)*l3" you have to indicate which links to use to look for the trace: l0 and l3 OR l1 and l3 => <code>MonitoringManager.getNextActionToReach(..., "l0", "l3");</code> OR <code>MonitoringManager.getNextActionToReach(..., "l1", "l3");</code></param>
        /// <returns>List of Pairs including a ComponentMonitoring and its associated game action useful to reach the targeted action, the number of actions returned is less or equal to maxActions parameters.</returns>
        public static List <KeyValuePair <ComponentMonitoring, string> > getNextActionsToReach(ComponentMonitoring monitor, string targetedActionName, int maxActions, params string[] linksConcerned)
        {
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1, true);                                                      // get caller stackFrame with informations
            string exceptionStackTrace = "(at " + stackFrame.GetFileName() + ":" + stackFrame.GetFileLineNumber().ToString() + ")";                     // to point where this function was called

            if (MonitoringManager.Instance == null)
            {
                throw new TraceAborted("No MonitoringManager found. You must add MonitoringManager component to one of your GameObject first (the Main_Loop for instance).", null);
            }

            string internalName = targetedActionName;

            if (!targetedActionName.Equals("##playerObjectives##"))
            {
                internalName = monitor.getInternalName(targetedActionName, exceptionStackTrace, true, linksConcerned);
            }
            if (monitor.fullPnSelected >= MonitoringManager.Instance.PetriNetsName.Count)
            {
                monitor.fullPnSelected = 1;
            }
            string pnName = MonitoringManager.Instance.PetriNetsName[monitor.fullPnSelected];

            return(MonitoringManager.getNextActionsToReach(pnName, internalName, maxActions));
        }