public void HandleConfirmTrade(Character confirmer) { if (!acceptedInvite || confirmer.dwId == dwFirstLockerId) { return; // PE } if (IsOwner(confirmer)) { Partner.SendPacket(PartnerLockPacket()); } else { Parent.SendPacket(PartnerLockPacket()); } if (dwFirstLockerId > 0) { if (InventoryManipulator.HasSpace(Parent, tempInvPartner) && InventoryManipulator.HasSpace(Parent, tempInvOwner)) { CurrentStatus = MR_LeaveResult.TradeDone; } else { CurrentStatus = MR_LeaveResult.TradeFail; } Destroy(); } else { dwFirstLockerId = confirmer.dwId; } }
public void OnLostQuestItem(CInPacket p, short nQuestID) { var nLostCount = p.Decode4(); var pAct = MasterManager.QuestTemplates[nQuestID].StartAct; if (pAct is null) { return; // invalid quest ID } if (nLostCount <= 0 || pAct.Items.Length <= 0) { return; // TODO trigger AB, close socket } var aLostItem = p.DecodeIntArray(nLostCount); foreach (var item in pAct.Items) { if (!aLostItem.Contains(item.Item.ItemID)) { continue; // TODO trigger AB? } if (ItemConstants.GetInventoryType(item.Item.ItemID) == InventoryType.Equip) { Parent.SendMessage("Not currently supported. Check again later."); return; // TODO } if (!MasterManager.ItemTemplates[item.Item.ItemID]?.Quest ?? true) { continue; } if (InventoryManipulator.HasSpace(Parent, item.Item.ItemID, (short)item.Item.Count)) { var itemToAdd = MasterManager.CreateItem(item.Item.ItemID); itemToAdd.nNumber = (short)item.Item.Count; InventoryManipulator.InsertInto(Parent, itemToAdd); } else { // TODO proper response packet Parent.SendMessage("Please make space in your inventory."); return; } } // TODO // if ( aChangedItem.a && *(aChangedItem.a - 1) > 0u ) // CUser::PostQuestEffect(&v16->vfptr, 1, &aChangedItem, 0, 0); }
private void Handle_CashShopCheckCouponRequest(WvsShopClient c, CInPacket p) { p.Decode2(); // something var code = p.DecodeString(); var coupon = new CouponCode(code, c); if (coupon.Invalid) { c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.InvalidCoupon)); } else if (coupon.Used) { c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.UsedCoupon)); } else if (coupon.IncorrectAccount) { c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.NotAvailableCoupon)); } else if (coupon.Expired) { c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.ExpiredCoupon)); } else if (coupon.Items != null && !InventoryManipulator.HasSpace(c.Character, coupon.Items)) { c.SendPacket(CPacket.CCashShop.CouponFail(CashItemFailed.NoEmptyPos)); // TODO fix this } else { if (coupon.Items != null) { foreach (var item in coupon.Items) { InventoryManipulator.InsertInto(c.Character, MasterManager.CreateItem(item, false)); CPacket.CCashShop.CouponAddItem(item); } } c.Account.AccountData.NX_Prepaid += coupon.NX; coupon.Dispose(); c.Account.Save(); } c.EnableActions(); }
public QuestResultType TryExchange(int nIncMoney, QuestAct.ActItem[] aActItem) { if (nIncMoney == 0 && aActItem.Length <= 0) { return(QuestResultType.Success); } if (nIncMoney < 0 && Parent.Stats.nMoney < nIncMoney) { return(QuestResultType.Failed_Meso); } foreach (var item in aActItem) { if (item.Item.Count > 0) { if (!InventoryManipulator.HasSpace(Parent, item.Item.ItemID, (short)item.Item.Count)) { return(QuestResultType.Failed_Inventory); // -> Etc inventory is full } } else { if (!InventoryManipulator.ContainsItem(Parent, item.Item.ItemID, (short)item.Item.Count)) { return(QuestResultType.Failed_Unknown); // idk what code to give them } } } Parent.Modify.GainMeso(nIncMoney); var weight = 0; foreach (var item in aActItem) { if (item.ProbRate != 0) { weight += item.ProbRate; } } var itemGiven = false; foreach (var item in aActItem.Shuffle()) { if (item.Item.Count < 0) { InventoryManipulator.RemoveQuantity(Parent, item.Item.ItemID, (short)item.Item.Count); } else { if (item.ProbRate == 0) { var newItem = MasterManager.CreateItem(item.Item.ItemID, false); if (!newItem.IsEquip) { newItem.nNumber = (short)item.Item.Count; } InventoryManipulator.InsertInto(Parent, newItem); } else if (!itemGiven) { var rand = Constants.Rand.Next(0, weight); if (rand < item.ProbRate) { var newItem = MasterManager.CreateItem(item.Item.ItemID, false); if (!newItem.IsEquip) { newItem.nNumber = (short)item.Item.Count; } InventoryManipulator.InsertInto(Parent, newItem); itemGiven = true; } else { weight -= item.ProbRate; } } } } return(QuestResultType.Success); }
/// <summary> /// deprecated /// </summary> /// <param name="itemId"></param> /// <param name="amount"></param> /// <returns></returns> public bool CanHoldItem(int itemId, short amount = 1) => InventoryManipulator.HasSpace(Character, itemId, amount);
public bool HasSpace(int nItemID, short nAmount = 1) => InventoryManipulator.HasSpace(Character, nItemID, nAmount);