コード例 #1
0
        public void PopulateNPCSpawns(Level level, List <IEntity> entityList)
        {
            if (level.npcSpawnLocationList == null)
            {
                Logger.Log(name, "Empty NPC spawn location list");
                return;
            }

            for (int i = 0; i < level.npcSpawnLocationList.Count; i++)
            {
                Logger.Log(name, "Attempting to spawn ", level.npcSpawnLocationList[i].name);
                IEntity npc = entityManager.GetPooledNPC(level.npcSpawnLocationList[i].name);

                if (npc == null)
                {
                    Logger.LogError(name, "Unable to find pooled NPC", level.npcSpawnLocationList[i].name);
                    continue;
                }

                //npc.Initialize(true, this.playerController.transform);
                npc.SetPosition(level.ConvertLevelPosToWorld(level.npcSpawnLocationList[i].levelLocation) + level.npcSpawnLocationList[i].worldOffset);
                npc.Activate();

                entityList.Add(npc);
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates the provided entity.
        /// </summary>
        /// <param name="entity">The entity to update.</param>
        /// <returns>A value indicating whether the entity was valid and was therefore saved.</returns>
        public virtual bool Update(IEntity entity)
        {
            bool didSucceed = false;

            using (LogGroup logGrop = LogGroup.Start("Updating the provided entity.", NLog.LogLevel.Debug))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                LogWriter.Debug("Type: " + entity.ShortTypeName);

                if (RequireAuthorisation)
                {
                    AuthoriseUpdateStrategy.New(entity.ShortTypeName).EnsureAuthorised(entity);
                }

                CheckStrategies(entity);

                // Ensure that the entity is activated
                if (!entity.IsActivated)
                {
                    if (entity.AutoActivate)
                    {
                        entity.Activate();
                    }
                    else
                    {
                        throw new InactiveEntityException(entity);
                    }
                }

                if (entity.IsValid)
                {
                    DataAccess.Data.Updater.Update(entity);
                    didSucceed = true;

                    // [Important] Trigger the reactions
                    React(entity);
                }
                else
                {
                    didSucceed = false;
                }

                LogWriter.Debug("Did succeed: " + didSucceed);
            }
            return(didSucceed);
        }
コード例 #3
0
        /// <summary>
        /// Assigns the provided entity to the DataSource property.
        /// </summary>
        /// <param name="entity">The entity to assign to the DataSource</param>
        /// <returns>The assigned entity.</returns>
        public IEntity Load(IEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Loading the provided entity onto DataSource and activating it.", NLog.LogLevel.Debug))
            {
                if (entity == null)
                {
                    Navigator.Current.Go(ActionOnSuccess, Command.TypeName);
                }
                else
                {
                    entity.Activate();

                    DataSource = entity;
                }
            }
            return(entity);
        }