コード例 #1
0
        private void restoreHoeDirt()
        {
            foreach (SaveTiles st in savedata.data)
            {
                foreach (GameLocation l in PyUtils.getAllLocationsAndBuidlings().Where(lb => lb.name == st.location))
                {
                    if (config.farmonly && !(l is Farm || l.IsGreenhouse || l is BuildableGameLocation))
                    {
                        continue;
                    }

                    foreach (Vector2 v in st.tiles)
                    {
                        if (!l.terrainFeatures.ContainsKey(v) || !(l.terrainFeatures[v] is HoeDirt))
                        {
                            l.terrainFeatures.Remove(v);
                            l.terrainFeatures.Add(v, Game1.isRaining ? new HoeDirt(1) : new HoeDirt(0));

                            if (l.objects.Keys.Contains(v) && l.objects[v] is SObject o && (o.Name.Equals("Weeds") || o.Name.Equals("Stone") || o.Name.Equals("Twig")))
                            {
                                l.objects.Remove(v);
                            }
                        }
                    }

                    foreach (SObject o in l.objects.Values.Where(obj => obj.name.Contains("Sprinkler")))
                    {
                        o.DayUpdate(l);
                    }
                }
            }
        }
コード例 #2
0
ファイル: input.xaml.cs プロジェクト: sebiba/TFE_main
 private void StopBtn_Click(object sender, EventArgs e)
 {
     waveSource.StopRecording();
     _log.Debug("End of recording in file");
     Cursor            = Cursors.Wait;
     StopBtn.IsEnabled = false;
     try
     {
         _notes = PyUtils.Getfreq(waveFile.Filename);  // get frequency
         _log.Debug(_notes.Count + " Notes get from the file: '" + waveFile.Filename);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Une erreur est survenue lors du traitement de votre fichier audio.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
         _log.Error("Error while getting frequences of the audio file: " + ex.Message);
     }
     for (int i = 0; i < _notes.Count; i++)  //remove alone note
     {
         try
         {
             if (_notes[i].value != _notes[i + 1].value)
             {
                 _notes.RemoveAt(i + 1);
             }
         }
         catch
         {
         }
     }
     Cursor            = Cursors.Arrow;
     TitleMenu.Content = "Lilypond";
     _frame.Navigate(new lilypond(_frame, TitleMenu, _log, _notes, true));
 }
コード例 #3
0
        public static Map Load(string path, IModHelper helper)
        {
            Dictionary <TileSheet, Texture2D> tilesheets = Helper.Reflection.GetField <Dictionary <TileSheet, Texture2D> >(Game1.mapDisplayDevice, "m_tileSheetTextures").GetValue();
            Map    map      = tmx2map(Path.Combine(helper.DirectoryPath, path));
            string fileName = new FileInfo(path).Name;

            foreach (TileSheet t in map.TileSheets)
            {
                string[] seasons       = new string[] { "summer_", "fall_", "winter_" };
                string   tileSheetPath = path.Replace(fileName, t.ImageSource + ".png");

                FileInfo tileSheetFile        = new FileInfo(Path.Combine(helper.DirectoryPath, tileSheetPath));
                FileInfo tileSheetFileVanilla = new FileInfo(Path.Combine(PyUtils.getContentFolder(), "Content", t.ImageSource + ".xnb"));
                if (tileSheetFile.Exists && !tileSheetFileVanilla.Exists && tilesheets.Find(k => k.Key.ImageSource == t.ImageSource).Key == null)
                {
                    helper.Content.Load <Texture2D>(tileSheetPath).inject(t.ImageSource);
                    if (t.ImageSource.Contains("spring_"))
                    {
                        foreach (string season in seasons)
                        {
                            string   seasonPath = path.Replace(fileName, t.ImageSource.Replace("spring_", season));
                            FileInfo seasonFile = new FileInfo(Path.Combine(helper.DirectoryPath, seasonPath + ".png"));
                            if (seasonFile.Exists && tilesheets.Find(k => k.Key.ImageSource == t.ImageSource.Replace("spring_", season)).Key == null)
                            {
                                helper.Content.Load <Texture2D>(seasonPath + ".png").inject(t.ImageSource.Replace("spring_", season));
                                helper.Content.Load <Texture2D>(seasonPath + ".png").inject("Maps/" + t.ImageSource.Replace("spring_", season));
                            }
                        }
                    }
                }
            }
            map.LoadTileSheets(Game1.mapDisplayDevice);
            return(map);
        }
