public override int ChoosePrefix(UnifiedRandom rand) { /* * I changed this so it would be impossible to get a non-arcane prefix */ int roll = rand.Next(37); byte pfix; if (roll <= 32) { pfix = (byte)rand.Next(26, 57); } else if (roll <= 35) { pfix = (byte)rand.Next(59, 61); } else { pfix = (byte)83; item.rare = 10; //This is to have the reforged moonstone show up bright purple if Mythical so it will contrast the other colors } return(pfix); }
public override int ChoosePrefix(UnifiedRandom rand) { /* I changed this so it would be impossible to get a non-ranged prefix */ int roll = rand.Next(37); byte pfix; if (roll <= 10) { pfix = (byte)rand.Next(16, 25); } else if (roll <= 26) { pfix = (byte)rand.Next(36, 51); } else if (roll <= 35) { pfix = (byte)rand.Next(53, 61); } else { pfix = (byte)82; item.rare = 10;//This is to have the reforged moonstone show up bright purple if Unreal so it will contrast the other colors } return pfix;//This is to have the reforged moonstone show up bright purple if Legendary so it will contrast the other colors }
public override int ChoosePrefix(Item item, UnifiedRandom rand) { int randValue = rand.Next(4); if (item.accessory && rand.Next(15) == 0) { switch (randValue) { case 0: return(mod.PrefixType("Natural")); case 1: return(mod.PrefixType("Spiritual")); case 2: return(mod.PrefixType("Brewing")); case 3: return(mod.PrefixType("Loaded")); case 4: return(mod.PrefixType("Crooked")); default: break; } } return(-1); }
private static Ambush CreateRandomWorldAmbush(int maxAttempts) { int attempts = 0; int randTileX, randTileY; UnifiedRandom rand = TmlHelpers.SafelyGetRand(); do { randTileX = rand.Next(64, Main.maxTilesX - 64); randTileY = rand.Next((int)Main.worldSurface, Main.maxTilesY - 220); if (Ambush.CheckForAmbushElegibility(randTileX, randTileY)) { break; } } while(attempts++ < maxAttempts); if (attempts >= maxAttempts) { return(null); } Ambush.AdjustAmbushTileCenter(randTileX, ref randTileY); return(Ambush.CreateRandomType(randTileX, randTileY)); }
public override int ChoosePrefix(UnifiedRandom rand) { /* * I changed this so it would be impossible to get a non-melee prefix */ int roll = rand.Next(41); byte pfix; if (roll <= 15) { pfix = (byte)rand.Next(1, 15); } else if (roll <= 31) { pfix = (byte)rand.Next(36, 51); } else if (roll <= 36) { pfix = (byte)rand.Next(53, 57); } else if (roll <= 39) { pfix = (byte)rand.Next(59, 61); } else { pfix = (byte)81; item.rare = 10; //This is to have the reforged moonstone show up bright purple if Legendary so it will contrast the other colors } return(pfix); }
public override int ChoosePrefix(UnifiedRandom rand) { int roll = rand.Next(37); byte pfix; if (roll <= 10) { pfix = (byte)rand.Next(16, 26); } else if (roll <= 26) { pfix = (byte)rand.Next(36, 52); } else if (roll <= 35) { pfix = (byte)rand.Next(53, 62); } else { pfix = (byte)82; item.rare = 10; } return(pfix); }
public override int ChoosePrefix(UnifiedRandom rand) { int roll = rand.Next(41); byte pfix; if (roll <= 15) { pfix = (byte)rand.Next(1, 16); } else if (roll <= 31) { pfix = (byte)rand.Next(36, 52); } else if (roll <= 36) { pfix = (byte)rand.Next(53, 58); } else if (roll <= 39) { pfix = (byte)rand.Next(59, 62); } else { pfix = (byte)81; item.rare = 10; } return(pfix); }
private static void PlaceAt(DesertDescription description, Point position) { ShapeData shapeData = new ShapeData(); Point origin = new Point(position.X, position.Y + 2); WorldUtils.Gen(origin, (GenShape) new Shapes.Circle(24, 12), Actions.Chain((GenAction) new Modifiers.Blotches(2, 0.3), new Actions.SetTile((ushort)53, false, true).Output(shapeData))); UnifiedRandom genRand = WorldGen.genRand; ShapeData data = new ShapeData(); int num1 = description.Hive.Top - position.Y; int direction = genRand.Next(2) == 0 ? -1 : 1; List <ChambersEntrance.PathConnection> pathConnectionList = new List <ChambersEntrance.PathConnection>() { new ChambersEntrance.PathConnection(new Point(position.X + -direction * 26, position.Y - 8), direction) }; int num2 = genRand.Next(2, 4); for (int index = 0; index < num2; ++index) { int y = (int)((double)(index + 1) / (double)num2 * (double)num1) + genRand.Next(-8, 9); int x = direction * genRand.Next(20, 41); int num3 = genRand.Next(18, 29); WorldUtils.Gen(position, (GenShape) new Shapes.Circle(num3 / 2, 3), Actions.Chain((GenAction) new Modifiers.Offset(x, y), (GenAction) new Modifiers.Blotches(2, 0.3), new Actions.Clear().Output(data), (GenAction) new Actions.PlaceWall((ushort)187, true))); pathConnectionList.Add(new ChambersEntrance.PathConnection(new Point(x + num3 / 2 * -direction + position.X, y + position.Y), -direction)); direction *= -1; } WorldUtils.Gen(position, (GenShape) new ModShapes.OuterOutline(data, true, false), Actions.Chain((GenAction) new Modifiers.Expand(1), (GenAction) new Modifiers.OnlyTiles(new ushort[1] { (ushort)53 }), (GenAction) new Actions.SetTile((ushort)397, false, true), (GenAction) new Actions.PlaceWall((ushort)187, true))); GenShapeActionPair pair = new GenShapeActionPair((GenShape) new Shapes.Rectangle(2, 4), Actions.Chain((GenAction) new Modifiers.IsSolid(), (GenAction) new Modifiers.Blotches(2, 0.3), (GenAction) new Actions.Clear(), (GenAction) new Modifiers.Expand(1), (GenAction) new Actions.PlaceWall((ushort)187, true), (GenAction) new Modifiers.OnlyTiles(new ushort[1] { (ushort)53 }), (GenAction) new Actions.SetTile((ushort)397, false, true))); for (int index = 1; index < pathConnectionList.Count; ++index) { ChambersEntrance.PathConnection pathConnection1 = pathConnectionList[index - 1]; ChambersEntrance.PathConnection pathConnection2 = pathConnectionList[index]; float num3 = Math.Abs(pathConnection2.Position.X - pathConnection1.Position.X) * 1.5f; for (float amount = 0.0f; (double)amount <= 1.0; amount += 0.02f) { Vector2 vector2_1 = new Vector2(pathConnection1.Position.X + pathConnection1.Direction * num3 * amount, pathConnection1.Position.Y); Vector2 vector2_2 = new Vector2(pathConnection2.Position.X + (float)((double)pathConnection2.Direction * (double)num3 * (1.0 - (double)amount)), pathConnection2.Position.Y); Vector2 vector2_3 = Vector2.Lerp(pathConnection1.Position, pathConnection2.Position, amount); Vector2 vector2_4 = vector2_3; double num4 = (double)amount; WorldUtils.Gen(Vector2.Lerp(Vector2.Lerp(vector2_1, vector2_4, (float)num4), Vector2.Lerp(vector2_3, vector2_2, amount), amount).ToPoint(), pair); } } WorldUtils.Gen(origin, (GenShape) new Shapes.Rectangle(new Microsoft.Xna.Framework.Rectangle(-29, -12, 58, 12)), Actions.Chain((GenAction) new Modifiers.NotInShape(shapeData), (GenAction) new Modifiers.Expand(1), (GenAction) new Actions.PlaceWall((ushort)0, true))); }
private void GenerateSlimes() { _slimes = new Slime[Main.maxTilesY / 6]; for (int i = 0; i < _slimes.Length; i++) { int num = (int)((double)Main.screenPosition.Y * 0.7 - (double)Main.screenHeight); int minValue = (int)((double)num - Main.worldSurface * 16.0); _slimes[i].Position = new Vector2(_random.Next(0, Main.maxTilesX) * 16, _random.Next(minValue, num)); _slimes[i].Speed = 5f + 3f * (float)_random.NextDouble(); _slimes[i].Depth = (float)i / (float)_slimes.Length * 1.75f + 1.6f; _slimes[i].Texture = _textures[_random.Next(2)].get_Value(); if (_random.Next(60) == 0) { _slimes[i].Texture = _textures[3].get_Value(); _slimes[i].Speed = 6f + 3f * (float)_random.NextDouble(); _slimes[i].Depth += 0.5f; } else if (_random.Next(30) == 0) { _slimes[i].Texture = _textures[2].get_Value(); _slimes[i].Speed = 6f + 2f * (float)_random.NextDouble(); } _slimes[i].Active = true; } _slimesRemaining = _slimes.Length; }
/* * Returns a random position near the position given. * * rand : a Random to use to get the position. * minDistance : the minimum amount of distance from the position. * maxDistance : the maximum amount of distance from the position. * circular : If true, gets a random point around a circle instead of a square. */ public static Vector2 GetRandomPosNear(Vector2 pos, UnifiedRandom rand, int minDistance, int maxDistance, bool circular = false) { int distance = maxDistance - minDistance; if (!circular) { float newPosX = pos.X + (Main.rand.Next(2) == 0 ? -(minDistance + rand.Next(distance)) : (minDistance + rand.Next(distance))); float newPosY = pos.Y + (Main.rand.Next(2) == 0 ? -(minDistance + rand.Next(distance)) : (minDistance + rand.Next(distance))); return(new Vector2(newPosX, newPosY)); } else { return(RotateVector(pos, pos + new Vector2(minDistance + rand.Next(distance)), MathHelper.Lerp(0, (float)(Math.PI * 2f), (float)rand.NextDouble()))); } }
private static int Main_DrawBuffIcon(On.Terraria.Main.orig_DrawBuffIcon orig, int drawBuffText, int i, int b, int x, int y) { SGAPlayer sgaply = Main.LocalPlayer.SGAPly(); if (SGAConfig.Instance.PotionFatigue || SGAmod.DRMMode) { int fatigue = sgaply.potionFatigue; if (fatigue < 1) { orig(drawBuffText, i, b, x, y); } if (SGAmod.BuffsThatHavePotions.Where(testby => testby == b).Count() > 0 && !Main.buffNoTimeDisplay[b]) { Texture2D extra = Main.extraTexture[80]; Texture2D buffTex = Main.buffTexture[b]; float alpha = MathHelper.Clamp(fatigue / 10000f, 0f, 1f); int frameHeight = extra.Height / 4; List <(Vector2, float, int)> effects = new List <(Vector2, float, int)>(); UnifiedRandom rando = new UnifiedRandom(b); for (int zz = 0; zz < 30; zz += 1) { int frame = (int)((Main.GlobalTime * 8f) + rando.Next(4) + i * 2f) % 4; float progress = (rando.NextFloat(0, 100) + Main.GlobalTime * 25) % 100; Vector2 offset = new Vector2(rando.Next(-16, 16), rando.Next(8, 16)); effects.Add((offset, progress, frame)); } effects = effects.OrderBy(testby => 10000 - testby.Item2).ToList(); foreach ((Vector2, float, int)place in effects) { float percent2 = place.Item2 / 100f; Vector2 position = new Vector2(0, MathHelper.SmoothStep(0f, -32f, percent2 * percent2)) + place.Item1 + new Vector2(x, y) + buffTex.Size() / 2f; float alpha2 = MathHelper.Clamp((float)Math.Sin((place.Item2 / 100f) * MathHelper.Pi) * 2f, 0f, 1f); Rectangle erect = new Rectangle(0, place.Item3 * frameHeight, extra.Width, frameHeight); Main.spriteBatch.Draw(extra, position, erect, Color.White * alpha * alpha2, 0, erect.Size() / 2f, alpha2, SpriteEffects.None, 0f); } } } return(orig(drawBuffText, i, b, x, y)); }
public override void Activate(Vector2 position, params object[] args) { Intensity = 0.002f; Active = true; int num = 200; int num2 = 10; _stars = new Star[num * num2]; int num3 = 0; for (int i = 0; i < num; i++) { float num4 = i / (float)num; for (int j = 0; j < num2; j++) { float num5 = j / (float)num2; _stars[num3].Position.X = num4 * Main.maxTilesX * 16f; _stars[num3].Position.Y = num5 * ((float)Main.worldSurface * 16f + 2000f) - 1000f; _stars[num3].Depth = _random.NextFloat() * 8f + 1.5f; _stars[num3].TextureIndex = _random.Next(StarTex.Length); _stars[num3].SinOffset = _random.NextFloat() * 6.28f; _stars[num3].AlphaAmplitude = _random.NextFloat() * 5f; _stars[num3].AlphaFrequency = _random.NextFloat() + 1f; num3++; } } Array.Sort(_stars, new Comparison <Star>(this.SortMethod)); }
public static void DropItemForEachInteractingPlayerOnThePlayer( NPC npc, int itemId, UnifiedRandom rng, int dropsAtXOutOfY_TheX, int dropsAtXOutOfY_TheY, int stack = 1, bool interactionRequired = true) { if (itemId <= 0 || itemId >= 5043) { return; } if (Main.netMode == 2) { for (int index = 0; index < (int)byte.MaxValue; ++index) { Player player = Main.player[index]; if (player.active && (npc.playerInteraction[index] || !interactionRequired) && rng.Next(dropsAtXOutOfY_TheY) < dropsAtXOutOfY_TheX) { int itemIndex = Item.NewItem(player.position, player.Size, itemId, stack, false, -1, false, false); CommonCode.ModifyItemDropFromNPC(npc, itemIndex); } } } else if (rng.Next(dropsAtXOutOfY_TheY) < dropsAtXOutOfY_TheX) { CommonCode.DropItemFromNPC(npc, itemId, stack, false); } npc.value = 0.0f; }
public override int ChoosePrefix(Item item, UnifiedRandom rand) { if (item.accessory && item.stack == 1 && rand.NextBool(40)) { string pref = "Yeeting"; switch (rand.Next(4)) { case 0: pref = "Swift"; break; case 1: pref = "Speedy"; break; case 2: pref = "Zippy"; break; default: pref = "Yeeting"; break; } return(mod.PrefixType(pref)); } return(-1); }
public override int ChoosePrefix(Item item, UnifiedRandom rand) { if ((item.accessory || item.damage > 0) && item.maxStack == 1 && rand.NextBool(30)) { return(mod.PrefixType(rand.Next(2) == 0 ? "Awesome" : "ReallyAwesome")); } return(-1); }
public override int ChoosePrefix(UnifiedRandom rand) { byte roll = (byte)rand.Next(1, 65); // Legendary = 81; Unreal = 82; Mythical = 83; // Therefore those are mapped to 62, 63, 64 (thus the + 19 in the following line) return(roll <= 61 ? roll : roll + 19); }
public override int ChoosePrefix(Item item, UnifiedRandom rand) { if (ClickerPrefix.DoConditionsApply(item)) { return(rand.Next(ClickerPrefix.ClickerPrefixes)); } return(base.ChoosePrefix(item, rand)); }
private static void PlaceAt(DesertDescription description, Point position) { ShapeData shapeData = new ShapeData(); Point origin = new Point(position.X, position.Y + 2); WorldUtils.Gen(origin, new Shapes.Circle(24, 12), Actions.Chain(new Modifiers.Blotches(), new Actions.SetTile(53).Output(shapeData))); UnifiedRandom genRand = WorldGen.genRand; ShapeData data = new ShapeData(); int num = description.Hive.Top - position.Y; int num2 = (genRand.Next(2) != 0) ? 1 : (-1); List <PathConnection> list = new List <PathConnection> { new PathConnection(new Point(position.X + -num2 * 26, position.Y - 8), num2) }; int num3 = genRand.Next(2, 4); for (int i = 0; i < num3; i++) { int num4 = (int)((float)(i + 1) / (float)num3 * (float)num) + genRand.Next(-8, 9); int num5 = num2 * genRand.Next(20, 41); int num6 = genRand.Next(18, 29); WorldUtils.Gen(position, new Shapes.Circle(num6 / 2, 3), Actions.Chain(new Modifiers.Offset(num5, num4), new Modifiers.Blotches(), new Actions.Clear().Output(data), new Actions.PlaceWall(187))); list.Add(new PathConnection(new Point(num5 + num6 / 2 * -num2 + position.X, num4 + position.Y), -num2)); num2 *= -1; } WorldUtils.Gen(position, new ModShapes.OuterOutline(data), Actions.Chain(new Modifiers.Expand(1), new Modifiers.OnlyTiles(53), new Actions.SetTile(397), new Actions.PlaceWall(187))); GenShapeActionPair pair = new GenShapeActionPair(new Shapes.Rectangle(2, 4), Actions.Chain(new Modifiers.IsSolid(), new Modifiers.Blotches(), new Actions.Clear(), new Modifiers.Expand(1), new Actions.PlaceWall(187), new Modifiers.OnlyTiles(53), new Actions.SetTile(397))); for (int j = 1; j < list.Count; j++) { PathConnection pathConnection = list[j - 1]; PathConnection pathConnection2 = list[j]; float num7 = Math.Abs(pathConnection2.Position.X - pathConnection.Position.X) * 1.5f; for (float num8 = 0f; num8 <= 1f; num8 += 0.02f) { Vector2 value = new Vector2(pathConnection.Position.X + pathConnection.Direction * num7 * num8, pathConnection.Position.Y); Vector2 value2 = new Vector2(pathConnection2.Position.X + pathConnection2.Direction * num7 * (1f - num8), pathConnection2.Position.Y); Vector2 vector = Vector2.Lerp(pathConnection.Position, pathConnection2.Position, num8); Vector2 value3 = Vector2.Lerp(value, vector, num8); Vector2 value4 = Vector2.Lerp(vector, value2, num8); WorldUtils.Gen(Vector2.Lerp(value3, value4, num8).ToPoint(), pair); } } WorldUtils.Gen(origin, new Shapes.Rectangle(new Rectangle(-29, -12, 58, 12)), Actions.Chain(new Modifiers.NotInShape(shapeData), new Modifiers.Expand(1), new Actions.PlaceWall(0))); }
/// <summary> Returns true 1 out of X times. </summary> public static bool NextBool(this UnifiedRandom r, int consequent) { if (consequent < 1) { throw new ArgumentOutOfRangeException(nameof(consequent), "consequent must be greater than or equal to 1."); } return(r.Next(consequent) == 0); }
/// <summary> Returns true X out of Y times. </summary> public static bool NextBool(this UnifiedRandom r, int antecedent, int consequent) { if (antecedent > consequent) { throw new ArgumentOutOfRangeException(nameof(antecedent), "antecedent must be less than or equal to consequent."); } return(r.Next(consequent) < antecedent); }
private void GenerateLanterns(bool onlyMissing) { if (!onlyMissing) { _lanterns = new Lantern[Main.maxTilesY / 4]; } for (int i = 0; i < _lanterns.Length; i++) { if (!onlyMissing || !_lanterns[i].Active) { int num = (int)((double)Main.screenPosition.Y * 0.7 - (double)Main.screenHeight); int minValue = (int)((double)num - Main.worldSurface * 16.0); _lanterns[i].Position = new Vector2(_random.Next(0, Main.maxTilesX) * 16, _random.Next(minValue, num)); ResetLantern(i); _lanterns[i].Active = true; } } _lanternsDrawing = _lanterns.Length; }
public static string GetAnimatedTitle() { var r = new UnifiedRandom(); InitializeQuoteList(); tModLoaderVersion2 = "tModLoader v" + ModLoader.version; tModLoaderVersionBak = ModLoader.version; return($"{tModLoaderVersion2} - TUA v{version} - {quote[r.Next(quote.Count)]}"); }
public override int ChoosePrefix(Item item, UnifiedRandom rand) { if (ClickerSystem.IsClickerWeapon(item)) { if (item.maxStack == 1 && item.useStyle > 0) { return(rand.Next(ClickerPrefix.ClickerPrefixes)); } } return(base.ChoosePrefix(item, rand)); }
public static string NextString(this UnifiedRandom rand, int length = 20) { string ret = ""; for (int i = 0; i < length; i++) { ret += (char)('A' + rand.Next(0, 63)); } return(ret); }
public override int ChoosePrefix(UnifiedRandom rand) { switch (rand.Next(16)) { case 1: return(PrefixID.Demonic); case 2: return(PrefixID.Frenzying); case 3: return(PrefixID.Dangerous); case 4: return(PrefixID.Savage); case 5: return(PrefixID.Furious); case 6: return(PrefixID.Terrible); case 7: return(PrefixID.Awful); case 8: return(PrefixID.Dull); case 9: return(PrefixID.Unhappy); case 10: return(PrefixID.Unreal); case 11: return(PrefixID.Shameful); case 12: return(PrefixID.Heavy); case 13: return(PrefixID.Zealous); case 14: return(mod.PrefixType("Tossable")); case 15: return(mod.PrefixType("Impacting")); default: return(mod.PrefixType("Olympian")); } }
public override int ChoosePrefix(UnifiedRandom rand) { int roll = rand.Next(37); byte pfix; if (roll <= 32) { pfix = (byte)rand.Next(26, 58); } else if (roll <= 35) { pfix = (byte)rand.Next(59, 62); } else { pfix = (byte)83; item.rare = 10; } return(pfix); }
/// <summary>Returns a random element from a list.</summary> public static T Choose <T>(this UnifiedRandom rand, IList <T> items) { if (items.Count == 0) { return(default(T)); } if (items.Count == 1) { return(items[0]); } return(items[rand.Next(items.Count)]); }
public override int ChoosePrefix(Item item, UnifiedRandom rand) { ItemEdits modItem = item.GetGlobalItem <ItemEdits>(); PrefixList prefixList = new PrefixList(); if (modItem.chemical == true) { return(0); } if (item.accessory == false && item.defense > 0 && !(item.melee && item.ranged && item.magic && item.summon && item.thrown && modItem.chemical)) { int[] result = new int[prefixList.AccessoryPrefixes.Count]; for (int i = 0; i < prefixList.AccessoryPrefixes.Count; i++) { result[i] = prefixList.AccessoryPrefixes[i]; } return(rand.Next(result)); } if (item.ranged && item.mana > 0) { int[] result = new int[prefixList.ManaGunPrefixes.Count]; for (int i = 0; i < result.Length; i++) { result[i] = prefixList.ManaGunPrefixes[i]; } return(rand.Next(result)); } if (item.magic) { int[] result = new int[prefixList.MagicPrefixes.Count]; for (int i = 0; i < result.Length; i++) { result[i] = prefixList.MagicPrefixes[i]; } return(rand.Next(result)); } return(base.ChoosePrefix(item, rand)); }
public override int ChoosePrefix(UnifiedRandom rand) { return(rand.Next(new int[] { PrefixID.Agile, PrefixID.Quick, PrefixID.Light, PrefixID.Slow, PrefixID.Sluggish, PrefixID.Lazy, PrefixID.Large, PrefixID.Broken, PrefixID.Heavy, PrefixID.Awful, PrefixID.Nimble, PrefixID.Shoddy, PrefixID.Small, PrefixID.Shoddy, PrefixID.Tiny, PrefixID.Weak, PrefixID.Unhappy, PrefixID.Hasty })); }
public void AssignNewBehavior() { switch (Random.Next(2)) { case 0: Controller = new ZipBehavior(); break; case 1: Controller = new HoverBehavior(); break; } }