Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        //Get a refrence to the network object script
        np = GetComponent <NetworkedPlayer>();

        //Find the health system component and hook up to it's events so we can make some UI appear
        hpSystem = GetComponent <HealthSystem>();
        hpSystem.OnPlayerTakeDamage += UIOnPlayerTakeDamage;
        hpSystem.OnPlayerDie        += UIOnPlayerDie;
        hpSystem.OnPlayerRespawn    += UIOnPlayerRespawn;

        //Find the weapon controller as well and hook up events
        wp = GetComponent <WeaponController>();
        wp.OnReloadEvent += UIOnReload;

        //Hide the reload circle on start
        reloadCircle.fillAmount = 0;
        //and disable it
        reloadCircle.gameObject.SetActive(false);

        //disable the death text and the respawn counter, as it's not used yet
        deathText.gameObject.SetActive(false);
        respawnCounterText.gameObject.SetActive(false);

        //Hide pause UI
        pauseUIScreen.SetActive(false);

        //hide the cursor by default
        Cursor.visible = false;
    }
    void DebugParry()
    {
        NetworkedPlayer attackingPlayer = null;

        foreach (var player in FindObjectsOfType <NetworkedPlayer>())
        {
            if (player.networkObject.NetworkId == networkObject.NetworkId)
            {
                continue;
            }

            attackingPlayer = player;
            break;
        }

        if (attackingPlayer != null)
        {
            if (Input.GetMouseButtonDown(1))
            {
                playerCharacter.TryAttack();
                attackingPlayer.networkObject.SendRpc(NetworkedPlayer.RPC_DEBUG_ATTACK, Receivers.Owner);
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(1))
            {
                Debug.Log("No matching player found");
            }
        }
    }
Beispiel #3
0
    public int JoinSmallestTeam(NetworkedPlayer player)
    {
        int index = SmallestTeamIndex();

        teams[index]?.Join(player);
        return(index);
    }
