Exemplo n.º 1
0
        public async Task <IActionResult> OnPostUpdateAsync(int id, int index, int encounterID)
        {
            EncounterID = encounterID;
            if (ModelState.TryGetValue("Ship.BonusCurrent", out var bonusVal) &&
                ModelState.TryGetValue("Ship.Name", out var nameVal) &&
                ModelState.TryGetValue("Ship.Roll", out var rollVal))
            {
                string newName = nameVal.AttemptedValue.Split(',')[index];
                if (int.TryParse(bonusVal.AttemptedValue.Split(',')[index], out int bonus))
                {
                    if (int.TryParse(rollVal.AttemptedValue.Split(',')[index], out int roll))
                    {
                        var ship = await _db.Ships.FindAsync(id);

                        if (ship != null)
                        {
                            ship.Name              = newName;
                            ship.BonusCurrent      = bonus;
                            ship.Roll              = roll;
                            _db.Attach(ship).State = EntityState.Modified;
                            await _db.SaveChangesAsync();
                        }
                    }
                }
            }
            return(RedirectToPage(EncounterHolder.Create(Encounter)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostResetCounterAsync(int encounterID)
        {
            EncounterID        = encounterID;
            CurrentRound.Round = 1;
            CurrentRound.Step  = ROUND_STEP.ENGINEERING;
            await _db.SaveChangesAsync();

            return(RedirectToPage(EncounterHolder.Create(Encounter)));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAddShipAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Ship.EncounterID = Encounter.EncounterID;
            _db.Ships.Add(Ship);
            await _db.SaveChangesAsync();

            return(RedirectToPage(EncounterHolder.Create(Encounter)));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostDeleteAsync(int id, int encounterID)
        {
            EncounterID = encounterID;
            var ship = await _db.Ships.FindAsync(id);

            if (ship != null)
            {
                _db.Ships.Remove(ship);
                await _db.SaveChangesAsync();
            }

            return(RedirectToPage(EncounterHolder.Create(Encounter)));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostDuplicateAsync(int id, int encounterID)
        {
            EncounterID = encounterID;
            var ship = await _db.Ships.FindAsync(id);

            if (ship != null)
            {
                Ship newShip = new Ship
                {
                    Name        = ship.Name + " (copy)",
                    BonusBase   = ship.BonusBase,
                    EncounterID = Encounter.EncounterID
                };
                _db.Ships.Add(newShip);
                await _db.SaveChangesAsync();
            }

            return(RedirectToPage(EncounterHolder.Create(Encounter)));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostRollAsync(int encounterID)
        {
            EncounterID       = encounterID;
            CurrentRound.Step = (ROUND_STEP)(((int)CurrentRound.Step + 1) % 3);
            if (CurrentRound.Step == ROUND_STEP.HELM)
            {
                Random r = new Random();
                foreach (var ship in Ships)
                {
                    ship.Roll = r.Next(20) + 1 + ship.BonusCurrent;
                    _db.Attach(ship).State = EntityState.Modified;
                }
            }
            else if (CurrentRound.Step == ROUND_STEP.ENGINEERING)
            {
                CurrentRound.Round++;
            }
            await _db.SaveChangesAsync();

            return(RedirectToPage(EncounterHolder.Create(Encounter)));
        }