當前位置: 首頁>>代碼示例>>C#>>正文


C# Entity.Init方法代碼示例

本文整理匯總了C#中wServer.realm.Entity.Init方法的典型用法代碼示例。如果您正苦於以下問題:C# Entity.Init方法的具體用法?C# Entity.Init怎麽用?C# Entity.Init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wServer.realm.Entity的用法示例。


在下文中一共展示了Entity.Init方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EnterWorld

        public virtual int EnterWorld(Entity entity)
        {
            if (entity is Player)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                Players.TryAdd(entity.Id, entity as Player);
                PlayersCollision.Insert(entity);
                SpawnEntity(entity);
                if (entity.Owner.PvP)
                {
                    (entity as Player).PvP = true;
                    (entity as Player).SendHelp("You have entered a PvP world!");
                }
                else
                    (entity as Player).PvP = false;
            }
            else if (entity is Enemy)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                Enemies.TryAdd(entity.Id, entity as Enemy);
                EnemiesCollision.Insert(entity);
                if (entity.ObjectDesc.Quest)
                    Quests.TryAdd(entity.Id, entity as Enemy);

                if (entity.isPet)
                {
                    Pets.TryAdd(entity.Id, entity);
                }
            }
            else if (entity is Projectile)
            {
                entity.Init(this);
                var prj = entity as Projectile;
                Projectiles[new Tuple<int, byte>(prj.ProjectileOwner.Self.Id, prj.ProjectileId)] = prj;
            }
            else if (entity is StaticObject)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                StaticObjects.TryAdd(entity.Id, entity as StaticObject);
                if (entity is Decoy)
                    PlayersCollision.Insert(entity);
                else
                    EnemiesCollision.Insert(entity);
            }
            return entity.Id;
        }
開發者ID:Club559,項目名稱:Travs-Domain-Server,代碼行數:49,代碼來源:World.cs

示例2: EnterWorld

        public virtual int EnterWorld(Entity entity)
        {
            if (entity is Player)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                Players.TryAdd(entity.Id, entity as Player);
                PlayersCollision.Insert(entity);
            }
            else if (entity is NPC)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                Enemies.TryAdd(entity.Id, entity as Enemy);
                NPCs.TryAdd(entity.Id, entity as NPC);
                if (entity.ObjectDesc.Enemy)
                    EnemiesCollision.Insert(entity);
                else
                    PlayersCollision.Insert(entity);
            }
            else if (entity is Enemy)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                Enemies.TryAdd(entity.Id, entity as Enemy);
                EnemiesCollision.Insert(entity);
                if (entity.ObjectDesc.Quest)
                    Quests.TryAdd(entity.Id, entity as Enemy);

                if(entity.isPet)
                {
                    Pets.TryAdd(entity.Id, entity);
                }
            }
            else if (entity is Projectile)
            {
                entity.Init(this);
                Projectile prj = entity as Projectile;
                Projectiles[new Tuple<int, byte>(prj.ProjectileOwner.Self.Id, prj.ProjectileId)] = prj;
                ProjectilesCollision.Insert(entity);
            }
            else if (entity is StaticObject)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                StaticObjects.TryAdd(entity.Id, entity as StaticObject);
                if (entity is Decoy)
                    PlayersCollision.Insert(entity);
                else
                    EnemiesCollision.Insert(entity);
            }
            return entity.Id;
        }
開發者ID:Club559,項目名稱:RotMGNPCs,代碼行數:53,代碼來源:World.cs

示例3: EnterWorld

        //public void FromJsonMap(string file)
        //{
        //    if (File.Exists(file))
        //    {
        //        var wmap = Json2Wmap.Convert(File.ReadAllText(file));
        //        FromWorldMap(new MemoryStream(wmap));
        //    }
        //    else
        //    {
        //        throw new FileNotFoundException("Json file not found!", file);
        //    }
        //}
        //public void FromJsonStream(Stream dat)
        //{
        //    byte[] data = { };
        //    dat.Read(data, 0, (int)dat.Length);
        //    var json = Encoding.ASCII.GetString(data);
        //    var wmap = Json2Wmap.Convert(json);
        //    FromWorldMap(new MemoryStream(wmap));
        //} //not working
        public virtual int EnterWorld(Entity entity)
        {
            var player = entity as Player;
            if (player != null)
            {
                try
                {
                    player.Id = GetNextEntityId();
                    entity.Init(this);
                    Players.TryAdd(player.Id, player);
                    PlayersCollision.Insert(player);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
            else
            {
                var enemy = entity as Enemy;
                if (enemy != null)
                {
                    enemy.Id = GetNextEntityId();
                    entity.Init(this);
                    Enemies.TryAdd(enemy.Id, enemy);
                    EnemiesCollision.Insert(enemy);
                    if (enemy.ObjectDesc.Quest)
                        Quests.TryAdd(enemy.Id, enemy);
                }
                else
                {
                    var projectile = entity as Projectile;
                    if (projectile != null)
                    {
                        projectile.Init(this);
                        var prj = projectile;
                        Projectiles[new Tuple<int, byte>(prj.ProjectileOwner.Self.Id, prj.ProjectileId)] = prj;
                    }
                    else
                    {
                        var staticObject = entity as StaticObject;
                        if (staticObject != null)
                        {
                            staticObject.Id = GetNextEntityId();
                            staticObject.Init(this);
                            StaticObjects.TryAdd(staticObject.Id, staticObject);
                            if (entity is Decoy)
                                PlayersCollision.Insert(staticObject);
                            else
                                EnemiesCollision.Insert(staticObject);
                        }
                        else
                        {
                            var pet = entity as Pet;
                            if (pet == null) return entity.Id;
                            if (pet.IsPet)
                            {
                                pet.Id = GetNextEntityId();
                                pet.Init(this);
                                if (!Pets.TryAdd(pet.Id, pet))
                                    Log.Error("Failed to add pet!");

                                PlayersCollision.Insert(pet);
                            }
                            else
                                Log.WarnFormat("This is not a real pet! {0}", pet.Name);
                        }
                    }
                }
            }
            return entity.Id;
        }
開發者ID:SirAnuse,項目名稱:fabiano-swagger-of-doom,代碼行數:92,代碼來源:World.cs


注:本文中的wServer.realm.Entity.Init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。