Ejemplo n.º 1
0
        private static bool CheckToolType(CustomResourceClump clump, Tool t)
        {
            if (clump.toolType.Contains(","))
            {
                string[] tools = clump.toolType.Split(',');
                foreach (string tool in tools)
                {
                    if (ToolTypes.ContainsKey(tool) && t.GetType() == ToolTypes[tool])
                    {
                        return(true);
                    }
                }
                return(false);
            }

            return(ToolTypes.ContainsKey(clump.toolType) && t.GetType() == ToolTypes[clump.toolType]);
        }
Ejemplo n.º 2
0
        private static void MineShaft_populateLevel_Postfix(MineShaft __instance)
        {
            SMonitor.Log($"checking for custom clumps after populateLevel. total resource clumps: {__instance.resourceClumps.Count}");
            float totalChance = 0;

            for (int j = 0; j < customClumps.Count; j++)
            {
                CustomResourceClump clump = customClumps[j];
                if (clump.minLevel > -1 && __instance.mineLevel < clump.minLevel || clump.maxLevel > -1 && __instance.mineLevel > clump.maxLevel)
                {
                    continue;
                }
                totalChance += clump.baseSpawnChance + clump.additionalChancePerLevel * __instance.mineLevel;
            }
            if (totalChance > 100)
            {
                SMonitor.Log($"Total chance of a custom clump is greater than 100%", LogLevel.Warn);
            }
            for (int i = 0; i < __instance.resourceClumps.Count; i++)
            {
                double ourChance = Game1.random.NextDouble();
                if (ourChance < totalChance / 100f)
                {
                    float cumulativeChance = 0;
                    for (int j = 0; j < customClumps.Count; j++)
                    {
                        CustomResourceClump clump = customClumps[j];
                        if (clump.minLevel > -1 && __instance.mineLevel < clump.minLevel || clump.maxLevel > -1 && __instance.mineLevel > clump.maxLevel)
                        {
                            continue;
                        }
                        cumulativeChance += clump.baseSpawnChance + clump.additionalChancePerLevel * __instance.mineLevel;
                        if (ourChance < cumulativeChance / 100f)
                        {
                            SMonitor.Log($"Converting clump at {__instance.resourceClumps[i].currentTileLocation} to {clump.index} {clump.clumpDesc} ");
                            __instance.resourceClumps[i] = new ResourceClump(clump.index, clump.tileWidth, clump.tileHeight, __instance.resourceClumps[i].tile.Value);
                            __instance.resourceClumps[i].health.Value = clump.durability;
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static bool ResourceClump_draw_prefix(ResourceClump __instance, SpriteBatch spriteBatch, float ___shakeTimer)
        {
            int indexOfClump = __instance.parentSheetIndex.Value;

            if (indexOfClump >= 0)
            {
                return(true);
            }
            CustomResourceClump clump = customClumps.FirstOrDefault(c => c.index == indexOfClump);

            Rectangle sourceRect = new Rectangle(clump.spriteX, clump.spriteY, 32, 32);

            Vector2 position = __instance.tile.Value * 64f;

            if (___shakeTimer > 0f)
            {
                position.X += (float)Math.Sin(6.2831853071795862 / (double)___shakeTimer) * 4f;
            }
            spriteBatch.Draw(clump.texture, Game1.GlobalToLocal(Game1.viewport, position), new Rectangle?(sourceRect), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, (__instance.tile.Y + 1f) * 64f / 10000f + __instance.tile.X / 100000f);
            return(false);
        }
Ejemplo n.º 4
0
        private static bool ResourceClump_performToolAction_prefix(ref ResourceClump __instance, Tool t, Vector2 tileLocation, GameLocation location, ref bool __result)
        {
            int indexOfClump = __instance.parentSheetIndex.Value;

            if (indexOfClump >= 0)
            {
                return(true);
            }
            CustomResourceClump clump = customClumps.FirstOrDefault(c => c.index == indexOfClump);

            if (clump == null)
            {
                return(true);
            }

            if (t == null)
            {
                return(false);
            }
            SMonitor.Log($"hitting custom clump {indexOfClump} with {t.GetType()} (should be {ToolTypes[clump.toolType]})");

            if (!CheckToolType(clump, t))
            {
                return(false);
            }
            SMonitor.Log($"tooltype is correct");
            if (t.UpgradeLevel < clump.toolMinLevel)
            {
                foreach (string sound in clump.failSounds)
                {
                    location.playSound(sound, NetAudio.SoundContext.Default);
                }

                Game1.drawObjectDialogue(string.Format(SHelper.Translation.Get("failed"), t.DisplayName));

                Game1.player.jitterStrength = 1f;
                return(false);
            }

            float power = Math.Max(1f, (float)(t.UpgradeLevel + 1) * 0.75f);

            __instance.health.Value -= power;
            Game1.createRadialDebris(Game1.currentLocation, clump.debrisType, (int)tileLocation.X + Game1.random.Next(__instance.width.Value / 2 + 1), (int)tileLocation.Y + Game1.random.Next(__instance.height.Value / 2 + 1), Game1.random.Next(4, 9), false, -1, false, -1);

            if (__instance.health.Value > 0f)
            {
                foreach (string sound in clump.hitSounds)
                {
                    location.playSound(sound, NetAudio.SoundContext.Default);
                }
                if (clump.shake != 0)
                {
                    SHelper.Reflection.GetField <float>(__instance, "shakeTimer").SetValue(clump.shake);
                    __instance.NeedsUpdate = true;
                }
                return(false);
            }

            __result = true;

            foreach (string sound in clump.breakSounds)
            {
                location.playSound(sound, NetAudio.SoundContext.Default);
            }

            Farmer who = t.getLastFarmerToUse();

            int addedItems = who.professions.Contains(18) ? 1 : 0;
            int experience = 0;

            SMonitor.Log($"custom clump has {clump.dropItems.Count} potential items.");
            foreach (DropItem item in clump.dropItems)
            {
                if (Game1.random.NextDouble() < item.dropChance / 100)
                {
                    SMonitor.Log($"dropping item {item.itemIdOrName}");

                    if (!int.TryParse(item.itemIdOrName, out int itemId))
                    {
                        foreach (KeyValuePair <int, string> kvp in Game1.objectInformation)
                        {
                            if (kvp.Value.StartsWith(item.itemIdOrName + "/"))
                            {
                                itemId = kvp.Key;
                                break;
                            }
                        }
                    }
                    int amount = addedItems + Game1.random.Next(item.minAmount, Math.Max(item.minAmount + 1, item.maxAmount + 1)) + ((Game1.random.NextDouble() < (double)((float)who.LuckLevel / 100f)) ? item.luckyAmount : 0);
                    Game1.createMultipleObjectDebris(itemId, (int)tileLocation.X, (int)tileLocation.Y, amount, who.UniqueMultiplayerID, location);
                }
            }
            if (expTypes.ContainsKey(clump.expType))
            {
                experience = clump.exp;
                who.gainExperience(expTypes[clump.expType], experience);
            }
            else
            {
                SMonitor.Log($"Invalid experience type {clump.expType}", LogLevel.Warn);
            }
            return(false);
        }