Beispiel #1
0
    // ---------------------------------------------------------------- //
    // 통신 처리 함수.

    //
    public void OnReceiveSyncGamePacket(PacketId id, byte[] data)
    {
        Debug.Log("Receive GameSyncPacket.[TitleControl]");

        SyncGamePacket packet = new SyncGamePacket(data);
        SyncGameData   sync   = packet.GetPacket();

        for (int i = 0; i < sync.itemNum; ++i)
        {
            string log = "[CLIENT] Sync item pickedup " +
                         "itemId:" + sync.items[i].itemId +
                         " state:" + sync.items[i].state +
                         " ownerId:" + sync.items[i].ownerId;
            Debug.Log(log);

            ItemManager.ItemState istate = new ItemManager.ItemState();

            // 아이템의 상태를 매니저에 등록.
            istate.item_id = sync.items[i].itemId;
            istate.state   = (ItemController.State)sync.items[i].state;
            istate.owner   = sync.items[i].ownerId;

            if (GlobalParam.get().item_table.ContainsKey(istate.item_id))
            {
                GlobalParam.get().item_table.Remove(istate.item_id);
            }
            GlobalParam.get().item_table.Add(istate.item_id, istate);
        }

        isReceiveSyncGameData = true;
    }
Beispiel #2
0
 public void ExplodeOffPlanet(Planet planet)
 {
     itemState  = ItemManager.ItemState.NoCollide;
     homePlanet = null;
     planet.RemoveItemFromPlanet(this);
     transform.SetParent(null);
     rigidbody2d.bodyType = RigidbodyType2D.Dynamic;
 }
Beispiel #3
0
 public void GrabOffPlanet(Planet planet)
 {
     itemState  = ItemManager.ItemState.Hooked;
     homePlanet = null;
     planet.RemoveItemFromPlanet(this);
     transform.SetParent(null);
     StartCoroutine(ReenableCollisions());
 }
Beispiel #4
0
 private void Stick(Planet planet)
 {
     homePlanet = planet;
     planet.AcceptItem(this);
     transform.SetParent(planet.transform);
     rigidbody2d.bodyType = RigidbodyType2D.Static;
     itemState            = ItemManager.ItemState.Stuck;
 }
Beispiel #5
0
    void FixedUpdate()
    {
        if (itemState == ItemManager.ItemState.NoCollide)
        {
            if (noCollideFrameCounter >= noCollideFrames)
            {
                itemState             = ItemManager.ItemState.Idle;
                noCollideFrameCounter = 0;
            }
            else
            {
                noCollideFrameCounter++;
            }
        }

        // only rotate is flying through space
        if (rigidbody2d.bodyType != RigidbodyType2D.Static)
        {
            transform.Rotate(0, 0, Time.deltaTime * rotationSpeed);
        }

        foreach (GameObject planet in planets)
        {
            float  dist = Vector3.Distance(planet.transform.position, transform.position);
            Planet p    = planet.GetComponent <Planet>();
            if (dist <= p.MaxGravDist)
            {
                Vector3 v         = planet.transform.position - transform.position;
                Vector2 gravForce = v.normalized * (1.0f - (dist / p.MaxGravDist)) * (p.MaxGravity * mass);
                rigidbody2d.AddForce(gravForce);
            }
        }

        GameObject[] moons = GameObject.FindGameObjectsWithTag("Moon");
        foreach (GameObject moon in moons)
        {
            float dist = Vector3.Distance(moon.transform.position, transform.position);
            Moon  m    = moon.GetComponentInChildren <Moon>();
            if (dist <= m.maxGravDist)
            {
                Vector3 v         = moon.transform.position - transform.position;
                Vector2 gravForce = v.normalized * (1.0f - (dist / m.maxGravDist)) * (m.maxGravity * mass);
                rigidbody2d.AddForce(gravForce);
            }
        }
    }
Beispiel #6
0
    // ---------------------------------------------------------------- //
    // 레벨 데이터를 로드하여 캐릭터/아이템을 배치합니다.
    public void     loadLevel(string local_account, string net_account, bool create_npc)
    {
        this.level_texts = this.level_data.text;

        string[] lines = this.level_texts.Split('\n');

        foreach (var line in lines)
        {
            if (line == "")
            {
                continue;
            }

            string[] words = line.Split();

            if (words.Length < 3)
            {
                continue;
            }

            string name = words[0];

            if (name.StartsWith("ChrModel_"))
            {
                // 캐릭터.
                this.create_character(words, local_account, net_account, create_npc);
            }
            if (name.StartsWith("ItemModel_"))
            {
                bool active = true;

                ItemManager.ItemState istate = ItemManager.get().FindItemState(name);

                // 맵에 관련이 없는 아이템의 생성 제어.
                if (current_map_name == "Field" && name == "ItemModel_Yuzu")
                {
                    if (istate.state != ItemController.State.Picked)
                    {
                        // 아무도 소유하지 않고 맵에 연결되지 않은 아이템이므로 생성하지 않습니다.
//						continue;
                        active = false;
                    }
                    else
                    {
                        if (istate.owner == net_account && GameRoot.get().net_player == null)
                        {
                            // 소유하고 있는 원격 캐릭터가 이 필드에는 없습니다.
//							continue;
                            active = false;
                        }
                    }
                }
                else if (current_map_name == "Field_v2" && name == "ItemModel_Negi")
                {
                    if (istate.state != ItemController.State.Picked)
                    {
                        // 아무도 소유하지 않고 맵에 연결된 아이템이 아니므로 생성하지 않습니다.
                        //continue;
                        active = false;
                    }
                    else
                    {
                        if (istate.owner == net_account && GameRoot.get().net_player == null)
                        {
                            // 소유하고 있는 리모트 캐릭터가 이 필드에는 없습니다.
                            //continue;
                            active = false;
                        }
                    }
                }

                // 맵에 연결된 아이템을 취득했을때의 제어.
                if (current_map_name == "Field" && name == "ItemModel_Negi" ||
                    current_map_name == "Field_v2" && name == "ItemModel_Yuzu")
                {
                    // 맵에 연결된 아이템이라도 가지고 나갔을 땐 생성하지 생성하지 않습니다.
                    if (istate.state == ItemController.State.Picked &&
                        istate.owner == net_account &&
                        GlobalParam.get().is_in_my_home != GlobalParam.get().is_remote_in_my_home)
                    {
                        // 다른 사람이 소유하고 있고 다른 맵에 있을 때에 생성하지 않습니다.
                        //continue;
                        active = false;
                    }
                }

                // 아이템.
                string item_name = this.create_item(words, local_account, active);

                ItemController new_item = ItemManager.get().findItem(item_name);

                if (new_item != null)
                {
                    bool   is_exportable = false;
                    string production    = "";

                    switch (new_item.name)
                    {
                    case "Negi":
                    {
                        is_exportable = true;
                        production    = "Field";
                    }
                    break;

                    case "Yuzu":
                    {
                        is_exportable = true;
                        production    = "Field_v2";
                    }
                    break;
                    }

                    new_item.setExportable(is_exportable);
                    new_item.setProduction(production);
                }
            }
        }
    }
