Example #1
0
        public override void Use(Entity entity, Item item)
        {
            if (SetToMin)
            {
                entity.GetComponent <HealthComponent>().InitMaxHealth = 1;

                return;
            }

            if (SetToMax)
            {
                var h = entity.GetComponent <HealthComponent>();
                h.ModifyHealth(h.MaxHealth, item);
                return;
            }

            var a = Amount;

            if (a > 0 && Scourge.IsEnabled(Scourge.OfIllness))
            {
                if (a == 1)
                {
                    return;
                }

                a = (int)(a / 2f);
            }

            entity.GetComponent <HealthComponent>().ModifyHealth(a, entity);
        }
Example #2
0
        private void RenderConsumables(bool hasMana)
        {
            var bottomY = 8 + 9 + 8 + (hasMana ? 10 : 0) + (Player.GetComponent <HealthComponent>().MaxHealth + Player.GetComponent <HeartsComponent>().Total > HeartsComponent.PerRow ? 10 : 0) + (int)(12 * (activeSlot.ActivePosition + 1));

            if (Scourge.IsEnabled(Scourge.OfKeys))
            {
                Graphics.Render(question, new Vector2(8, bottomY + 1));
                return;
            }

            Graphics.Render(coin, new Vector2(Wrap(8 + coin.Center.X), bottomY + 1 + coin.Center.Y), 0, coin.Center, coinScale);
            PrintString($"{coins}", 18, bottomY - 1);
            bottomY += 12;

            Graphics.Render(key, new Vector2(Wrap(7 + key.Center.X), bottomY + key.Center.Y + 2), 0, key.Center, keyScale);
            PrintString($"{keys}", 18, bottomY - 1);
            bottomY += bomb.Source.Height + 2;

            Graphics.Render(bomb, new Vector2(Wrap(8 + bomb.Center.X), bottomY + bomb.Center.Y), 0,
                            bomb.Center, bombScale);
            PrintString($"{bombs}", 18, bottomY - 1);
        }
Example #3
0
        public void RenderWindow()
        {
            ImGui.Separator();

            ImGui.Text($"Time: {Math.Floor(Time / 3600f)}h {Math.Floor(Time / 60f % 60f)}m {Math.Floor(Time % 60f)}s");
            ImGui.Text($"Won: {Won}");
            ImGui.Text($"Loop: {Run.Loop}");
            ImGui.Text($"Max Depth: {MaxDepth}");
            ImGui.Text($"Game Version: {GameVersion}");
            Run.CalculateScore();
            ImGui.Text($"Score: {Run.Score}");
            ImGui.Separator();

            if (ImGui.TreeNode("Items"))
            {
                foreach (var item in Items)
                {
                    ImGui.BulletText(item);
                }

                ImGui.TreePop();
            }

            if (ImGui.TreeNode("Banned items"))
            {
                foreach (var item in Banned)
                {
                    ImGui.BulletText(item);
                }

                ImGui.TreePop();
            }

            ImGui.Separator();
            ImGui.Text($"Coins Collected: {CoinsObtained}");
            ImGui.Text($"Keys Collected: {KeysObtained}");
            ImGui.Text($"Bombs Collected: {BombsObtained}");
            ImGui.Text($"Hearts Collected: {HeartsCollected}");
            ImGui.Text($"Heart Containers Collected: {MaxHealth}");
            ImGui.Separator();


            ImGui.Text($"Damage Taken: {DamageTaken}");
            ImGui.Text($"Damage Dealt: {DamageDealt}");
            ImGui.Text($"Mobs Killed: {MobsKilled}");
            ImGui.Text($"Rooms Explored: {RoomsExplored} / {RoomsTotal}");
            ImGui.Text($"Secret Rooms Explored: {SecretRoomsFound} / {SecretRoomsTotal}");
            ImGui.Separator();

            ImGui.Text($"Date Started: {Day} {Year}");
            ImGui.Text($"Tiles Walked: {TilesWalked}");
            ImGui.Text($"Pits Fallen: {PitsFallen}");
            ImGui.Text($"Bosses Defeated: {BossesDefeated}");
            ImGui.Text($"Spikes Triggered: {SpikesTriggered}");
            ImGui.Text($"Paintings Broke: {GlobalSave.GetInt("paintings_destroyed")}");

            ImGui.Separator();
            ImGui.Text($"Luck: {Run.Luck}");
            ImGui.Text($"Scourge: {Run.Scourge}");

            if (ImGui.TreeNode("Scourges"))
            {
                foreach (var curse in Scourge.Defined)
                {
                    var v = Scourge.IsEnabled(curse);

                    if (ImGui.Checkbox(curse, ref v))
                    {
                        if (v)
                        {
                            Scourge.Enable(curse);
                        }
                        else
                        {
                            Scourge.Disable(curse);
                        }
                    }
                }

                ImGui.TreePop();
            }
        }
