Ejemplo n.º 1
0
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    #region Helpers
    private Transform GetParentTransform(eEditablePrefabs forType)
    {
        if (forType == eEditablePrefabs.Brawler || forType == eEditablePrefabs.Scurrier)
        {
            EnemyGroup found = currentRoom.gameObject.GetComponentInChildren <EnemyGroup>();
            if (found == null)
            {
                Debug.Log("Could not find parent for new enemy");
                return(null);
            }
            return(found.transform);
        }
        else
        {
            OreVein foundOre = currentRoom.gameObject.GetComponentInChildren <OreVein>();
            if (foundOre)
            {
                return(foundOre.gameObject.transform.parent);
            }
            HealthFruit foundFruit = currentRoom.gameObject.GetComponent <HealthFruit>();
            if (foundFruit)
            {
                return(foundFruit.gameObject.transform.parent);
            }

            Debug.Log("Could not find the parent for new pickup");
            return(null);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Perform the collect ore action.
    /// </summary>
    /// <param name="agent">The agent performing this action.</param>
    /// <returns>If the action was performed this frame.</returns>
    public override bool Perform(GameObject agent)
    {
        // Make sure the ore vein is active.
        if (m_Target.activeSelf != false)
        {
            if (m_StartTime == 0.0f)
            {
                m_StartTime = Time.time;
            }

            // Work complete.
            if (Time.time - m_StartTime > m_WorkDuration)
            {
                // Update everything that work has been done.
                m_Inventory.IncreaseOre(1);
                m_Mined = true;
                OreVein oreVein = m_Target.GetComponent <OreVein>();
                oreVein.DecreaseOreAmount(1);
                oreVein.SetCurrentMiner(null);

                agent.GetComponent <Worker>().DecreaseHunger(m_WorkHunger);
            }

            // Set progress for progress bar.
            m_Inventory.SetProgress((Time.time - m_StartTime) / m_WorkDuration);

            // The action was performed this frame.
            return(true);
        }
        // The action was not performed this frame.
        else
        {
            return(false);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Check for the closest ore vein to mine ore from.
    /// </summary>
    /// <param name="agent">The agent we are checking for.</param>
    /// <returns>If an ore vein was found.</returns>
    public override bool CheckProceduralPrecondition(GameObject agent)
    {
        // Get all the ore veins in the scene.
        GameObject[] veins           = GameObject.FindGameObjectsWithTag("Ore");
        GameObject   closest         = null;
        float        closestDistance = float.MaxValue;

        // Find the closest ore vein.
        foreach (GameObject v in veins)
        {
            // Check that no one else is targeting this ore vein.
            OreVein ore = v.GetComponent <OreVein>();
            if (ore.GetCurrentMiner() == null)
            {
                float dist = (v.transform.position - agent.transform.position).magnitude;
                // Target the closest ore vein that no one else is targeting.
                if (dist < closestDistance)
                {
                    closest         = v;
                    closestDistance = dist;
                }
            }
        }

        if (closest != null)
        {
            // Target the closest ore vein.
            m_Target = closest;
            // Tell the ore vein that this agent is targeting it.
            m_Target.GetComponent <OreVein>().SetCurrentMiner(agent.name);

            return(m_Target != null);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 4
0
    public OreVein GenerateOreVeinsHelper(Vector2 startAt, Dictionary <Vector2, float> notInVein, OreVein workingOreVein, OreType type)
    {
        Vector2 top    = startAt + Vector2.up;
        Vector2 bottom = startAt - Vector2.up;
        Vector2 right  = startAt + Vector2.right;
        Vector2 left   = startAt - Vector2.right;

        if (workingOreVein.oreSpaces.Count == 0)
        {
            workingOreVein.oreSpaces.Add(new OreSpace(startAt, (int)(1000 * notInVein[startAt] * type.richness), workingOreVein));
        }

        if (notInVein.ContainsKey(startAt))
        {
            notInVein.Remove(startAt);
        }

        if (notInVein.ContainsKey(top))
        {
            workingOreVein.oreSpaces.Add(new OreSpace(top, (int)(1000 * notInVein[top] * type.richness), workingOreVein));
            notInVein.Remove(top);
            GenerateOreVeinsHelper(top, notInVein, workingOreVein, type);
        }

        if (notInVein.ContainsKey(bottom))
        {
            workingOreVein.oreSpaces.Add(new OreSpace(bottom, (int)(1000 * notInVein[bottom] * type.richness), workingOreVein));
            notInVein.Remove(bottom);
            GenerateOreVeinsHelper(bottom, notInVein, workingOreVein, type);
        }

        if (notInVein.ContainsKey(right))
        {
            workingOreVein.oreSpaces.Add(new OreSpace(right, (int)(1000 * notInVein[right] * type.richness), workingOreVein));
            notInVein.Remove(right);
            GenerateOreVeinsHelper(right, notInVein, workingOreVein, type);
        }

        if (notInVein.ContainsKey(left))
        {
            workingOreVein.oreSpaces.Add(new OreSpace(left, (int)(1000 * notInVein[left] * type.richness), workingOreVein));
            notInVein.Remove(left);
            GenerateOreVeinsHelper(left, notInVein, workingOreVein, type);
        }

        return(workingOreVein);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Serializes an example ore to eb
        /// </summary>
        protected List <OreVein> createOreVeins()
        {
            //Tin
            List <OreVein> oreVeins   = new List <OreVein>();
            OreVein        tinOre_0_0 = new OreVein(new BasicItemInformation("Tin Ore Vein", "Omegasis.Revitalize.Resources.Ore.Tin", "A ore vein that is full of tin.", "Revitalize.Ore", Color.Black, -300, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Tin"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Tin"), new Animation(0, 0, 16, 16)), Color.White, false, new Vector2(1, 1), null, null),
                                                    new OreResourceInformation(this.getOre("Tin"), true, true, true, false, new List <IntRange>()
            {
                new IntRange(1, 20)
            }, new List <IntRange>(),
                                                                               (i => i == 1),
                                                                               (i => i % 10 == 0), 1, 3, 1, 10, new IntRange(1, 3), new IntRange(1, 3), new IntRange(0, 0), new List <IntRange>()
            {
                new IntRange(0, 0)
            }, new List <IntRange>()
            {
                new IntRange(0, 9999)
            }, null, null, 0.80d, 0.20d, 0.25d, 1d, 1d, 1, 1, 1, 1), new List <ResourceInformation>(), 4);

            //Aluminum
            OreVein bauxiteOre_0_0 = new OreVein(new BasicItemInformation("Bauxite Ore Vein", "Omegasis.Revitalize.Resources.Ore.Bauxite", "A ore vein that is full of bauxite ore.", "Revitalize.Ore", Color.Black, -300, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Bauxite"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Bauxite"), new Animation(0, 0, 16, 16)), Color.White, false, new Vector2(1, 1), null, null),
                                                 new OreResourceInformation(this.getOre("Bauxite"), true, true, true, false, new List <IntRange>()
            {
                new IntRange(20, 50)
            }, new List <IntRange>(), null, (i => i % 10 == 0), 1, 3, 1, 10, new IntRange(1, 3), new IntRange(1, 3), new IntRange(0, 0), new List <IntRange>()
            {
                new IntRange(0, 0)
            }, new List <IntRange>()
            {
                new IntRange(0, 9999)
            }, null, null, .70d, 0.16d, 0.20d, 1d, 1d, 0, 0, 0, 0), new List <ResourceInformation>(), 5);

            //Silver
            OreVein silverOre_0_0 = new OreVein(new BasicItemInformation("Silver Ore Vein", "Omegasis.Revitalize.Resources.Ore.Silver", "A ore vein that is full of silver ore.", "Revitalize.Ore", Color.Black, -300, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Silver"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Silver"), new Animation(0, 0, 16, 16)), Color.White, false, new Vector2(1, 1), null, null),
                                                new OreResourceInformation(this.getOre("Silver"), true, true, true, false, new List <IntRange>()
            {
                new IntRange(60, 100)
            }, new List <IntRange>(), null, (i => i % 10 == 0), 1, 3, 1, 10, new IntRange(1, 3), new IntRange(1, 3), new IntRange(0, 0), new List <IntRange>()
            {
                new IntRange(0, 0)
            }, new List <IntRange>()
            {
                new IntRange(0, 9999)
            }, null, null, .50d, 0.10d, 0.14d, 1d, 1d, 0, 0, 0, 0), new List <ResourceInformation>(), 6);

            //Lead
            OreVein leadOre_0_0 = new OreVein(new BasicItemInformation("Lead Ore Vein", "Omegasis.Revitalize.Resources.Ore.Lead", "A ore vein that is full of lead ore.", "Revitalize.Ore", Color.Black, -300, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Lead"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Lead"), new Animation(0, 0, 16, 16)), Color.White, false, new Vector2(1, 1), null, null),
                                              new OreResourceInformation(this.getOre("Lead"), true, true, true, false, new List <IntRange>()
            {
                new IntRange(60, 70),
                new IntRange(90, 120)
            }, new List <IntRange>(), null, (i => i % 10 == 0), 1, 3, 1, 10, new IntRange(1, 3), new IntRange(1, 3), new IntRange(0, 0), new List <IntRange>()
            {
                new IntRange(0, 0)
            }, new List <IntRange>()
            {
                new IntRange(0, 9999)
            }, null, null, .60d, 0.13d, 0.17d, 1d, 1d, 0, 0, 0, 0), new List <ResourceInformation>(), 7);

            //Titanium
            OreVein titaniumOre_0_0 = new OreVein(new BasicItemInformation("Titanium Ore Vein", "Revitalize.Resources.Ore.Titanium", "A ore vein that is full of lead ore.", "Revitalize.Ore", Color.Black, -300, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Titanium"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Titanium"), new Animation(0, 0, 16, 16)), Color.White, false, new Vector2(1, 1), null, null),
                                                  new OreResourceInformation(this.getOre("Titanium"), true, true, true, false, new List <IntRange>()
            {
                new IntRange(60, 70),
                new IntRange(90, 120)
            }, new List <IntRange>(), null, (i => i % 10 == 0), 1, 3, 1, 10, new IntRange(1, 3), new IntRange(1, 3), new IntRange(0, 0), new List <IntRange>()
            {
                new IntRange(0, 0)
            }, new List <IntRange>()
            {
                new IntRange(0, 9999)
            }, null, null, .40d, 0.05d, 0.10d, 1d, 1d, 0, 0, 0, 0), new List <ResourceInformation>(), 8);

            //Prismatic nugget ore
            OreVein prismaticOre_0_0 = new OreVein(new BasicItemInformation("Prismatic Ore Vein", "Revitalize.Resources.Ore.Prismatic", "A ore vein that is full of prismatic ore.", "Revitalize.Ore", Color.Black, -300, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Prismatic"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Prismatic"), new Animation(0, 0, 16, 16)), Color.White, false, new Vector2(1, 1), null, null),
                                                   new OreResourceInformation(this.getOre("PrismaticNugget"), true, true, true, false, new List <IntRange>()
            {
                new IntRange(110, 120)
            }, new List <IntRange>(), null, (i => i % 10 == 0), 1, 3, 1, 1, new IntRange(1, 1), new IntRange(1, 1), new IntRange(1, 5), new List <IntRange>()
            {
                new IntRange(1, 9999)
            }, new List <IntRange>()
            {
            }, null, null, .05d, 0.01d, 0.01d, 0.10, 1d, 1, 1, 1, 1), new List <ResourceInformation>(), 10);


            oreVeins.Add(tinOre_0_0);
            oreVeins.Add(bauxiteOre_0_0);
            oreVeins.Add(silverOre_0_0);
            oreVeins.Add(leadOre_0_0);
            oreVeins.Add(titaniumOre_0_0);
            oreVeins.Add(prismaticOre_0_0);
            return(oreVeins);
        }
