Example #1
0
 public bool DeductMoney(int money)
 {
     if (MyPlayer.Money < money)
     {
         return(false);
     }
     PlayerAchievementLogic.GetInstance(MyPlayer.Id).UpdateAchievement(AchievementType.CostedMoney, money);
     MyPlayer.Money -= money;
     return(true);
 }
Example #2
0
 public bool DeductCoin(int coin)
 {
     if (MyPlayer.Coin < coin)
     {
         return(false);
     }
     PlayerAchievementLogic.GetInstance(MyPlayer.Id).UpdateAchievement(AchievementType.CostedCoin, coin);
     MyPlayer.Coin -= coin;
     return(true);
 }
Example #3
0
 public void ElevationLevelUp()
 {
     m_MyHeros.ModifyLocked(() =>
     {
         m_Hero.ElevationLevel += 1;
     });
     PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.HeroElevationLevel, m_Hero.ElevationLevel);
     AnnouncementLogic.PushHeroElevationAnnouncement(m_UserId, m_Hero.ElevationLevel, m_Hero.HeroType);
     RefreshMight();
 }
        public static PlayerAchievementLogic GetInstance(int userId)
        {
            if (m_Instances.ContainsKey(userId) && m_Instances[userId] != null)
            {
                return(m_Instances[userId]);
            }
            PlayerAchievementLogic pa = new PlayerAchievementLogic(userId);

            m_Instances.Add(userId, pa);
            return(pa);
        }
Example #5
0
 public int AddNewGear(int gearTypeId, int userId, ReceiveItemMethodType method)
 {
     m_Gear                 = new Gears();
     m_Gear.Id              = (int)CacheSet.GearCache.GetNextNo();
     m_Gear.TypeId          = gearTypeId;
     m_Gear.Level           = 1;
     m_Gear.StrengthenLevel = 0;
     CacheSet.GearCache.Add(m_Gear);
     PlayerAchievementLogic.GetInstance(userId).UpdateAchievement(AchievementType.GearQuality, m_Gear.Quality);
     AnnouncementLogic.PushReceiveGearAnnouncement(userId, method, m_Gear.TypeId);
     return(m_Gear.Id);
 }
Example #6
0
        public void AddExp(int exp, int playerLevel)
        {
            int newExp;
            int newLevel = GetNewLevel(exp, playerLevel, out newExp);

            PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.HeroLevel, newLevel);
            m_MyHeros.ModifyLocked(() =>
            {
                m_Hero.HeroExp = newExp;
                m_Hero.HeroLv  = newLevel;
            });
        }
Example #7
0
 public void ConsciousnessLevelUp()
 {
     if (m_Hero.HeroStarLevel >= GameConsts.Hero.MaxConsciousnessLevel)
     {
         return;
     }
     m_MyHeros.ModifyLocked(() =>
     {
         m_Hero.ConsciousnessLevel += 1;
     });
     PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.HeroConsiousnessLevel, m_Hero.ConsciousnessLevel);
     AnnouncementLogic.PushHeroConsciousnessAnnouncement(m_UserId, m_Hero.ConsciousnessLevel, m_Hero.HeroType);
     RefreshMight();
 }
Example #8
0
        public Dictionary <int, DropItem> OpenAllChance()
        {
            Dictionary <int, DropItem> dropItems = new Dictionary <int, DropItem>();
            var dataRow = CacheSet.ChanceCostTable.GetData(m_Chance.OpenedChanceRewards.Count + 1);

            if (dataRow == null)
            {
                return(null);
            }
            PlayerLogic p = new PlayerLogic();

            p.SetUser(m_UserId);
            switch (m_Type)
            {
            case ChanceType.Coin:
                if (!p.DeductCoin(dataRow.CoinCostAll))
                {
                    return(null);
                }
                AnnouncementLogic.PushOpenTenCoinChanceAnnouncement(m_UserId);
                break;

            case ChanceType.Money:
                if (!p.DeductMoney(dataRow.MoneyCostAll))
                {
                    return(null);
                }
                AnnouncementLogic.PushOpenTenMoneyChanceAnnouncement(m_UserId);
                PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, m_Chance.UnopenedChanceRewards.Count);
                break;

            default:
                return(null);
            }
            int i = 0;

            foreach (var item in m_Chance.UnopenedChanceRewards)
            {
                while (m_Chance.OpenedChanceRewards.ContainsKey(i))
                {
                    i++;
                }
                m_Chance.OpenedChanceRewards.Add(i, item.Value.Clone() as DropItem);
                dropItems.Add(i, item.Value);
                i++;
            }
            m_Chance.UnopenedChanceRewards.Clear();
            return(dropItems);
        }
