شرح : أضافة حرب StatusWar Full 100% - ابداع كونكر - Conquer

شرح : أضافة حرب StatusWar Full 100%

النهاردا ان شاء الله هشرح أضافة حرب StatuesWar لكل السورسات

وهطبق الشرح علي سورس TroZenA ولو بتستخدم سورس تاني هقولك

مكان أضافة الأكواد لو النظام عندك مختلف .

أولا : كلاس الحرب هتعمل كلاس بأسم StatuesWar

في فولدر Game

وبدل الاكواد دي بالي فيه

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TroZenA.Client;
using TroZenA.Interfaces;
using TroZenA.Network.GamePackets;
using System.Drawing;
using TroZenA.Network;
using TroZenA.Game.ConquerStructures;
using System.Threading.Generic;
using TroZenA.Game.ConquerStructures.Society;

namespace TroZenA.Game
{
    public class StatuesWar
    {
        public static SobNpcSpawn RightGate, LeftGate, Pole;
        public static DateTime WarStart;
        public static Map Map;
        public static bool IsWar = false;
        private IDisposable Subscriber;

        public StatuesWar()
        {
            Subscriber = World.Subscribe(work, 1000);

        }
        public void work(int time)
        {
            if (IsWar)
                if (DateTime.Now > WarStart.AddMinutes(60))
                    EndWar();

            if (TroZenA_Times.Start.StatuesWar && !IsWar)
                StartWar();

            if (IsWar)
            {
                if (Time32.Now > ScoreSendStamp.AddSeconds(3))
                {
                    ScoreSendStamp = Time32.Now;
                    SendScores();
                }
            }


        }
        public static void Join(Client.GameClient client)
        {
            if (IsWar)
            {
                if (client.AsMember == null)
                    return;
                var cooord = Map.RandomCoordinates();
                client.Entity.Teleport(Map.ID, 292, 187);
                client.Entity.Teleport(Map.ID, 224, 210);
                client.Entity.Teleport(Map.ID, 162, 139);
                if (!Map.Floor[client.Entity.X, client.Entity.Y, Game.MapObjectType.Player, null])
                {
                    client.Entity.PKMode = Game.Enums.PKMode.PK;
                    client.Send(new Data(true) { UID = client.Entity.UID, ID = Data.ChangePKMode, dwParam = (uint)client.Entity.PKMode });
                }

                client.Send(RightGate);
                client.Send(LeftGate);
                client.Send(Pole);
                client.OnDisconnect = p =>
                {
                    p.Entity.Teleport(1002, 300, 278);
                };
            }
        }

        public static void StartWar()
        {
            try
            {
                if (IsWar)
                    EndWar();
                PoleKeeper = null;
                IsWar = true;
                WarStart = DateTime.Now;
                Map = Kernel.Maps[3868].MakeDynamicMap();
                if (!Kernel.Maps.ContainsKey(Map.ID))
                    Kernel.Maps.Add(Map.ID, Map);
                if (!Database.MapsTable.MapInformations.ContainsKey(Map.ID))
                    Database.MapsTable.MapInformations.Add(Map.ID, new Database.MapsTable.MapInformation() { ID = Map.ID, BaseID = Map.BaseID });
                Constants.PKForbiddenMaps.Remove(Map.ID);
                Constants.PKFreeMaps.Add(Map.ID);
                Kernel.SendWorldMessage(new Message("StatuesWar War began [Prize : 5.000 ] Cps!", Color.White, Message.BroadcastMessage), Program.Values);
                foreach (var client in Program.Values)
                    client.MessageBox("You Want To Join StatuesWar and  Got Cps from the War [Prize : 5.000] Cps!",
                            p => { p.Entity.Teleport(1002, 295, 167); }, null, 60);
                #region RightGate
                LeftGate = new Network.GamePackets.SobNpcSpawn();
                LeftGate.UID = 84523;
                LeftGate.Mesh = 277;
                LeftGate.Type = (Enums.NpcType)26;
                LeftGate.X = (ushort)282;
                LeftGate.Y = (ushort)143;
                LeftGate.Hitpoints = 10000000;
                LeftGate.MaxHitpoints = 10000000;
                LeftGate.MapID = Map.ID;
                LeftGate.Mesh = (ushort)(240 + LeftGate.Mesh % 10);
                #endregion
                #region LeftGate
                RightGate = new Network.GamePackets.SobNpcSpawn();
                RightGate.UID = 84524;
                RightGate.Mesh = 277;
                RightGate.Type = (Enums.NpcType)26;
                RightGate.X = (ushort)175;
                RightGate.Y = (ushort)138;
                RightGate.Hitpoints = 10000000;
                RightGate.MaxHitpoints = 10000000;
                RightGate.MapID = Map.ID;
                #endregion
                #region StatuesPole
                Pole = new Network.GamePackets.SobNpcSpawn();
                Pole.UID = Map.EntityUIDCounter2.Next;
                Pole.Mesh = 1137;
                Pole.Type = (Enums.NpcType)10;
                Pole.X = 222;
                Pole.Y = 131;
                Pole.ShowName = true;
                Pole.Sort = 17;
                Pole.Hitpoints = 20000000;
                Pole.MaxHitpoints = 20000000;
                Pole.Name = "Statues-War";
                Pole.MapID = Map.ID;
                #endregion
                Map.AddNpc(LeftGate);//.Npcs.Add(LeftGate.UID, LeftGate);
                Map.AddNpc(RightGate);//.Npcs.Add(RightGate.UID, RightGate);
                Map.AddNpc(Pole);//.Npcs.Add(StatuesPole.UID, StatuesPole);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Program.SaveException(ex);
            }
        }

