Example #1
0
        public string GetScannerPdf(SearchFilters searchFilters)
        {
            Trawler  s     = new Trawler(Const.Locations[searchFilters.Location].CarScanner);
            DateTime sDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
            DateTime eDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

            s.InitDate(sDate);


            int numOfIterations = (eDate - sDate).Days;

            List <string> links     = s.GetGeneratedLinksByDate(sDate, eDate);
            List <JOffer> minOffers = new List <JOffer>();

            Dictionary <string, Dictionary <string, JOffer> > offerMap = new Dictionary <string, Dictionary <string, JOffer> >();

            for (int i = 0; i < links.Count; i++)
            {
                offerMap.Add(links[i], new Dictionary <string, JOffer>());
            }


            List <Thread> threads = new List <Thread>();

            //--- Start all threads
            for (int index = 0; index < links.Count; index++)
            {
                Thread thread = new Thread(() =>
                {
                    JSourceReader reader = new JSourceReader();
                    offerMap[Thread.CurrentThread.Name == null ?
                             links.ElementAt(0) :
                             Thread.CurrentThread.Name] =
                        reader.GetMapNorwegian(reader.GetScannerRates(Thread.CurrentThread.Name));
                });
                thread.Name = links.ElementAt(index);
                threads.Add(thread);
                thread.Start();
            }

            //check if threads has done
            Boolean allCompleted = false;

            while (!allCompleted)
            {
                int completed = links.Count;
                for (int i = 0; i < links.Count; i++)
                {
                    if (!threads.ElementAt(i).IsAlive)
                    {
                        --completed;
                    }
                    else
                    {
                        Thread.Sleep(100);
                        break;
                    }
                }
                if (completed == 0)
                {
                    break;
                }
            }
            s.SetTitle("scanner");
            return(CreatePdf(s, offerMap));
        }
Example #2
0
        //public string GetVehicleRentPdf(SearchFilters searchFilters)
        //{
        //    DateTime sDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
        //    DateTime eDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

        //    Vehicle s = new Vehicle(Const.Locations[searchFilters.Location].EcoBoking);
        //    s.InitDate(sDate);

        //    int numOfIterations = (eDate - sDate).Days;

        //    List<string> links = s.GetGeneratedLinksByDate(sDate, eDate);
        //    List<JOffer> minOffers = new List<JOffer>();

        //    Dictionary<string, Dictionary<string, JOffer>> offerMap = new Dictionary<string, Dictionary<string, JOffer>>();

        //    for (int i = 0; i < links.Count; i++)
        //        offerMap.Add(links[i], new Dictionary<string, JOffer>());


        //    for (int i = 0; i < links.Count; i++)
        //    {
        //        JSourceReader reader = new JSourceReader();
        //        List<JOffer> offers = reader.GetVehicleOffers(
        //                            reader.GetVehicleSource(links.ElementAt(i)));

        //        offerMap[links.ElementAt(i)] =
        //                reader.GetMapNorwegian(offers);

        //    }

        //    return CreatePdf(s, offerMap);
        //}

        public string GetCarTrawlerExcel(SearchFilters searchFilters)
        {
            DateTime sDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
            DateTime eDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

            Trawler s = new Trawler(Const.Locations[searchFilters.Location].CarTrawler);

            s.InitDate(sDate);

            int numOfIterations = (eDate - sDate).Days;

            List <string> links     = s.GetGeneratedLinksByDate(sDate, eDate);
            List <JOffer> minOffers = new List <JOffer>();

            Dictionary <string, Dictionary <string, JOffer> > offerMap = new Dictionary <string, Dictionary <string, JOffer> >();

            for (int i = 0; i < links.Count; i++)
            {
                offerMap.Add(links[i], new Dictionary <string, JOffer>());
            }

            List <Thread> threads = new List <Thread>();

            for (int index = 0; index < links.Count; index++)//--- Start all threads
            {
                Thread thread = new Thread(() =>
                {
                    JSourceReader reader = new JSourceReader();
                    offerMap[Thread.CurrentThread.Name == null ?
                             links.ElementAt(0) :
                             Thread.CurrentThread.Name] =
                        reader.GetMapNorwegian(reader.GetNorwRates(Thread.CurrentThread.Name));
                });
                thread.Name = links.ElementAt(index);
                threads.Add(thread);
                thread.Start();
            }

            Boolean allCompleted = false;//check if threads has done

            while (!allCompleted)
            {
                int completed = links.Count;
                for (int i = 0; i < links.Count; i++)
                {
                    if (!threads.ElementAt(i).IsAlive)
                    {
                        --completed;
                    }
                    else
                    {
                        Thread.Sleep(100);
                        break;
                    }
                }
                if (completed == 0)
                {
                    break;
                }
            }

            FileInfo template = new FileInfo(Server.MapPath(@"\Content\ExcelPackageTemplate.xlsx"));
            string   filename = @"\excel\" + s.GetTitle() + s.GetPuMonth() + "-" + s.GetPuDay() + s.GetCity() + ".xlsx";
            FileInfo newFile  = new FileInfo(Server.MapPath(filename));

            using (ExcelPackage excelPackage = new ExcelPackage(newFile, template))
            {
                ExcelWorkbook  myWorkbook  = excelPackage.Workbook;          // Getting the complete workbook...
                ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Rates"]; // Getting the worksheet by its name...

                int      rowNum = 2;
                DateTime doDate = new DateTime(Convert.ToInt32(s.GetPuYear()), Convert.ToInt32(s.GetPuMonth()), Convert.ToInt32(s.GetPuDay()));

                foreach (string link in links)
                {
                    Dictionary <string, JOffer> map = offerMap[link];
                    List <JOffer> offers            = new List <JOffer>();
                    if (map.Count > 0)
                    {
                        foreach (Category item in Const.categories)
                        {
                            if ((map.ContainsKey(item.Name)) && (map[item.Name] != null))
                            {
                                map[item.Name].SetSiteName(link);
                                offers.Add(map[item.Name]);
                            }
                            else
                            {
                                offers.Add(new JOffer());
                            }
                        }
                    }
                    myWorksheet.Cells[rowNum, 1].Value = s.GetPuMonth() + "-" + s.GetPuDay() + "/" + doDate.AddDays(rowNum - 1).Day + "\n" + (rowNum - 1);
                    for (int i = 0; i < offers.Count; i++)
                    {
                        myWorksheet.Cells[rowNum, i + 2].Value = offers.ElementAt(i).GetOffer();
                        myWorksheet.Row(rowNum).Height         = 45;
                    }
                    ++rowNum;
                }
                excelPackage.Save();// Saving the change...
            }
            return(filename);
        }
