Exemplo n.º 1
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);
        }
        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);
        }
        private void MonsterAttackQueue(int skillId)
        {
            List <PacketResponse>            brList   = new List <PacketResponse>();
            RecvBattleReportStartNotify      brStart  = new RecvBattleReportStartNotify(monster.instanceId);
            RecvBattleReportEndNotify        brEnd    = new RecvBattleReportEndNotify();
            RecvBattleReportActionAttackExec brAttack = new RecvBattleReportActionAttackExec(skillId);

            brList.Add(brStart);
            brList.Add(brAttack);
            brList.Add(brEnd);
            server.router.Send(_map, brList);
        }
        private void MonsterCastQueue(int skillId)
        {
            _casting = true;
            List <PacketResponse>                  brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify            brStart = new RecvBattleReportStartNotify(monster.instanceId);
            RecvBattleReportActionMonsterSkillExec brExec  = new RecvBattleReportActionMonsterSkillExec(skillId);
            RecvBattleReportEndNotify              brEnd   = new RecvBattleReportEndNotify();

            brList.Add(brStart);
            brList.Add(brExec);
            brList.Add(brEnd);
            server.router.Send(_map, brList);
        }
Exemplo n.º 5
0
        public void StartCast()
        {
            if (_targetInstanceId == 0)
            {
                _targetInstanceId = _client.character.instanceId;
            }
            IInstance target = _server.instances.GetInstance(_targetInstanceId);

            switch (target) // ToDO     Do a hositilty check to make sure this is allowed
            {
            case NpcSpawn npcSpawn:
                _Logger.Debug($"Start casting Skill [{_skillId}] on NPCId: {npcSpawn.instanceId}");
                break;

            case MonsterSpawn monsterSpawn:
                _Logger.Debug($"Start casting Skill [{_skillId}] on MonsterId: {monsterSpawn.instanceId}");
                break;

            case Character character:
                _Logger.Debug($"Start casting Skill [{_skillId}] on CharacterId: {character.instanceId}");
                break;

            default:
                _Logger.Error(
                    $"Instance with InstanceId: {target.instanceId} does not exist.  the ground is gettin blasted");
                break;
            }

            if (!_server.settingRepository.skillBase.TryGetValue(_skillId, out SkillBaseSetting skillBaseSetting))
            {
                _Logger.Error($"Could not get SkillBaseSetting for skillId : {_skillId}");
                return;
            }

            float castTime = skillBaseSetting.castingTime;

            _Logger.Debug($"Start casting Skill [{_skillId}] cast time is [{castTime}]");
            RecvSkillStartCastR spell = new RecvSkillStartCastR(0, castTime);

            _server.router.Send(spell, _client);
            List <PacketResponse>                brList      = new List <PacketResponse>();
            RecvBattleReportStartNotify          brStart     = new RecvBattleReportStartNotify(_client.character.instanceId);
            RecvBattleReportEndNotify            brEnd       = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillStartCast brStartCast = new RecvBattleReportActionSkillStartCast(_skillId);

            brList.Add(brStart);
            brList.Add(brStartCast);
            brList.Add(brEnd);
            _server.router.Send(_client.map, brList);
        }
Exemplo n.º 6
0
        public void SkillExec()
        {
            List <PacketResponse>           brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify     brStart = new RecvBattleReportStartNotify(_client.character.instanceId);
            RecvBattleReportEndNotify       brEnd   = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillExec brExec  =
                new RecvBattleReportActionSkillExec(_client.character.skillStartCast);

            brList.Add(brStart);
            brList.Add(brExec);
            brList.Add(brEnd);
            _server.router.Send(_client.map, brList);


            Task.Delay(TimeSpan.FromSeconds(_skillSetting.rigidityTime)).ContinueWith
                (t1 =>
            {
                //Make it so you can kinda see yourself
                _client.character.AddStateBit(CharacterState.InvulnerableForm);     //todo. fix stealth form
                RecvCharaNotifyStateflag myStateFlag = new RecvCharaNotifyStateflag(_client.character.instanceId, (ulong)_client.character.state);
                _server.router.Send(_client, myStateFlag.ToPacket());

                //make other players not able to see you
                _client.character.AddStateBit(CharacterState.InvisibleForm);
                RecvCharaNotifyStateflag stateFlag = new RecvCharaNotifyStateflag(_client.character.instanceId, (ulong)_client.character.state);
                _server.router.Send(_client.map, stateFlag, _client);
            }
                );


            //clear stealth after 10 seconds.   //ToDo  ,  change seconds to skills effective time.
            Task.Delay(TimeSpan.FromSeconds(_skillSetting.effectTime + _skillSetting.rigidityTime)).ContinueWith
                (t1 =>
            {
                _client.character.ClearStateBit(CharacterState.InvisibleForm);
                _client.character.ClearStateBit(CharacterState.InvulnerableForm);
                RecvCharaNotifyStateflag recvCharaNotifyStateflag = new RecvCharaNotifyStateflag(_client.character.instanceId, (ulong)_client.character.state);
                _server.router.Send(_client.map, recvCharaNotifyStateflag.ToPacket());
            }
                );

            //0bxxxxxxx1 - 1 Soul Form / 0 Normal  | (Soul form is Glowing with No armor)
            //0bxxxxxx1x - 1 Battle Pose / 0 Normal
            //0bxxxxx1xx - 1 Block Pose / 0 Normal | (for coming out of stealth while blocking)
            //0bxxxx1xxx - 1 transparent / 0 solid  | (stealth in party partial visibility)
            //0bxxx1xxxx -
            //0bxx1xxxxx - 1 invisible / 0 visible  | (Stealth to enemies)
            //0bx1xxxxxx - 1 blinking  / 0 solid    | (10  second invulnerability blinking)
            //0b1xxxxxxx -
        }
        private void StartMonsterCastQueue(int skillId, uint instanceId)
        {
            _casting = true;
            Character                   currentTarget = monster.GetCurrentTarget();
            List <PacketResponse>       brList        = new List <PacketResponse>();
            RecvBattleReportStartNotify brStart       = new RecvBattleReportStartNotify(monster.instanceId);
            RecvBattleReportEndNotify   brEnd         = new RecvBattleReportEndNotify();
            RecvBattleReportActionMonsterSkillStartCast brStartCast =
                new RecvBattleReportActionMonsterSkillStartCast(currentTarget.instanceId, skillId);

            brList.Add(brStart);
            brList.Add(brStartCast);
            brList.Add(brEnd);
            server.router.Send(_map, brList);
        }
