/// <summary> /// Returns position and direction for placement. /// </summary> /// <param name="placement"></param> /// <param name="border"></param> /// <returns>3 values, X, Y, and Direction (in degree).</returns> public int[] GetPosition(Placement placement, int border = -1) { if (this.PlaceIndex == -1) { throw new PuzzleException("Place hasn't been declared anything or it wasn't reserved."); } // todo: check those values var radius = 0; if (border >= 0) { radius = (_room.RoomType == RoomType.Alley ? 200 - border : 800 - border); if (radius < 0) { radius = 0; } } else { radius = (_room.RoomType == RoomType.Alley ? 200 : 800); } if (!_placementProviders.ContainsKey(placement)) { _placementProviders[placement] = new PlacementProvider(placement, radius); } var pos = _placementProviders[placement].GetPosition(); if (pos == null) { if (!_placementProviders.ContainsKey(Placement.Random)) { _placementProviders[Placement.Random] = new PlacementProvider(Placement.Random, radius); } pos = _placementProviders[Placement.Random].GetPosition(); } pos[0] += this.X; pos[1] += this.Y; return(pos); }
/// <summary> /// Creates new dungeon. /// </summary> /// <param name="instanceId"></param> /// <param name="dungeonName"></param> /// <param name="itemId"></param> /// <param name="seed"></param> /// <param name="floorPlan"></param> /// <param name="creature"></param> public Dungeon(long instanceId, string dungeonName, int itemId, int seed, int floorPlan, Creature creature) { dungeonName = dungeonName.ToLower(); Log.Debug("Dungeon: Creating '{0}', item id: {1}, seed: {2}, floorPlan: {3}", dungeonName, itemId, seed, floorPlan); // Get data this.Data = AuraData.DungeonDb.Find(dungeonName); if (this.Data == null) throw new ArgumentException("Dungeon '" + dungeonName + "' doesn't exist."); _treasureChests = new List<TreasureChest>(); _treasurePlacementProvider = new PlacementProvider(Placement.Treasure8, 750); this.Regions = new List<DungeonRegion>(); _clearedSections = new HashSet<int>(); this.InstanceId = instanceId; this.Name = dungeonName; this.ItemId = itemId; this.Seed = seed; this.FloorPlan = floorPlan; this.Options = XElement.Parse("<option />"); this.Creators = new List<long>(); this.PartyLeader = creature; // Only creatures who actually ENTER the dungeon at creation are considered "dungeon founders". this.Creators.AddRange(creature.Party.GetCreaturesOnAltar(creature.RegionId).Select(a => a.EntityId)); // Get script this.Script = ChannelServer.Instance.ScriptManager.DungeonScripts.Get(this.Name); if (this.Script == null) Log.Warning("Dungeon: No script found for '{0}'.", this.Name); // Generate floors this.Generator = new DungeonGenerator(this.Name, this.ItemId, this.Seed, this.FloorPlan, this.Options.ToString()); // Prepare puzzles for (int iFloor = 0; iFloor < this.Generator.Floors.Count; ++iFloor) this.GeneratePuzzles(iFloor); this.GenerateRegions(); }
/// <summary> /// Returns position and direction for placement. /// </summary> /// <param name="placement"></param> /// <param name="border"></param> /// <returns>3 values, X, Y, and Direction (in degree).</returns> public int[] GetPosition(Placement placement, int border = -1) { if (this.PlaceIndex == -1) throw new PuzzleException("Place hasn't been declared anything or it wasn't reserved."); // todo: check those values var radius = 0; if (border >= 0) { radius = (_room.RoomType == RoomType.Alley ? 200 - border : 800 - border); if (radius < 0) radius = 0; } else radius = (_room.RoomType == RoomType.Alley ? 200 : 800); if (!_placementProviders.ContainsKey(placement)) _placementProviders[placement] = new PlacementProvider(placement, radius); var pos = _placementProviders[placement].GetPosition(); if (pos == null) { if (!_placementProviders.ContainsKey(Placement.Random)) _placementProviders[Placement.Random] = new PlacementProvider(Placement.Random, radius); pos = _placementProviders[Placement.Random].GetPosition(); } pos[0] += this.X; pos[1] += this.Y; return pos; }
/// <summary> /// Creates new dungeon. /// </summary> /// <param name="instanceId"></param> /// <param name="dungeonName"></param> /// <param name="itemId"></param> /// <param name="seed"></param> /// <param name="floorPlan"></param> /// <param name="creature"></param> public Dungeon(long instanceId, string dungeonName, int itemId, int seed, int floorPlan, Creature creature) { dungeonName = dungeonName.ToLower(); // Get data this.Data = AuraData.DungeonDb.Find(dungeonName); if (this.Data == null) throw new ArgumentException("Dungeon '" + dungeonName + "' doesn't exist."); _treasureChests = new List<TreasureChest>(); _treasurePlacementProvider = new PlacementProvider(Placement.Treasure8, 750); this.Regions = new List<DungeonRegion>(); this.InstanceId = instanceId; this.Name = dungeonName; this.ItemId = itemId; this.Seed = seed; this.FloorPlan = floorPlan; this.Options = XElement.Parse("<option />"); this.Party = new List<Creature>(); // = creature.Party; || = party; this.Party.Add(creature); // Get script this.Script = ChannelServer.Instance.ScriptManager.DungeonScripts.Get(this.Name); if (this.Script == null) Log.Warning("Dungeon: No script found for '{0}'.", this.Name); // Generate floors this.Generator = new DungeonGenerator(this.Name, this.ItemId, this.Seed, this.FloorPlan, this.Options.ToString()); // Prepare puzzles for (int iFloor = 0; iFloor < this.Generator.Floors.Count; ++iFloor) this.GeneratePuzzles(iFloor); this.GenerateRegions(); }