Ejemplo n.º 1
0
    private void GetClosestPickup()
    {
        if (playerControl.IsDead)
        {
            return;
        }

        float distance = 100000;
        int   target   = -1;

        for (int i = 0; i < pickupSpawner.pickupSpawns.Length; i++)
        {
            if (pickupSpawner.pickupSpawns[i].Pickup != null)// && pickupSpawner.pickupSpawns[i].Pickup.GetComponent<DamagableObject>() == null)
            {
                float tempDistance = Vector2.Distance(pickupSpawner.pickupSpawns[i].Pickup.transform.position, rigidbody2D.position);
                if (tempDistance < distance)
                {
                    distance = tempDistance;
                    target   = i;
                }
            }
        }

        if (target > -1)
        {
            aiPhase      = AIPhase.PathToPickup;
            targetObject = pickupSpawner.pickupSpawns[target].Pickup.transform;
            GetDestinationPath(targetObject.transform.position);
        }
        else
        {
            targetObject = null;
        }
    }
Ejemplo n.º 2
0
    void UpdatePathToTarget(Vector2 distanceBetween, float minDistance)
    {
        if (distanceBetween.x < minDistance && distanceBetween.y < 0.2f)
        {
            if (aiPhase == AIPhase.PathToEnemy)
            {
                aiPhase = AIPhase.InCombat;
            }
            else if (aiPhase == AIPhase.PathToPickup)
            {
                if (targetObject.gameObject.GetComponent <DamagableObject>() != null)
                {
                    enemyControl = targetObject.gameObject.GetComponent <DamagableObject>();
                    aiPhase      = AIPhase.BreakingCrate;
                }
                else
                {
                    GetClosestTarget();
                }
            }
            else if (aiPhase == AIPhase.FreePath)
            {
                if (navPath.Count == 0)
                {
                    GetClosestTarget();
                }
            }
            else
            {
                GetClosestTarget();
            }
        }

        if (jumpPrepare)
        {
            if (playerControl.JumpCount == 0)
            {
                playerControl.Jump();
                jumpPrepare = false;
            }
        }
        else
        {
            if (destinationNode != null)
            {
                MoveTowardsNode(destinationNode);
            }
        }

        if (destinationNode == null || Vector2.Distance(transform.position, destinationNode.node.transform.position) < 0.5f)
        {
            ChooseNextPathNode();
        }
    }
Ejemplo n.º 3
0
    IEnumerator IAMove()
    {
        if (!nextDoorTarget)
        {
            yield break;
        }
        SetNavigation(nextDoorTarget.Cell, true);
        currentAIPhase = AIPhase.Move;
        yield return(StartCoroutine(Move()));

        endMoveThinking = true;
    }
Ejemplo n.º 4
0
 void Phase7(GameTime gametime)
 {
     //30 seconds follow and shoot other player with shield, run when shield is not active
     if (tempoAI >= PHASE7_TIME)
     {
         currentAIPhase = AIPhase.Phase8;
         tempoAI        = 0;
     }
     else
     {
         tempoAI += gametime.ElapsedGameTime.Ticks;
     }
 }
Ejemplo n.º 5
0
 void Phase6(GameTime gametime)
 {
     //30 seconds follow, dodge and shoot other player with shield
     if (tempoAI >= PHASE6_TIME)
     {
         currentAIPhase = AIPhase.Phase7;
         tempoAI        = 0;
     }
     else
     {
         tempoAI += gametime.ElapsedGameTime.Ticks;
     }
 }
Ejemplo n.º 6
0
 void Phase1(GameTime gametime)
 {
     //do nothing 2 seconds
     if (tempoAI >= PHASE1_TIME)
     {
         currentAIPhase = AIPhase.Phase2;
         tempoAI        = 0;
     }
     else
     {
         tempoAI += gametime.ElapsedGameTime.Ticks;
     }
 }
