المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : اضافه حرب GuildPoleWar


Hassan Emprator
2019-08-27, 08:48 PM
السلام عليكم انهارضه معانا اضافه كويستت جميله كدا وموجوده في معظم لاسرفر النهرضه احنا نضيفها مع بعضينا
اول حاجه الحرب عباره عن الي هما 3 عواميد زي الجلد ليدر دوبتي ليدر الدوق
دي اخرهم فقط تمام نبدا في الاضافه
اول حاجه دا الانبي سي


#region [ GuildPolerWar ] [ xx : 44]
case 41167:
{
switch (npcRequest.OptionID)
{
case 0:
{
dialog.Text("Hello There. Do you want to Join The GuildPoleWar?.");
dialog.Option("Yes Please.", 1);
dialog.Option("Cliam Prize.", 2);
dialog.Option("Just Passing By!", 255);
dialog.Send();
break;
}
case 1:
{
if (GuildPoleWar.IsWar)
{
GuildPoleWar.Join(client);
}
else
{
dialog.Text("The War Has Not Started [Pole Started [44] End [50] Minat] ");
dialog.Option("Aww ok!", 255);
dialog.Send();
}
break;
}
case 2:
{
if (!GuildPoleWar.IsWar)
{
GuildPoleWar.GetReward(client, 15000);
}
else
{
dialog.Text("Sorry you can claim Prize After its end");
dialog.Option("Ahh.", 255);
dialog.Send();
}
break;
}
}
break;
}
#endregion

ثاني حاجه نفتح كلاس Handel.cs وي نبحث عن

public static void ReceiveAttack(Game.Entity attacker, SobNpcSpawn attacked, Attack attack, uint damage, Database.SpellInformation spell)

لما تلاقيه هضيف دي تحت الكوص

#region GuildPoleWar
if (GuildPoleWar.IsWar)
{
if (attacker.MapID == GuildPoleWar.Map.ID)
{
GuildPoleWar.Attack(damage, attacker, attacked);
}
}
#endregion

بعدين نفس الكلاس Handel ونبحث عن

public static bool CanAttack(Game.Entity attacker, SobNpcSpawn attacked, Database.SpellInformation spell)

ونضيف دا برضو

#region GuildPoleWar
if (GuildPoleWar.IsWar)
{
if (attacker.MapID == GuildPoleWar.Map.ID)
{
return GuildPoleWar.Attack(0, attacker, attacked);
}
}
#endregion
بعدين نعمل كلاس جديد نسميه GuildPoleWar.cs

ونضيف فيه دا

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Generic;
using MrHassan.Game;
using MrHassan;
using MrHassan.Network.GamePackets;
using MrHassan.Client;

