Exemple #1
0
    void OnCollisionEnter(Collision collision)
    {
        if (!isServer)
        {
            return;
        }
        // This is the spell gameobject on the server
        GameObject go = NetworkServer.FindLocalObject(gameObject.GetComponent <NetworkIdentity>().netId);

        RpcSpawnEffect(go.transform.position, effectName);
        if (collision.gameObject.tag.Equals("player"))
        {
            NetworkIdentity id             = collision.gameObject.GetComponent <NetworkIdentity>();
            MainController  mainController = collision.gameObject.GetComponent <MainController>();
            Rigidbody       hitRB          = collision.gameObject.GetComponent <Rigidbody>();
            Vector3         totalVelocity  = (velocity * knockbackFactor) + mainController.walkVelocity;
            hitRB.velocity = totalVelocity;
            RpcDoPhysics(id);
            mainController.Health -= damage;
            if (mainController.Health <= 0)
            {
                collision.gameObject.SetActive(false);
                Destroy(collision.gameObject, 0.1f);
                go.SetActive(false);
                Destroy(go, 0.1f);
                return;
            }
        }
        go.SetActive(false);
        Destroy(go, 0.1f);
    }
Exemple #2
0
        /// <summary>
        /// Reads a reference to a NetworkIdentity from the stream.
        /// </summary>
        /// <returns>The NetworkIdentity object read.</returns>
        public NetworkIdentity ReadNetworkIdentity()
        {
            NetworkInstanceId netId = ReadNetworkId();

            if (netId.IsEmpty())
            {
                return(null);
            }
            GameObject go;

            if (NetworkServer.active)
            {
                go = NetworkServer.FindLocalObject(netId);
            }
            else
            {
                go = ClientScene.FindLocalObject(netId);
            }
            if (go == null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("ReadNetworkIdentity netId:" + netId + "go: null");
                }
                return(null);
            }

            return(go.GetComponent <NetworkIdentity>());
        }
    private void WaitingForNextState()
    {
        if (isServer && !matchOver)
        {
            waitTimer += Time.deltaTime;
            if (waitTimer > 5f)
            {
                waitTimer = 0f;
                sp        = new StatePointer(StartState);

                int currentPad         = rnd.Next(0, padList.Count - 1);
                DominationPadInfo info = padList[currentPad];
                transform.position = info.pos;
                maskImage.sprite   = info.icon.sprite;
                padList.RemoveAt(currentPad);
                //GetComponent<MeshRenderer>().enabled = true;
                //GetComponent<CapsuleCollider>().enabled = true;
                resetPlayersOnPad();
                players = NetworkServer.objects;
                foreach (KeyValuePair <NetworkInstanceId, NetworkIdentity> entry in players)
                {
                    if (entry.Value.isLocalPlayer)
                    {
                        NetworkServer.FindLocalObject(entry.Key).GetComponent <VoiceActing>().NextCapPoint();
                    }
                }
                RpcActivatePoint(info.listNumber);
            }
        }
    }
    public void Cmd_FinalizeGame(NetworkInstanceId netID)
    {
        Dictionary <NetworkInstanceId, NetworkIdentity> map = new Dictionary <NetworkInstanceId, NetworkIdentity>();

        foreach (KeyValuePair <NetworkInstanceId, NetworkIdentity> entry in NetworkServer.objects)
        {
            map.Add(entry.Key, entry.Value);
        }

        foreach (KeyValuePair <NetworkInstanceId, NetworkIdentity> entry in map)
        {
            if (entry.Key.Value != netID.Value)
            {
                GameObject theObject = NetworkServer.FindLocalObject(entry.Key);
                var        body      = theObject.GetComponent <Rigidbody2D>();
                if (body != null && theObject.GetComponent <PlayerController>() == null)
                {
                    body.gravityScale = 1;
                    body.isKinematic  = false;
                }
                else if (theObject.GetComponent <ScoreDisplaySupport>() == null)
                {
                    NetworkServer.Destroy(theObject);
                }
            }
        }
    }
Exemple #5
0
 private void TransferResources()
 {
     if (cargoHold.GetCargo().Count > 0)
     {
         cargoHold.Transfer(NetworkServer.FindLocalObject(owner.playerBase).GetComponent <Base>().cargoHold);
     }
 }
        static internal void OnAnimationTriggerServerMessage(NetworkMessage netMsg)
        {
            AnimationTriggerMessage msg = new AnimationTriggerMessage();

            netMsg.ReadMessage(msg);
            if (LogFilter.logDev)
            {
                Debug.Log("OnAnimationTriggerMessage for netId=" + msg.netId + " conn=" + netMsg.conn);
            }

            GameObject go = NetworkServer.FindLocalObject(msg.netId);

            if (go == null)
            {
                return;
            }
            NetworkAnimator animSync = go.GetComponent <NetworkAnimator>();

            if (animSync != null)
            {
                animSync.HandleAnimTriggerMsg(msg.hash);

                NetworkServer.SendToReady(go, (short)MsgType.AnimationTrigger, msg);
            }
        }
