/// <summary> /// f_repos packet /// </summary> /// <param name="fReposPacket"></param> public void FamilyRepos(FReposPacket fReposPacket) { if (Session.Character.Family == null || !(Session.Character.FamilyCharacter.Authority == FamilyAuthority.Head || Session.Character.FamilyCharacter.Authority == FamilyAuthority.Assistant || Session.Character.FamilyCharacter.Authority == FamilyAuthority.Member && Session.Character.Family.MemberAuthorityType == FamilyAuthorityType.ALL || Session.Character.FamilyCharacter.Authority == FamilyAuthority.Manager && Session.Character.Family.ManagerAuthorityType == FamilyAuthorityType.ALL)) { Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NO_FAMILY_RIGHT"))); return; } // check if the character is allowed to move the item if (Session.Character.InExchangeOrTrade || fReposPacket.Amount <= 0) { return; } if (fReposPacket.NewSlot > Session.Character.Family.WarehouseSize) { return; } ItemInstance sourceInventory = Session.Character.Family.Warehouse.LoadBySlotAndType(fReposPacket.OldSlot, InventoryType.FamilyWareHouse); ItemInstance destinationInventory = Session.Character.Family.Warehouse.LoadBySlotAndType(fReposPacket.NewSlot, InventoryType.FamilyWareHouse); if (sourceInventory != null && fReposPacket.Amount <= sourceInventory.Amount) { if (destinationInventory == null) { destinationInventory = sourceInventory.DeepCopy(); sourceInventory.Amount -= fReposPacket.Amount; destinationInventory.Amount = fReposPacket.Amount; destinationInventory.Slot = fReposPacket.NewSlot; if (sourceInventory.Amount > 0) { destinationInventory.Id = Guid.NewGuid(); } else { sourceInventory = null; } } else { if (destinationInventory.ItemVNum == sourceInventory.ItemVNum && (byte)sourceInventory.Item.Type != 0) { if (destinationInventory.Amount + fReposPacket.Amount > 99) { int saveItemCount = destinationInventory.Amount; destinationInventory.Amount = 99; sourceInventory.Amount = (byte)(saveItemCount + sourceInventory.Amount - 99); } else { destinationInventory.Amount += fReposPacket.Amount; sourceInventory.Amount -= fReposPacket.Amount; if (sourceInventory.Amount == 0) { DAOFactory.IteminstanceDAO.Delete(sourceInventory.Id); sourceInventory = null; } } } else { destinationInventory.Slot = fReposPacket.OldSlot; sourceInventory.Slot = fReposPacket.NewSlot; } } } if (sourceInventory != null && sourceInventory.Amount > 0) { DAOFactory.IteminstanceDAO.InsertOrUpdate(sourceInventory); } if (destinationInventory != null && destinationInventory.Amount > 0) { DAOFactory.IteminstanceDAO.InsertOrUpdate(destinationInventory); } Session.SendPacket((destinationInventory != null) ? destinationInventory.GenerateFStash() : UserInterfaceHelper.Instance.GenerateFStashRemove(fReposPacket.NewSlot)); Session.SendPacket((sourceInventory != null) ? sourceInventory.GenerateFStash() : UserInterfaceHelper.Instance.GenerateFStashRemove(fReposPacket.OldSlot)); ServerManager.Instance.FamilyRefresh(Session.Character.Family.FamilyId); }
private void ExecuteHandler(ClientSession session) { if (session.Character.Family == null || !(session.Character.FamilyCharacter.Authority == FamilyAuthority.Head || session.Character.FamilyCharacter.Authority == FamilyAuthority.Assistant || (session.Character.FamilyCharacter.Authority == FamilyAuthority.Member && session.Character.Family.MemberAuthorityType == FamilyAuthorityType.All) || (session.Character.FamilyCharacter.Authority == FamilyAuthority.Manager && session.Character.Family.ManagerAuthorityType == FamilyAuthorityType.All))) { session.SendPacket( UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("NO_FAMILY_RIGHT"))); return; } // check if the character is allowed to move the item if (session.Character.InExchangeOrTrade || Amount <= 0) { return; } if (NewSlot > session.Character.Family.WarehouseSize) { return; } ItemInstance sourceInventory = session.Character.Family.Warehouse.LoadBySlotAndType(OldSlot, InventoryType.FamilyWareHouse); ItemInstance destinationInventory = session.Character.Family.Warehouse.LoadBySlotAndType(NewSlot, InventoryType.FamilyWareHouse); if (sourceInventory != null && Amount <= sourceInventory.Amount) { if (destinationInventory == null) { destinationInventory = sourceInventory.DeepCopy(); sourceInventory.Amount -= Amount; destinationInventory.Amount = Amount; destinationInventory.Slot = NewSlot; if (sourceInventory.Amount > 0) { destinationInventory.Id = Guid.NewGuid(); } else { sourceInventory = null; } } else if (destinationInventory.ItemVNum == sourceInventory.ItemVNum && (byte)sourceInventory.Item.Type != 0) { if (destinationInventory.Amount + Amount > 255) { int saveItemCount = destinationInventory.Amount; destinationInventory.Amount = 255; sourceInventory.Amount = (byte)(saveItemCount + sourceInventory.Amount - 255); } else { destinationInventory.Amount += Amount; sourceInventory.Amount -= Amount; if (sourceInventory.Amount == 0) { DAOFactory.ItemInstanceDAO.Delete(sourceInventory.Id); sourceInventory = null; } } } else { destinationInventory.Slot = OldSlot; sourceInventory.Slot = NewSlot; } } if (sourceInventory?.Amount > 0) { DAOFactory.ItemInstanceDAO.InsertOrUpdate(sourceInventory); } if (destinationInventory?.Amount > 0) { DAOFactory.ItemInstanceDAO.InsertOrUpdate(destinationInventory); } session.SendPacket((destinationInventory != null) ? destinationInventory.GenerateFStash() : UserInterfaceHelper.Instance.GenerateFStashRemove(NewSlot)); session.SendPacket((sourceInventory != null) ? sourceInventory.GenerateFStash() : UserInterfaceHelper.Instance.GenerateFStashRemove(OldSlot)); ServerManager.Instance.FamilyRefresh(session.Character.Family.FamilyId); }