Example #9
0
        private void SetAchivementInfo()
        {
            var pa = PlayerAchievementLogic.GetInstance(m_UserId);

            m_ResponsePacket.AchievementInfo = new PBAchievementInfo();
            foreach (var trackingAchievement in pa.TrackingAchievements)
            {
                m_ResponsePacket.AchievementInfo.TrackingAchievements.Add(new PBTrackingAchievement()
                {
                    AchievementId = trackingAchievement.Value.Id,
                    ProgressCount = trackingAchievement.Value.Progress
                });
            }
            m_ResponsePacket.AchievementInfo.CompletedAchievements.AddRange(pa.CompletedAchievements);
        }
Example #10
0
        public void RefreshMight()
        {
            int   oldMight      = m_Hero.Might;
            var   atkData       = CacheSet.MightLevelParamTable.GetData(m_Hero.HeroLv);
            float physicalA_Atk = atkData.PhysicalAttack * atkData.PhysicalAttack / (atkData.PhysicalAttack + m_Hero.PhysicalDefense);
            float magicalA_Atk  = atkData.MagicAttack * atkData.MagicAttack / (atkData.MagicAttack + m_Hero.MagicDefense);
            //attack relate might
            float basePhysicalAtk    = m_Hero.PhysicalAttack * m_Hero.PhysicalAttack / (m_Hero.PhysicalAttack + atkData.PhysicalDefense * (1 - m_Hero.OppPhysicalDfsReduceRate));
            float baseMagicAtk       = m_Hero.MagicAttack * m_Hero.MagicAttack / (m_Hero.MagicAttack + atkData.MagicDefense * (1 - m_Hero.OppMagicDfsReduceRate));
            float baseAtk            = basePhysicalAtk + baseMagicAtk;
            float cooldownAtk        = baseAtk * m_Hero.ReducedSkillCoolDownRate * 1000;
            float waitingAtk         = baseAtk * m_Hero.ReduceSwitchHeroCoolDownRate * 1000;
            float criticalAtk        = baseAtk * m_Hero.CriticalHitRate * m_Hero.CriticalHitProb * 10000;
            float physicalReflectAtk = physicalA_Atk * m_Hero.PhysicalAtkReflectRate * 100;
            float magicalReflectAtk  = magicalA_Atk * m_Hero.MagicAtkReflectRate * 100;
            float skillAtk           = 50;
            //             for (int i = 0; i < m_Hero.SkillLevels.Count; i++)
            //             {
            //                 DTSkillLevelUp skillData = CacheSet.SkillLevelUpTable.GetData(h => (h.HeroType == m_Hero.HeroType && h.SkillIndex == i && h.SkillLevel == m_Hero.SkillLevels[i]));
            //                 skillAtk += 10;//skillData.MightParam;
            //             }
            float atkMight = baseAtk + cooldownAtk + waitingAtk + criticalAtk + physicalReflectAtk + magicalReflectAtk + m_Hero.AdditionalDamage + skillAtk;
            //HP related might
            float baseHP            = m_Hero.MaxHP;
            float defenseHP         = (m_Hero.PhysicalDefense + m_Hero.MagicDefense) * 6;
            float antiCriticalHitHP = (physicalA_Atk + magicalA_Atk) * (1 - m_Hero.AntiCriticalHitProb);
            float RecoverHP         = m_Hero.RecoverHP * 0.1f;
            float damageReduceHP    = (m_Hero.PhysicalDefense + m_Hero.MagicDefense) * (1 - m_Hero.DamageReductionRate);
            float physicalAbsorbHP  = basePhysicalAtk * m_Hero.PhysicalAtkHPAbsorbRate * 100;
            float magicalAbsorbHP   = baseMagicAtk * m_Hero.MagicAtkHPAbsorbRate * 100;
            float hpMight           = baseHP + defenseHP - antiCriticalHitHP + RecoverHP - damageReduceHP + physicalAbsorbHP + magicalAbsorbHP;
            int   might             = Mathf.RoundToInt(atkMight * hpMight / (atkMight + hpMight));

            m_Hero.Might = might;
//             TraceLog.WriteError("Calculating user:{0}->hero:{1} might:\nMaxHP => {2}\nPhysicalAttack => {3}\nMagicalAttack => {4}\nPhysicalDefense => {5}\nMagicalDefense=>{6}\n" +
//                 "OppPhysicalDfsReduceRate => {7}\nOppMagicDfsReduceRate => {8}\nPhysicalAtkHPAbsorbRate => {9}\nMagicAtkHPAbsorbRate => {10}\nPhysicalAtkReflectRate => {11}\n" +
//                 "MagicAtkReflectRate => {12}\nDamageReductionRate => {13}\nReducedSkillCoolDownRate => {14}\nReduceSwitchHeroCoolDownRate => {15}\nCriticalHitProb => {16}\n" +
//                 "CriticalHitRate => {17}\nAntiCriticalHitProb => {18}\nAdditionalDamage => {19}\nRecoverHP => {20}\nBaseAtk => {21}\nAtkMight => {22}\nHPMight => {23}", m_UserId, m_HeroId, m_Hero.MaxHP, m_Hero.PhysicalAttack, m_Hero.MagicAttack,
//                 m_Hero.PhysicalDefense, m_Hero.MagicDefense, m_Hero.OppPhysicalDfsReduceRate, m_Hero.OppMagicDfsReduceRate, m_Hero.PhysicalAtkHPAbsorbRate, m_Hero.MagicAtkHPAbsorbRate,
//                 m_Hero.PhysicalAtkReflectRate, m_Hero.MagicAtkReflectRate, m_Hero.DamageReductionRate, m_Hero.ReducedSkillCoolDownRate, m_Hero.ReduceSwitchHeroCoolDownRate,
//                 m_Hero.CriticalHitProb, m_Hero.CriticalHitRate, m_Hero.AntiCriticalHitProb, m_Hero.AdditionalDamage, m_Hero.RecoverHP, baseAtk, atkMight, hpMight);
            PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.HeroMight, m_Hero.Might);
            AnnouncementLogic.PushHeroMightAnnouncement(m_UserId, oldMight, might, m_Hero.HeroType);
            PlayerLogic p = new PlayerLogic();

            p.SetUser(m_UserId);
            p.RefreshMight();
        }
