public void Upsert_PopulatesPlayerPosition()
        {
            var topN       = 5;
            var ladderId   = "myLadder";
            var playerName = "My Player";
            var firstEntry = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "PC",
                Username = playerName,
                Score    = 1000
            };
            var secondEntryDifferentPlatform = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "PS4",
                Username = playerName,
                Score    = 3000,
                Position = 2
            };

            var repository = CreateInMemoryRepository(topN);

            repository.Upsert(firstEntry);

            repository
            .Upsert(secondEntryDifferentPlatform)
            .Should()
            .BeEquivalentTo(secondEntryDifferentPlatform);

            _dbContext
            .Ladders
            .Should()
            .HaveCount(2);
        }
Example #2
0
        public LadderChange(LadderEntry previous, LadderEntry detected)
        {
            Name = detected.Name;
            Bracket = detected.Request.Bracket;
            RegionID = detected.Request.RegionID;
            RealmID = detected.RealmID;
            PreviousRequestID = previous.Request.ID;
            PreviousClass = previous.ClassID;
            PreviousFaction = previous.FactionID;
            PreviousGenderID = previous.GenderID;
            PreviousRace = previous.RaceID;
            PreviousRanking = previous.Ranking;
            PreviousRating = previous.Rating;
            PreviousSpec = previous.SpecID;
            PreviousSeasonWins = previous.SeasonWins;
            PreviousSeasonLosses = previous.SeasonLosses;
            PreviousWeeklyWins = previous.WeeklyWins;
            PreviousWeeklyLosses = previous.WeeklyLosses;
            CurrentRequestID = detected.Request.ID;
            DetectedClass = detected.ClassID;
            DetectedFaction = detected.FactionID;
            DetectedGenderID = detected.GenderID;
            DetectedRace = detected.RaceID;
            DetectedRanking = detected.Ranking;
            DetectedRating = detected.Rating;
            DetectedSpec = detected.SpecID;
            DetectedSeasonWins = detected.SeasonWins;
            DetectedSeasonLosses = detected.SeasonLosses;
            DetectedWeeklyWins = detected.WeeklyWins;
            DetectedWeeklyLosses = detected.WeeklyLosses;


        }
Example #3
0
        public LadderEntry Upsert(LadderEntry entry)
        {
            var resultingEntry = _dbContext.Ladders
                                 .Where(l => l.LadderId == entry.LadderId &&
                                        l.Platform == entry.Platform &&
                                        l.Username == entry.Username)
                                 .FirstOrDefault();

            if (resultingEntry != null)
            {
                _logger.LogInformation("<{0},{1},{2}> already exist. Updating.", entry.LadderId, entry.Platform, entry.Username);

                resultingEntry.Score = resultingEntry.Score < entry.Score
                    ? resultingEntry.Score : entry.Score;
            }
            else
            {
                _logger.LogInformation("<{0},{1},{2}> needs to be created.", entry.LadderId, entry.Platform, entry.Username);
                _dbContext.Ladders.Add(entry);
                resultingEntry = entry;
            }
            _dbContext.SaveChanges();

            resultingEntry.Position = ComputeCurrentPosition(resultingEntry.LadderId, resultingEntry.Score);

            _logger.LogInformation("Current position in ladder {0} is {1}", resultingEntry.LadderId, resultingEntry.Position);

            return(resultingEntry);
        }
        public void Upsert_UsernameIsUniquePerPlatformAndPerLadderId()
        {
            var topN       = 5;
            var ladderId   = "myLadder";
            var playerName = "My Player";
            var firstEntry = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "PC",
                Username = playerName,
                Score    = 1000
            };
            var secondEntryDifferentPlatform = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "PS4",
                Username = playerName,
                Score    = 3000
            };

            var repository = CreateInMemoryRepository(topN);

            repository.Upsert(firstEntry);
            repository.Upsert(secondEntryDifferentPlatform);

            _dbContext
            .Ladders
            .Should()
            .HaveCount(2);
        }
