public override void Handle(NecClient client, NecPacket packet)
        {
            ItemEquipSlots equipSlot = (ItemEquipSlots)(1 << packet.data.ReadInt32());

            ItemService itemService = new ItemService(client.character);
            int         error       = 0;

            _Logger.Debug(equipSlot.ToString());
            try
            {
                ItemInstance unequippedItem = itemService.CheckAlreadyEquipped(equipSlot);
                unequippedItem = itemService.Unequip(unequippedItem.currentEquipSlot);
                RecvItemUpdateEqMask recvItemUpdateEqMask = new RecvItemUpdateEqMask(client, unequippedItem);
                router.Send(recvItemUpdateEqMask);

                //notify other players of your new look
                RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.character, client.soul.name);
                router.Send(client.map, myCharacterData, client);
            }
            catch (ItemException e)
            {
                error = (int)e.type;
            }

            RecvItemUnequip recvItemUnequip = new RecvItemUnequip(client, error);

            router.Send(recvItemUnequip);

            //Re-do all your stats
            router.Send(client, itemService.CalculateBattleStats(client));
        }
Exemplo n.º 2
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            int       response  = packet.data.ReadInt32();                                                             //0 for yes, -1 for no;
            NecClient necClient = server.clients.GetByCharacterInstanceId((uint)client.character.eventSelectExecCode); //Salvager

            //Notify the dead client that it has accepted body collection and it's soul now posseses the salvager.
            RecvCharaBodySelfSalvageResult recvCharaBodySelfSalvageResult = new RecvCharaBodySelfSalvageResult(response);

            router.Send(client, recvCharaBodySelfSalvageResult.ToPacket());

            //tell the salvager about your choice.
            RecvCharaBodySalvageRequest recvCharaBodySalvageRequest = new RecvCharaBodySalvageRequest(response);

            router.Send(necClient, recvCharaBodySalvageRequest.ToPacket());


            if (response == (int)MyResponse.AcceptCollection)
            {
                //tell the dead client who collected the body
                RecvCharaBodySalvageNotifySalvager recvCharaBodySalvageNotifySalvager = new RecvCharaBodySalvageNotifySalvager(necClient.character.instanceId, necClient.character.name, necClient.soul.name);
                router.Send(client, recvCharaBodySalvageNotifySalvager.ToPacket());

                //tell the salvager who they collected.
                RecvCharaBodySalvageNotifyBody recvCharaBodySalvageNotifyBody = new RecvCharaBodySalvageNotifyBody(client.character.deadBodyInstanceId, client.character.name, client.soul.name);
                router.Send(necClient, recvCharaBodySalvageNotifyBody.ToPacket());

                //tell the salvager to close the charabody access window.
                RecvCharaBodyAccessEnd recvCharaBodyAccessEnd = new RecvCharaBodyAccessEnd(0);
                router.Send(necClient, recvCharaBodyAccessEnd.ToPacket());

                //Tell the deadBody to disappear from the map, as it's being carried.
                RecvObjectDisappearNotify recvObjectDisappearNotify = new RecvObjectDisappearNotify(client.character.deadBodyInstanceId);
                router.Send(client.map, recvObjectDisappearNotify);

                //Tell the deadClient it can see the salvager even in soul form now.
                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(necClient.character, necClient.soul.name);
                router.Send(client, cData.ToPacket());

                //remove the deadBody from the map so newly entering players can't see it.
                client.map.deadBodies.Remove(client.character.deadBodyInstanceId);

                //Add the deadBody to the client that's carrying it for Movement Sends
                necClient.bodyCollection.Add(client.character.deadBodyInstanceId, client);

                //move the soulState client to the salvagers position
                IBuffer res5 = BufferProvider.Provide();
                res5.WriteUInt32(client.character.instanceId);
                res5.WriteFloat(necClient.character.x);
                res5.WriteFloat(necClient.character.y);
                res5.WriteFloat(necClient.character.z);
                res5.WriteByte(necClient.character.heading);      //Heading
                res5.WriteByte(necClient.character.movementAnim); //state
                router.Send(client, (ushort)AreaPacketId.recv_object_point_move_notify, res5, ServerType.Area);
            }
        }
Exemplo n.º 3
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            ItemZoneType fromZone      = (ItemZoneType)packet.data.ReadByte();
            byte         fromContainer = packet.data.ReadByte();
            short        fromSlot      = packet.data.ReadInt16();

            if (fromZone == ItemZoneType.CorpseAdventureBag)
            {
                fromZone = ItemZoneType.AdventureBag;
            }
            if (fromZone == ItemZoneType.CorpseEquippedBags)
            {
                fromZone = ItemZoneType.EquippedBags;
            }
            if (fromZone == ItemZoneType.CorpsePremiumBag)
            {
                fromZone = ItemZoneType.PremiumBag;
            }
            ItemLocation fromLoc = new ItemLocation(fromZone, fromContainer, fromSlot); //subtract 71 to get from BodyCollection to Adventurer

            client.map.deadBodies.TryGetValue(client.character.eventSelectReadyCode, out DeadBody deadBody);
            Character deadCharacter = _server.instances.GetInstance(deadBody.characterInstanceId) as Character;
            NecClient deadClient    = _server.clients.GetByCharacterInstanceId(deadBody.characterInstanceId);

            if (deadCharacter != null)
            {
                deadCharacter.lootNotify = fromLoc;                        //gotta be able to pass this information to loot_complete2 on successful loot
            }
            //Tell your character to start looting the dead body.  Updates Pose
            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0);  //result / err check
            res.WriteInt32(10); //loot time
            router.Send(client, (ushort)AreaPacketId.recv_charabody_loot_start2_r, res, ServerType.Area);

            if (deadClient != null)
            {
                //Tell the other player that they are getting lootified.
                res = BufferProvider.Provide();
                res.WriteByte((byte)fromZone);
                res.WriteByte(fromContainer);
                res.WriteInt16(fromSlot);
                res.WriteFloat(1);                            //base loot time
                res.WriteFloat(10);                           // loot time
                res.WriteCString($"{client.soul.name}");      // soul name
                res.WriteCString($"{client.character.name}"); // chara name
                router.Send(deadClient, (ushort)AreaPacketId.recv_charabody_notify_loot_start2, res, ServerType.Area);

                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(client.character, client.soul.name);
                _server.router.Send(deadClient, cData.ToPacket());
            }
        }
Exemplo n.º 4
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            uint targetId = packet.data.ReadUInt32();

            client.bodyCollection.TryGetValue(targetId, out NecClient necClient);
            client.bodyCollection.Remove(targetId);
            DeadBody deadBody = server.instances.GetInstance(targetId) as DeadBody;

            RecvCharaBodySelfSalvageEnd recvCharaBodySelfSalvageEnd = new RecvCharaBodySelfSalvageEnd(0);

            router.Send(necClient, recvCharaBodySelfSalvageEnd.ToPacket());


            deadBody.x            = client.character.x;
            deadBody.y            = client.character.y;
            deadBody.z            = client.character.z;
            necClient.character.x = client.character.x;
            necClient.character.y = client.character.y;
            necClient.character.z = client.character.z;

            deadBody.mapId = client.character.mapId;
            client.map.deadBodies.Add(deadBody.instanceId, deadBody);
            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());
            }

            //must occur after the charaBody notify.
            RecvCharaBodySalvageEnd recvCharaBodySalvageEnd = new RecvCharaBodySalvageEnd(deadBody.instanceId, 1);

            router.Send(client, recvCharaBodySalvageEnd.ToPacket());

            //send your soul to all the other souls runnin around
            RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(necClient.character, necClient.soul.name);

            foreach (NecClient soulStateClient in client.map.clientLookup.GetAll())
            {
                if (soulStateClient.character.state == CharacterState.SoulForm)
                {
                    server.router.Send(soulStateClient, cData.ToPacket());
                }
            }
        }
Exemplo n.º 5
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            NecClient necClient = server.clients.GetByCharacterInstanceId((uint)client.character.eventSelectExecCode);

            necClient.bodyCollection.Remove(client.character.deadBodyInstanceId);
            DeadBody deadBody = server.instances.GetInstance(client.character.deadBodyInstanceId) as DeadBody;

            RecvCharaBodySelfSalvageEnd recvCharaBodySelfSalvageEnd = new RecvCharaBodySelfSalvageEnd(0);

            router.Send(client, recvCharaBodySelfSalvageEnd.ToPacket());

            deadBody.x         = necClient.character.x;
            deadBody.y         = necClient.character.y;
            deadBody.z         = necClient.character.z;
            client.character.x = necClient.character.x;
            client.character.y = necClient.character.y;
            client.character.z = necClient.character.z;

            deadBody.mapId = necClient.character.mapId;
            client.map.deadBodies.Add(deadBody.instanceId, deadBody);
            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());
            }

            RecvCharaBodySalvageEnd recvCharaBodySalvageEnd = new RecvCharaBodySalvageEnd(client.character.deadBodyInstanceId, 0);

            router.Send(necClient, recvCharaBodySalvageEnd.ToPacket());

            //send your soul to all the other souls runnin around
            RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(client.character, client.soul.name);

            foreach (NecClient soulStateClient in client.map.clientLookup.GetAll())
            {
                if (soulStateClient.character.state == CharacterState.SoulForm)
                {
                    server.router.Send(soulStateClient, cData.ToPacket());
                }
            }
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            IBuffer res = BufferProvider.Provide();

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

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

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

            IBuffer res4 = BufferProvider.Provide();

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

            IBuffer res5 = BufferProvider.Provide();

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

            IBuffer res6 = BufferProvider.Provide();

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

            IBuffer res3 = BufferProvider.Provide();

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

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

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

            IBuffer res7 = BufferProvider.Provide();

            res7.WriteByte(0);
            Router.Send(client, (ushort)AreaPacketId.recv_event_end, res7, ServerType.Area);
        }
