Esempio n. 1
0
 public Inventory SearchInventoryContains(User user, Type itemType)
 {
     foreach (ConnectorObject conv in inputConveyors)
     {
         // If the connected input don't exist, destroy the connector
         if (WorldObjectManager.GetFromID(conv.Input.ObjectID) == null)
         {
             conv.CleanDestroy();
             break;
         }
         if (conv.Operating == false)
         {
             continue;
         }
         // If the owner of the input object is authorized to interract with the conv
         if (Utils.IsAuthorizedToInteract(conv, user))
         {
             // If the owner of the connector can interract with the output
             if (Utils.IsAuthorizedToInteract(conv.Input, conv.OwnerUser))
             {
                 foreach (var item in conv.InvInput.Stacks)
                 {
                     if (item.Quantity > 0)
                     {
                         if (item.Item.Type == itemType)
                         {
                             return(conv.InvInput);
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
        public InventoryCollection GetAllOutputInventory(User user, Type itemToPlace = null)
        {
            List <Inventory> invList = new List <Inventory>();

            foreach (ConnectorObject conv in outputConveyors)
            {
                // If the connected output don't exist, destroy the connector
                if (WorldObjectManager.GetFromID(conv.Output.ObjectID) == null)
                {
                    conv.CleanDestroy();
                    break;
                }
                if (conv.Operating == false)
                {
                    continue;
                }
                // If the owner of the input object is authorized to interract with the conv
                if (Utils.IsAuthorizedToInteract(conv, user))
                {
                    // If the owner of the connector can interract with the output
                    if (Utils.IsAuthorizedToInteract(conv.Output, conv.OwnerUser))
                    {
                        if (itemToPlace != null && conv.filter.CanAccept(itemToPlace) == false)
                        {
                            continue;
                        }
                        invList.Add(conv.InvOutput);
                    }
                }
            }
            return(new InventoryCollection(invList));
        }
Esempio n. 3
0
        public ConnectorObject GetFirstValidOutput(WorldObject inputObject, Type transportItemType)
        {
            // User is the owner of the input object (I.E hopper)
            User user = inputObject.OwnerUser;

            foreach (ConnectorObject conv in outputConveyors)
            {
                if (WorldObjectManager.GetFromID(conv.Output.ObjectID) == null)
                {
                    conv.CleanDestroy();
                    break;
                }
                if (conv.Operating == false)
                {
                    continue;
                }
                // If the owner of the input object is authorized to interract with the conv
                if (Utils.IsAuthorizedToInteract(conv, user))
                {
                    // If the owner of the connector can interract with the output
                    if (Utils.IsAuthorizedToInteract(conv.Output, conv.OwnerUser))
                    {
                        if (conv.filter.CanAccept(transportItemType) && Utils.VerifyInventoryPlace(conv.InvOutput, transportItemType))
                        {
                            return(conv);
                        }
                    }
                }
            }
            return(null);
        }
        public static string SellMessage(DateTime timestamp, SellAction a)
        {
            string     currency = WorldObjectManager.GetFromID(a.WorldObjectId).GetComponent <CreditComponent>().CurrencyName;
            TradeOffer offer    = (from TradeOffer o in WorldObjectManager.GetFromID(a.WorldObjectId).GetComponent <StoreComponent>().SellOffers()
                                   where o.Stack.Item.FriendlyName == a.ItemTypeName
                                   select o).FirstOrDefault();

            return($"Sell(timestamp={timestamp:u}, worldtime={a.TimeSeconds}, item={a.ItemTypeName}, price={offer.Price}, currency={currency}, user={a.Username})\n");
        }
Esempio n. 5
0
        public List <KeyValuePair <Type, int> > GetAllItemsInput(WorldObject objectAsk)
        {
            List <KeyValuePair <Type, int> > result = new List <KeyValuePair <Type, int> >();
            // User is the owner of the object that ask for the items
            User             user             = objectAsk.OwnerUser;
            List <Inventory> checkedInventory = new List <Inventory>();

            foreach (ConnectorObject conv in inputConveyors)
            {
                // If the connected input don't exist, destroy the connector
                if (WorldObjectManager.GetFromID(conv.Input.ObjectID) == null)
                {
                    conv.CleanDestroy();
                    break;
                }
                if (conv.Operating == false)
                {
                    continue;
                }
                // If the owner of the input object is authorized to interract with the conv
                if (Utils.IsAuthorizedToInteract(conv, user))
                {
                    // If the owner of the connector can interract with the output
                    if (Utils.IsAuthorizedToInteract(conv.Input, conv.OwnerUser))
                    {
                        if (conv.InvInput != null && checkedInventory.Contains(conv.InvInput) == false)
                        {
                            checkedInventory.Add(conv.InvInput);
                            foreach (var item in conv.InvInput.Stacks)
                            {
                                if (item.Quantity > 0)
                                {
                                    int qty = item.Quantity;
                                    int i   = 0;
                                    foreach (var kvp in result)
                                    {
                                        if (kvp.Key == item.Item.Type)
                                        {
                                            qty += kvp.Value;
                                            break;
                                        }
                                        i++;
                                    }
                                    if (qty != item.Quantity)
                                    {
                                        result.RemoveAt(i);
                                    }
                                    result.Add(new KeyValuePair <Type, int>(item.Item.Type, qty));
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 6
0
 private void update()
 {
     if (inputConveyors.Count > 0 && outputConveyors.Count > 0)
     {
         UpdateElectricityCost();
         foreach (ConnectorObject convIn in inputConveyors)
         {
             if (WorldObjectManager.GetFromID(convIn.Input.ObjectID) == null)
             {
                 convIn.CleanDestroy();
                 break;
             }
             if (convIn.Operating == false)
             {
                 continue;
             }
             PropertyAuthComponent convInAuth = convIn.Input.GetComponent <PropertyAuthComponent>();
             // If the owner of the connector input can interract with the stockpile
             if ((convIn.OwnerUser == null && convIn.Input.OwnerUser == null) || (convIn.OwnerUser != null && convIn.Input.AuthorizedToInteract(convIn.OwnerUser).Success))
             {
                 foreach (ConnectorObject convOut in outputConveyors)
                 {
                     if (WorldObjectManager.GetFromID(convOut.Output.ObjectID) == null)
                     {
                         convOut.CleanDestroy();
                         break;
                     }
                     if (convOut.Operating == false)
                     {
                         continue;
                     }
                     PropertyAuthComponent convOutAuth = convOut.Output.GetComponent <PropertyAuthComponent>();
                     // If the owner of the input can interract with the owner of the output
                     if ((convIn.OwnerUser == null && convOut.OwnerUser == null) || (convIn.OwnerUser != null && convOut.AuthorizedToInteract(convIn.OwnerUser).Success))
                     {
                         // If the owner of the connector output can interract with the stockpile
                         if ((convOut.OwnerUser == null && convOut.Output.OwnerUser == null) || (convOut.OwnerUser != null && convOut.Output.AuthorizedToInteract(convOut.OwnerUser).Success))
                         {
                             if (Utils.MoveItemFromToInventory(convIn.InvInput, convOut.InvOutput, 1, convIn.filter, convOut.filter))
                             {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
 }