当前位置: 首页>>代码示例>>C#>>正文


C# Entity.Has方法代码示例

本文整理汇总了C#中System.Entity.Has方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.Has方法的具体用法?C# Entity.Has怎么用?C# Entity.Has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Entity的用法示例。


在下文中一共展示了Entity.Has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add

 public void Add(Entity e)
 {
     if (e.Has<ImageComponent>())
     {
         var i = e.Get<ImageComponent>();
         this.images.Add(i);
     }
     else if (e.Has<SpriteSheetComponent>())
     {
         var i = e.Get<SpriteSheetComponent>();
         this.images.Add(i);
     }
 }
开发者ID:deengames,项目名称:nucleus-monogame,代码行数:13,代码来源:Screen.cs

示例2: OnInteract

        internal void OnInteract(Entity entity, MessageSession session, InteractMsg msg)
        {
            if (entity.Has<Fightable>())
            {
                var template = DataCenter.Instance.GetDatum<InteractTemplate>(msg.InteractId);
                if (template == null)
                {
                    Logger.Write("Request a invalid interact[{0}]", msg.InteractId);
                    return;
                }

                EffectSystem.Affect(entity, template);
            }
            else
            {
                PositionSystem.Global.Interact(entity, targets =>
                    {
                        // default interaction - remove removables
                        foreach (var target in targets.Where(target => target.Has<Removable>() && target.Get<Removable>().Action))
                        {
                            // despawn target
                            PositionSystem.Global.Disappear(target);
                            EntityBinder.Instance.Remove(target);
                            EntityManager.Instance.Remove(target.Id);
                        }
                    });
            }
        }
开发者ID:ktj007,项目名称:mmo,代码行数:28,代码来源:Interaction.cs

示例3: TryPoison

 public void TryPoison(Entity attacker, Entity defender)
 {
     if (attacker.Has<Poison> ()) {
         if (defender.Has<Health> ()) {
             float poisonChanceMult = defender.Has<PoisonChanceMultiplier> () ? defender.Get<PoisonChanceMultiplier> ().Multiplier : 1;
             if (Utils.DropChance ((int)(attacker.Get<Poison> ().Chance * poisonChanceMult))) {
                 if (defender.Has<Execute> ()) {
                     var poisonLoop = new Loop (new DoPoisonEntity (defender, attacker.Get<Poison> ().Damage, m_onPoisoned),
                                             attacker.Get<Poison> ().Speed);
                     defender.Get<Execute> ().AddNew (poisonLoop, "poison_effect");
                     IsPoisoned = true;
                 }
             }
         }
     }
 }
开发者ID:rustamserg,项目名称:mogate,代码行数:16,代码来源:Poisonable.cs

示例4: IsFoe

 public bool IsFoe(Entity target)
 {
     if (target.Has<IFFSystem> ()) {
         return ID != target.Get<IFFSystem> ().ID;
     }
     return false;
 }
开发者ID:rustamserg,项目名称:mogate,代码行数:7,代码来源:IFFSystem.cs

示例5: testEntityHas

 public void testEntityHas()
 {
     Entity entity = new Entity();
     Id id = new Id();
     id.Value = 1;
     entity.Add(id);
     Assert.AreEqual(entity.Has<Id>(), true);
 }
开发者ID:copperbyte,项目名称:Ash,代码行数:8,代码来源:AshTests.cs

