예제 #1
0
        public static bool TakeItem(Player player, QuantumStorageControllerMachine quantumStorageController,
                                    ItemBase itemBase)
        {
            var itemBaseCopy = itemBase.NewInstance();
            var amount       = itemBase.GetAmount();

            quantumStorageController.TakeItem(ref itemBase);

            itemBase.SetAmount(amount - itemBase.GetAmount());

            if (!player.mInventory.AddItem(itemBase))
            {
                quantumStorageController.AddItem(ref itemBase);
                if (itemBase.GetAmount() > 0)
                {
                    ItemManager.instance.DropItem(itemBase,
                                                  WorldScript.mLocalPlayer.mnWorldX, WorldScript.mLocalPlayer.mnWorldY,
                                                  WorldScript.mLocalPlayer.mnWorldZ,
                                                  Vector3.zero);
                }

                return(false);
            }

            quantumStorageController.Dirty = true;

            if (!WorldScript.mbIsServer)
            {
                NetworkManager.instance.SendInterfaceCommand(QuantumStorageMod.QuantumIoPortWindowKey,
                                                             "TakeItem",
                                                             null, itemBaseCopy, quantumStorageController, 0.0f);
            }

            return(true);
        }
예제 #2
0
    bool HopperIterator(ItemBase item, object offers)
    {
        List <FreightListing> offerslist = (List <FreightListing>)offers;

        if (offerslist == null)
        {
            return(false);
        }

        bool matchfound = false;

        foreach (FreightListing entry in offers as List <FreightListing> )
        {
            if (entry.Equals(item))
            {
                entry.Quantity += item.GetAmount();
                matchfound      = true;
                break;
            }
        }
        if (!matchfound)
        {
            (offers as List <FreightListing>).Add(new FreightListing(item, item.GetAmount()));
        }

        return(true);
    }
예제 #3
0
        public static ItemBase RemoveListItem(ItemBase item, ref List <ItemBase> sourcelist)
        {
            if (item == null)
            {
                return((ItemBase)null);
            }

            List <ItemBase> list = sourcelist.ToList <ItemBase>();

            if (item.IsStack())
            {
                int amount1 = item.GetAmount();
                for (int index = 0; index < list.Count; index++)
                {
                    ItemBase original = list[index];
                    int      amount2  = original.GetAmount();
                    if (original.Compare(item) && amount2 > amount1)
                    {
                        original.DecrementStack(amount1);
                        sourcelist = list;
                        item.SetAmount(0);
                        return(item.NewInstance());
                    }
                    else if (original.Compare(item) && amount2 == amount1)
                    {
                        list.Remove(original);
                        sourcelist = list;
                        item.SetAmount(0);
                        return(item.NewInstance());
                    }
                    else if (original.Compare(item))
                    {
                        item.SetAmount(item.GetAmount() - original.GetAmount());
                        list.Remove(original);
                        sourcelist = list;
                        return(item.NewInstance());
                    }
                }
            }
            else
            {
                for (int index = 0; index < list.Count; index++)
                {
                    ItemBase original = list[index];
                    if (original.Compare(item))
                    {
                        list.Remove(original);
                        sourcelist = list;
                        return(original);
                    }
                }
            }

            sourcelist = list;
            return((ItemBase)null);
        }
 public override void OnDelete()
 {
     if (WorldScript.mbIsServer)
     {
         if (mStoredLenses != null)
         {
             if (mStoredLenses.GetAmount() > 0)
             {
                 ItemManager.instance.DropItem(mStoredLenses, mnX, mnY, mnZ, Vector3.zero);
             }
         }
     }
 }
