Exemple #1
0
    public bool is_test_scene   = false;                                        // "TestItemScene"?


    // ================================================================ //
    // MonoBehaviour에서 상속.

    void    Start()
    {
        // "TestItemScene"이면 저장.
        if (this.is_test_scene)
        {
            this.saveLevel();
        }

        string map_owner_name = GlobalParam.get().account_name;

        if (!GlobalParam.get().is_in_my_home)
        {
            map_owner_name = GameRoot.getPartnerAcountName(map_owner_name);
        }

        string active_map_name   = MapCreator.getHomeMapName(map_owner_name);
        string inactive_map_name = MapCreator.getHomeMapName(GameRoot.getPartnerAcountName(map_owner_name));

        this.current_map_name = active_map_name;

        GameObject.Find(active_map_name).SetActive(true);
        GameObject.Find(inactive_map_name).SetActive(false);
    }
Exemple #2
0
    void    Update()
    {
        this.scene_timer += Time.deltaTime;
        this.disp_timer  -= Time.deltaTime;

        // ---------------------------------------------------------------- //
        // 다음 상태로 이동할지 체크합니다.

        switch (this.step.do_transition())
        {
        case STEP.GAME:
        {
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // 상태가 전환될 때 초기화.

        while (this.step.get_next() != STEP.NONE)
        {
            switch (this.step.do_initialize())
            {
            case STEP.CHARACTER_CHANGE:
            {
                GlobalParam.get().account_name     = this.account_name_net;
                GlobalParam.get().skip_enter_event = true;

                Application.LoadLevel("GameScene 1");
            }
            break;

            case STEP.GAME:
            {
                this.account_name_local = GlobalParam.get().account_name;
                this.account_name_net   = GameRoot.getPartnerAcountName(this.account_name_local);

                if (this.owner == this.account_name_local)
                {
                    this.is_host = true;
                }
                else
                {
                    // 다른 플레이어의 마을에 갔을 때.
                    this.is_host = false;
                }

                // 플레이어를 만듭니다.
                this.local_player = CharacterRoot.get().createPlayerAsLocal(this.account_name_local);

                this.local_player.cmdSetPosition(Vector3.zero);

                if (GlobalParam.get().is_in_my_home == GlobalParam.get().is_remote_in_my_home)
                {
                    this.net_player = CharacterRoot.get().createPlayerAsNet(this.account_name_net);

                    this.net_player.cmdSetPosition(Vector3.left * 1.0f);
                }

                // 레벨 데이터(level_data.txt)를 읽고 NPC/아이템을 배치합니다.
                MapCreator.get().loadLevel(this.account_name_local, this.account_name_net, !this.is_host);

                SoundManager.get().playBGM(Sound.ID.TFT_BGM01);

                //

                if (!GlobalParam.get().skip_enter_event)
                {
                    EnterEvent enter_event = EventRoot.get().startEvent <EnterEvent>();

                    if (enter_event != null)
                    {
                        enter_event.setPrincipal(this.local_player.behavior as chrBehaviorPlayer);
                        enter_event.setIsLocalPlayer(true);
                    }
                }

                foreach (ItemManager.ItemState istate in GlobalParam.get().item_table.Values)
                {
                    if (istate.state == ItemController.State.Picked)
                    {
                        // 이미 아이템을 획득했다면 가져갈 수 있게 합니다.
                        ItemManager.get().finishGrowingItem(istate.item_id);
                        chrController controll = CharacterRoot.getInstance().findPlayer(istate.owner);
                        if (controll != null)
                        {
                            QueryItemPick query = controll.cmdItemQueryPick(istate.item_id, false, true);
                            if (query != null)
                            {
                                query.is_anon = true;
                                query.set_done(true);
                                query.set_success(true);
                            }
                        }
                    }
                }
            }
            break;

            // 다른 플레이어가 찾아왔습니다.
            case STEP.WELCOME:
            {
                if (this.net_player == null)
                {
                    EnterEvent enter_event = EventRoot.get().startEvent <EnterEvent>();

                    if (enter_event != null)
                    {
                        this.net_player = CharacterRoot.getInstance().createPlayerAsNet(this.account_name_net);

                        this.net_player.cmdSetPosition(Vector3.left);

                        enter_event.setPrincipal(this.net_player.behavior as chrBehaviorPlayer);
                        enter_event.setIsLocalPlayer(false);
                    }
                }
            }
            break;

            // 다른 플레이어가 돌아갑니다.
            case STEP.BYEBYE:
            {
                if (this.net_player != null)
                {
                    LeaveEvent leave_event = EventRoot.get().startEvent <LeaveEvent>();

                    if (leave_event != null)
                    {
                        leave_event.setPrincipal(this.net_player.behavior as chrBehaviorPlayer);
                        leave_event.setIsLocalPlayer(false);
                    }
                }
            }
            break;

            case STEP.VISIT:
            {
                GlobalParam.get().is_in_my_home = false;
                Application.LoadLevel("GameScene 1");
            }
            break;

            case STEP.GO_HOME:
            {
                // 자기 마을로 돌아옵니다.
                GlobalParam.get().is_in_my_home = true;
                Application.LoadLevel("GameScene 1");
            }
            break;

            case STEP.TO_TITLE:
            {
                Application.LoadLevel("TitleScene");
            }
            break;
            }
        }

        // ---------------------------------------------------------------- //
        // 각 상태에서의 실행 처리.

        switch (this.step.do_execution(Time.deltaTime))
        {
        case STEP.GAME:
        {
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // 통신에 의한 이벤트 처리.

        // Network 클래스의 컴포넌트 획득.
        GameObject go      = GameObject.Find("Network");
        Network    network = go.GetComponent <Network>();

        if (network != null)
        {
            if (network.IsCommunicating() == true)
            {
                if (request_connet_event)
                {
                    // 접속 이벤트를 발동합니다.
                    GlobalParam.get().is_connected = true;
                    request_connet_event = false;
                }
                else if (GlobalParam.get().is_connected == false)
                {
                    // 접속했습니다.
                    Debug.Log("Guest connected.");
                    request_connet_event = true;
                    disp_timer           = 5.0f;
                }
            }
        }

        // 접속 종료 이벤트를 발동합니다.
        if (request_disconnet_event)
        {
            GlobalParam.get().is_disconnected = true;
            request_disconnet_event = false;
            // 접속 종료 시 이벤트.
            disconnect_event();
        }

        // ---------------------------------------------------------------- //

        if (Input.GetKeyDown(KeyCode.Z))
        {
            dbwin.console().print("로그 테스트 " + this.log_test_count);
            this.log_test_count++;
        }
    }