Beispiel #1
0
        public void doCollision(Entity ent)
        {
            if (ent.GetType() == typeof(FlyingEnemy) ||
                ent.GetType() == typeof(SpawnerEnemy) ||
                ent.GetType() == typeof(GuardEnemy))
            {

                    health -= 1.0f;
            }

            if (ent.GetType() == typeof(InfoPad))
            {
                String newPower = ((InfoPad)ent).power;

                if (!powers.isAvailable(newPower))
                {
                    powers.makeAvailable(newPower);
                    LogState.instance.catIntoLog("Discovered: " + newPower + "\n");
                    LogState.instance.catIntoAvailable(newPower);
                    LogState.instance.clearInput();
                    ent.health = 0;
                }
                else
                {
                    if (!justHit)
                    {
                        LogState.instance.catIntoLog("Already know " + newPower + "\n");
                        justHit = true;
                        ent.health = 0;
                    }
                }
            }
        }
Beispiel #2
0
        public Guid Create( Entity entity )
        {
            // TODO: can the ID be assigned manually? I can't remember
            Guid id = Guid.NewGuid();
            entity.Id = id;

            string name = entity.GetType().Name;
            if( data.ContainsKey( name ) == false ) {
                data.Add( name, new EntityCollection() );
            }

            if( name == "Entity" ) {
                Entity de = ( Entity )entity;
                // We set name here to support DynamicEntity
                name = de.LogicalName;
                de[name + "id"] = id;
            }
            else {
                entity.GetType().GetProperty( name + "id" ).SetValue( entity, id, null );
            }

            if( !data.ContainsKey( name ) ) {
                data[ name ] = new EntityCollection();
            }
            data[ name ].Entities.Add( entity );

            if( m_persist ) {
                PersistToDisk( m_filename );
            }

            return id;
        }
        protected internal void AddEntity(Entity e)
        {
            //Automatically detect proxy types assembly if an early bound type was used.
            if (ProxyTypesAssembly == null &&
                e.GetType().IsSubclassOf(typeof(Entity)))
            {
                ProxyTypesAssembly = Assembly.GetAssembly(e.GetType());
            }

            ValidateEntity(e); //Entity must have a logical name and an Id

            //Add the entity collection
            if (!Data.ContainsKey(e.LogicalName))
            {
                Data.Add(e.LogicalName, new Dictionary<Guid, Entity>());
            }

            if (Data[e.LogicalName].ContainsKey(e.Id))
            {
                Data[e.LogicalName][e.Id] = e;
            }
            else
            {
                Data[e.LogicalName].Add(e.Id, e);
            }

            //Update metadata for that entity
            if (!AttributeMetadata.ContainsKey(e.LogicalName))
                AttributeMetadata.Add(e.LogicalName, new Dictionary<string, string>());

            //Update attribute metadata
            if (ProxyTypesAssembly != null)
            {
                //If the context is using a proxy types assembly then we can just guess the metadata from the generated attributes
                var type = FindReflectedType(e.LogicalName);
                if (type != null)
                {
                    var props = type.GetProperties();
                    foreach (var p in props)
                    {
                        if (!AttributeMetadata[e.LogicalName].ContainsKey(p.Name))
                            AttributeMetadata[e.LogicalName].Add(p.Name, p.Name);
                    }
                }
                else
                    throw new Exception(string.Format("Couldnt find reflected type for {0}", e.LogicalName));

            }
            else
            {
                //If dynamic entities are being used, then the only way of guessing if a property exists is just by checking
                //if the entity has the attribute in the dictionary
                foreach (var attKey in e.Attributes.Keys)
                {
                    if (!AttributeMetadata[e.LogicalName].ContainsKey(attKey))
                        AttributeMetadata[e.LogicalName].Add(attKey, attKey);
                }
            }
        }
        internal static Entity GetRoundtripEntity(Entity entity)
        {
            Entity roundtripEntity = (Entity)Activator.CreateInstance(entity.GetType());
            IDictionary<string, object> roundtripState = ObjectStateUtility.ExtractRoundtripState(entity.GetType(), entity.OriginalValues);
            roundtripEntity.ApplyState(roundtripState);

            return roundtripEntity;
        }
