Beispiel #1
0
        private void GameEvents_UpdateTick(object s, EventArgs e)
        {
            EnforceSerializer();
            if (!Context.IsWorldReady)
            {
                return;
            }
            if ((Game1.player.CurrentItem == null && this.prevItem != null) || (Game1.player.CurrentItem != null && !Game1.player.CurrentItem.Equals(this.prevItem)))
            {
                ItemEvents.FireActiveItemChanged(new EventArgsActiveItemChanged(this.prevItem, Game1.player.CurrentItem));
                this.prevItem = Game1.player.CurrentItem;
            }
            PlayerModifierHelper._UpdateModifiers();
            Vector2 playerPos = new Vector2(Game1.player.getStandingX() / Game1.tileSize, Game1.player.getStandingY() / Game1.tileSize);

            if (LastTouchAction == playerPos)
            {
                return;
            }
            string text = Game1.currentLocation.doesTileHaveProperty((int)playerPos.X, (int)playerPos.Y, "TouchAction", "Back");

            LastTouchAction = playerPos;
            if (text == null)
            {
                return;
            }
            string[] split = (text).Split(' ');
            string[] args  = new string[split.Length - 1];
            Array.Copy(split, 1, args, 0, args.Length);
            this.ActionInfo = new EventArgsActionTriggered(Game1.player, split[0], args, playerPos);
            MoreEvents.FireTouchActionTriggered(this.ActionInfo);
        }
Beispiel #2
0
        /// <summary>Raised after the game finishes writing data to the save file (except the initial save creation).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaved(object sender, SavedEventArgs e)
        {
            // delete legacy mod data (migrated into save file by this point)
            {
                FileInfo legacyFile = new FileInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json"));
                if (legacyFile.Exists)
                {
                    legacyFile.Delete();
                }

                DirectoryInfo legacyDir = new DirectoryInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework"));
                if (legacyDir.Exists && !legacyDir.GetFileSystemInfos().Any())
                {
                    legacyDir.Delete();
                }
            }

            // read data
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items") ?? new Dictionary <string, InstanceState>();

            this.RestoreItems(data);
            ItemEvents.FireAfterDeserialize();
        }
Beispiel #3
0
        /// <summary>Raised after the player loads a save slot and the world is initialised.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            // read data
            if (Context.IsMainPlayer)
            {
                this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
                ItemEvents.FireBeforeDeserialize();
                IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items");
                if (data == null)
                {
                    // read from legacy mod file
                    FileInfo legacyFile = new FileInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json"));
                    if (legacyFile.Exists)
                    {
                        data = JsonConvert.DeserializeObject <Dictionary <string, InstanceState> >(File.ReadAllText(legacyFile.FullName));
                    }
                }

                if (data == null)
                {
                    data = new Dictionary <string, InstanceState>();
                }
                this.RestoreItems(data);
                ItemEvents.FireAfterDeserialize();
            }
        }
        private void SaveEvents_BeforeSave(object s, EventArgs e)
        {
            this.Monitor.Log("Packing custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeSerialize();
            var data = new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                foreach (Chest chest in loc.objects.Where(a => a.Value is Chest).Select(a => (Chest)a.Value))
                {
                    chest.items = Serialize(data, chest.items);
                }
            }
            Game1.player.items = Serialize(data, Game1.player.items);
            var house = (Game1.getLocationFromName("FarmHouse") as StardewValley.Locations.FarmHouse);

            if (house.fridge != null)
            {
                house.fridge.items = Serialize(data, house.fridge.items);
            }
            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");

            this.Helper.WriteJsonFile(path, data);
            ItemEvents.FireAfterSerialize();
        }
Beispiel #5
0
        /// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaving(object sender, SavingEventArgs e)
        {
            if (Context.IsMainPlayer)
            {
                this.Monitor.Log("Packing custom objects...", LogLevel.Trace);
                ItemEvents.FireBeforeSerialize();
                Dictionary <string, InstanceState> data = new Dictionary <string, InstanceState>();
                foreach (GameLocation loc in Game1.locations)
                {
                    foreach (Chest chest in loc.Objects.Values.OfType <Chest>())
                    {
                        this.Serialize(data, chest.items);
                    }
                }

                this.Serialize(data, Game1.player.Items);
                FarmHouse house = Game1.getLocationFromName("FarmHouse") as FarmHouse;

                if (house.fridge.Value != null)
                {
                    this.Serialize(data, house.fridge.Value.items);
                }
                this.Helper.Data.WriteSaveData("custom-items", data);
                ItemEvents.FireAfterSerialize();
            }
        }
Beispiel #6
0
        /// <summary>Raised after the game state is updated (≈60 times per second).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
        {
            this.EnforceSerializer();
            if (!Context.IsWorldReady)
            {
                return;
            }
            if (Game1.player.CurrentItem == null && this.PrevItem != null || Game1.player.CurrentItem != null && !Game1.player.CurrentItem.Equals(this.PrevItem))
            {
                ItemEvents.FireActiveItemChanged(new EventArgsActiveItemChanged(this.PrevItem, Game1.player.CurrentItem));
                this.PrevItem = Game1.player.CurrentItem;
            }

            IModHelperExtensions.PlayerModifierHelper.UpdateTick();
            if (Context.IsPlayerFree)
            {
                Vector2 playerPos = new Vector2(Game1.player.getStandingX() / Game1.tileSize, Game1.player.getStandingY() / Game1.tileSize);
                if (EntoaroxFrameworkMod.LastTouchAction != playerPos)
                {
                    string text = Game1.currentLocation.doesTileHaveProperty((int)playerPos.X, (int)playerPos.Y, "TouchAction", "Back");
                    EntoaroxFrameworkMod.LastTouchAction = playerPos;
                    if (text != null)
                    {
                        string[] split = text.Split(' ');
                        string[] args  = new string[split.Length - 1];
                        Array.Copy(split, 1, args, 0, args.Length);
                        this.ActionInfo = new EventArgsActionTriggered(Game1.player, split[0], args, playerPos);
                        MoreEvents.FireTouchActionTriggered(this.ActionInfo);
                    }
                }
            }
        }
