Esempio n. 1
0
        /// <summary>
        /// Adds an Entity to be part of the engine and the world
        /// </summary>
        /// <param name="xmasEntity">The entity added to world</param>
        /// <param name="info">Information regarding where and how to add the entity</param>
        /// <returns>whether or not the adding of the entity was successful</returns>
        public bool AddEntity(XmasEntity xmasEntity, EntitySpawnInformation info)
        {
            xmasEntity.Load();
            if (xmasEntity is Agent)
            {
                Agent agent = xmasEntity as Agent;
                Agent otheragent;
                if(string.IsNullOrEmpty(agent.Name))
                    throw new AgentHasNoNameException(agent);
                else if (agentLookup.TryGetValue(agent.Name, out otheragent))
                {
                    throw new AgentAlreadyExistsException(agent, otheragent);
                }
                else
                {
                    agentLookup.Add(agent.Name,agent);
                }
            }

            bool entityadded = OnAddEntity(xmasEntity, info);
            if (entityadded)
            {

                xmasEntity.Id = nextId;
                this.entityLookup.Add(xmasEntity.Id,xmasEntity);
                nextId++;

                EventManager.Raise(new EntityAddedEvent(xmasEntity,info.Position));

                this.evtman.AddEntity(xmasEntity);
                xmasEntity.OnEnterWorld();
            }

            return entityadded;
        }
Esempio n. 2
0
 /// <summary>
 /// Override this method to intercept when a entity is added
 /// </summary>
 /// <param name="xmasEntity">The entity to be added</param>
 /// <param name="info">information of the entity</param>
 /// <returns>Whether the entity could be added</returns>
 protected abstract bool OnAddEntity(XmasEntity xmasEntity, EntitySpawnInformation info);
Esempio n. 3
0
 /// <summary>
 /// Stores information on how an entity should be added when the world is being built
 /// </summary>
 /// <param name="ent">The entity constructor for the entity to be added</param>
 /// <param name="info">Information on how to add the entity</param>
 public void AddEntity(Func<XmasEntity> ent, EntitySpawnInformation info)
 {
     buildactions.Add(() => new AddEntityAction(ent(), info));
 }
Esempio n. 4
0
 public AddEntityAction(XmasEntity ent, EntitySpawnInformation info)
 {
     this.ent = ent;
     this.info = info;
 }
Esempio n. 5
0
 /// <summary>
 /// Stores information on how an entity should be added when the world is being built
 /// </summary>
 /// <param name="ent">The entity to be added</param>
 /// <param name="info">Information on how to add the entity</param>
 public void AddEntity(XmasEntity ent, EntitySpawnInformation info)
 {
     buildactions.Add(new AddEntityAction(ent, info));
 }
Esempio n. 6
0
        //Override this to provide a way to insert the agent
        protected override bool OnAddEntity(XmasEntity xmasEntity, EntitySpawnInformation info)
        {
            var spawn = (VacuumSpawnInformation)info;
            var spawnloc = (VacuumPosition)spawn.Position;

            if (xmasEntity is VacuumCleanerAgent)
            {
                vacuumTiles[spawnloc.PosID] = xmasEntity as VacuumCleanerAgent;
                return true;
            }
            else if (xmasEntity is DirtEntity)
            {
                dirtTiles[spawnloc.PosID] = xmasEntity as DirtEntity;
                return true;
            }

            return false;
        }
Esempio n. 7
0
 protected override bool OnAddEntity(XmasEntity xmasEntity, EntitySpawnInformation info)
 {
     TilePosition tilePos = (TilePosition) info.Position;
     return AddEntity(xmasEntity, tilePos);
 }