Example #3
0
        private void OnDayStarted(object sender, DayStartedEventArgs e)
        {
            // Set up notification messages
            MESSAGE_EVERYTHING_FAILING = new KeyValuePair <string, int>(i18n.Get("status_message.ship_falling_apart"), 10);
            MESSAGE_LOSING_FISH        = new KeyValuePair <string, int>(i18n.Get("status_message.losing_fish"), 9);
            MESSAGE_MAX_LEAKS          = new KeyValuePair <string, int>(i18n.Get("status_message.taking_on_water"), 8);
            MESSAGE_MULTI_PROBLEMS     = new KeyValuePair <string, int>(i18n.Get("status_message.lots_of_problems"), 7);
            MESSAGE_ENGINE_PROBLEM     = new KeyValuePair <string, int>(i18n.Get("status_message.engine_failing"), 7);
            MESSAGE_NET_PROBLEM        = new KeyValuePair <string, int>(i18n.Get("status_message.nets_torn"), 6);
            MESSAGE_LEAK_PROBLEM       = new KeyValuePair <string, int>(i18n.Get("status_message.leak"), 5);

            todayDayOfWeek = SDate.Now().DayOfWeek.ToString();

            Beach beach = Game1.getLocationFromName("Beach") as Beach;

            beach.modData[MURPHY_ON_TRIP] = "false";

            IslandSouthEast island = Game1.getLocationFromName("IslandSouthEast") as IslandSouthEast;

            island.modData[MURPHY_ON_TRIP] = "false";

            // Set Farmer moddata used for this mod
            EstablishPlayerData();

            if (Context.IsMainPlayer)
            {
                // Must be a user set date (default Wednesday), the player's fishing level >= 3 and the bridge must be fixed on the beach
                if (!Game1.MasterPlayer.mailReceived.Contains("PeacefulEnd.FishingTrawler_WillyIntroducesMurphy") && Game1.MasterPlayer.FishingLevel >= config.minimumFishingLevel && beach.bridgeFixed && todayDayOfWeek == Game1.MasterPlayer.modData[MURPHY_DAY_TO_APPEAR])
                {
                    Monitor.Log($"Sending {Game1.MasterPlayer.Name} intro letter about Murphy!", LogLevel.Trace);
                    Helper.Content.AssetEditors.Add(new CustomMail());
                    Game1.MasterPlayer.mailbox.Add("PeacefulEnd.FishingTrawler_WillyIntroducesMurphy");
                }

                // Must be a user set island date (default Satuday), met Murphy and Ginger Island's resort must be built
                IslandSouth resort = Game1.getLocationFromName("IslandSouth") as IslandSouth;
                if (!Game1.MasterPlayer.mailReceived.Contains("PeacefulEnd.FishingTrawler_MurphyGingerIsland") && Game1.MasterPlayer.mailReceived.Contains("PeacefulEnd.FishingTrawler_WillyIntroducesMurphy") && resort.resortRestored && todayDayOfWeek == Game1.MasterPlayer.modData[MURPHY_DAY_TO_APPEAR_ISLAND])
                {
                    Monitor.Log($"Sending {Game1.MasterPlayer.Name} Ginger Island letter about Murphy!", LogLevel.Trace);
                    Helper.Content.AssetEditors.Add(new CustomMail());
                    Game1.MasterPlayer.mailbox.Add("PeacefulEnd.FishingTrawler_MurphyGingerIsland");
                }
            }

            // Reset ownership of boat, deckhands
            mainDeckhand      = null;
            numberOfDeckhands = 0;

            // Set the reward chest
            Vector2 rewardChestPosition = new Vector2(-100, -100);
            Farm    farm = Game1.getLocationFromName("Farm") as Farm;

            rewardChest = farm.objects.Values.FirstOrDefault(o => o.modData.ContainsKey(REWARD_CHEST_DATA_KEY)) as Chest;
            if (rewardChest is null)
            {
                Monitor.Log($"Creating reward chest {rewardChestPosition}", LogLevel.Trace);
                rewardChest = new Chest(true, rewardChestPosition)
                {
                    Name = "Trawler Rewards"
                };
                rewardChest.modData.Add(REWARD_CHEST_DATA_KEY, "true");

                farm.setObject(rewardChestPosition, rewardChest);
            }

            // Create the trawler object for the beach
            var locationContext = (todayDayOfWeek == Game1.MasterPlayer.modData[MURPHY_DAY_TO_APPEAR_ISLAND] ? GameLocation.LocationContext.Island : GameLocation.LocationContext.Default);

            if (todayDayOfWeek == Game1.MasterPlayer.modData[MURPHY_DAY_TO_APPEAR_ISLAND])
            {
                trawlerObject = new Trawler(island);
            }
            else
            {
                trawlerObject = new Trawler(beach);
            }

            // Create the TrawlerReward class
            _trawlerRewards.Value = new TrawlerRewards(rewardChest);

            // Add the surface location
            TrawlerSurface surfaceLocation = new TrawlerSurface(Path.Combine(ModResources.assetFolderPath, "Maps", "FishingTrawler.tmx"), TRAWLER_SURFACE_LOCATION_NAME)
            {
                IsOutdoors = true, IsFarm = false, locationContext = locationContext
            };

            Game1.locations.Add(surfaceLocation);

            // Add the hull location
            TrawlerHull hullLocation = new TrawlerHull(Path.Combine(ModResources.assetFolderPath, "Maps", "TrawlerHull.tmx"), TRAWLER_HULL_LOCATION_NAME)
            {
                IsOutdoors = false, IsFarm = false, locationContext = locationContext
            };

            Game1.locations.Add(hullLocation);

            // Add the cabin location
            TrawlerCabin cabinLocation = new TrawlerCabin(Path.Combine(ModResources.assetFolderPath, "Maps", "TrawlerCabin.tmx"), TRAWLER_CABIN_LOCATION_NAME)
            {
                IsOutdoors = false, IsFarm = false, locationContext = locationContext
            };

            Game1.locations.Add(cabinLocation);

            // Verify our locations were added and establish our location variables
            _trawlerHull.Value    = Game1.getLocationFromName(TRAWLER_HULL_LOCATION_NAME) as TrawlerHull;
            _trawlerSurface.Value = Game1.getLocationFromName(TRAWLER_SURFACE_LOCATION_NAME) as TrawlerSurface;
            _trawlerCabin.Value   = Game1.getLocationFromName(TRAWLER_CABIN_LOCATION_NAME) as TrawlerCabin;
        }
