Ejemplo n.º 1
0
        public static void Postfix(Tool t, int explosion, Vector2 tileLocation, GameLocation location, Tree __instance)
        {
            if (__instance.health.Value > 0)
            {
                return;
            }
            if (!TreeHandler.currentTrees.ContainsKey(__instance))
            {
                Logger.log("Tree not found!");
                return;
            }
            TreeRenderer renderer   = TreeHandler.currentTrees[__instance];
            int          treeHeight = renderer.treeStructure.getExtent(new Type[] { typeof(Stump), typeof(Trunk) });
            bool         falling    = Reflector.reflector.GetField <bool>(__instance, "falling").GetValue();

            if (falling)
            {
                if (t != null && t.getLastFarmerToUse().IsLocalPlayer)
                {
                    if (t != null)
                    {
                        t.getLastFarmerToUse().gainExperience(2, (1 * treeHeight));
                    }
                }
                Game1.createDebris(12, (int)tileLocation.X, (int)tileLocation.Y, 4, (GameLocation)null);
                Game1.createRadialDebris(location, 12, (int)tileLocation.X, (int)tileLocation.Y, Game1.random.Next(20, 30), false, -1, false, -1);
            }
        }
Ejemplo n.º 2
0
        public virtual void addGravity(bool addToChildren = false)
        {
            float massHeld = getExtent() / 10f;
            float distance = renderer.treeStructure.getHeightOf(this, new Type[] { typeof(Stump), typeof(Trunk) }) / 10f;

            float parentRotation = renderer.treeStructure.findTotalRotationOfChild(this) - rotation;

            Logger.log("Limb has a weight of " + massHeld + ", and a distance of " + distance);

            float rotationFactor = Math.Max((massHeld * (1 - renderer.species.limbStregnth)) - (distance * (1 - renderer.species.limbStregnth) * 0.5f), 0f);

            Logger.log("Rotation factor = " + rotationFactor + "; Max(" + massHeld + " * " + renderer.species.limbStregnth + ") - (" + distance + " * " + renderer.species.limbStregnth + " * 0.5), 0)");

            //float newRot = ((rotationFactor * TreeRenderer.degreesToRadians(180f)) + rotation) / 2f - parentRotation;

            float rotDifference = TreeRenderer.degreesToRadians(180f) - (rotation + parentRotation);

            float newRot = (rotDifference * rotationFactor) + rotation;

            Logger.log("Rotating to " + TreeRenderer.radiansToDegrees(newRot) + " degrees...");
            rotation = newRot;

            if (addToChildren)
            {
                foreach (TreePart child in children)
                {
                    if (child is Limb)
                    {
                        (child as Limb).addGravity(addToChildren);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public Limb(TreeRenderer renderer, Microsoft.Xna.Framework.Rectangle sprite)
 {
     children      = new List <TreePart>();
     spriteSheet   = renderer.species.treeSheet;
     this.renderer = renderer;
     this.sprite   = sprite;
     rotation      = 0f;
     depth         = 0;
 }
Ejemplo n.º 4
0
 public LeafCluster(TreeRenderer renderer, Microsoft.Xna.Framework.Rectangle sprite, Color tint)
 {
     children      = new List <TreePart>();
     spriteSheet   = renderer.species.treeSheet;
     this.renderer = renderer;
     this.sprite   = sprite;
     this.tint     = tint;
     rotation      = 0f;
     depth         = -1;
 }
Ejemplo n.º 5
0
        public static void createAllTrees(GameLocation location)
        {
            currentTrees.Clear();

            if (location == null)
            {
                return;
            }

            foreach (Vector2 position in location.terrainFeatures.Keys)
            {
                if (location.terrainFeatures[position] is Tree)
                {
                    Tree tree = (Tree)(location.terrainFeatures[position]);
                    if (tree.growthStage > 3)
                    {
                        currentTrees[tree] = new TreeRenderer(tree, position);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void loadFromJSON(int treeType)
        {
            JObject treeJSON;

            try
            {
                treeJSON = Loader.load <JObject>("Trees/Tree_" + treeType + ".json", "Content/Trees/Tree_" + treeType + ".json") as JObject;
            }
            catch (Microsoft.Xna.Framework.Content.ContentLoadException e)
            {
                Logger.log("No tree json file found at Trees/Tree_" + treeType + "!", LogLevel.Error);
                if (treeType != 1)
                {
                    Logger.log("Trying to default to Tree_1...");
                    loadFromJSON(1);
                    return;
                }
                else
                {
                    throw e;
                }
            }

            Logger.log("Successfully located the tree json file for Tree_" + treeType);

            if (!treeJSON.ContainsKey("Format") || !treeJSON.ContainsKey("Structure") || !treeJSON.ContainsKey("Graphics"))
            {
                throw new KeyNotFoundException("Tree json is missing a vital field!  Missing:" + (treeJSON.ContainsKey("Format") ? " Format" : "") + (treeJSON.ContainsKey("Structure") ? " Structure" : "") + (treeJSON.ContainsKey("Graphics") ? " Graphics" : ""));
            }

            float format = Convert.ToSingle(treeJSON["Format"].ToString());

            if (format != 1.0f)
            {
                throw new Exception("Format " + format + " not expected!  No such format currently exists.  Maybe you need to update Map Utilites?");
            }



            JObject graphics = treeJSON["Graphics"] as JObject;

            string imageName = graphics["Sheet"].ToString();

            try
            {
                treeSheet = Loader.load <Texture2D>("Trees/" + imageName, "Content/Trees/" + imageName + ".png") as Texture2D;
            }
            catch (Microsoft.Xna.Framework.Content.ContentLoadException e)
            {
                Logger.log("Could not find tree sprite sheet '" + imageName + "', as defined in Tree_" + treeType + ".json!", LogLevel.Error);
                throw e;
            }

            makeWeightedRectsFromJSON(graphics["Stump"] as JArray, ref weightedStumpRects, ref weightedStumpColors);
            makeWeightedRectsFromJSON(graphics["Trunk"] as JArray, ref weightedTrunkRects, ref weightedTrunkColors);
            makeWeightedRectsFromJSON(graphics["Limb"] as JArray, ref weightedLimbRects, ref weightedLimbColors);
            makeWeightedRectsFromJSON(graphics["Branch"] as JArray, ref weightedBranchRects, ref weightedBranchColors);
            makeWeightedRectsFromJSON(graphics["Leaf"] as JArray, ref weightedLeafRects, ref weightedLeafColors);

            JObject structure = treeJSON["Structure"] as JObject;

            if (structure.ContainsKey("Trunk"))
            {
                JObject trunk = (structure["Trunk"] as JObject);
                tryApplyInt(ref minHeight, "Min Height", trunk);
                tryApplyInt(ref heightVariation, "Height Variation", trunk);
                tryApplyFloat(ref maxTrunkWobble, "Max Angle", trunk);
                maxTrunkWobble = TreeRenderer.degreesToRadians(maxTrunkWobble);
                tryApplyBool(ref limbAlternate, "Alternating", trunk);

                if (trunk.ContainsKey("Form"))
                {
                    switch (trunk["Form"].ToString().ToLower().Substring(0, 2))
                    {
                    case "op":
                        form = FORM_OPEN;
                        break;

                    case "co":
                        form = FORM_CONICAL;
                        break;

                    case "sp":
                        form = FORM_SPREADING;
                        break;

                    case "li":
                        form = FORM_LINEAR;
                        break;
                    }
                }
            }
            if (structure.ContainsKey("Limb"))
            {
                JObject limb = (structure["Limb"] as JObject);
                tryApplyFloat(ref limbFrequency, "Frequency", limb);
                tryApplyFloat(ref limbGrouping, "Grouping", limb);
                tryApplyFloat(ref limbGroupVariation, "Grouping Variation", limb);
                tryApplyInt(ref minLimbHeight, "Distance", limb);
                tryApplyFloat(ref minLimbHeightVariation, "Distance Variation", limb);
                tryApplyFloat(ref averageLimbInterval, "Interval", limb);
                tryApplyFloat(ref limbIntervalVariation, "Interval Variation", limb);
                tryApplyFloat(ref limbAngle, "Angle", limb);
                limbAngle = TreeRenderer.degreesToRadians(limbAngle);
                tryApplyFloat(ref limbGrowth, "Length Factor", limb);
                tryApplyFloat(ref limbGrowthVariation, "Length Variation", limb);
            }
            if (structure.ContainsKey("Branch"))
            {
                JObject branch = (structure["Branch"] as JObject);
                tryApplyFloat(ref branchFrequency, "Frequency", branch);
                tryApplyInt(ref minBranchDistance, "Distance", branch);
                tryApplyFloat(ref minBranchDistanceVariation, "Distance Variation", branch);
                tryApplyFloat(ref branchWhorl, "Whorling", branch);
                tryApplyFloat(ref averageBranchLength, "Length Factor", branch);
                tryApplyFloat(ref branchLengthVariation, "Length Variation", branch);
            }
        }