        #region Score
        public static SafeDictionary<uint, Guild.Member> Scores = new SafeDictionary<uint, Guild.Member>(100);
        public static Guild.Member PoleKeeper, CurrentTopLeader;
        private static bool changed = false;
        private static string[] scoreMessages;
        public static bool FirstRound = false;
        public static Time32 ScoreSendStamp, LastWin;
        public static bool Claim
        {
            get { return Program.Vars["stwclaim"]; }
            set { Program.Vars["stwclaim"] = value; }
        }
        public static uint KeeperID
        {
            get { return Program.Vars["stwkeeperid"]; }
            set { Program.Vars["stwkeeperid"] = value; }
        }
        public static void Start()
        {
            Scores = new SafeDictionary<uint, Guild.Member>(1000);
            WarStart = DateTime.Now;
            FirstRound = true;
            foreach (Guild Guild in Kernel.Guilds.Values)
            {
                foreach (Guild.Member member in Guild.Members.Values)
                    member.WarScore = 0;
            }
            Claim = false;
            IsWar = true;
        }

        public static void Reset()
        {
            LeftGate.Mesh = (ushort)(240 + LeftGate.Mesh % 10);
            RightGate.Mesh = (ushort)(270 + LeftGate.Mesh % 10);

            LeftGate.Hitpoints = LeftGate.MaxHitpoints;
            RightGate.Hitpoints = RightGate.MaxHitpoints;
            Pole.Hitpoints = Pole.MaxHitpoints;

            Update upd = new Update(true);
            upd.UID = LeftGate.UID;
            upd.Append(Update.Mesh, LeftGate.Mesh);
            upd.Append(Update.Hitpoints, LeftGate.Hitpoints);
            Kernel.SendWorldMessage(upd, Program.Values, (ushort)Map.ID);
            upd.Clear();
            upd.UID = RightGate.UID;
            upd.Append(Update.Mesh, RightGate.Mesh);
            upd.Append(Update.Hitpoints, RightGate.Hitpoints);
            Kernel.SendWorldMessage(upd, Program.Values, (ushort)Map.ID);

            foreach (Guild Guild in Kernel.Guilds.Values)
            {
                foreach (Guild.Member member in Guild.Members.Values)
                    member.WarScore = 0;
            }

            IsWar = true;
        }

