Esempio n. 1
0
        public async Task <IActionResult> Create(CombatFormationViewModel combatForm)
        {
            BattleFront battleFront = new BattleFront()
            {
                //BattleFrontId = combatForm.Id,
                Name          = combatForm.Name,
                TotalStrenght = combatForm.TotalStrenght,
                Commanders    = combatForm.Commanders,
                Armies        = combatForm.Armies,
                WeekId        = combatForm.WeekId,
                Image         = combatForm.Image,
                CoordinatesXY = combatForm.Coordinates,
                CoordX        = combatForm.CoordX,
                CoordY        = combatForm.CoordY,
                Adress        = combatForm.Adress
            };

            if (ModelState.IsValid)
            {
                if (combatForm.Coordinates != null)
                {
                    string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None);
                    battleFront.CoordX = str[0];
                    battleFront.CoordY = str[1];
                }
                if (combatForm.File != null)
                {
                    byte[] imageData = null;
                    // считываем переданный файл в массив байтов
                    using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)combatForm.File.Length);
                    }
                    // установка массива байтов
                    battleFront.Image = imageData;
                }
                _context.Add(battleFront);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(battleFront));
        }
        /// <summary>
        /// Grants rewards for taking this battlefield objective from the enemy.
        /// </summary>
        /// <param name="capturingRealm"></param>
        public void GrantCaptureRewards(Realms capturingRealm)
        {
            if (State == StateFlags.ZoneLocked)
            {
                return;
            }

            var closePlayers = GetClosePlayers(capturingRealm);

            var contributionDefinition  = new ContributionDefinition();
            var activeBattleFrontStatus = BattleFront.GetActiveBattleFrontStatus();

            VictoryPoint VP = new VictoryPoint(0, 0);

            // Check RC is within range of this BO to award RP for.
            var destructionRealmCaptain = activeBattleFrontStatus.DestructionRealmCaptain;

            if (destructionRealmCaptain?.GetDistanceToObject(this) < 200)
            {
                destructionRealmCaptain?.AddRenown(150, false, RewardType.ObjectiveCapture,
                                                   "for being Realm Captain");
            }
            var orderRealmCaptain = activeBattleFrontStatus.OrderRealmCaptain;

            if (orderRealmCaptain?.GetDistanceToObject(this) < 200)
            {
                orderRealmCaptain?.AddRenown(150, false, RewardType.ObjectiveCapture,
                                             "for being Realm Captain");
            }

            switch (State)
            {
            case StateFlags.Contested:     // small tick
                VP = RewardManager.RewardCaptureTick(closePlayers, capturingRealm, Tier, Name, 1f, BORewardType.CAPTURING);
                lock (closePlayers)
                {
                    foreach (var closePlayer in closePlayers)
                    {
                        closePlayer.UpdatePlayerBountyEvent((byte)ContributionDefinitions.BO_TAKE_SMALL_TICK);
                    }
                }
                break;

            case StateFlags.Secure:     // big tick
                VP = RewardManager.RewardCaptureTick(closePlayers, capturingRealm, Tier, Name, 1f, BORewardType.CAPTURED);

                WorldMgr.UpperTierCampaignManager.GetActiveCampaign().VictoryPointProgress.UpdateStatus(WorldMgr.UpperTierCampaignManager.GetActiveCampaign());

                lock (closePlayers)
                {
                    foreach (var closePlayer in closePlayers)
                    {
                        closePlayer.UpdatePlayerBountyEvent((byte)ContributionDefinitions.BO_TAKE_BIG_TICK);

                        // is this player the group leader?
                        if (closePlayer.PriorityGroup?.GetLeader() == closePlayer)
                        {
                            closePlayer.UpdatePlayerBountyEvent((byte)ContributionDefinitions.GROUP_LEADER_BO_BIG_TICK);
                        }
                    }
                }
                break;

            case StateFlags.Locked:     // unlock tick
                VP = RewardManager.RewardCaptureTick(closePlayers, capturingRealm, Tier, Name, 1f, BORewardType.GUARDED);
                lock (closePlayers)
                {
                    foreach (var closePlayer in closePlayers)
                    {
                        // ContributionManagerInstance holds the long term values of contribution for a player.
                        closePlayer.UpdatePlayerBountyEvent((byte)ContributionDefinitions.BO_TAKE_UNLOCK_TICK);
                    }
                }

                break;

            default:
                break;
            }

            // Make sure VP dont go less than 0
            if (BattleFront.VictoryPointProgress.OrderVictoryPoints <= 0)
            {
                BattleFront.VictoryPointProgress.OrderVictoryPoints = 0;
            }

            if (BattleFront.VictoryPointProgress.DestructionVictoryPoints <= 0)
            {
                BattleFront.VictoryPointProgress.DestructionVictoryPoints = 0;
            }

            BattlefrontLogger.Trace($"{Name} Order VP:{BattleFront.VictoryPointProgress.OrderVictoryPoints} Dest VP:{BattleFront.VictoryPointProgress.DestructionVictoryPoints}");
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, CombatFormationViewModel combatForm)
        {
            if (id != combatForm.Id)
            {
                return(NotFound());
            }
            BattleFront battleFront = new BattleFront()
            {
                BattleFrontId = combatForm.Id,
                Name          = combatForm.Name,
                TotalStrenght = combatForm.TotalStrenght,
                Commanders    = combatForm.Commanders,
                Armies        = combatForm.Armies,
                WeekId        = combatForm.WeekId,
                Image         = combatForm.Image,
                CoordinatesXY = combatForm.Coordinates,
                CoordX        = combatForm.CoordX,
                CoordY        = combatForm.CoordY,
                Adress        = combatForm.Adress
            };

            if (ModelState.IsValid)
            {
                if (combatForm.Coordinates != null)
                {
                    string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None);
                    battleFront.CoordX = str[0];
                    battleFront.CoordY = str[1];
                }
                if (combatForm.File != null)
                {
                    byte[] imageData = null;
                    // считываем переданный файл в массив байтов
                    using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)combatForm.File.Length);
                    }
                    // установка массива байтов
                    battleFront.Image = imageData;
                    try
                    {
                        _context.Update(battleFront);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!BattleFrontExists(battleFront.BattleFrontId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else if (combatForm.File == null)
                {
                    battleFront.Image = combatForm.Image;
                    try
                    {
                        _context.Update(battleFront);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!BattleFrontExists(battleFront.BattleFrontId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(battleFront));
        }