Beispiel #1
0
        public static ItemBase newInstance(ItemBase a)
        {
            VicisMod.log(LOGGER_PREFIX, "Creating new instance of " + a.GetDisplayString());
            switch (a.mType)
            {
            case ItemType.ItemCubeStack:
                ItemCubeStack ics = a as ItemCubeStack;
                return(new ItemCubeStack(ics.mCubeType, ics.mCubeValue, ics.mnAmount));

            case ItemType.ItemStack:
                ItemStack its = a as ItemStack;
                return(new ItemStack(its.mnItemID, its.mnAmount));

            case ItemType.ItemCharge:
                ItemCharge ic = a as ItemCharge;
                return(new ItemCharge(ic.mnItemID, (int)ic.mChargeLevel));

            case ItemType.ItemDurability:
                ItemDurability id = a as ItemDurability;
                return(new ItemDurability(id.mnItemID, id.mnCurrentDurability, id.mnMaxDurability));

            case ItemType.ItemLocation:
                ItemLocation il = a as ItemLocation;
                return(new ItemLocation(il.mnItemID, il.mLocX, il.mLocY, il.mLocZ, il.mLookVector));

            case ItemType.ItemSingle:
                return(new ItemSingle(a.mnItemID));
            }
            return(null);
        }
Beispiel #2
0
        public static ItemBase newInstance(ItemBase a)
        {
            switch (a.mType)
            {
            case ItemType.ItemCubeStack:
                ItemCubeStack ics = a as ItemCubeStack;
                return(new ItemCubeStack(ics.mCubeType, ics.mCubeValue, ics.mnAmount));

            case ItemType.ItemStack:
                ItemStack its = a as ItemStack;
                return(new ItemStack(its.mnItemID, its.mnAmount));

            case ItemType.ItemCharge:
                ItemCharge ic = a as ItemCharge;
                return(new ItemCharge(ic.mnItemID, (int)ic.mChargeLevel));

            case ItemType.ItemDurability:
                ItemDurability id = a as ItemDurability;
                return(new ItemDurability(id.mnItemID, id.mnCurrentDurability, id.mnMaxDurability));

            case ItemType.ItemLocation:
                ItemLocation il = a as ItemLocation;
                return(new ItemLocation(il.mnItemID, il.mLocX, il.mLocY, il.mLocZ, il.mLookVector));

            case ItemType.ItemSingle:
                return(new ItemSingle(a.mnItemID));
            }
            return(null);
        }
Beispiel #3
0
 /// <summary>
 ///     Compares the ItemID, Type, CubeType, and CubeValue values of ItemCubeStack
 ///     Does not compare the Amounts
 /// </summary>
 /// <param name="original">Original Item</param>
 /// <param name="comparer">Item to Compare Against</param>
 /// <returns>True if ItemID, Type, CubeType, CubeValue of both Items match, otherwise false</returns>
 public static bool CompareCubes(this ItemCubeStack original, ItemCubeStack comparer)
 {
     // We'll ignore the original stacks for now. May revisit in the future
     return(original != null && comparer != null &&
            original.mCubeType == comparer.mCubeType && original.mCubeValue == comparer.mCubeValue);
     // && original.mnAmount == comparer.mnAmount;
 }
Beispiel #4
0
 public bool ProvideFreight(ItemBase item)
 {
     if (item.mType == ItemType.ItemCubeStack)
     {
         ItemCubeStack stack = (ItemCubeStack)item;
         return(Machine.TryExtractItemsOrCubes(Station, item.mnItemID, stack.mCubeType, stack.mCubeValue, item.GetAmount()));
     }
     else
     {
         return(Machine.TryExtractItems(null, item.mnItemID, item.GetAmount()));
     }
 }
Beispiel #5
0
 private int GetItemCountFromItemBase(ItemBase item)
 {
     if (item.mnItemID == -1)
     {
         ItemCubeStack cubes = item as ItemCubeStack;
         return(Machine.CountCubes(cubes.mCubeType, cubes.mCubeValue));
     }
     else
     {
         return(Machine.CountItems(item.mnItemID));
     }
 }
Beispiel #6
0
    // An item that we'll try taking, and a flag whether we should actually take it or not (we could just be checking if we have space)
    public bool AttemptGiveItem(ItemBase item, int amount = 1, bool actuallyTakeItem = true)
    {
        VicisMod.log(getPrefix(), "Attempting to receive " + amount + " item " + item.GetDisplayString() + " with id = " + item.mnItemID + " and type = " + item.mType);
        // Can we even take this item(s)?
        if (getNumItems() + amount > maxItems)
        {
            return(false);
        }
        for (int i = 0; i < items.Count; ++i)
        {
            if (ItemBaseUtil.compareCubeStack(items[i] as ItemCubeStack, item as ItemCubeStack))
            {
                ItemCubeStack a         = items[i] as ItemCubeStack;
                int           amntTaken = Math.Min(amount, a.mnAmount);
                if (a != null && a.mnAmount < maxBinSize)
                {
                    if (actuallyTakeItem)
                    {
                        a.mnAmount += amount;
                    }
                    MarkDirtyDelayed();
                    return(true);
                }
            }
            else if (ItemBaseUtil.compareStack(items[i] as ItemStack, item as ItemStack))
            {
                ItemStack a = items[i] as ItemStack;
                if (a != null && a.mnAmount < maxBinSize)
                {
                    if (actuallyTakeItem)
                    {
                        a.mnAmount += amount;
                    }
                    MarkDirtyDelayed();
                    return(true);
                }
            }
        }

        if (items.Count < maxBins)
        {
            if (actuallyTakeItem)
            {
                items.Add(item);
            }
            MarkDirtyDelayed();
            return(true);
        }

        VicisMod.log(getPrefix(), "Did not accept item " + item.GetDisplayString());
        return(false);
    }