Example #5
0
        private static Chart CompilePCByDL()
        {
            BarGraph chart = new BarGraph("Player Count By Dueling Level", "graphs_pc_by_dl", 5, "Dueling Level", "Players", BarGraphRenderMode.Bars);

            int       lastLevel = -1;
            ChartItem lastItem  = null;

            Ladder ladder = Ladder.Instance;

            if (ladder != null)
            {
                ArrayList entries = ladder.ToArrayList();

                for (int i = entries.Count - 1; i >= 0; --i)
                {
                    LadderEntry entry = (LadderEntry)entries[i];
                    int         level = Ladder.GetLevel(entry.Experience);

                    if (lastItem == null || level != lastLevel)
                    {
                        chart.Items.Add(lastItem = new ChartItem(level.ToString(), 1));
                        lastLevel = level;
                    }
                    else
                    {
                        lastItem.Value++;
                    }
                }
            }

            return(chart);
        }
Example #6
0
        public static int GetExperienceGain(LadderEntry us, LadderEntry them, bool weWon)
        {
            if (us == null || them == null)
            {
                return(0);
            }

            int ourLevel   = GetLevel(us.Experience);
            int theirLevel = GetLevel(them.Experience);

            int scalar = GetOffsetScalar(ourLevel, theirLevel, weWon);

            if (scalar == 0)
            {
                return(0);
            }

            int xp = 25 * scalar;

            if (!weWon)
            {
                xp = (xp * GetLossFactor(ourLevel)) / 100;
            }

            xp /= 100;

            if (xp <= 0)
            {
                xp = 1;
            }

            return(xp * (weWon ? 1 : -1));
        }
        public void GetTopEntries_GetAllEntriesIfDBHasLessThanNEntriesForThatLadder()
        {
            var TopN         = 10;
            var ladderId     = "myLadder";
            var platform     = "PC";
            var secondPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 1000
            };

            _dbContext.Ladders.Add(secondPlayer);
            _dbContext.SaveChanges();

            var repository = CreateInMemoryRepository(TopN);

            repository
            .GetTopEntries(ladderId)
            .Should()
            .HaveCount(1)
            .And.ContainEquivalentOf(secondPlayer);

            _logger.Verify(l => l.LogInformation(It.IsAny <string>()), Times.Once());
        }
