Esempio n. 1
0
    void LateUpdate()
    {
        if (currentAction != null && currentAction.running)
        {
            float distanceToTarget = Vector3.Distance(currentAction.target.transform.position, this.transform.position);
            if (currentAction.agent.hasPath && distanceToTarget < 2.0f)
            {
                if (!invoked)
                {
                    Invoke("CompleteAction", currentAction.duration);
                    invoked = true;
                }
            }
            return;
        }
        if (planner == null || actionQueue == null)
        {
            planner = new GPlanner();
            var sortedGoals = from entry in goals orderby entry.Value descending select entry;
            foreach (KeyValuePair <SubGoal, int> sg in sortedGoals)
            {
                actionQueue = planner.plan(actions, sg.Key.sgoals, beliefs);
                if (actionQueue != null)
                {
                    currentGoal = sg.Key;
                    break;
                }
            }
        }

        if (actionQueue != null && actionQueue.Count == 0)
        {
            if (currentGoal.remove)
            {
                goals.Remove(currentGoal);
            }
            planner = null;
        }

        if (actionQueue != null && actionQueue.Count > 0)
        {
            currentAction = actionQueue.Dequeue();
            if (currentAction.PrePerform())
            {
                if (currentAction.target == null && currentAction.targetTag != "")
                {
                    currentAction.target = GameObject.FindWithTag(currentAction.targetTag);
                }
                if (currentAction.targetTag != null)
                {
                    currentAction.running = true;
                    currentAction.agent.SetDestination(currentAction.target.transform.position);
                }
            }
            else
            {
                actionQueue = null;
            }
        }
    }
Esempio n. 2
0
        internal static void ContinueOnNormalDesktop(GAction fn, Form form,
                                                     ref GAction fnInvokeAfterClose, bool bSecureDesktop)
        {
            if (fn == null)
            {
                Debug.Assert(false); return;
            }
            if (form == null)
            {
                Debug.Assert(false); return;
            }
            Debug.Assert(fnInvokeAfterClose == null);

            if (bSecureDesktop)
            {
                if (!AskContinueOnNormalDesktop())
                {
                    return;
                }

                fnInvokeAfterClose = fn;
                form.DialogResult  = DialogResult.Cancel;
            }
            else
            {
                fn();
            }
        }
Esempio n. 3
0
 public Node(Node parent, float cost, Dictionary <AgentStates, int> worldState, GAction action)
 {
     this.parent = parent;
     this.cost   = cost;
     worldNow    = new Dictionary <AgentStates, int>(worldState);
     this.action = action;
 }
Esempio n. 4
0
        private void OnBtnHelp(object sender, EventArgs e)
        {
            GAction f = delegate() { AppHelp.ShowHelp(AppDefs.HelpTopics.KeySources, null); };

            ProtectedDialog.ContinueOnNormalDesktop(f, this, ref m_fInvokeAfterClose,
                                                    m_bSecureDesktop);
        }
Esempio n. 5
0
 public Node(Node parent, float cost, Dictionary <string, int> allstates, GAction action)
 {
     this.parent = parent;
     this.cost   = cost;
     this.state  = new Dictionary <string, int>(allstates);
     this.action = action;
 }
Esempio n. 6
0
        internal static DialogResult ShowDialog(IOConnectionInfo ioInfo,
                                                bool bCreatingNew, out KeyCreationFormResult r)
        {
            bool bSecDesk = (Program.Config.Security.MasterKeyOnSecureDesktop &&
                             ProtectedDialog.IsSupported);

            GFunc <KeyCreationForm> fConstruct = delegate()
            {
                KeyCreationForm f = new KeyCreationForm();
                f.InitEx(ioInfo, bCreatingNew);
                f.SecureDesktopMode = bSecDesk;
                return(f);
            };

            GFunc <KeyCreationForm, KeyCreationFormResult> fResultBuilder = delegate(
                KeyCreationForm f)
            {
                KeyCreationFormResult rEx = new KeyCreationFormResult();
                rEx.CompositeKey     = f.CompositeKey;
                rEx.InvokeAfterClose = f.InvokeAfterClose;
                return(rEx);
            };

            DialogResult dr = ProtectedDialog.ShowDialog <KeyCreationForm,
                                                          KeyCreationFormResult>(bSecDesk, fConstruct, fResultBuilder, out r);

            GAction fIac = ((r != null) ? r.InvokeAfterClose : null);

            if (fIac != null)
            {
                fIac();
            }

            return(dr);
        }