예제 #5
0
        public static void StoreItem(Player player, QuantumStorageControllerMachine quantumStorageController,
                                     ItemBase itemToStore)
        {
            var itemToStoreCopy = itemToStore.NewInstance();

            if (player == WorldScript.mLocalPlayer &&
                !WorldScript.mLocalPlayer.mInventory.RemoveItemByExample(itemToStore, true))
            {
                return;
            }

            quantumStorageController.AddItem(ref itemToStore);
            quantumStorageController.Dirty = true;

            if (itemToStore != null && itemToStore.GetAmount() > 0)
            {
                if (player == WorldScript.mLocalPlayer)
                {
                    WorldScript.mLocalPlayer.mInventory.AddItem(itemToStore);
                }
            }


            if (!WorldScript.mbIsServer)
            {
                NetworkManager.instance.SendInterfaceCommand(QuantumStorageMod.QuantumIoPortWindowKey,
                                                             "StoreItem",
                                                             null, itemToStoreCopy, quantumStorageController, 0.0f);
            }
        }
        /// <summary>
        ///     Adds an ItemBase to a list, consolidating stacks - obeys list storage capacity by returning excess items
        /// </summary>
        /// <param name="item">The item to add to the list</param>
        /// <param name="targetlist">The list to transfer it to</param>
        /// <param name="returnpartialstack">If true returns partial stack when insufficient stack size found</param>
        /// <param name="storagecapacity">The list's storage capacity</param>
        /// <returns>The remaining items that do not fit in the list</returns>
        public static ItemBase AddListItem(this ItemBase item, IEnumerable <ItemBase> targetlist, bool returnpartialstack, int storagecapacity = int.MaxValue)
        {
            List <ItemBase> workingtarget = targetlist.ToList();
            int             remainder     = 0;
            int             listcount     = workingtarget.GetItemCount();
            int             itemcount     = item.GetAmount();
            int             newtotal      = listcount + itemcount;
            ItemBase        returnitem    = null;

            if (newtotal > storagecapacity)
            {
                remainder  = newtotal - storagecapacity;
                itemcount -= remainder;
                item.SetAmount(itemcount);
                returnitem = NewInstance(item);
                returnitem.SetAmount(remainder);
            }
            for (int index = 0; index < workingtarget.Count; index++)
            {
                if (workingtarget[index].IsStackAndSame(item))
                {
                    workingtarget[index].IncrementStack(itemcount);
                    break;
                }
                else
                {
                    workingtarget.Add(item);
                    break;
                }
            }
            targetlist = workingtarget;
            return(returnitem);
        }
    //You can also get a call when the player's cursor hovers over an icon/button so that you can display info about it
    //Example code below for displaying item info in the hotbar
    public override void ButtonEnter(string name, SegmentEntity targetEntity)
    {
        MyModMachine machine = targetEntity as MyModMachine;

        if (name == "itemicon")
        {
            ItemBase itemForSlot = ItemManager.SpawnItem(100);
            int      count       = itemForSlot.GetAmount();
            if (itemForSlot == null)
            {
                return;
            }
            if (HotBarManager.mbInited)
            {
                HotBarManager.SetCurrentBlockLabel(ItemManager.GetItemName(itemForSlot));
            }
            else
            {
                if (!SurvivalHotBarManager.mbInited)
                {
                    return;
                }
                string name1 = !WorldScript.mLocalPlayer.mResearch.IsKnown(itemForSlot) ? "Unknown Material" : ItemManager.GetItemName(itemForSlot);
                if (count > 1)
                {
                    SurvivalHotBarManager.SetCurrentBlockLabel(string.Format("{0} {1}", count, name1));
                }
                else
                {
                    SurvivalHotBarManager.SetCurrentBlockLabel(name1);
                }
            }
        }
    }
예제 #8
0
    private ItemBase GetItemForSlot(string name, out int count, MSAccessPort port)
    {
        ItemBase itemForSlot = null;

        count = 0;
        int slotNum = -1;

        int.TryParse(name.Replace("itemicon", ""), out slotNum); //Get slot name as number
        if (slotNum > -1)
        {
            if (WithdrawMode)
            {
                itemForSlot = port.MasterItemList[slotNum].itembase;
                count       = port.MasterItemList[slotNum].Quantity;
            }
            else
            {
                int row = slotNum / 10;
                int col = slotNum % 10;
                itemForSlot = WorldScript.mLocalPlayer.mInventory.maItemInventory[col, row];
                if (itemForSlot != null)
                {
                    count = itemForSlot.GetAmount();
                }
            }
        }
        return(itemForSlot);
    }
        /// <summary>
        ///     Deduct an item from an item list by example
        /// </summary>
        /// <param name="item">The example item to attempt to remove from the list</param>
        /// <param name="sourcelist">The list to take the item from</param>
        /// <param name="returnpartialstack">If true returns partial stack when insufficient stack size found</param>
        /// <returns>The ItemBase object or null if unavailable</returns>
        public static ItemBase RemoveListItem(this ItemBase item, ref List <ItemBase> sourcelist, bool returnpartialstack)
        {
            if (item == null)
            {
                Debug.LogError("RemoveListItem attempted to remove a null item from a list");
                return(null);
            }
            List <ItemBase> workingsource = sourcelist.ToList();

            if (item.IsStack())
            {
                int itemcount = item.GetAmount();
                int listitemcount;

                for (int index = 0; index < workingsource.Count; index++)
                {
                    ItemBase i = workingsource[index];
                    listitemcount = i.GetAmount();
                    if (i.Compare(item) && listitemcount > itemcount)
                    {
                        i.DecrementStack(itemcount);
                        sourcelist = workingsource;
                        return(NewInstance(item));
                    }
                    else if (i.Compare(item) && listitemcount == itemcount)
                    {
                        workingsource.Remove(i);
                        sourcelist = workingsource;
                        return(NewInstance(item));
                    }
                    else if (returnpartialstack)
                    {
                        item.SetAmount(listitemcount);
                        sourcelist = workingsource;
                        return(NewInstance(item));
                    }
                }
            }
            else
            {
                for (int index = 0; index < workingsource.Count; index++)
                {
                    ItemBase i = workingsource[index];
                    if (i.Compare(item))
                    {
                        workingsource.Remove(i);
                        sourcelist = workingsource;
                        return(i);
                    }
                }
            }
            sourcelist = workingsource;
            return(null);
        }
