Beispiel #1
0
        public static Stamp From(SerializedItem serializedStamp)
        {
            Stamp stamp = new Stamp();

            serializedStamp.AssignPropertiesTo(stamp);
            return(stamp);
        }
    void LateUpdate()
    {
        if (cursorItem != null && transform.childCount == 0)
        {
            cursorItem = null;
        }

        bool currentStatus = ClientComponent.INSTANCE.playerObject.GetComponent <UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled;

        if (transform.childCount > 0)
        {
            if (currentStatus == true)
            {
                ClientComponent.INSTANCE.playerObject.GetComponent <UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = false;
                Cursor.lockState = CursorLockMode.None;
                Cursor.visible   = true;
            }
        }
        else
        {
            if (currentStatus == false)
            {
                ClientComponent.INSTANCE.playerObject.GetComponent <UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = true;
                Cursor.lockState = CursorLockMode.Locked;
                Cursor.visible   = false;
            }
        }
    }
Beispiel #3
0
 private void SortInventoryItemSlotsOnLoad(SerializedItem item)
 {
     if (ItemDBCache.Items.ContainsKey(item.ItemId))
     {
         Inventory.Add(item.InventorySlot, ItemDBCache.Items[item.ItemId] as Item);
     }
 }
Beispiel #4
0
        public static IItemProperties From(SerializedItem stamp)
        {
            MapCharacter mapCharacter = new MapCharacter();

            stamp.AssignPropertiesTo(mapCharacter);
            return(mapCharacter);
        }
Beispiel #5
0
 public RedBlackTreePersistent(string path)
 {
     _path       = path;
     _serializer = new XmlSerializer(typeof(SerializedItem <TKey, TValue>));
     foreach (string file in Directory.EnumerateFiles(_path, "*" + typeof(TValue)))
     {
         using (StreamReader fileStream = File.OpenText(file))
         {
             SerializedItem <TKey, TValue> item = (SerializedItem <TKey, TValue>)_serializer.Deserialize(fileStream);
             base.Add(item.Key, item.Value);
         }
     }
 }
Beispiel #6
0
        public static TGroup DeserializeGroup <TGroup>(SerializedItem stamp) where TGroup : IGroup, new()
        {
            TGroup result = new TGroup();

            stamp.AssignPropertiesTo(result);
            if (stamp.Children != null)
            {
                foreach (SerializedItem childStamp in stamp.Children)
                {
                    result.Children.Add(MapElementFactory.CreateItemFrom(childStamp));
                }
            }
            return(result);
        }