Example #8
0
        public void GetAllEntriesForLadder_ReturnsAllEntriesForGivenLadder()
        {
            var myLadderId = "My Ladder Id";
            var myEntry    = new LadderEntry
            {
                LadderId = myLadderId,
                Platform = "PC",
                Score    = 123,
                Username = "******"
            };
            var myLadderList = new List <LadderEntry>
            {
                new LadderEntry(),
                new LadderEntry(),
                new LadderEntry(),
                new LadderEntry(),
            };

            myLadderList.Add(myEntry);

            _repository
            .Setup(r => r.GetAllEntriesForLadder(myLadderId))
            .Returns(myLadderList);

            var service = new LadderService(_repository.Object, _logger.Object);

            var result = service.GetAllEntriesForLadder(myLadderId);

            result
            .Should()
            .NotBeEmpty()
            .And.HaveCount(5)
            .And.ContainEquivalentOf(myEntry);
        }
        public void DeleteEntry_ReturnsTrueWhenGivenEntryIsInTheDatabaseAndRemovesTheEntry()
        {
            var TopN       = 1;
            var ladderId   = "myLadder";
            var platform   = "PC";
            var playerName = "Giampaolo";
            //Here we add entries to db using context directly to test repository
            var secondPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = playerName,
                Score    = 1000
            };

            _dbContext.Ladders.Add(secondPlayer);
            _dbContext.SaveChanges();

            var repository = CreateInMemoryRepository(TopN);

            repository.DeleteEntry(ladderId, platform, playerName)
            .Should()
            .BeTrue();

            _dbContext.Ladders.Count()
            .Should().Be(0);
        }
        public void Upsert_UpdateEntryIfAlreadyExistAndOnlyIfTheScoreIsBetter()
        {
            var topN       = 5;
            var ladderId   = "myLadder";
            var platform   = "PC";
            var playerName = "My Player";
            var firstEntry = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = playerName,
                Score    = 1000
            };
            var secondEntryWorstScore = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = playerName,
                Score    = 3000
            };
            var thirdEntryBetterScore = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = playerName,
                Score    = 900
            };

            var repository = CreateInMemoryRepository(topN);

            var result = repository.Upsert(firstEntry);

            repository.Upsert(secondEntryWorstScore);

            _dbContext
            .Ladders
            .Should()
            .HaveCount(1);

            //Position is not relevant right now
            result.Position = 0;
            result
            .Should()
            .BeEquivalentTo(firstEntry);

            result = repository.Upsert(thirdEntryBetterScore);

            _dbContext
            .Ladders
            .Should()
            .HaveCount(1);

            //Position is not relevant right now
            result.Position = 0;
            result
            .Should()
            .BeEquivalentTo(thirdEntryBetterScore);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Trace.WriteLine("POST /LadderEntry/Delete/" + id);
            LadderEntry ladderEntry = db.LadderEntries.Find(id);

            db.LadderEntries.Remove(ladderEntry);
            db.SaveChanges();
            return(RedirectToAction("Admin"));
        }
 public ActionResult Edit([Bind(Include = "id,Rank,ArmyList,Army,PlayerName")] LadderEntry ladderEntry)
 {
     Trace.WriteLine("POST /LadderEntry/Edit/" + ladderEntry.ID);
     if (ModelState.IsValid)
     {
         db.Entry(ladderEntry).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Admin"));
     }
     return(View(ladderEntry));
 }
        public void GetTopEntries_PopulatesPlayerPosition()
        {
            var TopN         = 2;
            var ladderId     = "myLadder";
            var platform     = "PC";
            var secondPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 1000
            };
            var firstPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 999,
                Position = 2
            };
            var anotherPlatformPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "AnotherPlatform",
                Username = "******",
                Score    = 1,
                Position = 1
            };
            var anotherLadderPlayer = new LadderEntry
            {
                LadderId = "AnotherLadder",
                Platform = platform,
                Username = "******",
                Score    = 1
            };

            _dbContext.Ladders.Add(secondPlayer);
            _dbContext.Ladders.Add(firstPlayer);
            _dbContext.Ladders.Add(anotherPlatformPlayer);
            _dbContext.Ladders.Add(anotherLadderPlayer);
            _dbContext.SaveChanges();


            var repository = CreateInMemoryRepository(TopN);

            repository
            .GetTopEntries(ladderId)
            .Should()
            .HaveCount(2)
            .And.HaveElementAt(0, anotherPlatformPlayer)
            .And.HaveElementAt(1, firstPlayer);

            _logger.Verify(l => l.LogInformation(It.IsAny <string>()), Times.Once());
        }
        public void GetAllEntriesForPlatform_ReturnsAllEntriesForSpecifiedLadder()
        {
            var TopN     = 1;
            var ladderId = "myLadder";
            var platform = "PC";
            //Here we add entries to db using context directly to test repository
            var secondPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 1000
            };
            var firstPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 999
            };
            var anotherPlatformPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "AnotherPlatform",
                Username = "******",
                Score    = 1
            };
            var anotherLadderPlayer = new LadderEntry
            {
                LadderId = "AnotherLadder",
                Platform = "AnotherPlatform",
                Username = "******",
                Score    = 1
            };

            _dbContext.Ladders.Add(secondPlayer);
            _dbContext.Ladders.Add(firstPlayer);
            _dbContext.Ladders.Add(anotherPlatformPlayer);
            _dbContext.Ladders.Add(anotherLadderPlayer);

            _dbContext.SaveChanges();

            var repository = CreateInMemoryRepository(TopN);

            repository
            .GetAllEntriesForLadder(ladderId)
            .Should()
            .HaveCount(3)
            .And.ContainEquivalentOf(anotherPlatformPlayer)
            .And.ContainEquivalentOf(firstPlayer)
            .And.ContainEquivalentOf(secondPlayer);
        }
