Which can be found
.Database
Source: (The files that does not exist, create them!)
ProjectX_V3_Game\SobDatabase.cs
Code:
//Project by BaussHacker aka. L33TS
using System;
using ProjectX_V3_Lib.Sql;
namespace ProjectX_V3_Game.Database
{
/// <summary>
/// Description of SobDatabase.
/// </summary>
public class SobDatabase
{
public static bool LoadSobs(bool display = true)
{
Console.ForegroundColor = ConsoleColor.Yellow;
if (display)
Console.WriteLine("\tLoading Sobs...");
using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
{
using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
{
cmd.Finish("DB_Sobs");
}
while (sql.Read())
{
uint ID = sql.ReadUInt32("SobID");
Entities.NPC associatedNPC = null;
if (Core.Kernel.NPCs.ContainsKey(ID))
associatedNPC = Core.Kernel.NPCs[ID];
Entities.Sob sob = new ProjectX_V3_Game.Entities.Sob(associatedNPC);
sob.EntityUID = ID;
sob.Name = sql.ReadString("SobName");
sob.MaxHP = sql.ReadInt32("SobHP");
sob.HP = sob.MaxHP;
sob.OriginalName = sql.ReadString("SobOriginalName");
sob.Mesh = sql.ReadUInt16("SobMesh");
sob.SecondaryMesh = sql.ReadUInt16("SobSecondaryMesh");
sob.ShowMesh = sob.Mesh;
sob.Flag = sql.ReadUInt16("SobFlag");
sob.SobType = sql.ReadUInt32("SobType");
ushort mapid = sql.ReadUInt16("SobMap");
sob.X = sql.ReadUInt16("SobX");
sob.Y = sql.ReadUInt16("SobY");
if (mapid == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed to load sobs. [MAPID]");
Console.ResetColor();
return false;
}
Maps.Map map;
Core.Kernel.Maps.TrySelect(mapid, out map);
sob.Map = map;
if (!sob.Map.EnterMap(sob))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed to load sobs. [MAP]");
Console.ResetColor();
return false;
}
if (!Core.Kernel.Sobs.TryAdd(sob.EntityUID, sob))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed to load npcs. [ADD]");
Console.ResetColor();
return false;
}
}
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\tLoaded {0} Sobs...", Core.Kernel.Sobs.Count);
return true;
}
}
}
Code:
//Project by BaussHacker aka. L33TS
using System;
using System.Linq;
using ProjectX_V3_Lib.Sql;
namespace ProjectX_V3_Game.Tournaments
{
/// <summary>
/// The handler for guild wars.
/// </summary>
public class GuildWars : Data.BattleClass
{
private Maps.Map Map;
private Entities.Sob GuildPole;
private Entities.Sob LeftGate;
private Entities.Sob RightGate;
private byte Round = 0;
public Data.Guild WinnerGuild;
public DateTime LastGuildWars;
public bool LeftGateOpen
{
get { return LeftGate.ShowMesh == LeftGate.SecondaryMesh; }
set { LeftGate.ShowMesh = (value) ? LeftGate.SecondaryMesh : LeftGate.Mesh; }
}
public bool RightGateOpen
{
get { return RightGate.ShowMesh == RightGate.SecondaryMesh; }
set { RightGate.ShowMesh = (value) ? RightGate.SecondaryMesh : RightGate.Mesh; }
}
private static GuildWars _gw;
public static GuildWars GW
{
get { return _gw; }
}
static GuildWars()
{
_gw = new GuildWars();
}
public GuildWars()
: base()
{
Map = Core.Kernel.Maps[1038];
GuildPole = Core.Kernel.Sobs[6700];
LeftGate = Core.Kernel.Sobs[6701];
RightGate = Core.Kernel.Sobs[6702];
string winner = Core.SystemVariables.Variables["GuildWarsWinner"];
string last = Core.SystemVariables.Variables["LastGuildWars"];
if (!string.IsNullOrWhiteSpace(winner))
{
Core.Kernel.Guilds.TrySelect(winner, out WinnerGuild);
}
if (!string.IsNullOrWhiteSpace(last))
{
DateTime gwTime;
if (!DateTime.TryParse(last, out gwTime))
gwTime = DateTime.Now;
LastGuildWars = gwTime;
}
}
public static void Handle()
{
if (DateTime.Now.Hour == 03)
{
if (GW.Start())
System.Threading.Thread.Sleep((60000) * 60);
}
}
public bool Start()
{
if (!GW.IsOn)
{
if (DateTime.Now >= LastGuildWars.AddHours(1) || WinnerGuild == null)
{
GW.Round = 0;
GW.IsOn = true;
using (var msg = Packets.Message.MessageCore.CreateCenter(Core.MessageConst.GW_START))
{
Packets.Message.MessageCore.SendGlobalMessage(msg);
}
return true;
}
}
return false;
}
public bool IsOn = false;
public Data.Guild[] GetTop5()
{
if (Core.Kernel.Guilds.Count == 0)
return new Data.Guild[0];
System.Collections.Generic.KeyValuePair<uint, Data.Guild>[]
OrderGuilds = Core.Kernel.Guilds.selectorCollection1.OrderBy(guild => guild.Value.GWDamage).ToArray();
Array.Reverse(OrderGuilds);
int len = Math.Min(5, OrderGuilds.Length);
Data.Guild[] guilds = new ProjectX_V3_Game.Data.Guild[len];
for (int i = 0; i < len; i++)
{
guilds[i] = OrderGuilds[i].Value;
}
return guilds;
}
public Data.Guild GetWinner()
{
Data.Guild[] TopGuilds = GetTop5();
if (TopGuilds.Length == 0)
return null;
return TopGuilds[0];
}
public void UpdateBroadcast()
{
Data.Guild[] TopGuilds = GetTop5();
if (TopGuilds.Length == 0)
return;
string[] Messages = new string[TopGuilds.Length];
int scorecount = 1;
for (int i = 0; i< TopGuilds.Length; i++)
{
if (TopGuilds[i].GWDamage > 0)
{
Messages[i] = string.Format(Core.MessageConst.GW_SCORE, scorecount, TopGuilds[i].Name, TopGuilds[i].GWDamage);
scorecount++;
}
else
Messages[i] = "";
}
//string GuildPoleHP = string.Format("Pole: {0}/{1}",
foreach (Maps.IMapObject mapObject in Map.MapObjects.Values)
{
if (mapObject is Entities.GameClient)
{
Entities.GameClient client = mapObject as Entities.GameClient;
#region Clear
using (var msg = Packets.Message.MessageCore.ClearScore())
{
client.Send(msg);
}
#endregion
#region Score
for (int i = 0; i< Messages.Length; i++)
{
if (string.IsNullOrWhiteSpace(Messages[i]))
break;
using (var msg = Packets.Message.MessageCore.CreateScore(Messages[i]))
{
client.Send(msg);
}
}
#endregion
}
}
}
public override bool HandleAttack(ProjectX_V3_Game.Entities.GameClient Attacker, ProjectX_V3_Game.Entities.GameClient Attacked, ref uint damage)
{
return true;
}
public override bool HandleBeginAttack(ProjectX_V3_Game.Entities.GameClient Attacker)
{
return true;
}
public override bool HandleBeginHit_Magic(ProjectX_V3_Game.Entities.GameClient Attacker, ProjectX_V3_Game.Packets.UseSpellPacket usespell)
{
return true;
}
public override bool HandleBeginHit_Physical(ProjectX_V3_Game.Entities.GameClient Attacker)
{
return true;
}
public override bool HandleBeginHit_Ranged(ProjectX_V3_Game.Entities.GameClient Attacker)
{
return true;
}
public override bool HandleDeath(ProjectX_V3_Game.Entities.GameClient Attacker, ProjectX_V3_Game.Entities.GameClient Attacked)
{
return true;
}
public override bool HandleRevive(ProjectX_V3_Game.Entities.GameClient Killed)
{
if (Killed.LastMapID == Map.MapID)
Killed.Teleport(1002, 400, 400);
else
Killed.Teleport(Killed.LastMapID, Killed.LastMapX, Killed.LastMapY);
return false;
}
public override void KillMob(ProjectX_V3_Game.Entities.GameClient Attacker, uint MobUID)
{
}
public override bool LeaveArea(ProjectX_V3_Game.Entities.GameClient client)
{
return true;
}
public override bool EnterArea(ProjectX_V3_Game.Entities.GameClient client)
{
if (LeftGateOpen || RightGateOpen)
return true;
if (client.Guild != null)
{
if (client.Guild.Name == GuildPole.Name)
return true;
}
if (client.X <= LeftGate.X && client.Y <= LeftGate.Y)
{
client.Teleport(client.Map.MapID, (ushort)(LeftGate.X + 1), (ushort)(LeftGate.Y + 1));
client.LastX = (ushort)(LeftGate.X + 1);
client.LastY = (ushort)(LeftGate.Y + 1);
return false;
}
else if (client.X <= RightGate.X && client.Y <= RightGate.Y)
{
client.Teleport(client.Map.MapID, (ushort)(RightGate.X + 1), (ushort)(RightGate.Y + 1));
client.LastX = (ushort)(RightGate.X + 1);
client.LastY = (ushort)(RightGate.Y + 1);
return false;
}
return true;
}
public override void ChangeMap(ProjectX_V3_Game.Entities.GameClient client)
{
if (client.Map.MapID == Map.MapID)
{
client.Battle = this;
UpdateBroadcast();
}
else if (client.LastMapID == Map.MapID)
{
if (client.Battle is GuildWars)
client.Battle = null;
#region Clear
using (var msg = Packets.Message.MessageCore.ClearScore())
{
client.Send(msg);
}
#endregion
}
}
public void Handle_GuildPole(Entities.Sob sob, Entities.IEntity attacker, int damage)
{
if (!IsOn)
return;
if (!(attacker is Entities.GameClient))
return;
Entities.GameClient attackerClient = (attacker as Entities.GameClient);
if (attackerClient.Guild == null)
return;
if (attackerClient.Guild.Name == GuildPole.Name)
return;
attackerClient.Guild.GWDamage += damage;
sob.HP -= damage;
UpdateBroadcast();
if (sob.HP < 0)
{
Data.Guild Winner = GetWinner();
if (Winner != null)
{
#region clear score
foreach (Maps.IMapObject mapObject in Map.MapObjects.Values)
{
if (mapObject is Entities.GameClient)
{
Entities.GameClient client = mapObject as Entities.GameClient;
#region Clear
using (var msg = Packets.Message.MessageCore.ClearScore())
{
client.Send(msg);
}
#endregion
}
}
#endregion
Round++;
if (Round >= 3)
{
GuildPole.HP = GuildPole.MaxHP;
GuildPole.Name = Winner.Name;
GuildPole.Screen.FullUpdate();
SaveWinner(Winner.Name);
WinnerGuild = Winner;
LeftGateOpen = false;
LeftGate.HP = GuildPole.MaxHP;
LeftGate.Screen.FullUpdate();
RightGateOpen = false;
RightGate.HP = GuildPole.MaxHP;
RightGate.Screen.FullUpdate();
foreach (Data.Guild guild in Core.Kernel.Guilds.selectorCollection1.Values)
guild.GWDamage = 0;
IsOn = false;
foreach (Maps.IMapObject mapObject in Map.MapObjects.Values)
{
if (mapObject is Entities.GameClient)
{
Entities.GameClient client = mapObject as Entities.GameClient;
if (client.Guild.Name == GuildPole.Name)
continue;
if (client.LastMapID == Map.MapID)
client.Teleport(1002, 400, 400);
else
client.Teleport(client.LastMapID, client.LastMapX, client.LastMapY);
}
}
using (var msg = Packets.Message.MessageCore.CreateCenter(
string.Format(Core.MessageConst.GW_WIN_FINAL, Winner.Name)))
{
Packets.Message.MessageCore.SendGlobalMessage(msg);
}
}
else
{
GuildPole.HP = GuildPole.MaxHP;
GuildPole.Name = Winner.Name;
GuildPole.Screen.FullUpdate();
LeftGateOpen = false;
LeftGate.HP = GuildPole.MaxHP;
LeftGate.Screen.FullUpdate();
RightGateOpen = false;
RightGate.HP = GuildPole.MaxHP;
RightGate.Screen.FullUpdate();
foreach (Data.Guild guild in Core.Kernel.Guilds.selectorCollection1.Values)
guild.GWDamage = 0;
foreach (Maps.IMapObject mapObject in Map.MapObjects.Values)
{
if (mapObject is Entities.GameClient)
{
Entities.GameClient client = mapObject as Entities.GameClient;
if (client.Guild.Name == GuildPole.Name)
continue;
if (client.LastMapID == Map.MapID)
client.Teleport(1002, 400, 400);
else
client.Teleport(client.LastMapID, client.LastMapX, client.LastMapY);
}
}
using (var msg = Packets.Message.MessageCore.CreateCenter(
string.Format(Core.MessageConst.GW_WIN, Winner.Name)))
{
Packets.Message.MessageCore.SendGlobalMessage(msg);
}
}
}
}
}
public void Handle_LeftGate(Entities.Sob sob, Entities.IEntity attacker, int damage)
{
if (!IsOn)
return;
if (!(attacker is Entities.GameClient))
return;
if (LeftGateOpen)
return;
Entities.GameClient attackerClient = (attacker as Entities.GameClient);
sob.HP -= damage;
if (sob.HP < 0)
{
LeftGateOpen = true;
sob.Screen.FullUpdate();
}
}
public void Handle_RightGate(Entities.Sob sob, Entities.IEntity attacker, int damage)
{
if (!IsOn)
return;
if (!(attacker is Entities.GameClient))
return;
if (RightGateOpen)
return;
Entities.GameClient attackerClient = (attacker as Entities.GameClient);
sob.HP -= damage;
if (sob.HP < 0)
{
RightGateOpen = true;
sob.Screen.FullUpdate();
}
}
private void SaveWinner(string Name = "")
{
LastGuildWars = DateTime.Now;
using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
{
using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
{
cmd.AddWhereValue("SystemVariableName", "GuildWarsWinner");
cmd.AddUpdateValue("SystemVariableValue", Name);
cmd.Finish("DB_SystemVariables");
}
sql.Execute();
}
using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
{
using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
{
cmd.AddWhereValue("SystemVariableName", "LastGuildWars");
cmd.AddUpdateValue("SystemVariableValue", LastGuildWars.ToString());
cmd.Finish("DB_SystemVariables");
}
sql.Execute();
}
}
}
}
Code:
#region GuildWars
public const string GW_SCORE = "[{0}] {1}: {2}";
public const string GW_WIN = "The winner of this round of GuildWars is {0}!";
public const string GW_WIN_FINAL = "The final winner of GuildWars is {0}!";
public const string GW_START = "GuildWars has started!";
#endregion
Code:
//Project by BaussHacker aka. L33TS
using System;
namespace ProjectX_V3_Game.Packets.Interaction.Battle
{
/// <summary>
/// Description of SobCombat.
/// </summary>
public class SobCombat
{
const uint GuildPole = 6700;
const uint LeftGate = 6701;
const uint RightGate = 6702;
public static void Handle(Entities.Sob sob, Entities.IEntity attacker, int damage)
{
switch (sob.EntityUID)
{
#region GuildPole
case GuildPole:
Tournaments.GuildWars.GW.Handle_GuildPole(sob, attacker, damage);
break;
#endregion
#region LeftGate
case LeftGate:
Tournaments.GuildWars.GW.Handle_LeftGate(sob, attacker, damage);
break;
#endregion
#region RightGate
case RightGate:
Tournaments.GuildWars.GW.Handle_RightGate(sob, attacker, damage);
break;
#endregion
}
}
}
}
Code:
//Project by BaussHacker aka. L33TS
using System;
namespace ProjectX_V3_Game.Packets.Interaction.Battle
{
/// <summary>
/// Subtypes: ?
/// </summary>
public class Combat
{
/// <summary>
/// Handling the combat of the interact packet.
/// </summary>
/// <param name="client">The client.</param>
/// <param name="interact">The interact packet.</param>
public static void Handle(Entities.GameClient client, InteractionPacket interact)
{
if (interact == null)
return;
if (!client.Alive)
return;
if (client.Paralyzed)
return;
if (!client.CanAttack)
return;
if (!(DateTime.Now >= client.LoginProtection.AddSeconds(10)))
{
using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
client.Send(fmsg);
return;
}
if (!(DateTime.Now >= client.ReviveProtection.AddSeconds(5)))
{
using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
client.Send(fmsg);
return;
}
if (!(DateTime.Now >= client.LastAttack.AddMilliseconds(Core.TimeIntervals.AttackInterval)) && client.AttackPacket == null)
{
using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
client.Send(fmsg);
return;
}
if (client.Battle != null)
{
if (!client.Battle.HandleBeginAttack(client))
{
using (var fmsg = Packets.Message.MessageCore.CreateSystem2(client.Name, Core.MessageConst.REST))
client.Send(fmsg);
return;
}
}
client.LastAttack = DateTime.Now;
//client.AutoAttacking = false;
switch (interact.Action)
{
case Enums.InteractAction.MagicAttack:
{
#region TemporaryDecryption
if (!interact.UnPacked)
{
interact.UnPacked = true;
byte[] packet = interact.Copy();
ushort SkillId = Convert.ToUInt16(((long)packet[24] & 0xFF) | (((long)packet[25] & 0xFF) << 8));
SkillId ^= (ushort)0x915d;
SkillId ^= (ushort)client.EntityUID;
SkillId = (ushort)(SkillId << 0x3 | SkillId >> 0xd);
SkillId -= 0xeb42;
uint Target = ((uint)packet[12] & 0xFF) | (((uint)packet[13] & 0xFF) << 8) | (((uint)packet[14] & 0xFF) << 16) | (((uint)packet[15] & 0xFF) << 24);
Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ client.EntityUID) - 0x746F4AE6;
ushort TargetX = 0;
ushort TargetY = 0;
long xx = (packet[16] & 0xFF) | ((packet[17] & 0xFF) << 8);
long yy = (packet[18] & 0xFF) | ((packet[19] & 0xFF) << 8);
xx = xx ^ (client.EntityUID & 0xffff) ^ 0x2ed6;
xx = ((xx << 1) | ((xx & 0x8000) >> 15)) & 0xffff;
xx |= 0xffff0000;
xx -= 0xffff22ee;
yy = yy ^ (client.EntityUID & 0xffff) ^ 0xb99b;
yy = ((yy << 5) | ((yy & 0xF800) >> 11)) & 0xffff;
yy |= 0xffff0000;
yy -= 0xffff8922;
TargetX = Convert.ToUInt16(xx);
TargetY = Convert.ToUInt16(yy);
interact.TargetUID = Target;
interact.MagicType = SkillId;
interact.X = TargetX;
interact.Y = TargetY;
}
#endregion
if (client.ContainsFlag1(Enums.Effect1.Riding) && interact.MagicType != 7001)
{
if (client.Stamina >= 100)
{
client.Stamina = 0;
client.RemoveFlag1(Enums.Effect1.Riding);
}
return;
}
Magic.Handle(client, interact);
break;
}
case Enums.InteractAction.Attack:
if (client.ContainsFlag1(Enums.Effect1.Riding))
{
if (client.Stamina >= 100)
{
client.Stamina = 0;
client.RemoveFlag1(Enums.Effect1.Riding);
}
return;
}
Physical.Handle(client, interact);
break;
case Enums.InteractAction.Shoot:
if (client.ContainsFlag1(Enums.Effect1.Riding))
{
if (client.Stamina >= 100)
{
client.Stamina = 0;
client.RemoveFlag1(Enums.Effect1.Riding);
}
return;
}
Ranged.Handle(client, interact);
break;
}
}
/// <summary>
/// Processing damage.
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="damage">The damage.</param>
public static void ProcessDamage(Entities.IEntity attacker, Entities.IEntity attacked, ref uint damage, bool kill_damage = true)
{
// Removed dura, bugged atm. the dura works, although client doesn't update proper etc. CBA to fix it as I never intended to use it
// Although you can go ahead and fix it yourself if you want, I may do it if I ever feel like it
// The dura lose is commented out below.
#region ATTACKER : GAMECLIENT
if (attacker is Entities.GameClient)
{
Entities.GameClient attackerclient = attacker as Entities.GameClient;
attackerclient.LoseAttackDura(damage);
#region ATTACKED : GAMECLIENT
if (attacked is Entities.GameClient)
{
Entities.GameClient attackedclient = attacked as Entities.GameClient;
// tournament check, damage = 1 + return
if (attackerclient.Battle != null)
{
if (!attackerclient.Battle.HandleAttack(attackerclient, attackedclient, ref damage))
{
damage = 0;
return;
}
}
else
{
if (attacked.Map.GotKillCons() && !attackedclient.ContainsFlag1(Enums.Effect1.BlueName) && !attackedclient.ContainsFlag1(Enums.Effect1.RedName) && !attackedclient.ContainsFlag1(Enums.Effect1.BlackName))
{
attackerclient.AddStatusEffect1(Enums.Effect1.BlueName, 20000);
}
attackedclient.LoseDefenseDura(damage);
}
}
#endregion
#region ATTACKED : MONSTER
else if (attacked is Entities.Monster)
{
Entities.Monster attackedmob = attacked as Entities.Monster;
if (((byte)attackedmob.Behaviour) >= 3)
{
attackerclient.AddStatusEffect1(Enums.Effect1.BlueName, 20000);
}
if (damage > 0)
{
ulong exp = (ulong)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)(damage / 2), (int)damage);
if (attacked.Level > (attacker.Level + 10))
exp *= 2;
else if (attacker.Level > (attacked.Level + 10))
exp = (ulong)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(1, (int)attackedmob.Level);
attackerclient.AddExp(exp);
}
}
#endregion
#region ATTACKED : SOB
/*else if (attacked is Entities.Sob)
{
Entities.Sob attackedsob = attacked as Entities.Sob;
if (damage > 0)
{
// Do stuff ...
}
}*/
#endregion
//if (Calculations.Battle.LoseDuraAttak())
//attackerclient.LoseAttackDura(damage);
}
#endregion
#region ATTACKER : MONSTER
#region ATTACKED : GAMECLIENT
if (attacked is Entities.GameClient)
{
Entities.GameClient attackedclient = attacked as Entities.GameClient;
attackedclient.LoseDefenseDura(damage);
}
#endregion
#endregion
if (kill_damage)
{
HitDamage(attacker, attacked, damage);
}
}
public static void HitDamage(Entities.IEntity attacker, Entities.IEntity attacked, uint damage)
{
if (attacked is Entities.Sob)
{
SobCombat.Handle(attacked as Entities.Sob, attacker, (int)damage);
}
else
{
attacked.HP -= (int)damage;
if (attacked.HP <= 0)
{
Kill(attacker, attacked, damage);
}
}
}
/// <summary>
/// Kills an entity.
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
public static void Kill(Entities.IEntity attacker, Entities.IEntity attacked, uint damage = 0)
{
attacked.HP = 0;
attacked.Alive = false;
if (attacked is Entities.Monster)
{
(attacked as Entities.Monster).Kill(attacker, damage);
if (attacker is Entities.GameClient)
{
if ((attacker as Entities.GameClient).Battle != null)
(attacker as Entities.GameClient).Battle.KillMob((attacker as Entities.GameClient), attacked.EntityUID);
}
}
using (var killpacket = new Packets.InteractionPacket())
{
killpacket.Action = Enums.InteractAction.Kill;
killpacket.TargetUID = attacked.EntityUID;
killpacket.X = attacked.X;
killpacket.Y = attacked.Y;
killpacket.Data = 1;
if (attacker != null)
{
killpacket.EntityUID = attacker.EntityUID;
attacker.Screen.UpdateScreen(killpacket);
if (attacker is Entities.GameClient)
(attacker as Entities.GameClient).Send(killpacket);
}
else
{
killpacket.EntityUID = 0;
attacked.Screen.UpdateScreen(killpacket);
if (attacked is Entities.GameClient)
(attacked as Entities.GameClient).Send(killpacket);
}
}
if (attacked is Entities.GameClient)
{
Entities.GameClient attackedclient = attacked as Entities.GameClient;
attackedclient.RemoveFlag1(Enums.Effect1.Fly);
attackedclient.RemoveFlag1(Enums.Effect1.Invisible);
if (attacker != null)
{
if (attacked.EntityUID != attacker.EntityUID)
{
if (attacker is Entities.GameClient)
{
if ((attacker as Entities.GameClient).Battle != null)
{
if (!(attacker as Entities.GameClient).Battle.HandleDeath((attacker as Entities.GameClient), attackedclient))
return;
}
else if (attacked.Map.GotKillCons())
{
Entities.GameClient attackerclient = attacker as Entities.GameClient;
if (attackedclient.Guild != null && attackerclient.Guild != null)
{
if (attackerclient.Guild.IsEnemy(attackedclient.Guild.Name))
attackerclient.PKPoints += 3;
else
attackerclient.PKPoints += 10;
}
else
attackerclient.PKPoints += 10;
}
}
}
}
attackedclient.AttackPacket = null;
attackedclient.ReviveTime = DateTime.Now.AddSeconds(20);
attackedclient.AddStatusEffect1(Enums.Effect1.Dead);
attackedclient.AddStatusEffect1(Enums.Effect1.Ghost);
attackedclient.RemoveFlag1(Enums.Effect1.BlueName);
attackedclient.Stamina = 0;
attackedclient.Transformation = Calculations.BasicCalculations.GetGhostTransform(attackedclient.Model);
}
if (attacked is Entities.BossCreature)
{
Entities.BossCreature creature = attacked as Entities.BossCreature;
creature.Abort();
}
else if (attacked is Entities.BossMonster)
{
Entities.BossMonster boss = attacked as Entities.BossMonster;
boss.AbortBoss(false);
if (attacker is Entities.GameClient)
boss.ON_DEATH(attacker as Entities.GameClient);
}
}
public static bool FixTarget(Entities.IEntity attacker, Entities.IEntity target)
{
if (attacker is Entities.GameClient && target is Entities.GameClient)
{
if ((attacker as Entities.GameClient).PKMode == Enums.PKMode.Team)
{
if ((attacker as Entities.GameClient).Team != null)
{
if ((attacker as Entities.GameClient).Team.Members.ContainsKey(target.EntityUID))
return false;
}
else if ((attacker as Entities.GameClient).Guild != null)
{
if ((attacker as Entities.GameClient).Guild.Members.Contains((target as Entities.GameClient).DatabaseUID))
return false;
else if ((attacker as Entities.GameClient).Guild != null)
{
if ((attacker as Entities.GameClient).Guild.IsAllie((target as Entities.GameClient).Guild.Name))
return false;
}
}
}
}
return true;
}
}
}
Code:
//Project by BaussHacker aka. L33TS
using System;
namespace ProjectX_V3_Game.Calculations
{
/// <summary>
/// Calculations used for battle / combat.
/// </summary>
public class Battle
{
/// <summary>
/// Returns a boolean defining whether the attack is a success. [Unused atm.]
/// </summary>
/// <param name="Percentage">The percentage.</param>
/// <returns>Returns true if the attack is a success.</returns>
public static bool AttackSuccess(double Percentage)
{
return false;
}
/// <summary>
/// Getting a boolean defining whether or not defense dura can be lost.
/// </summary>
/// <returns>Returns true if the chance is success.</returns>
public static bool LoseDuraDefense()
{
return false;
//return BasicCalculations.ChanceSuccess(2); // 10 % chance
}
/// <summary>
/// Getting a boolean defining whether or not attack dura can be lost.
/// </summary>
/// <returns>Returns true if the chance is success.</returns>
public static bool LoseDuraAttack()
{
return false;
//return BasicCalculations.ChanceSuccess(1); // 3 % chance
}
#region Physical
/// <summary>
/// Gets the physical damage.
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
public static uint GetPhysicalDamage(Entities.IEntity attacker, Entities.IEntity attacked)
{
double damage = 0;
if (attacker is Entities.GameClient)
{
if (attacked is Entities.GameClient)
damage = GetPhysicalDamage_PVP((attacker as Entities.GameClient), (attacked as Entities.GameClient));
else if (attacked is Entities.Monster)
damage = GetPhysicalDamage_PVM((attacker as Entities.GameClient), (attacked as Entities.Monster));
else if (attacked is Entities.Sob)
damage = GetPhysicalDamage_PVS((attacker as Entities.GameClient));
}
if (attacker is Entities.Monster)
{
if (attacked is Entities.GameClient)
damage = GetPhysicalDamage_MVP((attacker as Entities.Monster), (attacked as Entities.GameClient));
else if (attacked is Entities.Monster)
damage = GetPhysicalDamage_MVM((attacker as Entities.Monster), (attacked as Entities.Monster));
}
if (damage > 1)
{
if (attacker.Level > (attacked.Level + 10))
damage *= 1.25;
else if ((attacker.Level + 10) < attacked.Level)
damage = (damage * 0.75);
}
damage = (damage >= 1 ? damage : 1);
if (damage > 1)
{
damage += ((damage / 2) * attacker.Reborns);
}
return (uint)damage;
}
/// <summary>
/// Gets the physical damage (PVP).
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalDamage_PVP(Entities.GameClient attacker, Entities.GameClient attacked)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack);
damage *= 1 + attacker.DragonGemPercentage;
damage -= attacked.Defense;
if (attacked.ContainsFlag1(Enums.Effect1.Shield))
damage *= 0.5;
if (attacker.ContainsFlag1(Enums.Effect1.Stig))
damage *= 1.75;
double damage_perc = damage;
damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
damage -= damage_perc;
damage_perc = (damage / 100) * attacked.Bless;
damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical damage (PVM).
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalDamage_PVM(Entities.GameClient attacker, Entities.Monster attacked)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack);
damage *= 1 + attacker.DragonGemPercentage;
damage -= attacked.Defense;
if (attacker.ContainsFlag1(Enums.Effect1.Stig))
damage *= 1.75;
//double damage_perc = damage;
//damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
//damage -= damage_perc;
//damage_perc = (damage / 100) * attacked.Bless;
//damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical damage (PVS).
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalDamage_PVS(Entities.GameClient attacker)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack);
damage *= 1 + attacker.DragonGemPercentage;
if (attacker.ContainsFlag1(Enums.Effect1.Stig))
damage *= 1.75;
//double damage_perc = damage;
//damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
//damage -= damage_perc;
//damage_perc = (damage / 100) * attacked.Bless;
//damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical damage (MVP).
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalDamage_MVP(Entities.Monster attacker, Entities.GameClient attacked)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)attacker.MinAttack, (int)attacker.MaxAttack);
//damage *= 1 + attacker.DragonGemPercentage;
damage -= attacked.Defense;
if (attacked.ContainsFlag1(Enums.Effect1.Shield))
damage *= 0.5;
double damage_perc = damage;
damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
damage -= damage_perc;
damage_perc = (damage / 100) * attacked.Bless;
damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical damage (MVM).
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalDamage_MVM(Entities.Monster attacker, Entities.Monster attacked)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)attacker.MinAttack, (int)attacker.MaxAttack);
//damage *= 1 + attacker.DragonGemPercentage;
damage -= attacked.Defense;
//double damage_perc = damage;
//damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
//damage -= damage_perc;
//damage_perc = (damage / 100) * attacked.Bless;
//damage -= damage_perc;
return damage;
}
#endregion
#region Ranged
/// <summary>
/// Gets the ranged damage.
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
public static uint GetRangedDamage(Entities.IEntity attacker, Entities.IEntity attacked)
{
double damage = 0;
if (attacker is Entities.GameClient)
{
if (attacked is Entities.GameClient)
damage = GetRangedDamage_PVP((attacker as Entities.GameClient), (attacked as Entities.GameClient));
if (attacked is Entities.Monster)
damage = GetRangedDamage_PVM((attacker as Entities.GameClient), (attacked as Entities.Monster));
if (attacked is Entities.Sob)
damage = GetRangedDamage_PVS((attacker as Entities.GameClient));
}
if (damage > 1)
{
if (attacker.Level > (attacked.Level + 10))
damage *= 1.25;
else if ((attacker.Level + 10) < attacked.Level)
damage = (damage * 0.75);
}
damage = (damage >= 1 ? damage : 1);
if (damage > 1)
{
damage += ((damage / 2) * attacker.Reborns);
}
return (uint)damage;
}
/// <summary>
/// Gets the ranged damage. (PVP)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
private static double GetRangedDamage_PVP(Entities.GameClient attacker, Entities.GameClient attacked)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack);
damage *= 1 - (attacked.Dodge * 0.01);
damage *= 0.45;
if (attacker.ContainsFlag1(Enums.Effect1.Stig))
damage *= 1.75;
damage *= 1 + attacker.DragonGemPercentage;
double damage_perc = damage;
damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
damage -= damage_perc;
damage_perc = (damage / 100) * attacked.Bless;
damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the ranged damage. (PVM)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <returns>Returns the damage.</returns>
private static double GetRangedDamage_PVM(Entities.GameClient attacker, Entities.Monster attacked)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack);
damage *= 1 - (attacked.Dodge * 0.01);
damage *= 0.45;
if (attacker.ContainsFlag1(Enums.Effect1.Stig))
damage *= 1.75;
damage *= 1 + attacker.DragonGemPercentage;
//double damage_perc = damage;
//damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
//damage -= damage_perc;
//damage_perc = (damage / 100) * attacked.Bless;
//damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the ranged damage. (PVS)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <returns>Returns the damage.</returns>
private static double GetRangedDamage_PVS(Entities.GameClient attacker)
{
double damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack);
damage *= 0.45;
if (attacker.ContainsFlag1(Enums.Effect1.Stig))
damage *= 1.75;
damage *= 1 + attacker.DragonGemPercentage;
//double damage_perc = damage;
//damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
//damage -= damage_perc;
//damage_perc = (damage / 100) * attacked.Bless;
//damage -= damage_perc;
return damage;
}
#endregion
#region Magic
/// <summary>
/// Gets the magic damage.
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
public static uint GetMagicDamage(Entities.IEntity attacker, Entities.IEntity attacked, Data.Spell spell)
{
double damage = 0;
if (attacker is Entities.GameClient)
{
if (attacked is Entities.GameClient)
damage = GetMagicDamage_PVP((attacker as Entities.GameClient), (attacked as Entities.GameClient), spell);
else if (attacked is Entities.Monster)
damage = GetMagicDamage_PVM((attacker as Entities.GameClient), (attacked as Entities.Monster), spell);
else if (attacked is Entities.Sob)
damage = GetMagicDamage_PVS((attacker as Entities.GameClient), spell);
}
if (attacker is Entities.Monster)
{
if (attacked is Entities.GameClient)
damage = GetMagicDamage_MVP((attacker as Entities.Monster), (attacked as Entities.GameClient), spell);
else if (attacked is Entities.Monster)
damage = GetMagicDamage_MVM((attacker as Entities.Monster), (attacked as Entities.Monster), spell);
}
if (damage > 1)
{
if (attacker.Level > (attacked.Level + 10))
damage *= 1.25;
else if ((attacker.Level + 10) < attacked.Level)
damage = (damage * 0.75);
}
damage = (damage >= 1 ? damage : 1);
if (damage > 1)
{
damage += ((damage / 2) * attacker.Reborns);
}
return (uint)damage;
}
/// <summary>
/// Gets the magic damage. (PVP)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetMagicDamage_PVP(Entities.GameClient attacker, Entities.GameClient attacked, Data.Spell spell)
{
double damage = (double)attacker.MagicAttack;
damage -= attacked.MagicDefense;
damage *= 0.65;
damage += spell.Power;
damage *= 1 + attacker.PhoenixGemPercentage;
// damage -= attacked.Defense;
double damage_perc = damage;
damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
damage -= damage_perc;
damage_perc = (damage / 100) * attacked.Bless;
damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the magic damage. (PVM)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetMagicDamage_PVM(Entities.GameClient attacker, Entities.Monster attacked, Data.Spell spell)
{
double damage = (double)attacker.MagicAttack;
damage -= attacked.MagicDefense;
damage *= 0.65;
damage += spell.Power;
damage *= 1 + attacker.PhoenixGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the magic damage. (PVS)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetMagicDamage_PVS(Entities.GameClient attacker, Data.Spell spell)
{
double damage = (double)attacker.MagicAttack;
damage *= 0.65;
damage += spell.Power;
damage *= 1 + attacker.PhoenixGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the magic damage. (MVP)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetMagicDamage_MVP(Entities.Monster attacker, Entities.GameClient attacked, Data.Spell spell)
{
double damage = (double)attacker.MaxAttack;
damage -= attacked.MagicDefense;
damage *= 0.65;
damage += spell.Power;
//damage *= 1 + attacker.PhoenixGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the magic damage. (MVM)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetMagicDamage_MVM(Entities.Monster attacker, Entities.Monster attacked, Data.Spell spell)
{
double damage = attacker.MaxAttack;
damage -= attacked.MagicDefense;
damage *= 0.65;
damage += spell.Power;
// damage *= 1 + attacker.PhoenixGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
#endregion
#region PhysicalMagic
/// <summary>
/// Gets the physical magic damage.
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
public static uint GetPhysicalMagicDamage(Entities.IEntity attacker, Entities.IEntity attacked, Data.Spell spell)
{
double damage = 0;
if (attacker is Entities.GameClient)
{
if (attacked is Entities.GameClient)
damage = GetPhysicalMagicDamage_PVP((attacker as Entities.GameClient), (attacked as Entities.GameClient), spell);
else if (attacked is Entities.Monster)
damage = GetPhysicalMagicDamage_PVM((attacker as Entities.GameClient), (attacked as Entities.Monster), spell);
else if (attacked is Entities.Sob)
damage = GetPhysicalMagicDamage_PVS((attacker as Entities.GameClient), spell);
}
if (attacker is Entities.Monster)
{
if (attacked is Entities.GameClient)
damage = GetPhysicalMagicDamage_MVP((attacker as Entities.Monster), (attacked as Entities.GameClient), spell);
else if (attacked is Entities.Monster)
damage = GetPhysicalMagicDamage_MVM((attacker as Entities.Monster), (attacked as Entities.Monster), spell);
}
if (damage > 1)
{
if (attacker.Level > (attacked.Level + 10))
damage *= 1.25;
else if ((attacker.Level + 10) < attacked.Level)
damage = (damage * 0.75);
}
damage = (damage >= 1 ? damage : 1);
if (damage > 1)
{
damage += ((damage / 2) * attacker.Reborns);
}
return (uint)damage;
}
/// <summary>
/// Gets the magic damage. (PVP)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalMagicDamage_PVP(Entities.GameClient attacker, Entities.GameClient attacked, Data.Spell spell)
{
double damage = (double) ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack * 2);
damage -= attacked.Defense;
damage *= 0.65;
// penetration extra damage
if (spell.SpellID == 1290 && damage > 0)
{
double hunperc = (double)((damage / 100) * 26.6);
damage += (hunperc * spell.Level);
}
// damage += spell.Power;
damage *= 1 + attacker.DragonGemPercentage;
if (attacked.ContainsFlag1(Enums.Effect1.Shield))
damage *= 0.5;
// damage -= attacked.Defense;
double damage_perc = damage;
damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
damage -= damage_perc;
damage_perc = (damage / 100) * attacked.Bless;
damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical magic damage. (PVM)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalMagicDamage_PVM(Entities.GameClient attacker, Entities.Monster attacked, Data.Spell spell)
{
double damage = (double) ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack * 2);
damage -= attacked.Defense;
damage *= 0.65;
// penetration extra damage
if (spell.SpellID == 1290 && damage > 0)
{
double hunperc = (double)((damage / 100) * 26.6);
damage += (hunperc * spell.Level);
}
//damage += spell.Power;
damage *= 1 + attacker.DragonGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical magic damage. (PVS)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalMagicDamage_PVS(Entities.GameClient attacker, Data.Spell spell)
{
double damage = (double) ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(attacker.MinAttack, attacker.MaxAttack * 2);
damage *= 0.65;
// penetration extra damage
if (spell.SpellID == 1290 && damage > 0)
{
double hunperc = (double)((damage / 100) * 26.6);
damage += (hunperc * spell.Level);
}
//damage += spell.Power;
damage *= 1 + attacker.DragonGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical magic damage. (MVP)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalMagicDamage_MVP(Entities.Monster attacker, Entities.GameClient attacked, Data.Spell spell)
{
double damage = (double) ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)attacker.MaxAttack, (int)attacker.MaxAttack * 2);
damage -= attacked.Defense;
damage *= 0.65;
// penetration extra damage
if (spell.SpellID == 1290 && damage > 0)
{
double hunperc = (double)((damage / 100) * 26.6);
damage += (hunperc * spell.Level);
}
if (attacked.ContainsFlag1(Enums.Effect1.Shield))
damage *= 0.5;
// damage += spell.Power;
//damage *= 1 + attacker.PhoenixGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
/// <summary>
/// Gets the physical magic damage. (MVM)
/// </summary>
/// <param name="attacker">The attacker.</param>
/// <param name="attacked">The attacked.</param>
/// <param name="spell">The spell.</param>
/// <returns>Returns the damage.</returns>
private static double GetPhysicalMagicDamage_MVM(Entities.Monster attacker, Entities.Monster attacked, Data.Spell spell)
{
double damage = (double) ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)attacker.MaxAttack, (int)attacker.MaxAttack * 2);
damage -= attacked.Defense;
damage *= 0.65;
// penetration extra damage
if (spell.SpellID == 1290 && damage > 0)
{
double hunperc = (double)((damage / 100) * 26.6);
damage += (hunperc * spell.Level);
}
//damage += spell.Power;
// damage *= 1 + attacker.PhoenixGemPercentage;
// damage -= attacked.Defense;
// double damage_perc = damage;
// damage_perc = (damage / 100) * attacked.TortoiseGemPercentage;
// damage -= damage_perc;
// damage_perc = (damage / 100) * attacked.Bless;
// damage -= damage_perc;
return damage;
}
#endregion
}
}
Code:
/// <summary>
/// Teleports the client to a specific place.
/// </summary>
/// <param name="map">The map to teleport to.</param>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <returns>Returns true if the client was teleported.</returns>
public bool Teleport(Maps.Map map, ushort x, ushort y, bool isdynamic = false)
{
if (!Core.Kernel.Maps.Contains(map.MapID) && !isdynamic)
return false;
Maps.Map lMap = Map;
if (!lMap.LeaveMap(this))
return false;
if (DynamicMap != null)
{
LeaveDynamicMap(false);
}
DynamicMap = null;
ushort lastmap = lMap.MapID;
if (!map.EnterMap(this))
return false;
if (isdynamic)
DynamicMap = (Maps.DynamicMap)map;
AttackPacket = null;
RemoveFlag1(Enums.Effect1.Riding);
ushort SendMap = map.InheritanceMap;
Send(new Packets.GeneralDataPacket()
{
Id = EntityUID,
Data1 =SendMap,
Data2 = 0,
Timestamp = ProjectX_V3_Lib.Time.SystemTime.Now,
Action = Enums.DataAction.Teleport,
Data3Low = x,
Data3High = y,
Data4 = 0,
Data5 = 0,
});
Send(new Packets.GeneralDataPacket()
{
Id = EntityUID,
Data1 = SendMap,
Data2 = 0,
Timestamp = ProjectX_V3_Lib.Time.SystemTime.Now,
Action = Enums.DataAction.ChangeMap,
Data3Low = x,
Data3High = y,
Data4 = 0,
Data5 = 0,
});
using (var mapinfo = new Packets.MapInfoPacket())
{
mapinfo.MapID = SendMap;
mapinfo.DocID = SendMap;
foreach (Enums.MapTypeFlags flag in map.Flags.Values)
mapinfo.AddFlag(flag);
mapinfo.Finish();
this.Send(mapinfo);
}
if (lMap.MapType != Enums.MapType.Tournament)
{
LastMapID = lastmap;
LastMapX = X;
LastMapY = Y;
}
X = x;
Y = y;
#region Clear
using (var clear = Packets.Message.MessageCore.ClearScore())
{
this.Send(clear);
}
#endregion
if (Battle != null)
{
Battle.ChangeMap(this);
}
else
{
Tournaments.GuildWars.GW.ChangeMap(this);
}
if (lMap.MapType != Enums.MapType.Tournament)
{
Database.CharacterDatabase.UpdateCharacter(this, "PlayerLastMapID", lastmap);
}
if (!isdynamic && Map.MapType != Enums.MapType.Tournament)
{
Database.CharacterDatabase.UpdateCharacter(this, "PlayerMapID", Map.MapID);
Database.CharacterDatabase.UpdateCharacter(this, "PlayerX", X);
Database.CharacterDatabase.UpdateCharacter(this, "PlayerY", Y);
}
return true;
}
Code:
new BaseThread(Tournaments.GuildWars.Handle, 30000, "GuildWarsThread").Start();
Code:
//Project by BaussHacker aka. L33TS
using System;
namespace ProjectX_V3_Game.Entities
{
/// <summary>
/// Description of Sob.
/// </summary>
public class Sob : IEntity, Maps.IMapObject
{
private NPC associatedNPC;
public Sob(NPC associatedNPC)
{
this.associatedNPC = associatedNPC;
_baseentity = new BaseEntity(this);
_screen = new ProjectX_V3_Game.Core.Screen(this);
}
#region Global Variables
/// <summary>
/// The mesh of the sob.
/// </summary>
public ushort Mesh;
/// <summary>
/// The secondary mesh of the sob.
/// </summary>
public ushort SecondaryMesh;
/// <summary>
/// The mesh to show.
/// </summary>
public ushort ShowMesh;
/// <summary>
/// The flag of the sob.
/// </summary>
public ushort Flag;
/// <summary>
/// The sob type.
/// </summary>
public uint SobType;
/// <summary>
/// The original sob name.
/// </summary>
public string OriginalName;
#endregion
#region Properties
/// <summary>
/// The first status flag holder.
/// </summary>
private ulong _statusflag1;
/// <summary>
/// Gets or sets the first status flag.
/// </summary>
public ulong StatusFlag1
{
get { return _statusflag1; }
set
{
_statusflag1 = value;
}
}
/// <summary>
/// The alive holder.
/// </summary>
private bool _alive = true;
/// <summary>
/// Gets or sets whether the npc is alive. (Although it's always alive ^~^)
/// </summary>
public bool Alive
{
get { return _alive; }
set { _alive = value; }
}
/// <summary>
/// The base entity holder.
/// </summary>
private BaseEntity _baseentity;
/// <summary>
/// Gets the base entity holder.
/// </summary>
public BaseEntity BaseEntity
{
get { return _baseentity; }
}
/// <summary>
/// The reborn holder.
/// </summary>
private byte _reborns;
/// <summary>
/// Gets or sets the reborns of the character.
/// </summary>
public byte Reborns
{
get { return _reborns; }
set
{
_reborns = value;
this.BaseEntity.CalculateBaseStats();
}
}
/// <summary>
/// The class holder.
/// </summary>
private Enums.Class _class = Enums.Class.Other;
/// <summary>
/// Gets or sets the class.
/// </summary>
public Enums.Class Class
{
get { return _class; }
set
{
_class = value;
this.BaseEntity.CalculateBaseStats();
}
}
/// <summary>
/// Gets a boolean defining whether the client can update its own spawn and/or spawn to others.
/// </summary>
public bool CanUpdateSpawn
{
get { return true; }
}
/// <summary>
/// The name holder.
/// </summary>
private string _name;
/// <summary>
/// Gets or sets the name of the npc.
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
/// The entity uid holder.
/// </summary>
private uint _entityuid;
/// <summary>
/// Gets or sets the entity UID of the npc.
/// </summary>
public uint EntityUID
{
get { return _entityuid; }
set { _entityuid = value; }
}
/// <summary>
/// The screen holder.
/// </summary>
private Core.Screen _screen;
/// <summary>
/// Gets the screen.
/// </summary>
public Core.Screen Screen
{
get { return _screen; }
}
/// <summary>
/// The hp holder.
/// </summary>
private int _hp;
/// <summary>
/// Gets or sets the hp.
/// </summary>
public int HP
{
get { return _hp; }
set
{
_hp = value;
}
}
/// <summary>
/// The mp holder.
/// </summary>
private int _mp;
/// <summary>
/// Gets or sets the mp.
/// </summary>
public int MP
{
get { return _mp; }
set
{
_mp = value;
}
}
/// <summary>
/// The max hp holder.
/// </summary>
private int _maxhp;
/// <summary>
/// Gets or sets the max hp.
/// </summary>
public int MaxHP
{
get { return _maxhp; }
set
{
_maxhp = value;
}
}
/// <summary>
/// The max mp holder.
/// </summary>
private int _maxmp;
/// <summary>
/// Gets or sets the maxmp.
/// </summary>
public int MaxMP
{
get { return _maxmp; }
set
{
_maxmp = value;
}
}
/// <summary>
/// The level holder.
/// </summary>
private byte _level;
/// <summary>
/// Gets or sets the level.
/// </summary>
public byte Level
{
get { return _level; }
set
{
_level = value;
}
}
/// <summary>
/// The lastmapid holder.
/// </summary>
private ushort _lastmapid;
/// <summary>
/// Gets or sets the last map.
/// </summary>
public ushort LastMapID
{
get { return _lastmapid; }
set { _lastmapid = value; }
}
/// <summary>
/// The x coordinate holder.
/// </summary>
private ushort _x;
/// <summary>
/// Gets or sets the x coordinate.
/// </summary>
public ushort X
{
get { return _x; }
set
{
_x = value;
}
}
/// <summary>
/// The y coordinate holder.
/// </summary>
private ushort _y;
/// <summary>
/// Gets or sets the y coordinate.
/// </summary>
public ushort Y
{
get { return _y; }
set
{
_y = value;
}
}
/// <summary>
/// The dynamic map holder.
/// </summary>
private Maps.DynamicMap _dynamicMap;
/// <summary>
/// Gets or sets the dynamic map for the npc.
/// </summary>
public Maps.DynamicMap DynamicMap
{
get { return _dynamicMap; }
set { _dynamicMap = value; }
}
/// <summary>
/// The map holder.
/// </summary>
private Maps.Map _map;
/// <summary>
/// Gets or sets the map.
/// </summary>
public Maps.Map Map
{
get { return _map; }
set { _map = value; }
}
/// <summary>
/// The direction holder.
/// </summary>
private byte _direction;
/// <summary>
/// Gets or sets the direction.
/// </summary>
public byte Direction
{
get { return _direction; }
set { _direction = value; }
}
/// <summary>
/// The strength holder.
/// </summary>
private ushort _strength;
/// <summary>
/// Gets or sets the strength.
/// </summary>
public ushort Strength
{
get { return _strength; }
set
{
_strength = value;
this.BaseEntity.CalculateBaseStats();
}
}
/// <summary>
/// The agility holder.
/// </summary>
private ushort _agility;
/// <summary>
/// Gets or sets the agility.
/// </summary>
public ushort Agility
{
get { return _agility; }
set
{
_agility = value;
this.BaseEntity.CalculateBaseStats();
}
}
/// <summary>
/// The vitality holder.
/// </summary>
private ushort _vitality;
/// <summary>
/// Gets or sets the vitality.
/// </summary>
public ushort Vitality
{
get { return _vitality; }
set
{
_vitality = value;
this.BaseEntity.CalculateBaseStats();
}
}
/// <summary>
/// The spirit holder.
/// </summary>
private ushort _spirit;
/// <summary>
/// Gets or sets the spirit.
/// </summary>
public ushort Spirit
{
get { return _spirit; }
set
{
_spirit = value;
this.BaseEntity.CalculateBaseStats();
}
}
#endregion
#region Core Methods
public bool IsInMap(Maps.IMapObject MapObject)
{
if (DynamicMap != null)
{
if (MapObject.DynamicMap == null)
return false;
if (DynamicMap.DynamicID != MapObject.DynamicMap.DynamicID)
return false;
}
return Map.MapID == MapObject.Map.MapID;
}
public Packets.SobSpawnPacket CreateSobSpawnPacket()
{
Packets.SobSpawnPacket spawn = new ProjectX_V3_Game.Packets.SobSpawnPacket(new Packets.StringPacker(Name));
spawn.EntityUID = EntityUID;
spawn.MaxHealth = (uint)MaxHP;
spawn.Health = (uint)HP;
spawn.X = X;
spawn.Y = Y;
spawn.Mesh = ShowMesh;
spawn.Flag = Flag;
return spawn;
}
public void Revive()
{
HP = MaxHP;
Screen.FullUpdate();
}
[Obsolete("This method should never be called.")]
public Packets.SpawnPacket CreateSpawnPacket()
{
throw new Exception("DO NOT CALL THIS!");
}
/// <summary>
/// Calls the npc dialog associated with the npc.
/// </summary>
/// <param name="client">The client.</param>
/// <param name="option">The dialog option.</param>
public void CallDialog(GameClient client, byte option)
{
if (associatedNPC != null)
associatedNPC.CallDialog(client, option);
}
#endregion
#region Methods
/*private int MoveCount = 0;
private bool LastLeft = false;
public void Move()
{
new ProjectX_V3_Lib.Threading.BaseThread(MoveT, 500, "").Start();
}
private void MoveT()
{
if (LastLeft)
{
// move right
using (var movepacket = new Packets.MovementPacket())
{
movepacket.EntityUID = mob.EntityUID;
movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime();
movepacket.Direction = (uint)Enums.ConquerAngle.East;
movepacket.WalkMode = Enums.WalkMode.Run;
mob.Screen.UpdateScreen(movepacket);
}
}
else
{
// move left
using (var movepacket = new Packets.MovementPacket())
{
movepacket.EntityUID = mob.EntityUID;
movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime();
movepacket.Direction = (uint)Enums.ConquerAngle.West;
movepacket.WalkMode = Enums.WalkMode.Run;
mob.Screen.UpdateScreen(movepacket);
}
}
if (MoveCount >= 5)
{
LastLeft = !LastLeft;
MoveCount = 0;
}
}
*/
#endregion
#region Misc
#endregion
}
}
Code:
//Project by BaussHacker aka. L33TS
using System;
using System.Collections.Concurrent;
using ProjectX_V3_Lib.Network;
using System.Diagnostics;
namespace ProjectX_V3_Game.Core
{
/// <summary>
/// A screen class. TODO: Rewrite this to make it even faster and with better readability ;)
/// </summary>
[Serializable()]
public class Screen
{
/// <summary>
/// The collection of screen objects.
/// </summary>
public ConcurrentDictionary<uint, Maps.IMapObject> MapObjects;
/// <summary>
/// The collection of screen objects.
/// </summary>
public ConcurrentDictionary<uint, Maps.IMapObject> Items;
/// <summary>
/// The screen owner.
/// </summary>
private Maps.IMapObject Owner;
/// <summary>
/// Creates a new screen.
/// </summary>
/// <param name="owner">The owner of the screen.</param>
public Screen(Maps.IMapObject owner)
{
Owner = owner;
MapObjects = new ConcurrentDictionary<uint, ProjectX_V3_Game.Maps.IMapObject>();
Items = new ConcurrentDictionary<uint, ProjectX_V3_Game.Maps.IMapObject>();
}
public void FullUpdate()
{
ClearScreen();
UpdateScreen(null);
foreach (Maps.IMapObject MapObject in MapObjects.Values)
{
if (MapObject is Entities.GameClient)
{
MapObject.Screen.UpdateScreen(null);
}
}
}
/// <summary>
/// Clears the screen.
/// </summary>
public void ClearScreen()
{
foreach (Maps.IMapObject MapObject in MapObjects.Values)
{
try
{
MapObject.Screen.UpdateScreen(null);
if (Owner is Data.GroundItem && MapObject is Entities.GameClient)
{
using (var itemspawn = (Owner as Data.GroundItem).CreateItemSpawnPacket(2))
{
itemspawn.X = 0;
itemspawn.Y = 0;
(MapObject as Entities.GameClient).Send(itemspawn);
}
}
else
{
if (Owner is Entities.GameClient)
{
(Owner as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(MapObject.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
if (MapObject is Entities.GameClient)
{
(MapObject as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(Owner.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
}
Remove(MapObject);
}
catch { }
}
foreach (Maps.IMapObject MapObject in Items.Values)
{
try
{
MapObject.Screen.UpdateScreen(null);
if (Owner is Entities.GameClient)
{
using (var itemspawn = (MapObject as Data.GroundItem).CreateItemSpawnPacket(2))
{
itemspawn.X = 0;
itemspawn.Y = 0;
(Owner as Entities.GameClient).Send(itemspawn);
}
}
Remove(MapObject);
}
catch { }
}
MapObjects.Clear();
Items.Clear();
}
#region New
/*
* /// <summary>
/// Adds a map object to the screen.
/// </summary>
/// <param name="MapObject">The map object to add.</param>
public void AddToScreen(Maps.IMapObject MapObject)
{
if (MapObject is Data.GroundItem)
{
if (Items.ContainsKey(MapObject.EntityUID))
return;
Items.TryAdd(MapObject.EntityUID, MapObject);
}
else
{
if (MapObjects.ContainsKey(MapObject.EntityUID))
return;
MapObjects.TryAdd(MapObject.EntityUID, MapObject);
if (MapObject is Entities.GameClient)
{
ProjectX_V3_Lib.Network.DataPacket spawn;
if (Owner is Data.GroundItem)
spawn = (Owner as Data.GroundItem).CreateItemSpawnPacket(1);
else if (Owner is Entities.NPC)
spawn = (Owner as Entities.NPC).CreateNPCSpawnPacket();
else
spawn = Owner.CreateSpawnPacket(); // Player + Monster + AI
(MapObject as Entities.GameClient).Send(spawn);
}
}
}
public void UpdateScreen(DataPacket Packet, bool deadonly = false)
{
if (!Owner.CanUpdateSpawn)
return;
foreach (Maps.IMapObject MapObject in Owner.Map.MapObjects.Values)
{
if (MapObject == Owner)
continue;
if (ValidDistance(MapObject.X, MapObject.Y, Owner.X, Owner.Y))
{
bool CanSpawnTo = true;
bool CanSpawnFrom = true;
#region Owner is GameClient
if (Owner is Entities.GameClient)
{
Entities.GameClient OwnerClient = Owner as Entities.GameClient;
#region Arena Watch
if (!OwnerClient.IsAIBot)
{
if (MapObject is Entities.GameClient)
{
Entities.GameClient ObjectClient = MapObject as Entities.GameClient;
if (!ObjectClient.IsAIBot)
{
if (OwnerClient.ArenaMatch != null)
{
if (!OwnerClient.ArenaMatch.SpawnInArena(ObjectClient))
CanSpawnTo = false;
}
else if (ObjectClient.ArenaMatch != null)
{
if (!ObjectClient.ArenaMatch.SpawnInArena(OwnerClient))
CanSpawnFrom = false;
}
}
}
}
#endregion
}
#endregion
#region Owner is Monster
if (Owner is Entities.Monster)
{
Entities.Monster OwnerMonster = Owner as Entities.Monster;
}
#endregion
#region Owner is NPC
if (Owner is Entities.NPC)
{
Entities.NPC OwnerNPC = Owner as Entities.NPC;
}
#endregion
if (CanSpawnFrom)
{
AddToScreen(MapObject);
MapObject.Screen.AddToScreen(Owner);
}
else
{
Remove(MapObject);
MapObject.Screen.Remove(Owner);
}
}
else
{
Remove(MapObject);
MapObject.Screen.Remove(Owner);
}
}
UpdateScreenItems();
}
/// <summary>
/// Removes a mapobject from the screen.
/// </summary>
/// <param name="MapObject">The mapobject to remove.</param>
public void Remove(Maps.IMapObject MapObject)
{
Maps.IMapObject rObject;
if (MapObject is Data.GroundItem)
Items.TryRemove(MapObject.EntityUID, out rObject);
else if (MapObjects.TryRemove(MapObject.EntityUID, out rObject))
{
if (Owner is Entities.GameClient)
{
(Owner as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(MapObject.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
}
if (Owner is Data.GroundItem)
MapObject.Screen.Items.TryRemove(Owner.EntityUID, out rObject);
} */
#endregion
#region old
public void AddToScreen(Maps.IMapObject MapObject)
{
if (MapObject is Data.GroundItem)
{
if (Items.ContainsKey(MapObject.EntityUID))
return;
Items.TryAdd(MapObject.EntityUID, MapObject);
}
else
{
if (MapObjects.ContainsKey(MapObject.EntityUID))
return;
MapObjects.TryAdd(MapObject.EntityUID, MapObject);
}
}
/// <summary>
/// Removes a mapobject from the screen.
/// </summary>
/// <param name="MapObject">The mapobject to remove.</param>
public void Remove(Maps.IMapObject MapObject)
{
Maps.IMapObject rObject;
if (MapObject is Data.GroundItem)
Items.TryRemove(MapObject.EntityUID, out rObject);
else
MapObjects.TryRemove(MapObject.EntityUID, out rObject);
if (Owner is Data.GroundItem)
MapObject.Screen.Items.TryRemove(Owner.EntityUID, out rObject);
else
MapObject.Screen.MapObjects.TryRemove(Owner.EntityUID, out rObject);
}
/// <summary>
/// Updates the screen.
/// </summary>
/// <param name="Packet">Set to null if sending no packets to the screen.</param>
public void UpdateScreen(DataPacket Packet, bool deadonly = false)
{
if (!Owner.CanUpdateSpawn)
return;
foreach (Maps.IMapObject MapObject in MapObjects.Values)
{
try
{
if (MapObject == Owner)
continue;
if (!MapObject.IsInMap(Owner))
{
Remove(MapObject);
continue;
}
if (ValidDistance(Owner.X, Owner.Y, MapObject.X, MapObject.Y) && MapObject.CanUpdateSpawn)
{
if (MapObject is Entities.Monster)
{
if (!(MapObject as Entities.Monster).Alive && (DateTime.Now >= (MapObject as Entities.Monster).DieTime.AddMilliseconds(5000)))
{
if (Owner is Entities.GameClient)
{
(Owner as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(MapObject.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
Remove(MapObject);
continue;
}
}
if (Packet != null)
{
if (MapObject is Entities.GameClient)
{
Entities.GameClient client = MapObject as Entities.GameClient;
if (client != null)
{
if (!client.IsAIBot) // if the person in screen is not a bot
{
if (client.ArenaMatch != null) // if the person in screen has an arena match
{
if ((Owner as Entities.GameClient).ArenaMatch == null) // the the owner does not have an arena match
{
if (!client.ArenaMatch.SpawnInArena((Owner as Entities.GameClient))) // if the owner is a watcher
continue; // do not send any packets ...
}
}
}
if (!deadonly || deadonly && !client.Alive)
client.Send(Packet);
}
}
}
MapObject.Screen.AddToScreen(MapObject);
}
else
{
if (Owner is Entities.GameClient)
{
(Owner as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(MapObject.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
if (MapObject is Entities.GameClient)
{
(MapObject as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(Owner.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
Remove(MapObject);
}
}
catch { }
}
ProjectX_V3_Lib.Network.DataPacket spawn;
if (Owner is Data.GroundItem)
spawn = (Owner as Data.GroundItem).CreateItemSpawnPacket(1);
else if (Owner is Entities.NPC)
spawn = (Owner as Entities.NPC).CreateNPCSpawnPacket();
else if (Owner is Entities.Sob)
spawn = (Owner as Entities.Sob).CreateSobSpawnPacket();
else
spawn = Owner.CreateSpawnPacket(); // Player + Monster + AI
foreach (Maps.IMapObject MapObject in Owner.Map.MapObjects.Values)
{
try
{
if (MapObject == Owner)
continue;
if (!MapObject.IsInMap(Owner))
{
Remove(MapObject);
continue;
}
if (MapObjects.ContainsKey(MapObject.EntityUID))
continue;
if (ValidDistance(Owner.X, Owner.Y, MapObject.X, MapObject.Y) && MapObject.CanUpdateSpawn)
{
if (MapObject is Entities.Monster)
{
if (!(MapObject as Entities.Monster).Alive && (DateTime.Now >= (MapObject as Entities.Monster).DieTime.AddMilliseconds(5000)))
{
if (Owner is Entities.GameClient)
{
(Owner as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(MapObject.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
Remove(MapObject);
continue; // we don't want to add it, because it died before getting in screen
}
}
if (MapObject is Entities.GameClient)
{
Entities.GameClient client = MapObject as Entities.GameClient;
if (client != null) // if the person in screen is not null
{
if (Packet != null)
{
if (!deadonly || deadonly && !client.Alive)
client.Send(Packet);
}
client.Send(spawn);
}
}
if (Owner is Entities.GameClient)
{
if (MapObject is Entities.NPC)
{
using (var objspawn = (MapObject as Entities.NPC).CreateNPCSpawnPacket())
(Owner as Entities.GameClient).Send(objspawn);
}
else if (MapObject is Entities.Sob)
{
using (var objspawn = (MapObject as Entities.Sob).CreateSobSpawnPacket())
(Owner as Entities.GameClient).Send(objspawn);
}
else
{
bool send_spawn = true;
if (send_spawn)
{
using (var objspawn = MapObject.CreateSpawnPacket())
(Owner as Entities.GameClient).Send(objspawn);
}
}
}
MapObject.Screen.AddToScreen(Owner);
AddToScreen(MapObject);
}
else
{
if (Owner is Entities.GameClient)
{
(Owner as Entities.GameClient).Send(Packets.GeneralDataPacket.Create(MapObject.EntityUID, Enums.DataAction.RemoveEntity, 0, 0, 0, 0, 0, 0));
}
Remove(MapObject);
}
}
catch { }
}
spawn.Dispose();
if (!(Owner is Entities.NPC))
UpdateScreenItems();
// if (Owner is Entities.Monster)
// {
// if (MapObjects.Count == 0)
// {
// Entities.Monster mob;
// Core.Kernel.SpawnedMonsters.TryRemove(Owner.EntityUID, out mob);
// }
// else if (!Core.Kernel.SpawnedMonsters.ContainsKey(Owner.EntityUID))
// Core.Kernel.SpawnedMonsters.TryAdd(Owner.EntityUID, Owner);
// }
}
#endregion
/// <summary>
/// Updates the screen with items.
/// </summary>
public void UpdateScreenItems()
{
if (!Owner.CanUpdateSpawn)
return;
foreach (Maps.IMapObject MapObject in Items.Values)
{
try
{
if (MapObject == Owner)
continue;
if (!MapObject.IsInMap(Owner))
{
Remove(MapObject);
continue;
}
if (ValidDistance(Owner.X, Owner.Y, MapObject.X, MapObject.Y) && MapObject.CanUpdateSpawn)
{
MapObject.Screen.AddToScreen(Owner);
}
else
{
if (Owner is Entities.GameClient)
{
using (var itemspawn = (MapObject as Data.GroundItem).CreateItemSpawnPacket(2))
{
itemspawn.X = 0;
itemspawn.Y = 0;
(Owner as Entities.GameClient).Send(itemspawn);
}
}
Remove(MapObject);
}
}
catch { }
}
foreach (Maps.IMapObject MapObject in Owner.Map.Items.Values)
{
try
{
if (MapObject == Owner)
continue;
if (!MapObject.IsInMap(Owner))
{
Remove(MapObject);
continue;
}
if (Items.ContainsKey(MapObject.EntityUID))
continue;
if (ValidDistance(Owner.X, Owner.Y, MapObject.X, MapObject.Y) && MapObject.CanUpdateSpawn)
{
if (Owner is Entities.GameClient)
{
using (var itemspawn = (MapObject as Data.GroundItem).CreateItemSpawnPacket(1))
{
(Owner as Entities.GameClient).Send(itemspawn);
}
}
MapObject.Screen.AddToScreen(Owner);
AddToScreen(MapObject);
}
else
{
if (Owner is Entities.GameClient)
{
using (var itemspawn = (MapObject as Data.GroundItem).CreateItemSpawnPacket(2))
{
itemspawn.X = 0;
itemspawn.Y = 0;
(Owner as Entities.GameClient).Send(itemspawn);
}
}
Remove(MapObject);
}
}
catch { }
}
}
public bool ContainsEntity(uint UID)
{
return MapObjects.ContainsKey(UID);
}
public bool GetEntity(uint UID, out Maps.IMapObject map)
{
return MapObjects.TryGetValue(UID, out map);
}
/// <summary>
/// Checks if there is a valid distance.
/// </summary>
/// <param name="x1">The first x coordinate.</param>
/// <param name="y1">The first y coordinate.</param>
/// <param name="x2">The second x coordinate.</param>
/// <param name="y2">The second y coordinate.</param>
/// <returns>Returns true if the distance is valid.</returns>
public static bool ValidDistance(ushort x1, ushort y1, ushort x2, ushort y2)
{
return (GetDistance(x1, y1, x2, y2) <= 18);
}
/// <summary>
/// Checks if there is a valid distance.
/// </summary>
/// <param name="x1">The first x coordinate.</param>
/// <param name="y1">The first y coordinate.</param>
/// <param name="x2">The second x coordinate.</param>
/// <param name="y2">The second y coordinate.</param>
/// <returns>Returns true if the distance is valid.</returns>
public static bool ValidDistance(int x1, int y1, int x2, int y2)
{
return (GetDistance(x1, y1, x2, y2) <= 18);
}
/// <summary>
/// Checks if there is a valid distance.
/// </summary>
/// <param name="x1">The first x coordinate.</param>
/// <param name="y1">The first y coordinate.</param>
/// <param name="x2">The second x coordinate.</param>
/// <param name="y2">The second y coordinate.</param>
/// <returns>Returns true if the distance is valid.</returns>
public static bool ValidDistance(double x1, double y1, double x2, double y2)
{
return (GetDistance(x1, y1, x2, y2) <= 18);
}
/// <summary>
/// Gets the distance between coordinates.
/// </summary>
/// <param name="x1">The first x coordinate.</param>
/// <param name="y1">The first y coordinate.</param>
/// <param name="x2">The second x coordinate.</param>
/// <param name="y2">The second y coordinate.</param>
/// <returns>Returns the distance.</returns>
public static int GetDistance(ushort x1, ushort y1, ushort x2, ushort y2)
{
return GetDistance((double)x1, (double)y1, (double)x2, (double)y2);
}
/// <summary>
/// Gets the distance between coordinates.
/// </summary>
/// <param name="x1">The first x coordinate.</param>
/// <param name="y1">The first y coordinate.</param>
/// <param name="x2">The second x coordinate.</param>
/// <param name="y2">The second y coordinate.</param>
/// <returns>Returns the distance.</returns>
public static int GetDistance(int x1, int y1, int x2, int y2)
{
return GetDistance((double)x1, (double)y1, (double)x2, (double)y2);
}
/// <summary>
/// Gets the distance between coordinates.
/// </summary>
/// <param name="x1">The first x coordinate.</param>
/// <param name="y1">The first y coordinate.</param>
/// <param name="x2">The second x coordinate.</param>
/// <param name="y2">The second y coordinate.</param>
/// <returns>Returns the distance.</returns>
public static int GetDistance(double x1, double y1, double x2, double y2)
{
return (int)System.Math.Sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));;
}
public static int GetDegree(int X, int X2, int Y, int Y2)
{
int direction = 0;
double AddX = X2 - X;
double AddY = Y2 - Y;
double r = (double)Math.Atan2(AddY, AddX);
if (r < 0) r += (double)Math.PI * 2;
direction = (int)(360 - (r * 180 / Math.PI));
return direction;
}
public static short GetAngle(ushort X, ushort Y, ushort x2, ushort y2)
{
double r = Math.Atan2(y2 - Y, x2 - X);
if (r < 0)
r += Math.PI * 2;
return (short)Math.Round(r * 180 / Math.PI);
}
public static Enums.ConquerAngle GetFacing(short angle)
{
sbyte c_angle = (sbyte)((angle / 46) - 1);
return (c_angle == -1) ? Enums.ConquerAngle.South : (Enums.ConquerAngle)c_angle;
}
}
}
I think this is it, now GuildWars should work.
If you're not using the ProjectX source you could use this as a reference.