Beispiel #4
0
    void Update()
    {
        if (GetComponent <ObservableView>())
        {
            ObservableView  observableView = GetComponent <ObservableView>();
            NetworkedPlayer owner          = EdgeManager.GetPlayer(observableView.ownerId);
            Material        playerMat      = owner.GetComponent <MeshRenderer>().material;
            GetComponent <MeshRenderer>().material = playerMat;
            if (owner.isLocalPlayer)
            {
                float h = Input.GetAxis("Horizontal") * 100 * Time.deltaTime;
                float v = Input.GetAxis("Vertical") * Time.deltaTime;
                transform.Translate(0, 0, v);
                transform.Rotate(0, h, 0);

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    Observable      observable = owner.observer.observables[observableView.observableIndex];
                    NetworkedPlayer otherPlayer;

                    //Switch ownership to the other player in the room
                    if (owner.playerIndex == 0)
                    {
                        otherPlayer = EdgeManager.GetPlayer(1);
                    }
                    else
                    {
                        otherPlayer = EdgeManager.GetPlayer(0);
                    }
                    observable.ChangeOwnership(otherPlayer.playerId);
                }
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// Called before start, setup the events from the networkplayer here, as NetworkStart is called before regular Start.
    /// Hook up all the RPC event the shoot system needs
    /// </summary>
    void Awake()
    {
        np = GetComponent <NetworkedPlayer>();
        np.NetworkStartEvent += NetworkStart;
        np.ShootEvent        += RPCShoot;
        np.SwitchWeaponEvent += RPCSwitchWeapon;

        setupPlayer = GetComponent <SetupPlayer>();
    }
Beispiel #6
0
    /// <summary>
    /// Called before start, setup the events from the networkplayer here, as NetworkStart is called before regular Start.
    /// Hook up all the RPC events the health system needs
    /// </summary>
    void Awake()
    {
        np = GetComponent <NetworkedPlayer>();
        np.NetworkStartEvent += NetworkStart;
        np.DieEvent          += RPCDie;
        np.TakeDamageEvent   += RPCTakeDamage;

        setupPlayer = GetComponent <SetupPlayer>();
    }
    // Update is called once per frame
    void Update()
    {
        if (player == null & Utilities.IsLevelLoaded() && !Utilities.IsGameOver())
        {
            player = PlayerManager.GetControllablePlayer();
            if (player != null)
            {
                networkedPlayer = player.GetComponent <NetworkedPlayer>();
                playerScore     = player.GetComponent <PlayerScore>();
            }

            fleetShips       = PlayerManager.GetOwnedFleetAI();
            fleetShipToSpawn = GetFleetShipToSpawn();
        }

        if (networkedPlayer != null)
        {
            if (networkedPlayer.IslandWithinRange != null)
            {
                nearbyIsland              = networkedPlayer.IslandWithinRange.GetComponent <IslandDiscoveryTrigger>();
                fleetButton.interactable  = true;
                patrolButton.interactable = true;
                //TODO: Enable cannonButton once cannon upgrades have been implemented.
                //cannonButton.interactable = true;
            }
            else
            {
                nearbyIsland              = null;
                fleetButton.interactable  = false;
                patrolButton.interactable = false;
                cannonButton.interactable = false;
            }
        }


        if (fleetButton.IsInteractable() && Input.GetAxis("BuyFleetShip") == 1 && fleetButtonTimer >= buttonPressCooldown)
        {
            FleetButtonPress();
            fleetButtonTimer = 0.0f;
        }

        if (patrolButton.IsInteractable() && Input.GetAxis("BuyPatrolShip") == 1 && patrolButtonTimer >= buttonPressCooldown)
        {
            PatrolButtonPress();
            patrolButtonTimer = 0.0f;
        }

        //TODO: Add cannon upgrade button.
        if (fleetButtonTimer < buttonPressCooldown)
        {
            fleetButtonTimer += Time.deltaTime;
        }
        if (patrolButtonTimer < buttonPressCooldown)
        {
            patrolButtonTimer += Time.deltaTime;
        }
    }
Beispiel #8
0
    private void Awake()
    {
        np = GetComponent <NetworkedPlayer> ();
        np.NetworkStartEvent += NetworkStart;
        np.DoCommandEvent    += DoCommand;
        np.NewCommandsEvent  += NewCommands;
        np.NewWordListEvent  += NewWordList;

        _goalCommand.TimerDoneEvent += GoalTimerDone;
    }
Beispiel #9
0
    public static void DestroyNetworkedPlayer(BoltConnection a_connection)
    {
        NetworkedPlayer player = GetNetworkedPlayer(a_connection);

        if (player != null)
        {
            player.DestroyPlayer();
        }

        s_networkedPlayerList.Remove(player);
    }
Beispiel #10
0
 public override void HandleNetworkMessage(Message msg)
 {
     base.HandleNetworkMessage(msg);
     if (msg is GameStartMessage)
     {
         GameStartMessage nMsg  = msg as GameStartMessage;
         ConnectionStatus cStat = new ConnectionStatus();
         m_Server.GetQuickConnectionStatus(m_Connection, cStat);
         uniformTimeOffset = ((nMsg.uniformTime.Ticks / TimeSpan.TicksPerSecond) + (((float)cStat.ping) * 0.01f)) - (DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond);
         GameManager.Instance.StartGameInSeconds(nMsg.timeAfterToSpawn + uniformTimeOffset);
     }
     if (msg is PlayerConnectedMessage)
     {
         PlayerConnectedMessage nMsg = msg as PlayerConnectedMessage;
         NetworkedPlayer        p    = GameManager.Instance.AddPlayer(nMsg.playerID);
         p.playerID = nMsg.playerID;
     }
     else if (msg is PlayerDisconnectedMessage)
     {
         PlayerDisconnectedMessage nMsg = msg as PlayerDisconnectedMessage;
         GameManager.Instance.RemovePlayer(nMsg.playerID);
     }
     else if (msg is PlayerUpdateMessage)
     {
         PlayerUpdateMessage nMsg = msg as PlayerUpdateMessage;
         GameManager.Instance.UpdatePlayerInformation(ref nMsg.info, nMsg.playerID);
     }
     else if (msg is ObstacleGeneratedMessage)
     {
         ObstacleGeneratedMessage nMsg = msg as ObstacleGeneratedMessage;
         TileManager.Instance.SpawnObstacle(nMsg.itemID, nMsg.itemPos, nMsg.itemType);
     }
     else if (msg is ObstacleModifiedMessage)
     {
         ObstacleModifiedMessage nMsg = msg as ObstacleModifiedMessage;
         (GameManager.Instance.m_AllObstacles[(int)nMsg.obstacleID] as IObstacle).InteractedWith(GameManager.Instance.GetPlayer(nMsg.playerID));
     }
     else if (msg is PlayerFellBehindMessage)
     {
         PlayerFellBehindMessage nMsg = msg as PlayerFellBehindMessage;
         GameManager.Instance.PlayerFellBehind(nMsg.playerID);
     }
     else if (msg is PlayerWonMessage)
     {
         PlayerWonMessage nMsg = msg as PlayerWonMessage;
         GameManager.Instance.PlayerHasWonGame(GameManager.Instance.GetPlayer(nMsg.playerID));
     }
     else if (msg is PlayerAttackedPlayerMessage)
     {
         PlayerAttackedPlayerMessage nMsg = msg as PlayerAttackedPlayerMessage;
         GameManager.Instance.PlayerAttacked(nMsg.attackedPlayerID);
     }
 }
Beispiel #11
0
    public int GetIndex(NetworkedPlayer player)
    {
        for (int i = 0; i < teams.Count; i++)
        {
            if (teams[i].players.Contains(player))
            {
                return(i);
            }
        }

        return(0);
    }
Beispiel #12
0
    /// <summary>
    /// Add a ship from the lobby hook
    /// </summary>
    /// <param name="ship">The actual GameObject instantiated by the lobby, which is a NetworkBehaviour</param>
    /// <param name="playerNum">The number of the player (based on their slot position in the lobby)</param>
    /// <param name="c">The color of the player, choosen in the lobby</param>
    /// <param name="name">The name of the Player, choosen in the lobby</param>
    /// <param name="localID">The localID. e.g. if 2 player are on the same machine this will be 1 & 2</param>
    public static void AddShip(GameObject ship, int playerNum, Color c, string name, int localID)
    {
        NetworkedPlayer tmp = new NetworkedPlayer();
        tmp.m_Instance = ship;
        tmp.m_PlayerNumber = playerNum;
        tmp.m_PlayerColor = c;
        tmp.m_PlayerName = name;
        tmp.m_LocalPlayerID = localID;
        tmp.Setup();

        ServerSettings.players.Add(tmp);
        //m_Ships.Add(tmp);
    }
Beispiel #13
0
    /// <summary>
    /// Called before start, setup the events from the networkplayer here, as NetworkStart is called before regular Start.
    /// Hook up all the RPC event the shoot system needs
    /// </summary>
    void Awake()
    {
        np = GetComponentInParent <NetworkedPlayer>();
        np.NetworkStartEvent += NetworkStart;
        hp = GetComponentInParent <HealthSystem>();
        wp = GetComponentInParent <WeaponController>();

        //The SmoothMouseLook doesn't work if an animation is overriding the camera's rotation, so disable the animator untill we need it
        cameraAnimator         = GetComponent <Animator>();
        cameraAnimator.enabled = false;

        mouseLook = GetComponent <SimpleSmoothMouseLook>();
    }
Beispiel #14
0
    private void DisableTowers(NetworkedPlayer player)
    {
        var towers = FindObjectsOfType <Tower> ();

        foreach (var tower in towers)
        {
            var renderer = tower.GetComponent <SpriteRenderer> ();
            if (renderer.color == player.playerColor)
            {
                tower.MakeDead();
            }
        }
    }
    private void OnPlayerDestroy(NetworkedPlayer player) {
        player.GameObjectDestroyed -= OnPlayerDestroy;

        if (playerObject.TryGetComponent<NetworkedShoot>(out NetworkedShoot shoot)) {
            if (shoot.ammo > 0) {
                GameObject bulletDrop = Instantiate(bulletDropPrefab, playerObject.transform.position, Quaternion.identity);
                bulletDrop.GetComponent<NetworkedBulletPickup>().amount = shoot.ammo;
                NetworkServer.Spawn(bulletDrop);
            }
        }
        playerObject = null;
        RpcPlayDeathSound();
    }
Beispiel #16
0
 public void EndLevel(PlayerEnum identity)
 {
     foreach (NetworkedPlayer player in FindObjectsOfType <NetworkedPlayer>())
     {
         if (player.identity == identity)
         {
             winner = player;
         }
         else
         {
             loser = player;
         }
     }
     EndLevel();
 }
Beispiel #17
0
    public void Add(NetworkView networkView, bool enabled, NetworkedPlayer netPlayerScript)
    {
        for (int i = 0; i < 1; i++)
        {
            if (true)
            {
                networkView.stateSynchronization = NetworkStateSynchronization.Unreliable;
                networkView.observed             = netPlayerScript;

                //all
                networkView.enabled = enabled;
            }
            //current smart Add finish
        }
    }
Beispiel #18
0
 /// <summary>
 /// Called when a collider triggers this objects collider
 /// </summary>
 /// <param name="col"></param>
 void OnTriggerEnter(Collider col)
 {
     //Only do pickups on the server, as an RPC is called to all receivers if the player's server version enters it
     if (NetworkManager.Instance.IsMaster)
     {
         NetworkedPlayer np = col.GetComponent <NetworkedPlayer>();
         if (np)
         {
             //call the pickup RPC, and send along the respawn time as the clients are unaware of that variable
             networkObject.SendRpc(WeaponPickupBehavior.RPC_ON_PICKUP, Receivers.AllBuffered, weaponRespawnTime);
             //+1 to the weapon index, as the 0 index is the hands on the player.
             np.networkObject.SendRpc(PlayerBehavior.RPC_SWITCH_WEAPON, BeardedManStudios.Forge.Networking.Receivers.AllBuffered, weaponIndex + 1);
         }
     }
 }
Beispiel #19
0
    public void setPlayer(NetworkedPlayer player, NetworkConnection netConn, bool isLocalPlayer)
    {
        initialize();

        NetworkIdentity networkIdentity = GetComponent <NetworkIdentity>();

        networkIdentity.AssignClientAuthority(netConn);

        owner = player;
        ownerNetworkConnection = netConn;

        characterController.enabled = true;

        RpcSetPlayer(isLocalPlayer);
    }
 void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         if (m_owner != null)
         {
             int             ownerPlayerID = Utilities.GetPlayerID(m_owner);
             NetworkedPlayer nearbyPlayer  = other.gameObject.GetComponent <NetworkedPlayer>();
             if (ownerPlayerID == nearbyPlayer.PlayerID)
             {
                 m_ownerWithinRange             = false;
                 nearbyPlayer.IslandWithinRange = null;
                 Debug.Log("Owner exited island range.");
             }
         }
     }
 }
 void OnTriggerStay(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         if (m_owner != null)
         {
             //Makes sure that after island has been captured m_ownerWithinRange is set to true.
             if (!m_ownerWithinRange)
             {
                 int             ownerPlayerID = Utilities.GetPlayerID(m_owner);
                 NetworkedPlayer nearbyPlayer  = other.gameObject.GetComponent <NetworkedPlayer>();
                 if (ownerPlayerID == nearbyPlayer.PlayerID)
                 {
                     m_ownerWithinRange             = true;
                     nearbyPlayer.IslandWithinRange = this.gameObject;
                 }
             }
         }
     }
 }