Example #15
0
        public LadderEntry Find(Mobile mob)
        {
            LadderEntry entry = (LadderEntry)m_Table[mob];

            if (entry == null)
            {
                m_Table[mob] = entry = new LadderEntry(mob, this);
                entry.Index  = m_Entries.Count;
                m_Entries.Add(entry);
            }

            return(entry);
        }
        public void DeleteEntry_ReturnsFalseWhenGivenEntryIsNotInTheDatabaseAndDoesntRemoveTheEntry()
        {
            var TopN     = 1;
            var ladderId = "myLadder";
            var platform = "PC";
            //Here we add entries to db using context directly to test repository
            var secondPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 1000
            };
            var firstPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 999
            };
            var anotherPlatformPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "AnotherPlatform",
                Username = "******",
                Score    = 1
            };
            var anotherLadderPlayer = new LadderEntry
            {
                LadderId = "AnotherLadder",
                Platform = "AnotherPlatform",
                Username = "******",
                Score    = 1
            };

            _dbContext.Ladders.Add(secondPlayer);
            _dbContext.Ladders.Add(firstPlayer);
            _dbContext.Ladders.Add(anotherPlatformPlayer);
            _dbContext.Ladders.Add(anotherLadderPlayer);

            _dbContext.SaveChanges();

            var repository = CreateInMemoryRepository(TopN);

            repository.DeleteEntry("foo", "bar", "baz")
            .Should()
            .BeFalse();

            _dbContext.Ladders.Count()
            .Should().Be(4);
        }
        public void GetTopEntries_ReturnsTopNEntriesForSpecifiedLadder()
        {
            var TopN     = 1;
            var ladderId = "myLadder";
            var platform = "PC";
            //Here we add entries to db using context directly to test repository
            var secondPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 1000
            };
            var firstPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 999
            };
            var anotherPlatformPlayer = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "AnotherPlatform",
                Username = "******",
                Score    = 1
            };
            var anotherLadderPlayer = new LadderEntry
            {
                LadderId = "AnotherLadder",
                Platform = platform,
                Username = "******",
                Score    = 1
            };

            _dbContext.Ladders.Add(secondPlayer);
            _dbContext.Ladders.Add(firstPlayer);
            _dbContext.Ladders.Add(anotherPlatformPlayer);
            _dbContext.Ladders.Add(anotherLadderPlayer);
            _dbContext.SaveChanges();

            var repository = CreateInMemoryRepository(TopN);

            repository
            .GetTopEntries(ladderId)
            .Should()
            .HaveCount(1)
            .And.ContainEquivalentOf(anotherPlatformPlayer);

            _logger.Verify(l => l.LogInformation(It.IsAny <string>()), Times.Once());
        }
        public ActionResult Create([Bind(Include = "ArmyList,Army,PlayerName,Rank")] LadderEntry ladderEntry)
        {
            Trace.WriteLine("POST /LadderEntry/Create");


            if (ModelState.IsValid)
            {
                db.LadderEntries.Add(ladderEntry);
                db.SaveChanges();
                return(RedirectToAction("Admin"));
            }

            return(View(ladderEntry));
        }
        public void GetEntryForUser_ComputesThePositionOfTheUserInTheLadder()
        {
            var topN       = 5;
            var ladderId   = "myLadder";
            var platform   = "PC";
            var playerName = "My Player";
            var firstEntry = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = playerName,
                Score    = 1001
            };
            var secondEntry = new LadderEntry
            {
                LadderId = ladderId,
                Platform = platform,
                Username = "******",
                Score    = 1002
            };
            var thirdEntry = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "Another Platform",
                Username = playerName,
                Score    = 500,
                Position = 1
            };
            var fourthEntry = new LadderEntry
            {
                LadderId = "Another Ladder",
                Platform = "Another Platform",
                Username = playerName,
                Score    = 500
            };

            _dbContext.Ladders.Add(firstEntry);
            _dbContext.Ladders.Add(secondEntry);
            _dbContext.Ladders.Add(thirdEntry);
            _dbContext.Ladders.Add(fourthEntry);
            _dbContext.SaveChanges();

            var repository = CreateInMemoryRepository(topN);

            repository
            .GetEntryForUser(ladderId, "Another Platform", playerName)
            .Should()
            .NotBeNull()
            .And.BeEquivalentTo(thirdEntry);
        }
        // GET: Todos/Edit/5
        public ActionResult Edit(int?id)
        {
            Trace.WriteLine("GET /LadderEntry/Edit/" + id);
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LadderEntry ladderEntry = db.LadderEntries.Find(id);

            if (ladderEntry == null)
            {
                return(HttpNotFound());
            }
            return(View(ladderEntry));
        }