Exemplo n.º 8
0
        public void StartCast()
        {
            _Logger.Debug($"CastingTime : {_skillSetting.castingTime}");
            RecvSkillStartCastSelf startCast = new RecvSkillStartCastSelf(_skillid, _skillSetting.castingTime);

            _server.router.Send(_client, startCast.ToPacket()); //do not send "Self"  recvs to map. that breaks things.
            List <PacketResponse>                brList      = new List <PacketResponse>();
            RecvBattleReportStartNotify          brStart     = new RecvBattleReportStartNotify(_client.character.instanceId);
            RecvBattleReportEndNotify            brEnd       = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillStartCast brStartCast = new RecvBattleReportActionSkillStartCast(_skillid);

            brList.Add(brStart);
            brList.Add(brStartCast);
            brList.Add(brEnd);
            _server.router.Send(_client.map, brList);
        }
Exemplo n.º 9
0
        public void StartCast()
        {
            Logger.Debug($"CastingTime : {_skillSetting.CastingTime}");
            RecvSkillStartCastSelf startCast = new RecvSkillStartCastSelf(_skillid, _skillSetting.CastingTime);

            _server.Router.Send(_client.Map, startCast);
            List <PacketResponse>                brList      = new List <PacketResponse>();
            RecvBattleReportStartNotify          brStart     = new RecvBattleReportStartNotify(_client.Character.InstanceId);
            RecvBattleReportEndNotify            brEnd       = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillStartCast brStartCast = new RecvBattleReportActionSkillStartCast(_skillid);

            brList.Add(brStart);
            brList.Add(brStartCast);
            brList.Add(brEnd);
            _server.Router.Send(_client.Map, brList);
        }