Beispiel #7
0
        private void RestoreSave()
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }
            // read data
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            Dictionary <string, Tuple <bool, InstanceState> > locations = this.Helper.Data.ReadSaveData <Dictionary <string, Tuple <bool, InstanceState> > >("custom-locations") ?? new Dictionary <string, Tuple <bool, InstanceState> >();

            foreach (var location in locations)
            {
                if (location.Value.Item1)
                {
                    return;
                }
                Game1.locations.Remove(Game1.getLocationFromName(location.Key));
                Game1.locations.Add(location.Value.Item2.Restore <GameLocation>());
            }
            IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items") ?? new Dictionary <string, InstanceState>();

            this.RestoreItems(data);
            List <Tuple <string, Vector2, InstanceState> > features = this.Helper.Data.ReadSaveData <List <Tuple <string, Vector2, InstanceState> > >("custom-features") ?? new List <Tuple <string, Vector2, InstanceState> >();

            foreach (var feature in features)
            {
                Game1.getLocationFromName(feature.Item1)?.terrainFeatures.Add(feature.Item2, feature.Item3.Restore <TerrainFeature>());
            }
            ItemEvents.FireAfterDeserialize();
        }
        /// <summary>
        /// Drop item in town and record it so we can avoid picking it up again.
        /// </summary>
        public static async Task <CoroutineResult> Drop(ACDItem item)
        {
            if (!ZetaDia.IsInGame || !ZetaDia.IsInTown || item.IsAccountBound)
            {
                return(CoroutineResult.NoAction);
            }

            s_logger.Information($"[{nameof(Drop)}] Dropping {item.Name} ({item.ActorSnoId}) in town. AnnId={item.AnnId} ");

            bool dropResult = false;

            try
            {
                dropResult = item.Drop();
            }
            catch (InjectionSEHException)
            {
                s_logger.Information($"[{nameof(DropItems)}] Failed to Drop {item.Name} ({item.ActorSnoId}) in town. AnnId={item.AnnId} ");
                DroppedItemAnnIds.Add(item.AnnId);
            }

            if (dropResult)
            {
                DroppedItemAnnIds.Add(item.AnnId);
                ItemEvents.FireItemDropped(item);
                await Coroutine.Yield();

                return(CoroutineResult.Done);
            }

            return(CoroutineResult.Failed);
        }
        public async Task <IActionResult> PutItemEvents(int id, ItemEvents itemEvents)
        {
            if (id != itemEvents.ItemEventId)
            {
                return(BadRequest());
            }

            _context.Entry(itemEvents).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemEventsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #10
0
        /// <summary>
        /// Drop item in town and record it so we can avoid picking it up again.
        /// </summary>
        public static async Task <bool> Drop(TrinityItem item)
        {
            if (!ZetaDia.IsInGame || !ZetaDia.IsInTown || item.IsAccountBound)
            {
                return(false);
            }

            Core.Logger.Log($"[DropItems] --> Dropping {item.Name} ({item.ActorSnoId}) in town. AnnId={item.AnnId} ");

            bool dropResult = false;

            try
            {
                dropResult = item.Drop();
            }
            catch (InjectionSEHException)
            {
                Core.Logger.Log($"[DropItems] --> Failed to Drop {item.Name} ({item.ActorSnoId}) in town. AnnId={item.AnnId} ");
                DroppedItemAnnIds.Add(item.AnnId);
            }

            if (dropResult)
            {
                DroppedItemAnnIds.Add(item.AnnId);
                ItemEvents.FireItemDropped(item);
                await Coroutine.Sleep(500);

                return(true);
            }

            return(false);
        }
Beispiel #11
0
        private void SaveEvents_AfterSave(object s, EventArgs e)
        {
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");
            var    data = this.Helper.ReadJsonFile <Dictionary <string, InstanceState> >(path) ?? new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                foreach (SObject objects in loc.Objects.Values)
                {
                    if (objects is Chest chest)
                    {
                        chest = new Chest(chest.coins.Value, Deserialize(data, chest.items), chest.TileLocation, chest.giftbox.Value, chest.giftboxIndex.Value);
                    }
                }
            }
            Game1.player.Items = Deserialize(data, Game1.player.Items);
            if (Game1.getLocationFromName("FarmHouse") is FarmHouse house)
            {
                house.fridge.Value?.items.Clear();
                if (house.fridge.Value != null)
                {
                    var items = this.Deserialize(data, house.fridge.Value.items);
                    foreach (Item item in items)
                    {
                        house.fridge.Value.addItem(item);
                    }
                }
            }
            ItemEvents.FireAfterDeserialize();
        }
Beispiel #12
0
        private void SaveEvents_BeforeSave(object s, EventArgs e)
        {
            this.Monitor.Log("Packing custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeSerialize();
            var data = new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                //TODO Testing.    look into where Chests & Fridge store thier item locations

                /*[22:58:19 ERROR Entoarox Framework] This mod failed in the SaveEvents.AfterSave event. Technical details:
                 * System.InvalidCastException: Unable to cast object of type 'StardewValley.Object' to type 'StardewValley.Objects.Chest'.
                 * at Entoarox.Framework.Core.EntoaroxFrameworkMod.SaveEvents_AfterSave(Object s, EventArgs e)
                 * at StardewModdingAPI.Framework.Events.ManagedEvent.Raise() in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\Events\ManagedEvent.cs:line 126
                 */
                foreach (SObject objects in loc.Objects.Values)
                {
                    if (objects is Chest chest)
                    {
                        Serialize(data, chest.items);
                    }
                }
            }
            Game1.player.Items = Serialize(data, Game1.player.Items);
            if (Game1.getLocationFromName("FarmHouse") is FarmHouse house && house.fridge.Value != null)
            {
                Serialize(data, house.fridge.Value.items);
            }


            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");

            this.Helper.WriteJsonFile(path, data);
            ItemEvents.FireAfterSerialize();
        }
Beispiel #13
0
        private void SaveEvents_BeforeSave(object s, EventArgs e)
        {
            this.Monitor.Log("Packing custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeSerialize();
            Dictionary <string, InstanceState> data = new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                foreach (Chest chest in loc.Objects.Values.OfType <Chest>())
                {
                    this.Serialize(data, chest.items);
                }
            }

            this.Serialize(data, Game1.player.Items);
            FarmHouse house = Game1.getLocationFromName("FarmHouse") as FarmHouse;

            if (house.fridge.Value != null)
            {
                this.Serialize(data, house.fridge.Value.items);
            }
            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");

            this.Helper.WriteJsonFile(path, data);
            ItemEvents.FireAfterSerialize();
        }