Example #21
0
        private static Report CompileTop15()
        {
            Report report = new Report("Top 15 Duelists", "80%");

            report.Columns.Add("6%", "center", "Rank");
            report.Columns.Add("6%", "center", "Level");
            report.Columns.Add("6%", "center", "Guild");
            report.Columns.Add("70%", "left", "Name");
            report.Columns.Add("6%", "center", "Wins");
            report.Columns.Add("6%", "center", "Losses");

            Ladder ladder = Ladder.Instance;

            if (ladder != null)
            {
                ArrayList entries = ladder.ToArrayList();

                for (int i = 0; i < entries.Count && i < 15; ++i)
                {
                    LadderEntry entry = (LadderEntry)entries[i];
                    int         level = Ladder.GetLevel(entry.Experience);
                    string      guild = "";

                    PlayerMobile player = entry.Mobile as PlayerMobile;

                    if (player != null)
                    {
                        if (player.Guild != null)
                        {
                            guild = player.Guild.m_Abbreviation;
                        }
                    }

                    ReportItem item = new ReportItem();

                    item.Values.Add(LadderGump.Rank(entry.Index + 1));
                    item.Values.Add(level.ToString(), "N0");
                    item.Values.Add(guild);
                    item.Values.Add(entry.Mobile.Name);
                    item.Values.Add(entry.Wins.ToString(), "N0");
                    item.Values.Add(entry.Losses.ToString(), "N0");

                    report.Items.Add(item);
                }
            }

            return(report);
        }
        public LadderEntry Upsert(LadderEntry entry)
        {
            LadderEntry result = null;

            if (entry != null)
            {
                try
                {
                    result = _repository.Upsert(entry);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Upsert failed to read from repository");
                }
            }
            return(result);
        }
        public LadderEntry GetEntryForUser(string ladderId, string platform, string username)
        {
            LadderEntry result = null;

            if (IsValidGetEntryForUserInput(ladderId, platform, username))
            {
                try
                {
                    result = _repository.GetEntryForUser(ladderId, platform, username);
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "GetEntryForUser failed to read from repository");
                }
            }
            return(result);
        }
Example #24
0
        public CharacterCell()
        {
            InitializeComponent();

            if (DesignMode.IsDesignModeEnabled)
            {
                LadderEntry entry = new LadderEntry()
                {
                    Rank                = 2,
                    AccountName         = "Account Name",
                    CharacterClass      = "Ascendant",
                    CharacterName       = "Character Name",
                    CharacterLevel      = 65,
                    CharacterExperience = 69420
                };
                entry.LoadImageSource();
                BindingContext = entry;
            }
        }
Example #25
0
        public void Upsert_ReturnsTheUpdatedOrInsertedEntryIfEverythingIsOK()
        {
            var entry = new LadderEntry
            {
                LadderId = "My Ladder",
                Platform = "PC",
                Username = "******"
            };

            _repository
            .Setup(r => r.Upsert(entry))
            .Returns(() => entry);

            var service = new LadderService(_repository.Object, _logger.Object);

            service
            .Upsert(entry)
            .Should()
            .BeEquivalentTo(entry);
        }
Example #26
0
        public void UpdateEntry(LadderEntry entry)
        {
            int index = entry.Index;

            if (index >= 0 && index < m_Entries.Count)
            {
                // sanity

                int c;

                while ((index - 1) >= 0 && (c = entry.CompareTo(m_Entries[index - 1])) < 0)
                {
                    index = Swap(index, index - 1);
                }

                while ((index + 1) < m_Entries.Count && (c = entry.CompareTo(m_Entries[index + 1])) > 0)
                {
                    index = Swap(index, index + 1);
                }
            }
        }
