示例#1
0
        public void Use(Actor by, Coord target)
        {
            Direction fireDirection = Direction.GetDirection(by.Parent.Position, target);

            Coord spawnPos = by.Parent.Position + fireDirection;

            GameObject projectile = new UpdatingGameObject(spawnPos, Layers.Main, null, by.GameObject.Timeline);

            Characters[] alignChars = new[] {Characters.VERTICAL_LINE, Characters.SLASH, Characters.HYPHEN, Characters.BACK_SLASH, Characters.VERTICAL_LINE, Characters.SLASH, Characters.HYPHEN, Characters.BACK_SLASH};

            int dX = target.X - spawnPos.X;
            int dY = target.Y - spawnPos.Y;

            int dist = (int) Distance.MANHATTAN.Calculate(dX, dY);
            int speed = 30;

            int xVel = dX == 0 ? 0 : speed * dist / dX;
            int yVel = dY == 0 ? 0 : speed * dist / dY;


            Damagable damagable = new Damagable(1);
            projectile.AddComponent(damagable);
            projectile.AddComponent(new GlyphComponent(new Glyph(alignChars[(int) fireDirection.Type], Color.SaddleBrown))); 
            projectile.AddComponent(new NameComponent(new Title("an", "arrow")));

            ProjectileComponent projectileComponent = new ProjectileComponent(xVel, yVel, damagable);

            projectileComponent.OnCollide += (gameObject) =>
            {
                EffectTarget effectTarget = gameObject?.GetComponent<EffectTargetComponent>()?.EffectTarget;

                effectTarget?.ApplyEffect(new DamageEffect(_damage));

                by.MainBus.Send(new ParticleEvent(new GlyphFlash(new Glyph(Characters.ASTERISK, Color.Red), 200,
                    gameObject.Position)));

                
                if(gameObject.GetComponent<NameComponent>() is NameComponent nameComponent)
                    by.MainBus.Send(new LogMessage($"{{0}} was hit by {{1}}'s arrow", new LogLink(nameComponent.Title.ToString(), Color.Aquamarine, by), new LogLink(by.Being.Name, Color.Aquamarine, by)));
            };


            projectile.AddComponent(projectileComponent);

            by.MainBus.Send(new SpawnEvent(projectile));
        }
示例#2
0
        public void Use(Actor by, Coord target)
        {
            IGameObject gameObject = by.Parent.CurrentMap.GetObject(target);

            EffectTarget effectTarget = gameObject?.GetComponent <EffectTargetComponent>()?.EffectTarget;

            effectTarget?.ApplyEffect(new DamageEffect(_damage));
            by.Parent.GetComponent <EffectTargetComponent>()?.EffectTarget.ApplyEffect(new StaminaEffect(-_stamina));

            if (effectTarget != null)
            {
                by.MainBus.Send(new ParticleEvent(new GlyphFlash(new Glyph(Characters.SLASH, Color.Red), 200,
                                                                 target)));

                by.MainBus.Send(new LogMessage($"{{0}} attacked with their {Title.Name}", new LogLink(by.Being.Name, Color.Aquamarine, by)));
            }
            else
            {
                by.MainBus.Send(new ParticleEvent(new GlyphFlash(new Glyph(Characters.FULL_BLOCK, Color.FromArgb(100, Color.Gray)), 200,
                                                                 target)));
                by.MainBus.Send(new LogMessage($"{{0}} missed with their {Title.Name}", new LogLink(by.Being.Name, Color.Aquamarine, by)));
            }
        }