Beispiel #14
0
        public void GetGeneralUnlocks(ICLIFlags toolFlags)
        {
            string basePath;

            if (toolFlags is ExtractFlags flags)
            {
                basePath = flags.OutputPath;
            }
            else
            {
                throw new Exception("no output path");
            }

            foreach (var key in TrackedFiles[0x54])
            {
                STUGlobalInventoryMaster invMaster = GetInstance <STUGlobalInventoryMaster>(key);
                if (invMaster == null)
                {
                    continue;
                }

                var achivementUnlocks = invMaster.AchievementUnlocks?.Unlocks?.Select(it => GatherUnlock((ulong)it)).ToList();
                SprayAndIcon.SaveItems(basePath, null, "General", "Achievements", flags, achivementUnlocks);

                if (invMaster.EventGeneralUnlocks != null)
                {
                    foreach (var eventUnlocks in invMaster.EventGeneralUnlocks)
                    {
                        if (eventUnlocks?.Unlocks?.Unlocks == null)
                        {
                            continue;
                        }

                        var eventKey = ItemEvents.GetInstance().EventsNormal[(uint)eventUnlocks.Event];
                        var unlocks  = eventUnlocks.Unlocks.Unlocks.Select(it => GatherUnlock((ulong)it)).ToList();
                        SprayAndIcon.SaveItems(basePath, null, "General", eventKey, flags, unlocks);
                    }
                }

                if (invMaster.LevelUnlocks != null)
                {
                    var unlocks = new HashSet <ItemInfo>();
                    foreach (var levelUnlocks in invMaster.LevelUnlocks)
                    {
                        if (levelUnlocks?.Unlocks == null)
                        {
                            continue;
                        }
                        foreach (var unlock in levelUnlocks.Unlocks)
                        {
                            unlocks.Add(GatherUnlock(unlock));
                        }
                    }

                    SprayAndIcon.SaveItems(basePath, null, "General", "Standard", flags, unlocks.ToList());
                    Portrait.SaveItems(basePath, null, "General", "Standard", flags, unlocks.ToList());
                }
            }
        }
Beispiel #15
0
        public static Dictionary <string, HashSet <ItemInfo> > GetUnlocksForHero(ulong guid)
        {
            Dictionary <string, HashSet <ItemInfo> > @return = new Dictionary <string, HashSet <ItemInfo> >();

            STUHeroUnlocks unlocks = GetInstance <STUHeroUnlocks>(guid);

            if (unlocks == null)
            {
                return(null);
            }
            @return["Default"] = GatherUnlocks(unlocks.SystemUnlocks?.Unlocks?.Select(it => (ulong)it));

            if (unlocks.Unlocks != null)
            {
                foreach (STUUnlocks defaultUnlocks in unlocks.Unlocks)
                {
                    if (defaultUnlocks?.Unlocks == null)
                    {
                        continue;
                    }

                    if ([email protected]("Standard"))
                    {
                        @return["Standard"] = new HashSet <ItemInfo>();
                    }

                    foreach (ItemInfo info in GatherUnlocks(defaultUnlocks.Unlocks.Select(it => (ulong)it)))
                    {
                        @return["Standard"].Add(info);
                    }
                }
            }

            if (unlocks.LootboxUnlocks != null)
            {
                foreach (STULootBoxUnlocks eventUnlocks in unlocks.LootboxUnlocks)
                {
                    if (eventUnlocks?.Unlocks?.Unlocks == null)
                    {
                        continue;
                    }

                    string eventKey = $"Event/{ItemEvents.GetInstance().EventsNormal[(uint)eventUnlocks.Event]}";

                    if ([email protected](eventKey))
                    {
                        @return[eventKey] = new HashSet <ItemInfo>();
                    }

                    foreach (ItemInfo info in GatherUnlocks(eventUnlocks.Unlocks.Unlocks.Select(it => (ulong)it)))
                    {
                        @return[eventKey].Add(info);
                    }
                }
            }

            return(@return);
        }
Beispiel #16
0
        public Dictionary <string, HashSet <ItemInfo> > GetUnlocks()
        {
            Dictionary <string, HashSet <ItemInfo> > @return = new Dictionary <string, HashSet <ItemInfo> >();

            foreach (ulong key in TrackedFiles[0x54])
            {
                STUGlobalInventoryMaster invMaster = GetInstance <STUGlobalInventoryMaster>(key);
                if (invMaster == null)
                {
                    continue;
                }

                @return["Achievement"] = GatherUnlocks(invMaster.AchievementUnlocks?.Unlocks?.Select(it => (ulong)it));

                @return["Standard"] = new HashSet <ItemInfo>();

                if (invMaster.LevelUnlocks != null)
                {
                    foreach (STUAdditionalUnlocks levelUnlocks in invMaster.LevelUnlocks)
                    {
                        if (levelUnlocks?.Unlocks == null)
                        {
                            continue;
                        }

                        foreach (ItemInfo info in GatherUnlocks(levelUnlocks.Unlocks.Select(it => (ulong)it)))
                        {
                            @return["Standard"].Add(info);
                        }
                    }
                }

                if (invMaster.EventGeneralUnlocks != null)
                {
                    foreach (STULootBoxUnlocks eventUnlocks in invMaster.EventGeneralUnlocks)
                    {
                        if (eventUnlocks?.Unlocks?.Unlocks == null)
                        {
                            continue;
                        }

                        string eventKey = $"Event/{ItemEvents.GetInstance().EventsNormal[(uint)eventUnlocks.Event]}";

                        if ([email protected](eventKey))
                        {
                            @return[eventKey] = new HashSet <ItemInfo>();
                        }

                        foreach (ItemInfo info in GatherUnlocks(eventUnlocks.Unlocks.Unlocks.Select(it => (ulong)it)))
                        {
                            @return[eventKey].Add(info);
                        }
                    }
                }
            }

            return(@return);
        }
 private void Awake()
 {
     instance         = this;
     playerEvents     = new PlayerEvents();
     evilPlayerEvents = new EvilPlayerEvents();
     enemyEvents      = new EnemyEvents();
     levelEvents      = new LevelEvents();
     enviromentEvents = new EnviromentEvents();
     weaponEvents     = new WeaponEvents();
     itemEvents       = new ItemEvents();
 }
Beispiel #18
0
        public GameItem SetupItem(GameEntity ent, string name, Vector3Int pos, Player owner)
        {
            var index = Loader.GetIndexByName(name);
            var npc   = LuaNpcGetter.GetNpcById(index);

            ent.Owner        = owner;
            ent.OriginalName = name;
            ent.name         = name;
            var item = ent as GameItem;

            var evoTo = LuaNpcGetter.GetEvolutionTo(npc);

            if (evoTo.Length > 0)
            {
                if (!UnitEvolution.IsHasSoloEvolution(name))
                {
                    UnitEvolution.AddToSoloDict(name, evoTo);
                }

                if (item != null)
                {
                    item.SoloEvolution = true;
                }
            }

            var evoCross = LuaNpcGetter.GetNpcEvoCrossing(npc);

            if (evoCross.Keys.Count > 0)
            {
                foreach (var pair in evoCross)
                {
                    UnitEvolution.AddToStackDict(name, pair.Key, pair.Value);

                    if (!string.Equals(pair.Key, name, StringComparison.OrdinalIgnoreCase))
                    {
                        UnitEvolution.AddToStackDict(pair.Key, name, pair.Value);
                    }
                }
            }
            if (GroupUtil.IsItem(ent.Group))
            {
                SecondaryGroundLvL.SetGroundEnt(ChunkNumber, pos, item);
            }

            if (GroupUtil.isBuilding(ent.Group))
            {
                ChunkManager.AddVision(ent);
            }
            ItemEvents.OnCreateItem(item, firstCreate);

            Coloring.RecolorObject(ChunkUtil.GetDovvner(ent.CurrentPos));

            return(item);
        }