Example #4
0
        internal static void UpdateWhenCurrentLocationPatch(Beach __instance, GameTime time)
        {
            // Update the Murphy NPC
            if (ModEntry.ShouldMurphyAppear(__instance) && ModEntry.murphyNPC == null)
            {
                ModEntry.SpawnMurphy();
            }

            if (ModEntry.murphyNPC != null)
            {
                ModEntry.murphyNPC.update(time, __instance);

                if (__instance.modData.ContainsKey(ModEntry.MURPHY_ON_TRIP) && __instance.modData[ModEntry.MURPHY_ON_TRIP] == "true")
                {
                    ModEntry.murphyNPC = null;
                }
            }

            // Update the appearance of the reward chest
            if (ModEntry.rewardChest.items.Count() == 0 && __instance.getTileIndexAt(new Point(82, 37), "Buildings") != 10)
            {
                SwapRewardChestTiles(__instance, 10);
            }
            else if (ModEntry.rewardChest.items.Count() > 0 && __instance.getTileIndexAt(new Point(82, 37), "Buildings") != 0)
            {
                SwapRewardChestTiles(__instance, 0);
            }

            Trawler trawler = ModEntry.trawlerObject;

            if (trawler is null)
            {
                return;
            }

            if (trawler._boatDirection != 0)
            {
                trawler._boatOffset += trawler._boatDirection;
                if (__instance.currentEvent != null)
                {
                    foreach (NPC actor in __instance.currentEvent.actors)
                    {
                        actor.shouldShadowBeOffset = true;
                        actor.drawOffset.X         = trawler._boatOffset;
                    }
                    foreach (Farmer farmerActor in __instance.currentEvent.farmerActors)
                    {
                        farmerActor.shouldShadowBeOffset = true;
                        farmerActor.drawOffset.X         = trawler._boatOffset;
                    }
                }
            }

            Microsoft.Xna.Framework.Rectangle back_rectangle = new Microsoft.Xna.Framework.Rectangle(24, 188, 16, 220);
            back_rectangle.X += (int)trawler.GetTrawlerPosition().X;
            back_rectangle.Y += (int)trawler.GetTrawlerPosition().Y;
            if ((float)trawler._boatDirection != 0f)
            {
                if (trawler._nextBubble > 0f)
                {
                    trawler._nextBubble -= (float)time.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    Vector2 position2 = Utility.getRandomPositionInThisRectangle(back_rectangle, Game1.random);
                    TemporaryAnimatedSprite sprite2 = new TemporaryAnimatedSprite("TileSheets\\animations", new Microsoft.Xna.Framework.Rectangle(0, 0, 64, 64), 50f, 9, 1, position2, flicker: false, flipped: false, 0f, 0.025f, Color.White, 1f, 0f, 0f, 0f);
                    sprite2.acceleration = new Vector2(-0.25f * (float)Math.Sign(trawler._boatDirection), 0f);
                    if (Context.IsSplitScreen)
                    {
                        ModEntry.multiplayer.broadcastSprites(__instance, sprite2);
                    }
                    else
                    {
                        __instance.temporarySprites.Add(sprite2);
                    }
                    trawler._nextBubble = 0.01f;
                }
                if (trawler._nextSlosh > 0f)
                {
                    trawler._nextSlosh -= (float)time.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    Game1.playSound("waterSlosh");
                    trawler._nextSlosh = 0.5f;
                }
            }
            if (trawler._boatAnimating)
            {
                if (trawler._nextSmoke > 0f)
                {
                    trawler._nextSmoke -= (float)time.ElapsedGameTime.TotalSeconds;
                    return;
                }
                Vector2 position = new Vector2(158f, -32f) * 4f + trawler.GetTrawlerPosition();
                TemporaryAnimatedSprite sprite = new TemporaryAnimatedSprite("TileSheets\\animations", new Microsoft.Xna.Framework.Rectangle(0, 1600, 64, 128), 200f, 9, 1, position, flicker: false, flipped: false, 1f, 0.025f, Color.Gray, 1f, 0.025f, 0f, 0f);
                sprite.acceleration = new Vector2(-0.25f, -0.15f);
                __instance.temporarySprites.Add(sprite);
                trawler._nextSmoke = 0.2f;
            }
        }