        public static void FinishRound()
        {
            LastWin = Time32.Now;

            FirstRound = false;
            SortScores(out PoleKeeper);
            if (PoleKeeper != null)
            {
                KeeperID = PoleKeeper.ID;
                Kernel.SendWorldMessage(new Message("" + PoleKeeper.Name + " Win At StatueWar Around!", System.Drawing.Color.Red, Message.Center), Program.Values);

                Pole.Name = PoleKeeper.Name;
                if (PoleKeeper.Client != null)
                {
                    byte[] _buffer = new byte[PoleKeeper.Client.Entity.SpawnPacket.Length];
                    Buffer.BlockCopy(PoleKeeper.Client.Entity.SpawnPacket, 0, _buffer, 0, PoleKeeper.Client.Entity.SpawnPacket.Length);
                    Pole.SpawnPacket = _buffer;

                    Map.Statues.Clear();
                    Map.Npcs.Clear();

                    Map.Npcs.Add(Pole.UID, Pole);
                    if (!Map.Statues.ContainsKey(Pole.UID))
                        Map.Statues.Add(Pole.UID, Pole);


                    Game.Statue statue = new Statue(PoleKeeper.Client.Entity.SpawnPacket, 105176, Enums.ConquerAction.Cool, (byte)Enums.ConquerAngle.SouthWest, 327, 336, true);
                    statue = new Statue(PoleKeeper.Client.Entity.SpawnPacket, 105177, Enums.ConquerAction.Wave, (byte)Enums.ConquerAngle.SouthEast, 381, 260, true);

                    for (int i = 0; i < 2; i++)
                    {
                        SobNpcSpawn Base = new SobNpcSpawn();
                        Base.Owner = PoleKeeper.Client;
                        Base.SpawnPacket = _buffer;
                        Base.UID = Map.EntityUIDCounter2.Next;
                        Base.Mesh = 1003;
                        Base.Type = Enums.NpcType.Stake;
                        Base.Sort = 21;
                        Base.ShowName = true;
                        Base.Name = PoleKeeper.Client.Entity.Name;
                        Base.Hitpoints = Base.MaxHitpoints = 2000000;
                        Base.MapID = Map.ID;
                        switch (i)
                        {
                            case 0:
                                Base.X = 310;
                                Base.Y = 335;
                                break;
                            case 1:
                                Base.X = 385;
                                Base.Y = 255;
                                break;
                        }
                        if (!Map.Statues.ContainsKey(Base.UID))
                            Map.Statues.Add(Base.UID, Base);
                        if (!Map.Npcs.ContainsKey(Base.UID))
                            Map.Npcs.Add(Base.UID, Base);
                    }
                }
            }
            Pole.Hitpoints = Pole.MaxHitpoints;
            Reset();
            foreach (var c in Program.Values)
                if (c.Entity.MapID == Map.ID)
                {
                    c.Screen.FullWipe();
                    c.Screen.Reload(null);
                }


        }

        public static void AddScore(uint addScore, Guild.Member Guild)
        {
            if (Guild != null)
            {
                Guild.WarScore += addScore;
                changed = true;
                if (!Scores.ContainsKey(Guild.ID))
                    Scores.Add(Guild.ID, Guild);
                if ((int)Pole.Hitpoints <= 0)
                {
                    FinishRound();
                    return;
                }
            }
        }

        public static void SendScores()
        {
            if (scoreMessages == null)
                scoreMessages = new string[0];
            if (Scores.Count == 0)
                return;
            if (changed)
                SortScores(out CurrentTopLeader);

            for (int c = 0; c < scoreMessages.Length; c++)
            {
                Message msg = new Message(scoreMessages[c], System.Drawing.Color.Red, c == 0 ? Message.FirstRightCorner : Message.ContinueRightCorner);
                Kernel.SendWorldMessage(msg, Program.Values, (ushort)Map.ID);
            }
        }

        private static void SortScores(out Guild.Member winner)
        {
            winner = null;
            List ret = new List();
            int Place = 0;
            foreach (Guild.Member Guild in Scores.Values.OrderByDescending((p) => p.WarScore))
            {
                if (Place == 0)
                    winner = Guild;
                string str = "No  " + (Place + 1).ToString() + ": " + Guild.Name + "(" + Guild.WarScore + ")";
                ret.Add(str);
                Place++;
                if (Place == 4)
                    break;
            }

            changed = false;
            scoreMessages = ret.ToArray();
        }
        #endregion
        public static void EndWar()
        {
            try
            {
                if (PoleKeeper != null)
                {
                    Kernel.SendWorldMessage(new Message(PoleKeeper.Name + " StatueWar End !", System.Drawing.Color.White, Message.Center), Program.Values);

                }
                else
                {
                    Kernel.SendWorldMessage(new Message("No Winner at STatueWar and ended!", System.Drawing.Color.Red, Message.Center), Program.Values);

                }
                Claim = true;
                IsWar = false;
                foreach (var client in Program.Values)
                    if (client.Entity.MapID == Map.ID)
                        client.Entity.Teleport(1002, 300, 278);
                if (!Database.MapsTable.MapInformations.ContainsKey(Map.ID))
                    Database.MapsTable.MapInformations.Remove(Map.ID);
                Map.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Program.SaveException(ex);
            }

        }
    }
}

