Ejemplo n.º 1
0
            public void LoadEntries(TagCompound tag, out TEntry[] savedEntryLookup)
            {
                var savedEntryList = tag.GetList <TEntry>(entriesKey);
                var entries        = CreateEntries();

                // Return if there is no saved mod blocks in world.
                if (savedEntryList.Count == 0)
                {
                    savedEntryLookup = null;
                }
                else
                {
                    // Load entries from save, and pathing variables
                    savedEntryLookup = new TEntry[savedEntryList.Max(e => e.type) + 1];

                    // Check saved entries
                    foreach (var entry in savedEntryList)
                    {
                        // If the saved entry can be found among the loaded blocks, then use the entry created for the loaded block
                        if (ModContent.TryFind(entry.modName, entry.name, out TBlock block))
                        {
                            savedEntryLookup[entry.type] = entries[block.Type];
                        }
                        else                           // If it can't be found, then add entry to the end of the entries list and set the loadedType to the unloaded placeholder
                        {
                            savedEntryLookup[entry.type] = entry;
                            entry.type       = (ushort)entries.Count;
                            entry.loadedType = canPurgeOldData ? entry.vanillaReplacementType : ModContent.Find <TBlock>(string.IsNullOrEmpty(entry.unloadedType) ? entry.DefaultUnloadedType : entry.unloadedType).Type;
                            entries.Add(entry);
                        }
                    }
                }

                this.entries = entries.ToArray();
            }
Ejemplo n.º 2
0
        public override bool?UseItem(Player player)
        {
            if (FargoSoulsUtil.WorldIsExpertOrHarder())
            {
                if (!FargoSoulsUtil.AnyBossAlive())
                {
                    FargoSoulsWorld.ShouldBeEternityMode = !FargoSoulsWorld.ShouldBeEternityMode;

                    if (Main.netMode != NetmodeID.MultiplayerClient && FargoSoulsWorld.ShouldBeEternityMode && !FargoSoulsWorld.spawnedDevi &&
                        ModContent.TryFind("Fargowiltas", "Deviantt", out ModNPC deviantt) && !NPC.AnyNPCs(deviantt.Type))
                    {
                        FargoSoulsWorld.spawnedDevi = true;

                        if (ModContent.TryFind("Fargowiltas", "SpawnProj", out ModProjectile spawnProj))
                        {
                            Projectile.NewProjectile(player.GetSource_ItemUse(Item), player.Center - 1000 * Vector2.UnitY, Vector2.Zero, spawnProj.Type, 0, 0, Main.myPlayer, deviantt.Type);
                        }

                        FargoSoulsUtil.PrintLocalization($"Mods.{Mod.Name}.Message.{Name}SpawnDevi", new Color(175, 75, 255));
                    }

                    SoundEngine.PlaySound(SoundID.Roar, player.Center);

                    if (Main.netMode == NetmodeID.Server)
                    {
                        NetMessage.SendData(MessageID.WorldData); //sync world
                    }
                }
            }
            else
            {
                FargoSoulsUtil.PrintLocalization($"Mods.{Mod.Name}.Message.{Name}WrongDifficulty", new Color(175, 75, 255));
            }
            return(true);
        }
Ejemplo n.º 3
0
        public override void AddRecipes()
        {
            CreateRecipe()
            .AddIngredient(ItemID.NightsEdge, 1)
            .AddIngredient(ItemID.SoulofNight, 12)
            .AddIngredient(null, "WrathElement", 6)
            .AddIngredient(ItemID.CursedFlame, 25)
            .AddTile(134)
            .Register();

            CreateRecipe()
            .AddIngredient(ItemID.NightsEdge, 1)
            .AddIngredient(ItemID.SoulofNight, 12)
            .AddIngredient(null, "WrathElement", 6)
            .AddIngredient(ItemID.Ichor, 25)
            .AddTile(134)
            .Register();

            if (AntiarisMod.Thorium != null && ModContent.TryFind <ModItem>($"{AntiarisMod.Thorium.Name}/BloodThirster", out ModItem bloodThirster))
            {
                CreateRecipe()
                .AddIngredient(bloodThirster)
                .AddIngredient(ItemID.SoulofNight, 12)
                .AddIngredient(null, "WrathElement", 6)
                .AddIngredient(ItemID.Ichor, 25)
                .AddTile(134)
                .Register();
            }
        }
