示例#1
0
    void TargetSongWasSet(int player, int song)
    {
        string song_name = "";

        switch (song)
        {
        case -1:
            song_name = "silence"; break;

        case 0:
            song_name = "\"Forest\""; break;

        case 1:
            song_name = "\"Dungeon\""; break;

        case 2:
            song_name = "\"HellGate\""; break;

        case 3:
            song_name = "\"The Grim\""; break;
        }
        var    player_info_list = PlayerListScript.Instance().GetPlayerInfoList();
        string player_name      = "You";

        if (player_info_list.ContainsKey(player))
        {
            player_name = player_info_list[player].name_;
        }
        ConsoleScript.Log(player_name + " changed song to " + song_name);
        target_song_ = song;
    }
示例#2
0
    void NetEventPlayerDisconnected(NetEvent net_event)
    {
        NetworkPlayer player = net_event.network_player();

        ConsoleScript.Log("Player " + player + " disconnected");
        PlayerListScript.Instance().Remove(int.Parse(player.ToString()));
        Network.RemoveRPCs(player);
        Network.DestroyPlayerObjects(player);
    }
示例#3
0
    void AssignTokenColors()
    {
        // Create list of tokens
        var token_objects = new List <GameObject>();

        foreach (GameObject grabbable in grabbable_objects)
        {
            if (grabbable.GetComponent <TokenScript>())
            {
                token_objects.Add(grabbable);
            }
        }
        var players = PlayerListScript.Instance().GetPlayerInfoList();

        // Assign owners to tokens as needed
        if (Network.isServer)
        {
            var used_id = new HashSet <int>();
            foreach (GameObject token in token_objects)
            {
                used_id.Add(token.GetComponent <TokenScript>().owner_id_);
            }
            foreach (GameObject token in token_objects)
            {
                var token_script = token.GetComponent <TokenScript>();
                if (!players.ContainsKey(token_script.owner_id_))
                {
                    foreach (var pair in players)
                    {
                        if (!used_id.Contains(pair.Key))
                        {
                            token_script.owner_id_ = pair.Key;
                            used_id.Add(pair.Key);
                        }
                    }
                }
            }
        }
        // Assign colors to tokens based on owner
        foreach (GameObject token in token_objects)
        {
            var token_script = token.GetComponent <TokenScript>();
            if (players.ContainsKey(token_script.owner_id_))
            {
                token.renderer.material.color = players[token_script.owner_id_].color_;
            }
            else
            {
                token.renderer.material.color = Color.white;
            }
        }
    }
示例#4
0
    void TellServerPlayerName(string name)
    {
        int player_id = int.Parse(Network.player.ToString());

        ConsoleScript.Log("Telling server that player " + player_id + " is named: " + player_name_);
        if (Network.isClient)
        {
            networkView.RPC("SetPlayerName", RPCMode.Server, player_id, name);
        }
        else
        {
            PlayerListScript.Instance().SetPlayerName(player_id, name);
        }
    }
示例#5
0
    void Update()
    {
        var player_list = PlayerListScript.Instance().GetPlayerInfoList();

        if (player_list.ContainsKey(id_))
        {
            SetColor(player_list[id_].color_);
        }
        if (networkView.isMine)
        {
            if (Input.GetKeyDown("f"))
            {
                card_face_up_ = !card_face_up_;
            }
            if (Input.GetKeyDown("e"))
            {
                card_rotated_ = (card_rotated_ + 1) % 4;
            }
            if (Input.GetKeyDown("q"))
            {
                card_rotated_ = (card_rotated_ + 3) % 4;
            }
            if (Input.GetKeyDown("r"))
            {
                card_face_up_ = false;
                card_rotated_ = 0;
            }
            tapping_ = Input.GetKey("t");
            var     main_camera = GameObject.Find("Main Camera").camera;
            Vector3 pos         = new Vector3();
            {
                Ray        ray         = main_camera.ScreenPointToRay(Input.mousePosition);
                RaycastHit raycast_hit = new RaycastHit();
                if (Physics.Raycast(ray, out raycast_hit, 100.0f, 1 << 8))
                {
                    pos = raycast_hit.point - ray.direction;
                }
            }

            if (Input.GetMouseButton(0))
            {
                Ray          ray = main_camera.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] raycast_hits;
                raycast_hits = Physics.RaycastAll(ray);
                System.Array.Sort(raycast_hits, new RaycastHitComparator());
                int hit_deck_id = -1;
                foreach (RaycastHit hit in raycast_hits)
                {
                    var hit_obj = hit.collider.gameObject;
                    if (hit_obj.layer != LayerMask.NameToLayer("Dice") &&
                        hit_obj.layer != LayerMask.NameToLayer("Tokens") &&
                        hit_obj.layer != LayerMask.NameToLayer("Cards"))
                    {
                        continue;
                    }
                    GrabbableScript grabbable_script = hit_obj.GetComponent <GrabbableScript>();
                    if (!grabbable_script)
                    {
                        hit_obj          = hit_obj.transform.parent.gameObject;
                        grabbable_script = hit_obj.GetComponent <GrabbableScript>();
                    }
                    if (hit_obj.GetComponent <DeckScript>())
                    {
                        hit_deck_id = grabbable_script.id_;
                    }
                    if (grabbable_script.held_by_player_ == id_)
                    {
                        continue;
                    }
                    if (hit_obj.GetComponent <DeckScript>() && deck_held_time_ > 0.0f && grabbable_script.id_ == deck_held_id_)
                    {
                        deck_held_time_ += Time.deltaTime;
                        if (deck_held_time_ > DECK_HOLD_THRESHOLD)
                        {
                            Grab(grabbable_script.id_, id_);
                        }
                        break;
                    }
                    if (!hit_obj.GetComponent <DiceScript>() && !Input.GetMouseButtonDown(0))
                    {
                        continue;
                    }
                    if (hit_obj.GetComponent <DeckScript>())
                    {
                        deck_held_time_ = Time.deltaTime;
                        deck_held_id_   = grabbable_script.id_;
                        break;
                    }
                    Grab(grabbable_script.id_, id_);
                }
                if (hit_deck_id != deck_held_id_ && deck_held_time_ > 0.0f)
                {
                    if (!Network.isServer)
                    {
                        networkView.RPC("TellObjectManagerAboutCardPeel", RPCMode.Server, deck_held_id_, id_);
                    }
                    else
                    {
                        TellObjectManagerAboutCardPeel(deck_held_id_, id_);
                    }
                    deck_held_time_ = 0.0f;
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                if (!Network.isServer)
                {
                    networkView.RPC("TellObjectManagerAboutMouseRelease", RPCMode.Server, id_);
                }
                else
                {
                    TellObjectManagerAboutMouseRelease(id_);
                }
                deck_held_time_ = 0.0f;
            }
            rigidbody.position = pos;
            transform.position = pos;
        }
    }
