// Called from LoadLevel, patched via MonoModRules.PatchLevelLoader public static bool LoadCustomEntity(EntityData entityData, Level level) { LevelData levelData = level.Session.LevelData; Vector2 offset = new Vector2(levelData.Bounds.Left, levelData.Bounds.Top); if (Everest.Events.Level.LoadEntity(level, levelData, offset, entityData)) { return(true); } // Everest comes with a few core utility entities out of the box. if (entityData.Name == "everest/spaceController") { level.Add(new SpaceController()); return(true); } if (entityData.Name == "everest/spaceControllerBlocker") { level.Add(new SpaceControllerBlocker()); return(true); } if (entityData.Name == "everest/flagTrigger") { level.Add(new FlagTrigger(entityData, offset)); return(true); } if (entityData.Name == "everest/changeInventoryTrigger") { level.Add(new ChangeInventoryTrigger(entityData, offset)); return(true); } if (entityData.Name == "everest/coreMessage") { level.Add(new CustomCoreMessage(entityData, offset)); return(true); } if (entityData.Name == "everest/memorial") { level.Add(new CustomMemorial(entityData, offset)); return(true); } if (entityData.Name == "everest/npc") { level.Add(new CustomNPC(entityData, offset, new EntityID(levelData.Name, entityData.ID))); return(true); } if (entityData.Name == "everest/dialogTrigger" || entityData.Name == "dialog/dialogtrigger" || entityData.Name == "cavern/dialogtrigger") { level.Add(new DialogCutsceneTrigger(entityData, offset, new EntityID(levelData.Name, entityData.ID))); return(true); } if (entityData.Name == "everest/crystalShatterTrigger" || entityData.Name == "outback/destroycrystalstrigger") { level.Add(new CrystalShatterTrigger(entityData, offset)); return(true); } if (entityData.Name == "everest/completeAreaTrigger" || entityData.Name == "outback/completeareatrigger") { level.Add(new CompleteAreaTrigger(entityData, offset)); return(true); } if (entityData.Name == "everest/lavaBlockerTrigger" || entityData.Name == "cavern/lavablockertrigger") { level.Add(new LavaBlockerTrigger(entityData, offset)); return(true); } if (entityData.Name == "everest/coreModeTrigger" || entityData.Name == "cavern/coremodetrigger") { level.Add(new CoreModeTrigger(entityData, offset)); return(true); } // The following entities have hardcoded "attributes." // Everest allows custom maps to set them. if (entityData.Name == "spinner") { if (level.Session.Area.ID == 3 || (level.Session.Area.ID == 7 && level.Session.Level.StartsWith("d-")) || entityData.Bool("dust")) { level.Add(new DustStaticSpinner(entityData, offset)); return(true); } CrystalColor color = CrystalColor.Blue; if (level.Session.Area.ID == 5) { color = CrystalColor.Red; } else if (level.Session.Area.ID == 6) { color = CrystalColor.Purple; } else if ("core".Equals(entityData.Attr("color"), StringComparison.InvariantCultureIgnoreCase)) { color = (CrystalColor)(-1); } else if (!Enum.TryParse(entityData.Attr("color"), true, out color)) { color = CrystalColor.Blue; } level.Add(new CrystalStaticSpinner(entityData, offset, color)); return(true); } if (entityData.Name == "trackSpinner") { if (level.Session.Area.ID == 3 || (level.Session.Area.ID == 7 && level.Session.Level.StartsWith("d-")) || entityData.Bool("dust")) { level.Add(new DustTrackSpinner(entityData, offset)); return(true); } level.Add(new BladeTrackSpinner(entityData, offset)); return(true); } if (entityData.Name == "rotateSpinner") { if (level.Session.Area.ID == 3 || (level.Session.Area.ID == 7 && level.Session.Level.StartsWith("d-")) || entityData.Bool("dust")) { level.Add(new DustRotateSpinner(entityData, offset)); return(true); } level.Add(new BladeRotateSpinner(entityData, offset)); return(true); } if (entityData.Name == "checkpoint" && entityData.Position == Vector2.Zero && !entityData.Bool("allowOrigin")) { // Workaround for mod levels with old versions of Ahorn containing a checkpoint at (0, 0): // Create the checkpoint and avoid the start position update in orig_Load. level.Add(new Checkpoint(entityData, offset)); return(true); } if (entityData.Name == "triggerSpikesOriginalUp") { level.Add(new TriggerSpikesOriginal(entityData, offset, TriggerSpikesOriginal.Directions.Up)); return(true); } if (entityData.Name == "triggerSpikesOriginalDown") { level.Add(new TriggerSpikesOriginal(entityData, offset, TriggerSpikesOriginal.Directions.Down)); return(true); } if (entityData.Name == "triggerSpikesOriginalLeft") { level.Add(new TriggerSpikesOriginal(entityData, offset, TriggerSpikesOriginal.Directions.Left)); return(true); } if (entityData.Name == "triggerSpikesOriginalRight") { level.Add(new TriggerSpikesOriginal(entityData, offset, TriggerSpikesOriginal.Directions.Right)); return(true); } if (entityData.Name == "darkChaserEnd") { level.Add(new BadelineOldsiteEnd(entityData, offset)); return(true); } if (entityData.Name == "cloud") { patch_Cloud cloud = new Cloud(entityData, offset) as patch_Cloud; if (entityData.Has("small")) { cloud.Small = entityData.Bool("small"); } level.Add(cloud); return(true); } if (entityData.Name == "cobweb") { patch_Cobweb cobweb = new Cobweb(entityData, offset) as patch_Cobweb; if (entityData.Has("color")) { cobweb.OverrideColor = entityData.HexColor("color"); } level.Add(cobweb); return(true); } if (entityData.Name == "movingPlatform") { patch_MovingPlatform platform = new MovingPlatform(entityData, offset) as patch_MovingPlatform; if (entityData.Has("texture")) { platform.OverrideTexture = entityData.Attr("texture"); } level.Add(platform); return(true); } if (entityData.Name == "sinkingPlatform") { patch_SinkingPlatform platform = new SinkingPlatform(entityData, offset) as patch_SinkingPlatform; if (entityData.Has("texture")) { platform.OverrideTexture = entityData.Attr("texture"); } level.Add(platform); return(true); } if (entityData.Name == "crumbleBlock") { patch_CrumblePlatform platform = new CrumblePlatform(entityData, offset) as patch_CrumblePlatform; if (entityData.Has("texture")) { platform.OverrideTexture = entityData.Attr("texture"); } level.Add(platform); return(true); } if (entityData.Name == "wire") { Wire wire = new Wire(entityData, offset); if (entityData.Has("color")) { wire.Color = entityData.HexColor("color"); } level.Add(wire); return(true); } return(false); }
/// <summary> /// Search for a custom entity that matches the <see cref="EntityData.Name"/>.<br/> /// To register a custom entity, use <see cref="CustomEntityAttribute"/> or <see cref="Everest.Events.Level.OnLoadEntity"/>.<br/> /// <seealso href="https://github.com/EverestAPI/Resources/wiki/Custom-Entities-and-Triggers">Read More</seealso>. /// </summary> /// <param name="entityData"></param> /// <param name="level">The level to add the entity to.</param> /// <returns></returns> public static bool LoadCustomEntity(EntityData entityData, Level level) { LevelData levelData = level.Session.LevelData; Vector2 offset = new Vector2(levelData.Bounds.Left, levelData.Bounds.Top); if (Everest.Events.Level.LoadEntity(level, levelData, offset, entityData)) { return(true); } if (EntityLoaders.TryGetValue(entityData.Name, out EntityLoader loader)) { Entity loaded = loader(level, levelData, offset, entityData); if (loaded != null) { level.Add(loaded); return(true); } } if (entityData.Name == "everest/spaceController") { level.Add(new SpaceController()); return(true); } // The following entities have hardcoded "attributes." // Everest allows custom maps to set them. if (entityData.Name == "spinner") { if (level.Session.Area.ID == 3 || (level.Session.Area.ID == 7 && level.Session.Level.StartsWith("d-")) || entityData.Bool("dust")) { level.Add(new DustStaticSpinner(entityData, offset)); return(true); } CrystalColor color = CrystalColor.Blue; if (level.Session.Area.ID == 5) { color = CrystalColor.Red; } else if (level.Session.Area.ID == 6) { color = CrystalColor.Purple; } else if (level.Session.Area.ID == 10) { color = CrystalColor.Rainbow; } else if ("core".Equals(entityData.Attr("color"), StringComparison.InvariantCultureIgnoreCase)) { color = (CrystalColor)(-1); } else if (!Enum.TryParse(entityData.Attr("color"), true, out color)) { color = CrystalColor.Blue; } level.Add(new CrystalStaticSpinner(entityData, offset, color)); return(true); } if (entityData.Name == "trackSpinner") { if (level.Session.Area.ID == 10 || entityData.Bool("star")) { level.Add(new StarTrackSpinner(entityData, offset)); return(true); } else if (level.Session.Area.ID == 3 || (level.Session.Area.ID == 7 && level.Session.Level.StartsWith("d-")) || entityData.Bool("dust")) { level.Add(new DustTrackSpinner(entityData, offset)); return(true); } level.Add(new BladeTrackSpinner(entityData, offset)); return(true); } if (entityData.Name == "rotateSpinner") { if (level.Session.Area.ID == 10 || entityData.Bool("star")) { level.Add(new StarRotateSpinner(entityData, offset)); return(true); } else if (level.Session.Area.ID == 3 || (level.Session.Area.ID == 7 && level.Session.Level.StartsWith("d-")) || entityData.Bool("dust")) { level.Add(new DustRotateSpinner(entityData, offset)); return(true); } level.Add(new BladeRotateSpinner(entityData, offset)); return(true); } if (entityData.Name == "checkpoint" && entityData.Position == Vector2.Zero && !entityData.Bool("allowOrigin")) { // Workaround for mod levels with old versions of Ahorn containing a checkpoint at (0, 0): // Create the checkpoint and avoid the start position update in orig_Load. level.Add(new Checkpoint(entityData, offset)); return(true); } if (entityData.Name == "cloud") { patch_Cloud cloud = new Cloud(entityData, offset) as patch_Cloud; if (entityData.Has("small")) { cloud.Small = entityData.Bool("small"); } level.Add(cloud); return(true); } if (entityData.Name == "cobweb") { patch_Cobweb cobweb = new Cobweb(entityData, offset) as patch_Cobweb; if (entityData.Has("color")) { cobweb.OverrideColors = entityData.Attr("color")?.Split(',').Select(s => Calc.HexToColor(s)).ToArray(); } level.Add(cobweb); return(true); } if (entityData.Name == "movingPlatform") { patch_MovingPlatform platform = new MovingPlatform(entityData, offset) as patch_MovingPlatform; if (entityData.Has("texture")) { platform.OverrideTexture = entityData.Attr("texture"); } level.Add(platform); return(true); } if (entityData.Name == "sinkingPlatform") { patch_SinkingPlatform platform = new SinkingPlatform(entityData, offset) as patch_SinkingPlatform; if (entityData.Has("texture")) { platform.OverrideTexture = entityData.Attr("texture"); } level.Add(platform); return(true); } if (entityData.Name == "crumbleBlock") { patch_CrumblePlatform platform = new CrumblePlatform(entityData, offset) as patch_CrumblePlatform; if (entityData.Has("texture")) { platform.OverrideTexture = entityData.Attr("texture"); } level.Add(platform); return(true); } if (entityData.Name == "wire") { Wire wire = new Wire(entityData, offset); if (entityData.Has("color")) { wire.Color = entityData.HexColor("color"); } level.Add(wire); return(true); } if (!_LoadStrings.Contains(entityData.Name)) { Logger.Log(LogLevel.Warn, "LoadLevel", $"Failed loading entity {entityData.Name}"); } return(false); }
private void OverlayEntities(MapElement entities, Bitmap map, VirtualMap <char> solids, bool background) { CassetteBlock.Blocks.Clear(); using (Graphics g = Graphics.FromImage(map)) { List <Entity> ents = new List <Entity>(); for (int i = entities.Children.Count - 1; i >= 0; i--) { MapElement child = entities.Children[i]; Entity entity = null; if (child.Name.IndexOf("spikes", StringComparison.OrdinalIgnoreCase) == 0) { entity = background ? Spikes.FromElement(child) : null; } else if (child.Name.IndexOf("triggerSpikes", StringComparison.OrdinalIgnoreCase) == 0) { entity = background ? TriggerSpikes.FromElement(child) : null; } else if (child.Name.IndexOf("strawberry", StringComparison.OrdinalIgnoreCase) == 0) { entity = background ? Strawberry.FromElement(child) : null; } else if (child.Name.Equals("goldenBerry", StringComparison.OrdinalIgnoreCase)) { entity = background ? Strawberry.FromElement(child) : null; } else if (child.Name.Equals("redBlocks", StringComparison.OrdinalIgnoreCase)) { entity = background ? ClutterBlock.FromElement(child) : null; } else if (child.Name.Equals("greenBlocks", StringComparison.OrdinalIgnoreCase)) { entity = background ? ClutterBlock.FromElement(child) : null; } else if (child.Name.Equals("yellowBlocks", StringComparison.OrdinalIgnoreCase)) { entity = background ? ClutterBlock.FromElement(child) : null; } else if (child.Name.Equals("clutterCabinet", StringComparison.OrdinalIgnoreCase)) { entity = background ? ClutterCabinet.FromElement(child) : null; } else if (child.Name.Equals("introCar", StringComparison.OrdinalIgnoreCase)) { entity = background ? IntroCar.FromElement(child) : null; } else if (child.Name.Equals("clothesLine", StringComparison.OrdinalIgnoreCase)) { entity = background ? ClothesLine.FromElement(child) : null; } else if (child.Name.Equals("colorSwitch", StringComparison.OrdinalIgnoreCase)) { entity = background ? ColorSwitch.FromElement(child) : null; } else if (child.Name.Equals("memorialTextController", StringComparison.OrdinalIgnoreCase)) { entity = background ? Strawberry.FromElement(child) : null; } else if (child.Name.Equals("bonfire", StringComparison.OrdinalIgnoreCase)) { entity = background ? Bonfire.FromElement(child) : null; } else if (child.Name.Equals("trapDoor", StringComparison.OrdinalIgnoreCase)) { entity = background ? TrapDoor.FromElement(child) : null; } else if (child.Name.Equals("movingPlatform", StringComparison.OrdinalIgnoreCase)) { entity = background ? MovingPlatform.FromElement(child) : null; } else if (child.Name.Equals("sinkingPlatform", StringComparison.OrdinalIgnoreCase)) { entity = background ? SinkingPlatform.FromElement(child) : null; } else if (child.Name.Equals("clutterDoor", StringComparison.OrdinalIgnoreCase)) { entity = background ? ClutterDoor.FromElement(child) : null; } else if (child.Name.Equals("bridge", StringComparison.OrdinalIgnoreCase)) { entity = background ? Bridge.FromElement(child) : null; } else if (child.Name.Equals("bridgeFixed", StringComparison.OrdinalIgnoreCase)) { entity = background ? BridgeFixed.FromElement(child) : null; } else if (child.Name.Equals("jumpThru", StringComparison.OrdinalIgnoreCase)) { entity = background ? JumpThru.FromElement(child) : null; } else if (child.Name.Equals("door", StringComparison.OrdinalIgnoreCase)) { entity = background ? Door.FromElement(child) : null; } else if (child.Name.Equals("blockField", StringComparison.OrdinalIgnoreCase)) { entity = background ? BlockField.FromElement(child) : null; } else if (child.Name.Equals("lamp", StringComparison.OrdinalIgnoreCase)) { entity = background ? Lamp.FromElement(child) : null; } else if (child.Name.Equals("hahaha", StringComparison.OrdinalIgnoreCase)) { entity = background ? Haha.FromElement(child) : null; } else if (child.Name.Equals("waterFall", StringComparison.OrdinalIgnoreCase)) { entity = background ? WaterFall.FromElement(child) : null; } else if (child.Name.Equals("water", StringComparison.OrdinalIgnoreCase)) { entity = background ? Water.FromElement(child) : null; } else if (child.Name.Equals("key", StringComparison.OrdinalIgnoreCase)) { entity = background ? Key.FromElement(child) : null; } else if (child.Name.Equals("resortLantern", StringComparison.OrdinalIgnoreCase)) { entity = background ? ResortLantern.FromElement(child) : null; } else if (child.Name.Equals("bird", StringComparison.OrdinalIgnoreCase)) { entity = background ? Bird.FromElement(child) : null; } else if (child.Name.Equals("memorial", StringComparison.OrdinalIgnoreCase)) { entity = background ? Memorial.FromElement(child) : null; } else if (child.Name.Equals("player", StringComparison.OrdinalIgnoreCase)) { entity = background ? PlayerSpawn.FromElement(child) : null; } else if (child.Name.Equals("zipMover", StringComparison.OrdinalIgnoreCase)) { entity = background ? ZipMover.FromElement(child) : null; } else if (child.Name.Equals("wire", StringComparison.OrdinalIgnoreCase)) { entity = background ? Wire.FromElement(child) : null; } else if (child.Name.Equals("crumbleBlock", StringComparison.OrdinalIgnoreCase)) { entity = background ? CrumbleBlock.FromElement(child) : null; } else if (child.Name.Equals("refill", StringComparison.OrdinalIgnoreCase)) { entity = background ? Refill.FromElement(child) : null; } else if (child.Name.Equals("spring", StringComparison.OrdinalIgnoreCase)) { entity = background ? Spring.FromElement(child) : null; } else if (child.Name.Equals("fakeWall", StringComparison.OrdinalIgnoreCase)) { entity = background ? FakeWall.FromElement(child) : null; } else if (child.Name.Equals("exitBlock", StringComparison.OrdinalIgnoreCase)) { entity = background ? FakeWall.FromElement(child) : null; } else if (child.Name.Equals("lightBeam", StringComparison.OrdinalIgnoreCase)) { entity = background ? LightBeam.FromElement(child) : null; } else if (child.Name.Equals("cobweb", StringComparison.OrdinalIgnoreCase)) { entity = background ? Cobweb.FromElement(child) : null; } else if (child.Name.Equals("cassette", StringComparison.OrdinalIgnoreCase)) { entity = background ? Cassette.FromElement(child) : null; } else if (child.Name.Equals("flutterBird", StringComparison.OrdinalIgnoreCase)) { entity = background ? FlutterBird.FromElement(child) : null; } else if (child.Name.Equals("checkpoint", StringComparison.OrdinalIgnoreCase)) { entity = background ? Checkpoint.FromElement(child) : null; } else if (child.Name.Equals("fallingBlock", StringComparison.OrdinalIgnoreCase)) { entity = background ? FallingBlock.FromElement(child) : null; } else if (child.Name.Equals("introCrusher", StringComparison.OrdinalIgnoreCase)) { entity = background ? FallingBlock.FromElement(child) : null; } else if (child.Name.Equals("cassetteBlock", StringComparison.OrdinalIgnoreCase)) { entity = background ? CassetteBlock.FromElement(child) : null; } else if (child.Name.Equals("dashBlock", StringComparison.OrdinalIgnoreCase)) { entity = background ? DashBlock.FromElement(child) : null; } else if (child.Name.Equals("coverupWall", StringComparison.OrdinalIgnoreCase)) { entity = background ? CoverupWall.FromElement(child) : null; } else if (child.Name.Equals("npc", StringComparison.OrdinalIgnoreCase)) { entity = background ? NPC.FromElement(child) : null; } else if (child.Name.Equals("birdForsakenCityGem", StringComparison.OrdinalIgnoreCase)) { entity = background ? ForsakenCityGem.FromElement(child) : null; } else if (child.Name.Equals("soundSource", StringComparison.OrdinalIgnoreCase)) { entity = background ? SoundSource.FromElement(child) : null; } else if (child.Name.Equals("friendlyGhost", StringComparison.OrdinalIgnoreCase)) { entity = background ? FriendlyGhost.FromElement(child) : null; } else if (child.Name.Equals("floatingDebris", StringComparison.OrdinalIgnoreCase)) { entity = background ? FloatingDebris.FromElement(child) : null; } else if (child.Name.Equals("hangingLamp", StringComparison.OrdinalIgnoreCase)) { entity = background ? HangingLamp.FromElement(child) : null; } else if (child.Name.Equals("lockBlock", StringComparison.OrdinalIgnoreCase)) { entity = background ? LockBlock.FromElement(child) : null; } else if (child.Name.Equals("heartGem", StringComparison.OrdinalIgnoreCase)) { entity = background ? HeartGem.FromElement(child) : null; } else if (child.Name.Equals("blackGem", StringComparison.OrdinalIgnoreCase)) { entity = background ? HeartGem.FromElement(child) : null; } else if (child.Name.Equals("dreamMirror", StringComparison.OrdinalIgnoreCase)) { entity = background ? DreamMirror.FromElement(child) : null; } else if (child.Name.Equals("darkChaser", StringComparison.OrdinalIgnoreCase)) { entity = background ? DarkChaser.FromElement(child) : null; } else if (child.Name.Equals("dreamBlock", StringComparison.OrdinalIgnoreCase)) { entity = background ? DreamBlock.FromElement(child) : null; } else if (child.Name.Equals("touchSwitch", StringComparison.OrdinalIgnoreCase)) { entity = background ? TouchSwitch.FromElement(child) : null; } else if (child.Name.Equals("switchGate", StringComparison.OrdinalIgnoreCase)) { entity = background ? SwitchGate.FromElement(child) : null; } else if (child.Name.Equals("invisibleBarrier", StringComparison.OrdinalIgnoreCase)) { entity = background ? InvisibleBarrier.FromElement(child) : null; } else if (child.Name.Equals("payphone", StringComparison.OrdinalIgnoreCase)) { entity = background ? Payphone.FromElement(child) : null; } else if (child.Name.Equals("spinner", StringComparison.OrdinalIgnoreCase)) { entity = background ? Spinner.FromElement(child) : null; } else if (child.Name.Equals("rotateSpinner", StringComparison.OrdinalIgnoreCase)) { entity = background ? RotateSpinner.FromElement(child) : null; } else if (child.Name.Equals("trackSpinner", StringComparison.OrdinalIgnoreCase)) { entity = background ? TrackSpinner.FromElement(child) : null; } else if (child.Name.Equals("towerViewer", StringComparison.OrdinalIgnoreCase)) { entity = background ? TowerViewer.FromElement(child) : null; } else if (child.Name.Equals("foregroundDebris", StringComparison.OrdinalIgnoreCase)) { entity = !background?ForegroundDebris.FromElement(child) : null; } else if (background) { Console.WriteLine(child.Name); } if (entity != null) { ents.Add(entity); } } ents.Sort(delegate(Entity one, Entity two) { int comp = two.Depth.CompareTo(one.Depth); return(comp == 0 ? one.ID.CompareTo(two.ID) : comp); }); for (int i = 0; i < ents.Count; i++) { Entity entity = ents[i]; entity.Render(g, solids); } } }