コード例 #4
0
        internal static void saveHoeDirt()
        {
            hoeDirtChache = new Dictionary <GameLocation, List <Vector2> >();
            foreach (GameLocation location in PyUtils.getAllLocationsAndBuidlings())
            {
                if (location is GameLocation)
                {
                    if (!hoeDirtChache.ContainsKey(location))
                    {
                        hoeDirtChache.Add(location, new List <Vector2>());
                    }

                    hoeDirtChache[location] = location.terrainFeatures.Keys
                                              .Where(t => location.terrainFeatures[t] is HoeDirt)
                                              .ToList();
                }
            }

            string savestring = string.Join(";", hoeDirtChache.toList(l => l.Key.Name + ":" + string.Join(",", l.Value.toList(v => $"{v.X}-{v.Y}"))));

            int index = savetiles.save.FindIndex(s => s.StartsWith(player + ">"));

            if (index == -1)
            {
                savetiles.save.Add(player + ">" + savestring);
            }
            else
            {
                savetiles.save[index] = player + ">" + savestring;
            }

            helper.WriteConfig(savetiles);
        }
コード例 #5
0
        /// <summary>
        /// 设定Python环境变量按钮
        /// </summary>
        private void pyOk_Click(object sender, EventArgs e)
        {
            string pyPath = "";

            if (pyAutoSetOption.Checked)
            {
                pyPath = PyUtils.PythonVersions[pyAutoSetValue.SelectedItem.ToString()];
            }
            else if (pyManualSetOption.Checked)
            {
                if (StringUtils.IsEmpty(pyManualSetValue.Text))
                {
                    MessageBox.Show("请先指定Python所在路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                pyPath = pyManualSetValue.Text;
            }
            pyOk.Enabled         = false;
            pySettingTip.Visible = true;
            new Thread(() =>
            {
                PyUtils.SetPythonValue(pyPath);
                pySettingTip.Visible = false;
                pyOk.Enabled         = true;
            }).Start();
        }
コード例 #6
0
        public static TileAction getCustomAction(string action, string conditions = "", string fallback = "")
        {
            if (action == null || action == "")
            {
                return(null);
            }

            TileAction result = null;

            string[] prop = action.Split(' ');
            if (actions.ContainsKey(prop[0]))
            {
                if (PyUtils.checkEventConditions(conditions))
                {
                    result = actions[prop[0]];
                    result.currentAction = action;
                }
                else
                {
                    result = getCustomAction(fallback);
                }
            }

            return(result);
        }
コード例 #7
0
ファイル: LuaUtils.cs プロジェクト: MadAbs/smapi-mod-dump
        public static bool setGameValue(string field, object value, int delay = 0, object root = null)
        {
            List <string> tree      = new List <string>(field.Split('.'));
            FieldInfo     fieldInfo = null;

            object currentBranch = root == null ? Game1.game1 : root;

            fieldInfo = typeof(Game1).GetField(tree[0], BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
            tree.Remove(tree[0]);

            if (tree.Count > 0)
            {
                foreach (string branch in tree)
                {
                    currentBranch = fieldInfo.GetValue(currentBranch);
                    fieldInfo     = currentBranch.GetType().GetField(branch, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                }
            }

            if (delay > 0)
            {
                PyUtils.setDelayedAction(delay, () => fieldInfo.SetValue(fieldInfo.IsStatic ? null : currentBranch, value));
            }
            else
            {
                fieldInfo.SetValue(fieldInfo.IsStatic ? null : currentBranch, value);
            }

            return(true);
        }
コード例 #8
0
        public static Map Load(string path, IModHelper helper, bool syncTexturesToClients, IContentPack contentPack)
        {
            Dictionary <TileSheet, Texture2D> tilesheets = Helper.Reflection.GetField <Dictionary <TileSheet, Texture2D> >(Game1.mapDisplayDevice, "m_tileSheetTextures").GetValue();
            Map    map      = tmx2map(Path.Combine(contentPack != null ? contentPack.DirectoryPath : helper.DirectoryPath, path));
            string fileName = new FileInfo(path).Name;

            Monitor.Log(path);
            foreach (TileSheet t in map.TileSheets)
            {
                t.ImageSource = t.ImageSource.Replace(".png", "");
                string[] seasons       = new string[] { "summer_", "fall_", "winter_" };
                string   tileSheetPath = path.Replace(fileName, t.ImageSource + ".png");

                FileInfo tileSheetFile        = new FileInfo(Path.Combine(contentPack != null ? contentPack.DirectoryPath : helper.DirectoryPath, tileSheetPath));
                FileInfo tileSheetFileVanilla = new FileInfo(Path.Combine(PyUtils.getContentFolder(), "Content", t.ImageSource + ".xnb"));
                if (tileSheetFile.Exists && !tileSheetFileVanilla.Exists && tilesheets.Find(k => k.Key.ImageSource == t.ImageSource).Key == null)
                {
                    Texture2D tilesheet = contentPack != null?contentPack.LoadAsset <Texture2D>(tileSheetPath) : helper.Content.Load <Texture2D>(tileSheetPath);

                    tilesheet.inject(t.ImageSource);
                    tilesheet.inject("Maps/" + t.ImageSource);

                    if (syncTexturesToClients && Game1.IsMultiplayer && Game1.IsServer)
                    {
                        foreach (Farmer farmhand in Game1.otherFarmers.Values)
                        {
                            PyNet.sendGameContent(t.ImageSource, tilesheet, farmhand, (b) => Monitor.Log("Syncing " + t.ImageSource + " to " + farmhand.Name + ": " + (b ? "successful" : "failed"), b ? LogLevel.Info : LogLevel.Warn));
                        }
                    }

                    if (t.ImageSource.Contains("spring_"))
                    {
                        foreach (string season in seasons)
                        {
                            string   seasonPath = path.Replace(fileName, t.ImageSource.Replace("spring_", season));
                            FileInfo seasonFile = new FileInfo(Path.Combine(contentPack != null ? contentPack.DirectoryPath : helper.DirectoryPath, seasonPath + ".png"));
                            if (seasonFile.Exists && tilesheets.Find(k => k.Key.ImageSource == t.ImageSource.Replace("spring_", season)).Key == null)
                            {
                                Texture2D seasonTilesheet = contentPack != null?contentPack.LoadAsset <Texture2D>(seasonPath + ".png") : helper.Content.Load <Texture2D>(seasonPath + ".png");

                                string seasonTextureName = t.ImageSource.Replace("spring_", season);
                                seasonTilesheet.inject(seasonTextureName);
                                seasonTilesheet.inject("Maps/" + seasonTextureName);

                                if (syncTexturesToClients && Game1.IsMultiplayer && Game1.IsServer)
                                {
                                    foreach (Farmer farmhand in Game1.otherFarmers.Values)
                                    {
                                        PyNet.sendGameContent(new string[] { seasonTextureName, "Maps/" + seasonTextureName }, seasonTilesheet, farmhand, (b) => Monitor.Log("Syncing " + seasonTextureName + " to " + farmhand.Name + ": " + (b ? "successful" : "failed"), b ? LogLevel.Info : LogLevel.Warn));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            map.LoadTileSheets(Game1.mapDisplayDevice);
            return(map);
        }
コード例 #9
0
        private static void loadHoeDirt()
        {
            hoeDirtChache = new Dictionary <GameLocation, List <Vector2> >();

            if (savetiles.save == null)
            {
                savetiles.save = new List <string>();
            }

            int index = savetiles.save.FindIndex(s => s.StartsWith(player + ">"));

            if (index != -1)
            {
                string savestring = savetiles.save[index];
                savestring.Replace(player + ">", "");
                List <string> locationstrings = new List <string>(savestring.Split(';'));
                foreach (string loc in locationstrings)
                {
                    string locationname = loc.Split(':')[0];
                    loc.Replace(locationname + ":", "");
                    List <string> vstrings = new List <string>(loc.Split(','));
                    GameLocation  location;
                    try
                    {
                        location = PyUtils.getAllLocationsAndBuidlings().Find(e => e.Name == locationname);
                    }
                    catch
                    {
                        continue;
                    }
                    if (location != null && !hoeDirtChache.ContainsKey(location))
                    {
                        hoeDirtChache.Add(location, new List <Vector2>());
                    }

                    foreach (string v in vstrings)
                    {
                        string[] split = v.Split('-');

                        if (split.Length < 2)
                        {
                            continue;
                        }

                        int x = -1;
                        int y = -1;

                        int.TryParse(split[0], out x);
                        int.TryParse(split[1], out y);

                        if (x >= 0 && y >= 0)
                        {
                            hoeDirtChache[location].AddOrReplace(new Vector2(x, y));
                        }
                    }
                }
            }
            helper.WriteConfig(savetiles);
        }
コード例 #10
0
 public override void Entry(IModHelper helper)
 {
     Monitor.Log("Environment:" + PyUtils.getContentFolder());
     exportAllMaps();
     convert();
     loadContentPacks();
     setTileActions();
 }
コード例 #11
0
        public void switchMonsters()
        {
            List <int> glMonster = new List <int>();

            for (int i = 0; i < Game1.currentLocation.characters.Count(); i++)
            {
                Character c = Game1.currentLocation.characters[i];
                if (c is Monster && !(c is Duggy))
                {
                    glMonster.Add(i);
                }
            }

            if (glMonster.Count <= 0)
            {
                return;
            }

            Monster pickMonster = (Monster)Game1.currentLocation.characters[glMonster[Game1.random.Next(glMonster.Count())]];

            Type t = pickMonster.GetType();

            for (int j = 0; j < glMonster.Count(); j++)
            {
                Monster monster = (Monster)Game1.currentLocation.characters[glMonster[j]];
                if (monster == pickMonster)
                {
                    continue;
                }

                if (Game1.currentLocation is MineShaft)
                {
                    MineShaft gl = (MineShaft)Game1.currentLocation;

                    if (pickMonster is GreenSlime || pickMonster is Bat)
                    {
                        monster = (Monster)Activator.CreateInstance(t, new object[] { monster.position, gl.mineLevel });
                    }
                    else
                    {
                        monster = (Monster)Activator.CreateInstance(t, new object[] { monster.position });
                    }
                }
                else if (Game1.currentLocation is SlimeHutch && pickMonster is GreenSlime)
                {
                    monster = (Monster)Activator.CreateInstance(t, new object[] { monster.position, (pickMonster as GreenSlime).color.Value });
                }

                Game1.currentLocation.characters[glMonster[j]] = monster;
            }

            Game1.player.forceTimePass = true;
            Game1.currentLocation.damageMonster(new Rectangle(0, 0, Game1.currentLocation.map.DisplayWidth, Game1.currentLocation.map.DisplayHeight), 0, 0, false, 1.5f, 100, 0f, 1f, false, Game1.player);
            pickMonster.doEmote(20);

            PyUtils.setDelayedAction(500, secondHit);
        }
コード例 #12
0
        public Texture2D CreateScaledTexture2D(Rectangle orgSize, Texture2D scaledTexture, float scale = -1, Rectangle?forcedSourceRectangle = null)
        {
            if (scale == -1)
            {
                scale = (float)(Convert.ToDouble(scaledTexture.Width) / Convert.ToDouble(orgSize.Width));
            }

            return(ScaledTexture2D.FromTexture(PyUtils.getRectangle(orgSize.Width, orgSize.Height, Color.White), scaledTexture, scale, forcedSourceRectangle));;
        }
コード例 #13
0
        public ScaledTexture2D(Texture2D tex, int width, int height, float scale = 1)
            : base(tex.GraphicsDevice, (int)(width / scale), (int)(height / scale))
        {
            Color[] data = new Color[(int)(width / scale) * (int)(height / scale)];
            PyUtils.getRectangle((int)(width / scale), (int)(height / scale), Color.White).GetData(data);
            SetData(data);

            Scale    = scale;
            STexture = tex;
        }
コード例 #14
0
        public void doMagic(bool playedToday)
        {
            if (Game1.currentLocation.isOutdoors || Game1.currentLocation.name.Equals("Greenhouse"))
            {
                GameLocation   gls       = Game1.currentLocation;
                List <Vector2> treetiles = new TerrainSelector <TerrainFeature>(t => (t is Tree || t is FruitTree || t is Grass || t is Bush)).keysIn(gls);

                for (int i = 0; i < treetiles.Count; i++)
                {
                    if (gls.terrainFeatures[treetiles[i]] is Tree)
                    {
                        if (!playedToday)
                        {
                            Tree tree = gls.terrainFeatures[treetiles[i]] as Tree;
                            tree.growthStage = (tree.growthStage < 4) ? tree.growthStage + 1 : tree.growthStage;
                            gls.terrainFeatures[treetiles[i]] = tree;
                        }
                        (gls.terrainFeatures[treetiles[i]] as Tree).performUseAction(treetiles[i]);
                    }

                    if (gls.terrainFeatures[treetiles[i]] is FruitTree)
                    {
                        if (!playedToday)
                        {
                            FruitTree tree = (gls.terrainFeatures[treetiles[i]] as FruitTree);
                            tree.growthStage     = (tree.growthStage <= 4) ? tree.growthStage + 1 : tree.growthStage;
                            tree.daysUntilMature = tree.daysUntilMature - 7;
                            gls.terrainFeatures[treetiles[i]] = tree;
                        }
                        (gls.terrainFeatures[treetiles[i]] as FruitTree).performUseAction(treetiles[i]);
                    }

                    if (gls.terrainFeatures[treetiles[i]] is Grass)
                    {
                        if (!playedToday)
                        {
                            Grass grass = (gls.terrainFeatures[treetiles[i]] as Grass);
                            grass.numberOfWeeds = Math.Min(grass.numberOfWeeds + Game1.random.Next(1, 4), 4);
                            gls.terrainFeatures[treetiles[i]] = grass;
                        }
                    }
                    (gls.terrainFeatures[treetiles[i]] as Grass).doCollisionAction(gls.terrainFeatures[treetiles[i]].getBoundingBox(treetiles[i]), 3, treetiles[i], Game1.player, Game1.currentLocation);

                    if (gls.terrainFeatures[treetiles[i]] is Bush)
                    {
                        (gls.terrainFeatures[treetiles[i]] as Bush).performUseAction(treetiles[i]);
                    }
                }
                priorRadius = Game1.player.magneticRadius;
                Game1.player.magneticRadius += 2000;

                PyUtils.setDelayedAction(8000, () => Game1.player.magneticRadius = priorRadius);
            }
        }
コード例 #15
0
        private void SaveEvents_AfterLoad(object sender, System.EventArgs e)
        {
            hoeDirtChache = PyUtils.getAllLocationsAndBuidlings().toDictionary(l => new DictionaryEntry <GameLocation, List <Vector2> >(l, l.terrainFeatures.toList(t => t.Value is HoeDirt ? t.Key : Vector2.Zero)));
            hoeDirtChache.useAll(k => k.Value.RemoveAll(v => v == Vector2.Zero));

            new TerrainSelector <HoeDirt>().whenAddedToLocation((gl, list) => list.useAll(v => hoeDirtChache[gl].AddOrReplace(v)));
            new TileLocationSelector((l, v) => hoeDirtChache[l].Contains(v)).whenRemovedFromLocation(restoreTiles);

            /* Legacy Fix */
            "Town".toLocation().objects.Remove(new Vector2(2, 0));
        }
コード例 #16
0
ファイル: UnitTest1.cs プロジェクト: sebiba/TFE_main
 public void GetFreqWrongTypeOfFile()
 {
     try
     {
         PyUtils.Getfreq(@"D:\programmation\python\TFE\note.py");
         Assert.Fail();
     }
     catch (IOException e)
     {
         Assert.AreEqual("Une erreur d'E/S s'est produite.", e.Message);
     }
 }
コード例 #17
0
ファイル: UnitTest1.cs プロジェクト: sebiba/TFE_main
 public void GetFreqWrongPath()
 {
     try
     {
         PyUtils.Getfreq(@"test");
         Assert.Fail();
     }
     catch (FileNotFoundException e)
     {
         Assert.AreEqual("Impossible de trouver le fichier spécifié.", e.Message);
     }
 }
コード例 #18
0
ファイル: UnitTest1.cs プロジェクト: sebiba/TFE_main
 public void FreqToNoteNegatif()
 {
     try
     {
         string test = PyUtils.FreqToNote(-5.2f);
         Assert.Fail();
     }
     catch (Exception e)
     {
         Assert.AreEqual("math domain error", e.Message);
     }
 }
コード例 #19
0
 public override void Entry(IModHelper helper)
 {
     Monitor.Log("Environment:" + PyUtils.getContentFolder());
     exportAllMaps();
     convert();
     loadContentPacks();
     setTileActions();
     LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged;
     PyLua.registerType(typeof(Map), false, true);
     PyLua.registerType(typeof(TMXActions), false, false);
     PyLua.addGlobal("TMX", new TMXActions());
 }
コード例 #20
0
        /// <summary>Wraps the the method in the predicate, so it only executes if the predicate returns true.</summary>
        /// <returns>Returns the wrapped method.</returns>
        public static EventHandler <TArgs> addPredicate <TArgs>(this EventHandler <TArgs> t, string conditions)
        {
            EventHandler <TArgs> d = delegate(object sender, TArgs e)
            {
                if (PyUtils.checkEventConditions(conditions))
                {
                    t.Invoke(sender, e);
                }
            };

            return(d);
        }
コード例 #21
0
        /// <summary>Wraps the the method in the predicate, so it only executes if the predicate returns true.</summary>
        /// <returns>Returns the wrapped method.</returns>
        public static Action <TArgs> addPredicate <TArgs>(this Action <TArgs> t, string conditions)
        {
            Action <TArgs> d = delegate(TArgs e)
            {
                if (PyUtils.checkEventConditions(conditions))
                {
                    t.Invoke(e);
                }
            };

            return(d);
        }
コード例 #22
0
        public void doMagic(bool playedToday)
        {
            if (Game1.currentLocation.isOutdoors || Game1.currentLocation.name.Equals("Greenhouse"))
            {
                GameLocation gls = Game1.currentLocation;

                foreach (KeyValuePair <Vector2, TerrainFeature> entry in gls.terrainFeatures)
                {
                    if (entry.Value is Tree tree)
                    {
                        if (!playedToday)
                        {
                            tree.growthStage = (tree.growthStage < 5) ? tree.growthStage + 1 : tree.growthStage;
                        }

                        tree.performUseAction(entry.Key);
                        continue;
                    }

                    if (entry.Value is FruitTree ftree)
                    {
                        if (!playedToday)
                        {
                            ftree.growthStage     = (ftree.growthStage <= 5) ? ftree.growthStage + 1 : ftree.growthStage;
                            ftree.daysUntilMature = ftree.daysUntilMature - 7;
                        }
                        ftree.performUseAction(entry.Key);
                        continue;
                    }

                    if (entry.Value is Grass grass)
                    {
                        if (!playedToday)
                        {
                            grass.numberOfWeeds = Math.Min(grass.numberOfWeeds + Game1.random.Next(1, 4), 4);
                        }
                        grass.doCollisionAction(gls.terrainFeatures[entry.Key].getBoundingBox(entry.Key), 3, entry.Key, Game1.player, Game1.currentLocation);
                        continue;
                    }

                    if (entry.Value is Bush bush)
                    {
                        bush.performUseAction(entry.Key);
                        continue;
                    }
                }
                priorRadius = Game1.player.magneticRadius;
                Game1.player.magneticRadius += 2000;

                PyUtils.setDelayedAction(8000, () => Game1.player.magneticRadius = priorRadius);
            }
        }
コード例 #23
0
        public override void Entry(IModHelper helper)
        {
            CustomWallsAndFloorsMod.helper = helper;
            loadContentPacks();
            monitor = Monitor;

            HarmonyInstance harmony = HarmonyInstance.Create("Platonymous.CustomWallsAndFloors");

            harmony.Patch(PyUtils.getTypeSDV("Objects.Wallpaper").GetMethod("placementAction"), new HarmonyMethod(typeof(CustomWallsAndFloorsMod), "Prefix_placement"), null);
            harmony.Patch(PyUtils.getTypeSDV("GameLocation").GetMethod("setMapTileIndex"), new HarmonyMethod(typeof(CustomWallsAndFloorsMod), "Prefix_setMapTile"), null);

            StardewModdingAPI.Events.SaveEvents.AfterLoad  += SaveEvents_AfterLoad;
            StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
        }
コード例 #24
0
        public override void Entry(IModHelper helper)
        {
            CustomWallsAndFloorsMod.helper = helper;
            loadContentPacks();
            monitor = Monitor;

            HarmonyInstance harmony = HarmonyInstance.Create("Platonymous.CustomWallsAndFloors");

            harmony.Patch(PyUtils.getTypeSDV("Objects.Wallpaper").GetMethod("placementAction"), new HarmonyMethod(typeof(CustomWallsAndFloorsMod), "Prefix_placement"), null);
            harmony.Patch(PyUtils.getTypeSDV("GameLocation").GetMethod("setMapTileIndex"), new HarmonyMethod(typeof(CustomWallsAndFloorsMod), "Prefix_setMapTile"), null);

            helper.Events.GameLoop.SaveLoaded += OnSaveLoaded;
            helper.Events.GameLoop.Saving     += OnSaving;
        }
コード例 #25
0
        private void exportAllMaps()
        {
            string        exportFolderPath = Path.Combine(Helper.DirectoryPath, "Converter", "FullMapExport");
            DirectoryInfo exportFolder     = new DirectoryInfo(exportFolderPath);
            DirectoryInfo modFolder        = new DirectoryInfo(Helper.DirectoryPath);
            string        contentPath      = PyUtils.getContentFolder();

            if (!exportFolder.Exists && contentPath != null)
            {
                exportFolder.Create();
            }
            else
            {
                return;
            }

            string[] files = Directory.GetFiles(Path.Combine(contentPath, "Maps"), "*.xnb", SearchOption.TopDirectoryOnly);
            foreach (string file in files)
            {
                string fileName   = new FileInfo(file).Name;
                string folderName = new FileInfo(file).Directory.Name;

                if (fileName[0] == fileName.ToLower()[0])
                {
                    continue;
                }

                Map    map  = null;
                string path = Path.Combine(folderName, fileName);

                try
                {
                    map = Helper.Content.Load <Map>(path, ContentSource.GameContent);
                    map.LoadTileSheets(Game1.mapDisplayDevice);
                }
                catch
                {
                    continue;
                }

                if (map == null)
                {
                    continue;
                }

                string exportPath = Path.Combine(exportFolderPath, fileName.Replace(".xnb", ".tmx"));
                TMXContent.Save(map, exportPath, true, Monitor);
            }
        }
コード例 #26
0
        public void doMagic(bool playedToday)
        {
            maxDist = playedToday ? 5 : 9;

            if (Game1.isRaining || !Game1.currentLocation.isOutdoors)
            {
                return;
            }

            Game1.playSound("thunder_small");

            PyUtils.setDelayedAction(500, () => Game1.isRaining = true);
            PyUtils.setDelayedAction(2000, () => new TerrainSelector <HoeDirt>(h => h.state < 1).keysIn(Game1.currentLocation).useAll(k => water(k)));
            PyUtils.setDelayedAction(6000, () => Game1.isRaining = false);
        }
コード例 #27
0
        private void SaveEvents_AfterLoad(object sender, System.EventArgs e)
        {
            hoeDirtChache = new Dictionary <GameLocation, List <Vector2> >();
            foreach (var location in PyUtils.getAllLocationsAndBuidlings())
            {
                hoeDirtChache[location] = location.terrainFeatures
                                          .Where(t => t.Value is HoeDirt)
                                          .Select(t => t.Key).ToList();
            }

            new TerrainSelector <HoeDirt>().whenAddedToLocation((gl, list) => list.ForEach(v => hoeDirtChache[gl].AddOrReplace(v)));
            new TileLocationSelector((l, v) => hoeDirtChache[l].Contains(v)).whenRemovedFromLocation(restoreTiles);

            /* Legacy Fix */
            "Town".toLocation().objects.Remove(new Vector2(2, 0));
        }
コード例 #28
0
        public void doMagic(bool playedToday)
        {
            if (!playedToday)
            {
                lastLocation = Game1.getLocationFromName("Town");
                lastPosition = new Vector2(53,24);
            }

            targetLocation = Game1.getLocationFromName(lastLocation.name);
            targetPosition = new Vector2(lastPosition.X, lastPosition.Y);
            lastLocation = Game1.currentLocation;
            lastPosition = new Vector2(Game1.player.getTileX(), Game1.player.getTileY());

            PyUtils.setDelayedAction(6000, start);
            PyUtils.setDelayedAction(7000, teleport);
        }
コード例 #29
0
        private static void ReplaceAllObjects <TIn>(Dictionary <object, List <object> > found, Func <TIn, bool> predicate, Func <TIn, object> replacer, bool reverse = false)
        {
            List <object> objs = new List <object>(found.Keys.ToArray());

            if (reverse)
            {
                objs.Reverse();
            }

            foreach (object key in objs)
            {
                foreach (object obj in found[key])
                {
                    if (obj is TIn item && predicate(item))
                    {
                        if (key is IDictionary <Vector2, SObject> dict)
                        {
                            foreach (Vector2 k in dict.Keys.Reverse())
                            {
                                if (dict[k] == obj)
                                {
                                    if (obj is SObject sobj && splitElemets(sobj.name).Count() > 2 && splitElemets(sobj.name)[1] == "Terrain")
                                    {
                                        GameLocation gl = PyUtils.getAllLocationsAndBuidlings().Find(l => l.objects == dict);
                                        if (gl != null)
                                        {
                                            if (gl.terrainFeatures.ContainsKey(k))
                                            {
                                                gl.terrainFeatures[k] = (TerrainFeature)replacer(item);
                                            }
                                            else
                                            {
                                                gl.terrainFeatures.Add(k, (TerrainFeature)replacer(item));
                                            }
                                        }

                                        dict.Remove(k);
                                    }
                                    else
                                    {
                                        dict[k] = (SObject)replacer(item);
                                    }

                                    break;
                                }
                            }
                        }
コード例 #30
0
        public void doMagic(bool playedToday)
        {
            gamePtr = Program.gamePtr;

            Game1.player.forceTimePass = true;
            Game1.playSound("stardrop");
            targetTime  = Game1.timeOfDay + 200;
            currentTime = Game1.timeOfDay;
            oldTS       = new TimeSpan(gamePtr.TargetElapsedTime.Ticks);

            gamePtr.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 1);

            for (int i = 0; i < 12; i++)
            {
                PyUtils.setDelayedAction((i + 1) * 1000 / 2 - i * 20, moveTimeForward);
            }
        }