Beispiel #19
0
        public static async Task <CoroutineResult> SellItems()
        {
            if (!ZetaDia.IsInTown)
            {
                return(CoroutineResult.NoAction);
            }

            var sellItem = InventoryManager.Backpack
                           .FirstOrDefault(i => ShouldSell(i) &&
                                           InventoryManager.CanSellItem(i));

            if (sellItem == null)
            {
                if (await RepairItems() == CoroutineResult.Running)
                {
                    return(CoroutineResult.Running);
                }

                GameUI.CloseVendorWindow();
                return(CoroutineResult.Done);
            }

            if (!UIElements.VendorWindow.IsVisible)
            {
                var merchant = TownInfo.NearestMerchant;
                if (merchant == null)
                {
                    s_logger.Error($"[{nameof(SellItems)}] Unable to find merchant info for this area :(");
                    return(CoroutineResult.Failed);
                }

                if (await CommonCoroutines.MoveAndInteract(
                        merchant.GetActor(),
                        () => UIElements.VendorWindow.IsVisible) == CoroutineResult.Running)
                {
                    return(CoroutineResult.Running);
                }
            }

            if (!sellItem.IsValid || sellItem.IsUnidentified)
            {
                s_logger.Debug($"[{nameof(SellItems)}] Invalid Items Detected: IsValid={sellItem.IsValid} IsUnidentified={sellItem.IsUnidentified}");
                return(CoroutineResult.Failed);
            }

            s_logger.Debug($"[{nameof(SellItems)}] Selling: {sellItem.Name} ({sellItem.ActorSnoId}) Quality={sellItem.ItemQualityLevel} IsAncient={sellItem.Stats.IsAncient} Name={sellItem.InternalName}");
            ItemEvents.FireItemSold(sellItem);
            InventoryManager.SellItem(sellItem);
            Core.Inventory.InvalidAnnIds.Add(sellItem.AnnId);
            return(CoroutineResult.Running);
        }
Beispiel #20
0
        public void OnDropped()
        {
            if (IsPickupNoClick)
            {
                return;
            }

            if (IsPrimalAncient)
            {
                Core.Logger.Warn($"Primal {Name} dropped. (SnoId={ActorSnoId} Ann={AnnId} AcdId={AcdId} GbId={GameBalanceId}) InternalName={InternalName} Quality={ItemQualityLevel} Ancient={IsAncient} Primal={IsPrimalAncient} RawType={RawItemType}");
            }
            else
            {
                Core.Logger.Log($"{Name} dropped. (SnoId={ActorSnoId} Ann={AnnId} AcdId={AcdId} GbId={GameBalanceId}) InternalName={InternalName} Quality={ItemQualityLevel} Ancient={IsAncient} Primal={IsPrimalAncient} RawType={RawItemType}");
            }

            ItemEvents.FireItemDropped(this);
        }
