public static void UseObject(object obj, bool skipQueue = false) { int serial = AliasCommands.ResolveSerial(obj); if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return; } if (!Options.CurrentOptions.UseObjectQueue || skipQueue) { Engine.SendPacketToServer(new UseObject(serial)); } else if (Engine.UseObjectQueue.Count < Options.CurrentOptions.UseObjectQueueAmount) { Engine.UseObjectQueue.Enqueue(serial); } }
public static bool Property(object obj, string value) { int serial = AliasCommands.ResolveSerial(obj); if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); } Entity entity = (Entity)Engine.Items.GetItem(serial) ?? Engine.Mobiles.GetMobile(serial); if (entity?.Properties != null) { return(entity.Properties.Any(pe => pe.Text.ToLower().Contains(value.ToLower()))); } UOC.SystemMessage(Strings.Item_properties_null_or_not_loaded___); return(false); }
private static bool CheckNotoriety(object obj, Notoriety notoriety) { int serial = AliasCommands.ResolveSerial(obj); if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); } Mobile m = Engine.Mobiles.GetMobile(serial); if (m == null) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); } return(m.Notoriety == notoriety); }
public static bool Hidden(object obj = null) { int serial = AliasCommands.ResolveSerial(obj); if (serial <= 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); } Mobile mobile = Engine.Mobiles.GetMobile(serial); if (mobile != null) { return(mobile.Status.HasFlag(MobileStatus.Hidden)); } UOC.SystemMessage(Strings.Mobile_not_found___); return(false); }
public static void SetOrganizerContainers(string entryName, object sourceContainer = null, object destinationContainer = null) { int sourceSerial = AliasCommands.ResolveSerial(sourceContainer, false); int destinationSerial = AliasCommands.ResolveSerial(destinationContainer, false); OrganizerManager manager = OrganizerManager.GetInstance(); OrganizerEntry entry = manager.Items.FirstOrDefault(e => e.Name.ToLower().Equals(entryName.ToLower())); if (entry == null) { UOC.SystemMessage(Strings.Invalid_organizer_agent_name___, true); return; } entry.SourceContainer = sourceSerial; entry.DestinationContainer = destinationSerial; UOC.SystemMessage(Strings.Organizer_containers_set___, true); }
public static void RemoveFriend(object obj = null) { int serial = obj != null ? AliasCommands.ResolveSerial(obj) : UOC.GetTargeSerialAsync(Strings.Target_friend_to_remove___).Result; if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return; } FriendEntry entry = Options.CurrentOptions.Friends.FirstOrDefault(i => i.Serial == serial); if (entry == null) { return; } Engine.Dispatcher?.Invoke(() => Options.CurrentOptions.Friends.Remove(entry)); }
public static bool Flying(object obj) { int serial = AliasCommands.ResolveSerial(obj); if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); } Mobile mobile = Engine.Mobiles.GetMobile(serial); if (mobile == null) { // TODO better message UOC.SystemMessage(Strings.Cannot_find_item___); return(false); } return(mobile.Status.HasFlag(MobileStatus.Flying)); }
public static bool CheckCommand(byte[] data, int length) { string text = null; if (data[0] == 0xAD) { text = ParseUnicodeSpeech(data, data.Length); } else if (data[0] == 0x03) { text = ParseAsciiSpeech(data, data.Length); } if (text != null && text.Length >= 7 && text.Substring(0, 7).Equals(">macro ")) { string macroName = text.Substring(7, text.Length - 7); MacroEntry macro = MacroManager.GetInstance().Items.FirstOrDefault(m => m.Name == macroName); if (macro == null) { UOC.SystemMessage(Strings.Macro_not_found___, 35); } else { macro.Execute(); } return(true); } if (string.IsNullOrEmpty(text) || text[0] != Options.CurrentOptions.CommandPrefix) { return(false); } string[] args = text.Remove(0, 1).Split(' '); return(_commands.ContainsKey(args[0]) && _commands[args[0]].Invoke(args.Skip(1).ToArray())); }
public static bool FindType(int graphic, int range = -1, object findLocation = null, int hue = -1) { int owner = 0; if (findLocation != null) { owner = AliasCommands.ResolveSerial(findLocation); } Entity entity; bool Predicate(Entity i) { return(i.ID == graphic && (hue == -1 || i.Hue == hue) && (range == -1 || i.Distance < range) && !_ignoreList.Contains(i.Serial)); } if (owner != 0) { entity = Engine.Items.SelectEntities(i => Predicate(i) && i.IsDescendantOf(owner)) ?.FirstOrDefault(); } else { entity = (Entity)Engine.Mobiles.SelectEntities(Predicate)?.FirstOrDefault() ?? Engine.Items.SelectEntities(i => Predicate(i) && i.Owner == 0)?.FirstOrDefault(); } if (entity == null) { return(false); } AliasCommands.SetAlias("found", entity.Serial); UOC.SystemMessage(string.Format(Strings.Object___0___updated___, "found")); return(true); }
public static bool FindWand(string wandName, object containerSource = null, int minimumCharges = -1) { try { WandTypes wandType = Utility.GetEnumValueByName <WandTypes>(wandName); int containerSerial = AliasCommands.ResolveSerial(containerSource); if (containerSource == null) { containerSerial = -1; } Item[] matches = FindWands(wandType, containerSerial, minimumCharges).Result; if (matches == null) { UOC.SystemMessage(Strings.Cannot_find_item___); return(false); } AliasCommands.SetMacroAlias("found", matches.First().Serial); if (MacroManager.QuietMode) { return(true); } UOC.SystemMessage(string.Format(Strings.Object___0___updated___, "found")); return(true); } catch (InvalidOperationException) { UOC.SystemMessage(string.Format(Strings.Invalid_skill_name___0__, wandName)); } return(false); }
public static int AddFriend(object obj = null) { int serial = obj != null ? AliasCommands.ResolveSerial(obj) : UOC.GetTargetSerialAsync(Strings.Target_new_friend___).Result; if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(0); } Mobile m = Engine.Mobiles.GetMobile(serial); if (m == null) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(0); } FriendEntry fe = new FriendEntry { Name = m.Name?.Trim(), Serial = m.Serial }; if (!Options.CurrentOptions.Friends.Contains(fe)) { Engine.Dispatcher?.Invoke(() => { Options.CurrentOptions.Friends.Add(fe); if (Options.CurrentOptions.RehueFriends) { MainCommands.Resync(); } }); } return(m.Serial); }
public static bool MoveTypeOffset(int id, object findLocation, int xOffset, int yOffset, int zOffset, int amount = -1) { if (findLocation == null || ((string)findLocation).Equals("ground", StringComparison.InvariantCultureIgnoreCase)) { UOC.SystemMessage(Strings.Invalid_container___); return(false); } int owner = AliasCommands.ResolveSerial(findLocation); bool Predicate(Item i) { return(i.ID == id && i.IsDescendantOf(owner)); } Item entity = Engine.Items.SelectEntities(Predicate)?.FirstOrDefault(); if (entity == null) { return(false); } PlayerMobile player = Engine.Player; if (player == null) { return(false); } int x = player.X + xOffset; int y = player.Y + yOffset; int z = player.Z + zOffset; ActionPacketQueue.EnqueueDragDropGround(entity.Serial, amount, x, y, z); return(true); }
public static void PlayMacro(string name) { MacroManager manager = MacroManager.GetInstance(); MacroEntry current = manager.GetCurrentMacro(); if (current != null && current.IsBackground) { UOC.SystemMessage(Strings.Cannot_PlayMacro_from_background_macro___); return; } MacroEntry macro = manager.Items.FirstOrDefault(m => m.Name == name); if (macro == null) { UOC.SystemMessage(Strings.Unknown_macro___); return; } Task.Run(() => macro.Action(macro)); }
public static void UseType(object type, int hue = -1, object container = null) { int serial = AliasCommands.ResolveSerial(type); if (serial <= 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return; } if (container == null) { container = Engine.Player?.Backpack?.Serial; } int containerSerial = AliasCommands.ResolveSerial(container); if (!Engine.Items.GetItem(containerSerial, out Item containerItem)) { UOC.SystemMessage(Strings.Cannot_find_container___); return; } Item useItem = hue == -1 ? containerItem.Container.SelectEntity(i => i.ID == serial) : containerItem.Container.SelectEntity(i => i.ID == serial && i.Hue == hue); if (useItem == null) { UOC.SystemMessage(Strings.Cannot_find_item___); return; } Engine.SendPacketToServer(new UseObject(useItem.Serial)); }
public static int CountType(int graphic, object source = null, int hue = -1) { if (source == null) { source = "backpack"; } int sourceSerial = AliasCommands.ResolveSerial(source); Item countainerItem = Engine.Items.GetItem(sourceSerial); if (countainerItem?.Container == null) { UOC.SystemMessage(Strings.Invalid_container___); return(0); } Item[] matches = countainerItem.Container.SelectEntities(i => i.ID == graphic && (hue == -1 || i.Hue == hue)); return(matches?.Sum(i => i.Count) ?? 0); }
public static void MoveType(int id, int sourceSerial, int destinationSerial, int x = -1, int y = -1, int z = 0, int hue = -1, int amount = -1) { Item sourceItem = Engine.Items.GetItem(sourceSerial); if (sourceItem == null) { UOC.SystemMessage(Strings.Cannot_find_item___); return; } if (sourceItem.Container == null) { UOC.SystemMessage(Strings.Invalid_container___); return; } Item entity = sourceItem.Container.SelectEntities(i => i.ID == id && (hue == -1 || i.Hue == hue)) .FirstOrDefault(); if (entity == null) { return; } if (amount == -1) { amount = entity.Count; } if (amount > entity.Count) { amount = entity.Count; } UOC.DragDropAsync(entity.Serial, amount, destinationSerial, x, y, z).Wait(); }
public static bool InFriendList(object obj) { int serial = AliasCommands.ResolveSerial(obj); if (serial != 0) { bool result = Options.CurrentOptions.Friends.Any(fe => fe.Serial == serial); if (result) { return(true); } if (Options.CurrentOptions.IncludePartyMembersInFriends) { result = Engine.Player?.Party?.Contains(serial) ?? false; } return(result); } UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); }
public static void Organizer(string name, object sourceContainer = null, object destinationContainer = null) { OrganizerManager manager = OrganizerManager.GetInstance(); OrganizerEntry entry = manager.Items.FirstOrDefault(oa => oa.Name.ToLower().Equals(name.ToLower())); if (entry == null) { UOC.SystemMessage(string.Format(Strings.Organizer___0___not_found___, name)); return; } if (sourceContainer != null && destinationContainer != null) { int sourceContainerSerial = AliasCommands.ResolveSerial(sourceContainer); int destinatinContainerSerial = AliasCommands.ResolveSerial(destinationContainer); manager.Organize(entry, sourceContainerSerial, destinatinContainerSerial).Wait(); } else { manager.Organize(entry).Wait(); } }
public static bool InRegion(string attribute, object obj) { int serial = AliasCommands.ResolveSerial(obj); if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); } Entity entity = (Entity)Engine.Items.GetItem(serial) ?? Engine.Mobiles.GetMobile(serial); if (entity == null) { UOC.SystemMessage(Strings.Cannot_find_item___); return(false); } RegionAttributes attr = Utility.GetEnumValueByName <RegionAttributes>(attribute); Region region = entity.GetRegion(); return(region != null && region.Attributes.HasFlag(attr)); }
public double BuffTime(string name) { name = name.ToLower(); BuffIconData data = _buffIconData.FirstOrDefault(bd => bd.Name.ToLower().Equals(name)); if (data == null) { UOC.SystemMessage(Strings.Unknown_buff_name___); return(0); } if (!BuffExists(name)) { return(0); } if (_expireTimes[data.ID] < DateTime.Now) { return(0); } return((_expireTimes[data.ID] - DateTime.Now).TotalMilliseconds); }
public static void MoveItemOffset(object obj, int xOffset, int yOffset, int zOffset, int amount = -1) { int serial = AliasCommands.ResolveSerial(obj); if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return; } PlayerMobile player = Engine.Player; if (player == null) { return; } int x = player.X + xOffset; int y = player.Y + yOffset; int z = player.Z + zOffset; ActionPacketQueue.EnqueueDragDropGround(serial, amount, x, y, z); }
public static void MoveType(int id, object sourceContainer, object destinationContainer, int x = -1, int y = -1, int z = 0, int hue = -1, int amount = -1) { int sourceSerial = AliasCommands.ResolveSerial(sourceContainer); if (sourceSerial == -1) { UOC.SystemMessage(Strings.Invalid_source_container___); return; } int destinationSerial; if (destinationContainer is int destSerial) { destinationSerial = destSerial; } else { destinationSerial = AliasCommands.ResolveSerial(destinationContainer); } Item sourceItem = Engine.Items.GetItem(sourceSerial); if (sourceItem == null) { UOC.SystemMessage(Strings.Cannot_find_item___); return; } if (sourceItem.Container == null) { UOC.SystemMessage(Strings.Invalid_container___); return; } Item entity = sourceItem.Container.SelectEntities(i => i.ID == id && (hue == -1 || i.Hue == hue)) .FirstOrDefault(); if (entity == null) { return; } if (amount == -1) { amount = entity.Count; } if (amount > entity.Count) { amount = entity.Count; } if (destinationSerial == -1) { ActionPacketQueue.EnqueueDragDropGround(entity.Serial, amount, x, y, z); } else { ActionPacketQueue.EnqueueDragDrop(entity.Serial, amount, destinationSerial); } }
public static void SetAbility(string ability, string onOff = "toggle") { AbilitiesManager manager = AbilitiesManager.GetInstance(); if (ability.ToLower().Equals("stun")) { Engine.SendPacketToServer(new StunRequest()); return; } if (ability.ToLower().Equals("disarm")) { Engine.SendPacketToServer(new DisarmRequest()); return; } bool primary; switch (ability.ToLower()) { case "primary": primary = true; break; default: primary = false; break; } string onOffNormalized = onOff.Trim().ToLower(); if (onOffNormalized != "toggle") { switch (onOffNormalized) { case "on": { if (primary && manager.IsPrimaryEnabled || !primary && manager.IsSecondaryEnabled) { if (!MacroManager.QuietMode) { UOC.SystemMessage(Strings.Ability_already_set___, 0x3F); } return; } break; } case "off": { if (primary && !manager.IsPrimaryEnabled || !primary && !manager.IsSecondaryEnabled) { if (!MacroManager.QuietMode) { UOC.SystemMessage(Strings.Ability_not_set___, 0x3F); } return; } break; } } } UOC.SystemMessage(string.Format(Strings.Setting_ability___0_____, ability), 0x3F); manager.SetAbility(primary ? AbilityType.Primary : AbilityType.Secondary); }
public bool CheckHands(int serial) { if (!Options.CurrentOptions.CheckHandsPotions) { return(false); } Item item = Engine.Items?.GetItem(serial); if (item == null || !_potionTypes.Contains(item.ID)) { return(false); } // Explosion / Conflagaration pot doesn't need hand free if (item.ID == 0xf0d && item.Hue == 0 || item.ID == 0xf06 && item.Hue == 1161) { return(false); } if (_checkHandsInProgress) { UOC.SystemMessage(Strings.Arm___Disarm_already_in_progress___, (int)UOC.SystemMessageHues.Red); return(false); } _checkHandsInProgress = true; Item leftHand = Engine.Player?.Equipment.FirstOrDefault(i => i.Layer == Layer.TwoHanded); Item rightHand = Engine.Player?.Equipment.FirstOrDefault(i => i.Layer == Layer.OneHanded); if (leftHand == null && rightHand != null) { //OSI crossbow in OneHanded layer?? leftHand = rightHand; rightHand = null; } WeaponData leftHandWD = null; if (leftHand != null) { leftHandWD = GetWeaponData(leftHand.ID); } if ((!(leftHandWD?.Twohanded ?? false) && leftHand?.Properties != null && !(leftHand.Properties?.Any(p => p.Cliloc == 1061171 /* Two-Handed Weapon */) ?? false) || leftHand?.Properties != null && !(leftHand.Properties?.All(p => p.Cliloc != 1072792 /* Balanced */) ?? false)) && (rightHand == null || leftHand == null)) { _checkHandsInProgress = false; return(false); } if (leftHand == null) { _checkHandsInProgress = false; return(false); } ActionPacketQueue.EnqueueDragDrop(leftHand.Serial, 1, Engine.Player.GetLayer(Layer.Backpack), QueuePriority.High); ActionPacketQueue.EnqueuePackets( new BasePacket[] { new UseObject(serial), new DragItem(leftHand.Serial, 1), new EquipRequest(leftHand.Serial, leftHand.Layer, (int)Engine.Player?.Serial) }, QueuePriority.High).ContinueWith(t => _checkHandsInProgress = false); return(true); }
public static void SetForceWalk(bool force) { UOC.SetForceWalk(force); UOC.SystemMessage(force ? Strings.Force_Walk_On : Strings.Force_Walk_Off); }
public static bool Cast(string name, object obj) { int serial = AliasCommands.ResolveSerial(obj); if (serial == 0) { UOC.SystemMessage(Strings.Invalid_or_unknown_object_id); return(false); } SpellData sd = _manager.GetSpellData(name) ?? _manager.GetMasteryData(name); if (sd == null) { UOC.SystemMessage(Strings.Unknown_spell___); return(false); } // Debugging only Stopwatch sw = new Stopwatch(); sw.Start(); // _manager.CastSpell(sd.ID); int index = 0; bool result; if (Options.CurrentOptions.UseExperimentalFizzleDetection) { (index, result) = UOC.WaitForTargetOrFizzle(sd.Timeout + 1000); } else { result = TargetCommands.WaitForTarget(sd.Timeout + 500); } if (index == 0 && !result) { UOC.SystemMessage(Strings.Timeout___); return(false); } if (!result) { return(false); } // Debugging only sw.Stop(); if (Options.CurrentOptions.Debug) { UOC.SystemMessage( $"Target received in {sw.ElapsedMilliseconds}ms, Spell data timeout: {sd.Timeout}ms"); } // TargetCommands.Target(serial); return(true); }