예제 #1
0
 public void OnBattleLoaded(Scene scene, LoadSceneMode mode)
 {
     stateMachine = GetComponent <TurnStateMachine>();
     stateMachine.Initialize();
     _settings = GameManager.Settings.battleSettings;
     StartCoroutine(SetupBattle());
 }
예제 #2
0
        public async Task <BattleHandler> CreateBattleHandlerAsync(long battleId)
        {
            BattleSettings battleSettings;

            try
            {
                var battleDto = await _apiClient.GetBattleAsync(battleId);

                battleSettings = new BattleSettings
                {
                    ChunkSettings = new ChunkSettings
                    {
                        ChunkHeight = battleDto.Settings.ChunkHeight,
                        ChunkWidth  = battleDto.Settings.ChunkWidth
                    },
                    Cooldown       = battleDto.Settings.Cooldown,
                    MaxHeightIndex = battleDto.Settings.MaxHeightIndex,
                    MinHeightIndex = battleDto.Settings.MinHeightIndex,
                    MaxWidthIndex  = battleDto.Settings.MaxWidthIndex,
                    MinWidthIndex  = battleDto.Settings.MinWidthIndex,
                    StartDateUTC   = battleDto.StartDateUTC,
                    EndDateUTC     = battleDto.EndDateUTC
                };
            }
            catch (Exception)
            {
                return(null);
            }

            var chunklerClient      = _serviceProvider.GetRequiredService <IChunklerClient>();
            var chunkHandlerFactory = _serviceProvider.GetRequiredService <IChunkHandlerFactory>();

            return(new BattleHandler(battleId, battleSettings, chunklerClient, chunkHandlerFactory));
        }
예제 #3
0
 public BattleService(IDockerService dockerService, ILogger <BattleService> logger, ILoggerFactory loggerFactory, IOptions <BattleSettings> battleSettings)
 {
     this.dockerService  = dockerService;
     this.logger         = logger;
     this.loggerFactory  = loggerFactory;
     this.battleSettings = battleSettings.Value ?? throw new ArgumentNullException();
 }
예제 #4
0
    void StartAttack()
    {
        _gameState = GameState.AttackScreen;
        RenderAttackScreen();

        BattleSettings battleSettings = new BattleSettings()
        {
            VictoriesNeededToWin   = _victoriesNeededToWin,
            Party1CurrentVictories = _party1VictoryCount,
            Party2CurrentVictories = _party2VictoryCount,
            BossFight                        = _bossFight,
            PVEStartHealth                   = _pveStartHealth,
            PVPStartHealth                   = _pvpStartHealth,
            BossStartHealth                  = _bossStartHealth,
            InitialActiveScreenSeconds       = InitialActiveScreenSeconds,
            MinimumActiveScreenSeconds       = MinimumActiveScreenSeconds,
            ActiveScreenScalingFactor        = ActiveScreenScalingFactor,
            BossMaximumDamagePerAttack       = BossMaximumDamagePerAttack,
            BossMinimumDamagePerAttack       = BossMinimumDamagePerAttack,
            PlayerMinimumDamagePerAttack     = PlayerMinimumDamagePerAttack,
            PlayerMaximumDamagePerAttack     = PlayerMaximumDamagePerAttack,
            BuffIncreaseActiveTimeMultiplier = _buffIncreaseActiveTimeMultiplier,
            BuffParty1CritChance             = _buffParty1CritChance,
            BuffParty2CritChance             = _buffParty2CritChance,
            MusicVolume                      = _musicVolume,
            TestMode             = _joystickMapping.TestMode,
            EndRoundNotification = EndRoundNotification
        };

        _attackPanel.StartBattle(_buttonMaster, battleSettings);
    }
예제 #5
0
 public Model(Battle.Model obj)
 {
     settings = obj.battleSettings;
     teams    = new List <WifiFriendly.Team>();
     for (int i = 0; i < obj.teams.Count; i++)
     {
         teams.Add(new WifiFriendly.Team(obj.teams[i]));
     }
 }
예제 #6
0
 // Battle
 public static void WriteBattleSettings(this NetworkWriter writer, BattleSettings obj)
 {
     writer.WriteInt32((int)obj.battleType);
     writer.WriteBoolean(obj.isWildBattle);
     writer.WriteBoolean(obj.isInverse);
     writer.WriteBoolean(obj.canMegaEvolve);
     writer.WriteBoolean(obj.canZMove);
     writer.WriteBoolean(obj.canDynamax);
 }