Beispiel #5
0
        public string Format(Entity entity)
        {
            var key = entity.GetType();
            if (!htmlTags.ContainsKey(key))
                throw new Exception(string.Format("HtmlFormatter got unknown Entity: {0}", entity.GetType()));

            var strToFormat = htmlTags[key];
            var entityContent = entity.GetSubEntitiesFormat(this);
            return string.Format(strToFormat, entityContent);
        }
Beispiel #6
0
        public void Add(Entity entity)
        {
            if (entity.Self.Id == null)
                session.Save(entity);

            var existingObject = ((IList<CachedEntity>)Find(entity.GetType(), entity.Self.Id)).FirstOrDefault();
            if (existingObject == null)
            {
                entities.Add(new CachedEntity {Id = entity.Self.Id, Type = entity.GetType(), Value = entity});
            }
            else
            {
                existingObject.Value = entity;
            }
        }
        public bool Collider(Entity entity_a, Entity entity_b)
        {
            float entity_a_LH = entity_a.X - entity_a.Width/2; 	                //LH
            float entity_a_RH = entity_a.X + entity_a.Width/2;	//RH
            float entity_a_T = entity_a.Y - entity_a.Height/2;	                    //Top
            float entity_a_B = entity_a.Y +entity_a.Height/2;	//Btm

            //Let's get centre of entity_b for a little more realism/accuracy
            float entity_b_X = entity_b.X;// +(entity_b.Width * 0.5f);
            float entity_b_Y = entity_b.Y;// +(entity_b.Height * 0.5f);

            if (entity_b_X >= entity_a_LH && entity_b_X <= entity_a_RH && entity_b_Y <= entity_a_B && entity_b_Y >= entity_a_T)
            {
                //On enemy collission with tower increase capacity of tower - or this can be ran in main game loop
                if (entity_a.GetType() == typeof(Tower))
                {
                    //Temporary for testing - set object to inactive for list clean up - Pass responsibility to enemy directly
                    entity_b.Active = false;
                }
                return true;
            }
            else
            {
                return false;
            }
        }
Beispiel #8
0
        public override void OnBoxCollision(Entity collided, Rectangle intersect)
        {
            // Collides with another Hero
            if (collided.GetType() == typeof (Hero)) _tint = Color.Red;

            base.OnBoxCollision(collided, intersect);
        }
Beispiel #9
0
 public void ScoreKill(Entity entity)
 {
     if ((entity.GetType() == typeof(Alien)) && (entity.PlayerNumber != PlayerNumber))
     {
         Match.GetInstance().GetPlayer(PlayerNumber).Kills++;
     }
     else if ((entity.GetType() == typeof(Ship)) && (entity.PlayerNumber != PlayerNumber))
     {
         Match.GetInstance().GetPlayer(PlayerNumber).Kills++;
     }
     else if (((entity.GetType() == typeof(AlienFactory)) || (entity.GetType() == typeof(MissileController))) &&
              (entity.PlayerNumber != PlayerNumber))
     {
         Match.GetInstance().GetPlayer(PlayerNumber).Kills++;
     }
 }