Exemple #7
0
    public void CmdRemove(NetworkInstanceId ID)
    {
        GameObject obj = NetworkServer.FindLocalObject(ID);

        Destroy(obj);
        NetworkServer.Destroy(obj);
    }
Exemple #8
0
    ////////////////////////////////////////////////////////////////////////////////////////////
    ////// BELOW > TIREI O COMMAND PRA DEIXAR OS TESTES MAIS FACEIS
    public void Build2(GameObject newTower)
    {
        if (activeBuildingTree != null)
        {
            Destroy(activeBuildingTree.gameObject);
        }

        this.TowerPrefab = newTower;

        NetworkInstanceId towerId        = gameObject.GetComponent <NetworkBehaviour>().netId;
        List <GameObject> prefabs        = GameObject.Find("NetworkManager").GetComponent <NetworkManagerCustom>().spawnPrefabs;
        GameObject        newTowerPrefab = null;

        foreach (GameObject t in prefabs)
        {
            if (newTower.name == t.name)
            {
                newTowerPrefab = t;
                break;
            }
        }

        GameObject baseTower = NetworkServer.FindLocalObject(towerId);
        GameObject nTo       = (GameObject)Instantiate(newTowerPrefab, baseTower.transform.position, baseTower.transform.rotation);

        NetworkServer.Spawn(nTo);
        NetworkServer.Destroy(baseTower);

        //////////////////////////////////////////////////////////////////////////////////////////
    }
    public void CmdDestroyObject(NetworkInstanceId netID, GameObject test)
    {
        GameObject obj = NetworkServer.FindLocalObject(netID);

        NetworkServer.Destroy(obj);
        RpcDestroy(test);
    }
Exemple #10
0
    public override void Interact(NetworkInstanceId id)
    {
        Debug.Log("Interacting with " + gameObject.name);
        if (m_RegisteredPlayer == NetworkInstanceId.Invalid)
        {
            bool reg = RegisterPlayer(id);
            //Register the ship's owner
            m_PlayerController.CmdSetAuth(netId);

            GameObject netGameMnger = GameObject.FindGameObjectWithTag("NetworkGameManager");
            _Ship = netGameMnger.GetComponent <NetworkGameManager>().m_Ship;
            m_PlayerController.CmdSetAuth(_Ship);
            Debug.Log(_Ship);
            if (isServer)
            {
                _PSN = NetworkServer.FindLocalObject(_Ship).GetComponent <Player_Ship_Navigation>();
            }
            else
            {
                _PSN = ClientScene.FindLocalObject(_Ship).GetComponent <Player_Ship_Navigation>();
            }

            Debug.Log("User registered to system: " + reg);
        }
        else
        {
            _PSN = null;
            UnregisterPlayer();
            Debug.Log("Player unregistered.");
        }
    }
Exemple #11
0
    /** OnPlayerSendChatMessage:
     * this is caught by the host and it modifies a incoming message then sends it back to all the other players
     */
    public void PlayerSendChatMessage(NetworkMessage netMsg)
    {
        string message = netMsg.ReadMessage <StringMessage>().value.Trim();

        if (message.Length > 100)
        {
            message = message.Substring(0, 100).Trim();
        }

        string senderName = myChat.GetNameById(netMsg.conn.connectionId);

        foreach (NetworkInstanceId n in netMsg.conn.clientOwnedObjects)
        {
            GameObject G = NetworkServer.FindLocalObject(n);
            if (G.GetComponent <PlayerMatUpdate>() != null)
            {
                senderName += " (" + G.GetComponent <PlayerMatUpdate>().GetColorName() + ") ";
            }
        }

        ChatMessage chatMessage = new ChatMessage()
        {
            sender = senderName, message = message
        };

        NetworkServer.SendToAll(ChatMessageReceived, chatMessage);
    }