Beispiel #7
0
 public void SetItem(SerializedItem item)
 {
     if (item != null)
     {
         if (preview != null)
         {
             Destroy(preview.gameObject);
         }
         preview = item.Preview(transform);
         if (preview == null)
         {
             return;
         }
         preview.gameObject.layer = LayerMask.NameToLayer(previewLayer);
     }
 }
        public static IItemProperties CreateItemFrom(SerializedItem stamp)
        {
            // Coding Gorilla's suggestion has been implemented here!!!
            // ![](5BB3346892E7D77EE7412ACA3E59628A.png;;36,0,203,187)
            // TODO: Also be able to reconstruct Characters and CharacterGroups
            if (stamp.TypeName == "StampGroup")
            {
                return(StampGroup.From(stamp));
            }

            if (stamp.TypeName == "MapCharacterGroup")
            {
                return(MapCharacterGroup.From(stamp));
            }

            if (stamp.TypeName == "MapCharacter")
            {
                return(MapCharacter.From(stamp));
            }
            return(Stamp.From(stamp));
        }
    private void touchBlock(SerializedItem holding, int x, int y, int z, Vector3 normal)
    {
        // public enum Direction { north, east, south, west, up, down };
        //                         z+   , x+  , z-   , x-  , y+, y-
        int dir = 0;

        if (normal.Equals(Vector3.forward))
        {
            dir = 0;
        }
        else if (normal.Equals(Vector3.back))
        {
            dir = 2;
        }
        else if (normal.Equals(Vector3.right))
        {
            dir = 1;
        }
        else if (normal.Equals(Vector3.left))
        {
            dir = 3;
        }
        else if (normal.Equals(Vector3.up))
        {
            dir = 4;
        }
        else if (normal.Equals(Vector3.down))
        {
            dir = 5;
        }
        ClientUseItemMessage use = new ClientUseItemMessage();

        use.HotbarIndex = (uint)(inventory.currentSelection & 0xF);
        use.Direction   = (uint)(dir & 0xF);
        use.BlockX      = x;
        use.BlockY      = y;
        use.BlockZ      = z;
        client.GetClient().sendMessage(use);
    }
    // Update is called once per frame
    void LateUpdate()
    {
        // if (Camera.current == null) return;

        if (WindowManager.INSTANCE.transform.childCount > 0)
        {
            return;
        }
        if (WindowManager.INSTANCE.busyTick)
        {
            WindowManager.INSTANCE.busyTick = false;
            return;
        }

        Ray        r = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
        RaycastHit h;
        bool       hit = Physics.Raycast(r, out h);

        if (hit && h.transform.GetComponent <Entity>() != null)
        {
            // hit an entity
            Entity target = h.transform.GetComponent <Entity>();

            if (Input.GetMouseButtonDown(0))
            {
                hitEntity(target, 0);
            }
            else if (Input.GetMouseButtonDown(1))
            {
                hitEntity(target, 1);
            }
            else if (Input.GetMouseButtonDown(2))
            {
                hitEntity(target, 2);
            }

            if (aimingEntity == null || !aimingEntity.IsAlive || target.entityId != ((Entity)aimingEntity.Target).entityId)
            {
                aimingEntity = new WeakReference(target, true);
            }

            cancelBreaking();
            return;
        }
        else
        {
            aimingEntity = null;
        }

        if (!hit || Vector3.Distance(h.point, ClientComponent.INSTANCE.playerObject.transform.position) > 10f)
        {
            hideSelection();
            return;
        }

        Vector3 b = h.point - (0.5f * h.normal);
        int     x = Mathf.FloorToInt(b.x);
        int     y = Mathf.FloorToInt(b.y);
        int     z = Mathf.FloorToInt(b.z);

        showSelection(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));

        if (breakingBlock != null)
        {
            if (x != breakingX || y != breakingY || z != breakingZ)
            {
                cancelBreaking();

                if (Input.GetMouseButton(1))
                {
                    c = true;
                }
            }
            else
            {
                long span = (long)((DateTime.Now - breakingTime).TotalMilliseconds);
                if (span > breakingBlock.GetBreakTime(inventory.GetSelectedItem()))
                {
                    // Should be finished
                    client.chunkManager.setBlockAt(x, y, z, 0);
                    ClientRemoveBlockMessage removeBlockMessage = new ClientRemoveBlockMessage();
                    removeBlockMessage.X = x;
                    removeBlockMessage.Y = y;
                    removeBlockMessage.Z = z;
                    client.GetClient().sendMessage(removeBlockMessage);

                    selection.SetActive(false);
                    selection.GetComponent <MeshRenderer>().material.mainTexture = null;

                    if (Input.GetMouseButtonDown(1))
                    {
                        c = true;
                    }
                    else
                    {
                        c = false;
                    }
                }
                else
                {
                    handAnimation.Play("hand_breaking");

                    int stageTextureId = (int)(((DateTime.Now - breakingTime).TotalMilliseconds / breakingBlock.GetBreakTime(inventory.GetSelectedItem())) * 10f);
                    if (stageTextureId > 9)
                    {
                        stageTextureId = 9;
                    }
                    if (!selection.activeSelf)
                    {
                        selection.SetActive(true);
                    }
                    if (stageTextureId != displayingStageTexture)
                    {
                        displayingStageTexture = stageTextureId;
                        selection.GetComponent <MeshRenderer>().material.mainTexture = breakStageTextures[displayingStageTexture];
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(1) || c)
        {
            cancelBreaking();
            int id = client.chunkManager.getBlockAt(x, y, z);
            if (id == 0)
            {
                cancelBreaking();
                return;
            }
            c = false;
            // int meta = f & 0xFFFF;
            breakingBlock = Block.prototypes[id];
            breakingX     = x;
            breakingY     = y;
            breakingZ     = z;
            breakingTime  = DateTime.Now;
            // Debug.Log("START BREAKING <" + breakingBlock.GetType().Name + ">");

            ClientActionMessage startBreakingMessage = new ClientActionMessage();
            startBreakingMessage.Action = ClientActionMessage.Types.ActionType.StartBreak;
            startBreakingMessage.BlockX = x;
            startBreakingMessage.BlockY = y;
            startBreakingMessage.BlockZ = z;
            client.GetClient().sendMessage(startBreakingMessage);
        }

        if (Input.GetMouseButtonUp(0))
        {
            cancelBreaking();
            Vector3        adding  = h.point + (0.5f * h.normal);
            SerializedItem holding = inventory.items[inventory.currentSelection];

            touchBlock(holding, x, y, z, h.normal);

            if (holding != null)
            {
                if (holding.Id < Block.prototypes.Length)
                {
                    int addingX = Mathf.FloorToInt(adding.x);
                    int addingY = Mathf.FloorToInt(adding.y);
                    int addingZ = Mathf.FloorToInt(adding.z);
                    Debug.Log(string.Format("ADDING AT ({0},{1},{2})", addingX, addingY, addingZ));
                    // Place block
                    client.chunkManager.setBlockAt(addingX, addingY, addingZ, holding.Id);

                    holding.Count--;
                    if (holding.Count <= 0)
                    {
                        inventory.items[inventory.currentSelection] = null;
                    }

                    handAnimation.Play("hand_place");
                }
            }
        }

        if (Input.GetMouseButtonUp(1))
        {
            cancelBreaking();
            c = false;
        }
    }
Beispiel #11
0
 // Use this for initialization
 void Start()
 {
     items = new SerializedItem[9]; // 9 for initial bar
 }
Beispiel #12
0
    public void updateFromMetadata(int elem, SerializedMetadata meta)
    {
        SerializedItem[] reference;
        switch (elem)
        {
        case 0:
            reference = items;
            break;

        case 1:
            reference = craftingInput;
            break;

        case 2:
            reference = craftingOutput;
            break;

        default:
            return;
        }
        if (meta.Entries.Count != reference.Length)
        {
            reference = new SerializedItem[meta.Entries.Count];
        }
        Debug.Log("UPDATED INVENTORY SIZE = " + items.Length);
        for (uint i = 0; i < meta.Entries.Count; i++)
        {
            reference[i]            = new SerializedItem();
            reference[i].Id         = meta.Entries[i].MetaValue.Entries[0].Int32Value;
            reference[i].Count      = (uint)meta.Entries[i].MetaValue.Entries[1].Int32Value;
            reference[i].BinaryMeta = meta.Entries[i].MetaValue.Entries[2].MetaValue;
        }
        switch (elem)
        {
        case 0:
            items = reference;
            break;

        case 1:
            craftingInput = reference;
            break;

        case 2:
            craftingOutput = reference;
            break;
        }

        PlayerInventoryWindow invWindow = (PlayerInventoryWindow)WindowManager.INSTANCE.getInventoryWindow();

        if (invWindow != null)
        {
            switch (elem)
            {
            case 0:
                invWindow.UpdateItems();
                break;

            case 1:
                invWindow.UpdateCraftingInputs();
                break;

            case 2:
                invWindow.UpdateCraftingOutput();
                break;
            }
        }
    }
Beispiel #13
0
 public static StampGroup From(SerializedItem stamp)
 {
     return(GroupHelper.DeserializeGroup <StampGroup>(stamp));
 }