Example #1
0
        /// <summary> Attack, interact or just swing </summary>
        public static RlEvent onSelectKeyPressed(Entity actor, RlGameContext ctx)
        {
            var body = actor.get <Body>();
            var dir  = body.facing;
            var es   = ctx.entitiesAt(body.pos + body.facing.vec).ToList(); // avoid null entity

            if (es.Count == 0)
            {
                // no entity found
                return(new RlEv.JustSwing(actor, dir));
            }
            // trying to find an attackable or interactable entity
            for (int i = 0; i < es.Count; i++)
            {
                var e = es[i];
                if (e.has <Interactable>())
                {
                    return(new RlEv.Interact(actor, dir));
                }
                else if (e.has <Performance>())
                {
                    return(new RlEv.MeleeAttack(actor, dir));
                }
            }
            return(new RlEv.JustSwing(actor, dir));
        }
Example #2
0
 public RlViewServices(ControlContext ctrlCtx, RlGameContext gameCtx, PosUtil posUtil)
 {
     this.gameCtx  = gameCtx;
     this.cradle   = ctrlCtx.cradle;
     this.posUtil  = posUtil;
     this.input    = ctrlCtx.input;
     this.viewUtil = new RlEventViewUtils(this.posUtil, this.input);
 }
Example #3
0
 public Vec2i randomPosInsideRoom(RlGameContext cx)
 {
     while (true)
     {
         var room = this.output.Rooms.RandomItem();
         int x    = Nez.Random.Range(room.Left + 1, room.Right - 1);
         int y    = Nez.Random.Range(room.Top + 1, room.Bottom - 1);
         if (cx.entitiesAt(new Vec2i(x, y)).Any(e => e.get <Body>()?.isBlocker ?? false))
         {
             continue;
         }
         return(new Vec2i(x, y));
     }
 }
Example #4
0
        /// <summary> Returns the only adjacent, interactive entity or null </summary>
        static Entity findOnlyNeighbor(Entity entity, RlGameContext cx)
        {
            var body = entity.get <Body>();
            var pos  = body.pos;

            var es = pos.neighbors
                     .Select(v => cx.entitiesAt(v))
                     // FIXME: detecting interactable/attackable entities
                     .filterT(e => e.has <Body>());

            if (es.FirstOrDefault() is Entity e1)
            {
                return(es.ElementAtOrDefault(1) == null ? e1 : null);
            }
            else
            {
                return(null);
            }
        }
Example #5
0
 public TickControl(RlGameState game, RlGameContext gameCtx, RlViewPlatform view)
 {
     this.game    = game;
     this.gameCtx = gameCtx;
     this.view    = view;
 }
Example #6
0
 public void replCtx(RlGameContext gameCtx, PosUtil posUtil)
 {
     this.services.replCtx(gameCtx, posUtil);
 }
Example #7
0
 public void replCtx(RlGameContext gameCtx, PosUtil posUtil)
 {
     this.gameCtx = gameCtx;
     this.posUtil = posUtil;
 }
Example #8
0
 public PlayerControl(RlGameContext gameCtx)
 {
     this.gameCtx = gameCtx;
     this.diaMode = new KeyMode(VKey.Dia);
     this.dirMode = new KeyMode(VKey.Dir);
 }