public override void OnAttached(AbstractEntity entity)
        {
            this.iceSpike  = entity as Entity;
            this.constants = Game.Instance.Simulation.EntityManager["player_constants"];
            this.templates = Game.Instance.ContentManager.Load <LevelData>("Level/Common/DynamicTemplates");

            entity.GetProperty <CollisionProperty>("collision").OnContact += IceSpikeCollisionHandler;

            string targetPlayerName = entity.GetString("target_player");

            if (targetPlayerName != "")
            {
                targetPlayer = Game.Instance.Simulation.EntityManager[targetPlayerName];
                Game.Instance.Simulation.EntityManager.EntityRemoved += OnEntityRemoved;
            }
            else
            {
                targetPlayer = null;
            }

            shootingPlayer = Game.Instance.Simulation.EntityManager[entity.GetString("player")];

            createdAt = Game.Instance.Simulation.Time.At;

            (entity as Entity).OnUpdate += OnUpdate;
        }
 public override void OnDetached(AbstractEntity flame)
 {
     (flame as Entity).OnUpdate -= OnUpdate;
     flame.GetProperty <CollisionProperty>("collision").OnContact  -= FlamethrowerCollisionHandler;
     flame.GetBoolAttribute(CommonNames.Fueled).ValueChanged       -= FlameFuelChangeHandler;
     player.GetVector3Attribute(CommonNames.Position).ValueChanged -= PlayerPositionHandler;
 }
Example #3
0
        public override void OnAttached(
            AbstractEntity entity
            )
        {
            this.powerup   = entity as Entity;
            this.constants = Game.Instance.Simulation.EntityManager["powerup_constants"];
            this.island    = Game.Instance.Simulation.EntityManager[entity.GetString("island_reference")];

            rand = new Random(island.GetHashCode());

            // initialize properties
            Debug.Assert(this.powerup.HasVector3("relative_position"), "must have a relative translation attribute");
            if (!this.powerup.HasAttribute(CommonNames.Position))
            {
                this.powerup.AddVector3Attribute(CommonNames.Position, Vector3.Zero);
            }

            Debug.Assert(powerup.HasBool("fixed"));

            // get position on surface
            powerup.AddFloatAttribute("surface_offset", 0f);
            CalculateSurfaceOffset();
            Vector3 islandPos = island.GetVector3(CommonNames.Position);

            PositionOnIsland(ref islandPos);

            // add timeout respawn attribute
            this.powerup.AddFloatAttribute("respawn_at", 0);

            // register handlers
            this.island.GetVector3Attribute(CommonNames.Position).ValueChanged += OnIslandPositionChanged;
            entity.GetProperty <CollisionProperty>("collision").OnContact      += PowerupCollisionHandler;

            powerup.OnUpdate += OnUpdate;
        }
        public override void OnDetached(AbstractEntity entity)
        {
            (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;
        }
Example #5
0
        public override void OnAttached(AbstractEntity explosion)
        {
            liveTo = Game.Instance.Simulation.Time.At + explosion.GetInt("live_span");

            explosion.GetProperty <CollisionProperty>("collision").OnContact += ExplosionCollisionHandler;

            (explosion as Entity).OnUpdate += OnUpdate;
        }
Example #6
0
 public override void OnDetached(
     AbstractEntity entity
     )
 {
     powerup.OnUpdate -= OnUpdate;
     this.island.GetVector3Attribute(CommonNames.Position).ValueChanged -= OnIslandPositionChanged;
     if (entity.HasProperty("collision"))
     {
         entity.GetProperty <CollisionProperty>("collision").OnContact -= PowerupCollisionHandler;
     }
 }
Example #7
0
        internal PropertyBuilder(AbstractEntity entity, MemberInfo memberInfo, ConfigurationSource configurationSource)
        {
            var propertyName = memberInfo.GetSimpleMemberName();

            _property = entity.GetProperty(propertyName);

            if (_property == default)
            {
                _property = new Property(
                    propertyName,
                    memberInfo.GetMemberType(),
                    memberInfo as PropertyInfo,
                    configurationSource
                    );
                entity.AddProperty(_property);
            }
        }
        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);
        }
 public override void OnDetached(AbstractEntity entity)
 {
     entity.GetProperty <CollisionProperty>("collision").OnContact -= IceSpikeCollisionHandler;
     Game.Instance.Simulation.EntityManager.EntityRemoved          -= OnEntityRemoved;
     (entity as Entity).OnUpdate -= OnUpdate;
 }
