private void PlayerDamage()
        {
            int       damage        = monster.level * Util.GetRandomNumber(1, 5); //ToDo  make a legitimate damage calculation.
            Character currentTarget = monster.GetCurrentTarget();

            currentTarget.hp.Modify(-damage, monster.instanceId);

            _Logger.Debug($"Monster {monster.instanceId} is attacking {currentTarget.name}");
            List <PacketResponse>           brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify     brStart = new RecvBattleReportStartNotify(currentTarget.instanceId);
            RecvBattleReportEndNotify       brEnd   = new RecvBattleReportEndNotify();
            RecvBattleReportNotifyHitEffect brHit   = new RecvBattleReportNotifyHitEffect(currentTarget.instanceId);
            RecvBattleReportDamageHp        brHp    = new RecvBattleReportDamageHp(currentTarget.instanceId, damage);
            RecvCharaUpdateHp cHpUpdate             = new RecvCharaUpdateHp(currentTarget.hp.current);

            brList.Add(brStart);
            brList.Add(brHit);
            brList.Add(brHp);
            brList.Add(brEnd);
            server.router.Send(_map, brList);
            server.router.Send(_map.clientLookup.GetByCharacterInstanceId(currentTarget.instanceId),
                               cHpUpdate.ToPacket());

            if (currentTarget.hp.depleted)
            {
                monster.SetAgro(false);
                monster.monsterAgroList.Remove(currentTarget.instanceId);
            }

            //PlayerDeadCheck(currentTarget);
        }