Exemplo n.º 7
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.º 8
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            ItemZoneType   zone      = (ItemZoneType)packet.data.ReadByte();
            byte           bag       = packet.data.ReadByte();
            short          slot      = packet.data.ReadInt16();
            ItemEquipSlots equipSlot = (ItemEquipSlots)packet.data.ReadInt32();

            _Logger.Debug($"storageType:{zone} bagId:{bag} bagSlotIndex:{slot} equipBit:{equipSlot}");

            ItemLocation location    = new ItemLocation(zone, bag, slot);
            ItemService  itemService = new ItemService(client.character);
            int          error       = 0;

            try
            {
                if (equipSlot.HasFlag(ItemEquipSlots.LeftHand | ItemEquipSlots.RightHand)) //two handed weapon replaces 1h weapon and shield
                {
                    ItemInstance itemRight = itemService.CheckAlreadyEquipped(ItemEquipSlots.RightHand);
                    if (itemRight != null)
                    {
                        itemRight = itemService.Unequip(itemRight.currentEquipSlot);
                        itemRight.currentEquipSlot = ItemEquipSlots.None;
                        RecvItemUpdateEqMask recvItemUpdateEqMaskCurr = new RecvItemUpdateEqMask(client, itemRight);
                        router.Send(recvItemUpdateEqMaskCurr, client);
                    }

                    ItemInstance itemLeft = itemService.CheckAlreadyEquipped(ItemEquipSlots.LeftHand);
                    if (itemLeft != null)
                    {
                        itemLeft = itemService.Unequip(itemLeft.currentEquipSlot);
                        itemLeft.currentEquipSlot = ItemEquipSlots.None;
                        RecvItemUpdateEqMask recvItemUpdateEqMaskCurr = new RecvItemUpdateEqMask(client, itemLeft);
                        router.Send(recvItemUpdateEqMaskCurr, client);
                    }
                }
                else //everything else besides 2h weapons.
                {
                    //update the equipment array
                    ItemInstance equippedItem = itemService.CheckAlreadyEquipped(equipSlot);
                    if (equippedItem != null)
                    {
                        equippedItem = itemService.Unequip(equippedItem.currentEquipSlot);
                        equippedItem.currentEquipSlot = ItemEquipSlots.None;
                        RecvItemUpdateEqMask recvItemUpdateEqMaskCurr = new RecvItemUpdateEqMask(client, equippedItem);
                        router.Send(recvItemUpdateEqMaskCurr, client);
                    }
                }

                //update the equipment array
                ItemInstance newEquippedItem = itemService.Equip(location, equipSlot);

                //Tell the client to move the icons to equipment slots
                RecvItemUpdateEqMask recvItemUpdateEqMask = new RecvItemUpdateEqMask(client, newEquippedItem);
                router.Send(client, recvItemUpdateEqMask.ToPacket());

                //notify other players of your new look
                RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.character, client.soul.name);
                router.Send(client.map, myCharacterData, client);
            }
            catch (ItemException e)
            {
                error = (int)e.type;
            }

            //tell the send if everything went well or not.  notify the client chat of any errors
            RecvItemEquip recvItemEquip = new RecvItemEquip(client, error);

            router.Send(recvItemEquip);

            //Re-do all your stats
            router.Send(client, itemService.CalculateBattleStats(client));
        }
