Ejemplo n.º 1
0
    /// <summary>
    /// Returns an unpurchased FleetShip owned by the client that is ready to be spawned.
    /// </summary>
    /// <returns>
    /// A FleetShip ready to be spawned or null if there aren't any.
    /// </returns>
    private FleetShip GetFleetShipToSpawn()
    {
        FleetShip temp = null;

        if (fleetShips != null)
        {
            for (int i = 0; i < fleetShips.Length; ++i)
            {
                NetworkedAI ai    = fleetShips[i].GetComponentInChildren <NetworkedAI>();
                FleetAI     fleet = fleetShips[i].GetComponentInChildren <FleetAI>();

                if (ai != null && fleet != null)
                {
                    if (!fleet.Purchased)
                    {
                        temp = new FleetShip(ai, fleet);
                        break;
                    }
                }
            }
        }
        return(temp);
    }
Ejemplo n.º 2
0
 public FleetShip(NetworkedAI netAI, FleetAI ai)
 {
     networkedAI = netAI;
     aiShip = ai;
 }
Ejemplo n.º 3
0
 public FleetShip()
 {
     networkedAI = null;
     aiShip = null;
 }
Ejemplo n.º 4
0
 public FleetShip(NetworkedAI netAI, FleetAI ai)
 {
     networkedAI = netAI;
     aiShip      = ai;
 }
Ejemplo n.º 5
0
    /// <summary>
    /// Updates the game over ai logic
    /// </summary>
    void UpdateAI()
    {
        // Must do this here as health component gets turned off when it dies
        var        ai          = PlayerManager.GetAllAI();
        GameObject aiToDestroy = null;

        for (int i = 0; i < ai.Count; ++i)
        {
            if (Utilities.IsControllableAI(ai[i]))
            {
                // This includes all AI contolled by the client (including Rogues)
                var  health             = ai[i].GetComponent <AIHealth>();
                var  network            = ai[i].GetComponent <NetworkedAI>();
                bool assignedPlayerDead = network.GetAssignedPlayer() != null &&
                                          !network.IsAssignedPlayerIsAlive();

                if (health.IsAlive && assignedPlayerDead)
                {
                    health.AssignedPlayerDead = true;

                    //This caused player owned Ai to be destroyed when the player died.
                    //This is now disabled as this was not desired functionality.
                    //network.SetVisible(false, true);
                }

                if (!health.IsAlive)
                {
                    if (health.AssignedPlayerDead)
                    {
                        // Wait until assigned player is no longer dead to respawn
                        if (!assignedPlayerDead)
                        {
                            health.AssignedPlayerDead = false;

                            if (network.aiType == NetworkedAI.AIType.FLEET)
                            {
                                if (network.GetComponent <FleetAI>().Purchased)
                                {
                                    network.SetVisible(true, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        //Handles ai respawning and showing on game start.
                        switch (network.aiType)
                        {
                        case NetworkedAI.AIType.ROGUE:
                            if (network.AlreadySpawned)
                            {
                                network.SetVisible(false, true);
                                StartCoroutine(RespawnAI(network, 5.0f));
                            }
                            else
                            {
                                network.SetVisible(false, true);
                                network.SetVisible(true, false);
                                network.AlreadySpawned = true;
                            }
                            break;

                        case NetworkedAI.AIType.FLEET:
                            //DONE: Handle fleet ship spawning and dying. Also make sure that fleet ships a not visible on game start
                            //      and only become visible once they have been purchased by the player. The shop manager will hold
                            //      a list of AI fleet ships. The FleetAI class will keep track of whether a fleet ship has been purchased.


                            FleetAI fleet = network.GetComponent <FleetAI>();
                            if (fleet.Purchased)
                            {
                                network.SetVisible(false, true);
                                fleet.UnassignFormationPosition();
                                fleet.Purchased = false;
                            }

                            //temp death and spawn code
                            break;

                        case NetworkedAI.AIType.PATROL:
                            /* TODO: Implement patrol ship death handling.
                             * Patrol ships will be owned by the scene and
                             * there will be one per island.
                             * Once a player has captured an island and bought a
                             * patrol ship for that island. The designated
                             * patrol ship will be made visible and
                             * the ship's owning player will be set.
                             * There will also be a purchased variable
                             * that will be used to determine whether the
                             * player has purchased the patrol ship for an island.
                             */
                            network.SetVisible(false, true);
                            aiToDestroy = ai[i];
                            break;

                        default:
                            break;
                        }
                        // No assigned player, immediate respawn
                    }
                }
            }
        }

        //Destory flagged AI
        if (aiToDestroy != null)
        {
            PlayerManager.RemoveAI(aiToDestroy);
            PhotonNetwork.Destroy(aiToDestroy.transform.parent.gameObject);
        }
    }