예제 #1
0
    public override void    execute()
    {
        CameraControl camera = CameraControl.get();

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

        switch (this.step.do_transition())
        {
        // 이벤트 시작.
        case STEP.START:
        {
            this.step.set_next(STEP.OPEN_DOOR);
            //camera.module.parallelMoveTo(this.get_locator_position("cam_loc_0"));

            Debug.Log("Name:" + this.player.controll.account_name);

            foreach (ItemManager.ItemState istate in GlobalParam.get().item_table.Values)
            {
                Debug.Log("Item:" + istate.item_id + " Own:" + istate.owner + " State:" + istate.state);

                if (istate.owner == this.player.controll.account_name &&
                    istate.state == ItemController.State.Picked)
                {
                    // 이미 아이템을 획득했다면 가지고 갈 수 있게 합니다.
                    ItemManager.get().activeItme(istate.item_id, true);
                    ItemManager.get().finishGrowingItem(istate.item_id);
                    QueryItemPick query = this.player.controll.cmdItemQueryPick(istate.item_id, false, true);
                    if (query != null)
                    {
                        query.is_anon = true;
                        query.set_done(true);
                        query.set_success(true);
                    }
                    ItemManager.get().setVisible(istate.item_id, true);
                }
            }

            // 리모트에서 이사 중은 로컬도 이사합니다.
            do
            {
                MovingData moving = GlobalParam.get().remote_moving;
                if (!moving.moving)
                {
                    break;
                }

                chrController remote = CharacterRoot.get().findCharacter(moving.characterId);
                if (remote == null)
                {
                    break;
                }

                chrBehaviorNet remote_player = remote.behavior as chrBehaviorNet;
                if (remote_player == null)
                {
                    break;
                }

                chrBehaviorNPC_House house = CharacterRoot.getInstance().findCharacter <chrBehaviorNPC_House>(moving.houseId);
                if (house == null)
                {
                    break;
                }

                Debug.Log("House move event call:" + moving.characterId + ":" + moving.houseId);

                remote_player.beginHouseMove(house);

                // '이사중~' 말풍선 표시.
                house.startHouseMove();
            } while(false);
        }
        break;

        // 배추가 옆으로 움직이고 & 대야를 타고 플레이어가 등장.
        case STEP.OPEN_DOOR:
        {
            if (this.hakusai_fcurve.isDone() && this.tarai_fcurve.isDone())
            {
                this.step.set_next(STEP.GET_OFF_TARAI_0);
            }
        }
        break;

        // 대야에서 내립니다(기슭으로 점프).
        case STEP.GET_OFF_TARAI_0:
        {
            if (!this.player_jump.isMoving())
            {
                this.step.set_next(STEP.GET_OFF_TARAI_1);
            }
        }
        break;

        // 대야에서 내립니다(조금 걷기).
        case STEP.GET_OFF_TARAI_1:
        {
            if (!this.player_move.isMoving())
            {
                this.step.set_next(STEP.CLOSE_DOOR);
            }
        }
        break;


        // 배추가 돌아오고 & 대야가 밖으로 이동.
        case STEP.CLOSE_DOOR:
        {
            if (this.hakusai_fcurve.isDone() && this.tarai_fcurve.isDone())
            {
                this.step.set_next(STEP.END);
            }
        }
        break;

        case STEP.END:
        {
            camera.module.popPosture();

            this.step.set_next(STEP.IDLE);
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // 상태가 전환됐을 때의 초기화.

        while (this.step.get_next() != STEP.NONE)
        {
            dbwin.console().print(this.step.ToString());

            switch (this.step.do_initialize())
            {
            // 이벤트 시작.
            case STEP.START:
            {
                camera.module.pushPosture();

                this.player.beginOuterControll();
                this.player.controll.cmdSetPosition(this.tarai_leave_spline.curve.cvs.back().position);

                this.tarai_fune.transform.position = this.tarai_leave_spline.curve.cvs.back().position;

                if (!this.is_local_player)
                {
                    SoundManager.get().playSE(Sound.ID.SMN_JINGLE01);
                }
            }
            break;

            // 배추가 옆으로 이동하고 & 대야를 타고 플레이어가 등장.
            case STEP.OPEN_DOOR:
            {
                this.hakusai_set.setControl(true);
                this.hakusai_fcurve.setSlopeAngle(10.0f, 10.0f);
                this.hakusai_fcurve.setDuration(4.0f);
                this.hakusai_fcurve.start();
                this.hakusai_tracer.restart();

                this.tarai_fcurve.setSlopeAngle(60.0f, 5.0f);
                this.tarai_fcurve.setDuration(3.5f);
                this.tarai_fcurve.setDelay(0.5f);
                this.tarai_fcurve.start();
            }
            break;

            // 대야에서 내립니다(기슭으로 점프).
            case STEP.GET_OFF_TARAI_0:
            {
                Vector3 start = this.player.controll.getPosition();
                Vector3 goal  = this.get_locator_position("chr_loc_0");

                this.player_jump.start(start, goal, 1.0f);
            }
            break;

            // 대야에서 내립니다(조금 걷기).
            case STEP.GET_OFF_TARAI_1:
            {
                this.player_move.position.start = this.player.controll.getPosition();
                this.player_move.position.goal  = this.get_locator_position("chr_loc_1");
                this.player_move.startConstantVelocity(chrBehaviorLocal.MOVE_SPEED);
            }
            break;

            // 배추가 돌아오고 & 대야가 밖으로 이동.
            case STEP.CLOSE_DOOR:
            {
                this.hakusai_fcurve.setSlopeAngle(10.0f, 10.0f);
                this.hakusai_fcurve.setDuration(4.0f);
                this.hakusai_fcurve.setDelay(1.0f);
                this.hakusai_fcurve.start();
                this.hakusai_tracer.restart();
                this.hakusai_tracer.setCurrentByDistance(this.hakusai_tracer.curve.calcTotalDistance());

                this.tarai_tracer.attach(this.tarai_enter_spline.curve);
                this.tarai_tracer.restart();
                this.tarai_fcurve.reset();
                this.tarai_fcurve.setSlopeAngle(10.0f, 60.0f);
                this.tarai_fcurve.setDuration(2.5f);
                this.tarai_fcurve.start();

                this.ripple_effect.is_created = false;
            }
            break;

            case STEP.END:
            {
                // 이벤트 종료.
                this.hakusai_set.reset();
                this.hakusai_set.setControl(false);

                this.player.endOuterControll();

                this.player = null;
            }
            break;
            }
        }

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

        switch (this.step.do_execution(Time.deltaTime))
        {
        // 배추가 옆으로 움직인다 & 대야를 타고 플레이어가 등장..
        case STEP.OPEN_DOOR:
        {
            this.hakusai_fcurve.execute(Time.deltaTime);
            this.hakusai_tracer.proceedToDistance(this.hakusai_tracer.curve.calcTotalDistance() * this.hakusai_fcurve.getValue());
            this.hakusai_set.setPosition(this.hakusai_tracer.cv.position);

            this.tarai_fcurve.execute(Time.deltaTime);
            this.tarai_tracer.proceedToDistance(this.tarai_tracer.curve.calcTotalDistance() * (1.0f - this.tarai_fcurve.getValue()));

            SimpleSpline.ControlVertex cv = this.tarai_tracer.getCurrent();

            this.tarai_fune.setPosition(cv.position);
            this.player.controll.cmdSetPosition(cv.position);
            this.player.controll.cmdSmoothHeadingTo(cv.position - cv.tangent.Y(0.0f));

            if (this.tarai_fcurve.isTriggerDone())
            {
                this.ripple_effect.is_created = false;
            }
        }
        break;

        // 대야에서 내립니다(기슭을 향해 점프).
        case STEP.GET_OFF_TARAI_0:
        {
            this.player_jump.execute(Time.deltaTime);
            this.player.controll.cmdSetPosition(this.player_jump.position);
            this.player.controll.cmdSmoothHeadingTo(this.player_jump.goal);
        }
        break;

        // 대야에서 내립니다(조금 걷는다).
        case STEP.GET_OFF_TARAI_1:
        {
            this.player_move.execute(Time.deltaTime);
            this.player.controll.cmdSetPosition(this.player_move.position.current);
            this.player.controll.cmdSmoothHeadingTo(this.player_move.position.goal);
            this.player.playWalkMotion();
        }
        break;

        // 배추가 돌아옵니다 & 대야가 밖으로 이동.
        case STEP.CLOSE_DOOR:
        {
            this.hakusai_fcurve.execute(Time.deltaTime);
            this.hakusai_tracer.proceedToDistance(this.hakusai_tracer.curve.calcTotalDistance() * (1.0f - this.hakusai_fcurve.getValue()));
            this.hakusai_set.setPosition(this.hakusai_tracer.getCurrent().position);

            this.tarai_fcurve.execute(Time.deltaTime);
            this.tarai_tracer.proceedToDistance(this.tarai_tracer.curve.calcTotalDistance() * (1.0f - this.tarai_fcurve.getValue()));
            this.tarai_fune.transform.position = this.tarai_tracer.getCurrent().position;
            this.player.stopWalkMotion();
        }
        break;
        }

        // 대야 뒤에 나오는 물결.
        if (!this.ripple_effect.is_created || Vector3.Distance(this.ripple_effect.last_position, this.tarai_fune.getPosition()) > 2.0f)
        {
            this.ripple_effect.is_created    = true;
            this.ripple_effect.last_position = this.tarai_fune.transform.position;

            EffectRoot.get().createRipple(this.ripple_effect.last_position);
        }

        // ---------------------------------------------------------------- //
    }
예제 #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++;
        }
    }