Beispiel #10
0
        /// <summary>
        /// Generic collision detection function.
        /// Checks collisions between two Entities.
        /// </summary>
        /// <param name="a">the first Entity.</param>
        /// <param name="b">the second Entity.</param>
        /// <returns>True if the two Entities are colliding; false otherwise.</returns>
        public static bool CheckCollision(Entity a, Entity b)
        {
            if (b.GetType() == typeof(MysteryBox))
            {
                return CheckCollision(a, (MysteryBox)b);
            }
            else
            {
                if (a.myModel != null && b.myModel != null)
                {
                    for (int i = 0; i < a.myModel.Meshes.Count; i++)
                    {
                        BoundingSphere HeroSphere = a.myModel.Meshes[i].BoundingSphere;
                        HeroSphere.Center += a.getPOSITION();

                        for (int j = 0; j < b.myModel.Meshes.Count; j++)
                        {
                            BoundingSphere EnemySphere = b.myModel.Meshes[j].BoundingSphere;
                            EnemySphere.Center += b.getPOSITION();

                            if (HeroSphere.Intersects(EnemySphere))
                            {
                                //collision!
                                return true;
                            }
                        }
                    }
                }
                return false;
            }
        }
        /// <summary>
        /// 为指定的实体创建一个 DataContractSerializer。
        /// 此过程会通过引用属性、列表属性,递归搜索实体类中所涉及到的其它所有实体类型,
        /// 并传递给 DataContractSerializer 作为已知类型,否则,将无法序列化。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DataContractSerializer CreateSerializer(Entity entity)
        {
            var graph = new SerializationEntityGraph();
            graph.DeepSearch(entity);

            return new DataContractSerializer(entity.GetType(), graph._knownTypes);
        }
Beispiel #12
0
        public void addEntity(Entity type, Vector2 position, Game game)
        {
            Type t = type.GetType();

            if (t == typeof(InfoPad))
            {
                entities.Add(new InfoPad(position, ((InfoPad)type).power));
            }
            else if (t == typeof(FlyingEnemy))
            {
                entities.Add(new FlyingEnemy(position));
            }
            else if (t == typeof(SpawnerEnemy))
            {
                entities.Add(new SpawnerEnemy(position));
            }
            else if (t == typeof(GuardEnemy))
            {
                entities.Add(new GuardEnemy(position));
            }
            else
            { }

            entities.Last<Entity>().LoadContent(game);
        }
Beispiel #13
0
 public override bool OnCollision(Entity ent, byte collide)
 {
     if (ent.GetType() == typeof(TheGame.Models.Player.Player)) {
         TheGame.Models.Player.Player player = (TheGame.Models.Player.Player) ent;
         player.Finished = true;
     }
     return false;
 }
        internal static object GetId(Entity entity)
        {
            if (entity == null)
              {
            return null;
              }

              return entity.GetType().InvokeMember("Id", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public, null, entity, null, CultureInfo.InvariantCulture);
        }
 //Aka Kill (Sam)
 public void DieAHorribleDeath(Entity murderer = null)
 {
     game.entities_toremove.Add (this);
     if (murderer == null) { return; }
     string name = murderer.GetType ().FullName;
     if (name == "NoMoreClones.FriendlyBullet") {
         game.score += score_worth;
     }
 }
 public static Entity Collision(this IDrawableComponentProperties component, Entity entity)
 {
     foreach (Entity ent in Ressources.objectsList)
     {
         if (ent.GetType() == entity.GetType())
             if (ent.Area.Intersects(component.Area))
                 return ent;
     }
     return new Enemy(new Vector2(-50, -50));
 }
 private static IEnumerable<string> BuildResultSetRow(IEnumerable<string> columns, Entity result)
 {
     foreach (string field in columns)
     {
         var type = result.GetType();
         var property = type.GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
         object propertyValue = property.GetValue(result, null);
         yield return string.Format("{0}", propertyValue);
     }
 }
        static bool GetEntitiesToAlwaysDrawFilter(Entity e)
        {
            var t = e.GetType();

            // Skip the entities we will never draw (_neverDrawTypes)
            if (_neverDrawTypes.Any(x => t.IsSubclassOf(x) || t == x))
                return false;

            // Get the entities we will always draw (_alwaysDrawTypes)
            return _alwaysDrawTypes.Any(x => t.IsSubclassOf(x) || t == x);
        }
 public IEntityViewModel Retrieve(Entity e)
 {
     if (_cache.ContainsKey(e))
         return _cache[e];
     //e.g. Infinitum.Diagrams.Models.Entity => Infinitum.Diagrams.ViewModels.EntityViewModel
     var viewModelType =
         $"{e.GetType().FullName.Replace("Models", "ViewModels")}ViewModel";
     var viewModel = (IEntityViewModel) IoCService.Instance.Resolve(Type.GetType(viewModelType), e);
     Register(viewModel);
     return viewModel;
 }
		public void Initialize(GameView game, Entity entity)
		{
			this.game = game;
			this.Entity = entity;

			name = entity.GetType().Name;
			transform.localPosition = ToUnityVector3(entity.Position);

			entity.Moved += OnMoved;
			entity.Destroyed += OnDestroyed;
		}