namespace MrHassan.Game
{
public class GuildPoleWar
{
public const int Member = 0,
DeputyLeader = 1,
GuildLeader = 2;
public static uint UidPolaGuildLeader = 0;
public static uint UidPolaDubLeader = 0;
public static uint UidPolaMemberLeader = 0;
public static SobNpcSpawn[] Poles = new SobNpcSpawn[3];
public static uint[] PolesWinners = new uint[3];
public static SafeDictionary<uint, Entity>[] AllScores = new SafeDictionary<uint, Entity>[3];

public static DateTime WarStart;
public static Map Map;
public static bool IsWar = false;
public static bool claim1 = false;
public static bool claim2 = false;
public static bool claim3 = false;
public static IDisposable SubscriberMax;

public GuildPoleWar()
{
Map = Kernel.Maps[50016];
SubscriberMax = World.Subscribe(work, 1000);
}
public void work(int time)
{
if (IsWar)
{
if (Time32.Now > ScoreSendStamp.AddSeconds(3))
{
ScoreSendStamp = Time32.Now;
SendScores();
}
}
}
public static void Join(GameState client)
{
if (IsWar)
{
//var cooord = Map.RandomCoordinates();
client.Entity.Teleport(Map.ID, 315, 330);
client.OnDisconnect = p =>
{
p.Entity.Teleport(1002, 300, 278);
};
}
}

public static void StartWar()
{
try
{
IsWar = true;
WarStart = DateTime.Now;
Poles = new SobNpcSpawn[3];
PolesWinners = new uint[3];
claim1 = false;
claim2 = false;
claim3 = false;
Map.Statues.Clear();
Map.Npcs.Clear();
Start();
Summon("GuildLeader", 300, 288, GuildLeader);
Summon("DeputyLeader", 300, 268, DeputyLeader);
Summon("Member", 327, 266, Member);
}
catch (Exception ex)
{
//Program.SaveException(ex, true);
}
}

public static bool Attack(uint addScore, Entity entity, SobNpcSpawn Pole)
{
if (!IsWar)
return false;

int _rank = (int)Member;
if (entity.GuildRank == (ushort)Enums.GuildMemberRank.GuildLeader)
_rank = GuildLeader;
else if (entity.GuildRank == (ushort)Enums.GuildMemberRank.DeputyLeader)
_rank = DeputyLeader;

var pole = Poles[_rank];
if (pole != null)
{

if (pole != Pole)
return false;

if (PolesWinners[_rank] == entity.UID)
return false;

if (addScore > 0)
{

AddScore(addScore, entity, pole);
}

return true;
}
return false;
}
public static bool Attack2(Entity entity, SobNpcSpawn Pole)
{
if (!IsWar)
return false;

int _rank = (int)Member;
if (entity.GuildRank == (ushort)Enums.GuildMemberRank.GuildLeader)
_rank = GuildLeader;
else if (entity.GuildRank == (ushort)Enums.GuildMemberRank.DeputyLeader)
_rank = DeputyLeader;

var pole = Poles[_rank];
if (pole != null)
{

if (pole != Pole)
return false;

if (PolesWinners[_rank] == entity.UID)
return false;


return true;
}
return false;
}
public static void Summon(string Name, ushort X, ushort Y, int rank)
{

SobNpcSpawn Base = new SobNpcSpawn();
Base.UID = Map.EntityUIDCounter2.Next + 100;
Base.Mesh = 1137;
Base.Type = (Enums.NpcType)10;
Base.Sort = 21;
Base.ShowName = true;
Base.Name = Name;
Base.Hitpoints = Base.MaxHitpoints = 30000000;
Base.MapID = Map.ID;
Base.X = X;
Base.Y = Y;
Poles[rank] = Base;
if (!Map.Npcs.ContainsKey(Base.UID))
Map.Npcs.Add(Base.UID, Base);


}

#region Score

public static bool FirstRound = false;
public static Time32 ScoreSendStamp, LastWin;

public static void Start()
{
AllScores = new SafeDictionary<uint, Entity>[3];
WarStart = DateTime.Now;
FirstRound = true;
foreach (var c in Program.Values)
c.Entity.WarScore = 0;
IsWar = true;
}

public static void Reset(int _Class)
{
var rank = Enums.GuildMemberRank.Member;
if (_Class == DeputyLeader)
rank = Enums.GuildMemberRank.DeputyLeader;
if (_Class == GuildLeader)
rank = Enums.GuildMemberRank.GuildLeader;

foreach (var c in Program.Values.Where(p => p.Entity.GuildRank == (ushort)rank))
c.Entity.WarScore = 0;

IsWar = true;
}

public static void FinishRound(SobNpcSpawn Pole, int _Class, Entity PoleKeeper)
{
//Entity PoleKeeper;
LastWin = Time32.Now;
FirstRound = false;
SortScores(out PoleKeeper, _Class);
if (PoleKeeper != null)
{
Pole.Name = PoleKeeper.Name;
PolesWinners[_Class] = PoleKeeper.UID;
Pole.Hitpoints = Pole.MaxHitpoints;
if (PoleKeeper.GuildRank == (ushort)Enums.GuildMemberRank.GuildLeader)
{
UidPolaGuildLeader = PoleKeeper.UID;
}
else if (PoleKeeper.GuildRank == (ushort)Enums.GuildMemberRank.DeputyLeader)
{
UidPolaDubLeader = PoleKeeper.UID;
}
else
{
UidPolaMemberLeader = PoleKeeper.UID;
}
}

Pole.Hitpoints = Pole.MaxHitpoints;
foreach (var c in Program.Values)
{
if (c.Map.ID == Map.ID)
Pole.SendSpawn(c);
}

Reset(_Class);
}

public static void AddScore(uint addScore, Entity entity, SobNpcSpawn Pole)
{
if (entity != null)
{
int _rank = (int)Member;
if (entity.GuildRank == (ushort)Enums.GuildMemberRank.GuildLeader)
_rank = GuildLeader;
else if (entity.GuildRank == (ushort)Enums.GuildMemberRank.DeputyLeader)
_rank = DeputyLeader;

if (Pole.Hitpoints <= addScore)
Pole.Hitpoints = 0;

var Scores = AllScores[(ushort)((int)_rank)];
if (Scores == null)
Scores = AllScores[(ushort)((int)_rank)] = new SafeDictionary<uint, Entity>();

if (!Scores.ContainsKey(entity.UID))
Scores.Add(entity.UID, entity);
Pole.Hitpoints -= addScore;
entity.WarScore += addScore;

if ((int)Pole.Hitpoints <= 0)
{
FinishRound(Pole, (int)_rank, entity);
return;
}
}
}

public static void SendScores()
{
for (int i = 0; i < AllScores.Length; i++)
{
var Scores = AllScores[i];

if (Scores == null)
continue;
if (Scores.Count == 0)
continue;

Entity CurrentTopLeader;

var scoreMessages = SortScores(out CurrentTopLeader, i);
if (scoreMessages == null)
continue;
for (int c = 0; c < scoreMessages.Length; c++)
{
Message msg = new Message(scoreMessages[c], System.Drawing.Color.Red, c == 0 ? Message.FirstRightCorner : Message.ContinueRightCorner);
foreach (GameState client in Program.Values)
{
if (client != null)
{
if (client.Map.ID == Map.ID)
{
if (i == DeputyLeader)
{
if (client.Entity.GuildRank == (ushort)Enums.GuildMemberRank.DeputyLeader)
client.Send(msg);
}
else if (i == GuildLeader)
{
if (client.Entity.GuildRank == (ushort)Enums.GuildMemberRank.GuildLeader)
client.Send(msg);
}
else
{
if (client.Entity.GuildRank != (ushort)Enums.GuildMemberRank.GuildLeader && client.Entity.GuildRank != (ushort)Enums.GuildMemberRank.DeputyLeader)
client.Send(msg);
}
}
}
}
}
}
}

private static string[] SortScores(out Entity winner, int i)
{
winner = null;
List<string> ret = new List<string>();
int Place = 0;

var Scores = AllScores[i];
if (Scores == null) return new string[0];
foreach (var e in Scores.Values.OrderByDescending((p) => p.WarScore))
{
if (Place == 0)
winner = e;
string str = "No " + (Place + 1).ToString() + ": " + e.Name + "(" + e.WarScore + ")";
ret.Add(str);
Place++;
if (Place == 4)
break;
}

return ret.ToArray();
}
#endregion

public static void EndWar()
{
try
{
IsWar = false;
claim1 = true;
claim2 = true;
claim3 = true;
if (Map.Npcs != null)
Map.Npcs.Clear();

foreach (var client in Program.Values)
{
if (client.Entity.MapID == Map.ID)
{
client.Entity.Teleport(1002, 309, 260);
}
}

SubscriberMax.Dispose();
}
catch (Exception eee)
{
}

}
public static void GetReward(Client.GameState clienthoda, uint cps)
{
if (IsWar == false)
{
if (clienthoda.Entity.UID == UidPolaGuildLeader)
{
if (claim1 == true)
{

clienthoda.Entity.AddTopStatus((ulong)Update.Flags .TopGuildLeader, 1, DateTime.Now.AddDays(1));
UidPolaGuildLeader = 0;
clienthoda.Entity.ConquerPoints += cps;
claim1 = false;
}
}
else if (clienthoda.Entity.UID == UidPolaDubLeader)
{
if (claim2 == true)
{
clienthoda.Entity.AddTopStatus((ulong)Update.Flags .TopDeputyLeader, 1, DateTime.Now.AddDays(1));
UidPolaDubLeader = 0;

clienthoda.Entity.ConquerPoints += cps;
claim2 = false;
}
}
else if (clienthoda.Entity.UID == UidPolaMemberLeader)
{
if (claim3 == true)
{
UidPolaMemberLeader = 0;
clienthoda.Entity.ConquerPoints += cps;
claim3 = false;
}
}
}

}
}

}