예제 #7
0
    public void StartBattle(BattleSettings battle)
    {
        _enemies.Clear();

        foreach (var e in battle.Enemies)
        {
            _enemies.Add(Instantiate(e));
        }

        SetState(States.InitBattle);
    }
예제 #8
0
 public BattleHandler(long battleId, BattleSettings battleSettings, IChunklerClient chunklerClient, IChunkHandlerFactory chunkHandlerFactory)
 {
     _isClosing              = false;
     _battleId               = battleId;
     _battleSettings         = battleSettings ?? throw new ArgumentNullException(nameof(battleSettings));
     _subscriptionCounter    = 0;
     _lastUpdatedTicksUTC    = DateTime.UtcNow.Ticks;
     _chunklerClient         = chunklerClient ?? throw new ArgumentNullException(nameof(chunklerClient));
     _chunkHandlerFactory    = chunkHandlerFactory ?? throw new ArgumentNullException(nameof(chunkHandlerFactory));
     _chunkHandlers          = new ConcurrentDictionary <ChunkKey, AsyncLazy <ChunkHandler> >();
     _compactedChunkHandlers = new Dictionary <ChunkKey, AsyncLazy <ChunkHandler> >();
 }
        public static BattleSettingsModel ToModel(this BattleSettings battleSettings)
        {
            var model = new BattleSettingsModel()
            {
                BattleHostPictureBattleSponsorshipPercentage = battleSettings.BattleHostPictureBattleSponsorshipPercentage,
                BattleHostVideoBattleSponsorshipPercentage   = battleSettings.BattleHostVideoBattleSponsorshipPercentage,
                DefaultVideosFeaturedImageUrl               = battleSettings.DefaultVideosFeaturedImageUrl,
                DefaultVotingChargeForPaidVoting            = battleSettings.DefaultVotingChargeForPaidVoting,
                SiteOwnerPictureBattleSponsorshipPercentage = battleSettings.SiteOwnerPictureBattleSponsorshipPercentage,
                SiteOwnerVideoBattleSponsorshipPercentage   = battleSettings.SiteOwnerVideoBattleSponsorshipPercentage
            };

            return(model);
        }
예제 #10
0
        public IHttpActionResult Post(BattleSettingsModel entityModel)
        {
            var battleSettings = new BattleSettings()
            {
                BattleHostPictureBattleSponsorshipPercentage = entityModel.BattleHostPictureBattleSponsorshipPercentage,
                BattleHostVideoBattleSponsorshipPercentage   = entityModel.BattleHostVideoBattleSponsorshipPercentage,
                DefaultVideosFeaturedImageUrl               = entityModel.DefaultVideosFeaturedImageUrl,
                DefaultVotingChargeForPaidVoting            = entityModel.DefaultVotingChargeForPaidVoting,
                SiteOwnerPictureBattleSponsorshipPercentage = entityModel.SiteOwnerPictureBattleSponsorshipPercentage,
                SiteOwnerVideoBattleSponsorshipPercentage   = entityModel.SiteOwnerVideoBattleSponsorshipPercentage
            };

            _settingService.Save(battleSettings);
            VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting");
            return(RespondSuccess(new { BattleSettings = battleSettings.ToModel() }));
        }
예제 #11
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
         GameManager.instance.resetBattlePrep();
         battleSettings = GameManager.instance.CurrentBattleSettings;
         areneGo        = Instantiate(battleSettings.Scenery);
         areneComp      = areneGo.GetComponent <Arene>();
         fillPhraseFin();
         StartCoroutine("addbots");
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
예제 #12
0
        public Battle(BattleSettings battleSettings, ICollection <string> dockerImages,
                      IDockerService dockerService, IStorageClient storageClient, ILogger <Battle> logger)
        {
            this.battleInfo = new BattleInfo
            {
                BattleId = Guid.NewGuid().ToString(),
                Map      = battleSettings.Map
            };
            this.dockerService = dockerService;
            this.logger        = logger;
            this.storageClient = storageClient;
            this.dockerImages  = dockerImages;
            var gameSettings = GameSettings.Default;

            gameSettings.ZoneRadius = battleSettings.ZoneRadius;
            this.game = new Game(dockerImages, this.LoadMap(this.battleInfo), GameSettings.Default);
        }
