Modernization Fixes & Updates to Default Values (#3)

This commit is contained in:
Kamron Batman 2018-10-28 00:33:16 -07:00 • committed by GitHub
parent 445eddff68
commit dcf64091b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
768 changed files with 10507 additions and 14196 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Server.Gumps;
using Server.Items;
@ -15,7 +16,7 @@ namespace Server.Engines.ConPVP
private BRGame m_Game;
private ArrayList m_Helpers;
private List<Mobile> m_Helpers;
private Point3DList m_Path = new Point3DList();
private int m_PathIdx;
@ -29,7 +30,7 @@ namespace Server.Engines.ConPVP
m_Game = game;
m_Helpers = new ArrayList();
m_Helpers = new List<Mobile>();
m_Timer = new EffectTimer(this);
m_Timer.Start();
@ -230,7 +231,7 @@ namespace Server.Engines.ConPVP
private void DoAnim(Point3D start, Point3D end, Map map)
{
Effects.SendMovingEffect(new Entity(Serial.Zero, start, map), new Entity(Serial.Zero, end, map),
ItemID, 15, 0, false, false, Hue, 0);
ItemID, 15, 0, false, false, Hue);
}
private void DoCatch(Mobile m)
@ -270,29 +271,21 @@ namespace Server.Engines.ConPVP
dest = swap;
}*/
ArrayList list = new ArrayList();
double rise, run, zslp;
double dist3d, dist2d;
double x, y, z;
int xd, yd, zd;
Point3D p;
List<Point3D> list = new List<Point3D>();
xd = dest.X - org.X;
yd = dest.Y - org.Y;
zd = dest.Z - org.Z;
dist2d = Math.Sqrt(xd * xd + yd * yd);
if (zd != 0)
dist3d = Math.Sqrt(dist2d * dist2d + zd * zd);
else
dist3d = dist2d;
int xd = dest.X - org.X;
int yd = dest.Y - org.Y;
int zd = dest.Z - org.Z;
double dist2d = Math.Sqrt(xd * xd + yd * yd);
double dist3d = zd == 0 ? dist2d : Math.Sqrt(dist2d * dist2d + zd * zd);
rise = yd / dist3d;
run = xd / dist3d;
zslp = zd / dist3d;
double rise = yd / dist3d;
double run = xd / dist3d;
double zslp = zd / dist3d;
x = org.X;
y = org.Y;
z = org.Z;
double x = org.X;
double y = org.Y;
double z = org.Z;
while (Utility.NumberBetween(x, dest.X, org.X, 0.5) && Utility.NumberBetween(y, dest.Y, org.Y, 0.5) &&
Utility.NumberBetween(z, dest.Z, org.Z, 0.5))
{
@ -302,7 +295,7 @@ namespace Server.Engines.ConPVP
if (list.Count > 0)
{
p = (Point3D)list[list.Count - 1];
Point3D p = list[list.Count - 1];
if (p.X != ix || p.Y != iy || p.Z != iz)
list.Add(new Point3D(ix, iy, iz));
@ -317,9 +310,8 @@ namespace Server.Engines.ConPVP
z += zslp;
}
if (list.Count > 0)
if ((Point3D)list[list.Count - 1] != dest)
list.Add(dest);
if (list.Count > 0 && list[list.Count - 1] != dest)
list.Add(dest);
/*if ( dist3d > 4 && ( dest.X != org.X || dest.Y != org.Y ) )
{
@ -359,7 +351,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < count; i++)
{
p = (Point3D)list[i];
Point3D p = list[i];
int xp = i - count / 2;
@ -371,7 +363,7 @@ namespace Server.Engines.ConPVP
m_Path.Clear();
for (int i = 0; i < list.Count; i++)
m_Path.Add((Point3D)list[i]);
m_Path.Add(list[i]);
m_PathIdx = 0;
@ -616,7 +608,7 @@ namespace Server.Engines.ConPVP
for (int i = m_Helpers.Count - 1; i >= 0; i--)
{
Mobile mob = (Mobile)m_Helpers[i];
Mobile mob = m_Helpers[i];
BRPlayerInfo pi = team[mob];
if (pi != null)
@ -661,7 +653,7 @@ namespace Server.Engines.ConPVP
if (m_Helpers.Count > 0)
{
Mobile last = (Mobile)m_Helpers[0];
Mobile last = m_Helpers[0];
if (m_Game.GetTeamInfo(last) != team)
m_Helpers.Clear();
@ -951,7 +943,7 @@ namespace Server.Engines.ConPVP
{
if (m_TeamInfo?.Game != null)
{
from.CloseGump(typeof(BRBoardGump));
from.CloseGump<BRBoardGump>();
from.SendGump(new BRBoardGump(from, m_TeamInfo.Game));
}
}
@ -983,16 +975,17 @@ namespace Server.Engines.ConPVP
{
}
public BRBoardGump(Mobile mob, BRGame game, BRTeamInfo section)
: base(60, 60)
public BRBoardGump(Mobile mob, BRGame game, BRTeamInfo section) : base(60, 60)
{
m_Game = game;
BRTeamInfo ourTeam = game.GetTeamInfo(mob);
ArrayList entries = new ArrayList();
List<BRTeamInfo> entries = new List<BRTeamInfo>();
int total = 0;
if (section == null)
{
for (int i = 0; i < game.Context.Participants.Count; ++i)
{
BRTeamInfo teamInfo = game.Controller.TeamInfo[i % game.Controller.TeamInfo.Length];
@ -1002,17 +995,15 @@ namespace Server.Engines.ConPVP
entries.Add(teamInfo);
}
total = entries.Count;
}
else
foreach (BRPlayerInfo player in section.Players.Values)
if (player.Score > 0)
entries.Add(player);
total++;
entries.Sort();
/*
delegate( IRankedCTF a, IRankedCTF b )
{
return b.Score - a.Score;
} );*/
int height = 0;
@ -1027,7 +1018,7 @@ namespace Server.Engines.ConPVP
AddImageTiled(16, 15, 369, height - 29, 3604);
for (int i = 0; i < entries.Count; i += 1)
for (int i = 0; i < total; i += 1)
AddImageTiled(22, 58 + i * 75, 357, 70, 0x2430);
AddAlphaRegion(16, 15, 369, height - 29);
@ -1043,7 +1034,7 @@ namespace Server.Engines.ConPVP
if (section == null)
for (int i = 0; i < entries.Count; ++i)
{
BRTeamInfo teamInfo = entries[i] as BRTeamInfo;
BRTeamInfo teamInfo = entries[i];
AddImage(30, 70 + i * 75, 10152);
AddImage(30, 85 + i * 75, 10151);
@ -1208,20 +1199,20 @@ namespace Server.Engines.ConPVP
}
[PropertyObject]
public sealed class BRTeamInfo : IRankedCTF, IComparable
public sealed class BRTeamInfo : IRankedCTF, IComparable<BRTeamInfo>
{
private BRGoal m_Goal;
public BRTeamInfo(int teamID)
{
TeamID = teamID;
Players = new Hashtable();
Players = new Dictionary<Mobile, BRPlayerInfo>();
}
public BRTeamInfo(int teamID, GenericReader ip)
{
TeamID = teamID;
Players = new Hashtable();
Players = new Dictionary<Mobile, BRPlayerInfo>();
int version = ip.ReadEncodedInt();
@ -1247,7 +1238,7 @@ namespace Server.Engines.ConPVP
[CommandProperty(AccessLevel.GameMaster)]
public BRBoard Board{ get; set; }
public Hashtable Players{ get; }
public Dictionary<Mobile, BRPlayerInfo> Players{ get; }
public BRPlayerInfo this[Mobile mob]
{
@ -1281,9 +1272,8 @@ namespace Server.Engines.ConPVP
}
}
public int CompareTo(object obj)
public int CompareTo(BRTeamInfo ti)
{
BRTeamInfo ti = (BRTeamInfo)obj;
int res = ti.Captures.CompareTo(Captures);
if (res == 0)
{
@ -1367,32 +1357,16 @@ namespace Server.Engines.ConPVP
public BRTeamInfo[] TeamInfo{ get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public BRTeamInfo Team1
{
get => TeamInfo[0];
set { }
}
public BRTeamInfo Team1 => TeamInfo[0];
[CommandProperty(AccessLevel.GameMaster)]
public BRTeamInfo Team2
{
get => TeamInfo[1];
set { }
}
public BRTeamInfo Team2 => TeamInfo[1];
[CommandProperty(AccessLevel.GameMaster)]
public BRTeamInfo Team3
{
get => TeamInfo[2];
set { }
}
public BRTeamInfo Team3 => TeamInfo[2];
[CommandProperty(AccessLevel.GameMaster)]
public BRTeamInfo Team4
{
get => TeamInfo[3];
set { }
}
public BRTeamInfo Team4 => TeamInfo[3];
[CommandProperty(AccessLevel.GameMaster)]
public TimeSpan Duration{ get; set; }
@ -1515,7 +1489,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
Participant p = m_Context.Participants[i] as Participant;
Participant p = m_Context.Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
if (p.Players[j] != null)
@ -1566,19 +1540,12 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse });
Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
}
private void DelayBounce_Callback(object state)
private void DelayBounce_Callback(Mobile mob, Container corpse)
{
object[] states = (object[])state;
Mobile mob = (Mobile)states[0];
Container corpse = (Container)states[1];
DuelPlayer dp = null;
if (mob is PlayerMobile mobile)
dp = mobile.DuelPlayer;
DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null;
m_Context.RemoveAggressions(mob);
@ -1631,7 +1598,7 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump(typeof(BRBoardGump));
mob.CloseGump<BRBoardGump>();
mob.SendGump(new BRBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -1651,7 +1618,7 @@ namespace Server.Engines.ConPVP
}
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant,
ApplyHues(m_Context.Participants[i],
Controller.TeamInfo[i % Controller.TeamInfo.Length].Color);
m_FinishTimer?.Stop();
@ -1664,51 +1631,49 @@ namespace Server.Engines.ConPVP
private void Finish_Callback()
{
ArrayList teams = new ArrayList();
List<BRTeamInfo> teams = new List<BRTeamInfo>();
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
BRTeamInfo teamInfo = Controller.TeamInfo[i % Controller.TeamInfo.Length];
if (teamInfo == null)
continue;
teams.Add(teamInfo);
if (teamInfo != null)
teams.Add(teamInfo);
}
teams.Sort();
Tournament tourny = m_Context.m_Tournament;
Tournament tourney = m_Context.m_Tournament;
StringBuilder sb = new StringBuilder();
if (tourny != null && tourny.TournyType == TournyType.FreeForAll)
if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll)
{
sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant);
sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant);
sb.Append("-man FFA");
}
else if (tourny != null && tourny.TournyType == TournyType.RandomTeam)
else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam)
{
sb.Append(tourny.ParticipantsPerMatch);
sb.Append(tourney.ParticipantsPerMatch);
sb.Append("-team");
}
else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue)
else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue)
{
sb.Append("Red v Blue");
}
else if (tourny != null && tourny.TournyType == TournyType.Faction)
else if (tourney != null && tourney.TourneyType == TourneyType.Faction)
{
sb.Append(tourny.ParticipantsPerMatch);
sb.Append(tourney.ParticipantsPerMatch);
sb.Append("-team Faction");
}
else if (tourny != null)
else if (tourney != null)
{
for (int i = 0; i < tourny.ParticipantsPerMatch; ++i)
for (int i = 0; i < tourney.ParticipantsPerMatch; ++i)
{
if (sb.Length > 0)
sb.Append('v');
sb.Append(tourny.PlayersPerParticipant);
sb.Append(tourney.PlayersPerParticipant);
}
}
@ -1717,7 +1682,7 @@ namespace Server.Engines.ConPVP
string title = sb.ToString();
BRTeamInfo winner = (BRTeamInfo)(teams.Count > 0 ? teams[0] : null);
BRTeamInfo winner = teams.Count > 0 ? teams[0] : null;
for (int i = 0; i < teams.Count; ++i)
{
@ -1728,9 +1693,9 @@ namespace Server.Engines.ConPVP
else if (i == 1)
rank = TrophyRank.Silver;
BRPlayerInfo leader = ((BRTeamInfo)teams[i]).Leader;
BRPlayerInfo leader = teams[i].Leader;
foreach (BRPlayerInfo pl in ((BRTeamInfo)teams[i]).Players.Values)
foreach (BRPlayerInfo pl in teams[i].Players.Values)
{
Mobile mob = pl.Player;
@ -1767,7 +1732,7 @@ namespace Server.Engines.ConPVP
if (pl == leader)
item.ItemID = 4810;
item.Name = $"{item.Name}, {((BRTeamInfo)teams[i]).Name.ToLower()} team";
item.Name = $"{item.Name}, {teams[i].Name.ToLower()} team";
if (!mob.PlaceInBackpack(item))
mob.BankBox.DropItem(item);
@ -1804,7 +1769,7 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump(typeof(BRBoardGump));
dp.Mobile.CloseGump<BRBoardGump>();
dp.Mobile.SendGump(new BRBoardGump(dp.Mobile, this));
}
}
@ -1818,7 +1783,7 @@ namespace Server.Engines.ConPVP
p.Players[j].Eliminated = true;
}
m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant);
m_Context.Finish(m_Context.Participants[winner.TeamID]);
}
public override void OnStop()
@ -1838,10 +1803,10 @@ namespace Server.Engines.ConPVP
m_Bomb?.Delete();
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant, -1);
ApplyHues(m_Context.Participants[i], -1);
m_FinishTimer?.Stop();
m_FinishTimer = null;
}
}
}
}