示例6: ChangeMe

        internal bool ChangeMe(Entity admin,
                               [CommandArgument("새로운 Resource Id")] int newResourceId)
        {
            if (!admin.Has<Displayable>())
                return false;

            ChangeResourceAndBroadcast(admin, newResourceId);
            return true;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:9,代码来源:EnterLeave.cs

示例7: SetPos

        internal bool SetPos(Entity admin,
                             [CommandArgument("새로운 X 위치", 0)] double newX,
                             [CommandArgument("새로운 Y 위치", 0)] double newY)
        {
            if (!admin.Has<Pos>())
                return false;

            var msg = new UpdatePositionMsg {X = newX, Y = newY, InstanceMove = true};
            admin.Assign(msg);

            PositionSystem.Global.Move(admin);
            return true;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:13,代码来源:Movement.cs

示例8: Attack

        public void Attack(Entity attacker, Entity defender)
        {
            if (attacker.Has<Attack> ()) {
                if (defender.Has<Health> ()) {
                    int basedmg = attacker.Get<Attack> ().Damage;
                    int criticaldmg = 0;
                    if (attacker.Has<CriticalHit> ()) {
                        if (Utils.DropChance (attacker.Get<CriticalHit> ().HitChance)) {
                            criticaldmg = attacker.Get<CriticalHit> ().CriticalDamage;
                        }
                    }
                    float attackMult = attacker.Has<AttackMultiplier> () ? attacker.Get<AttackMultiplier> ().Multiplier : 1;
                    int defence = defender.Has<Armor> () ? defender.Get<Armor> ().Defence : 0;
                    basedmg = (int)(basedmg * attackMult);
                    criticaldmg = (int)(criticaldmg * attackMult);
                    int damage = Math.Max(0, basedmg + criticaldmg - defence);

                    if (m_onAttack != null)
                        m_onAttack (attacker, damage, criticaldmg);

                    defender.Get<Health> ().HP = Math.Max (0, defender.Get<Health> ().HP - damage);
                }
            }
        }
开发者ID:rustamserg,项目名称:mogate,代码行数:24,代码来源:Attackable.cs

示例9: SpawnNpc

        internal bool SpawnNpc(Entity admin,
                               [CommandArgument("Npc의 이름")] string npcName,
                               [CommandArgument("Npc의 X 위치", 0)] double newX,
                               [CommandArgument("Npc의 Y 위치", 0)] double newY)
        {
            if (!admin.Has<Pos>())
                return false;

            var npc = EntityManager.Instance.Create(EntityTemplate.Ids.Npc);
            npc.Get<Motion>().Dir = admin.Get<Motion>().Dir;
            npc.Get<Nameplate>().Name = npcName;
            npc.Get<Pos>().Assign(new Pos {X = newX, Y = newY});

            PositionSystem.Global.Appear(npc);
            EntityBinder.Instance.Add(npc);
            return true;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:17,代码来源:EnterLeave.cs

示例10: SpawnEntity

        internal bool SpawnEntity(Entity admin,
                                  [CommandArgument("생성할 Entity의 TemplateId")] int templateId)
        {
            var entityTemplate = DataCenter.Instance.GetEntityTemplate(templateId);
            if (entityTemplate == null)
                return false;

            var entity = EntityManager.Instance.Create(DataCenter.Instance.GetCreateInfo(entityTemplate));
            if (entity.Has<Pos>() && admin.Has<Pos>())
            {
                entity.Get<Pos>().Assign(admin.Get<Pos>());
                PositionSystem.Global.Appear(entity);
            }

            EntityBinder.Instance.Add(entity);
            return true;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:17,代码来源:EnterLeave.cs

示例11: OnResetPeer

        internal void OnResetPeer(Entity entity, MessageSession session, ResetPeerMessage msg)
        {
            PositionSystem.Global.Disappear(entity);

            if (entity.Has<Player>())
                entity.Get<Player>().Logged = false;

            if (entity.Has<Tickable>())
                entity.Detach<Tickable>();

            EntityBinder.Instance.Update(entity);

            if (entity.Has<Nameplate>())
                Logger.Write("{0} is logout.", entity.Get<Nameplate>().Name);
        }
开发者ID:ktj007,项目名称:mmo,代码行数:15,代码来源:EnterLeave.cs

示例12: OnArmorTriggered

        void OnArmorTriggered(Entity item, Entity attacker)
        {
            var gameState = (IGameState)Game.Services.GetService (typeof(IGameState));
            var hud = (HUDLayer)Scene.GetLayer ("hud");

            if (attacker.Has<Consumable<ConsumableTypes>> ()) {
                int cost = item.Get<Price> ().Cost;
                int armorId = item.Get<Loot> ().Drop;

                if (attacker.Has<Armor> () && attacker.Get<Armor> ().ArchetypeID >= armorId) {
                    hud.FeedbackMessage ("Already weared", Color.Red);
                } else {
                    if (attacker.Get<Consumable<ConsumableTypes>> ().TryConsume (ConsumableTypes.Money, cost)) {
                        if (!attacker.Has<Armor> ()) {
                            attacker.Register (new Armor (Archetypes.Armors [armorId] ["defence"], armorId));
                        } else {
                            attacker.Get<Armor> ().ArchetypeID = armorId;
                            attacker.Get<Armor> ().Defence = Archetypes.Armors [armorId] ["defence"];
                        }
                        gameState.PlayerArmorID = armorId;
                        RemoveEntityByTag (item.Tag);
                        hud.FeedbackMessage ("Picked up new armor", Color.Yellow);
                    } else {
                        string feedbackMsg = string.Format ("Need {0} money", cost);
                        hud.FeedbackMessage (feedbackMsg, Color.Red);
                    }
                }
            }
        }
开发者ID:rustamserg,项目名称:mogate,代码行数:29,代码来源:ItemsLayer.cs

示例13: OnHealthTriggered

        void OnHealthTriggered(Entity item, Entity from)
        {
            var hud = (HUDLayer)Scene.GetLayer ("hud");

            if (from.Has<Health> ()) {
                if (from.Get<Health> ().HP < from.Get<Health> ().MaxHP) {
                    from.Get<Health> ().HP = from.Get<Health> ().HP + item.Get<Loot>().Drop;
                    RemoveEntityByTag (item.Tag);
                    hud.FeedbackMessage ("Picked up health potion", Color.Yellow);
                }
            }
        }
开发者ID:rustamserg,项目名称:mogate,代码行数:12,代码来源:ItemsLayer.cs

示例14: OnMoneyTriggered

        void OnMoneyTriggered(Entity item, Entity attacker)
        {
            var hud = (HUDLayer)Scene.GetLayer ("hud");

            if (attacker.Has<Consumable<ConsumableTypes>> ()) {
                int droppedMoney = item.Get<Loot>().Drop;
                float moneyMult = attacker.Get<MoneyMultiplier> ().Multiplier;
                droppedMoney = (int)(droppedMoney * moneyMult);
                attacker.Get<Consumable<ConsumableTypes>> ().Refill (ConsumableTypes.Money, droppedMoney);
                RemoveEntityByTag (item.Tag);

                string feedbackMsg = string.Format ("Picked {0} money", droppedMoney);
                hud.FeedbackMessage (feedbackMsg, Color.Yellow);
            }
        }
开发者ID:rustamserg,项目名称:mogate,代码行数:15,代码来源:ItemsLayer.cs

示例15: TryFindEnemyOnRoute

        void TryFindEnemyOnRoute(Entity monster, IEnumerable<Entity> targets)
        {
            if (!monster.Has<IFFSystem> ())
                return;

            foreach (var enemy in monster.Get<IFFSystem> ().GetFoes (targets)) {
                var enemyPos = enemy.Get<Position> ().MapPos;
                var monsterPos = monster.Get<Position> ().MapPos;

                var distToEnemy = Utils.DirectionDist (monsterPos, enemyPos, monster.Get<LookDirection> ().Direction);
                if (distToEnemy < monster.Get<Perception> ().AlertDistance) {
                    monster.Get<Patrol> ().Steps += monster.Get<Perception> ().AlertDistance - distToEnemy + 1;
                    if (monster.Has<DirectLight> ()) {
                        monster.Get<DirectLight> ().LightColor = Color.Red;
                    }
                    break;
                } else {
                    if (monster.Has<DirectLight> ()) {
                        monster.Get<DirectLight> ().LightColor = Color.White;
                    }
                }
            }
        }
开发者ID:rustamserg,项目名称:mogate,代码行数:23,代码来源:MonstersLayer.cs


注:本文中的System.Entity.Has方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。