Beispiel #21
0
 /// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void OnSaving(object sender, SavingEventArgs e)
 {
     if (Context.IsMainPlayer)
     {
         this.Monitor.Log("Packing custom objects...", LogLevel.Trace);
         ItemEvents.FireBeforeSerialize();
         var data      = new Dictionary <string, InstanceState>();
         var features  = new List <Tuple <string, Vector2, InstanceState> >();
         var locations = new Dictionary <string, Tuple <bool, InstanceState> >();
         foreach (var loc in this.GetAllLocations())
         {
             foreach (Chest chest in loc.Objects.Values.OfType <Chest>())
             {
                 this.Serialize(data, chest.items);
             }
             this.Serialize(data, loc.Objects);
             if (loc.terrainFeatures != null)
             {
                 this.Serialize(features, loc, loc.terrainFeatures);
             }
         }
         foreach (var location in Game1.locations.Where(a => a is ICustomItem).ToArray())
         {
             Game1.locations.Remove(location);
             this.Serialize(locations, location);
         }
         this.Serialize(data, Game1.player.Items);
         FarmHouse house = Game1.getLocationFromName("FarmHouse") as FarmHouse;
         if (house.fridge.Value != null)
         {
             this.Serialize(data, house.fridge.Value.items);
         }
         this.Monitor.Log("Found and serialized [" + data.Count + "] Item instances", LogLevel.Trace);
         this.Monitor.Log("Found and serialized [" + features.Count + "] TerrainFeature instances", LogLevel.Trace);
         this.Monitor.Log("Found and serialized [" + locations.Count + "] GameLocation instances", LogLevel.Trace);
         string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework");
         this.Helper.Data.WriteSaveData("custom-items", data);
         this.Helper.Data.WriteSaveData("custom-features", features);
         this.Helper.Data.WriteSaveData("custom-locations", locations);
         ItemEvents.FireAfterSerialize();
         this.Monitor.Log("Packing complete", LogLevel.Trace);
     }
 }
        /// <summary>Raised after the game finishes writing data to the save file (except the initial save creation).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnSaved(object sender, SavedEventArgs e)
        {
            // delete legacy mod data (migrated into save file by this point)
            {
                FileInfo legacyFile = new FileInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json"));
                if (legacyFile.Exists)
                {
                    legacyFile.Delete();
                }

                DirectoryInfo legacyDir = new DirectoryInfo(Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework"));
                if (legacyDir.Exists && !legacyDir.GetFileSystemInfos().Any())
                {
                    legacyDir.Delete();
                }
            }

            // read data
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            Dictionary <string, Tuple <bool, InstanceState> > locations = this.Helper.Data.ReadSaveData <Dictionary <string, Tuple <bool, InstanceState> > >("custom-locations") ?? new Dictionary <string, Tuple <bool, InstanceState> >();

            foreach (var location in locations)
            {
                if (location.Value.Item1)
                {
                    return;
                }
                Game1.locations.Remove(Game1.getLocationFromName(location.Key));
                Game1.locations.Add(location.Value.Item2.Restore <GameLocation>());
            }
            IDictionary <string, InstanceState> data = this.Helper.Data.ReadSaveData <Dictionary <string, InstanceState> >("custom-items") ?? new Dictionary <string, InstanceState>();

            this.RestoreItems(data);
            List <Tuple <string, Vector2, InstanceState> > features = this.Helper.Data.ReadSaveData <List <Tuple <string, Vector2, InstanceState> > >("custom-features") ?? new List <Tuple <string, Vector2, InstanceState> >();

            foreach (var feature in features)
            {
                Game1.getLocationFromName(feature.Item1)?.terrainFeatures.Add(feature.Item2, feature.Item3.Restore <TerrainFeature>());
            }
            ItemEvents.FireAfterDeserialize();
        }
Beispiel #23
0
        private void SaveEvents_AfterSave(object s, EventArgs e)
        {
            this.Monitor.Log("Unpacking custom objects...", LogLevel.Trace);
            ItemEvents.FireBeforeDeserialize();
            string path = Path.Combine(Constants.CurrentSavePath, "Entoarox.Framework", "CustomItems.json");
            Dictionary <string, InstanceState> data = this.Helper.ReadJsonFile <Dictionary <string, InstanceState> >(path) ?? new Dictionary <string, InstanceState>();

            foreach (GameLocation loc in Game1.locations)
            {
                foreach (Chest chest in loc.Objects.Values.OfType <Chest>())
                {
                    this.Deserialize(data, chest.items);
                }
            }

            FarmHouse house = (FarmHouse)Game1.getLocationFromName("FarmHouse");

            this.Deserialize(data, Game1.player.Items);
            this.Deserialize(data, house.fridge.Value.items);
            ItemEvents.FireAfterDeserialize();
        }
        public async Task <ActionResult <ItemEvents> > PostItemEvents(ItemEvents itemEvents)
        {
            _context.ItemEvents.Add(itemEvents);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ItemEventsExists(itemEvents.ItemEventId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetItemEvents", new { id = itemEvents.ItemEventId }, itemEvents));
        }
Beispiel #25
0
        public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags)
        {
            List <ulong> masters = track[0x75];

            foreach (ulong masterKey in masters)
            {
                if (!map.ContainsKey(masterKey))
                {
                    continue;
                }
                STUD masterStud = new STUD(Util.OpenFile(map[masterKey], handler));

                if (masterStud.Instances == null)
                {
                    continue;
                }
                HeroMaster master = (HeroMaster)masterStud.Instances[0];
                if (master == null)
                {
                    continue;
                }
                string heroName = Util.GetString(master.Header.name.key, map, handler);
                if (heroName == null)
                {
                    continue;
                }
                string goodhero = heroName;
                foreach (var c in Path.GetInvalidFileNameChars())
                {
                    goodhero = goodhero.Replace(c, '_');
                }

                if (master.Header.itemMaster.key == 0)   // AI
                {
                    continue;
                }
                bool ex = System.Diagnostics.Debugger.IsAttached || flags.Expert;

                bool hasName = false;
                if (!map.ContainsKey(master.Header.itemMaster.key))
                {
                    Console.Out.WriteLine("Error loading inventory master file...");
                    continue;
                }
                STUD inventoryStud = new STUD(Util.OpenFile(map[master.Header.itemMaster.key], handler));
#if OUTPUT_STUDINVENTORYMASTER
                Stream studStream  = Util.OpenFile(map[master.Header.itemMaster.key], handler);
                string outFilename = string.Format("./STUDs/ListInventoryMaster/{0}.stud", goodhero);
                string putPathname = outFilename.Substring(0, outFilename.LastIndexOf('/'));
                Directory.CreateDirectory(putPathname);
                Stream OutWriter = File.Create(outFilename);
                studStream.CopyTo(OutWriter);
                OutWriter.Close();
                studStream.Close();
#endif
                InventoryMaster inventory = (InventoryMaster)inventoryStud.Instances[0];
                if (inventory == null)
                {
                    Console.Out.WriteLine("Error loading inventory master file...");
                    continue;
                }

                Dictionary <int, string> indexMap = new Dictionary <int, string>();
                List <OWRecord>          items    = new List <OWRecord>();

                items.AddRange(inventory.Achievables.ToList());

                for (int i = 0; i < inventory.DefaultGroups.Length; ++i)
                {
                    string name = $"STANDARD_{ItemEvents.GetInstance().GetEvent(inventory.DefaultGroups[i].@event)}";
                    items.AddRange(inventory.Defaults[i].ToList());
                }

                for (int i = 0; i < inventory.ItemGroups.Length; ++i)
                {
                    string name = ItemEvents.GetInstance().GetEvent(inventory.ItemGroups[i].@event);
                    items.AddRange(inventory.Items[i].ToList());
                }

                foreach (OWRecord record in items)
                {
                    STUD item = new STUD(Util.OpenFile(map[record], handler));
                    if (item.Instances == null)
                    {
                        continue;
                    }
                    WeaponSkinItem skin = item.Instances[0] as WeaponSkinItem;
                    if (skin == null)
                    {
                        continue;
                    }
                    if (!hasName)
                    {
                        if (ex)
                        {
                            Console.Out.WriteLine("Weapons for {0} ({2:X16}) in package {1:X16}", heroName, map[masterKey].package.packageKey, masterKey);
                        }
                        else
                        {
                            Console.Out.WriteLine("Weapons for {0}", heroName);
                        }
                        hasName = true;
                    }

                    Console.Out.WriteLine("\tIndex {0} - {1}", skin.Data.index, Util.GetString(skin.Header.name, map, handler));
                }

                if (hasName)
                {
                    Console.Out.WriteLine("");
                }
            }
        }
Beispiel #26
0
        public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags)
        {
            List <ulong> masters = track[0x75];

            foreach (ulong masterKey in masters)
            {
                if (!map.ContainsKey(masterKey))
                {
                    continue;
                }
                STUD masterStud = new STUD(Util.OpenFile(map[masterKey], handler));

                if (masterStud.Instances == null)
                {
                    continue;
                }
                HeroMaster master = (HeroMaster)masterStud.Instances[0];
                if (master == null)
                {
                    continue;
                }
                string heroName = Util.GetString(master.Header.name.key, map, handler);
                if (heroName == null)
                {
                    continue;
                }
                string goodhero = heroName;
                foreach (var c in Path.GetInvalidFileNameChars())
                {
                    goodhero = goodhero.Replace(c, '_');
                }

                if (master.Header.itemMaster.key == 0)   // AI
                {
                    continue;
                }
                bool ex = System.Diagnostics.Debugger.IsAttached || flags.Expert;
                if (ex)
                {
                    Console.Out.WriteLine("Cosmetics for {0} ({1:X16})", heroName, GUID.LongKey(masterKey));
                }
                else
                {
                    Console.Out.WriteLine("Cosmetics for {0}", heroName);
                }
                if (!map.ContainsKey(master.Header.itemMaster.key))
                {
                    Console.Out.WriteLine("Error loading inventory master file...");
                    continue;
                }
                STUD inventoryStud = new STUD(Util.OpenFile(map[master.Header.itemMaster.key], handler));
#if OUTPUT_STUDINVENTORYMASTER
                Stream studStream  = Util.OpenFile(map[master.Header.itemMaster.key], handler);
                string outFilename = string.Format("./STUDs/ListInventoryMaster/{0}.stud", goodhero);
                string putPathname = outFilename.Substring(0, outFilename.LastIndexOf('/'));
                Directory.CreateDirectory(putPathname);
                Stream OutWriter = File.Create(outFilename);
                studStream.CopyTo(OutWriter);
                OutWriter.Close();
                studStream.Close();
#endif
                InventoryMaster inventory = (InventoryMaster)inventoryStud.Instances[0];
                if (inventory == null)
                {
                    Console.Out.WriteLine("Error loading inventory master file...");
                    continue;
                }

                Console.Out.WriteLine("\tACHIEVEMENT ({0} items)", inventory.Achievables.Length);
                foreach (OWRecord record in inventory.Achievables)
                {
                    GetInventoryName(record.key, ex, map, handler, goodhero);
                }

                for (int i = 0; i < inventory.DefaultGroups.Length; ++i)
                {
                    if (inventory.Defaults[i].Length == 0)
                    {
                        continue;
                    }
                    OWRecord[] records = inventory.Defaults[i];
                    Console.Out.WriteLine("\tSTANDARD_{0} ({1} items)", ItemEvents.GetInstance().GetEvent(inventory.DefaultGroups[i].@event), records.Length);
                    foreach (OWRecord record in records)
                    {
                        GetInventoryName(record.key, ex, map, handler, goodhero);
                    }
                }

                for (int i = 0; i < inventory.ItemGroups.Length; ++i)
                {
                    if (inventory.Items[i].Length == 0)
                    {
                        continue;
                    }
                    OWRecord[] records = inventory.Items[i];
                    Console.Out.WriteLine("\t{0} ({1} items)", ItemEvents.GetInstance().GetEvent(inventory.ItemGroups[i].@event), records.Length);
                    foreach (OWRecord record in records)
                    {
                        GetInventoryName(record.key, ex, map, handler, goodhero);
                    }
                }
                Console.Out.WriteLine("");
            }
        }