Esempio n. 2
0
        private void PlayerDamage()
        {
            int       damage        = (int)Util.GetRandomNumber(8, 43);
            Character currentTarget = _monster.GetCurrentTarget();

            currentTarget.Hp.Modify(-damage, _monster.InstanceId);

            Logger.Debug($"Monster {_monster.InstanceId} is attacking {currentTarget.Name}");
            List <PacketResponse>           brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify     brStart = new RecvBattleReportStartNotify(currentTarget.InstanceId);
            RecvBattleReportEndNotify       brEnd   = new RecvBattleReportEndNotify();
            RecvBattleReportNotifyHitEffect brHit   = new RecvBattleReportNotifyHitEffect(currentTarget.InstanceId);
            RecvBattleReportDamageHp        brHp    = new RecvBattleReportDamageHp(currentTarget.InstanceId, damage);
            RecvCharaUpdateHp cHpUpdate             = new RecvCharaUpdateHp(currentTarget.Hp.current);

            brList.Add(brStart);
            brList.Add(brHit);
            brList.Add(brHp);
            brList.Add(brEnd);
            _server.Router.Send(Map, brList);
            _server.Router.Send(Map.ClientLookup.GetByCharacterInstanceId(currentTarget.InstanceId),
                                cHpUpdate.ToPacket());

            if (currentTarget.Hp.depleted)
            {
                _monster.SetAgro(false);
                _monster.MonsterAgroList.Remove(currentTarget.InstanceId);
            }

            //PlayerDeadCheck(currentTarget);
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0);
            Router.Send(client, (ushort)AreaPacketId.recv_raisescale_request_revive_r, res, ServerType.Area);

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            RecvCharaUpdateHp cHpUpdate = new RecvCharaUpdateHp(client.Character.Hp.current);

            Router.Send(client, cHpUpdate.ToPacket());

            IBuffer res4 = BufferProvider.Provide();

            res4.WriteUInt32(client.Character.InstanceId);
            Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_start_notify, res4, ServerType.Area);

            IBuffer res5 = BufferProvider.Provide();

            res5.WriteUInt32(client.Character.InstanceId);
            Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_notify_raise, res5, ServerType.Area);

            IBuffer res6 = BufferProvider.Provide();

            Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_end_notify, res6, ServerType.Area);

            IBuffer res3 = BufferProvider.Provide();

            res3.WriteUInt32(client.Character.DeadBodyInstanceId);
            Router.Send(client.Map, (ushort)AreaPacketId.recv_object_disappear_notify, res3, ServerType.Area);

            client.Character.hadDied     = false;
            client.Character.Hp.depleted = false;
            RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(client.Character, client.Soul.Name);

            Router.Send(client, cData.ToPacket());

            IBuffer res7 = BufferProvider.Provide();

            res7.WriteByte(0);
            Router.Send(client, (ushort)AreaPacketId.recv_event_end, res7, ServerType.Area);
        }
        private void AttackObjectsInRange(NecClient client, int damage)
        {
            float perHp = 100.0f;

            //Damage Players in range
            foreach (NecClient targetClient in client.map.clientLookup.GetAll())
            {
                if (targetClient == client)
                {
                    continue;                         //skip damaging yourself
                }
                if (targetClient.character.partyId == client.character.partyId && client.character.partyId != 0)
                {
                    continue;                                                                                              //skip damaging party members
                }
                //if (targetClient.Soul.CriminalLevel == 0 && client.CriminalOnlyDamage == true) continue; //skip attacking non criminal players.  TODO

                double distanceToCharacter = Distance(targetClient.character.x, targetClient.character.y,
                                                      client.character.x, client.character.y);
                _Logger.Debug(
                    $"target Character name [{targetClient.character.name}] distanceToCharacter [{distanceToCharacter}] Radius { /*[{monsterSpawn.Radius}]*/" 125 "} {targetClient.character.name}");
                if (distanceToCharacter > /*targetClient.Character.Radius +*/ 125)
                {
                    continue;
                }

                if (targetClient.character.hp.depleted)
                {
                    continue;
                }

                damage -= targetClient.character.battleParam.plusPhysicalDefence;
                if (damage < 0)
                {
                    damage = 1;             //pity damage
                }
                targetClient.character.hp.Modify(-damage, client.character.instanceId);
                perHp = (float)targetClient.character.hp.current / targetClient.character.hp.max * 100;
                _Logger.Debug(
                    $"CurrentHp [{targetClient.character.hp.current}] MaxHp[{targetClient.character.hp.max}] perHp[{perHp}]");
                RecvCharaUpdateHp cHpUpdate = new RecvCharaUpdateHp(targetClient.character.hp.current);
                _server.router.Send(targetClient, cHpUpdate.ToPacket());

                //logic to turn characters to criminals on criminal actions.  possibly should move to character task.
                client.character.criminalState += 1;
                if ((client.character.criminalState == 1) | (client.character.criminalState == 2) |
                    (client.character.criminalState == 3))
                {
                    IBuffer res40 = BufferProvider.Provide();
                    res40.WriteUInt32(client.character.instanceId);
                    res40.WriteByte(client.character.criminalState);

                    _Logger.Debug($"Setting crime level for Character {client.character.name} to {client.character.criminalState}");
                    router.Send(client.map, (ushort)AreaPacketId.recv_chara_update_notify_crime_lv, res40, ServerType.Area);
                    //Router.Send(client.Map, (ushort) AreaPacketId.recv_charabody_notify_crime_lv, res40, ServerType.Area, client);
                }

                if (client.character.criminalState > 255)
                {
                    client.character.criminalState = 255;
                }

                DamageTheObject(client, targetClient.character.instanceId, damage, perHp);
            }

            //Damage Monsters in range
            foreach (MonsterSpawn monsterSpawn in client.map.monsterSpawns.Values)
            {
                double distanceToObject =
                    Distance(monsterSpawn.x, monsterSpawn.y, client.character.x, client.character.y);
                //_Logger.Debug($"target Monster name [{monsterSpawn.name}] distanceToObject [{distanceToObject}] Radius [{monsterSpawn.radius}] {monsterSpawn.name}");
                if (distanceToObject > monsterSpawn.radius * 5
                    ) //increased hitbox for monsters by a factor of 5.  Beetle radius is 40
                {
                    continue;
                }

                if (monsterSpawn.hp.depleted)
                {
                    continue;
                }

                monsterSpawn.hp.Modify(-damage, client.character.instanceId);
                perHp = (float)monsterSpawn.hp.current / monsterSpawn.hp.max * 100;
                _Logger.Debug($"CurrentHp [{monsterSpawn.hp.current}] MaxHp[{monsterSpawn.hp.max}] perHp[{perHp}]");

                //just for fun. turn on inactive monsters
                if (monsterSpawn.active == false)
                {
                    monsterSpawn.active      = true;
                    monsterSpawn.spawnActive = true;
                    if (!monsterSpawn.taskActive)
                    {
                        MonsterTask monsterTask = new MonsterTask(_server, monsterSpawn);
                        if (monsterSpawn.defaultCoords)
                        {
                            monsterTask.monsterHome = monsterSpawn.monsterCoords[0];
                        }
                        else
                        {
                            monsterTask.monsterHome = monsterSpawn.monsterCoords.Find(x => x.coordIdx == 64);
                        }
                        monsterTask.Start();
                    }
                }

                DamageTheObject(client, monsterSpawn.instanceId, damage, perHp);
            }

            //Damage NPCs in range
            foreach (NpcSpawn npcSpawn in client.map.npcSpawns.Values)
            {
                double distanceToObject = Distance(npcSpawn.x, npcSpawn.y, client.character.x, client.character.y);
                // _Logger.Debug($"target NPC name [{npcSpawn.name}] distanceToObject [{distanceToObject}] Radius [{npcSpawn.radius}] {npcSpawn.name}");
                if (distanceToObject > npcSpawn.radius)
                {
                    continue;
                }

                //attacking an NPC is a misdimeanor crime for non-criminals.
                if ((client.character.criminalState == 0))
                {
                    client.character.criminalState += 1;
                    IBuffer res40 = BufferProvider.Provide();
                    res40.WriteUInt32(client.character.instanceId);
                    res40.WriteByte(client.character.criminalState);

                    router.Send(client.map, (ushort)AreaPacketId.recv_chara_update_notify_crime_lv, res40, ServerType.Area);
                }

                DamageTheObject(client, npcSpawn.instanceId, damage, perHp);
            }
        }
