Пример #1
0
 public Buttons(Level parent, BinaryReader reader) : this(parent)
 {
     var count = reader.ReadUInt16();
     for (var i = 0; i < count; i++)
     {
         BlockEvents.Add(new BlockEvent(parent, reader));
     }
     count = reader.ReadUInt16();
     for (var i = 0; i < count; i++)
     {
         Add(new Button(this, reader));
     }
 }
Пример #2
0
        public override void OnEnable()
        {
            base.OnEnable();

            action = target as BlockEvents;

            timeoutAttributes      = new object[] { new TooltipAttribute("Block events for the specified amount of time.") };
            realTimeAttributes     = new object[] { new TooltipAttribute("Use real time, ignoring time scale.") };
            useEventAttributes     = new object[] { new TooltipAttribute("Respond to the unblock event itself.") };
            boolVariableAttributes = new object[]
            {
                new TooltipAttribute("Bool variable to test."),
                new UIHintAttribute(UIHint.Variable)
            };
        }
Пример #3
0
        public void UseBreak(Vector3 pos, Item item, Player player)
        {
            if (player.IsSpectator)
            {
                return;
            }
            Block block = this.GetBlock(pos);

            BlockBreakEventArgs blockBreakEvent = new BlockBreakEventArgs(player, block, item);

            if (player.IsSurvival && !block.CanBreak)
            {
                blockBreakEvent.IsCancel = true;
            }

            if (Server.ServerConfig.SpawnProtection > 0 || player.Op)
            {
                //TODO
            }

            BlockEvents.OnBlockBreak(blockBreakEvent);
            if (blockBreakEvent.IsCancel)
            {
                return;
            }

            Item[] drops = blockBreakEvent.Drops;

            //TODO : can destroy

            LevelEventPacket pk = new LevelEventPacket();

            pk.EventId  = LevelEventPacket.EVENT_PARTICLE_DESTROY;
            pk.Position = pos + new Vector3(0.5f, 0.5f, 0.5f);
            pk.Data     = block.RuntimeId;
            player.SendPacket(pk); //TODO : near players

            block.Break(player, item);

            item.BlockDestroyed(block, player);

            //TODO : item drop
        }
Пример #4
0
        public void UseItem(Vector3 pos, Item item, BlockFace blockFace, Vector3 clickPos, Player player)
        {
            Block clicked = this.GetBlock(pos);
            Block replace = clicked.GetSideBlock(blockFace);

            if (clicked.Y > 255 || clicked.Y < 0 || clicked.ID == BlockFactory.AIR)
            {
                return;
            }

            PlayerInteractEventArgs playerInteractEvent = new PlayerInteractEventArgs(player, item, clicked, blockFace);

            if (player.IsAdventure)
            {
                playerInteractEvent.IsCancel = true;
            }

            if (Server.ServerConfig.SpawnProtection > 0 || player.Op)
            {
                //TODO
            }

            PlayerEvents.OnPlayerInteract(playerInteractEvent);
            if (playerInteractEvent.IsCancel)
            {
                return;
            }

            clicked.Update(World.BLOCK_UPDATE_TOUCH);
            if (!player.Sneaking && clicked.CanBeActivated && clicked.Activate(player, item))
            {
                return;
            }

            if (!player.Sneaking && item.CanBeActivate && item.Activate(player, this, clicked, blockFace, clickPos))
            {
                if (item.Count <= 0)
                {
                    return;
                }
            }

            if (!item.CanBePlace)
            {
                return;
            }
            Block hand = item.Block;

            hand.Position = replace.Position;

            if (clicked.CanBeReplaced)
            {
                replace       = clicked;
                hand.Position = replace.Position;
            }

            //TODO : near by entity check

            //TODO : check can place on

            BlockPlaceEventArgs blockPlaceEvent = new BlockPlaceEventArgs(player, hand, replace, clicked, item);

            //TODO : check spawn protection

            BlockEvents.OnBlockPlace(blockPlaceEvent);
            if (blockPlaceEvent.IsCancel)
            {
                return;
            }
            hand.Place(clicked, replace, blockFace, clickPos, player, item);

            LevelSoundEventPacket pk = new LevelSoundEventPacket();

            pk.Position  = (Vector3)hand.Position;
            pk.Sound     = LevelSoundEventPacket.SOUND_PLACE;
            pk.ExtraData = hand.RuntimeId;
            pk.Pitch     = 1;
            player.SendPacket(pk); //TODO : near players
        }