Example #11
0
 public void InstanceCompleted(int instanceId, int stars)
 {
     if (m_InstanceProgress.Progress.ContainsKey(instanceId))
     {
         if (m_InstanceProgress.Progress[instanceId] < stars)
         {
             m_InstanceProgress.Progress[instanceId] = stars;
         }
     }
     else
     {
         m_InstanceProgress.Progress.Add(instanceId, stars);
         PlayerAchievementLogic.GetInstance(m_InstanceProgress.UserId).UpdateAchievement(AchievementType.InstanceCompletedCount);
     }
     PlayerDailyQuestLogic.GetInstance(m_InstanceProgress.UserId).UpdateDailyQuest(DailyQuestType.CompleteInstance, 1);
 }
Example #12
0
        public void AddLevel(int level)
        {
            if (CacheSet.PlayerTable.GetData(MyPlayer.Level + level) == null)
            {
                return;
            }
            else
            {
                MyPlayer.Level += level;
            }
            var pa = PlayerAchievementLogic.GetInstance(MyPlayer.Id);

            pa.UpdateAchievement(AchievementType.PlayerLevel, MyPlayer.Level);
            pa.OpenNewAchievement(MyPlayer.Level);
            AnnouncementLogic.PushLevelUpAnnouncement(MyPlayer.Id, MyPlayer.Level);
            MyPlayer.Exp = 0;
        }
Example #13
0
        public bool Strengthen(int userId)
        {
            if (m_Gear.StrengthenLevel >= GameConsts.Gear.MaxStrengthenLevel)
            {
                return(false);
            }
            Random r = new Random();

            if (r.Next(100) > GameConsts.Gear.StrengthenSuccessRate[m_Gear.Quality][m_Gear.StrengthenLevel])
            {
                return(false);
            }
            PlayerAchievementLogic.GetInstance(userId).UpdateAchievement(AchievementType.GearLevel, m_Gear.StrengthenLevel, m_Gear.StrengthenLevel + 1);
            m_Gear.StrengthenLevel += 1;
            AnnouncementLogic.PushGearStrengthenAnnouncement(userId, m_Gear.StrengthenLevel, m_Gear.TypeId);
            return(true);
        }
Example #14
0
        public void AddExp(int exp)
        {
            int newExp;
            int newLevel = GetNewLevel(exp, out newExp);

            if (newLevel > MyPlayer.Level)
            {
                var pa = PlayerAchievementLogic.GetInstance(MyPlayer.Id);
                pa.UpdateAchievement(AchievementType.PlayerLevel, newLevel);
                pa.OpenNewAchievement(newLevel);
            }
            MyPlayer.ModifyLocked(() =>
            {
                MyPlayer.Exp   = newExp;
                MyPlayer.Level = newLevel;
            });
        }
