Exemplo n.º 1
0
    public override void OnAddBlock(RaycastHit hit)
    {
        Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);

        if (CanAddBlock(pos))
        {
            PlayerController.instance.PlayHandAnimation();

            byte type = NBTGeneratorManager.id2type[id];
            byte data = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage;

            if (hit.normal == Vector3.up || hit.normal == Vector3.down)
            {
                data |= 0b0000;
            }
            else if (hit.normal == Vector3.left || hit.normal == Vector3.right)
            {
                data |= 0b0100;
            }
            else if (hit.normal == Vector3.back || hit.normal == Vector3.forward)
            {
                data |= 0b1000;
            }
            NBTHelper.SetBlockData(pos, type, data);

            InventorySystem.DecrementCurrent();
            ItemSelectPanel.instance.RefreshUI();
        }
    }
Exemplo n.º 2
0
    public virtual void OnAddBlock(RaycastHit hit)
    {
        Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);

        if (CanAddBlock(pos))
        {
            PlayerController.instance.PlayHandAnimation();

            byte type = NBTGeneratorManager.id2type[id];
            byte data = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage;
            NBTHelper.SetBlockData(pos, type, data);

            InventorySystem.DecrementCurrent();
            ItemSelectPanel.instance.RefreshUI();
        }
    }
Exemplo n.º 3
0
    public override void OnAddBlock(RaycastHit hit)
    {
        Vector3Int pos        = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);
        byte       targetType = NBTHelper.GetBlockByte(pos);

        bool       canAdd   = false;
        byte       type     = NBTGeneratorManager.id2type[id];
        byte       data     = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage;
        Vector3Int finalPos = pos;

        if (targetType == 126)
        {
            canAdd = true;
            type   = 125;
        }

        if (WireFrameHelper.generator is NBTWoodenSlab &&
            (WireFrameHelper.data < 8 && hit.normal == Vector3.up) ||
            (WireFrameHelper.data >= 8 && hit.normal == Vector3.down))
        {
            canAdd   = true;
            type     = 125;
            finalPos = WireFrameHelper.pos;
        }

        if (targetType == 0 && CanAddBlock(pos))
        {
            canAdd = true;
            if (WireFrameHelper.hitPos.y - pos.y > 0)
            {
                data += 8;
            }
        }

        if (canAdd)
        {
            PlayerController.instance.PlayHandAnimation();

            NBTHelper.SetBlockData(finalPos, type, data);

            InventorySystem.DecrementCurrent();
            ItemSelectPanel.instance.RefreshUI();
        }
    }
Exemplo n.º 4
0
    // 0 = south
    // 1 = west
    // 2 = north
    // 3 = east
    public override void OnAddBlock(RaycastHit hit)
    {
        if (hit.normal == Vector3.down)
        {
            return;
        }

        Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);


        if (CanAddBlock(pos))
        {
            PlayerController.instance.PlayHandAnimation();

            byte type = NBTGeneratorManager.id2type[id];
            byte data = CalcBlockDirection(pos, 0, 1, 2, 3);
            NBTHelper.SetBlockData(pos, type, data);

            InventorySystem.DecrementCurrent();
            ItemSelectPanel.instance.RefreshUI();
        }
    }
Exemplo n.º 5
0
    public override void OnAddBlock(RaycastHit hit)
    {
        if (hit.normal.y != 0)
        {
            return;
        }

        Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);


        if (CanAddBlock(pos))
        {
            PlayerController.instance.PlayHandAnimation();

            byte type = NBTGeneratorManager.id2type[id];
            byte data = 0;

            if (hit.normal == Vector3.back)
            {
                data = 2;
            }
            else if (hit.normal == Vector3.forward)
            {
                data = 3;
            }
            else if (hit.normal == Vector3.left)
            {
                data = 4;
            }
            else if (hit.normal == Vector3.right)
            {
                data = 5;
            }
            NBTHelper.SetBlockData(pos, type, data);

            InventorySystem.DecrementCurrent();
            ItemSelectPanel.instance.RefreshUI();
        }
    }