Ejemplo n.º 4
0
        internal static void LoadModData(Player player, IList <TagCompound> list)
        {
            foreach (var tag in list)
            {
                string modName       = tag.GetString("mod");
                string modPlayerName = tag.GetString("name");

                if (ModContent.TryFind <ModPlayer>(modName, modPlayerName, out var modPlayerBase))
                {
                    var modPlayer = player.GetModPlayer(modPlayerBase);

                    try {
                        modPlayer.Load(tag.GetCompound("data"));
                    }
                    catch (Exception e) {
                        var mod = modPlayer.Mod;

                        throw new CustomModDataException(mod,
                                                         "Error in reading custom player data for " + mod.Name, e);
                    }
                }
                else
                {
                    player.GetModPlayer <UnloadedPlayer>().data.Add(tag);
                }
            }
        }
Ejemplo n.º 5
0
        internal static void LoadTiles(TagCompound tag)
        {
            if (!tag.ContainsKey("data"))
            {
                return;
            }

            var tables = TileTables.Create();

            foreach (var tileTag in tag.GetList <TagCompound>("tileMap"))
            {
                ushort type    = (ushort)tileTag.GetShort("value");
                string modName = tileTag.GetString("mod");
                string name    = tileTag.GetString("name");
                tables.tiles[type] = ModContent.TryFind(modName, name, out ModTile tile) ? tile.Type : (ushort)0;
                if (tables.tiles[type] == 0)
                {
                    tables.tiles[type]        = ModContent.Find <ModTile>("ModLoader/PendingUnloadedTile").Type;
                    tables.tileModNames[type] = modName;
                    tables.tileNames[type]    = name;
                }
                tables.frameImportant[type] = tileTag.GetBool("framed");
            }
            foreach (var wallTag in tag.GetList <TagCompound>("wallMap"))
            {
                ushort type    = (ushort)wallTag.GetShort("value");
                string modName = wallTag.GetString("mod");
                string name    = wallTag.GetString("name");
                tables.walls[type] = ModContent.TryFind(modName, name, out ModWall wall) ? wall.Type : (ushort)0;
            }
            using (var memoryStream = new MemoryStream(tag.GetByteArray("data")))
                using (var reader = new BinaryReader(memoryStream))
                    ReadTileData(reader, tables);
            WorldIO.ValidateSigns();
        }
Ejemplo n.º 6
0
        public override bool?UseItem(Player player)
        {
            if (ModContent.TryFind("Fargowiltas", "Abominationn", out ModNPC modNPC))
            {
                NPC.SpawnOnPlayer(player.whoAmI, modNPC.Type);
            }

            return(true);
        }
Ejemplo n.º 7
0
        public override void OnKill()
        {
            NPC.SetEventFlagCleared(ref FargoSoulsWorld.downedBoss[(int)FargoSoulsWorld.Downed.TrojanSquirrel], -1);

            if (ModContent.TryFind("Fargowiltas", "Squirrel", out ModNPC squrrl) && !NPC.AnyNPCs(squrrl.Type))
            {
                FargoSoulsUtil.NewNPCEasy(NPC.GetSource_FromThis(), NPC.Center, squrrl.Type);
            }
        }
Ejemplo n.º 8
0
 public override void Load(TagCompound tag)
 {
     Setup(tag);
     if (ModContent.TryFind(modName, itemName, out ModItem modItem))
     {
         item.SetDefaults(modItem.Type);
         item.modItem.Load(tag.GetCompound("data"));
         ItemIO.LoadGlobals(item, tag.GetList <TagCompound>("globalData"));
     }
 }
Ejemplo n.º 9
0
 internal void TryRestore(ref ModTileEntity newEntity)
 {
     if (ModContent.TryFind(modName, tileEntityName, out ModTileEntity tileEntity))
     {
         newEntity          = ModTileEntity.ConstructFromBase(tileEntity);
         newEntity.type     = (byte)tileEntity.Type;
         newEntity.Position = Position;
         newEntity.Load(data);
     }
 }
Ejemplo n.º 10
0
        public override BaseFluid Deserialize(TagCompound tag)
        {
            if (ModContent.TryFind(tag.GetString("Mod"), tag.GetString("Name"), out BaseFluid baseFluid))
            {
                BaseFluid fluid = baseFluid.Clone();
                return(fluid);
            }

            // todo: UnloadedFluid
            throw new Exception();
        }