예제 #10
0
 public void InventoryAssessment(ItemBase Item)
 {
     if (!cInventory.HasItem(Item.GetName()))
     {
         cInventory.AddItem(Item);
     }
     else
     {
         cInventory.AddAmount(Item.GetName(), Item.GetAmount());
     }
 }
    private bool TakeLensSurrounding()
    {
        ItemBase taken = CommunityUtil.TakeFromSurrounding((MachineEntity)this, mTargetLens);

        if (taken == null)
        {
            return(false);
        }
        if (taken.GetAmount() <= 0)
        {
            return(false);
        }
        if (taken.GetAmount() > getStorageAvailable())
        {
            Debug.Log("[Auto Lens Swapper][info] 'Take Surrounding' took more than max_storage!\nNothing lost, but not intended!");
        }
        AddLenses(taken.GetAmount());
        MarkDirtyDelayed();
        return(true);
    }
예제 #12
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()));
     }
 }
예제 #13
0
        public override void LowFrequencyUpdate()
        {
            if (!WorldScript.mbIsServer)
            {
                return;
            }

            var storageController = StorageIoService.GetStorageController();

            if (storageController == null || _incomingItem == null || !storageController.IsOperating() || !storageController.IsInputEnabled())
            {
                return;
            }

            var itemLimit          = storageController.GetItemLimit(_incomingItem);
            var itemInStorage      = storageController.GetItems().Find(x => x.Compare(_incomingItem));
            var itemCountInStorage = 0;

            if (itemInStorage != null)
            {
                itemCountInStorage = itemInStorage.GetAmount();
            }

            var itemCountInStorageAfterAdd = _incomingItem.GetAmount() + itemCountInStorage;

            if (itemLimit > 0 && itemCountInStorageAfterAdd > itemLimit)
            {
                return;
            }

            storageController.AddItem(ref _incomingItem);
            if (_incomingItem == null || _incomingItem.GetAmount() == 0)
            {
                _incomingItem = null;
                MarkDirtyDelayed();
                RequestImmediateNetworkUpdate();
                return;
            }
        }
 public bool TryDeliverItem(StorageUserInterface sourceEntity, ItemBase item, ushort cubeType, ushort cubeValue, bool sendImmediateNetworkUpdate)
 {
     if (!isValidLensID(item.mnItemID))
     {
         return(false);                               //Not a lens!
     }
     if (item.GetAmount() <= 0)
     {
         return(false);
     }
     if (item.mnItemID != mTargetLens.mnItemID)
     {
         return(false);                                       //Must be correct type!
     }
     if (item.GetAmount() > getStorageAvailable())
     {
         return(false);
     }
     AddLenses(item.GetAmount());
     MarkDirtyDelayed();
     return(true);
 }
