public void AddResource(ResourceType type, double value, int amount = 1)
        {
            Resource     resource     = new Resource(type, type.Weight(), 1f);
            ResourcePile resourcePile = new ResourcePile(resource, amount);

            resources.Add(resourcePile);
        }
        public void CreateResourcePile(ResourcePile pile)
        {
            engine.CreateObject(pile.UnityId, MapObject.ResourcesPile, pile.location.X, pile.location.Y);

            var color = resourceColor[pile.Resource];

            engine.SetColor(pile.UnityId, color.r, color.g, color.b);
        }
Beispiel #3
0
    public void GatheringResources()
    {
        if (Gathering == true)
        {
            Gathering = uiMan.GatheringMaster;

            float        dist        = Mathf.Infinity;
            ResourcePile nearestPile = null;

            ResourcePile[] pileList = GameObject.FindObjectsOfType <ResourcePile>();

            foreach (PlayerFarmer f in PlayerList)
            {
                foreach (ResourcePile p in pileList)
                {
                    float d = Vector3.Distance(this.transform.position, p.transform.position);


                    if (d < dist)
                    {
                        nearestPile = p;
                        dist        = d;
                        Target      = nearestPile.gameObject;
                    }


                    if (Gathering == true && Target != null)
                    {
                        if (currentResources <= 0)
                        {
                            Debug.Log("Going to gather");
                            myAgent.SetDestination(Target.transform.position);
                        }
                        if (currentResources >= 1)
                        {
                            Debug.Log("Returning to dumpster");

                            myAgent.SetDestination(Dumpster.transform.position);
                        }
                    }
                }
            }
            if (currentResources >= 1 && Gathering == true)
            {
                Debug.Log("Returning to dumpster");

                myAgent.SetDestination(Dumpster.transform.position);
            }
            if (currentResources <= 0 && Gathering == true)
            {
                Debug.Log("Returning to dumpster");

                myAgent.SetDestination(Target.transform.position);
            }
        }
    }
Beispiel #4
0
    void Update()
    {
        int hits = Physics2D.BoxCastNonAlloc(box.bounds.center, box.bounds.extents, 0f, Vector2.up, scan, 0.1f, 1 << LayerMask.NameToLayer("ResourcePile"));

        if (hits > 0)
        {
            for (int i = 0; i < hits; i++)
            {
                ResourcePile resPile = scan[i].collider.gameObject.GetComponent <ResourcePile>();
                resPile.ClearVisuals();
            }
            UpdateGUI();
        }
    }
Beispiel #5
0
    /// <summary>
    /// This function checks if the type of ResourcePile required by the Cart is Available with Resources.
    /// </summary>
    /// <returns><c>true</c>, if for required pile was looked, <c>false</c> otherwise.</returns>
    bool LookForRequiredPile()
    {
        ResourcePile[] objects = FindObjectsOfType <ResourcePile>();

        foreach (ResourcePile resource in objects)
        {
            if (resource.pileResourceType == cartResourceType)
            {
                if (resource.ammount > 0)
                {
                    targetResourcePile = resource;
                    //Debug.Log("Found a Resource Pile of Type : " + targetResourcePile.pileResourceType);
                    return(true);
                }
            }
        }

        //Debug.Log("No Resource Pile of Type : " + cartResourceType.resourceName + " found with available resources!" );
        return(false);
    }
Beispiel #6
0
    public void ProcessPile(ResourcePile resPile)
    {
        var pileItems = resPile.GetResourceList();

        foreach (var type in pileItems.Keys)
        {
            if (type == ResourceType.People)
            {
                for (int p = 0; p < pileItems[type]; ++p)
                {
                    folowerManager.AddNewAgent(followerSpawn.position);
                }
            }
            if (campInventory.ContainsKey(type))
            {
                campInventory[type] += pileItems[type];
            }
            else
            {
                campInventory.Add(type, pileItems[type]);
            }
        }
        resPile.ClearData();
    }
Beispiel #7
0
        /// <summary>
        /// Chatmetaleux's method to fix the ghost items (experimental)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>This only fix a bug in saved games, not the cause !</remarks>
        private void FixGhostItems_Click(object sender, RoutedEventArgs e)
        {
            int cnt = 0;
            // search for crates
            var results = GnomanEmpire.Instance.Fortress.StockManager.ItemsByItemID(GameLibrary.ItemID.Crate.ToString());

            if (results != null)
            {
                foreach (var valuePair in results)
                {
                    List <Game.Item> list = valuePair.Value;
                    foreach (Game.Item item in list)
                    {
                        if (item.Claimed && item.ClaimedBy == null)
                        {
                            AddStatusText(string.Format("container claimed @{0} : {1}", item.Position.ToString(), item.Name()));
                            StorageContainer sc = (StorageContainer)item;
                            foreach (Item it in sc.ContainedResources)
                            {
                                it.FixClaimedItems();
                                AddStatusText(string.Format("fix container->{0} ", it.Name()));
                            }
                            AddStatusText("container still claimed ? " + item.Claimed.ToString());
                            cnt++;
                        }
                    }
                }
            }
            AddStatusText(string.Format("Done. {0} containers fixed.", cnt));
            cnt = 0;

            // search for piles
            for (int z = 0; z < GnomanEmpire.Instance.Map.MapHeight; z++)
            {
                for (int height = 0; height < GnomanEmpire.Instance.Map.MapHeight; ++height)
                {
                    for (int width = 0; width < GnomanEmpire.Instance.Map.MapWidth; ++width)
                    {
                        foreach (GameEntity ge in GnomanEmpire.Instance.Map.Levels[z][height][width].Objects)
                        {
                            if (ge is Game.ResourcePile)
                            {
                                ResourcePile rp = (ResourcePile)ge;
                                AddStatusText(string.Format("pile @{0} : {1}", rp.Position.ToString(), rp.Name()));
                                foreach (Item it in rp.ContainedResources)
                                {
                                    it.FixClaimedItems();
                                }
                                cnt++;
                            }
                            else if (ge is Game.StorageContainer)
                            {
                                StorageContainer sc = (StorageContainer)ge;
                                AddStatusText(string.Format("container @{0} : {1}", sc.Position.ToString(), sc.Name()));
                                foreach (Item it in sc.ContainedResources)
                                {
                                    it.FixClaimedItems();
                                }
                                cnt++;
                            }
                        }
                        if (GnomanEmpire.Instance.Map.Levels[z][height][width].EmbeddedWall is ConstructedContainer) // container on stockpile
                        {
                            ConstructedContainer cc = (ConstructedContainer)GnomanEmpire.Instance.Map.Levels[z][height][width].EmbeddedWall;
                            AddStatusText(string.Format("container stockpile @z{0} y{1} x{2} ", z, height, width));
                            foreach (Item it in cc.Container.ContainedResources)
                            {
                                it.FixClaimedItems();
                            }
                            cc.Container.FixClaimedItems();
                            cnt++;
                        }
                    }
                }
            }
            AddStatusText(string.Format("Done. {0} piles/container fixed.", cnt));
        }
 public void AddResource(ResourcePile resource)
 {
     resources.Add(resource);
 }