Esempio n. 5
0
        private void AttackObjectsInRange(NecClient client, int damage)
        {
            float perHp = 100.0f;

            //Damage Players in range
            foreach (NecClient targetClient in client.Map.ClientLookup.GetAll())
            {
                if (targetClient == client)
                {
                    continue;
                }

                double distanceToCharacter = distance(targetClient.Character.X, targetClient.Character.Y,
                                                      client.Character.X, client.Character.Y);
                Logger.Debug(
                    $"target Character name [{targetClient.Character.Name}] distanceToCharacter [{distanceToCharacter}] Radius { /*[{monsterSpawn.Radius}]*/" 125 "} {targetClient.Character.Name}");
                if (distanceToCharacter > /*targetClient.Character.Radius +*/ 125)
                {
                    continue;
                }

                if (targetClient.Character.Hp.depleted)
                {
                    continue;
                }

                targetClient.Character.Hp.Modify(-damage, client.Character.InstanceId);
                perHp = (float)targetClient.Character.Hp.current / targetClient.Character.Hp.max * 100;
                Logger.Debug(
                    $"CurrentHp [{targetClient.Character.Hp.current}] MaxHp[{targetClient.Character.Hp.max}] perHp[{perHp}]");
                RecvCharaUpdateHp cHpUpdate = new RecvCharaUpdateHp(targetClient.Character.Hp.current);
                _server.Router.Send(targetClient, cHpUpdate.ToPacket());

                //logic to turn characters to criminals on criminal actions.  possibly should move to character task.
                client.Character.criminalState += 1;
                if (client.Character.criminalState == 1 | client.Character.criminalState == 2 |
                    client.Character.criminalState == 3)
                {
                    IBuffer res40 = BufferProvider.Provide();
                    res40.WriteUInt32(client.Character.InstanceId);
                    res40.WriteByte(client.Character.criminalState);

                    Logger.Debug(
                        $"Setting crime level for Character {client.Character.Name} to {client.Character.criminalState}");
                    Router.Send(client, (ushort)AreaPacketId.recv_chara_update_notify_crime_lv, res40,
                                ServerType.Area);
                    Router.Send(client.Map, (ushort)AreaPacketId.recv_charabody_notify_crime_lv, res40,
                                ServerType.Area, client);
                }

                if (client.Character.criminalState > 255)
                {
                    client.Character.criminalState = 255;
                }

                DamageTheObject(client, targetClient.Character.InstanceId, damage, perHp);
            }

            //Damage Monsters in range
            foreach (MonsterSpawn monsterSpawn in client.Map.MonsterSpawns.Values)
            {
                double distanceToObject =
                    distance(monsterSpawn.X, monsterSpawn.Y, client.Character.X, client.Character.Y);
                Logger.Debug(
                    $"target Monster name [{monsterSpawn.Name}] distanceToObject [{distanceToObject}] Radius [{monsterSpawn.Radius}] {monsterSpawn.Name}");
                if (distanceToObject > monsterSpawn.Radius * 5
                    ) //increased hitbox for monsters by a factor of 5.  Beetle radius is 40
                {
                    continue;
                }

                if (monsterSpawn.Hp.depleted)
                {
                    continue;
                }

                monsterSpawn.Hp.Modify(-damage, client.Character.InstanceId);
                perHp = (float)monsterSpawn.Hp.current / monsterSpawn.Hp.max * 100;
                Logger.Debug($"CurrentHp [{monsterSpawn.Hp.current}] MaxHp[{monsterSpawn.Hp.max}] perHp[{perHp}]");

                DamageTheObject(client, monsterSpawn.InstanceId, damage, perHp);
            }

            //Damage NPCs in range
            foreach (NpcSpawn npcSpawn in client.Map.NpcSpawns.Values)
            {
                double distanceToObject = distance(npcSpawn.X, npcSpawn.Y, client.Character.X, client.Character.Y);
                Logger.Debug(
                    $"target NPC name [{npcSpawn.Name}] distanceToObject [{distanceToObject}] Radius [{npcSpawn.Radius}] {npcSpawn.Name}");
                if (distanceToObject > npcSpawn.Radius)
                {
                    continue;
                }

                DamageTheObject(client, npcSpawn.InstanceId, damage, perHp);
            }
        }
