// 소유 중인 아이템을 버려도 되는가?. public QueryItemDrop queryDropItem(string owner_id, ItemController item, bool local) { QueryItemDrop query = null; do { // 자신의 것이 아닌 것은 주울 수 없습니다. if (item.picker != owner_id) { break; } query = new QueryItemDrop(item.id); this.queries.Add(query); } while(false); if (item != null && local) { // 아이템의 스테이트를 네트워크에 보냅니다. SendItemStateChanged(item.id, ItemController.State.Dropping, owner_id); } return(query); }
// 쿼리 아이템을 버려도 되나?. public QueryItemDrop cmdItemQueryDrop(bool local = true) { QueryItemDrop query = null; do { if (!this.item_carrier.isCarrying()) { break; } query = this.item_man.queryDropItem(this.account_name, this.item_carrier.item, local); if (query == null) { break; } this.queries.Add(query); } while(false); return(query); }
// ================================================================ // // 아이템 정보 패킷 취득 함수. public void OnReceiveItemPacket(int node, PacketId id, byte[] data) { ItemPacket packet = new ItemPacket(data); ItemData item = packet.GetPacket(); // 서버 상태와 동기화. ItemState istate = new ItemState(); istate.item_id = item.itemId; ItemController.State state = (ItemController.State)item.state; istate.state = (state == ItemController.State.Dropped)? ItemController.State.None : state; istate.owner = item.ownerId; if (GlobalParam.getInstance().item_table.ContainsKey(istate.item_id)) { GlobalParam.getInstance().item_table.Remove(istate.item_id); } GlobalParam.getInstance().item_table.Add(istate.item_id, istate); string log = "[CLIENT] Receive itempacket [" + "itemId:" + item.itemId + " state:" + state.ToString() + " ownerId:" + item.ownerId + "]"; Debug.Log(log); dbwin.console().print(log); if (state == ItemController.State.Picked) { Debug.Log("Receive item pick."); dbwin.console().print("Receive item pick."); // 응답이 있는 쿼리를 탐색. QueryItemPick query_pick = QueryManager.get().findQuery <QueryItemPick>(x => x.target == item.itemId); bool remote_pick = true; if (query_pick != null) { string account_name = PartyControl.get().getLocalPlayer().getAcountID(); if (item.ownerId == account_name) { Debug.Log("Receive item pick local:" + item.ownerId); dbwin.console().print("Receive item pick local:" + item.ownerId); item_query_done(query_pick, true); remote_pick = false; } else { Debug.Log("Receive item pick remote:" + item.ownerId); dbwin.console().print("Receive item pick remote:" + item.ownerId); item_query_done(query_pick, false); } } if (remote_pick == true) { Debug.Log("Remote pick item:" + item.ownerId); dbwin.console().print("Remote pick item:" + item.ownerId); // 리모트 캐릭터가 가지게 한다. chrController remote = CharacterRoot.getInstance().findPlayer(item.ownerId); if (remote) { // 아이템 획득 쿼리 발행. QueryItemPick query = remote.cmdItemQueryPick(item.itemId, false, true); if (query != null) { item_query_done(query, true); } } } // 아이템 획득 상태 변경. this.setItemState(item.itemId, ItemController.State.Picked, item.ownerId); } else if (state == ItemController.State.Dropped) { Debug.Log("Receive item drop."); // 응답이 있는 쿼리를 검색. QueryItemDrop query_drop = QueryManager.get().findQuery <QueryItemDrop>(x => x.target == item.itemId); bool remote_drop = true; if (query_drop != null) { // 요청에 대한 응답이 있다. string account_name = AccountManager.get().getAccountData(GlobalParam.get().global_account_id).avator_id; if (item.ownerId == account_name) { // 자신이 획득. Debug.Log("Receive item drop local:" + item.ownerId); item_query_done(query_drop, true); remote_drop = false; } else { // 상대가 획득. Debug.Log("Receive item pick remote:" + item.ownerId); item_query_done(query_drop, false); } } if (remote_drop == true) { // 리모트 캐릭터가 획득. chrController remote = CharacterRoot.getInstance().findPlayer(item.ownerId); if (remote) { // 아이템획득 쿼리 발행. Debug.Log("QuetyitemDrop:cmdItemQueryDrop"); remote.cmdItemDrop(item.itemId, false); } } } else { Debug.Log("Receive item error."); } }
// 아이템 정보 패킷 획득 함수. public void OnReceiveItemPacket(PacketId id, byte[] data) { ItemPacket packet = new ItemPacket(data); ItemData item = packet.GetPacket(); // 서버의 상태와 동기화합니다. ItemState istate = new ItemState(); istate.item_id = item.itemId; ItemController.State state = (ItemController.State)item.state; istate.state = (state == ItemController.State.Dropped)? ItemController.State.None : state; istate.owner = item.ownerId; if (GlobalParam.get().item_table.ContainsKey(item.itemId)) { GlobalParam.get().item_table.Remove(istate.item_id); } GlobalParam.get().item_table.Add(istate.item_id, istate); string log = "[CLIENT] Receive itempacket. " + "itemId:" + item.itemId + " state:" + state.ToString() + " ownerId:" + item.ownerId; Debug.Log(log); if (state == ItemController.State.Picked) { Debug.Log("Receive item pick."); // 응답이 있는 쿼리를 검색. QueryItemPick query_pick = null; foreach (var query in this.queries) { QueryItemPick pick = query as QueryItemPick; if (pick != null && pick.target == item.itemId) { query_pick = pick; break; } } bool remote_pick = true; if (query_pick != null) { if (item.ownerId == GlobalParam.get().account_name) { Debug.Log("Receive item pick local:" + item.ownerId); item_query_done(query_pick, true); remote_pick = false; } else { Debug.Log("Receive item pick remote:" + item.ownerId); item_query_done(query_pick, false); } } if (remote_pick == true) { // 리모트 캐릭터가 취득하게 합니다. chrController remote = CharacterRoot.getInstance().findPlayer(item.ownerId); if (remote) { // 아이템 획득 쿼리 발행. QueryItemPick query = remote.cmdItemQueryPick(item.itemId, false, true); if (query != null) { item_query_done(query, true); } } } } else if (state == ItemController.State.Dropped) { Debug.Log("Receive item drop."); // 응답이 있는 쿼리를 검색. QueryItemDrop query_drop = null; foreach (var query in this.queries) { QueryItemDrop drop = query as QueryItemDrop; if (drop != null && drop.target == item.itemId) { query_drop = drop; break; } } bool remote_drop = true; if (query_drop != null) { // 요청에 대한 응답이 있을 때. if (item.ownerId == GlobalParam.get().account_name) { // 자신이 획득. Debug.Log("Receive item drop local:" + item.ownerId); item_query_done(query_drop, true); remote_drop = false; } else { // 상대가 획득. Debug.Log("Receive item pick remote:" + item.ownerId); item_query_done(query_drop, false); } } if (remote_drop == true) { // 리모트 캐릭터가 회득하게 합니다. chrController remote = CharacterRoot.getInstance().findPlayer(item.ownerId); if (remote) { // 아이템 획득 쿼리 발행. Debug.Log("QuetyitemDrop:cmdItemQueryDrop"); QueryItemDrop query = remote.cmdItemQueryDrop(false); if (query != null) { query.is_drop_done = true; item_query_done(query, true); } } } } else { Debug.Log("Receive item error."); } }
// ================================================================ // // 조정을 마친 쿼리 실행. protected void execute_queries() { foreach (QueryBase query in this.controll.queries) { if (!query.isDone()) { continue; } switch (query.getType()) { case "item.pick": { QueryItemPick query_pick = query as QueryItemPick; if (query.isSuccess()) { // 아이템을 가지고 있으면 버린다. if (this.controll.item_carrier.isCarrying()) { Debug.Log("Pick:" + query_pick.target + " Carry:" + this.controll.item_carrier.item.id); if (query_pick.target != this.controll.item_carrier.item.id) { // 상대방 플레이어에게 드롭한 사실을 알려줘야만 하므로 쿼리를 만든다. // 동기화할 필요는 없으므로 드롭은 바로 실행한다. Debug.Log("behavior:cmdItemQueryDrop"); QueryItemDrop query_drop = this.controll.cmdItemQueryDrop(); query_drop.is_drop_done = true; this.controll.cmdItemDrop(this.controll.account_name); } } this.controll.cmdItemPick(query_pick,this.controll.account_name,query_pick.target); if (!query_pick.is_anon) { SoundManager.get().playSE(Sound.ID.TFT_SE01); } } query.set_expired(true); } break; case "item.drop": { if (query.isSuccess()) { if ((query as QueryItemDrop).is_drop_done) { // 이미 드롭 완료. Debug.Log("[CLIENT CHAR] Item already dropped."); } else { Debug.Log("[CLIENT CHAR] Item dropped."); this.controll.cmdItemDrop(this.controll.account_name); } } query.set_expired(true); } break; case "house-move.start": { do { if (!query.isSuccess()) { break; } QueryHouseMoveStart query_start = query as QueryHouseMoveStart; chrBehaviorNPC_House house = CharacterRoot.get().findCharacter <chrBehaviorNPC_House>(query_start.target); if (house == null) { break; } var start_event = EventRoot.get().startEvent <HouseMoveStartEvent>(); start_event.setPrincipal(this); start_event.setHouse(house); } while(false); query.set_expired(true); } break; case "house-move.end": { do { if (!query.isSuccess()) { break; } chrBehaviorNPC_House house = this.step_house_move.house; var end_event = EventRoot.get().startEvent <HouseMoveEndEvent>(); end_event.setPrincipal(this); end_event.setHouse(house); } while(false); query.set_expired(true); } break; case "talk": { if (query.isSuccess()) { QueryTalk query_talk = query as QueryTalk; this.controll.cmdDispBalloon(query_talk.words); } query.set_expired(true); } break; } break; } }
// 소유 중인 아이템을 버려도 되는가?. public QueryItemDrop queryDropItem(string owner_id, ItemController item, bool local) { QueryItemDrop query = null; do { // 자신의 것이 아닌 것은 주울 수 없습니다. if(item.picker != owner_id) { break; } query = new QueryItemDrop(item.id); this.queries.Add(query); } while(false); if(item != null && local) { // 아이템의 스테이트를 네트워크에 보냅니다. SendItemStateChanged(item.id, ItemController.State.Dropping, owner_id); } return(query); }
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")); // 맵에 연관되지 않은 아이템은 가지고 돌아감. bool isPickingup = false; string current_map = MapCreator.get().getCurrentMapName(); ItemController itemYuzu = ItemManager.get().findItem("Yuzu"); if (itemYuzu != null && itemYuzu.isActive()) { if (current_map != itemYuzu.getProduction()) { // 가지고 돌아기는 아이템이 있었다. this.player.controll.cmdItemQueryPick(itemYuzu.name, true, true); isPickingup = true; } } ItemController itemNegi = ItemManager.get().findItem("Negi"); if (itemNegi != null && itemNegi.isActive()) { if (current_map != itemNegi.getProduction()) { // 가지고 돌아가는 아이템이 있었다. this.player.controll.cmdItemQueryPick(itemNegi.name, true, true); isPickingup = true; } } if (this.player.controll.item_carrier.isCarrying() && isPickingup == false) { ItemController item = this.player.controll.item_carrier.getItem(); if (item.isExportable() == false) { // 가지고 나갈 수 없는 것은 두고 갑니다. QueryItemDrop query_drop = this.player.controll.cmdItemQueryDrop(); query_drop.is_drop_done = true; this.player.controll.cmdItemDrop(this.player.controll.account_name); } } } break; // 배추가 옆으로 움직이고 & 대야가 등장. case STEP.OPEN_DOOR: { if (this.hakusai_fcurve.isDone() && this.tarai_fcurve.isDone()) { this.step.set_next(STEP.RIDE_TARAI_0); } } break; // 대야를 탑니다(기슭까지 걷는다). case STEP.RIDE_TARAI_0: { if (!this.player_move.isMoving()) { this.step.set_next(STEP.RIDE_TARAI_1); } } break; // 대야를 탑니다(대야를 향해 점프). case STEP.RIDE_TARAI_1: { if (!this.player_jump.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.tarai_fune.transform.position = this.tarai_enter_spline.curve.cvs.front().position; } 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, 10.0f); this.tarai_fcurve.setDuration(2.0f); this.tarai_fcurve.setDelay(2.0f); this.tarai_fcurve.start(); } break; // 대야를 탑니다(기슭까지 걷는다). case STEP.RIDE_TARAI_0: { this.player_move.position.start = this.player.controll.getPosition(); this.player_move.position.goal = this.get_locator_position("chr_loc_0"); this.player_move.startConstantVelocity(chrBehaviorLocal.MOVE_SPEED); } break; // 대야를 탑니다(대야를 향해서 점프). case STEP.RIDE_TARAI_1: { Vector3 start = this.player.controll.getPosition(); Vector3 goal = this.tarai_enter_spline.curve.cvs.back().position; this.player_jump.start(start, goal, 1.0f); } break; // 배추가 돌아오고 & 대야가 밖을 향해 이동. case STEP.CLOSE_DOOR: { this.hakusai_fcurve.setSlopeAngle(10.0f, 10.0f); this.hakusai_fcurve.setDuration(4.0f); this.hakusai_fcurve.start(); this.hakusai_tracer.restart(); this.hakusai_tracer.setCurrentByDistance(this.hakusai_tracer.curve.calcTotalDistance()); this.tarai_tracer.attach(this.tarai_leave_spline.curve); this.tarai_tracer.restart(); this.tarai_fcurve.reset(); this.tarai_fcurve.setSlopeAngle(20.0f, 60.0f); this.tarai_fcurve.setDuration(2.0f); this.tarai_fcurve.start(); } break; case STEP.END: { // 이벤트 종료. this.hakusai_set.reset(); this.hakusai_set.setControl(false); if (this.is_local_player) { if (this.is_map_change) { GlobalParam.get().skip_enter_event = false; GlobalParam.get().fadein_start = false; if (GlobalParam.get().is_in_my_home) { GameRoot.get().step.set_next(GameRoot.STEP.VISIT); } else { GameRoot.get().step.set_next(GameRoot.STEP.GO_HOME); } // 정원 이동을 알림. if (GlobalParam.get().request_move_home) { Debug.Log("NotifyFieldMoving Leave END."); GameRoot.get().NotifyFieldMoving(); } } else { GlobalParam.get().is_in_my_home = !GlobalParam.get().is_in_my_home; this.player.controll.cmdSetPosition(this.initial_player_position); this.player.endOuterControll(); } } else { // 아이템을 비활성화하고 나서 드롭하지 않으면 재생합니다. ItemBehaviorFruit fruit = this.player.controll.getCarriedItem <ItemBehaviorFruit>(); if (fruit != null) { fruit.activeItem(false); } // 맵 이동이 없을 때 아이템을 가지고 돌아온 경우 아이템의 게임 오브젝트를. // 폐기하지 않게 하고자 아이템을 버립니다. this.player.controll.cmdItemDrop(this.player.name); CharacterRoot.get().deletaCharacter(this.player.controll); } 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.getCurrent().position); this.tarai_fcurve.execute(Time.deltaTime); this.tarai_tracer.proceedToDistance(this.tarai_tracer.curve.calcTotalDistance() * this.tarai_fcurve.getValue()); this.tarai_fune.setPosition(this.tarai_tracer.getCurrent().position); if (this.tarai_fcurve.isTriggerDone()) { this.ripple_effect.is_created = false; } } break; // 대야를 탑니다(기슭까지 걷는다). case STEP.RIDE_TARAI_0: { 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.RIDE_TARAI_1: { this.player_jump.execute(Time.deltaTime); this.player.controll.cmdSetPosition(this.player_jump.position); this.player.controll.cmdSmoothHeadingTo(this.player_jump.goal); this.player.stopWalkMotion(); if (this.player_jump.is_trigger_bounce && this.player_jump.bounce_count == 1) { this.ripple_effect.is_created = false; } } 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.cv.position); this.tarai_fcurve.execute(Time.deltaTime); this.tarai_tracer.proceedToDistance(this.tarai_tracer.curve.calcTotalDistance() * 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)); 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); } // ---------------------------------------------------------------- // }
// ================================================================ // // ?꾩씠???뺣낫 ?⑦궥 痍⑤뱷 ?⑥닔. public void OnReceiveItemPacket(int node, PacketId id, byte[] data) { ItemPacket packet = new ItemPacket(data); ItemData item = packet.GetPacket(); // ?쒕쾭 ?곹깭? ?숆린?? ItemState istate = new ItemState(); istate.item_id = item.itemId; ItemController.State state = (ItemController.State)item.state; istate.state = (state == ItemController.State.Dropped)? ItemController.State.None : state; istate.owner = item.ownerId; if (GlobalParam.getInstance().item_table.ContainsKey(istate.item_id)) { GlobalParam.getInstance().item_table.Remove(istate.item_id); } GlobalParam.getInstance().item_table.Add(istate.item_id, istate); string log = "[CLIENT] Receive itempacket [" + "itemId:" + item.itemId + " state:" + state.ToString() + " ownerId:" + item.ownerId + "]"; Debug.Log(log); dbwin.console().print(log); if (state == ItemController.State.Picked) { Debug.Log("Receive item pick."); dbwin.console().print("Receive item pick."); // ?묐떟???덈뒗 荑쇰━瑜??먯깋. QueryItemPick query_pick = QueryManager.get().findQuery <QueryItemPick>(x => x.target == item.itemId); bool remote_pick = true; if (query_pick != null) { string account_name = PartyControl.get().getLocalPlayer().getAcountID(); if (item.ownerId == account_name) { Debug.Log("Receive item pick local:" + item.ownerId); dbwin.console().print("Receive item pick local:" + item.ownerId); item_query_done(query_pick, true); remote_pick = false; } else { Debug.Log("Receive item pick remote:" + item.ownerId); dbwin.console().print("Receive item pick remote:" + item.ownerId); item_query_done(query_pick, false); } } if (remote_pick == true) { Debug.Log("Remote pick item:" + item.ownerId); dbwin.console().print("Remote pick item:" + item.ownerId); // 由щえ??罹먮┃?곌? 媛吏寃??쒕떎. chrController remote = CharacterRoot.getInstance().findPlayer(item.ownerId); if (remote) { // ?꾩씠???띾뱷 荑쇰━ 諛쒗뻾. QueryItemPick query = remote.cmdItemQueryPick(item.itemId, false, true); if (query != null) { item_query_done(query, true); } } } // ?꾩씠???띾뱷 ?곹깭 蹂寃? this.setItemState(item.itemId, ItemController.State.Picked, item.ownerId); } else if (state == ItemController.State.Dropped) { Debug.Log("Receive item drop."); // ?묐떟???덈뒗 荑쇰━瑜?寃?? QueryItemDrop query_drop = QueryManager.get().findQuery <QueryItemDrop>(x => x.target == item.itemId); bool remote_drop = true; if (query_drop != null) { // ?붿껌??????묐떟???덈떎. string account_name = AccountManager.get().getAccountData(GlobalParam.get().global_account_id).avator_id; if (item.ownerId == account_name) { // ?먯떊???띾뱷. Debug.Log("Receive item drop local:" + item.ownerId); item_query_done(query_drop, true); remote_drop = false; } else { // ?곷?媛 ?띾뱷. Debug.Log("Receive item pick remote:" + item.ownerId); item_query_done(query_drop, false); } } if (remote_drop == true) { // 由щえ??罹먮┃?곌? ?띾뱷. chrController remote = CharacterRoot.getInstance().findPlayer(item.ownerId); if (remote) { // ?꾩씠?쒗쉷??荑쇰━ 諛쒗뻾. Debug.Log("QuetyitemDrop:cmdItemQueryDrop"); remote.cmdItemDrop(item.itemId, false); } } } else { Debug.Log("Receive item error."); } }