Ejemplo n.º 7
0
    private void GetClosestTarget()
    {
        if (playerControl.IsDead)
        {
            return;
        }

        if (Random.Range(0, 100) < 50)
        {
            aiPhase      = AIPhase.PathToEnemy;
            enemyControl = enemies[Random.Range(0, enemies.Count)].GetComponentInParent <PlayerController>();
            GetDestinationPath(enemyControl.transform.position);

            return;
        }

        float distance = 100000;
        int   target   = -1;

        for (int i = 0; i < enemies.Count; i++)
        {
            if (!enemies[i].GetComponent <PlayerController>().IsDead&& !enemies[i].GetComponent <PlayerController>().Invulnerable)
            {
                float tempDistance = Vector2.Distance(enemies[i].position, rigidbody2D.position);
                if (tempDistance < distance)
                {
                    distance = tempDistance;
                    target   = i;
                }
            }
        }

        if (target > -1)
        {
            aiPhase      = AIPhase.PathToEnemy;
            enemyControl = enemies[target].GetComponentInParent <PlayerController>();
            GetDestinationPath(enemyControl.transform.position);
        }
        else
        {
            enemyControl = null;
        }
    }
Ejemplo n.º 8
0
 void Phase3(GameTime gametime)
 {
     //do nothing 2 seconds with shield
     if (tempoEscudo <= 0 && escudoActivo == false)
     {
         escudoActivo = true;
         escudoActual = ESCUDO;
         tempoEscudo  = TEMPO_ARREFECIMENTO_ESCUDO;
     }
     if (tempoAI >= PHASE3_TIME)
     {
         currentAIPhase = AIPhase.Phase4;
         tempoAI        = 0;
     }
     else
     {
         tempoAI += gametime.ElapsedGameTime.Ticks;
     }
 }
Ejemplo n.º 9
0
    /*
     * Transitions to the next phase by loading in the next set of moves.
     */
    public static void NextPhase()
    {
        phaseIndex++;
        if (phaseIndex > phases.Count)
        {
            Debug.LogError("You win!");
        }

        currentPhase   = phases[phaseIndex];
        self.healthMax = currentPhase.maxHealth;
        GameManager.Arena.RadiusInWorldUnits = currentPhase.maxArenaRadius;

        // Heal up to the new max health.
        CombatCore.Entity.HealEntity(self, float.PositiveInfinity);

        self.SetInvincible(true);
        Add(new Moves.Basic.Teleport(World.Arena.CENTER).Wait(3f));
        Add(new AISequence(() => { self.SetInvincible(false); }));
    }
Ejemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        Profiler.BeginSample("Initialize phases");
        AIPhase.Load();
        Profiler.EndSample();


        phases = new List <AIPhase>();

        //phases.Add(AIPhase.PHASE_TUTORIAL_1);
        //phases.Add(AIPhase.PHASE_TUTORIAL_2);
        //phases.Add(AIPhase.PHASE_TUTORIAL_3);
        //phases.Add(AIPhase.PHASE1);
        phases.Add(AIPhase.PHASE_TEST);
        //phases.Add(AIPhase.PHASE_UNIT_TEST);

        StartCoroutine(ExecuteQueue());
        NextPhase();
    }
Ejemplo n.º 11
0
    IEnumerator AIFSM()
    {
        currentAIPhase = AIPhase.Idle;
        if (!nextRoomInvestigate)
        {
            nextRoomInvestigate = GetNextRoom();
        }
        if ((!nextDoorTarget))
        {
            nextDoorTarget = GetNextDoor();
        }
        //Debug.Log($"it's my turn {characterRef.ColorName} with {nextRoomInvestigate.RoomName}");
        yield return(StartCoroutine(IAMove()));

        yield return(StartCoroutine(IAEndMove()));

        yield return(StartCoroutine(IASuggest()));

        OnEndTurn?.Invoke();
    }
