Ejemplo n.º 1
0
        public string ToString()
        {
            if (PlayerID != null)
            {
                if (BackingController != null)
                {
                    return(StandardIdentifier());
                }
                else // can't use netid yet
                {
                    // try to recover
                    GameObject NPCHost;

                    // The following section is disgusting,
                    // but I can't tell why this is happening.
                    // I only pull the value after
                    // the local player controller is spawned
                    // (in NetworkedPlayerController.OnStartServer)
                    // so there's no reason why the gameobject
                    // should be null/unready.
                    //
                    // It looks (to me) like Unity's networking tries to
                    // instantiate this object with new rather than
                    // with AddComponent, so it becomes "headless".
                    // This is all undocumented behaviour,
                    // so I'm just going to try and avoid dealing with it.
                    try
                    {
                        NPCHost = gameObject;
                    }
                    catch (NullReferenceException nre)
                    {
                        Debug.LogWarning(NoGameObjectWarning);
                        NPCHost = NetworkServer.FindLocalObject(PlayerID);
                        if (NPCHost == null)
                        {
                            return(BackupIndentifier());
                        }
                    }
                    NetworkedPlayerController NPC
                        = NPCHost
                          .GetComponent <NetworkedPlayerController>();
                    MyContract.RequireFieldNotNull(
                        NPC,
                        "NetworkedPlayerController attached to the "
                        + "local object corresponding to NetworkInstanceId "
                        + PlayerID.ToString()
                        );
                    BackingController = NPC;
                    return(StandardIdentifier());
                }
            }
            else
            {
                return("Null" + PrintInitStatus());
            }
        }
Ejemplo n.º 2
0
    string MakeUniqueIdentity()
    {
        //Player + NetIDで名前を付ける
        string uniqueName = "Player " + playerNetID.ToString();

        return(uniqueName);
    }
Ejemplo n.º 3
0
    public void RegisterPlayer(NetworkInstanceId netId, string ruyiProfileId, string ruyiProfileName)
    {
        Debug.Log("Register Player: " + netId.ToString() + " | Host: " + isServer);

        //  TODO:   Get Profile Name
        var      savePath = string.IsNullOrEmpty(ruyiProfileName) ? SAVEGAME_LOCATION : Path.Combine(ruyiProfileName, SAVEGAME_LOCATION);
        SaveGame saveGame;

        try
        {
            saveGame = mSaveLoad.Load <SaveGame>(RuyiNet.GetActivePersistentDataPath(), savePath);
        }
        catch (FileNotFoundException)
        {
            saveGame = new SaveGame();
        }

        PlayerStateData playerState = new PlayerStateData
        {
            NetId           = netId,
            ProfileId       = ruyiProfileId,
            ProfileName     = string.IsNullOrEmpty(ruyiProfileName) ? "Player " + netId : ruyiProfileName,
            Score           = 0,
            CurrentStrength = saveGame.Strength,
            MaxStrength     = saveGame.Strength
        };

        if (mPlayerState != null)
        {
            mPlayerState.Add(playerState);
        }

        RpcUpdatePlayerColors();
    }
Ejemplo n.º 4
0
    string MakeUniqueIdentity()
    {
        //Player + NetIDで名前設定
        string UniqueName = "Player" + playerNetID.ToString();

        Debug.Log("生成した名前:" + UniqueName);
        return(UniqueName);
    }
Ejemplo n.º 5
0
    public void DealDamageToEnemy(GameObject otherObject)
    {
        GameObject player = NetworkServer.FindLocalObject(ownerId);

        damageRate = player.GetComponent <PlayerStats>().Damage;
        DevLog.Log("Bullet", "Player with id <" + ownerId.ToString() + "> dealt damage to enemy with " + damageRate);
        otherObject.GetComponent <Health>().EnemyTakeDamage(damageRate, ownerId);
    }
