コード例 #1
0
        public override void OnUpdate(Context context)
        {
            if (context.LivingEnitites.Count == 0 || context.LocalPlayer == null)
            {
                return;
            }
            WeaponBase weapon = context.LocalPlayer.WeaponComponent.GetCurrentWeapon();
            bool       targetFound;

            HitUtils.HitData data;
            weapon.ComputeAimAssistDir(weapon.AttackPos, weapon.AttackDir, out targetFound, out data);
            if (targetFound)
            {
                context.LocalPlayer.BlackBoard.ActionAdd(AgentActionAttack.CreateAction(weapon.AttackDir));
            }

            /*
             * Transform camTransform = Camera.main.transform;
             * RaycastHit hit;
             * if (Physics.SphereCast(camTransform.position, 5f, camTransform.forward, out hit, 100f, -5))
             * {
             *  if (context.SearchForEntity(hit.transform) != null)
             *      context.LocalPlayer.BlackBoard.ActionAdd(AgentActionAttack.CreateAction(camTransform.forward));
             * }
             */
        }
コード例 #2
0
        public void Update(ComponentPlayer localPlayer)
        {
            VisibleEntities.Clear();
            LivingEnitites.Clear();
            //refresh context
            if (localPlayer != null)
            {
                LocalPlayer = localPlayer.Owner;
                float closestDist  = Mathf.Infinity;
                float closestvDist = closestDist;
                foreach (AgentHumanDT agentHumanDT in Mission.Instance.CurrentGameZone.Agents)
                {
                    if (agentHumanDT.IsAlive && !agentHumanDT.IsFriend(LocalPlayer))
                    {
                        LivingEnitites.Add(agentHumanDT);
                        HitUtils.HitData data;
                        bool             targetFound;
                        WeaponBase       weapon   = LocalPlayer.WeaponComponent.GetCurrentWeapon();
                        Vector3          startPos = LocalPlayer.Position;
                        startPos.y += 1.7f;
                        weapon.ComputeAimAssistDir(startPos, agentHumanDT.EyePosition - startPos, out targetFound, out data);
                        if (targetFound)
                        {
                            float vdist = Vector3.Distance(agentHumanDT.transform.position, localPlayer.transform.position);
                            if (closestvDist > vdist)
                            {
                                closestvDist   = vdist;
                                ClosestVEntity = agentHumanDT;
                            }
                            VisibleEntities.Add(agentHumanDT);
                        }

                        /*RaycastHit hit;
                         * if (Physics.SphereCast(localPlayer.Owner.EyePosition, 5f, agentHumanDT.ChestPosition - localPlayer.Owner.EyePosition, out hit, 100f, -5, QueryTriggerInteraction.UseGlobal))
                         * {
                         *  AgentHumanDT target;
                         *  int offset = 0;
                         *  do
                         *  {
                         *      target = m_SearchDelegates[offset](hit.transform);
                         *      offset++;
                         *  }
                         *  while (target == null && offset < m_SearchDelegates.Length);
                         *  if (target != null)
                         *      VisibleEntities.Add(agentHumanDT);
                         * }*/
                        float dist = Vector3.Distance(agentHumanDT.transform.position, localPlayer.transform.position);
                        if (closestDist > dist)
                        {
                            closestDist   = dist;
                            ClosestEntity = agentHumanDT;
                        }
                    }
                }
            }
            Utils.NativeLMSLog(string.Format("Context update: v {0} l {1} p {2}", VisibleEntities.Count, LivingEnitites.Count, localPlayer != null));
        }