Ejemplo n.º 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);
    }
Ejemplo n.º 2
0
    public float GetWorkDuration()
    {
        IToolItem tool = this.GetTool();

        if (tool == null)
        {
            return(0f);
        }
        return(tool.workDuration);
    }
Ejemplo n.º 3
0
    public bool EnsureWorkExists()
    {
        IToolItem tool = this.GetTool();

        if (tool != null && tool.canWork)
        {
            return(true);
        }
        return(false);
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 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();
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
 }
Ejemplo n.º 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();
         }
     }
 }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 12
0
 public override float GetWorkDuration(IToolItem tool)
 {
     return(15f);
 }
Ejemplo n.º 13
0
 public virtual bool CanWork(IToolItem tool, Inventory workbenchInv)
 {
     return(false);
 }
Ejemplo n.º 14
0
 public virtual float GetWorkDuration(IToolItem tool)
 {
     return(1f);
 }
Ejemplo n.º 15
0
 public override float GetWorkDuration(IToolItem tool)
 {
     return(this.craftingDuration);
 }
Ejemplo n.º 16
0
    public bool EnsureWorkExists()
    {
        IToolItem tool = this.GetTool();

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