Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Rice emu Shop system source

Newbie Spellweaver
Joined
Jul 24, 2015
Messages
20
Reaction score
15
Shop buy system minimal fixed source code:

Server/Packets/Game/Shop.cs

Code:
using System;
using DriftCity.Server.Structures;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DriftCity.Server.Core;


namespace DriftCity.Server.Packets.Game
{
    public static class Shop
    {


        [DriftCityPacket(405, DriftCityServer.ServerType.Game)]
        public static void BuyItem(DriftCityPacket packet)
        {
            
            int id = packet.Reader.ReadInt32();
            int quantity = packet.Reader.ReadInt32();


            DbConnection dbconn_d = Database.GetConnection();
            DbCommand items = dbconn_d.CreateCommand();
            items.CommandText = @"SELECT price FROM items WHERE id = '" + id + "'";


            DbDataReader itemdata = items.ExecuteReader();
            
            if( itemdata.HasRows )
            {
                while( itemdata.Read() )
                {
                   // By SdfSdf
                    Log.WriteLine("Shop Buy - ItemID: {0} Quantity: {1} Price: {2}", id, quantity, (itemdata.GetInt32(0)));


                    var ack = new DriftCityPacket(406);
                    ack.Writer.Write(id);
                    ack.Writer.Write(quantity);
                    ack.Writer.Write(itemdata.GetInt32(0) * quantity);


                    packet.Sender.Send(ack);


                    break;
                }
            }
            else
            {
                packet.Sender.Error( "Add item id = {0} to the database!", id );
            }


            itemdata.Close();
        }
    }


}

Credits: By SdfSdf
 
Back
Top