Beispiel #7
0
	// ---------------------------------------------------------------- //
	// 통신 처리 함수.

	// 
	public void OnReceiveSyncGamePacket(PacketId id, byte[] data)
	{
		Debug.Log("Receive GameSyncPacket.[TitleControl]");
		
		SyncGamePacket packet = new SyncGamePacket(data);
		SyncGameData sync = packet.GetPacket();
		
		for (int i = 0; i < sync.itemNum; ++i) {
			string log = "[CLIENT] Sync item pickedup " +
				"itemId:" + sync.items[i].itemId +
					" state:" + sync.items[i].state + 
					" ownerId:" + sync.items[i].ownerId;
			Debug.Log(log);
			
			ItemManager.ItemState istate = new ItemManager.ItemState();
			
			// 아이템의 상태를 매니저에 등록.
			istate.item_id = sync.items[i].itemId;
			istate.state = (ItemController.State) sync.items[i].state;
			istate.owner = sync.items[i].ownerId;
			
			if (GlobalParam.get().item_table.ContainsKey(istate.item_id)) {
				GlobalParam.get().item_table.Remove(istate.item_id);
			}
			GlobalParam.get().item_table.Add(istate.item_id, istate);
		}

		isReceiveSyncGameData = true;
	}
Beispiel #8
0
    // 매 프레임 호출됩니다.
    public override void    execute()
    {
        float germ_time  = 5.0f;
        float glass_time = 5.0f;

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

        switch (this.step.do_transition())
        {
        case STEP.GERM:
        {
            if (this.step.get_time() > germ_time)
            {
                this.step.set_next(STEP.GLASS);
            }
        }
        break;

        case STEP.GLASS:
        {
            if (this.step.get_time() > glass_time)
            {
                this.step.set_next(STEP.APPEAR);
            }
        }
        break;

        case STEP.APPEAR:
        {
            if (this.ip_jump.isDone())
            {
                this.step.set_next(STEP.FRUIT);
            }
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // 상태가 전환되면 초기화합니다.

        while (this.step.get_next() != STEP.NONE)
        {
            switch (this.step.do_initialize())
            {
            case STEP.GERM:
            {
                // 성장 중엔 주울 수 없습니다.
                this.controll.cmdSetPickable(false);

                this.germ.SetActive(true);
                this.glass.SetActive(false);
                this.fruit.SetActive(false);

                if (this.transform.parent.name == "Negi")
                {
                    ItemManager.ItemState state = ItemManager.get().FindItemState("Negi");

                    if (state.state != ItemController.State.Picked)
                    {
                        this.controll.cmdDispBalloon(0);
                    }
                }
            }
            break;

            case STEP.GLASS:
            {
                this.germ.SetActive(false);
                this.glass.SetActive(true);
                this.fruit.SetActive(false);
            }
            break;

            case STEP.APPEAR:
            {
                this.germ.SetActive(false);
                this.glass.SetActive(false);
                this.fruit.SetActive(true);

                Vector3 start = this.transform.position;
                Vector3 goal  = this.transform.position;

                this.ip_jump.start(start, goal, 1.0f);

                // 연기 효과.

                // 효과가 열매 모델에 묻히지 않게 카메라 쪽으로 밉니다.

                Vector3 smoke_position = this.transform.position + Vector3.up * 0.3f;

                GameObject main_camera = GameObject.FindGameObjectWithTag("MainCamera");

                Vector3 v = main_camera.transform.position - smoke_position;

                v.Normalize();
                v *= 1.0f;

                smoke_position += v;

                EffectRoot.getInstance().createSmoke01(smoke_position);
            }
            break;

            case STEP.FRUIT:
            {
                if (this.transform.parent.name == "Negi")
                {
                    ItemManager.ItemState state = ItemManager.get().FindItemState("Negi");

                    if (state.state != ItemController.State.Picked)
                    {
                        this.controll.cmdDispBalloon(1);
                    }
                }

                // 성장을 다 했으면 주울 수 있습니다
                this.controll.cmdSetPickable(true);
            }
            break;
            }
        }

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

        switch (this.step.do_execution(Time.deltaTime))
        {
        case STEP.APPEAR:
        {
            this.ip_jump.execute(Time.deltaTime);

            this.transform.position = this.ip_jump.position;
        }
        break;
        }

        // ---------------------------------------------------------------- //
    }