Esempio n. 1
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);
            }
        }
        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);
        }
Esempio n. 3
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 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.");
        }
Esempio n. 5
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);
        }