Beispiel #27
0
        public void SaveUnlocksForHeroes(ICLIFlags flags, IEnumerable <STUHero> heroes, string basePath, bool npc = false)
        {
            if (flags.Positionals.Length < 4)
            {
                QueryHelp(QueryTypes);
                return;
            }

            Log("Initializing...");

            Dictionary <string, Dictionary <string, ParsedArg> > parsedTypes = ParseQuery(flags, QueryTypes, QueryNameOverrides);

            if (parsedTypes == null)
            {
                return;
            }

            foreach (STUHero hero in heroes)
            {
                string heroNameActual = GetString(hero.Name);
                string heroFileName   = GetValidFilename(heroNameActual);

                if (heroFileName == null)
                {
                    continue;
                    // heroFileName = "Unknown";
                    // heroNameActual = "Unknown";
                }
                heroNameActual = heroNameActual.TrimEnd(' ');
                heroFileName   = heroFileName.TrimEnd(' ');

                Dictionary <string, ParsedArg> config = new Dictionary <string, ParsedArg>();
                foreach (string key in new [] { heroNameActual.ToLowerInvariant(), "*" })
                {
                    if (!parsedTypes.ContainsKey(key))
                    {
                        continue;
                    }
                    foreach (KeyValuePair <string, ParsedArg> parsedArg in parsedTypes[key])
                    {
                        if (config.ContainsKey(parsedArg.Key))
                        {
                            config[parsedArg.Key] = config[parsedArg.Key].Combine(parsedArg.Value);
                        }
                        else
                        {
                            config[parsedArg.Key] = parsedArg.Value.Combine(null); // clone for safety
                        }
                    }
                }

                if (config.Count == 0)
                {
                    continue;
                }

                var unlocks = GetInstance <STUHeroUnlocks>(hero.LootboxUnlocks);

                if (unlocks?.Unlocks == null && !npc)
                {
                    continue;
                }
                if (unlocks?.LootboxUnlocks != null && npc)
                {
                    continue;
                }

                Log($"Processing data for {heroNameActual}...");

                List <ItemInfo> weaponSkins = ListHeroUnlocks.GetUnlocksForHero(hero.LootboxUnlocks)?.SelectMany(x => x.Value.Where(y => y.Type == "Weapon")).ToList(); // eww?

                var achievementUnlocks = GatherUnlocks(unlocks?.SystemUnlocks?.Unlocks?.Select(it => (ulong)it)).ToList();
                foreach (ItemInfo itemInfo in achievementUnlocks)
                {
                    if (itemInfo == null)
                    {
                        continue;
                    }
                    Dictionary <string, TagExpectedValue> tags = new Dictionary <string, TagExpectedValue> {
                        { "event", new TagExpectedValue("base") }
                    };
                    SaveItemInfo(itemInfo, basePath, heroFileName, flags, hero, "Achievement", config, tags, weaponSkins);
                }

                if (npc)
                {
                    foreach (STUHeroSkin skin in hero.Skins)
                    {
                        if (config.ContainsKey("skin") && config["skin"].ShouldDo(GetFileName(skin.SkinOverride)))
                        {
                            Skin.Save(flags, $"{basePath}\\{RootDir}", hero, skin, false);
                        }
                    }
                    continue;
                }

                foreach (var defaultUnlocks in unlocks.Unlocks)
                {
                    var dUnlocks = GatherUnlocks(defaultUnlocks.Unlocks.Select(it => (ulong)it)).ToList();

                    foreach (ItemInfo itemInfo in dUnlocks)
                    {
                        Dictionary <string, TagExpectedValue> tags = new Dictionary <string, TagExpectedValue> {
                            { "event", new TagExpectedValue("base") }
                        };
                        SaveItemInfo(itemInfo, basePath, heroFileName, flags, hero, "Standard", config, tags, weaponSkins);
                    }
                }

                foreach (var eventUnlocks in unlocks.LootboxUnlocks)
                {
                    if (eventUnlocks?.Unlocks?.Unlocks == null)
                    {
                        continue;
                    }

                    var eventKey = ItemEvents.GetInstance().EventsNormal[(uint)eventUnlocks.Event];
                    var eUnlocks = eventUnlocks.Unlocks.Unlocks.Select(it => GatherUnlock(it)).ToList();

                    foreach (ItemInfo itemInfo in eUnlocks)
                    {
                        if (itemInfo == null)
                        {
                            continue;
                        }
                        Dictionary <string, TagExpectedValue> tags = new Dictionary <string, TagExpectedValue> {
                            { "event", new TagExpectedValue(eventUnlocks.Event.ToString().ToLowerInvariant()) }
                        };
                        SaveItemInfo(itemInfo, basePath, heroFileName, flags, hero, eventKey, config, tags, weaponSkins);
                    }
                }

                Combo.ComboInfo guiInfo = new Combo.ComboInfo();
                Combo.Find(guiInfo, hero.ImageResource1);
                Combo.Find(guiInfo, hero.ImageResource2);
                Combo.Find(guiInfo, hero.ImageResource3);
                Combo.Find(guiInfo, hero.ImageResource4);
                guiInfo.SetTextureName(hero.ImageResource1, "Icon");
                guiInfo.SetTextureName(hero.ImageResource2, "Portrait");
                guiInfo.SetTextureName(hero.ImageResource4, "Avatar");
                guiInfo.SetTextureName(hero.SpectatorIcon, "SpectatorIcon");
                SaveLogic.Combo.SaveLooseTextures(flags, Path.Combine(basePath, RootDir, heroFileName, "GUI"), guiInfo);
            }
        }
        public async static Task <bool> Execute()
        {
            if (!ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("[SellItems] Need to be in town to sell items");
                return(false);
            }

            var sellItems = Core.Inventory.Backpack.Where(ShouldSell).ToList();

            if (!sellItems.Any())
            {
                await RepairItems.Execute();

                Core.Logger.Verbose("[SellItems] Nothing to sell");
                return(false);
            }

            Core.Logger.Verbose("[SellItems] Now to sell {0} items", sellItems.Count);
            sellItems.ForEach(i => Core.Logger.Debug($"[SellItems] Selling: {i.Name} ({i.ActorSnoId}) InternalName={i.InternalName} Ancient={i.IsAncient} Ann={i.AnnId}"));

            await Coroutine.Sleep(Randomizer.Fudge(150));

            GameUI.CloseVendorWindow();

            var merchant = TownInfo.NearestMerchant;

            if (merchant == null)
            {
                Core.Logger.Error("[SellItems] Unable to find merchant info for this area :(");
                return(false);
            }

            if (!UIElements.VendorWindow.IsVisible)
            {
                if (!await MoveToAndInteract.Execute(merchant))
                {
                    Core.Logger.Error($"[SellItems] Failed to move to merchant ({merchant.Name}) to sell items :(");
                    return(false);
                }
                await Coroutine.Sleep(Randomizer.Fudge(1000));
            }

            if (UIElements.VendorWindow.IsVisible)
            {
                await Coroutine.Sleep(Randomizer.Fudge(1500));

                var freshItems = Core.Inventory.Backpack.Where(ShouldSell);
                foreach (var item in freshItems)
                {
                    if (InventoryManager.CanSellItem(item.ToAcdItem()))
                    {
                        if (!item.IsValid || item.IsUnidentified)
                        {
                            Core.Logger.Verbose($"[SellItems] Invalid Items Detected: IsValid={item.IsValid} IsUnidentified={item.IsUnidentified}");
                            continue;
                        }

                        await Coroutine.Sleep(Randomizer.Fudge(100));

                        Core.Logger.Verbose($"[SellItems] Selling: {item.Name} ({item.ActorSnoId}) Quality={item.ItemQualityLevel} IsAncient={item.IsAncient} Name={item.InternalName}");
                        InventoryManager.SellItem(item.ToAcdItem());
                        ItemEvents.FireItemSold(item);
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                    }
                }

                await Coroutine.Sleep(Randomizer.Fudge(1000));

                await RepairItems.Execute();

                return(true);
            }

            Core.Logger.Error($"[SellItems] Failed to sell items");
            return(false);
        }
