Пример #1
0
        public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user)
        {
            packet.Decode <byte>();

            var name   = packet.Decode <string>();
            var portal = user.Field.Template.Portals.Values
                         .FirstOrDefault(p => p.Name.Equals(name));

            if (portal == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(portal.Script))
            {
                return;
            }

            var context      = new ConversationContext(user.Socket);
            var conversation = await user.Service.ConversationManager.Build(
                portal.Script,
                context,
                new FieldSpeaker(context, user.Field),
                new FieldUserSpeaker(context, user)
                );

            await user.Converse(conversation);
        }
Пример #2
0
        public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user)
        {
            var npc = user.Field.GetObject <FieldNPC>(packet.Decode <int>());

            if (npc == null)
            {
                return;
            }

            var template = npc.Template;

            if (template.Trunk)
            {
                await user.Interact(new TrunkDialog(user, template, user.AccountData.Trunk));

                return;
            }

            var shop = user.Service.TemplateManager.Get <NPCShopTemplate>(template.ID);

            if (shop != null)
            {
                await user.Interact(new ShopDialog(user, shop));

                return;
            }

            var script = template.Scripts.FirstOrDefault()?.Script;

            if (script == null)
            {
                return;
            }

            var context      = new ConversationContext(user.Socket);
            var conversation = await user.Service.ConversationManager.Build(
                script,
                context,
                new FieldNPCSpeaker(context, npc),
                new FieldUserSpeaker(context, user)
                );

            await user.Converse(conversation);
        }