예제 #13
0
        public Battle(BattleSettings battleSettings, ISet <string> dockerImages,
                      IDockerService dockerService, IStorageClient storageClient, ILogger <Battle> logger)
        {
            this.battleInfo = new BattleInfo
            {
                BattleId = Guid.NewGuid().ToString(),
                Map      = battleSettings.Map
            };

            this.warmDelay   = TimeSpan.FromSeconds(battleSettings.ContainersWarmSeconds);
            this.answerDelay = TimeSpan.FromMilliseconds(battleSettings.ContainersAnswerMilliseconds);

            this.dockerService = dockerService;
            this.logger        = logger;
            this.storageClient = storageClient;
            this.dockerImages  = dockerImages;
            var gameSettings = GameSettings.Default;

            gameSettings.ZoneRadius = battleSettings.ZoneRadius;
            this.game = new Game(dockerImages, this.LoadMap(this.battleInfo), GameSettings.Default);
        }
 public void MergeFrom(ItemTemplate other)
 {
     if (other == null)
     {
         return;
     }
     if (other.TemplateId.Length != 0)
     {
         TemplateId = other.TemplateId;
     }
     if (other.pokemonSettings_ != null)
     {
         if (pokemonSettings_ == null)
         {
             pokemonSettings_ = new global::PokemonGoDesktop.API.Proto.PokemonSettings();
         }
         PokemonSettings.MergeFrom(other.PokemonSettings);
     }
     if (other.itemSettings_ != null)
     {
         if (itemSettings_ == null)
         {
             itemSettings_ = new global::PokemonGoDesktop.API.Proto.ItemSettings();
         }
         ItemSettings.MergeFrom(other.ItemSettings);
     }
     if (other.moveSettings_ != null)
     {
         if (moveSettings_ == null)
         {
             moveSettings_ = new global::PokemonGoDesktop.API.Proto.MoveSettings();
         }
         MoveSettings.MergeFrom(other.MoveSettings);
     }
     if (other.moveSequenceSettings_ != null)
     {
         if (moveSequenceSettings_ == null)
         {
             moveSequenceSettings_ = new global::PokemonGoDesktop.API.Proto.MoveSequenceSettings();
         }
         MoveSequenceSettings.MergeFrom(other.MoveSequenceSettings);
     }
     if (other.typeEffective_ != null)
     {
         if (typeEffective_ == null)
         {
             typeEffective_ = new global::PokemonGoDesktop.API.Proto.TypeEffectiveSettings();
         }
         TypeEffective.MergeFrom(other.TypeEffective);
     }
     if (other.badgeSettings_ != null)
     {
         if (badgeSettings_ == null)
         {
             badgeSettings_ = new global::PokemonGoDesktop.API.Proto.BadgeSettings();
         }
         BadgeSettings.MergeFrom(other.BadgeSettings);
     }
     if (other.camera_ != null)
     {
         if (camera_ == null)
         {
             camera_ = new global::PokemonGoDesktop.API.Proto.CameraSettings();
         }
         Camera.MergeFrom(other.Camera);
     }
     if (other.playerLevel_ != null)
     {
         if (playerLevel_ == null)
         {
             playerLevel_ = new global::PokemonGoDesktop.API.Proto.PlayerLevelSettings();
         }
         PlayerLevel.MergeFrom(other.PlayerLevel);
     }
     if (other.gymLevel_ != null)
     {
         if (gymLevel_ == null)
         {
             gymLevel_ = new global::PokemonGoDesktop.API.Proto.GymLevelSettings();
         }
         GymLevel.MergeFrom(other.GymLevel);
     }
     if (other.battleSettings_ != null)
     {
         if (battleSettings_ == null)
         {
             battleSettings_ = new global::PokemonGoDesktop.API.Proto.GymBattleSettings();
         }
         BattleSettings.MergeFrom(other.BattleSettings);
     }
     if (other.encounterSettings_ != null)
     {
         if (encounterSettings_ == null)
         {
             encounterSettings_ = new global::PokemonGoDesktop.API.Proto.EncounterSettings();
         }
         EncounterSettings.MergeFrom(other.EncounterSettings);
     }
     if (other.iapItemDisplay_ != null)
     {
         if (iapItemDisplay_ == null)
         {
             iapItemDisplay_ = new global::PokemonGoDesktop.API.Proto.IapItemDisplay();
         }
         IapItemDisplay.MergeFrom(other.IapItemDisplay);
     }
     if (other.iapSettings_ != null)
     {
         if (iapSettings_ == null)
         {
             iapSettings_ = new global::PokemonGoDesktop.API.Proto.IapSettings();
         }
         IapSettings.MergeFrom(other.IapSettings);
     }
     if (other.pokemonUpgrades_ != null)
     {
         if (pokemonUpgrades_ == null)
         {
             pokemonUpgrades_ = new global::PokemonGoDesktop.API.Proto.PokemonUpgradeSettings();
         }
         PokemonUpgrades.MergeFrom(other.PokemonUpgrades);
     }
     if (other.equippedBadges_ != null)
     {
         if (equippedBadges_ == null)
         {
             equippedBadges_ = new global::PokemonGoDesktop.API.Proto.EquippedBadgeSettings();
         }
         EquippedBadges.MergeFrom(other.EquippedBadges);
     }
 }
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (TemplateId.Length != 0)
                    {
                        hash ^= TemplateId.GetHashCode();
                    }
                    if (pokemonSettings_ != null)
                    {
                        hash ^= PokemonSettings.GetHashCode();
                    }
                    if (itemSettings_ != null)
                    {
                        hash ^= ItemSettings.GetHashCode();
                    }
                    if (moveSettings_ != null)
                    {
                        hash ^= MoveSettings.GetHashCode();
                    }
                    if (moveSequenceSettings_ != null)
                    {
                        hash ^= MoveSequenceSettings.GetHashCode();
                    }
                    if (typeEffective_ != null)
                    {
                        hash ^= TypeEffective.GetHashCode();
                    }
                    if (badgeSettings_ != null)
                    {
                        hash ^= BadgeSettings.GetHashCode();
                    }
                    if (camera_ != null)
                    {
                        hash ^= Camera.GetHashCode();
                    }
                    if (playerLevel_ != null)
                    {
                        hash ^= PlayerLevel.GetHashCode();
                    }
                    if (gymLevel_ != null)
                    {
                        hash ^= GymLevel.GetHashCode();
                    }
                    if (battleSettings_ != null)
                    {
                        hash ^= BattleSettings.GetHashCode();
                    }
                    if (encounterSettings_ != null)
                    {
                        hash ^= EncounterSettings.GetHashCode();
                    }
                    if (iapItemDisplay_ != null)
                    {
                        hash ^= IapItemDisplay.GetHashCode();
                    }
                    if (iapSettings_ != null)
                    {
                        hash ^= IapSettings.GetHashCode();
                    }
                    if (pokemonUpgrades_ != null)
                    {
                        hash ^= PokemonUpgrades.GetHashCode();
                    }
                    if (equippedBadges_ != null)
                    {
                        hash ^= EquippedBadges.GetHashCode();
                    }
                    return(hash);
                }
        public static string GetConsolidatedPrizesString(this VideoBattle battle,
                                                         List <VideoBattlePrize> allPrizes,
                                                         int?winnerPosition,
                                                         ISponsorService sponsorService,
                                                         ISettingService settingService,
                                                         IPaymentProcessingService paymentProcessingService,
                                                         IFormatterService formatterService,
                                                         ICreditService creditService,
                                                         BattleSettings battleSettings)
        {
            var battleOwnerPrizes = allPrizes.Where(x => !x.IsSponsored && (!winnerPosition.HasValue || x.WinnerPosition == winnerPosition.Value));
            var sponsoredPrizes   = allPrizes.Where(x => x.IsSponsored && (!winnerPosition.HasValue || x.WinnerPosition == winnerPosition.Value));

            var videoBattlePrizes      = battleOwnerPrizes as VideoBattlePrize[] ?? battleOwnerPrizes.ToArray();
            var totalPrizesAmountFixed = videoBattlePrizes.Where(x => x.PrizeType == BattlePrizeType.FixedAmount).Sum(x => x.PrizeAmount);

            var totalPrizesAmountPercentage = 0m;

            if (videoBattlePrizes.Any(x => x.PrizeType == BattlePrizeType.PercentageAmount))
            {
                var contextKeyName = string.Format(CreditContextKeyNames.BattleVote, battle.Id);
                //get spent credits for battle votes
                var credits = creditService.GetCredits(contextKeyName, null, CreditTransactionType.Spent);

                var orderSum    = credits.Sum(x => x.CreditCount);
                var netOrderSum = paymentProcessingService.GetNetAmountAfterPaymentProcessing(orderSum);

                var totalWinners = videoBattlePrizes.Count();

                //total voting amount from percentage
                totalPrizesAmountPercentage = netOrderSum -
                                              totalWinners * netOrderSum * battle.ParticipantPercentagePerVote / 100;
            }

            var sponsorships = sponsorService.GetSponsorsGrouped(null, battle.Id, BattleType.Video,
                                                                 SponsorshipStatus.Accepted);

            var sponsorshipAmount = sponsorships.Sum(x => x.SponsorshipAmount);

            //amount after payment processing
            var netSponsorshipAmount = paymentProcessingService.GetNetAmountAfterPaymentProcessing(sponsorshipAmount);

            var siteOwnerShare = netSponsorshipAmount * battleSettings.SiteOwnerVideoBattleSponsorshipPercentage / 100;

            //it may be possible that battle host himself is sponsor, he won't be getting commissions for that :)
            var battleHostAsSponsorAmount =
                sponsorships.Where(x => x.UserId == battle.ChallengerId).Sum(x => x.SponsorshipAmount);


            var battleHostShare = (netSponsorshipAmount - battleHostAsSponsorAmount) * battleSettings.BattleHostVideoBattleSponsorshipPercentage / 100;

            //amount available for winners
            var winnerPrizePool = netSponsorshipAmount - siteOwnerShare - battleHostShare;

            if (winnerPosition.HasValue)
            {
                winnerPrizePool = PrizeDistributionHelper.GetPrizeDistributionPercentage(winnerPosition.Value,
                                                                                         allPrizes.Count(x => !x.IsSponsored), settingService) * winnerPrizePool;
            }

            var totalAmount = Math.Round(totalPrizesAmountFixed + totalPrizesAmountPercentage + winnerPrizePool);

            var totalPrizeString = totalAmount > 0 ? formatterService.FormatCurrency(totalAmount, ApplicationContext.Current.ActiveCurrency) : "";


            if (allPrizes.Any(x => x.PrizeType == BattlePrizeType.FixedProduct || x.PrizeType == BattlePrizeType.Other))
            {
                if (!winnerPosition.HasValue)
                {
                    totalPrizeString += "+";
                }
                else
                {
                    //now append each product as prize with it's name to the prize string
                    foreach (var prize in videoBattlePrizes.Where(x => x.PrizeType == BattlePrizeType.FixedProduct || x.PrizeType == BattlePrizeType.Other))
                    {
                        if (prize.PrizeType == BattlePrizeType.FixedProduct)
                        {
                            //todo: do something for fixed product
                        }
                        else
                        {
                            totalPrizeString += (totalPrizeString != "" ? " + " : "") + prize.PrizeOther;
                        }
                    }
                    //and sponsored products
                    foreach (var prize in sponsoredPrizes.Where(x => x.PrizeType == BattlePrizeType.Other))
                    {
                        totalPrizeString += (totalPrizeString != "" ? " + " : "") + prize.PrizeOther + "*";
                    }
                }
            }

            return(totalPrizeString);
        }
