Beispiel #1
0
    private void LoadFromJSON()
    {
        string    deckJson = System.IO.File.ReadAllText($"{deckDir}/{fileName}");
        SavedDeck loaded   = SavedDeck.LoadFromString(deckJson);

        this.name      = loaded.name;
        this.character = loaded.character;
        this.cards     = new List <Card>(loaded.cards);
    }
Beispiel #2
0
    public override void OnStartAuthority()
    {
        build = SavedDeck.LoadFromString(buildJson);
        var byType = build.cards.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());

        foreach (var kvp in byType)
        {
            RegisterPrefab(kvp.Key.spellPrefab, kvp.Value);
        }
        this.buildJson = build.ToString();
        CmdAvatarSpawned();
    }
Beispiel #3
0
    public override void OnStartServer()
    {
        // Get the chosen buildJson and deserialize it.
        build = SavedDeck.LoadFromString(buildJson);
        // Spawn the build.character.avatarPrefab with client authority
        var spawnPoint = NetworkManager.singleton.GetStartPosition();

        build = SavedDeck.LoadFromString(buildJson);
        var avatarGameObject = GameObject.Instantiate(build.character.avatarPrefab, spawnPoint.position, spawnPoint.rotation);

        avatarGameObject.GetComponent <Avatar>().playerNetId = netId;
        NetworkServer.Spawn(avatarGameObject, connectionToClient);

        // // setup the avatar
        // avatar = avatarGameObject.GetComponent<Avatar>();
        // avatar.Init(this);
    }
Beispiel #4
0
    public void RpcAvatarSpawned()
    {
        Debug.Log("RpcAvatarSpawned");
        var avatars = FindObjectsOfType <Avatar>();
        var players = new List <GamePlayer>(FindObjectsOfType <GamePlayer>());

        var playerDictionary = players.ToDictionary(x => x.netId, x => x);

        foreach (Avatar a in avatars)
        {
            if (playerDictionary.ContainsKey(a.playerNetId))
            {
                // map the other players to their respective avatars
                if (a.initialized == true)
                {
                    continue;
                }
                a.Init(playerDictionary[a.playerNetId]);
                playerDictionary[a.playerNetId].avatar = a;

                // get the buildJson of this gamePlayer and call LoadCards() to initialize the deck
                a.deck.LoadCards(SavedDeck.LoadFromString(playerDictionary[a.playerNetId].buildJson).cards);
                if (a.hasAuthority)
                {
                    // This will only happen on the local player
                    hudUI.SetActive(true);
                    // link healthUI to health
                    healthUI.Health = ((PlayerHealth)avatar.health);
                    // link deckUI to deck
                    deckUI.deck = avatar.deck;
                    deckUI.Init();
                }
                continue;
            }
            // we should never get here, so spit out a warning
            Debug.LogWarning($"Warning, avatar with connectionId: {netIdentity.connectionToClient} does not have a gamePlayer");
        }
        // look up all avatars in the scene and match them with their gameplayers
    }
Beispiel #5
0
 private void RpcSelectCharacterBuild(string deckJson)
 {
     selectedBuild = SavedDeck.LoadFromString(deckJson);
 }