Beispiel #7
0
 public bool GiveItem(SegmentEntity entity, ItemBase item)
 {
     if (GetFreeSpace(entity) == 1)
     {
         var conveyor = entity.As <ConveyorEntity>();
         if (item.mType == ItemType.ItemCubeStack)
         {
             ItemCubeStack cube = item as ItemCubeStack;
             conveyor.AddCube(cube.mCubeType, cube.mCubeValue, 1);
             return(true);
         }
         conveyor.AddItem(item);
         return(true);
     }
     return(false);
 }
        public Boolean HasItems(SegmentEntity entity, ItemBase item, out Int32 amount)
        {
            var hopper = entity.As <StorageHopper>();

            var           isCube = item.mType == ItemType.ItemCubeStack;
            ItemCubeStack cube   = null;

            if (isCube)
            {
                cube = item.As <ItemCubeStack>();
            }

            amount = !isCube?hopper.CountHowManyOfItem(item.mnItemID)
                         : hopper.CountHowManyOfType(cube.mCubeType, cube.mCubeValue);

            return(amount > 0);
        }
        public ItemBase TakeItem(SegmentEntity entity, ItemBase item)
        {
            var hopper = entity.As <StorageHopper>();

            var           isCube = item.mType == ItemType.ItemCubeStack;
            ItemCubeStack cube   = null;

            if (isCube)
            {
                cube = item.As <ItemCubeStack>();
            }

            if (!isCube)
            {
                return(hopper.RemoveSingleSpecificItemByID(item.mnItemID));
            }
            return(hopper.RemoveSingleSpecificCubeStack(cube));
        }
Beispiel #10
0
        public bool HasItem(SegmentEntity entity, ItemBase item)
        {
            if (GetFreeSpace(entity) == 1)
            {
                return(false);
            }
            var conveyor = entity.As <ConveyorEntity>();

            if (item.mType == ItemType.ItemCubeStack)
            {
                ItemCubeStack cube = item as ItemCubeStack;
                if (conveyor.mCarriedCube == cube.mCubeType && conveyor.mCarriedValue == cube.mCubeValue)
                {
                    return(true);
                }
                return(false);
            }
            return(item.CompareDeep(conveyor.mCarriedItem));
        }
Beispiel #11
0
 public static int getAmount(this ItemBase item)
 {
     if (item.mType == ItemType.ItemCubeStack)
     {
         ItemCubeStack a = item as ItemCubeStack;
         if (a != null)
         {
             return(a.mnAmount);
         }
     }
     else if (item.mType == ItemType.ItemStack)
     {
         ItemStack a = item as ItemStack;
         if (a != null)
         {
             return(a.mnAmount);
         }
     }
     return(1);
 }
    private static Color ItemColor(ItemBase itemBase)
    {
        Color lCol = Color.green;

        if (itemBase.mType == ItemType.ItemCubeStack)
        {
            ItemCubeStack itemCubeStack = itemBase as ItemCubeStack;
            if (CubeHelper.IsGarbage(itemCubeStack.mCubeType))
            {
                lCol = Color.red;
            }
            if (CubeHelper.IsSmeltableOre(itemCubeStack.mCubeType))
            {
                lCol = Color.green;
            }
        }
        if (itemBase.mType == ItemType.ItemStack)
        {
            lCol = Color.cyan;
        }
        if (itemBase.mType == ItemType.ItemSingle)
        {
            lCol = Color.white;
        }
        if (itemBase.mType == ItemType.ItemCharge)
        {
            lCol = Color.magenta;
        }
        if (itemBase.mType == ItemType.ItemDurability)
        {
            lCol = Color.yellow;
        }
        if (itemBase.mType == ItemType.ItemLocation)
        {
            lCol = Color.gray;
        }

        return(lCol);
    }
        public Boolean GiveItem(SegmentEntity entity, ItemBase item)
        {
            var hopper = entity.As <StorageHopper>();

            var           isCube = item.mType == ItemType.ItemCubeStack;
            ItemCubeStack cube   = null;

            if (isCube)
            {
                cube = item.As <ItemCubeStack>();
            }

            if (!isCube)
            {
                return(hopper.AddItem(item));
            }

            // Might be possible to replace with ^ as universal for Item/Cubes
            var currentStorage = hopper.mnStorageFree;

            hopper.AddCube(cube.mCubeType, cube.mCubeValue);
            return(currentStorage != hopper.mnStorageFree);
        }