Exemple #12
0
        private void OnPlayerUpdateRequest(NetworkMessage netMsg)
        {
            NetworkMessagePlayerUpdate msg = netMsg.ReadMessage <NetworkMessagePlayerUpdate>();

            if (isServer && msg.isServerResponse == false)
            {
                msg.isServerResponse = true;

                NetworkInstanceId netID = new NetworkInstanceId(msg.PlayerNetID);
                GameObject        go    = NetworkServer.FindLocalObject(netID);
                if (go != null)
                {
                    PlayerInfo pinfo = go.GetComponent <PlayerInfo>();
                    msg.deaths = pinfo.ThePlayerData.playerDeaths;
                    msg.kills  = pinfo.ThePlayerData.playerKills;
                    NetworkServer.SendToAll(4001, msg);
                }
            }
            else if (Client.isConnected)
            {
                NetworkInstanceId netID = new NetworkInstanceId(msg.PlayerNetID);
                GameObject        go    = ClientScene.FindLocalObject(netID);
                if (go != null)
                {
                    PlayerInfo pinfo = go.GetComponent <PlayerInfo>();
                    pinfo.ThePlayerData.playerKills  = msg.kills;
                    pinfo.ThePlayerData.playerDeaths = msg.deaths;
                }
            }
        }
Exemple #13
0
    void CmdDestroyBrick(NetworkInstanceId brickID)
    {
        GameObject brick = NetworkServer.FindLocalObject(brickID);

        Debug.Log(brick.transform.name + " ok i will destroy (" + brickID + ")");
        NetworkServer.Destroy(brick);
    }
Exemple #14
0
    public void RpcDrainUnit(NetworkInstanceId unitId)
    {
        GameObject findUnit = null;
        Unit       unitToDrain;

        if (isServer)
        {
            findUnit = NetworkServer.FindLocalObject(unitId);
        }
        else if (isClient)
        {
            findUnit = ClientScene.FindLocalObject(unitId);
        }

        if (findUnit != null)
        {
            unitToDrain = findUnit.GetComponent <Unit> ();

            unitToDrain.Damage(5f);
            damageAmplifier = damageAmplifier - 0.1f;

            Bullet newBullet = ((GameObject)(Instantiate(drainBullet, unitToDrain.transform.position, drainBullet.transform.rotation))).GetComponent <Bullet>();
            newBullet.Setup(this, -5f, 5f);
        }
        else
        {
            Debug.Log("Error: Drain Unit Not Found");
        }
    }
        // ------------------ server message handlers -------------------

        static internal void OnAnimationServerMessage(NetworkMessage netMsg)
        {
            netMsg.ReadMessage(s_AnimationMessage);

            if (LogFilter.logDev)
            {
                Debug.Log("OnAnimationMessage for netId=" + s_AnimationMessage.netId + " conn=" + netMsg.conn);
            }

            GameObject go = NetworkServer.FindLocalObject(s_AnimationMessage.netId);

            if (go == null)
            {
                return;
            }
            NetworkAnimator animSync = go.GetComponent <NetworkAnimator>();

            if (animSync != null)
            {
                NetworkReader reader = new NetworkReader(s_AnimationMessage.parameters);
                animSync.HandleAnimMsg(s_AnimationMessage, reader);

                NetworkServer.SendToReady(go, MsgType.Animation, s_AnimationMessage);
            }
        }
Exemple #16
0
    public virtual void TakeDamage(int amount, NetworkInstanceId attacker)
    {
        print("this is being called now on " + gameObject.name);
        //print(amount + " " + attacker);
        currHealth -= amount;

        //print(currHealth);

        if (GetComponent <ParticleSystem>() != null)
        {
            GetComponent <ParticleSystem>().Play();
        }


        if (currHealth <= 0 && !isDead)
        {
            // the following code will only be run for player objects,
            // they're the only things that have money
            GameObject localAttacker = NetworkServer.FindLocalObject(attacker);
            if (localAttacker && localAttacker.GetComponent <PlayerController>())
            {
                localAttacker.GetComponent <PlayerController>().AddMoney(1);
            }

            // call rpc and on server death
            if (NetworkServer.active)
            {
                RpcDeath();
                OnServerDeath();
            }
        }
    }
