|
|
المشاركات 126 |
+التقييم 0.05 |
تاريخ التسجيل Apr 2019 |
الاقامة |
نظام التشغيل |
رقم العضوية 47 |
using ConquerOnline.Client;
using ConquerOnline.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConquerOnline.Game
{
public class ArenaRoom
{
//All Rights Reserved © Ąbdṳallah Môhsen.
public static Counter RoomUID = new Counter(0);
public static SafeDictionary<uint, RoomInfo> FightersPool = new SafeDictionary<uint, RoomInfo>();
public static List<ushort> MapPool = new List<ushort>();
public class RoomInfo
{
public uint ChallengedCPS;
public uint FirstChallengerUID;
public uint SecondChallengerUID;
public uint RoomUID;
public Map Map;
public DateTime StartedIn;
public string OppName(uint UID)
{
string name = "";
if (Kernel.GamePool.ContainsKey(UID))
name = Kernel.GamePool[UID].Entity.Name;
return name;
}
public bool Exported = false, Canceled = false;
public GameClient FirstChallenger
{
get { return Kernel.GamePool.ContainsKey(FirstChallengerUID) ? Kernel.GamePool[FirstChallengerUID] : null; }
}
public GameClient SecondChallenger
{
get { return Kernel.GamePool.ContainsKey(SecondChallengerUID) ? Kernel.GamePool[SecondChallengerUID] : null; }
}
public bool AreReady { get { return FirstChallenger != null && SecondChallenger != null; }}
public void Disable()
{
Exported = true;
FightersPool.Remove(RoomUID);
if (Map != null)
Map.Dispose();
}
public void Cancel()
{
if (!Canceled && !Exported)
{
if (FirstChallenger != null)
{
FirstChallenger.Entity.ConquerPoints += ChallengedCPS;
FirstChallenger.Send("Your challange room has been canceled and your " + Kernel.NumberToWords(ChallengedCPS) + " cps have been restored.");
if (FirstChallenger.Entity.MapID == Map.ID)
FirstChallenger.Entity.Teleport(1002, 462, 312);
}
if (SecondChallenger != null)
{
SecondChallenger.Entity.ConquerPoints += ChallengedCPS;
SecondChallenger.Send("Your challange room has been canceled and your " + Kernel.NumberToWords(ChallengedCPS) + " cps have been restored.");
if (SecondChallenger.Entity.MapID == Map.ID)
SecondChallenger.Entity.Teleport(1002, 462, 312);
}
Canceled = true;
Disable();
}
}
}
public static void SendChallange(GameClient client, RoomInfo Info)
{
if (!RegistrationChallenger(client.Entity.UID))
{
GameClient Opponent;
if (Kernel.GamePool.TryGetValue(Info.SecondChallenger UID, out Opponent))
{
if (!RegistrationChallenger(Opponent.Entity.UID))
{
if (Kernel.GetDistance(Opponent.Entity.X, Opponent.Entity.Y, 461, 310) < 15)
{
if (client.Entity.ConquerPoints >= Info.ChallengedCPS)
{
Opponent.MessageBox(client.Entity.Name + " challenges you in an (1 vs 1) challenge, Do you agree to the challenge and pay " + Kernel.NumberToWords(Info.ChallengedCPS) + " CPS?", (p =>
{
if (Opponent.Entity.ConquerPoints >= Info.ChallengedCPS && client.Entity.ConquerPoints >= Info.ChallengedCPS)
{
Opponent.Entity.ConquerPoints -= Info.ChallengedCPS;
client.Entity.ConquerPoints -= Info.ChallengedCPS;
Opponent.OpponentUID = client.Entity.UID;
Info.StartedIn = DateTime.Now;
FightersPool.Add(Info.RoomUID, Info);
Import(Opponent);
Import(client);
new Database.NpcSpawns(36211, 54856, "Room Exit", Enums.NpcType.Talker, Info.Map.ID, 32, 37, Info.Map);
}
else client.MessageBox("You do not have that amount of cps to start the challange.");
}));
}
else client.MessageBox("You do not have that amount of cps to start the challange.");
}
else client.MessageBox("The opponent must be next to you now, but you can not send a challenge because he is far from Arena Room Master.");
}
else
{
client.MessageBox(Opponent.Entity.Name + " defies someone now, you can challenge him later.");
Opponent.MessageBox(client.Entity.Name + " tries to challenge you, but you are challenging now.");
}
}
}
}
public static void Import(GameClient Challenger)
{
RoomInfo info;
if (TryGetRoom(Challenger.Entity.UID, out info))
{
Challenger.Entity.Teleport(700, info.Map.ID, (ushort)Kernel.Random.Next(35, 70), (ushort)Kernel.Random.Next(35, 70));
Challenger.Entity.PrevPKMode = Challenger.Entity.PKMode;
Challenger.Entity.SetPKMode(Enums.PKMode.PK);
Challenger.Send("You have been signed in, waiting for your Opponent. Be ready!");
}
}
public static void CancelMyChallange(uint UID)
{
RoomInfo room;
if (TryGetRoom(UID, out room))
room.Cancel();
}
public static void Export(GameClient Winner, GameClient Loser)
{
RoomInfo room;
if (TryGetRoom(Winner.Entity.UID, out room))
{
if (!room.Exported && !room.Canceled)
{
Winner.Entity.Teleport(1002, 458, 313);
Loser.Entity.Teleport(1002, 463, 313);
Winner.Entity.SetPKMode(Winner.Entity.PrevPKMode);
Loser.Entity.SetPKMode(Loser.Entity.PrevPKMode);
if (Winner.Entity.MapID == 1002)
{
Winner.Entity.ConquerPoints += (room.ChallengedCPS * 2);
Logs.ArenaRooms((room.ChallengedCPS * 2), Winner, Loser.Entity.Name);
Network.GamePackets.Message.SendMessage(Winner.Ent ity.Name + " defeated " + Loser.Entity.Name + " in an 1 vs 1 challenge and got " + Kernel.NumberToWords((room.ChallengedCPS * 2)) + " CPS", Network.GamePackets.Message.ChatType.Center);
Loser.Send(new Arena.Arena.ArenaSignup() { DialogId = Arena.Arena.ArenaSignup.MainIDs.Dialog, OptionId = Arena.Arena.ArenaSignup.DialogButton.Lose }.BuildPacket());
Winner.Send(new Arena.Arena.ArenaSignup() { DialogId = Arena.Arena.ArenaSignup.MainIDs.Dialog, OptionId = Arena.Arena.ArenaSignup.DialogButton.Win }.BuildPacket());
}
room.Exported = true;
room.Disable();
Winner.OpponentUID = 0;
Loser.OpponentUID = 0;
Winner.Entity.BringToLife();
Loser.Entity.BringToLife();
MsgTournaments.MainBase.RemoveNpc(room.Map.ID, 36211);
}
}
}
public static bool TryGetRoom(uint UID, out RoomInfo Info)
{
Info = FightersPool.Values.Where(f => f.FirstChallengerUID == UID || f.SecondChallengerUID == UID).FirstOrDefault();
return Info != null;
}
public static bool RegistrationChallenger(uint UID)
{
return FightersPool.Values.Where(f => f.FirstChallengerUID == UID || f.SecondChallengerUID == UID).FirstOrDefault() != null;
}
}
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
بعدك كدا هنروح على فوت ونضيف دا
//Player Die
if (ArenaRoom.RegistrationChallenger(UID) && ArenaRoom.RegistrationChallenger(killer.UID))
{
ArenaRoom.RoomInfo room;
if (ArenaRoom.TryGetRoom(UID, out room))
{
if (!room.Exported)
{
if (killer.MapID == room.Map.ID && Owner.Entity.MapID == room.Map.ID)
{
ArenaRoom.Export(killer.Owner, Owner);
}
}
}
}
//Npcs
#region Room Master
case 36210:
{
dialog.Avatar(14);
switch (OptionID)
{
case 0:
{
dialog.Text("Of course you see yourself as a hero because you are here, how can I help you?");
if (!ArenaRoom.RegistrationChallenger(client.Entity.UID))
dialog.Option("New challenge.", 1);
else
dialog.Option("My challenges.", 4);
dialog.Option("Informations.", 3)
.Option("Just passing by.")
.Send();
break;
}
case 1:
{
dialog.Text("Please enter a Opponent name that you would like to challenge")
.Input("Opponent Name", 2, 13)
.Option("Just passing by")
.Send();
break;
}
case 2:
{
GameClient Opponent = Kernel.GamePool.Values.Where(u => u.Entity.Name == npcRequest.Input).FirstOrDefault();
if (Opponent != null)
{
dialog.Text("You have been chosen for " + Opponent.Entity.Name + " to challenge him, you must now set the bet.").Input("CPS Amount", 3, 13).Option("Just passing by").Send();
client.OpponentUID = Opponent.Entity.UID;
}
else dialog.Text("You have typed a Opponent name that is not correct, or he is offline.").Option("Try again", 1).Send();
break;
}
case 3:
{
uint cpsAmount;
if (uint.TryParse(npcRequest.Input, out cpsAmount) && cpsAmount > 0)
{
client.MessageBox("Are you sure to start the challenge and pay " + Kernel.NumberToWords(cpsAmount) + " CPS?", (p =>
{
if (client.Entity.ConquerPoints >= cpsAmount)
{
if (client.OpponentUID > 0)
{
if (client.Entity.UID != client.OpponentUID)
{
ArenaRoom.SendChallange(client, new ArenaRoom.RoomInfo()
{
FirstChallengerUID = client.Entity.UID,
SecondChallengerUID = client.OpponentUID,
ChallengedCPS = cpsAmount,
RoomUID = ArenaRoom.RoomUID.Next,
Map = Kernel.Maps[700].MakeDynamicMap()
});
}
else dialog.Text("You can not challenge yourself?.").Option("Sorry.").Send();
}
}
}));
}
break;
}
case 4:
{
if (client.OpponentUID == 0)
{
ArenaRoom.CancelMyChallange(client.Entity.UID);
dialog.Text("You do not have any challanges!").Option("Alright.").Send();
}
else
{
ArenaRoom.RoomInfo room;
if (ArenaRoom.TryGetRoom(client.Entity.UID, out room))
{
dialog.Text("Your current challange vs " + room.OppName(client.OpponentUID) + ", Are you ready to start this challage?")
.Option("Lets start.", 5)
.Option("Cancel this challange.", 6)
.Option("Later.")
.Send();
}
}
break;
}
case 5:
{
ArenaRoom.RoomInfo room;
if (ArenaRoom.TryGetRoom(client.Entity.UID, out room))
{
if (room.AreReady)
ArenaRoom.Import(client);
else
dialog.Text("Your Opponent is not online!").Option("Alright.").Send();
}
else
dialog.Text("You do not have any challanges!").Option("Alright.").Send();
break;
}
case 6:
{
ArenaRoom.CancelMyChallange(client.Entity.UID);
dialog.Text("You do not have any challanges!").Option("Alright.").Send();
break;
}
}
break;
}
case 36211:
{
dialog.Avatar(14);
switch (OptionID)
{
case 0:
{
dialog.Text("Hi~" + client.Entity.Name + ",~Do you want to leave and take your cps.\n");
dialog.Option("Yes.", 1);
dialog.Option("No, I'll stay here.");
dialog.Send();
break;
}
case 1:
{
ArenaRoom.CancelMyChallange(client.Entity.UID);
break;
}
}
break;
}
#endregion