public override void CheckForGameEnd() { if (Participants == null || !GameInProgress) { return; } int leftstanding = 0; Mobile winner = null; foreach (IChallengeEntry entry in Participants) { // either being the last participant left if (entry.Status == ChallengeStatus.Active) { leftstanding++; winner = entry.Participant; } // or reaching the target score if (entry.Score >= TargetScore) { winner = entry.Participant; leftstanding = 1; break; } } // and then check to see if this is the King of the Hill if (leftstanding == 1 && winner != null) { // declare the winner and end the game XmlPoints.SendText(winner, 100311, ChallengeName); // "You have won {0}" Winner = winner; RefreshSymmetricNoto(winner); GameBroadcast(100312, winner.Name); // "The winner is {0}" AwardWinnings(winner, TotalPurse); EndGame(); KingOfTheHillGump.RefreshAllGumps(this, true); } if (leftstanding < 1) { // declare a tie and keep the fees GameBroadcast(100313); // "The match is a draw" EndGame(); KingOfTheHillGump.RefreshAllGumps(this, true); } }
public void CheckForDisqualification() { if (Participants == null || !GameInProgress) { return; } bool statuschange = false; foreach (IChallengeEntry entry in Participants) { if (entry.Participant == null || entry.Status == ChallengeStatus.Forfeit || entry.Status == ChallengeStatus.Disqualified) { continue; } bool hadcaution = (entry.Caution != ChallengeStatus.None); // and a map check if (entry.Participant.Map != Map) { // check to see if they are offline if (entry.Participant.Map == Map.Internal) { // then give them a little time to return before disqualification if (entry.Caution == ChallengeStatus.Offline) { // were previously out of bounds so check for disqualification // check to see how long they have been out of bounds if (DateTime.Now - entry.LastCaution > MaximumOfflineDuration) { entry.Status = ChallengeStatus.Disqualified; GameBroadcast(100308, entry.Participant.Name); // "{0} has been disqualified" RefreshSymmetricNoto(entry.Participant); statuschange = true; } } else { entry.LastCaution = DateTime.Now; statuschange = true; } entry.Caution = ChallengeStatus.Offline; } else { // changing to any other map is instant disqualification entry.Status = ChallengeStatus.Disqualified; GameBroadcast(100308, entry.Participant.Name); // "{0} has been disqualified" RefreshSymmetricNoto(entry.Participant); statuschange = true; } } else // make a range check if (m_ArenaSize > 0 && !Utility.InRange(entry.Participant.Location, Location, m_ArenaSize) || (IsInChallengeGameRegion && !(Region.Find(entry.Participant.Location, entry.Participant.Map) is ChallengeGameRegion))) { if (entry.Caution == ChallengeStatus.OutOfBounds) { // were previously out of bounds so check for disqualification // check to see how long they have been out of bounds if (DateTime.Now - entry.LastCaution > MaximumOutOfBoundsDuration) { entry.Status = ChallengeStatus.Disqualified; GameBroadcast(100308, entry.Participant.Name); // "{0} has been disqualified" RefreshSymmetricNoto(entry.Participant); statuschange = true; } } else { entry.LastCaution = DateTime.Now; // inform the player XmlPoints.SendText(entry.Participant, 100309, MaximumOutOfBoundsDuration.TotalSeconds); // "You are out of bounds! You have {0} seconds to return" statuschange = true; } entry.Caution = ChallengeStatus.OutOfBounds; } else // make a hiding check if (entry.Participant.Hidden) { if (entry.Caution == ChallengeStatus.Hidden) { // were previously hidden so check for disqualification // check to see how long they have hidden if (DateTime.Now - entry.LastCaution > MaximumHiddenDuration) { entry.Status = ChallengeStatus.Disqualified; GameBroadcast(100308, entry.Participant.Name); // "{0} has been disqualified" RefreshSymmetricNoto(entry.Participant); statuschange = true; } } else { entry.LastCaution = DateTime.Now; // inform the player XmlPoints.SendText(entry.Participant, 100310, MaximumHiddenDuration.TotalSeconds); // "You have {0} seconds become unhidden" statuschange = true; } entry.Caution = ChallengeStatus.Hidden; } else { entry.Caution = ChallengeStatus.None; } if (hadcaution && entry.Caution == ChallengeStatus.None) { statuschange = true; } // if they were disqualified, then drop them if (entry.Status == ChallengeStatus.Disqualified) { ClearChallenge(entry.Participant); } } if (statuschange) { // update gumps with the new status KingOfTheHillGump.RefreshAllGumps(this, false); } // it is possible that the game could end like this so check CheckForGameEnd(); }
public void CheckForKingOfTheHill() { ArrayList mlist = new ArrayList(); ArrayList elist = new ArrayList(); // who is currently on the hill IPooledEnumerable eable = this.GetMobilesInRange(0); foreach (Mobile p in eable) { if (p == null) { continue; } IChallengeEntry entry = GetParticipant(p); // if this is not a current participant then move them if (entry == null) { // prepare to move them off mlist.Add(p); } else // dont let players who are in a caution state such as hidden to score if (entry.Caution == ChallengeStatus.None) { // prepare to bump their score elist.Add(entry); } } eable.Free(); // move non-participants foreach (Mobile p in mlist) { for (int i = 10; i < 20; i++) { int x = p.Location.X + i * (Utility.RandomBool() ? 1 : -1); int y = p.Location.Y + i * (Utility.RandomBool() ? 1 : -1); int z = Map.GetAverageZ(x, y); Point3D newloc = new Point3D(x, y, z); if (XmlSpawner.IsValidMapLocation(newloc, p.Map)) { p.MoveToWorld(newloc, p.Map); } } } // only score if one player is alone on the hill if (elist.Count == 1) { IChallengeEntry entry = (IChallengeEntry)elist[0]; if (entry != null && entry.Participant != null) { // bump their score entry.Score++; // display the score entry.Participant.PublicOverheadMessage(MessageType.Regular, 0, true, entry.Score.ToString()); // update all the gumps if you like KingOfTheHillGump.RefreshAllGumps(this, false); // check for win conditions CheckForGameEnd(); } } }