Ejemplo n.º 1
0
        public override void Resolve(GameLocation location, BaseFeatureSaveData featureSaveData)
        {
            Tree         currentTree  = location.terrainFeatures[featureSaveData.FeaturePosition] as Tree;
            TreeSaveData treeSaveData = featureSaveData as TreeSaveData;

            currentTree.stump.Value  = false;
            currentTree.health.Value = treeSaveData.health;
            this.reflectionHelper.GetField <NetBool>(currentTree, "falling").GetValue().Value = false;

            this.monitor.Log($"Stopped {currentTree.GetType()} at position {featureSaveData.Feature} from falling.", LogLevel.Trace);
        }
Ejemplo n.º 2
0
        public override void Handle(BaseFeatureSaveData featureSaveData, GameLocation location)
        {
            Tree         tree         = location.terrainFeatures[featureSaveData.FeaturePosition] as Tree;
            TreeSaveData treeSaveData = featureSaveData as TreeSaveData;

            //Growth stages 0 - 2 are instantly removed, so there are no side effects

            tree.health.Value = treeSaveData.health;

            if (tree.growthStage.Value >= 3)
            {
                int min   = 5;
                int max   = 8;
                int total = 30;

                //Trees at growth stage >5 spawn 2 debris with chunkType 92 each with 1 chunk (sap)
                //This must be a stump.
                if (tree.growthStage.Value >= 5)
                {
                    int numToRemove = 2;
                    for (int i = 0; i < location.debris.Count; i++)
                    {
                        Debris debris = location.debris[i];

                        if (debris.chunkType.Value == 92 && debris.debrisType.Value == Debris.DebrisType.RESOURCE &&
                            debris.Chunks.Count == 1)
                        {
                            if (!this.WithinRange(featureSaveData.FeaturePosition,
                                                  debris.Chunks[0].position.Value / Game1.tileSize, 2))
                            {
                                continue;
                            }

                            location.debris.RemoveAt(i);
                            numToRemove--;
                            i--;

                            this.monitor.Log($"Removing sap for stage 5 stump. {numToRemove} left.", LogLevel.Trace);

                            if (numToRemove == 0)
                            {
                                break;
                            }
                        }
                    }

                    min   = 7;
                    max   = 10;
                    total = 40;
                }
                else
                {
                    //Trees at growth stage [3,4] spawn 1 debris with chunkType 388 with 4 chunks, each chunk has type 388 or 389 (extra wood)
                    for (int i = 0; i < location.debris.Count; i++)
                    {
                        Debris debris = location.debris[i];

                        if (debris.chunkType.Value == 388 && debris.debrisType.Value == Debris.DebrisType.RESOURCE)
                        {
                            if (debris.Chunks.Count == 4 &&
                                (debris.Chunks[0].debrisType == 388 || debris.Chunks[0].debrisType == 389))
                            {
                                if (!this.WithinRange(featureSaveData.FeaturePosition,
                                                      debris.Chunks[0].position.Value / Game1.tileSize, 2))
                                {
                                    continue;
                                }

                                this.monitor.Log($"Removing 4 extra wood for tree stages 3 and 4.", LogLevel.Trace);

                                location.debris.RemoveAt(i);
                                break;
                            }
                        }
                    }
                }

                //Trees of stage >3 spawn 4 chunks of up to total items, each chunk of size [min,max] with chunkType 12 and the chunks have debrisType 12
                int numRemoved = 0;
                for (int i = 0; i < location.debris.Count; i++)
                {
                    Debris debris = location.debris[i];

                    if (debris.chunkType.Value == 12 && debris.debrisType.Value == Debris.DebrisType.CHUNKS)
                    {
                        if (debris.Chunks.Count >= min && debris.Chunks.Count <= max &&
                            debris.Chunks[0].debrisType == 12)
                        {
                            if (!this.WithinRange(featureSaveData.FeaturePosition,
                                                  debris.Chunks[0].position.Value / Game1.tileSize, 3) ||
                                numRemoved + debris.Chunks.Count > total)
                            {
                                continue;
                            }

                            this.monitor.Log(
                                $"Removing wood, count: {debris.Chunks.Count}, total: {numRemoved + debris.Chunks.Count}/{total}.",
                                LogLevel.Trace);
                            numRemoved += debris.Chunks.Count;
                            location.debris.RemoveAt(i);
                            i--;
                            if (numRemoved == total)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }