public override bool HandleEvent(Event e) { if ((e is ItemUsedEvent ite && ite.Who == payer && ite.Item == takenItem) || (e is ItemAddedEvent iae && iae.Who == payer && iae.Item == takenItem)) { var component = payer.GetComponent <HealthComponent>(); var hearts = payer.GetComponent <HeartsComponent>(); var a = Math.Min(component.MaxHealth, lastPrice); if (a > 0) { component.ModifyHealth(-a, this, DamageType.Custom); if (!component.LastModifiedHearts) { component.MaxHealth -= a; } } var d = lastPrice - a; if (d > 0) { hearts.Hurt(-d, this, DamageType.Custom); } TextParticle.Add(payer, Locale.Get("max_hp"), lastPrice, true, true); payer = null; takenItem = null; } return(base.HandleEvent(e)); }
protected override bool Interact(Entity e) { TimesUsed++; var keys = Effects.Keys; var key = keys.ElementAt(Rnd.Int(keys.Count)); var bad = false; TextParticle.Add(this, Locale.Get(key)); Timer.Add(() => { bad = Effects[key](this, e); if (!Broken) { GetComponent <AudioEmitterComponent>().Emit(bad ? "item_dice_good" : "item_dice_bad"); } }, 1f); if (TimesUsed >= 3) { GetComponent <AudioEmitterComponent>().Emit("item_dice_break"); Timer.Add(() => { GetComponent <AudioEmitterComponent>().Emit(bad ? "item_dice_good" : "item_dice_bad"); }, 0.6f); Break(); } return(true); }
protected override bool Interact(Entity e) { var c = e.GetComponent <ConsumablesComponent>(); if (c.Coins < 1) { AnimationUtil.ActionFailed(); TextParticle.Add(e, Locale.Get("no_coins")); return(true); } GetComponent <AudioEmitterComponent>().Emit("level_well_coin"); c.Coins--; var keys = DiceStatue.Effects.Keys; var key = keys.ElementAt(Rnd.Int(keys.Count)); TextParticle.Add(this, Locale.Get(key)); Timer.Add(() => { DiceStatue.Effects[key](this, e); }, 1f); return(true); }
private bool Interact(Entity e) { var c = e.GetComponent <HealthComponent>(); var d = GetComponent <DialogComponent>(); if (c.IsFull()) { // Ya look pretty good d.StartAndClose("nurse_0", 3); return(false); } var price = (int)(c.MaxHealth - c.Health) * 4; var consumables = e.GetComponent <ConsumablesComponent>(); if (consumables.Coins < price) { d.Dialog.Str.SetVariable("price", price); d.StartAndClose("nurse_1", 5); return(false); } c.ModifyHealth(c.MaxHealth, this); TextParticle.Add(e, Locale.Get("coins"), price, true, true); d.StartAndClose("nurse_2", 5); return(false); }
public override void Use(Entity entity, Item item) { base.Use(entity, item); var amount = Run.Depth * 5; entity.GetComponent<ConsumablesComponent>().Coins += amount; TextParticle.Add(entity, Locale.Get("coins"), amount, true); }
public override void Destroy() { base.Destroy(); if (Entity is Player) { TextParticle.Add(Entity, Locale.Get("damage"), 1, true, true); } }
protected override void OnTake(Item item, Entity who) { base.OnTake(item, who); var h = who.GetComponent <HealthComponent>(); h.ModifyHealth(h.MaxHealth, this); TextParticle.Add(who, "HP", h.MaxHealth, true); }
public override void Use(Entity entity, Item item) { switch (stat) { case Stat.InvincibilityTime: { entity.GetComponent <HealthComponent>().InvincibilityTimerMax += value; TextParticle.Add(entity, Locale.Get("invincibility_time")); break; } } }
public override void Run(Console Console, string[] Args) { var all = Console.GameArea.Tagged[Tags.Player]; foreach (var player in all) { var health = player.GetComponent <HealthComponent>(); health.Unhittable = !health.Unhittable; TextParticle.Add(player, "God Mode", 1, true, !health.Unhittable); Console.Print(health.Unhittable ? "God mode is on" : "God mode is off"); } }
protected override bool Interact(Entity e) { var h = e.GetComponent <HealthComponent>(); if (h.Health > 1) { TextParticle.Add(this, "HP", (int)h.Health - 1, true, true); } h.SetHealth(1, this, type: DamageType.Custom); e.GetComponent <InventoryComponent>().Pickup(Items.CreateAndAdd("bk:broken_heart", Area, true)); Run.AddScourge(true); Break(); return(true); }
public static bool Reroll(Item item, ItemPool pool, Func <ItemData, bool> filter = null) { var id = Items.Generate(pool, i => i.Id != item.Id && Items.ShouldAppear(i) && (filter == null || filter(i))); if (id != null) { item.LastId = item.Id; item.ConvertTo(id); item.AutoPickup = false; TextParticle.Add(item, Locale.Get("rerolled")).Stacks = false; return(true); } return(false); }
public override void Use(Entity entity, Item item) { base.Use(entity, item); var h = entity.GetComponent <HealthComponent>(); var amount = h.MaxHealth; if (amount == 0) { return; } entity.GetComponent <HeartsComponent>().ModifyShields(amount, item); h.InitMaxHealth = 0; TextParticle.Add(entity, Locale.Get("max_hp"), amount, true, true); TextParticle.Add(entity, Locale.Get("shields"), amount, true); }
public override void Happen(Player e) { var c = e.GetComponent <ActiveWeaponComponent>(); var item = c.Item; TextParticle.Add(e, item.Name, 1, true, true); c.Drop(); item.Done = true; if (e.GetComponent <WeaponComponent>().Item == null) { c.Set(Items.CreateAndAdd(LevelSave.MeleeOnly || item.Data.WeaponType == WeaponType.Melee ? "bk:ancient_sword" : "bk:ancient_revolver", e.Area)); } else { c.RequestSwap(); } }
public override bool HandleEvent(Event e) { if (e is HealthModifiedEvent hme) { if (hme.Amount < 0 && hme.Who == Item.Owner && Rnd.Chance(chance)) { hme.Amount = 0; if (Item.Id == "bk:cats_ear") { TextParticle.Add(Item.Owner, "Sick dodge!"); } return(true); } } return(base.HandleEvent(e)); }
public static bool Reroll(Item item, List <ItemData> pool, Func <ItemData, bool> filter = null, bool d2 = false) { var id = d2 ? item.LastId : null; if (id == null) { id = Items.GenerateAndRemove(pool, i => i.Id != item.Id && (filter == null || filter(i))); } if (id != null) { item.LastId = item.Id; item.ConvertTo(id); item.AutoPickup = false; TextParticle.Add(item, Locale.Get("rerolled")).Stacks = false; return(true); } return(false); }
public static void Reroll(Area area, Room room, bool rerollStands, bool spawnNewItems, bool ignore, ItemType[] types, Action <Item> processItem = null, bool d2 = false) { var items = room.Tagged[Tags.Item].ToArray(); var pool = Items.GeneratePool(Items.GetPool(room.GetPool() ?? ItemPool.Shop)); foreach (var e in items) { Item item = null; if (e is ItemStand s) { if (rerollStands) { if (s.Item == null) { if (spawnNewItems) { var id = s is ShopStand std?Items.Generate(std.GetPool()) : Items.GenerateAndRemove(pool); s.SetItem(Items.CreateAndAdd(id, area), null); TextParticle.Add(s, Locale.Get("rerolled")).Stacks = false; } continue; } var i = s.Item; if (!CanReroll(i)) { continue; } item = i; } } else if (e is Item i) { if (!CanReroll(i)) { continue; } if (types != null) { var found = false; foreach (var t in types) { if (t == i.Type) { found = true; } } if (found == ignore) { continue; } } item = i; } if (item == null || (item.TryGetComponent <OwnerComponent>(out var o) && !(o.Owner is ItemStand))) { continue; } if (Reroll(item, pool, null, d2)) { processItem?.Invoke(item); } if (e is ShopStand st) { st.Recalculate(); } } Audio.PlaySfx("item_reroll"); }
public override void Use(Entity entity, Item item) { if (Bomb) { var component = entity.GetComponent <HeartsComponent>(); if (Set) { component.BombsMax = Amount; } else { component.BombsMax += Amount; } if (GiveHp && Amount > 0) { component.ModifyBombs(Amount, entity); TextParticle.Add(entity, "HP", Amount, true); } } else { if (Amount > 0) { if (entity.GetComponent <LampComponent>().Item?.Id == "bk:shielded_lamp") { entity.GetComponent <HeartsComponent>().ModifyShields(Amount, entity); return; } else if (entity.GetComponent <LampComponent>().Item?.Id == "bk:explosive_lamp") { var c = entity.GetComponent <HeartsComponent>(); Amount = (int)Math.Ceiling(Amount / 2f); c.BombsMax += Amount; if (GiveHp) { c.ModifyBombs(Amount, entity); TextParticle.Add(entity, "HP", Amount, true); } return; } } var component = entity.GetComponent <HealthComponent>(); if (Set) { component.MaxHealth = Amount; } else { component.MaxHealth += Amount; } if (GiveHp && Amount > 0) { component.ModifyHealth(Amount, entity); TextParticle.Add(entity, "HP", Amount, true); } } TextParticle.Add(entity, Locale.Get("max_hp"), Math.Abs(Amount), true, Amount < 0); }
public override void Setup(JsonValue settings) { base.Setup(settings); modifiers = Items.ParseUses(settings["modifiers"]); if (modifiers != null) { foreach (var m in modifiers) { m.Item = Item; } } damage = settings["damage"].Number(1); speed = settings["speed"].Number(6); speedMax = settings["speedm"].Number(10); range = settings["range"].Number(0) * 0.5f; scaleMin = settings["scale"].Number(1); scaleMax = settings["scalem"].Number(1); slice = settings["texture"].String("rect"); toCursor = settings["cursor"].Bool(false); toEnemy = settings["tomb"].Bool(false); sfx = settings["sfx"].String("item_gun_fire"); sfx_number = settings["sfxn"].Int(0); ReloadSfx = settings["rsfx"].Bool(false); manaUsage = settings["mana"].Int(0); color = settings["color"].String(""); angleAdd = settings["ang"].Number(0); if (manaUsage > 0) { manaDrop = settings["mdr"].Int(0); } if (slice == "default") { slice = "rect"; } accuracy = settings["accuracy"].Number(0).ToRadians(); count = settings["amount"].Int(1); prefab = settings["prefab"].String(""); light = settings["light"].Bool(true); knockback = settings["knockback"].Number(1); rect = settings["rect"].Bool(false); wait = settings["wait"].Bool(false); disableBoost = settings["dsb"].Bool(false); shells = settings["shells"].Bool(true); emeralds = settings["emeralds"].Bool(false); SpawnProjectile = (entity, item) => { if (manaUsage > 0) { var mana = entity.GetComponent <ManaComponent>(); if (mana.Mana < manaUsage) { AnimationUtil.ActionFailed(); return; } mana.ModifyMana(-manaUsage); } if (emeralds) { if (GlobalSave.Emeralds == 0) { AnimationUtil.ActionFailed(); TextParticle.Add(entity, Locale.Get("no_emeralds")); return; } GlobalSave.Emeralds--; } var bad = entity is Creature c && !c.IsFriendly(); var sl = slice; if (bad) { sl = "small"; } entity.TryGetComponent <StatsComponent>(out var stats); if (sfx == "item_gun_fire") { entity.GetComponent <AudioEmitterComponent>().EmitRandomizedPrefixed(sfx, 2, 0.5f, sz: 0.2f); } else { if (sfx_number == 0) { entity.GetComponent <AudioEmitterComponent>().EmitRandomized(sfx, 0.5f, sz: 0.25f); } else { entity.GetComponent <AudioEmitterComponent>().EmitRandomizedPrefixed(sfx, sfx_number, 0.5f, sz: 0.25f); } } var aim = entity.GetComponent <AimComponent>(); var from = toCursor ? entity.Center : aim.Center; var am = toCursor ? entity.GetComponent <CursorComponent>().Cursor.GamePosition : aim.RealAim; if (toEnemy) { var target = entity.Area.FindClosest(from, Tags.MustBeKilled, e => true); if (target != null) { am = target.Center; } } var a = MathUtils.Angle(am.X - from.X, am.Y - from.Y); var pr = prefab.Length == 0 ? null : ProjectileRegistry.Get(prefab); var ac = accuracy; if (stats != null) { ac /= stats.Accuracy; } var cnt = count; var accurate = false; if (entity is Player pl) { var e = new PlayerShootEvent { Player = (Player)entity }; entity.HandleEvent(e); cnt += e.Times - 1; accurate = e.Accurate; if (sl == "rect") { sl = pl.ProjectileTexture; } } for (var i = 0; i < cnt; i++) { var angle = a; if (accurate) { angle += (i - (int)(cnt * 0.5f)) * 0.2f + Rnd.Float(-ac / 2f, ac / 2f); } else if (cnt == 1 || i > 0) { angle += Rnd.Float(-ac / 2f, ac / 2f); } angle += angleAdd * (float)Math.PI * 2; var antiAngle = angle - (float)Math.PI; var projectile = Projectile.Make(entity, sl, angle, Rnd.Float(speed, speedMax), !rect, 0, null, Rnd.Float(scaleMin, scaleMax), damage * (item.Scourged ? 1.5f : 1f), Item); projectile.Boost = !disableBoost; projectile.Item = item; Camera.Instance.Push(antiAngle, 4f); entity.GetComponent <RectBodyComponent>()?.KnockbackFrom(antiAngle, 0.4f * knockback); var clr = bad ? Projectile.RedLight : ProjectileColor.Yellow; if (!string.IsNullOrEmpty(color) && ProjectileColor.Colors.TryGetValue(color, out clr)) { projectile.Color = clr; } if (light) { projectile.AddLight(32f, clr); } projectile.FlashTimer = 0.05f; if (range > 0.01f) { if (Math.Abs(projectile.Range - (-1)) < 0.1f) { projectile.Range = range / speed; } else { projectile.Range += range / speed; } } projectile.Center = from; if (modifiers != null) { foreach (var m in modifiers) { if (m is ModifyProjectilesUse mpu) { mpu.ModifyProjectile(projectile); } } } pr?.Invoke(projectile); if (wait && i == 0) { ProjectileDied = false; if (prefab == "bk:axe") { projectile.OnDeath += (prj, e, t) => { prj.OnDeath += (prj2, e2, t2) => ProjectileDied = true; }; } else { projectile.OnDeath += (prj, e, t) => ProjectileDied = true; } } if (manaUsage > 0) { if (manaDrop == 0) { projectile.OnDeath += (prj, e, t) => { PlaceMana(entity.Area, prj.Center); }; } else if (manaDrop == 1) { PlaceMana(entity.Area, entity.Center); } else { var where = entity.Center; projectile.OnDeath += (prj, e, t) => { PlaceMana(entity.Area, where); }; } } } if (shells) { Timer.Add(() => { var p = new ShellParticle(new Particle(Controllers.Destroy, new TexturedParticleRenderer { Region = CommonAse.Particles.GetSlice("shell") })); p.Position = entity.Center; p.Y += Rnd.Float(-4, 10); entity.Area.Add(p); var f = (entity.CenterX > entity.GetComponent <CursorComponent>().Cursor.GamePosition.X ? 1 : -1); p.Particle.Velocity = new Vector2(f * Rnd.Float(40, 60), 0) + entity.GetAnyComponent <BodyComponent>().Velocity; p.Particle.Angle = 0; p.Particle.Zv = Rnd.Float(1.5f, 2.5f); p.Particle.AngleVelocity = f * Rnd.Float(40, 70); p.AddShadow(); }, 0.2f); } }; }
public override void Use(Entity entity, Item item) { Run.Luck += Amount; TextParticle.Add(entity, Locale.Get("luck"), Amount, true, Amount < 0); }
public override void Use(Entity entity, Item item) { base.Use(entity, item); var stats = entity.GetComponent <StatsComponent>(); if (Math.Abs(Math.Abs(Speed) - (AddSpeed ? 0 : 1)) >= 0.01f) { TextParticle.Add(entity, Locale.Get("speed"), Math.Abs(Speed), true, Speed < 0); if (AddSpeed) { stats.Speed += Speed; } else { stats.Speed *= Speed; } } if (Math.Abs(Math.Abs(Damage) - (AddDamage ? 0 : 1)) >= 0.01f) { TextParticle.Add(entity, Locale.Get("damage"), Math.Abs(Damage), true, Damage < 0); if (AddDamage) { stats.Damage += Damage; } else { stats.Damage *= Damage; } } if (Math.Abs(Math.Abs(FireRate) - (AddFireRate ? 0 : 1)) >= 0.01f) { TextParticle.Add(entity, Locale.Get("fire_rate"), Math.Abs(FireRate), true, FireRate < 0); if (AddFireRate) { stats.FireRate += FireRate; } else { stats.FireRate *= FireRate; } } if (Math.Abs(Math.Abs(RangedRate) - (AddRangedRate ? 0 : 1)) >= 0.01f) { TextParticle.Add(entity, Locale.Get("fire_rate"), Math.Abs(RangedRate), true, RangedRate < 0); if (AddRangedRate) { stats.RangedRate += RangedRate; } else { stats.RangedRate *= RangedRate; } } if (Math.Abs(Math.Abs(Accuracy) - (AddAccuracy ? 0 : 1)) >= 0.01f) { TextParticle.Add(entity, Locale.Get("accuracy"), Math.Abs(Accuracy), true, Accuracy < 0); if (AddAccuracy) { stats.Accuracy += Accuracy; } else { stats.Accuracy *= Accuracy; } } if (Math.Abs(Math.Abs(Range) - (AddRange ? 0 : 1)) >= 0.01f) { TextParticle.Add(entity, Locale.Get("range"), Math.Abs(Range), true, Range < 0); if (AddRange) { stats.Range += Range; } else { stats.Range *= Range; } } }