Beispiel #1
0
    public static void Hide()
    {
        InputManager.enabled = true;
        PlayerController.LockCursor(true);
        if (Instance != null)
        {
            Instance.gameObject.SetActive(false);
        }

        if (InventorySystem.grabItem.id != null)
        {
            InventorySystem.DropGrabItem();
        }

        // clear crafting
        foreach (int i in indexList)
        {
            if (InventorySystem.items[i].id != null)
            {
                NBTObject obj = NBTGeneratorManager.GetObjectGenerator(InventorySystem.items[i].id);
                InventorySystem.Increment(obj, (byte)InventorySystem.items[i].damage, InventorySystem.items[i].count);
                InventorySystem.items[i].id     = null;
                InventorySystem.items[i].damage = 0;
                InventorySystem.items[i].count  = 0;
            }
        }
        InventorySystem.items[resultIndex].id     = null;
        InventorySystem.items[resultIndex].damage = 0;
        InventorySystem.items[resultIndex].count  = 0;

        ItemSelectPanel.instance.RefreshUI();
    }
    public static void Increment(NBTObject generator, byte data, byte count)
    {
        // 优先加到已有的同类的里面
        for (int i = 0; i < 36; i++)
        {
            if (items[i].id == null)
            {
                continue;
            }

            if (NBTGeneratorManager.GetObjectGenerator(items[i].id) == null)
            {
                Debug.Log("cannot get type,slot=" + i + ",id=" + items[i].id);
                continue;
            }

            string id = items[i].id;
            short  d  = items[i].damage;
            byte   c  = items[i].count;
            if (id == generator.id && d == data && c < generator.maxStackCount)
            {
                int diff = generator.maxStackCount - c;

                if (count > diff)
                {
                    items[i].count = generator.maxStackCount;
                    count         -= (byte)diff;
                }
                else
                {
                    items[i].count += count;
                    return;
                }
            }
        }
        //已有的放不下,需要放在空格内
        for (int i = 0; i < 36; i++)
        {
            if (items[i].id == null)
            {
                items[i].id     = generator.id;
                items[i].damage = data;

                if (count > generator.maxStackCount)
                {
                    items[i].count = generator.maxStackCount;
                    count         -= generator.maxStackCount;
                }
                else
                {
                    items[i].count = count;
                    return;
                }
            }
        }
    }
    public static void DropGrabItem()
    {
        NBTObject generator = NBTGeneratorManager.GetObjectGenerator(grabItem.id);

        Item.CreatePlayerDropItem(generator, (byte)grabItem.damage, grabItem.count);

        grabItem.id     = null;
        grabItem.damage = 0;
        grabItem.count  = 0;
    }
Beispiel #4
0
    public static Item CreateBlockDropItem(string id, byte data, Vector3 pos)
    {
        float     right     = Random.Range(-1f, 1f);
        float     forward   = Random.Range(-1f, 1f);
        Vector3   dir       = Vector3.up + right * Vector3.right + forward * Vector3.forward;
        NBTObject generator = NBTGeneratorManager.GetObjectGenerator(id);
        Item      item      = Create(generator, data, pos, dir.normalized);

        item.coolDownTime = 0.5f;
        return(item);
    }
Beispiel #5
0
    public static Texture2D GetIcon(string id, short data)
    {
        NBTObject generator = NBTGeneratorManager.GetObjectGenerator(id);

        if (generator != null)
        {
            string path = generator.GetIconPathByData(data);
            return(Resources.Load <Texture2D>(generator.pathPrefix + path));
        }
        Debug.Log("no icon, id=" + id + ",data=" + data);
        return(null);
    }