Beispiel #29
0
        public static async Task <bool> Execute()
        {
            if (!ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("[SalvageItems] Need to be in town to salvage items");
                return(false);
            }

            var salvageItems = Core.Inventory.Backpack.Where(ShouldSalvage).ToList();

            if (!salvageItems.Any())
            {
                Core.Logger.Verbose("[SalvageItems] Nothing to salvage");
                return(false);
            }

            Core.Logger.Verbose("[SalvageItems] Starting salvage for {0} items", salvageItems.Count);
            salvageItems.ForEach(i => Core.Logger.Debug($"[SalvageItems] Salvaging: {i.Name} ({i.ActorSnoId}) InternalName={i.InternalName} Ancient={i.IsAncient} Ann={i.AnnId}"));

            GameUI.CloseVendorWindow();

            var blacksmith = TownInfo.BlacksmithSalvage;

            if (blacksmith == null)
            {
                Core.Logger.Error("[SalvageItems] Unable to find a blacksmith info for this area :(");
                return(false);
            }

            if (!UIElements.SalvageWindow.IsVisible)
            {
                var blacksmithNpc = TownInfo.Blacksmith;
                if (blacksmithNpc != null)
                {
                    Core.DBGridProvider.AddCellWeightingObstacle(blacksmithNpc.ActorId, 4);
                }

                if (!await MoveTo.Execute(blacksmith.InteractPosition))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to blacksmith interact position ({blacksmith.Name}) to salvage items :(");
                    return(false);
                }
                ;

                if (!await MoveToAndInteract.Execute(blacksmith, 10f))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to blacksmith ({blacksmith.Name}) to salvage items :(");
                    return(false);
                }
                ;
                await Coroutine.Sleep(Rnd.Next(750, 1250));
            }

            if (UIElements.SalvageWindow.IsVisible)
            {
                if (ZetaDia.Me.Level >= 70 && UIElements.SalvageAllWrapper.IsVisible)
                {
                    var items = Core.Inventory.Backpack.Where(i => Combat.TrinityCombat.Loot.ShouldSalvage(i)).ToList();

                    var normals = items.Where(i => NormalQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                    if (normals.Count > 0)
                    {
                        Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {normals.Count} Normal");
                        if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Normal))
                        {
                            normals.ForEach(ItemEvents.FireItemSalvaged);
                        }
                    }

                    var magic = items.Where(i => MagicQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                    if (magic.Count > 0)
                    {
                        Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {magic.Count} Magic");
                        if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Magic))
                        {
                            magic.ForEach(ItemEvents.FireItemSalvaged);
                        }
                    }

                    var rares = items.Where(i => RareQualityLevels.Contains(i.ItemQualityLevel)).ToList();
                    if (rares.Count > 0)
                    {
                        Core.Logger.Verbose($"[SalvageItems] Bulk Salvaging {rares.Count} Rare");
                        if (InventoryManager.SalvageItemsOfRarity(SalvageRarity.Rare))
                        {
                            rares.ForEach(ItemEvents.FireItemSalvaged);
                        }
                    }
                }

                await Coroutine.Sleep(500);

                await Coroutine.Yield();

                var timeout = DateTime.UtcNow.Add(TimeSpan.FromSeconds(30));
                while (DateTime.UtcNow < timeout)
                {
                    if (!UIElements.SalvageWindow.IsVisible)
                    {
                        break;
                    }

                    await Coroutine.Sleep(Rnd.Next(200, 300));

                    Core.Actors.Update();

                    var freshItems = Core.Inventory.Backpack.Where(i => ShouldSalvage(i) && !Core.Inventory.InvalidAnnIds.Contains(i.AnnId)).ToList();
                    if (!freshItems.Any())
                    {
                        break;
                    }

                    var item = freshItems.First();

                    if (ZetaDia.Actors.GetACDByAnnId(item.AnnId) == null)
                    {
                        Core.Logger.Log("AnnId doesn't exist, skipping salvage");
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                        continue;
                    }

                    if (!Core.Actors.IsAnnIdValid(item.AnnId))
                    {
                        Core.Logger.Log("AnnId test failed, skipping salvage to prevent disconnect");
                        Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                        continue;
                    }

                    Core.Logger.Log($"Salvaging: {item.Name} ({item.ActorSnoId}) Ancient={item.IsAncient}");
                    InventoryManager.SalvageItem(item.AnnId);
                    Core.Inventory.InvalidAnnIds.Add(item.AnnId);
                    ItemEvents.FireItemSalvaged(item);
                }

                await Coroutine.Sleep(Rnd.Next(750, 1250));

                await RepairItems.Execute();

                return(true);
            }

            Core.Logger.Error($"[SalvageItems] Failed to salvage items");
            return(false);
        }
