internal void DistributeGold() { Party party = LegacyLogic.Instance.WorldManager.Party; if (party != null && Random.Value < m_dropGoldChance) { Int32 num = m_dropGoldAmount.Random(); if (LegacyLogic.Instance.WorldManager.Difficulty == EDifficulty.HARD) { num = (Int32)(num * 0.75f); } if (num > 0) { NpcEffect npcEffect; if (party.HirelingHandler.HasEffect(ETargetCondition.HIRE_BONUSGF, out npcEffect) && npcEffect.TargetEffect != ETargetCondition.NONE) { num = (Int32)Math.Round(num * (1f + npcEffect.EffectValue), MidpointRounding.AwayFromZero); } party.ChangeGold(num); if (m_monster != null) { MonsterLootEntryEventArgs monsterLootEntryEventArgs = new MonsterLootEntryEventArgs(m_monster); monsterLootEntryEventArgs.Gold = num; m_monsterLootEntries.Add(monsterLootEntryEventArgs); LegacyLogic.Instance.EventManager.InvokeEvent(this, EEventType.PARTY_GET_LOOT, monsterLootEntryEventArgs); } else if (m_quest != null) { QuestLootEntryEventArgs questLootEntryEventArgs = new QuestLootEntryEventArgs(m_quest); questLootEntryEventArgs.Gold = num; LegacyLogic.Instance.EventManager.InvokeEvent(this, EEventType.PARTY_GET_LOOT, questLootEntryEventArgs); } } } }
public static void GenerateFirstRoom(Room room, IntRange widthRange, IntRange heightRange, int columns, int rows, Random rng) { room.roomWidth = widthRange.Random(rng); room.roomHeight = heightRange.Random(rng); room.xPos = Mathf.RoundToInt((columns / 2f) - (room.roomWidth / 2f)); room.yPos = Mathf.RoundToInt((rows / 2f) - (room.roomHeight / 2f)); }
public static void GenerateCorridor( Corridor corridor, Room room, IntRange length, IntRange roomWidth, IntRange roomHeight, int columns, int rows, bool firstCorridor, Random rng) { corridor.direction = (Direction)rng.Next(0, 4); var oppositeDirection = (Direction)(((int)room.enteringCorridor + 2) % 4); if (!firstCorridor && (corridor.direction == oppositeDirection)) { var directionInt = (int)corridor.direction; directionInt++; directionInt = directionInt % 4; corridor.direction = (Direction)directionInt; } corridor.corridorLength = length.Random(rng); var maxLength = length.Max; switch (corridor.direction) { case Direction.North: corridor.startXPos = rng.Next(room.xPos, (room.xPos + room.roomWidth) - 1); corridor.startYPos = room.yPos + room.roomHeight; maxLength = rows - corridor.startYPos - roomHeight.Min; break; case Direction.East: corridor.startXPos = room.xPos + room.roomWidth; corridor.startYPos = rng.Next(room.yPos, (room.yPos + room.roomHeight) - 1); maxLength = columns - corridor.startXPos - roomWidth.Min; break; case Direction.South: corridor.startXPos = rng.Next(room.xPos, room.xPos + room.roomWidth); corridor.startYPos = room.yPos; maxLength = corridor.startYPos - roomHeight.Min; break; case Direction.West: corridor.startXPos = room.xPos; corridor.startYPos = rng.Next(room.yPos, room.yPos + room.roomHeight); maxLength = corridor.startXPos - roomWidth.Min; break; } corridor.corridorLength = Mathf.Clamp(corridor.corridorLength, 1, maxLength); }
protected virtual int GetAttackDamgae(IntRange damageSource) { int damage = damageSource.Random(); if (Random.Range(1, 101) <= aggresiveCreature.critChance.GetValue()) { damage *= 2; } return(damage); }
void initializeValues() { new GameObject("Dungeon"); roomsAmount = roomsRange.Random(); rooms = new List <Room>(); corridors = new List <Corridor>(); if (!useSeed) { seed = Random.Range(-1000, 1000); } Random.seed = seed; }
private void generateBreakPoints(IntRange lengthRange, ref Directions direction) { int movesInSameDirection, rand; Directions opositeDirection = (Directions)(((int)direction + 2) % 4); Vector2Int currentPosition = breakPoints[0]; length = lengthRange.Random(); movesInSameDirection = 0; if (breakPoints.Count > 1) { breakPoints.RemoveRange(1, breakPoints.Count - 1); } for (int i = 0; i <= length; i++) { switch (direction) { case Directions.North: currentPosition.y--; break; case Directions.South: currentPosition.y++; break; case Directions.East: currentPosition.x++; break; case Directions.West: currentPosition.x--; break; } movesInSameDirection++; rand = Random.Range(0, 10); if (rand < 2 && movesInSameDirection > 1 && length - i > 1) { Directions randomDirecion; do { randomDirecion = (Directions)Random.Range(0, 4); } while (randomDirecion == direction || randomDirecion == opositeDirection); direction = randomDirecion; opositeDirection = (Directions)(((int)direction + 2) % 4); breakPoints.Add(currentPosition); movesInSameDirection = 0; } } breakPoints.Add(currentPosition); }
public Point Random(System.Random rnd, int maxWidth, int maxHeight) { var left = Mathf.Clamp(center.x - range, 0, maxWidth); var right = Mathf.Clamp(center.x + range, 0, maxWidth); var bottom = Mathf.Clamp(center.y - range, 0, maxHeight); var top = Mathf.Clamp(center.y + range, 0, maxHeight); IntRange xr = new IntRange(left, right); IntRange yr = new IntRange(bottom, top); Point pt = null; while (pt == null || !IsInRange(pt)) { pt = new Point(xr.Random(rnd), yr.Random(rnd)); } return(pt); }
public static void GenerateRoom(Room room, IntRange widthRange, IntRange heightRange, int columns, int rows, Corridor corridor, Random rng) { room.enteringCorridor = corridor.direction; room.roomWidth = widthRange.Random(rng); room.roomHeight = heightRange.Random(rng); switch (corridor.direction) { case Direction.North: room.roomHeight = Mathf.Clamp(room.roomHeight, 1, rows - corridor.EndPositionY); room.yPos = corridor.EndPositionY; room.xPos = rng.Next((corridor.EndPositionX - room.roomWidth) + 1, corridor.EndPositionX); room.xPos = Mathf.Clamp(room.xPos, 0, columns - room.roomWidth); break; case Direction.East: room.roomWidth = Mathf.Clamp(room.roomWidth, 1, columns - corridor.EndPositionX); room.xPos = corridor.EndPositionX; room.yPos = rng.Next((corridor.EndPositionY - room.roomHeight) + 1, corridor.EndPositionY); room.yPos = Mathf.Clamp(room.yPos, 0, rows - room.roomHeight); break; case Direction.South: room.roomHeight = Mathf.Clamp(room.roomHeight, 1, corridor.EndPositionY); room.yPos = (corridor.EndPositionY - room.roomHeight) + 1; room.xPos = rng.Next((corridor.EndPositionX - room.roomWidth) + 1, corridor.EndPositionX); room.xPos = Mathf.Clamp(room.xPos, 0, columns - room.roomWidth); break; case Direction.West: room.roomWidth = Mathf.Clamp(room.roomWidth, 1, corridor.EndPositionX); room.xPos = (corridor.EndPositionX - room.roomWidth) + 1; room.yPos = rng.Next((corridor.EndPositionY - room.roomHeight) + 1, corridor.EndPositionY); room.yPos = Mathf.Clamp(room.yPos, 0, rows - room.roomHeight); break; } }
/// <summary> /// Splits containers down to a range size, and returns all created containers as a list /// </summary> /// <param name="mine"></param> /// <param name="range"></param> /// <returns></returns> public static List <ContainerXXX> RecursiveDivision(this ContainerXXX mine, IntRange range) { List <ContainerXXX> to_return = new List <ContainerXXX>(); // Get random dimensions. int size = range.Random(); Point container_dimension = new Point(size, Random.Range(size - 1, size + 1)); for (int i = 0; i < range.max; i++) { if (container_dimension.x < range.min || container_dimension.y < range.min) { return(to_return); } if (container_dimension.x > mine.dimension.x || container_dimension.y > mine.dimension.y) // If these dimensions are more than the rectangle { container_dimension -= new Point(1, 1); } else { break; } } Corner corner = CornerExtension.GetRandomCorner(); ContainerSplitPacket csp = mine.QuadSplit(container_dimension, corner); to_return.Add(csp.result); foreach (ContainerXXX container in csp.container1.RecursiveDivision(range)) { to_return.Add(container); } foreach (ContainerXXX container in csp.container2.RecursiveDivision(range)) { to_return.Add(container); } return(to_return); }
protected void BuyStockAtPowerLevel(EnumValue powerLevel, IntRange stockRange, FloatRange itemBudgetRange) { int desiredCount = stockRange.Random(); int currentCount = GetTotalCount(powerLevel); float currentBudget = GetTotalCost(powerLevel); int requiredStockCount = desiredCount - currentCount; float desiredTotalBudget = itemBudgetRange.Mean * requiredStockCount; if (requiredStockCount > 0) { float requiredStockBudget = desiredTotalBudget - currentBudget; if (requiredStockBudget > 0) { for (int i = 0; i < requiredStockCount; i++) { EnumValue itemPowerLevel = EnumValue.Create(powerLevelEnum, powerLevelEnum[powerLevel]); TSpecificItem randomSpecificItem = CreateRandomSpecificItem(itemPowerLevel, itemBudgetRange); Add(randomSpecificItem); } } } }
public Room(IntRange widthRange, IntRange heightRange, bool canBeDeadEnd) { width = widthRange.Random(); height = heightRange.Random(); getExitsAmount(canBeDeadEnd); }
void InitData() { numberOfZombies = numberOfZombiesRange.Random(rnd); currentDungeon.zombieSpawns = new List <Point>(); }