Esempio n. 6
0
        private void OldBattleLogic(NecClient client, uint instanceId)
        {
            int   damage = 0;
            float perHp  = 100.0f;
            int   seed   = Util.GetRandomNumber(0, 20);

            if (seed < 2)
            {
                damage = Util.GetRandomNumber(1, 4); // Light hit
            }
            else if (seed < 19)
            {
                damage = Util.GetRandomNumber(16, 24); // Normal hit
            }
            else
            {
                damage = Util.GetRandomNumber(32, 48); // Critical hit
            }
            //stops the logic gate below if nothing is targeted.  This was because Rev 1 of battle logic only worked on targeted objects.  probably will go away with progress on 'area of affect' based melee
            if (instanceId == 0)
            {
                return;
            }

            IInstance instance = Server.Instances.GetInstance(instanceId);

            switch (instance)
            {
            case NpcSpawn npcSpawn:
                client.Map.NpcSpawns.TryGetValue(npcSpawn.InstanceId, out npcSpawn);
                {
                    double distanceToNPC = distance(npcSpawn.X, npcSpawn.Y, client.Character.X, client.Character.Y);
                    Logger.Debug(
                        $"NPC name [{npcSpawn.Name}] distanceToNPC [{distanceToNPC}] Radius [{npcSpawn.Radius}] {npcSpawn.Name}");
                    if (distanceToNPC > npcSpawn.Radius + 125)
                    {
                        //SendBattleReportEndNotify(client, instance);
                        return;
                    }

                    if (client.Character.criminalState < 1)
                    {
                        client.Character.criminalState = 1;
                        IBuffer res40 = BufferProvider.Provide();
                        res40.WriteUInt32(client.Character.InstanceId);
                        res40.WriteByte(client.Character.criminalState);

                        Logger.Debug(
                            $"Setting crime level for Character {client.Character.Name} to {client.Character.criminalState}");
                        Router.Send(client, (ushort)AreaPacketId.recv_chara_update_notify_crime_lv, res40,
                                    ServerType.Area);
                        Router.Send(client.Map, (ushort)AreaPacketId.recv_charabody_notify_crime_lv, res40,
                                    ServerType.Area, client);
                    }
                }
                break;

            case MonsterSpawn monsterSpawn:
                client.Map.MonsterSpawns.TryGetValue(monsterSpawn.InstanceId, out monsterSpawn);
                {
                    double distanceToMonster = distance(monsterSpawn.X, monsterSpawn.Y, client.Character.X,
                                                        client.Character.Y);
                    Logger.Debug(
                        $"monster name [{monsterSpawn.Name}] distanceToMonster [{distanceToMonster}] Radius [{monsterSpawn.Radius}] {monsterSpawn.Name}");
                    if (distanceToMonster > monsterSpawn.Radius + 125)
                    {
                        //SendBattleReportEndNotify(client, instance);
                        return;
                    }

                    if (monsterSpawn.GetAgroCharacter(client.Character.InstanceId))
                    {
                        monsterSpawn.UpdateHP(-damage);
                    }
                    else
                    {
                        monsterSpawn.UpdateHP(-damage, _server, true, client.Character.InstanceId);
                    }

                    if (client.Character.IsStealthed())
                    {
                        uint newState = client.Character.ClearStateBit(0x8);
                        RecvCharaNotifyStateflag charState =
                            new RecvCharaNotifyStateflag(client.Character.InstanceId, newState);
                        _server.Router.Send(client.Map, charState);
                    }

                    perHp = (float)monsterSpawn.Hp.current / monsterSpawn.Hp.max * 100;
                    Logger.Debug($"CurrentHp [{monsterSpawn.Hp.current}] MaxHp[{monsterSpawn.Hp.max}] perHp[{perHp}]");
                }
                break;

            case Character character:
                NecClient targetClient        = client.Map.ClientLookup.GetByCharacterInstanceId(instance.InstanceId);
                double    distanceToCharacter = distance(targetClient.Character.X, targetClient.Character.Y,
                                                         client.Character.X, client.Character.Y);
                Logger.Debug(
                    $"target Character name [{targetClient.Character.Name}] distanceToCharacter [{distanceToCharacter}] Radius { /*[{monsterSpawn.Radius}]*/" 125 "} {targetClient.Character.Name}");
                if (distanceToCharacter > /*targetClient.Character.Radius +*/ 125)
                {
                    //SendBattleReportEndNotify(client, instance);
                    return;
                }

                targetClient.Character.Hp.Modify(-damage, character.InstanceId);
                perHp = (float)targetClient.Character.Hp.current / targetClient.Character.Hp.max * 100;
                Logger.Debug(
                    $"CurrentHp [{targetClient.Character.Hp.current}] MaxHp[{targetClient.Character.Hp.max}] perHp[{perHp}]");
                RecvCharaUpdateHp cHpUpdate = new RecvCharaUpdateHp(targetClient.Character.Hp.current);
                _server.Router.Send(targetClient, cHpUpdate.ToPacket());

                //logic to turn characters to criminals on criminal actions.  possibly should move to character task.
                client.Character.criminalState += 1;
                if (client.Character.criminalState == 1 | client.Character.criminalState == 2 |
                    client.Character.criminalState == 3)
                {
                    IBuffer res40 = BufferProvider.Provide();
                    res40.WriteUInt32(client.Character.InstanceId);
                    res40.WriteByte(client.Character.criminalState);

                    Logger.Debug(
                        $"Setting crime level for Character {client.Character.Name} to {client.Character.criminalState}");
                    Router.Send(client, (ushort)AreaPacketId.recv_chara_update_notify_crime_lv, res40,
                                ServerType.Area);
                    Router.Send(client.Map, (ushort)AreaPacketId.recv_charabody_notify_crime_lv, res40,
                                ServerType.Area, client);
                }

                if (client.Character.criminalState > 255)
                {
                    client.Character.criminalState = 255;
                }

                break;

            default:
                Logger.Error($"Instance with InstanceId: {instance.InstanceId} does not exist");
                break;
            }

            List <PacketResponse>            brTargetList = new List <PacketResponse>();
            RecvBattleReportStartNotify      brStart      = new RecvBattleReportStartNotify(client.Character.InstanceId);
            RecvBattleReportEndNotify        brEnd        = new RecvBattleReportEndNotify();
            RecvBattleReportActionAttackExec brAttack     = new RecvBattleReportActionAttackExec((int)instance.InstanceId);
            RecvBattleReportNotifyHitEffect  brHit        = new RecvBattleReportNotifyHitEffect(instance.InstanceId);
            RecvBattleReportPhyDamageHp      brPhyHp      = new RecvBattleReportPhyDamageHp(instance.InstanceId, damage);
            RecvBattleReportDamageHp         brHp         = new RecvBattleReportDamageHp(instance.InstanceId, damage);
            RecvObjectHpPerUpdateNotify      oHpUpdate    = new RecvObjectHpPerUpdateNotify(instance.InstanceId, perHp);


            brTargetList.Add(brStart);
            brTargetList.Add(brAttack);
            brTargetList.Add(brHit);
            brTargetList.Add(brPhyHp);
            //brTargetList.Add(brHp);
            brTargetList.Add(oHpUpdate);
            brTargetList.Add(brEnd);
            Router.Send(client.Map, brTargetList);
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            _necClients = client.map.clientLookup.GetAll();
            //if (client.Character.soulFormState == 1)
            {
                client.character.state       = CharacterState.InvulnerableForm;
                client.character.hasDied     = false;
                client.character.hp.depleted = false;
                client.character.deadType    = 0;
                client.character.hp.ToMax();


                IBuffer res1 = BufferProvider.Provide();
                res1.WriteInt32(0); //Has to be 0 or else you DC
                res1.WriteUInt32(client.character.deadBodyInstanceId);
                res1.WriteUInt32(client.character.instanceId);
                router.Send(client, (ushort)AreaPacketId.recv_revive_init_r, res1, ServerType.Area);

                IBuffer res3 = BufferProvider.Provide();
                res3.WriteUInt32(client.character.deadBodyInstanceId);
                router.Send(client.map, (ushort)AreaPacketId.recv_object_disappear_notify, res3, ServerType.Area);

                res3 = BufferProvider.Provide();
                res3.WriteUInt32(client.character.instanceId);
                router.Send(client.map, (ushort)AreaPacketId.recv_object_disappear_notify, res3, ServerType.Area, client);


                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(client.character, client.soul.name);
                router.Send(client.map, cData.ToPacket());


                //Disappear .. all the monsters, NPCs, and characters.  welcome to Life! it's less lonely
                foreach (NpcSpawn npcSpawn in client.map.npcSpawns.Values)
                {
                    RecvObjectDisappearNotify recvObjectDisappearNotify = new RecvObjectDisappearNotify(npcSpawn.instanceId);
                    router.Send(client, recvObjectDisappearNotify.ToPacket());
                }

                foreach (MonsterSpawn monsterSpawn in client.map.monsterSpawns.Values)
                {
                    RecvObjectDisappearNotify recvObjectDisappearNotify = new RecvObjectDisappearNotify(monsterSpawn.instanceId);
                    router.Send(client, recvObjectDisappearNotify.ToPacket());
                }

                foreach (NecClient client2 in _necClients)
                {
                    if (client2 == client)
                    {
                        continue;                    //Don't dissapear yourself ! that'd be bad news bears.
                    }
                    RecvObjectDisappearNotify recvObjectDisappearNotify = new RecvObjectDisappearNotify(client2.character.instanceId);
                    router.Send(client, recvObjectDisappearNotify.ToPacket());
                }

                List <PacketResponse>       brList  = new List <PacketResponse>();
                RecvBattleReportStartNotify brStart = new RecvBattleReportStartNotify(client.character.instanceId);
                RecvBattleReportNotifyRaise recvBattleReportNotifyRaise = new RecvBattleReportNotifyRaise(client.character.instanceId);
                RecvBattleReportEndNotify   brEnd = new RecvBattleReportEndNotify();

                brList.Add(brStart);
                brList.Add(recvBattleReportNotifyRaise);
                brList.Add(brEnd);
                router.Send(client.map, brList);
                RecvCharaUpdateMaxHp recvCharaUpdateMaxHp1 = new RecvCharaUpdateMaxHp(client.character.hp.max);
                router.Send(client, recvCharaUpdateMaxHp1.ToPacket());


                Task.Delay(TimeSpan.FromSeconds(3)).ContinueWith
                    (t1 =>
                {
                    RecvCharaUpdateHp cHpUpdate = new RecvCharaUpdateHp(client.character.hp.max);
                    router.Send(client, cHpUpdate.ToPacket());

                    //if you are not dead, do normal stuff.  else...  do dead person stuff
                    if (client.character.state != CharacterState.SoulForm)
                    {
                        foreach (NecClient otherClient in _necClients)
                        {
                            if (otherClient == client)
                            {
                                // skip myself
                                continue;
                            }
                            if (otherClient.character.state != CharacterState.SoulForm)
                            {
                                RecvDataNotifyCharaData otherCharacterData = new RecvDataNotifyCharaData(otherClient.character, otherClient.soul.name);
                                router.Send(otherCharacterData, client);
                            }

                            if (otherClient.union != null)
                            {
                                RecvDataNotifyUnionData otherUnionData = new RecvDataNotifyUnionData(otherClient.character, otherClient.union.name);
                                router.Send(otherUnionData, client);
                            }
                        }

                        foreach (MonsterSpawn monsterSpawn in client.map.monsterSpawns.Values)
                        {
                            RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn);
                            router.Send(monsterData, client);
                        }

                        foreach (NpcSpawn npcSpawn in client.map.npcSpawns.Values)
                        {
                            if (npcSpawn.visibility != 2)     //2 is the magic number for soul state only.  make it an Enum some day
                            {
                                RecvDataNotifyNpcData npcData = new RecvDataNotifyNpcData(npcSpawn);
                                router.Send(npcData, client);
                            }
                        }

                        foreach (DeadBody deadBody in client.map.deadBodies.Values)
                        {
                            if (client.map.id.ToString()[0] != "1"[0])     //Don't Render dead bodies in town.  Town map ids all start with 1
                            {
                                RecvDataNotifyCharaBodyData deadBodyData = new RecvDataNotifyCharaBodyData(deadBody);
                                router.Send(deadBodyData, client);
                            }
                        }
                    }
                }
                    );
                Task.Delay(TimeSpan.FromSeconds(10)).ContinueWith
                    (t1 =>
                {
                    client.character.ClearStateBit(CharacterState.InvulnerableForm);
                    RecvCharaNotifyStateflag recvCharaNotifyStateflag = new RecvCharaNotifyStateflag(client.character.instanceId, (ulong)client.character.state);
                    router.Send(client.map, recvCharaNotifyStateflag.ToPacket());
                }
                    );
            }

            /*else if (client.Character.soulFormState == 0)
             * {
             *  IBuffer res1 = BufferProvider.Provide();
             *  res1.WriteInt32(client.Character.InstanceId); // ID
             *  res1.WriteInt32(100101); //100101, its the id to get the tombstone
             *  Router.Send(client, (ushort) AreaPacketId.recv_chara_notify_stateflag, res1, ServerType.Area);
             *
             *  IBuffer res = BufferProvider.Provide();
             *  res.WriteInt32(1); // 0 = sucess to revive, 1 = failed to revive
             *  Router.Send(client, (ushort) AreaPacketId.recv_raisescale_request_revive_r, res, ServerType.Area);
             *
             *  IBuffer res5 = BufferProvider.Provide();
             *  Router.Send(client, (ushort) AreaPacketId.recv_self_lost_notify, res5, ServerType.Area);
             * }*/

            if (client.map.deadBodies.ContainsKey(client.character.deadBodyInstanceId))
            {
                client.map.deadBodies.Remove(client.character.deadBodyInstanceId);
            }

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0);                                                                                // 0 = sucess to revive, 1 = failed to revive
            router.Send(client, (ushort)AreaPacketId.recv_raisescale_request_revive_r, res, ServerType.Area); //responsible for camera movement

            IBuffer res7 = BufferProvider.Provide();

            res7.WriteByte(0);
            //router.Send(client, (ushort)AreaPacketId.recv_event_end, res7, ServerType.Area); //why is this needed? the script play ends the event
        }