Ejemplo n.º 11
0
        public bool HasTile(Mod mod, string tileName)
        {
            mod ??= Mod;

            if (!ModContent.TryFind(mod.Name, tileName, out ModTile item))
            {
                throw new RecipeException($"The tile {tileName} does not exist in the mod {mod.Name}.\r\nIf you are trying to use a vanilla tile, try removing the first argument.");
            }

            return(HasTile(item.Type));
        }
Ejemplo n.º 12
0
 public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
 {
     if (ModContent.TryFind("Fargowiltas", "Deviantt", out ModNPC modNPC) && target.type == modNPC.Type)
     {
         damage *= 4;
     }
     if (target.type == ModContent.NPCType <NPCs.DeviBoss.DeviBoss>())
     {
         damage *= 12;
     }
 }
Ejemplo n.º 13
0
 public override void AddRecipes()
 {
     if (ModContent.TryFind("Fargowiltas/Mutant", out ModItem mutant))
     {
         CreateRecipe()
         .AddIngredient(ItemID.StoneBlock, 50)
         .AddIngredient(mutant)
         .AddTile(TileID.HeavyWorkBench)
         .Register();
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Adds an ingredient to this recipe with the given item name from the given mod, and with the given stack stack. If the mod parameter is null, then it will automatically use an item from the mod creating this recipe.
        /// </summary>
        /// <param name="mod">The mod.</param>
        /// <param name="itemName">Name of the item.</param>
        /// <param name="stack">The stack.</param>
        /// <exception cref="RecipeException">The item " + itemName + " does not exist in mod " + mod.Name + ". If you are trying to use a vanilla item, try removing the first argument.</exception>
        public Recipe AddIngredient(Mod mod, string itemName, int stack = 1)
        {
            mod ??= this.Mod;

            if (!ModContent.TryFind(mod.Name, itemName, out ModItem item))
            {
                throw new RecipeException($"The item {itemName} does not exist in the mod {mod.Name}.\r\nIf you are trying to use a vanilla item, try removing the first argument.");
            }

            return(AddIngredient(item, stack));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Adds a required crafting station to this recipe with the given tile name from the given mod. If the mod parameter is null, then it will automatically use a tile from the mod creating this recipe.
        /// </summary>
        /// <param name="mod">The mod.</param>
        /// <param name="tileName">Name of the tile.</param>
        /// <exception cref="RecipeException">The tile " + tileName + " does not exist in mod " + mod.Name + ". If you are trying to use a vanilla tile, try using Recipe.AddTile(tileID).</exception>
        public Recipe AddTile(Mod mod, string tileName)
        {
            mod ??= this.Mod;

            if (!ModContent.TryFind(mod.Name, tileName, out ModTile tile))
            {
                throw new RecipeException($"The tile {tileName} does not exist in the mod {mod.Name}.\r\nIf you are trying to use a vanilla tile, try using Recipe.AddTile(tileID).");
            }

            return(AddTile(tile));
        }
Ejemplo n.º 16
0
        public void ReplaceResult(Mod mod, string itemName, int stack = 1)
        {
            mod ??= Mod;

            if (!ModContent.TryFind(mod.Name, itemName, out ModItem item))
            {
                throw new RecipeException($"The item {itemName} does not exist in the mod {mod.Name}.\r\nIf you are trying to use a vanilla item, try removing the first argument.");
            }

            ReplaceResult(item.Type, stack);
        }
Ejemplo n.º 17
0
        public bool TryGetResult(Mod mod, string itemName, out Item result)
        {
            mod ??= Mod;

            if (!ModContent.TryFind(mod.Name, itemName, out ModItem item))
            {
                throw new RecipeException($"The item {itemName} does not exist in the mod {mod.Name}.\r\nIf you are trying to use a vanilla item, try removing the first argument.");
            }

            return(TryGetResult(item.Type, out result));
        }
Ejemplo n.º 18
0
 public override void AddRecipes()
 {
     if (ModContent.TryFind("Fargowiltas/Deviantt", out ModItem modItem))
     {
         CreateRecipe()
         .AddIngredient(ItemID.WizardHat)
         .AddIngredient(ItemID.GoldCoin, 15)
         .AddIngredient(modItem.Type)
         .AddTile(TileID.MythrilAnvil)
         .Register();
     }
 }
Ejemplo n.º 19
0
 public override void AddRecipes()
 {
     if (ModContent.TryFind("Fargowiltas/Deviantt", out ModItem modItem))
     {
         CreateRecipe()
         .AddIngredient(ItemID.LifeCrystal)
         .AddIngredient(ItemID.GoldCoin, 10)
         .AddIngredient(modItem.Type)
         .AddTile(TileID.CookingPots)
         .Register();
     }
 }
Ejemplo n.º 20
0
        public static void LoadHairDye(Player player, string hairDyeItemName)
        {
            if (hairDyeItemName == "")
            {
                return;
            }

            // no mystery hair dye at this stage
            if (ModContent.TryFind <ModItem>(hairDyeItemName, out var modItem))
            {
                player.hairDye = (byte)GameShaders.Hair.GetShaderIdFromItemId(modItem.Type);
            }
        }
Ejemplo n.º 21
0
        public static void DropSummon(NPC npc, string itemName, bool downed, ref bool droppedSummonFlag, bool prerequisite = true)
        {
            if (FargoSoulsWorld.EternityMode && prerequisite && !downed && Main.netMode != NetmodeID.MultiplayerClient && npc.HasPlayerTarget && !droppedSummonFlag)
            {
                Player player = Main.player[npc.target];

                if (ModContent.TryFind("Fargowiltas", itemName, out ModItem modItem))
                {
                    Item.NewItem(npc.GetSource_Loot(), player.Hitbox, modItem.Type);
                }
                droppedSummonFlag = true;
            }
        }
Ejemplo n.º 22
0
        public override void OnKill(NPC npc)
        {
            base.OnKill(npc);

            if (Main.netMode != NetmodeID.MultiplayerClient &&
                !FargoSoulsUtil.BossIsAlive(ref EModeGlobalNPC.mutantBoss, ModContent.NPCType <NPCs.MutantBoss.MutantBoss>()) &&
                ModContent.TryFind("Fargowiltas", "Mutant", out ModNPC mutant) && !NPC.AnyNPCs(mutant.Type))
            {
                int n = NPC.NewNPC(npc.GetSource_FromThis(), (int)npc.Center.X, (int)npc.Center.Y, mutant.Type);
                if (n != Main.maxNPCs && Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, n);
                }
            }
        }
Ejemplo n.º 23
0
        internal static void LoadModBuffs(Player player, IList <TagCompound> list)
        {
            //buffs list is guaranteed to be compacted
            int buffCount = Player.MaxBuffs;

            while (buffCount > 0 && player.buffType[buffCount - 1] == 0)
            {
                buffCount--;
            }

            if (buffCount == 0)
            {
                //always the case since vanilla buff saving was disabled, when extra buff slots were added
                foreach (var tag in list)
                {
                    if (buffCount == Player.MaxBuffs)
                    {
                        return;
                    }

                    var modName = tag.GetString("mod");
                    int type    = modName == "Terraria" ? tag.GetInt("id") : ModContent.TryFind(modName, tag.GetString("name"), out ModBuff buff) ? buff.Type : 0;
                    if (type > 0)
                    {
                        player.buffType[buffCount] = type;
                        player.buffTime[buffCount] = tag.GetInt("time");
                        buffCount++;
                    }
                }
                return;
            }

            //legacy code path
            //iterate the list in reverse, insert each buff at its index and push the buffs after it up a slot
            foreach (var tag in list.Reverse())
            {
                if (!ModContent.TryFind(tag.GetString("mod"), tag.GetString("name"), out ModBuff buff))
                {
                    continue;
                }

                int index = Math.Min(tag.GetByte("index"), buffCount);
                Array.Copy(player.buffType, index, player.buffType, index + 1, Player.MaxBuffs - index - 1);
                Array.Copy(player.buffTime, index, player.buffTime, index + 1, Player.MaxBuffs - index - 1);
                player.buffType[index] = buff.Type;
                player.buffTime[index] = tag.GetInt("time");
            }
        }
Ejemplo n.º 24
0
 internal static void LoadTileEntities(IList <TagCompound> list)
 {
     foreach (TagCompound tag in list)
     {
         ModTileEntity newEntity;
         if (ModContent.TryFind(tag.GetString("mod"), tag.GetString("name"), out ModTileEntity tileEntity))
         {
             newEntity          = ModTileEntity.ConstructFromBase(tileEntity);
             newEntity.type     = (byte)tileEntity.Type;
             newEntity.Position = new Point16(tag.GetShort("X"), tag.GetShort("Y"));
             if (tag.ContainsKey("data"))
             {
                 try {
                     newEntity.Load(tag.GetCompound("data"));
                     if (newEntity is UnloadedTileEntity)
                     {
                         ((UnloadedTileEntity)newEntity).TryRestore(ref newEntity);
                     }
                 }
                 catch (Exception e) {
                     throw new CustomModDataException(tileEntity.Mod,
                                                      "Error in reading " + tileEntity.Name + " tile entity data for " + tileEntity.Mod.Name, e);
                 }
             }
         }
         else
         {
             tileEntity         = ModContent.GetInstance <UnloadedTileEntity>();
             newEntity          = ModTileEntity.ConstructFromBase(tileEntity);
             newEntity.type     = (byte)tileEntity.Type;
             newEntity.Position = new Point16(tag.GetShort("X"), tag.GetShort("Y"));
             ((UnloadedTileEntity)newEntity).SetData(tag);
         }
         if (tileEntity.ValidTile(newEntity.Position.X, newEntity.Position.Y))
         {
             newEntity.ID = TileEntity.AssignNewID();
             TileEntity.ByID[newEntity.ID] = newEntity;
             if (TileEntity.ByPosition.TryGetValue(newEntity.Position, out TileEntity other))
             {
                 TileEntity.ByID.Remove(other.ID);
             }
             TileEntity.ByPosition[newEntity.Position] = newEntity;
         }
     }
 }
Ejemplo n.º 25
0
        public override void Load(TagCompound tag)
        {
            List <ushort> canRestore     = new List <ushort>();
            bool          canRestoreFlag = false;

            foreach (var infoTag in tag.GetList <TagCompound>("list"))
            {
                if (!infoTag.ContainsKey("mod"))
                {
                    infos.Add(null);
                    canRestore.Add(0);
                    continue;
                }

                string modName        = infoTag.GetString("mod");
                string name           = infoTag.GetString("name");
                bool   frameImportant = infoTag.ContainsKey("frameX");
                var    info           = frameImportant ?
                                        new UnloadedTileInfo(modName, name, infoTag.GetShort("frameX"), infoTag.GetShort("frameY")) :
                                        new UnloadedTileInfo(modName, name);
                infos.Add(info);

                int type = ModContent.TryFind(modName, name, out ModTile tile) ? tile.Type : 0;
                canRestore.Add((ushort)type);
                if (type != 0)
                {
                    canRestoreFlag = true;
                }
            }
            if (canRestoreFlag)
            {
                RestoreTiles(canRestore);
                for (int k = 0; k < canRestore.Count; k++)
                {
                    if (canRestore[k] > 0)
                    {
                        infos[k] = null;
                    }
                }
            }
            if (pendingInfos.Count > 0)
            {
                ConfirmPendingInfo();
            }
        }
Ejemplo n.º 26
0
        internal static void ReadContainers(BinaryReader reader)
        {
            byte[] flags = new byte[1];

            reader.Read(flags, 0, reader.ReadByte());

            if ((flags[0] & 1) == 1)
            {
                var tables = ContainerTables.Create();
                int count  = reader.ReadUInt16();

                for (int k = 0; k < count; k++)
                {
                    tables.headSlots[reader.ReadUInt16()] = ModContent.TryFind(reader.ReadString(), reader.ReadString(), out ModItem item) ? item.item.headSlot : 0;
                }

                count = reader.ReadUInt16();

                for (int k = 0; k < count; k++)
                {
                    tables.bodySlots[reader.ReadUInt16()] = ModContent.TryFind(reader.ReadString(), reader.ReadString(), out ModItem item) ? item.item.bodySlot : 0;
                }

                count = reader.ReadUInt16();

                for (int k = 0; k < count; k++)
                {
                    tables.legSlots[reader.ReadUInt16()] = ModContent.TryFind(reader.ReadString(), reader.ReadString(), out ModItem item) ? item.item.legSlot : 0;
                }

                ReadContainerData(reader, tables);
            }

            //legacy load //Let's not care anymore.

            /*if ((flags[0] & 2) == 2) {
             *      int count = reader.ReadInt32();
             *      for (int k = 0; k < count; k++) {
             *              int id = reader.ReadInt32();
             *              TEItemFrame itemFrame = TileEntity.ByID[id] as TEItemFrame;
             *              ItemIO.LoadLegacy(itemFrame.item, reader, true);
             *      }
             * }*/
        }