Example #10
0
        private static void AnalyzeType(AbstractEntity entity)
        {
            foreach (var propertyInfo in entity.Type.GetProperties())
            {
                if (!propertyInfo.CanWrite || !propertyInfo.CanRead)
                {
                    continue;
                }

                var property = entity.GetProperty(propertyInfo.Name);
                if (property != default && property.IsIgnored)
                {
                    continue;
                }
                else if (property == default && ShouldIgnoreProperty(propertyInfo))
                {
                    property = new Property(propertyInfo.Name, propertyInfo.PropertyType, propertyInfo, Enums.ConfigurationSource.DataAnnotation);
                    property.Ignore();
                    entity.AddProperty(property);

                    continue;
                }

                if (property == default && ShouldBeReadOnlyProperty(propertyInfo))
                {
                    property = new Property(propertyInfo.Name, propertyInfo.PropertyType, propertyInfo, Enums.ConfigurationSource.DataAnnotation);
                    property.SetIsReadOnly();
                    entity.AddProperty(property);
                }

                var propertyType = propertyInfo.PropertyType.GetDataType();

                if (propertyType.IsNoClass())
                {
                    property = entity.GetProperty(propertyInfo.Name);
                    if (property == default)
                    {
                        property = new Property(propertyInfo.Name, propertyInfo.PropertyType, propertyInfo, Enums.ConfigurationSource.Convention);
                        entity.AddProperty(property);
                    }

                    if (!property.IsPrimaryKey && propertyInfo.IsPrímaryKey())
                    {
                        property.SetPrimiaryKey(true, Enums.ConfigurationSource.DataAnnotation);
                    }

                    if (property.AutoGeneratedOption == DatabaseGeneratedOption.None)
                    {
                        if (property.IsPrimaryKey)
                        {
                            property.SetAutoGeneratedOption(IsAutoGenerated(propertyInfo));
                        }
                        else
                        {
                            property.SetAutoGeneratedOption(propertyInfo.GetCustomAttribute <DatabaseGeneratedAttribute>()?.DatabaseGeneratedOption ?? DatabaseGeneratedOption.None);
                        }
                    }
                }
                else if (propertyType.IsClass() || Storm.Models.TypeHandlerMap.Map.ContainsKey(propertyType))
                {
                    property = entity.GetProperty(propertyInfo.Name);
                    if (property == default || !property.IsOwnsOne)
                    {
                        if (propertyInfo.IsOwnsOne())
                        {
                            if (property == default)
                            {
                                property = new Property(propertyInfo.Name, propertyInfo.PropertyType, propertyInfo, Enums.ConfigurationSource.DataAnnotation);
                                entity.AddProperty(property);
                            }

                            var ownsOneEntity = new OwnsOneEntity(propertyInfo.PropertyType, Enums.ConfigurationSource.DataAnnotation);
                            property.SetOwnsOneEntity(ownsOneEntity);
                            AnalyzeType(ownsOneEntity);
                        }
                    }
                    else if (property.IsOwnsOne && !property.OwnsOne.GetProperties().Any())
                    {
                        AnalyzeType(property.OwnsOne);
                    }

                    if (property == default || !property.IsOwnsOne)
                    {
                        propertyInfo.PropertyType.LookupDbType("", false, out var _);
                        if (Storm.Models.TypeHandlerMap.Map.ContainsKey(propertyInfo.PropertyType))
                        {
                            property = entity.GetProperty(propertyInfo.Name);
                            if (property == default)
                            {
                                property = new Property(propertyInfo.Name, propertyInfo.PropertyType, propertyInfo, Enums.ConfigurationSource.DataAnnotation);
                                entity.AddProperty(property);
                            }
                        }
                    }
                }

                if (property != default && property.ColumnName.IsNullOrEmpty())
                {
                    property.SetColumnName(propertyInfo.GetColumnName());
                }
            }
        }
Example #11
0
        public override void OnDetached(AbstractEntity explosion)
        {
            (explosion as Entity).OnUpdate -= OnUpdate;

            explosion.GetProperty <CollisionProperty>("collision").OnContact -= ExplosionCollisionHandler;
        }