Beispiel #6
0
    public void RefreshUI()
    {
        for (int i = 0; i < 9; i++)
        {
            InventoryItem item = InventorySystem.items[i];
            if (item.id == null)
            {
                itemList[i].icon.gameObject.SetActive(false);
                itemList[i].count.gameObject.SetActive(false);
            }
            else
            {
                itemList[i].icon.texture = BlockIconHelper.GetIcon(item.id, item.damage);
                itemList[i].icon.gameObject.SetActive(true);
                if (item.count > 1)
                {
                    itemList[i].count.gameObject.SetActive(true);
                    itemList[i].count.text = item.count.ToString();
                }
                else
                {
                    itemList[i].count.gameObject.SetActive(false);
                }
            }
            itemList[i].select.SetActive(i == curIndex);
        }

        if (lastIndex != curIndex)
        {
            lastIndex = curIndex;
            //HeroChangeSelectIndexReq(curIndex);
        }

        InventoryItem curItem = InventorySystem.items[curIndex];

        if (curItem.id != null)
        {
            NBTObject generator = NBTGeneratorManager.GetObjectGenerator(curItem.id);
            if (generator != null)
            {
                PlayerController.ShowBlock(generator, curItem.damage);
            }
            else
            {
                PlayerController.ShowHand();
            }
        }
        else
        {
            PlayerController.ShowHand();
        }
    }
Beispiel #7
0
    void UpdateDesc()
    {
        if (highlightIndex != -1 && InventorySystem.grabItem.id == null)
        {
            InventoryItem item = InventorySystem.items[highlightIndex];

            if (item.id != null)
            {
                if (!descTrans.gameObject.activeSelf)
                {
                    descTrans.gameObject.SetActive(true);
                }
                descTrans.anchoredPosition = Input.mousePosition / UISystem.scale + offset;

                NBTObject generator = NBTGeneratorManager.GetObjectGenerator(item.id);
                if (generator == null)
                {
                    descLabel.text = item.id;
                }
                else
                {
                    descLabel.text = generator.GetNameByData(item.damage);
                }
                descLabel.Rebuild(CanvasUpdate.PreRender);
                descTrans.sizeDelta = new Vector2(Mathf.CeilToInt(descLabel.renderedWidth) + 10, 16);
            }
            else
            {
                if (descTrans.gameObject.activeSelf)
                {
                    descTrans.gameObject.SetActive(false);
                }
            }
        }
        else
        {
            if (descTrans.gameObject.activeSelf)
            {
                descTrans.gameObject.SetActive(false);
            }
        }
    }
Beispiel #8
0
    public void RefreshUI()
    {
        for (int i = 0; i < 9; i++)
        {
            InventoryItem item = InventorySystem.items[i];
            if (item.id == null)
            {
                itemList[i].icon.gameObject.SetActive(false);
                itemList[i].count.gameObject.SetActive(false);
                itemList[i].damageObj.SetActive(false);
            }
            else
            {
                itemList[i].icon.texture = BlockIconHelper.GetIcon(item.id, item.damage);
                itemList[i].icon.gameObject.SetActive(true);
                if (item.count > 1)
                {
                    itemList[i].count.gameObject.SetActive(true);
                    itemList[i].count.text = item.count.ToString();
                }
                else
                {
                    itemList[i].count.gameObject.SetActive(false);
                }

                NBTObject generator = NBTGeneratorManager.GetObjectGenerator(item.id);
                if (generator != null && generator is NBTItem)
                {
                    NBTItem nbtItem = generator as NBTItem;

                    if (nbtItem.durability == -1 || item.damage == 0)
                    {
                        itemList[i].damageObj.SetActive(false);
                    }
                    else
                    {
                        itemList[i].damageObj.SetActive(true);
                        float process = (nbtItem.durability - item.damage) / (float)nbtItem.durability;
                        itemList[i].damage.rectTransform.sizeDelta = new Vector2(13 * process, 1);
                        itemList[i].damage.color = Color.Lerp(Color.red, Color.green, process);
                    }
                }
            }
            itemList[i].select.SetActive(i == curIndex);
        }

        if (lastIndex != curIndex)
        {
            lastIndex = curIndex;
            //HeroChangeSelectIndexReq(curIndex);
        }

        InventoryItem curItem = InventorySystem.items[curIndex];

        if (curItem.id != null)
        {
            NBTObject generator = NBTGeneratorManager.GetObjectGenerator(curItem.id);
            if (generator != null)
            {
                PlayerController.ShowBlock(generator, curItem.damage);
            }
            else
            {
                PlayerController.ShowHand();
            }
        }
        else
        {
            PlayerController.ShowHand();
        }
    }
    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();
        }
    }
Beispiel #10
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);
        }
    }