Example #4
0
        public override bool HandleEvent(Event e)
        {
            if (e is LostSupportEvent)
            {
                if (GetComponent <HealthComponent>().Unhittable)
                {
                    return(true);
                }

                if (!GetComponent <BuffsComponent>().PitImmunity)
                {
                    GetComponent <HealthComponent>().ModifyHealth(-1, Run.Level);
                }


                for (var i = 0; i < 4; i++)
                {
                    var part = new ParticleEntity(Particles.Dust());

                    part.Position       = Center;
                    part.Particle.Scale = Rnd.Float(0.4f, 0.8f);
                    Area.Add(part);
                }
            }
            else if (e is RoomChangedEvent c)
            {
                if (c.New == null || Run.Level == null || Camera.Instance == null)
                {
                    return(base.HandleEvent(e));
                }

                if (c.New.Tagged[Tags.MustBeKilled].Count > 0)
                {
                    Audio.PlaySfx("level_door_shut");

                    foreach (var p in Area.Tagged[Tags.Player])
                    {
                        if (p.GetComponent <RoomComponent>().Room != c.New)
                        {
                            AnimationUtil.Poof(p.Center);
                            p.Center = Center;
                            AnimationUtil.Poof(p.Center);
                        }
                    }
                }

                ((InGameState)Engine.Instance.State).ResetFollowing();

                var pr = (PixelPerfectGameRenderer)Engine.Instance.StateRenderer;

                if (c.Old != null)
                {
                    if (Scourge.IsEnabled(Scourge.OfLost))
                    {
                        c.Old.Hide();
                    }

                    if (c.Old.Type == RoomType.DarkMarket || c.Old.Type == RoomType.Hidden)
                    {
                        pr.EnableClip = false;
                        c.Old.Hide(true);
                        InBuilding = false;
                        ((InGameState)Engine.Instance.State).UpdateRainVolume();
                    }
                }

                if (c.New.Type == RoomType.DarkMarket)
                {
                    Achievements.Unlock("bk:dark_market");
                }

                if (c.New.Type == RoomType.DarkMarket || c.New.Type == RoomType.Hidden)
                {
                    pr.EnableClip   = true;
                    pr.ClipPosition = new Vector2(c.New.X + 16, c.New.Y + 16);
                    pr.ClipSize     = new Vector2(c.New.Width - 16, c.New.Height - 32);
                    InBuilding      = true;
                    ((InGameState)Engine.Instance.State).UpdateRainVolume();
                }
                else
                {
                    pr.EnableClip = false;
                }

                if (c.New.Type == RoomType.Shop)
                {
                    Audio.PlaySfx("level_door_bell");
                }

                c.New.Discover();
                var level = Run.Level;

                if (InGameState.Ready)
                {
                    switch (c.New.Type)
                    {
                    case RoomType.Secret:
                    case RoomType.Special:
                    case RoomType.Shop:
                    case RoomType.SubShop:
                    case RoomType.Treasure: {
                        foreach (var door in c.New.Doors)
                        {
                            if (door.TryGetComponent <LockComponent>(out var component) && component.Lock is GoldLock)
                            {
                                if (!(c.New.Type == RoomType.Shop && ((door.Rooms[0] != null && door.Rooms[0].Type == RoomType.SubShop) ||
                                                                      (door.Rooms[1] != null && door.Rooms[1].Type == RoomType.SubShop))))
                                {
                                    component.Lock.SetLocked(false, this);
                                }
                            }
                        }

                        break;
                    }

                    case RoomType.OldMan:
                    case RoomType.Granny: {
                        if (c.New.Type == RoomType.OldMan)
                        {
                            GetComponent <StatsComponent>().SawDeal = true;
                        }

                        c.New.OpenHiddenDoors();

                        foreach (var r in Area.Tagged[Tags.Room])
                        {
                            var room = (Room)r;

                            if (room.Type == (c.New.Type == RoomType.OldMan ? RoomType.Granny : RoomType.OldMan))
                            {
                                room.CloseHiddenDoors();
                                break;
                            }
                        }

                        break;
                    }
                    }

                    if (c.New.Type == RoomType.Secret)
                    {
                        ExplosionMaker.CheckForCracks(level, c.New, this);
                    }
                }

                if (c.Old != null)
                {
                    if (c.Old.Type == RoomType.OldMan)
                    {
                        var found = false;

                        foreach (var p in c.Old.Tagged[Tags.Player])
                        {
                            if (p != this && p is Player)
                            {
                                found = true;

                                break;
                            }
                        }

                        if (!found)
                        {
                            c.Old.CloseHiddenDoors();
                        }
                    }
                    else if (c.Old.Type == RoomType.Treasure && Run.Type != RunType.BossRush && !Rnd.Chance(5))
                    {
                        var found = false;

                        foreach (var p in c.Old.Tagged[Tags.Player])
                        {
                            if (p != this && p is Player)
                            {
                                found = true;

                                break;
                            }
                        }

                        if (!found)
                        {
                            foreach (var door in c.Old.Doors)
                            {
                                var x = (int)Math.Floor(door.CenterX / 16);
                                var y = (int)Math.Floor(door.Bottom / 16);
                                var t = level.Get(x, y);

                                if (level.Get(x, y).Matches(TileFlags.Passable))
                                {
                                    var index = level.ToIndex(x, y);

                                    level.Set(index, level.Biome is IceBiome ? Tile.WallB : Tile.WallA);
                                    level.UpdateTile(x, y);
                                    level.ReCreateBodyChunk(x, y);
                                    level.LoadPassable();

                                    Camera.Instance.Shake(10);
                                }
                            }

                            c.Old.ApplyToEachTile((x, y) => {
                                if (Run.Level.Get(x, y).IsWall())
                                {
                                    return;
                                }

                                Timer.Add(() => {
                                    var part = new TileParticle();

                                    part.Top       = Run.Level.Tileset.WallTopADecor;
                                    part.TopTarget = Run.Level.Tileset.WallTopADecor;
                                    part.Side      = Run.Level.Tileset.FloorSidesD[0];
                                    part.Sides     = Run.Level.Tileset.WallSidesA[2];
                                    part.Tile      = Tile.WallA;

                                    part.X        = x * 16;
                                    part.Y        = y * 16;
                                    part.Target.X = x * 16;
                                    part.Target.Y = y * 16;
                                    part.TargetZ  = -8f;

                                    Area.Add(part);
                                }, Rnd.Float(0.5f));
                            });

                            foreach (var d in c.Old.Doors)
                            {
                                d.Done = true;
                            }

                            c.Old.Done = true;
                        }
                    }
                }

                // Darken the lighting in evil rooms
                if (c.New.Type == RoomType.OldMan || c.New.Type == RoomType.Spiked)
                {
                    Tween.To(0.7f, Lights.RadiusMod, x => Lights.RadiusMod = x, 0.3f);
                }
                else if (c.Old != null && (c.Old.Type == RoomType.OldMan || c.Old.Type == RoomType.Spiked))
                {
                    Tween.To(1f, Lights.RadiusMod, x => Lights.RadiusMod = x, 0.3f);
                }
            }
            else if (e is HealthModifiedEvent hm)
            {
                if (hm.Amount < 0)
                {
                    if ((hm.From is Mob m && m.HasPrefix) || (hm.From is creature.bk.BurningKnight k && k.InFight) || hm.From is BkOrbital)
                    {
                        hm.Amount = Math.Min(hm.Amount, -2);
                    }
                    else if (hm.Type != DamageType.Custom && hm.Type != DamageType.Explosive)
                    {
                        hm.Amount = Math.Max(-1, hm.Amount);
                    }
                }
            }
Example #5
0
        private void RenderHealthBar(bool pad)
        {
            var red    = Player.GetComponent <HealthComponent>();
            var phases = red.Phases;

            if (Scourge.IsEnabled(Scourge.OfRisk))
            {
                Graphics.Render(question, new Vector2(8 + (int)((4 + ItemSlot.Source.Width) * (activeSlot.ActivePosition + 1)), 11));

                if (phases > 0)
                {
                    Graphics.Print($"x{phases}", Font.Small, new Vector2(8 + question.Width + 4 + (int)((4 + ItemSlot.Source.Width) * (activeSlot.ActivePosition + 1)), 12));
                }

                return;
            }

            var hearts   = Player.GetComponent <HeartsComponent>();
            var totalRed = red.Health;

            if (lastRed > totalRed)
            {
                lastRed = totalRed;
            }
            else if (lastRed < totalRed)
            {
                lastRed = Math.Min(totalRed, lastRed + Engine.Delta * 30);
            }

            var r       = (int)lastRed;
            var maxRed  = red.MaxHealth;
            var hurt    = red.InvincibilityTimer > 0;
            var shields = hearts.ShieldHalfs;
            var bombs   = (int)hearts.Bombs;
            var dbombs  = bombs * 2;
            var mbombs  = (int)hearts.BombsMax;
            var mdbombs = mbombs * 2;

            var n  = r;
            var jn = maxRed;

            if (jn % 2 == 1)
            {
                jn++;
            }

            var vegan = Settings.Vegan;

            for (var i = 0; i < maxRed; i += 2)
            {
                var region = hurt ? (vegan ? veganchangedHeartBackground : changedHeartBackground) : (vegan ? veganHeartBackground : HeartBackground);

                if (i == maxRed - 1)
                {
                    region = hurt ? (vegan ? veganchangedHalfHeartBackground : changedHalfHeartBackground) : (vegan ? veganhalfHeartBackground : halfHeartBackground);
                }

                Graphics.Render(region, GetHeartPosition(pad, i, true));
            }

            for (var i = jn; i < maxRed + mdbombs; i += 2)
            {
                var region = hurt ? ChangedBombBg : BombBg;

                Graphics.Render(region, GetHeartPosition(pad, i, true) + new Vector2(0, -1));
            }

            for (var i = jn + mdbombs; i < maxRed + shields + mdbombs; i += 2)
            {
                var region = hurt ? changedShieldBackground : ShieldBackground;

                if (i == maxRed + shields - 1)
                {
                    region = hurt ? changedHalfShieldBackground : halfShieldBackground;
                }

                Graphics.Render(region, GetHeartPosition(pad, i, true));
            }

            for (var j = 0; j < n; j++)
            {
                var h = j % 2 == 0;
                Graphics.Render(h ? (vegan ? veganHalfHeart : HalfHeart) : (vegan ? veganHeart : Heart), GetHeartPosition(pad, j) + (h ? Vector2.Zero : new Vector2(-1, 0)));
            }

            for (var j = jn; j < maxRed + dbombs; j += 2)
            {
                Graphics.Render(Bomb, GetHeartPosition(pad, j) + new Vector2(0, -1));
            }

            if (phases > 0)
            {
                Graphics.Print($"x{phases}", Font.Small, GetHeartPosition(pad, Math.Min(15, maxRed + shields + bombs)) + new Vector2(4, -2));
            }
        }