예제 #1
0
        public override void PerformSetup(Context context, IState previousState)
        {
            PartyDataWrapper  party      = context.Get <PartyDataWrapper>();
            FirebaseWrapper   fbWrapper  = context.Get <FirebaseWrapper>();
            PlayerDataWrapper playerData = context.Get <PlayerDataWrapper>();

            playerData.SetActiveParty(0u);

            fbWrapper.WriteData(playerData.GetDataPath(fbWrapper.UserId), playerData);

            _context.Clear <PartyDataWrapper>();

            Calamity            = party.Calamity;
            SurvivingCharacters = party.Characters.FindAll(x => x.IsAlive());
            FallenCharacters    = party.Characters.FindAll(x => !x.IsAlive());
        }
예제 #2
0
        public override void PerformSetup(Context context, IState previousState)
        {
            base.PerformSetup(context, previousState);

            Party = context.Get <PartyDataWrapper>();
            FirebaseWrapper fbWrapper = context.Get <FirebaseWrapper>();

            if (Results.Success)
            {
                Random random = new Random();

                Party.Gold            += Results.GoldReward;
                Party.CalamityDefeated = Party.Day >= 30;

                fbWrapper.WriteData(Party.GetDataPath(fbWrapper.UserId), Party);

                // Update Stats
                StatType[] statTypes       = Enum.GetValues(typeof(StatType)).Cast <StatType>().ToArray();
                uint       expPerCharacter = (uint)Math.Ceiling(Results.ExpReward / (float)Party.Characters.Count);
                foreach (PlayerCharacter playerCharacter in Party.Characters)
                {
                    IStatMap oldMap = playerCharacter.Stats.Copy();
                    IStatMap newMap = playerCharacter.Stats;

                    // Add EXP
                    newMap.ModifyStat(StatType.EXP, (int)expPerCharacter);

                    // Level Up
                    uint lvlsUp = newMap[StatType.LVL] - oldMap[StatType.LVL];
                    for (int i = 0; i < lvlsUp; i++)
                    {
                        newMap = playerCharacter.Class.LevelUpStats.Increment(newMap, random);
                    }

                    playerCharacter.Stats = newMap;

                    // Calc Changes
                    uint[] changes = new uint[statTypes.Length];
                    for (int i = 0; i < statTypes.Length; i++)
                    {
                        changes[i] = newMap[(StatType)i] - oldMap[(StatType)i];
                    }
                    changes[(int)StatType.EXP] = newMap[StatType.EXP] + 100 * lvlsUp - oldMap[StatType.EXP];

                    _oldStatMaps[playerCharacter.Id]     = oldMap;
                    _statChanges[playerCharacter.Id]     = changes;
                    _gainedAbilities[playerCharacter.Id] =
                        playerCharacter.Class.GetAllAbilities(newMap[StatType.LVL])
                        .Except(playerCharacter.Class.GetAllAbilities(oldMap[StatType.LVL]))
                        .ToArray();
                }
            }
            else
            {
                PlayerDataWrapper playerData = _context.Get <PlayerDataWrapper>();
                playerData.SetActiveParty(0u);

                fbWrapper.WriteData(Party.GetDataPath(fbWrapper.UserId), Party);
                fbWrapper.WriteData(playerData.GetDataPath(fbWrapper.UserId), playerData);

                _context.Clear <PartyDataWrapper>();
            }
        }