Exemplo n.º 9
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            //you are dead here.  only getting soul form characters and NPCs.  sorry bro.
            if (client.character.state.HasFlag(CharacterState.SoulForm))
            {
                _Logger.Debug("Rendering Dead stuff");
                foreach (NecClient otherClient in client.map.clientLookup.GetAll())
                {
                    if (otherClient == client)
                    {
                        // skip myself
                        continue;
                    }
                    //Render all the souls if you are in soul form yourself
                    if (otherClient.character.state.HasFlag(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 (NpcSpawn npcSpawn in client.map.npcSpawns.Values)
                {
                    if (npcSpawn.visibility == 2 | npcSpawn.visibility == 3) //2 is the magic number for soul state only.  make it an Enum some day
                    {
                        RecvDataNotifyNpcData npcData = new RecvDataNotifyNpcData(npcSpawn);
                        router.Send(npcData, client);
                    }
                }
            }
            else //if you are not dead, do normal stuff.  else...  do dead person stuff
            {
                _Logger.Debug($"Not dead.  rendering living stuff.  CharacterState:{client.character.state}");
                foreach (NecClient otherClient in client.map.clientLookup.GetAll())
                {
                    if (otherClient == client)
                    {
                        continue;
                    }
                    if (!otherClient.character.state.HasFlag(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);
                    _Logger.Debug($"Monster Id {monsterSpawn.id} with model {monsterSpawn.modelId} is loading");
                    router.Send(monsterData, client);
                }

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

            //Allways render the stuff below this line.
            if (client.map.id.ToString()[0] != "1"[0]) //Don't Render dead bodies in town.  Town map ids all start with 1
            {
                foreach (DeadBody deadBody in client.map.deadBodies.Values)
                {
                    RecvDataNotifyCharaBodyData deadBodyData = new RecvDataNotifyCharaBodyData(deadBody);
                    router.Send(deadBodyData, client);
                }
            }

            foreach (Gimmick gimmickSpawn in client.map.gimmickSpawns.Values)
            {
                RecvDataNotifyGimmickData gimmickData = new RecvDataNotifyGimmickData(gimmickSpawn);
                router.Send(gimmickData, client);
            }

            foreach (GGateSpawn gGateSpawn in client.map.gGateSpawns.Values)
            {
                RecvDataNotifyGGateStoneData gGateSpawnData = new RecvDataNotifyGGateStoneData(gGateSpawn);
                router.Send(gGateSpawnData, client);
            }

            foreach (MapTransition mapTran in client.map.mapTransitions.Values)
            {
                RecvDataNotifyMapLink mapLink = new RecvDataNotifyMapLink(mapTran.instanceId, mapTran.referencePos, mapTran.maplinkOffset, mapTran.maplinkWidth, mapTran.maplinkColor, mapTran.maplinkHeading);
                router.Send(mapLink, client);

                //un-comment for debugging maplinks to visualize the left and right Reference Positions

                /*
                 * GGateSpawn gGateSpawn = new GGateSpawn();
                 * Server.Instances.AssignInstance(gGateSpawn);
                 * gGateSpawn.X = mapTran.LeftPos.X;
                 * gGateSpawn.Y = mapTran.LeftPos.Y;
                 * gGateSpawn.Z = mapTran.LeftPos.Z;
                 * gGateSpawn.Heading = mapTran.MaplinkHeading;
                 * gGateSpawn.Name = $"This is the Left Side of the transition";
                 * gGateSpawn.Title = $"X: {mapTran.LeftPos.X}  Y:{mapTran.LeftPos.Y} ";
                 * gGateSpawn.MapId = mapTran.MapId;
                 * gGateSpawn.ModelId = 1805000;
                 * gGateSpawn.Active = 0;
                 * gGateSpawn.SerialId = 1900001;
                 *
                 * RecvDataNotifyGGateData gGateData = new RecvDataNotifyGGateData(gGateSpawn);
                 * Router.Send(gGateData, client);
                 *
                 * gGateSpawn = new GGateSpawn();
                 * Server.Instances.AssignInstance(gGateSpawn);
                 * gGateSpawn.X = mapTran.RightPos.X;
                 * gGateSpawn.Y = mapTran.RightPos.Y;
                 * gGateSpawn.Z = mapTran.RightPos.Z;
                 * gGateSpawn.Heading = mapTran.MaplinkHeading;
                 * gGateSpawn.Name = $"This is the Right Side of the transition";
                 * gGateSpawn.Title = $"X: {mapTran.RightPos.X}  Y:{mapTran.RightPos.Y} ";
                 * gGateSpawn.MapId = mapTran.MapId;
                 * gGateSpawn.ModelId = 1805000;
                 * gGateSpawn.Active = 0;
                 * gGateSpawn.SerialId = 1900002;
                 *
                 * gGateData = new RecvDataNotifyGGateData(gGateSpawn);
                 * Router.Send(gGateData, client);
                 */
            }

            // ToDo this should be a database lookup
            RecvMapFragmentFlag mapFragments = new RecvMapFragmentFlag(client.map.id, 0xff);

            router.Send(mapFragments, client);


            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0);
            router.Send(client, (ushort)AreaPacketId.recv_map_get_info_r, res, ServerType.Area);
        }
Exemplo n.º 10
0
        public void Enter(NecClient client, MapPosition mapPosition = null)
        {
            if (client.Map != null)
            {
                client.Map.Leave(client);
            }

            Logger.Info(client, $"Entering Map: {Id}:{FullName}");
            // If position is passed in use it and set character position, if null then use map default coords
            // If this isn't set here, the wrong coords are in character until send_movement_info updates it.
            if (mapPosition != null)
            {
                client.Character.X       = mapPosition.X;
                client.Character.Y       = mapPosition.Y;
                client.Character.Z       = mapPosition.Z;
                client.Character.Heading = mapPosition.Heading;
            }
            else
            {
                client.Character.X       = this.X;
                client.Character.Y       = this.Y;
                client.Character.Z       = this.Z;
                client.Character.Heading = this.Orientation;
            }

            client.Map                 = this;
            client.Character.MapId     = Id;
            client.Character.mapChange = false;
            ClientLookup.Add(client);
            Logger.Debug($"Client Lookup count is now : {ClientLookup.GetAll().Count}  for map  {this.Id} ");

            RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.Character, client.Soul.Name);

            _server.Router.Send(this, myCharacterData, client);
            if (client.Union != null)
            {
                RecvDataNotifyUnionData myUnionData = new RecvDataNotifyUnionData(client.Character, client.Union.Name);
                _server.Router.Send(this, myUnionData, client);
            }

            foreach (MonsterSpawn monsterSpawn in this.MonsterSpawns.Values)
            {
                if (monsterSpawn.Active == true)
                {
                    monsterSpawn.SpawnActive = true;
                    if (!monsterSpawn.TaskActive)
                    {
                        MonsterTask monsterTask = new MonsterTask(_server, monsterSpawn);
                        if (monsterSpawn.defaultCoords)
                        {
                            monsterTask.monsterHome = monsterSpawn.monsterCoords[0];
                        }
                        else
                        {
                            monsterTask.monsterHome = monsterSpawn.monsterCoords.Find(x => x.CoordIdx == 64);
                        }
                        monsterTask.Start();
                    }
                    else
                    {
                        if (monsterSpawn.MonsterVisible)
                        {
                            Logger.Debug($"MonsterTask already running for [{monsterSpawn.Name}]");
                            RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn);
                            _server.Router.Send(monsterData, client);
                            if (!monsterSpawn.GetAgro())
                            {
                                monsterSpawn.MonsterMove(_server, client, monsterSpawn.MonsterWalkVelocity, (byte)2,
                                                         (byte)0);
                            }
                        }
                    }
                }
            }

            //on successful map entry, update the client database position
            if (!_server.Database.UpdateCharacter(client.Character))
            {
                Logger.Error("Could not update the database with current known player position");
            }
        }
        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.º 12
0
        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;
            }

            Character character2 = null;

            if (uint.TryParse(command[1], out uint x))
            {
                IInstance instance = server.instances.GetInstance(x);
                if (instance is Character character)
                {
                    character2 = character;
                }
                else if (instance is DeadBody deadbody)
                {
                    responses.Add(ChatResponse.CommandError(client, "That's a dead body man. have some respect!"));
                    character2            = new Character();
                    character2.instanceId = deadbody.instanceId;
                }
                else
                {
                    responses.Add(ChatResponse.CommandError(client, "Please provide a character instance id"));
                    return;
                }
            }

            if (!int.TryParse(command[2], out int y))
            {
                try
                {
                    string binaryString = command[2];
                    binaryString = binaryString.Replace("0b", "");
                    _Logger.Debug(binaryString);
                    y = Convert.ToInt32(binaryString, 2);
                }
                catch
                {
                    responses.Add(ChatResponse.CommandError(client, "Please provide a value to test"));
                    return;
                }
            }


            switch (command[0])
            {
            case "hp":
                IBuffer res = BufferProvider.Provide();
                res.WriteInt32(y);
                character2.hp.SetCurrent(y);
                router.Send(client, (ushort)AreaPacketId.recv_chara_update_hp, res, ServerType.Area);

                RecvCharaUpdateMaxHp recvCharaUpdateMaxHp1 = new RecvCharaUpdateMaxHp(y);
                if (y > character2.hp.max)
                {
                    router.Send(client, recvCharaUpdateMaxHp1.ToPacket());
                }
                break;

            case "dead":
                SendBattleReportStartNotify(client, character2);
                //recv_battle_report_noact_notify_dead = 0xCDC9,
                IBuffer res2 = BufferProvider.Provide();
                res2.WriteUInt32(character2.instanceId);
                res2.WriteInt32(2);     // death type? 1 = death, 2 = death and message, 3 = unconscious, beyond that = nothing
                res2.WriteInt32(2);
                res2.WriteInt32(y);
                router.Send(client.map, (ushort)AreaPacketId.recv_battle_report_noact_notify_dead, res2,
                            ServerType.Area);
                SendBattleReportEndNotify(client, character2);
                break;


            case "pose2":
                IBuffer res4 = BufferProvider.Provide();
                res4.WriteUInt32(character2.instanceId); //Character ID
                res4.WriteInt32(y);                      //Character pose
                router.Send(client.map, (ushort)AreaPacketId.recv_chara_pose_notify, res4, ServerType.Area);
                break;

            case "emotion":
                //recv_emotion_notify_type = 0xF95B,
                IBuffer res5 = BufferProvider.Provide();
                res5.WriteUInt32(character2.instanceId);
                res5.WriteInt32(y);
                router.Send(client.map, (ushort)AreaPacketId.recv_emotion_notify_type, res5, ServerType.Area);
                break;

            case "deadstate":
                //recv_charabody_notify_deadstate = 0xCC36, // Parent = 0xCB94 // Range ID = 03
                IBuffer res6 = BufferProvider.Provide();
                res6.WriteUInt32(character2.deadBodyInstanceId);
                res6.WriteInt32(y);     //4 changes body to ash pile, 5 causes a mist to happen and disappear
                res6.WriteInt32(y);     // change type. unknown impact.
                router.Send(client.map, (ushort)AreaPacketId.recv_charabody_notify_deadstate, res6,
                            ServerType.Area);
                break;

            case "start":
                SendBattleReportStartNotify(client, character2);
                IBuffer res7 = BufferProvider.Provide();
                //recv_battle_report_action_item_enchant = 0x6BDC,
                res7.WriteInt32(517);
                res7.WriteInt32(y);
                router.Send(client.map, (ushort)AreaPacketId.recv_battle_report_action_item_enchant, res7,
                            ServerType.Area);
                SendBattleReportEndNotify(client, character2);
                break;

            case "end":
                IBuffer res8 = BufferProvider.Provide();
                router.Send(client.map, (ushort)AreaPacketId.recv_battle_report_end_notify, res8, ServerType.Area);
                break;

            case "bodystate":     ///State of your dead body
                //recv_charabody_state_update_notify = 0x1A0F,
                IBuffer res10 = BufferProvider.Provide();
                res10.WriteUInt32(character2.deadBodyInstanceId);
                res10.WriteInt32(y);     //0b0 = disconnected backpack, 0b1 = normal, 0b100 = title:On 0b10000=invisible. nothing above ob1 << 5
                router.Send(client.map, (ushort)AreaPacketId.recv_charabody_state_update_notify, res10, ServerType.Area);
                responses.Add(ChatResponse.CommandError(client, $"setting bodyState to {y} for character {character2.name}"));
                break;

            case "charastate":     //state of your regular body
                //recv_chara_notify_stateflag = 0x23D3,
                IBuffer res11 = BufferProvider.Provide();
                res11.WriteUInt32(character2.instanceId);
                res11.WriteInt64(y);
                router.Send(client.map, (ushort)AreaPacketId.recv_chara_notify_stateflag, res11, ServerType.Area);
                responses.Add(ChatResponse.CommandError(client,
                                                        $"setting charaState to {y} for character {character2.name}"));
                break;

            case "spirit":
                //recv_charabody_notify_spirit = 0x36A6, // Dead-Body online status toggle.  0 = disconnected client. 1 = connected
                NecClient necClient = client.map.clientLookup.GetByCharacterInstanceId(character2.instanceId);
                IBuffer   res12     = BufferProvider.Provide();
                res12.WriteUInt32(character2.deadBodyInstanceId);
                res12.WriteByte((byte)y);
                router.Send(necClient, (ushort)AreaPacketId.recv_charabody_notify_spirit, res12, ServerType.Area);
                break;

            case "abyss":     //lil marker in soul form of where you died if you jump off the map
                //recv_charabody_self_notify_abyss_stead_pos = 0x679B,
                IBuffer res13 = BufferProvider.Provide();
                res13.WriteFloat(character2.x);
                res13.WriteFloat(character2.y);
                res13.WriteFloat(character2.z);
                router.Send(client.map, (ushort)AreaPacketId.recv_charabody_self_notify_abyss_stead_pos, res13,
                            ServerType.Area);
                break;

            case "charadata":
                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(character2,
                                                                            client.soul.name /*Should be client of supplied instanceID. this is a band-aid*/);
                router.Send(server.clients.GetAll(), cData.ToPacket());
                break;

            case "charabodydata":
                //recv_data_notify_charabody_data = 0x906A,
                DeadBody deadBody = server.instances.GetInstance(character2.deadBodyInstanceId) as DeadBody;
                IBuffer  res14    = BufferProvider.Provide();
                res14.WriteUInt32(character2.deadBodyInstanceId); //Instance ID of dead body
                res14.WriteUInt32(character2.instanceId);         //Reference to actual player's instance ID
                res14.WriteCString("soulname");                   // Soul name
                res14.WriteCString($"{character2.name}");         // Character name
                res14.WriteFloat(character2.x + 200);             // X
                res14.WriteFloat(character2.y);                   // Y
                res14.WriteFloat(character2.z);                   // Z
                res14.WriteByte(character2.heading);              // Heading
                res14.WriteInt32(character2.level);               //??level?


                int numEntries = 19;
                res14.WriteInt32(numEntries);     //less than or equal to 19
                //Consolidated Frequently Used Code
                //LoadEquip.SlotSetup(res14, character2, numEntries);

                res14.WriteInt32(numEntries);
                //Consolidated Frequently Used Code
                //LoadEquip.EquipItems(res14, character2, numEntries);

                res14.WriteInt32(numEntries);
                //Consolidated Frequently Used Code
                //LoadEquip.EquipSlotBitMask(res14, character2, numEntries);

                //Traits
                res14.WriteUInt32(character2.raceId);    //race
                res14.WriteUInt32(character2.sexId);
                res14.WriteByte(character2.hairId);      //hair
                res14.WriteByte(character2.hairColorId); //color
                res14.WriteByte(character2.faceId);      //face

                res14.WriteInt32(deadBody
                                 .connectionState);   // 0 = bag, 1 for dead? (Can't enter soul form if this isn't 0 or 1 i think).
                res14.WriteInt32(deadBody.modelType); //4 = ash pile, not sure what this is.
                res14.WriteInt32(y);
                res14.WriteInt32(deadBody
                                 .deathPose);                 //death pose 0 = faced down, 1 = head chopped off, 2 = no arm, 3 = faced down, 4 = chopped in half, 5 = faced down, 6 = faced down, 7 and up "T-pose" the body (ONLY SEND 1 IF YOU ARE CALLING THIS FOR THE FIRST TIME)
                res14.WriteByte(deadBody
                                .criminalStatus);             //crim status (changes icon on the end also), 0 = white, 1 = yellow, 2 = red, 3 = red with crim icon,
                res14.WriteByte(deadBody.beginnerProtection); // (bool) Beginner protection
                res14.WriteInt32(1);
                router.Send(client.map, (ushort)AreaPacketId.recv_data_notify_charabody_data, res14,
                            ServerType.Area);
                break;

            case "event":
                IBuffer res16 = BufferProvider.Provide();
                //recv_event_start = 0x1B5C,
                res16.WriteInt32(0);
                res16.WriteByte(0);
                router.Send(client, (ushort)AreaPacketId.recv_event_start, res16, ServerType.Area);

                IBuffer res17 = BufferProvider.Provide();
                //recv_event_quest_report = 0xE07E,
                res17.WriteInt32(0);
                router.Send(client, (ushort)AreaPacketId.recv_event_quest_report, res17, ServerType.Area);

                IBuffer res18 = BufferProvider.Provide();
                //recv_event_block_message_end_no_object = 0x1AB,
                //Router.Send(client, (ushort)AreaPacketId.recv_event_block_message_end_no_object, res18, ServerType.Area);

                IBuffer res19 = BufferProvider.Provide();
                router.Send(client, (ushort)AreaPacketId.recv_event_sync, res19, ServerType.Area);
                break;

            case "popup":
                IBuffer res22 = BufferProvider.Provide();
                //recv_event_start = 0x1B5C,
                res22.WriteInt32(0);
                res22.WriteByte((byte)y);
                //Router.Send(client, (ushort)AreaPacketId.recv_event_start, res22, ServerType.Area);

                IBuffer res21 = BufferProvider.Provide();
                //recv_normal_system_message = 0xAE2B,
                res21.WriteCString("ToBeFound");
                router.Send(client, (ushort)AreaPacketId.recv_normal_system_message, res21, ServerType.Area);

                IBuffer res23 = BufferProvider.Provide();
                //recv_event_end = 0x99D,
                res23.WriteByte((byte)y);
                //Router.Send(client, (ushort)AreaPacketId.recv_event_end, res23, ServerType.Area);
                break;

            case "recv":
                IBuffer res24 = BufferProvider.Provide();
                //recv_auction_receive_item_r = 0xB1CA,
                res24.WriteInt32(y);
                router.Send(client, (ushort)AreaPacketId.recv_auction_receive_gold_r, res24, ServerType.Area);
                break;

            case "atk":     //udates settings 1-22 on the attribute tab
                res = BufferProvider.Provide();
                res.WriteInt32(y);
                res.WriteInt16(888);
                router.Send(client, (ushort)AreaPacketId.recv_chara_update_atk_magic_attr, res, ServerType.Area);
                break;

            case "ability":         //udates settings 1-7 on the ability tab
                res = BufferProvider.Provide();
                res.WriteInt32(y);  //attribute
                res.WriteInt16(10); //base
                res.WriteInt16(25); //total
                router.Send(client, (ushort)AreaPacketId.recv_chara_update_ability, res, ServerType.Area);
                break;

            case "battle":     //udates settings 1-7 on the ability tab
                res = BufferProvider.Provide();
                res.WriteInt16(10);
                res.WriteInt16(10);
                res.WriteInt16(10);
                res.WriteInt16(10);

                res.WriteInt16(10);
                res.WriteInt16(10);
                res.WriteInt16(10);
                res.WriteInt16(10);
                router.Send(client, (ushort)AreaPacketId.recv_chara_update_battle_base_param, res, ServerType.Area);
                break;

            case "alignment":
                IBuffer res28 = BufferProvider.Provide();
                //recv_chara_update_alignment_param = 0xB435,
                res28.WriteInt32(1);
                res28.WriteInt32(2);
                res28.WriteInt32(3);
                router.Send(client, (ushort)AreaPacketId.recv_chara_update_alignment_param, res28, ServerType.Area);
                res28 = BufferProvider.Provide();
                res28.WriteInt32(y);     //Alignment ID
                router.Send(client, (ushort)AreaPacketId.recv_chara_update_alignment, res28, ServerType.Area);
                break;

            case "shop":
                IBuffer res29 = BufferProvider.Provide();
                //recv_shop_notify_open = 0x52FD, // Parent = 0x5243 // Range ID = 02
                res29.WriteInt16((short)y);     //Shop type
                res29.WriteInt32(0);
                res29.WriteInt32(0);
                res29.WriteByte(0);
                router.Send(client, (ushort)AreaPacketId.recv_shop_notify_open, res29, ServerType.Area);
                break;

            case "sc":
                IBuffer res32 = BufferProvider.Provide();
                //recv_shop_sell_check_r = 0x4E8D,
                res32.WriteInt32(0);
                router.Send(client, (ushort)AreaPacketId.recv_shop_sell_check_r, res32, ServerType.Area);
                break;

            case "view":
                IBuffer res33 = BufferProvider.Provide();
                //recv_chara_view_landing_notify = 0x14DA,
                res33.WriteInt32(y);
                router.Send(client.map, (ushort)AreaPacketId.recv_chara_view_landing_notify, res33,
                            ServerType.Area);
                break;

            case "damage":
                int hp = character2.hp.current;
                client.character.hp.Modify(-hp, character2.instanceId);
                IBuffer res35 = BufferProvider.Provide();
                res35.WriteInt32(hp - hp);
                router.Send(client, (ushort)AreaPacketId.recv_chara_update_hp, res35, ServerType.Area);
                break;

            case "itemforth":
                IBuffer res38 = BufferProvider.Provide();
                res38.WriteUInt32(200000002); //item ID?
                res38.WriteInt32(200101);     //Owner going 'forth'  id?
                res38.WriteUInt32(200201);    //item state setting?
                res38.WriteByte(1);           //newJp
                router.Send(client.map, (ushort)AreaPacketId.recv_chara_update_notify_item_forth, res38,
                            ServerType.Area);
                break;

            case "disconnect":
                NecClient deadManClient = server.clients.GetByCharacterInstanceId(x);
                IBuffer   res39         = BufferProvider.Provide();
                res39.WriteUInt32(client.character.instanceId);
                res39.WriteUInt32(client.character.instanceId);
                res39.WriteUInt32(client.character.instanceId);
                res39.WriteUInt32(client.character.instanceId);
                res39.WriteUInt32(client.character.instanceId);
                res39.WriteUInt32(client.character.instanceId);
                res39.WriteUInt32(client.character.instanceId);
                router.Send(deadManClient, (ushort)AreaPacketId.recv_chara_update_notify_item_forth, res39,
                            ServerType.Area);
                break;

            case "crime":
                //for (byte i = 0; i < y; i++)
            {
                NecClient crimeClient = server.clients.GetByCharacterInstanceId(x);
                IBuffer   res40       = BufferProvider.Provide();
                res40.WriteUInt32(crimeClient.character.instanceId);
                res40.WriteByte((byte)y);
                client.character.criminalState = (byte)y;
                _Logger.Debug($"Setting crime level for Character {crimeClient.character.name} to {y}");
                router.Send(crimeClient, (ushort)AreaPacketId.recv_chara_update_notify_crime_lv, res40, ServerType.Area);
                router.Send(crimeClient.map, (ushort)AreaPacketId.recv_charabody_notify_crime_lv, res40, ServerType.Area, crimeClient);
                Thread.Sleep(400);
            }
            break;

            case "inherit":
                //for (byte i = 0; i < y; i++)
            {
                NecClient inheritClient = server.clients.GetByCharacterInstanceId(x);
                IBuffer   res41         = BufferProvider.Provide();
                res41.WriteInt32(y);
                res41.WriteInt32(0x64);         //less than or equal to 0x64
                for (int i = 0; i < 0x64; i++)  //limit is the int32 above
                {
                    res41.WriteInt32(i);
                    // TODO what ip is this? Area Msg ?? use -> Server.Setting.DataAreaIpAddress or Server.Setting.DataMsgIpAddress
                    res41.WriteFixedString("127.0.0.1", 0x10);         //size is 0x10
                }

                res41.WriteUInt32(client.character.instanceId);
                // TODO what ip is this? Area Msg ?? use -> Server.Setting.DataAreaIpAddress or Server.Setting.DataMsgIpAddress
                res41.WriteFixedString("127.0.0.1", 0x10);         //size is 0x10
                res41.WriteByte((byte)y);
                router.Send(inheritClient, (ushort)MsgPacketId.recv_chara_get_inheritinfo_r, res41,
                            ServerType.Msg);

                Thread.Sleep(400);
            }
            break;

            case "seqmask":
                IBuffer res43 = BufferProvider.Provide();
                //95 torso ?
                //55 full armor too ?
                //93 full armor ?
                // 27 full armor ?
                //11 under ?
                // 38 = boots and cape
                //byte y = unchecked((byte)110111);
                //byte y = unchecked ((byte)Util.GetRandomNumber(0, 100)); // for the moment i only get the armor on this way :/


                /*int[] EquipBitMask = new int[]
                 * {
                 *  1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288,
                 *  1048576, 2097152
                 * };*/
                res43.WriteInt64(180201);
                res43.WriteInt32(y);
                router.Send(client.map, (ushort)AreaPacketId.recv_item_update_spirit_eqmask, res43, ServerType.Area);
                break;

            default:
                _Logger.Error($"There is no recv of type : {command[0]} ");
                break;
            }
        }