View file

@ -31,7 +31,7 @@ namespace Server.Engines.ConPVP
{
if (m_TeamInfo?.Game != null)
{
from.CloseGump(typeof(CTFBoardGump));
from.CloseGump<CTFBoardGump>();
from.SendGump(new CTFBoardGump(from, m_TeamInfo.Game));
}
}
@ -58,12 +58,7 @@ namespace Server.Engines.ConPVP
private CTFGame m_Game;
public CTFBoardGump(Mobile mob, CTFGame game)
: this(mob, game, null)
{
}
public CTFBoardGump(Mobile mob, CTFGame game, CTFTeamInfo section)
public CTFBoardGump(Mobile mob, CTFGame game, CTFTeamInfo section = null)
: base(60, 60)
{
m_Game = game;
@ -719,60 +714,28 @@ namespace Server.Engines.ConPVP
public CTFTeamInfo[] TeamInfo{ get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team1
{
get => TeamInfo[0];
set { }
}
public CTFTeamInfo Team1 => TeamInfo[0];
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team2
{
get => TeamInfo[1];
set { }
}
public CTFTeamInfo Team2 => TeamInfo[1];
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team3
{
get => TeamInfo[2];
set { }
}
public CTFTeamInfo Team3 => TeamInfo[2];
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team4
{
get => TeamInfo[3];
set { }
}
public CTFTeamInfo Team4 => TeamInfo[3];
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team5
{
get => TeamInfo[4];
set { }
}
public CTFTeamInfo Team5 => TeamInfo[4];
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team6
{
get => TeamInfo[5];
set { }
}
public CTFTeamInfo Team6 => TeamInfo[5];
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team7
{
get => TeamInfo[6];
set { }
}
public CTFTeamInfo Team7 => TeamInfo[6];
[CommandProperty(AccessLevel.GameMaster)]
public CTFTeamInfo Team8
{
get => TeamInfo[7];
set { }
}
public CTFTeamInfo Team8 => TeamInfo[7];
[CommandProperty(AccessLevel.GameMaster)]
public TimeSpan Duration{ get; set; }
@ -876,7 +839,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
Participant p = m_Context.Participants[i] as Participant;
Participant p = m_Context.Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
if (p.Players[j] != null)
@ -932,19 +895,12 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse });
Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
}
private void DelayBounce_Callback(object state)
private void DelayBounce_Callback(Mobile mob, Container corpse)
{
object[] states = (object[])state;
Mobile mob = (Mobile)states[0];
Container corpse = (Container)states[1];
DuelPlayer dp = null;
if (mob is PlayerMobile mobile)
dp = mobile.DuelPlayer;
DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null;
m_Context.RemoveAggressions(mob);
@ -1027,7 +983,7 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump(typeof(CTFBoardGump));
mob.CloseGump<CTFBoardGump>();
mob.SendGump(new CTFBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -1047,7 +1003,7 @@ namespace Server.Engines.ConPVP
}
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant, Controller.TeamInfo[i % 8].Color);
ApplyHues(m_Context.Participants[i], Controller.TeamInfo[i % 8].Color);
m_FinishTimer?.Stop();
@ -1070,37 +1026,37 @@ namespace Server.Engines.ConPVP
teams.Sort(delegate(CTFTeamInfo a, CTFTeamInfo b) { return b.Score - a.Score; });
Tournament tourny = m_Context.m_Tournament;
Tournament tourney = m_Context.m_Tournament;
StringBuilder sb = new StringBuilder();
if (tourny != null && tourny.TournyType == TournyType.FreeForAll)
if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll)
{
sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant);
sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant);
sb.Append("-man FFA");
}
else if (tourny != null && tourny.TournyType == TournyType.RandomTeam)
else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam)
{
sb.Append(tourny.ParticipantsPerMatch);
sb.Append(tourney.ParticipantsPerMatch);
sb.Append("-team");
}
else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue)
else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue)
{
sb.Append("Red v Blue");
}
else if (tourny != null && tourny.TournyType == TournyType.Faction)
else if (tourney != null && tourney.TourneyType == TourneyType.Faction)
{
sb.Append(tourny.ParticipantsPerMatch);
sb.Append(tourney.ParticipantsPerMatch);
sb.Append("-team Faction");
}
else if (tourny != null)
else if (tourney != null)
{
for (int i = 0; i < tourny.ParticipantsPerMatch; ++i)
for (int i = 0; i < tourney.ParticipantsPerMatch; ++i)
{
if (sb.Length > 0)
sb.Append('v');
sb.Append(tourny.PlayersPerParticipant);
sb.Append(tourney.PlayersPerParticipant);
}
}
@ -1193,7 +1149,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
Participant p = m_Context.Participants[i] as Participant;
Participant p = m_Context.Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
{
@ -1201,7 +1157,7 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump(typeof(CTFBoardGump));
dp.Mobile.CloseGump<CTFBoardGump>();
dp.Mobile.SendGump(new CTFBoardGump(dp.Mobile, this));
}
}
@ -1214,7 +1170,7 @@ namespace Server.Engines.ConPVP
p.Players[j].Eliminated = true;
}
m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant);
m_Context.Finish(m_Context.Participants[winner.TeamID]);
}
public override void OnStop()
@ -1236,7 +1192,7 @@ namespace Server.Engines.ConPVP
}
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant, -1);
ApplyHues(m_Context.Participants[i], -1);
m_FinishTimer?.Stop();

