예제 #1
0
        // Track a crop
        public static void trackCrop(Pipliz.Vector3Int location, GrowableType classInstance, bool save = false)
        {
            long   nextUpdate    = (long)(Pipliz.Time.MillisecondsSinceStart + classInstance.maxGrowth * Pipliz.Random.NextFloat(classInstance.growthMultiplierMin, classInstance.growthMultiplierMax) * 60000);
            string cropLocString = ColonyAPI.Managers.WorldManager.XYZPositionToString(location);

            CropTracker.Add(cropLocString, location);


            // add it to the update list
            if (CropUpdateHolder.ContainsKey(nextUpdate))
            {
                // other crops are set to update at this time too, so add this to the list
                CropUpdateHolder[nextUpdate].Add(cropLocString);
            }
            else
            {
                // no crops are currently setup to update at this time, make a new list
                CropUpdateHolder.Add(nextUpdate, new List <string>()
                {
                    cropLocString
                });
            }

            if (save == true)
            {
                SaveCropTracker();
            }
        }
예제 #2
0
        // Stop tracking a crop
        public static void untrackCrop(Pipliz.Vector3Int location, GrowableType classInstance, bool save = false)
        {
            // check if it's being tracked, if so remove it
            string cropLocString = ColonyAPI.Managers.WorldManager.XYZPositionToString(location);

            if (CropTracker.ContainsKey(cropLocString))
            {
                CropTracker.Remove(cropLocString);
            }

            if (save == true)
            {
                SaveCropTracker();
            }
        }
예제 #3
0
    public int CountChildren(GrowableType type, bool recursive = false)
    {
        Assert.IsTrue(Children.ContainsKey(type), "Keys must be initialized in the constructor.");

        int count = Children[type].Count;

        if (recursive)
        {
            foreach (AGrowable growable in Children[type])
            {
                count += growable.CountChildren(type, recursive);
            }
        }

        return(count);
    }
예제 #4
0
    // Params, they must be configurable

    public AGrowable(Tree owner, GameObject gameObject, GrowableType type, Vector3 scale, float maxSize, float relativePercentPosition, EnergyRegulator.EnergyData energyData)
    {
        Owner      = owner;
        GameObject = gameObject;
        Type       = type;
        Scale      = scale;
        RelativePercentPosition = relativePercentPosition;
        EnergyRegulator         = new EnergyRegulator(energyData);

        // Initialiaze the children container
        Children = new Dictionary <GrowableType, List <AGrowable> >();
        foreach (GrowableType growableType in (GrowableType[])Enum.GetValues(typeof(GrowableType)))
        {
            Children[growableType] = new List <AGrowable>();
        }
        Depth       = 0;
        CurrentSize = 0;
        MaxSize     = maxSize;
        Parent      = null;
    }
예제 #5
0
        // Run this every 500ms
        public static void doCropUpdates()
        {
            Profiler.BeginSample("CropUpdate");

            long updateStartTime = Pipliz.Time.MillisecondsSinceStart;



            // Do we have crops in the world?
            if (CropUpdateHolder.Count > 0)
            {
                // A dictionary to store a list of keys
                Dictionary <long, List <string> > CropsToUpdate = CropUpdateHolder.Where(c => c.Key < updateStartTime).ToDictionary(k => k.Key, k => k.Value);

                // we have crops to update!
                if (CropsToUpdate.Count > 0)
                {
                    // loop through each expired time
                    foreach (long time in CropsToUpdate.Keys)
                    {
                        // does the child lsit have a nice list of crops to update at this time?
                        if (CropsToUpdate[time].Count > 0)
                        {
                            foreach (string cropLocString in CropsToUpdate[time])
                            {
                                // get the instance of the crop tracker and check it exists!
                                if (!CropTracker.ContainsKey(cropLocString))
                                {
                                    // it doesn't exist, so just ignore it
                                    continue;
                                }

                                ushort currentBlockID;
                                World.TryGetTypeAt(CropTracker[cropLocString], out currentBlockID);

                                string currentBlockName = ItemTypes.IndexLookup.GetName(currentBlockID);

                                // check if it can be updated
                                if (hasProgression(currentBlockName))
                                {
                                    //Utilities.WriteLog("Can update " + currentBlockName);
                                    // get the new stage
                                    string newBlockName = getNextStage(currentBlockName);

                                    // update the block
                                    updateBlock(CropTracker[cropLocString], newBlockName);

                                    // check this isn't the last stage
                                    if (hasProgression(newBlockName))
                                    {
                                        // Utilities.WriteLog("Is not last stage!" + newBlockName);
                                        // update the next update time

                                        // get a new classinstance to calculate the proper growth time
                                        GrowableType g = CropTypes[newBlockName];
                                        float        growthMulitiplier = ColonyAPI.Managers.ConfigManager.getConfigFloat("ColonyPlusPlus-Core", "crops.growthMultiplier");
                                        if (growthMulitiplier == 0f)
                                        {
                                            growthMulitiplier = 1f;
                                        }
                                        long nextUpdate = (long)(Pipliz.Time.MillisecondsSinceStart + g.maxGrowth * growthMulitiplier * Pipliz.Random.NextFloat(g.growthMultiplierMin, g.growthMultiplierMax) * 60000);

                                        // add it to the update list
                                        if (CropUpdateHolder.ContainsKey(nextUpdate))
                                        {
                                            // other crops are set to update at this time too, so add this to the list
                                            CropUpdateHolder[nextUpdate].Add(cropLocString);
                                        }
                                        else
                                        {
                                            // no crops are currently setup to update at this time, make a new list
                                            CropUpdateHolder.Add(nextUpdate, new List <string>()
                                            {
                                                cropLocString
                                            });
                                        }
                                    }
                                    else
                                    {
                                        // this is the last stage, remove it from the croptracker too!
                                        CropTracker.Remove(cropLocString);
                                    }
                                }
                                else
                                {
                                    // this should have been removed but wasn't... remove it now I guess...
                                    CropTracker.Remove(cropLocString);
                                }
                            }
                        }

                        // remove the crop update holder, it'll be re-added anyway for the enxt update
                        CropUpdateHolder.Remove(time);
                        ColonyAPI.Helpers.Utilities.WriteLog("ColonyPlusPlus-Core", "Now tracking:" + CropTracker.Count + " crops");
                    }

                    SaveCropTracker();
                }
            }

            Profiler.EndSample();
        }
예제 #6
0
 public static void loadTrackCrop(Pipliz.Vector3Int location, GrowableType classInstance)
 {
     trackCrop(location, classInstance);
     //SaveCropTracker();
 }
예제 #7
0
 // Register the crop in the growable Types list.
 public static void registerCrop(GrowableType classInstance)
 {
     GrowableTypesTracker.Add(classInstance);
 }