public void OnFinish() { ushort[] m_startX = { 430, 423, 439, 428, 452, 464, 439 }; ushort[] m_startY = { 378, 394, 384, 365, 365, 378, 396 }; foreach (var usr in _getUserScores.OrderByDescending(x => x.Points)) { Client client; if (!ServerKernel.Players.TryGetValue(usr.Identity, out client) || client.Character == null) { continue; } Character plr = client.Character; plr.ChangeMap(m_startX[ThreadSafeRandom.RandGet() % 7], m_startY[ThreadSafeRandom.RandGet() % 7], 1002); switch (GetRank(plr.Identity)) { case 1: plr.AwardMoney(3000000); plr.AwardEmoney(1000); ServerKernel.SendMessageToAll( string.Format( "Congratulations! {0} has won the Score PK Tournament and awarded 3,000,000 silvers and 1,000 CPs.", plr.Name), ChatTone.TALK); break; case 2: plr.AwardMoney(2000000); plr.AwardEmoney(500); ServerKernel.SendMessageToAll( string.Format( "{0} has got second place in the Score PK Tournament and awarded 2,000,000 silvers and 500 CPs.", plr.Name), ChatTone.TALK); break; case 3: plr.AwardMoney(1000000); plr.AwardEmoney(250); ServerKernel.SendMessageToAll( string.Format( "{0} has got third place in the Score PK Tournament and awarded 1,000,000 silvers and 250 CPs.", plr.Name), ChatTone.TALK); break; default: plr.AwardMoney(100000); plr.AwardEmoney(100); plr.Send( "You awarded 100,000 silvers and 100 CPs for participating the Score PK Tournament."); break; } } m_pState = EventState.ENDED; }
/// <summary> /// Runs the startup tasks. /// </summary> /// <returns>Task.</returns> protected override async Task RunStartupTasks() { // Do these before allowing the base method to run, which will invoke startup scheduled tasks await ServerKernel.LoadRepositories(ServerConfigurationManager).ConfigureAwait(false); await base.RunStartupTasks().ConfigureAwait(false); DirectoryWatchers.Start(); Parallel.ForEach(GetExports <IServerEntryPoint>(), entryPoint => entryPoint.Run()); }
private Map PrepareMap() { //Map pMap = m_pBaseMap.CreateSample(); //pMap.Identity = (uint) ServerKernel.NextQualifierMap(); DbDynamicMap dbMap = new DbDynamicMap { Identity = (uint)ServerKernel.NextQualifierMap(), MapDoc = 900000, Name = "ArenaQualifier", Type = 7, FileName = "newarena.DMap" }; Map pMap = new Map(dbMap); pMap.Load(); return(pMap); }
public void OnIdle() { DateTime now = DateTime.Now; if (m_pState == EventState.IDLE && now.Minute >= 29 && now.Minute < 40) { foreach (var plr in m_pMap.Players.Values) { plr.ChangeMap(430, 380, 1002); } ServerKernel.SendMessageToAll("Score PK Tournament will start in 1 minute! Hurry up to join the event.", ChatTone.TALK); m_pState = EventState.STARTING; } }
public void OnTimer() { if (m_lNext.Count <= 0) { return; } if (!m_pNext.IsTimeOut() && m_lLast.Count > 0) { return; } m_pNext.Update(); var bc = m_lNext[0]; m_pActive = bc; lock (m_pLock) { m_lLast.Add(bc); m_lNext.RemoveAt(0); } m_pAdLogRepo.SaveOrUpdate(new DbBroadcastLog { Addition = bc.Addition, Message = bc.Message, Time = (uint)UnixTimestamp.Timestamp(), UserIdentity = bc.OwnerIdentity, UserName = bc.OwnerName }); ServerKernel.SendMessageToAll(new MsgTalk(bc.Message, ChatTone.BROADCAST) { Sender = bc.OwnerName }); }
public static void CancelMaintenance() { m_tRestart.Clear(); ServerKernel.SendMessageToAll("Maintenance canceled! You're enabled to play normally.", ChatTone.CENTER); ServerKernel.Log.SaveLog("Canceled.", true); }
public bool Add(Item item, bool isLogin = false) { ItemPosition pos = Calculations.GetItemPosition(item.Type); #region Sanity Checks if (!isLogin) { // Level check if (item.Itemtype.ReqLevel > m_pOwner.Level) { return(false); } // Profession check if (m_pOwner.Metempsychosis > 0 && m_pOwner.Level >= 70 && item.Itemtype.ReqLevel <= 70) { } else { if (item.Itemtype.ReqProfession > 0) { // item int iProfession = item.Itemtype.ReqProfession / 10; int iProfessionLevel = item.Itemtype.ReqProfession % 10; if (iProfession == 19) { iProfession = 10; } // user int uProfession = m_pOwner.Profession / 10; int uProfessionLevel = m_pOwner.Profession % 10; if (uProfession > 10 && iProfession == 10) { uProfession = 10; } if (iProfession == uProfession) { if (iProfessionLevel > uProfessionLevel) { return(false); } } else { return(false); } } // Attribute check if (item.Itemtype.ReqForce != 0 && item.Itemtype.ReqForce > m_pOwner.Strength) { return(false); } if (item.Itemtype.ReqSpeed != 0 && item.Itemtype.ReqSpeed > m_pOwner.Agility) { return(false); } if (item.Itemtype.ReqHealth != 0 && item.Itemtype.ReqHealth > m_pOwner.Vitality) { return(false); } if (item.Itemtype.ReqSoul != 0 && item.Itemtype.ReqSoul > m_pOwner.Spirit) { return(false); } ushort type = (ushort)(item.Type / 1000); if (pos == ItemPosition.RIGHT_HAND && !m_pOwner.WeaponSkill.Skills.ContainsKey(type) && item.Itemtype.ReqWeaponskill > 0) { return(false); } if (m_pOwner.WeaponSkill.Skills.ContainsKey(type)) { if (pos == ItemPosition.RIGHT_HAND && m_pOwner.WeaponSkill.Skills[type].Level < item.Itemtype.ReqWeaponskill) { return(false); } } if (type == 421 && item.Position < (ItemPosition)20 && Items.ContainsKey(ItemPosition.LEFT_HAND)) { m_pOwner.Send("Please remove the equipment in your left hand first."); return(false); } if (type == 900 && Items.ContainsKey(ItemPosition.RIGHT_HAND) && Items[ItemPosition.RIGHT_HAND].GetItemSubtype() == 421) { m_pOwner.Send("You cannot equip a shield while wearing a backsword."); return(false); } } // Gender check if (item.Itemtype.ReqSex != 0) { if (item.Itemtype.ReqSex != m_pOwner.Gender) { return(false); } } } ItemSort itemSort = item.GetSort(); if ((itemSort == ItemSort.ITEMSORT_USABLE || itemSort == ItemSort.ITEMSORT_USABLE2 || itemSort == ItemSort.ITEMSORT_USABLE3) && pos == ItemPosition.INVENTORY && item.Type / 1000 != 1050) { // Stores the item temporary data. m_pOwner.LastItemResource = 0; m_pOwner.LastUsedItem = item.Identity; m_pOwner.LastUsedItemTime = (uint)UnixTimestamp.Timestamp(); m_pOwner.LastUsedItemtype = item.Type; if ((item.Type >= 1000000 && item.Type < 1050000) || item.Type == 725065 || item.Type == 725066) // potion { if (!m_pOwner.IsAlive) { m_pOwner.Send(ServerString.STR_NOT_ALIVE); return(false); } if (item.Itemtype.Life > 0 && m_pOwner.QueryStatus(FlagInt.POISON_STAR) != null) { //m_pOwner.Send(ServerString.STR_CANT_HEAL_POISON_STAR); return(false); } if (item.Itemtype.Life > 0 && m_pOwner.Life >= m_pOwner.MaxLife) { //m_pOwner.Send(ServerString.STR_YOUR_LIFE_FULL); return(false); // return false so it wont spend processing recalculating the user stts } if (item.Itemtype.Mana > 0 && m_pOwner.Mana >= m_pOwner.MaxMana) { //m_pOwner.Send(ServerString.STR_YOUR_MANA_FULL); return(false); // return false so it wont spend processing recalculating the user stts } if (m_pOwner.IsGm) { m_pOwner.FillLife(); m_pOwner.FillMana(); return(false); } if (m_pOwner.Inventory.Remove(item.Type, 1)) { m_pOwner.AddAttribute(ClientUpdateType.HITPOINTS, item.Itemtype.Life, true); m_pOwner.AddAttribute(ClientUpdateType.MANA, item.Itemtype.Mana, true); } return(false); } if (item.Type == SpecialItem.MEMORY_AGATE) { item.SendCarry(); return(false); } if (item.Type == 723726) { if (m_pOwner.Inventory.Remove(item.Type, 1)) { m_pOwner.FillLife(); m_pOwner.FillMana(); } return(false); } if (item.Type == 723790 && m_pOwner.Inventory.Remove(723790)) { m_pOwner.AddAttribute(ClientUpdateType.HITPOINTS, 500, true); return(false); } if (item.Type == SpecialItem.TYPE_EXP_BALL || item.Type == 723834) { if (m_pOwner.ExpBallAmount >= 10) { int nDayOfYear = UnixTimestamp.ToDateTime(m_pOwner.LastUsedExpBall).DayOfYear; int nDayOfYear2 = DateTime.Now.DayOfYear; if (nDayOfYear == nDayOfYear2) { return(false); } m_pOwner.ExpBallAmount = 0; } if (m_pOwner.Inventory.Remove(item.Identity)) { m_pOwner.ExpBallAmount = (byte)(m_pOwner.ExpBallAmount + 1); m_pOwner.LastUsedExpBall = (uint)UnixTimestamp.Timestamp(); m_pOwner.Save(); m_pOwner.AwardExperience(ServerKernel.GetExpBallExperience(m_pOwner.Level), true, true); } return(false); } if ((item.Type >= 1060020 && item.Type <= 1060039) || item.Type == 1060102) { if (m_pOwner.Map.IsChgMapDisable()) { return(false); } m_pOwner.Inventory.Remove(item.Identity); } else if (item.Type / 1000 == 1060) { m_pOwner.Inventory.Remove(item.Identity); } m_pOwner.TaskItem = item; m_pOwner.GameAction.ProcessAction(item.Itemtype.IdAction, m_pOwner, null, item, null); return(false); } if (pos == ItemPosition.INVENTORY) { return(false); } if (pos == ItemPosition.LEFT_HAND && itemSort == ItemSort.ITEMSORT_WEAPON_SHIELD) { if (Items.ContainsKey(ItemPosition.RIGHT_HAND) && Items[ItemPosition.RIGHT_HAND].GetSort() == ItemSort.ITEMSORT_WEAPON_DOUBLE_HAND) { if (!m_pOwner.Magics.CheckType(10311)) { return(false); } } if (!Items.ContainsKey(ItemPosition.RIGHT_HAND)) { return(false); } } #endregion if (item.IsArrowSort()) { item.Position = ItemPosition.LEFT_HAND; } switch (item.Position) { case ItemPosition.RIGHT_HAND: if (pos != ItemPosition.RIGHT_HAND || (itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND && itemSort != ItemSort.ITEMSORT_WEAPON_DOUBLE_HAND && itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND2)) { item.Position = 0; return(false); } if ((itemSort == ItemSort.ITEMSORT_WEAPON_DOUBLE_HAND && Items.ContainsKey(ItemPosition.LEFT_HAND))) { Remove(ItemPosition.LEFT_HAND); } if (Items.ContainsKey(ItemPosition.RIGHT_HAND) && item.Position == ItemPosition.RIGHT_HAND) { Remove(ItemPosition.RIGHT_HAND, ItemRemoveMethod.REMOVE_TO_INVENTORY); } break; case ItemPosition.LEFT_HAND: if (itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND && itemSort != ItemSort.ITEMSORT_WEAPON_SHIELD && itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND2 && item.Type / 1000 != 1050) { item.Position = 0; return(false); } if (m_pOwner.Profession >= 100) { if (Items.ContainsKey(ItemPosition.LEFT_HAND) && Items[ItemPosition.LEFT_HAND] == item) { Remove(ItemPosition.LEFT_HAND, ItemRemoveMethod.REMOVE_TO_INVENTORY); } item.Position = 0; return(false); } if (item.IsArrowSort() && (!Items.ContainsKey(ItemPosition.RIGHT_HAND) || !Items[ItemPosition.RIGHT_HAND].IsBow())) { item.Position = 0; return(false); } if (Items.ContainsKey(ItemPosition.LEFT_HAND)) { Remove(ItemPosition.LEFT_HAND, ItemRemoveMethod.REMOVE_TO_INVENTORY); } break; case ItemPosition.ACCESSORY_R: { if ((itemSort != ItemSort.ITEMSORT_ACCESSORY) || item.Type / 10000 == 38) { item.Position = 0; return(false); } switch (item.Type / 10000) { case 38: item.Position = 0; return(false); } if (Items.ContainsKey(ItemPosition.ACCESSORY_R)) { Remove(ItemPosition.ACCESSORY_R); } break; } case ItemPosition.ACCESSORY_L: { if (itemSort != ItemSort.ITEMSORT_ACCESSORY || item.Type / 10000 == 37) { item.Position = 0; return(false); } switch (item.Type / 10000) { case 37: item.Position = 0; return(false); } if (Items.ContainsKey(ItemPosition.ACCESSORY_L)) { Remove(ItemPosition.ACCESSORY_L); } break; } default: if (pos == item.Position && Items.ContainsKey(item.Position)) { Remove(item.Position); } else if (pos != item.Position) { if (item.Position < ItemPosition.ALT_HEAD && pos != item.Position) { item.Position = 0; return(false); } if (item.Position >= ItemPosition.ALT_HEAD && item.Position <= ItemPosition.ALT_STEED) { switch (item.Position) { case ItemPosition.ALT_HEAD: { if (pos != ItemPosition.HEADWEAR) { return(false); } break; } case ItemPosition.ALT_NECKLACE: { if (pos != ItemPosition.NECKLACE) { return(false); } break; } case ItemPosition.ALT_RING: { if (pos != ItemPosition.RING) { return(false); } break; } case ItemPosition.ALT_WEAPON_R: { if (pos != ItemPosition.RIGHT_HAND) { return(false); } break; } case ItemPosition.ALT_WEAPON_L: { if (pos != ItemPosition.LEFT_HAND && pos != ItemPosition.RIGHT_HAND) { return(false); } break; } case ItemPosition.ALT_ARMOR: { if (pos != ItemPosition.ARMOR) { return(false); } break; } case ItemPosition.ALT_BOOTS: { if (pos != ItemPosition.BOOTS) { return(false); } break; } case ItemPosition.ALT_BOTTLE: { if (pos != ItemPosition.BOTTLE) { return(false); } break; } case ItemPosition.ALT_GARMENT: { if (pos != ItemPosition.GARMENT) { return(false); } break; } default: item.Position = 0; return(false); } if (Items.ContainsKey(item.Position) && Items.Count >= 40) { item.Position = 0; return(false); } if (Items.ContainsKey(item.Position)) { Remove(item.Position); } } else { item.Position = 0; return(false); } } break; } var itemEquip = new MsgItem { Identity = item.Identity, Action = ItemAction.EQUIP, Param1 = (uint)item.Position }; // We build the item information packet MsgItemInformation itemInfo = item.InformationPacket(!isLogin); // If we are logging in, we set this as default, because the item hasnt been // created yet, otherwise, we send this as an update. if (isLogin) { itemInfo.ItemMode = ItemMode.DEFAULT; m_pOwner.Send(itemInfo); } else { //itemInfo.ItemMode = ItemMode.Update; if (!m_pOwner.Inventory.Contains(item.Identity)) { return(false); } Item trash; m_pOwner.Inventory.Items.TryRemove(item.Identity, out trash); item.Save(); m_pOwner.RecalculateAttributes(); } m_pOwner.Send(itemEquip); Items.TryAdd(item.Position, item); SendEquipedItems(); item.SendPurification(); item.TryUnlockItem(); item.SendItemLockTime(); switch (item.Position) { case ItemPosition.HEADWEAR: m_pOwner.Helmet = item.Type; m_pOwner.HelmetColor = (ushort)item.Color; break; case ItemPosition.ARMOR: m_pOwner.Armor = item.Type; m_pOwner.ArmorColor = (ushort)item.Color; break; case ItemPosition.LEFT_HAND: m_pOwner.LeftHand = item.Type; m_pOwner.ShieldColor = (ushort)item.Color; break; case ItemPosition.RIGHT_HAND: m_pOwner.RightHand = item.Type; break; case ItemPosition.GARMENT: m_pOwner.Garment = item.Type; break; case ItemPosition.ACCESSORY_R: m_pOwner.RightAccessory = item.Type; break; case ItemPosition.ACCESSORY_L: m_pOwner.LeftAccessory = item.Type; break; case ItemPosition.STEED: m_pOwner.MountType = item.Type; m_pOwner.MountColor = item.SocketProgress; m_pOwner.MountPlus = item.Plus; break; case ItemPosition.STEED_ARMOR: m_pOwner.MountArmor = item.Type; break; } return(true); }
public static void HandleComposition(Character pRole, MsgDataArray pMsg) { Item target, source; if (pRole.Inventory.Items.TryGetValue(pMsg.MainIdentity, out target) && pRole.Inventory.Items.TryGetValue(pMsg.MinorIdentity, out source)) { if (target.Identity == source.Identity) { return; } // Sort check uint oldPlus = target.Plus; if (!pRole.Inventory.Items.ContainsKey(source.Identity)) { return; } switch (pMsg.Mode) { case CompositionMode.CMP_ITEM_PLUS: { if (source.Type < SpecialItem.TYPE_STONE1 || source.Type > SpecialItem.TYPE_STONE8) { if (target.GetSort() != source.GetSort()) { pRole.Send(ServerString.STR_COMPOSITION_NOT_MATCH); return; } if (source.Plus == 0 || source.Plus > 8) { pRole.Send(ServerString.STR_COMPOSITION_NOT_MINOR_ITEM); return; } } if (target.Plus >= 12) { pRole.Send(ServerString.STR_COMPOSITION_MAX); return; } target.CompositionProgress += StonePlus(source.Plus, false); while (target.CompositionProgress >= GetAddLevelExp(target.Plus, false) && target.Plus < 12) { if (target.Plus < 12) { target.CompositionProgress -= GetAddLevelExp(target.Plus, false); target.Plus++; } else { target.CompositionProgress = 0; } } break; } case CompositionMode.CMP_STEED_PLUS: { target.CompositionProgress += StonePlus(source.Plus, true); while (target.CompositionProgress >= GetAddLevelExp(target.Plus, true) && target.Plus < 12) { if (target.Plus < 12) { target.CompositionProgress -= GetAddLevelExp(target.Plus, true); target.Plus++; } } break; } case CompositionMode.CMP_STEED_PLUS_NEW: { target.CompositionProgress += StonePlus(source.Plus, true); while (target.CompositionProgress >= GetAddLevelExp(target.Plus, true) && target.Plus < 12) { if (target.Plus < 12) { target.CompositionProgress -= GetAddLevelExp(target.Plus, true); target.Plus++; } } int color1 = (int)target.SocketProgress; int color2 = (int)source.SocketProgress; int B1 = color1 & 0xFF; int B2 = color2 & 0xFF; int G1 = (color1 >> 8) & 0xFF; int G2 = (color2 >> 8) & 0xFF; int R1 = (color1 >> 16) & 0xFF; int R2 = (color2 >> 16) & 0xFF; int newB = (int)Math.Floor(0.9 * B1) + (int)Math.Floor(0.1 * B2); int newG = (int)Math.Floor(0.9 * G1) + (int)Math.Floor(0.1 * G2); int newR = (int)Math.Floor(0.9 * R1) + (int)Math.Floor(0.1 * R2); target.SocketProgress = (uint)(newB | (newG << 8) | (newR << 16)); break; } } if (!pRole.Inventory.Remove(source.Identity)) { return; } //pRole.AddMentorComposing((ushort)(StonePlus(source.Plus, false) / 10)); if (oldPlus < target.Plus && target.Plus >= 6) { ServerKernel.SendMessageToAll(pRole.Gender == 1 ? string.Format(ServerString.STR_COMPOSITION_OVERPOWER_MALE, pRole.Name, target.Itemtype.Name, target.Plus) : string.Format(ServerString.STR_COMPOSITION_OVERPOWER_FEMALE, pRole.Name, target.Itemtype.Name, target.Plus), ChatTone.TOP_LEFT); } target.Save(); pRole.Send(target.InformationPacket(true)); } }
public static void HandleNobility(Character pRole, MsgPeerage pMsg) { switch (pMsg.Action) { #region List case NobilityAction.LIST: { int maxPages = 5; int page = pMsg.Data; int maxPerPage = 10; int value = 0; int amount = 0; int minValue = page * maxPerPage; int maxValue = (page + 1) * maxPerPage; MsgPeerage nPacket = new MsgPeerage(32 + 48); nPacket.Action = NobilityAction.LIST; ushort maxCount = (ushort)Math.Ceiling((double)ServerKernel.Nobility.Count / 10); nPacket.DataShort = (ushort)(maxCount > maxPages ? maxPages : maxCount); foreach (DbDynaRankRec dynaRank in ServerKernel.Nobility.Values.OrderByDescending(x => x.Value)) { if (value >= maxPages * maxPerPage) { break; } if (value < minValue) { value++; continue; } if (value >= maxValue) { break; } uint lookface = 0; Client pPlayer = ServerKernel.Players.Values.FirstOrDefault(x => x.Identity == dynaRank.UserIdentity); if (pPlayer != null && pPlayer.Character != null) { lookface = pPlayer.Character.Body; } NobilityLevel rank = Nobility.GetNobilityLevel((uint)value); nPacket.WriteNobilityData(dynaRank.UserIdentity, lookface, dynaRank.Username, dynaRank.Value, rank, value); value++; amount++; } nPacket.DataHighLow = (ushort)amount; nPacket.WriteByte((byte)amount, 28); pRole.Send(nPacket); break; } #endregion #region Query Remaining Silver case NobilityAction.QUERY_REMAINING_SILVER: { var nPacket = new MsgPeerage { Action = NobilityAction.QUERY_REMAINING_SILVER, DataLong = GetRemainingSilver((NobilityLevel)pMsg.Data, pRole.NobilityDonation), Data3 = 60, // The max amount of players in the ranking Data4 = (uint)pRole.Nobility.Level }; pRole.Send(nPacket); break; } #endregion #region Donate case NobilityAction.DONATE: { if (pRole.Level < 70) { pRole.Send(ServerString.STR_PEERAGE_DONATE_ERR_BELOW_LEVEL); return; } long donation = pMsg.DataLong; if (donation < 3000000) { pRole.Send(ServerString.STR_PEERAGE_DONATE_ERR_BELOW_UNDERLINE); return; } if (donation > int.MaxValue) { donation = int.MaxValue; } NobilityLevel oldRank = pRole.NobilityRank; int oldPos = pRole.Nobility.GetRanking; // donate cps if (pMsg.Data2 >= 1) { uint cps = (uint)donation / 50000; if (cps > pRole.Emoney) { pRole.Send(ServerString.STR_NOT_ENOUGH_EMONEY); return; } if (!pRole.ReduceEmoney(cps, true)) { return; } pRole.Nobility.Donate(donation); //pRole.Send("You can only donate silvers to the empire."); //return; } if (pMsg.Data2 == 0) // donate silvers { if (!pRole.ReduceMoney(donation, true)) { return; } pRole.Nobility.Donate(donation); } if (!ServerKernel.Nobility.ContainsKey(pRole.Identity)) { ServerKernel.Nobility.TryAdd(pRole.Identity, pRole.Nobility.Database); } pRole.Nobility.UpdateRanking(); pRole.Nobility.UpdateLevel(); if (pRole.NobilityRank > NobilityLevel.EARL && oldPos > pRole.Nobility.GetRanking) { foreach (var plr in ServerKernel.Players.Values.Where(x => x.Character.NobilityRank > NobilityLevel.EARL)) { plr.Character.Nobility.SendNobilityIcon(); } } else if (pRole.NobilityRank > NobilityLevel.EARL) { pRole.Nobility.SendNobilityIcon(); } if (pRole.NobilityRank > oldRank) { switch (pRole.NobilityRank) { case NobilityLevel.KING: if (pRole.Gender == 1) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_KING, pRole.Name), ChatTone.CENTER); } else { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_QUEEN, pRole.Name), ChatTone.CENTER); } break; case NobilityLevel.PRINCE: if (pRole.Gender == 1) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_DUKE, pRole.Name), ChatTone.CENTER); } else { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_DUCHESS, pRole.Name), ChatTone.CENTER); } break; case NobilityLevel.DUKE: if (pRole.Gender == 1) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_MARQUIS, pRole.Name), ChatTone.CENTER); } else { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_MARQUISE, pRole.Name), ChatTone.CENTER); } break; case NobilityLevel.EARL: if (pRole.Gender == 1) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_EARL, pRole.Name), ChatTone.TOP_LEFT); } else { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_COUNTESS, pRole.Name), ChatTone.TOP_LEFT); } break; case NobilityLevel.BARON: if (pRole.Gender == 1) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_VISCOUNT, pRole.Name), ChatTone.TOP_LEFT); } else { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_VISCOUNTESS, pRole.Name), ChatTone.TOP_LEFT); } break; case NobilityLevel.KNIGHT: if (pRole.Gender == 1) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_BARON, pRole.Name), ChatTone.TOP_LEFT); } else { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_BARONESS, pRole.Name), ChatTone.TOP_LEFT); } break; } } break; } #endregion } }
public void OnTimer() { if (m_pState == EventState.ERROR) { return; } DateTime now = DateTime.Now; int nNow = int.Parse(now.ToString("HHmmss")); switch (m_pState) { case EventState.IDLE: { if (nNow % 10000 < 1000 || nNow % 10000 >= 2000) { return; } // todo check what's needed before event start m_pState = EventState.STARTING; break; } case EventState.STARTING: { foreach (var plr in m_pStatistic.Values) { plr.HitsDealtNow = 0; plr.HitsTakenNow = 0; } ServerKernel.SendMessageToAll("Line Skill PK Tournament has started.", ChatTone.TALK); m_pState = EventState.RUNNING; break; } case EventState.RUNNING: { if (nNow % 10000 >= 1000 && nNow % 10000 < 2000) { if (m_pTableTimeOut.ToNextTime()) { SendTable(); } } else { m_pState = EventState.FINISHING; } break; } case EventState.FINISHING: { ServerKernel.SendMessageToAll("The Line Skill PK Tournament has ended.", ChatTone.TOP_LEFT); foreach (var plr in m_pStatistic.Values.OrderByDescending(x => x.KDA) .ThenByDescending(x => x.HitsDealtNow) .ThenBy(x => x.HitsTakenNow) .Where(x => x.HitsDealtNow > 0)) { uint gold = 0; uint emoney = 0; try { switch (GetRank(plr.Identity)) { case 1: gold = ServerKernel.LineSkillGoldReward[0]; emoney = ServerKernel.LineSkillEmoneyReward[0]; ServerKernel.SendMessageToAll( string.Format("Congratulations! {0} has won the Line Skill PK Tournament.", plr.Name), ChatTone.TALK); break; case 2: gold = ServerKernel.LineSkillGoldReward[1]; emoney = ServerKernel.LineSkillEmoneyReward[1]; ServerKernel.SendMessageToAll( string.Format("{0} has taken the 2nd place in the Line Skill PK Tournament.", plr.Name), ChatTone.TALK); break; case 3: gold = ServerKernel.LineSkillGoldReward[2]; emoney = ServerKernel.LineSkillEmoneyReward[2]; ServerKernel.SendMessageToAll( string.Format("{0} has taken the 3rd place in the Line Skill PK Tournament.", plr.Name), ChatTone.TALK); break; default: gold = ServerKernel.LineSkillGoldReward[3]; emoney = ServerKernel.LineSkillEmoneyReward[3]; break; } } catch { ServerKernel.Log.SaveLog("ERROR MESSAGE GET PRIZE LINE SKILL", true, LogType.ERROR); } Client player; if (ServerKernel.Players.TryGetValue(plr.Identity, out player)) { if (player.Character == null) { continue; //? } player.Character.AwardMoney(gold); player.Character.AwardEmoney(emoney); player.Character.Send(string.Format("You received {0} silvers and {1} CPs for playing on the Line Skill PK Tournament.", gold, emoney)); } else { DbUser user = Database.Characters.SearchByIdentity(plr.Identity); if (user == null) { continue; } if (user.Money + gold > int.MaxValue) { user.Money = int.MaxValue; } else { user.Money += gold; } if (user.Emoney + emoney > int.MaxValue) { user.Emoney = int.MaxValue; } else { user.Emoney += emoney; } Database.Characters.SaveOrUpdate(user); } } m_pState = EventState.ENDED; break; } case EventState.ENDED: { foreach (var plr in m_pMap.Players.Values) { plr.ChangeMap(plr.RecordMapX, plr.RecordMapY, plr.RecordMapIdentity); } ServerKernel.SendMessageToAll("Line Skill PK Tournament has ended.", ChatTone.TOP_LEFT); m_pState = EventState.IDLE; break; } } }
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 HandleFlowers(Character pUser, MsgFlower pMsg) { switch (pMsg.Mode) { case 0: // give flower { string szInfo = pMsg.ReadString(16, 18).Trim('\0'); string[] pInfo = szInfo.Split(' '); if (pInfo.Length < 3) { return; } uint idTarget = uint.Parse(pInfo[0]); ushort usAmount = ushort.Parse(pInfo[1]); var pType = (FlowerType)uint.Parse(pInfo[2][0].ToString()); Client pTargetClient; if (!ServerKernel.Players.TryGetValue(idTarget, out pTargetClient)) { pUser.Send("The target doesn't exist."); return; } if (pTargetClient.Character == null) { // should not happen return; } Character pTarget = pTargetClient.Character; if (!pUser.IsAlive) { pUser.Send(ServerString.STR_FLOWER_SENDER_NOT_ALIVE); return; } if (pUser.Gender != 1) { pUser.Send(ServerString.STR_FLOWER_SENDOR_NOT_MALE); return; } if (pTarget.Gender != 2) { pUser.Send(ServerString.STR_FLOWER_RECEIVER_NOT_FEMALE); return; } if (pUser.Level < 40) { pUser.Send(ServerString.STR_FLOWER_LEVEL_TOO_LOW); return; } Item pFlower; if (pMsg.ItemIdentity == 0) { if (pUser.RedRoses >= uint.Parse(DateTime.Now.ToString("yyyyMMdd"))) { pUser.Send(ServerString.STR_FLOWER_HAVE_SENT_TODAY); return; } // player sending red rose normal switch (pUser.Owner.VipLevel) { case 0: usAmount = 1; break; case 1: usAmount = 2; break; case 2: usAmount = 5; break; case 3: usAmount = 7; break; case 4: usAmount = 9; break; case 5: usAmount = 12; break; default: usAmount = 15; break; } pType = FlowerType.RED_ROSE; pUser.RedRoses = uint.Parse(DateTime.Now.ToString("yyyyMMdd")); } else if (pUser.Inventory.Items.TryGetValue(pMsg.ItemIdentity, out pFlower)) { // player sending packs switch (pFlower.GetItemSubtype()) { case 751: // red rose pType = FlowerType.RED_ROSE; break; case 752: // white rose pType = FlowerType.WHITE_ROSE; break; case 753: // orchid rose pType = FlowerType.ORCHID; break; case 754: // tulip rose pType = FlowerType.TULIP; break; default: return; } usAmount = pFlower.Durability; if (!pUser.Inventory.Remove(pMsg.ItemIdentity)) { return; } } else { pUser.Send("You don't have the required item."); return; } switch (pType) { case FlowerType.RED_ROSE: pTarget.RedRoses += usAmount; break; case FlowerType.WHITE_ROSE: pTarget.WhiteRoses += usAmount; break; case FlowerType.ORCHID: pTarget.Orchids += usAmount; break; case FlowerType.TULIP: pTarget.Tulips += usAmount; break; } switch (usAmount) { case 3: switch (pType) { case FlowerType.RED_ROSE: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_RED_3, pTarget.Name, pUser.Name)); break; case FlowerType.WHITE_ROSE: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_WHITE_3, pTarget.Name, pUser.Name)); break; case FlowerType.ORCHID: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_LILY_3, pTarget.Name, pUser.Name)); break; case FlowerType.TULIP: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_TULIP_3, pTarget.Name, pUser.Name)); break; } break; case 9: switch (pType) { case FlowerType.RED_ROSE: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_RED_9, pTarget.Name, pUser.Name)); break; case FlowerType.WHITE_ROSE: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_WHITE_9, pTarget.Name, pUser.Name)); break; case FlowerType.ORCHID: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_LILY_9, pTarget.Name, pUser.Name)); break; case FlowerType.TULIP: pTarget.Send(string.Format(ServerString.STR_FLOWER_GM_PROMPT_TULIP_9, pTarget.Name, pUser.Name)); break; } break; case 99: switch (pType) { case FlowerType.RED_ROSE: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_RED_99, pTarget.Name, pUser.Name), ChatTone.CENTER); break; case FlowerType.WHITE_ROSE: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_WHITE_99, pTarget.Name, pUser.Name), ChatTone.CENTER); break; case FlowerType.ORCHID: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_LILY_99, pTarget.Name, pUser.Name), ChatTone.CENTER); break; case FlowerType.TULIP: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_TULIP_99, pTarget.Name, pUser.Name), ChatTone.CENTER); break; } break; case 999: switch (pType) { case FlowerType.RED_ROSE: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_RED_999, pTarget.Name, pUser.Name), ChatTone.CENTER); break; case FlowerType.WHITE_ROSE: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_WHITE_999, pTarget.Name, pUser.Name), ChatTone.CENTER); break; case FlowerType.ORCHID: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_LILY_999, pTarget.Name, pUser.Name), ChatTone.CENTER); break; case FlowerType.TULIP: ServerKernel.SendMessageToAll(string.Format(ServerString.STR_FLOWER_GM_PROMPT_TULIP_999, pTarget.Name, pUser.Name), ChatTone.CENTER); break; } break; default: pTarget.Send(string.Format(ServerString.STR_FLOWER_RECEIVER_PROMPT, pUser.Name)); break; } pUser.Send(pMsg); pUser.Send(new MsgFlower { Mode = 0, Identity = pUser.Identity }); pTarget.Send(new MsgFlower { Sender = pUser.Name, Receptor = pTarget.Name, SendAmount = usAmount, SendFlowerType = pType }); ServerKernel.FlowerRanking.AddFlowers(pType, usAmount, pTarget.Identity); break; } default: { ServerKernel.Log.SaveLog(string.Format("Packet 1150:{0} not handled", pMsg.Mode), true, "p1150", LogType.WARNING); break; } } }
public static void HandleSelfSynMemAwardRank(Character pUser, MsgSelfSynMemAwardRank pMsg) { switch (pMsg.Type) { case 0: // CTF reward guilds ranking { var rank = ServerKernel.Syndicates.Values.Where(x => x.MoneyPrize > 0 || x.EmoneyPrize > 0) .OrderByDescending(x => x.MoneyPrize) .ThenByDescending(x => x.EmoneyPrize) .ToList(); int idx = 0; for (; idx < 5; idx++) { if (idx >= rank.Count) { break; } pMsg.AddToRanking(rank[idx].Name, rank[idx].EmoneyPrize, rank[idx].MoneyPrize); } //pMsg.AddToRanking("Guild1", 50000, 500000000); //pMsg.AddToRanking("Guild2", 40000, 450000000); //pMsg.AddToRanking("Guild3", 30000, 400000000); //pMsg.AddToRanking("Guild4", 20000, 300000000); #region Testing Offsets //pMsg.Count = 2; //pMsg.WriteUInt(30, 30); //pMsg.WriteLong(34, 34); //pMsg.WriteString("NameOfGuild", 16, 42); //pMsg.WriteUInt(82, 82); //pMsg.WriteLong(86, 86); //pMsg.WriteString("NameOfGuild2", 16, 94); #endregion pMsg.EmoneyPrize = pUser.Syndicate.EmoneyPrize; pMsg.MoneyPrize = pUser.Syndicate.MoneyPrize; pUser.Send(pMsg); break; } case 1: // Syndicate last CTF reward ranking { // offset 22 your syn next money reward // offset 18 your syn next emoney reward // offset 10 num page when receiving and result amount when sending // pMsg.WriteUInt(uint.MaxValue, 22); // pMsg.WriteUInt(45546, 18); pMsg.EmoneyPrize = pUser.Syndicate.EmoneyPrize; pMsg.MoneyPrize = pUser.Syndicate.MoneyPrize; var rank = ServerKernel.CaptureTheFlag.GetSyndicateMembers(pUser.SyndicateIdentity) .Where(x => x.Value3 > 0) .OrderByDescending(x => x.Value3).ToList(); int nRank = 0; for (; nRank < rank.Count; nRank++) { if (rank[nRank].PlayerIdentity == pUser.Identity) { break; } } if (rank.Count - 1 >= nRank) { pMsg.AddToRanking((uint)(nRank + 1), pUser.Identity, pUser.Name, rank[nRank].Value5, (uint)rank[nRank].Value6, (uint)rank[nRank].Value3); } int startIdx = (int)((pMsg.Page - 1) * 4); int idx = startIdx; for (; idx < startIdx + 4; idx++) { if (idx >= rank.Count) { break; } var res = rank[idx]; pMsg.AddToRanking((uint)(idx + 1), res.PlayerIdentity, res.PlayerName, res.Value5, (uint)res.Value6, (uint)res.Value3); } //if (pMsg.ReadUShort(10) == 1) //{ // pMsg.AddToRanking(1, 1000, pUser.Name, 545468792, 32000, 8698); // pMsg.AddToRanking(2, 1000, "Ninja[PM]", 464564654, 32001, 8697); // pMsg.AddToRanking(3, 1000, "Archer[PM]", 42346688, 32002, 8696); // pMsg.AddToRanking(4, 1000, "Trojan[PM]", 12313436, 32003, 8695); //} //else if (pMsg.ReadUShort(10) == 2) //{ // pMsg.AddToRanking(5, 1000, "FireTaoist[PM]", 546463, 32004, 8694); // pMsg.AddToRanking(6, 1000, "WaterTaoist[PM]", 546463, 32004, 8694); // pMsg.AddToRanking(7, 1000, "Warrior[PM]", 546463, 32004, 8694); // pMsg.AddToRanking(8, 1000, "Trojan2[PM]", 546463, 32004, 8694); //} //else if (pMsg.ReadUShort(10) == 3) //{ // pMsg.AddToRanking(9, 1000, "Ninja2[PM]", 546463, 32004, 8694); // pMsg.AddToRanking(10, 1000, "WaterTao[PM]", 546463, 32004, 8694); // pMsg.AddToRanking(11, 1000, "WaterTaois[PM]", 546463, 32004, 8694); // pMsg.AddToRanking(12, 1000, "FiretTas[PM]", 546463, 32004, 8694); //} pMsg.ResultNum = (uint)rank.Count; pUser.Send(pMsg); break; } case 3: // set emoney prize { Syndicate pSyn = pUser.Syndicate; if (pSyn == null) { return; } if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER) { return; } if (pSyn.EmoneyPrize > 0 && pMsg.EmoneyPrize <= pSyn.EmoneyPrize) { return; } uint deductEmoney = pMsg.EmoneyPrize; if (pSyn.EmoneyPrize <= 0) { if (deductEmoney > pSyn.EmoneyDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_EMONEY); return; } } else { if (deductEmoney - pSyn.EmoneyPrize > pSyn.EmoneyDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_EMONEY); return; } deductEmoney -= pSyn.EmoneyPrize; } pSyn.EmoneyDonation -= deductEmoney; pSyn.EmoneyPrize = pMsg.EmoneyPrize; string szEvent = ServerKernel.NextSyndicateEvent(); ServerKernel.SendMessageToAll(string.Format(ServerString.STR_SYNREWARD_SET, pUser.Name, pSyn.Name, pMsg.MoneyPrize, pMsg.EmoneyPrize, szEvent), ChatTone.TALK); break; } case 4: // set money prize { Syndicate pSyn = pUser.Syndicate; if (pSyn == null) { return; } if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER) { return; } if (pSyn.MoneyPrize > 0 && pMsg.MoneyPrize <= pSyn.MoneyPrize) { return; } ulong deductMoney = (ulong)pMsg.MoneyPrize; if (pSyn.MoneyPrize <= 0) { if (deductMoney > pSyn.SilverDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_MONEY); return; } } else { if (deductMoney - (ulong)pSyn.MoneyPrize > pSyn.SilverDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_MONEY); return; } deductMoney -= (ulong)pSyn.MoneyPrize; } pSyn.SilverDonation -= deductMoney; pSyn.MoneyPrize = pMsg.MoneyPrize; string szEvent = ServerKernel.NextSyndicateEvent(); ServerKernel.SendMessageToAll(string.Format(ServerString.STR_SYNREWARD_SET, pUser.Name, pSyn.Name, pMsg.MoneyPrize, pMsg.EmoneyPrize, szEvent), ChatTone.TALK); break; } case 5: // set money & emoney prize { Syndicate pSyn = pUser.Syndicate; if (pSyn == null) { return; } if (pUser.SyndicateRank != SyndicateRank.GUILD_LEADER) { return; } if (pSyn.MoneyPrize > 0 && pMsg.MoneyPrize <= pSyn.MoneyPrize) { return; } if (pSyn.EmoneyPrize > 0 && pMsg.EmoneyPrize <= pSyn.EmoneyPrize) { return; } ulong deductMoney = (ulong)pMsg.MoneyPrize; uint deductEmoney = pMsg.EmoneyPrize; if (pSyn.MoneyPrize <= 0) { if (deductMoney > pSyn.SilverDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_MONEY); return; } } else { if (deductMoney - (ulong)pSyn.MoneyPrize > pSyn.SilverDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_MONEY); return; } deductMoney -= (ulong)pSyn.MoneyPrize; } if (pSyn.EmoneyPrize <= 0) { if (deductEmoney > pSyn.EmoneyDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_EMONEY); return; } } else { if (deductEmoney - pSyn.EmoneyPrize > pSyn.EmoneyDonation) { pUser.Send(ServerString.STR_SYNREWARD_NOT_ENOUGH_EMONEY); return; } deductEmoney -= pSyn.EmoneyPrize; } pSyn.SilverDonation -= deductMoney; pSyn.EmoneyDonation -= deductEmoney; pSyn.MoneyPrize = pMsg.MoneyPrize; pSyn.EmoneyPrize = pMsg.EmoneyPrize; string szEvent = ServerKernel.NextSyndicateEvent(); ServerKernel.SendMessageToAll(string.Format(ServerString.STR_SYNREWARD_SET, pUser.Name, pSyn.Name, pMsg.MoneyPrize, pMsg.EmoneyPrize, szEvent), ChatTone.TALK); break; } case 8: // Current players from syndicate ranking on CTF { // 18 is current exploit //pMsg.WriteUInt(18, 18); //pMsg.AddToRanking("PlayerName0", 500); //pMsg.AddToRanking("PlayerName1", 400); //pMsg.AddToRanking("PlayerName2", 300); //pMsg.AddToRanking("PlayerName3", 200); //pMsg.AddToRanking("PlayerName4", 100); var rank = ServerKernel.CaptureTheFlag.GetSyndicateMembers(pUser.SyndicateIdentity) .Where(x => x.Value3 > 0) .OrderByDescending(x => x.Value3) .ToList(); int startIdx = (int)(pMsg.Page * 5); int idx = startIdx; for (; idx < startIdx + 5; idx++) { if (idx >= rank.Count) { break; } var res = rank[idx]; pMsg.AddToRanking(res.PlayerName, (uint)res.Value3); if (res.PlayerIdentity == pUser.Identity) { pMsg.Exploits = (uint)res.Value3; } } pMsg.ResultNum = (uint)rank.Count; #region Testing Offsets //pMsg.Count = 3; //pMsg.WriteString("KOSKSOSK", 16, 30); // name //pMsg.WriteUInt(46, 46); // exploit //pMsg.WriteString("KOSKSOSK2", 16, 50); //pMsg.WriteUInt(46, 66); //pMsg.WriteString("KOSKSOSK3", 16, 70); //pMsg.WriteUInt(46, 86); #endregion pUser.Send(pMsg); break; } case 9: // CTF window (Arena) { // offset 18 your syn point amount ctf running ServerKernel.CaptureTheFlag.SendInterfaceRanking(pUser, pMsg); break; } default: { Console.WriteLine("Unhandled type 1063:{0}", pMsg.Type); break; } } }
public static void ServerTasks() { m_pLoginMs.Update(); m_pLogin.Update(); m_t_1Second.Startup(1); m_tPlayer.Startup(1); m_tItem.Startup(5); while (true) { try { // handle socket connection if (ServerKernel.LoginServer == null && m_pLoginMs.ToNextTime()) { ServerKernel.Log.SaveLog("Connect to the account server...", true, LogType.MESSAGE); try { var pSocket = new LoginSocket(); pSocket.ConnectTo(ServerKernel.LoginServerAddress, ServerKernel.LoginServerPort); ServerKernel.LoginServer = new LoginClient(pSocket, pSocket, null); try { ServerKernel.Log.SaveLog("Connected to the account server!", true, LogType.MESSAGE); ServerKernel.Log.SaveLog("Server will attempt a connection after 1 second...", true, LogType.MESSAGE); Thread.Sleep(1000); var pMsg = new MsgLoginSvAuthRequest(ServerKernel.HelloSendString); ServerKernel.LoginServer.Send(pMsg); } catch (SocketException ex) { ServerKernel.LoginServer = null; pSocket.Dispose(); pSocket = null; } } catch (SocketException ex) { if (ex.ErrorCode != 10061 && ex.ErrorCode != 10057) { ServerKernel.Log.SaveLog("Exception thrown while trying to connect to login server", true, LogType.ERROR); ServerKernel.Log.SaveLog(ex.ToString(), false, LogType.EXCEPTION); } } } // clean the login request list if (ServerKernel.LoginServer != null) { if (m_pLogin.ToNextTime() && ServerKernel.LoginQueue.Count > 0) { List <LoginRequest> temp = ServerKernel.LoginQueue.Values.Where(x => x.IsExpired()).ToList(); LoginRequest trash; foreach (var pReq in temp) { ServerKernel.LoginQueue.TryRemove(pReq.AccountIdentity, out trash); } } } if (m_t_1Second.ToNextTime()) { Program.UpdateTitle(); } if (!m_tItem.ToNextTime()) { continue; } foreach (Client user in ServerKernel.Players.Values.ToList()) { if (user.Character == null) { continue; } if (!user.Character.LoginComplete || user.Character.Inventory == null || user.Character.Equipment == null) { continue; } foreach (Item item in user.Character.Inventory.Items.Values) { if (!item.ArtifactIsActive() || !item.RefineryIsActive()) { item.CheckForPurificationExpired(); } if (item.ItemExpired()) { user.Character.Inventory.Remove(item.Identity); ServerKernel.Log.GmLog("item_expire", string.Format("Item[{0}] type[{1}] owner[{2}] expired-at[{3}]", item.Identity, item.Type, item.PlayerIdentity, UnixTimestamp.Timestamp())); } item.TryUnlockItem(); } foreach (Item item in user.Character.Equipment.Items.Values) { if (!item.ArtifactIsActive() || !item.RefineryIsActive()) { item.CheckForPurificationExpired(); } if (item.ItemExpired()) { user.Character.Equipment.Remove(item.Position, Equipment.ItemRemoveMethod.DELETE); ServerKernel.Log.GmLog("item_expire", string.Format("Item[{0}] type[{1}] owner[{2}] expired-at[{3}]", item.Identity, item.Type, item.PlayerIdentity, UnixTimestamp.Timestamp())); } item.TryUnlockItem(); } try { foreach (Warehouse wh in user.Character.Warehouses.Values.ToList()) { foreach (Item item in wh.Items.Values.ToList()) { if (!item.ArtifactIsActive() || !item.RefineryIsActive()) { item.CheckForPurificationExpired(); } if (item.ItemExpired()) { wh.Delete(item.Identity); ServerKernel.Log.GmLog("item_expire", string.Format("Item[{0}] type[{1}] owner[{2}] expired-at[{3}]", item.Identity, item.Type, item.PlayerIdentity, UnixTimestamp.Timestamp())); } } } } catch { } } foreach (var detained in ServerKernel.DetainedObjects.Values.Where(x => x.IsItem())) { detained.OnTimer(); } foreach (Map map in ServerKernel.Maps.Values) { foreach (IScreenObject _object in map.GameObjects.Values) { if (_object is MapItem) { var item = _object as MapItem; if (item.IsDisappear()) { map.RemoveItem(item); item.SelfDelete(); } } } } if (m_tRestart.IsActive() && m_tRestart.ToNextTime(30)) { m_nRestartAlert++; if (MaintenanceRemainingSeconds() <= 0) { ServerKernel.SendMessageToAll("Server is being brought down to maintenance.", ChatTone.TALK); Program.SaveAll(); Environment.Exit(0); break; } //string msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY, // MaintenanceRemainingSeconds()); int remainSecs = MaintenanceRemainingSeconds(); string msg = ""; if (remainSecs == 60) { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_MINUTE, remainSecs / 60); } else if (remainSecs > 60 && remainSecs % 60 == 0) { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_MINUTES, remainSecs / 60); } else if (remainSecs % 60 > 0) { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_MIN_AND_SECS, remainSecs / 60, remainSecs % 60); } else { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_SECONDS, remainSecs); } ServerKernel.SendMessageToAll(msg, ChatTone.CENTER); ServerKernel.Log.SaveLog(msg, true, LogType.DEBUG); } } catch (Exception ex) { ServerKernel.Log.SaveLog(ex.ToString(), true, LogType.EXCEPTION); } finally { Thread.Sleep(1000); } } }
public static void HandleChangeName(Character pUser, MsgChangeName pMsg) { NameChangeLogRepo repo = new NameChangeLogRepo(); var nameChanges = repo.FetchByUser(pUser.Identity); bool waitingChange = false; ushort usDone = 0; if (nameChanges != null) { int now = UnixTimestamp.Timestamp(); foreach (var name in nameChanges) { if (now < name.Timestamp + YEAR_INTERVAL) { usDone += 1; } if (name.Changed == 0) { waitingChange = true; } } } switch (pMsg.Mode) { case ChangeNameMode.REQUEST_INFO: { pMsg.Param1 = usDone; pMsg.Param2 = MAX_PER_YEAR; pUser.Send(pMsg); break; } case ChangeNameMode.CHANGE_NAME: { if (waitingChange) { pUser.Send("You are waiting for your name to change. Please wait until next maintenance and try again.", ChatTone.TALK); return; } if (usDone >= MAX_PER_YEAR) { pUser.Send("You cannot change your name anymore."); return; } string szName = pMsg.Name; if (!CheckName(szName)) { pMsg.Mode = ChangeNameMode.CHANGE_NAME_ERROR; pUser.Send(pMsg); pUser.Send("The name you input have invalid characters."); return; } if (!pUser.ReduceEmoney(5000)) { pUser.Send(ServerString.STR_NOT_ENOUGH_EMONEY); return; } szName = szName.Replace(' ', '~'); DbNameChangeLog pName = new DbNameChangeLog { UserIdentity = pUser.Identity, OldName = pUser.Name, NewName = szName, Timestamp = (uint)UnixTimestamp.Timestamp() }; if (!repo.SaveOrUpdate(pName)) { pUser.AwardEmoney(5000); pUser.Send("Error while trying to save your new name. You will receive your 5,000 CPs back."); return; } ServerKernel.SendMessageToAll(string.Format("{0} has changed his/her name to {1}. The new name will take effect after the next maintenance.", pUser.Name, szName), ChatTone.TALK); pMsg.Mode = ChangeNameMode.CHANGED_SUCCESSFULY; pUser.Send(pMsg); break; } default: { ServerKernel.Log.SaveLog("unhandled type " + pMsg.Mode, true, "name_change", LogType.ERROR); break; } } }
public void OnTimer() { if (m_pState == SyndicateWarState.NOT_BUILT) { return; } int now = int.Parse(DateTime.Now.ToString("HHmmss")); if (m_pState == SyndicateWarState.NOT_RUNNING && (now >= _STARTUP_TIME && now < _END_TIME)) { // start foreach (var syn in m_pSynPoints.Values) { syn.Value1 = 0; m_pRepo.SaveOrUpdate(syn); } foreach (var user in m_pUserPoints.Values) { user.Value1 = 0; m_pRepo.SaveOrUpdate(user); } IScreenObject pScrObj; if (m_pMainMap.GameObjects.TryGetValue(920, out pScrObj) && pScrObj is DynamicNpc) { DynamicNpc pNpc = pScrObj as DynamicNpc; pNpc.Life = pNpc.MaxLife; pNpc.SendToRange(); } m_tRank.Startup(10); m_pState = SyndicateWarState.RUNNING; } else if (m_pState == SyndicateWarState.RUNNING && (now >= _STARTUP_TIME && now < _END_TIME)) { // running if (m_tRank.IsActive() && m_tRank.ToNextTime()) { List <string> pRank = new List <string>(9); pRank.Add("Syndicate Score War"); int count = 0; foreach (var rnk in m_pSynPoints.Values.OrderByDescending(x => x.Value1)) { if (rnk.Value1 > 0) { if (count++ < 8) { pRank.Add(string.Format("Nº{0}. {1,16} - {2}", count, rnk.ObjectName.PadRight(16), rnk.Value1)); } else { break; } } } foreach (var player in m_pMainMap.Players.Values.ToList()) { player.Send(pRank[0], ChatTone.EVENT_RANKING); for (int i = 1; i < pRank.Count; i++) { player.Send(pRank[i], ChatTone.EVENT_RANKING_NEXT); } } } } else if (m_pState == SyndicateWarState.RUNNING && (now < _STARTUP_TIME || now > _END_TIME)) { // prepare to finish ServerKernel.SendMessageToAll(string.Format("The time is up! The Guild Score War is over."), ChatTone.TOP_LEFT); m_pState = SyndicateWarState.ENDING; } else if (m_pState == SyndicateWarState.ENDING) { // end time int rank = 0; foreach (var syn in m_pSynPoints.Values.OrderByDescending(x => x.Value1)) { if (rank++ >= 4) { break; } uint synId = syn.ObjectIdentity; int deliverMoney = 0; int deliverEmoney = 0; uint totalMoney = ServerKernel.SYN_SCORE_MONEY_REWARD[rank - 1]; uint totalEmoney = ServerKernel.SYN_SCORE_EMONEY_REWARD[rank - 1]; foreach (var user in m_pUserPoints.Values.Where(x => x.ObjectIdentity == synId && x.PlayerIdentity > 0) .OrderByDescending(x => x.Value1)) { float nPercent = (user.Value1 / (float)syn.Value1); int money = (int)(totalMoney * nPercent); int emoney = (int)(totalEmoney * nPercent); deliverMoney += money; deliverEmoney += emoney; if (money <= 0 && emoney <= 0) { continue; } Client pClient; if (ServerKernel.Players.TryGetValue(user.PlayerIdentity, out pClient)) { pClient.Character.AwardMoney(money); pClient.Character.AwardEmoney(emoney); pClient.SendMessage(string.Format(ServerString.STR_SSPK_AWARDED_PRIZE, user.Value1, money, emoney), ChatTone.GUILD); } else { DbUser pUser = Database.Characters.SearchByIdentity(user.PlayerIdentity); if (pUser != null) { pUser.Money = (uint)Math.Min(int.MaxValue, pUser.Money + money); pUser.Emoney = (uint)Math.Min(int.MaxValue, pUser.Emoney + emoney); Database.Characters.SaveOrUpdate(pUser); } } } } ServerKernel.SendMessageToAll(string.Format("The Guild Score War is over."), ChatTone.TALK); m_pState = SyndicateWarState.NOT_RUNNING; } }
public void Finish(Character pWinner, Character pLoser, bool bDispose) { if (pWinner == m_pPlayer1) { Win1 = true; } else { Win2 = true; } pWinner.ArenaQualifier.Points = (uint)(pWinner.ArenaQualifier.Points * 1.03f); pLoser.ArenaQualifier.Points = (uint)(pLoser.ArenaQualifier.Points * .97f); pWinner.ArenaQualifier.TodayWins += 1; pWinner.ArenaQualifier.TotalWins += 1; pLoser.ArenaQualifier.TodayLoses += 1; pLoser.ArenaQualifier.TotalLoses += 1; int todayMatch0 = (int)(pWinner.ArenaQualifier.TodayWins + pWinner.ArenaQualifier.TodayLoses); int todayMatch1 = (int)(pLoser.ArenaQualifier.TodayWins + pLoser.ArenaQualifier.TodayLoses); if (pWinner.ArenaQualifier.TodayWins == 9) { pWinner.ArenaQualifier.TotalHonorPoints += 5000; pWinner.ArenaQualifier.HonorPoints += 5000; } if (todayMatch0 == 20) { pWinner.ArenaQualifier.TotalHonorPoints += 5000; pWinner.ArenaQualifier.HonorPoints += 5000; } if (todayMatch1 == 20) { pLoser.ArenaQualifier.TotalHonorPoints += 5000; pLoser.ArenaQualifier.HonorPoints += 5000; } MsgQualifyingInteractive pMsg = new MsgQualifyingInteractive { Type = ArenaType.DIALOG, Option = 3 // lose }; try { pLoser.Send(pMsg); } catch { } pMsg.Option = 1; // win try { pWinner.Send(pMsg); } catch { } pWinner.ArenaQualifier.Save(); pLoser.ArenaQualifier.Save(); if (pWinner.Syndicate != null && pLoser.Syndicate != null) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END3, pWinner.SyndicateName, pWinner.Name, pLoser.SyndicateName, pLoser.Name, pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER); } else if (pWinner.Syndicate != null && pLoser.Syndicate == null) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END1, pWinner.SyndicateName, pWinner.Name, pLoser.Name, pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER); } else if (pWinner.Syndicate == null && pLoser.Syndicate != null) { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END2, pWinner.Name, pLoser.SyndicateName, pLoser.Name, pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER); } else { ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END0, pWinner.Name, pLoser.Name, pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER); } if (bDispose) { m_pStatus = ArenaStatus.DISPOSED; ShowFinalDialog(pWinner, pLoser); } else { m_tStartup.Startup(3); m_pStatus = ArenaStatus.FINISHED; } }
/// <summary> /// On this method the user will award it's prize every question. /// </summary> public bool UserAnswer(Character pRole, ushort nQuestion, ushort nReply) { try { if (m_state <= QuizState.STOPPED || m_state >= QuizState.ENDED) { return(false); } QuizShowUserObject plrObj = null; if (!m_quizUserInformation.ContainsKey(pRole.Identity)) { plrObj = new QuizShowUserObject { Experience = 0, Name = pRole.Name, Points = 0, TimeTaken = 0, UserIdentity = pRole.Identity, LastQuestion = nQuestion }; m_quizUserInformation.Add(pRole.Identity, plrObj); } plrObj = m_quizUserInformation[pRole.Identity]; if (plrObj.LastQuestion == nQuestion) { return(false); // player already answered } int expBallAmount = 0; var pQuestion = m_temporaryQuestions[nQuestion - 1]; if (pQuestion.Correct == nReply) { expBallAmount = (ServerKernel.QUIZ_MAX_EXPERIENCE / ServerKernel.QUIZ_MAX_QUESTION); pRole.AwardExperience( (ServerKernel.GetExpBallExperience(pRole.Level) / 600) // gets the exp and divides by 600 * expBallAmount); // multiply by the correct answer tax plrObj.Points += (ushort)(m_pNextQuestion.GetRemain()); } else { expBallAmount = (ServerKernel.QUIZ_MAX_EXPERIENCE / (ServerKernel.QUIZ_MAX_QUESTION * 4)); pRole.AwardExperience( (ServerKernel.GetExpBallExperience(pRole.Level) / 600) // gets the exp and divides by 600 * expBallAmount); // multiply by the correct answer tax plrObj.Points += 1; } plrObj.TimeTaken += (ushort)((m_pNextQuestion.GetRemain() - ServerKernel.QUIZ_TIME_PER_QUESTION) * -1); plrObj.Experience += (ushort)expBallAmount; plrObj.LastQuestion = nQuestion - 1; var pMsg = new MsgQuiz { Type = QuizShowType.AFTER_REPLY, CurrentScore = plrObj.Points, TimeTaken = plrObj.TimeTaken, Rank = plrObj.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); pRole.Send(pMsg); return(true); } catch { // should not happen ServerKernel.Log.SaveLog("Could not add reward to user on Quiz Show", true, "quiz", LogType.ERROR); } return(false); }
public static void HandleInteract(Character pRole, MsgInteract pMsg) { if (pRole == null || pRole.BattleSystem == null) { return; } pRole.BattleSystem.DestroyAutoAttack(); pRole.BattleSystem.ResetBattle(); if (pRole.BattleSystem.QueryMagic() != null) { pRole.BattleSystem.QueryMagic().SetMagicState(0); pRole.BattleSystem.QueryMagic().BreakAutoAttack(); pRole.BattleSystem.QueryMagic().AbortMagic(true); } if (!pRole.IsAlive) { return; } var obj = pRole.BattleSystem.FindRole(pMsg.TargetIdentity); if (obj == null && pMsg.Action != InteractionType.ACT_ITR_MAGIC_ATTACK && pMsg.Action != InteractionType.ACT_ITR_COUNTER_KILL_SWITCH && pMsg.Action != InteractionType.ACT_ITR_PRESENT_EMONEY) { return; } switch (pMsg.Action) { #region 2/28 - Meele and Bow case InteractionType.ACT_ITR_SHOOT: case InteractionType.ACT_ITR_ATTACK: { pRole.BattleSystem.CreateBattle(pMsg.TargetIdentity); pRole.BattleSystem.SetAutoAttack(); pRole.SetAttackTarget(obj); break; } #endregion #region 8 - Court case InteractionType.ACT_ITR_COURT: { if (pRole.Identity == pMsg.TargetIdentity) { return; } Character pTarget; if (pRole.Map.Players.TryGetValue(pMsg.TargetIdentity, out pTarget)) { if (pTarget.Mate != ServerString.NOMATE_NAME) { pRole.Send(ServerString.TARGET_ALREADY_MARRIED); return; } if (pRole.Mate != ServerString.NOMATE_NAME) { pRole.Send(ServerString.YOURE_ALREADY_MARRIED); return; } if (pTarget.Gender == pRole.Gender) { pRole.Send(ServerString.NOT_ALLOWED_SAME_GENDER_MARRIAGE); return; } pTarget.SetMarryRequest(pRole.Identity); pTarget.Send(pMsg); } else { pRole.Send(ServerString.MARRIAGE_NOT_APPLY); return; } break; } #endregion #region 9 - Marry case InteractionType.ACT_ITR_MARRY: { if (pRole.Identity == pMsg.TargetIdentity) { return; } Character pTarget; if (pRole.Map.Players.TryGetValue(pMsg.TargetIdentity, out pTarget)) { if (pTarget.Mate != ServerString.NOMATE_NAME) { pRole.Send(ServerString.TARGET_ALREADY_MARRIED); return; } if (pRole.Mate != ServerString.NOMATE_NAME) { pRole.Send(ServerString.YOURE_ALREADY_MARRIED); return; } if (pTarget.Gender == pRole.Gender) { pRole.Send(ServerString.NOT_ALLOWED_SAME_GENDER_MARRIAGE); return; } if (!pRole.FetchMarryRequest(pTarget.Identity)) { pRole.Send(ServerString.MARRIAGE_NOT_APPLY); return; } pRole.Mate = pTarget.Name; pTarget.Mate = pRole.Name; MsgName msg = new MsgName { Identity = pRole.Identity, Action = StringAction.MATE }; msg.Append(pRole.Mate); pRole.Send(msg); msg = new MsgName { Identity = pTarget.Identity, Action = StringAction.MATE }; msg.Append(pTarget.Mate); pTarget.Send(msg); if (pRole.Family != null && pTarget.Family == null) { pRole.Family.AppendMember(pRole, pTarget); } else if (pRole.Family == null && pTarget.Family != null) { pTarget.Family.AppendMember(pTarget, pRole); } ServerKernel.SendMessageToAll(string.Format(ServerString.STR_MARRY, pRole.Name, pTarget.Name), ChatTone.CENTER); } else { pRole.Send(ServerString.MARRIAGE_NOT_APPLY); return; } break; } #endregion #region 24 - Magic Attack case InteractionType.ACT_ITR_MAGIC_ATTACK: { #region TemporaryDecryption ushort skillId = Convert.ToUInt16(((long)pMsg[24] & 0xFF) | (((long)pMsg[25] & 0xFF) << 8)); skillId ^= 0x915d; skillId ^= (ushort)pRole.Identity; skillId = (ushort)(skillId << 0x3 | skillId >> 0xd); skillId -= 0xeb42; uint Target = ((uint)pMsg[12] & 0xFF) | (((uint)pMsg[13] & 0xFF) << 8) | (((uint)pMsg[14] & 0xFF) << 16) | (((uint)pMsg[15] & 0xFF) << 24); Target = ((((Target & 0xffffe000) >> 13) | ((Target & 0x1fff) << 19)) ^ 0x5F2D2463 ^ pRole.Identity) - 0x746F4AE6; pMsg.TargetIdentity = Target; ushort TargetX = 0; ushort TargetY = 0; long xx = (pMsg[16] & 0xFF) | ((pMsg[17] & 0xFF) << 8); long yy = (pMsg[18] & 0xFF) | ((pMsg[19] & 0xFF) << 8); xx = xx ^ (pRole.Identity & 0xffff) ^ 0x2ed6; xx = ((xx << 1) | ((xx & 0x8000) >> 15)) & 0xffff; xx |= 0xffff0000; xx -= 0xffff22ee; yy = yy ^ (pRole.Identity & 0xffff) ^ 0xb99b; yy = ((yy << 5) | ((yy & 0xF800) >> 11)) & 0xffff; yy |= 0xffff0000; yy -= 0xffff8922; TargetX = Convert.ToUInt16(xx); TargetY = Convert.ToUInt16(yy); pMsg.MagicType = skillId; pMsg.CellX = TargetX; pMsg.CellY = TargetY; #endregion if (pRole.IsAlive) { pRole.ProcessMagicAttack(pMsg.MagicType, pMsg.TargetIdentity, pMsg.CellX, pMsg.CellY); } break; } #endregion #region 39 - Claim CPs case InteractionType.ACT_ITR_PRESENT_EMONEY: if (pRole.CoinMoney > 0) { pRole.AwardEmoney(pRole.CoinMoney, true); pMsg.Amount = pRole.CoinMoney; pRole.CoinMoney = 0; pRole.Send(pMsg); } break; #endregion #region 44 - Counter Kill Switch case InteractionType.ACT_ITR_COUNTER_KILL_SWITCH: { if (pRole.Profession / 10 != 5 || !pRole.IsPureClass()) { pRole.Send(ServerString.STR_SCAPEGOAT_ONLY_PURE_NINJA); return; } if (!pRole.IsAlive || pRole.IsWing()) { return; } if (pRole.Scapegoat) // disable { pMsg.TargetIdentity = pMsg.EntityIdentity = pRole.Identity; pMsg.Damage = 0; pMsg.CellX = pRole.MapX; pMsg.CellY = pRole.MapY; pRole.Send(pMsg); pRole.Scapegoat = false; } else { pMsg.TargetIdentity = pMsg.EntityIdentity = pRole.Identity; pMsg.Damage = 1; pMsg.CellX = pRole.MapX; pMsg.CellY = pRole.MapY; pRole.Send(pMsg); pRole.Scapegoat = true; } break; } #endregion #region 36 - QuestJar case InteractionType.ACT_ITR_INCREASE_JAR: { // TODO Only temporal for now. But allowed login/logout the player. QuestJar quest = ServerKernel.PlayerQuests.Where(x => x.Player.Identity == pRole.Identity).FirstOrDefault(); if (quest != null) { pMsg.Amount = quest.Kills; } pRole.Send(pMsg); break; } #endregion default: ServerKernel.Log.SaveLog("Missing Interaction Type: " + pMsg.Action, true, "itr_msg", LogType.WARNING); break; } }