public static bool ProcessCommand(string[] split, MapleClient c) { if (split.Length == 0) { return(false); } string command = split[0].ToLower(); Delegate action; Commands.TryGetValue(command, out action); if (action != null) { try { action.DynamicInvoke(split, c); } catch (Exception e) { ServerConsole.Debug("Error parsing GMCommand command: " + command + "\r\n" + e.ToString()); c.Account.Character.SendBlueMessage("An error occured while processing your command"); } return(true); } return(false); }
public bool ExecuteScriptForNpc() { if (ScriptInstance == null) { return(false); } try { if (IsShop) { Client.SendPacket(Packets.ShowShop((ShopScript)ScriptInstance, NpcId)); } ScriptInstance.Execute(); return(true); } catch (Exception ex) { string errorString = string.Format("NpcId: {0}\r\nState: {1}\r\n Selection: {2}\r\nException: {3}", NpcId, ScriptInstance.State, ScriptInstance.Selection, ex); ServerConsole.Debug("Npc script execution error: " + errorString); FileLogging.Log("Npc scripts", errorString); SendOk("An error occured, please report this on the forums\r\nNpcId: " + NpcId); Dispose(); return(false); } }
public NpcEngine(MapleClient c, int id) { Client = c; NpcId = id; Type npcT; if (DataBuffer.NpcScripts.TryGetValue(NpcId, out npcT) && npcT != null) { ScriptInstance = ScriptActivator.CreateScriptInstance(npcT, npcT.ToString(), c.Account.Character) as NpcScript; if (ScriptInstance == null) { string error = string.Format("Error loading {0} {1}", "NpcScript", npcT.ToString()); ServerConsole.Error(error); FileLogging.Log("Npc scripts", error); return; } if (ScriptInstance.IsShop) { IsShop = true; } else { ScriptInstance.SendOk = new Action <string>(SendOk); ScriptInstance.SendNext = new Action <string>(SendNext); ScriptInstance.SendPrev = new Action <string>(SendPrev); ScriptInstance.SendNextPrev = new Action <string>(SendNextPrev); ScriptInstance.SendSimple = new Action <string>(SendSimple); ScriptInstance.EndChat = new Action(Dispose); ScriptInstance.SendYesNo = new Action <string>(SendYesNo); ScriptInstance.SendAskText = new Action <string, int, int, string>(SendAskText); } } else { SendOk(string.Format(@"An error has occured in my script. Please report this as a bug\r\nNpcId: {0}", NpcId)); ServerConsole.Debug(string.Format(@"Missing script for NPC: {0}", NpcId)); ScriptInstance = null; c.Account.Character.EnableActions(); } }
public static void EnterScriptedPortal(WzMap.Portal portal, MapleCharacter character) { if (!string.IsNullOrEmpty(portal.Script)) { Type portalScriptType; if (DataBuffer.PortalScripts.TryGetValue(portal.Script, out portalScriptType) && portalScriptType != null) { PortalScript scriptInstance = Activator.CreateInstance(portalScriptType) as PortalScript; if (scriptInstance == null) { string error = string.Format("Error loading {0} {1}", "PortalScript", portal.Script); ServerConsole.Error(error); FileLogging.Log("Portal scripts", error); return; } scriptInstance.Character = new ScriptCharacter(character, portal.Script); try { scriptInstance.Execute(); } catch (Exception e) { string error = string.Format("Script: {0} error: {1}", portal.Script, e); FileLogging.Log("Portal scripts", error); ServerConsole.Debug("Portal script execution error: " + error); character.EnableActions(); } } else { character.SendBlueMessage(string.Format("This portal is not coded yet (mapId: {0}, portalId: {1}, script name: {2})", character.MapId, portal.Id, portal.Script)); character.EnableActions(); } } else { character.EnableActions(); } }
public static void Handle(MapleClient c, PacketReader pr) { string accountPassword = pr.ReadMapleString(); string accountName = pr.ReadMapleString(); if (accountName.StartsWith("NP12:auth")) { c.SendPacket(MapleCharacter.ServerNotice("Please start MapleStory using the leatty launcher.", 1)); return; } ServerConsole.Debug("Login account: " + accountName); MapleAccount account = MapleAccount.GetAccountFromDatabase(accountName); if (account != null) { if (Program.IsAccountOnline(account.Id)) { c.SendPacket(LoginAccountFailed(7)); } else { if (account.CheckPassword(accountPassword)) { c.Account = account; c.SendPacket(LoginAccountSuccess(account)); } else { c.SendPacket(LoginAccountFailed(4)); } } } else { c.SendPacket(LoginAccountFailed(5)); } }
public static void Handle(PacketReader packet, MapleClient c) { if (packet.Length >= 2) { if (ServerConstants.PrintPackets) { ServerConsole.Info("Receiving: {0}", Functions.ByteArrayToStr(packet.ToArray())); } RecvHeader header = (RecvHeader)packet.ReadHeader(); if (header <= RecvHeader.ErrorCode) { switch (header) { #region Miscellaneous case RecvHeader.ErrorCode: ErrorCodeHandler.Handle(c, packet); break; case RecvHeader.BlackCipher: BlackCipherHandler.Handle(packet.ReadInt(), c); break; case RecvHeader.HandShake: ReceiveHandShakeHandler.Handle(c, packet); break; case RecvHeader.CrashReport: break; case RecvHeader.Pong: PongHandler.Handle(c); break; #endregion #region Login Server case RecvHeader.EnteredLoginScreen: EnteredLoginScreenHandler.Handle(c); break; case RecvHeader.ClientLoaded: ClientLoadedHandler.Handle(c); break; case RecvHeader.ShowServerList: case RecvHeader.ReShowServerList: ServerlistRequestHandler.Handle(c); break; case RecvHeader.WorldSelect: WorldSelectHandler.Handle(packet.ReadShort(), c); break; case RecvHeader.CheckCharacterName: CheckCharnameHandler.Handle(c, packet.ReadMapleString()); break; case RecvHeader.CreateCharacter: CreateCharHandler.Handle(c, packet); break; case RecvHeader.DeleteCharacter: DeleteCharacterHandler.Handle(c, packet); break; case RecvHeader.SetAccountPic: SetAccountPicHandler.Handle(c, packet); break; case RecvHeader.ChooseCharacterWithPic: ChooseCharWithPicHandler.Handle(c, packet); break; case RecvHeader.EnterMap: CharacterLoginHandler.Handle(c, packet); break; case RecvHeader.AccountLogin: LoginAccountHandler.Handle(c, packet); break; case RecvHeader.ChooseChannel: ChooseChannelHandler.Handle(c, packet); break; #endregion default: #if DEBUG ServerConsole.Debug("Unhandled recv packet: {0}", Functions.ByteArrayToStr(packet.ToArray())); #endif break; } } else { if (c.Account?.Character?.Map == null) { return; } switch (header) { #region GameServer // Spam packets: case RecvHeader.ClickDialog: case RecvHeader.AttackSpam: case RecvHeader.FinalPactEnd: break; case RecvHeader.PartyResponse: PartyResponseHandler.Handle(c, packet); break; case RecvHeader.PartyOperation: PartyHandler.Handle(c, packet); break; case RecvHeader.RequestRecommendedPartyMembers: RecommendedPartyMembersHandler.Handle(c, packet); break; case RecvHeader.CharacterReceiveDamage: CharacterReceiveDamage.Handle(c, packet); break; case RecvHeader.PlayerChat: PlayerChatHandler.Handle(c, packet); break; case RecvHeader.SpecialChat: SpecialChatHandler.Handle(c, packet); break; case RecvHeader.RequestWeeklyMapleStar: WeeklyMapleStarHandler.Handle(c, packet); return; case RecvHeader.MoveCharacter: MoveCharacterHandler.Handle(c, packet); break; case RecvHeader.EnterMapPortal: EnterMapPortalHandler.Handle(c, packet); break; case RecvHeader.EnterDoor: EnterDoorHandler.Handle(c, packet); break; case RecvHeader.MoveMob: MoveMobHandler.Handle(c, packet); break; case RecvHeader.NpcChat: NpcChatHandler.Handle(c, packet); break; case RecvHeader.NpcShopAction: NpcShopActionHandler.Handle(c, packet); break; case RecvHeader.NpcAnimation: NpcAnimationHandler.Handle(c, packet); break; case RecvHeader.NpcChatMore: NpcChatMoreHandler.Handle(c, packet); break; case RecvHeader.FacialExpression: FacialExpressionHandler.Handle(c, packet); break; case RecvHeader.MeleeAttack: DealDamageHandler.HandleMelee(c, packet, header); break; case RecvHeader.RangedAttack: DealDamageHandler.HandleRanged(c, packet); break; case RecvHeader.PassiveAttack: case RecvHeader.MagicAttack: DealDamageHandler.HandleMagic(c, packet); break; case RecvHeader.DistributeAp: DistributeAPHandler.HandleSingle(c, packet); break; case RecvHeader.AutoAssignAp: DistributeAPHandler.HandleDistribute(c, packet); break; case RecvHeader.DistributeSp: DistributeSPHandler.Handle(c, packet); break; case RecvHeader.UseSkill: UseSkillHandler.Handle(c, packet); break; case RecvHeader.MoveItem: MoveItemHandler.Handle(c, packet); break; case RecvHeader.SlotMerge: InventorySortHandler.HandleSlotMerge(c, packet); break; case RecvHeader.ItemSort: InventorySortHandler.HandleItemSort(c, packet); break; case RecvHeader.ChangeChannel: ChangeChannelHandler.Handle(c, packet); break; case RecvHeader.EnterCashShop: EnterCSHandler.Handle(c, packet); break; case RecvHeader.AutoAggroMob: AutoAggroHandler.Handle(c, packet); break; case RecvHeader.LootMapItem: LootItemHandler.HandlePlayer(c, packet); break; case RecvHeader.RegenerateHpMp: RegenerateHPMPHandler.Handle(c, packet); break; case RecvHeader.ChangeKeybind: KeybindHandler.HandleKeyMapChange(c, packet); break; case RecvHeader.QuickSlotKeyMap: KeybindHandler.HandleQuickSlotKeysChange(c, packet); break; case RecvHeader.CancelBuff: CancelBuffHandler.Handle(c, packet); break; case RecvHeader.CharacterInfoRequest: CharacterInfoRequest.Handle(c, packet); break; case RecvHeader.QuestAction: QuestActionHandler.Handle(c, packet); break; case RecvHeader.EnterMapPortalSpecial: EnterMapPortalSpecialHandler.Handle(c, packet); break; case RecvHeader.GuildAction: GuildActionHandler.Handle(c, packet); break; case RecvHeader.DropMeso: DropMesoHandler.Handle(c, packet); break; case RecvHeader.Trade: TradeHandler.Handle(c, packet); break; case RecvHeader.UseConsumable: UseItemHandler.Handle(c, packet); break; case RecvHeader.UseReturnScroll: UseItemHandler.HandleReturnScroll(c, packet); break; case RecvHeader.UseEquipScroll: UseScrollHandler.HandleRegularEquipScroll(c, packet); break; case RecvHeader.UseSpecialEquipScroll: UseScrollHandler.HandleSpecialEquipScroll(c, packet); break; case RecvHeader.UseEquipEnhancementScroll: UseScrollHandler.HandleEquipEnhancementScroll(c, packet); break; case RecvHeader.UseCashItem: UseSpecialItemHandler.Handle(c, packet); break; case RecvHeader.UsePotentialScroll: UseScrollHandler.HandlePotentialScroll(c, packet); break; case RecvHeader.UseBonusPotentialScroll: UseScrollHandler.HandleBonusPotentialScroll(c, packet); break; case RecvHeader.UseCube: UseScrollHandler.HandleCube(c, packet); break; case RecvHeader.UseMagnifyGlass: UseMagnifyingGlassHandler.Handle(c, packet); break; case RecvHeader.SetSkillMacro: SetSkillMacroHandler.Handle(c, packet); break; case RecvHeader.ProffesionReactorAction: ProfessionReactorActionHandler.Handle(c, packet); break; case RecvHeader.ProffesionReactorDestroy: ProfessionReactorActionHandler.HandleDestroy(c, packet); break; case RecvHeader.ReactorAction: ReactorActionHandler.Handle(c, packet); break; case RecvHeader.CraftDone: CraftHandler.HandleCraftDone(c, packet); break; case RecvHeader.CraftEffect: CraftHandler.HandleCraftEffect(c, packet); break; case RecvHeader.CraftMake: CraftHandler.HandleCraftMake(c, packet); break; case RecvHeader.CraftUnk: CraftHandler.HandleUnk(c, packet); break; case RecvHeader.GainAranCombo: AranComboHandler.HandleGain(c); break; case RecvHeader.DecayAranCombo: AranComboHandler.HandleDecay(c); break; case RecvHeader.BlackBlessing: BlackBlessingHandler.Handle(c); break; case RecvHeader.RequestHyperskillInfo: HyperskillInfoRequestHandler.Handle(c, packet); return; case RecvHeader.SkillSwipe: StealSkillHandler.HandleSkillSwipe(c, packet); break; case RecvHeader.ChooseStolenSkill: StealSkillHandler.HandleChooseSkill(c, packet); break; case RecvHeader.StealSkill: StealSkillHandler.HandleStealSkill(c, packet); break; case RecvHeader.MessengerOperation: MapleMessengerHandler.Handle(c, packet); break; case RecvHeader.MoveSummon: SummonHandler.HandleMove(c, packet); break; case RecvHeader.SummonAttack: SummonHandler.HandleAttack(c, packet); break; case RecvHeader.SummonUseSkill: SummonHandler.HandleSkill(c, packet); break; case RecvHeader.RemoveSummon: SummonHandler.HandleRemove(c, packet); break; case RecvHeader.FindPlayer: FindPlayerHandler.Handle(c, packet); break; case RecvHeader.BuddyOperation: BuddyOperationHandler.Handle(c, packet); break; case RecvHeader.UseGoldenHammer: UseGoldenHammerHandler.Handle(c, packet); break; #endregion #region CashShop case RecvHeader.CashshopSelect: CashShop.Select(c, packet); break; #endregion default: #if DEBUG ServerConsole.Debug("Unhandled recv packet: {0}", Functions.ByteArrayToStr(packet.ToArray())); #endif c.Account.Character.EnableActions(); break; } } } }
public static void HandleAttack(MapleClient c, PacketReader pr) { int objectId = pr.ReadInt(); MapleCharacter chr = c.Account.Character; MapleSummon summon = chr.Map.GetSummon(objectId); if (summon != null) { if (summon.Owner.Id != chr.Id) { return; } int tickCount = pr.ReadInt(); WzCharacterSkill skillInfo = DataBuffer.GetCharacterSkillById(summon.SourceSkillId); if (skillInfo == null || skillInfo.SummonInfo == null) { return; } WzCharacterSkill.SummonAttackInfo summonAttackInfo = skillInfo.SummonInfo; byte animation = pr.ReadByte(); byte attackByte = pr.ReadByte(); int attacks = (attackByte & 0x0F); int targets = ((attackByte >> 4) & 0x0F); if (summonAttackInfo.MobCount < targets || summonAttackInfo.AttackCount < attacks) { ServerConsole.Warning("Player " + chr.Name + "'s summon: " + summon.SourceSkillId + "has mismatching targets- or attackcount: " + attacks + "/" + summonAttackInfo.AttackCount + " attacks, " + targets + "/" + summonAttackInfo.MobCount + " mobs"); return; } pr.Skip(12); List <AttackPair> attackList = new List <AttackPair>(); for (int i = 0; i < targets; i++) { int targetObjectId = pr.ReadInt(); MapleMonster target = chr.Map.GetMob(targetObjectId); if (target == null) { ServerConsole.Debug("Error parsing summon attack, summon skillId: " + summon.SourceSkillId + " attack byte: " + attackByte); return; } AttackPair ap = new AttackPair(); ap.TargetObjectId = targetObjectId; pr.Skip(24); int damage = pr.ReadInt(); //only supports 1 damage count, not sure if there are summons with attackcount > 1 ap.Damage.Add(damage); attackList.Add(ap); pr.Skip(4); } AttackInfo attackInfo = new AttackInfo(); attackInfo.Attacks = attacks; attackInfo.AttacksByte = attackByte; attackInfo.Speed = animation; attackInfo.Targets = targets; attackInfo.TargetDamageList = attackList; foreach (AttackPair ap in attackList) { MapleMonster mob = chr.Map.GetMob(ap.TargetObjectId); if (mob != null) { long totalDamage = 0; foreach (int i in ap.Damage) { totalDamage += i; } if (totalDamage > int.MaxValue) { totalDamage = int.MaxValue; } mob.Damage(chr, (int)totalDamage); } } bool darkFlare = summon.SourceSkillId == ChiefBandit.DARK_FLARE || summon.SourceSkillId == Hermit.DARK_FLARE || summon.SourceSkillId == NightWalker3.DARK_FLARE; chr.Map.BroadcastPacket(summon.GetAttackPacket(attackInfo, darkFlare)); } }
public static void UseEquipEnhancementScroll(MapleEquip equip, MapleItem scroll, MapleCharacter chr) { if (equip == null || scroll == null) { return; } WzItemEnhancer wzScrollInfo = DataBuffer.GetItemById(scroll.ItemId) as WzItemEnhancer; WzEquip equipInfo = DataBuffer.GetEquipById(equip.ItemId); if (wzScrollInfo == null || equipInfo == null) { return; } int maxEnhancements; if (wzScrollInfo == null || equipInfo == null || (maxEnhancements = equipInfo.MaxStarEnhance) - equip.Enhancements < 1 || equip.RemainingUpgradeCount > 0) { chr.SendPopUpMessage("You cannot use that on this item."); chr.EnableActions(); return; } int chance; bool diminishChance = false; int enhancements; int curseChance = 100; switch (scroll.ItemId) { case 2049323: //advanced equip enhancement scroll curseChance = 0; goto case 2049300; case 2049300: case 2049303: case 2049306: case 2049325: { chance = 100; diminishChance = true; enhancements = 1; break; } case 2049301: //equip enhancement scroll case 2049307: { chance = 80; diminishChance = true; enhancements = 1; break; } default: { if (wzScrollInfo.StatEnhancements.TryGetValue("forceUpgrade", out enhancements) && //multiple star enhances wzScrollInfo.StatEnhancements.TryGetValue("success", out chance)) { if (!wzScrollInfo.StatEnhancements.TryGetValue("cursed", out curseChance)) { curseChance = 100; } break; } chr.SendPopUpMessage("This item is not coded, please report it on the forums. ItemId " + scroll.ItemId); ServerConsole.Debug("ItemID {0} is unhandled in UseEnhancementScroll", scroll.ItemId); return; } } bool scrollProtection = equip.CheckAndRemoveFlag(MapleItemFlags.ScrollProtection); bool curseProtection = equip.CheckAndRemoveFlag(MapleItemFlags.CurseProtection) && equip.Enhancements < 12; bool success = EnhanceEquip(equip, chance, diminishChance, enhancements, maxEnhancements); bool destroyed = false; byte scrollResult = 1; bool removeScroll = success || !scrollProtection; if (!success) { scrollResult = 0; if (!curseProtection && Functions.MakeChance(curseChance)) { scrollResult = 2; destroyed = true; } } if (removeScroll) { chr.Inventory.RemoveItemsFromSlot(scroll.InventoryType, scroll.Position, 1); } if (destroyed) { chr.Inventory.RemoveItem(equip.InventoryType, equip.Position); } else { chr.Client.SendPacket(MapleInventory.Packets.AddItem(equip, equip.InventoryType, equip.Position)); //Update item } chr.Map.BroadcastPacket(Packets.ShowScrollEffect(chr.Id, scrollResult, scroll.ItemId, equip.ItemId), chr, true); }
public static JobType GetJobTypeById(short id) { switch (id) { case 0: return(JobType.Explorer); case 1: return(JobType.DualBlade); case 508: return(JobType.Jett); case 1000: return(JobType.Cygnus); case 2000: return(JobType.Aran); case 2001: return(JobType.Evan); case 2002: return(JobType.Mercedes); case 2003: return(JobType.Phantom); case 2004: return(JobType.Luminous); case 2005: return(JobType.Shade); case 3000: return(JobType.Resistance); case 3001: return(JobType.Demon); case 3002: return(JobType.Xenon); case 4001: return(JobType.Hayato); case 4002: return(JobType.Kanna); case 5000: return(JobType.Mihile); case 6000: return(JobType.Kaiser); case 6001: return(JobType.AngelicBuster); case 10112: return(JobType.Zero); case 11000: return(JobType.BeastTamer); default: ServerConsole.Debug("Unhandled job id found in makecharinfo: " + id); return(0); } }
public static void Handle(MapleClient c, PacketReader pr) { MapleCharacter chr = c.Account.Character; if (!chr.DisableActions()) { return; } int tickCount = pr.ReadInt(); short magnifySlot = pr.ReadShort(); short equipSlot = pr.ReadShort(); MapleItem magnifyer = null; MapleEquip equip = c.Account.Character.Inventory.GetItemSlotFromInventory(MapleInventoryType.Equip, equipSlot) as MapleEquip; if (magnifySlot != 0x7F) // Using magnify button in inventory sends 0x007F as the slot { magnifyer = chr.Inventory.GetItemSlotFromInventory(MapleInventoryType.Use, magnifySlot); if (magnifyer == null) { return; //todo: check if it's a magnifying glass } } if (equip == null) { return; } WzEquip equipInfo = DataBuffer.GetEquipById(equip.ItemId); if (equipInfo == null) { return; } if (equip.PotentialState >= MaplePotentialState.HiddenRare && equip.PotentialState <= MaplePotentialState.HiddenLegendary) { long price = equipInfo.RevealPotentialCost; ServerConsole.Debug("pot cost: " + price); if (chr.Mesos < price) { chr.SendPopUpMessage(string.Format("You do not have {0} mesos", price)); chr.EnableActions(); } else { chr.Inventory.RemoveMesos(price); equip.PotentialState += 16; if (magnifyer != null) { chr.Inventory.RemoveItemsFromSlot(magnifyer.InventoryType, magnifyer.Position, 1); } c.SendPacket(MapleInventory.Packets.AddItem(equip, equip.InventoryType, equip.Position)); chr.Map.BroadcastPacket(MagnifyEffectPacket(chr.Id, equip.Position, true), chr, true); chr.EnableActions(false); } } else { chr.SendPopUpMessage("You cannot use that on this item"); chr.EnableActions(); } }