هتفتح PacketHandler ولو سورسك مختلف هتلاقي الاوامر في GameClient or GameState

هتبحث عن

case "hairstyle":

فوقه حط الكود دا عشان تشغل الحرب بالشفره وقت ما تحب

 case "statueswar":
                                {
                                    switch (Data[1])
                                    {
                                        case "on":
                                            {
                                                if (!StatuesWar.IsWar)
                                                {
                                                    StatuesWar.Start();
                                                    foreach (var client2 in Kernel.GamePool.Values)
                                                    {
                                                        client2.Send(new Message("Statues War Starts", System.Drawing.Color.Red, Network.GamePackets.Message.BroadcastMessage));
                                                    }
                                                }
                                                break;
                                            }
                                        case "off":
                                            {
                                                if (!StatuesWar.IsWar)
                                                {
                                                    StatuesWar.EndWar();
                                                    foreach (var client2 in Kernel.GamePool.Values)
                                                    {
                                                        client2.Send(new Message("Statues War Ended", System.Drawing.Color.Red, Network.GamePackets.Message.BroadcastMessage));
                                                    }
                                                }
                                                break;
                                            }
                                    }
                                    break;
                                }

ودا الانبسي

#region StatuesWar
                    case 41162:
                        {
                            switch (npcRequest.OptionID)
                            {
                                case 0:
                                    {
                                        dialog.Text("Hello there. Do you want to Join The StatuesWar?.");
                                        dialog.Option("Yes Please.", 1);
                                        dialog.Option("Cliam Prize.", 2);
                                        dialog.Option("Just Passing By!", 255);
                                        dialog.Send();
                                        break;
                                    }
                                case 1:
                                    {
                                        if (StatuesWar.IsWar)
                                            {
                                                Random R = new Random();
                                                int Nr = R.Next(1, 4);
                                                if (Nr == 1) client.Entity.Teleport(3868, 292, 187);
                                                if (Nr == 2) client.Entity.Teleport(3868, 224, 210);
                                                if (Nr == 3) client.Entity.Teleport(3868, 162, 139);
                                                if (Nr == 4) client.Entity.Teleport(3868, 162, 139);
                                            }
                                        else
                                        {
                                            dialog.Text("The War Has Not Started Start [17.00] Every Thursday");
                                            dialog.Option("Aww ok!", 255);
                                            dialog.Send();
                                        }
                                        break;
                                    }
                                case 2:
                                    {
                                        if (StatuesWar.KeeperID != 0 && !StatuesWar.IsWar && StatuesWar.Claim && client.Entity.UID == StatuesWar.KeeperID)
                                        {
                                            StatuesWar.Claim = false;
                                            StatuesWar.KeeperID = 0;
                                            client.Entity.ConquerPoints += 20000;
                                            client.Entity.AddTopStatus(Update.Flags2.Top2Monk, 2, DateTime.Now.AddDays(1));
                                            TroZenA.Kernel.SendWorldMessage(new Message("Congratulations! " + client.Entity.Name + "  has Claimed StatuesWar Prize [ 20k cps ] !", System.Drawing.Color.White, Message.Center), Program.Values);
                                        }
                                        else
                                        {
                                            dialog.Text("Sorry you dont have Any Prize to claim only CL of the winner guild can claim Prize After CW");
                                            dialog.Option("Ahh.", 255);
                                            dialog.Send();
                                        }

                                        break;
                                    }
                            }
                            break;
                        }
                    #endregion

افتح World ابحث عن

public void CreateTournaments()

وحط الكود دا تحته

new Game.StatuesWar();

ركز بقا في الي جاي هتفتح Handle.cs

وهتلاقيه في المسار دا Game\Attacking

هتبحث عن الكود دا

if (attacker.MapID == 1509)

