Пример #1
0
    // This will get the ore that is attached to the rock we are mining and set it to the players item list
    public ItemBase GetRockItem(OreAbstractClass ore)
    {
        ToolItems = GameObject.Find("TemplateTools");
        XMLParser  XML           = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <XMLParser>();
        GameObject SubGameObject = new GameObject(ore.XMLName);

        SubGameObject.transform.parent = ToolItems.transform;
        ItemBase PlantItem = ore;

        return(PlantItem);
    }
Пример #2
0
    public override void useTool()
    {
        /*Assigned index based on level*/
        if (SceneManager.GetActiveScene().name == "Mines")
        {
            INDEX = 1;
        }
        if (SceneManager.GetActiveScene().name == "Mines1")
        {
            INDEX = 2;
        }
        if (SceneManager.GetActiveScene().name == "Mines2")
        {
            INDEX = 3;
        }
        /*****************************************************/

        // Only use the tool if we are on any of the mines levels
        if (SceneManager.GetActiveScene().name == "Mines" || SceneManager.GetActiveScene().name == "Mines1" || SceneManager.GetActiveScene().name == "Mines2")
        {
            Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>();
            //rockPlacer = GameObject.FindGameObjectWithTag("Rockplacer").GetComponent<JunkPlacer>();
            cInventory = GameObject.FindGameObjectWithTag("InventoryManager").GetComponent <InventoryClass>();
            //TODO - when we add more grids and tilemaps, this will break
            // Get the camera position to world.
            Vector3    pos    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector3Int posInt = grid.WorldToCell(pos);
            // check if the dictionary has an ore at the given location
            if (Dictioary.TileMapData.ElementAt(INDEX).Value[posInt].HasOre())
            {
                OreAbstractClass Ore   = Dictioary.TileMapData.ElementAt(INDEX).Value[posInt].GetOre();
                AudioSource      Audio = gameObject.GetComponentInParent <AudioSource>();
                /*Play the sound*/
                Audio.clip = GetSoundEffect();
                Audio.Play();
                Debug.Log("GATHERED ORE");
                ToolUsed = true;
                /****************/
                // Assess the ore
                InventoryAssessment(GetRockItem(Ore), posInt);
                // Edit the dictionary
                Dictioary.TileMapData.ElementAt(INDEX).Value[posInt].TileMap.SetTile(posInt, GetTile());
                Dictioary.TileMapData.ElementAt(INDEX).Value.Remove(posInt);
            }
        }
    }
Пример #3
0
 public void SetOre(OreAbstractClass P)
 {
     Ore = P;
 }