Example #5
0
        private void OnDayStarted(object sender, DayStartedEventArgs e)
        {
            todayDayOfWeek = SDate.Now().DayOfWeek.ToString();

            Beach beach = Game1.getLocationFromName("Beach") as Beach;

            beach.modData[MURPHY_ON_TRIP] = "false";

            // Set Farmer moddata used for this mod
            EstablishPlayerData();

            if (Context.IsMainPlayer)
            {
                // Must be a Wednesday, the player's fishing level >= 3 and the bridge must be fixed on the beach
                if (!Game1.MasterPlayer.mailReceived.Contains("PeacefulEnd.FishingTrawler_WillyIntroducesMurphy") && Game1.MasterPlayer.FishingLevel >= config.minimumFishingLevel && beach.bridgeFixed && todayDayOfWeek == Game1.MasterPlayer.modData[MURPHY_DAY_TO_APPEAR])
                {
                    Monitor.Log($"Sending {Game1.MasterPlayer.Name} intro letter about Murphy!", LogLevel.Trace);
                    Helper.Content.AssetEditors.Add(new IntroMail());
                    Game1.MasterPlayer.mailbox.Add("PeacefulEnd.FishingTrawler_WillyIntroducesMurphy");
                }
            }

            // Reset ownership of boat, deckhands
            mainDeckhand      = null;
            numberOfDeckhands = 0;

            // Set the reward chest
            Vector2 rewardChestPosition = new Vector2(-100, -100);
            Farm    farm = Game1.getLocationFromName("Farm") as Farm;

            rewardChest = farm.objects.Values.FirstOrDefault(o => o.modData.ContainsKey(REWARD_CHEST_DATA_KEY)) as Chest;
            if (rewardChest is null)
            {
                Monitor.Log($"Creating reward chest {rewardChestPosition}", LogLevel.Trace);
                rewardChest = new Chest(true, rewardChestPosition)
                {
                    Name = "Trawler Rewards"
                };
                rewardChest.modData.Add(REWARD_CHEST_DATA_KEY, "true");

                farm.setObject(rewardChestPosition, rewardChest);
            }

            // Create the trawler object for the beach
            trawlerObject = new Trawler(beach);

            // Create the TrawlerReward class
            _trawlerRewards.Value = new TrawlerRewards(rewardChest);

            // Add the surface location
            TrawlerSurface surfaceLocation = new TrawlerSurface(Path.Combine(ModResources.assetFolderPath, "Maps", "FishingTrawler.tmx"), TRAWLER_SURFACE_LOCATION_NAME)
            {
                IsOutdoors = true, IsFarm = false
            };

            Game1.locations.Add(surfaceLocation);

            // Add the hull location
            TrawlerHull hullLocation = new TrawlerHull(Path.Combine(ModResources.assetFolderPath, "Maps", "TrawlerHull.tmx"), TRAWLER_HULL_LOCATION_NAME)
            {
                IsOutdoors = false, IsFarm = false
            };

            Game1.locations.Add(hullLocation);

            // Add the cabin location
            TrawlerCabin cabinLocation = new TrawlerCabin(Path.Combine(ModResources.assetFolderPath, "Maps", "TrawlerCabin.tmx"), TRAWLER_CABIN_LOCATION_NAME)
            {
                IsOutdoors = false, IsFarm = false
            };

            Game1.locations.Add(cabinLocation);

            // Verify our locations were added and establish our location variables
            _trawlerHull.Value    = Game1.getLocationFromName(TRAWLER_HULL_LOCATION_NAME) as TrawlerHull;
            _trawlerSurface.Value = Game1.getLocationFromName(TRAWLER_SURFACE_LOCATION_NAME) as TrawlerSurface;
            _trawlerCabin.Value   = Game1.getLocationFromName(TRAWLER_CABIN_LOCATION_NAME) as TrawlerCabin;
        }