Cavern Lab gen base and Onyx Seeker

This commit is contained in:
Altixal committed 2022-12-31 18:15:58 +07:00
1 parent 4f4512eaac
commit 5398f9a740
7 files changed
+200

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
using CalamityMod.Projectiles.Typeless;
using CalamityMod.Rarities;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items.LabFinders
{
public class OnyxSeekingMechanism : ModItem
{
public override void SetStaticDefaults()
{
SacrificeTotal = 1;
DisplayName.SetDefault("Onyx Seeking Mechanism");
Tooltip.SetDefault("Moves swiftly towards a lab within the caverns");
}
public override void SetDefaults()
{
Item.width = 24;
Item.height = 26;
Item.noUseGraphic = true;
Item.useStyle = ItemUseStyleID.Swing;
Item.useTime = Item.useAnimation = 36;
Item.shoot = ModContent.ProjectileType<OnyxLabSeeker>();
Item.Calamity().MaxCharge = 100;
Item.Calamity().ChargePerUse = 10;
Item.Calamity().UsesCharge = true;
Item.rare = ModContent.RarityType<DarkOrange>();
}
public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0 && CalamityWorld.CavernLabCenter != Vector2.Zero;
public override void AddRecipes()
{
//Temporary recipe probably
CreateRecipe().
AddIngredient<LabSeekingMechanism>().
AddIngredient(ItemID.Obsidian, 1000).
AddTile(TileID.Anvils).
Register();
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

+63
View File
@@ -0,0 +1,63 @@
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Typeless
{
public class OnyxLabSeeker : ModProjectile
{
public ref float Time => ref Projectile.ai[0];
public override string Texture => "CalamityMod/Items/LabFinders/OnyxSeekingMechanism";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Seeking Mechanism");
ProjectileID.Sets.TrailingMode[Projectile.type] = 1;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 24;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.tileCollide = false;
Projectile.timeLeft = 300;
}
public override void AI() => RedLabSeeker.Behavior(Projectile, CalamityWorld.CavernLabCenter, Color.Magenta, ref Time);
public override void Kill(int timeLeft)
{
for (int i = 0; i < 8; i++)
{
Dust dust = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(16f, 16f), 267);
dust.color = Color.Magenta;
dust.scale = Main.rand.NextFloat(0.95f, 1.25f);
dust.velocity = Main.rand.NextVector2Circular(2.5f, 2.5f);
dust.velocity.Y -= 1.5f;
dust.fadeIn = 1.2f;
dust.noGravity = true;
}
}
public override bool? CanCutTiles() => false;
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
if (Time > 80f && Projectile.ai[1] == 0f)
{
for (int i = 0; i < 24; i += 2)
{
Vector2 drawPosition = Projectile.Center - Projectile.velocity.SafeNormalize(Vector2.Zero) * i * Utils.GetLerpValue(80f, 125f, Time, true) * 25f - Main.screenPosition;
Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(lightColor) * (1f - i / 24f), Projectile.rotation, texture.Size() * 0.5f, Projectile.scale, SpriteEffects.None, 0);
}
}
return true;
}
}
}
+4
View File
@@ -34,6 +34,9 @@ namespace CalamityMod.Schematics
internal const string IceLabKey = "Ice Laboratory";
internal const string IceLabFilename = "Schematics/DraedonsLab_Ice.csch";
internal const string CavernLabKey = "Cavern Laboratory";
internal const string CavernLabFilename = "Schematics/DraedonsLab_CavernWorkshop.csch";
internal const string AstralBeaconKey = "Astral Beacon";
internal const string AstralBeaconFilename = "Schematics/AstralBeacon.csch";
@@ -55,6 +58,7 @@ namespace CalamityMod.Schematics
[PlagueLabKey] = CalamitySchematicIO.LoadSchematic(PlagueLabFilename),
[HellLabKey] = CalamitySchematicIO.LoadSchematic(HellLabFilename),
[IceLabKey] = CalamitySchematicIO.LoadSchematic(IceLabFilename),
[CavernLabKey] = CalamitySchematicIO.LoadSchematic(CavernLabFilename),
// Astral world gen structures
[AstralBeaconKey] = CalamitySchematicIO.LoadSchematic(AstralBeaconFilename),
+3
View File
@@ -173,6 +173,9 @@ namespace CalamityMod.Systems
DraedonStructures.PlacePlagueLab(out Point plaguePlacementPosition, workshopPositions, WorldGen.structures);
workshopPositions.Add(plaguePlacementPosition);
DraedonStructures.PlaceCavernLab(out Point cavernPlacementPosition, workshopPositions, WorldGen.structures);
workshopPositions.Add(cavernPlacementPosition);
for (int i = 0; i < workshopCount; i++)
{
DraedonStructures.PlaceWorkshop(out Point placementPosition, workshopPositions, WorldGen.structures);
+1
View File
@@ -83,6 +83,7 @@ namespace CalamityMod.World
public static Vector2 JungleLabCenter;
public static Vector2 HellLabCenter;
public static Vector2 IceLabCenter;
public static Vector2 CavernLabCenter;
#endregion
}
+83
View File
@@ -605,5 +605,88 @@ namespace CalamityMod.World
}
}
#endregion
#region Cavern Lab
public static void FillCavernLaboratoryChest(Chest chest)
{
int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion);
List<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<DubiousPlating>(), WorldGen.genRand.Next(10, 17 + 1)),
new ChestItem(ModContent.ItemType<MysteriousCircuitry>(), WorldGen.genRand.Next(10, 15 + 1)),
new ChestItem(ItemID.Torch, WorldGen.genRand.Next(20, 40 + 1)),
new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(8, 16 + 1)),
new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(7, 10 + 1)),
new ChestItem(ItemID.Dynamite, WorldGen.genRand.Next(4, 6 + 1)),
new ChestItem(potionType, WorldGen.genRand.Next(4, 7 + 1)),
new ChestItem(ModContent.ItemType<LabSeekingMechanism>(), 1),
};
//Special, non-main line lab: Adds the base Lab Seeking Mechanism
contents.Insert(0, new ChestItem(ModContent.ItemType<LabSeekingMechanism>(), 1));
for (int i = 0; i < contents.Count; i++)
{
chest.item[i].SetDefaults(contents[i].Type);
chest.item[i].stack = contents[i].Stack;
}
}
public static void PlaceCavernLab(out Point placementPoint, List<Point> workshopPoints, StructureMap structures)
{
int tries = 0;
string mapKey = CavernLabKey;
do
{
int underworldTop = Main.maxTilesY - 200;
int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.15f), (int)(Main.maxTilesX * 0.85f));
int placementPositionY = WorldGen.genRand.Next(underworldTop - 400, underworldTop - 50);
placementPoint = new Point(placementPositionX, placementPositionY);
Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1));
int activeTilesInArea = 0;
int plainTilesInArea = 0;
int xCheckArea = 30;
bool canGenerateInLocation = true;
// new Vector2 is used here since a lambda expression cannot capture a ref, out, or in parameter.
bool nearbyOtherWorkshop = workshopPoints.Any(point => Vector2.Distance(point.ToVector2(), new Vector2(placementPositionX, placementPositionY)) < 240f);
float totalTiles = (schematicSize.X + xCheckArea * 2) * schematicSize.Y;
for (int x = placementPoint.X - xCheckArea; x < placementPoint.X + schematicSize.X + xCheckArea; x++)
{
for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++)
{
Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y);
if (ShouldAvoidLocation(new Point(x, y)))
canGenerateInLocation = false;
if (tile.HasTile)
{
//Only spawn on normal cave tiles. Some special seeds are weeping rn.
if (tile.TileType == TileID.Dirt || tile.TileType == TileID.Stone || tile.TileType == TileID.Mud || TileID.Sets.Conversion.Moss[tile.TileType])
plainTilesInArea++;
//Letting it spawn in natural mud means avoiding every other mud biome at all costs
if (tile.TileType == TileID.JungleGrass || tile.TileType == TileID.MushroomGrass)
plainTilesInArea -= 1000;
activeTilesInArea++;
}
}
}
if (!canGenerateInLocation || nearbyOtherWorkshop || plainTilesInArea < totalTiles * 0.4f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y)))
tries++;
else
{
bool _ = true;
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action<Chest>(FillCavernLaboratoryChest));
structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4);
CalamityWorld.CavernLabCenter = placementPoint.ToWorldCoordinates() + new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)) * 8f;
break;
}
}
while (tries <= 50000);
}
#endregion
}
}