Exemplo n.º 6
0
    void OnRightClick()
    {
        string id = InventorySystem.items[ItemSelectPanel.curIndex].id;

        if (WireFrameHelper.render && id != null)
        {
            Vector3Int pos = WireFrameHelper.pos;

            pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);

            if (CanAddBlock(pos))
            {
                handAnimator.SetTrigger("interactTrigger");

                byte type = NBTGeneratorManager.id2type[id];
                byte data = (byte)InventorySystem.items[ItemSelectPanel.curIndex].damage;
                NBTHelper.SetBlockData(pos, type, data);

                InventorySystem.DecrementCurrent();
                ItemSelectPanel.instance.RefreshUI();
            }
        }
    }
Exemplo n.º 7
0
    public override void OnAddBlock(RaycastHit hit)
    {
        Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);

        if (CanAddBlock(pos))
        {
            PlayerController.instance.PlayHandAnimation();

            byte type = NBTGeneratorManager.id2type[id];
            byte data = 0;

            Vector3 playerPos = PlayerController.instance.position;
            Vector2 dir       = (new Vector2(playerPos.x, playerPos.z) - new Vector2(pos.x, pos.z)).normalized;
            if (dir.x > 0)
            {
                if (dir.y > 0)
                {
                    if (dir.y > dir.x)
                    {
                        // positive z
                        data = 3;
                    }
                    else
                    {
                        // positive x
                        data = 1;
                    }
                }
                else
                {
                    if (-dir.y > dir.x)
                    {
                        // negative z
                        data = 2;
                    }
                    else
                    {
                        // positive x
                        data = 1;
                    }
                }
            }
            else
            {
                if (dir.y > 0)
                {
                    if (dir.y > -dir.x)
                    {
                        // positive z
                        data = 3;
                    }
                    else
                    {
                        // negative x
                        data = 0;
                    }
                }
                else
                {
                    if (-dir.y > -dir.x)
                    {
                        // negative z
                        data = 2;
                    }
                    else
                    {
                        // negative x
                        data = 0;
                    }
                }
            }

            if (hit.point.y - pos.y > 0)
            {
                data += 4;
            }

            NBTHelper.SetBlockData(pos, type, data);

            InventorySystem.DecrementCurrent();
            ItemSelectPanel.instance.RefreshUI();
        }
    }
Exemplo n.º 8
0
    void Update()
    {
        DrawWireFrame();
        PositionCorrection();

        if (acceptInput)
        {
            RotateView();

            if (Input.GetKey(KeyCode.Mouse0))
            {
                OnLeftMousePressed();
            }
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                OnLeftMouseDown();
            }
            if (Input.GetKeyUp(KeyCode.Mouse0))
            {
                OnLeftMouseUp();
            }
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                OnRightClick();
            }
            if (!isFlying)
            {
                if (Input.GetKeyDown(KeyCode.W))
                {
                    if (Time.time - lastW < timeInterval)
                    {
                        isRun = true;
                        vcamWide.SetActive(true);
                        lastW = 0;
                    }
                    else
                    {
                        lastW = Time.time;
                    }
                }
                if (Input.GetKeyUp(KeyCode.W))
                {
                    isRun = false;
                    vcamWide.SetActive(false);
                }
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Jump();
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                uint          slot = ItemSelectPanel.curIndex;
                InventoryItem item = InventorySystem.items[ItemSelectPanel.curIndex];
                if (item.id != null)
                {
                    NBTObject generator = NBTGeneratorManager.GetObjectGenerator(item.id);
                    if (generator != null)
                    {
                        short data = InventorySystem.items[slot].damage;
                        Item.CreatePlayerDropItem(generator, (byte)data);
                        InventorySystem.DecrementCurrent();
                        ItemSelectPanel.instance.RefreshUI();
                    }
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.F2))
        {
            Utilities.Capture();
        }
    }
