Exemplo n.º 1
0
    // Get artifact tree
    public static Coroutine GetArtifactTree(LobbyPlayer player)
    {
        return(GameDB.instance.StartCoroutine(GameDB.Get <ArtifactTree>(
                                                  "AccountToArtifactTree",
                                                  player.accountId,
                                                  data => {
            if (data == null)
            {
                player.artifactTree = ArtifactTree.GetStarterArtifactTree();
            }
            else
            {
                player.artifactTree = data;
            }

            Lobby.RPC("ReceiveArtifactTree", player.peer, player.accountId, Jboy.Json.WriteObject(player.artifactTree));
        }
                                                  )));
    }
Exemplo n.º 2
0
    // InstantiatePlayer
    void InstantiatePlayer(uLink.NetworkPlayer networkPlayer, string accountId, string playerName, Vector3 respawnPosition, float cameraYRotation, int partyId)
    {
        LogManager.General.Log(string.Format("Instantiating player prefabs for '{0}' with account ID '{1}'", playerName, accountId));

        var party = GameServerParty.partyList[partyId];

        // Instantiates an avatar for the player connecting to the server
        // The player will be the "owner" of this object. Read the manual chapter 7 for more
        // info about object roles: Creator, Owner and Proxy.
        GameObject obj = uLink.Network.Instantiate(
            networkPlayer,                                      // Owner
            proxyPrefab,
            ownerPrefab,
            creatorPrefab,
            respawnPosition,
            Cache.quaternionIdentity,
            0,                                                          // Network group
            accountId                                                   // Initial data
            );

        // Player component
        Player player = obj.GetComponent <Player>();

        player.accountId        = accountId;
        networkPlayer.localData = player;

        // Send name
        player.networkView.RPC("ReceivePlayerName", uLink.RPCMode.All, playerName);

        // Async: DB requests
        if (isTestServer)
        {
            // This section is for quick client tests on the test server

            // Send other players and myself information about stats
            player.skillBuild    = SkillBuild.GetStarterBuild();
            player.customization = new CharacterCustomization();

            player.networkView.RPC("ReceiveSkillBuild", uLink.RPCMode.All, player.skillBuild);
            player.networkView.RPC("ReceiveCharacterCustomization", uLink.RPCMode.All, player.customization);
            player.networkView.RPC("ReceiveCharacterStats", uLink.RPCMode.All, new CharacterStats());
            player.networkView.RPC("ReceiveArtifactTree", uLink.RPCMode.All, Jboy.Json.WriteObject(ArtifactTree.GetStarterArtifactTree()));

            // After the skill build has been sent, switch the attunement
            player.networkView.RPC("SwitchWeapon", uLink.RPCMode.All, (byte)0);
            player.networkView.RPC("SwitchAttunement", uLink.RPCMode.All, (byte)0);
        }
        else
        {
            // Experience / Level
            ExperienceDB.GetExperience(
                accountId,
                data => {
                uint exp = 0;

                if (data != null)
                {
                    exp = data.experience;
                }

                player.networkView.RPC("SetExperience", uLink.RPCMode.All, exp);
            }
                );

            // TODO: We need to wait until this is finished in ApplyCharacterStats
            // Skill build
            SkillBuildsDB.GetSkillBuild(
                accountId,
                data => {
                if (data == null)
                {
                    player.skillBuild = SkillBuild.GetStarterBuild();
                }
                else
                {
                    player.skillBuild = data;
                }

                // Send build
                player.networkView.RPC("ReceiveSkillBuild", uLink.RPCMode.All, player.skillBuild);

                // After the build has been sent, switch the attunement
                player.networkView.RPC("SwitchWeapon", uLink.RPCMode.All, (byte)0);
                player.networkView.RPC("SwitchAttunement", uLink.RPCMode.All, (byte)0);
            }
                );

            // Character customization
            CharacterCustomizationDB.GetCharacterCustomization(
                accountId,
                data => {
                if (data == null)
                {
                    player.customization = new CharacterCustomization();
                }
                else
                {
                    player.customization = data;
                }

                // Send customization
                player.networkView.RPC("ReceiveCharacterCustomization", uLink.RPCMode.All, player.customization);
            }
                );

            // Character stats
            StartCoroutine(ServerGameDB.GetCharacterStats(player));

            // Guild
            GuildsDB.GetGuildList(accountId, data => {
                if (data != null)
                {
                    GuildsDB.GetGuild(data.mainGuildId, guild => {
                        if (guild != null)
                        {
                            player.networkView.RPC("ReceiveMainGuildInfo", uLink.RPCMode.All, guild.name, guild.tag);
                        }
                    });
                }
            });

            // Artifacts
            ArtifactsDB.GetArtifactTree(
                accountId,
                data => {
                if (data == null)
                {
                    player.artifactTree = ArtifactTree.GetStarterArtifactTree();
                }
                else
                {
                    player.artifactTree = data;
                }

                player.networkView.RPC("ReceiveArtifactTree", uLink.RPCMode.All, Jboy.Json.WriteObject(player.artifactTree));
            }
                );

            // Retrieve arena stats
            var statsBucket = new Bucket("AccountToStats");
            statsBucket.Get(
                accountId,
                Constants.Replication.Default,
                (request) => {
                var statsInDB = request.GetValue <PlayerStats>();

                LogManager.General.Log("Queried stats of account '" + accountId + "' successfully (Ranking: " + statsInDB.bestRanking + ")");

                // Send ranking
                player.networkView.RPC("ReceiveBestRanking", uLink.RPCMode.All, statsInDB.bestRanking);
            }, (request) => {
                var statsInDB = new PlayerStats();

                LogManager.General.Log("Account '" + accountId + "' aka player '" + playerName + "' doesn't have any player stats yet");

                // Send ranking
                player.networkView.RPC("ReceiveBestRanking", uLink.RPCMode.All, statsInDB.bestRanking);
            }
                );
        }

        if (GameManager.isArena)
        {
            player.networkView.RPC("GameMaxScore", uLink.RPCMode.Owner, gameMode.scoreNeededToWin);
        }

        // Layer
        if (GameManager.isPvP)
        {
            player.networkView.RPC("ChangeParty", uLink.RPCMode.All, partyId);
            player.networkView.RPC("ChangeLayer", uLink.RPCMode.All, party.layer);
        }
        else
        {
            player.networkView.RPC("ChangeLayer", uLink.RPCMode.All, Config.instance.openWorldPvPLayer);
        }

        // Respawn
        player.networkView.RPC("Respawn", uLink.RPCMode.All, respawnPosition);
        player.networkView.RPC("SetCameraYRotation", uLink.RPCMode.Owner, cameraYRotation);

        // On non account restricted servers we start the game instantly
        if (!GameManager.isArena || isTestServer)
        {
            player.networkView.RPC("StartGame", uLink.RPCMode.Owner);
            GameManager.gameStarted = true;
        }

        // Disable encryption in non-ranked games
        //if(!GameManager.isRankedGame)
        //	uLink.Network.UninitializeSecurity(networkPlayer);
    }
