|
المشاركات 150 |
+التقييم 0.08 |
تاريخ التسجيل Oct 2019 |
الاقامة |
نظام التشغيل |
رقم العضوية 2284 |
//Copyright MaZzGanGy 2019 - 2020
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaZzGanGy.Client;
using MaZzGanGy.Interfaces;
using MaZzGanGy.Network.GamePackets;
using System.Drawing;
using MaZzGanGy.Network;
using MaZzGanGy.Game.ConquerStructures;
using System.Threading.Generic;
using MaZzGanGy.Game.ConquerStructures.Society;
namespace MaZzGanGy.Game
{
public class WarOfPlayers
{
public static SobNpcSpawn Pole;
public static DateTime WarStart;
public static Map Map;
public static bool IsWar = false;
private IDisposable Subscriber;
public WarOfPlayers()
{
Map = Kernel.Maps[700].MakeDynamicMap();
Subscriber = World.Subscribe(work, 1000);
}
public void work(int time)
{
if (IsWar)
if (DateTime.Now > WarStart.AddMinutes(10))
EndWar();
if (DateTime.Now.Minute == 50 && !IsWar)
StartWar();
if (IsWar)
{
if (Time32.Now > ScoreSendStamp.AddSeconds(3))
{
ScoreSendStamp = Time32.Now;
SendScores();
}
}
}
public static void Join(Client.GameState client) //Make By MaZzGanGy
{
if (IsWar)
{
if (client.AsMember == null)
//client.MessageBox("Please Into in Guild First.");
return;
var cooord = Map.RandomCoordinates();
client.Entity.Teleport(Map.ID, 37, 50);
client.Entity.Teleport(Map.ID, 46, 37);
client.Entity.Teleport(Map.ID, 46, 46);
client.Entity.Teleport(Map.ID, 40, 40);
client.Entity.Teleport(Map.ID, 37, 40);
if (!Map.Floor[client.Entity.X, client.Entity.Y, Game.MapObjectType.Entity, 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(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;
//Database.DMaps.LoadMap(1002);
//Map = Kernel.Maps[1002].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(" WarOfPlayers War began ", Color.White, Message.BroadcastMessage), Program.Values);
foreach (var client in Program.Values)
client.MessageBox("You Want To Join WarOfPlayers and Got 50.000.000 Cps from the War ?",
p => { p.Entity.Teleport(1002, 300, 300); }, null, 60);
#region WarOfPlayersPole // BY MaZzGanGy
Pole = new Network.GamePackets.SobNpcSpawn();
Pole.UID = Map.EntityUIDCounter2.Next;
Pole.Mesh = 1137;
Pole.Type = (Enums.NpcType)10;
Pole.X = 50;
Pole.Y = 50;
Pole.ShowName = true;
Pole.Sort = 17;
Pole.Hitpoints = 20000000;
Pole.MaxHitpoints = 20000000;
Pole.Name = "WarOfPlayers";
Pole.MapID = Map.ID;
#endregion
Map.AddNpc(Pole);//.Npcs.Add(WarOfPlayersPole.UID, WarOfPlayersPole);
}
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()
{
Pole.Hitpoints = Pole.MaxHitpoints;
Update upd = new Update(true);
Kernel.SendWorldMessage(upd, Program.Values, (ushort)Map.ID);
upd.Clear();
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 WarOfPlayers round!", System.Drawing.Color.Red, Message.Center), Program.Values);
Pole.Name = PoleKeeper.Name;
if (PoleKeeper.Client != null)
{
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);
}
}
Pole.Hitpoints = Pole.MaxHitpoints;
// Kernel.SendWorldMessage(Pole, Program.GamePool, (ushort)Map.ID);
Reset();
foreach (var c in Program.Values)
if (c.Entity.MapID == Map.ID)
{
// c.SendScreenSpawn(Pole, true);
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<string> ret = new List<string>();
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 + " Winnar & WarOfPlayers End ", System.Drawing.Color.White, Message.Center), Program.Values);
}
else
{
Kernel.SendWorldMessage(new Message("No Winner at WarOfPlayers 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);
}
}
}
}
void ReceiveAttack(Game.Entity attacker, SobNpcSpawn attacked,
#region WarOfPlayers
if (Game.WarOfPlayers.IsWar)
{
if (attacker.MapID == Game.WarOfPlayers.Map.ID)
{
if (attacked.UID == Game.WarOfPlayers.Pole.UID)
{
if (Game.WarOfPlayers.PoleKeeper == attacker.Owner.AsMember)
return;
if (attacked.Hitpoints <= damage)
attacked.Hitpoints = 0;
Game.WarOfPlayers.AddScore(damage, attacker.Owner.AsMember);
}
}
}
#endregion TWin War
public static bool CanAttack(Game.Entity attacker, SobNpcSpawn attacked,
#region WarOfPlayers
if (Game.WarOfPlayers.IsWar)
{
if (attacker.MapID == Game.WarOfPlayers.Map.ID)
{
if (attacker.GuildID == 0 || !Game.WarOfPlayers.IsWar)
if (attacked.UID == Game.WarOfPlayers.Pole.UID)
return false;
if (Game.WarOfPlayers.PoleKeeper != null)
{
if (Game.WarOfPlayers.PoleKeeper == attacker.Owner.AsMember)
if (attacked.UID == Game.WarOfPlayers.Pole.UID)
return false;
if (Game.WarOfPlayers.PoleKeeper == attacker.Owner.AsMember)
if (attacker.PKMode == Enums.PKMode.Team)
return false;
}
}
}
#endregion Twinwar
public void Die(
#region WarOfPlayers
if (Game.WarOfPlayers.Map != null)
{
if (MapID == Game.WarOfPlayers.Map.ID)
{
if (UID != Game.WarOfPlayers.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);
}
}
}
#endregion
#region WarOfPlayers
case 411622:
{
switch (npcRequest.OptionID)
{
case 0:
{
dialog.Text("Hello there. Do you want to Join The WarOfPlayers?.");
dialog.Option("Yes Please.", 1);
dialog.Option("Cliam Prize.", 2);
dialog.Option("Just Passing By!", 255);
dialog.Send();
break;
}
case 1:
{
if (WarOfPlayers.IsWar)
{
WarOfPlayers.Join(client);
}
else
{
dialog.Text("The War Has Not Started Start [xx.50] : [xx.00] Every Hour");
dialog.Option("Aww ok!", 255);
dialog.Send();
}
break;
}
case 2:
{
if (WarOfPlayers.KeeperID != 0 && !WarOfPlayers.IsWar && WarOfPlayers.Claim && client.Entity.UID == WarOfPlayers.KeeperID)
{
WarOfPlayers.Claim = false;
WarOfPlayers.KeeperID = 0;
client.Entity.ConquerPoints += 50000000;
//client.Entity.BoundCps += 50000;
MaZzGanGy.Kernel.SendWorldMessage(new Message(" Congratulations ! " + client.Entity.Name + " has Claimed WarOfPlayers Prize [50.000.000] ConquerPoints", 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
void CreateTournaments()
new Game.WarOfPlayers();