Exemple #17
0
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!m_Disposed && m_Channels != null)
            {
                for (int i = 0; i < m_Channels.Length; i++)
                {
                    m_Channels[i].Dispose();
                }
            }
            m_Channels = null;

            if (m_ClientOwnedObjects != null)
            {
                foreach (var netId in m_ClientOwnedObjects)
                {
                    var obj = NetworkServer.FindLocalObject(netId);
                    if (obj != null)
                    {
                        obj.GetComponent <NetworkIdentity>().ClearClientOwner();
                    }
                }
            }
            m_ClientOwnedObjects = null;

            m_Disposed = true;
        }
    [Command] // Spawn a house through the server
    void CmdSpawnHouse(Vector3 pos, bool isHost, NetworkInstanceId humanID)
    {
        GameObject obj = Instantiate(house, pos, Quaternion.Euler(0, Random.Range(0, 359), 0));

        obj.layer = 28;
        obj.GetComponent <House>().humanBuilt = true;

        NetworkServer.Spawn(obj);

        // Assign the house to the host player
        if (isHost)
        {
            var human = NetworkServer.FindLocalObject(humanID);
            human.GetComponent <HumanAI>()._house = obj;
        }
        else
        {
            var houseID = obj.GetComponent <NetworkIdentity>().netId;
            RpcAssignHouse(humanID, houseID);
        }

        var teamID = GetComponent <RagdollSetup>().teamID;

        if (teamID == 0)
        {
            GameManager.Instance.teamOneHomes.Add(obj);
        }

        if (teamID == 1)
        {
            GameManager.Instance.teamTwoHomes.Add(obj);
        }
    }
Exemple #19
0
    private void CmdUpdateShield(float angle)
    {
        //Position and rotate shield according to player position and mouse click position
        shield = NetworkServer.FindLocalObject(shieldId).GetComponent <Shield>();

        shield.gameObject.SetActive(shielding);
        if (!shielding)
        {
            return;
        }

        Vector3 offset = new Vector3(Mathf.Cos(angle) * shieldDistanceFromPlayer, 0.0f, Mathf.Sin(angle) * shieldDistanceFromPlayer);

        shield.transform.position = transform.position;
        shield.transform.position = shield.transform.position + offset;

        float degrees = Mathf.Atan2(-offset.z, offset.x);

        degrees *= (180 / Mathf.PI);
        //this prevents from rotating wrong way

        Vector3 rot = shield.transform.eulerAngles;

        shield.transform.rotation = Quaternion.Euler(rot.x, 0, degrees);
    }
Exemple #20
0
 public bool RegisterPlayer(NetworkInstanceId player)
 {
     if (m_RegisteredPlayer == NetworkInstanceId.Invalid)
     {
         m_RegisteredPlayer = player;
         GameObject registeredPlayer;
         if (isServer)
         {
             registeredPlayer = NetworkServer.FindLocalObject(m_RegisteredPlayer);
         }
         else
         {
             registeredPlayer = ClientScene.FindLocalObject(m_RegisteredPlayer);
         }
         if (registeredPlayer != null)
         {
             m_PlayerController = registeredPlayer.GetComponent <STL_PlayerController>();
             m_PlayerController.m_PlayerStatus = m_Interaction_Status;
         }
         registeredPlayer.GetComponent <STL_PlayerController>().CmdSetAuth(netId);
         Run();
         return(true);
     }
     else
     {
         //TODO SOUND: play busy sound
         return(false);
     }
 }
    public void CmdTakeDamageInServer(NetworkInstanceId netId, float damageValue)
    {
        GameObject snake = NetworkServer.FindLocalObject(GetSnakeNetId(netId));

        print(snake);
        snake.GetComponent <Snake>().CmdTakeDamage(damageValue);
    }
Exemple #22
0
    // Sets ownership of all a client's owned objects to the host
    public void ClearObjectAuthority(HashSet <NetworkInstanceId> clientOwnedObjects)
    {
        if (clientOwnedObjects.Count <= 0)
        {
            return;
        }

        // Create a copy of the list to prevent any issues with deletion
        var ownedObjects = clientOwnedObjects.ToList();

        foreach (var ownedObject in ownedObjects)
        {
            var ownedGameObject = NetworkServer.FindLocalObject(ownedObject);

            // Kill any PlayerCharacter and PlayerConnection objects in the list
            if (ownedGameObject.GetComponent <PlayerCharacter>() != null ||
                ownedGameObject.GetComponent <PlayerConnection>() != null)
            {
                Destroy(ownedGameObject);
                continue; // Skip to next owned object
            }

            // Give authority back to host for non-player related objects
            var newConnectionToClient = GameManager.GetCurrent().GetPlayerConnection(0).connectionToClient;
            var objectNetworkIdentity = ownedGameObject.GetComponent <NetworkIdentity>();
            objectNetworkIdentity.RemoveClientAuthority(objectNetworkIdentity.clientAuthorityOwner);
            objectNetworkIdentity.AssignClientAuthority(newConnectionToClient);
            print("Authority assigned to " + newConnectionToClient + " for " + ownedGameObject);
        }
    }
