示例#1
0
        public override void OnResponse(NetState state, RelayInfo info)
        {
            if (info == null || state == null || state.Mobile == null || Rewards == null)
            {
                return;
            }

            Mobile from = state.Mobile;

            switch (info.ButtonID)
            {
            case 12:
                // page up
                int nitems = 0;
                if (Rewards != null)
                {
                    nitems = Rewards.Count;
                }

                int page = viewpage + 1;
                if (page > (int)(nitems / maxItemsPerPage))
                {
                    page = (int)(nitems / maxItemsPerPage);
                }
                state.Mobile.SendGump(new PointsRewardGump(state.Mobile, page));
                break;

            case 13:
                // page down
                page = viewpage - 1;
                if (page < 0)
                {
                    page = 0;
                }
                state.Mobile.SendGump(new PointsRewardGump(state.Mobile, page));
                break;

            default:
            {
                if (info.ButtonID >= 1000)
                {
                    int selection = info.ButtonID - 1000;
                    if (selection < Rewards.Count)
                    {
                        XmlPointsRewards r = Rewards[selection] as XmlPointsRewards;

                        // check the price
                        if (XmlPoints.HasCredits(from, r.Cost))
                        {
                            // create an instance of the reward type
                            object o = null;

                            try{
                                o = Activator.CreateInstance(r.RewardType, r.RewardArgs);
                            } catch {}

                            bool received = true;

                            if (o is Item)
                            {
                                // and give them the item
                                from.AddToBackpack((Item)o);
                            }
                            else
                            if (o is Mobile)
                            {
                                // if it is controllable then set the buyer as master.  Note this does not check for control slot limits.
                                if (o is BaseCreature)
                                {
                                    BaseCreature b = o as BaseCreature;
                                    b.Controlled    = true;
                                    b.ControlMaster = from;
                                }

                                ((Mobile)o).MoveToWorld(from.Location, from.Map);
                            }
                            else
                            if (o is XmlAttachment)
                            {
                                XmlAttachment a = o as XmlAttachment;

                                XmlAttach.AttachTo(from, a);
                            }
                            else
                            {
                                from.SendMessage(33, "unable to create {0}.", r.RewardType.Name);
                                received = false;
                            }

                            // complete the transaction
                            if (received)
                            {
                                // charge them
                                XmlPoints.TakeCredits(from, r.Cost);
                                from.SendMessage("You have purchased {0} for {1} credits.", r.Name, r.Cost);
                            }
                        }
                        else
                        {
                            from.SendMessage("Insufficient Credits for {0}.", r.Name);
                        }
                        from.SendGump(new PointsRewardGump(from, viewpage));
                    }
                }
                break;
            }
            }
        }