/// <summary> /// 受到来自一个目标的攻击 /// </summary> /// <param name="attacker">攻击来源</param> /// <param name="damage">攻击伤害</param> public void TakeAttack(CardHolder attacker, int damage) { PreTakeAttackEvent?.Invoke(); if (TakeAttackDamageChangeEvent != null) { damage = TakeAttackDamageChangeEvent(damage); } if (CurrentBlockValue > 0) { PreBlockEvent?.Invoke(); if (CurrentBlockValue > damage) { CurrentBlockValue -= damage; damage = 0; } else { damage -= CurrentBlockValue; CurrentBlockValue = 0; BlockBreakEvent?.Invoke(); } AfterBlockEvent?.Invoke(); } if (damage > 0) { TakeDamage(attacker, damage); } AfterTakeAttackEvent?.Invoke(); }
protected override bool OnBlockBreak(BlockBreakEventArgs e) { if (e.Player != null && e.Player is OpenPlayer player) { if (player.GameMode == GameMode.Creative) { BlockBreakEvent ev = new BlockBreakEvent(player, e.Block, e.Drops); EventDispatcher.DispatchEvent(ev); if (ev.IsCancelled) { return(false); } ev.OnComplete(); return(true); //BreakBlock(e.Block, BlockFace.None, player); } } return(false); }
public Task OnBlockBreak(BlockBreakEvent e) { return(Task.Run(() => { if (Random.NextBool()) { Log.Info($"Cancelled block breaking."); e.SetCancelled(true); } else { Log.Info("Did not cancel breaking"); if (Random.Next(0, 10) == 5) { Log.Info($"Golden apple yay."); e.Drops.Add(new ItemGoldenApple()); e.Source.Level.BroadcastMessage($"A goldenapple was found! Lucky!"); } } })); }
public bool BreakBlock(Block block, BlockFace face, OpenPlayer player = null, Item tool = null) { BlockEntity blockEntity = GetBlockEntity(block.Coordinates); bool canBreak = player == null || tool == null || tool.BreakBlock(this, player, block, blockEntity); if (!canBreak || !AllowBreak || player?.GameMode == GameMode.Spectator) { if (player != null) { RevertBlockAction(player, block, blockEntity); } return(false); } // block.BreakBlock(this, face); List <Item> drops = new List <Item>(); if (player == null || player.GameMode != GameMode.Creative) { drops.AddRange(block.GetDrops(tool ?? new ItemAir())); } if (blockEntity != null) { // RemoveBlockEntity(block.Coordinates); drops.AddRange(blockEntity.GetDrops()); } BlockBreakEvent e = new BlockBreakEvent(player, block, drops); EventDispatcher.DispatchEvent(e); if (e.IsCancelled) { if (player != null) { RevertBlockAction(player, block, blockEntity); } return(false); } block.BreakBlock(this, face); if (blockEntity != null) { RemoveBlockEntity(block.Coordinates); } if (player == null || player.GameMode != GameMode.Creative) { foreach (Item drop in e.Drops) { DropItem(block.Coordinates, drop); } } e.OnComplete(); return(true); }