Beispiel #14
0
 private void ItemWriter(ItemBase item, BinaryWriter writer)
 {
     if (item == null)
     {
         Debug.LogWarning("Freight Cart NetworkSync tried to write a null cart inventory item!");
         writer.Write(-2);
     }
     writer.Write(item.mnItemID);
     if (item.mnItemID == -1)
     {
         // Cube!
         ItemCubeStack cube = (item as ItemCubeStack);
         writer.Write(cube.mCubeType);
         writer.Write(cube.mCubeValue);
         writer.Write(cube.mnAmount);
     }
     else
     {
         if (item.mType == ItemType.ItemStack)
         {
             writer.Write((item as ItemStack).mnAmount);
         }
     }
 }
Beispiel #15
0
    protected virtual void dropOffToConveyors()
    {
        bool ignore;
        List <ConveyorEntity> list = VicisMod.checkSurrounding <ConveyorEntity>(this, out ignore);

        VicisMod.log(getPrefix(), "Found " + list.Count + " ConveyorEntities");
        string msg = items.Count + ": ";

        foreach (ItemBase it in items)
        {
            msg += it.GetDisplayString() + ", ";
        }
        VicisMod.log(getPrefix(), "Currently storing " + msg);
        for (int i = 0; i < list.Count && items.Count > 0; ++i)
        {
            ConveyorEntity c = list[i] as ConveyorEntity;
            if (!isConveyorNotFacingMe(c))
            {
                VicisMod.log(getPrefix(), "Conveyor is either not facing somewhere else: " + isConveyorNotFacingMe(c));
                continue;
            }
            if (c.mbReadyToConvey && c.mrLockTimer == 0f)
            {
                VicisMod.log(getPrefix(), "Ready to convey, will be giving " + items[0].GetDisplayString() + ", a " + items[0].mType);
                if (items[0].mType == ItemType.ItemCubeStack)
                {
                    ItemCubeStack a = items[0] as ItemCubeStack;
                    c.AddCube(a.mCubeType, a.mCubeValue, 1);
                    c.mItemForwards = forwards;
                    --a.mnAmount;
                    if (a.mnAmount == 0)
                    {
                        VicisMod.log(getPrefix(), "Removing cube " + a.GetDisplayString() + " from items list");
                        items.RemoveAt(0);
                    }
                }
                else if (items[0].mType == ItemType.ItemStack)
                {
                    ItemStack a = ItemBaseUtil.newInstance(items[0]) as ItemStack;
                    a.mnAmount = 1;
                    ItemBaseUtil.decrementStack(items[0], 1);
                    c.AddItem(a);
                    c.mItemForwards = forwards;
                    if (ItemBaseUtil.getAmount(items[0]) == 0)
                    {
                        VicisMod.log(getPrefix(), "Removing item " + a.GetDisplayString() + " from items list");
                        items.RemoveAt(0);
                    }
                }
                else
                {
                    c.AddItem(items[0]);
                    c.mrCarryTimer       = 1f;
                    c.mrVisualCarryTimer = 1f;
                    c.mItemForwards      = forwards;
                    items.RemoveAt(0);
                }
            }
            else
            {
                VicisMod.log(getPrefix(), "Conveyor is not ready to convey");
            }
        }
    }
    public static bool StoreItems(Player player, StorageHopper hopper, ItemBase itemToStore)
    {
        if (player == WorldScript.mLocalPlayer)
        {
            if (!WorldScript.mLocalPlayer.mInventory.RemoveItemByExample(itemToStore, true))
            {
                // player didn't have this item
                Debug.Log("Player " + player.mUserName + " doesnt have " + itemToStore);
                return(false);
            }
        }

        //stored first to reduce the gap - the VSU below could take several hundred MS due to logging.
        if (!hopper.AddItem(itemToStore))
        {
            Debug.LogWarning("Bad thing that used to be unhandled! Thread interaccess probably caused this to screw up!");

            if (player == WorldScript.mLocalPlayer)
            {
                WorldScript.mLocalPlayer.mInventory.AddItem(itemToStore);
                return(false);
            }
            else
            {
                //Give the NETWORK player their items back!
                player.mInventory.AddItem(itemToStore);                //This needs to be communicated to the player, NOT just added to the local version of the inventory
                return(false);
            }
        }

        if (player.mbIsLocalPlayer)
        {
            Color    lCol  = Color.green;
            ItemBase lItem = itemToStore;
            if (lItem.mType == ItemType.ItemCubeStack)
            {
                ItemCubeStack lCubeStack = lItem as ItemCubeStack;
                if (CubeHelper.IsGarbage(lCubeStack.mCubeType))
                {
                    lCol = Color.red;
                }
                if (CubeHelper.IsSmeltableOre(lCubeStack.mCubeType))
                {
                    lCol = Color.green;
                }
            }
            if (lItem.mType == ItemType.ItemStack)
            {
                //probably a crafted item of some sort; we could introspect further into bar types
                lCol = Color.cyan;
            }
            if (lItem.mType == ItemType.ItemSingle)
            {
                //Minecart
                lCol = Color.white;
            }
            if (lItem.mType == ItemType.ItemCharge)
            {
                //Drill head/Minecart
                lCol = Color.magenta;
            }
            if (lItem.mType == ItemType.ItemDurability)
            {
                //Drill head
                lCol = Color.yellow;
            }
            if (lItem.mType == ItemType.ItemLocation)
            {
                lCol = Color.gray;
            }


            FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1, hopper.mnZ, 0.75f, "Stored " + player.GetItemName(lItem), lCol, 1.5f);
        }

        player.mInventory.VerifySuitUpgrades();        //we may have just taken a suit upgrade OUT.

        if (!WorldScript.mbIsServer)
        {
            NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceStoreItems, null, itemToStore, hopper, 0);
        }

        return(true);
    }
    public static bool TakeItems(Player player, StorageHopper hopper)
    {
        if (hopper.mnStorageUsed > 0)
        {
//			ushort lCube, lValue;
//			lSelectedHopper.GetSpecificCube(eHopperRequestType.eAny, out lCube, out lValue);//this also reduces CubeStacks
//			if (lCube != eCubeTypes.NULL)
//			{
//				Debug.Log("Transferring "+ TerrainData.mEntries[lCube].Name +" from StorageHopper to player inventory");
//				WorldScript.mLocalPlayer.mInventory.CollectValue(lCube, lValue, 1);
//				WorldScript.mLocalPlayer.mInventory.VerifySuitUpgrades();//we may have just taken a suit upgrade OUT.
//				return;
//			}
            //only remove Items now
            //This is really ficking stupid, we should duplicate the item and ASK if it'll fit and THEN remove it. Please god someone change this.
            ItemBase lItem = hopper.RemoveFirstInventoryItem();
            if (lItem != null)
            {
                Debug.Log("RemovingFirstInventoryItem from StorageHopper for " + player.mUserName);


                //This has a potential issue where the server and client diverge

                //TODO: ensure it fits?
                if (!player.mInventory.AddItem(lItem))
                {
                    //Do we know why it didn't fit?

                    //Doesn't fit, put it back in
                    if (!hopper.AddItem(lItem))                    //oh dear god threading
                    {
                        //THROW IT TO THE GROUND
                        ItemManager.instance.DropItem(lItem, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero);
                    }
                    return(false);
                }
                else
                {
                    if (player.mbIsLocalPlayer == true)
                    {
                        //if we know what sort of item it was, colour the text!

                        Color lCol = Color.green;
                        if (lItem.mType == ItemType.ItemCubeStack)
                        {
                            ItemCubeStack lCubeStack = lItem as ItemCubeStack;
                            if (CubeHelper.IsGarbage(lCubeStack.mCubeType))
                            {
                                lCol = Color.red;
                            }
                            if (CubeHelper.IsSmeltableOre(lCubeStack.mCubeType))
                            {
                                lCol = Color.green;
                            }
                        }
                        if (lItem.mType == ItemType.ItemStack)
                        {
                            //probably a crafted item of some sort; we could introspect further into bar types
                            lCol = Color.cyan;
                        }
                        if (lItem.mType == ItemType.ItemSingle)
                        {
                            //Minecart
                            lCol = Color.white;
                        }
                        if (lItem.mType == ItemType.ItemCharge)
                        {
                            //Drill head/Minecart
                            lCol = Color.magenta;
                        }
                        if (lItem.mType == ItemType.ItemDurability)
                        {
                            //Drill head
                            lCol = Color.yellow;
                        }
                        if (lItem.mType == ItemType.ItemLocation)
                        {
                            lCol = Color.gray;
                        }

                        FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1, hopper.mnZ, 1.0f, player.GetItemName(lItem), lCol, 1.5f);
                    }
                }
                player.mInventory.VerifySuitUpgrades();     //we may have just taken a suit upgrade OUT.

                if (!WorldScript.mbIsServer)                //Tell the server we took the items
                {
                    NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceTakeItems, null, lItem, hopper, 0);
                }

                return(true);
            }
        }
        return(false);
    }