هتحط فوقه دا

 #region StatuesWar
            if (Game.StatuesWar.IsWar)
            {
                if (Game.StatuesWar.Pole != null)
                {
                    if (attacker.MapID == 3868 && attacked.UID == 3091995)
                    {
                        if (Game.StatuesWar.PoleKeeper == attacker.Owner.AsMember)
                            return;
                        if (attacked.Hitpoints <= damage)
                            attacked.Hitpoints = 0;
                        Game.StatuesWar.AddScore(damage, attacker.Owner.AsMember);
                    }
                }
            }
            #endregion TWin War

وهتبحث عن الفويد دا

public static bool CanAttack(

وانزل تحت مثلا لحد الكود دا أو اي كود شبهه

if (attacker.MapID == 1507)

وحط فوقه الكود دا

 #region StatueWar
            if (Game.StatuesWar.IsWar)
            {
                if (attacker.MapID == Game.StatuesWar.Map.ID)
                {
                    if (attacker.GuildID == 0 || !Game.StatuesWar.IsWar)
                        if (attacked.UID == Game.StatuesWar.Pole.UID)
                            return false;
                    if (Game.StatuesWar.PoleKeeper != null)
                    {
                        if (Game.StatuesWar.PoleKeeper == attacker.Owner.AsMember)
                            if (attacked.UID == Game.StatuesWar.Pole.UID)
                                return false;
                        if (Game.StatuesWar.PoleKeeper == attacker.Owner.AsMember)
                            if (attacker.PKMode == Enums.PKMode.Team)
                                return false;

                    }
                }
            }
            #endregion Twinwar

بعد كدا هتبحث عن كلاس SobNpcSpawn

class SobNpcSpawn : Writer,

ابحث فيه عن

public void Die(Game.Entity killer)

تحته حط الكود دا

 #region StatuesWar
            if (Game.StatuesWar.Map != null)
            {
                if (MapID == Game.StatuesWar.Map.ID)
                {
                    if (UID != Game.StatuesWar.Pole.UID)
                    {
                        if (Hitpoints != 0 || Mesh != 251 && Mesh != 281)
                        {
                            if (Mesh == 241)
                                Mesh = (ushort)(250 + Mesh % 10);
                            else
                                Mesh = (ushort)(280 + Mesh % 10);

                            Update upd = new Update(true);
                            upd.UID = UID;
                            upd.Append(Update.Mesh, Mesh);
                            killer.Owner.SendScreen(upd, true);
                            Hitpoints = 0;
                        }
                        Attack attack = new Attack(true);
                        attack.Attacker = killer.UID;
                        attack.Attacked = UID;
                        attack.AttackType = Network.GamePackets.Attack.Kill;
                        attack.X = X;
                        attack.Y = Y;
                        killer.Owner.Send(attack);
                        killer.KOCount++;
                    }
                }
            }
            #endregion

خلصنا الاضافه نعرف السورس عليه بقا ونشيل الايرور

هتفتح كلاس Guild.cs

class Guild : Writer

ابحث عن الكود دا

public uint CTFCpsReward

تحته ضيف الكود دا

public uint WarScore;

بعدين هنبحث عن

class SobNpcSpawn : Writer

تحته هنحط الكود دا

public byte[] SpawnPacket;

بعد كدا ابحث عن الكود دا

public Dictionary<uint, INpc> Npcs;

تحته ضيف

public Dictionary<uint, INpc> Statues = new Dictionary<uint, INpc>();

وكدا مبقاش عندك أي ايرور ان شاء الله 🙂

وعشان نشطب وتبقا كدا الحرب كامله 100% ان شاء الله هنرفع دا في النافي كات

و دا كود النافي كات يضلف في sobnpcs

3091995    Statues-War    10    1137    3868    222    131    20000000    20000000    24    17    1    0

وطبعآ معاد الحرب الساعه 5 كل يوم وتقدر تغيرو من الكود دا

public static bool StatuesWar
            {
                get
                {
                    return (now.DayOfWeek == DayOfWeek.Thursday && now.Hour == 17 && now.Minute == 0);
                }
            }

وهتلاقيه في Program

في رعاية الله

12 thoughts on “شرح : أضافة حرب StatusWar Full 100%”

أضف تعليق

قوانين المدونة & عن تيم تهيس