Example #27
0
        public void Upsert_LogsErrorWhenRepositoryThrows()
        {
            var entry = new LadderEntry
            {
                LadderId = "My Ladder",
                Platform = "PC",
                Username = "******"
            };


            var exceptionMessage = "An error occurred because blablabalabla";

            _repository
            .Setup(r => r.Upsert(entry))
            .Throws(new Exception(exceptionMessage));

            var service = new LadderService(_repository.Object, _logger.Object);

            service.Upsert(entry);

            _logger.Verify(l => l.LogError(It.IsAny <Exception>(), It.IsAny <string>()), Times.Once());
        }
        public void GetEntryForUser_ReturnsNullIfUserNotPresent()
        {
            var topN       = 5;
            var ladderId   = "myLadder";
            var playerName = "My Player";
            var firstEntry = new LadderEntry
            {
                LadderId = ladderId,
                Platform = "PC",
                Username = playerName,
                Score    = 1000
            };

            _dbContext.Ladders.Add(firstEntry);
            _dbContext.SaveChanges();

            var repository = CreateInMemoryRepository(topN);

            var result = repository.GetEntryForUser(ladderId, "AnotherPlatform", playerName);

            Assert.Null(result);
        }
Example #29
0
        public async Task InsertOrUpdateEntry_ReturnsOkAndGivenEntryIfJWTPayloadIsAValidEntry()
        {
            var entry = new LadderEntry
            {
                LadderId = "My Ladder Id",
                Platform = "MyCoolPlatform",
                Username = "******",
                Score    = 12000,
                Position = 1
            };

            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Add(_factory.JWTHeaderName, PrepareJWTPayload(JsonConvert.SerializeObject(entry)));

            var response = await client.PostAsync("/ladder", new StringContent("{}", Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var result = JsonConvert.DeserializeObject <LadderEntry>(await response.Content.ReadAsStringAsync());

            result.Should().BeEquivalentTo(entry);
        }
Example #30
0
        public void GetEntryForUser_ReturnsMyEntryWhenMyKeyMatchesOneEntry()
        {
            var myLadderId = "My Ladder Id";
            var myPlatform = "PC";
            var myUsername = "******";
            var myEntry    = new LadderEntry
            {
                LadderId = myLadderId,
                Platform = myPlatform,
                Username = myUsername
            };

            _repository
            .Setup(r => r.GetEntryForUser(myLadderId, myPlatform, myUsername))
            .Returns(() => myEntry);

            var service = new LadderService(_repository.Object, _logger.Object);
            var result  = service.GetEntryForUser(myLadderId, myPlatform, myUsername);

            result
            .Should()
            .BeEquivalentTo(myEntry);
        }
Example #31
0
        public PlayerDetailGump(PlayerMobile from, PlayerMobile mobile)
        {
            _from   = from;
            _mobile = mobile;

            Width = 320;

            int n = Notoriety.Compute(from, mobile);

            int notoColor = _notorietyColors[n];

            AddBorderedText(20, 18, Width - 40, 20, Center(mobile.Name ?? "Unknown"), notoColor, BlackColor32);

            AddSeperator(30, 40, Width - 60);

            const int LabelOffset = 20;
            const int LabelWidth  = 55;

            const int ValueOffset = 25 + LabelWidth;
            int       ValueWidth  = Width - (20 + ValueOffset);

            int y = 44;

            PlayerMobile pm = mobile as PlayerMobile;

            Guild guild = mobile.Guild as Guild;

            if (guild != null)
            {
                AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Guild:"), LabelColor32, BlackColor32);

                AddBorderedText(ValueOffset, y, ValueWidth, 20, guild.Name ?? "Unknown", WhiteColor32, BlackColor32);
                y += 20;
            }

            if (mobile.PublicMyRunUO && mobile.Kills >= 5)
            {
                AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Kills:"), LabelColor32, BlackColor32);
                AddBorderedText(ValueOffset, y, ValueWidth, 20, mobile.Kills.ToString("N0"), WhiteColor32, BlackColor32);

                y += 20;
            }

            Account acct = mobile.Account as Account;

            if (acct != null)
            {
                TimeSpan age = DateTime.UtcNow - acct.Created;

                int ageInDays = ( int )age.TotalDays;

                int ageInYears  = ((ageInDays + 162) / 365);
                int ageInMonths = ((ageInDays + 15) / 30);
                int ageInWeeks  = ((ageInDays + 3) / 7);

                string ageString;

                if (ageInYears > 0)
                {
                    ageString = String.Format("{0:N0} year{1}", ageInYears, ageInYears == 1?"":"s");
                }
                else if (ageInMonths > 1)
                {
                    ageString = String.Format("{0:N0} month{1}", ageInMonths, ageInMonths == 1?"":"s");
                }
                else if (ageInWeeks > 1)
                {
                    ageString = String.Format("{0:N0} week{1}", ageInWeeks, ageInWeeks == 1?"":"s");
                }
                else
                {
                    ageString = String.Format("Newbie", ageInDays, ageInDays == 1?"":"s");
                }



                AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Age:"), LabelColor32, BlackColor32);
                AddBorderedText(ValueOffset, y, ValueWidth, 20, ageString, WhiteColor32, BlackColor32);

                y += 20;
            }

            PlayerState ps = PlayerState.Find(mobile);

            if (ps != null)
            {
                Faction fac = ps.Faction;

                //AddItem( Width - 51, 7, 5535, (fac.Definition.HueSecondary ^ 0x0000) - 1 );
                AddItem(7, 7, 5534, (fac.Definition.HuePrimary ^ 0x0000) - 1);

                y += 8;

                AddBorderedText(LabelOffset, y, LabelWidth + ValueWidth, 20, fac.Definition.FriendlyName, WhiteColor32, BlackColor32);

                y += 21;
                AddSeperator(30, y, Width - 60);
                y += 3;

                string rank = String.Format(
                    "Level {0} {1}",
                    ps.Rank.Rank,
                    ps.Rank.Title.String
                    );

                AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Rank:"), LabelColor32, BlackColor32);
                AddBorderedText(ValueOffset, y, ValueWidth, 20, rank, WhiteColor32, BlackColor32);
                y += 20;

                AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Points:"), LabelColor32, BlackColor32);
                AddBorderedText(ValueOffset, y, ValueWidth, 20, String.Format("{0:N0}", ps.KillPoints), WhiteColor32, BlackColor32);
                y += 20;
            }

            Ladder instance = Ladder.Instance;

            if (instance != null)
            {
                LadderEntry entry = instance.Find(mobile);

                if (entry != null && (entry.Wins + entry.Losses) > 0)
                {
                    y += 8;

                    AddBorderedText(LabelOffset, y, LabelWidth + ValueWidth, 20, "Duelist", WhiteColor32, BlackColor32);

                    y += 21;
                    AddSeperator(30, y, Width - 60);
                    y += 3;

                    string rank = LadderGump.Rank(entry.Index + 1);

                    AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Rank:"), LabelColor32, BlackColor32);
                    AddBorderedText(ValueOffset, y, ValueWidth, 20, rank, WhiteColor32, BlackColor32);
                    y += 20;

                    AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Level:"), LabelColor32, BlackColor32);
                    AddBorderedText(ValueOffset, y, ValueWidth, 20, Ladder.GetLevel(entry.Experience).ToString("N0"), WhiteColor32, BlackColor32);
                    y += 20;

                    AddBorderedText(LabelOffset, y, LabelWidth, 20, Right("Matches:"), LabelColor32, BlackColor32);
                    AddBorderedText(ValueOffset, y, ValueWidth, 20, String.Format("{0:N0}", (entry.Wins + entry.Losses)), WhiteColor32, BlackColor32);
                    y += 20;
                }
            }

            Height = y + 12;

            Ethic ethic = Ethic.Find(mobile);

            if (ethic == Ethic.Hero)
            {
                AddItem(Width - 36, Height - 26, 7188);
            }
            else if (ethic == Ethic.Evil)
            {
                AddItem(Width - 35, Height - 36, 6232);
            }
        }