bool AIShipIsInMaxRange(AI_Ship ship)
 {
     if (components.Count(comp => comp is Component_Weapon) == 0) return false;
     float maxWeaponRange = components
         .Where(comp => comp is Component_Weapon)
         .Select(comp => (Component_Weapon)comp)
         .Max(weapon => weapon.range);
     float distance = Vector3.Distance(ship.transform.position, trans.position);
     return distance <= maxWeaponRange;
 }
 void aiShip_OnShipMouseEnter(AI_Ship ship)
 {
     if(AIShipIsInMaxRange(ship))
     {
         combatInterface.SetCursorType(CursorType.Attack);
     }
     else
     {
         combatInterface.SetCursorType(CursorType.Invalid);
     }
     ship.ShowHPBars(true);
 }
 void aiShip_OnShipClick(AI_Ship ship)
 {
     if (AIShipIsInMaxRange(ship))
     {
         Debug.Log("on Ship click " + ship);
         TutorialSystem.Instance.ShowTutorial(TutorialSystem.TutorialType.ClickEnemyToEngage, false);
         combatInterface.SetCursorType(CursorType.Default);
         ship.ShowHPBars(false);
         targetShip = ship;
         ChangeState(PlayerState.TargetingEnemy);
     }
 }
    private IEnumerator ComponentSelectionAndTargeting()
    {
        //stop listening to mouse events on ai ships
        SubscribeToAIShipMouseEvents(false);
        //show enemy target
        int targetShipIndex = 0;
        List<AI_Ship> aiShips = TurnBasedCombatSystem.Instance.ai_Ships;
        int numAIShips = aiShips.Count;
        #if FULL_DEBUG
        if (numAIShips == 0)
        {
            Debug.LogError("No ai ships found");
        }
        #endif

        //targetShip = aiShips[targetShipIndex];
        targetShipIndex = aiShips.IndexOf(targetShip);
        Transform aiTargetTrans = targetShip.transform;
        spaceGround.Display(false);
        //camera
        yield return StartCoroutine(CameraDirector.Instance.OverheadAimAt(trans, aiTargetTrans, GlobalVars.CameraAimAtPeriod));
        //show comp seleciton panel
        combatInterface.EnableComponentSelectionPanel(true);
        combatInterface.ShowComponentSelectionPanel(true);
        //show hotkeys
        //combatInterface.ShowComponentHotkeyButtons(SelectAllComponents, components.Where(c => c.CanActivate));
        ShowTargetingPanel(true);
        trans.LookAt(aiTargetTrans);
        InputManager.Instance.RegisterKeysDown(TargetNext, KeyCode.Tab);
        InputManager.Instance.RegisterKeysDown(StopTargetingSequence, KeyCode.Escape);
        TutorialSystem.Instance.ShowNextTutorial(TutorialSystem.TutorialType.ClickEnemyToEngage);

        while (!attackTargetConfirmed)
        {
            if (stopTargetingSequence)
            {
                startTargetingSequence = false;
                stopTargetingSequence = false;
                targetComponent = null;
                ShowTargetingPanel(false);
                combatInterface.ShowComponentSelectionPanel(false);
                InputManager.Instance.DeregisterKeysDown(TargetNext, KeyCode.Tab);
                InputManager.Instance.DeregisterKeysDown(StopTargetingSequence, KeyCode.Escape);
                yield return StartCoroutine(CameraDirector.Instance.MoveToFocusOn(trans, GlobalVars.CameraMoveToFocusPeriod));
                break;
            }
            if (targetNext)
            {
                ShowTargetingPanel(false);
                targetShipIndex = ++targetShipIndex % numAIShips;
                targetShip = aiShips[targetShipIndex];
                ShowTargetingPanel(true);
                aiTargetTrans = targetShip.transform;
                yield return StartCoroutine(CameraDirector.Instance.OverheadAimAt(trans, aiTargetTrans, GlobalVars.CameraAimAtPeriod));
                trans.LookAt(aiTargetTrans);
                targetNext = false;
            }
            yield return null;
        }
        ShowTargetingPanel(false);
        SubscribeToAIShipMouseEvents(true);
        combatInterface.ShowComponentSelectionPanel(false);
        InputManager.Instance.DeregisterKeysDown(TargetNext, KeyCode.Tab);
        InputManager.Instance.DeregisterKeysDown(StopTargetingSequence, KeyCode.Escape);
    }
 void aiShip_OnShipMouseExit(AI_Ship ship)
 {
     combatInterface.SetCursorType(CursorType.Default);
     ship.ShowHPBars(false);
 }
 void aiShip_OnShipMouseEnter(AI_Ship ship)
 {
     if (!startTargetingSequence)
     {
         combatInterface.SetCursorType(CursorType.Attack);
         ship.ShowHPBars(true);
     }
 }
 void aiShip_OnShipClick(AI_Ship ship)
 {
     combatInterface.SetCursorType(CursorType.Default);
     startTargetingSequence = true;
     targetShip = ship;
     Debug.Log("on Ship click " + ship);
     ship.ShowHPBars(false);
 }
Пример #8
0
    //Waits for the player to select the target ship and target component to fire the selected weapons at
    private IEnumerator WeaponTargetingSequence()
    {
        targetShipIndex = 0;
        targetConfirmed = false;
        targetComponent = null;

        List<AI_Ship> ai_ships = TurnBasedCombatSystem.Instance.ai_Ships;
        numAiShips = ai_ships.Count;
        //Debug.Log(targetShipIndex);
        targetShip = ai_ships[targetShipIndex];
        Transform aiTargetTrans;

        #if UNITY_EDITOR
        Debug.Log("Select Target to fire upon: [Click] to confirm, [Esc] to cancel, [Tab] to switch targets");
        #endif

        #if !NO_DEBUG
        if (numAiShips == 0)
        {
            Debug.LogError("No ai ships found");
        }
        #endif
        //aims camera at the ship that is currently targeted
        aiTargetTrans = targetShip.transform;
        yield return StartCoroutine(CameraDirector.Instance.OverheadAimAt(trans, aiTargetTrans, GlobalVars.CameraAimAtPeriod));
        trans.LookAt(aiTargetTrans);

        //shows the targeting panel for the target ship
        TargetShip(targetShip, true);

        //runs until a targetcomponent is successfully confirmed (until a component is clicked on)
        while(!targetConfirmed)
        {
            //end targeting sequence upon hitting Esc
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                TargetShip(targetShip, false);
                targetConfirmed = true;
                targetComponent = null;
            }
            //switch to the next ai ship
            if (Input.GetKeyDown(KeyCode.Tab))
            {
                TargetShip(targetShip, false);
                targetShipIndex = ++targetShipIndex % numAiShips;
                targetShip = ai_ships[targetShipIndex];
                TargetShip(targetShip, true);

                //aims camera at the ship that is currently targeted
                aiTargetTrans = targetShip.transform;
                yield return StartCoroutine(CameraDirector.Instance.OverheadAimAt(trans, aiTargetTrans, GlobalVars.CameraAimAtPeriod));
                trans.LookAt(aiTargetTrans);
            }
            yield return null;

        }//while
    }