예제 #1
0
        public void HandleChallengeDamagePacket(Client client, Packet packet)
        {
            C2SChallengeDamagePacket challengeDamagePacket = new C2SChallengeDamagePacket(packet);

            ((ChallengeBattleGame)client.ActiveChallengeGame).SetHp(challengeDamagePacket.Player,
                                                                    challengeDamagePacket.Hp);

            if (((ChallengeBattleGame)client.ActiveChallengeGame).Finished)
            {
                bool win        = ((ChallengeBattleGame)client.ActiveChallengeGame).PlayerHp > 0;
                int  timeNeeded = (((ChallengeBattleGame)client.ActiveChallengeGame).EndTime
                                   - ((ChallengeBattleGame)client.ActiveChallengeGame).StartTime).Seconds;

                S2CChallengeFinishPacket challengeFinishPacket = new S2CChallengeFinishPacket(win, 1, 1, 2, timeNeeded, new List <ItemReward>());
                client.PacketStream.Write(challengeFinishPacket);

                ChallengeProgress challengeProgress = new ChallengeProgress();
                challengeProgress.CharacterId = client.ActiveCharacter.CharacterId;
                challengeProgress.ChallengeId = client.ActiveChallengeGame.ChallengeId;
                challengeProgress.Success    += Convert.ToInt16(win);
                challengeProgress.Attempts   += 1;

                var dbChallengeProgressContext = client.DatabaseContext.ChallengeProgress.Find(new object[]
                                                                                               { challengeProgress.CharacterId, challengeProgress.ChallengeId });

                if (dbChallengeProgressContext == null)
                {
                    client.DatabaseContext.ChallengeProgress.Add(challengeProgress);
                }
                else
                {
                    dbChallengeProgressContext.Success  = challengeProgress.Success;
                    dbChallengeProgressContext.Attempts = challengeProgress.Attempts;
                    client.DatabaseContext.ChallengeProgress.Update(dbChallengeProgressContext);
                }

                client.DatabaseContext.SaveChanges();
                client.ActiveChallengeGame = null;

                List <ChallengeProgress> challengeProgressList = client.DatabaseContext.ChallengeProgress
                                                                 .Where(q => q.CharacterId == client.Account.Characters[0].CharacterId).ToList();

                client.ActiveCharacter.ChallengeProgress = challengeProgressList;
                S2CChallengeProgressAnswerPacket challengeProgressAnswerPacket = new S2CChallengeProgressAnswerPacket(challengeProgressList);
                client.PacketStream.Write(challengeProgressAnswerPacket);
            }
        }
예제 #2
0
        public void HandleTutorialEndPacket(Client client, Packet packet)
        {
            C2STutorialEndPacket     tutorialEndPacket     = new C2STutorialEndPacket(packet);
            S2CChallengeFinishPacket challengeFinishPacket = new S2CChallengeFinishPacket(true, 1, 1, 2, 10, new List <ItemReward>());

            client.PacketStream.Write(challengeFinishPacket);

            TutorialProgress tutorialProgress = new TutorialProgress();

            tutorialProgress.CharacterId = client.ActiveCharacter.CharacterId;
            tutorialProgress.TutorialId  = tutorialEndPacket.TutorialId;
            tutorialProgress.Success    += Convert.ToInt16(1);
            tutorialProgress.Attempts   += 1;

            var dbTutorialProgressContext = client.DatabaseContext.TutorialProgress.Find(new object[]
                                                                                         { tutorialProgress.CharacterId, tutorialProgress.TutorialId });

            if (dbTutorialProgressContext == null)
            {
                client.DatabaseContext.TutorialProgress.Add(tutorialProgress);
            }
            else
            {
                dbTutorialProgressContext.Success  = tutorialProgress.Success;
                dbTutorialProgressContext.Attempts = tutorialProgress.Attempts;
                client.DatabaseContext.TutorialProgress.Update(dbTutorialProgressContext);
            }

            client.DatabaseContext.SaveChanges();

            List <TutorialProgress> tutorialProgressList = client.DatabaseContext.TutorialProgress
                                                           .Where(q => q.CharacterId == client.Account.Characters[0].CharacterId).ToList();

            client.ActiveCharacter.TutorialProgress = tutorialProgressList;
            S2CTutorialProgressAnswerPacket tutorialProgressAnswerPacket = new S2CTutorialProgressAnswerPacket(tutorialProgressList);

            client.PacketStream.Write(tutorialProgressAnswerPacket);
        }