محمد ياسر
2019-07-19, 04:02 PM
السلام عليكم عليكم ورحمة الله وبركاته
اضافه حرب الهيروا الي ناس كتير بتدور عليه ومش اتلقيه لاني سحبه من سورس موجوده فيه
يلا نبداء باول كلاستين
في فلدر Game اعمل فلدر داخله اسمه Statue
وارمي الكلاسين دول
واحد باسم Statue.cs
ارمي الاكواد ده جواها
using System;
using MoDY.Network.GamePackets;
using System.Collections.Concurrent;
namespace MoDY.Game
{
public unsafe class Statue : Network.Writer
{
public static ConcurrentDictionary<uint, Statue> Statues = new ConcurrentDictionary<uint, Statue>();
public byte[] SpawnPacket = null;
public uint UID;
public Statue(byte[] array)
{
UID = 105175;
SpawnPacket = new byte[array.Length];
for (ushort x = 0; x < array.Length; x++)
SpawnPacket[x] = array[x];
WriteByte(0, MsgPlayer.Facing, SpawnPacket);
WriteUInt32(0, MsgPlayer.Action, SpawnPacket);
WriteUInt16(1000, MsgPlayer.GuildRank, SpawnPacket);
WriteUInt32(105175, MsgPlayer.UID, SpawnPacket);
WriteUInt64(0, MsgPlayer.StatusFlag, SpawnPacket);
WriteUInt64(0, MsgPlayer.StatusFlag2, SpawnPacket);
WriteUInt64(0, MsgPlayer.StatusFlag3, SpawnPacket);
WriteUInt32(0, MsgPlayer.Hitpoints, SpawnPacket);
WriteUInt32(0, MsgPlayer.GuildID, SpawnPacket);
X = 328;
Y = 304;
if (array.Length > 200)
{
if (!Statues.ContainsKey(105175))
Statues.TryAdd(105175, this);
else
{
Statues[105175] = this;
}
}
}
public static bool operator >(Statue statue, Client.GameState client)
{
if (!client.Screen.Statue.ContainsKey(statue.UID))
{
if (Kernel.GetDistance(statue.X, statue.Y, client.Player.X, client.Player.Y) < 16 && client.Player.MapID == 1002)
{
if (statue.SpawnPacket.Length > 200)
{
client.Send(statue.SpawnPacket);
return true;
}
}
}
return false;
}
public static bool operator <(Statue statue, Client.GameState client)
{
if (Kernel.GetDistance(statue.X, statue.Y, client.Player.X, client.Player.Y) >= 16 && client.Player.MapID == 1002)
{
return true;
}
return false;
}
}
}
وواحد باسم StatueTable.cs
ارمي دول جواها
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace MoDY.Database
{
public unsafe class StatueTable
{
public static void Load()
{
using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("statue").Where("UID", 105175))
using (var reader = cmd.CreateReader())
{
if (reader.Read())
{
using (var stream = new MemoryStream((reader.ReadBlob("data"))))
using (var hreader = new BinaryReader(stream))
{
uint Count = hreader.ReadUInt32();
byte[] array = new byte[Count];
for (int x = 0; x < Count; x++)
array[x] = hreader.ReadByte();
new Game.Statue(array);
}
}
else
{
string SQL = "INSERT INTO `statue` (uid, data) VALUES (@UID, @Data)";
MemoryStream stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(0);
byte[] rawData = stream.ToArray();
using (var conn = DataHolder.MySqlConnection)
{
conn.Open();
using (var cmd2 = new MySql.Data.MySqlClient.MySqlCommand(SQL, conn))
{
cmd2.Parameters.AddWithValue("@UID", 105175);
cmd2.Parameters.AddWithValue("@Data", rawData);
cmd2.ExecuteNonQuery();
}
}
}
}
}
public static void Save()
{
MemoryStream stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(stream);
bool WasAdd = false;
foreach (var statu in Game.Statue.Statues.Values)
{
if (statu.SpawnPacket != null)
{
if (statu.SpawnPacket.Length > 200)
{
WasAdd = true;
writer.Write(statu.SpawnPacket.Length);
writer.Write(statu.SpawnPacket);
}
}
}
if (!WasAdd)
writer.Write(0);
string SQL = "UPDATE `statue` SET data=@Data where UID = " + 105175 + " ;";
byte[] rawData = stream.ToArray();
using (var conn = DataHolder.MySqlConnection)
{
conn.Open();
using (var cmd = new MySql.Data.MySqlClient.MySqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = SQL;
cmd.Parameters.AddWithValue("@Data", rawData);
cmd.ExecuteNonQuery();
}
}
}
}
}
وارفع ده للقاعده
تحميل الملف (عفواً لايمكن عرض الروابط في الإرشيف)
كده خلصنا من شغل التمثال
نيجي لشغل الكوسته نفسه
في المسار ده او اي مسار
Game\Features\Event
اعمل ملف اسمه
HeroOfGame.cs
ارمي في دول
using MoDY.Network.GamePackets;
using System;
using System.Linq;
namespace MoDY.Game.Features.Tournaments
{
public unsafe class HeroOfGame
{
public HeroOfGame()
{
open = false;
}
public void CheakUp()
{
if (DateTime.Now.Hour == 19 && DateTime.Now.Minute == 17 && DateTime.Now.Second <= 2 && !open)
{
Start();
}
}
uint Secounds = 0;
private IDisposable Subscribe;
bool open = false;
bool SendInvitation = false;
public void Start()
{
if (!open)
{
Secounds = 0;
SendInvitation = false;
open = true;
Subscribe = Thread.Subscribe(Work, 1000);
}
}
public void SendMapMessage(string packet)
{
var data = new Network.GamePackets.MsgTalk(packet, System.Drawing.Color.Yellow, Network.GamePackets.MsgTalk.Center);
var MapDictionary = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionary)
{
client.Send(data);
}
}
public int CkeckUPAlive()
{
int Count = 0;
var MapDictionary = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionary)
{
if (client.Player.Hitpoints > 0)
Count++;
}
return Count;
}
public void Close()
{
open = false;
Subscribe.Dispose();
}
public void Work(int time)
{
if (!SendInvitation)
{
foreach (var client in Kernel.GamePool.Values)
{
if (!client.InQualifier() && client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Player.Dead)
{
client.MessageBox("Hero OF Game has begun! Would you like to join?",
(p) => { p.Player.Teleport(1507, 96, 113); }, null, 40);
}
}
SendInvitation = true;
}
else
{
if (open)
{
if (Secounds == 30)
SendMapMessage("Hero OF Game will start in 30 Secounds");
else if (Secounds == 40)
SendMapMessage("Hero OF Game will start in 20 Secounds");
else if (Secounds == 50)
SendMapMessage("Hero OF Game will start in 10 Secounds");
else if (Secounds == 55)
SendMapMessage("Hero OF Game will start in 5 Secounds");
else if (Secounds == 58)
SendMapMessage("Hero OF Game will start in 3 Secounds");
else if (Secounds == 60)
{
var MapDictionary = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionary)
{
client.Player.AllowToAttack = true;
}
SendMapMessage("Fight Now!");
}
else if (Secounds > 60)
{
byte[] Messaje = new Network.GamePackets.MsgTalk("Alive Players : [ " + CkeckUPAlive() + " ]", System.Drawing.Color.Yellow, Network.GamePackets.MsgTalk.FirstRightCorner).ToAr ray();
var MapDictionar = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionar)
client.Send(Messaje);
if (CkeckUPAlive() == 1)
{
var client = Kernel.GamePool.Values.SingleOrDefault(p => p.Player.MapID == 1507 && p.Player.Hitpoints > 0);
if (client != null)
{
Game.Statue statue = new Statue(client.Player.SpawnPacket);
client.Player.ConquerPoints += 5000;
client.Player.AddTopStatus((ulong)MsgUpdate.Flags3 .rygh_hglx, 3, DateTime.Now.AddMinutes(58));
Game.Player.SendWorldMessage("Congratulation ! " + client.Player.Name + " win the Hero OF Game, he receice 5000 Conquer Points");
Close();
}
foreach (var player in Kernel.GamePool.Values)
{
if (player.Player.MapID == 1507)
player.Player.Teleport(1002, 300, 278);
player.Player.AllowToAttack = false;
}
}
else if (CkeckUPAlive() == 0)
{
Close();
}
}
Secounds++;
}
}
}
}
}
في كلاس screen.cs
ابحث عن
public void Reload(IPacket spawnWith)
{
تحت القوس ضيف دول
CleanUp(spawnWith);
if (Owner.Player.MapID == 1002)
{
foreach (var statue in Game.Statue.Statues.Values)
{
if (statue > Owner)
{
Statue.TryAdd(statue.UID, statue);
}
else if (statue < Owner)
{
Game.Statue astatue;
Statue.TryRemove(statue.UID, out astatue);
}
}
}
else
{
if (Statue.Count > 0)
Statue.Clear();
}
في نفس الكلاس ضيف ال public ده
public ConcurrentDictionary<uint, Statue> Statue = new ConcurrentDictionary<uint, Statue>();
في كلاس Thread.cs او world.cs
ضيف ال public ده
public HeroOfGame HeroOfGame = new HeroOfGame();
وضيف الانفيت تحت اي انفيت عندك
#region HeroOFGame
if (DateTime.Now.Hour == 19 && DateTime.Now.Hour == 16 && DateTime.Now.Second == 30)
{
HeroOfGame.CheakUp();
}
#endregion
في كلاس ال war.cs
ابحث عن
public class Start
تحت القوس الي تحتيه ضيف ده
public static bool HeroOfGame
{
get
{
return now.Minute == 30;
}
}
في كلاس EventTimeTable.cs او progrem لو ملقتهاش في الكلاس الاول اتلقيه في البروجرام
ضيف ده
ابحث عن
DeathWarEnd = reader.ReadUInt32("DeathWarEnd");
تحته ضيف ده
HeroOFGameHour = reader.ReadUInt32("HeroOFGameHour");
HeroOFGameMinute = reader.ReadUInt32("HeroOFGameMinute");
في نفس الكلاس
ابحث عن
DeathWarEnd = 0,
ضيف تحته ده
HeroOFGameHour = 0,
HeroOFGameMinute = 0,
ده الاضافه كامله لسورس msg علشان الي كان عايزه دلوقتي بقيت سهله ونقل التمثال موجود في شرح ميروا
اضافه حرب الهيروا الي ناس كتير بتدور عليه ومش اتلقيه لاني سحبه من سورس موجوده فيه
يلا نبداء باول كلاستين
في فلدر Game اعمل فلدر داخله اسمه Statue
وارمي الكلاسين دول
واحد باسم Statue.cs
ارمي الاكواد ده جواها
using System;
using MoDY.Network.GamePackets;
using System.Collections.Concurrent;
namespace MoDY.Game
{
public unsafe class Statue : Network.Writer
{
public static ConcurrentDictionary<uint, Statue> Statues = new ConcurrentDictionary<uint, Statue>();
public byte[] SpawnPacket = null;
public uint UID;
public Statue(byte[] array)
{
UID = 105175;
SpawnPacket = new byte[array.Length];
for (ushort x = 0; x < array.Length; x++)
SpawnPacket[x] = array[x];
WriteByte(0, MsgPlayer.Facing, SpawnPacket);
WriteUInt32(0, MsgPlayer.Action, SpawnPacket);
WriteUInt16(1000, MsgPlayer.GuildRank, SpawnPacket);
WriteUInt32(105175, MsgPlayer.UID, SpawnPacket);
WriteUInt64(0, MsgPlayer.StatusFlag, SpawnPacket);
WriteUInt64(0, MsgPlayer.StatusFlag2, SpawnPacket);
WriteUInt64(0, MsgPlayer.StatusFlag3, SpawnPacket);
WriteUInt32(0, MsgPlayer.Hitpoints, SpawnPacket);
WriteUInt32(0, MsgPlayer.GuildID, SpawnPacket);
X = 328;
Y = 304;
if (array.Length > 200)
{
if (!Statues.ContainsKey(105175))
Statues.TryAdd(105175, this);
else
{
Statues[105175] = this;
}
}
}
public static bool operator >(Statue statue, Client.GameState client)
{
if (!client.Screen.Statue.ContainsKey(statue.UID))
{
if (Kernel.GetDistance(statue.X, statue.Y, client.Player.X, client.Player.Y) < 16 && client.Player.MapID == 1002)
{
if (statue.SpawnPacket.Length > 200)
{
client.Send(statue.SpawnPacket);
return true;
}
}
}
return false;
}
public static bool operator <(Statue statue, Client.GameState client)
{
if (Kernel.GetDistance(statue.X, statue.Y, client.Player.X, client.Player.Y) >= 16 && client.Player.MapID == 1002)
{
return true;
}
return false;
}
}
}
وواحد باسم StatueTable.cs
ارمي دول جواها
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace MoDY.Database
{
public unsafe class StatueTable
{
public static void Load()
{
using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("statue").Where("UID", 105175))
using (var reader = cmd.CreateReader())
{
if (reader.Read())
{
using (var stream = new MemoryStream((reader.ReadBlob("data"))))
using (var hreader = new BinaryReader(stream))
{
uint Count = hreader.ReadUInt32();
byte[] array = new byte[Count];
for (int x = 0; x < Count; x++)
array[x] = hreader.ReadByte();
new Game.Statue(array);
}
}
else
{
string SQL = "INSERT INTO `statue` (uid, data) VALUES (@UID, @Data)";
MemoryStream stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(0);
byte[] rawData = stream.ToArray();
using (var conn = DataHolder.MySqlConnection)
{
conn.Open();
using (var cmd2 = new MySql.Data.MySqlClient.MySqlCommand(SQL, conn))
{
cmd2.Parameters.AddWithValue("@UID", 105175);
cmd2.Parameters.AddWithValue("@Data", rawData);
cmd2.ExecuteNonQuery();
}
}
}
}
}
public static void Save()
{
MemoryStream stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(stream);
bool WasAdd = false;
foreach (var statu in Game.Statue.Statues.Values)
{
if (statu.SpawnPacket != null)
{
if (statu.SpawnPacket.Length > 200)
{
WasAdd = true;
writer.Write(statu.SpawnPacket.Length);
writer.Write(statu.SpawnPacket);
}
}
}
if (!WasAdd)
writer.Write(0);
string SQL = "UPDATE `statue` SET data=@Data where UID = " + 105175 + " ;";
byte[] rawData = stream.ToArray();
using (var conn = DataHolder.MySqlConnection)
{
conn.Open();
using (var cmd = new MySql.Data.MySqlClient.MySqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = SQL;
cmd.Parameters.AddWithValue("@Data", rawData);
cmd.ExecuteNonQuery();
}
}
}
}
}
وارفع ده للقاعده
تحميل الملف (عفواً لايمكن عرض الروابط في الإرشيف)
كده خلصنا من شغل التمثال
نيجي لشغل الكوسته نفسه
في المسار ده او اي مسار
Game\Features\Event
اعمل ملف اسمه
HeroOfGame.cs
ارمي في دول
using MoDY.Network.GamePackets;
using System;
using System.Linq;
namespace MoDY.Game.Features.Tournaments
{
public unsafe class HeroOfGame
{
public HeroOfGame()
{
open = false;
}
public void CheakUp()
{
if (DateTime.Now.Hour == 19 && DateTime.Now.Minute == 17 && DateTime.Now.Second <= 2 && !open)
{
Start();
}
}
uint Secounds = 0;
private IDisposable Subscribe;
bool open = false;
bool SendInvitation = false;
public void Start()
{
if (!open)
{
Secounds = 0;
SendInvitation = false;
open = true;
Subscribe = Thread.Subscribe(Work, 1000);
}
}
public void SendMapMessage(string packet)
{
var data = new Network.GamePackets.MsgTalk(packet, System.Drawing.Color.Yellow, Network.GamePackets.MsgTalk.Center);
var MapDictionary = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionary)
{
client.Send(data);
}
}
public int CkeckUPAlive()
{
int Count = 0;
var MapDictionary = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionary)
{
if (client.Player.Hitpoints > 0)
Count++;
}
return Count;
}
public void Close()
{
open = false;
Subscribe.Dispose();
}
public void Work(int time)
{
if (!SendInvitation)
{
foreach (var client in Kernel.GamePool.Values)
{
if (!client.InQualifier() && client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Player.Dead)
{
client.MessageBox("Hero OF Game has begun! Would you like to join?",
(p) => { p.Player.Teleport(1507, 96, 113); }, null, 40);
}
}
SendInvitation = true;
}
else
{
if (open)
{
if (Secounds == 30)
SendMapMessage("Hero OF Game will start in 30 Secounds");
else if (Secounds == 40)
SendMapMessage("Hero OF Game will start in 20 Secounds");
else if (Secounds == 50)
SendMapMessage("Hero OF Game will start in 10 Secounds");
else if (Secounds == 55)
SendMapMessage("Hero OF Game will start in 5 Secounds");
else if (Secounds == 58)
SendMapMessage("Hero OF Game will start in 3 Secounds");
else if (Secounds == 60)
{
var MapDictionary = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionary)
{
client.Player.AllowToAttack = true;
}
SendMapMessage("Fight Now!");
}
else if (Secounds > 60)
{
byte[] Messaje = new Network.GamePackets.MsgTalk("Alive Players : [ " + CkeckUPAlive() + " ]", System.Drawing.Color.Yellow, Network.GamePackets.MsgTalk.FirstRightCorner).ToAr ray();
var MapDictionar = Kernel.GamePool.Values.Where(p => p.Player.MapID == 1507).ToArray();
foreach (var client in MapDictionar)
client.Send(Messaje);
if (CkeckUPAlive() == 1)
{
var client = Kernel.GamePool.Values.SingleOrDefault(p => p.Player.MapID == 1507 && p.Player.Hitpoints > 0);
if (client != null)
{
Game.Statue statue = new Statue(client.Player.SpawnPacket);
client.Player.ConquerPoints += 5000;
client.Player.AddTopStatus((ulong)MsgUpdate.Flags3 .rygh_hglx, 3, DateTime.Now.AddMinutes(58));
Game.Player.SendWorldMessage("Congratulation ! " + client.Player.Name + " win the Hero OF Game, he receice 5000 Conquer Points");
Close();
}
foreach (var player in Kernel.GamePool.Values)
{
if (player.Player.MapID == 1507)
player.Player.Teleport(1002, 300, 278);
player.Player.AllowToAttack = false;
}
}
else if (CkeckUPAlive() == 0)
{
Close();
}
}
Secounds++;
}
}
}
}
}
في كلاس screen.cs
ابحث عن
public void Reload(IPacket spawnWith)
{
تحت القوس ضيف دول
CleanUp(spawnWith);
if (Owner.Player.MapID == 1002)
{
foreach (var statue in Game.Statue.Statues.Values)
{
if (statue > Owner)
{
Statue.TryAdd(statue.UID, statue);
}
else if (statue < Owner)
{
Game.Statue astatue;
Statue.TryRemove(statue.UID, out astatue);
}
}
}
else
{
if (Statue.Count > 0)
Statue.Clear();
}
في نفس الكلاس ضيف ال public ده
public ConcurrentDictionary<uint, Statue> Statue = new ConcurrentDictionary<uint, Statue>();
في كلاس Thread.cs او world.cs
ضيف ال public ده
public HeroOfGame HeroOfGame = new HeroOfGame();
وضيف الانفيت تحت اي انفيت عندك
#region HeroOFGame
if (DateTime.Now.Hour == 19 && DateTime.Now.Hour == 16 && DateTime.Now.Second == 30)
{
HeroOfGame.CheakUp();
}
#endregion
في كلاس ال war.cs
ابحث عن
public class Start
تحت القوس الي تحتيه ضيف ده
public static bool HeroOfGame
{
get
{
return now.Minute == 30;
}
}
في كلاس EventTimeTable.cs او progrem لو ملقتهاش في الكلاس الاول اتلقيه في البروجرام
ضيف ده
ابحث عن
DeathWarEnd = reader.ReadUInt32("DeathWarEnd");
تحته ضيف ده
HeroOFGameHour = reader.ReadUInt32("HeroOFGameHour");
HeroOFGameMinute = reader.ReadUInt32("HeroOFGameMinute");
في نفس الكلاس
ابحث عن
DeathWarEnd = 0,
ضيف تحته ده
HeroOFGameHour = 0,
HeroOFGameMinute = 0,
ده الاضافه كامله لسورس msg علشان الي كان عايزه دلوقتي بقيت سهله ونقل التمثال موجود في شرح ميروا