Exemplo n.º 13
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());
                }
                    );
            }
        }
Exemplo n.º 14
0
        public override void Execute(string[] command, NecClient client, ChatMessage message,
                                     List <ChatResponse> responses)
        {
            //if (client.Character.soulFormState == 1)
            {
                IBuffer res1 = BufferProvider.Provide();
                res1.WriteInt32(0); //Has to be 0 or else you DC
                res1.WriteUInt32(client.Character.DeadBodyInstanceId);
                res1.WriteUInt32(client.Character.InstanceId);
                Router.Send(client, (ushort)AreaPacketId.recv_revive_init_r, res1, ServerType.Area);

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

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


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

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

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

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

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

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

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

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

            if (client == null)
            {
                return;
            }
            //Try to update the character stats.
            if (!database.UpdateCharacter(client.character))
            {
                _Logger.Error("Could not update the database with character details before disconnect");
            }
            if (!database.UpdateSoul(client.soul))
            {
                _Logger.Error("Could not update the database with soul details before disconnect");
            }
            clients.Remove(client);

            //I disconnected while my dead body was being carried around by another player
            if (client.character.hasDied)
            {
                DeadBody deadBody = instances.GetInstance(client.character.deadBodyInstanceId) as DeadBody;
                if (deadBody.salvagerId != 0)
                {
                    NecClient mySalvager = clients.GetByCharacterInstanceId(deadBody.salvagerId);
                    if (mySalvager != null)
                    {
                        deadBody.x               = mySalvager.character.x;
                        deadBody.y               = mySalvager.character.y;
                        deadBody.z               = mySalvager.character.z;
                        deadBody.mapId           = mySalvager.character.mapId;
                        deadBody.connectionState = 0;
                        mySalvager.bodyCollection.Remove(deadBody.instanceId);

                        mySalvager.map.deadBodies.Add(deadBody.instanceId, deadBody);
                        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
                        {
                            router.Send(mySalvager.map, cBodyData.ToPacket(), client);
                        }

                        //must occur after the charaBody notify.
                        RecvCharaBodySalvageEnd recvCharaBodySalvageEnd = new RecvCharaBodySalvageEnd(deadBody.instanceId, 5);
                        router.Send(mySalvager, recvCharaBodySalvageEnd.ToPacket());
                    }
                }
            }

            //while i was dead and being carried around, the player carrying me disconnected
            foreach (NecClient collectedBody in client.bodyCollection.Values)
            {
                DeadBody deadBody = instances.GetInstance(collectedBody.character.deadBodyInstanceId) as DeadBody;

                RecvCharaBodySelfSalvageEnd recvCharaBodySelfSalvageEnd = new RecvCharaBodySelfSalvageEnd(3);
                router.Send(collectedBody, recvCharaBodySelfSalvageEnd.ToPacket());


                deadBody.x = client.character.x;
                deadBody.y = client.character.y;
                deadBody.z = client.character.z;
                collectedBody.character.x = client.character.x;
                collectedBody.character.y = client.character.y;
                collectedBody.character.z = client.character.z;
                //ToDo  add Town checking.  if map.ID.toString()[0]==1 skip deadbody rendering
                deadBody.mapId = client.character.mapId;

                client.map.deadBodies.Add(deadBody.instanceId, deadBody);
                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
                {
                    router.Send(client.map, cBodyData.ToPacket());
                }

                //send your soul to all the other souls runnin around
                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(collectedBody.character, collectedBody.soul.name);
                foreach (NecClient soulStateClient in client.map.clientLookup.GetAll())
                {
                    if (soulStateClient.character.state == CharacterState.SoulForm)
                    {
                        router.Send(soulStateClient, cData.ToPacket());
                    }
                }
            }

            Map map = client.map;

            //If i was dead, toggle my deadBody to a Rucksack
            if (map != null)
            {
                if (map.deadBodies.ContainsKey(client.character.deadBodyInstanceId))
                {
                    map.deadBodies.TryGetValue(client.character.deadBodyInstanceId, out DeadBody deadBody);
                    deadBody.connectionState = 0;
                    RecvCharaBodyNotifySpirit recvCharaBodyNotifySpirit = new RecvCharaBodyNotifySpirit(client.character.deadBodyInstanceId, (byte)RecvCharaBodyNotifySpirit.ValidSpirit.DisconnectedClient);
                    router.Send(map, recvCharaBodyNotifySpirit.ToPacket());

                    Task.Delay(TimeSpan.FromSeconds(600)).ContinueWith
                        (t1 =>
                    {
                        if (map.deadBodies.ContainsKey(client.character.deadBodyInstanceId))
                        {
                            RecvObjectDisappearNotify recvObjectDisappearNotify = new RecvObjectDisappearNotify(client.character.deadBodyInstanceId);
                            router.Send(client.map, recvObjectDisappearNotify.ToPacket(), client);
                            map.deadBodies.Remove(client.character.deadBodyInstanceId);
                        }
                    }
                        );
                }
            }

            if (map != null)
            {
                map.Leave(client);
            }

            Union union = client.union;

            if (union != null)
            {
                union.Leave(client);
            }

            Character character = client.character;

            if (character != null)
            {
                instances.FreeInstance(character);
                character.characterActive = false;
            }
        }
Exemplo n.º 16
0
        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;
            }

            Character character2 = null;

            if (uint.TryParse(command[1], out uint x))
            {
                IInstance instance = Server.Instances.GetInstance(x);
                if (instance is Character character)
                {
                    character2 = character;
                }
                else if (instance is DeadBody deadbody)
                {
                    responses.Add(ChatResponse.CommandError(client, $"That's a dead body man. have some respect!"));
                    character2            = new Character();
                    character2.InstanceId = deadbody.InstanceId;
                }
                else
                {
                    responses.Add(ChatResponse.CommandError(client, $"Please provide a character instance id"));
                    return;
                }
            }

            if (!int.TryParse(command[2], out int y))
            {
                try
                {
                    string binaryString = command[2];
                    binaryString = binaryString.Replace("0b", "");
                    Logger.Debug(binaryString);
                    y = Convert.ToInt32(binaryString, 2);
                }
                catch
                {
                    responses.Add(ChatResponse.CommandError(client, $"Please provide a value to test"));
                    return;
                }
            }


            switch (command[0])
            {
            case "hp":
                IBuffer res = BufferProvider.Provide();
                res.WriteInt32(y);
                character2.Hp.setCurrent(y);
                Router.Send(client, (ushort)AreaPacketId.recv_chara_update_hp, res, ServerType.Area);
                break;

            case "dead":
                SendBattleReportStartNotify(client, character2);
                //recv_battle_report_noact_notify_dead = 0xCDC9,
                IBuffer res2 = BufferProvider.Provide();
                res2.WriteUInt32(character2.InstanceId);
                res2.WriteInt32(
                    y);     // death type? 1 = death, 2 = death and message, 3 = unconscious, beyond that = nothing
                res2.WriteInt32(0);
                res2.WriteInt32(0);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_noact_notify_dead, res2,
                            ServerType.Area);
                SendBattleReportEndNotify(client, character2);
                break;

            case "pose":
                IBuffer res3 = BufferProvider.Provide();
                //recv_battle_attack_pose_start_notify = 0x7CB2,
                res3.WriteInt32(y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_attack_pose_start_notify, res3,
                            ServerType.Area);
                break;

            case "pose2":
                IBuffer res4 = BufferProvider.Provide();
                res4.WriteUInt32(character2.InstanceId); //Character ID
                res4.WriteInt32(y);                      //Character pose
                Router.Send(client.Map, (ushort)AreaPacketId.recv_chara_pose_notify, res4, ServerType.Area,
                            client);

                break;

            case "emotion":
                //recv_emotion_notify_type = 0xF95B,
                IBuffer res5 = BufferProvider.Provide();
                res5.WriteUInt32(character2.InstanceId);
                res5.WriteInt32(y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_emotion_notify_type, res5, ServerType.Area);
                break;

            case "deadstate":
                //recv_charabody_notify_deadstate = 0xCC36, // Parent = 0xCB94 // Range ID = 03
                IBuffer res6 = BufferProvider.Provide();
                res6.WriteUInt32(character2.InstanceId);
                res6.WriteInt32(
                    y);     //4 here causes a cloud and the model to disappear, 5 causes a mist to happen and disappear
                res6.WriteInt32(y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_charabody_notify_deadstate, res6,
                            ServerType.Area);
                break;

            case "start":
                SendBattleReportStartNotify(client, character2);
                IBuffer res7 = BufferProvider.Provide();
                //recv_battle_report_action_item_enchant = 0x6BDC,
                res7.WriteInt32(517);
                res7.WriteInt32(y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_action_item_enchant, res7,
                            ServerType.Area);
                SendBattleReportEndNotify(client, character2);
                break;

            case "end":
                IBuffer res8 = BufferProvider.Provide();
                Router.Send(client.Map, (ushort)AreaPacketId.recv_battle_report_end_notify, res8, ServerType.Area);
                break;

            case "gimmick":
                //recv_data_notify_gimmick_data = 0xBFE9,
                IBuffer res9 = BufferProvider.Provide();
                res9.WriteInt32(y);     //Gimmick instance id
                res9.WriteFloat(client.Character.X + 100);
                res9.WriteFloat(client.Character.Y);
                res9.WriteFloat(client.Character.Z);
                res9.WriteByte(client.Character.Heading);
                res9.WriteInt32(y);     //Gimmick number (from gimmick.csv)
                res9.WriteInt32(0);     //Gimmick State
                Router.Send(client.Map, (ushort)AreaPacketId.recv_data_notify_gimmick_data, res9, ServerType.Area);
                break;

            case "bodystate":     ///State of your dead body
                //recv_charabody_state_update_notify = 0x1A0F,
                IBuffer res10 = BufferProvider.Provide();
                res10.WriteUInt32(character2.InstanceId);
                res10.WriteInt32(y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_charabody_state_update_notify, res10,
                            ServerType.Area);
                responses.Add(ChatResponse.CommandError(client,
                                                        $"setting bodyState to {y} for character {character2.Name}"));

                break;

            case "charastate":     //state of your regular body
                //recv_chara_notify_stateflag = 0x23D3,
                IBuffer res11 = BufferProvider.Provide();
                res11.WriteUInt32(character2.InstanceId);
                res11.WriteInt32(y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_chara_notify_stateflag, res11, ServerType.Area);
                responses.Add(ChatResponse.CommandError(client,
                                                        $"setting charaState to {y} for character {character2.Name}"));
                break;

            case "spirit":
                //recv_charabody_notify_spirit = 0x36A6,
                IBuffer res12 = BufferProvider.Provide();
                res12.WriteUInt32(character2.InstanceId);
                res12.WriteByte((byte)y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_charabody_notify_spirit, res12, ServerType.Area);
                break;

            case "abyss":     //lil marker in soul form of where you died if you jump off the map
                //recv_charabody_self_notify_abyss_stead_pos = 0x679B,
                IBuffer res13 = BufferProvider.Provide();
                res13.WriteFloat(character2.X);
                res13.WriteFloat(character2.Y);
                res13.WriteFloat(character2.Z);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_charabody_self_notify_abyss_stead_pos, res13,
                            ServerType.Area);
                break;

            case "charadata":
                RecvDataNotifyCharaData cData = new RecvDataNotifyCharaData(character2,
                                                                            client.Soul.Name /*Should be client of supplied instanceID. this is a band-aid*/);
                Router.Send(Server.Clients.GetAll(), cData.ToPacket());
                break;

            case "charabodydata":
                //recv_data_notify_charabody_data = 0x906A,
                DeadBody _deadBody = Server.Instances.GetInstance(character2.DeadBodyInstanceId) as DeadBody;
                IBuffer  res14     = BufferProvider.Provide();
                res14.WriteUInt32(character2.DeadBodyInstanceId); //Instance ID of dead body
                res14.WriteUInt32(character2.InstanceId);         //Reference to actual player's instance ID
                res14.WriteCString("soulname");                   // Soul name
                res14.WriteCString($"{character2.Name}");         // Character name
                res14.WriteFloat(character2.X + 200);             // X
                res14.WriteFloat(character2.Y);                   // Y
                res14.WriteFloat(character2.Z);                   // Z
                res14.WriteByte(character2.Heading);              // Heading
                res14.WriteInt32(character2.Level);               //??level?


                int numEntries = 19;
                res14.WriteInt32(numEntries);     //less than or equal to 19
                //Consolidated Frequently Used Code
                LoadEquip.SlotSetup(res14, character2, numEntries);

                res14.WriteInt32(numEntries);
                //Consolidated Frequently Used Code
                LoadEquip.EquipItems(res14, character2, numEntries);

                res14.WriteInt32(numEntries);
                //Consolidated Frequently Used Code
                LoadEquip.EquipSlotBitMask(res14, character2, numEntries);

                //Consolidated Frequently Used Code
                LoadEquip.BasicTraits(res14, character2);

                res14.WriteInt32(_deadBody
                                 .ConnectionState);    // 0 = bag, 1 for dead? (Can't enter soul form if this isn't 0 or 1 i think).
                res14.WriteInt32(_deadBody.ModelType); //4 = ash pile, not sure what this is.
                res14.WriteInt32(y);
                res14.WriteInt32(_deadBody
                                 .deathPose);                  //death pose 0 = faced down, 1 = head chopped off, 2 = no arm, 3 = faced down, 4 = chopped in half, 5 = faced down, 6 = faced down, 7 and up "T-pose" the body (ONLY SEND 1 IF YOU ARE CALLING THIS FOR THE FIRST TIME)
                res14.WriteByte(_deadBody
                                .CriminalStatus);              //crim status (changes icon on the end also), 0 = white, 1 = yellow, 2 = red, 3 = red with crim icon,
                res14.WriteByte(_deadBody.BeginnerProtection); // (bool) Beginner protection
                res14.WriteInt32(1);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_data_notify_charabody_data, res14,
                            ServerType.Area);
                break;

            case "scaleopen":
                IBuffer res0 = BufferProvider.Provide();
                res0.WriteInt32(0);     //1 = cinematic, 0 Just start the event without cinematic
                res0.WriteByte(0);
                Router.Send(client, (ushort)AreaPacketId.recv_event_start, res0, ServerType.Area);

                IBuffer res15 = BufferProvider.Provide();
                //recv_raisescale_view_open = 0xC25D, // Parent = 0xC2E5 // Range ID = 01  // was 0xC25D
                res15.WriteInt16(1); //Basic revival rate %
                res15.WriteInt16(5); //Penalty %
                res15.WriteInt16(
                    (short)y);       //Offered item % (this probably changes with recv_raisescale_update_success_per)
                res15.WriteInt16(4); //Dimento medal addition %
                Router.Send(client, (ushort)AreaPacketId.recv_raisescale_view_open, res15, ServerType.Area);
                break;

            case "event":
                IBuffer res16 = BufferProvider.Provide();
                //recv_event_start = 0x1B5C,
                res16.WriteInt32(0);
                res16.WriteByte(0);
                Router.Send(client, (ushort)AreaPacketId.recv_event_start, res16, ServerType.Area);

                IBuffer res17 = BufferProvider.Provide();
                //recv_event_quest_report = 0xE07E,
                res17.WriteInt32(0);
                Router.Send(client, (ushort)AreaPacketId.recv_event_quest_report, res17, ServerType.Area);

                IBuffer res18 = BufferProvider.Provide();
                //recv_event_block_message_end_no_object = 0x1AB,
                //Router.Send(client, (ushort)AreaPacketId.recv_event_block_message_end_no_object, res18, ServerType.Area);

                IBuffer res19 = BufferProvider.Provide();
                Router.Send(client, (ushort)AreaPacketId.recv_event_sync, res19, ServerType.Area);
                break;

            case "popup":
                IBuffer res22 = BufferProvider.Provide();
                //recv_event_start = 0x1B5C,
                res22.WriteInt32(0);
                res22.WriteByte((byte)y);
                //Router.Send(client, (ushort)AreaPacketId.recv_event_start, res22, ServerType.Area);

                IBuffer res21 = BufferProvider.Provide();
                //recv_normal_system_message = 0xAE2B,
                res21.WriteCString("ToBeFound");
                Router.Send(client, (ushort)AreaPacketId.recv_normal_system_message, res21, ServerType.Area);

                IBuffer res23 = BufferProvider.Provide();
                //recv_event_end = 0x99D,
                res23.WriteByte((byte)y);
                //Router.Send(client, (ushort)AreaPacketId.recv_event_end, res23, ServerType.Area);
                break;

            case "recv":
                IBuffer res24 = BufferProvider.Provide();
                //recv_auction_receive_item_r = 0xB1CA,
                res24.WriteInt32(y);
                Router.Send(client, (ushort)AreaPacketId.recv_auction_receive_gold_r, res24, ServerType.Area);
                break;

            case "string":
                IBuffer res26 = BufferProvider.Provide();
                //recv_charabody_notify_loot_item = 0x8CDE, // Parent = 0x8CC6 // Range ID = 01
                res26.WriteByte(0);
                res26.WriteByte(0);
                res26.WriteInt16(0);

                res26.WriteInt16((short)y);
                res26.WriteCString("adad");     // Length 0x31
                res26.WriteCString("adad");     // Length 0x5B
                Router.Send(client, (ushort)AreaPacketId.recv_charabody_notify_loot_item, res26, ServerType.Area);
                break;

            case "ac":
                IBuffer res27 = BufferProvider.Provide();
                //recv_item_update_ac
                res27.WriteInt64(10200101);
                res27.WriteInt16((short)y);
                Router.Send(client, (ushort)AreaPacketId.recv_item_update_ac, res27, ServerType.Area);
                break;

            case "alignment":
                IBuffer res28 = BufferProvider.Provide();
                //recv_chara_update_alignment_param = 0xB435,
                res28.WriteInt32(1);
                res28.WriteInt32(2);
                res28.WriteInt32(3);
                Router.Send(client, (ushort)AreaPacketId.recv_chara_update_alignment_param, res28,
                            ServerType.Area);
                break;

            case "shop":
                IBuffer res29 = BufferProvider.Provide();
                //recv_shop_notify_open = 0x52FD, // Parent = 0x5243 // Range ID = 02
                res29.WriteInt16((short)y);      //Shop type
                res29.WriteInt32(0);
                res29.WriteInt32(0);
                res29.WriteByte(0);
                Router.Send(client, (ushort)AreaPacketId.recv_shop_notify_open, res29, ServerType.Area);
                break;

            case "dura":

                IBuffer res30 = BufferProvider.Provide();
                res30.WriteInt64(10200101);
                res30.WriteInt32(y);     // MaxDura points
                Router.Send(client, (ushort)AreaPacketId.recv_item_update_maxdur, res30, ServerType.Area);

                //recv_item_update_durability = 0x1F5A,
                IBuffer res31 = BufferProvider.Provide();
                res31.WriteInt64(10200101);
                res31.WriteInt32(y - 1);
                Router.Send(client, (ushort)AreaPacketId.recv_item_update_durability, res31, ServerType.Area);
                break;

            case "sc":
                IBuffer res32 = BufferProvider.Provide();
                //recv_shop_sell_check_r = 0x4E8D,
                res32.WriteInt32(0);
                Router.Send(client, (ushort)AreaPacketId.recv_shop_sell_check_r, res32, ServerType.Area);
                break;

            case "view":
                IBuffer res33 = BufferProvider.Provide();
                //recv_chara_view_landing_notify = 0x14DA,
                res33.WriteInt32(y);
                Router.Send(client.Map, (ushort)AreaPacketId.recv_chara_view_landing_notify, res33,
                            ServerType.Area);
                break;

            case "itemnum":
                IBuffer res34 = BufferProvider.Provide();
                //recv_item_update_num = 0x5F8,
                res34.WriteInt64(10200101);
                res34.WriteByte(25);
                Router.Send(client, (ushort)AreaPacketId.recv_item_update_num, res34, ServerType.Area);
                break;

            case "damage":
                int hp = character2.Hp.current;
                client.Character.Hp.Modify(-hp, character2.InstanceId);
                IBuffer res35 = BufferProvider.Provide();
                res35.WriteInt32(hp - hp);
                Router.Send(client, (ushort)AreaPacketId.recv_chara_update_hp, res35, ServerType.Area);
                break;

            case "union":
                IBuffer res36 = BufferProvider.Provide();
                res36.WriteUInt32(client.Character.InstanceId);
                res36.WriteInt32(8888 /*client.Character.UnionId*/);
                res36.WriteCString("Trade_Union");
                Router.Send(client.Map, (ushort)AreaPacketId.recv_chara_notify_union_data, res36, ServerType.Area);
                break;

            case "xunion":
                IBuffer res37 = BufferProvider.Provide();
                res37.WriteUInt32(client.Character.InstanceId);
                res37.WriteInt32(0 /*client.Character.UnionId*/);
                res37.WriteCString("");
                Router.Send(client.Map, (ushort)AreaPacketId.recv_chara_notify_union_data, res37, ServerType.Area);
                break;

            case "itemforth":
                IBuffer res38 = BufferProvider.Provide();
                res38.WriteUInt32(client.Character.InstanceId); //item ID?
                res38.WriteInt32(10200101);                     //Owner going 'forth'  id?
                res38.WriteUInt32(client.Character.InstanceId); //item state setting?
                Router.Send(client.Map, (ushort)AreaPacketId.recv_chara_update_notify_item_forth, res38,
                            ServerType.Area);
                break;

            case "disconnect":
                NecClient DeadManClient = Server.Clients.GetByCharacterInstanceId(x);
                IBuffer   res39         = BufferProvider.Provide();
                res39.WriteUInt32(client.Character.InstanceId);
                res39.WriteUInt32(client.Character.InstanceId);
                res39.WriteUInt32(client.Character.InstanceId);
                res39.WriteUInt32(client.Character.InstanceId);
                res39.WriteUInt32(client.Character.InstanceId);
                res39.WriteUInt32(client.Character.InstanceId);
                res39.WriteUInt32(client.Character.InstanceId);
                Router.Send(DeadManClient, (ushort)AreaPacketId.recv_chara_update_notify_item_forth, res39,
                            ServerType.Area);
                break;

            case "crime":
                //for (byte i = 0; i < y; i++)
            {
                NecClient crimeClient = Server.Clients.GetByCharacterInstanceId(x);
                IBuffer   res40       = BufferProvider.Provide();
                res40.WriteUInt32(crimeClient.Character.InstanceId);
                res40.WriteByte((byte)y);
                client.Character.criminalState = (byte)y;
                Logger.Debug($"Setting crime level for Character {crimeClient.Character.Name} to {y}");
                Router.Send(crimeClient, (ushort)AreaPacketId.recv_chara_update_notify_crime_lv, res40,
                            ServerType.Area);
                Router.Send(crimeClient.Map, (ushort)AreaPacketId.recv_charabody_notify_crime_lv, res40,
                            ServerType.Area, crimeClient);
                Thread.Sleep(400);
            }
            break;

            case "inherit":
                //for (byte i = 0; i < y; i++)
            {
                NecClient inheritClient = Server.Clients.GetByCharacterInstanceId(x);
                IBuffer   res41         = BufferProvider.Provide();
                res41.WriteInt32(y);
                res41.WriteInt32(0x64);        //less than or equal to 0x64
                for (int i = 0; i < 0x64; i++) //limit is the int32 above
                {
                    res41.WriteInt32(i);
                    // TODO what ip is this? Area Msg ?? use -> Server.Setting.DataAreaIpAddress or Server.Setting.DataMsgIpAddress
                    res41.WriteFixedString("127.0.0.1", 0x10);     //size is 0x10
                }

                res41.WriteUInt32(client.Character.InstanceId);
                // TODO what ip is this? Area Msg ?? use -> Server.Setting.DataAreaIpAddress or Server.Setting.DataMsgIpAddress
                res41.WriteFixedString("127.0.0.1", 0x10);     //size is 0x10
                res41.WriteByte((byte)y);
                Router.Send(inheritClient, (ushort)MsgPacketId.recv_chara_get_inheritinfo_r, res41,
                            ServerType.Msg);

                Thread.Sleep(400);
            }
            break;

            default:
                Logger.Error($"There is no recv of type : {command[0]} ");
                break;
            }
        }
