Пример #1
0
    public IInventoryItem GetFirstItemNotTool(IToolItem tool, Inventory workbenchInv)
    {
        IInventoryItem inventoryItem;
        IInventoryItem inventoryItem1;

        Inventory.OccupiedIterator occupiedIterator = workbenchInv.occupiedIterator;
        try
        {
            while (occupiedIterator.Next(out inventoryItem))
            {
                if (object.ReferenceEquals(inventoryItem, tool))
                {
                    continue;
                }
                inventoryItem1 = inventoryItem;
                return(inventoryItem1);
            }
            Debug.LogWarning("Could not find target item");
            return(null);
        }
        finally
        {
            ((IDisposable)(object)occupiedIterator).Dispose();
        }
        return(inventoryItem1);
    }
Пример #2
0
    public float GetWorkDuration()
    {
        IToolItem tool = this.GetTool();

        if (tool == null)
        {
            return(0f);
        }
        return(tool.workDuration);
    }
Пример #3
0
    public bool EnsureWorkExists()
    {
        IToolItem tool = this.GetTool();

        if (tool != null && tool.canWork)
        {
            return(true);
        }
        return(false);
    }
Пример #4
0
    public override bool CompleteWork(IToolItem tool, Inventory workbenchInv)
    {
        BlueprintDataBlock block;

        if (this.CanWork(tool, workbenchInv) && BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(base.GetFirstItemNotTool(tool, workbenchInv).datablock, out block))
        {
            workbenchInv.AddItem(block, Inventory.Slot.Preference.Define(Inventory.Slot.Kind.Default, block.IsSplittable(), Inventory.Slot.Kind.Belt), 1);
            return(true);
        }
        return(false);
    }
Пример #5
0
    public void CancelWork()
    {
        IToolItem tool = this.GetTool();

        if (tool != null)
        {
            tool.CancelWork();
        }
        this._inventory.locked  = false;
        this._startTime_network = 0;
        this._workDuration      = -1f;
        base.CancelInvoke("CompleteWork");
        this.SendWorkStatusUpdate();
    }
Пример #6
0
    public override bool CanWork(IToolItem tool, Inventory workbenchInv)
    {
        if (workbenchInv.occupiedSlotCount > 2)
        {
            Debug.Log("Too many items for research");
            return(false);
        }
        IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv);

        if (((firstItemNotTool != null) && firstItemNotTool.datablock.isResearchable) && BlueprintDataBlock.FindBlueprintForItem(firstItemNotTool.datablock))
        {
            return(true);
        }
        Debug.Log("Can't work!?!!?");
        return(false);
    }
Пример #7
0
 public IInventoryItem GetFirstItemNotTool(IToolItem tool, Inventory workbenchInv)
 {
     using (Inventory.OccupiedIterator iterator = workbenchInv.occupiedIterator)
     {
         IInventoryItem item;
         while (iterator.Next(out item))
         {
             if (!object.ReferenceEquals(item, tool))
             {
                 return(item);
             }
         }
     }
     Debug.LogWarning("Could not find target item");
     return(null);
 }
Пример #8
0
 private void StartWork()
 {
     if (this.EnsureWorkExists())
     {
         IToolItem tool = this.GetTool();
         if (tool != null)
         {
             this._startTime_network = NetCull.time;
             this._workDuration      = this.GetWorkDuration();
             base.Invoke("CompleteWork", this._workDuration);
             this._inventory.locked = true;
             tool.StartWork();
             this.SendWorkStatusUpdate();
         }
     }
 }
Пример #9
0
    public override bool CanWork(IToolItem tool, Inventory workbenchInv)
    {
        if (workbenchInv.occupiedSlotCount > 2)
        {
            Debug.Log("Too many items for recycle");
            return(false);
        }
        IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv);

        if (!firstItemNotTool.datablock.isRecycleable)
        {
            return(false);
        }
        if (!BlueprintDataBlock.FindBlueprintForItem(firstItemNotTool.datablock))
        {
            return(false);
        }
        return(true);
    }
Пример #10
0
    public override bool CompleteWork(IToolItem tool, Inventory workbenchInv)
    {
        BlueprintDataBlock block;
        int num5;

        if (!this.CanWork(tool, workbenchInv))
        {
            return(false);
        }
        IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv);

        BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(firstItemNotTool.datablock, out block);
        int uses = 1;

        if (firstItemNotTool.datablock.IsSplittable())
        {
            uses = firstItemNotTool.uses;
        }
        for (int i = 0; i < uses; i++)
        {
            foreach (BlueprintDataBlock.IngredientEntry entry in block.ingredients)
            {
                int num4 = Random.Range(0, 4);
                if ((num4 != 0) && (((num4 == 1) || (num4 == 2)) || (num4 == 3)))
                {
                    workbenchInv.AddItemAmount(entry.Ingredient, entry.amount);
                }
            }
        }
        if (!firstItemNotTool.datablock.IsSplittable())
        {
            num5 = firstItemNotTool.uses;
        }
        else
        {
            num5 = uses;
        }
        if (firstItemNotTool.Consume(ref num5))
        {
            firstItemNotTool.inventory.RemoveItem(firstItemNotTool.slot);
        }
        return(true);
    }
Пример #11
0
    public override bool CompleteWork(IToolItem tool, Inventory workbenchInv)
    {
        BlueprintDataBlock blueprintDataBlock;
        int num;

        if (!this.CanWork(tool, workbenchInv))
        {
            return(false);
        }
        IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv);

        BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(firstItemNotTool.datablock, out blueprintDataBlock);
        int num1 = 1;

        if (firstItemNotTool.datablock.IsSplittable())
        {
            num1 = firstItemNotTool.uses;
        }
        for (int i = 0; i < num1; i++)
        {
            BlueprintDataBlock.IngredientEntry[] ingredientEntryArray = blueprintDataBlock.ingredients;
            for (int j = 0; j < (int)ingredientEntryArray.Length; j++)
            {
                BlueprintDataBlock.IngredientEntry ingredientEntry = ingredientEntryArray[j];
                int num2 = UnityEngine.Random.Range(0, 4);
                if (num2 != 0)
                {
                    if (num2 == 1 || num2 == 2 || num2 == 3)
                    {
                        workbenchInv.AddItemAmount(ingredientEntry.Ingredient, ingredientEntry.amount);
                    }
                }
            }
        }
        num = (firstItemNotTool.datablock.IsSplittable() ? num1 : firstItemNotTool.uses);
        if (firstItemNotTool.Consume(ref num))
        {
            firstItemNotTool.inventory.RemoveItem(firstItemNotTool.slot);
        }
        return(true);
    }
Пример #12
0
 public override float GetWorkDuration(IToolItem tool)
 {
     return(15f);
 }
Пример #13
0
 public virtual bool CanWork(IToolItem tool, Inventory workbenchInv)
 {
     return(false);
 }
Пример #14
0
 public virtual float GetWorkDuration(IToolItem tool)
 {
     return(1f);
 }
Пример #15
0
 public override float GetWorkDuration(IToolItem tool)
 {
     return(this.craftingDuration);
 }
Пример #16
0
    public bool EnsureWorkExists()
    {
        IToolItem tool = this.GetTool();

        return((tool != null) && tool.canWork);
    }