예제 #15
0
 // This function will assess if an item is already in the inventory, either adding it or increasing the amount.
 public void InventoryAssessment(ItemBase Item, Vector3Int ID)
 {
     //ItemBase Item = GO.GetComponent<ItemBase>();
     if (!cInventory.HasItem(Item.GetName()))
     {
         cInventory.AddItem(Item);
     }
     else
     {
         cInventory.AddAmount(Item.GetName(), Item.GetAmount());
     }
     //TileDataClass Temp = new TileDataClass();
     //Dictioary.TileMapData.Add(ID, Temp);
 }
        /// <summary>
        ///     Deduct an item from an item list by example
        /// </summary>
        /// <param name="item">The example item to attempt to remove from the list</param>
        /// <param name="sourcelist">The list to take the item from</param>
        /// <param name="returnpartialstack">If true returns partial stack when insufficient stack size found</param>
        /// <returns>The ItemBase object or null if unavailable</returns>
        public static ItemBase RemoveListItem(this ItemBase item, IEnumerable <ItemBase> sourcelist, bool returnpartialstack)
        {
            List <ItemBase> workingsource = sourcelist.ToList();

            if (item.IsStack())
            {
                int itemcount = item.GetAmount();
                int listitemcount;

                for (int index = 0; index < workingsource.Count; index++)
                {
                    ItemBase i = workingsource[index];
                    listitemcount = i.GetAmount();
                    if (i.Compare(item) && listitemcount > itemcount)
                    {
                        i.DecrementStack(itemcount);
                        sourcelist = workingsource;
                        return(item);
                    }
                    else if (i.Compare(item) && listitemcount == itemcount)
                    {
                        workingsource.Remove(i);
                        sourcelist = workingsource;
                        return(item);
                    }
                    else if (returnpartialstack)
                    {
                        item.SetAmount(listitemcount);
                        sourcelist = workingsource;
                        return(item);
                    }
                }
            }
            else
            {
                for (int index = 0; index < workingsource.Count; index++)
                {
                    ItemBase i = workingsource[index];
                    if (i.Compare(item))
                    {
                        workingsource.Remove(i);
                        sourcelist = workingsource;
                        return(i);
                    }
                }
            }
            sourcelist = workingsource;
            return(null);
        }
        /// <summary>
        ///     Adds an ItemBase to a list, consolidating stacks - obeys list storage capacity by returning excess items
        /// </summary>
        /// <param name="item">The item to add to the list</param>
        /// <param name="targetlist">The list to transfer it to</param>
        /// <param name="returnpartialstack">If true returns partial stack when insufficient stack size found</param>
        /// <param name="storagecapacity">The list's storage capacity</param>
        /// <returns>The remaining items that do not fit in the list</returns>
        public static ItemBase AddListItem(this ItemBase item, ref List <ItemBase> targetlist, bool returnpartialstack, int storagecapacity = int.MaxValue)
        {
            if (item == null)
            {
                Debug.LogError("AddListItem attempted to add a null item!");
                return(null);
            }
            List <ItemBase> workingtarget = targetlist.ToList();
            int             remainder     = 0;
            int             listcount     = workingtarget.GetItemCount();
            int             itemcount     = item.GetAmount();
            int             newtotal      = listcount + itemcount;
            ItemBase        returnitem    = null;

            if (newtotal > storagecapacity)
            {
                remainder  = newtotal - storagecapacity;
                itemcount -= remainder;
                item.SetAmount(itemcount);
                returnitem = NewInstance(item);
                returnitem.SetAmount(remainder);
            }
            int listlength = workingtarget.Count;

            for (int index = 0; index <= listlength; index++)
            {
                if (index != listlength && item.IsStack())
                {
                    if (workingtarget[index].Compare(item))
                    {
                        workingtarget[index].IncrementStack(itemcount);
                        item = null;
                        break;
                    }
                }
                else
                {
                    workingtarget.Add(NewInstance(item));
                    item = null;
                    break;
                }
            }
            targetlist = workingtarget;
            return(returnitem);
        }
예제 #18
0
    /*RIP AZIR*/
    public void BuyShopItem()
    {
        XMLParser      XML         = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <XMLParser>();
        MoneyClass     PlayerMoney = GameObject.FindGameObjectWithTag("Player").GetComponent <MoneyClass>();
        InventoryClass cInventory  = GameObject.FindGameObjectWithTag("InventoryManager").GetComponent <InventoryClass>();
        ItemBase       Item        = new ItemBase();
        ItemBase       NewItem     = gameObject.GetComponentInParent <ItemBase>();
        ItemTypeFinder TypeFinder  = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <ItemTypeFinder>();
        // Get the object the component will be on and give it a name
        GameObject SubGameObject = new GameObject(NewItem.bName);

        SubGameObject.transform.parent = cInventory.ToolItems.transform;

        // If the player has enough gold
        if (PlayerMoney.GetMoney() >= NewItem.GetSellPrice())
        {
            // If it has the item and is stackable
            if (cInventory.HasItem(NewItem.GetName()) && NewItem.GetStackable())
            {
                cInventory.AddAmount(NewItem.GetName(), NewItem.GetAmount());
                PlayerMoney.SetMoney(PlayerMoney.GetMoney() - NewItem.GetSellPrice());
            }
            else
            {
                // Find the type of the item and set it up, after add it to the dictionary.
                Item = TypeFinder.ItemTyepFinder(NewItem, SubGameObject);
                Item.SetUpThisItem(NewItem.bItemType, NewItem.bName, NewItem.bAmount,
                                   NewItem.bStackable, NewItem.bSrcImage, NewItem.bSoundEffect,
                                   NewItem.bTile, NewItem.bPrefab, NewItem.bSellPrice, NewItem.bCustomData,
                                   NewItem.GetDesc());
                cInventory.AddItem(Item);
                PlayerMoney.SetMoney(PlayerMoney.GetMoney() - Item.GetSellPrice());
            }
        }
        cInventory.UpdateUI();
    }
예제 #19
0
        public bool AddItem(ref ItemBase item)
        {
            SegmentEntity adjacentEntity = GetConnectedStorage();

            if (adjacentEntity == null)
            {
                return(false);
            }

            List <SegmentEntity> segmentEntities = new List <SegmentEntity>();

            segmentEntities.Add(adjacentEntity);
            (adjacentEntity as IQuantumStorage).GetConnectedSegments(ref segmentEntities);

            foreach (SegmentEntity segmentEntity in segmentEntities)
            {
                if (!(segmentEntity is IQuantumStorage storageEntity))
                {
                    continue;
                }

                if (storageEntity.IsFull())
                {
                    continue;
                }

                storageEntity.AddItem(ref item);
                if (item == null || item.GetAmount() == 0)
                {
                    _quantumStorageController.Dirty = true;
                    return(true);
                }
            }

            return(false);
        }