Пример #4
0
    public SaveData(Vector3Int date, Vector3 pos, Vector3Int time, float[] lighting, bool[] resets, int[] slots, float playerGold, int playerEnergy, ItemBase[] inventory,
                    ItemBase[] hotbar, ItemBase[] chest, Dictionary <string, Dictionary <Vector3Int, TileDataClass> > dataBase)
    {
        // Set up all the arrays we will be saving to
        Inventory = new ItemData[slots[0]];
        HotBar    = new ItemData[slots[1]];
        Chest     = new ItemData[slots[2]];
        Lighting  = new float[4];
        Farm      = new PlantData[dataBase.ElementAt(0).Value.Count];
        Mines     = new RockData[dataBase.ElementAt(1).Value.Count];
        Mines1    = new RockData[dataBase.ElementAt(2).Value.Count];
        Mines2    = new RockData[dataBase.ElementAt(3).Value.Count];
        Forest    = new TreeData[dataBase.ElementAt(4).Value.Count];

        Date[0]             = date.x; Date[1] = date.y; Date[2] = date.z;
        Time[0]             = time.x; Time[1] = time.y; Time[2] = time.z;
        PlayerPos[0]        = pos.x; PlayerPos[1] = pos.y; PlayerPos[2] = pos.z;
        WeeklyResets        = resets;
        InventorySlotAmount = slots;
        PlayerGold          = playerGold;
        PlayerEnergy        = playerEnergy;
        Lighting            = lighting;

        string TileName   = "";
        string PrefabName = "";

        for (int i = 0; i < slots[0]; i++)
        {
            if (inventory[i] != null)
            {
                if (inventory[i].GetTile() != null)
                {
                    TileName = inventory[i].GetTile().name;
                }
                if (inventory[i].GetPrefab() != null)
                {
                    PrefabName = inventory[i].GetPrefab().name;
                }

                Inventory[i].SetUp(inventory[i].GetName(), inventory[i].mItemType.ToString(),
                                   inventory[i].GetSrcImage(), TileName,
                                   inventory[i].GetSoundEffect().name, PrefabName, inventory[i].GetAmount(),
                                   inventory[i].GetStackable(), inventory[i].GetSellPrice(), inventory[i].GetDesc());
            }

            TileName   = "";
            PrefabName = "";
        }
        for (int i = 0; i < slots[1]; i++)
        {
            if (hotbar[i] != null)
            {
                if (hotbar[i].GetTile() != null)
                {
                    TileName = hotbar[i].GetTile().name;
                }
                if (hotbar[i].GetPrefab() != null)
                {
                    PrefabName = hotbar[i].GetPrefab().name;
                }


                HotBar[i].SetUp(hotbar[i].GetName(), hotbar[i].mItemType.ToString(), hotbar[i].GetSrcImage(),
                                TileName, hotbar[i].GetSoundEffect().name, PrefabName, hotbar[i].GetAmount(),
                                hotbar[i].GetStackable(), hotbar[i].GetSellPrice(), hotbar[i].GetDesc());
            }

            TileName   = "";
            PrefabName = "";
        }
        for (int i = 0; i < slots[2]; i++)
        {
            if (chest[i] != null)
            {
                if (chest[i].GetTile() != null)
                {
                    TileName = chest[i].GetTile().name;
                }
                if (chest[i].GetPrefab() != null)
                {
                    PrefabName = chest[i].GetPrefab().name;
                }

                Chest[i].SetUp(chest[i].GetName(), chest[i].mItemType.ToString(), chest[i].GetSrcImage(),
                               TileName, chest[i].GetSoundEffect().name, PrefabName, chest[i].GetAmount(),
                               chest[i].GetStackable(), chest[i].GetSellPrice(), chest[i].GetDesc());
            }

            TileName   = "";
            PrefabName = "";
        }

        int counter = 0;

        foreach (var var in dataBase.ElementAt(0).Value)
        {
            if (var.Value.GetPlant() != null)
            {
                PlantAbstractClass Plant         = var.Value.GetPlant();
                Vector3Int         Key           = new Vector3Int(var.Key.x, var.Key.y, var.Key.z);
                string[]           GrowthSprites = new string[Plant.mGrowthSprites.Length];
                GrowthSprites[0] = Plant.mGrowthSprites[0].name;
                GrowthSprites[1] = Plant.mGrowthSprites[1].name;
                GrowthSprites[2] = Plant.mGrowthSprites[2].name;
                Farm[counter].SetUp(Plant.mCurrentDays, Plant.mGrowthTime, Plant.GetType().ToString(),
                                    Plant.GetSrcImage(), Plant.GetAmount(), GrowthSprites, Key, Key, var.Value.Tile.name,
                                    Plant.mHarvestable, Plant.mGrowth, Plant.XMLName, Plant.mWatered);
            }
            counter++;
        }
        counter = 0;
        foreach (var var in dataBase.ElementAt(1).Value)
        {
            OreAbstractClass Ore = var.Value.GetOre();
            float[]          Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Mines[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount());
            counter++;
        }

        counter = 0;
        foreach (var var in dataBase.ElementAt(2).Value)
        {
            OreAbstractClass Ore = var.Value.GetOre();
            float[]          Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Mines1[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount());
            counter++;
        }
        counter = 0;
        foreach (var var in dataBase.ElementAt(3).Value)
        {
            OreAbstractClass Ore = var.Value.GetOre();
            float[]          Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Mines2[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount());
            counter++;
        }
        counter = 0;
        foreach (var var in dataBase.ElementAt(4).Value)
        {
            ItemBase Wood = var.Value.GetItem();
            float[]  Key  = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Forest[counter].SetUp(Wood.mItemType.ToString(), Wood.GetName(), Key, Key, var.Value.Tile.name, Wood.GetName(), Wood.GetAmount());
            counter++;
        }
        counter = 0;
    }