Exemplo n.º 10
0
        public bool MonsterCheck()
        {
            // Logger.Debug($"Monster HP [{_monster.GetHP()}]");
            if (_monster.Hp.current <= 0)
            {
                foreach (uint instanceId in _monster.GetAgroInstanceList())
                {
                    _monster.MonsterHate(_server, false, instanceId);
                }

                Logger.Debug($"Monster is dead InstanceId [{_monster.InstanceId}]");
                //Death Animation
                List <PacketResponse>       brList  = new List <PacketResponse>();
                RecvBattleReportStartNotify brStart = new RecvBattleReportStartNotify(_monster.InstanceId);
                RecvBattleReportEndNotify   brEnd   = new RecvBattleReportEndNotify();
                RecvBattleReportNoactDead   brDead  = new RecvBattleReportNoactDead(_monster.InstanceId, 1);
                brList.Add(brStart);
                brList.Add(brDead);
                brList.Add(brEnd);
                _server.Router.Send(Map, brList);

                //Make the monster a lootable state
                IBuffer res10 = BufferProvider.Provide();
                res10.WriteUInt32(_monster.InstanceId);
                res10.WriteInt32(2); //Toggles state between Alive(attackable),  Dead(lootable), or Inactive(nothing).
                _server.Router.Send(Map, (ushort)AreaPacketId.recv_monster_state_update_notify, res10,
                                    ServerType.Area);

                Thread.Sleep(_monster.RespawnTime);
                //decompose the body
                IBuffer res7 = BufferProvider.Provide();
                res7.WriteUInt32(_monster.InstanceId);
                res7.WriteInt32(
                    5); //4 here causes a cloud and the model to disappear, 5 causes a mist to happen and disappear
                res7.WriteInt32(1);
                _server.Router.Send(Map, (ushort)AreaPacketId.recv_charabody_notify_deadstate, res7, ServerType.Area);
                Thread.Sleep(2000);
                RecvObjectDisappearNotify objectDisappearData = new RecvObjectDisappearNotify(_monster.InstanceId);
                _server.Router.Send(Map, objectDisappearData);
                _monster.MonsterVisible = false;

                spawnMonster = true;
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        public void TriggerTrap(Trap trap, MonsterSpawn monster)
        {
            Logger.Debug(
                $"trap._name [{trap._name}] trap.InstanceId [{trap.InstanceId}] trap._skillEffectId [{trap._skillEffectId}] trap._triggerEffectId [{trap._triggerEffectId}]");
            NecClient client = _map.ClientLookup.GetByCharacterInstanceId(ownerInstanceId);

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

            int damage = Util.GetRandomNumber(70, 90);
            RecvDataNotifyEoData eoTriggerData = new RecvDataNotifyEoData(trap.InstanceId, monster.InstanceId,
                                                                          trap._triggerEffectId, TrapPos, 2, 2);

            _server.Router.Send(_map, eoTriggerData);
            float perHp = (((float)monster.Hp.current / (float)monster.Hp.max) * 100);
            List <PacketResponse>            brList    = new List <PacketResponse>();
            RecvBattleReportStartNotify      brStart   = new RecvBattleReportStartNotify(ownerInstanceId);
            RecvBattleReportEndNotify        brEnd     = new RecvBattleReportEndNotify();
            RecvBattleReportActionAttackExec brAttack  = new RecvBattleReportActionAttackExec(trap._skillId);
            RecvBattleReportNotifyHitEffect  brHit     = new RecvBattleReportNotifyHitEffect(monster.InstanceId);
            RecvBattleReportPhyDamageHp      brPhyHp   = new RecvBattleReportPhyDamageHp(monster.InstanceId, damage);
            RecvObjectHpPerUpdateNotify      oHpUpdate = new RecvObjectHpPerUpdateNotify(monster.InstanceId, perHp);
            RecvBattleReportDamageHp         brHp      = new RecvBattleReportDamageHp(monster.InstanceId, damage);

            brList.Add(brStart);
            //brList.Add(brAttack);
            brList.Add(brHit);
            //brList.Add(brPhyHp);
            brList.Add(brHp);
            brList.Add(oHpUpdate);
            brList.Add(brEnd);
            _server.Router.Send(_map, brList);
            if (monster.GetAgroCharacter(ownerInstanceId))
            {
                monster.UpdateHP(-damage);
            }
            else
            {
                monster.UpdateHP(-damage, _server, true, ownerInstanceId);
            }
        }
Exemplo n.º 12
0
        public void StartCast(SkillBaseSetting skillBase)
        {
            Logger.Debug(
                $"Trap StartCast skillBase.Id [{skillBase.Id}] skillBase.CastingTime [{skillBase.CastingTime}]");
            RecvSkillStartCastSelf startCast = new RecvSkillStartCastSelf(skillBase.Id, skillBase.CastingTime);

            _server.Router.Send(startCast, _client);
            List <PacketResponse>                brList      = new List <PacketResponse>();
            RecvBattleReportStartNotify          brStart     = new RecvBattleReportStartNotify(_client.Character.InstanceId);
            RecvBattleReportEndNotify            brEnd       = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillStartCast brStartCast = new RecvBattleReportActionSkillStartCast(skillBase.Id);

            brList.Add(brStart);
            brList.Add(brStartCast);
            brList.Add(brEnd);
            _server.Router.Send(_client.Map, brList);
        }
Exemplo n.º 13
0
        public void SkillExec()
        {
            List <PacketResponse>           brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify     brStart = new RecvBattleReportStartNotify(_client.Character.InstanceId);
            RecvBattleReportEndNotify       brEnd   = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillExec brExec  =
                new RecvBattleReportActionSkillExec(_client.Character.skillStartCast);

            brList.Add(brStart);
            brList.Add(brExec);
            brList.Add(brEnd);
            _server.Router.Send(_client.Map, brList);

            IBuffer res11 = BufferProvider.Provide();

            res11.WriteUInt32(_client.Character.InstanceId);

            uint newState = 0;

            if (_client.Character.IsStealthed())
            {
                newState = _client.Character.ClearStateBit(0x8);
                res11.WriteUInt32(newState);
            }
            else
            {
                newState = _client.Character.AddStateBit(0x8);
                res11.WriteUInt32(newState);
            }

            RecvCharaNotifyStateflag stateFlag = new RecvCharaNotifyStateflag(_client.Character.InstanceId, newState);

            _server.Router.Send(_client.Map, stateFlag);

            //0bxxxxxxx1 - 1 Soul Form / 0 Normal  | (Soul form is Glowing with No armor)
            //0bxxxxxx1x - 1 Battle Pose / 0 Normal
            //0bxxxxx1xx - 1 Block Pose / 0 Normal | (for coming out of stealth while blocking)
            //0bxxxx1xxx - 1 transparent / 0 solid  | (stealth in party partial visibility)
            //0bxxx1xxxx -
            //0bxx1xxxxx - 1 invisible / 0 visible  | (Stealth to enemies)
            //0bx1xxxxxx - 1 blinking  / 0 solid    | (10  second invulnerability blinking)
            //0b1xxxxxxx -
        }
Exemplo n.º 14
0
        private void PlayerDead()
        {
            playerDied = true;
            List <PacketResponse>       brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify brStart = new RecvBattleReportStartNotify(_client.Character.killerInstanceId);
            RecvBattleReportNoactDead   cDead1  = new RecvBattleReportNoactDead(_client.Character.InstanceId, 1);
            RecvBattleReportNoactDead   cDead2  = new RecvBattleReportNoactDead(_client.Character.InstanceId, 2);
            RecvBattleReportEndNotify   brEnd   = new RecvBattleReportEndNotify();

            brList.Add(brStart);
            brList.Add(cDead1);                                //animate the death of your living body
            brList.Add(brEnd);
            _server.Router.Send(_client.Map, brList, _client); // send death animation to other players


            brList[1] = cDead2;
            _server.Router.Send(_client, brList); // send death animaton to player 1

            DeadBody deadBody = _server.Instances.GetInstance((uint)_client.Character.DeadBodyInstanceId) as DeadBody;

            deadBody.X                   = _client.Character.X;
            deadBody.Y                   = _client.Character.Y;
            deadBody.Z                   = _client.Character.Z;
            deadBody.Heading             = _client.Character.Heading;
            _client.Character.movementId = _client.Character.DeadBodyInstanceId;

            Thread.Sleep(5000);
            _client.Character.hadDied = false; // quick switch to living state so your dead body loads with your gear
            //load your dead body on to the map for you to see in soul form.
            RecvDataNotifyCharaBodyData cBodyData = new RecvDataNotifyCharaBodyData(deadBody, _client);

            _server.Router.Send(_client, cBodyData.ToPacket());

            _client.Character.hadDied = true; // back to dead so your soul appears with-out gear.

            Thread.Sleep(100);

            //reload your living body with no gear
            RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(_client.Character, _client.Soul.Name);

            _server.Router.Send(_client.Map, cData.ToPacket());
        }
Exemplo n.º 15
0
        public void SkillExec(Trap trap, bool isBaseTrap)
        {
            Vector3 trgCoord = new Vector3(_client.Character.X, _client.Character.Y, _client.Character.Z);

            if (!int.TryParse($"{trap._skillId}".Substring(1, 6) + 1, out int effectId))
            {
                Logger.Error($"Creating effectId from skillid [{trap._skillId}]");
            }

            List <PacketResponse>           brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify     brStart = new RecvBattleReportStartNotify(_client.Character.InstanceId);
            RecvBattleReportEndNotify       brEnd   = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillExec brExec  = new RecvBattleReportActionSkillExec(trap._skillId);

            brList.Add(brStart);
            brList.Add(brExec);
            brList.Add(brEnd);
            _server.Router.Send(_client.Map, brList);
            Logger.Debug($"SpearTrap effectId [{effectId}]");
            RecvDataNotifyEoData eoData = new RecvDataNotifyEoData(trap.InstanceId, _client.Character.InstanceId,
                                                                   effectId, trgCoord, 2, 2);

            _server.Router.Send(_map, eoData);

            if (isBaseTrap)
            {
                _trapTask = new TrapTask(_server, _map, _trapPos, _ownerInstanceId, trap, this.InstanceId);
                _trapTask.AddTrap(trap);
                _map.AddTrap(this.InstanceId, this);
                _trapTask.Start();
            }
            else
            {
                _trapTask.AddTrap(trap);
            }
        }
        private void DamageTheObject(NecClient client, uint instanceId, int damage, float perHp)
        {
            List <PacketResponse>       brTargetList = new List <PacketResponse>();
            RecvBattleReportStartNotify brStart      = new RecvBattleReportStartNotify(instanceId);
            RecvBattleReportEndNotify   brEnd        = new RecvBattleReportEndNotify();
            RecvBattleReportActionAttackExec
                brAttack = new RecvBattleReportActionAttackExec(
                (int)instanceId);     //should this be the instance ID of the attacker? we have it marked as skillId
            RecvBattleReportNotifyHitEffect brHit       = new RecvBattleReportNotifyHitEffect(instanceId);
            RecvBattleReportPhyDamageHp     brPhyHp     = new RecvBattleReportPhyDamageHp(instanceId, damage);
            RecvBattleReportDamageHp        brHp        = new RecvBattleReportDamageHp(instanceId, damage);
            RecvObjectHpPerUpdateNotify     oHpUpdate   = new RecvObjectHpPerUpdateNotify(instanceId, perHp);
            RecvBattleReportNotifyKnockback brKnockBack = new RecvBattleReportNotifyKnockback(instanceId, 001, 001);

            brTargetList.Add(brStart);
            brTargetList.Add(brAttack);
            brTargetList.Add(brHit);
            //brTargetList.Add(brPhyHp);
            brTargetList.Add(brHp);
            brTargetList.Add(oHpUpdate);
            //brTargetList.Add(brKnockBack); //knockback doesn't look right here. need to make it better.
            brTargetList.Add(brEnd);
            router.Send(client.map, brTargetList);
        }
Exemplo n.º 17
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 Execute(string[] command, NecClient client, ChatMessage message,
                                     List <ChatResponse> responses)
        {
            if (command[0] == null)
            {
                responses.Add(ChatResponse.CommandError(client, $"Invalid argument: {command[0]}"));
                return;
            }

            List <PacketResponse> brList = new List <PacketResponse>();
            //always start your battle reports
            RecvBattleReportStartNotify brStart = new RecvBattleReportStartNotify(client.character.instanceId);

            brList.Add(brStart);

            RecvBattleReportEndNotify brEnd = new RecvBattleReportEndNotify();


            IBuffer res36 = BufferProvider.Provide();

            switch (command[0])
            {
            case "itemuse":
                RecvBattleReportActionItemUse itemUse = new RecvBattleReportActionItemUse(50100302 /*camp*/);
                brList.Add(itemUse);
                break;

            case "stealunidentified":
                RecvBattleReportActionStealUnidentified stealUnidentified = new RecvBattleReportActionStealUnidentified(50100302 /*camp*/);
                brList.Add(stealUnidentified);
                break;

            case "stealmoney":
                RecvBattleReportActionStealMoney stealMoney = new RecvBattleReportActionStealMoney(50100302 /*camp*/);
                brList.Add(stealMoney);
                break;

            case "97d9":
                RecvBattleReportNoactNotifyHealAp o97d9 = new RecvBattleReportNoactNotifyHealAp();
                brList.Add(o97d9);
                break;

            case "partygetitem":
                RecvPartyNotifyGetItem recvPartyNotifyGetItem = new RecvPartyNotifyGetItem(client.character.instanceId);
                router.Send(recvPartyNotifyGetItem, client);
                IBuffer res = BufferProvider.Provide();
                res.WriteInt32(200101);
                res.WriteCString("Dagger");
                res.WriteByte(20);
                router.Send(client.map, (ushort)MsgPacketId.recv_party_notify_get_item, res, ServerType.Msg);
                break;

            case "partygetmoney":
                RecvPartyNotifyGetMoney recvPartyNotifyGetMoney = new RecvPartyNotifyGetMoney(client.character.instanceId);
                router.Send(client.map, recvPartyNotifyGetMoney);
                break;

            case "ac":
                RecvBattleReportNotifyDamageAc recvBattleReportNotifyDamageAc = new RecvBattleReportNotifyDamageAc(client.character.instanceId, Util.GetRandomNumber(0, 250));
                brList.Add(recvBattleReportNotifyDamageAc);
                break;


            default:
                _Logger.Error($"There is no recv of type : {command[0]} ");
                Task.Delay(TimeSpan.FromMilliseconds(10 * 1000)).ContinueWith
                    (t1 => { }
                    );
                break;
            }

            //always end your battle reports
            //brList.Add(brEnd);
            router.Send(client, brList);
        }
        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
        }
Exemplo n.º 20
0
        public override void Execute(string[] command, NecClient client, ChatMessage message,
                                     List <ChatResponse> responses)
        {
            if (client.Character.hadDied == true)
            {
                IBuffer res4 = BufferProvider.Provide();
                Router.Send(client.Map, (ushort)AreaPacketId.recv_self_lost_notify, res4, ServerType.Area);
            }

            if (client.Character.hadDied == false)
            {
                client.Character.hadDied =
                    true; // setting before the Sleep so other monsters can't "kill you" while you're dieing
                client.Character.Hp.Modify(-client.Character.Hp.current);
                client.Character.state = 0b00000001;
                List <PacketResponse>       brList  = new List <PacketResponse>();
                RecvBattleReportStartNotify brStart = new RecvBattleReportStartNotify(client.Character.InstanceId);
                RecvBattleReportNoactDead   cDead1  = new RecvBattleReportNoactDead(client.Character.InstanceId, 1);
                RecvBattleReportNoactDead   cDead2  = new RecvBattleReportNoactDead(client.Character.InstanceId, 2);
                RecvBattleReportEndNotify   brEnd   = new RecvBattleReportEndNotify();

                brList.Add(brStart);
                brList.Add(cDead1);                             //animate the death of your living body
                brList.Add(brEnd);
                Server.Router.Send(client.Map, brList, client); // send death animation to other players


                brList[1] = cDead2;
                Router.Send(client, brList); // send death animaton to player 1

                DeadBody deadBody =
                    Server.Instances.GetInstance((uint)client.Character.DeadBodyInstanceId) as DeadBody;

                deadBody.X                  = client.Character.X;
                deadBody.Y                  = client.Character.Y;
                deadBody.Z                  = client.Character.Z;
                deadBody.Heading            = client.Character.Heading;
                client.Character.movementId = client.Character.DeadBodyInstanceId;

                Task.Delay(TimeSpan.FromMilliseconds((int)(5 * 1000))).ContinueWith
                    (t1 =>
                {
                    client.Character.hadDied =
                        false;     // quick switch to living state so your dead body loads with your gear
                    //load your dead body on to the map for you to see in soul form.
                    RecvDataNotifyCharaBodyData cBodyData = new RecvDataNotifyCharaBodyData(deadBody, client);
                    Server.Router.Send(client, cBodyData.ToPacket());

                    client.Character.hadDied = true;     // back to dead so your soul appears with-out gear.
                }
                    );

                Task.Delay(TimeSpan.FromMilliseconds((int)(15 * 1000))).ContinueWith
                    (t1 =>
                {
                    //reload your living body with no gear
                    RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(client.Character, client.Soul.Name);
                    Server.Router.Send(client, cData.ToPacket());
                }
                    );
            }
        }
        public void SkillExec()
        {
            Vector3      trgCoord     = new Vector3();
            NpcSpawn     npcSpawn     = null;
            MonsterSpawn monsterSpawn = null;
            Character    character    = null;
            IInstance    target       = _server.instances.GetInstance(_targetInstanceId);

            switch (target)
            {
            case NpcSpawn npc:
                npcSpawn = npc;
                _Logger.Debug(
                    $"NPCId: {npcSpawn.instanceId} is gettin blasted by Skill Effect {_client.character.skillStartCast}");
                trgCoord.X = npcSpawn.x;
                trgCoord.Y = npcSpawn.y;
                trgCoord.Z = npcSpawn.z;
                break;

            case MonsterSpawn monster:
                monsterSpawn = monster;
                _Logger.Debug(
                    $"MonsterId: {monsterSpawn.instanceId} is gettin blasted by Skill Effect {_client.character.skillStartCast}");
                trgCoord.X = monsterSpawn.x;
                trgCoord.Y = monsterSpawn.y;
                trgCoord.Z = monsterSpawn.z;

                break;

            case Character chara:
                character = chara;
                _Logger.Debug(
                    $"CharacterId: {character.instanceId} is gettin blasted by Skill Effect {_client.character.skillStartCast}");
                trgCoord.X = character.x;
                trgCoord.Y = character.y;
                trgCoord.Z = character.z;
                break;

            default:
                _Logger.Error(
                    $"Instance with InstanceId: {_targetInstanceId} does not exist.  the ground is gettin blasted");
                break;
            }

            if (!_server.settingRepository.skillBase.TryGetValue(_skillId, out SkillBaseSetting skillBaseSetting))
            {
                _Logger.Error($"Could not get SkillBaseSetting for skillId : {_skillId}");
                return;
            }

            if (!int.TryParse($"{_skillId}".Substring(1, 6) + 1, out int effectId))
            {
                _Logger.Error($"Creating effectId from skillid [{_skillId}]");
            }

            List <PacketResponse>           brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify     brStart = new RecvBattleReportStartNotify(_client.character.instanceId);
            RecvBattleReportEndNotify       brEnd   = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillExec brExec  =
                new RecvBattleReportActionSkillExec(_client.character.skillStartCast);
            RecvBattleReportActionEffectOnHit brEof = new RecvBattleReportActionEffectOnHit(600021);

            brList.Add(brStart);
            brList.Add(brExec);
            brList.Add(brEof);
            brList.Add(brEnd);
            _server.router.Send(_client.map, brList);
            brList.Clear();
            trgCoord.Z += 10;
            _Logger.Debug($"skillid [{_skillId}] effectId [{effectId}]");

            RecvDataNotifyEoData eoData =
                new RecvDataNotifyEoData(instanceId, _targetInstanceId, effectId, trgCoord, 2, 2);
            //_server.Router.Send(_client.Map, eoData);
            RecvEoNotifyDisappearSchedule eoDisappear = new RecvEoNotifyDisappearSchedule(instanceId, 2.0F);
            //_server.Router.Send(_client.Map, eoDisappear);

            //Vector3 _srcCoord  = new Vector3(_client.Character.X, _client.Character.Y, _client.Character.Z);
            //Recv8D92 effectMove = new Recv8D92(_srcCoord, trgCoord, InstanceId, _client.Character.skillStartCast, 3000, 2, 2);  // ToDo need real velocities
            //_server.Router.Send(_client.Map, effectMove);

            int damage = Util.GetRandomNumber(70, 90);
            //RecvDataNotifyEoData eoTriggerData = new RecvDataNotifyEoData(_client.Character.InstanceId, monsterSpawn.InstanceId, effectId, _srcCoord, 2, 2);
            //_server.Router.Send(_client.Map, eoTriggerData);
            int monsterHp = monsterSpawn.hp.current;
            List <PacketResponse> brList2 = new List <PacketResponse>();
            float perHp = monsterHp > 0 ? monsterHp / (float)monsterSpawn.hp.max * 100 : 0;
            RecvBattleReportStartNotify brStart1 = new RecvBattleReportStartNotify(_client.character.instanceId);
            RecvBattleReportEndNotify   brEnd1   = new RecvBattleReportEndNotify();
            //RecvBattleReportDamageHp brHp = new RecvBattleReportDamageHp(monsterSpawn.InstanceId, damage);
            RecvBattleReportPhyDamageHp     brPhyHp   = new RecvBattleReportPhyDamageHp(monsterSpawn.instanceId, damage);
            RecvObjectHpPerUpdateNotify     oHpUpdate = new RecvObjectHpPerUpdateNotify(monsterSpawn.instanceId, perHp);
            RecvBattleReportNotifyHitEffect brHit     = new RecvBattleReportNotifyHitEffect(monsterSpawn.instanceId);

            brList2.Add(brStart1);
            //brList2.Add(brHp);
            brList2.Add(brPhyHp);
            brList2.Add(oHpUpdate);
            brList2.Add(brHit);
            brList2.Add(brEnd1);
            //brList.Add(oHpUpdate);
            _server.router.Send(_client.map, brList2);
            //if (monsterSpawn.GetAgroCharacter(_client.Character.InstanceId))
            //{
            // monsterSpawn.UpdateHP(-damage);
            //}
            //else
            //{
            //monsterSpawn.UpdateHP(-damage, _server, true, _client.Character.InstanceId);
            //}
            _Logger.Debug($"{monsterSpawn.name} has {monsterSpawn.hp.current} HP left.");
        }
        public bool MonsterCheck()
        {
            // Logger.Debug($"Monster HP [{_monster.GetHP()}]");
            if (monster.hp.current <= 0)
            {
                foreach (uint instanceId in monster.GetAgroInstanceList())
                {
                    monster.MonsterHate(server, false, instanceId);

                    NecClient client = server.clients.GetByCharacterInstanceId(instanceId);
                    client.character.experienceCurrent += monster.loot.experience;

                    IBuffer res = BufferProvider.Provide();
                    res.WriteUInt64(client.character.experienceCurrent);
                    res.WriteByte(0);                                                                            //bool
                    server.router.Send(client, (ushort)AreaPacketId.recv_self_exp_notify, res, ServerType.Area); //This should go to the party of whomever did the most damage.  TODO

                    //To-Do,  make a variable to track union gold
                    client.character.adventureBagGold += monster.loot.gold; //Updates your Character.AdventureBagGold
                    server.database.UpdateCharacter(client.character);

                    res = BufferProvider.Provide();
                    res.WriteUInt64(client.character.adventureBagGold); // Sets your Adventure Bag Gold
                    server.router.Send(client, (ushort)AreaPacketId.recv_self_money_notify, res, ServerType.Area);
                }

                _Logger.Debug($"Monster is dead InstanceId [{monster.instanceId}]");
                //Death Animation
                List <PacketResponse>       brList  = new List <PacketResponse>();
                RecvBattleReportStartNotify brStart = new RecvBattleReportStartNotify(monster.instanceId);
                RecvBattleReportEndNotify   brEnd   = new RecvBattleReportEndNotify();
                RecvBattleReportNoactDead   brDead  = new RecvBattleReportNoactDead(monster.instanceId, 1);
                brList.Add(brStart);
                brList.Add(brDead);
                brList.Add(brEnd);
                server.router.Send(_map, brList);

                //Make the monster a lootable state
                IBuffer res10 = BufferProvider.Provide();
                res10.WriteUInt32(monster.instanceId);
                res10.WriteInt32(2); //Toggles state between Alive(attackable),  Dead(lootable), or Inactive(nothing).
                server.router.Send(_map, (ushort)AreaPacketId.recv_monster_state_update_notify, res10,
                                   ServerType.Area);

                Thread.Sleep(monster.respawnTime);
                //decompose the body
                IBuffer res7 = BufferProvider.Provide();
                res7.WriteUInt32(monster.instanceId);
                res7.WriteInt32(Util.GetRandomNumber(1, 5)); //4 here causes a cloud and the model to disappear, 5 causes a mist to happen and disappear
                res7.WriteInt32(1);
                server.router.Send(_map, (ushort)AreaPacketId.recv_charabody_notify_deadstate, res7, ServerType.Area);
                Thread.Sleep(2000);
                RecvObjectDisappearNotify objectDisappearData = new RecvObjectDisappearNotify(monster.instanceId);
                server.router.Send(_map, objectDisappearData);
                monster.monsterVisible = false;

                _spawnMonster = true;
                return(true);
            }

            return(false);
        }
Exemplo n.º 23
0
        private void PlayerDead()
        {
            _playerDied = true;
            _client.character.hasDied  = true;
            _client.character.state    = CharacterState.SoulForm;
            _client.character.deadType = (short)Util.GetRandomNumber(1, 4);
            _Logger.Debug($"Death Animation Number : {_client.character.deadType}");

            List <PacketResponse>       brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify brStart = new RecvBattleReportStartNotify(_client.character.instanceId);
            RecvBattleReportNoactDead   cDead1  = new RecvBattleReportNoactDead(_client.character.instanceId, _client.character.deadType);
            RecvBattleReportEndNotify   brEnd   = new RecvBattleReportEndNotify();

            brList.Add(brStart);
            brList.Add(cDead1);                       //animate the death of your living body
            brList.Add(brEnd);
            _server.router.Send(_client.map, brList); // send death animation to all players

            DeadBody deadBody = _server.instances.GetInstance(_client.character.deadBodyInstanceId) as DeadBody;

            deadBody.x                  = _client.character.x;
            deadBody.y                  = _client.character.y;
            deadBody.z                  = _client.character.z;
            deadBody.heading            = _client.character.heading;
            deadBody.beginnerProtection = (byte)_client.character.beginnerProtection;
            deadBody.charaName          = _client.character.name;
            deadBody.soulName           = _client.soul.name;
            deadBody.equippedItems      = _client.character.equippedItems;
            deadBody.raceId             = _client.character.raceId;
            deadBody.sexId              = _client.character.sexId;
            deadBody.hairId             = _client.character.hairId;
            deadBody.hairColorId        = _client.character.hairColorId;
            deadBody.faceId             = _client.character.faceId;
            deadBody.faceArrangeId      = _client.character.faceArrangeId;
            deadBody.voiceId            = _client.character.voiceId;
            deadBody.level              = _client.character.level;
            deadBody.classId            = _client.character.classId;
            deadBody.equippedItems      = _client.character.equippedItems;
            deadBody.criminalStatus     = _client.character.criminalState;
            deadBody.connectionState    = 1;
            _clients = _client.map.clientLookup.GetAll();
            _client.map.deadBodies.Add(deadBody.instanceId, deadBody);
            List <NecClient> soulStateClients = new List <NecClient>();

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

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

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

            //load your dead body on the map for looting.  disappear your character model for everyone else besides you
            Task.Delay(TimeSpan.FromSeconds(5)).ContinueWith
                (t1 =>
            {
                RecvDataNotifyCharaBodyData cBodyData = new RecvDataNotifyCharaBodyData(deadBody);
                if (_client.map.id.ToString()[0] != "1"[0])     //Don't Render dead bodies in town.  Town map ids all start with 1
                {
                    _server.router.Send(_client.map, cBodyData.ToPacket(), _client);
                }
                _server.router.Send(_client, cBodyData.ToPacket());
                RecvObjectDisappearNotify recvObjectDisappearNotify = new RecvObjectDisappearNotify(_client.character.instanceId);
                _server.router.Send(_client.map, recvObjectDisappearNotify.ToPacket(), _client);
                //send your soul to all the other souls runnin around
                foreach (NecClient client in _clients)
                {
                    if (client.character.state == CharacterState.SoulForm)
                    {
                        soulStateClients.Add(client);
                    }
                }
                //re-render your soulstate character to your client with out gear on it, and any other soul state clients on map.
                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(_client.character, _client.soul.name);
                _server.router.Send(soulStateClients, cData.ToPacket());
            }
                );
            //Re-render all the NPCs and Monsters, and character objects
            Task.Delay(TimeSpan.FromSeconds(6)).ContinueWith
                (t1 =>
            {
                foreach (NecClient otherClient in _clients)
                {
                    if (otherClient == _client)
                    {
                        // skip myself
                        continue;
                    }
                    //Render all the souls if you are in soul form yourself
                    if (otherClient.character.state == CharacterState.SoulForm)
                    {
                        RecvDataNotifyCharaData otherCharacterData = new RecvDataNotifyCharaData(otherClient.character, otherClient.soul.name);
                        _server.router.Send(otherCharacterData, _client);
                    }

                    if (otherClient.union != null)
                    {
                        RecvDataNotifyUnionData otherUnionData = new RecvDataNotifyUnionData(otherClient.character, otherClient.union.name);
                        _server.router.Send(otherUnionData, _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);
                        _server.router.Send(npcData, _client);
                    }
                }
            }
                );
        }
Exemplo n.º 24
0
        public void SkillExec()
        {
            Vector3      trgCoord     = new Vector3();
            NpcSpawn     npcSpawn     = null;
            MonsterSpawn monsterSpawn = null;
            Character    character    = null;
            float        perHp        = 0;
            int          damage       = Util.GetRandomNumber(70, 90);
            IInstance    target       = _server.Instances.GetInstance((uint)_targetInstanceId);

            switch (target)
            {
            case NpcSpawn npc:
                npcSpawn = npc;
                Logger.Debug(
                    $"NPCId: {npcSpawn.InstanceId} SerialId: {npcSpawn.Id} is gettin blasted by Skill Effect {_client.Character.skillStartCast}");
                trgCoord.X = npcSpawn.X;
                trgCoord.Y = npcSpawn.Y;
                trgCoord.Z = npcSpawn.Z;
                break;

            case MonsterSpawn monster:
                monsterSpawn = monster;
                Logger.Debug(
                    $"MonsterId: {monsterSpawn.InstanceId} is gettin blasted by Skill Effect {_client.Character.skillStartCast}");
                trgCoord.X = monsterSpawn.X;
                trgCoord.Y = monsterSpawn.Y;
                trgCoord.Z = monsterSpawn.Z;
                int monsterHP = monsterSpawn.Hp.current;
                perHp = monsterHP > 0 ? (((float)monsterHP / (float)monsterSpawn.Hp.max) * 100) : 0;
                if (monsterSpawn.GetAgroCharacter(_client.Character.InstanceId))
                {
                    monsterSpawn.UpdateHP(-damage);
                }
                else
                {
                    monsterSpawn.UpdateHP(-damage, _server, true, _client.Character.InstanceId);
                }

                break;

            case Character chara:
                character = chara;
                Logger.Debug(
                    $"CharacterId: {character.InstanceId} is gettin blasted by Skill Effect {_client.Character.skillStartCast}");
                trgCoord.X = character.X;
                trgCoord.Y = character.Y;
                trgCoord.Z = character.Z;
                break;

            default:
                Logger.Error(
                    $"Instance with InstanceId: {target.InstanceId} does not exist.  the ground is gettin blasted");
                break;
            }

            if (!_server.SettingRepository.SkillBase.TryGetValue(_skillId, out SkillBaseSetting skillBaseSetting))
            {
                Logger.Error($"Could not get SkillBaseSetting for skillId : {_skillId}");
                return;
            }

            List <PacketResponse>           brList  = new List <PacketResponse>();
            RecvBattleReportStartNotify     brStart = new RecvBattleReportStartNotify(_client.Character.InstanceId);
            RecvBattleReportEndNotify       brEnd   = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillExec brExec  =
                new RecvBattleReportActionSkillExec(_client.Character.skillStartCast);

            brList.Add(brStart);
            brList.Add(brExec);
            brList.Add(brEnd);
            _server.Router.Send(_client.Map, brList);
            if (!int.TryParse($"{_skillId}".Substring(1, 6) + 1, out int effectId))
            {
                Logger.Error($"Creating effectId from skillid [{_skillId}]");
            }

            trgCoord.Z += 10;
            Logger.Debug($"skillid [{_skillId}] effectId [{effectId}]");
            RecvDataNotifyEoData eoData =
                new RecvDataNotifyEoData(InstanceId, _targetInstanceId, effectId, trgCoord, 2, 2);

            _server.Router.Send(_client.Map, eoData);
            RecvEoNotifyDisappearSchedule eoDisappear = new RecvEoNotifyDisappearSchedule(InstanceId, 2.0F);

            _server.Router.Send(_client.Map, eoDisappear);

            Vector3  _srcCoord  = new Vector3(_client.Character.X, _client.Character.Y, _client.Character.Z);
            Recv8D92 effectMove = new Recv8D92(_srcCoord, trgCoord, InstanceId, _client.Character.skillStartCast, 3000,
                                               2, 2); // ToDo need real velocities

            _server.Router.Send(_client.Map, effectMove);

            RecvDataNotifyEoData eoTriggerData = new RecvDataNotifyEoData(_client.Character.InstanceId,
                                                                          _targetInstanceId, effectId, _srcCoord, 2, 2);

            _server.Router.Send(_client.Map, eoTriggerData);

            RecvBattleReportDamageHp        brHp      = new RecvBattleReportDamageHp(_targetInstanceId, damage);
            RecvObjectHpPerUpdateNotify     oHpUpdate = new RecvObjectHpPerUpdateNotify(_targetInstanceId, perHp);
            RecvBattleReportNotifyHitEffect brHit     = new RecvBattleReportNotifyHitEffect(_targetInstanceId);

            brList.Add(brStart);
            brList.Add(brHp);
            brList.Add(oHpUpdate);
            brList.Add(brHit);
            brList.Add(brEnd);
            brList.Add(oHpUpdate);
            _server.Router.Send(_client.Map, brList);
        }