Example #15
0
        public override bool TakeAction()
        {
            var pa = PlayerAchievementLogic.GetInstance(m_UserId);
            TrackingAchievement nextAchievement;
            PackageFullReason   reason;
            var RewardItems = pa.CompleteAchievement(m_RequestPacket.AchievementId, out nextAchievement);

            if (RewardItems == null)
            {
                ErrorCode = (int)ErrorType.RequireNotMet;
                ErrorInfo = "You can not claim this achievement";
                return(false);
            }
            PlayerPackageLogic pp = new PlayerPackageLogic();

            pp.SetUser(m_UserId);
            PBReceivedItems receivedItems;

            pp.GetItems(RewardItems, ReceiveItemMethodType.None, out receivedItems);
            m_ResponsePacket.ReceivedItems = receivedItems;
            if (nextAchievement != null)
            {
                m_ResponsePacket.NextTrackingAchievement = new PBTrackingAchievement()
                {
                    AchievementId = nextAchievement.Id,
                    ProgressCount = nextAchievement.Progress,
                };
            }
            PlayerLogic p = new PlayerLogic();

            p.SetUser(m_UserId);

            m_ResponsePacket.PlayerInfo = new PBPlayerInfo()
            {
                Id     = p.MyPlayer.Id,
                Exp    = p.MyPlayer.Exp,
                Level  = p.MyPlayer.Level,
                Coin   = p.MyPlayer.Coin,
                Money  = p.MyPlayer.Money,
                Spirit = p.MyPlayer.Spirit
            };
            m_ResponsePacket.AchievementId = m_RequestPacket.AchievementId;
            return(true);
        }
Example #16
0
        public bool EndBattle(int enemyId, bool isWin, bool isRevenge, out int token)
        {
            int userId = m_UserId;

            token = 0;
            if (isRevenge)
            {
                SetUser(enemyId);
                AddBattleReport(userId, false, !isWin);
                SetUser(userId);
                return(true);
            }
            if (m_Arena.EnemyId <= 0)
            {
                SetUser(enemyId);
                m_Arena.EnemyId = 0;
                SetUser(userId);
                return(false);
            }

            SetUser(enemyId);
            if (m_Arena.EnemyId <= 0)
            {
                SetUser(userId);
                m_Arena.EnemyId = 0;
                return(false);
            }
            token           = GetTokenCount(isWin);
            m_Arena.EnemyId = 0;
            AddBattleReport(userId, false, !isWin);
            SetUser(userId);
            if (isWin)
            {
                ArenaRankLogic ar = new ArenaRankLogic();
                ar.SwapRank(userId, enemyId);
                m_Arena.WinCount += 1;
                PlayerAchievementLogic.GetInstance(userId).UpdateAchievement(AchievementType.PvpWinCount);
            }
            m_Arena.ArenaTokenCount += token;
            m_Arena.EnemyId          = 0;
            AddBattleReport(enemyId, true, isWin);
            PlayerDailyQuestLogic.GetInstance(m_UserId).UpdateDailyQuest(DailyQuestType.CompleteOfflineArena, 1);
            return(true);
        }
Example #17
0
        public void AddLevel(int addLevel)
        {
            PlayerLogic player = new PlayerLogic();

            player.SetUser(m_UserId);
            int oldLevel = m_Hero.HeroLv;

            if (m_Hero.HeroLv + addLevel > player.MyPlayer.Level)
            {
                m_Hero.HeroLv = player.MyPlayer.Level;
            }
            else
            {
                m_Hero.HeroLv += addLevel;
            }
            PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.HeroLevel, m_Hero.HeroLv);
            RefreshMight();
            m_Hero.HeroExp = 0;
        }
Example #18
0
        public ItemListItem AddNewHero(int heroId, ReceiveItemMethodType method = ReceiveItemMethodType.None)
        {
            Hero playerHero;
            var  HeroData = CacheSet.HeroTable.GetData(heroId);

            if (m_MyHeros.Heros.TryGetValue(heroId, out playerHero))
            {
                int          itemId = HeroData.StarLevelUpItemId;
                ItemListItem item   = new ItemListItem()
                {
                    Id    = itemId,
                    Count = GameConfigs.GetInt("Hero_Piece_Count_For_Star_Level_" + HeroData.DefaultStarLevel, 10)
                };
                return(item);
            }
            else
            {
                Hero hero = new Hero();
                int  star = HeroData.DefaultStarLevel;//TODO read config
                hero.HeroType           = heroId;
                hero.HeroExp            = 0;
                hero.HeroLv             = 1;
                hero.HeroStarLevel      = star;
                hero.ConsciousnessLevel = 0;
                hero.ElevationLevel     = 0;
                m_HeroId = heroId;
                hero.SkillLevels.AddRange(new int[] { 1, 1, 1, 1, 1, 0, 0, 0, 0, 1 });
                hero.SkillExps.AddRange(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
                m_MyHeros.ModifyLocked(() =>
                {
                    m_MyHeros.Heros[heroId] = hero;
                    m_Hero = m_MyHeros.Heros[heroId];
                    RefreshMight();
                });
                PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.HeroCount, MyHeros.Heros.Count);
                AnnouncementLogic.PushReceiveHeroAnnouncement(m_UserId, method, hero.HeroType);
            }
            return(null);
        }
