Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public virtual async Task Leave(FieldUser user, MiniRoomLeaveType type = MiniRoomLeaveType.Kicked)
        {
            var pair = Users.FirstOrDefault(kv => kv.Value == user);

            using (var p = new Packet(SendPacketOperations.MiniRoom))
            {
                p.Encode <byte>((byte)MiniRoomAction.MRP_Leave);
                p.Encode <byte>(pair.Key);
                p.Encode <byte>((byte)type);
                await BroadcastPacket(p);
            }
            await user.Interact(this, true);

            Users.Remove(pair);
        }
Exemplo n.º 3
0
        public Task OnPacket(RecvPacketOperations operation, FieldUser user, IPacket packet)
        {
            var type = (TrunkRequest)packet.Decode <byte>();

            switch (type)
            {
            case TrunkRequest.GetItem:
                return(OnTrunkGetItemRequest(user, packet));

            case TrunkRequest.PutItem:
                return(OnTrunkPutItemRequest(user, packet));

            case TrunkRequest.SortItem:
                return(OnTrunkSortItemRequest(user, packet));

            case TrunkRequest.Money:
                return(OnTrunkMoneyRequest(user, packet));

            case TrunkRequest.CloseDialog:
                return(user.Interact(this, true));
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
 protected override Task ExecuteAfter(FieldUser user, TestCommandOption option)
 {
     return(user.Interact(_room));
 }