View file

@ -29,7 +29,7 @@ namespace Server.Engines.ConPVP
{
if (m_TeamInfo?.Game != null)
{
from.CloseGump(typeof(DDBoardGump));
from.CloseGump<DDBoardGump>();
from.SendGump(new DDBoardGump(from, m_TeamInfo.Game));
}
}
@ -389,18 +389,10 @@ namespace Server.Engines.ConPVP
public DDTeamInfo[] TeamInfo{ get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public DDTeamInfo Team1
{
get => TeamInfo[0];
set { }
}
public DDTeamInfo Team1 => TeamInfo[0];
[CommandProperty(AccessLevel.GameMaster)]
public DDTeamInfo Team2
{
get => TeamInfo[1];
set { }
}
public DDTeamInfo Team2 => TeamInfo[1];
[CommandProperty(AccessLevel.GameMaster)]
public DDWayPoint PointA{ get; set; }
@ -501,7 +493,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
Participant p = m_Context.Participants[i] as Participant;
Participant p = m_Context.Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
if (p.Players[j] != null)
@ -552,19 +544,12 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse });
Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
}
private void DelayBounce_Callback(object state)
private void DelayBounce_Callback(Mobile mob, Container corpse)
{
object[] states = (object[])state;
Mobile mob = (Mobile)states[0];
Container corpse = (Container)states[1];
DuelPlayer dp = null;
if (mob is PlayerMobile mobile)
dp = mobile.DuelPlayer;
DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null;
m_Context.RemoveAggressions(mob);
@ -613,7 +598,7 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump(typeof(DDBoardGump));
mob.CloseGump<DDBoardGump>();
mob.SendGump(new DDBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -653,7 +638,7 @@ namespace Server.Engines.ConPVP
Controller.PointB.Game = this;
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant,
ApplyHues(m_Context.Participants[i],
Controller.TeamInfo[i % Controller.TeamInfo.Length].Color);
m_FinishTimer?.Stop();
@ -674,37 +659,37 @@ namespace Server.Engines.ConPVP
teams.Sort((a, b) => b.Score - a.Score);
Tournament tourny = m_Context.m_Tournament;
Tournament tourney = m_Context.m_Tournament;
StringBuilder sb = new StringBuilder();
if (tourny != null && tourny.TournyType == TournyType.FreeForAll)
if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll)
{
sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant);
sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant);
sb.Append("-man FFA");
}
else if (tourny != null && tourny.TournyType == TournyType.RandomTeam)
else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam)
{
sb.Append(tourny.ParticipantsPerMatch);
sb.Append(tourney.ParticipantsPerMatch);
sb.Append("-team");
}
else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue)
else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue)
{
sb.Append("Red v Blue");
}
else if (tourny != null && tourny.TournyType == TournyType.Faction)
else if (tourney != null && tourney.TourneyType == TourneyType.Faction)
{
sb.Append(tourny.ParticipantsPerMatch);
sb.Append(tourney.ParticipantsPerMatch);
sb.Append("-team Faction");
}
else if (tourny != null)
else if (tourney != null)
{
for (int i = 0; i < tourny.ParticipantsPerMatch; ++i)
for (int i = 0; i < tourney.ParticipantsPerMatch; ++i)
{
if (sb.Length > 0)
sb.Append('v');
sb.Append(tourny.PlayersPerParticipant);
sb.Append(tourney.PlayersPerParticipant);
}
}
@ -797,7 +782,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
Participant p = m_Context.Participants[i] as Participant;
Participant p = m_Context.Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
{
@ -805,7 +790,7 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump(typeof(DDBoardGump));
dp.Mobile.CloseGump<DDBoardGump>();
dp.Mobile.SendGump(new DDBoardGump(dp.Mobile, this));
}
}
@ -818,7 +803,7 @@ namespace Server.Engines.ConPVP
p.Players[j].Eliminated = true;
}
m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant);
m_Context.Finish(m_Context.Participants[winner.TeamID]);
}
public override void OnStop()
@ -854,7 +839,7 @@ namespace Server.Engines.ConPVP
}
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant, -1);
ApplyHues(m_Context.Participants[i], -1);
m_FinishTimer?.Stop();
m_FinishTimer = null;

