|
|
المشاركات 328 |
+التقييم 0.18 |
تاريخ التسجيل Nov 2019 |
الاقامة |
نظام التشغيل |
رقم العضوية 2314 |
NewMonsterSpawn
using System;
using System.IO;
using System.Linq;
using System.Text;
using MidoAzoz.Game;
using System.Collections.Generic;
namespace MidoAzoz.Database
{
public class NewMonsterSpawn
{
public static bool Loading = false;
public static Map Map;
public static Database.MonsterInformation MonsterInformation;
public static Dictionary<uint, MonstersInfo> MSSpawn = new Dictionary<uint, MonstersInfo>();
public class MonstersInfo
{
public uint UID;
public uint Count;
public string Name;
public ushort MapID;
public ushort Xx;
public ushort Yy;
public uint MonsterID;
public bool EmptySpots;
public int Respawn;
public byte RangeSpot;
}
public static void Load()
{
using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("newmobspawn"))
using (var reader = cmd.CreateReader())
{
while (reader.Read())
{
MonstersInfo MoB = new MonstersInfo();
MoB.UID = reader.ReadUInt32("UID");
MoB.Count = reader.ReadUInt32("Count");
MoB.Name = reader.ReadString("Name");
MoB.MapID = reader.ReadUInt16("MapID");
if (!Kernel.Maps.ContainsKey(MoB.MapID))
Database.DMaps.LoadMap(MoB.MapID);
MoB.Xx = reader.ReadUInt16("Xx");
MoB.Yy = reader.ReadUInt16("Yy");
MoB.MonsterID = reader.ReadUInt32("MonsterID");
MoB.EmptySpots = reader.ReadBoolean("EmptySpots");
MoB.Respawn = reader.ReadInt32("Respawn");
MoB.RangeSpot = reader.ReadByte("RangeSpot");
MSSpawn.Add(MoB.UID, MoB);
}
}
SendSpawns();
Loading = false;
}
public static void SendSpawns()
{
Loading = true;
foreach (var mob in MSSpawn.Values)
{
try
{
Map = Kernel.Maps[mob.MapID];
if (Map == null) { ReportError(mob, "[Map]"); continue; }
if (mob.Count < 1) { ReportError(mob, "[Count]"); continue; }
if (mob.MapID < 1) { ReportError(mob, "[MapID]"); continue; }
if (mob.MonsterID < 1) { ReportError(mob, "[MonsterID]"); continue; }
Tuple<ushort, ushort> coords;
if (mob.EmptySpots)
{
for (uint i = 0; i <= mob.Count; i++)
{
coords = Map.RandomCoordinates();
if (Kernel.GetDistance(coords.Item1, coords.Item2, mob.Xx, mob.Yy) > mob.RangeSpot * 2)//Mesh haytl3 el wo7osh fi el distance da..
{
if (Map.Npcs.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0 && Map.Entities.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0)
Spawn(mob, coords.Item1, coords.Item2);//Haytl3 el w7osh [b3eed] 3an el distance ale bt7dd..
}
}
}
if (!mob.EmptySpots)
{
if (mob.Xx > 0)
{
for (uint i = 0; i <= mob.Count; i++)
{
coords = Kernel.Maps[mob.MapID].RandomCoordinates(mob.Xx, mob.Yy, mob.RangeSpot);
if (Kernel.GetDistance(coords.Item1, coords.Item2, mob.Xx, mob.Yy) < mob.RangeSpot)//Haytl3 el w7osh [fe] el distance ale bt7dd bas..
{
if (Map.Npcs.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0 && Map.Entities.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0)
Spawn(mob, coords.Item1, coords.Item2);
}
}
}
if (mob.Xx == 0)
{
for (uint i = 0; i <= mob.Count; i++)
{
coords = Map.RandomCoordinates();
if (Map.Npcs.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0 && Map.Entities.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0)
Spawn(mob, coords.Item1, coords.Item2);//Haytl3 el w7osh fe el map kolha
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
public static void ReportError(MonstersInfo Mob, string reson)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(string.Format("UID: {0}, ID: {1}, Name: {2}, Count: {3}, MapID: {4}.." + reson.ToUpper(), Mob.UID, Mob.MonsterID, Mob.Name, Mob.Count, Mob.MapID));
Console.ForegroundColor = ConsoleColor.Red;
}
public static void Spawn(MonstersInfo Mob, ushort X, ushort Y)
{
if (Database.MonsterInformation.MonsterInformations.ContainsKey(Mob.MonsterID))
{
Database.MonsterInformation mt = Database.MonsterInformation.MonsterInformations[Mob.MonsterID];
mt.RespawnTime = Mob.Respawn;
mt.BoundX = X;
mt.BoundY = Y;
mt.BoundCX = X;
mt.BoundCY = Y;
Player entity = new Player(PlayerFlag.Monster, false);
entity.MapObjType = MapObjectType.Monster;
entity.MonsterInfo = mt.Copy();
entity.MonsterInfo.Owner = entity;
entity.Name = mt.Name;
entity.MinAttack = mt.MinAttack;
entity.MaxAttack = entity.MagicAttack = mt.MaxAttack;
entity.Hitpoints = entity.MaxHitpoints = mt.Hitpoints;
entity.Defence = mt.Defence;
entity.Body = mt.Mesh;
entity.Level = mt.Level;
entity.UID = Map.EntityUIDCounter.Next;
entity.MapID = Map.ID;
entity.SendUpdates = true;
entity.X = X;
entity.Y = Y;
if (Map.Floor[entity.X, entity.Y, MapObjectType.Monster, entity])
{
Map.AddEntity(entity);
}
Map.Timer = Map.MonsterTimers.Add(Map);
foreach (var p in Kernel.GamePool.Values.Where(z => z.Map.ID == Map.ID && z.GetDistance(entity) <= 19))
entity.SendSpawn(p);
}
}
}
}
private static void _timerCallBack(Map map, int time)
if (Database.NewMonsterSpawn.Loading) return;
Database.NewMonsterSpawn.Load();
using System;
using System.IO;
using System.Linq;
using System.Text;
using MidoAzoz.Game;
using System.Collections.Generic;
namespace MidoAzoz.Database
{
public class NewMonsterSpawn
{
public static bool Loading = false;
public static Map Map;
public static Database.MonsterInformation MonsterInformation;
public static Dictionary<uint, MonstersInfo> MSSpawn = new Dictionary<uint, MonstersInfo>();
public class MonstersInfo
{
public uint UID;
public uint Count;
public string Name;
public ushort MapID;
public ushort Xx;
public ushort Yy;
public uint MonsterID;
public bool EmptySpots;
public int Respawn;
public byte RangeSpot;
}
public static void Load()
{
using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("newmobspawn"))
using (var reader = cmd.CreateReader())
{
while (reader.Read())
{
MonstersInfo MoB = new MonstersInfo();
MoB.UID = reader.ReadUInt32("UID");
MoB.Count = reader.ReadUInt32("Count");
MoB.Name = reader.ReadString("Name");
MoB.MapID = reader.ReadUInt16("MapID");
if (!Kernel.Maps.ContainsKey(MoB.MapID))
Database.DMaps.LoadMap(MoB.MapID);
MoB.Xx = reader.ReadUInt16("Xx");
MoB.Yy = reader.ReadUInt16("Yy");
MoB.MonsterID = reader.ReadUInt32("MonsterID");
MoB.EmptySpots = reader.ReadBoolean("EmptySpots");
MoB.Respawn = reader.ReadInt32("Respawn");
MoB.RangeSpot = reader.ReadByte("RangeSpot");
MSSpawn.Add(MoB.UID, MoB);
}
}
SendSpawns();
Loading = false;
}
public static void SendSpawns()
{
Loading = true;
foreach (var mob in MSSpawn.Values)
{
try
{
Map = Kernel.Maps[mob.MapID];
if (Map == null) { ReportError(mob, "[Map]"); continue; }
if (mob.Count < 1) { ReportError(mob, "[Count]"); continue; }
if (mob.MapID < 1) { ReportError(mob, "[MapID]"); continue; }
if (mob.MonsterID < 1) { ReportError(mob, "[MonsterID]"); continue; }
Tuple<ushort, ushort> coords;
if (mob.EmptySpots)
{
for (uint i = 0; i <= mob.Count; i++)
{
coords = Map.RandomCoordinates();
if (Kernel.GetDistance(coords.Item1, coords.Item2, mob.Xx, mob.Yy) > mob.RangeSpot * 2)//Mesh haytl3 el wo7osh fi el distance da..
{
if (Map.Npcs.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0 && Map.Entities.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0)
Spawn(mob, coords.Item1, coords.Item2);//Haytl3 el w7osh [b3eed] 3an el distance ale bt7dd..
}
}
}
if (!mob.EmptySpots)
{
if (mob.Xx > 0)
{
for (uint i = 0; i <= mob.Count; i++)
{
coords = Kernel.Maps[mob.MapID].RandomCoordinates(mob.Xx, mob.Yy, mob.RangeSpot);
if (Kernel.GetDistance(coords.Item1, coords.Item2, mob.Xx, mob.Yy) < mob.RangeSpot)//Haytl3 el w7osh [fe] el distance ale bt7dd bas..
{
if (Map.Npcs.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0 && Map.Entities.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0)
Spawn(mob, coords.Item1, coords.Item2);
}
}
}
if (mob.Xx == 0)
{
for (uint i = 0; i <= mob.Count; i++)
{
coords = Map.RandomCoordinates();
if (Map.Npcs.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0 && Map.Entities.Values.Where(n => n.X == coords.Item1 && n.Y == coords.Item2).Count() == 0)
Spawn(mob, coords.Item1, coords.Item2);//Haytl3 el w7osh fe el map kolha
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
public static void ReportError(MonstersInfo Mob, string reson)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(string.Format("UID: {0}, ID: {1}, Name: {2}, Count: {3}, MapID: {4}.." + reson.ToUpper(), Mob.UID, Mob.MonsterID, Mob.Name, Mob.Count, Mob.MapID));
Console.ForegroundColor = ConsoleColor.Red;
}
public static void Spawn(MonstersInfo Mob, ushort X, ushort Y)
{
if (Database.MonsterInformation.MonsterInformations.ContainsKey(Mob.MonsterID))
{
Database.MonsterInformation mt = Database.MonsterInformation.MonsterInformations[Mob.MonsterID];
mt.RespawnTime = Mob.Respawn;
mt.BoundX = X;
mt.BoundY = Y;
mt.BoundCX = X;
mt.BoundCY = Y;
Entity entity = new Entity(EntityFlag.Monster, false);
entity.MapObjType = MapObjectType.Monster;
entity.MonsterInfo = mt.Copy();
entity.MonsterInfo.Owner = entity;
entity.Name = mt.Name;
entity.MinAttack = mt.MinAttack;
entity.MaxAttack = entity.MagicAttack = mt.MaxAttack;
entity.Hitpoints = entity.MaxHitpoints = mt.Hitpoints;
entity.Defence = mt.Defence;
entity.Body = mt.Mesh;
entity.Level = mt.Level;
entity.UID = Map.EntityUIDCounter.Next;
entity.MapID = Map.ID;
entity.SendUpdates = true;
entity.X = X;
entity.Y = Y;
if (Map.Floor[entity.X, entity.Y, MapObjectType.Monster, entity])
{
Map.AddEntity(entity);
}
Map.Timer = Map.MonsterTimers.Add(Map);
foreach (var p in Kernel.GamePool.Values.Where(z => z.Map.ID == Map.ID && z.GetDistance(entity) <= 19))
entity.SendSpawn(p);
}
}
}
}
|
الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1) | |
أدوات الموضوع | |
|
الموضوع | كاتب الموضوع | المنتدى | مشاركات | آخر مشاركة |
اضافت اشكال في القنصل خوش وافهم | ElSaher | تطوير سيرفرات كونكر | 27 | 2024-09-30 08:35 AM |
تعديل علي دروب وحوش عاديه و وحوش كبيره | Tefa | تطوير سيرفرات كونكر | 6 | 2022-04-10 04:14 PM |
مشكله في مابات التوبات | Diego | مشكلات السيرفيرات كونكر الشخصيه | 2 | 2020-04-10 10:00 AM |
حل للمشكله دي يشباب مجناني خش وافهم | uncelsam | مشكلات السيرفيرات كونكر الشخصيه | 5 | 2020-02-25 03:52 PM |
اذاي تخلي في اي بي 6 يجيله ايبك ف جيانج بسهوله | Tefa | تطوير سيرفرات كونكر | 2 | 2019-11-06 12:39 PM |