Esempio n. 7
0
        private void ShowHelpEx(string strTopic, string strSection)
        {
            GAction f = delegate() { AppHelp.ShowHelp(strTopic, strSection); };

            ProtectedDialog.ContinueOnNormalDesktop(f, this, ref m_fInvokeAfterClose,
                                                    m_bSecureDesktop);
        }
Esempio n. 8
0
        private static void CheckRefs(Module m, int iMdTokenType,
                                      GAction <Module, int> fCheck)
        {
            if ((m == null) || (fCheck == null))
            {
                Debug.Assert(false); return;
            }
            if ((iMdTokenType & 0x00FFFFFF) != 0)
            {
                Debug.Assert(false);                 // Not a valid MetadataTokenType
                return;
            }
            if ((iMdTokenType < 0) || (iMdTokenType == 0x7F000000))
            {
                Debug.Assert(false);                 // Loop below would need to be adjusted
                return;
            }

            try
            {
                // https://msdn.microsoft.com/en-us/library/ms404456(v=vs.100).aspx
                // https://docs.microsoft.com/en-us/dotnet/standard/metadata-and-self-describing-components
                int s = iMdTokenType | 1;                 // RID = 0 <=> 'nil token'
                int e = iMdTokenType | 0x00FFFFFF;

                for (int i = s; i <= e; ++i)
                {
                    fCheck(m, i);
                }
            }
            catch (ArgumentOutOfRangeException) { }            // End of metadata table
            catch (ArgumentException) { Debug.Assert(false); }
            // Other exceptions indicate an unresolved reference
        }
 public void PlanAborted(GAction aborter)
 {
     // An action bailed out of the plan. State has been reset to plan again.
     // Take note of what happened and make sure if you run the same goal again
     // that it can succeed.
     Debug.Log("<color=red>Plan Aborted</color> " + aborter);
 }
Esempio n. 10
0
 public GNode(GNode parent, float runningCost, Dictionary <string, object> state, GAction action)
 {
     this.parent      = parent;
     this.runningCost = runningCost;
     this.state       = state;
     this.action      = action;
 }