View file

@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Server.Gumps;
using Server.Items;
@ -170,12 +171,10 @@ namespace Server.Engines.ConPVP
private void ReKingify(Mobile m)
{
KHTeamInfo ti = null;
if (m_Game == null || m == null)
return;
ti = m_Game.GetTeamInfo(m);
if (ti == null)
if (m_Game.GetTeamInfo(m) == null)
return;
King = m;
@ -216,7 +215,6 @@ namespace Server.Engines.ConPVP
protected override void OnTick()
{
KHTeamInfo ti = null;
KHPlayerInfo pi = null;
if (m_Hill == null || m_Hill.Deleted || m_Hill.Game == null)
@ -232,7 +230,7 @@ namespace Server.Engines.ConPVP
return;
}
ti = m_Hill.Game.GetTeamInfo(m_Hill.King);
KHTeamInfo ti = m_Hill.Game.GetTeamInfo(m_Hill.King);
if (ti != null)
pi = ti[m_Hill.King];
@ -251,11 +249,9 @@ namespace Server.Engines.ConPVP
if (m_Counter >= m_Hill.ScoreInterval)
{
string hill = m_Hill.Name;
string king = m_Hill.King.Name;
if (king == null)
king = "";
string king = m_Hill.King.Name ?? "";
if (hill == null || hill == "")
if (string.IsNullOrEmpty(hill))
hill = "the hill";
m_Hill.Game.Alert("{0} ({1}) is king of {2}!", king, ti.Name, hill);
@ -315,7 +311,7 @@ namespace Server.Engines.ConPVP
{
if (m_Game != null)
{
from.CloseGump(typeof(KHBoardGump));
from.CloseGump<KHBoardGump>();
from.SendGump(new KHBoardGump(from, m_Game));
}
else
@ -364,16 +360,14 @@ namespace Server.Engines.ConPVP
KHTeamInfo ourTeam = game.GetTeamInfo(mob);
ArrayList entries = new ArrayList();
List<KHTeamInfo> entries = new List<KHTeamInfo>();
for (int i = 0; i < game.Context.Participants.Count; ++i)
{
KHTeamInfo teamInfo = game.Controller.TeamInfo[i % game.Controller.TeamInfo.Length];
if (teamInfo == null)
continue;
entries.Add(teamInfo);
if (teamInfo != null)
entries.Add(teamInfo);
}
entries.Sort();
@ -408,7 +402,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < entries.Count; ++i)
{
KHTeamInfo teamInfo = entries[i] as KHTeamInfo;
KHTeamInfo teamInfo = entries[i];
AddImage(30, 70 + i * 75, 10152);
AddImage(30, 85 + i * 75, 10151);
@ -505,7 +499,7 @@ namespace Server.Engines.ConPVP
}
}
public sealed class KHPlayerInfo : IRankedCTF, IComparable
public sealed class KHPlayerInfo : IRankedCTF, IComparable<KHPlayerInfo>
{
private int m_Captures;
@ -521,30 +515,18 @@ namespace Server.Engines.ConPVP
public Mobile Player{ get; }
public int CompareTo(object obj)
public int CompareTo(KHPlayerInfo pi)
{
KHPlayerInfo pi = (KHPlayerInfo)obj;
int res = pi.Score.CompareTo(Score);
if (res == 0)
{
res = pi.Captures.CompareTo(Captures);
if (res != 0)
return res;
if (res == 0)
res = pi.Kills.CompareTo(Kills);
}
res = pi.Captures.CompareTo(Captures);
return res;
return res != 0 ? res : pi.Kills.CompareTo(Kills);
}
public string Name
{
get
{
if (Player?.Name == null)
return "";
return Player.Name;
}
}
public string Name => Player.Name ?? "";
public int Kills
{
@ -586,13 +568,13 @@ namespace Server.Engines.ConPVP
public KHTeamInfo(int teamID)
{
TeamID = teamID;
Players = new Hashtable();
Players = new Dictionary<Mobile, KHPlayerInfo>();
}
public KHTeamInfo(int teamID, GenericReader ip)
{
TeamID = teamID;
Players = new Hashtable();
Players = new Dictionary<Mobile, KHPlayerInfo>();
int version = ip.ReadEncodedInt();
@ -613,7 +595,7 @@ namespace Server.Engines.ConPVP
public KHPlayerInfo Leader{ get; set; }
public Hashtable Players{ get; }
public Dictionary<Mobile, KHPlayerInfo> Players{ get; }
public KHPlayerInfo this[Mobile mob]
{
@ -706,7 +688,7 @@ namespace Server.Engines.ConPVP
Name = "King of the Hill Controller";
Duration = TimeSpan.FromMinutes(30.0);
Boards = new ArrayList();
Boards = new List<KHBoard>();
Hills = new HillOfTheKing[4];
TeamInfo = new KHTeamInfo[8];
@ -722,60 +704,28 @@ namespace Server.Engines.ConPVP
public KHTeamInfo[] TeamInfo{ get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team1_W
{
get => TeamInfo[0];
set { }
}
public KHTeamInfo Team1_W => TeamInfo[0];
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team2_E
{
get => TeamInfo[1];
set { }
}
public KHTeamInfo Team2_E => TeamInfo[1];
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team3_N
{
get => TeamInfo[2];
set { }
}
public KHTeamInfo Team3_N => TeamInfo[2];
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team4_S
{
get => TeamInfo[3];
set { }
}
public KHTeamInfo Team4_S => TeamInfo[3];
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team5_NW
{
get => TeamInfo[4];
set { }
}
public KHTeamInfo Team5_NW => TeamInfo[4];
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team6_SE
{
get => TeamInfo[5];
set { }
}
public KHTeamInfo Team6_SE => TeamInfo[5];
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team7_SW
{
get => TeamInfo[6];
set { }
}
public KHTeamInfo Team7_SW => TeamInfo[6];
[CommandProperty(AccessLevel.GameMaster)]
public KHTeamInfo Team8_NE
{
get => TeamInfo[7];
set { }
}
public KHTeamInfo Team8_NE => TeamInfo[7];
public HillOfTheKing[] Hills{ get; private set; }
@ -807,7 +757,7 @@ namespace Server.Engines.ConPVP
set => Hills[3] = value;
}
public ArrayList Boards{ get; private set; }
public List<KHBoard> Boards{ get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public TimeSpan Duration{ get; set; }
@ -873,7 +823,7 @@ namespace Server.Engines.ConPVP
Duration = reader.ReadTimeSpan();
Boards = reader.ReadItemList();
Boards = reader.ReadStrongItemList<KHBoard>();
Hills = new HillOfTheKing[reader.ReadEncodedInt()];
for (int i = 0; i < Hills.Length; ++i)
@ -893,8 +843,7 @@ namespace Server.Engines.ConPVP
{
private Timer m_FinishTimer;
public KHGame(KHController controller, DuelContext context)
: base(context)
public KHGame(KHController controller, DuelContext context) : base(context)
{
Controller = controller;
}
@ -928,7 +877,7 @@ namespace Server.Engines.ConPVP
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
Participant p = m_Context.Participants[i] as Participant;
Participant p = m_Context.Participants[i];
for (int j = 0; j < p.Players.Length; ++j)
if (p.Players[j] != null)
@ -979,19 +928,12 @@ namespace Server.Engines.ConPVP
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
{
Timer.DelayCall(ts, new TimerStateCallback(DelayBounce_Callback), new object[] { mob, corpse });
Timer.DelayCall(ts, () => DelayBounce_Callback(mob, corpse));
}
private void DelayBounce_Callback(object state)
private void DelayBounce_Callback(Mobile mob, Container corpse)
{
object[] states = (object[])state;
Mobile mob = (Mobile)states[0];
Container corpse = (Container)states[1];
DuelPlayer dp = null;
if (mob is PlayerMobile mobile)
dp = mobile.DuelPlayer;
DuelPlayer dp = mob is PlayerMobile mobile ? mobile.DuelPlayer : null;
m_Context.RemoveAggressions(mob);
@ -1045,7 +987,7 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump(typeof(KHBoardGump));
mob.CloseGump<KHBoardGump>();
mob.SendGump(new KHBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -1065,7 +1007,7 @@ namespace Server.Engines.ConPVP
}
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant,
ApplyHues(m_Context.Participants[i],
Controller.TeamInfo[i % Controller.TeamInfo.Length].Color);
m_FinishTimer?.Stop();
@ -1083,46 +1025,44 @@ namespace Server.Engines.ConPVP
private void Finish_Callback()
{
ArrayList teams = new ArrayList();
List<KHTeamInfo> teams = new List<KHTeamInfo>();
for (int i = 0; i < m_Context.Participants.Count; ++i)
{
KHTeamInfo teamInfo = Controller.TeamInfo[i % Controller.TeamInfo.Length];
if (teamInfo == null)
continue;
teams.Add(teamInfo);
if (teamInfo != null)
teams.Add(teamInfo);
}
teams.Sort();
Tournament tourny = m_Context.m_Tournament;
Tournament tourney = m_Context.m_Tournament;
StringBuilder sb = new StringBuilder();
if (tourny != null && tourny.TournyType == TournyType.FreeForAll)
if (tourney != null && tourney.TourneyType == TourneyType.FreeForAll)
{
sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant);
sb.Append(m_Context.Participants.Count * tourney.PlayersPerParticipant);
sb.Append("-man FFA");
}
else if (tourny != null && tourny.TournyType == TournyType.RandomTeam)
else if (tourney != null && tourney.TourneyType == TourneyType.RandomTeam)
{
sb.Append(tourny.ParticipantsPerMatch);
sb.Append(tourney.ParticipantsPerMatch);
sb.Append("-team");
}
else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue)
else if (tourney != null && tourney.TourneyType == TourneyType.RedVsBlue)
{
sb.Append("Red v Blue");
}
else if (tourny != null)
else if (tourney != null)
{
for (int i = 0; i < tourny.ParticipantsPerMatch; ++i)
for (int i = 0; i < tourney.ParticipantsPerMatch; ++i)
{
if (sb.Length > 0)
sb.Append('v');
sb.Append(tourny.PlayersPerParticipant);
sb.Append(tourney.PlayersPerParticipant);
}
}
@ -1131,7 +1071,7 @@ namespace Server.Engines.ConPVP
string title = sb.ToString();
KHTeamInfo winner = (KHTeamInfo)(teams.Count > 0 ? teams[0] : null);
KHTeamInfo winner = teams.Count > 0 ? teams[0] : null;
for (int i = 0; i < teams.Count; ++i)
{
@ -1142,9 +1082,9 @@ namespace Server.Engines.ConPVP
else if (i == 1)
rank = TrophyRank.Silver;
KHPlayerInfo leader = ((KHTeamInfo)teams[i]).Leader;
KHPlayerInfo leader = teams[i].Leader;
foreach (KHPlayerInfo pl in ((KHTeamInfo)teams[i]).Players.Values)
foreach (KHPlayerInfo pl in teams[i].Players.Values)
{
Mobile mob = pl.Player;
@ -1182,7 +1122,7 @@ namespace Server.Engines.ConPVP
if (pl == leader)
item.ItemID = 4810;
item.Name = $"{item.Name}, {((KHTeamInfo)teams[i]).Name.ToLower()}";
item.Name = $"{item.Name}, {teams[i].Name.ToLower()}";
if (!mob.PlaceInBackpack(item))
mob.BankBox.DropItem(item);
@ -1219,21 +1159,22 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump(typeof(KHBoardGump));
dp.Mobile.CloseGump<KHBoardGump>();
dp.Mobile.SendGump(new KHBoardGump(dp.Mobile, this));
}
}
if (i == winner.TeamID)
if (i == winner?.TeamID)
continue;
if (p?.Players != null)
if (p.Players != null)
for (int j = 0; j < p.Players.Length; ++j)
if (p.Players[j] != null)
p.Players[j].Eliminated = true;
}
m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant);
if (winner != null)
m_Context.Finish(m_Context.Participants[winner.TeamID]);
}
public override void OnStop()
@ -1250,10 +1191,10 @@ namespace Server.Engines.ConPVP
board.m_Game = null;
for (int i = 0; i < m_Context.Participants.Count; ++i)
ApplyHues(m_Context.Participants[i] as Participant, -1);
ApplyHues(m_Context.Participants[i], -1);
m_FinishTimer?.Stop();
m_FinishTimer = null;
}
}
}
}

