protected ItemActionInfo GetClosestItem(double range = double.MaxValue) { ItemActionInfo temp = null; var dist = range; foreach (var item in itemsToPick) { if (item.Value.dropTime.MSecToNow() <= pickDelay) { continue; } var newDist = item.Value.DistanceTo(game.CurrentX, game.CurrentY); if (newDist < dist) { temp = item.Value; dist = newDist; } } return(temp); }
protected bool Pick(ItemActionInfo item, bool pick, bool telekinesis) { if (!game.InGame) { throw new Exception("Out of game"); } using (var suspender = new GameSuspender(game)) { if (!game.GameReady()) { throw new Exception("Out of game"); } if (game.IsDead()) { Disable(PickitDisableReason.Died); throw new Exception("Player is dead"); } if (telekinesis && DoTelekinesis(item.uid)) { } else if (pick) { game.PickItem(item.uid); } else { --item.pickTryCount; return(false); } } return(true); }
public ItemActionInfo ReadItemAction(byte[] data) { var i = new ItemActionInfo(); i.action = (ItemActionType)data[1]; var category = (ItemCategory)data[3]; i.uid = BitConverter.ToUInt32(data, 4); var pOffset = data[0] == 0x9D ? 13 : 8; i.flags = (ItemFlag)BitConverter.ToUInt32(data, pOffset); var version = data[pOffset += 4]; ++pOffset; //Log("Uid {0} action {1}", i.uid, i.action); if (i.action != ItemActionType.AddToGround && i.action != ItemActionType.DropToGround && i.action != ItemActionType.OnGround) { return(null); } i.x = BitConverter.ToUInt16(data, pOffset); i.y = BitConverter.ToUInt16(data, pOffset += 2); i.x = (i.x + 131072) / 32; i.y = (i.y + 131072) / 32; pOffset += 2; //TODO: Unknown bit //pOffset = pOffset * 8 + 1; pOffset = pOffset * 8 - 32 + 5; i.x = ByteConverter.GetBits(data, ref pOffset, 16); i.y = ByteConverter.GetBits(data, ref pOffset, 16); //var tmp = ByteConverter.GetBits(data, ref pOffset, 4); var container = ItemContainer.Ground; if (i.flags.HasFlag(ItemFlag.Ear)) { return(null); /*var charClass = ByteConverter.GetBits(data, ref pOffset, 3); * var level = (ushort)ByteConverter.GetBits(data, ref pOffset, 7); * var builder = new System.Text.StringBuilder(); * int mChar; * while ((mChar = ByteConverter.GetBits(data, ref pOffset, 7)) != 0) * builder.Append((char)mChar); * var name = builder.ToString(); * return i;*/ } i.code = String.Concat( (char)ByteConverter.GetBits(data, ref pOffset, 8), (char)ByteConverter.GetBits(data, ref pOffset, 8), (char)ByteConverter.GetBits(data, ref pOffset, 8)); pOffset += 4; if (i.code == "gld") { pOffset += 4; if (ByteConverter.GetBits(data, ref pOffset, 1) == 1) { i.goldCount = ByteConverter.GetBits(data, ref pOffset, 20); } else { i.goldCount = ByteConverter.GetBits(data, ref pOffset, 18); } return(i); } var location = EquipmentLocation.NotApplicable; // Buffer to container mapping (sanitize NPC tabs IDs and coords, changed belt location to X, Y, etc.) if (i.flags.HasFlag(ItemFlag.InStore) || // Flag is not always set for shop items !?! i.action == ItemActionType.AddToShop || i.action == ItemActionType.RemoveFromShop) { int buff = (int)container | 0x80; if (i.y < 2 && (buff == 0x83 || buff == 0x85 || buff == 0x89)) { buff -= 1; i.y += 8; } container = (ItemContainer)buff; } else if (container == ItemContainer.Equipment) { if (location == EquipmentLocation.NotApplicable) { if ((i.flags & ItemFlag.InSocket) != 0) { container = ItemContainer.Item; } else { container = ItemContainer.Belt; i.y = i.x / 4; i.x = i.x % 4; } } else { // Hides them in dump... not needed anyway i.y = -1; i.x = -1; } } // TODO: I don't know what this is (always 2 ??) var unknown1 = (byte)ByteConverter.GetBits(data, ref pOffset, 4); // Used Sockets : 3 byte usedSockets = 0; if (i.flags.HasFlag(ItemFlag.Socketed)) { usedSockets = (byte)ByteConverter.GetBits(data, pOffset, 3); } pOffset += 3; // Ends here if Simple or Gamble Item if ((i.flags & ItemFlag.SimpleItem) != 0 || (i.flags & ItemFlag.Gamble) != 0) { return(i); } // ILevel : 7 i.iLvl = (byte)ByteConverter.GetBits(data, ref pOffset, 7); // Quality : 4 i.quality = (ItemQuality)ByteConverter.GetBits(data, ref pOffset, 4); // Graphic : 1 : 3 if (ByteConverter.GetBits(data, ref pOffset, 1) == 1) { ByteConverter.GetBits(data, ref pOffset, 3); } //TODO: ClassInfo : 1 : 11 if (ByteConverter.GetBits(data, ref pOffset, 1) == 1) { ByteConverter.GetBits(data, ref pOffset, 11); } // Quality information if (i.flags.HasFlag(ItemFlag.Identified)) { switch (i.quality) { case ItemQuality.Inferior: /*this.prefix = new ItemAffix(ItemAffixType.InferiorPrefix, * ByteConverter.GetBits(data, ref pOffset, 3));*/ ByteConverter.GetBits(data, ref pOffset, 3); break; case ItemQuality.Superior: //this.prefix = new ItemAffix(ItemAffixType.SuperiorPrefix, 0); //TODO: quality type // 00 = AR // 01 = Max Dmg // 02 = AC // 03 = AR + Max Dmg // 04 = Durability // 05 = Durability + AR // 06 = Durability + Max Dmg // 07 = Durability + AC pOffset += 3; break; case ItemQuality.Magic: /*this.prefix = new ItemAffix(ItemAffixType.MagicPrefix, * ByteConverter.GetBits(data, ref pOffset, 11)); * this.suffix = new ItemAffix(ItemAffixType.MagicSuffix, * ByteConverter.GetBits(data, ref pOffset, 11));*/ ByteConverter.GetBits(data, ref pOffset, 11); ByteConverter.GetBits(data, ref pOffset, 11); break; case ItemQuality.Rare: case ItemQuality.Craft: /*this.prefix = new ItemAffix(ItemAffixType.RarePrefix, * ByteConverter.GetBits(data, ref pOffset, 8)); * this.suffix = new ItemAffix(ItemAffixType.RareSuffix, * ByteConverter.GetBits(data, ref pOffset, 8));*/ ByteConverter.GetBits(data, ref pOffset, 8); ByteConverter.GetBits(data, ref pOffset, 8); for (int j = 0; j < 3; ++j) { if (ByteConverter.GetBits(data, ref pOffset, 1) == 1) { ByteConverter.GetBits(data, ref pOffset, 11); } //this.magicPrefixes[i] = new ItemAffix(ItemAffixType.MagicPrefix, //ByteConverter.GetBits(data, ref pOffset, 11)); if (ByteConverter.GetBits(data, ref pOffset, 1) == 1) { ByteConverter.GetBits(data, ref pOffset, 11); } //this.magicSuffixes[i] = new ItemAffix(ItemAffixType.MagicSuffix, //ByteConverter.GetBits(data, ref pOffset, 11)); } break; case ItemQuality.Set: //this.setItem = BaseSetItem.Get(ByteConverter.GetBits(data, ref pOffset, 12)); ByteConverter.GetBits(data, ref pOffset, 12); break; case ItemQuality.Unique: if (i.code != "std") // TODO: add UniqueItem entry to parse mod (req lvl 90) { ByteConverter.GetBits(data, ref pOffset, 12); } //this.uniqueItem = BaseUniqueItem.Get(ByteConverter.GetBits(data, ref pOffset, 12)); break; } } // Personalized Name : 7 * (NULLSTRING Length) if (i.flags.HasFlag(ItemFlag.Personalized)) { System.Text.StringBuilder builder = new System.Text.StringBuilder(); int mChar; while ((mChar = ByteConverter.GetBits(data, ref pOffset, 7)) != 0) { builder.Append((char)mChar); } var personalizedName = builder.ToString(); } // Runeword Info : 16 if (i.flags.HasFlag(ItemFlag.Runeword)) { //HACK: this is probably wrong, but works for all the runewords I tested so far... //TODO: Need to test cases where runewordUnknown != 5 and where ID is around 100 //TODO: remove these fields once testing is done var runewordID = ByteConverter.GetBits(data, ref pOffset, 12); var runewordUnknown = ByteConverter.GetBits(data, ref pOffset, 4); } var itemInfo = ItemStorage.GetInfo(i.code); if (itemInfo == null) { return(null); } if (itemInfo.BodyLocation == ItemBodyLocation.Armor && itemInfo.ArmorType != ItemArmorType.Amulet && itemInfo.ArmorType != ItemArmorType.Ring) { var defense = ByteConverter.GetBits(data, ref pOffset, 11) - 10; } var maxDurability = 0; var currentDurability = 0; if (itemInfo.BodyLocation == ItemBodyLocation.Armor && itemInfo.ArmorType != ItemArmorType.Amulet && itemInfo.ArmorType != ItemArmorType.Ring || itemInfo.BodyLocation == ItemBodyLocation.Weapon) { maxDurability = ByteConverter.GetBits(data, ref pOffset, 8); // 0 durability means indestructible, but only found on old items (having the "zod bug"...) if (maxDurability > 0) { currentDurability = ByteConverter.GetBits(data, ref pOffset, 8); //TODO: unknown. Indestructible bit ?? ByteConverter.GetBits(data, ref pOffset, 1); } } // Total Sockets : 4 if (i.flags.HasFlag(ItemFlag.Socketed)) { i.sockets = ByteConverter.GetBits(data, ref pOffset, 4); } return(i); }
protected void LogDrop(ItemActionInfo i) { var message = "Dropped "; var addsocks = false; var addilvl = false; var color = i.quality.GetColor(); switch (i.quality) { case ItemQuality.Unique: { if (i.info.PossibleUniques.Count == 1) { message += i.info.PossibleUniques[0]; } else if (i.info.IsBijou()) { message += i.info.Name; } else { message += i.info.Name + " ("; for (int j = 0; j < i.info.PossibleUniques.Count; ++j) { message += i.info.PossibleUniques[j]; if (j != i.info.PossibleUniques.Count - 1) { message += ", "; } } message += ")"; } break; } case ItemQuality.Set: { if (i.info.PossibleSets.Count == 1) { message += i.info.PossibleSets[0]; } else if (i.info.IsBijou()) { message += i.info.Name; } else { message += i.info.Name + " ("; for (int j = 0; j < i.info.PossibleSets.Count; ++j) { message += i.info.PossibleSets[j]; if (j != i.info.PossibleSets.Count - 1) { message += ", "; } } message += ")"; } break; } case ItemQuality.Normal: { message += i.info.Name; if (i.info.IsRune()) { color = Color.MediumPurple; message += " (" + i.info.RuneNumber().ToString() + ")"; } else { addsocks = true; addilvl = true; } break; } case ItemQuality.Superior: { message += "Superior " + i.info.Name; addsocks = true; addilvl = true; break; } default: { message += i.info.Name; break; } } if (addsocks && i.sockets != 0) { message += " (" + i.sockets.ToString() + ")"; } if (addilvl && i.iLvl > 1) { message += " (L" + i.iLvl.ToString() + ")"; } if (i.IsEth) { message += " (Eth)"; } Logger.Pickit.Log(this, LogType.None, message, color); }
public void AddPendingItem(ItemActionInfo item) { item.pickTryCount = 0; itemsToPick[item.uid] = item; }