Beispiel #18
0
 public static bool compareCubeStack(this ItemCubeStack a, ItemCubeStack b)
 {
     // We'll ignore the item stacks for now. May revisit in the future
     return(a != null && b != null && compareBase(a, b) && a.mCubeType == b.mCubeType && a.mCubeValue == b.mCubeValue);// && a.mnAmount == b.mnAmount;
 }
Beispiel #19
0
 public void HandleItemDrag(string name, ItemBase draggedItem, DragAndDropManager.DragRemoveItem dragDelegate)
 {
     //Debug.Log("Handle Item Drag: " + ItemManager.GetItemName(draggedItem));
     if (this.SuitInventory.ValidItems.Contains(draggedItem.mnItemID))
     {
         if (name.StartsWith("Suit_Slot"))
         {
             int      num    = int.Parse(name.Substring("Suit_Slot".Length, name.Length - "Suit_Slot".Length - "_Collider".Length)) - 1;
             int      num2   = num % 10;
             int      num3   = num / 10;
             ItemBase itemAt = this.SuitInventory.GetItemAt(num2, num3);
             if (this.dragSourceX >= 0 && this.dragSourceY >= 0 && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
             {
                 bool flag             = true;
                 int  currentStackSize = ItemManager.GetCurrentStackSize(draggedItem);
                 if (currentStackSize < 2)
                 {
                     flag = false;
                 }
                 if (itemAt != null)
                 {
                     if (itemAt.mnItemID != draggedItem.mnItemID)
                     {
                         flag = false;
                     }
                     else if (itemAt.mType == ItemType.ItemCubeStack)
                     {
                         ItemCubeStack itemCubeStack  = itemAt as ItemCubeStack;
                         ItemCubeStack itemCubeStack2 = draggedItem as ItemCubeStack;
                         if (itemCubeStack.mCubeType != itemCubeStack2.mCubeType || itemCubeStack.mCubeValue != itemCubeStack2.mCubeValue)
                         {
                             flag = false;
                         }
                     }
                 }
                 if (flag)
                 {
                     UIManager.instance.mSplitPanel.Show(draggedItem, this.dragSourceX, this.dragSourceY, itemAt, num2, num3);
                     this.SuitInventory.MarkDirtyDelayed(5);
                     return;
                 }
             }
             if (itemAt != null)
             {
                 if (draggedItem.mType == ItemType.ItemCubeStack && itemAt.mType == ItemType.ItemCubeStack)
                 {
                     ItemCubeStack itemCubeStack3 = draggedItem as ItemCubeStack;
                     ItemCubeStack itemCubeStack4 = itemAt as ItemCubeStack;
                     if (itemCubeStack3.mCubeType == itemCubeStack4.mCubeType && itemCubeStack3.mCubeValue == itemCubeStack4.mCubeValue)
                     {
                         int maxStackSize = global::TerrainData.GetMaxStackSize(itemCubeStack4.mCubeType);
                         if (maxStackSize != 100)
                         {
                             if (itemCubeStack3.mnAmount + itemCubeStack4.mnAmount > maxStackSize)
                             {
                                 int num4 = maxStackSize - itemCubeStack4.mnAmount;
                                 itemCubeStack3.mnAmount -= num4;
                                 itemCubeStack4.mnAmount += num4;
                                 this.SuitInventory.MarkDirty();
                                 this.dirty = true;
                                 return;
                             }
                         }
                         if (dragDelegate(draggedItem, null))
                         {
                             itemCubeStack4.mnAmount += itemCubeStack3.mnAmount;
                             this.SuitInventory.MarkDirty();
                             this.dirty = true;
                             return;
                         }
                         return;
                     }
                 }
                 if (draggedItem.mType == ItemType.ItemStack && itemAt.mnItemID == draggedItem.mnItemID)
                 {
                     ItemStack itemStack  = draggedItem as ItemStack;
                     ItemStack itemStack2 = itemAt as ItemStack;
                     if (dragDelegate(draggedItem, null))
                     {
                         itemStack2.mnAmount += itemStack.mnAmount;
                         this.SuitInventory.MarkEverythingDirty();
                         this.dirty = true;
                         return;
                     }
                     return;
                 }
             }
             if (dragDelegate(draggedItem, itemAt))
             {
                 if (itemAt != null)
                 {
                     this.SuitInventory.RemoveItemAt(num2, num3);
                 }
                 this.SuitInventory.AddItemAt(num2, num3, draggedItem);
                 this.SuitInventory.MarkEverythingDirty();
                 this.dirty = true;
             }
             return;
         }
     }
 }
        private void CubeAdd(string parameters)
        {
            string text = parameters;

            parameters = parameters.ToLowerInvariant();
            string playername = parameters;

            string[] commandPars = null;
            if (parameters.Contains(" "))
            {
                int num = parameters.IndexOf(' ');
                playername  = parameters.Substring(0, num);
                commandPars = parameters.Substring(parameters.IndexOf(' ') + 1, parameters.Length - num - 1).Split(' ');
            }
            else
            {
                //Dump out here, need more params
                global::Console.LogTargetFunction("cubeadd playername cubeid amount [metavalue]", ConsoleMessageType.Trace);
                return;
            }
            if (commandPars.Length < 2)
            {
                //Dump out here, need more params
                global::Console.LogTargetFunction("cubeadd playername cubeid amount [metavalue]", ConsoleMessageType.Trace);
                return;
            }

            int id      = Convert.ToInt32(commandPars[0]);
            int ammount = Convert.ToInt32(commandPars[1]);

            bool cube = false;

            ItemBase itemStack = null;

            ushort cubeid    = Convert.ToUInt16(id);
            ushort cubeValue = TerrainData.GetDefaultValue(cubeid);

            if (commandPars.Length > 2)
            {
                cubeValue = Convert.ToUInt16(commandPars[2]);
            }
            itemStack = new ItemCubeStack(cubeid, cubeValue, ammount);

            if (itemStack != null)
            {
                cube = true;
            }

            if (cube)
            {
                int count = NetworkManager.instance.mServerThread.connections.Count;
                for (int i = 0; i < count; i++)
                {
                    NetworkServerConnection networkServerConnection = NetworkManager.instance.mServerThread.connections[i];
                    if (networkServerConnection.mState == eNetworkConnectionState.Playing)
                    {
                        if (networkServerConnection.mPlayer.mUserName.ToLower() == playername.ToLower())
                        {
                            if (networkServerConnection.mPlayer.mInventory.CanFit(itemStack))
                            {
                                networkServerConnection.mPlayer.mInventory.AddItem(itemStack);
                                if (itemStack.mType == ItemType.ItemCubeStack)
                                {
                                    var itemCubeStack = itemStack as ItemCubeStack;
                                    global::Console.LogTargetFunction("Gave " + itemCubeStack.mnAmount + " of " + TerrainData.GetNameForValue(itemCubeStack.mCubeType, itemCubeStack.mCubeValue) + " to " + playername, ConsoleMessageType.Trace);
                                }
                                return;
                            }
                            else
                            {
                                global::Console.LogTargetFunction("Inventory full", ConsoleMessageType.Trace);
                                return;
                            }
                        }
                    }
                }
                global::Console.LogTargetFunction("Player Not Found", ConsoleMessageType.Trace);
                return;
            }
            else
            {
                global::Console.LogTargetFunction("Cube Not Found", ConsoleMessageType.Trace);
                return;
            }
        }
Beispiel #21
0
    // An item that we're going to give, or check that we can give
    public ItemBase AttemptTakeItem(ItemBase item, int amount = 1, bool actuallyGiveItem = true)
    {
        VicisMod.log(getPrefix(), "Attempting to give " + amount + " item " + item.GetDisplayString() + " with id = " + item.mnItemID + " and type = " + item.mType);
        if (getNumItems() == 0)
        {
            return(null);
        }
        for (int i = 0; i < items.Count; ++i)
        {
            if (ItemBaseUtil.compareCubeStack(items[i] as ItemCubeStack, item as ItemCubeStack))
            {
                ItemCubeStack a = items[i] as ItemCubeStack;
                VicisMod.log(getPrefix(), "Found a CubeStack " + a.GetDisplayString() + ", which is storing " + a.mnAmount + " blocks");
                if (a != null)
                {
                    int           amntTaken = Math.Min(amount, a.mnAmount);
                    ItemCubeStack ret       = new ItemCubeStack(a.mCubeType, a.mCubeValue, amntTaken);
                    if (actuallyGiveItem)
                    {
                        VicisMod.log(getPrefix(), "Taking away");
                        a.mnAmount -= amntTaken;
                        if (a.mnAmount <= 0)
                        {
                            VicisMod.log(getPrefix(), "There are " + a.mnAmount + " items for " + a.GetDisplayString() + ", removing it from items");
                            items.RemoveAt(i);
                        }
                    }
                    MarkDirtyDelayed();
                    return(ret);
                }
                // a was null, this is bad. Clean up, hide the evidence
                VicisMod.log(getPrefix(), "Removing a null that masquaraded as an ItemCubeStack!");
                items.RemoveAt(i);
                return(null);
            }
            else if (ItemBaseUtil.compareStack(items[i] as ItemStack, item as ItemStack))
            {
                ItemStack a = items[i] as ItemStack;
                VicisMod.log(getPrefix(), "Found a Stack " + a.GetDisplayString() + ", which is storing " + a.mnAmount + " blocks");
                if (a != null)
                {
                    int       amntTaken = Math.Min(amount, a.mnAmount);
                    ItemStack ret       = new ItemStack(a.mnItemID, amntTaken);
                    if (actuallyGiveItem)
                    {
                        VicisMod.log(getPrefix(), "Taking away");
                        a.mnAmount -= amntTaken;
                        if (a.mnAmount <= 0)
                        {
                            VicisMod.log(getPrefix(), "There are " + a.mnAmount + " items for " + a.GetDisplayString() + ", removing it from items");
                            items.RemoveAt(i);
                        }
                    }
                    MarkDirtyDelayed();
                    return(ret);
                }
                // a was null, this is bad. Clean up, hide the evidence
                VicisMod.log(getPrefix(), "Removing a null that masquaraded as an ItemStack!");
                items.RemoveAt(i);
                return(null);
            }
        }

        if (ItemBaseUtil.isStack(item))
        {
            VicisMod.log(getPrefix(), "Could not find a stack or cube stack for " + item.GetDisplayString() + ", returning null");
            return(null);
        }

        // What we're looking for is not a stack, start looking at the individual items.
        for (int i = 0; i < items.Count; ++i)
        {
            if (ItemBaseUtil.compareBase(items[i], item))
            {
                ItemBase ret = items[i];
                VicisMod.log(getPrefix(), "Found a " + ret.GetDisplayString() + ", with id = " + ret.mnItemID + " and type = " + ret.mType);
                if (actuallyGiveItem)
                {
                    VicisMod.log(getPrefix(), "Removing from items");
                    items.RemoveAt(i);
                }
                MarkDirtyDelayed();
                return(ret);
            }
        }
        return(null);
    }
 public static bool TakeItems(Player player, ExtraStorageHoppers_OT hopper)
 {
     if (hopper.mnStorageUsed > 0)
     {
         ItemBase lItemToAdd = hopper.RemoveFirstInventoryItem();
         if (lItemToAdd != null)
         {
             Debug.Log("RemovingFirstInventoryItem from for " + player.mUserName);
             if (!player.mInventory.AddItem(lItemToAdd))
             {
                 if (!hopper.AddItem(lItemToAdd))
                 {
                     ItemManager.instance.DropItem(lItemToAdd, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero);
                 }
                 return(false);
             }
             if (player.mbIsLocalPlayer)
             {
                 Color green = Color.green;
                 if (lItemToAdd.mType == ItemType.ItemCubeStack)
                 {
                     ItemCubeStack stack = lItemToAdd as ItemCubeStack;
                     if (CubeHelper.IsGarbage(stack.mCubeType))
                     {
                         green = Color.red;
                     }
                     if (CubeHelper.IsSmeltableOre(stack.mCubeType))
                     {
                         green = Color.green;
                     }
                 }
                 if (lItemToAdd.mType == ItemType.ItemStack)
                 {
                     green = Color.cyan;
                 }
                 if (lItemToAdd.mType == ItemType.ItemSingle)
                 {
                     green = Color.white;
                 }
                 if (lItemToAdd.mType == ItemType.ItemCharge)
                 {
                     green = Color.magenta;
                 }
                 if (lItemToAdd.mType == ItemType.ItemDurability)
                 {
                     green = Color.yellow;
                 }
                 if (lItemToAdd.mType == ItemType.ItemLocation)
                 {
                     green = Color.gray;
                 }
                 FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 1f, player.GetItemName(lItemToAdd), green, 1.5f);
             }
             player.mInventory.VerifySuitUpgrades();
             if (!WorldScript.mbIsServer)
             {
                 NetworkManager.instance.SendInterfaceCommand("ExtraStorageHopperWindow_OT", "TakeItems", null, lItemToAdd, hopper, 0f);
             }
             return(true);
         }
     }
     return(false);
 }
 public static bool TakeItems(Player player, ExtraStorageHoppers hopper, ItemBase item)
 {
     //ENABLE/DISABLE FEEDING OF HIVEBIND - ONLY FOR VOID HOPPER
     if (hopper.GetCubeValue() == 0)
     {
         if (hopper.FeedHiveMind)
         {
             hopper.FeedHiveMind = false;
             FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 1f, "Not Feeding Hivemind!", Color.green, 2f);
         }
         else
         {
             hopper.FeedHiveMind = true;
             FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 1f, "Feeding Hivemind!", Color.red, 2f);
         }
         return(true);
     }
     else if (hopper.mnStorageUsed > 0)
     {
         ItemBase itemBase;
         if (item == null)
         {
             itemBase = hopper.RemoveFirstInventoryItem();
         }
         else if (item.mType == ItemType.ItemCubeStack)
         {
             hopper.TryPartialExtractItemsOrCubes(null, item.mnItemID, (item as ItemCubeStack).mCubeType, (item as ItemCubeStack).mCubeValue, ItemManager.GetCurrentStackSize(item), out itemBase);
         }
         else
         {
             hopper.TryPartialExtractItems(null, item.mnItemID, ItemManager.GetCurrentStackSize(item), out itemBase);
         }
         if (itemBase != null)
         {
             Debug.Log("Removing Item from StorageHopper for " + player.mUserName);
             if (!player.mInventory.AddItem(itemBase))
             {
                 if (!hopper.AddItem(itemBase))
                 {
                     ItemManager.instance.DropItem(itemBase, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero);
                 }
                 return(false);
             }
             if (player.mbIsLocalPlayer)
             {
                 Color lCol = Color.green;
                 if (itemBase.mType == ItemType.ItemCubeStack)
                 {
                     ItemCubeStack itemCubeStack = itemBase as ItemCubeStack;
                     if (CubeHelper.IsGarbage(itemCubeStack.mCubeType))
                     {
                         lCol = Color.red;
                     }
                     if (CubeHelper.IsSmeltableOre(itemCubeStack.mCubeType))
                     {
                         lCol = Color.green;
                     }
                 }
                 if (itemBase.mType == ItemType.ItemStack)
                 {
                     lCol = Color.cyan;
                 }
                 if (itemBase.mType == ItemType.ItemSingle)
                 {
                     lCol = Color.white;
                 }
                 if (itemBase.mType == ItemType.ItemCharge)
                 {
                     lCol = Color.magenta;
                 }
                 if (itemBase.mType == ItemType.ItemDurability)
                 {
                     lCol = Color.yellow;
                 }
                 if (itemBase.mType == ItemType.ItemLocation)
                 {
                     lCol = Color.gray;
                 }
                 FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 1f, player.GetItemName(itemBase), lCol, 1.5f, 64f);
             }
             player.mInventory.VerifySuitUpgrades();
             if (!WorldScript.mbIsServer)
             {
                 NetworkManager.instance.SendInterfaceCommand("ExtraStorageHopperWindowNew", "TakeItems", null, itemBase, hopper, 0f);
             }
             return(true);
         }
     }
     return(false);
 }
 public static bool StoreItems(Player player, ExtraStorageHoppers hopper, ItemBase itemToStore)
 {
     if ((player == WorldScript.mLocalPlayer) && !WorldScript.mLocalPlayer.mInventory.RemoveItemByExample(itemToStore, true))
     {
         Debug.Log(string.Concat(new object[] { "Player ", player.mUserName, " doesnt have ", player.GetItemName(itemToStore) }));
         return(false);
     }
     if (!hopper.AddItem(itemToStore))
     {
         Debug.LogWarning("Bad thing that used to be unhandled! Thread interaccess probably caused this to screw up!");
         if (player == WorldScript.mLocalPlayer)
         {
             WorldScript.mLocalPlayer.mInventory.AddItem(itemToStore);
             return(false);
         }
         player.mInventory.AddItem(itemToStore);
         return(false);
     }
     if (player.mbIsLocalPlayer)
     {
         Color    green = Color.green;
         ItemBase lItem = itemToStore;
         if (lItem.mType == ItemType.ItemCubeStack)
         {
             ItemCubeStack stack = lItem as ItemCubeStack;
             if (CubeHelper.IsGarbage(stack.mCubeType))
             {
                 green = Color.red;
             }
             if (CubeHelper.IsSmeltableOre(stack.mCubeType))
             {
                 green = Color.green;
             }
         }
         if (lItem.mType == ItemType.ItemStack)
         {
             green = Color.cyan;
         }
         if (lItem.mType == ItemType.ItemSingle)
         {
             green = Color.white;
         }
         if (lItem.mType == ItemType.ItemCharge)
         {
             green = Color.magenta;
         }
         if (lItem.mType == ItemType.ItemDurability)
         {
             green = Color.yellow;
         }
         if (lItem.mType == ItemType.ItemLocation)
         {
             green = Color.gray;
         }
         if (hopper.GetCubeValue() == 0)
         {
             green = Color.red;
             FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 0.75f, "Sent " + player.GetItemName(lItem) + " to the void!", green, 1.5f);
         }
         else
         {
             FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 0.75f, "Stored " + player.GetItemName(lItem), green, 1.5f);
         }
     }
     player.mInventory.VerifySuitUpgrades();
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand("ExtraStorageHopperWindow", "StoreItems", null, itemToStore, hopper, 0f);
     }
     return(true);
 }
 public static bool TakeItems(Player player, ExtraStorageHoppers hopper)
 {
     //ENABLE/DISABLE FEEDING OF HIVEBIND - ONLY FOR VOID HOPPER
     if (hopper.GetCubeValue() == 0)
     {
         if (hopper.FeedHiveMind)
         {
             hopper.FeedHiveMind = false;
             FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 1f, "Not Feeding Hivemind!", Color.green, 2f);
         }
         else
         {
             hopper.FeedHiveMind = true;
             FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 1f, "Feeding Hivemind!", Color.red, 2f);
         }
         return(true);
     }
     //******************** TAKE ITEMS FROM HOPPER AND ADD THEM TO INVENTORY ********************
     if (hopper.mnStorageUsed > 0)
     {
         ItemBase lItemToAdd = hopper.RemoveFirstInventoryItem();
         if (lItemToAdd != null)
         {
             Debug.Log("RemovingFirstInventoryItem from for " + player.mUserName);
             if (!player.mInventory.AddItem(lItemToAdd))
             {
                 if (!hopper.AddItem(lItemToAdd))
                 {
                     ItemManager.instance.DropItem(lItemToAdd, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero);
                 }
                 return(false);
             }
             if (player.mbIsLocalPlayer)
             {
                 Color green = Color.green;
                 if (lItemToAdd.mType == ItemType.ItemCubeStack)
                 {
                     ItemCubeStack stack = lItemToAdd as ItemCubeStack;
                     if (CubeHelper.IsGarbage(stack.mCubeType))
                     {
                         green = Color.red;
                     }
                     if (CubeHelper.IsSmeltableOre(stack.mCubeType))
                     {
                         green = Color.green;
                     }
                 }
                 if (lItemToAdd.mType == ItemType.ItemStack)
                 {
                     green = Color.cyan;
                 }
                 if (lItemToAdd.mType == ItemType.ItemSingle)
                 {
                     green = Color.white;
                 }
                 if (lItemToAdd.mType == ItemType.ItemCharge)
                 {
                     green = Color.magenta;
                 }
                 if (lItemToAdd.mType == ItemType.ItemDurability)
                 {
                     green = Color.yellow;
                 }
                 if (lItemToAdd.mType == ItemType.ItemLocation)
                 {
                     green = Color.gray;
                 }
                 FloatingCombatTextManager.instance.QueueText(hopper.mnX, hopper.mnY + 1L, hopper.mnZ, 1f, player.GetItemName(lItemToAdd), green, 1.5f);
             }
             player.mInventory.VerifySuitUpgrades();
             if (!WorldScript.mbIsServer)
             {
                 NetworkManager.instance.SendInterfaceCommand("ExtraStorageHopperWindow", "TakeItems", null, lItemToAdd, hopper, 0f);
             }
             return(true);
         }
     }
     return(false);
 }