Thanks!Quote:
Here it is : [Only registered and activated users can see links. Click Here To Register...]
Thanks!Quote:
Here it is : [Only registered and activated users can see links. Click Here To Register...]
public class Monster
{
public uint ID;
public string Name;
public byte Type;
public ushort Lookface;
public uint Life;
public uint AttackMin;
public uint AttackMax;
public uint Defence;
public uint Dexterity;
public uint Dodge;
public ushort AttackRange;
public ushort ViewRange;
public uint EscapeLife;
public uint MoveSpeed;
public ushort Level;
public byte AttackUser;
public uint DropMoney;
public uint DropItemType;
public uint DropHP;
public uint DropMP;
public byte MagicType;
public uint MagicDefence;
public uint MagicHitRate;
public byte AIType;
public uint Defence2;
public uint ExtraExp;
}
public static void LoadMobs()
{
foreach (string file in Directory.GetFiles(DatabasePath + "\\cq_monstertype\\"))
{
IniFile cq_mob = new IniFile(file);
Monster mob = new Monster();
mob.ID = cq_mob.ReadUInt32("cq_monstertype", "id", 0);
mob.Name = cq_mob.ReadString("cq_monstertype", "name", "");
mob.Type = cq_mob.ReadByte("cq_monstertype", "type", 0);
mob.Lookface = cq_mob.ReadUInt16("cq_monstertype", "lookface", 0);
mob.Life = cq_mob.ReadUInt32("cq_monstertype", "life", 0);
mob.AttackMax = cq_mob.ReadUInt32("cq_monstertype", "attack_max", 0);
mob.AttackMin = cq_mob.ReadUInt32("cq_monstertype", "attack_min", 0);
mob.Defence = cq_mob.ReadUInt32("cq_monstertype", "defence", 0);
mob.Dexterity = cq_mob.ReadUInt32("cq_monstertype", "dexterity", 0);
mob.Dodge = cq_mob.ReadUInt32("cq_monstertype", "dodge", 0);
mob.AttackRange = cq_mob.ReadUInt16("cq_monstertype", "attack_range", 0);
mob.ViewRange = cq_mob.ReadUInt16("cq_monstertype", "view_range", 0);
mob.EscapeLife = cq_mob.ReadUInt32("cq_monstertype", "escape_life", 0);
mob.Level = cq_mob.ReadUInt16("cq_monstertype", "level", 0);
mob.AttackUser = cq_mob.ReadByte("cq_monstertype", "attack_user", 0);
mob.DropMoney = cq_mob.ReadUInt32("cq_monstertype", "drop_money", 0);
mob.DropItemType = cq_mob.ReadUInt32("cq_monstertype", "drop_itemtype", 0);
mob.DropHP = cq_mob.ReadUInt32("cq_monstertype", "drop_hp", 0);
mob.DropMP = cq_mob.ReadUInt32("cq_monstertype", "drop_mp", 0);
mob.MagicType = cq_mob.ReadByte("cq_monstertype", "magic_type", 0);
mob.MagicHitRate = cq_mob.ReadUInt32("cq_monstertype", "magic_hitrate", 0);
mob.MagicDefence = cq_mob.ReadUInt32("cq_monstertype", "magic_def", 0);
mob.AIType = cq_mob.ReadByte("cq_monstertype", "ai_type", 0);
mob.Defence2 = cq_mob.ReadUInt32("cq_monstertype", "defence2", 0);
mob.ExtraExp = cq_mob.ReadUInt32("cq_monstertype", "extra_exp", 0);
Kernel.Mobs.Add(mob.ID, mob);
}
Console.WriteLine("Monsters Loaded [{0}]", Kernel.Mobs.Count);
}
public class MobSpawn
{
public uint SpawnID;
public ushort MapID;
public ushort X;
public ushort Y;
public ushort Xc;
public ushort Yc;
public uint MaxMobs;
public ushort RestSecs;
public uint SpawnAmount;
public uint MobID;
}
public static void LoadMobSpawns()
{
foreach (string file in Directory.GetFiles(DatabasePath + "\\cq_generator\\"))
{
IniFile cq_gen = new IniFile(file);
MobSpawn spawn = new MobSpawn();
spawn.SpawnID = cq_gen.ReadUInt32("cq_generator", "id", 0);
spawn.MapID = cq_gen.ReadUInt16("cq_generator", "mapid", 0);
spawn.X = cq_gen.ReadUInt16("cq_generator", "bound_x", 0);
spawn.Y = cq_gen.ReadUInt16("cq_generator", "bound_y", 0);
spawn.Xc = cq_gen.ReadUInt16("cq_generator", "bound_cx", 0);
spawn.Yc = cq_gen.ReadUInt16("cq_generator", "bould_cy", 0);
spawn.MaxMobs = cq_gen.ReadUInt32("cq_generator", "maxnpc", 0);
spawn.RestSecs = cq_gen.ReadUInt16("cq_generator", "rest_secs", 0);
spawn.SpawnAmount = cq_gen.ReadUInt32("cq_generator", "max_per_gen", 0);
spawn.MobID = cq_gen.ReadUInt32("cq_generator", "npctype", 0);
Kernel.MobSpawns.Add(spawn.SpawnID, spawn);
}
Console.WriteLine("Monster Spawns Loaded [{0}]", Kernel.MobSpawns.Count);
}
public static void SpawnMobs()
{
foreach (MobSpawn spawn in Kernel.MobSpawns.Values)
{
Monster ThisMob = new Monster();
foreach (Monster mob in Kernel.Mobs.Values)
{
if (mob.ID == spawn.MobID)
{
ThisMob = mob;
break;
}
}
for (uint i = 0; i < spawn.SpawnAmount; i++)
{
Entity newMob = new Entity(EntityFlag.Monster, null);
newMob.Action = ConquerAction.None;
newMob.Dead = false;
newMob.Defence = (ushort)ThisMob.Defence;
newMob.Dodge = (sbyte)ThisMob.Dodge;
newMob.Facing = (ConquerAngle)Global.Random.Next(0, 9);
newMob.Hitpoints = ThisMob.Life;
newMob.MaxHitpoints = ThisMob.Life;
newMob.Level = (byte)ThisMob.Level;
newMob.MagicAttack = ThisMob.AttackMin;
newMob.MaxAttack = ThisMob.AttackMax;
newMob.MinAttack = ThisMob.AttackMin;
newMob.MDefence = (ushort)ThisMob.MagicDefence;
newMob.Model = ThisMob.Lookface;
newMob.Name = ThisMob.Name;
newMob.UID = (uint)Global.Random.Next(400000, 500000);
while (Kernel.eMonsters.ContainsKey(newMob.UID))
newMob.UID = (uint)Global.Random.Next(400000, 500000);
newMob.MapID = spawn.MapID;
newMob.X = (ushort)Global.Random.Next(
Math.Min(spawn.X, spawn.Xc),
Math.Max(spawn.X, spawn.Xc));
newMob.Y = (ushort)Global.Random.Next(
Math.Min(spawn.Y, spawn.Yc),
Math.Max(spawn.Y, spawn.Yc));
Kernel.eMonsters.Add(newMob.UID, newMob);
}
}
Console.WriteLine("Monsters Spawned [{0}]", Kernel.eMonsters.Count);
}
public static Dictionary<uint, Entity> eMonsters = new Dictionary<uint, Entity>();
public static Dictionary<uint, Monster> Mobs = new Dictionary<uint, Monster>();
public static Dictionary<uint, MobSpawn> MobSpawns = new Dictionary<uint, MobSpawn>();
foreach (Entity mob in Kernel.eMonsters.Values)
{
if (mob.MapID == Client.Entity.MapID)
if (Kernel.GetDistance(mob.X, mob.Y, Client.Entity.X, Client.Entity.Y) <= 24)
{
if (!mob.Dead)
mob.SendSpawn(Client);
}
}
Above i've written where I have put the codes :PQuote:
Hopefully more people will start working on this source base, and actually learn stuff.
Here's Monster Loading/Spawning.
Monster Class: <-- i've made a new .cs called Monster.cs and put this in it.
Monster Loading: <--- i've put this in Database.csCode:public class Monster { public uint ID; public string Name; public byte Type; public ushort Lookface; public uint Life; public uint AttackMin; public uint AttackMax; public uint Defence; public uint Dexterity; public uint Dodge; public ushort AttackRange; public ushort ViewRange; public uint EscapeLife; public uint MoveSpeed; public ushort Level; public byte AttackUser; public uint DropMoney; public uint DropItemType; public uint DropHP; public uint DropMP; public byte MagicType; public uint MagicDefence; public uint MagicHitRate; public byte AIType; public uint Defence2; public uint ExtraExp; }
Spawn Class: <--- i've put this in Monster.csCode:public static void LoadMobs() { foreach (string file in Directory.GetFiles(DatabasePath + "\\cq_monstertype\\")) { IniFile cq_mob = new IniFile(file); Monster mob = new Monster(); mob.ID = cq_mob.ReadUInt32("cq_monstertype", "id", 0); mob.Name = cq_mob.ReadString("cq_monstertype", "name", ""); mob.Type = cq_mob.ReadByte("cq_monstertype", "type", 0); mob.Lookface = cq_mob.ReadUInt16("cq_monstertype", "lookface", 0); mob.Life = cq_mob.ReadUInt32("cq_monstertype", "life", 0); mob.AttackMax = cq_mob.ReadUInt32("cq_monstertype", "attack_max", 0); mob.AttackMin = cq_mob.ReadUInt32("cq_monstertype", "attack_min", 0); mob.Defence = cq_mob.ReadUInt32("cq_monstertype", "defence", 0); mob.Dexterity = cq_mob.ReadUInt32("cq_monstertype", "dexterity", 0); mob.Dodge = cq_mob.ReadUInt32("cq_monstertype", "dodge", 0); mob.AttackRange = cq_mob.ReadUInt16("cq_monstertype", "attack_range", 0); mob.ViewRange = cq_mob.ReadUInt16("cq_monstertype", "view_range", 0); mob.EscapeLife = cq_mob.ReadUInt32("cq_monstertype", "escape_life", 0); mob.Level = cq_mob.ReadUInt16("cq_monstertype", "level", 0); mob.AttackUser = cq_mob.ReadByte("cq_monstertype", "attack_user", 0); mob.DropMoney = cq_mob.ReadUInt32("cq_monstertype", "drop_money", 0); mob.DropItemType = cq_mob.ReadUInt32("cq_monstertype", "drop_itemtype", 0); mob.DropHP = cq_mob.ReadUInt32("cq_monstertype", "drop_hp", 0); mob.DropMP = cq_mob.ReadUInt32("cq_monstertype", "drop_mp", 0); mob.MagicType = cq_mob.ReadByte("cq_monstertype", "magic_type", 0); mob.MagicHitRate = cq_mob.ReadUInt32("cq_monstertype", "magic_hitrate", 0); mob.MagicDefence = cq_mob.ReadUInt32("cq_monstertype", "magic_def", 0); mob.AIType = cq_mob.ReadByte("cq_monstertype", "ai_type", 0); mob.Defence2 = cq_mob.ReadUInt32("cq_monstertype", "defence2", 0); mob.ExtraExp = cq_mob.ReadUInt32("cq_monstertype", "extra_exp", 0); Kernel.Mobs.Add(mob.ID, mob); } Console.WriteLine("Monsters Loaded [{0}]", Kernel.Mobs.Count); }
Monster Spawn Loading: <---- i've put this in Database.csCode:public class MobSpawn { public uint SpawnID; public ushort MapID; public ushort X; public ushort Y; public ushort Xc; public ushort Yc; public uint MaxMobs; public ushort RestSecs; public uint SpawnAmount; public uint MobID; }
I've put this in Database.cs :Code:public static void LoadMobSpawns() { foreach (string file in Directory.GetFiles(DatabasePath + "\\cq_generator\\")) { IniFile cq_gen = new IniFile(file); MobSpawn spawn = new MobSpawn(); spawn.SpawnID = cq_gen.ReadUInt32("cq_generator", "id", 0); spawn.MapID = cq_gen.ReadUInt16("cq_generator", "mapid", 0); spawn.X = cq_gen.ReadUInt16("cq_generator", "bound_x", 0); spawn.Y = cq_gen.ReadUInt16("cq_generator", "bound_y", 0); spawn.Xc = cq_gen.ReadUInt16("cq_generator", "bound_cx", 0); spawn.Yc = cq_gen.ReadUInt16("cq_generator", "bould_cy", 0); spawn.MaxMobs = cq_gen.ReadUInt32("cq_generator", "maxnpc", 0); spawn.RestSecs = cq_gen.ReadUInt16("cq_generator", "rest_secs", 0); spawn.SpawnAmount = cq_gen.ReadUInt32("cq_generator", "max_per_gen", 0); spawn.MobID = cq_gen.ReadUInt32("cq_generator", "npctype", 0); Kernel.MobSpawns.Add(spawn.SpawnID, spawn); } Console.WriteLine("Monster Spawns Loaded [{0}]", Kernel.MobSpawns.Count); }
Dictionaries: <--- i've put these in Kernel.csCode:public static void SpawnMobs() { foreach (MobSpawn spawn in Kernel.MobSpawns.Values) { Monster ThisMob = new Monster(); foreach (Monster mob in Kernel.Mobs.Values) { if (mob.ID == spawn.MobID) { ThisMob = mob; break; } } for (uint i = 0; i < spawn.SpawnAmount; i++) { Entity newMob = new Entity(EntityFlag.Monster, null); newMob.Action = ConquerAction.None; newMob.Dead = false; newMob.Defence = (ushort)ThisMob.Defence; newMob.Dodge = (sbyte)ThisMob.Dodge; newMob.Facing = (ConquerAngle)Global.Random.Next(0, 9); newMob.Hitpoints = ThisMob.Life; newMob.MaxHitpoints = ThisMob.Life; newMob.Level = (byte)ThisMob.Level; newMob.MagicAttack = ThisMob.AttackMin; newMob.MaxAttack = ThisMob.AttackMax; newMob.MinAttack = ThisMob.AttackMin; newMob.MDefence = (ushort)ThisMob.MagicDefence; newMob.Model = ThisMob.Lookface; newMob.Name = ThisMob.Name; newMob.UID = (uint)Global.Random.Next(400000, 500000); while (Kernel.eMonsters.ContainsKey(newMob.UID)) newMob.UID = (uint)Global.Random.Next(400000, 500000); newMob.MapID = spawn.MapID; newMob.X = (ushort)Global.Random.Next( Math.Min(spawn.X, spawn.Xc), Math.Max(spawn.X, spawn.Xc)); newMob.Y = (ushort)Global.Random.Next( Math.Min(spawn.Y, spawn.Yc), Math.Max(spawn.Y, spawn.Yc)); Kernel.eMonsters.Add(newMob.UID, newMob); } } Console.WriteLine("Monsters Spawned [{0}]", Kernel.eMonsters.Count); }
Screen: <--- i've put this in the constructor of Screen.csCode:public static Dictionary<uint, Entity> eMonsters = new Dictionary<uint, Entity>(); public static Dictionary<uint, Monster> Mobs = new Dictionary<uint, Monster>(); public static Dictionary<uint, MobSpawn> MobSpawns = new Dictionary<uint, MobSpawn>();
This is just a "alpha" code I guess you could say, it's prolly not the greatest, but it works.Code:foreach (Entity mob in Kernel.eMonsters.Values) { if (mob.MapID == Client.Entity.MapID) if (Kernel.GetDistance(mob.X, mob.Y, Client.Entity.X, Client.Entity.Y) <= 24) { if (!mob.Dead) mob.SendSpawn(Client); } }
I'm still working on lots more with monsters =P
public static void SpawnMobs()
{
Monster ThisMob = new Monster(); //<--- Changed
foreach (MobSpawn spawn in Kernel.MobSpawns.Values)
{
foreach (Monster mob in Kernel.Mobs.Values)
{
if (mob.ID == spawn.MobID)
{
ThisMob = mob;
break;
}
}
for (uint i = 0; i < spawn.SpawnAmount; i++)
{
Random Global = new Random(); //<--- Changed
Entity newMob = new Entity(EntityFlag.Monster, null);
newMob.Action = ConquerAction.None;
newMob.Dead = false;
newMob.Defence = (ushort)ThisMob.Defence;
newMob.Dodge = (sbyte)ThisMob.Dodge;
newMob.Facing = (ConquerAngle)Global.Next(0, 9);
newMob.Hitpoints = (int)ThisMob.Life; //<--- Changed
newMob.MaxHitpoints = (int)ThisMob.Life; //<--- Changed
newMob.Level = (byte)ThisMob.Level;
newMob.MagicAttack = ThisMob.AttackMin;
newMob.MaxAttack = ThisMob.AttackMax;
newMob.MinAttack = ThisMob.AttackMin;
newMob.MDefence = (ushort)ThisMob.MagicDefence;
newMob.Model = ThisMob.Lookface;
newMob.Name = ThisMob.Name;
newMob.UID = (uint)Global.Next(400000, 500000);
while (Kernel.eMonsters.ContainsKey(newMob.UID))
newMob.UID = (uint)Global.Next(400000, 500000);
newMob.MapID = spawn.MapID;
newMob.X = (ushort)Global.Next(
Math.Min(spawn.X, spawn.Xc),
Math.Max(spawn.X, spawn.Xc));
newMob.Y = (ushort)Global.Next(
Math.Min(spawn.Y, spawn.Yc),
Math.Max(spawn.Y, spawn.Yc));
Kernel.eMonsters.Add(newMob.UID, newMob);
}
}
Console.WriteLine("Monsters Spawned [{0}]", Kernel.eMonsters.Count);
}
Database.LoadMobs(); Database.LoadMobSpawns();
I've done it and its same as what I did in last line in LoadDatabase()Quote:
Try adding
below Database.LoadDatabase in Progam.csCode:Database.LoadMobs(); Database.LoadMobSpawns();
foreach (Entity mob in Kernel.eMonsters.Values)
{
if (mob.MapID == Client.Entity.MapID)
if (Kernel.GetDistance(mob.X, mob.Y, Client.Entity.X, Client.Entity.Y) <= 24)
{
if (!mob.Dead)
mob.SendSpawn(Client);
}
}
public static void SpawnMobs()
Hey Kinshi I got a question :PQuote:
I've got all the mobs to spawn =P
foreach (Entity mob in Kernel.eMonsters.Values)
{
if (mob.MapID == Client.Entity.MapID)
if (Kernel.GetDistance(mob.X, mob.Y, Client.Entity.X, Client.Entity.Y) <= 24)
{
if (!mob.Dead)
mob.SendSpawn(Client);
}
}
Dictionary<uint, INpc> Npcs;
if (Kernel.Npcs.TryGetValue(Client.Entity.MapID, out Npcs))
{
foreach (Entity mob in Kernel.eMonsters.Values)
{
if (mob.MapID == Client.Entity.MapID)
if (Kernel.GetDistance(mob.X, mob.Y, Client.Entity.X, Client.Entity.Y) <= 24)
{
if (!mob.Dead)
mob.SendSpawn(Client);
}
}
foreach (KeyValuePair<uint, INpc> DE in Npcs)
{
INpc npc = DE.Value;
if (Kernel.GetDistance(npc.X, npc.Y, Client.Entity.X, Client.Entity.Y) <= 16)
{
npc.SendSpawn(Client);
}
}
}
m_Screen = new IMapObject[ScreenDictionary.Count];
ScreenDictionary.Values.CopyTo(m_Screen, 0);
}
}
public void Reload(bool Clear, ConquerCallback Callback)
{
lock (ScreenDictionary)
{
if (Clear)
ScreenDictionary.Clear();
else
Cleanup();
foreach (GameClient pClient in Kernel.Clients)
{
if (pClient.Identifier != Client.Identifier)
{
if (pClient.Entity.MapID == Client.Entity.MapID)
{
if (Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, Client.Entity.X, Client.Entity.Y) <= 16)
{
pClient.Entity.SendSpawn(Client);
if (pClient.MyGuild != null)
{
Guild.SendGuildName(Client, pClient.MyGuild);
Guild.SendGuildInfo(pClient, Client, pClient.MyGuild);
Guild.SendGuildInfo(pClient, pClient.MyGuild);
}
if (Callback != null)
Callback.Invoke(Client.Entity, pClient.Entity);
}
}
}
}
foreach (Entity mob in Kernel.eMonsters.Values)
{
if (mob.MapID == Client.Entity.MapID)
if (Kernel.GetDistance(mob.X, mob.Y, Client.Entity.X, Client.Entity.Y) <= 24)
{
if (!mob.Dead)
mob.SendSpawn(Client);
}
}
Dictionary<uint, INpc> Npcs;
if (Kernel.Npcs.TryGetValue(Client.Entity.MapID, out Npcs))
{
foreach (KeyValuePair<uint, INpc> DE in Npcs)
{
INpc npc = DE.Value;
if (Kernel.GetDistance(npc.X, npc.Y, Client.Entity.X, Client.Entity.Y) <= 16)
npc.SendSpawn(Client);
}
}
m_Screen = new IMapObject[ScreenDictionary.Count];
ScreenDictionary.Values.CopyTo(m_Screen, 0);
}
}