Exemplo n.º 1
0
        public bool addComponent(Vector2 key, MultiTiledComponent obj)
        {
            if (this.objects.ContainsKey(key))
            {
                ModCore.log("Bad DATA");
                return(false);
            }

            this.objects.Add(key, obj);
            if (this.childrenGuids.ContainsKey(key) == false)
            {
                this.childrenGuids.Add(key, obj.guid);
            }


            if (key.X > this.width)
            {
                this.width = (int)key.X;
            }
            if (key.Y > this.height)
            {
                this.height = (int)key.Y;
            }
            (obj as MultiTiledComponent).containerObject = this;
            (obj as MultiTiledComponent).offsetKey       = key;
            this.info.forceUpdate();
            return(true);
        }
        public override ICustomObject recreate(Dictionary <string, string> additionalSaveData, object replacement)
        {
            //instead of using this.offsetkey.x use get additional save data function and store offset key there

            Vector2             offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"]));
            MultiTiledComponent self      = Revitalize.ModCore.Serializer.DeserializeGUID <MultiTiledComponent>(additionalSaveData["GUID"]);

            if (self == null)
            {
                return(null);
            }

            if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
            {
                //Get new container
                MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID <MultiTiledObject>(additionalSaveData["ParentGUID"]);
                self.containerObject = obj;
                obj.addComponent(offsetKey, self);
                //Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
                Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (MultiTiledObject)obj);
            }
            else
            {
                self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]];
                Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self);
                //Revitalize.ModCore.log("READD AN OBJECT!!!!");
            }

            return((ICustomObject)self);
        }
        protected virtual List <MultiTiledObject> FluidGraphSearchInputTanksThatCanAcceptThisFluid(Fluid L)
        {
            List <MultiTiledObject>    fluidSources       = new List <MultiTiledObject>();
            List <MultiTiledComponent> searchedComponents = new List <MultiTiledComponent>();
            List <MultiTiledComponent> entitiesToSearch   = new List <MultiTiledComponent>();

            entitiesToSearch.AddRange(this.GetNeighboringFluidManagers());
            searchedComponents.Add(this);
            while (entitiesToSearch.Count > 0)
            {
                MultiTiledComponent searchComponent = entitiesToSearch[0];
                entitiesToSearch.Remove(searchComponent);
                if (searchedComponents.Contains(searchComponent))
                {
                    continue;
                }
                else
                {
                    searchedComponents.Add(searchComponent);
                    entitiesToSearch.AddRange(searchComponent.GetNeighboringFluidManagers());

                    if (searchComponent.containerObject.info.fluidManager.canRecieveThisFluid(L))
                    {
                        fluidSources.Add(searchComponent.containerObject);
                    }
                }
            }
            return(fluidSources);
        }
        /// <summary>
        /// Gets all of the energy nodes in a network that are either consumers or storage. This should ALWAYS be ran after EnergyGraphSearchSources
        /// </summary>
        /// <returns></returns>
        protected virtual List <MultiTiledObject> EnergyGraphSearchConsumers()
        {
            List <MultiTiledObject>    energySources      = new List <MultiTiledObject>();
            List <MultiTiledComponent> searchedComponents = new List <MultiTiledComponent>();
            List <MultiTiledComponent> entitiesToSearch   = new List <MultiTiledComponent>();

            entitiesToSearch.AddRange(this.getAppropriateEnergyNeighbors());
            searchedComponents.Add(this);
            while (entitiesToSearch.Count > 0)
            {
                MultiTiledComponent searchComponent = entitiesToSearch[0];
                entitiesToSearch.Remove(searchComponent);
                if (searchedComponents.Contains(searchComponent))
                {
                    continue;
                }
                else
                {
                    searchedComponents.Add(searchComponent);
                    entitiesToSearch.AddRange(searchComponent.getAppropriateEnergyNeighbors());

                    if (searchComponent.containerObject.info.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Consumes || searchComponent.containerObject.info.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Storage)
                    {
                        energySources.Add(searchComponent.containerObject);
                    }
                }
            }
            return(energySources);
        }
        /// <summary>
        /// Searches a network of fluid managers to see if any of these fluid managers have an output tank with the corresponding fluid.
        /// </summary>
        /// <param name="L"></param>
        /// <returns></returns>
        protected virtual List <MultiTiledObject> FluidGraphSearchForFluidFromOutputTanks(Fluid L)
        {
            List <MultiTiledObject>     fluidSources       = new List <MultiTiledObject>();
            HashSet <Guid>              searchedComponents = new HashSet <Guid>();
            Queue <MultiTiledComponent> entitiesToSearch   = new Queue <MultiTiledComponent>();
            HashSet <Guid>              searchedObjects    = new HashSet <Guid>();

            foreach (MultiTiledComponent tile in this.GetNeighboringFluidManagers())
            {
                entitiesToSearch.Enqueue(tile);
            }
            //entitiesToSearch.AddRange(this.GetNeighboringFluidManagers());
            searchedComponents.Add(this.guid);
            while (entitiesToSearch.Count > 0)
            {
                MultiTiledComponent searchComponent = entitiesToSearch.Dequeue();
                //entitiesToSearch.Remove(searchComponent);
                if (searchedComponents.Contains(searchComponent.guid))
                {
                    continue;
                }

                /*
                 * else if (searchedObjects.Contains(searchComponent.containerObject))
                 * {
                 *  continue;
                 * }
                 */
                else
                {
                    searchedComponents.Add(searchComponent.guid);
                    searchedObjects.Add(searchComponent.containerObject.guid);

                    List <MultiTiledComponent> neighbors = searchComponent.GetNeighboringFluidManagers();

                    foreach (MultiTiledComponent tile in neighbors)
                    {
                        if (searchedObjects.Contains(tile.containerObject.guid) || searchedComponents.Contains(tile.guid))
                        {
                            continue;
                        }
                        else
                        {
                            entitiesToSearch.Enqueue(tile);
                        }
                    }

                    if (searchComponent.containerObject.info.fluidManager.doesThisOutputTankContainThisFluid(L))
                    {
                        fluidSources.Add(searchComponent.containerObject);
                        //ModCore.log("Found a tank that contains this fluid!");
                    }
                }
            }
            return(fluidSources);
        }