Esempio n. 11
0
        private void OnClickKeyFileCreate(object sender, EventArgs e)
        {
            IOConnectionInfo ioc      = m_ioInfo;
            bool             bSecDesk = m_bSecureDesktop;

            GAction f = delegate()
            {
                KeyFileCreationForm dlg = new KeyFileCreationForm();
                dlg.InitEx(ioc);

                DialogResult dr = dlg.ShowDialog();
                if ((dr == DialogResult.OK) && !bSecDesk)
                {
                    string strFile = dlg.ResultFile;
                    if (!string.IsNullOrEmpty(strFile))
                    {
                        m_cmbKeyFile.Items.Add(strFile);
                        m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1;

                        UpdateUIState();
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }

                UIUtil.DestroyForm(dlg);
            };

            ProtectedDialog.ContinueOnNormalDesktop(f, this, ref m_fInvokeAfterClose,
                                                    bSecDesk);
        }
Esempio n. 12
0
 // Constructor
 public Node(Node parent, float cost, Dictionary <GKey, int> allStates, GAction action)
 {
     this.Parent = parent;
     this.Cost   = cost;
     this.State  = new Dictionary <GKey, int>(allStates);
     this.Action = action;
 }
Esempio n. 13
0
 public void FillDummyActions()
 {
     m_actions = new GAction[(int)ACTION.count];
     for (int i = 0; i < (int)ACTION.count; i++)
     {
         m_actions[i] = new GAction("", "", null, null, null, 0, 0, new ACTION_EFFECT[0], false, false, false, false, null);
     }
 }
Esempio n. 14
0
    //Makes a new set of actions by removing one action from a set of actions.
    //SUBSET? WHY? This removes the possibility for repeating actions later in the tree.
    private HashSet <GAction> ActionSubset(HashSet <GAction> actions, GAction removeMe)
    {
        HashSet <GAction> subset = new HashSet <GAction>(actions);

        subset.Remove(removeMe);

        return(subset);
    }
Esempio n. 15
0
    void LateUpdate()
    {
        if (mCurrentAction != null && mCurrentAction.Running)
        {
            mCurrentAction.Perform();
            if (!mCurrentAction.Running)
            {
                mCurrentAction.PostPerform();
                mCurrentAction = null;
            }
            else
            {
                return;
            }
        }

        if (mPlanner == null || mActionQueue == null)
        {
            mPlanner = new GPlanner();

            var sortedGoals = from entry in mGoals orderby entry.Value descending select entry;

            foreach (KeyValuePair <GAgentSubGoal, int> sg in sortedGoals)
            {
                mActionQueue = mPlanner.Plan(mActions, sg.Key.SubGoals, Beliefs);
                if (mActionQueue != null)
                {
                    mCurrentGoal = sg.Key;
                    break;
                }
            }
        }

        if (mActionQueue != null && mActionQueue.Count == 0)
        {
            if (mCurrentGoal.Remove)
            {
                mGoals.Remove(mCurrentGoal);
            }
            mPlanner = null;
        }

        if (mActionQueue != null && mActionQueue.Count > 0)
        {
            GAction newAction = mActionQueue.Dequeue();
            //if (newAction != currentAction)
            // {
            mCurrentAction = newAction;

            if (!mCurrentAction.PrePerform())
            {
                mActionQueue = null;
            }
            // }
        }
    }
Esempio n. 16
0
        public IEnumerator InitializeTest()
        {
            clearCondition = new Dictionary <AgentStates, int>();


            gameObject = GameObject.Instantiate(new GameObject());
            actionWithoutPrecondition = gameObject.AddComponent <EmptyAction>();
            beforeAndAfterAction      = gameObject.AddComponent <BeforeAndAfterAction>();
            before2 = gameObject.AddComponent <Before2Action>();
            yield return(null);
        }
Esempio n. 17
0
    public void GenericActionEnd(ACTION action_id)
    {
        GAction ac = m_actions[(int)action_id];

        if (ac.m_attack_end_prefab)
        {
            CreateActionObject(action_id, ac.m_attack_end_prefab, ac.m_damage);
        }
        else
        {
            Util.Print("Missing damager/appearance for attack!!");
        }
    }
Esempio n. 18
0
    ///This will begin/refresh a sustained action - if possible.
    public void AttemptSustainedAction(ACTION action)
    {
        GAction g_action = GetAction(action);

        if (g_action != null && g_action.IsReady())
        {
            AttemptAction(ACTION.BLOCK, TRIGGER.READY);
        }
        else
        {
            g_action.m_action_timer.Sustain();
        }
    }
Esempio n. 19
0
    private List <GAction> ActionSubset(List <GAction> actions, GAction removeMe)
    {
        List <GAction> subset = new List <GAction>();

        foreach (GAction a in actions)
        {
            if (!a.Equals(removeMe))
            {
                subset.Add(a);
            }
        }
        return(subset);
    }
Esempio n. 20
0
    List <GAction> ActionSubset(List <GAction> actions, GAction actionToRemove)
    {
        List <GAction> subset = new List <GAction>();

        foreach (GAction action in actions)
        {
            if (!action.Equals(actionToRemove))
            {
                subset.Add(action);
            }
        }

        return(subset);
    }
Esempio n. 21
0
 public Node(Node parent, float cost, Dictionary <string, int> allStates, Dictionary <string, int> beliefstates, GAction action)
 {
     this.parent = parent;
     this.cost   = cost;
     this.state  = new Dictionary <string, int>(allStates);
     foreach (KeyValuePair <string, int> b in beliefstates)
     {
         if (!this.state.ContainsKey(b.Key))
         {
             this.state.Add(b.Key, b.Value);
         }
     }
     this.action = action;
 }
Esempio n. 22
0
    public Node(Node parent, float cost, Dictionary <string, int> allstates, Dictionary <string, int> beliefStates, GAction action)
    {
        this.parent = parent;
        this.cost   = cost;
        this.state  = new Dictionary <string, int>(allstates);// Copy the dictionary
        this.action = action;

        foreach (KeyValuePair <string, int> kvp in beliefStates)
        {
            if (!this.state.ContainsKey(kvp.Key))
            {
                this.state.Add(kvp.Key, kvp.Value);
            }
        }
    }
Esempio n. 23
0
    // Overloaded Constructor
    public Node(Node parent, float cost, Dictionary <string, int> allStates, Dictionary <string, int> beliefStates, GAction action)
    {
        this.parent = parent;
        this.cost   = cost;
        this.state  = new Dictionary <string, int>(allStates);

        //as well as the world states add the agents beliefs as states that can be
        //used to match preconditions
        foreach (KeyValuePair <string, int> b in beliefStates)
        {
            if (!this.state.ContainsKey(b.Key))
            {
                this.state.Add(b.Key, b.Value);
            }
        }
        this.action = action;
    }
Esempio n. 24
0
    ///This will begin an action - if possible.
    public void AttemptAction(ACTION action, TRIGGER trigger)
    {
        GAction g_action = GetAction(action);

        if (g_action == null)
        {
            return;
        }

        float target_distance = Mathf.Infinity;

        if (g_action.m_is_hostile)
        {
            if (g_action.m_requires_target && !HasHostileTarget())
            {
                return;
            }
            if (m_main_hostile_target != null)
            {
                target_distance = Vector3.Distance(
                    transform.position,
                    m_main_hostile_target.transform.position
                    );
            }
        }
        else
        {
            if (g_action.m_requires_target && !HasFriendlyTarget())
            {
                return;
            }
            if (m_main_hostile_target != null)
            {
                target_distance = Vector3.Distance(
                    transform.position,
                    m_main_friendly_target.transform.position);
            }
        }

        if (g_action.IsReadyConditionalAtRange(trigger, target_distance))
        {
            g_action.m_action_timer.AttemptAction();
            //m_entity.m_actor.PlayNormal(g_action.m_name + "Windup");
        }
    }
Esempio n. 25
0
    public void GenericActionStart(ACTION action_id)
    {
        GAction    ac            = m_actions[(int)action_id];
        GameObject action_object = null;

        if (ac.m_attack_start_prefab)
        {
            action_object = CreateActionObject(action_id, ac.m_attack_start_prefab, ac.m_damage);
        }
        else
        {
            Util.Print("Missing damager/appearance for attack!!");
        }
        if (action_object != null)
        {
            m_entity.m_actor.PlayBlocking("Attack");
        }
    }
Esempio n. 26
0
    public Node(Node parent, float cost, Dictionary <AgentStates, int> worldState, Dictionary <AgentStates, int> beliefStates,
                GAction action)
    {
        this.parent = parent;
        this.cost   = cost;
        worldNow    = new Dictionary <AgentStates, int>(worldState);
        this.action = action;

        //add belief states to world states.
        foreach (KeyValuePair <AgentStates, int> keyValuePair in beliefStates)
        {
            if (worldNow.ContainsKey(keyValuePair.Key))
            {
                return;
            }
            worldNow.Add(keyValuePair.Key, keyValuePair.Value);
        }
    }
Esempio n. 27
0
    private void CreatePerformActionState()
    {
        performActionState = (fsm, gagent) =>
        {
            if (!HasActionPlan())
            {
                Debug.Log("Done with actions, planning new actions.");
                fsm.PopState();
                fsm.PushState(planningState);
                worldDataProvider.ActionsFinished();
                return;
            }

            GAction action = currentActions.Peek();
            if (action.IsDone())
            {
                currentActions.Dequeue();
            }

            if (HasActionPlan())
            {
                action = currentActions.Peek();
                bool success = action.Perform(gagent);

                if (!success)
                {
                    fsm.PopState();
                    fsm.PushState(planningState);
                    worldDataProvider.PlanAborted(action);
                }
            }
            else
            {
                fsm.PopState();
                fsm.PushState(planningState);
                worldDataProvider.ActionsFinished();
            }
        };
    }
Esempio n. 28
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        serializedObject.Update();
        GAgentVisual agent = (GAgentVisual)target;

        GUILayout.Label("Name: " + agent.name);
        GUILayout.Label("Current Action: " + agent.gameObject.GetComponent <GAgent>().currentAction);
        GUILayout.Label("Actions: ");

        for (int i = 0; i < agent.gameObject.GetComponent <GAgent>().actions.Count; i++)
        {
            GAction a   = agent.gameObject.GetComponent <GAgent>().actions[i];
            string  pre = "";
            string  eff = "";

            foreach (KeyValuePair <AgentStates, int> p in a.preconditions)
            {
                pre += p.Key + ", ";
            }
            foreach (KeyValuePair <AgentStates, int> e in a.effects)
            {
                eff += e.Key + ", ";
            }

            GUILayout.Label(i + "===  " + a.actionName + "(" + pre + ")(" + eff + ")");
        }

        GUILayout.Label("Goals: ");
        foreach (KeyValuePair <SubGoal, int> g in agent.gameObject.GetComponent <GAgent>().goals)
        {
            GUILayout.Label("---: ");
            foreach (KeyValuePair <AgentStates, int> sg in g.Key.sgoal)
            {
                GUILayout.Label("=====  " + sg.Key);
            }
        }
        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 29
0
    private void LateUpdate()
    {
        if (currentAction != null && currentAction.running)
        {
            if (currentAction.agent.hasPath && currentAction.agent.remainingDistance < 1f)
            {
                if (!invoked)
                {
                    Invoke(nameof(CompleteAction), currentAction.duration);
                    invoked = true;
                }
            }


            return;
        }

        if (planner == null || actionQ == null)
        {
            planner = new Gplanner();
            IOrderedEnumerable <KeyValuePair <SubGoal, int> > sorted =
                from goal in goals orderby goal.Value descending select goal;

            foreach (KeyValuePair <SubGoal, int> sg in sorted)
            {
                actionQ = planner.plan(actions, sg.Key.sgoal, beliefs);
                if (actionQ != null)
                {
                    currentSubgoal = sg.Key;
                    break;
                }
            }
        }

        if (actionQ != null && actionQ.Count == 0)
        {
            if (currentSubgoal.remove)
            {
                goals.Remove(currentSubgoal);
            }

            planner = null;
        }

        if (actionQ != null && actionQ.Count > 0)
        {
            currentAction = actionQ.Dequeue();
            if (currentAction.PrePerform())
            {
                if (currentAction.target == null && currentAction.targetTag != "")
                {
                    currentAction.target = GameObject.FindWithTag(currentAction.targetTag);
                }

                if (currentAction.target != null)
                {
                    currentAction.running = true;
                    currentAction.agent.SetDestination(currentAction.target.transform.position);
                    Debug.Log("Selected object" + currentAction.target);
                }
                else
                {
                    Debug.LogError("No object found");
                }
            }
            else
            {
                actionQ = null;
            }
        }
    }
Esempio n. 30
0
        private byte[] GetSystemEntropy()
        {
            SHA512Managed h = new SHA512Managed();

            byte[] pb4 = new byte[4];
            byte[] pb8 = new byte[8];

            GAction <byte[], bool> f = delegate(byte[] pbValue, bool bClearValue)
            {
                if (pbValue == null)
                {
                    Debug.Assert(false); return;
                }
                if (pbValue.Length == 0)
                {
                    return;
                }
                h.TransformBlock(pbValue, 0, pbValue.Length, pbValue, 0);
                if (bClearValue)
                {
                    MemUtil.ZeroByteArray(pbValue);
                }
            };
            Action <int> fI32 = delegate(int iValue)
            {
                MemUtil.Int32ToBytesEx(iValue, pb4, 0);
                f(pb4, false);
            };
            Action <long> fI64 = delegate(long lValue)
            {
                MemUtil.Int64ToBytesEx(lValue, pb8, 0);
                f(pb8, false);
            };
            Action <string> fStr = delegate(string strValue)
            {
                if (strValue == null)
                {
                    Debug.Assert(false); return;
                }
                if (strValue.Length == 0)
                {
                    return;
                }
                f(StrUtil.Utf8.GetBytes(strValue), false);
            };

            fI32(Environment.TickCount);
            fI64(DateTime.UtcNow.ToBinary());

#if !KeePassLibSD && !NETSTANDARD2_0
            // In try-catch for systems without GUI;
            // https://sourceforge.net/p/keepass/discussion/329221/thread/20335b73/
            try
            {
                Point pt = Cursor.Position;
                fI32(pt.X);
                fI32(pt.Y);
            }
            catch (Exception) { Debug.Assert(NativeLib.IsUnix()); }
#endif

            try
            {
                fI32((int)NativeLib.GetPlatformID());
#if KeePassUAP
                fStr(EnvironmentExt.OSVersion.VersionString);
#else
                fStr(Environment.OSVersion.VersionString);
#endif

                fI32(Environment.ProcessorCount);

#if !KeePassUAP && !NETSTANDARD2_0
                fStr(Environment.CommandLine);
                fI64(Environment.WorkingSet);
#endif
            }
            catch (Exception) { Debug.Assert(false); }

            try
            {
                foreach (DictionaryEntry de in Environment.GetEnvironmentVariables())
                {
                    fStr(de.Key as string);
                    fStr(de.Value as string);
                }
            }
            catch (Exception) { Debug.Assert(false); }

            try
            {
#if KeePassUAP
                f(DiagnosticsExt.GetProcessEntropy(), true);
#elif !KeePassLibSD && !NETSTANDARD2_0
                using (Process p = Process.GetCurrentProcess())
                {
                    fI64(p.Handle.ToInt64());
                    fI32(p.HandleCount);
                    fI32(p.Id);
                    fI64(p.NonpagedSystemMemorySize64);
                    fI64(p.PagedMemorySize64);
                    fI64(p.PagedSystemMemorySize64);
                    fI64(p.PeakPagedMemorySize64);
                    fI64(p.PeakVirtualMemorySize64);
                    fI64(p.PeakWorkingSet64);
                    fI64(p.PrivateMemorySize64);
                    fI64(p.StartTime.ToBinary());
                    fI64(p.VirtualMemorySize64);
                    fI64(p.WorkingSet64);

                    // Not supported in Mono 1.2.6:
                    // fI32(p.SessionId);
                }
#endif
            }
            catch (Exception) { Debug.Assert(NativeLib.IsUnix()); }

            try
            {
                CultureInfo ci = CultureInfo.CurrentCulture;
                if (ci != null)
                {
                    fI32(ci.GetHashCode());
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            catch (Exception) { Debug.Assert(false); }

            f(Guid.NewGuid().ToByteArray(), false);
            f(GetCspRandom(), true);

            h.TransformFinalBlock(MemUtil.EmptyByteArray, 0, 0);
            byte[] pbHash = h.Hash;
            h.Clear();
            MemUtil.ZeroByteArray(pb4);
            MemUtil.ZeroByteArray(pb8);
            return(pbHash);
        }