Example #19
0
 public bool AddFriend(int userId, int friendId)
 {
     if (!CheckFriend(userId, friendId))
     {
         return(false);
     }
     if (m_Friends.RemovedFriends.ContainsKey(friendId))
     {
         m_Friends.Friends.Add(friendId, (Friend)m_Friends.RemovedFriends[friendId].Clone());
         m_Friends.RemovedFriends.Remove(friendId);
     }
     else
     {
         Friend f1 = new Friend();
         f1.CanReceiveEnergy = false;
         f1.CanSendEnergy    = true;
         m_Friends.Friends.Add(friendId, f1);
     }
     SetUser(friendId);
     PlayerAchievementLogic.GetInstance(friendId).UpdateAchievement(AchievementType.FriendCount);
     if (m_Friends.RemovedFriends.ContainsKey(userId))
     {
         m_Friends.Friends.Add(userId, (Friend)m_Friends.RemovedFriends[userId].Clone());
         m_Friends.RemovedFriends.Remove(userId);
     }
     else
     {
         Friend f2 = new Friend();
         f2.CanReceiveEnergy = false;
         f2.CanSendEnergy    = true;
         m_Friends.Friends.Add(userId, f2);
     }
     SetUser(userId);
     PlayerAchievementLogic.GetInstance(userId).UpdateAchievement(AchievementType.FriendCount);
     return(true);
 }
Example #20
0
        public DropItem OpenChance(int index, bool isFree)
        {
            if (isFree)
            {
                if (DateTime.UtcNow.Ticks < m_Chance.NextFreeTime)
                {
                    return(null);
                }
                switch (m_Type)
                {
                case ChanceType.Coin:
                    PlayerCoinChance coinChance = m_Chance as PlayerCoinChance;
                    if (coinChance.TotalFreeCount >= GameConsts.Chance.MaxFreeCountForCoinChance)
                    {
                        return(null);
                    }
                    coinChance.TotalFreeCount += 1;
                    m_Chance.NextFreeTime      = DateTime.UtcNow.AddSeconds(GameConsts.Chance.FreeCoinChanceCDSeconds).Ticks;
                    break;

                case ChanceType.Money:
                    m_Chance.NextFreeTime = DateTime.UtcNow.AddSeconds(GameConsts.Chance.FreeMoneyChanceCDSeconds).Ticks;
                    PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, 1);
                    break;

                default:
                    return(null);
                }
            }
            else
            {
                var         dataRow = CacheSet.ChanceCostTable.GetData(m_Chance.OpenedChanceRewards.Count + 1);
                PlayerLogic p       = new PlayerLogic();
                p.SetUser(m_UserId);
                switch (m_Type)
                {
                case ChanceType.Coin:
                    if (!p.DeductCoin(dataRow.CoinCost))
                    {
                        return(null);
                    }
                    break;

                case ChanceType.Money:
                    if (!p.DeductMoney(dataRow.MoneyCost))
                    {
                        return(null);
                    }
                    PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, 1);
                    break;

                default:
                    return(null);
                }
            }

            RandomDropLogic random = RandomDropLogic.GetInstance();
            int             id     = random.OpenChanceBox(m_Chance.UnopenedChanceRewards);
            DropItem        di     = m_Chance.UnopenedChanceRewards[id];

            try
            {
                m_Chance.OpenedChanceRewards.Add(index, di.Clone() as DropItem);
            }
            catch
            {
                return(null);
            }
            m_Chance.UnopenedChanceRewards.Remove(id);
            return(di);
        }
Example #21
0
 public void GearLevelUp(int targetLevel, int userId)
 {
     PlayerAchievementLogic.GetInstance(userId).UpdateAchievement(AchievementType.GearLevel, m_Gear.Level, targetLevel);
     m_Gear.Level = targetLevel;
 }