当前位置: 首页>>代码示例>>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;未经允许,请勿转载。