예제 #20
0
    public SaveData(Vector3Int date, Vector3 pos, Vector3Int time, float[] lighting, bool[] resets, int[] slots, float playerGold, int playerEnergy, ItemBase[] inventory,
                    ItemBase[] hotbar, ItemBase[] chest, Dictionary <string, Dictionary <Vector3Int, TileDataClass> > dataBase)
    {
        // Set up all the arrays we will be saving to
        Inventory = new ItemData[slots[0]];
        HotBar    = new ItemData[slots[1]];
        Chest     = new ItemData[slots[2]];
        Lighting  = new float[4];
        Farm      = new PlantData[dataBase.ElementAt(0).Value.Count];
        Mines     = new RockData[dataBase.ElementAt(1).Value.Count];
        Mines1    = new RockData[dataBase.ElementAt(2).Value.Count];
        Mines2    = new RockData[dataBase.ElementAt(3).Value.Count];
        Forest    = new TreeData[dataBase.ElementAt(4).Value.Count];

        Date[0]             = date.x; Date[1] = date.y; Date[2] = date.z;
        Time[0]             = time.x; Time[1] = time.y; Time[2] = time.z;
        PlayerPos[0]        = pos.x; PlayerPos[1] = pos.y; PlayerPos[2] = pos.z;
        WeeklyResets        = resets;
        InventorySlotAmount = slots;
        PlayerGold          = playerGold;
        PlayerEnergy        = playerEnergy;
        Lighting            = lighting;

        string TileName   = "";
        string PrefabName = "";

        for (int i = 0; i < slots[0]; i++)
        {
            if (inventory[i] != null)
            {
                if (inventory[i].GetTile() != null)
                {
                    TileName = inventory[i].GetTile().name;
                }
                if (inventory[i].GetPrefab() != null)
                {
                    PrefabName = inventory[i].GetPrefab().name;
                }

                Inventory[i].SetUp(inventory[i].GetName(), inventory[i].mItemType.ToString(),
                                   inventory[i].GetSrcImage(), TileName,
                                   inventory[i].GetSoundEffect().name, PrefabName, inventory[i].GetAmount(),
                                   inventory[i].GetStackable(), inventory[i].GetSellPrice(), inventory[i].GetDesc());
            }

            TileName   = "";
            PrefabName = "";
        }
        for (int i = 0; i < slots[1]; i++)
        {
            if (hotbar[i] != null)
            {
                if (hotbar[i].GetTile() != null)
                {
                    TileName = hotbar[i].GetTile().name;
                }
                if (hotbar[i].GetPrefab() != null)
                {
                    PrefabName = hotbar[i].GetPrefab().name;
                }


                HotBar[i].SetUp(hotbar[i].GetName(), hotbar[i].mItemType.ToString(), hotbar[i].GetSrcImage(),
                                TileName, hotbar[i].GetSoundEffect().name, PrefabName, hotbar[i].GetAmount(),
                                hotbar[i].GetStackable(), hotbar[i].GetSellPrice(), hotbar[i].GetDesc());
            }

            TileName   = "";
            PrefabName = "";
        }
        for (int i = 0; i < slots[2]; i++)
        {
            if (chest[i] != null)
            {
                if (chest[i].GetTile() != null)
                {
                    TileName = chest[i].GetTile().name;
                }
                if (chest[i].GetPrefab() != null)
                {
                    PrefabName = chest[i].GetPrefab().name;
                }

                Chest[i].SetUp(chest[i].GetName(), chest[i].mItemType.ToString(), chest[i].GetSrcImage(),
                               TileName, chest[i].GetSoundEffect().name, PrefabName, chest[i].GetAmount(),
                               chest[i].GetStackable(), chest[i].GetSellPrice(), chest[i].GetDesc());
            }

            TileName   = "";
            PrefabName = "";
        }

        int counter = 0;

        foreach (var var in dataBase.ElementAt(0).Value)
        {
            if (var.Value.GetPlant() != null)
            {
                PlantAbstractClass Plant         = var.Value.GetPlant();
                Vector3Int         Key           = new Vector3Int(var.Key.x, var.Key.y, var.Key.z);
                string[]           GrowthSprites = new string[Plant.mGrowthSprites.Length];
                GrowthSprites[0] = Plant.mGrowthSprites[0].name;
                GrowthSprites[1] = Plant.mGrowthSprites[1].name;
                GrowthSprites[2] = Plant.mGrowthSprites[2].name;
                Farm[counter].SetUp(Plant.mCurrentDays, Plant.mGrowthTime, Plant.GetType().ToString(),
                                    Plant.GetSrcImage(), Plant.GetAmount(), GrowthSprites, Key, Key, var.Value.Tile.name,
                                    Plant.mHarvestable, Plant.mGrowth, Plant.XMLName, Plant.mWatered);
            }
            counter++;
        }
        counter = 0;
        foreach (var var in dataBase.ElementAt(1).Value)
        {
            OreAbstractClass Ore = var.Value.GetOre();
            float[]          Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Mines[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount());
            counter++;
        }

        counter = 0;
        foreach (var var in dataBase.ElementAt(2).Value)
        {
            OreAbstractClass Ore = var.Value.GetOre();
            float[]          Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Mines1[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount());
            counter++;
        }
        counter = 0;
        foreach (var var in dataBase.ElementAt(3).Value)
        {
            OreAbstractClass Ore = var.Value.GetOre();
            float[]          Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Mines2[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount());
            counter++;
        }
        counter = 0;
        foreach (var var in dataBase.ElementAt(4).Value)
        {
            ItemBase Wood = var.Value.GetItem();
            float[]  Key  = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z;
            Forest[counter].SetUp(Wood.mItemType.ToString(), Wood.GetName(), Key, Key, var.Value.Tile.name, Wood.GetName(), Wood.GetAmount());
            counter++;
        }
        counter = 0;
    }