Exemple #23
0
    // Update is called once per frame
    void Update()
    {
        if (ClientScene.localPlayers.Count == 0 || bank.Instance.goods.Count == 0)
        {
            return;
        }

        foreach (var mygoodtype in (GoodType[])Enum.GetValues(typeof(GoodType)))
        {
            var info = bank.Instance.goods.First(g => g.type == mygoodtype);

            PlayerGoodInfo playerGoodInfo;
            try
            {
                playerGoodInfo = info.playerPositions.First(
                    p => NetworkServer.FindLocalObject(p.id)?.GetComponent <NetworkIdentity>().hasAuthority ?? false);
            }
            catch (InvalidOperationException e)
            {
                return;
            }
            GoodPositionTexts[mygoodtype].GetComponent <Text>().text  = playerGoodInfo.position.ToString();
            GoodInventoryTexts[mygoodtype].GetComponent <Text>().text = info.inventory.ToString();
            GoodPriceTexts[mygoodtype].GetComponent <Text>().text     = info.price.ToString();
        }
    }
 private void SetPoints()
 {
     if ((pointTeamA / winConidtion) > 0.8f)
     {
         if (!teamAIsWinningPlayed)
         {
             teamAIsWinningPlayed = true;
             players = NetworkServer.objects;
             foreach (KeyValuePair <NetworkInstanceId, NetworkIdentity> entry in players)
             {
                 if (entry.Value.isLocalPlayer)
                 {
                     NetworkServer.FindLocalObject(entry.Key).GetComponent <VoiceActing>().TeamWinning(0);
                 }
             }
         }
     }
     if ((pointTeamB / winConidtion) > 0.8f)
     {
         if (!teamBIsWinningPlayed)
         {
             teamBIsWinningPlayed = true;
             players = NetworkServer.objects;
             foreach (KeyValuePair <NetworkInstanceId, NetworkIdentity> entry in players)
             {
                 if (entry.Value.isLocalPlayer)
                 {
                     NetworkServer.FindLocalObject(entry.Key).GetComponent <VoiceActing>().TeamWinning(1);
                 }
             }
         }
     }
     RpcSetPoints(pointTeamA, pointTeamB);
 }
Exemple #25
0
 private void Cmd_SelectCell(NetworkInstanceId cellId)
 {
     if (GameManager.singleton.activePlayer == this)
     {
         NetworkServer.FindLocalObject(cellId).GetComponent <GameCell>().Select(this);
     }
 }
        CreateNew
            (NetworkInstanceId controllerNetworkId)
        {
            MyContract.RequireArgumentNotNull(
                controllerNetworkId,
                "controllerNetworkId"
                );

            GameObject PlayerControllerHost
                = NetworkServer.FindLocalObject(controllerNetworkId);

            MyContract.RequireArgumentNotNull(
                PlayerControllerHost,
                GameObjectNotPresentMessage
                );

            NetworkedPlayerController PlayerController
                = PlayerControllerHost
                  .GetComponent <NetworkedPlayerController>();

            MyContract.RequireArgumentNotNull(
                PlayerController,
                NPCNotPresentMessage
                );

            return(CreateNew(PlayerController));
        }
    public void CmdSpawnPlayer(NetworkInstanceId netId)
    {
        GameObject        newPlayer = NetworkServer.FindLocalObject(netId);
        NetworkConnection conn      = newPlayer.GetComponent <NetworkIdentity>().connectionToClient;

        NetworkServer.ReplacePlayerForConnection(conn, newPlayer, 0);
    }
    [Command]// (serveur)
    public void CmdAddLocalAuthority(GameObject obj)
    {
        NetworkInstanceId nIns   = obj.GetComponent <NetworkIdentity>().netId;
        GameObject        client = NetworkServer.FindLocalObject(nIns);
        NetworkIdentity   ni     = client.GetComponent <NetworkIdentity>();

        ni.AssignClientAuthority(connectionToClient);
    }
    [Command]// (serveur)
    public void CmdRemoveLocalPlayerAuthority(GameObject obj)
    {
        NetworkInstanceId nIns   = obj.GetComponent <NetworkIdentity>().netId;
        GameObject        client = NetworkServer.FindLocalObject(nIns);
        NetworkIdentity   ni     = client.GetComponent <NetworkIdentity>();

        ni.RemoveClientAuthority(ni.clientAuthorityOwner);
    }
Exemple #30
0
 public void OnRemoveFromPool()
 {
     if (CurrentMagazine != null)
     {
         EquipmentPool.DisposeOfObject(NetworkServer.FindLocalObject(ControlledByPlayer).gameObject, CurrentMagazine.gameObject);
     }
     ControlledByPlayer = NetworkInstanceId.Invalid;
 }