public void SetItem(int i, Item item) { Action <Point2D> itemTakeHandler = (p) => ItemTake.Raise(i, p); Action <Point2D> itemTransferHandler = (p) => ItemTransfer.Raise(i, p); Action <Point2D> itemActHandler = (p) => ItemAct.Raise(i, p); Action <KeyModifiers> itemInteractHandler = (mods) => ItemInteract.Raise(i); if (items[i] != null) { items[i].Take -= itemTakeHandler; items[i].Transfer -= itemTransferHandler; items[i].Act -= itemActHandler; items[i].Interact -= itemInteractHandler; items[i].Remove(); items[i].Dispose(); } if (item != null) { items[i] = new ItemWidget(this, null); items[i].Item = item; items[i].Move(slotPositions[i].X, slotPositions[i].Y); items[i].Take += itemTakeHandler; items[i].Transfer += itemTransferHandler; items[i].Act += itemActHandler; items[i].Interact += itemInteractHandler; } }
private void AddItems(Character chr) { // Note: Exchange logic, so A gets B and B gets A stuff for (int i = 0; i < 2; i++) { if (i == chr.RoomSlotId) { continue; } var charFrom = Users[i]; for (int j = 0; j < 10; j++) { TradeItem ti = ItemList[i][j]; if (ti?.OriginalItem != null) { chr.Inventory.AddItem2(ti.OriginalItem); ItemTransfer.PlayerTradeExchange(charFrom.ID, chr.ID, ti.OriginalItem.ItemID, ti.OriginalItem.Amount, _transaction, ti.OriginalItem); ti.OriginalItem = null; } } var mesos = Mesos[i]; if (mesos != 0) { chr.AddMesos(mesos); MesosTransfer.PlayerTradeExchange(charFrom.ID, chr.ID, mesos, _transaction); } } }
public void RunTransfer() { header = AdalAuthenticate(); var start = DateTime.Now; DataWriter.TruncateTables(true, false, false, true, true, false); var truncate = DateTime.Now; Debug.WriteLine("Truncate = " + truncate.Subtract(start).TotalSeconds); ItemCategoryTransfer.WriteCategories(header); DateTime cat = DateTime.Now; Debug.WriteLine("Category = " + cat.Subtract(truncate).TotalSeconds); LocationsAndVendorsTransfer.WriteLocationsAndVendors(context, header); DateTime loc = DateTime.Now; Debug.WriteLine("Locations = " + loc.Subtract(cat).TotalSeconds); ItemTransfer.WriteItems(context, header); DateTime items = DateTime.Now; Debug.WriteLine("Items = " + items.Subtract(loc).TotalSeconds); ItemAttributeLookup.ReadItemAttributes(context, header); DateTime lookup = DateTime.Now; Debug.WriteLine("Lookup = " + lookup.Subtract(items).TotalSeconds); }
private static void DropItem(Character chr, byte inventory, short slot, short quantity) { if (chr.AssertForHack(chr.Room != null, "Trying to drop item while in a 'room'")) { NoChange(chr); return; } // Remove items from slot, taking stars if possible var drop = chr.Inventory.TakeItemAmountFromSlot(inventory, slot, quantity, true); if (drop == null) { // Item not found or quantity not enough NoChange(chr); return; } bool droppedFromEquips = Constants.isEquip(drop.ItemID) && slot < 0; ItemTransfer.ItemDropped(chr.ID, chr.MapID, drop.ItemID, drop.Amount, "", drop); chr.Field.DropPool.Create(Reward.Create(drop), chr.ID, 0, DropType.Normal, chr.ID, new Pos(chr.Position), chr.Position.X, 0, false, (short)(chr.Field.DropPool.DropEverlasting ? drop.InventorySlot : 0), false, true); if (droppedFromEquips) { MapPacket.SendAvatarModified(chr, MapPacket.AvatarModFlag.Equips); } }
public static void HandleShopUpdateItem(Character pCharacter, byte inv, short invslot, short bundle, short bundleamount, int price) { MiniRoomBase mrb = pCharacter.Room; if (pCharacter.AssertForHack(mrb.Users[0] != pCharacter, "PlayerShop hack: Tried to update shop item while not owner.")) { return; } BaseItem tehItem = pCharacter.Inventory.GetItem(inv, invslot); if (tehItem == null) { //Doesn't have item in inventory ReportManager.FileNewReport("Tried adding an item into player shop without having it.", pCharacter.ID, 0); InventoryPacket.NoChange(pCharacter); return; } var newItem = tehItem.Duplicate(); newItem.InventorySlot = invslot; if (newItem.Amount < bundle || bundle <= 0 || bundle > 100) { //Packet edits ReportManager.FileNewReport("Tried adding an item into player shop with an incorrect amount/incorrect itemid.", pCharacter.ID, 0); InventoryPacket.NoChange(pCharacter); return; } PlayerShopItem pst = new PlayerShopItem(newItem) { Price = price }; pst.sItem.Amount = (short)(bundle * bundleamount); pst.Bundles = bundle; pst.BundleAmount = bundleamount; mrb.AddItemToShop(pCharacter, pst); if (Constants.isStackable(pst.sItem.ItemID)) { pCharacter.Inventory.TakeItemAmountFromSlot(inv, invslot, (short)(bundle * bundleamount), false); } else { pCharacter.Inventory.TakeItem(pst.sItem.ItemID, bundle); } ItemTransfer.PersonalShopPutUpItem(pCharacter.ID, pst.sItem.ItemID, pst.sItem.Amount, mrb.TransactionID, pst.sItem); InventoryPacket.NoChange(pCharacter); //-.- }
public void RevertItems(Character pOwner) { if (pOwner == pOwner.Room.Users[0]) { foreach (var pst in Items) { if (pst.Value.sItem.Amount != 0) //If an item is set to 0, no point of adding it. { pOwner.Inventory.AddItem2(pst.Value.sItem); ItemTransfer.PersonalShopGetBackItem(pOwner.ID, pst.Value.sItem.ItemID, pst.Value.sItem.Amount, _transaction, pst.Value.sItem); pst.Value.sItem = null; } } } }
private void Dg_itemOrder_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { try { TextBox t = e.EditingElement as TextBox; // Assumes columns are all TextBoxes var columnName = e.Column.Header.ToString(); ItemTransfer row = e.Row.Item as ItemTransfer; int index = invoiceItems.IndexOf(invoiceItems.Where(p => p.itemUnitId == row.itemUnitId).FirstOrDefault()); long oldReserved = 0; long newReserved = 0; if (!t.Text.Equals("")) { newReserved = int.Parse(t.Text); } oldReserved = (long)invoiceItems[index].lockedQuantity; if (newReserved > oldReserved && (newReserved - oldReserved) > row.availableQuantity) { t.Text = oldReserved.ToString(); invoiceItems[index].newLocked = oldReserved; Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trErrorAmountNotAvailableFromToolTip"), animation: ToasterAnimation.FadeIn); } else if (newReserved > row.quantity) { t.Text = oldReserved.ToString(); invoiceItems[index].newLocked = oldReserved; Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trErrorAmountIncreaseToolTip"), animation: ToasterAnimation.FadeIn); } else { t.Text = newReserved.ToString(); invoiceItems[index].newLocked = newReserved; } refrishDataGridItems(); } catch (Exception ex) { SectionData.ExceptionMessage(ex, this); } }
public void HandleMoveItemBack(Character pCharacter, byte slot) { if (Items.TryGetValue(slot, out PlayerShopItem pst)) { pCharacter.Inventory.AddItem2(pst.sItem); ItemTransfer.PersonalShopGetBackItem(pCharacter.ID, pst.sItem.ItemID, pst.sItem.Amount, _transaction, pst.sItem); var x = pst.sItem.Amount; if (x == 1) { PlayerShopPackets.MoveItemToInventory(pCharacter, 0, slot); // Remove? but that would reorder it!!! } else { byte left = (byte)(x - 1); //amount left PlayerShopPackets.MoveItemToInventory(pCharacter, left, slot); } } InventoryPacket.NoChange(pCharacter); }
public void CommitTransfer(ItemTransfer transfer) { if (Settings.IsVerbose) { Console.WriteDebugLine(" Committing transfer"); Console.WriteDebugLine(" Source: " + transfer.Source.GetType().Name); Console.WriteDebugLine(" Destination: " + transfer.Destination.GetType().Name); Console.WriteDebugLine(" Type: " + transfer.Type); Console.WriteDebugLine(" Quantity: " + transfer.Quantity); } var type = transfer.Type; transfer.Source.Inventory [type] -= transfer.Quantity; transfer.Destination.Inventory [type] += transfer.Quantity; if (Settings.IsVerbose) { Console.WriteDebugLine(" Source (" + transfer.Source.GetType().Name + ") total: " + transfer.Source.Inventory[type]); Console.WriteDebugLine(" Destination (" + transfer.Destination.GetType().Name + ") total: " + transfer.Destination.Inventory[type]); } }
public JsonResult Create(string transItem, int OutletId) { int sid = Convert.ToInt32(Session["OutletID"].ToString()); if (OutletId != 0 && transItem != null) { ItemTransfer itemTransfer = new ItemTransfer(); itemTransfer.ManagerApproved = false; itemTransfer.ItemFrom = sid; itemTransfer.Item = transItem; itemTransfer.OutletID = OutletId; itemTransfer.IsDeleted = false; itemTransfer.TransferDate = DateTime.Now; db.ItemTransfers.Add(itemTransfer); db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); } else { return(Json(false, JsonRequestBehavior.AllowGet)); } }
private void RevertItems() { for (int i = 0; i < 2; i++) { Character chr = Users[i]; if (chr == null) { continue; } for (int j = 0; j < 10; j++) { TradeItem ti = ItemList[i][j]; if (ti?.OriginalItem != null) //just to make sure that the player actually has items in trade.. { chr.Inventory.AddItem2(ti.OriginalItem); ItemTransfer.PlayerTradeReverted(chr.ID, ti.OriginalItem.ItemID, ti.OriginalItem.Amount, _transaction, ti.OriginalItem); ti.OriginalItem = null; } } } }
public static void HandleStorage(Character chr, Packet pr) { if (chr.TrunkNPCID == 0) { return; } byte opcode = pr.ReadByte(); switch ((StorageAction)opcode) { case StorageAction.Withdraw: // Remove { byte inventory = pr.ReadByte(); byte slot = pr.ReadByte(); BaseItem item = chr.Storage.GetItem(inventory, slot); if (item == null) { return; } short amount = item.Amount; if (!Constants.isStackable(item.ItemID)) { amount = 1; // 1 'set' } if (chr.Inventory.HasSlotsFreeForItem(item.ItemID, amount, inventory != 1)) { // AddItem2 will distribute stackable items chr.Inventory.AddItem2(item); chr.Storage.TakeItemOut(inventory, slot); ItemTransfer.PlayerStorageWithdraw(chr.ID, chr.TrunkNPCID, item.ItemID, item.Amount, null, item); EncodeStorage(chr, StorageEncode.EncodeWithdraw, GetEncodeFlagForInventory(Constants.getInventory(item.ItemID))); } else { SendError(chr, StorageErrors.InventoryFullOrNot); } break; } case StorageAction.Deposit: // Add { byte slot = (byte)pr.ReadShort(); int itemid = pr.ReadInt(); short amount = pr.ReadShort(); NPCData data = DataProvider.NPCs[chr.TrunkNPCID]; var storageCost = data.Trunk; if (chr.Inventory.Mesos < storageCost) { SendError(chr, StorageErrors.NotEnoughMesos); return; } byte inventory = Constants.getInventory(itemid); BaseItem item = chr.Inventory.GetItem(inventory, slot); if (item == null || item.ItemID != itemid || item.CashId != 0) { // hax return; } if (!chr.Storage.SlotsAvailable()) { SendError(chr, StorageErrors.StorageIsFull); return; } var isRechargable = Constants.isRechargeable(item.ItemID); if (isRechargable) { amount = item.Amount; } var possibleNewItem = chr.Inventory.TakeItemAmountFromSlot(inventory, slot, amount, true); if (chr.AssertForHack(possibleNewItem == null, "Storage hack (amount > item.amount)")) { return; } chr.Storage.AddItem(possibleNewItem); ItemTransfer.PlayerStorageStore(chr.ID, chr.TrunkNPCID, item.ItemID, item.Amount, "" + item.GetHashCode() + " " + possibleNewItem.GetHashCode(), possibleNewItem); EncodeStorage(chr, StorageEncode.EncodeDeposit, GetEncodeFlagForInventory(Constants.getInventory(item.ItemID))); chr.AddMesos(-storageCost); //why did you forget this diamondo :P MesosTransfer.PlayerGaveToNPC(chr.ID, chr.TrunkNPCID, storageCost, "" + item.GetHashCode()); break; } case StorageAction.StoreMesos: { int mesos = pr.ReadInt(); if (mesos < 0) { // Store if (chr.AssertForHack(Math.Abs(mesos) > chr.Inventory.Mesos, "Trying to store more mesos than he has") == false) { Common.Tracking.MesosTransfer.PlayerStoreMesos(chr.ID, Math.Abs(mesos)); chr.AddMesos(mesos); chr.Storage.ChangeMesos(mesos); } } else { // Withdraw if (chr.AssertForHack(Math.Abs(mesos) > chr.Storage.Mesos, "Trying to withdraw more mesos than he has") == false) { Common.Tracking.MesosTransfer.PlayerRetrieveMesos(chr.ID, Math.Abs(mesos)); chr.AddMesos(mesos); chr.Storage.ChangeMesos(mesos); } } break; } case StorageAction.Exit: { chr.TrunkNPCID = 0; break; } default: { Program.MainForm.LogAppend("Unknown Storage action: {0}", pr); break; } } }
public Telegram(ItemTransfer item, Emotes emotion) { Emotion = emotion; Text = item.ToString(); }
//First line structutre //CHARACTER NAME: MESSAGE ID //End line structure: //## is end without jump or choice //#<ID> jumps to message of that ID //and a choice structure ends it in a choice public Message(string rawDialog) { Lines = new List<Telegram>(); ItemTransfers = new List<ItemTransfer>(); FavorChanges = new List<CharachterFavorChange>(); BoolChanges = new List<BoolChange>(); int index = 0; int line = 0; JumpID = 0; EndsInChoice = false; JustEnds = false; JumpsAtEnd = false; BoolJump = false; string[] allLines = rawDialog.Split('\n'); foreach (string c in allLines) { if (c != null && c != "") { //if first line: Get ID and CHARACTER if (index == 0) { Character = (Characters)Enum.Parse(typeof(Characters), c.Split(':')[0].Trim()); ID = Convert.ToInt32(c.Split(':')[1].Trim()); index++; } //if Item line: Get the item transfer info else if (c[0] == '[') { ItemTransfer item = new ItemTransfer(c, line); ItemTransfers.Add(item); Lines.Add(new Telegram(item, Lines[Lines.Count-1].Emotion)); index++; } else if (c[0] == '/' && c[1] == '/' ) { //Comment } //if dialog line add the dialog to the list else if (c[0] == '<') { Lines.Add(new Telegram(c)); line++; index++; } //For favors // add, subtract else if(c[0] == '+' || c[0] == '-') { FavorChanges.Add(new CharachterFavorChange(c)); } //For Bools else if(c[0] == '*') { BoolChanges.Add(new BoolChange(c)); } //if end line check end paramaters else if (c[0] == '#') { if (c[1] == '<') { JumpsAtEnd = true; JumpID = Convert.ToInt32(c.Trim().TrimStart('#').TrimStart('<').TrimEnd('>')); } else if (c[1] == '#') { JustEnds = true; } else if (c[1] == '?') { EndsInChoice = true; EndChoice = new Choice(c); } else if (c[1] == '!') { BoolJump = true; JumpBool = new BooleanJump(c); } else if(c[1] == '=') { FavorJump = true; JumpFavor = new FavorCheck(c); } } } } Length = line; }
public override void OnPacket(Character pCharacter, byte pOpcode, Packet pPacket) { switch (pOpcode) { case 13: { byte charslot = pCharacter.RoomSlotId; // Put Item if (!IsFull()) { // You can't put items while the second char isn't there yet InventoryPacket.NoChange(pCharacter); return; } byte inventory = pPacket.ReadByte(); short slot = pPacket.ReadShort(); short amount = pPacket.ReadShort(); byte toslot = pPacket.ReadByte(); var demItem = pCharacter.Inventory.GetItem(inventory, slot); if (demItem == null || toslot < 1 || toslot > 9) // Todo: trade check { // HAX var msg = $"Player tried to add an item in trade with to an incorrect slot. Item = null? {demItem == null}; toSlot {toslot}"; Program.MainForm.LogAppend(msg); ReportManager.FileNewReport(msg, pCharacter.ID, 0); InventoryPacket.NoChange(pCharacter); return; } BaseItem tehItem = pCharacter.Inventory.TakeItemAmountFromSlot(inventory, slot, amount, Constants.isRechargeable(demItem.ItemID)); if (ItemList[charslot][toslot] == null) { ItemList[charslot][toslot] = new TradeItem() { OriginalItem = tehItem }; } var pTradeItem = ItemList[charslot][toslot].OriginalItem; ItemTransfer.PlayerTradePutUp(pCharacter.ID, demItem.ItemID, slot, amount, _transaction, demItem); bool isUser0 = pCharacter.Name == Users[0].Name; TradePacket.AddItem(Users[0], toslot, pTradeItem, (byte)(isUser0 ? 0 : 1)); TradePacket.AddItem(Users[1], toslot, pTradeItem, (byte)(isUser0 ? 1 : 0)); InventoryPacket.NoChange(pCharacter); // -.- break; } case 14: // Put mesos { //MessagePacket.SendNotice("PUTMESO PACKET: " + pPacket.ToString(), pCharacter); int amount = pPacket.ReadInt(); if (amount < 0 || pCharacter.Inventory.Mesos < amount) { // HAX var msg = "Player tried putting an incorrect meso amount in trade. Amount: " + amount; Program.MainForm.LogAppend(msg); ReportManager.FileNewReport(msg, pCharacter.ID, 0); return; } pCharacter.AddMesos(-amount, true); MesosTransfer.PlayerTradePutUp(pCharacter.ID, amount, _transaction); Mesos[pCharacter.RoomSlotId] += amount; bool isUser0 = pCharacter.Name == Users[0].Name; TradePacket.PutCash(Users[0], Mesos[pCharacter.RoomSlotId], (byte)(isUser0 ? 0 : 1)); TradePacket.PutCash(Users[1], Mesos[pCharacter.RoomSlotId], (byte)(isUser0 ? 1 : 0)); break; } // Accept trade case 0xF: { byte charslot = pCharacter.RoomSlotId; Locked[charslot] = true; for (int i = 0; i < 2; i++) { Character chr = Users[i]; if (chr != pCharacter) { TradePacket.SelectTrade(chr); } } if (Locked[0] == true && Locked[1] == true) { Character chr = Users[0]; Character chr2 = Users[1]; if (ContinueTrade()) { CompleteTrade(); TradePacket.TradeSuccessful(chr); TradePacket.TradeSuccessful(chr2); } else { // Unsuccessful error RemovePlayer(chr, 6); RemovePlayer(chr2, 6); } } break; } } }
public static void HandlePickupDrop(Character chr, Packet packet) { // 5F 18 FF 12 01 00 00 00 00 packet.Skip(4); // pos? int dropid = packet.ReadInt(); if (chr.AssertForHack(chr.Room != null, "Trying to loot a drop while in a 'room'") || !chr.Field.DropPool.Drops.TryGetValue(dropid, out Drop drop) || !drop.CanTakeDrop(chr)) { InventoryPacket.NoChange(chr); return; } var dropLootRange = drop.Pt2 - chr.Position; chr.AssertForHack(dropLootRange > 200, "Possible drop VAC! Distance: " + dropLootRange, dropLootRange > 250); bool SentDropNotice = false; Reward reward = drop.Reward; int dropNoticeItemIdOrMesos = reward.Drop; short pickupAmount = reward.Amount; if (reward.Mesos) { // Party meso distribution if (drop.SourceID != 0 && chr.PartyID != 0 && drop.OwnPartyID == chr.PartyID) { var PartyData = chr.Field.GetInParty(chr.PartyID); var Count = PartyData.Count(); if (Count > 1) { SentDropNotice = true; var Base = drop.Reward.Drop * 0.8 / Count + 0.5; Base = Math.Floor(Base); if (Base <= 0.0) { Base = 0.0; } var Bonus = Convert.ToInt32(drop.Reward.Drop - Count * Base); if (Bonus < 0) { Bonus = 0; } drop.Reward.Drop = Convert.ToInt32(Base); foreach (var BonusUser in PartyData) { int mesosGiven = reward.Drop; if (chr.ID == BonusUser.ID) { mesosGiven += Bonus; } // Now figure out what we really gave the user mesosGiven = BonusUser.AddMesos(mesosGiven, true); Common.Tracking.MesosTransfer.PlayerLootMesos(drop.SourceID, chr.ID, mesosGiven, "Party " + chr.PartyID + ", " + chr.MapID + ", " + drop.GetHashCode()); CharacterStatsPacket.SendGainDrop(BonusUser, true, mesosGiven, 0); } } } if (!SentDropNotice) { dropNoticeItemIdOrMesos = chr.AddMesos(reward.Drop, true); Common.Tracking.MesosTransfer.PlayerLootMesos( drop.SourceID, chr.ID, dropNoticeItemIdOrMesos, chr.MapID + ", " + drop.GetHashCode() ); } } else if (Constants.isStar(reward.ItemID)) { if (!chr.Inventory.HasSlotsFreeForItem(reward.ItemID, reward.Amount, Constants.isStackable(reward.ItemID))) { CannotLoot(chr, -1); InventoryPacket.NoChange(chr); return; } var rewardItem = drop.Reward.GetData(); chr.Inventory.AddItem2(rewardItem); ItemTransfer.ItemPickedUp(chr.ID, chr.MapID, reward.ItemID, reward.Amount, chr.MapID + ", " + drop.GetHashCode(), rewardItem); } else if (chr.Inventory.AddItem2(drop.Reward.GetData()) == drop.Reward.Amount) { CannotLoot(chr, -1); InventoryPacket.NoChange(chr); // ._. stupid nexon return; } else { if (Constants.isEquip(drop.Reward.ItemID)) { ItemTransfer.ItemPickedUp(chr.ID, chr.MapID, reward.ItemID, reward.Amount, chr.MapID + ", " + drop.GetHashCode(), drop.Reward.GetData()); } } if (!SentDropNotice) { CharacterStatsPacket.SendGainDrop(chr, reward.Mesos, dropNoticeItemIdOrMesos, pickupAmount); } chr.Field.DropPool.RemoveDrop(drop, RewardLeaveType.FreeForAll, chr.ID); }
public void BuyItem(Character pCharacter, byte slot, short quantity) { //This may seem confusing, but the client calculates the amount left itself. //The formula is bundles * bundleamount, so if you have 2 bundles with 25 in each, it will obviously show 50. If you have 100 items in 1 bundle, it will show you 100 PlayerShopItem pst = Items[slot]; PlayerShop ps = MiniRoomBase.PlayerShops[pCharacter.Room.ID]; if (pst == null) { return; } if (pCharacter.AssertForHack( quantity < 0, $"PlayerShop hack: trying to buy negative amount. Requested {quantity}" )) { return; } if (pst.sItem.Amount <= 0) { // TODO: Get packet? return; } var cost = quantity * pst.Price; var realAmount = (short)(quantity * pst.BundleAmount); if (cost > pCharacter.Inventory.Mesos) { // TODO: Get packet? return; } if (pCharacter.AssertForHack( pst.Bundles < quantity, $"PlayerShop hack: buying more than there's in store. Bundle: {pst.Bundles}, requested {quantity}" )) { return; } if (pCharacter.AssertForHack( pst.sItem.Amount < realAmount, $"PlayerShop hack: buying more than there's in store. Item amount: {pst.sItem.Amount}, requested {realAmount}" )) { return; } pCharacter.Inventory.AddNewItem(pst.sItem.ItemID, realAmount); pCharacter.AddMesos(-cost); Owner.AddMesos(cost); MesosTransfer.PlayerBuysFromPersonalShop(pCharacter.ID, Owner.ID, cost, _transaction); ItemTransfer.PersonalShopBoughtItem(Owner.ID, pCharacter.ID, pst.sItem.ItemID, realAmount, TransactionID, pst.sItem); pst.Bundles -= quantity; pst.sItem.Amount -= realAmount; PlayerShopPackets.PersonalShopRefresh(pCharacter, ps); PlayerShopPackets.SoldItemResult(Owner, pCharacter, slot, quantity); }
public void CommitTransfer(ItemTransfer transfer) { if (Settings.IsVerbose) { Console.WriteDebugLine (" Committing transfer"); Console.WriteDebugLine (" Source: " + transfer.Source.GetType().Name); Console.WriteDebugLine (" Destination: " + transfer.Destination.GetType().Name); Console.WriteDebugLine (" Type: " + transfer.Type); Console.WriteDebugLine (" Quantity: " + transfer.Quantity); } var type = transfer.Type; transfer.Source.Inventory [type] -= transfer.Quantity; transfer.Destination.Inventory [type] += transfer.Quantity; if (Settings.IsVerbose) { Console.WriteDebugLine (" Source (" + transfer.Source.GetType().Name + ") total: " + transfer.Source.Inventory[type]); Console.WriteDebugLine (" Destination (" + transfer.Destination.GetType().Name + ") total: " + transfer.Destination.Inventory[type]); } }
public static void HandleCashItem(Character chr, Packet packet) { short slot = packet.ReadShort(); int itemid = packet.ReadInt(); BaseItem item = chr.Inventory.GetItem(2, slot); if (chr.AssertForHack(item == null, "HandleCashItem with null item") || chr.AssertForHack(item.ItemID != itemid, "HandleCashItem with itemid inconsistency") || chr.AssertForHack(!DataProvider.Items.TryGetValue(itemid, out var data), "HandleCashItem with unknown item") || chr.AssertForHack(!data.Cash, "HandleCashItem with non-cash item")) { return; } var itemType = (Constants.Items.Types.ItemTypes)Constants.getItemType(itemid); bool used = false; switch (itemType) { case Constants.Items.Types.ItemTypes.ItemWeather: used = chr.Field.MakeWeatherEffect(itemid, packet.ReadString(), new TimeSpan(0, 0, 30)); break; case Constants.Items.Types.ItemTypes.ItemJukebox: used = chr.Field.MakeJukeboxEffect(itemid, chr.Name, packet.ReadInt()); break; case Constants.Items.Types.ItemTypes.ItemPetTag: { var name = packet.ReadString(); var petItem = chr.GetSpawnedPet(); if (petItem != null && !chr.IsInvalidTextInput("Pet name tag", name, Constants.MaxPetName, Constants.MinPetName)) { petItem.Name = name; PetsPacket.SendPetNamechange(chr, petItem.Name); used = true; } } break; case Constants.Items.Types.ItemTypes.ItemMegaPhone: { var text = packet.ReadString(); if (!chr.IsInvalidTextInput("Megaphone item", text, Constants.MaxSpeakerTextLength)) { switch (itemid) { case 2081000: // Super Megaphone (channel) MessagePacket.SendMegaphoneMessage(chr.Name + " : " + text); used = true; break; case 2082000: // Super Megaphone Server.Instance.CenterConnection.PlayerSuperMegaphone( chr.Name + " : " + text, packet.ReadBool() ); used = true; break; } } } break; case Constants.Items.Types.ItemTypes.ItemKite: if (chr.Field.Kites.Count > 0) { //Todo : check for character positions..? MapPacket.KiteMessage(chr); } else { string message = packet.ReadString(); Kite pKite = new Kite(chr, chr.ID, itemid, message, chr.Field); used = true; } break; case Constants.Items.Types.ItemTypes.ItemMesoSack: if (data.Mesos > 0) { int amountGot = chr.AddMesos(data.Mesos); MiscPacket.SendGotMesosFromLucksack(chr, amountGot); used = true; } break; case Constants.Items.Types.ItemTypes.ItemTeleportRock: { byte mode = packet.ReadByte(); int map = -1; if (mode == 1) { string name = packet.ReadString(); Character target = Server.Instance.GetCharacter(name); if (target != null && target != chr) { map = target.MapID; used = true; } else { SendRockError(chr, RockErrors.DifficultToLocate); } } else { map = packet.ReadInt(); if (!chr.Inventory.HasRockLocation(map)) { map = -1; } } if (map != -1) { //I don't think it's even possible for you to be in a map that doesn't exist and use a Teleport rock? Map from = chr.Field; Map to = DataProvider.Maps.ContainsKey(map) ? DataProvider.Maps[map] : null; if (to == from) { SendRockError(chr, RockErrors.AlreadyThere); } else if (from.Limitations.HasFlag(FieldLimit.TeleportItemLimit)) { SendRockError(chr, RockErrors.CannotGo); } else if (chr.AssertForHack(chr.PrimaryStats.Level < 7, "Using telerock while not lvl 8 or higher.")) { // Hacks. } else { chr.ChangeMap(map); used = true; } } break; } default: Program.MainForm.LogAppend("Unknown cashitem used: {0} {1} {2}", itemType, itemid, packet.ToString()); break; } if (used) { ItemTransfer.ItemUsed(chr.ID, item.ItemID, 1, ""); chr.Inventory.TakeItem(item.ItemID, 1); } else { InventoryPacket.NoChange(chr); } }
public void DoSkillCost(int skillid, byte level) { var data = GetSkillLevelData(skillid, level); if (data == null) { return; } if (skillid == Constants.DragonKnight.Skills.DragonRoar) { var lefthp = (int)(Character.PrimaryStats.MaxHP * (data.XValue / 100.0d)); Character.DamageHP((short)lefthp); } var mp = data.MPUsage; var hp = data.HPUsage; var cash = data.MesosUsage; var item = data.ItemIDUsage; if (mp > 0) { mp = GetElemAmpInc(skillid, mp); if (Character.AssertForHack(Character.PrimaryStats.MP < mp, "MP Hack (no MP left)")) { return; } Character.ModifyMP((short)-mp, true); } if (hp > 0) { if (Character.AssertForHack(Character.PrimaryStats.HP < hp, "HP Hack (no HP left)")) { return; } Character.ModifyHP((short)-hp, true); } if (item > 0) { var slotsAvailable = Character.Inventory.ItemAmountAvailable(item); if (Character.AssertForHack(slotsAvailable < data.ItemAmountUsage, "Player tried to use skill with item consumption. Not enough items to consume.")) { return; } Character.Inventory.TakeItem(item, data.ItemAmountUsage); ItemTransfer.PlayerUsedSkill(Character.ID, skillid, item, data.ItemAmountUsage); } if (cash > 0 && false) { var min = (short)(cash - (80 + level * 5)); var max = (short)(cash + (80 + level * 5)); var realAmount = (short)Character.CalcDamageRandomizer.ValueBetween(min, max); if (Character.AssertForHack(((long)Character.Inventory.Mesos - realAmount) < 0, "Player tried to use skill with meso consumption. Not enough mesos.")) { return; } Character.AddMesos(-realAmount); MesosTransfer.PlayerUsedSkill(Character.ID, realAmount, skillid); } }
public ItemDTO CreateItem(ItemDTO item) { header = AdalAuthenticate(); return(ItemTransfer.CreateItem(item, header)); }