Beispiel #21
0
        public virtual bool Equals(Entity obj)
        {
            if (obj == null) return false;

            if (IsTransient)
            {
                return ReferenceEquals(this, obj);
            }

            return obj.Id == Id && obj.GetType() == GetType();
        }
Beispiel #22
0
        public override void OnCollision(Entity e, SoundEngine soundEngine)
        {
            Type type = e.GetType();

            if (type == typeof(Enemy))
            {
                health--;
                bleeding = true;
                shaking = true;
                soundEngine.PlaySound("mario shrink");
            }
        }
Beispiel #23
0
        public static Packet AddPublicEntityInfo(this Packet packet, Entity entity)
        {
            switch (entity.DataType)
            {
                case DataType.Creature: packet.AddCreatureInfo(entity as Creature, CreaturePacketType.Public); break;
                case DataType.Item: packet.AddItemInfo(entity as Item, ItemPacketType.Public); break;
                case DataType.Prop: packet.AddPropInfo(entity as Prop); break;
                default:
                    throw new Exception("Unknown entity type '" + entity.GetType().ToString() + "', '" + entity.DataType + "'.");
            }

            return packet;
        }
        static bool GetEntitiesToDrawFilter(Entity e)
        {
            var t = e.GetType();

            // Skip the entities we will never draw (_neverDrawTypes)
            if (_neverDrawTypes.Any(x => t.IsSubclassOf(x) || t == x))
                return false;

            // Skip the entities we will always draw (_alwaysDrawTypes) since we will just add all of those later
            if (_alwaysDrawTypes.Any(x => t.IsSubclassOf(x) || t == x))
                return false;

            return true;
        }
Beispiel #25
0
        public static Entity GenerateTemplateCopy(Type copyType, Entity origEntity, Entity parent,
            List<KeyValuePair<Action<object>, object>> copyActions)
        {
            var copyEntity = Activator.CreateInstance(copyType) as Entity;
             var origProperties = new List<PropertyInfo>(origEntity.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance));

             origProperties.ForEach(origProperty => {
            try {

               var origValue = origProperty.GetValue(origEntity, null);
               var attrs = origProperty.GetCustomAttributes(typeof(ModelCopyAttribute), true).ToList();
               var copyAttr = attrs.IsNotEmpty()
                  ? attrs.First() as ModelCopyAttribute
                  : new ModelCopyAttribute { Method = CopyMethod.Copy };
               var copyProperty = copyEntity.GetType().GetProperty(origProperty.Name,
                                                               BindingFlags.Public | BindingFlags.Instance);
               if(origValue == null ||copyProperty == null) return;

               switch (copyAttr.Method) {
                  case CopyMethod.Copy:
                     CopyMethodCopy(copyEntity, copyProperty, origValue);
                     break;
                  case CopyMethod.Parent:
                     CopyMethodParent(copyEntity, copyProperty, parent);
                     break;
                  case CopyMethod.Generate:
                     CopyMethodGenerate(copyEntity, copyProperty, copyAttr);
                     break;
                  case CopyMethod.Template:
                     if (!origProperty.IsCollection() && !origProperty.ContainsType(typeof(IEntity))) return;
                     if (origProperty.IsCollection())
                        CopyMethodTemplateAsList(copyEntity, copyProperty, origValue as IEnumerable, copyActions);
                     else
                        CopyMethodTemplateAsEntity(copyEntity, copyProperty, origValue as Entity, copyActions);
                     break;
               }
            }
            catch (Exception e) {
               throw;
            }
             });
             if (copyActions == null) return copyEntity;

             copyActions.ForEach(action => {
            var method = copyEntity.GetType().GetMethod(action.Key.Method.Name);
            if (method == null) return;
            method.Invoke(copyEntity, new[] { action.Value });
             });
             return copyEntity;
        }