예제 #21
0
    public static int WithdrawItem(Player player, MSAccessPort port, ItemBase item, int amount)
    {
        if (item == null)
        {
            Debug.LogWarning("MSAccessPort is trying to withdraw null item!");
            return(amount);
        }
        if (!WorldScript.mbIsServer)
        {
            NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceWithdrawItem, amount.ToString(), item, port, 0.0f);
        }
        ItemBase itemout;

        //Handle special items by copying the full data on retrieval and inserting into the player inventory
        if (item.mType != ItemType.ItemStack && item.mType != ItemType.ItemCubeStack)
        {
            for (int index = 0; index < amount; index++)
            {
                if (!player.mInventory.CanFit(item))
                {
                    if (player.mbIsLocalPlayer)
                    {
                        FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Inventory full!", Color.red, 1.5f);
                    }
                    if (index != 0)
                    {
                        player.mInventory.MarkEverythingDirty();
                        port.MarkDirtyDelayed();
                        port.mbJustTransmitted = true;
                    }
                    return(amount - index);
                }
                if (port.WithdrawItem(item, out itemout) == 0)
                {
                    if (itemout == null)
                    {
                        Debug.LogWarning("MSAccessPort attempted to withdraw item: " + item.ToString() + " but found null on withdraw");
                        return(amount - index);
                    }
                    port.mrCurrentPower -= port.mrTransportCost;
                    if (itemout != null && !player.mInventory.AddItem(itemout))
                    {
                        ItemManager.instance.DropItem(itemout, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero);
                    }
                    else if (itemout == null)
                    {
                        Debug.LogWarning("MSAccessPort tried to withdraw single item but returned null itemout?");
                    }
                }
                else
                {
                    if (index != 0)
                    {
                        player.mInventory.MarkEverythingDirty();
                        port.MarkDirtyDelayed();
                        port.mbJustTransmitted = true;
                    }
                    return(amount - index);
                }
            }
        }
        else
        {
            //Stacked items have all necessary info stored in the passed itembase and don't need the original from mass storage
            if (!player.mInventory.CanFit(item))
            {
                if (player.mbIsLocalPlayer)
                {
                    FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Inventory full!", Color.red, 1.5f);
                }
                return(item.GetAmount());
            }
            int remainder = port.WithdrawItem(item, out itemout);
            if (remainder != 0)
            {
                port.mrCurrentPower -= port.mrTransportCost * (item.GetAmount() - remainder);
                if (itemout != null && !player.mInventory.AddItem(itemout))
                {
                    ItemManager.instance.DropItem(item, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero);
                }
                else if (itemout == null)
                {
                    Debug.LogWarning("MSAccessPort tried to withdraw item stack but returned null itemout?");
                }
                player.mInventory.MarkEverythingDirty();
                port.MarkDirtyDelayed();
                port.mbJustTransmitted = true;
            }
            else
            {
                if (itemout != null && !player.mInventory.AddItem(itemout))
                {
                    ItemManager.instance.DropItem(item, player.mnWorldX, player.mnWorldY, player.mnWorldZ, Vector3.zero);
                }
                else if (itemout == null)
                {
                    Debug.LogWarning("MSAccessPort tried to withdraw item stack but returned null itemout?");
                }
                port.mrCurrentPower -= port.mrTransportCost * item.GetAmount();
            }
        }
        player.mInventory.MarkEverythingDirty();
        port.MarkDirtyDelayed();
        port.mbJustTransmitted = true;
        return(0);
    }