Ejemplo n.º 6
0
    public override void OnStartClient()
    {
        base.OnStartClient();

        infoObject      = ClientScene.FindLocalObject(playerID);
        gameObject.name = "Player (" + playerID.ToString() + ")";

        GlobalInfo.current.SetupTargetCamera(gameObject);
    }
Ejemplo n.º 7
0
    // Use this for initialization
    void Start()
    {
        NetworkInstanceId gamePlayerNetID = gameObject.GetComponent <NetworkIdentity>().netId;

        Debug.Log("ID player : " + gamePlayerNetID);

        if (isServer)
        {
            if (!isLocalPlayer)
            {
                Debug.Log("Attempt Player Classic Online init...");
                LoadClassicOnlinePlayer();
                Debug.Log("New Player Online !");
            }
            else
            {
                Debug.Log("Attempt Player VR Local Host init...");
                LoadVRLocalPlayer();
                Debug.Log("You are now Online !");
            }
        }
        else
        {
            if (!isLocalPlayer)
            {
                int i = 0;
                foreach (GameObject go in GameObject.FindGameObjectsWithTag("Player"))
                {
                    if (int.Parse(gamePlayerNetID.ToString()) > int.Parse(go.GetComponent <NetworkIdentity>().netId.ToString()))
                    {
                        i++;
                    }
                }

                if (i == 0)
                {
                    Debug.Log("Attempt Player VR Online Client init...");
                    LoadlVROnlinePlayer();
                    Debug.Log("New Player Online !");
                }
                else
                {
                    Debug.Log("Attempt Player Classic Online init...");
                    LoadClassicOnlinePlayer();
                    Debug.Log("New Player Online !");
                }
            }
            else
            {
                Debug.Log("Player Classic Local Client init...");
                LoadClassicLocalPlayer();
                Debug.Log("You are now Online !");
            }
        }
    }
Ejemplo n.º 8
0
 void SetUID()
 {
     if (!isLocalPlayer)
     {
         playerTransform.name = playerUID;
     }
     else
     {
         playerTransform.name = "Player_" + playerNetworkID.ToString();
     }
 }
 string MakeUniqueIdentity()
 {
     if (playerUniqueIdentity == "Player" || playerUniqueIdentity == "" || playerUniqueIdentity == "Player(Clone)")
     {
         string uniqueName = "Player " + playerNetID.ToString();  //The ID of the player
         return(uniqueName);
     }
     else
     {
         return(playerUniqueIdentity);
     }
 }
Ejemplo n.º 10
0
    public string GetNickname(NetworkInstanceId _netID)
    {
        for (int f = 0; f < listNetClient.Count; ++f)
        {
            if (listNetClient [f].netId == _netID)
            {
                return(listNetClient [f].m_nickName);
            }
        }

        return(_netID.ToString() + "님");
    }
Ejemplo n.º 11
0
    public void RpcAddPickup(NetworkInstanceId chestId, string pickupName)
    {
        if (chestPickups.ContainsKey(chestId))
        {
            return;
        }

        chestPickups.Add(chestId, PickupCatalog.GetPickupDef(PickupCatalog.FindPickupIndex(pickupName)));
#if DEBUG
        Debug.Log($"Synced pickup in chest id [{chestId.ToString()}]");
#endif
    }
Ejemplo n.º 12
0
    /// <summary>
    /// when a client requests details about the player, get the details and send them back
    /// </summary>
    /// <param name="netMessage">the message requesting the details</param>
    private void OnClientRequestPlayerDetails(NetworkMessage netMessage)
    {
        PlayerRequestPlayerDataMessage requestedMessage = netMessage.ReadMessage <PlayerRequestPlayerDataMessage>();

        NetworkInstanceId senderID  = requestedMessage.SenderID;
        NetworkInstanceId subjectID = requestedMessage.SubjectID;

        GameObject  subjectPlayerObject = NetworkServer.FindLocalObject(subjectID);
        CustomLobby subjectPlayer       = subjectPlayerObject.GetComponent <CustomLobby>();

        NetworkServer.SendToClient(int.Parse(senderID.ToString()), CustomMsgType.ClientRecievePlayerDetails, new GamePlayerDetailsMessage(subjectID, subjectPlayer.playerDetails));
    }