Beispiel #22
0
    private void OnCollisionEnter(Collision collision)
    {
        NetworkedPlayer p = collision.gameObject.GetComponentInParent <NetworkedPlayer>();

        if (p != null)
        {
            if (p.teamIndex != owner.teamIndex)
            {
                CollidedWithEnemy(p);
            }

            else
            {
                CollidedWithAlly(p);
            }
        }

        else
        {
            CollidedWithGeometry(collision.collider);
        }
    }
Beispiel #23
0
    // create a player for a connection
    // note: connection can be null
    static NetworkedPlayer CreatePlayer(BoltConnection connection)
    {
        NetworkedPlayer player;

        // create a new player object, assign the connection property
        // of the object to the connection was passed in
        player            = new NetworkedPlayer();
        player.connection = connection;

        // if we have a connection, assign this player
        // as the user data for the connection so that we
        // always have an easy way to get the player object
        // for a connection
        if (player.connection != null)
        {
            player.connection.UserData = player;
        }

        // add to list of all players
        s_networkedPlayerList.Add(player);

        return(player);
    }
Beispiel #24
0
    private void OnTriggerEnter(Collider other)
    {
        if (!NetworkManager.Instance.IsServer)
        {
            return;
        }

        NetworkedPlayer player = other.transform.root.GetComponent <NetworkedPlayer>();

        if (player != null)
        {
            if (!player.isAlive)
            {
                return;
            }
            Debug.Log(player.playerName + " died in zone " + gameObject.name);


            player.networkObject.alive = false;

            player.networkObject.SendRpc(NetworkedPlayerBehavior.RPC_DIE, Receivers.All, "VOID", 0);

            // return flag

            if (player.flag == null)
            {
                return;
            }

            player.flag.GetComponentInParent <Zone>().networkObject.SendRpc(Zone.RPC_RETRIEVED, Receivers.All, "VOID", player.playerName);

            player.flag = null;
            player.networkObject.hasFlag = false;

            player.networkObject.SendRpc(NetworkedPlayer.RPC_TOGGLE_FLAG, true, Receivers.AllBuffered, false);
        }
    }
 public void SetCreator(NetworkedPlayer player)
 {
     creator = player;
 }
