public MobSpawnItem(bool startOnly, params int[] itemNum) : this() { MapStartOnly = startOnly; for (int ii = 0; ii < itemNum.Length; ii++) { Items.Add(new InvItem(itemNum[ii]), 100); } }
public override List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems) { int itemCount = Amount.Pick(map.Rand); List <MapItem> spawners = new List <MapItem>(); SpawnList <MapItem> subList = new SpawnList <MapItem>(); if (UseSpecialItems) { for (int ii = 0; ii < specialItems.Count; ii++) { MapItem spawn = specialItems.GetSpawn(ii); if (!spawn.IsMoney) { ItemEntrySummary itemEntry = DataManager.Instance.DataIndices[DataManager.DataType.Item].Entries[spawn.Value] as ItemEntrySummary; if (itemEntry.UsageType == UseType) { subList.Add(spawn, specialItems.GetSpawnRate(ii)); } } } } if (UseMapItems) { foreach (string key in map.ItemSpawns.Spawns.GetKeys()) { SpawnList <InvItem> spawns = map.ItemSpawns.Spawns.GetSpawn(key); for (int ii = 0; ii < spawns.Count; ii++) { //TODO: spawn rate is somewhat distorted here InvItem spawn = spawns.GetSpawn(ii); ItemEntrySummary itemEntry = DataManager.Instance.DataIndices[DataManager.DataType.Item].Entries[spawn.ID] as ItemEntrySummary; if (itemEntry.UsageType == UseType) { subList.Add(new MapItem(spawn), spawns.GetSpawnRate(ii)); } } } } if (subList.Count == 0) { return(spawners); } for (int ii = 0; ii < itemCount; ii++) { spawners.Add(subList.Pick(map.Rand)); } return(spawners); }
public override List <MapItem> GenerateItems(BaseMapGenContext map, SpawnList <MapItem> specialItems) { int itemCount = Amount.Pick(map.Rand); List <MapItem> spawners = new List <MapItem>(); SpawnList <MapItem> subList = new SpawnList <MapItem>(); if (UseSpecialItems) { for (int ii = 0; ii < specialItems.Count; ii++) { MapItem spawn = specialItems.GetSpawn(ii); if (!spawn.IsMoney) { if (Range.Min <= spawn.Value && spawn.Value < Range.Max) { subList.Add(spawn, specialItems.GetSpawnRate(ii)); } } } } if (UseMapItems) { foreach (string key in map.ItemSpawns.Spawns.GetKeys()) { SpawnList <InvItem> spawns = map.ItemSpawns.Spawns.GetSpawn(key); for (int ii = 0; ii < spawns.Count; ii++) { //TODO: spawn rate is somewhat distorted here InvItem spawn = spawns.GetSpawn(ii); //ItemData data = DataManager.Instance.GetItem(spawn.ID); if (Range.Min <= spawn.ID && spawn.ID < Range.Max) { subList.Add(new MapItem(spawn), spawns.GetSpawnRate(ii)); } } } } if (subList.Count == 0) { return(spawners); } for (int ii = 0; ii < itemCount; ii++) { spawners.Add(subList.Pick(map.Rand)); } return(spawners); }
public Tweener Spawn(Type tweenType) { Tweener result; if (DeSpawnList.Count > 0) { var index = DeSpawnList.Count - 1; result = DeSpawnList[index]; DeSpawnList.RemoveAt(index); } else { result = Activator.CreateInstance(tweenType) as Tweener; } SpawnList.Add(result); if (result != null) { result.Reset(); return(result); } else { return(null); } }
protected ShopSecurityState(ShopSecurityState other) : this() { for (int ii = 0; ii < other.Security.Count; ii++) { Security.Add(other.Security.GetSpawn(ii).Copy(), other.Security.GetSpawnRate(ii)); } }
public void SpawnListAddNegative() { // add negative var spawnList = new SpawnList <string>(); Assert.Throws <ArgumentException>(() => { spawnList.Add("apple", -1); }); }
public MobSpawnStatus(MobSpawnStatus other) : this() { for (int ii = 0; ii < other.Statuses.Count; ii++) { Statuses.Add(other.Statuses.GetSpawn(ii).Clone(), other.Statuses.GetSpawnRate(ii)); } }
protected PoolTeamSpawner(PoolTeamSpawner other) { NormalSpawns = new SpawnList <MobSpawn>(); for (int ii = 0; ii < other.NormalSpawns.Count; ii++) { NormalSpawns.Add(other.NormalSpawns.GetSpawn(ii).Copy(), other.NormalSpawns.GetSpawnRate(ii)); } LeaderSpawns = new SpawnList <MobSpawn>(); for (int ii = 0; ii < other.LeaderSpawns.Count; ii++) { LonerSpawns.Add(other.LeaderSpawns.GetSpawn(ii).Copy(), other.LeaderSpawns.GetSpawnRate(ii)); } LonerSpawns = new SpawnList <MobSpawn>(); for (int ii = 0; ii < other.LonerSpawns.Count; ii++) { LonerSpawns.Add(other.LonerSpawns.GetSpawn(ii).Copy(), other.LonerSpawns.GetSpawnRate(ii)); } SupportSpawns = new SpawnList <MobSpawn>(); for (int ii = 0; ii < other.SupportSpawns.Count; ii++) { SupportSpawns.Add(other.SupportSpawns.GetSpawn(ii).Copy(), other.SupportSpawns.GetSpawnRate(ii)); } TeamSizes = new SpawnList <int>(); for (int ii = 0; ii < other.TeamSizes.Count; ii++) { TeamSizes.Add(other.TeamSizes.GetSpawn(ii), other.TeamSizes.GetSpawnRate(ii)); } }
protected RoomGenGuardedCave(RoomGenGuardedCave <T> other) { Treasures = other.Treasures.Copy(); TileTreasures = other.TileTreasures.Copy(); GuardTypes = new SpawnList <MobSpawn>(); for (int ii = 0; ii < other.GuardTypes.Count; ii++) { GuardTypes.Add(other.GuardTypes.GetSpawn(ii).Copy(), other.GuardTypes.GetSpawnRate(ii)); } }
public override SpawnList <MobSpawn> GetPossibleSpawns() { SpawnList <MobSpawn> spawnerList = new SpawnList <MobSpawn>(); for (int ii = 0; ii < Spawns.Count; ii++) { spawnerList.Add(Spawns.GetSpawn(ii).Spawn, Spawns.GetSpawnRate(ii)); } return(spawnerList); }
public override SpawnList <MobSpawn> GetPossibleSpawns() { SpawnList <MobSpawn> spawnerList = new SpawnList <MobSpawn>(); foreach (MobSpawn spawner in Spawns) { spawnerList.Add(spawner, 100); } return(spawnerList); }
protected RoomGenWaterRing(RoomGenWaterRing <T> other) { PadWidth = other.PadWidth; PadHeight = other.PadHeight; ItemAmount = other.ItemAmount; Treasures = new SpawnList <MapItem>(); for (int ii = 0; ii < other.Treasures.Count; ii++) { Treasures.Add(new MapItem(other.Treasures.GetSpawn(ii)), other.Treasures.GetSpawnRate(ii)); } WaterTerrain = other.WaterTerrain.Copy(); }
protected BulkSpawner(BulkSpawner <TGenContext, TSpawnable> other) : this() { foreach (TSpawnable specificSpawn in other.SpecificSpawns) { SpecificSpawns.Add((TSpawnable)specificSpawn.Copy()); } SpawnAmount = other.SpawnAmount; for (int ii = 0; ii < other.RandomSpawns.Count; ii++) { RandomSpawns.Add((TSpawnable)other.RandomSpawns.GetSpawn(ii).Copy(), other.RandomSpawns.GetSpawnRate(ii)); } }
protected PoolTeamSpawner(PoolTeamSpawner other) { Spawns = new SpawnList <TeamMemberSpawn>(); for (int ii = 0; ii < other.Spawns.Count; ii++) { Spawns.Add(new TeamMemberSpawn(other.Spawns.GetSpawn(ii)), other.Spawns.GetSpawnRate(ii)); } TeamSizes = new SpawnList <int>(); for (int ii = 0; ii < other.TeamSizes.Count; ii++) { TeamSizes.Add(other.TeamSizes.GetSpawn(ii), other.TeamSizes.GetSpawnRate(ii)); } }
public override List <MobSpawn> GenerateMobs(BaseMapGenContext map, SpawnList <MobSpawn> specialMobs) { int mobCount = Amount.Pick(map.Rand); List <MobSpawn> spawners = new List <MobSpawn>(); IEnumerable <int> species = GetSpecies(map, specialMobs); SpawnList <MobSpawn> subList = new SpawnList <MobSpawn>(); for (int ii = 0; ii < specialMobs.Count; ii++) { MobSpawn spawn = specialMobs.GetSpawn(ii); if (CheckIfAllowed(map, spawn, species)) { subList.Add(spawn, specialMobs.GetSpawnRate(ii)); } } for (int ii = 0; ii < map.TeamSpawns.Count; ii++) { SpawnList <MobSpawn> memberSpawns = map.TeamSpawns.GetSpawn(ii).GetPossibleSpawns(); for (int jj = 0; ii < memberSpawns.Count; jj++) { MobSpawn spawn = memberSpawns.GetSpawn(jj); if (CheckIfAllowed(map, spawn, species)) { subList.Add(spawn, memberSpawns.GetSpawnRate(jj)); } } } if (subList.Count > 0) { for (int ii = 0; ii < mobCount; ii++) { spawners.Add(subList.Pick(map.Rand)); } } return(spawners); }
public override SpawnList <MobSpawn> GetPossibleSpawns() { SpawnList <MobSpawn> spawnerList = new SpawnList <MobSpawn>(); for (int ii = 0; ii < NormalSpawns.Count; ii++) { spawnerList.Add(NormalSpawns.GetSpawn(ii), NormalSpawns.GetSpawnRate(ii)); } for (int ii = 0; ii < LeaderSpawns.Count; ii++) { spawnerList.Add(LeaderSpawns.GetSpawn(ii), LeaderSpawns.GetSpawnRate(ii)); } for (int ii = 0; ii < LonerSpawns.Count; ii++) { spawnerList.Add(LonerSpawns.GetSpawn(ii), LonerSpawns.GetSpawnRate(ii)); } for (int ii = 0; ii < SupportSpawns.Count; ii++) { spawnerList.Add(SupportSpawns.GetSpawn(ii), SupportSpawns.GetSpawnRate(ii)); } return(spawnerList); }
public static void LoadNPC() { NpcList.Clear(); using (SQLiteConnection conn = new SQLiteConnection("Data Source=npc.db")) { conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM npc"; using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { if (rdr.HasRows) { string Name = rdr[1].ToString(); Texture2D tx = NpcSpriteList[rdr[2].ToString()]; NpcList.Add(new Npc(Name, tx)); } } } cmd.CommandText = "SELECT * FROM spawn"; using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { if (rdr.HasRows) { string[] spltString = new string[] { "<>" }; List <Quest> AQuest = new List <Quest>(); if (rdr[4].ToString() != string.Empty) { string[] QuestString = rdr[4].ToString().Split(spltString, StringSplitOptions.RemoveEmptyEntries); foreach (string sb in QuestString) { AQuest.Add(QuestList.Find(x => x.QuestName == sb)); } } Npc n = NpcList.Find(x => x.NpcName == rdr[1].ToString()); Spawn s = new Spawn(n, Int32.Parse(rdr[2].ToString()), Int32.Parse(rdr[3].ToString()), AQuest); SpawnList.Add(s); } } } } }
public override void Apply(T map) { foreach (string key in Spawns.GetKeys()) { SpawnList <InvItem> itemList = Spawns.GetSpawn(key); if (itemList.CanPick) { if (!map.ItemSpawns.Spawns.ContainsKey(key)) { map.ItemSpawns.Spawns.Add(key, new SpawnList <InvItem>(), Spawns.GetSpawnRate(key)); } SpawnList <InvItem> destList = map.ItemSpawns.Spawns.GetSpawn(key); for (int ii = 0; ii < itemList.Count; ii++) { destList.Add(new InvItem(itemList.GetSpawn(ii)), itemList.GetSpawnRate(ii)); } } } }
public override void Apply(T map) { int chosenAmount = Amount.Pick(map.Rand); if (chosenAmount > 0) { SpawnList <int> spawningRooms = new SpawnList <int>(); //get all places that spawnings are eligible for (int ii = 0; ii < map.RoomPlan.RoomCount; ii++) { IRoomGen room = map.RoomPlan.GetRoom(ii); if (!BaseRoomFilter.PassesAllFilters(map.RoomPlan.GetRoomPlan(ii), this.Filters)) { continue; } spawningRooms.Add(ii, 10000); } int trials = 10 * chosenAmount; for (int ii = 0; ii < trials && chosenAmount > 0; ii++) { if (spawningRooms.SpawnTotal == 0)//check to make sure there's still spawn choices left { break; } int spawnIndex = spawningRooms.PickIndex(map.Rand); int roomNum = spawningRooms.GetSpawn(spawnIndex); Team newTeam = Spawn.GetSpawn(map); if (newTeam == null) { continue; } List <Loc> freeTiles = Grid.FindTilesInBox(map.RoomPlan.GetRoom(roomNum).Draw.Start, map.RoomPlan.GetRoom(roomNum).Draw.Size, (Loc testLoc) => { return(((IGroupPlaceableGenContext <Team>)map).CanPlaceItem(testLoc)); }); //this actually places the members of the team in random scattered locations, leaving them to group together via wandering if (freeTiles.Count >= newTeam.Players.Count) { Loc[] locs = new Loc[newTeam.Players.Count]; for (int jj = 0; jj < newTeam.Players.Count; jj++) { int randIndex = map.Rand.Next(freeTiles.Count); locs[jj] = freeTiles[randIndex]; freeTiles.RemoveAt(randIndex); } ((IGroupPlaceableGenContext <Team>)map).PlaceItems(newTeam, locs); chosenAmount--; } if (freeTiles.Count == 0)//if spawningRooms is now impossible there, remove the room entirely { spawningRooms.RemoveAt(spawnIndex); } else //otherwise decrease spawn rate for room { spawningRooms.SetSpawnRate(spawnIndex, Math.Max(spawningRooms.GetSpawnRate(spawnIndex) * ClumpFactor / 100, 1)); } } } }
void createMap() { MapGen <MapGenContext> layout = new MapGen <MapGenContext>(); //Initialize a 6x4 grid of 10x10 cells. InitGridPlanStep <MapGenContext> startGen = new InitGridPlanStep <MapGenContext>(1); startGen.CellX = 6; startGen.CellY = 4; startGen.CellWidth = 9; startGen.CellHeight = 9; layout.GenSteps.Add(-4, startGen); //Create a path that is composed of a ring around the edge GridPathBranch <MapGenContext> path = new GridPathBranch <MapGenContext>(); path.RoomRatio = new RandRange(70); path.BranchRatio = new RandRange(0, 50); SpawnList <RoomGen <MapGenContext> > genericRooms = new SpawnList <RoomGen <MapGenContext> >(); //cross genericRooms.Add(new RoomGenSquare <MapGenContext>(new RandRange(4, 8), new RandRange(4, 8))); //round genericRooms.Add(new RoomGenRound <MapGenContext>(new RandRange(5, 9), new RandRange(5, 9))); path.GenericRooms = genericRooms; SpawnList <PermissiveRoomGen <MapGenContext> > genericHalls = new SpawnList <PermissiveRoomGen <MapGenContext> >(); genericHalls.Add(new RoomGenAngledHall <MapGenContext>(50)); path.GenericHalls = genericHalls; layout.GenSteps.Add(-4, path); //Output the rooms into a FloorPlan layout.GenSteps.Add(-2, new DrawGridToFloorStep <MapGenContext>()); //Draw the rooms of the FloorPlan onto the tiled map, with 1 TILE padded on each side layout.GenSteps.Add(0, new DrawFloorToTileStep <MapGenContext>(10)); //Add the stairs up and down layout.GenSteps.Add(2, new FloorStairsStep <MapGenContext, StairsUp, StairsDown>(new StairsUp(), new StairsDown())); //Generate water (specified by user as Terrain 2) with a frequency of 35%, using Perlin Noise in an order of 3, softness 1. int terrain = 2; PerlinWaterStep <MapGenContext> waterPostProc = new PerlinWaterStep <MapGenContext>(new RandRange(35), 3, new TileTest(terrain), 1, false); layout.GenSteps.Add(3, waterPostProc); //Remove walls where diagonals of water exist and replace with water layout.GenSteps.Add(4, new DropDiagonalBlockStep <MapGenContext>(new TileTest(terrain))); //Remove water stuck in the walls layout.GenSteps.Add(4, new EraseIsolatedStep <MapGenContext>(new TileTest(terrain))); //Apply Items SpawnList <Item> itemSpawns = new SpawnList <Item>(); for (int i = 0; i < items.Count; i++) { itemSpawns.Add(new Item(i), items[i].percentage); } RandomSpawnStep <MapGenContext, Item> itemPlacement = new RandomSpawnStep <MapGenContext, Item>(new PickerSpawner <MapGenContext, Item>(new LoopedRand <Item>(itemSpawns, new RandRange(8, 17)))); layout.GenSteps.Add(6, itemPlacement); //Apply Mobs /*SpawnList<Mob> mobSpawns = new SpawnList<Mob>(); * mobSpawns.Add(new Mob((int)'r'), 20); * mobSpawns.Add(new Mob((int)'T'), 10); * mobSpawns.Add(new Mob((int)'D'), 5); * RandomSpawnStep<MapGenContext, Mob> mobPlacement = new RandomSpawnStep<MapGenContext, Mob>(new PickerSpawner<MapGenContext, Mob>(new LoopedRand<Mob>(mobSpawns, new RandRange(10, 19)))); * layout.GenSteps.Add(6, mobPlacement);*/ //Run the generator and print MapGenContext context = layout.GenMap(RogueElements.MathUtils.Rand.NextUInt64()); Print(context.Map); }
public override List <MobSpawn> ChooseSpawns(IRandom rand) { List <MobSpawn> chosenSpawns = new List <MobSpawn>(); if (!TeamSizes.CanPick) { return(chosenSpawns); } int teamSize = TeamSizes.Pick(rand); bool selectedLeader = false; bool selectedNonSupport = false; //pick first team member SpawnList <TeamMemberSpawn> eligibleSpawns = new SpawnList <TeamMemberSpawn>(); for (int ii = 0; ii < Spawns.Count; ii++) { TeamMemberSpawn spawn = Spawns.GetSpawn(ii); bool add = false; switch (spawn.Role) { case TeamMemberSpawn.MemberRole.Normal: case TeamMemberSpawn.MemberRole.Leader: add = true; break; case TeamMemberSpawn.MemberRole.Support: add = (teamSize > 1); break; case TeamMemberSpawn.MemberRole.Loner: add = (teamSize == 1); break; } if (add) { eligibleSpawns.Add(spawn, Spawns.GetSpawnRate(ii)); } } if (!eligibleSpawns.CanPick) { return(chosenSpawns); } TeamMemberSpawn chosenSpawn = eligibleSpawns.Pick(rand); if (chosenSpawn.Role == TeamMemberSpawn.MemberRole.Leader) { selectedLeader = true; } if (chosenSpawn.Role != TeamMemberSpawn.MemberRole.Support) { selectedNonSupport = true; } chosenSpawns.Add(chosenSpawn.Spawn); //pick remaining team members for (int jj = 1; jj < teamSize; jj++) { eligibleSpawns.Clear(); for (int ii = 0; ii < Spawns.Count; ii++) { TeamMemberSpawn spawn = Spawns.GetSpawn(ii); bool add = false; switch (spawn.Role) { case TeamMemberSpawn.MemberRole.Normal: add = true; break; case TeamMemberSpawn.MemberRole.Leader: add = !selectedLeader; break; case TeamMemberSpawn.MemberRole.Support: add = selectedNonSupport; break; } if (add) { eligibleSpawns.Add(spawn, Spawns.GetSpawnRate(ii)); } } if (!eligibleSpawns.CanPick) { return(chosenSpawns); } chosenSpawn = eligibleSpawns.Pick(rand); if (chosenSpawn.Role == TeamMemberSpawn.MemberRole.Leader) { selectedLeader = true; } if (chosenSpawn.Role != TeamMemberSpawn.MemberRole.Support) { selectedNonSupport = true; } chosenSpawns.Add(chosenSpawn.Spawn); } return(chosenSpawns); }