Exemplo n.º 9
0
    void Update()
    {
        DrawWireFrame();
        PositionCorrection();

        if (acceptInput)
        {
            RotateView();

            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                OnLeftMouseDown();
            }
            if (Input.GetKeyUp(KeyCode.Mouse0))
            {
                OnLeftMouseUp();
            }
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                OnRightClick();
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Jump();
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                uint          slot = ItemSelectPanel.curIndex;
                InventoryItem item = InventorySystem.items[ItemSelectPanel.curIndex];
                if (item.id != null)
                {
                    NBTObject generator = NBTGeneratorManager.GetObjectGenerator(item.id);
                    if (generator != null)
                    {
                        short data = InventorySystem.items[slot].damage;
                        Item.CreatePlayerDropItem(generator, (byte)data);
                        InventorySystem.DecrementCurrent();
                        ItemSelectPanel.instance.RefreshUI();
                    }
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.F2))
        {
            Utilities.Capture();
        }

        if (needUpdate && Time.realtimeSinceStartup - lastUpdateTime > timeInterval)
        {
            needUpdate     = false;
            lastUpdateTime = Time.realtimeSinceStartup;
            CSHeroMoveReq req = new CSHeroMoveReq
            {
                Position = new CSVector3 {
                    x = transform.position.x, y = transform.position.y, z = transform.position.z
                },
                Rotation = new CSVector3 {
                    x = 0, y = transform.localEulerAngles.y, z = camera.transform.localEulerAngles.x
                }
            };
            NetworkManager.SendPkgToServer(ENUM_CMD.CS_HERO_MOVE_REQ, req);
        }
    }
Exemplo n.º 10
0
    public override void OnAddBlock(RaycastHit hit)
    {
        if (hit.normal != Vector3.up)
        {
            return;
        }

        Vector3Int pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);

        byte upperType = NBTHelper.GetBlockByte(pos + Vector3Int.up);
        byte lowerType = NBTHelper.GetBlockByte(pos);

        if (upperType != 0 || lowerType != 0)
        {
            return;
        }

        PlayerController.instance.PlayHandAnimation();

        byte type      = NBTGeneratorManager.id2type[id];
        byte upperData = 0b1000;
        byte lowerData = 0b0000;

        Vector3 playerPos = PlayerController.instance.position;
        Vector2 dir       = (new Vector2(playerPos.x, playerPos.z) - new Vector2(pos.x, pos.z)).normalized;

        Vector3 diff = WireFrameHelper.hitPos - pos;

        if (dir.x > 0)
        {
            if (dir.y > 0)
            {
                if (dir.y > dir.x)
                {
                    // positive z
                    lowerData = 3;
                    if (diff.x > 0)
                    {
                        upperData |= 0b0001;
                    }
                }
                else
                {
                    // positive x
                    lowerData = 2;
                    if (diff.z < 0)
                    {
                        upperData |= 0b0001;
                    }
                }
            }
            else
            {
                if (-dir.y > dir.x)
                {
                    // negative z
                    lowerData = 1;
                    if (diff.x < 0)
                    {
                        upperData |= 0b0001;
                    }
                }
                else
                {
                    // positive x
                    lowerData = 2;
                    if (diff.z < 0)
                    {
                        upperData |= 0b0001;
                    }
                }
            }
        }
        else
        {
            if (dir.y > 0)
            {
                if (dir.y > -dir.x)
                {
                    // positive z
                    lowerData = 3;
                    if (diff.x > 0)
                    {
                        upperData |= 0b0001;
                    }
                }
                else
                {
                    // negative x
                    lowerData = 0;
                    if (diff.z > 0)
                    {
                        upperData |= 0b0001;
                    }
                }
            }
            else
            {
                if (-dir.y > -dir.x)
                {
                    // negative z
                    lowerData = 1;
                    if (diff.x < 0)
                    {
                        upperData |= 0b0001;
                    }
                }
                else
                {
                    // negative x
                    lowerData = 0;
                    if (diff.z > 0)
                    {
                        upperData |= 0b0001;
                    }
                }
            }
        }

        NBTHelper.SetBlockData(pos + Vector3Int.up, type, upperData);
        NBTHelper.SetBlockData(pos, type, lowerData);

        InventorySystem.DecrementCurrent();
        ItemSelectPanel.instance.RefreshUI();
    }