Exemplo n.º 6
0
 public MultiTiledObject(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Dictionary <Vector2, MultiTiledComponent> ObjectsList)
     : base(PyTKData, info, TileLocation)
 {
     this.objects       = new Dictionary <Vector2, StardewValley.Object>();
     this.childrenGuids = new Dictionary <Vector2, Guid>();
     foreach (var v in ObjectsList)
     {
         MultiTiledComponent component = (MultiTiledComponent)v.Value.getOne();
         this.addComponent(v.Key, component);
     }
 }
Exemplo n.º 7
0
 public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary <Vector2, MultiTiledComponent> ObjectsList)
     : base(info, TileLocation)
 {
     this.objects       = new Dictionary <Vector2, StardewValley.Object>();
     this.childrenGuids = new Dictionary <Vector2, Guid>();
     foreach (var v in ObjectsList)
     {
         MultiTiledComponent component = (MultiTiledComponent)v.Value.getOne();
         this.addComponent(v.Key, (component as MultiTiledComponent));
     }
     this.guid = Guid.NewGuid();
 }
Exemplo n.º 8
0
        public bool addComponent(Vector2 key, MultiTiledComponent obj)
        {
            if (this.objects.ContainsKey(key))
            {
                return(false);
            }

            this.objects.Add(key, obj);
            this.childrenGuids.Add(key, Guid.NewGuid());

            if (key.X > this.width)
            {
                this.width = (int)key.X;
            }
            if (key.Y > this.height)
            {
                this.height = (int)key.Y;
            }
            (obj as MultiTiledComponent).containerObject = this;
            (obj as MultiTiledComponent).offsetKey       = key;
            return(true);
        }
Exemplo n.º 9
0
        public override ICustomObject recreate(Dictionary <string, string> additionalSaveData, object replacement)
        {
            MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID <MultiTiledObject>(additionalSaveData["GUID"]);

            if (obj == null)
            {
                return(null);
            }

            Dictionary <Vector2, Guid> guids = new Dictionary <Vector2, Guid>();

            foreach (KeyValuePair <Vector2, Guid> pair in obj.childrenGuids)
            {
                guids.Add(pair.Key, pair.Value);
            }

            foreach (KeyValuePair <Vector2, Guid> pair  in guids)
            {
                obj.childrenGuids.Remove(pair.Key);
                //Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString());
                MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID <MultiTiledComponent>(pair.Value.ToString());
                component.InitNetFields();

                obj.addComponent(pair.Key, component);
            }
            obj.InitNetFields();

            if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"]))
            {
                Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj);
                return(obj);
            }
            else
            {
                return(Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]]);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Recreate the data from data already stored on the object.
        /// </summary>
        public virtual void recreate()
        {
            Dictionary <Vector2, Guid> guids = new Dictionary <Vector2, Guid>();

            foreach (KeyValuePair <Vector2, Guid> pair in this.childrenGuids)
            {
                guids.Add(pair.Key, pair.Value);
            }

            foreach (KeyValuePair <Vector2, Guid> pair in guids)
            {
                this.childrenGuids.Remove(pair.Key);
                MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID <MultiTiledComponent>(pair.Value.ToString());
                component.InitNetFields();
                this.removeComponent(pair.Key);
                this.addComponent(pair.Key, component);
            }
            this.InitNetFields();

            if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
            {
                Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
            }
        }
        public override Item getOne()
        {
            MultiTiledComponent component = new MultiTiledComponent(this.info, this.TileLocation, this.offsetKey, this.containerObject);

            return(component);
        }