Ejemplo n.º 13
0
    }           //When OnParticleCollision is invoked from a script attached to a ParticleSystem,

    //the GameObject parameter represents a GameObject with an attached Collider struck by the ParticleSystem.
    public void OnParticleCollision(GameObject other)
    {
        //add isServer and spawn particle manager with client authority
        //tell server to decrement the health of the player
        //Debug.Log("HIT COLLISION ENTER!!!!!!!!!");
        Debug.Log("HIT COLLISION IN PARTICLE -> the object hit is: " + other.name);

        NetworkInstanceId id = other.GetComponent <NetworkIdentity>().netId;

        Debug.Log("hit network id: " + id.ToString());
        CmdPlayerHit(id);
    }
        void Update()
        {
            if (CloudController == null)
            {
                CloudController = GameObject.Find("CloudAnchorsExampleController").GetComponent <CloudAnchorsExampleController>();
            }

            if (mNetID.ToString() == "0")
            {
                mNetID = gameObject.GetComponent <NetworkIdentity>().netId;
            }
        }
Ejemplo n.º 15
0
        public void CmdMakeSphere(Vector3 position)
        {
            GameObject obj = (GameObject)Instantiate(spherePrefab, position, Quaternion.identity);

            NetworkServer.SpawnWithClientAuthority(obj, connectionToClient);
            NetworkInstanceId id = obj.GetComponent <NetworkIdentity>().netId;

            Debug.Log("network id: " + id.ToString());
            Debug.Log("INSTANTIATED!!!!!!!!!!!!");
            //dont set colour for now
            //RpcSetSphereColor (sphere, myColour.r, myColour.g, myColour.b);
            RpcgetReferenceToObject(id);
        }
Ejemplo n.º 16
0
 public static void ResumeWalking(NetworkInstanceId id)
 {
     readyList[int.Parse(id.ToString())] = true;
     for (int i = 0; i < Selector.activeMinigames.Count; i++)
     {
         if (readyList[i] == false)
         {
             goto NotReady;
         }
     }
     FindObjectOfType <OverworldScript>().Go();
     NotReady :;
 }
Ejemplo n.º 17
0
    private void OnGUI()
    {
        string text = "";

        text = "Ball:" + ballobject.ToString() + System.Environment.NewLine;
        if (isServer)
        {
            foreach (NetworkConnection m in NetworkServer.connections)
            {
                text += m.connectionId + System.Environment.NewLine;
            }
        }
        text    += "Spieler:" + playercount.ToString() + System.Environment.NewLine;
        txt.text = text;
    }
Ejemplo n.º 18
0
    void RpcCarCallback(NetworkInstanceId carid, NetworkInstanceId driverid, int seatid)
    {
        Debug.Log("Found a vehicle netID(" + carid.ToString() + ") callback : Find open seat ID = " + seatid);
        if (seatid == -1)
        {
            return;
        }

        GameObject obj = ClientScene.FindLocalObject(carid);

        if (obj)
        {
            Vehicle vehicle = obj.GetComponent <Vehicle>();
            vehicle.GetInTheVehicle(this, seatid);
        }
    }