Exemplo n.º 17
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            foreach (NecClient otherClient in client.Map.ClientLookup.GetAll())
            {
                if (otherClient == client)
                {
                    // skip myself
                    continue;
                }

                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)
            {
                if (monsterSpawn.Active == false)
                {
                    RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn);
                    Logger.Debug($"Monster Id {monsterSpawn.Id} with model {monsterSpawn.ModelId} is loading");
                    Router.Send(monsterData, client);
                }
            }

            foreach (NpcSpawn npcSpawn in client.Map.NpcSpawns.Values)
            {
                // This requires database changes to add the GGates to the Npc database!!!!!
                if (npcSpawn.Name == "GGate")
                {
                    GGateSpawn gGate = new GGateSpawn();
                    gGate.X       = npcSpawn.X;
                    gGate.Y       = npcSpawn.Y;
                    gGate.Z       = npcSpawn.Z;
                    gGate.Heading = npcSpawn.Heading;
                    gGate.MapId   = npcSpawn.MapId;
                    gGate.Name    = npcSpawn.Name;
                    gGate.Title   = npcSpawn.Title;

                    RecvDataNotifyGGateData gGateData = new RecvDataNotifyGGateData(gGate);
                    Router.Send(gGateData, client);
                }
                else
                {
                    RecvDataNotifyNpcData npcData = new RecvDataNotifyNpcData(npcSpawn);
                    Router.Send(npcData, client);
                }
            }

            foreach (Gimmick gimmickSpawn in client.Map.GimmickSpawns.Values)
            {
                RecvDataNotifyGimmickData gimmickData = new RecvDataNotifyGimmickData(gimmickSpawn);
                Router.Send(gimmickData, client);
                GGateSpawn gGateSpawn = new GGateSpawn();
                Server.Instances.AssignInstance(gGateSpawn);
                gGateSpawn.X        = gimmickSpawn.X;
                gGateSpawn.Y        = gimmickSpawn.Y;
                gGateSpawn.Z        = gimmickSpawn.Z + 300;
                gGateSpawn.Heading  = gimmickSpawn.Heading;
                gGateSpawn.Name     = $"gGateSpawn to your current position. ID {gimmickSpawn.ModelId}";
                gGateSpawn.Title    = $"type '/gimmick move {gimmickSpawn.InstanceId} to move this ";
                gGateSpawn.MapId    = gimmickSpawn.MapId;
                gGateSpawn.ModelId  = 1900001;
                gGateSpawn.Active   = 0;
                gGateSpawn.SerialId = 1900001;

                RecvDataNotifyGGateData gGateData = new RecvDataNotifyGGateData(gGateSpawn);
                Router.Send(gGateData, client);
            }

            foreach (GGateSpawn gGateSpawn in client.Map.GGateSpawns.Values)
            {
                RecvDataNotifyGGateData gGateSpawnData = new RecvDataNotifyGGateData(gGateSpawn);
                Router.Send(gGateSpawnData, client);
            }

            foreach (DeadBody deadBody in client.Map.DeadBodies.Values)
            {
                RecvDataNotifyCharaBodyData deadBodyData = new RecvDataNotifyCharaBodyData(deadBody, client);
                Router.Send(deadBodyData, client);
            }

            foreach (MapTransition mapTran in client.Map.MapTransitions.Values)
            {
                MapPosition mapPos = new MapPosition(mapTran.ReferencePos.X, mapTran.ReferencePos.Y,
                                                     mapTran.ReferencePos.Z, mapTran.MaplinkHeading);
                RecvDataNotifyMapLink mapLink = new RecvDataNotifyMapLink(client, this.Id, mapPos,
                                                                          mapTran.MaplinkOffset, mapTran.MaplinkWidth, mapTran.MaplinkColor);
                Router.Send(mapLink, client);
            }

            // ToDo this should be a database lookup
            RecvMapFragmentFlag mapFragments = new RecvMapFragmentFlag(client.Map.Id, 0xff);

            Router.Send(mapFragments, client);


            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(client.Map.Id);
            Router.Send(client, (ushort)AreaPacketId.recv_map_get_info_r, res, ServerType.Area);
        }