Esempio n. 8
0
        public override void Execute(string[] command, NecClient client, ChatMessage message,
                                     List <ChatResponse> responses)
        {
            //if (client.Character.soulFormState == 1)
            {
                IBuffer res1 = BufferProvider.Provide();
                res1.WriteInt32(0); //Has to be 0 or else you DC
                res1.WriteUInt32(client.Character.DeadBodyInstanceId);
                res1.WriteUInt32(client.Character.InstanceId);
                Router.Send(client, (ushort)AreaPacketId.recv_revive_init_r, res1, ServerType.Area);

                IBuffer res = BufferProvider.Provide();
                res.WriteInt32(0);            // 0 = sucess to revive, 1 = failed to revive
                Router.Send(client, (ushort)AreaPacketId.recv_raisescale_request_revive_r, res,
                            ServerType.Area); //responsible for camera movement

                client.Character.soulFormState -= 1;
                client.Character.Hp.toMax();
                client.Character.movementId = client.Character.InstanceId;
                client.Character.state      = 0b00000000;


                IBuffer res2 = BufferProvider.Provide();
                res2.WriteInt32(0); // Error code, 0 = success
                Router.Send(client, (ushort)AreaPacketId.recv_revive_execute_r, res2, ServerType.Area);

                RecvCharaUpdateHp cHpUpdate = new RecvCharaUpdateHp(client.Character.Hp.current);
                Router.Send(client, cHpUpdate.ToPacket());

                IBuffer res4 = BufferProvider.Provide();
                res4.WriteUInt32(client.Character.InstanceId);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_start_notify, res4, ServerType.Area);

                IBuffer res5 = BufferProvider.Provide();
                res5.WriteUInt32(client.Character.InstanceId);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_notify_raise, res5, ServerType.Area);

                IBuffer res6 = BufferProvider.Provide();
                Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_end_notify, res6, ServerType.Area);
                //

                IBuffer res3 = BufferProvider.Provide();
                res3.WriteUInt32(client.Character.DeadBodyInstanceId);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_object_disappear_notify, res3, ServerType.Area);

                client.Character.hadDied     = false;
                client.Character.Hp.depleted = false;
                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(client.Character, client.Soul.Name);
                Router.Send(client, cData.ToPacket());
            }

            /*else if (client.Character.soulFormState == 0)
             * {
             *  IBuffer res1 = BufferProvider.Provide();
             *  res1.WriteInt32(client.Character.InstanceId); // ID
             *  res1.WriteInt32(100101); //100101, its the id to get the tombstone
             *  Router.Send(client.Map, (ushort) AreaPacketId.recv_chara_notify_stateflag, res1, ServerType.Area);
             *
             *  IBuffer res = BufferProvider.Provide();
             *  res.WriteInt32(1); // 0 = sucess to revive, 1 = failed to revive
             *  Router.Send(client.Map, (ushort) AreaPacketId.recv_raisescale_request_revive_r, res, ServerType.Area);
             *
             *  IBuffer res5 = BufferProvider.Provide();
             *  Router.Send(client.Map, (ushort) AreaPacketId.recv_self_lost_notify, res5, ServerType.Area);
             * }*/
        }
        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);
        }