Exemplo n.º 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));
        }
Exemplo n.º 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);
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 5
0
 public TickControl(RlGameState game, RlGameContext gameCtx, RlViewPlatform view)
 {
     this.game    = game;
     this.gameCtx = gameCtx;
     this.view    = view;
 }
Exemplo n.º 6
0
 public void replCtx(RlGameContext gameCtx, PosUtil posUtil)
 {
     this.services.replCtx(gameCtx, posUtil);
 }
Exemplo n.º 7
0
 public void replCtx(RlGameContext gameCtx, PosUtil posUtil)
 {
     this.gameCtx = gameCtx;
     this.posUtil = posUtil;
 }
Exemplo n.º 8
0
 public PlayerControl(RlGameContext gameCtx)
 {
     this.gameCtx = gameCtx;
     this.diaMode = new KeyMode(VKey.Dia);
     this.dirMode = new KeyMode(VKey.Dir);
 }