예제 #1
0
        protected override void OnUpdate()
        {
            LogSystem            log = EntityManager.World.GetExistingSystem <LogSystem>();
            GameStateSystem      gss = EntityManager.World.GetExistingSystem <GameStateSystem>();
            TurnManagementSystem tms = EntityManager.World.GetExistingSystem <TurnManagementSystem>();
            View view = gss.View;

            Entity[] healingItems = new Entity[view.Width * view.Height];
            Entities.WithAll <HealItem>().ForEach((Entity e, ref WorldCoord coord) =>
            {
                int i           = View.XYToIndex(new int2(coord.x, coord.y), view.Width);
                healingItems[i] = e;
            });

            Entities.WithAll <Player>().ForEach((Entity e, ref WorldCoord coord, ref HealthPoints hp) =>
            {
                int i = View.XYToIndex(new int2(coord.x, coord.y), view.Width);
                if (EntityManager.HasComponent(healingItems[i], typeof(HealItem)))
                {
                    HealItem heal = EntityManager.GetComponentData <HealItem>(healingItems[i]);

                    if (hp.now + heal.HealAmount > hp.max)
                    {
                        heal.HealAmount = (hp.max - hp.now);
                    }

                    hp.now += heal.HealAmount;

                    if (heal.HealAmount > 0)
                    {
                        log.AddLog($"Healed for {heal.HealAmount.ToString()} points.");
                    }
                    else if (heal.HealAmount == 0)
                    {
                        log.AddLog("Healed for 0 points.  ...that's disappointing.");
                    }
                    else if (heal.HealAmount < 0)
                    {
                        string dmgLog = $"The Kobolds have poisoned the potion!!  {(-1 * heal.HealAmount).ToString()} damage taken!";
                        log.AddLog(dmgLog);
                        gss.LastPlayerHurtLog = dmgLog;
                    }
                    PostUpdateCommands.DestroyEntity(healingItems[i]);
                }
            });
        }
예제 #2
0
        public Entity CreateHealingItem(EntityCommandBuffer ecb, int2 xy, float3 pos, int healAmount)
        {
            Entity entity = ecb.CreateEntity(HealingPotion);

            HealItem         heal = new HealItem();
            Sprite2DRenderer s    = new Sprite2DRenderer();
            Translation      t    = new Translation();
            WorldCoord       c    = new WorldCoord();
            LayerSorting     l    = new LayerSorting();

            t.Value = pos;

            c.x = xy.x;
            c.y = xy.y;

            // Only tint sprites if ascii
            s.color = GlobalGraphicsSettings.ascii
                ? new Unity.Tiny.Core2D.Color(1.0f, 0.26f, 0.23f)
                : Color.Default;
            if (GlobalGraphicsSettings.ascii)
            {
                s.color.a = 0;
            }

            s.sprite = SpriteSystem.IndexSprites[SpriteSystem.ConvertToGraphics((char)235)];
            l.layer  = 1;

            heal.HealAmount = healAmount;

            ecb.SetComponent(entity, s);
            ecb.SetComponent(entity, t);
            ecb.SetComponent(entity, c);
            ecb.SetComponent(entity, l);
            ecb.SetComponent(entity, heal);

            return(entity);
        }