예제 #22
0
    public static int DepositItem(Player player, MSAccessPort port, ItemBase item, int amount)
    {
        if (!WorldScript.mbIsServer)
        {
            NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceDepositItem, amount.ToString(), item, port, 0.0f);
        }
        //Handle special case items by getting the exact item from inventory based on the example ID
        if (item.mType != ItemType.ItemStack && item.mType != ItemType.ItemCubeStack)
        {
            for (int index = 0; index < amount; index++)
            {
                if (item != null)
                {
                    // This is required due to the dubious item type associated with MasterList
                    item = player.mInventory.TryAndGetItem(item.mnItemID);
                    if (!player.mInventory.RemoveSpecificItem(item))
                    {
                        if (player.mbIsLocalPlayer)
                        {
                            FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Item not found!", Color.red, 1.5f);
                        }
                        if (index != 0)
                        {
                            player.mInventory.MarkEverythingDirty();
                            port.MarkDirtyDelayed();
                            port.mbJustTransmitted = true;
                        }
                        return(amount - index);
                    }
                    if (port.DepositItem(item) != 0)
                    {
                        if (player.mbIsLocalPlayer)
                        {
                            FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Mass Storage full!", Color.red, 1.5f);
                        }
                        //Return item to player if it failed to deposit
                        player.mInventory.AddItem(item);
                        if (index != 0)
                        {
                            player.mInventory.MarkEverythingDirty();
                            port.MarkDirtyDelayed();
                            port.mbJustTransmitted = true;
                        }
                        return(amount - index);
                    }
                    else
                    {
                        port.mrCurrentPower -= port.mrTransportCost;
                    }
                }
            }
        }
        else
        {
            if (!player.mInventory.RemoveItemByExample(item))
            {
                if (player.mbIsLocalPlayer)
                {
                    FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Item not found!", Color.red, 1.5f);
                }
                return(item.GetAmount());
            }
            int remainder = port.DepositItem(item);
            if (remainder != 0)
            {
                if (player.mbIsLocalPlayer)
                {
                    FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Mass Storage full!", Color.red, 1.5f);
                }
                //Return item to player if it failed to deposit
                player.mInventory.AddItem(ItemManager.CloneItem(item).SetAmount(remainder));
                port.mrCurrentPower -= port.mrTransportCost * (item.GetAmount() - remainder);
                player.mInventory.MarkEverythingDirty();
                port.MarkDirtyDelayed();
                port.mbJustTransmitted = true;
                return(remainder);
            }
            else
            {
                port.mrCurrentPower -= port.mrTransportCost * item.GetAmount();
            }
        }

        player.mInventory.MarkEverythingDirty();
        port.MarkDirtyDelayed();
        port.mbJustTransmitted = true;
        return(0);
    }