예제 #17
0
    public void StartBattle(ButtonMaster buttonMaster, BattleSettings battleSettings)
    {
        _freezeTime     = true;
        _buttonMaster   = buttonMaster;
        _battleSettings = battleSettings;

        Debug.Log(_battleSettings.TestMode);
        _testMode    = _battleSettings.TestMode;
        _musicVolume = _battleSettings.MusicVolume;

        if (_battleSettings.BossFight)
        {
            _party1StartHealth = _battleSettings.PVEStartHealth;
            _party2StartHealth = _battleSettings.BossStartHealth;
        }
        else
        {
            _party2StartHealth = _battleSettings.PVPStartHealth;
            _party1StartHealth = _battleSettings.PVPStartHealth;
        }

        _completedCycles = 0;
        _party1Health    = _party1StartHealth;
        _party2Health    = _party2StartHealth;

        //Want to clean up old rendering of things from previous games
        _party1.RefreshHealth(_party1StartHealth, _party1StartHealth);
        _party2.RefreshHealth(_party2StartHealth, _party2StartHealth);

        //Prep the player/boss panels for battle.
        _party1.PrepForBattle(
            _battleSettings.BossFight,
            _party1StartHealth,
            _battleSettings.VictoriesNeededToWin,
            _battleSettings.Party1CurrentVictories
            );
        _party2.PrepForBattle(
            _battleSettings.BossFight,
            _party2StartHealth,
            _battleSettings.VictoriesNeededToWin,
            _battleSettings.Party2CurrentVictories
            );

        bool bFinalRound = false;

        if (_battleSettings.VictoriesNeededToWin > 1 &&
            _battleSettings.Party1CurrentVictories == (_battleSettings.VictoriesNeededToWin - 1) &&
            _battleSettings.Party2CurrentVictories == (_battleSettings.VictoriesNeededToWin - 1))
        {
            bFinalRound = true;
        }

        PlayMusic(bFinalRound);

        _battleRaging        = true;
        EndRoundNotification = _battleSettings.EndRoundNotification;

        //Start on normal mode, move to Panic Mode later
        PanicModePanel.SetActive(false);


        StartAttackCycle(AttackMode.Normal);
    }
예제 #18
0
 public BattleProperties(BattleSettings battleSetting, bool runnable)
 {
     BattleSetting = battleSetting;
     Runnable      = runnable;
 }