Ejemplo n.º 19
0
    void Update()
    {
        if (Value != "")
        {
            return;
        }

        if (isLocalPlayer)
        {
            Value = _id.ToString();
            CmdTellId(Value);
        }
        else
        {
            Value = _syncValue;
        }
    }
    public override void OnClientDisconnect(NetworkConnection conn)
    {
        HashSet <NetworkInstanceId> hSet       = conn.clientOwnedObjects;
        NetworkInstanceId           instanceId = NetworkInstanceId.Invalid;

        foreach (NetworkInstanceId id in hSet)
        {
            instanceId = id;
        }
        foreach (GameObject ship in GameObject.FindGameObjectsWithTag("Player"))
        {
            if (ship.GetComponent <Player_ID>().playerNetID.ToString() == instanceId.ToString())
            {
                ship.GetComponent <ColorSquareManager>().TransmitChange(ship.GetComponent <Ship>().GetShipID(), true);
            }
        }
        base.OnClientDisconnect(conn);
    }
    public void RpcDropEverything(NetworkInstanceId _playerDropping)
    {
        Debug.Log("Dropping Everything from Player#: " + _playerDropping.ToString());
        //Drop weapon
        PlayerController playerDropping = ClientScene.FindLocalObject(_playerDropping).GetComponent <PlayerController>();

        Destroy(playerDropping.GetComponent <HingeJoint2D>());
        if (playerDropping.weaponsGunScript != null)
        {
            playerDropping.weaponsGunScript.equipped = false;
            playerDropping.holdingGun = false;
            playerDropping.weaponsGunScript.GetComponent <Animator>().SetTrigger("idle");
            playerDropping.weaponsGunScript.rb.velocity       += new Vector2(Random.Range(0.5f, 2.0f), Random.Range(0.5f, 2.0f));
            playerDropping.weaponsGunScript.rb.angularVelocity = 15.0f;
        }
        //Drop ammo
        playerDropping.nameCanvasInstance.GetComponentInChildren <TextMeshProUGUI>().text = "";
    }
Ejemplo n.º 22
0
    public void ButtonAction()
    {
        buttons[CurMenuItem].sceneimage.color = buttons[CurMenuItem].PressedColor;
        GameObject        Player = this.transform.parent.gameObject;
        NetworkInstanceId netID  = Player.GetComponent <NetworkIdentity>().netId;

        Debug.Log("Sending emote with networkID: " + netID.ToString());
        Vector3 offset = new Vector3(0.0f, 2.5f, 0.0f);

        //IconObject DisplayEmote;
        if (CurMenuItem == 0)
        {
            SendEmoteMessageAndClientID m = new SendEmoteMessageAndClientID();
            m.emoteType = 0;
            m.netId     = netID;
            NetworkManager.singleton.client.Send(LevelMsgType.EmoteSingleSender, m);
        }
        else if (CurMenuItem == 1)
        {
            SendEmoteMessageAndClientID m = new SendEmoteMessageAndClientID();
            m.emoteType = 1;
            m.netId     = netID;
            NetworkManager.singleton.client.Send(LevelMsgType.EmoteSingleSender, m);
        }
        else if (CurMenuItem == 2)
        {
            SendEmoteMessageAndClientID m = new SendEmoteMessageAndClientID();
            m.emoteType = 2;
            m.netId     = netID;
            NetworkManager.singleton.client.Send(LevelMsgType.EmoteSingleSender, m);
        }
        else if (CurMenuItem == 3)
        {
            SendEmoteMessageAndClientID m = new SendEmoteMessageAndClientID();
            m.emoteType = 3;
            m.netId     = netID;
            NetworkManager.singleton.client.Send(LevelMsgType.EmoteSingleSender, m);
        }

        menuon = false;
    }
Ejemplo n.º 23
0
        public void OnReceived()
        {
            if (!NetworkServer.active)
            {
                return;
            }

            Log("Received kookeh drop message");
            Log("NetworkID" + netId.ToString());
            Log("PickupIndex" + this.pickupIndex.ToString());

            var bodyObject = Util.FindNetworkObject(netId);

            var body = bodyObject.GetComponent <CharacterBody>();

            Log("Body is null: " + (body == null).ToString());

            var inventory     = body.master.inventory;
            var charTransform = body.GetFieldValue <Transform>("transform");

            DropItemHandler.DropItem(charTransform, inventory, pickupIndex);
            DropItemHandler.CreateNotification(body, charTransform, pickupIndex);
        }
