コード例 #1
0
ファイル: MapInstance.cs プロジェクト: Urthawen/codebreak
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        public void SpawnEntity(AbstractEntity entity)
        {
            AddMessage(() =>
            {
                if (!m_entityById.ContainsKey(entity.Id))
                {
                    m_entityById.Add(entity.Id, entity);

                    if (m_subInstance) // For npc etc
                    {
                        entity.SetMap(this);
                    }

                    Dispatch(WorldMessage.GAME_MAP_INFORMATIONS(OperatorEnum.OPERATOR_ADD, entity));
                    AddUpdatable(entity);

                    if (entity.Type == EntityTypeEnum.TYPE_CHARACTER)
                    {
                        InitializeOnFirstPlayerEnter();

                        m_playerCount++;
                        m_entityByName.Add(entity.Name.ToLower(), entity);

                        AddHandler(entity.Dispatch);
                        SendAllInformations(entity);
                    }
                }
                else
                {
                    Logger.Error("MapInstance::SpawnEntity : an entity with the same id alrezdy exists : " + entity.Name);

                    WorldService.Instance.AddUpdatable(entity);
                }
            });
        }