示例#1
0
        public void DistributeReward(string userId)
        {
            var user        = db.Users.Find(userId);
            var wildBattle  = db.WildBattles.First(wb => wb.UserId == userId);
            var currentLand = db.CurrentLands.First(cl => cl.UserId == userId);

            foreach (var wildBattleAction in wildBattle.WildBattleActions.Where(wb => wb.CaptureSuccess == true))
            {
                db.UserCreatures.Add(new UserCreature
                {
                    CreatureId = wildBattleAction.Defender.CreatureId,
                    Level      = wildBattleAction.Defender.Level,
                    UserId     = userId
                });
            }

            var experienceService = new ExperienceService();

            if (user.ClearedLands.Any(cl => cl.LandId == currentLand.LandId))
            {
                wildBattle.GoldEarned = (wildBattle.Stage.GoldReward / 2);
                wildBattle.XpEarned   = (wildBattle.Stage.XpReward / 2);

                user.Gold += (wildBattle.Stage.GoldReward / 2);
                experienceService.AddXp(userId, (wildBattle.Stage.XpReward / 2));
            }

            else
            {
                wildBattle.GoldEarned = wildBattle.Stage.GoldReward;
                wildBattle.XpEarned   = wildBattle.Stage.XpReward;

                user.Gold += wildBattle.Stage.GoldReward;
                experienceService.AddXp(userId, wildBattle.Stage.XpReward);
            }

            db.SaveChanges();
        }
示例#2
0
        public void DistributeReward(int battleId)
        {
            var battle = db.Battles.Find(battleId);

            var winner = battle.Competitors.First(c => c.Winner);
            var loser  = battle.Competitors.First(c => !c.Winner);

            int rankDifference = winner.User.LadderPoints - loser.User.LadderPoints;

            int winnerRankingPoints = 0;
            int winnerGold          = 0;
            int winnerXp            = 0;

            int loserRankingPoints = 0;
            int loserGold          = 0;
            int loserXp            = 0;

            if (rankDifference < -300)
            {
                winnerRankingPoints = 15;
                winnerGold          = 14;
                winnerXp            = 18;

                loserRankingPoints = -12;
                loserGold          = 3;
                loserXp            = 4;
            }

            else if (rankDifference < -200)
            {
                winnerRankingPoints = 12;
                winnerGold          = 12;
                winnerXp            = 16;

                loserRankingPoints = -9;
                loserGold          = 4;
                loserXp            = 5;
            }

            else if (rankDifference >= -100 && rankDifference <= 100)
            {
                winnerRankingPoints = 9;
                winnerGold          = 10;
                winnerXp            = 14;

                loserRankingPoints = -6;
                loserGold          = 6;
                loserXp            = 7;
            }

            else if (rankDifference < 200)
            {
                winnerRankingPoints = 6;
                winnerGold          = 8;
                winnerXp            = 12;

                loserRankingPoints = -4;
                loserGold          = 7;
                loserXp            = 8;
            }

            else if (rankDifference < 300)
            {
                winnerRankingPoints = 3;
                winnerGold          = 7;
                winnerXp            = 10;

                loserRankingPoints = -2;
                loserGold          = 7;
                loserXp            = 9;
            }

            else
            {
                winnerRankingPoints = 1;
                winnerGold          = 6;
                winnerXp            = 9;

                loserRankingPoints = -1;
                loserGold          = 6;
                loserXp            = 9;
            }

            winner.User.Battles++;
            winner.User.Wins++;
            winner.GoldEarned          = winnerGold;
            winner.User.Gold          += winnerGold;
            winner.RankingPointsEarned = winnerRankingPoints;
            winner.User.LadderPoints  += winnerRankingPoints;
            winner.XpEarned            = winnerXp;

            loser.User.Battles++;
            loser.User.Losses++;
            loser.GoldEarned          = loserGold;
            loser.User.Gold          += loserGold;
            loser.XpEarned            = loserXp;
            loser.RankingPointsEarned = loserRankingPoints;

            if (loser.User.LadderPoints + loserRankingPoints >= 0)
            {
                loser.User.LadderPoints += loserRankingPoints;
            }

            else
            {
                loser.User.LadderPoints = 0;
            }

            var experienceService = new ExperienceService();

            experienceService.AddXp(winner.UserId, winnerXp);
            experienceService.AddXp(loser.UserId, loserXp);

            db.SaveChanges();
        }
示例#3
0
        public void RunBattle()
        {
            var battle = db.Battles.Find(battleId);

            var challengerCompetitor = battle.Competitors.First(c => c.Challenger);
            var receiverCompetitor   = battle.Competitors.First(c => !c.Challenger);

            //var challengerCharacters = challengerCompetitor.BattleCharacters;
            //var receiverCharacters = receiverCompetitor.BattleCharacters;

            //Så länge båda tävlande har Hp kvar...
            while (challengerCompetitor.TotalHp > 0 && receiverCompetitor.TotalHp > 0)
            {
                //så plockar vi fram första karatären i båda lagen som lever.
                var challengerCharacter = challengerCompetitor.BattleCharacters.First(ct => ct.Alive);
                var receiverCharacter   = receiverCompetitor.BattleCharacters.First(rt => rt.Alive);

                //Så länge båda av dom lever...
                while (challengerCharacter.Alive && receiverCharacter.Alive)
                {
                    int damage = Convert.ToInt32(CalculateDamage(challengerCharacter.Id, receiverCharacter.Id));

                    db.Attacks.Add(new Attack
                    {
                        BattleId    = battleId,
                        AttackerId  = challengerCharacter.Id,
                        DefenderId  = receiverCharacter.Id,
                        Damage      = damage,
                        HpRemaining = receiverCharacter.Hp - damage,
                        Effect      = effect
                    });

                    receiverCharacter.Hp -= damage;

                    if (receiverCharacter.Alive)
                    {
                        damage = Convert.ToInt32(CalculateDamage(receiverCharacter.Id, challengerCharacter.Id));

                        db.Attacks.Add(new Attack
                        {
                            BattleId    = battleId,
                            AttackerId  = receiverCharacter.Id,
                            DefenderId  = challengerCharacter.Id,
                            Damage      = damage,
                            HpRemaining = challengerCharacter.Hp - damage,
                            Effect      = effect
                        });

                        challengerCharacter.Hp -= damage;
                    }

                    //else if han har någon annan gubbe som lever
                }

                var experienceService = new ExperienceService();
                experienceService.CalculateXp
                (
                    challengerCompetitor.User.TeamMembers.First(tm => tm.CharacterId == challengerCharacter.CharacterId).Id,
                    receiverCompetitor.User.TeamMembers.First(tm => tm.CharacterId == receiverCharacter.CharacterId).Id,
                    challengerCharacter.Alive
                );
            }

            if (receiverCompetitor.TotalHp > 0)
            {
                receiverCompetitor.Winner = true;
            }

            else
            {
                challengerCompetitor.Winner = true;
            }

            db.SaveChanges();

            var rewardService = new RewardService();

            rewardService.DistributeReward(battleId);
        }