Beispiel #26
0
 public void Init(NetworkedPlayer np, int commandIndex, string commandText)
 {
     _np               = np;
     _commandIndex     = commandIndex;
     _commandText.text = commandText;
 }
Beispiel #27
0
 public void AssignPlayer(NetworkedPlayer p)
 {
     player = p;
 }
Beispiel #28
0
 /// <summary>
 /// Called on initialization
 /// </summary>
 void Start()
 {
     //set the reference
     np = GetComponent <NetworkedPlayer>();
 }
    // Update is called once per frame
    void Update()
    {
        if (player == null & Utilities.IsLevelLoaded() && !Utilities.IsGameOver())
        {
            player = PlayerManager.GetControllablePlayer();
            if(player != null)
            {
                networkedPlayer = player.GetComponent<NetworkedPlayer>();
                playerScore = player.GetComponent<PlayerScore>();
            }

            fleetShips = PlayerManager.GetOwnedFleetAI();
            fleetShipToSpawn = GetFleetShipToSpawn();
        }

        if (networkedPlayer != null)
        {
            if (networkedPlayer.IslandWithinRange != null)
            {
                nearbyIsland = networkedPlayer.IslandWithinRange.GetComponent<IslandDiscoveryTrigger>();
                fleetButton.interactable = true;
                patrolButton.interactable = true;
                //TODO: Enable cannonButton once cannon upgrades have been implemented.
                //cannonButton.interactable = true;
            }
            else
            {
                nearbyIsland = null;
                fleetButton.interactable = false;
                patrolButton.interactable = false;
                cannonButton.interactable = false;
            }
        }

        if (fleetButton.IsInteractable() && Input.GetAxis("BuyFleetShip") == 1 && fleetButtonTimer >=buttonPressCooldown)
        {
            FleetButtonPress();
            fleetButtonTimer = 0.0f;
        }

        if (patrolButton.IsInteractable() && Input.GetAxis("BuyPatrolShip") == 1 && patrolButtonTimer >= buttonPressCooldown)
        {
            PatrolButtonPress();
            patrolButtonTimer = 0.0f;
        }

        //TODO: Add cannon upgrade button.
        if (fleetButtonTimer < buttonPressCooldown)
        {
            fleetButtonTimer += Time.deltaTime;
        }
        if (patrolButtonTimer < buttonPressCooldown)
        {
            patrolButtonTimer += Time.deltaTime;
        }
    }
Beispiel #30
0
 public void JoinTeam(int i, NetworkedPlayer player)
 {
     teams[i].Join(player);
 }
    public override void OnInspectorGUI()
    {
        NetworkedPlayer myTarget = (NetworkedPlayer)target;

        EditorGUILayout.LabelField("NUMPLAYERS:", NetworkedPlayer.numInstPlayers.ToString());
    }
Beispiel #32
0
 void OnEnable()
 {
     targetObject = (NetworkedPlayer)target;
     netTransform = targetObject.GetComponent <NetworkTransform> ();
 }