| MaZzGanGYy |
2020-08-01 04:23 AM |
سـيستم ال Booth لـسورس اليـكس .
بـــــسم الله الـرحمن الـرحـــيم
يـلا حـاجة تـقيلة اهـي ونـاس كـتير كـانو مـحتاجنها
وانشـاء الله السـيستم كـامل مفهـوش اي حـاجة
هـتعمل كـلاس بـاسم Booth
وترزع فـية دول
كود PHP:
//Copyright MaZzGanGy © 2020-2021 using Extensions; using Project_Terror_v2.Database; using System; using System.Collections.Generic; using System.IO;
namespace Project_Terror_v2.Game.MsgServer { class Booth { public class booth { public uint UID; public ushort Mesh = 100; public string Name; public ushort Map; public ushort X; public ushort Y; public List<string> Items; public byte Type; } public static SafeDictionary<uint, booth> Boooths = new SafeDictionary<uint, booth>(); public static void Load() { string[] text = File.ReadAllLines(Program.ServerConfig.DbLocation + "//Booths.txt"); booth booth = new booth(); for (int x = 0; x < text.Length; x++) { string line = text[x]; string[] split = line.Split('='); if (split[0] == "ID") { if (booth.UID == 0) booth.UID = uint.Parse(split[1]); else { if (!Boooths.ContainsKey(booth.UID)) { Boooths.Add(booth.UID, booth); booth = new booth(); booth.UID = uint.Parse(split[1]); } } } else if (split[0] == "Type") { booth.Type = byte.Parse(split[1]); } else if (split[0] == "Name") { booth.Name = split[1]; } else if (split[0] == "Mesh") { booth.Mesh = ushort.Parse(split[1]); } else if (split[0] == "Map") { booth.Map = ushort.Parse(split[1]); } else if (split[0] == "X") { booth.X = ushort.Parse(split[1]); } else if (split[0] == "Y") { booth.Y = ushort.Parse(split[1]); } else if (split[0] == "ItemAmount") { booth.Items = new List<string>(ushort.Parse(split[1])); } else if (split[0].Contains("Item") && split[0] != "ItemAmount") { string name = split[1]; booth.Items.Add(name); } } if (!Boooths.ContainsKey(booth.UID)) Boooths.Add(booth.UID, booth); CreateBooths(); } public static void CreateBooths()// Created By Amr Hassan { foreach (var bo in Boooths.Values) { Project_Terror_v2.Role.Instance.Vendor booth = new Project_Terror_v2.Role.Instance.Vendor();
Role.SobNpc Base = new Role.SobNpc(); Base.ObjType = Role.MapObjectType.SobNpc; Base.UID = bo.UID; if (Role.Instance.Vendor.Booths.ContainsKey(Base.UID)) Role.Instance.Vendor.Booths.Remove(Base.UID); Role.Instance.Vendor.Booths.Add(Base.UID, booth); Base.Mesh = (Role.SobNpc.StaticMesh)bo.Mesh; Base.Type = Role.Flags.NpcType.Booth; Base.Name = bo.Name; Base.Map = bo.Map; Base.X = bo.X; Base.Y = bo.Y; booth.VendorNpc = Base;
if (Server.ServerMaps.ContainsKey(bo.Map)) { if (Server.ServerMaps[bo.Map].View.Contain(Base.UID, bo.X, bo.Y)) Server.ServerMaps[bo.Map].View.LeaveMap<Role.IMapObj>(Base); Server.ServerMaps[bo.Map].View.EnterMap<Role.IMapObj>(Base); }
for (int i = 0; i < bo.Items.Count; i++) { var line = bo.Items[i].Split(new string[] { "@@", "@" }, StringSplitOptions.RemoveEmptyEntries); Project_Terror_v2.Role.Instance.Vendor.VendorItem item = new Project_Terror_v2.Role.Instance.Vendor.VendorItem();
item.DataItem = new MsgGameItem(); item.DataItem.UID = Database.Server.ITEM_Counter.Next;
item.DataItem.ITEM_ID = uint.Parse(line[0]); if (line.Length >= 2) item.AmountCost = uint.Parse(line[1]); if (line.Length >= 3) item.DataItem.Plus = byte.Parse(line[2]); if (line.Length >= 4) item.DataItem.Enchant = byte.Parse(line[3]); if (line.Length >= 5) item.DataItem.Bless = byte.Parse(line[4]); if (line.Length >= 6) item.DataItem.SocketOne = (Role.Flags.Gem)byte.Parse(line[5]); if (line.Length >= 7) item.DataItem.SocketTwo = (Role.Flags.Gem)byte.Parse(line[6]); if (line.Length >= 8) item.DataItem.StackSize = ushort.Parse(line[7]);
Database.ItemType.DBItem CIBI; if (Database.Server.ItemsBase.TryGetValue(item.DataItem.ITEM_ID, out CIBI)) { item.DataItem.Durability = CIBI.Durability; item.DataItem.MaximDurability = CIBI.Durability; item.CostType = Game.MsgServer.MsgItemView.ActionMode.CPs; booth.Items.TryAdd(item.DataItem.UID, item); } }
} Console.WriteLine("" + Project_Terror_v2.Role.Instance.Vendor.Booths.Count + " New Booths Loaded."); } } }
وبعدين تـروح عـ كلاس Vendor.cs
وتـبدل الي فـية بـدا
كود PHP:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.Concurrent; using Project_Terror_v2.Game.MsgServer;
namespace Project_Terror_v2.Role.Instance { public class Vendor { public static Extensions.Counter VendorCounter = new Extensions.Counter(100000);
public const byte MaxItems = 20;
public class VendorItem { public Game.MsgServer.MsgItemView.ActionMode CostType; public Game.MsgServer.MsgGameItem DataItem; public long AmountCost;
public void Regenerate(VendorItem item, Vendor booth) { booth.Items.TryRemove(item.DataItem.UID, out item); this.AmountCost = item.AmountCost; this.DataItem = new MsgGameItem(); this.DataItem.ITEM_ID = item.DataItem.ITEM_ID; this.DataItem.UID = Database.Server.ITEM_Counter.Next; this.DataItem.Plus = item.DataItem.Plus; this.DataItem.Enchant = item.DataItem.Enchant; this.DataItem.Bless = item.DataItem.Bless; this.DataItem.SocketOne = item.DataItem.SocketOne; this.DataItem.SocketTwo = item.DataItem.SocketTwo; this.DataItem.StackSize = item.DataItem.StackSize; Database.ItemType.DBItem CIBI; if (Database.Server.ItemsBase.TryGetValue(this.DataItem.ITEM_ID, out CIBI)) { this.DataItem.Durability = CIBI.Durability; this.DataItem.MaximDurability = CIBI.Durability; this.CostType = item.CostType; booth.Items.TryAdd(this.DataItem.UID, this); } } } public Client.GameClient Owner; public static Dictionary<uint, Vendor> Booths = new Dictionary<uint, Vendor>(); public ConcurrentDictionary<uint, VendorItem> Items; public Game.MsgServer.MsgMessage HalkMeesaje = null; public SobNpc VendorNpc; public uint VendorUID; public static bool TryGetValue(uint uid, out Vendor booth) { return Booths.TryGetValue(uid, out booth); } // public static bool InVending; public bool InVending; public Vendor() { Items = new ConcurrentDictionary<uint, VendorItem>(); } public Vendor(Client.GameClient client) { Items = new ConcurrentDictionary<uint, VendorItem>(); Owner = client; } public unsafe void CreateVendor(ServerSockets.Packet stream) { if (InVending) return;
VendorUID = VendorCounter.Next;
VendorNpc = new SobNpc(); VendorNpc.ObjType = MapObjectType.SobNpc; VendorNpc.OwnerVendor = Owner; VendorNpc.Name = Owner.Player.Name; VendorNpc.UID = VendorUID; VendorNpc.Mesh = SobNpc.StaticMesh.Vendor; VendorNpc.Type = Flags.NpcType.Booth; VendorNpc.Map = Owner.Player.Map; VendorNpc.X = (ushort)(Owner.Player.X + 1); VendorNpc.Y = Owner.Player.Y;
Owner.Map.View.EnterMap<Role.IMapObj>(VendorNpc);
foreach (var IObj in Owner.Player.View.Roles(MapObjectType.Player)) { Role.Player screenObj = IObj as Role.Player; screenObj.View.CanAdd(VendorNpc, true, stream); } Owner.Player.Send(VendorNpc.GetArray(stream, false)); InVending = true; } public unsafe void StopVending(ServerSockets.Packet stream) { if (InVending) {
ActionQuery actione = new ActionQuery() { ObjId = VendorUID, Type = ActionType.RemoveEntity }; Owner.Player.View.SendView(stream.ActionCreate(actione), true);
Items.Clear(); Owner.Map.View.LeaveMap<Role.IMapObj>(VendorNpc); InVending = false; Owner.MyVendor = null; } } public bool AddItem(Game.MsgServer.MsgGameItem DataItem, Game.MsgServer.MsgItemView.ActionMode CostType, long Amout) { if (DataItem.Bound == 1 || DataItem.Inscribed == 1 || DataItem.Locked != 0 || DataItem.ITEM_ID == 750000) return false;
if (Items.Count == MaxItems) return false; if (!Items.ContainsKey(DataItem.UID)) { VendorItem VItem = new VendorItem(); VItem.DataItem = DataItem; VItem.CostType = CostType; VItem.AmountCost = Amout; Items.TryAdd(DataItem.UID, VItem); return true; } return false; } } }
هـتروح عـلي كـلاس MsgItemUsuagePacket.cs
وتـبحث عـن
case ItemUsuageID.BuyVendingItem:
وهـتبدل ال case كلو بـدا
كود PHP:
case ItemUsuageID.BuyVendingItem: { if (client.IsConnectedInterServer()) break; if (client.Inventory.HaveSpace(1)) { Role.Instance.Vendor booth = null; if (Role.Instance.Vendor.TryGetValue((uint)dwParam, out booth)) { if (booth.Items.ContainsKey(id)) { Role.Instance.Vendor.VendorItem item; if (booth.Items.TryGetValue(id, out item)) { if (item.CostType == MsgItemView.ActionMode.CPs) { if (client.Player.ConquerPoints >= item.AmountCost) { client.Player.ConquerPoints -= (uint)item.AmountCost; //client.Send(stream.ItemUsageCreate(action, id, dwParam, timestamp, dwParam2, dwParam3, dwparam4)); client.Inventory.Update(item.DataItem, Role.Instance.AddMode.MOVE, stream); //var newitem = new Role.Instance.Vendor.VendorItem(); //newitem.Regenerate(item, booth); //Game.MsgServer.MsgItemExtra itemExtra = new Game.MsgServer.MsgItemExtra(); //foreach (var i in booth.Items.Values) //{ // client.Send(stream.ItemViewCreate((uint)dwParam, i.AmountCost, i.DataItem, i.CostType));
// if (i.DataItem.Refinary.InLife) // { // i.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.RefinaryAdding; // if (i.DataItem.Refinary.EffectDuration == 0) // i.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.PermanentRefinery; // itemExtra.Refinerys.Add(i.DataItem.Refinary); // } // if (i.DataItem.Purification.InLife) // { // i.DataItem.Purification.Typ = Game.MsgServer.MsgItemExtra.Typing.PurificationAdding; // itemExtra.Purifications.Add(i.DataItem.Purification); // } //} } } else if (item.CostType == MsgItemView.ActionMode.Gold) { if (client.Player.Money >= item.AmountCost) { client.Player.Money -= item.AmountCost;
client.Player.SendUpdate(stream, client.Player.Money, MsgUpdate.DataType.Money); //client.Send(stream.ItemUsageCreate(action, id, dwParam, timestamp, dwParam2, dwParam3, dwparam4)); client.Inventory.Update(item.DataItem, Role.Instance.AddMode.MOVE, stream); //var newitem = new Role.Instance.Vendor.VendorItem(); //newitem.Regenerate(item, booth); //Game.MsgServer.MsgItemExtra itemExtra = new Game.MsgServer.MsgItemExtra(); //foreach (var i in booth.Items.Values) //{ // client.Send(stream.ItemViewCreate((uint)dwParam, i.AmountCost, i.DataItem, i.CostType));
// if (i.DataItem.Refinary.InLife) // { // i.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.RefinaryAdding; // if (i.DataItem.Refinary.EffectDuration == 0) // i.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.PermanentRefinery; // itemExtra.Refinerys.Add(i.DataItem.Refinary); // } // if (i.DataItem.Purification.InLife) // { // i.DataItem.Purification.Typ = Game.MsgServer.MsgItemExtra.Typing.PurificationAdding; // itemExtra.Purifications.Add(i.DataItem.Purification); // } //} //if (itemExtra.Refinerys.Count != 0 || itemExtra.Purifications.Count != 0) // client.Send(itemExtra.CreateArray(stream)); } } } } } else { Role.IMapObj Obj; if (client.Player.View.TryGetValue((uint)dwParam, out Obj, Role.MapObjectType.SobNpc)) { Role.SobNpc npc = Obj as Role.SobNpc; if (npc.OwnerVendor.IsVendor) { if (npc.OwnerVendor.Inventory.ClientItems.ContainsKey(id)) { Role.Instance.Vendor.VendorItem VItem = null; if (npc.OwnerVendor.MyVendor.Items.TryGetValue(id, out VItem)) { bool RightBuy = false; if (VItem.CostType == MsgItemView.ActionMode.CPs) { if (RightBuy = (client.Player.ConquerPoints >= VItem.AmountCost)) { client.Player.ConquerPoints -= (uint)VItem.AmountCost; npc.OwnerVendor.Player.ConquerPoints += (uint)VItem.AmountCost; } } else if (VItem.CostType == MsgItemView.ActionMode.Gold) { if (RightBuy = (client.Player.Money >= VItem.AmountCost)) { client.Player.Money -= VItem.AmountCost; npc.OwnerVendor.Player.Money += VItem.AmountCost;
client.Player.SendUpdate(stream, client.Player.Money, MsgUpdate.DataType.Money); npc.OwnerVendor.Player.SendUpdate(stream, npc.OwnerVendor.Player.Money, MsgUpdate.DataType.Money); } } if (RightBuy) { if (npc.OwnerVendor.MyVendor.Items.TryRemove(id, out VItem)) { client.Inventory.Update(VItem.DataItem, Role.Instance.AddMode.MOVE, stream);
client.Send(stream.ItemUsageCreate(action, id, dwParam, timestamp, dwParam2, dwParam3, dwparam4));
action = ItemUsuageID.RemoveVendingItem; npc.OwnerVendor.Send(stream.ItemUsageCreate(action, id, dwParam, timestamp, dwParam2, dwParam3, dwparam4));
npc.OwnerVendor.Inventory.Update(VItem.DataItem, Role.Instance.AddMode.REMOVE, stream, true);
var sellit = Database.Server.ItemsBase[VItem.DataItem.ITEM_ID]; #if Arabic string Messaj = "" + npc.OwnerVendor.Player.Name + " just sold " + sellit.Name + " to " + client.Player.Name + " for " + VItem.AmountCost + (VItem.CostType == MsgItemView.ActionMode.CPs ? " ConquerPoints." : " Gold."); #else string Messaj = "" + npc.OwnerVendor.Player.Name + " just sold " + sellit.Name + " to " + client.Player.Name + " for " + VItem.AmountCost + (VItem.CostType == MsgItemView.ActionMode.CPs ? " ConquerPoints." : " Gold.");
#endif client.SendSysMesage(Messaj, MsgMessage.ChatMode.TopLeft, MsgMessage.MsgColor.red, true); } } } } } } } } break; }
فـ نـفس الكـلاس تـبحث عـن case ItemUsuageID.ShowVendingList:
ودا تحت الي فوق علطول يعني
بـدلـو كـلو بدا
كود PHP:
case ItemUsuageID.ShowVendingList: { if (client.IsConnectedInterServer()) break; Role.Instance.Vendor booth = null; if (Role.Instance.Vendor.TryGetValue(id, out booth)) { Game.MsgServer.MsgItemExtra itemExtra = new Game.MsgServer.MsgItemExtra(); foreach (var item in booth.Items.Values) { client.Send(stream.ItemViewCreate(id, item.AmountCost, item.DataItem, item.CostType));
if (item.DataItem.Refinary.InLife) { item.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.RefinaryAdding; if (item.DataItem.Refinary.EffectDuration == 0) item.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.PermanentRefinery; itemExtra.Refinerys.Add(item.DataItem.Refinary); } if (item.DataItem.Purification.InLife) { item.DataItem.Purification.Typ = Game.MsgServer.MsgItemExtra.Typing.PurificationAdding; itemExtra.Purifications.Add(item.DataItem.Purification); } } if (itemExtra.Refinerys.Count != 0 || itemExtra.Purifications.Count != 0) client.Send(itemExtra.CreateArray(stream)); } else { Role.IMapObj Obj; if (client.Player.View.TryGetValue(id, out Obj, Role.MapObjectType.SobNpc)) { Role.SobNpc npc = Obj as Role.SobNpc; if (npc.OwnerVendor.IsVendor) { Game.MsgServer.MsgItemExtra itemExtra = new Game.MsgServer.MsgItemExtra(); foreach (var item in npc.OwnerVendor.MyVendor.Items.Values) { client.Send(stream.ItemViewCreate(npc.UID, item.AmountCost, item.DataItem, item.CostType));
if (item.DataItem.Refinary.InLife) { item.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.RefinaryAdding; if (item.DataItem.Refinary.EffectDuration == 0) item.DataItem.Refinary.Typ = Game.MsgServer.MsgItemExtra.Typing.PermanentRefinery; itemExtra.Refinerys.Add(item.DataItem.Refinary); } if (item.DataItem.Purification.InLife) { item.DataItem.Purification.Typ = Game.MsgServer.MsgItemExtra.Typing.PurificationAdding; itemExtra.Purifications.Add(item.DataItem.Purification); } } if (itemExtra.Refinerys.Count != 0 || itemExtra.Purifications.Count != 0) client.Send(itemExtra.CreateArray(stream)); } } } break; }
وبـعدين تـروح لـكلاس Server.cs
ابحـث عـن
ضـيف تـحتو
بالنـسبة لـتكست ال Booth فـ دا تـاخدو مـ سورس تـاني وتـحطو ف القـاعدة بـاعت السـورس
صـورة
عفواً لايمكن عرض الروابط إلا بعد الرد على الموضوع
|