void DoPatrolling() { //close door if neccessary if (World.TryCloseDoor(CoordX - lookX, CoordY - lookY)) { return; } //let's SUDDENLY turn to the random direction, maybe? :D if (MyRandom.getRandomInt(suddenTurningFrequency) == 0) { turnToRandomPassableDirection(); return; } //Move forward if there is nothing to do... if (TryMoveForward()) { return; } else //or open door if there is. Otherwise turn to random direction { if (!World.TryOpenDoor(CoordX + lookX, CoordY + lookY)) { turnToRandomPassableDirection(); } } }
static void addColumns() { for (int i = 0; i < maxColumns; i++) { for (int j = 0; j < maxTries; j++) { bool wrongCoords = false; int x = MyRandom.getRandomInt(1, mapWidth - 1); int y = MyRandom.getRandomInt(1, mapHeight - 1); for (int xx = -1; xx < 2; xx++) { for (int yy = -1; yy < 2; yy++) { if (map[x + xx, y + yy] != piece.floor) { wrongCoords = true; } } } if (wrongCoords == true) { continue; } map[x, y] = piece.wall; break; } } }
static bool digRoom(int x, int y) // HERE BE DRAGONS { int roomWidth = MyRandom.getRandomInt(minRoomSize, maxRoomSize); int roomHeight = MyRandom.getRandomInt(minRoomSize, maxRoomSize); int dir = corrDirection(x, y); ////DEBUG //if (dir != 1) return false; ////DEBUG ENDED //directions: // 0 //3#1 // 2 if (dir == 0) //dig up { int intersect = MyRandom.getRandomInt(roomWidth); if (isEmpty(x - intersect - 2, y - roomHeight - 1, roomWidth + 2, roomHeight + 2)) { dig(x - intersect, y - roomHeight, roomWidth /* + 1*/, roomHeight); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } if (dir == 1) //dig right { int intersect = MyRandom.getRandomInt(roomHeight); if (isEmpty(x, y - intersect - 2, roomWidth + 2, roomHeight + 2)) { dig(x + 1, y - intersect, roomWidth, roomHeight); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } if (dir == 2) //dig down { int intersect = MyRandom.getRandomInt(roomWidth); if (isEmpty(x - intersect - 2, y, roomWidth + 2, roomHeight + 2)) { dig(x - intersect, y + 1, roomWidth, roomHeight); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } if (dir == 3) //dig left { int intersect = MyRandom.getRandomInt(roomHeight); if (isEmpty(x - roomWidth - 1, y - intersect - 2, roomWidth + 2, roomHeight + 2)) { dig(x - roomWidth, y - intersect, roomWidth, roomHeight); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } return(false); }
static void randomtest() { const int testmax = 6; const long picks = 1000000; MyRandom.setSeed(); var pick = new long[testmax]; long picksum = 0; for (long i = 0; i < testmax; i++) { pick[i] = 0; } for (long i = 0; i < picks; i++) { long j = MyRandom.getRandomInt(testmax); picksum += j; pick[j]++; } for (int i = 0; i < testmax; i++) { Console.Write(i.ToString() + ":x" + pick[i].ToString() + "; "); if (i % 9 == 0 && i > 0) { Console.WriteLine(); } } Console.Write("Pick medium: " + (picksum / picks).ToString()); }
static void placeActors() { int plx, ply; plx = player.CoordX; ply = player.CoordY; int x, y; for (int i = 0; i < 7; i++) { do { x = MyRandom.getRandomInt(mapWidth); y = MyRandom.getRandomInt(mapHeight); if (map[x, y].IsPassable && !WorldLOS.VisibleLineExist(x, y, plx, ply)) { AllActors.Add(UnitCreator.createActor("Guard", x, y)); } } while (!map[x, y].IsPassable); } for (int i = 0; i < 3; i++) { do { x = MyRandom.getRandomInt(mapWidth); y = MyRandom.getRandomInt(mapHeight); if (map[x, y].IsPassable && !WorldLOS.VisibleLineExist(x, y, plx, ply)) { AllActors.Add(UnitCreator.createActor("Officer", x, y)); } } while (!map[x, y].IsPassable); } }
public static void ShowSplashScreen() { int WhatToDraw = MyRandom.getRandomInt(0, 5); if (WhatToDraw == 0) { DrawImage1StartupScreen(); } if (WhatToDraw == 1) { DrawImage2StartupScreen(); } if (WhatToDraw == 2) { DrawImage3StartupScreen(); } if (WhatToDraw == 3) { DrawImage3aStartupScreen(); } if (WhatToDraw == 4) { DrawImage4StartupScreen(); } //DrawImage4StartupScreen(); Console.ForegroundColor = ConsoleColor.Gray; string anykey = "Press any key"; int cursorXstart = Program.consoleWidth / 2 - anykey.Length / 2; Console.SetCursorPosition(cursorXstart, Program.consoleHeight - 1); Console.Write(anykey); Console.ReadKey(true); }
//stats are from 1 to 20 (inclusive). //20 is superhuman stat, maybe public SneakRoleplayStats() //"base human" stats { Level = 1; Strength = MyRandom.getRandomInt(8, 13); Nerve = MyRandom.getRandomInt(8, 13); Endurance = MyRandom.getRandomInt(8, 13); Agility = MyRandom.getRandomInt(8, 10); Knowledge = MyRandom.getRandomInt(8, 13); }
static int CalculateRangedDamage(Unit attacker, Unit victim) { int MinDamage = attacker.Inv.Wielded.MinMeleeDamage; int MaxDamage = attacker.Inv.Wielded.MaxMeleeDamage; int baseDamage = MyRandom.getRandomInt(MinDamage, MaxDamage + 1); int finalDamage = baseDamage; if (finalDamage < 0) { finalDamage = 0; } return(finalDamage); }
static int CalculateMeleeDamage(Unit attacker, Unit victim) { int MinMeleeDamage = attacker.Inv.Wielded.MinMeleeDamage; int MaxMeleeDamage = attacker.Inv.Wielded.MaxMeleeDamage; int baseDamage = MyRandom.getRandomInt(MinMeleeDamage, MaxMeleeDamage + 1); int finalDamage = (int)(baseDamage + baseDamage * (attacker.Stats.Strength - 10) / 10 * attacker.Inv.Wielded.StrengthFactor); if (finalDamage < 0) { finalDamage = 0; } return(finalDamage); }
static bool digCorridor(int x, int y) // HERE BE DRAGONS { int corrLength = MyRandom.getRandomInt(minCorridorLength, maxCorridorLength); int dir = corrDirection(x, y); //directions: // 0 //3#1 // 2 if (dir == 0) //dig up { if (isEmpty(x - 1, y - corrLength, 3, corrLength + 1)) { dig(x, y - corrLength, 1, corrLength); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } if (dir == 1) //dig right { if (isEmpty(x, y - 1, corrLength + 1, 3)) { dig(x, y, corrLength, 1); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } if (dir == 2) //dig down { if (isEmpty(x - 1, y, 3, corrLength + 1)) { dig(x, y, 1, corrLength); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } if (dir == 3) //dig left { if (isEmpty(x - corrLength, y - 1, corrLength + 1, 3)) { dig(x - corrLength, y, corrLength, 1); map[x, y] = piece.door; lockMap[x, y] = currentLockLevel; return(true); } } return(false); }
void peepDialogue() { Log.AddLine("Peep in which direction?"); ConsoleKeyInfo keyPressed = Console.ReadKey(true); KeyToVector.ProcessInput(keyPressed); int peepX = CoordX + KeyToVector.x, peepY = CoordY + KeyToVector.y; if (peepX == CoordX && peepY == CoordY) { int randomMessageNumber = MyRandom.getRandomInt(3); switch (randomMessageNumber) { case 0: Log.AddLine("You feel SO introversive for a moment"); break; case 1: Log.AddLine("You peep yourself. So interesting"); break; case 2: Log.AddLine("If you wanna, hm, look at yourself, get a room, please."); break; } return; } //don't peep through walls anymore! :D if (World.IsPassable(peepX, peepY) || World.IsDoorPresent(peepX, peepY)) { isPeeping = true; lastPeepX = peepX; lastPeepY = peepY; WorldRendering.drawInCircleFOV(peepX, peepY, visibilityRadius); WorldRendering.drawUnitsInCircle(peepX, peepY, visibilityRadius); this.Draw(); Console.ForegroundColor = ConsoleColor.Gray; Timing.AddActionTime(TimeCost.CloseDoorCost(this)); Log.ReplaceLastLine("You carefully peep in that direction... Press space or esc to stop"); keyPressed = Console.ReadKey(true); if (keyPressed.Key == ConsoleKey.Spacebar || keyPressed.Key == ConsoleKey.Escape) { isPeeping = false; Log.ReplaceLastLine("You carefully peep in that direction..."); } } else { Log.ReplaceLastLine("You try to peep through this, but in vain."); } }
public static void Strangle(Unit attacker, Unit victim) { if (victim.IsUnaware()) { int KOtime = MyRandom.getRandomInt(50, 150); victim.KnockedOutTime += KOtime; if (attacker is Player) { Log.AddLine("You strangle " + victim.Name + "!"); } } else { Log.AddLine(attacker.Name + " tried to grab and strangle " + victim.Name + ", but the victim was aware of it!"); } }
static void tryAddKeyplace() //this tries to add a tile where the key should be placed. { int x = MyRandom.getRandomInt(1, mapWidth - 1); int y = MyRandom.getRandomInt(1, mapHeight - 1); //for (int i = 0; i < maxTries; i++) //{ while (map[x, y] != piece.floor || lockMap[x, y] != currentLockLevel) { x = MyRandom.getRandomInt(1, mapWidth - 1); y = MyRandom.getRandomInt(1, mapHeight - 1); } map[x, y] = piece.keyplace; lockMap[x, y] = currentLockLevel + 1; // break; //} }
void turnToRandomPassableDirection() //turn to random direction which is passable { int newLookX, newLookY; int tries = 0; do { newLookX = MyRandom.getRandomInt(-1, 2); newLookY = MyRandom.getRandomInt(-1, 2); if (tries > 50) { break; //this is } tries++; //a quite dirty workaround } while ((newLookX == 0 && newLookY == 0) || !World.IsPassable(CoordX + newLookX, CoordY + newLookY)); turnToDirection(newLookX, newLookY); Timing.AddActionTime(TimeCost.GuardWait(this)); }
static void tryAddRoom() //this tries to build a random room { int x, y; bool done = false; for (int i = 0; i < maxTries; i++) { x = 0; y = 0; while (!isWall(x, y)) { x = MyRandom.getRandomInt(1, mapWidth - 1); y = MyRandom.getRandomInt(1, mapHeight - 1); } done = digRoom(x, y); if (done) { break; } } }
static void tryAddCorridor() //this tries to build a random corridor { //in the dungeon int x, y; bool done = false; for (int i = 0; i < maxTries; i++) { x = 0; y = 0; while (!isWall(x, y)) { x = MyRandom.getRandomInt(1, mapWidth - 1); y = MyRandom.getRandomInt(1, mapHeight - 1); } done = digCorridor(x, y); if (done) { break; } } }
public void PickupDialogue() //NEED TO WORK WITH LISTS. !!! { List <Item> picked = World.getItemListAt(owner.CoordX, owner.CoordY); if (picked.Count > 0) { picked = MultipleItemSelectionMenu("pick up", picked); if (picked == null) { return; } foreach (Item i in picked) { if (TryPickUpItem(i)) { World.AllItemsOnFloor.Remove(i); Log.AddLine("You picked up the " + i.DisplayName + "."); } } } else { int randomMessageNumber = MyRandom.getRandomInt(3); switch (randomMessageNumber) { case 0: Log.AddLine("There's nothing here to pick up."); break; case 1: Log.AddLine("All that lying here is the dust."); break; case 2: Log.AddLine("Of course you can pick up the air."); break; } return; } }
void closeDoorDialogue() { Log.AddLine("Close door in which direction?"); ConsoleKeyInfo keyPressed = Console.ReadKey(true); KeyToVector.ProcessInput(keyPressed); int doorX = CoordX + KeyToVector.x, doorY = CoordY + KeyToVector.y; if (doorX == CoordX && doorY == CoordY) { int randomMessageNumber = MyRandom.getRandomInt(3); switch (randomMessageNumber) { case 0: Log.AddLine("Wow. You costumed like a door this Halloween?"); break; case 1: Log.AddLine("You have almost closed yourself, but suddenly remembered that you're not a door."); break; case 2: Log.AddLine("Okay... Try another time"); break; } return; } if (World.TryCloseDoor(doorX, doorY)) { Timing.AddActionTime(TimeCost.PeepCost(this)); Log.ReplaceLastLine("You carefully closed the door."); } else { Log.ReplaceLastLine("You tried to close this, but something went wrong..."); } }
void strangleDialogue() { Log.AddLine("Grab in which direction?"); ConsoleKeyInfo keyPressed = Console.ReadKey(true); KeyToVector.ProcessInput(keyPressed); int strangleX = CoordX + KeyToVector.x, strangleY = CoordY + KeyToVector.y; if (strangleX == CoordX && strangleY == CoordY) { int randomMessageNumber = MyRandom.getRandomInt(3); switch (randomMessageNumber) { case 0: Log.AddLine("Wanna strangle yourself huh?"); break; case 1: Log.AddLine("Suicide will not help with your mission."); break; case 2: Log.AddLine("If you wanna touch yourself, get a room, please."); break; } return; } if (World.isActorPresent(strangleX, strangleY)) { Attack.Strangle(this, World.getActorAt(strangleX, strangleY)); Timing.AddActionTime(TimeCost.StrangleCost(this)); } else { Log.AddLine("There's nobody here!"); } }
public static void AddOneFromList(List <string> values) { int r = MyRandom.getRandomInt(values.Count); AddLine(values[r]); }
public static int StrangleCost(Unit acting) { return(MyRandom.getRandomInt(15, 25)); }
public static int[,] generateDungeon() { int roomwidth, roomheight, roomx, roomy; //fill everything with "earth" //set everything with zero lock level as well for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { map[i, j] = piece.wall; lockMap[i, j] = currentLockLevel; } } //place a room in the center of a dungeon roomwidth = MyRandom.getRandomInt(minRoomSize + 1, maxRoomSize); roomheight = MyRandom.getRandomInt(minRoomSize + 1, maxRoomSize); roomx = mapWidth / 2 - roomwidth / 2; roomy = mapHeight / 2 - roomheight / 2; if (isEmpty(roomx, roomy, roomwidth, roomheight)) { dig(roomx, roomy, roomwidth, roomheight); } //total rooms and corridors int rooms = 1; int corridors = 0; //now let's start a generation loop int iteration = 0; while (corridors < maxCorridors || rooms < maxRooms) { //do we need to increase the current lock level? //TEMPORARY SOLUTION!!111 //Hehehe... Temporary... for (int i = 0; i <= maxKeys; i++) { if (rooms > i * maxRooms / (maxKeys + 1) && i > currentLockLevel) { tryAddKeyplace(); currentLockLevel = i; } } //firstly, pick a random wall adjacent to room //or corridor or something ///!!MOVED TO ANOTHER METHOD!! //okay, it's picked. Now let's decide //will we build whether a corridor or a room if (true) { if (corridors < maxCorridors) { tryAddCorridor(); corridors++; } } if (true /*iteration % 2 == 0*/) { if (rooms < maxRooms) { tryAddRoom(); rooms++; } } //repeat... iteration++; } //now let's make walls on perimeter for (int i = 0; i < mapWidth; i++) { map[i, 0] = piece.wall; map[i, mapHeight - 1] = piece.wall; } for (int j = 0; j < mapHeight; j++) { map[0, j] = piece.wall; map[mapWidth - 1, j] = piece.wall; } //let's place an entrance stair int sx = 0, sy = 0; while (map[sx, sy] != piece.floor || lockMap[sx, sy] != 0) { sx = MyRandom.getRandomInt(mapWidth); sy = MyRandom.getRandomInt(mapHeight); } map[sx, sy] = piece.upstair; //let's add some columns addColumns(); //transform "pieces" into ints int[,] finalMap = new int[mapWidth, mapHeight]; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { finalMap[i, j] = (int)map[i, j]; } } return(finalMap); }