using System; using System.Linq; using GladiatorIdle.Gfx; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using D = GladiatorIdle.Gfx.Draw; namespace GladiatorIdle.Arena { /// Expeditionen (Schublade: Regionen, Dauer, Aufbruch; unterwegs: Fortschritt statt Gegnerwahl), /// Rückkehr-Bericht und Ereignis-Karten mit Entscheidungen (beides als Fenster über dem Hub), /// dazu die laufenden Segen unter der Kopfleiste. internal sealed partial class HubScene { string _expRegion = "gallia"; int _expDuration; string? _eventShown; // Ereignis, dessen Karte offen ist string? _eventOutcome; // Text-Key des Ausgangs, nach der Entscheidung string? _eventSeen; // für den Klang beim Erscheinen static string DurationLabel(int i) => NumberFormat.Duration(Adventures.Durations[i]); static int LootCount(int duration) => 1 + 2 * duration; static Color ChanceColor(double c) => c >= 0.75 ? D.Green : c >= 0.4 ? D.Gold : D.Red; /// Ein Fenster liegt über dem Hub (Bericht oder Ereignis): darunter nichts anklickbar. bool Modal => _game.ExpeditionResult != null || _game.PendingEvent != null || _eventShown != null; void UpdateAdventure() { if (_game.PendingEvent is string id && _eventSeen != id) { _eventSeen = id; SoundManager.PlayChapterSting(); } } Texture2D? Picture(string art) => Assets.Sprite(art, "jpg"); static void DrawPicture(SpriteBatch sb, Texture2D? tex, RectangleF r, float alpha = 1) { if (tex == null) { D.Rect(sb, r, new Color(30, 22, 15)); return; } // "cover": Bild füllt das Rechteck, mittig beschnitten float k = MathF.Max(r.Width / tex.Width, r.Height / tex.Height); int sw = (int)(r.Width / k), sh = (int)(r.Height / k); var src = new Rectangle((tex.Width - sw) / 2, (tex.Height - sh) / 2, sw, sh); sb.Draw(tex, new Rectangle((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height), src, Color.White * alpha); } // ── Schublade: Regionen und Aufbruch ──────────────────────── void DrawExpeditions(SpriteBatch sb, RectangleF r) { float x = r.X + 30, w = r.Width - 60, y = r.Y + 40; D.Text(sb, Assets.Serif, 34, L.t("exp.title"), new Vector2(x, y), D.Gold); D.TextWrap(sb, Assets.Sans, 17, L.t("exp.intro"), new RectangleF(x, y + 26, w, 44), D.Sand); if (_game.Away == null && !_game.RegionOpen(RegionDef.Get(_expRegion))) _expRegion = RegionDef.All.Last(reg => _game.RegionOpen(reg)).Id; const float GX = 20, GY = 18; float cw = (w - 2 * GX) / 3, ch = 250, y0 = y + 84; for (int i = 0; i < RegionDef.All.Length; i++) { var reg = RegionDef.All[i]; var cr = new RectangleF(x + i % 3 * (cw + GX), y0 + i / 3 * (ch + GY), cw, ch); bool open = _game.RegionOpen(reg), sel = reg.Id == (_game.Away?.Region ?? _expRegion); D.Rect(sb, cr, new Color(24, 18, 12) * 0.95f); DrawPicture(sb, Picture(reg.Art), new RectangleF(cr.X + 5, cr.Y + 5, cr.Width - 10, ch - 80), open ? 1 : 0.3f); D.Text(sb, Assets.Serif, 22, L.t(reg.Key).ToUpperInvariant(), new Vector2(cr.X + 14, cr.Bottom - 54), open ? D.Gold : D.Dim); string info = open ? string.Format(L.t("exp.chance"), NumberFormat.Percent(_game.ExpeditionChance(reg))) : string.Format(L.t("exp.locked"), L.t(ArenaDef.All[reg.Unlock].Key)); D.Text(sb, Assets.Sans, 16, info, new Vector2(cr.X + 14, cr.Bottom - 24), open ? ChanceColor(_game.ExpeditionChance(reg)) : D.Dim); D.Frame(sb, cr, sel ? D.Gold : D.Border, sel ? 4 : 2); if (open && _game.Away == null && _ui.Hover(cr) && _ui.Hit(cr)) { _expRegion = reg.Id; SoundManager.PlayClick(); } } float by = y0 + 2 * (ch + GY) + 10; if (_game.Away is { } a) { DrawAwayStatus(sb, new RectangleF(x, by, w, 80), a); return; } float bw = 240; for (int d = 0; d < 3; d++) if (_ui.Button(sb, new RectangleF(x + d * (bw + 12), by + 6, bw, 60), string.Format(L.t("exp.duration"), DurationLabel(d), LootCount(d)), selected: _expDuration == d, size: 18)) _expDuration = d; if (_ui.Button(sb, new RectangleF(x + w - 300, by + 6, 300, 60), L.t("exp.start"), _game.RegionOpen(RegionDef.Get(_expRegion)) && !_game.FreedomEarned, selected: true, size: 24, accent: D.Gold)) if (_game.StartExpedition(_expRegion, _expDuration)) { SoundManager.PlayStart(); _drawer = Drawer.None; } } void DrawAwayStatus(SpriteBatch sb, RectangleF r, Expedition a) { var reg = RegionDef.Get(a.Region); double total = Adventures.Durations[a.Duration]; float bw = r.Width - 380; D.Text(sb, Assets.SansBold, 22, string.Format(L.t("exp.away"), L.t(reg.Key)), new Vector2(r.X, r.Y + 14), D.Gold); D.Text(sb, Assets.Sans, 18, string.Format(L.t("exp.left"), NumberFormat.Duration(a.Left)), new Vector2(r.X, r.Y + 44), D.Sand); D.Bar(sb, new RectangleF(r.X, r.Y + 64, bw, 14), (float)(1 - a.Left / total), (float)(1 - a.Left / total), D.Gold); if (_ui.Button(sb, new RectangleF(r.Right - 340, r.Y + 10, 340, 60), L.t("exp.recall"), size: 18, accent: D.Red)) { _game.Recall(); SoundManager.PlayBoo(); } } /// Statt der Gegnerwahl, solange der Gladiator unterwegs ist: Bild der Region und Fortschritt. void DrawAwayCard(SpriteBatch sb, Expedition a) { var reg = RegionDef.Get(a.Region); var r = new RectangleF(Camera.W - 860, 150, 820, 640); Ui.Panel(sb, r, D.Gold, 0.92f); DrawPicture(sb, Picture(reg.Art), new RectangleF(r.X + 20, r.Y + 20, r.Width - 40, 430)); DrawAwayStatus(sb, new RectangleF(r.X + 30, r.Y + 470, r.Width - 60, 90), a); } // ── Segen ─────────────────────────────────────────────────── void DrawBuffs(SpriteBatch sb) { float y = 136; foreach (var b in _game.Buffs) { string text = string.Format(L.t("buff." + b.Kind.ToString().ToLowerInvariant()), NumberFormat.Percent(b.Mult - 1), NumberFormat.Duration(b.Left)); D.Text(sb, Assets.SansBold, 17, text, new Vector2(40, y), D.Blue); y += 24; } } // ── Fenster: Rückkehr-Bericht und Ereignis ────────────────── void DrawModal(SpriteBatch sb) { D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * 0.65f); if (_game.ExpeditionResult is { } rep) DrawReport(sb, rep); else if (_eventShown != null || _game.PendingEvent != null) DrawEvent(sb); } void DrawReport(SpriteBatch sb, ExpeditionReport rep) { var reg = RegionDef.Get(rep.Region); var r = new RectangleF(Camera.W / 2 - 520, 70, 1040, 940); Ui.Panel(sb, r, rep.Success ? D.Gold : D.Red, 0.97f); DrawPicture(sb, Picture(reg.Art), new RectangleF(r.X + 30, r.Y + 30, r.Width - 60, 300)); float y = r.Y + 370; D.Text(sb, Assets.Serif, 36, string.Format(L.t(rep.Success ? "exp.back.ok" : "exp.back.fail"), L.t(reg.Key)), new Vector2(r.Center.X, y), rep.Success ? D.Gold : D.Red, Align.Center); y += 44; if (!rep.Success) { D.Text(sb, Assets.Sans, 18, L.t("exp.back.failtext"), new Vector2(r.Center.X, y), D.Sand, Align.Center); y += 34; } foreach (int n in rep.Log) { D.TextWrap(sb, Assets.Serif, 19, "· " + L.t("expedition.log." + n), new RectangleF(r.X + 80, y - 10, r.Width - 160, 40), D.Sand); // i18n-ok y += 32; } y += 14; void Line(string label, string value) { D.Text(sb, Assets.Sans, 20, label, new Vector2(r.X + 220, y), D.Dim); D.Text(sb, Assets.SansBold, 22, value, new Vector2(r.Right - 220, y), D.Sand, Align.Right); y += 34; } Line(L.t("exp.reward.gold"), "+" + NumberFormat.Format(rep.Gold)); // i18n-ok Line(L.t("exp.reward.fame"), "+" + NumberFormat.Format(rep.Fame)); // i18n-ok Line(L.t("exp.reward.xp"), "+" + NumberFormat.Format(rep.Xp)); // i18n-ok if (rep.Loot.Count > 0) { float size = 88, lx = r.Center.X - (rep.Loot.Count * (size + 12) - 12) / 2; for (int i = 0; i < rep.Loot.Count; i++) ItemTile(sb, new RectangleF(lx + i * (size + 12), y + 4, size, size), rep.Loot[i], false); } if (_ui.Button(sb, new RectangleF(r.Center.X - 170, r.Bottom - 80, 340, 60), L.t("exp.ok"), selected: true, size: 24)) { _game.DismissExpeditionResult(); SoundManager.PlayCoins(); } } void DrawEvent(SpriteBatch sb) { _eventShown ??= _game.PendingEvent; var ev = Adventures.GetEvent(_eventShown!); var r = new RectangleF(Camera.W / 2 - 700, 110, 1400, 860); Ui.Panel(sb, r, D.Gold, 0.97f); var pic = new RectangleF(r.X + 34, r.Y + 34, 640, 360); DrawPicture(sb, Picture(ev.Art), pic); D.Frame(sb, pic, D.Border, 2); float tx = pic.Right + 34, tw = r.Right - 34 - tx; D.TextWrap(sb, Assets.Serif, 34, L.t(ev.Title), new RectangleF(tx, r.Y + 30, tw, 100), D.Gold); D.TextWrap(sb, Assets.Serif, 21, L.t(ev.Text), new RectangleF(tx, r.Y + 140, tw, 250), D.Sand); float y = pic.Bottom + 34; if (_eventOutcome != null) { D.TextWrap(sb, Assets.Serif, 26, L.t(_eventOutcome), new RectangleF(r.X + 80, y + 20, r.Width - 160, 200), new Color(245, 236, 214)); if (_ui.Button(sb, new RectangleF(r.Center.X - 170, r.Bottom - 90, 340, 62), L.t("event.ok"), selected: true, size: 24)) { _eventShown = null; _eventOutcome = null; SoundManager.PlayClick(); } return; } for (int i = 0; i < ev.Choices.Length; i++) { var c = ev.Choices[i]; double cost = _game.ChoiceCost(c); string label = L.t(ev.ChoiceKey(c)); if (cost > 0) label += " · " + string.Format(L.t("event.cost"), NumberFormat.Format(cost)); // i18n-ok if (c.Chance < 1) label += " · " + L.t("event.risky") + " " + NumberFormat.Percent(c.Chance); // i18n-ok if (_ui.Button(sb, new RectangleF(r.X + 60, y, r.Width - 120, 64), label, _game.Gold >= cost, size: 21)) { var outcome = _game.Choose(i); if (outcome != null) { _eventOutcome = outcome; if (outcome.EndsWith(".fail", StringComparison.Ordinal)) SoundManager.PlayBoo(); else SoundManager.PlayGoodEvent(); } } y += 76; } } } }