Exemplo n.º 1
0
    private void FightClosestTarget()
    {
        TargetableByAI closestTarget = AI_Controller.Instance.GetClosestTarget(transform.position);

        if (closestTarget != null)
        {
            charController.Command_Attack(closestTarget.GetComponent <Alive>());
        }
    }
Exemplo n.º 2
0
    public TargetableByAI GetClosestTarget(Vector3 position)
    {
        float          minDistance   = 99999;
        TargetableByAI closestTarget = null;

        foreach (TargetableByAI target in targets)
        {
            if ((target != null) && (!target.GetComponent <Alive>().IsDead))
            {
                float distance = Vector3.Distance(position, target.transform.position);
                if ((distance < minDistance) || (closestTarget == null))
                {
                    minDistance   = distance;
                    closestTarget = target;
                }
            }
        }

        return(closestTarget);
    }
Exemplo n.º 3
0
    public override void UpdateSystem()
    {
        Dependency = JobHandle.CombineDependencies(Dependency, m_raycastSystem.RaycastSystemDependency);

        if (m_inputManagementSystem.InputData.mouseInput.rightClickPressed)
        {
            NativeArray <RaycastResult> raycastResult = m_raycastSystem.RaycastResult;
            bool shiftPressed = m_inputManagementSystem.InputData.keyboardInput.shiftDown;

            Dependency = Entities.WithReadOnly(raycastResult).WithAll <SelectedTag>().ForEach((Entity entity, int entityInQueryIndex, ref CurrentTarget currentTarget, ref DynamicBuffer <Command> commandBuffer) =>
            {
                if (raycastResult[0].raycastTargetType == RaycastTargetType.Ground)
                {
                    TargetData targetData = new TargetData
                    {
                        targetEntity = raycastResult[0].raycastTargetEntity,
                        targetType   = AITargetType.Ground,
                        targetPos    = raycastResult[0].hitPosition
                    };

                    if (shiftPressed)
                    {
                        CommandProcessSystem.QueueCommand(CommandType.Move, commandBuffer, targetData, false);
                    }
                    else
                    {
                        commandBuffer.Clear();
                        CommandProcessSystem.QueueCommand(CommandType.Move, commandBuffer, targetData, true);
                    }

                    return;
                }

                Translation targetPos = GetComponent <Translation>(raycastResult[0].raycastTargetEntity);
                TargetableByAI target = GetComponent <TargetableByAI>(raycastResult[0].raycastTargetEntity);

                if (raycastResult[0].raycastTargetType == RaycastTargetType.ResourceNode)
                {
                    TargetData targetData = new TargetData
                    {
                        targetEntity = raycastResult[0].raycastTargetEntity,
                        targetType   = target.targetType,
                        targetPos    = targetPos.Value
                    };

                    if (shiftPressed)
                    {
                        CommandProcessSystem.QueueCommand(CommandType.Harvest, commandBuffer, targetData, false);
                    }
                    else
                    {
                        commandBuffer.Clear();
                        CommandProcessSystem.QueueCommand(CommandType.Harvest, commandBuffer, targetData, true);
                    }
                    return;
                }

                if (raycastResult[0].raycastTargetType == RaycastTargetType.Enemy)
                {
                    TargetData targetData = new TargetData
                    {
                        targetEntity = raycastResult[0].raycastTargetEntity,
                        targetType   = target.targetType,
                        targetPos    = targetPos.Value
                    };

                    if (shiftPressed)
                    {
                        CommandProcessSystem.QueueCommand(CommandType.Attack, commandBuffer, targetData, false);
                    }
                    else
                    {
                        commandBuffer.Clear();
                        CommandProcessSystem.QueueCommand(CommandType.Attack, commandBuffer, targetData, true);
                    }

                    return;
                }
            }).ScheduleParallel(Dependency);
        }
    }