示例#6
0
    void DrawGameGUI()
    {
        if (chat_shown_)
        {
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
            {
                if (chat_.Length > 0)
                {
                    SendChatMessage(chat_);
                }
                chat_       = "";
                chat_shown_ = false;
                GUI.FocusControl("TheLabel");
                Event.current.Use();
            }
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                chat_       = "";
                chat_shown_ = false;
                GUI.FocusControl("TheLabel");
                Event.current.Use();
            }
        }
        else
        {
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
            {
                chat_shown_ = true;
                //ConsoleScript.Log ("Showing chat");
                Event.current.Use();
            }
        }

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Exit Game"))
        {
            Network.Disconnect();
            Application.LoadLevel(Application.loadedLevel);
        }
        GUILayout.EndHorizontal();

        /*GUILayout.BeginHorizontal();
         * if(GUILayout.Button("Copy Join URL To Clipboard")){
         *      RequestPageURLForCopyGameJoin();
         * }
         * GUILayout.EndHorizontal();*/
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Restart Game"))
        {
            ObjectManagerScript.Instance().RecoverDice();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Label(game_name_);
        GUILayout.EndHorizontal();
        Dictionary <int, PlayerInfo> player_info_list = PlayerListScript.Instance().GetPlayerInfoList();

        foreach (var pair in player_info_list)
        {
            GUI.contentColor = pair.Value.color_;
            GUILayout.BeginHorizontal();
            GUILayout.Label(pair.Key + ": " + pair.Value.name_);
            GUILayout.EndHorizontal();
            GUI.contentColor = Color.white;
        }


        GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, 300));
        if (!help_shown_)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press '?' for help", help_gui_skin.label);
            GUILayout.EndHorizontal();
        }
        else
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press '?' to close help", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press 'Z' to zoom in", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press 'WASD' to move while zoomed", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press 'Q' or 'E' to rotate cards", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press 'R' to rotate a card to be readable", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press 'F' to flip cards", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press 'T' to tap tokens", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press 'RETURN' to chat", help_gui_skin.label);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Press '1-5' to play different songs", help_gui_skin.label);
            GUILayout.EndHorizontal();
        }
        GUILayout.EndArea();

        if (chat_shown_)
        {
            GUILayout.BeginArea(new Rect(Screen.width * 0.5f - 200, Screen.height - 30, 400, 200));
            GUILayout.BeginHorizontal();
            GUI.SetNextControlName("TheLabel");
            GUILayout.Label("Chat:");
            GUI.SetNextControlName("ChatField");
            chat_ = GUILayout.TextField(chat_, GUILayout.MinWidth(350));
            if (chat_.Length > 90)
            {
                chat_ = chat_.Substring(0, 90);
            }
            GUI.FocusControl("ChatField");
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
        if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Slash)
        {
            help_shown_ = !help_shown_;
            Event.current.Use();
        }
    }
示例#7
0
 void ReceiveChatMessage(int id, string msg)
 {
     ConsoleScript.Log(PlayerListScript.Instance().GetPlayerInfoList()[id].name_ + ": " + msg);
     PlayRandomSound(chat_sounds, 0.6f);
 }