public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Transform     transform = entity.GetOrCreate <Transform>("Transform");
            PhysicsBlock  physics   = entity.GetOrCreate <PhysicsBlock>("Physics");
            ModelInstance model     = entity.GetOrCreate <ModelInstance>("Model");

            physics.Add(new TwoWayBinding <Matrix>(transform.Matrix, physics.Transform));

            SceneryBlock sceneryBlock = entity.GetOrCreate <SceneryBlock>("SceneryBlock");

            physics.Add(new Binding <Vector3, float>(physics.Size, x => new Vector3(x), sceneryBlock.Scale));
            model.Add(new Binding <Matrix>(model.Transform, () => Matrix.CreateScale(sceneryBlock.Scale) * transform.Matrix, transform.Matrix, sceneryBlock.Scale));

            this.SetMain(entity, main);

            entity.Add("IsAffectedByGravity", physics.IsAffectedByGravity);
            sceneryBlock.EditorProperties();

            if (!main.EditorEnabled && !physics.IsAffectedByGravity &&
                (sceneryBlock.Type.Value == Voxel.t.WhitePermanent || sceneryBlock.Type.Value == Voxel.t.White))
            {
                Sound.AttachTracker(entity);
                AkSoundEngine.PostEvent(AK.EVENTS.PLAY_WHITE_LIGHT, entity);
                SoundKiller.Add(entity, AK.EVENTS.STOP_WHITE_LIGHT);
                physics.Add(new CommandBinding <Collidable, ContactCollection>(physics.Collided, delegate(Collidable other, ContactCollection contacts)
                {
                    float impulse = contacts.Max(x => x.NormalImpulse);
                    if (impulse > 0.2f)
                    {
                        AkSoundEngine.PostEvent(AK.EVENTS.PLAY_WHITE_LIGHT_HIT, entity);
                    }
                }));
            }
        }
示例#2
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            entity.CannotSuspend = true;

            Transform     transform = entity.GetOrCreate <Transform>("Transform");
            PhysicsBlock  physics   = entity.GetOrCreate <PhysicsBlock>("Physics");
            ModelInstance model     = entity.GetOrCreate <ModelInstance>("Model");

            physics.Add(new TwoWayBinding <Matrix>(transform.Matrix, physics.Transform));

            Property <Vector3> scale = new Property <Vector3> {
                Value = new Vector3(0.5f)
            };

            model.Add(new Binding <Matrix>(model.Transform, () => Matrix.CreateScale(scale) * transform.Matrix, scale, transform.Matrix));

            entity.Add("Fade", new Animation
                       (
                           new Animation.Delay(5.0f),
                           new Animation.Vector3MoveTo(scale, Vector3.Zero, 1.0f),
                           new Animation.Execute(entity.Delete)
                       ));

            this.SetMain(entity, main);
            PhysicsBlock.CancelPlayerCollisions(physics);
        }
示例#3
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Transform     transform = entity.GetOrCreate <Transform>("Transform");
            PhysicsBlock  physics   = entity.GetOrCreate <PhysicsBlock>("Physics");
            ModelInstance model     = entity.GetOrCreate <ModelInstance>("Model");

            physics.Add(new TwoWayBinding <Matrix>(transform.Matrix, physics.Transform));

            SceneryBlock sceneryBlock = entity.GetOrCreate <SceneryBlock>("SceneryBlock");

            physics.Add(new Binding <Vector3, float>(physics.Size, x => new Vector3(x), sceneryBlock.Scale));
            model.Add(new Binding <Matrix>(model.Transform, () => Matrix.CreateScale(sceneryBlock.Scale) * transform.Matrix, transform.Matrix, sceneryBlock.Scale));

            this.SetMain(entity, main);

            entity.Add("IsAffectedByGravity", physics.IsAffectedByGravity);
            sceneryBlock.EditorProperties();
        }
示例#4
0
        public void Use(Player p, string[] args)
        {
            if (doory == null)
            {
                Door door = new Door(Block.NameToBlock(args[0]), Block.NameToBlock(args[1]));
                doory = door;
            }
            if (args.Length == 0)
            {
                Help(p); return;
            }
            if (!p.ExtraData.ContainsKey("Door"))
            {
                p.ExtraData.Add("Door", false);
            }

            if (!(bool)p.ExtraData["Door"])
            {
                Block b  = Block.NameToBlock(args[0]);
                Block b1 = Block.NameToBlock(args[1]);
                if (b is UNKNOWN || b1 is UNKNOWN)
                {
                    p.SendMessage("Cannot find block \"" + args[0] + "\"!");
                    return;
                }
                PhysicsBlock.Add(doory);
                if (b.Permission > p.Group.Permission || b1.Permission > p.Group.Permission)
                {
                    p.SendMessage("Cannot place " + StringUtils.TitleCase(b.Name) + "!");
                    return;
                }

                p.ExtraData["Door"] = true;
                if (!p.ExtraData.ContainsKey("BlockDoor"))
                {
                    p.ExtraData.Add("BlockDoor", b);
                }
                p.SendMessage("&b" + StringUtils.TitleCase(b.Name) + Server.DefaultColor + " door mode &9on");
                p.OnPlayerBlockChange.Normal += OnPlayerBlockChangeOnNormal;
                return;
            }
            else
            {
                if (args[0] != ((Block)p.ExtraData["BlockDoor"]).Name)
                {
                    if (doory == null)
                    {
                        Door door = new Door(Block.NameToBlock(args[0]), Block.NameToBlock(args[1]));
                        doory = door;
                    }
                    Block b  = Block.NameToBlock(args[0]);
                    Block b1 = Block.NameToBlock(args[1]);
                    if (b is UNKNOWN || b1 is UNKNOWN)
                    {
                        p.SendMessage("Cannot find block \"" + args[0] + "\"!");
                        return;
                    }
                    if (b.Permission > p.Group.Permission || b1.Permission > p.Group.Permission)
                    {
                        p.SendMessage("Cannot place " + StringUtils.TitleCase(b.Name) + "!");
                        return;
                    }

                    p.ExtraData["Door"]      = true;
                    p.ExtraData["BlockDoor"] = b;

                    p.SendMessage("&b" + StringUtils.TitleCase(b.Name) + Server.DefaultColor + " mode &9on");
                    return;
                }
                if (!p.ExtraData.ContainsKey("BlockMode"))
                {
                    throw new Exception("No block set in block mode");
                }

                Block prev = (Block)p.ExtraData["BlockMode"];
                p.OnPlayerBlockChange.Normal -= OnPlayerBlockChangeOnNormal;
                doory = null;
                p.SendMessage("&b" + StringUtils.TitleCase(prev.Name) + Server.DefaultColor + " mode &coff");
                p.ExtraData["Mode"]      = false;
                p.ExtraData["BlockMode"] = null;
            }
        }