public override void OnAttached(AbstractEntity entity)
        {
            base.OnAttached(entity);

            direction = entity.GetVector3("direction");
            Debug.Assert(direction != Vector3.Zero);
            direction.Normalize();
        }
        public override void OnAttached(AbstractEntity light)
        {
            this.light  = light as Entity;
            this.island = Game.Instance.Simulation.EntityManager[light.GetString("island")];

            // register island change handler
            island.GetVector3Attribute(CommonNames.Position).ValueChanged += OnIslandPositionChanged;

            positionOffset = light.GetVector3(CommonNames.Position) - island.GetVector3(CommonNames.Position);

//            (light as Entity).Update += OnUpdate;
        }
        public override void OnAttached(AbstractEntity entity)
        {
            Debug.Assert(entity.HasVector3(CommonNames.Position));

            this.island          = entity as Entity;
            this.constants       = Game.Instance.Simulation.EntityManager["island_constants"];
            this.playerConstants = Game.Instance.Simulation.EntityManager["player_constants"];

            if (!entity.HasAttribute(CommonNames.MaxHealth))
            {
                entity.AddFloatAttribute(CommonNames.MaxHealth, (entity.GetVector3(CommonNames.Scale).Length() * constants.GetFloat("scale_health_multiplier")));
            }
            entity.AddFloatAttribute(CommonNames.Health, entity.GetFloat(CommonNames.MaxHealth));

            hasFixedMovementPath = entity.GetBool("fixed");

            entity.AddVector3Attribute("repulsion_velocity", Vector3.Zero);
            entity.AddVector3Attribute("pushback_velocity", Vector3.Zero);
            entity.AddVector3Attribute("repositioning_velocity", Vector3.Zero);

            entity.AddStringAttribute("repulsed_by", "");
            entity.AddIntAttribute("players_on_island", 0);
            entity.AddIntAttribute("players_targeting_island", 0);

            // approximation of island's radius and height
            Vector3 scale = island.GetVector3(CommonNames.Scale);

            entity.AddFloatAttribute("height", scale.Y);
            scale.Y = 0;
            entity.AddFloatAttribute("radius", scale.Length());

            (entity as Entity).OnUpdate += OnUpdate;

            entity.GetProperty <CollisionProperty>("collision").OnContact += CollisionHandler;
//            ((Vector3Attribute)entity.GetAttribute("repulsion_velocity")).ValueChanged += RepulsionChangeHandler;
            entity.GetAttribute <StringAttribute>("repulsed_by").ValueChanged    += RepulsedByChangeHandler;
            entity.GetAttribute <IntAttribute>("players_on_island").ValueChanged += PlayersOnIslandChangeHandler;

            originalPosition = entity.GetVector3(CommonNames.Position);
        }
Exemplo n.º 4
0
        private void AddSpawnLight(AbstractEntity player)
        {
            spawnLight = new Entity("spawn_light_" + player.Name);
            spawnLight.AddStringAttribute("player", player.Name);
            spawnLight.AddStringAttribute("island", destinationIsland.Name);

            Vector3 position = player.GetVector3(CommonNames.Position);
            Vector3 surfacePos;

            Simulation.GetPositionOnSurface(ref position, destinationIsland, out surfacePos);
            spawnLight.AddVector3Attribute(CommonNames.Position, surfacePos);

            Game.Instance.Simulation.EntityManager.AddDeferred(spawnLight, "spawn_light_base", templates);

            // and sound
            Game.Instance.AudioPlayer.Play(Game.Instance.Simulation.SoundRegistry.Respawn);
        }