Пример #1
0
 public void RemoveItem(Database.Records.WorldItemRecord item, int quantity, bool removeFromDB = true)
 {
     if (_character != null)
     {
         if (_character.Player != null)
         {
             if (item.Quantity - quantity < 1)
             {
                 _character.Player.Send("OR" + item.ID);
                 item.Owner = -1;
                 item.SaveAndFlush();
                 if (removeFromDB)
                 {
                     item.DeleteAndFlush();
                 }
                 Items.Remove(item);
             }
             else
             {
                 item.Quantity -= quantity;
                 RefreshQuantity(item);
             }
             _character.Player.Action.RefreshPods();
         }
     }
 }
Пример #2
0
 public Database.Records.WorldItemRecord AddItem(Database.Records.WorldItemRecord item, bool newStack = false, int quantity = 1)
 {
     if (item.Position == -1)
     {
         try
         {
             dontHaveItem :;
             if (!HaveItemWithSameEffects(item.Effects, -1, item.Template) || newStack)
             {
                 item.Quantity = quantity;
                 item.SaveAndFlush();
                 Items.Add(item);
                 if (_character != null)
                 {
                     if (_character.Player != null)
                     {
                         _character.Player.Send("OAKO" + item.DisplayItem);
                         _character.Player.Action.RefreshPods();
                     }
                 }
                 return(item);
             }
             else
             {
                 Database.Records.WorldItemRecord existItem = GetItemWithSameEffects(item.Effects, item.Template);
                 if (existItem != null)
                 {
                     item.DeleteAndFlush();
                     existItem.Quantity += quantity;
                     RefreshQuantity(existItem);
                     return(existItem);
                 }
                 else
                 {
                     newStack = true;
                     goto dontHaveItem;
                 }
             }
         }
         catch (Exception e)
         {
             Utilities.ConsoleStyle.Error("Cant add item : " + e.ToString());
         }
         return(null);
     }
     else
     {
         if (_character != null)
         {
             if (_character.Player != null)
             {
                 _character.Player.Send("OAKO" + item.DisplayItem);
                 _character.Player.Action.RefreshPods();
             }
         }
         Items.Add(item);
         return(item);
     }
 }