Exemple #1
0
        public ToolItem GetToolData()
        {
            ToolItem i = ScriptableObject.CreateInstance <ToolItem>();

            i.SetValues(itemName, itemText, value, spriteName, toolType, inputType, power, precision, sustainedBreakCooldown, breakRadius);

            return(i);
        }
Exemple #2
0
        /// <summary>
        /// Deforms the voxel rock by removing the voxel(s) under the mouse position.
        /// </summary>
        public IEnumerator DeformRock(ToolItem item)
        {
            if (item == null)
            {
                yield break;
            }

            if (Platform == RuntimePlatform.Android)
            {
                yield return(new WaitForSeconds(touchInputDelay));

                if (Input.touchCount > 1)
                {
                    yield break;
                }
            }

            RaycastHit hit;

            if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                yield break;
            }

            Vector3 voxelPosition = hit.point - hit.normal * 0.5f;

            switch (item.Type)
            {
            case ToolType.POINT:
                voxelGrid.TryVoxelDestruction(
                    Mathf.FloorToInt(voxelPosition.x),
                    Mathf.FloorToInt(voxelPosition.y),
                    Mathf.FloorToInt(voxelPosition.z),
                    item.Power);
                break;

            case ToolType.AREA:
                List <Vector3Int> indices = new List <Vector3Int>();

                for (int x = 0; x < voxelGrid.X; x++)
                {
                    for (int y = 0; y < voxelGrid.Y; y++)
                    {
                        for (int z = 0; z < voxelGrid.Z; z++)
                        {
                            if (Mathf.Pow(x - voxelPosition.x, 2) + Mathf.Pow(y - voxelPosition.y, 2) + Mathf.Pow(z - voxelPosition.z, 2) <= item.BreakRadius)
                            {
                                indices.Add(new Vector3Int(x, y, z));
                            }
                        }
                    }
                }

                voxelGrid.TryMultipleVoxelDestruction(indices.ToArray(), item.Power);
                break;
            }
        }
Exemple #3
0
        public SaveItem(InventoryItem item)
        {
            if (item is ToolItem)
            {
                type = ItemType.TOOL;
            }
            else if (item is MineralItem)
            {
                type = ItemType.MINERAL;
            }
            else if (item is ConsumableItem)
            {
                type = ItemType.CONSUMABLE;
            }
            else
            {
                type = ItemType.OTHER;
            }

            itemName   = item.ItemName;
            itemText   = item.ItemText;
            value      = item.Value;
            spriteName = item.SpriteName;

            switch (type)
            {
            case ItemType.TOOL:
                ToolItem t = item as ToolItem;

                toolType  = t.Type;
                inputType = t.InputType;
                power     = t.Power;
                precision = t.Precision;
                sustainedBreakCooldown = t.SustainedBreakCooldown;
                breakRadius            = t.BreakRadius;
                break;

            case ItemType.MINERAL:
                MineralItem m = item as MineralItem;

                modelName = m.ModelName;
                colorR    = m.Color.r;
                colorG    = m.Color.g;
                colorB    = m.Color.b;
                break;

            case ItemType.CONSUMABLE:
                ConsumableItem c = item as ConsumableItem;

                consumableType = c.Type;
                strength       = c.Strength;
                duration       = c.Duration;
                break;
            }
        }
Exemple #4
0
        /// <summary>
        /// Run when a voxel is broken.
        /// </summary>
        /// <param name="tool">Tool used to break the voxel.</param>
        public void OnBreakVoxel(ToolItem tool, VoxelType type)
        {
            float mult = 1;

            switch (type)
            {
            case VoxelType.ROCK:
                mult = 2 - hardRockMult;
                break;

            case VoxelType.HARD_ROCK:
                mult = hardRockMult;
                break;

            default:
                break;
            }
            AdjustRockIntegrity(-tool.Precision * baseIntegrityLossFactor * mult);
        }
Exemple #5
0
        /// <summary>
        /// Equip an item.
        /// </summary>
        /// <param name="item">Item to equip.</param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetItemEquipped(InventoryItem item, bool value)
        {
            if (!playerItems.Contains(item) || !(item is ToolItem))
            {
                return(false);
            }

            ToolItem i        = item as ToolItem;
            ToolItem toRemove = null;

            foreach (ToolItem t in equippedItems)
            {
                // Set the item that will be swapped out
                if (t.Type.Equals(i.Type))
                {
                    toRemove = t; break;
                }
            }

            // Remove the existing item of the swap type and put it back in the inventory
            if (toRemove != null)
            {
                equippedItems.Remove(toRemove);
                AddItem(toRemove, InventoryType.PLAYER);
            }

            // Add the new item to the equipped items (the old one was either removed or never existed)
            if (value)
            {
                equippedItems.Add(i);
                playerItems.Remove(i);
            }

            UIManager.Instance.LoadInventoryToEquipmentBar();
            UIManager.Instance.LoadInventoryToInventoryModal(InventoryType.PLAYER);

            return(value);
        }
Exemple #6
0
        /// <summary>
        /// Checks for inputs each frame.
        /// </summary>
        public void Update()
        {
            // Wrap these in state machine checks wherever applicable.
            GameState state = StateManager.Instance.State;

            if (!inputIsLocked)   // Only perform input checks if input is unlocked.
            // Perform per-state input behavior
            {
                switch (state)
                {
                default:
                case GameState.MENU:
                    /// TODO: Input behavior for menu state
                    break;

                case GameState.MINING:
                    // Get the active tool
                    ToolItem i = InventoryManager.Instance.ActiveTool;

                    // If there is an active tool...
                    if (i != null)
                    {
                        // Check tool type-specific inputs.
                        switch (i.InputType)
                        {
                        case ToolInputType.INSTANT:
                            if (GameClick())
                            {
                                StartCoroutine(DeformRock(i));
                            }
                            break;

                        case ToolInputType.SUSTAINED:
                            if (GameClickHold())
                            {
                                StartCoroutine(DeformRock(i));
                            }
                            break;
                        }

                        if (i.Type == ToolType.CHISEL && GameClick())
                        {
                            TryMineGem();
                        }
                    }

                    // Do camera controls.
                    if (GetInputDelta() != Vector2.zero)
                    {
                        DoCameraPan(GetInputDelta());
                    }

                    DoCameraZoom();
                    break;
                }

                // Smooth the camera controls.
                SmoothCamera();

                lastMousePosition = Input.mousePosition;
            }
        }