Beispiel #26
0
        public bool DuplicationChecking(Entity entity, string name)
        {
            var example = Activator.CreateInstance(entity.GetType()).As<TermStyle>();
            example.Name = name;
            var count = _termStyleRepository.Count(example);

            if (entity.IsNew())
                return 0 < count;
            else
            {
                if( entity.Name == name && 1 == count)
                    return false;
                return 0 < count;
            }
        }
Beispiel #27
0
        public EntityStruct(Entity e)
        {
            id         = e.Id;

            type        = e.GetType();

            position    = e.Position;
            velocity    = e.Velocity;

            crouching   = e.Crouching;
            alive       = e.Alive;
            angle       = e.Angle;

            fov         = e.FOV;
            radius      = e.Radius;
        }
Beispiel #28
0
        public virtual void Copy(Entity entity)
        {
            var type = entity.GetType();

            foreach (var property in type.GetProperties())
            {
                //don't copy property if:
                if (!property.CanWrite ||//it read only
                    property.PropertyType.IsSubclassOf(typeof(Entity)) ||//it Entity
                    property.GetCustomAttributes(typeof(ScriptIgnoreAttribute), true).Length > 0)//it has ScriptIgnore attribute
                {
                    continue;
                }

                property.SetValue(this, property.GetValue(entity, null), null);
            }
        }
 /// <summary>
 /// Adds the given entity into the list of entities, and adjusts the player location if a player object is added
 /// </summary>
 public void AddEntity(Entity.Entity e)
 {
     e.currentWorld = world;
     Console.WriteLine("Added Entity: " + e.GetType().FullName + " (#" + e.GetHashCode() + ")");
     if (e is Player) {
         if (playerLoc == -1) {
             playerLoc = 0;
             entities.Insert(0, e);
         } else {
             entities[playerLoc] = e;
         }
     } else {
         if (e is NPC)
             civilianCount++;
         // entities.Add(e);
         entitiesToAdd.Add(e);
     }
 }
        public virtual EntityCombatCommand GetAction(Entity issuer)
        {
            Console.WriteLine();
            Console.WriteLine(issuer.Name + ": " + issuer.GetType().Name);
            Console.WriteLine("1: Attack");
            Console.WriteLine("2: Cast Spell");
            Console.WriteLine("3: Consumables");
            Console.Write("Please enter a number matching your choice: ");
            int selection = GetIntInRange(1, 3);
            switch(selection)
            {
                case 1:
                    return new AttackCommand(issuer);

                case 2:
                    int i = 1;
                    foreach (var spell in issuer.SpellList)
                    {
                        Console.WriteLine(i++ + ": " + spell.Description);
                    }
                    Console.WriteLine("0: Go back to action selection.");
                    Console.Write("Please enter a number matching your choice: ");
                    int choice = GetIntInRange(0, i - 1);
                    if (choice == 0)
                        return GetAction(issuer);
                    return new CastSpellCommand(issuer, issuer.SpellList[choice - 1]);

                case 3:
                    i = 1;
                    foreach (var cons in issuer.Consumables)
                    {
                        Console.WriteLine(i++ + ": " + cons.Description);
                    }
                    Console.WriteLine("0: Go back to action selection.");
                    Console.Write("Please enter a number matching your choice: ");
                    choice = GetIntInRange(0, i - 1);
                    if (choice == 0)
                        return GetAction(issuer);
                    return new UseItemCombatCommand(issuer, issuer.Consumables[choice - 1]);

                default:
                    return new AttackCommand(issuer);
            }
        }