ملحوظه لو جالك ايرور هتغيره لي اسم البروكت بتاعك وله جالك ايرور في Entity تحولها لي Player

بعدين كلاس ورلد ونبحث عن دا

public void CreateTournaments()

ونضيف فيه دا

new GuildPoleWar();

في الاخر نضيف دا في

private void WorldTournaments(int time)

#region GuildPoleWar
{
if (Now64.Minute == 01 && Now64.Second <= 00)
{
if (GuildPoleWar.IsWar == false)
{
GuildPoleWar.StartWar();
Kernel.SendWorldMessage(new Message("Guild Pole Pk War began !", Color.White, Message.BroadcastMessage), Program.Values);
foreach (var client in Program.Values)
client.MessageBox("Guild Pole began! Would you Like to join ...?",
p => { p.Entity.Teleport(1002, 310, 258); }, null, 60);
}
}
if (GuildPoleWar.IsWar)
{
if (Time32.Now > GuildPoleWar.ScoreSendStamp.AddSeconds(3))
{
GuildPoleWar.ScoreSendStamp = Time32.Now;
GuildPoleWar.SendScores();
}
}

if (Now64.Minute == 59 && Now64.Second == 59)
{
if (GuildPoleWar.IsWar == true)
{
GuildPoleWar.EndWar();
Kernel.SendWorldMessage(new Message("GuildPole war has ended.!", Color.White, Message.BroadcastMessage), Program.Values);

}
}
}
#endregion

اخر حاجه ال maps

اول حاجه 50016/1002/8192/0

محمد ياسر
2019-08-27, 08:49 PM
عاش

AhmedNasser
2019-08-28, 12:46 AM
عااش