예제 #1
0
        protected override IBuffer ToBuffer()
        {
            IBuffer res = BufferProvider.Provide();

            res.WriteInt16(_character.level);                                                               // level
            res.WriteUInt64(_experience.CalculateLevelUp((uint)_character.level - 1).cumulativeExperience); // exp start
            res.WriteUInt64(_experience.CalculateLevelUp((uint)_character.level - 0).cumulativeExperience); // exp next
            res.WriteUInt64(_experience.CalculateLevelUp((uint)_character.level + 1).cumulativeExperience); // exp next 2
            return(res);
        }
        private void LevelUpCheck(NecClient client)
        {
            Experience experience = new Experience();

            Task.Delay(TimeSpan.FromSeconds(1)).ContinueWith
                (t1 =>
            {
                while (client.character.experienceCurrent > experience.CalculateLevelUp((uint)client.character.level + 1).cumulativeExperience)
                {
                    client.character.level++;
                    client.character.skillPoints += 1;
                    client.character.hp.SetMax(client.character.hp.max + 10);
                    client.character.mp.SetMax(client.character.mp.max + 10);
                    client.character.strength     += (ushort)Util.GetRandomNumber(0, 2);
                    client.character.vitality     += (ushort)Util.GetRandomNumber(0, 2);
                    client.character.dexterity    += (ushort)Util.GetRandomNumber(0, 2);
                    client.character.agility      += (ushort)Util.GetRandomNumber(0, 2);
                    client.character.intelligence += (ushort)Util.GetRandomNumber(0, 2);
                    client.character.piety        += (ushort)Util.GetRandomNumber(0, 2);
                    client.character.luck         += (ushort)Util.GetRandomNumber(0, 2);
                    int luckyShot = Util.GetRandomNumber(0, client.character.luck);
                    if (luckyShot > client.character.luck * .8)
                    {
                        client.character.hp.SetMax(client.character.hp.max + 10);
                        client.character.mp.SetMax(client.character.mp.max + 10);
                        client.character.strength     = (ushort)(Util.GetRandomNumber(-2, 2) + client.character.strength);
                        client.character.vitality     = (ushort)(Util.GetRandomNumber(-2, 2) + client.character.vitality);
                        client.character.dexterity    = (ushort)(Util.GetRandomNumber(-2, 2) + client.character.dexterity);
                        client.character.agility      = (ushort)(Util.GetRandomNumber(-2, 2) + client.character.agility);
                        client.character.intelligence = (ushort)(Util.GetRandomNumber(-2, 2) + client.character.intelligence);
                        client.character.piety        = (ushort)(Util.GetRandomNumber(-2, 2) + client.character.piety);
                        client.character.luck         = (ushort)(Util.GetRandomNumber(-2, 2) + client.character.luck);
                    }
                    client.character.hp.ToMax();

                    RecvCharaUpdateLvDetailStart recvCharaUpdateLvDetailStart = new RecvCharaUpdateLvDetailStart();
                    RecvCharaUpdateLv recvCharaUpdateLv                   = new RecvCharaUpdateLv(client.character);
                    RecvCharaUpdateLvDetail recvCharaUpdateLvDetail       = new RecvCharaUpdateLvDetail(client.character, experience);
                    RecvCharaUpdateLvDetail2 recvCharaUpdateLvDetail2     = new RecvCharaUpdateLvDetail2(client.character, experience);
                    RecvCharaUpdateLvDetailEnd recvCharaUpdateLvDetailEnd = new RecvCharaUpdateLvDetailEnd();

                    RecvSelfSkillPointNotify recvSelfSkillPointNotify = new RecvSelfSkillPointNotify(client.character.skillPoints);
                    RecvCharaUpdateMaxHp recvCharaUpdateMaxHp         = new RecvCharaUpdateMaxHp(client.character.hp.max);
                    RecvCharaUpdateMaxMp recvCharaUpdateMaxMp         = new RecvCharaUpdateMaxMp(client.character.mp.max);
                    RecvCharaUpdateHp recvCharaUpdateHp = new RecvCharaUpdateHp(client.character.hp.max);
                    RecvCharaUpdateMp recvCharaUpdateMp = new RecvCharaUpdateMp(client.character.mp.max);
                    RecvCharaUpdateAbility recvCharaUpdateAbilityStr = new RecvCharaUpdateAbility((int)RecvCharaUpdateAbility.Ability.Str, client.character.strength, client.character.battleParam.plusStrength);
                    RecvCharaUpdateAbility recvCharaUpdateAbilityVit = new RecvCharaUpdateAbility((int)RecvCharaUpdateAbility.Ability.Vit, client.character.vitality, client.character.battleParam.plusVitality);
                    RecvCharaUpdateAbility recvCharaUpdateAbilityDex = new RecvCharaUpdateAbility((int)RecvCharaUpdateAbility.Ability.Dex, client.character.dexterity, client.character.battleParam.plusDexterity);
                    RecvCharaUpdateAbility recvCharaUpdateAbilityAgi = new RecvCharaUpdateAbility((int)RecvCharaUpdateAbility.Ability.Agi, client.character.agility, client.character.battleParam.plusAgility);
                    RecvCharaUpdateAbility recvCharaUpdateAbilityInt = new RecvCharaUpdateAbility((int)RecvCharaUpdateAbility.Ability.Int, client.character.intelligence, client.character.battleParam.plusIntelligence);
                    RecvCharaUpdateAbility recvCharaUpdateAbilityPie = new RecvCharaUpdateAbility((int)RecvCharaUpdateAbility.Ability.Pie, client.character.piety, client.character.battleParam.plusPiety);
                    RecvCharaUpdateAbility recvCharaUpdateAbilityLuk = new RecvCharaUpdateAbility((int)RecvCharaUpdateAbility.Ability.Luk, client.character.luck, client.character.battleParam.plusLuck);

                    router.Send(recvCharaUpdateLvDetailStart, client);


                    router.Send(recvSelfSkillPointNotify, client);
                    router.Send(recvCharaUpdateMaxHp, client);
                    router.Send(recvCharaUpdateMaxMp, client);
                    router.Send(recvCharaUpdateHp, client);
                    router.Send(recvCharaUpdateMp, client);
                    router.Send(recvCharaUpdateAbilityStr, client);
                    router.Send(recvCharaUpdateAbilityVit, client);
                    router.Send(recvCharaUpdateAbilityDex, client);
                    router.Send(recvCharaUpdateAbilityAgi, client);
                    router.Send(recvCharaUpdateAbilityInt, client);
                    router.Send(recvCharaUpdateAbilityPie, client);
                    router.Send(recvCharaUpdateAbilityLuk, client);

                    router.Send(recvCharaUpdateLv, client);
                    router.Send(recvCharaUpdateLvDetail, client);
                    router.Send(recvCharaUpdateLvDetail2, client);
                    router.Send(recvCharaUpdateLvDetailEnd, client);
                }
            }
                );
        }
        private void ResolveInn(NecClient client, int objectId, NpcSpawn npcSpawn)
        {
            if (client.character.eventSelectExecCode == 0)
            {
                int[]   hPandMPperChoice   = { 100, 50, 100, 100, 100, 100, 100, 50, 80, 100, 100 };
                byte[]  conditionPerChoice = { 150, 50, 100, 110, 120, 160, 150, 50, 80, 100, 120 };
                ulong[] goldCostPerChoice  = { 0, 0, 60, 300, 1200, 3000, 100, 0, 60, 300, 10000 };
                _Logger.Debug($"The selection you have made is {client.character.eventSelectExtraSelectionCode}");

                if (client.character.adventureBagGold < goldCostPerChoice[client.character.eventSelectExtraSelectionCode])
                {
                    IBuffer res = BufferProvider.Provide();
                    res.WriteCString("You don't have enough gold! This is why I don't like doing business with adventurers.");
                    router.Send(client, (ushort)AreaPacketId.recv_event_system_message, res, ServerType.Area); // show system message on middle of the screen.
                    RecvEventEnd(client);
                }
                else
                {
                    client.character.hp.SetCurrent((sbyte)hPandMPperChoice[client.character.eventSelectExtraSelectionCode], true);
                    client.character.mp.SetCurrent((sbyte)hPandMPperChoice[client.character.eventSelectExtraSelectionCode], true);
                    client.character.condition.SetCurrent(conditionPerChoice[client.character.eventSelectExtraSelectionCode]);
                    client.character.od.ToMax();
                    client.character.gp.ToMax();
                    client.character.adventureBagGold -= goldCostPerChoice[client.character.eventSelectExtraSelectionCode];
                    if (client.character.hp.current >= client.character.hp.max)
                    {
                        client.character.hp.ToMax();
                    }
                    if (client.character.mp.current >= client.character.mp.current)
                    {
                        client.character.mp.ToMax();
                    }

                    RecvCharaUpdateHp recvCharaUpdateHp = new RecvCharaUpdateHp(client.character.hp.current);
                    router.Send(recvCharaUpdateHp, client);
                    RecvCharaUpdateMp recvCharaUpdateMp = new RecvCharaUpdateMp(client.character.mp.current);
                    router.Send(recvCharaUpdateMp, client);
                    RecvCharaUpdateCon recvCharaUpdateCon = new RecvCharaUpdateCon(conditionPerChoice[client.character.eventSelectExtraSelectionCode]);
                    router.Send(recvCharaUpdateCon, client);
                    RecvSelfMoneyNotify recvSelfMoneyNotify = new RecvSelfMoneyNotify(client, client.character.adventureBagGold);
                    router.Send(recvSelfMoneyNotify, client);
                    RecvEventScriptPlay recvEventScriptPlay = new RecvEventScriptPlay("inn/fade_bgm", client.character.instanceId);
                    router.Send(recvEventScriptPlay, client);
                    Experience experience = new Experience();

                    //Level up stuff after inn cutscene
                    Task.Delay(TimeSpan.FromSeconds(6)).ContinueWith
                        (t1 =>
                    {
                        if (client.character.experienceCurrent > experience.CalculateLevelUp((uint)client.character.level + 1).cumulativeExperience)
                        {
                            RecvEventStart recvEventStart = new RecvEventStart(0, 0);
                            router.Send(recvEventStart, client);

                            LevelUpCheck(client);

                            Task.Delay(TimeSpan.FromSeconds(10)).ContinueWith
                                (t1 =>
                            {
                                RecvEventEnd recvEventEnd = new RecvEventEnd(0);
                                router.Send(recvEventEnd, client);         //Need a better way to end the event at the right time.
                            }
                                );
                        }
                    }
                        );
                }
            }
            else
            {
                SendEventEnd(client);
            }

            client.character.eventSelectExtraSelectionCode = 0;
            client.character.eventSelectExecCode           = 0;
            client.character.eventSelectReadyCode          = 0;
            client.character.secondInnAccess = false;
            server.database.UpdateCharacter(client.character);
        }