Ejemplo n.º 6
0
    //interraction avec l'objet sur lequel l'utilisateur clique
    void interract(Vector2 screenPosition)
    {
        RaycastHit2D hit = Physics2D.Raycast(screenPosition, Vector2.zero);

        if (hit.transform != null && hit.transform.gameObject.layer == 5)
        {
            return;                                                                  //use to prevent from clickink through UI
        }
        StopCoroutine("move");
        deselection();
        //rotateToTarget(screenPosition);
        if (hit.collider != null)
        {
            playerGridPos = new Vector2(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y));
            Vector2 hitGridPos = new Vector2(Mathf.Round(hit.collider.transform.position.x), Mathf.Round(hit.collider.transform.position.y));

            if (hit.collider.tag == "Destructible" &&         //check if a destructible is hit
                Vector2.Distance(hit.collider.transform.position, gameObject.transform.position) <= maxInteractionDistance)                   //check if the distance between the play and the object is correct
            {
                if (hit.collider.gameObject.GetComponent <OreVein> () != null)
                {
                    OreVein oreVein = hit.collider.gameObject.GetComponent <OreVein> ();
                    oreVein.damage(digDamages [oreVein.getType()]);
                }
                else
                {
                    hit.collider.gameObject.GetComponent <Destructible> ().damage(digDamagesToRocks);
                }
                rotateToTarget(hit.collider.transform.position);
                audioSource.PlayOneShot(digSound);
                endPlaceBuilding();
            }
            else if ((hit.collider.tag == "Floor" && placingObject) &&           //building construction
                     Vector2.Distance(hit.collider.transform.position, gameObject.transform.position) <= maxConstructionDistance &&               //check if the distance between the play and the object is correct
                     (Mathf.Abs(playerGridPos.x - hitGridPos.x) > 0.01f || Mathf.Abs(playerGridPos.y - hitGridPos.y) > 0.01f))                      //check if the selected case is not player's case
            {
                if (enoughRessources(buildingToPlace.GetComponent <Building>().getCosts()))
                {
                    mapManager.placeBuilding(buildingToPlace, hit.collider.transform.position);
                }
                else
                {
                    PopupMessage.instance.ShowMessage("Not enough ressources");
                }
                //endPlaceBuilding ();
            }
            else if ((hit.collider.tag == "Item") &&          //item collection
                     Vector2.Distance(hit.collider.transform.position, gameObject.transform.position) <= maxInteractionDistance)                 //check if the distance between the play and the object is correct
            {
                if (hit.collider.gameObject.GetComponent <Item> ().collect())
                {
                    audioSource.PlayOneShot(collectSound);
                }
            }
            else if (hit.collider.tag == "Building" && !placingObject)              //building selection
            {
                selectedTile    = hit.collider.gameObject;
                buildingToPlace = null;
                if (itemSlot != null && itemSlot.GetComponent <UsableItem> () != null &&
                    selectedTile.GetComponent <Building> ().hasUpgrade(itemSlot.GetComponent <UsableItem> ().type))
                {
                    buildingToPlace = selectedTile;
                }
                //UIManager.instance.getCostsBar().updateDisplay ();
                selectedTile.GetComponent <Building> ().selection();
                if (OnSelectBuildingEvent != null)
                {
                    OnSelectBuildingEvent();
                }
            }
            else
            {
                Debug.Log("Rien touché");
            }
            if (placingObject)
            {
                endPlaceBuilding();
            }
        }
    }
Ejemplo n.º 7
0
 public OreSpace(Vector2 location, int oreCount, OreVein oreVein)
 {
     this.location = location;
     this.oreCount = oreCount;
     this.oreVein  = oreVein;
 }