View file

@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Text;
using Server.Network;
namespace Server.Engines.ConPVP
{
public class TourneyMatch
{
public TourneyMatch(List<TourneyParticipant> participants)
{
Participants = participants;
for (int i = 0; i < participants.Count; ++i)
{
TourneyParticipant part = participants[i];
StringBuilder sb = new StringBuilder();
sb.Append("Matched in a duel against ");
if (participants.Count > 2)
sb.AppendFormat("{0} other {1}: ", participants.Count - 1,
part.Players.Count == 1 ? "players" : "teams");
bool hasAppended = false;
for (int j = 0; j < participants.Count; ++j)
{
if (i == j)
continue;
if (hasAppended)
sb.Append(", ");
sb.Append(participants[j].NameList);
hasAppended = true;
}
sb.Append(".");
part.AddLog(sb.ToString());
}
}
public List<TourneyParticipant> Participants{ get; set; }
public TourneyParticipant Winner{ get; set; }
public DuelContext Context{ get; set; }
public bool InProgress => Context != null && Context.Registered;
public void Start(Arena arena, Tournament tourney)
{
TourneyParticipant first = Participants[0];
DuelContext dc = new DuelContext(first.Players[0], tourney.Ruleset.Layout, false);
dc.Ruleset.Options.SetAll(false);
dc.Ruleset.Options.Or(tourney.Ruleset.Options);
for (int i = 0; i < Participants.Count; ++i)
{
TourneyParticipant tourneyPart = Participants[i];
Participant duelPart = new Participant(dc, tourneyPart.Players.Count)
{
TourneyPart = tourneyPart
};
for (int j = 0; j < tourneyPart.Players.Count; ++j)
duelPart.Add(tourneyPart.Players[j]);
for (int j = 0; j < duelPart.Players.Length; ++j)
if (duelPart.Players[j] != null)
duelPart.Players[j].Ready = true;
dc.Participants.Add(duelPart);
}
if (tourney.EventController != null)
dc.m_EventGame = tourney.EventController.Construct(dc);
dc.m_Tournament = tourney;
dc.m_Match = this;
dc.m_OverrideArena = arena;
if (tourney.SuddenDeath > TimeSpan.Zero &&
(tourney.SuddenDeathRounds == 0 || tourney.Pyramid.Levels.Count <= tourney.SuddenDeathRounds))
dc.StartSuddenDeath(tourney.SuddenDeath);
dc.SendReadyGump(0);
if (dc.StartedBeginCountdown)
{
Context = dc;
for (int i = 0; i < Participants.Count; ++i)
{
TourneyParticipant p = Participants[i];
for (int j = 0; j < p.Players.Count; ++j)
{
Mobile mob = p.Players[j];
foreach (Mobile view in mob.GetMobilesInRange(18))
if (!mob.CanSee(view))
mob.Send(view.RemovePacket);
mob.LocalOverheadMessage(MessageType.Emote, 0x3B2, false,
"* Your mind focuses intently on the fight and all other distractions fade away *");
}
}
}
else
{
dc.Unregister();
dc.StopCountdown();
}
}
}
}