Ejemplo n.º 24
0
        public void SetupRequestUI()
        {
            Assert.IsTrue(isLocalPlayer, "Only run DrawPeaceRequestUI on the LocalPlayer");
            if (ReceivedWarAssistanceRequest)
            {
                MainUIRoot.Instance.Diplomacy.DisplayPrompt($"Ihr Bündnisparter {PlayerOfRequest} hat {Enemy} den Krieg erklärt. Möchten sie zu ihrem Bündnis stehen", () =>
                {
                    CmdSendDeclarationOfWar(Enemy);
#pragma warning disable 618
                    Enemy          = NetworkInstanceId.Invalid;
                    SelectedPlayer = NetworkInstanceId.Invalid;
#pragma warning restore 618
                    ReceivedRequest = false;
                    ReceivedWarAssistanceRequest     = false;
                    Player.LocalPlayer.ShowDiplomacy = false;
                }, () =>
                {
                    int index                  = PlayerRelationships.Find(PlayerOfRequest);
                    var relationship           = PlayerRelationships[index];
                    relationship.State         = RelationshipState.Peace;
                    PlayerRelationships[index] = relationship;
#pragma warning disable 618
                    var ally = NetworkServer.FindLocalObject(PlayerOfRequest).GetComponent <Diplomacy>();
#pragma warning restore 618
                    index              = ally.PlayerRelationships.Find(netId);
                    relationship       = ally.PlayerRelationships[index];
                    relationship.State = RelationshipState.Peace;
                    ally.PlayerRelationships[index] = relationship;
#pragma warning disable 618
                    Enemy          = NetworkInstanceId.Invalid;
                    SelectedPlayer = NetworkInstanceId.Invalid;
#pragma warning restore 618
                    ReceivedWarAssistanceRequest = false;
                    ReceivedRequest = false;
                    Player.LocalPlayer.ShowDiplomacy = false;
                });
            }
            else
            {
                string request = "";
                switch (RequestType)
                {
                case RelationshipState.Peace:
                { request = "Frieden schließen"; break; }

                case RelationshipState.TradingAgreement:
                { request = "ein Handelsabkommen abschließen"; break; }

                case RelationshipState.Alliance:
                { request = "ein Bündnis abschließen"; break; }
                }
                string playerName;
                Player player = GameManager.Instance.GetPlayerOfId(PlayerOfRequest);
                if (player != null)
                {
                    playerName = player.ToString();
                }
                else
                {
                    playerName = PlayerOfRequest.ToString();
                }
                MainUIRoot.Instance.Diplomacy.DisplayPrompt($"Spieler {playerName} möchte {request}", () =>
                {
                    CmdAcceptRequest(RequestType);
                    Player.LocalPlayer.ShowDiplomacy = false;
                }, () =>
                {
                    CmdDeclineRequest();
                    Player.LocalPlayer.ShowDiplomacy = false;
                });
            }
        }
Ejemplo n.º 25
0
 string GenerateName()
 {
     return("Player " + playerId.ToString());
 }
Ejemplo n.º 26
0
    string MakeUniqueName()
    {
        string uniqueName = "Player" + playerNetID.ToString();

        return(uniqueName);
    }
Ejemplo n.º 27
0
    private string MakeNamePlayer()
    {
        string tempName = "Player" + playerID.ToString();

        return(tempName);
    }
Ejemplo n.º 28
0
    string CreateUniqueIdentity()
    {
        string uniqueName = "Player" + playerNetID.ToString();

        return(uniqueName);
    }
Ejemplo n.º 29
0
 string MakeUniqueIdentity()
 {
     return("Player" + playerNetID.ToString());
 }
Ejemplo n.º 30
0
    string MakeUniqueID()
    {
        string uniqueID = "Player " + playerNetID.ToString();

        return(uniqueID);
    }