Exemplo n.º 18
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.º 19
0
        public void Enter(NecClient client, MapPosition mapPosition = null)
        {
            if (client.map != null)
            {
                client.map.Leave(client);
            }
            client.map = this;

            _Logger.Info(client, $"Entering Map: {id}:{fullName}");
            // If position is passed in use it and set character position, if null then use map default coords
            // If this isn't set here, the wrong coords are in character until send_movement_info updates it.
            if (mapPosition != null)
            {
                client.character.x       = mapPosition.x;
                client.character.y       = mapPosition.y;
                client.character.z       = mapPosition.z;
                client.character.heading = mapPosition.heading;
            }
            //set character coords to default map entry coords If arriving form another map.
            else if (client.character.mapId != id)
            {
                client.character.x       = x;
                client.character.y       = y;
                client.character.z       = z;
                client.character.heading = orientation;
            }

            client.character.mapId     = id;
            client.character.mapChange = false;
            clientLookup.Add(client);
            _Logger.Debug($"Client Lookup count is now : {clientLookup.GetAll().Count}  for map  {id} ");
            _Logger.Debug($"Character State for character {client.character.name} is {client.character.state}");
            //Send your character data to the other living or dead players on the map.

            //on successful map entry, update the client database position
            if (!_server.database.UpdateCharacter(client.character))
            {
                _Logger.Error("Could not update the database with current known player position");
            }
            if (!_server.database.UpdateSoul(client.soul))
            {
                _Logger.Error("Could not update the database with soul details ");
            }

            //ToDo  move all this rendering logic to Send_Map_Entry.   We dont need a copy of this logic on every map instance.
            RecvDataNotifyCharaData myCharacterData = new RecvDataNotifyCharaData(client.character, client.soul.name);

            //dead
            //you are dead here.  only getting soul form characters. sorry bro.
            if (client.character.state.HasFlag(CharacterState.SoulForm))
            {
                foreach (NecClient otherClient in clientLookup.GetAll())
                {
                    if (otherClient == client)
                    {
                        continue;
                    }
                    if (otherClient.character.state.HasFlag(CharacterState.SoulForm))
                    {
                        _server.router.Send(myCharacterData, otherClient);
                    }
                }
            }
            else //Bro, you alive! You gon see living characters!
            {
                foreach (NecClient otherClient in clientLookup.GetAll())
                {
                    if (otherClient == client)
                    {
                        continue;
                    }
                    if (otherClient.character.state.HasFlag(CharacterState.SoulForm))
                    {
                        continue;
                    }
                    _server.router.Send(myCharacterData, otherClient);
                }
            }

            if (client.union != null)
            {
                RecvDataNotifyUnionData myUnionData = new RecvDataNotifyUnionData(client.character, client.union.name);
                _server.router.Send(this, myUnionData, client);
            }

            Task.Delay(TimeSpan.FromSeconds(10)).ContinueWith
                (t1 =>
            {
                foreach (MonsterSpawn monsterSpawn in monsterSpawns.Values)
                {
                    if (monsterSpawn.active)
                    {
                        monsterSpawn.spawnActive = true;
                        if (!monsterSpawn.taskActive)
                        {
                            MonsterTask monsterTask = new MonsterTask(_server, monsterSpawn);
                            if (monsterSpawn.defaultCoords)
                            {
                                monsterTask.monsterHome = monsterSpawn.monsterCoords[0];
                            }
                            else
                            {
                                monsterTask.monsterHome = monsterSpawn.monsterCoords.Find(x => x.coordIdx == 64);
                            }
                            monsterTask.Start();
                        }
                        else
                        {
                            if (monsterSpawn.monsterVisible)
                            {
                                _Logger.Debug($"MonsterTask already running for [{monsterSpawn.name}]");
                                RecvDataNotifyMonsterData monsterData = new RecvDataNotifyMonsterData(monsterSpawn);
                                _server.router.Send(monsterData, client);
                                if (!monsterSpawn.GetAgro())
                                {
                                    monsterSpawn.MonsterMove(_server, client, monsterSpawn.monsterWalkVelocity, 2,
                                                             0);
                                }
                            }
                        }
                    }
                }
            }
                );
        }