Ejemplo n.º 12
0
    IEnumerator IASuggest()
    {
        if (!isInRoom)
        {
            yield break;
        }
        CE_Card    _pickCharacterCard = CE_GameManager.Instance.GameDeck.GetCard(NoteSystem.PickRandomNotes(CardType.Character).ID);
        CE_Card    _pickWeaponCard    = CE_GameManager.Instance.GameDeck.GetCard(NoteSystem.PickRandomNotes(CardType.Weapon).ID);
        CE_Card    _pickRoomCard      = CE_GameManager.Instance.GameDeck.GetCard(nextRoomInvestigate.ID);
        CE_Suggest _suggest           = new CE_Suggest(_pickCharacterCard, _pickRoomCard, _pickWeaponCard);

        OnStartSuggest?.Invoke(_suggest, this);
        int _askIndex = CE_GameManager.Instance.CurrentCharacterTurnIndex;

        Debug.Log($"{characterRef.ColorName} is suggesting {_suggest.Room.Name} with {_suggest.Weapon.Name} at {_suggest.Character.Name}");
        while (isInRoom && currentAIPhase == AIPhase.Suggest)
        {
            _askIndex++;
            _askIndex = _askIndex > CE_GameManager.Instance.AllCharacterInGame.Count - 1 ? 0 : _askIndex;
            IGamePlayable _askTo  = CE_GameManager.Instance.AllCharacterInGame[_askIndex];
            CE_Card       _result = _askTo.HandCards.GetSuggestCard(_suggest);
            OnSuggestProgress?.Invoke(_suggest, this, _askTo, _result);
            Debug.Log($"{_askTo.CharacterRef.ColorName} {(_result == null ? "can't" : "can")} answer.");
            if (_result != null)
            {
                NoteSystem.MatchCard(_result.ID);
                currentAIPhase = AIPhase.Idle;
            }
            if (CE_GameManager.Instance.CurrentCharacterTurnIndex == _askIndex)
            {
                CE_GameManager.Instance.EndGame();
                currentAIPhase = AIPhase.Idle;
            }
            Debug.Log($"{_askTo.CharacterRef.ColorName} {(_result == null ? "can't" : "can")} answer.");
            yield return(new WaitForSeconds(1));
        }

        nextRoomInvestigate = null;
        currentAIPhase      = AIPhase.Idle;
        yield return(new WaitForSeconds(5));
    }
Ejemplo n.º 13
0
    void ChooseNewFreeRun()
    {
        aiPhase = AIPhase.FreePath;
        NodeConnection destination = nodeManager.GetClosestNodeTo(transform.position);

        int count = Random.Range(1, 3);

        do
        {
            destination = destination.node.connections[Random.Range(0, destination.node.connections.Count)];
            if (destination.node.canBeDestination)
            {
                count--;
            }
        }while (!destination.node.canBeDestination && count != 0);

        destinationNode = null;
        navPath         = nodeManager.FindPath(nodeManager.GetClosestNodeTo(transform.position), destination);

        ChooseNextPathNode();
    }
Ejemplo n.º 14
0
        void Phase5(GameTime gametime)
        {
            //30 seconds follow and shoot other player with shield
            if (tempoEscudo <= 0 && escudoActivo == false)
            {
                escudoActivo = true;
                escudoActual = ESCUDO;
                tempoEscudo  = TEMPO_ARREFECIMENTO_ESCUDO;
            }


            if (tempoAI >= PHASE5_TIME)
            {
                currentAIPhase = AIPhase.Phase6;
                tempoAI        = 0;
            }
            else
            {
                tempoAI += gametime.ElapsedGameTime.Ticks;
            }
        }
Ejemplo n.º 15
0
 IEnumerator IAEndMove()
 {
     while (endMoveThinking)
     {
         currentAIPhase = AIPhase.RoomEnterThink;
         if (stepCount < diceCount && CurrentCell == nextDoorTarget.Cell)
         {
             endMoveThinking = false;
             EnterInRoom();
         }
         else
         {
             endMoveThinking = false;
         }
         yield return(null);
     }
     nextDoorTarget = null;
     IsMoving       = false;
     stepCount      = 0;
     diceCount      = 0;
     iaNavigation.Reset();
 }
Ejemplo n.º 16
0
 public void Reset()
 {
     vidaActual             = VIDA;
     escudoActual           = 0;
     posicaoX               = posNaveCentroX;
     naveDrawRectangulo.X   = posNaveCentroX;
     escudoDrawRectangulo.X = posEscudoCentroX;
     naveShape.Center       = centerNave;
     escudoShape.Center     = centerEscudo;
     escudoActivo           = false;
     visivel     = true;
     disparou    = false;
     tempoEscudo = 0;
     tempoTiros  = 0;
     disable     = false;
     if (scriptedAI)
     {
         tempoAI        = 0;
         currentAIPhase = AIPhase.Phase1;
         scriptedAI     = true;
         switchSide     = false;
     }
 }
Ejemplo n.º 17
0
        void Phase4(GameTime gametime)
        {
            //30 seconds left and right shooting with shield
            if (tempoEscudo <= 0 && escudoActivo == false)
            {
                escudoActivo = true;
                escudoActual = ESCUDO;
                tempoEscudo  = TEMPO_ARREFECIMENTO_ESCUDO;
            }

            if (!switchSide)
            {
                if (tempoAI < PHASE4_TIME && vidaActual > 0 && posicaoX + naveDrawRectangulo.Width + RAPIDEZ <= GameConstants.WINDOW_WIDTH)
                {
                    posicaoX               += RAPIDEZ;
                    naveDrawRectangulo.X   += RAPIDEZ;
                    escudoDrawRectangulo.X += RAPIDEZ;
                    naveShape.Center.X     += RAPIDEZ;
                    escudoShape.Center.X   += RAPIDEZ;
                    if (disparou == false)
                    {
                        disparou = true;
                        if (Jogador.Jogador2 == jogador)
                        {
                            GameMLS.AdicionarBala(new Bala(texturaBala, jogador, posicaoX + naveDrawRectangulo.Width / 2 - texturaBala.Width / 2,
                                                           posicaoY, true));
                        }
                        else
                        {
                            GameMLS.AdicionarBala(new Bala(texturaBala, jogador, posicaoX + naveDrawRectangulo.Width / 2 - texturaBala.Width / 2,
                                                           posicaoY + naveDrawRectangulo.Height - texturaBala.Height, false));
                        }
                    }
                }
                else
                {
                    switchSide = true;
                }
            }

            else
            {
                if (tempoAI < PHASE4_TIME && vidaActual > 0 && posicaoX - RAPIDEZ >= 0)
                {
                    posicaoX               -= RAPIDEZ;
                    naveDrawRectangulo.X   -= RAPIDEZ;
                    escudoDrawRectangulo.X -= RAPIDEZ;
                    naveShape.Center.X     -= RAPIDEZ;
                    escudoShape.Center.X   -= RAPIDEZ;
                    if (disparou == false)
                    {
                        disparou = true;
                        if (Jogador.Jogador2 == jogador)
                        {
                            GameMLS.AdicionarBala(new Bala(texturaBala, jogador, posicaoX + naveDrawRectangulo.Width / 2 - texturaBala.Width / 2,
                                                           posicaoY, true));
                        }
                        else
                        {
                            GameMLS.AdicionarBala(new Bala(texturaBala, jogador, posicaoX + naveDrawRectangulo.Width / 2 - texturaBala.Width / 2,
                                                           posicaoY + naveDrawRectangulo.Height - texturaBala.Height, false));
                        }
                    }
                }
                else
                {
                    switchSide = false;
                }
            }

            if (tempoAI >= PHASE4_TIME)
            {
                currentAIPhase = AIPhase.Phase5;
                tempoAI        = 0;
            }
            else
            {
                tempoAI += gametime.ElapsedGameTime.Ticks;
            }
        }
Ejemplo n.º 18
0
    void changePhase()
    {
        if (phase == AIPhase.tactical)
        {
            Ray        r = new Ray(transform.position, player.transform.position - transform.position);
            RaycastHit rh;
            if (Physics.Raycast(r, out rh))
            {
                if (rh.collider.name == "Dude3D")
                {
                    phase = AIPhase.attack;
                }
            }
            else
            {
                phase = AIPhase.idle;
            }
        }
        else
        {
            Ray        r = new Ray(transform.position, player.transform.position - transform.position);
            RaycastHit rh;
            if (Physics.Raycast(r, out rh))
            {
                if (rh.collider.name == "Dude3D")
                {
                    phase = AIPhase.tactical;
                }
            }
            else
            {
                phase = AIPhase.idle;
            }
        }
        Vector2 fromPlayer;

        switch (phase)
        {
        case AIPhase.idle:
            direction   = getFurthest();
            nextPhaseIn = 2.0f + Random.value * 3.0f;
            _sr.sprite  = idle;
            break;

        case AIPhase.tactical:
            fromPlayer  = transform.position.xy() - player.transform.position.xy();
            fromPlayer  = fromPlayer.normalized * (0.5f + Random.value * 1.5f);
            direction   = player.transform.position.xy() + fromPlayer;
            nextPhaseIn = 1 + Random.value * 2;
            _sr.sprite  = tactical;
            break;

        case AIPhase.attack:
            fromPlayer  = transform.position.xy() - player.transform.position.xy();
            fromPlayer  = fromPlayer.normalized * (0.5f + Random.value * 1.5f);
            direction   = player.transform.position.xy() + fromPlayer;
            bulletCool  = bulletCooldown;
            bullets     = 3;
            _sr.sprite  = aim;
            nextPhaseIn = 1;
            break;
        }
    }
Ejemplo n.º 19
0
    /// <summary>
    /// Called every simulation tick.
    /// </summary>
    public void Update()
    {
        if (!mActive)
        {
            return;
        }

        // TODO: Maybe stagger updates over multiple ticks.
        // TODO: Maybe worker threads to help with decision making perf.

        // AI Follows a schedule of actions to be taken.
        // State driven? Checks for various conditions then jumps to a certain state.
        // State stack? Allows to return to what it was doing.

        // Fitting objects in the level:
        // A hint system where the level designer places hints for object placement
        // Procedural placement fitting
        //		Don't block of corridors
        //		Favour placing against walls
        //		Have gaps around objects placed in the middle of rooms

        ++_counter;

        if (_counter == 1)
        {
            //CItemStart spawn = _world.GetEntity<CItemStart>(_world.mPlayers[1].mSpawnItemID);
            //spawn.QueueEvent(new CElevatorEvent(CElevatorEvent.EType.T_SPAWN_UNIT, 1, 0));
            _phase = AIPhase.DECIDE;

            //_GetFirstAvailableResume();

            //_world.ControllerPlaceBlueprint("item_desk_test", 19, 15, 2, _playerIndex);

            //_world.ControllerPlaceBlueprint("item_food_test", 17, 12, 1, _playerIndex);

            //_world.ControllerPlaceBlueprint("item_safe_test", 20, 10, 0, _playerIndex);
            //_world.ControllerPlaceBlueprint("item_safe_test", 21, 10, 0, _playerIndex);
            //_world.ControllerPlaceBlueprint("item_safe_test", 22, 10, 0, _playerIndex);
            //mWorld.ControllerPlaceBlueprint("item_safe_test", 23, 10, 0, mPlayerId);

            //_world.ControllerPlaceBlueprint("item_test_0", 20, 7, 1, _playerIndex);

            //_world.ControllerPlaceBlueprint("item_door", 16, 6, 1, _playerIndex);
            //mWorld.ControllerPlaceBlueprint("item_door", 26, 12, 1, mPlayerId);
        }
        else
        {
            /*
             * // Check if we have an unassigned desk, and then assign someone to it
             * // TODO: Ideally we only want to assign to desks we know are within reach/safe.
             * CItemProxy deskProxy = _GetUnassignedDesk();
             * if (deskProxy != null)
             * {
             *      CUnit unit = _GetUnassignedWorker();
             *      if (unit != null)
             *      {
             *              Debug.Log("Assigning worker " + unit.mID + " to desk " + deskProxy.mID);
             *              _world.ControllerSelectEntity(_playerIndex, unit.mID);
             *              _world.ControllerClaimDesk(_playerIndex, deskProxy.mID);
             *      }
             * }
             *
             * _DistributeContractToAssignedDesks();
             *
             * if (_counter % 60 == 0)
             * {
             *      _GetFirstAvailableResume();
             *      if (_GetContractCount() < 4)
             *              _GetFirstAvailableContract();
             *
             *      if (_GetTotalInterns(true) < 5)
             *              _world.ControllerHireIntern(_playerIndex);
             * }
             */

            if (_counter % 60 == 0)
            {
                if (_GetTotalInterns(true) < 5)
                {
                    mWorld.ControllerHireIntern(mPlayerId);
                }
            }
        }

        /*
         * if (_phase == AIPhase.START)
         * {
         *      Debug.LogWarning("The AI is here");
         *
         *
         * }
         * else if (_phase == AIPhase.DECIDE)
         * {
         * }
         */
    }
Ejemplo n.º 20
0
 public void AIGotoPhase(AIPhase phase)
 {
     npc.ai[1] = (int)phase;
 }
Ejemplo n.º 21
0
 void EnterInRoom()
 {
     isInRoom           = true;
     transform.position = NextRoomInvestigate.Position;
     currentAIPhase     = AIPhase.Suggest;
 }
Ejemplo n.º 22
0
        public Nave(ContentManager content, SoundEffect[] sound, int posicaoFixaY, Jogador j)
        {
            //carrega as texturas e sons
            LoadContent(content, sound);

            //inicializa os valores da nave
            vidaActual       = VIDA;
            escudoActual     = 0;
            posNaveCentroX   = SCREEN_WIDTH_CENTER - texturaNave.Width / 2;
            posEscudoCentroX = SCREEN_WIDTH_CENTER - TexturaEscudo.Width / 2;
            posicaoX         = posNaveCentroX;
            posicaoY         = posicaoFixaY;
            escudoActivo     = false;
            visivel          = true;
            jogador          = j;
            disparou         = false;
            disable          = false;
            tempoEscudo      = 0;
            tempoTiros       = 0;
            if (j == Jogador.AIScripted)
            {
                tempoAI        = 0;
                currentAIPhase = AIPhase.Phase1;
                scriptedAI     = true;
                switchSide     = false;
            }
            else
            {
                tempoAI        = -1;
                currentAIPhase = AIPhase.NoPhase;
                scriptedAI     = false;
            }


            //determina as teclas da nave conforme o jogador
            if (Jogador.Jogador1 == jogador)
            {
                teclaEsquerda      = Keys.K;
                teclaDireita       = Keys.L;
                teclaDisparar      = Keys.N;
                teclaActivarEscudo = Keys.M;
            }

            else if (Jogador.Jogador2 == jogador)
            {
                teclaEsquerda      = Keys.Left;
                teclaDireita       = Keys.Right;
                teclaDisparar      = Keys.Space;
                teclaActivarEscudo = Keys.C;
            }

            //cria um novo rectangulo de desenho para a nave e o escudo
            naveDrawRectangulo   = new Rectangle(posNaveCentroX, posicaoY, texturaNave.Width, texturaNave.Height);
            escudoDrawRectangulo = new Rectangle(posEscudoCentroX, posicaoY - (texturaEscudo.Height - texturaNave.Height) / 2,
                                                 texturaEscudo.Width, texturaEscudo.Height);

            centerNave   = new Point2(posNaveCentroX + TexturaNave.Width / 2, posicaoY + TexturaNave.Height / 2);
            centerEscudo = new Point2(posEscudoCentroX + TexturaEscudo.Width / 2, posicaoY + TexturaEscudo.Height / 2);

            //cria novas figuras geometricas para detectar colisoes
            naveShape   = new CircleF(centerNave, texturaNave.Width / 2);
            escudoShape = new CircleF(centerEscudo, texturaEscudo.Width / 2);
        }