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