Exemplo n.º 3
0
    // Sends data about the account to any player
    public static void SendPublicAccountInfo(string accountId, LobbyPlayer toPlayer)
    {
        var player = GetLobbyPlayer(accountId);

        // Name
        LobbyGameDB.GetPlayerName(accountId, data => {
            if (data == null)
            {
                if (player == toPlayer)
                {
                    Lobby.RPC("AskPlayerName", toPlayer.peer);
                }
            }
            else
            {
                Lobby.RPC("ReceivePlayerName", toPlayer.peer, accountId, data);

                if (player == toPlayer)
                {
                    if (string.IsNullOrEmpty(player.name))
                    {
                        player.name = data;
                        LobbyServer.OnReceivePlayerName(player);
                    }
                }
            }
        });

        // Character customization
        CharacterCustomizationDB.GetCharacterCustomization(accountId, data => {
            if (data == null)
            {
                if (player == toPlayer)
                {
                    Lobby.RPC("CustomizeCharacter", toPlayer.peer, accountId);
                }
            }
            else
            {
                if (player != null)
                {
                    player.custom = data;
                }
                Lobby.RPC("ReceiveCharacterCustomization", toPlayer.peer, accountId, data);
            }
        });

        // Skill build
        SkillBuildsDB.GetSkillBuild(accountId, data => {
            if (data == null)
            {
                Lobby.RPC("ReceiveSkillBuild", toPlayer.peer, accountId, SkillBuild.GetStarterBuild());
            }
            else
            {
                Lobby.RPC("ReceiveSkillBuild", toPlayer.peer, accountId, data);
            }
        });

        // Stats
        LobbyGameDB.GetPlayerStats(accountId, data => {
            if (data == null)
            {
                data = new PlayerStats();
            }

            // Assign stats
            if (player != null)
            {
                player.stats = data;
            }

            // Send the stats to the player
            Lobby.RPC("ReceivePlayerStats", toPlayer.peer,
                      accountId,
                      Jboy.Json.WriteObject(data)
                      );
        });

        // FFA Stats
        LobbyGameDB.GetPlayerFFAStats(accountId, data => {
            if (data == null)
            {
                data = new PlayerStats();
            }

            // Assign stats
            if (player != null)
            {
                player.ffaStats = data;
            }

            // Send the stats to the player
            Lobby.RPC("ReceivePlayerFFAStats", toPlayer.peer,
                      accountId,
                      Jboy.Json.WriteObject(data)
                      );
        });

        // Character stats
        TraitsDB.GetCharacterStats(accountId, data => {
            if (data == null)
            {
                data = new CharacterStats();
            }

            if (player != null)
            {
                player.charStats = data;
            }

            Lobby.RPC("ReceiveCharacterStats", toPlayer.peer, accountId, data);
        });

        // Artifact inventory
        ArtifactsDB.GetArtifactInventory(accountId, data => {
            if (data == null)
            {
                data = new ArtifactInventory();
            }

            if (player != null)
            {
                player.artifactInventory = data;
            }

            Lobby.RPC("ReceiveArtifactInventory", toPlayer.peer, accountId, Jboy.Json.WriteObject(data));
        });

        // Artifact tree
        ArtifactsDB.GetArtifactTree(accountId, data => {
            if (data == null)
            {
                data = ArtifactTree.GetStarterArtifactTree();
            }

            if (player != null)
            {
                player.artifactTree = data;
            }

            Lobby.RPC("ReceiveArtifactTree", toPlayer.peer, accountId, Jboy.Json.WriteObject(data));
        });

        // Experience
        ExperienceDB.GetExperience(accountId, data => {
            uint exp = 0;

            if (data != null)
            {
                exp = data.experience;
            }

            Lobby.RPC("ReceiveExperience", toPlayer.peer, accountId, exp);
        });

        // Item inventory
        ItemInventoryDB.GetItemInventory(accountId, data => {
            if (data == null)
            {
                data = new ItemInventory();
            }

            if (player != null)
            {
                player.itemInventory = data;
            }

            Lobby.RPC("ReceiveItemInventory", toPlayer.peer, accountId, Jboy.Json.WriteObject(data));
        });

        // View profile
        Lobby.RPC("ViewProfile", toPlayer.peer, accountId);
    }