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); }
protected override bool CanTake(Entity entity) { if (!base.CanTake(entity)) { return(false); } if (GlobalSave.Emeralds < price) { AnimationUtil.ActionFailed(); var npc = Area.FindClosest(Center, Tags.Npc, n => n is ShopNpc); if (npc != null && npc.TryGetComponent <DialogComponent>(out var c)) { c.StartAndClose($"shopkeeper_{Rnd.Int(15, 18)}", 3); } return(false); } GlobalSave.Emeralds -= price; Items.Unlock(Item.Id); AlreadyOnStand.Remove(Item.Id); if (!ShowUnlocked) { Item.Done = true; /*var item = PickItem(); * SetItem(item, entity, false);*/ AnimationUtil.Poof(Center, 1); } Audio.PlaySfx("item_purchase"); Achievements.Unlock("bk:unlock"); entity.HandleEvent(new ItemBoughtEvent { Item = item, Who = entity, Stand = this }); foreach (var i in Area.Tagged[Tags.Item]) { if (i is Item it) { it.CheckMasked(); } else if (i is ItemStand its) { its.Item?.CheckMasked(); } } DoStuff(); return(ShowUnlocked); }
public void Reroll(Entity entity, bool consumeCoin) { if (broken) { return; } var room = GetComponent <RoomComponent>().Room; if (room == null) { return; } Animate(); if (consumeCoin) { var component = entity.GetComponent <ConsumablesComponent>(); if (component.Coins == 0) { GetComponent <DialogComponent>().StartAndClose("machine_0", 3); AnimationUtil.ActionFailed(); return; } // todo: animate coin going in component.Coins -= 1; coinsConsumed++; if (Rnd.Float(100) > (coinsConsumed + Run.Luck) * 30) { return; // Did not pay enough :P } } GetComponent <DialogComponent>().Close(); Items.Unlock("bk:d6"); // Reset the luck for the next uses coinsConsumed = 0; Reroller.Reroll(entity.Area, room, true, false, true, ignoredTypes); numRolled += (consumeCoin ? 1 : 2); Audio.PlaySfx("level_vending_machine"); if (numRolled > 1 && Rnd.Float(100) < numRolled * 15 - Run.Luck * 2) { Break(); } }
protected override bool CanTake(Entity entity) { if (!base.CanTake(entity)) { return(false); } if (!Sells || Free) { return(true); } if (!OkToBuy(entity)) { AnimationUtil.ActionFailed(); entity.GetComponent <DialogComponent>().StartAndClose($"~~{Locale.Get("scourged")}~~", 2); return(false); } else if (!TryPay(entity)) { AnimationUtil.ActionFailed(); foreach (var n in GetComponent <RoomComponent>().Room.Tagged[Tags.Npc]) { if (n is ShopNpc s) { n.GetComponent <DialogComponent>().StartAndClose(s.GetFailDialog(), 3); break; } else if (n is ShopKeeper) { n.GetComponent <DialogComponent>().StartAndClose($"shopkeeper_{Rnd.Int(15, 18)}", 3); break; } } return(false); } Sells = false; Audio.PlaySfx("item_purchase"); return(true); }
protected virtual bool Interact(Entity entity) { if (open || !CanOpen) { return(true); } if (TryOpen(entity)) { Open(entity); return(true); } else { AnimationUtil.ActionFailed(); } return(false); }
protected override bool Interact(Entity entity) { if (GlobalSave.Emeralds < 3) { AnimationUtil.ActionFailed(); foreach (var n in Area.Tagged[Tags.Npc]) { if (n is Mike) { n.GetComponent <DialogComponent>().Start("mike_0"); break; } } return(true); } GlobalSave.Emeralds -= 3; return(base.Interact(entity)); }
protected virtual bool Interact(Entity entity) { if (!CanUse()) { AnimationUtil.ActionFailed(); return(true); } entity.RemoveComponent <PlayerInputComponent>(); entity.GetComponent <HealthComponent>().Unhittable = true; if (Run.Depth == Run.ContentEndDepth || (Run.Type == RunType.BossRush && Run.Depth == 5)) { if (Run.Type == RunType.Regular || Run.Type == RunType.Twitch) { SaveManager.Delete(SaveType.Level); Run.ActualDepth = -1; Run.Depth = 1; Run.Loop++; Achievements.Unlock("bk:loop"); } else { Run.Win(); } } else { ((InGameState)Engine.Instance.State).TransitionToBlack(entity.Center, () => { Run.NumPlayers = 0; Descend(); }); } Audio.PlaySfx("player_descending"); return(true); }
public override bool HandleEvent(Event e) { if (Item != null && Item.HandleOwnerEvent(e)) { return(true); } if (e is ItemCheckEvent ev && !ev.Handled && ShouldReplace(ev.Item)) { if (Entity is Player && Item != null && Item.Scourged) { AnimationUtil.ActionFailed(); ev.Blocked = true; Entity.GetComponent <DialogComponent>().StartAndClose($"~~{Locale.Get("scourged")}~~", 2); return(false); } Set(ev.Item, ev.Animate); return(true); } return(base.HandleEvent(e)); }
protected virtual bool Interact(Entity entity) { if (Item != null && Item.Masked && Run.Depth < 1) { return(false); } if (entity.TryGetComponent <InventoryComponent>(out var inventory)) { if (item != null) { if (CanTake(entity)) { var i = item; var remove = false; if (this is GarderobeStand) { return(true); } else if (this is PermanentStand && Item != null && Item.Type == ItemType.Weapon) { var c = entity.GetComponent <ActiveWeaponComponent>(); var item = c.Item; c.Set(Items.CreateAndAdd(Item.Id, Area), false); if (item != null) { item.Done = true; } return(true); } else if (this is PermanentStand && Item != null && Item.Type == ItemType.Active) { var c = entity.GetComponent <ActiveItemComponent>(); var item = c.Item; c.Set(Items.CreateAndAdd(Item.Id, Area), false); if (item != null) { item.Done = true; } return(true); } else if (this is LampStand && Item != null && Item.Type == ItemType.Lamp) { var c = entity.GetComponent <LampComponent>(); var item = c.Item; c.Set(Items.CreateAndAdd(Item.Id, Area), false); if (item != null) { item.Done = true; } return(true); } else { SetItem(null, entity, false); remove = true; } if (!inventory.Pickup(i) && remove) { SetItem(i, null, false); } } return(this is HatStand || this is ShopStand || Run.Depth == -2); } else if (!(this is ShopStand) && entity.TryGetComponent <ActiveWeaponComponent>(out var weapon) && weapon.Item != null) { if (weapon.Item.Scourged) { AnimationUtil.ActionFailed(); } else { SetItem(weapon.Drop(), entity); weapon.RequestSwap(); } return(true); } } return(true); }
private bool Interact(Entity e) { Animate(); var p = e ?? LocalPlayer.Locate(Area); var active = p.GetComponent <ActiveItemComponent>(); if (active.Item == null) { GetComponent <DialogComponent>().StartAndClose("charger_0", 3); AnimationUtil.ActionFailed(); return(true); } if (active.Item.Delay <= 0.02f) { GetComponent <DialogComponent>().StartAndClose("charger_1", 3); AnimationUtil.ActionFailed(); return(true); } if (e != null) { var component = p.GetComponent <ConsumablesComponent>(); if (component.Coins == 0) { if (noMoneyAttempt == 0) { GetComponent <DialogComponent>().StartAndClose("charger_2", 3); } else if (noMoneyAttempt == 1) { GetComponent <DialogComponent>().StartAndClose("charger_3", 3); } else { var hp = p.GetComponent <HealthComponent>(); hp.ModifyHealth(-1, this); GetComponent <DialogComponent>().StartAndClose($"charger_{(hp.HasNoHealth ? 5 : 4)}", 3); } noMoneyAttempt++; AnimationUtil.ActionFailed(); return(true); } noMoneyAttempt = 0; component.Coins -= 1; } timesUsed += e == null ? 4 : 1; active.Charge(Rnd.Int(1, 3)); Audio.PlaySfx("item_charge"); if (Rnd.Float(100) < timesUsed * 2 - Run.Luck * 0.5f) { Break(false); ExplosionMaker.Make(p); return(true); } return(false); }
protected bool Interact(Entity entity) { if (broken) { return(false); } var room = GetComponent <RoomComponent>().Room; if (room == null) { return(false); } Animate(); var component = entity.GetComponent <ConsumablesComponent>(); if (component.Coins == 0) { GetComponent <DialogComponent>().StartAndClose("machine_0", 3); AnimationUtil.ActionFailed(); return(false); } GetComponent <DialogComponent>().Close(); component.Coins -= 1; coinsConsumed++; if (Rnd.Float(100) > (coinsConsumed + Run.Luck - Run.Scourge) * 2) { Audio.PlaySfx("level_vending_machine_coin"); return(false); // Did not pay enough :P } // Reset the luck for the next uses coinsConsumed = 0; var item = Items.Generate(ItemPool.Shop); if (item == null) { return(false); } var e = Items.CreateAndAdd(item, Area); e.CenterX = CenterX; e.CenterY = Bottom; e.GetAnyComponent <BodyComponent>().Velocity = new Vector2(0, 128); spawnedCount++; Audio.PlaySfx("level_vending_machine"); if (spawnedCount > 1 && Rnd.Float(100) < spawnedCount * 30 - Run.Luck * 2) { Break(false); return(true); } return(false); }
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); } }; }