예제 #23
0
 // Update is called once per frame
 void Update()
 {
     GetCamera(); // Don't know if we need to do this every frame but hey hoo will look later #RIP AZIR
     // Reduce the cooldown
     if (CoolDown > 0.0f)
     {
         CoolDown -= Time.deltaTime;
     }
     // if action is locked then reduce the timer till 0 and reset
     if (actionLocked)
     {
         actionLockedTimer -= Time.deltaTime;
         if (actionLockedTimer < 0)
         {
             actionLocked      = false;
             actionLockedTimer = actionLock;
         }
     }
     /*This is used to assign tools when one of the keys are pressed*/
     if (Input.GetKeyUp(KeyCode.Alpha1) && !Selected[0])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[0] != false)
         {
             Selected[0] = true;
             Debug.Log("SLOT: 0 SELECTED");
             tool = ItemList[0].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[0].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[0].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha2) && !Selected[1])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[1] != false)
         {
             Selected[1] = true;
             Debug.Log("SLOT: 1 SELECTED");
             tool = ItemList[1].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[1].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[1].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha3) && !Selected[2])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[2] != false)
         {
             Selected[2] = true;
             Debug.Log("SLOT: 2 SELECTED");
             tool = ItemList[2].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[2].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[2].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha4) && !Selected[3])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[3] != false)
         {
             Selected[3] = true;
             Debug.Log("SLOT: 3 SELECTED");
             tool = ItemList[3].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[3].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[3].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha5) && !Selected[4])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[4] != false)
         {
             Selected[4] = true;
             Debug.Log("SLOT: 4 SELECTED");
             tool = ItemList[4].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[4].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[4].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha6) && !Selected[5])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[5] != false)
         {
             Selected[5] = true;
             Debug.Log("SLOT: 5 SELECTED");
             tool = ItemList[5].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[5].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[5].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha7) && !Selected[6])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[6] != false)
         {
             Selected[6] = true;
             Debug.Log("SLOT: 6 SELECTED");
             tool = ItemList[6].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[6].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[6].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha8) && !Selected[7])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[7] != false)
         {
             Selected[7] = true;
             Debug.Log("SLOT: 7 SELECTED");
             tool = ItemList[7].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[7].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[7].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha9) && !Selected[8])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[8] != false)
         {
             Selected[8] = true;
             Debug.Log("SLOT: 8 SELECTED");
             tool = ItemList[8].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[8].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[8].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     if (Input.GetKeyUp(KeyCode.Alpha0) && !Selected[9])
     {
         for (int i = 0; i < 10; i++)
         {
             if (Selected[i])
             {
                 Vector3 transform = ImageSlots[i].transform.parent.transform.position;
                 transform.y = 70.0f;
                 ImageSlots[i].transform.parent.transform.position = transform;
             }
             Selected[i] = false;
         }
         if (Markers[9] != false)
         {
             Selected[9] = true;
             Debug.Log("SLOT: 9 SELECTED");
             tool = ItemList[9].GetComponent <ItemBase>();
             Vector3 transform = ImageSlots[9].transform.parent.transform.position;
             transform.y += 3.0f;
             ImageSlots[9].transform.parent.transform.position = transform;
             FindFarmComponenets();
         }
         else
         {
             tool = new ItemBase();
         }
     }
     /******************************************/
     /* If we can act */
     if (!actionLocked && !cInventory.UIEnabled && !Chest.UIEnabled)
     {
         if (Input.GetMouseButtonDown(0))
         {
             /*If we don't have an active tool then tell the player*/
             if (tool == null)
             {
                 Debug.Log("PLEASE SELECT A VALID TOOL");
             }
             /*Make sure that we actually have an amount of the used tool*/
             else if (tool.GetAmount() > 0)
             {
                 // Get the camera if null
                 if (camera == null)
                 {
                     GetCamera();
                 }
                 // Get the mouse pos
                 mouseWorldPoint = camera.ScreenToWorldPoint(Input.mousePosition);
                 // Get the player
                 GameObject Player = GameObject.FindGameObjectWithTag("Player");
                 Debug.Log(Vector2.Distance(Player.transform.position, mouseWorldPoint));
                 /*If we are in range, the lock our actions and find the farm compoents and then use the tool. */
                 if (Vector2.Distance(Player.transform.position, mouseWorldPoint) < interactRange)
                 {
                     actionLocked = true;
                     FindFarmComponenets();
                     tool.useTool();
                     ToolScript Tool = (ToolScript)tool;
                     if (Tool.ToolUsed)
                     {
                         Tool.ToolUsed = false;
                         Stam.UseStamina(tool.GetCustomData());
                     }
                 }
                 else
                 {
                     Debug.Log("OUT OF RANGE OF TOOL");
                 }
             }
         }
     }
 }
예제 #24
0
    public override void UpdateMachine(SegmentEntity targetEntity)
    {
        MSAccessPort port = targetEntity as MSAccessPort;

        if (port == null)
        {
            GenericMachinePanelScript.instance.Hide();
            UIManager.RemoveUIRules("Machine");
            return;
        }

        if (networkredraw)
        {
            networkredraw = false;
            this.manager.RedrawWindow();
        }
        this.manager.UpdatePowerBar("powerbar", port.mrCurrentPower, port.mrMaxPower);

        if (!dirty)
        {
            return;
        }

        if (WithdrawMode)
        {
            if (listcount != port.MasterItemList.Count)
            {
                this.manager.RedrawWindow();
            }
            if (port.AccessState != MSAccessPort.eState.Withdraw)
            {
                port.AccessState = MSAccessPort.eState.Withdraw;
            }

            for (int n = 0; n < listcount; n++)
            {
                int      row  = n / 15;
                int      col  = n % 15;
                ItemBase item = port.MasterItemList[n].itembase;
                if (item != null)
                {
                    string itemicon  = ItemManager.GetItemIcon(item);
                    int    stacksize = port.MasterItemList[n].Quantity;

                    this.manager.UpdateIcon("itemicon" + n, itemicon, Color.white);
                    this.manager.UpdateLabel("StackSize" + n, this.FormatStackText(stacksize), Color.white);
                }
            }
        }
        else
        {
            for (int n = 0; n < 80; n++)
            {
                int      row  = n / 10;
                int      col  = n % 10;
                ItemBase item = WorldScript.mLocalPlayer.mInventory.maItemInventory[col, row];
                if (item != null)
                {
                    string itemicon  = ItemManager.GetItemIcon(item);
                    int    stacksize = item.GetAmount();

                    this.manager.UpdateIcon("itemicon" + n, itemicon, Color.white);
                    this.manager.UpdateLabel("StackSize" + n, this.FormatStackText(stacksize), Color.white);
                }
            }
        }
        dirty = false;
    }