public DynamicNpc(DbDynamicNPC dbNpc) { m_dbNpc = dbNpc; m_pPacket = new MsgNpcInfoEx { Flag = dbNpc.Type, Identity = dbNpc.Id, Lookface = dbNpc.Lookface, Life = dbNpc.Life, MaxLife = dbNpc.Maxlife, MapX = dbNpc.Cellx, MapY = dbNpc.Celly, Type = dbNpc.Type }; try { m_sElevation = Map[MapX, MapY].Elevation; } catch { m_sElevation = 999; } if (OwnerType == _OWNER_USER && OwnerIdentity > 0) { Client temp = null; if (ServerKernel.Players.TryGetValue(OwnerIdentity, out temp)) { if (temp.Character != null) { m_pRole = temp.Character; m_pPacket.Name = temp.Character.Name; } } } if (OwnerType == _OWNER_SYN && OwnerIdentity > 0 && IsSynFlag()) { Syndicate temp = ServerKernel.Syndicates.Values.FirstOrDefault(x => x.Identity == OwnerIdentity); if (temp != null) { m_pPacket.Name = temp.Name; } } Scores = new ConcurrentDictionary <uint, SynScore>(); m_tDeathTime = new TimeOutMS(500); m_tDeathTime.Startup(500); }
public bool Create(IRole pRole, int nStatus, int nPower, int nSecs, int nTimes, uint caster = 0, byte level = 0) { m_pOwner = pRole; m_dwCaster = caster; m_nStatus = nStatus; m_nData = nPower; m_tKeep = new TimeOutMS(nSecs * 1000); m_tKeep.Startup((int)Math.Min(((long)nSecs * 1000), int.MaxValue)); m_tKeep.Update(); m_tInterval = new TimeOutMS(1000); m_tInterval.Update(); m_pLevel = level; return(true); }
public void SetDelay() { if (m_dbMagictype == null) { return; } if (m_tDelay == null) { m_tDelay = new TimeOutMS((int)Timeout); } m_tDelay.Startup((int)Timeout); m_tDelay.SetInterval((int)Timeout); m_tDelay.Update(); }
public void OnTimer() { if (m_quizShow.Count < ServerKernel.QUIZ_MAX_QUESTION) { return; // no questions, no quiz } DateTime now = DateTime.Now; if (ServerKernel.QUIZ_SHOW_HOUR.Contains(now.Hour + 1)) { if (now.Minute == 55 && now.Second == 0 && m_state < QuizState.STARTING) { ServerKernel.SendMessageToAll("Quiz show will start in 5 minutes.", ChatTone.TOP_LEFT); } // Quiz starting if (now.Minute == 59 && now.Second <= 1 && m_state < QuizState.STARTING) { if (now.DayOfWeek == DayOfWeek.Sunday && now.Hour + 1 == 22) { return; } ReloadQuestions(); // reset basic variable m_nActualQuestion = 0; m_quizUserInformation.Clear(); m_temporaryQuestions.Clear(); // start the quiz m_state = QuizState.STARTING; // and send the initial packet :) var pMsg = new MsgQuiz { Type = QuizShowType.START_QUIZ, TimeTillStart = (ushort)(60 - now.Second), TimePerQuestion = ServerKernel.QUIZ_TIME_PER_QUESTION, QuestionAmount = ServerKernel.QUIZ_MAX_QUESTION, FirstPrize = ServerKernel.QUIZ_SHOW_AWARD[0], SecondPrize = ServerKernel.QUIZ_SHOW_AWARD[1], ThirdPrize = ServerKernel.QUIZ_SHOW_AWARD[2] }; // send to all players foreach (var plr in ServerKernel.Players.Values) { // create the user object that will be held by the server while it's alive var plrObj = new QuizShowUserObject { Experience = 0, Name = plr.Character.Name, Points = 0, TimeTaken = 0, UserIdentity = plr.Identity, Canceled = false }; m_quizUserInformation.Add(plr.Identity, plrObj); // save the info plr.Send(pMsg); // send packet to client } // quiz will only happen if there is at least 20 questions if (m_quizShow.Count > ServerKernel.QUIZ_MAX_QUESTION) { List <KeyValuePair <uint, DbGameQuiz> > tempList = new List <KeyValuePair <uint, DbGameQuiz> >(); Random rand = new Random(); foreach (var question in m_quizShow.Values) { tempList.Add(new KeyValuePair <uint, DbGameQuiz>((uint)rand.Next(), question)); } int num = 0; foreach (var question in tempList.OrderBy(x => x.Key).Where(question => num++ < ServerKernel.QUIZ_MAX_QUESTION)) { m_temporaryQuestions.Add(question.Value); } } else { if (m_quizShow.Count < ServerKernel.QUIZ_MAX_QUESTION) { m_state = QuizState.STOPPED; return; } // we have exactly 20 questions :) so ok foreach (var question in m_quizShow.Values) { m_temporaryQuestions.Add(question); } } // send message to all (supposing they didn't receive the window lol) ServerKernel.SendMessageToAll(ServerString.STR_QUIZ_SHOW_START, ChatTone.TOP_LEFT); } } if (ServerKernel.QUIZ_SHOW_HOUR.Contains(now.Hour) && now.Minute <= (ServerKernel.QUIZ_MAX_QUESTION * ServerKernel.QUIZ_TIME_PER_QUESTION) / 60) { // quiz started if (m_state == QuizState.STARTING && now.Minute == 0) { m_state = QuizState.RUNNING; m_pNextQuestion.Startup(ServerKernel.QUIZ_TIME_PER_QUESTION); m_pEventCheck.Startup(800); DbGameQuiz question = m_temporaryQuestions[m_nActualQuestion++]; var pMsg = new MsgQuiz { Type = QuizShowType.QUESTION_QUIZ, QuestionNumber = (ushort)(m_nActualQuestion), LastCorrectAnswer = 0, ExperienceAwarded = 1, TimeTakenTillNow = 0, CurrentScore = 0 }; pMsg.AddString(question.Question, question.Answer0, question.Answer1, question.Answer2, question.Answer3); foreach (var plr in ServerKernel.Players.Values) { plr.Send(pMsg); } } // quiz running if (m_state == QuizState.RUNNING && m_pNextQuestion.ToNextTime() && m_nActualQuestion < ServerKernel.QUIZ_MAX_QUESTION) { foreach (var usr in m_quizUserInformation.Values) { if (usr.LastQuestion < m_nActualQuestion) { usr.Points += 1; usr.TimeTaken += ServerKernel.QUIZ_TIME_PER_QUESTION; } } UpdateRanking(); DbGameQuiz question = m_temporaryQuestions[m_nActualQuestion++]; var pMsg = new MsgQuiz { Type = QuizShowType.QUESTION_QUIZ, QuestionNumber = (ushort)m_nActualQuestion, LastCorrectAnswer = m_temporaryQuestions[m_nActualQuestion - 2].Correct }; pMsg.AddString(question.Question, question.Answer0, question.Answer1, question.Answer2, question.Answer3); foreach (var plr in ServerKernel.Players.Values.Where(x => !x.Character.QuizCanceled)) { var plrObj = m_quizUserInformation.Values.FirstOrDefault(x => x.UserIdentity == plr.Identity); if (plrObj == null) { plrObj = new QuizShowUserObject { Experience = 0, Name = plr.Character.Name, Points = 0, TimeTaken = 0, UserIdentity = plr.Identity, LastQuestion = 0 }; } if (plrObj.LastQuestion < m_nActualQuestion - 2) { pMsg.LastCorrectAnswer = 0; } pMsg.CurrentScore = plrObj.Points; pMsg.ExperienceAwarded = plrObj.Experience; pMsg.TimeTakenTillNow = plrObj.TimeTaken; plrObj.LastQuestion = m_nActualQuestion - 1; plr.Send(pMsg); } if (m_nActualQuestion >= ServerKernel.QUIZ_MAX_QUESTION) { m_state = QuizState.ENDED; } } if (m_state == QuizState.ENDED && m_pNextQuestion.ToNextTime()) { foreach (var usr in m_quizUserInformation.Values) { if (usr.LastQuestion < m_nActualQuestion) { usr.Points += 1; usr.TimeTaken += ServerKernel.QUIZ_TIME_PER_QUESTION; Client pClient; if (ServerKernel.Players.TryGetValue(usr.UserIdentity, out pClient)) { var pMsg = new MsgQuiz { Type = QuizShowType.AFTER_REPLY, CurrentScore = usr.Points, TimeTaken = usr.TimeTaken, Rank = usr.Rank }; var rank = RankingStrings(); pMsg.AddString(rank[0].Name, rank[0].Points, rank[0].TimeTaken); pMsg.AddString(rank[1].Name, rank[1].Points, rank[1].TimeTaken); pMsg.AddString(rank[2].Name, rank[2].Points, rank[2].TimeTaken); pClient.Send(pMsg); } } Client pUser = null; if (ServerKernel.Players.TryGetValue(usr.UserIdentity, out pUser)) { try { pUser.Character.QuizPoints += usr.Points; int i = 0; foreach (var tmp in m_quizUserInformation.Values.OrderByDescending(x => x.Points)) { if (i++ > 3) { break; } if (tmp.UserIdentity == usr.UserIdentity) { long amount = (ServerKernel.GetExpBallExperience(pUser.Character.Level) / 600) * ServerKernel.QUIZ_SHOW_AWARD[i - 1]; pUser.Character.AwardExperience(amount); ushort emoney = ServerKernel.QUIZ_SHOW_EMONEY[i - 1]; uint money = ServerKernel.QUIZ_SHOW_MONEY[i - 1]; pUser.Character.AwardEmoney(emoney); pUser.Character.AwardMoney(money); pUser.Character.Send( string.Format("You awarded {0} CPs and {2} for winning on {1} place on Quiz Show.", emoney, i, money)); } } MsgQuiz pMsg = new MsgQuiz { Type = QuizShowType.FINISH_QUIZ, Score = usr.Rank, Rank = usr.TimeTaken, FirstPrize = usr.Points, FinalPrize = usr.Experience }; QuizShowUserObject[] pList = RankingStrings(); pMsg.AddString(pList[0].Name, pList[0].Points, pList[0].TimeTaken); pMsg.AddString(pList[1].Name, pList[1].Points, pList[1].TimeTaken); pMsg.AddString(pList[2].Name, pList[2].Points, pList[2].TimeTaken); pUser.Send(pMsg); } catch { } } else { try { // disconnected? still have prize to claim DbUser dbObj = new CharacterRepository().SearchByIdentity(usr.UserIdentity); if (dbObj == null) { continue; } Character pTemp = new Character(null, dbObj, null); pTemp.QuizPoints += usr.Points; int i = 1; foreach (var tmp in m_quizUserInformation.Values.OrderByDescending(x => x.Points)) { if (i++ > 3) { break; } if (tmp.UserIdentity == usr.UserIdentity) { long amount = (ServerKernel.GetExpBallExperience(pTemp.Level) / 600) * ServerKernel.QUIZ_SHOW_AWARD[i - 1]; pTemp.AwardExperience(amount); } } pTemp.Save(); pTemp = null; } catch { } } } ServerKernel.SendMessageToAll(ServerString.STR_QUIZ_SHOW_ENDED, ChatTone.TOP_LEFT); m_state = QuizState.STOPPED; } } }
public static void EventTasks() { m_pScorePK.Startup(1); m_pQuizShow.Startup(750); m_pPigeon.Startup(1); m_pMapEvent.Startup(10); m_pGuildWar.Startup(1); while (true) { try { if (m_pGuildWar.ToNextTime()) { foreach (var itr in ServerKernel.Maps.Values.Where(x => x.IsSynMap())) { foreach (var pNpc in itr.GameObjects.Values.OfType <DynamicNpc>()) { pNpc.CheckFightTime(); } } } if (m_pQuizShow.ToNextTime()) { ServerKernel.QuizShow.OnTimer(); } if (m_pPigeon.ToNextTime()) { ServerKernel.Broadcast.OnTimer(); } if (ServerKernel.ScorePkEvent.IsReady && m_pScorePK.ToNextTime()) { ServerKernel.ScorePkEvent.OnTimer(); } if (ServerKernel.CaptureTheFlag != null && ServerKernel.CaptureTheFlag.IsActive) { ServerKernel.CaptureTheFlag.OnTimer(); } if (ServerKernel.ArenaQualifier != null && ServerKernel.ArenaQualifier.Status == ArenaQualifierStatus.ENABLED) { ServerKernel.ArenaQualifier.OnTimer(); } if (ServerKernel.SyndicateScoreWar != null && ServerKernel.SyndicateScoreWar.IsAvaiable) { ServerKernel.SyndicateScoreWar.OnTimer(); } if (ServerKernel.LineSkillPk != null && ServerKernel.LineSkillPk.IsReady) { ServerKernel.LineSkillPk.OnTimer(); } if (m_pSynRecruit.ToNextTime()) { ServerKernel.SyndicateRecruitment.CheckSyndicates(); } DateTime now = DateTime.Now; if (now.Hour == 0 && now.Minute == 0 && now.Second == 0 && m_pUpdateLock.ToNextTime()) { foreach (var plr in ServerKernel.Players.Values.ToList()) { plr.Character.DailyReset(); } foreach (var arena in ServerKernel.ArenaRecord.Values) { DbUser dbUsr = Database.Characters.SearchByIdentity(arena.PlayerIdentity); if (dbUsr == null) { arena.Delete(); continue; } arena.LastRanking = arena.Ranking; arena.LastSeasonPoints = arena.Points; arena.LastSeasonWins = arena.TodayWins; arena.LastSeasonsLoses = arena.TodayLoses; arena.Lookface = dbUsr.Lookface; arena.Level = dbUsr.Level; arena.Profession = dbUsr.Profession; if (arena.Ranking > 0) { IHonorReward reward = ServerKernel.HonorRewards.Values.FirstOrDefault(x => x.Ranking == arena.Ranking); if (reward != null) { arena.HonorPoints += reward.DailyHonor; arena.TotalHonorPoints += reward.DailyHonor; } } arena.Level = dbUsr.Level; arena.Lookface = dbUsr.Lookface; arena.Profession = dbUsr.Profession; arena.PlayerName = dbUsr.Name; arena.Save(); } foreach (var arena in ServerKernel.ArenaRecord.Values) { arena.Points = ServerKernel.ArenaQualifier.GetStartupPoints(arena.Level); arena.TodayWins = 0; arena.TodayLoses = 0; arena.Save(); } } if (m_pMapEvent.ToNextTime()) { foreach ( var npc in ServerKernel.Maps.Values.Where(x => x.IsPkField() || x.IsPkGameMap() || x.IsSynMap()) .SelectMany(map => map.GameObjects.Values) .OfType <DynamicNpc>()) { if (npc.MapIdentity == 7600 || npc.MapIdentity == 2057) { continue; } npc.SendOwnerRanking(); } } } catch (Exception ex) { ServerKernel.Log.SaveLog(ex.ToString(), true, LogType.EXCEPTION); } finally { Thread.Sleep(750); } } #pragma warning disable CS0162 // Se detectó código inaccesible Console.WriteLine("Game Event Processing Thread exited"); #pragma warning restore CS0162 // Se detectó código inaccesible }