Beispiel #30
0
        public void Parse(Dictionary <ushort, List <ulong> > track, Dictionary <ulong, Record> map, CASCHandler handler, bool quiet, OverToolFlags flags)
        {
            Dictionary <string, Dictionary <string, Dictionary <string, List <JSONPkg> > > > dict = new Dictionary <string, Dictionary <string, Dictionary <string, List <JSONPkg> > > >();

            foreach (ulong key in track[0x54])
            {
                if (!map.ContainsKey(key))
                {
                    continue;
                }

                using (Stream input = Util.OpenFile(map[key], handler)) {
                    if (input == null)
                    {
                        continue;
                    }
                    STUD stud = new STUD(input);
                    if (stud.Instances == null || stud.Instances[0] == null)
                    {
                        continue;
                    }

                    GlobalInventoryMaster master = stud.Instances[0] as GlobalInventoryMaster;
                    if (master == null)
                    {
                        continue;
                    }

                    if (!dict.ContainsKey("ACHIEVEMENT"))
                    {
                        dict["ACHIEVEMENT"] = new Dictionary <string, Dictionary <string, List <JSONPkg> > >();
                    }

                    if (!dict.ContainsKey("AVAILABLE"))
                    {
                        dict["AVAILABLE"] = new Dictionary <string, Dictionary <string, List <JSONPkg> > >();
                    }

                    if (!dict.ContainsKey("LOOTBOX_EXCLUSIVE"))
                    {
                        dict["LOOTBOX_EXCLUSIVE"] = new Dictionary <string, Dictionary <string, List <JSONPkg> > >();
                    }

                    for (int i = 0; i < master.Generic.Length; ++i)
                    {
                        if (master.GenericItems[i].Length == 0)
                        {
                            continue;
                        }
                        string s = ItemEvents.GetInstance().GetEvent(master.Generic[i].@event);
                        if (!dict["ACHIEVEMENT"].ContainsKey(s))
                        {
                            dict["ACHIEVEMENT"][s] = new Dictionary <string, List <JSONPkg> >();
                        }

                        for (int j = 0; j < master.GenericItems[i].Length; ++j)
                        {
                            JSONPkg pkg = GenerateJSONPkg(master.GenericItems[i][j].key, map, handler);
                            if (pkg.Name == null)
                            {
                                continue;
                            }
                            pkg.EventId = master.Generic[i].@event;
                            pkg.Event   = s;

                            if (!dict["ACHIEVEMENT"][s].ContainsKey(pkg.Type))
                            {
                                dict["ACHIEVEMENT"][s][pkg.Type] = new List <JSONPkg>();
                            }
                            dict["ACHIEVEMENT"][s][pkg.Type].Add(pkg);
                        }
                    }

                    for (int i = 0; i < master.Categories.Length; ++i)
                    {
                        if (master.CategoryItems[i].Length == 0)
                        {
                            continue;
                        }

                        string s = ItemEvents.GetInstance().GetEvent(master.Categories[i].@event);
                        if (!dict["AVAILABLE"].ContainsKey(s))
                        {
                            dict["AVAILABLE"][s] = new Dictionary <string, List <JSONPkg> >();
                        }

                        for (int j = 0; j < master.CategoryItems[i].Length; ++j)
                        {
                            JSONPkg pkg = GenerateJSONPkg(master.CategoryItems[i][j].key, map, handler);
                            if (pkg.Name == null)
                            {
                                continue;
                            }
                            pkg.EventId = master.Categories[i].@event;
                            pkg.Event   = s;

                            if (!dict["AVAILABLE"][s].ContainsKey(pkg.Type))
                            {
                                dict["AVAILABLE"][s][pkg.Type] = new List <JSONPkg>();
                            }
                            dict["AVAILABLE"][s][pkg.Type].Add(pkg);
                        }
                    }

                    for (int i = 0; i < master.ExclusiveOffsets.Length; ++i)
                    {
                        if (master.LootboxExclusive[i].Length == 0)
                        {
                            continue;
                        }

                        string s = ItemEvents.GetInstance().GetEvent((ulong)i);
                        if (!dict["LOOTBOX_EXCLUSIVE"].ContainsKey(s))
                        {
                            dict["LOOTBOX_EXCLUSIVE"][s] = new Dictionary <string, List <JSONPkg> >();
                        }

                        for (int j = 0; j < master.LootboxExclusive[i].Length; ++j)
                        {
                            JSONPkg pkg = GenerateJSONPkg(master.LootboxExclusive[i][j].item, map, handler);
                            if (pkg.Name == null)
                            {
                                continue;
                            }
                            pkg.EventId = (ulong)i;
                            pkg.Event   = s;

                            if (!dict["LOOTBOX_EXCLUSIVE"][s].ContainsKey(pkg.Type))
                            {
                                dict["LOOTBOX_EXCLUSIVE"][s][pkg.Type] = new List <JSONPkg>();
                            }
                            dict["LOOTBOX_EXCLUSIVE"][s][pkg.Type].Add(pkg);
                        }
                    }
                }
            }

            if (Path.GetDirectoryName(flags.Positionals[2]).Trim().Length > 0 && !Directory.Exists(Path.GetDirectoryName(flags.Positionals[2])))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(flags.Positionals[2]));
            }
            using (Stream file = File.OpenWrite(flags.Positionals[2])) {
                using (TextWriter writer = new StreamWriter(file)) {
                    writer.Write(JsonConvert.SerializeObject(dict, Formatting.Indented));
                }
            }
        }