Beispiel #1
0
        public AddEditCraftingItemWindowTests()
        {
            definedCraftingMaterials = new List <CraftingMaterial>
            {
                new CraftingMaterial {
                    Name = TestCraftingMaterialName, SourceType = SourceType.Mining, Location = TestLocation
                }
            };

            var craftingItem = BuildCraftingItem(
                TestCraftingItemName,
                SourceType.Cooking,
                (1, definedCraftingMaterials.First()));

            editedCraftingItem = BuildCraftingItem(
                TestEditedItemName,
                SourceType.Leatherworking,
                (1, definedCraftingMaterials.First()),
                (2, craftingItem));

            definedCraftingItems = new List <CraftingItem>
            {
                craftingItem,
                BuildCraftingItem(TestCraftingItemName + "2", SourceType.Alchemy, (3, definedCraftingMaterials.First())),
                editedCraftingItem
            };
        }
 public void SetCraftingItem(CraftingItem newCraftingItem)
 {
     //Debug.Log ("Setting crafting item");
     if (HasCraftingItem)
     {
         if (CraftingWorldItem != newCraftingItem)
         {
             //it's not the same one - is it the same type?
             CraftingItem oldCraftingItem = CraftingWorldItem;
             CraftingWorldItem = newCraftingItem;
             if (oldCraftingItem.SkillToUse != newCraftingItem.SkillToUse)
             {
                 mRequiredSkill = null;
                 Blueprint      = null;
                 RefreshRequest();
             }
         }
     }
     else
     {
         if (CraftingWorldItem != newCraftingItem)
         {
             CraftingWorldItem = newCraftingItem;
             RefreshRequest();
         }
     }
 }
Beispiel #3
0
    /**
     * Called whenever the player makes a sacrifice to the gods: this god will then decide how it wants to react
     * to this type of sacrifice, based on their preferences
     */
    public void SacrificeMade(string sacrificeItemName)
    {
        // Get the actual item being sacrificed, we need it's use function
        CraftingItem sacrificeItem = WorldManager.instance.GetCraftingItemByName(sacrificeItemName);

        if (sacrificeItem == null)
        {
            Debug.Log("WARNING! Diety::SacrificeMade() Could not find the CraftingItem with the name: " + sacrificeItemName);
            return;
        }

        // Perfrom the function of the crafting item
        sacrificeItem.ActivateUse(WorldManager.instance.GetActivePlayer());

        // Adjust the gods feelings towards the player based on the item sacrifised and its preferences
        float prefVal  = GetValueForItem(sacrificeItemName);
        float prefMag  = Mathf.Abs(prefVal);
        float prefSign = Mathf.Sign(prefVal);

        // The dieties relation to the player will react more at the smaller ends of the spectrum
        float deltaRelation = 0.0f;

        // the larger the magnitude of the relation, the smaller the change will be so that a larger relation is harder to change
        float reactionMag      = 1.0f - Mathf.Abs(playerRelation);
        float maxDeltaReaction = prefMag * GLOBAL_MAX_DELTA_REACTION;

        deltaRelation = (maxDeltaReaction * reactionMag) * prefSign;

        playerRelation += deltaRelation;

        Debug.Log(sacrificeItemName + " for " + dietyName + " :: " + playerRelation + " --- Delta = " + deltaRelation);
    }
Beispiel #4
0
        private CraftingItem BuildCraftingItem(string name, SourceType sourceType = SourceType.Blacksmith)
        {
            var item = new CraftingItem {
                Name = name, SourceType = sourceType
            };

            item.SetMaterials(BuildSpecifiedCraftingMaterial(2, craftingMaterial).ToSingleton());

            return(item);
        }
Beispiel #5
0
        public static void AddCraftingToCraftingTAbleModel(int tableModelID, CraftingItem _craft)
        {
            var _table = GetCraftingTableModel(tableModelID);

            if (_table != null)
            {
                _table.Craftings.Add(_craft);
                SaveChanges(saveType.Model);
            }
        }
 public void ClearCrafting()
 {
     //Debug.Log ("Clearing crafting");
     SendItemsBackToInventory();
     if (CraftingWorldItem != null)
     {
         CraftingWorldItem = null;
         Blueprint         = null;
         RefreshRequest();
     }
 }
Beispiel #7
0
 public override bool DoesContextAllowForUse(IItemOfInterest targetObject)
 {
     if (base.DoesContextAllowForUse(targetObject))
     {
         CraftingItem craftingItem = targetObject.gameObject.GetComponent <CraftingItem> ();
         if (craftingItem.SkillToUse == name)
         {
             return(true);
         }
     }
     return(false);
 }
 public bool FindCraftingItemInFocus()
 {
     if (Player.Local.Surroundings.IsWorldItemInPlayerFocus)
     {
         CraftingItem newCraftingItem = null;
         if (Player.Local.Surroundings.WorldItemFocus.worlditem.Is <CraftingItem>(out newCraftingItem))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
    private void CreateRequiredItemList()
    {
        requiredItems = new ReorderableList(selectedRecipe.requiredItems, typeof(CraftingItem), true, true, true, true);
        requiredItems.drawHeaderCallback += (Rect rect) => { EditorGUI.LabelField(rect, "Required items"); };

        requiredItems.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) =>
        {
            CraftingItem requiredItem = (CraftingItem)requiredItems.list[index];
            requiredItem.item   = (ScriptableItemData)EditorGUI.ObjectField(new Rect(rect.x, rect.y, rect.width * 0.5f, EditorGUIUtility.singleLineHeight), "Required Item", requiredItem.item, typeof(ScriptableItemData), false);
            requiredItem.amount = EditorGUI.IntField(new Rect(rect.width * 0.55f, rect.y, rect.width * 0.4f, EditorGUIUtility.singleLineHeight), "Required Amount", requiredItem.amount);
        };
    }
Beispiel #10
0
    // Spawns an item from the bots drop list, returns the item dropped
    protected void DropItemFromList()
    {
        if (dropList == null)
        {
            return;
        }
        if (dropList.Length == 0)
        {
            return;
        }

        // Decide on the item type
        int dropIdx = Random.Range(0, dropList.Length - 1);

        // Crafting items only get dropped some percentage of the time, based on their rarity score
        if (dropList[dropIdx].GetType() == typeof(CraftingItem))
        {
            CraftingItem craftingItem = (CraftingItem)dropList[dropIdx];

            int randDropProb = Random.Range(0, 100);
            if (randDropProb > craftingItem.rarityScore)
            {
                return;
            }
        }

        // Spawn the container object
        GameObject dropObj = world.SpawnObject("P_DroppedItem", transform.position);

        if (dropObj == null)
        {
            Debug.Log("ERROR! Failed to spawn a DroppedItem container from " + name);
            return;
        }

        DroppedItem droppedContainter = dropObj.GetComponent <DroppedItem>();

        if (droppedContainter == null)
        {
            Debug.Log("ERROR! DroppedItem object " + dropObj.name + " doesn't have a DroppedItem component!");
            return;
        }

        if (dropList[dropIdx].GetType() == typeof(CraftingItem))
        {
            droppedContainter.DropCraftingItem(this, (CraftingItem)dropList[dropIdx]);
        }
        else
        {
            droppedContainter.Drop(this, dropList[dropIdx].GetType());
        }
    }
 bool Contains(List <CraftingItem> recipe, CraftingItem item, out int maxQuantity)
 {
     maxQuantity = 0;
     foreach (CraftingItem c in recipe)
     {
         if (item.item.id == c.item.id && c.quantity >= item.quantity)
         {
             maxQuantity = c.quantity / item.quantity;
             return(true);
         }
     }
     return(false);
 }
Beispiel #12
0
    public bool AddCraftingItem(CraftingItem craftingItem)
    {
        // If the map doesn't contain a key for this item yet, a new entry will have to be created
        int currentAmout = 0;

        if(craftingItems.TryGetValue(craftingItem.craftingItemName, out currentAmout)) {
            int newAmout = Mathf.Min(currentAmout + 1, MAX_ITEMS);

            craftingItems[craftingItem.craftingItemName] = newAmout;
        }
        else {
            craftingItems.Add(craftingItem.craftingItemName, 1);
        }

        return true;
    }
Beispiel #13
0
    public bool AddCraftingItem(CraftingItem craftingItem)
    {
        // If the map doesn't contain a key for this item yet, a new entry will have to be created
        int currentAmout = 0;

        if (craftingItems.TryGetValue(craftingItem.craftingItemName, out currentAmout))
        {
            int newAmout = Mathf.Min(currentAmout + 1, MAX_ITEMS);

            craftingItems[craftingItem.craftingItemName] = newAmout;
        }
        else
        {
            craftingItems.Add(craftingItem.craftingItemName, 1);
        }

        return(true);
    }
Beispiel #14
0
    // Crafting items are different b/c there is only one class, but any number of values
    public void DropCraftingItem(Pawn dropper, CraftingItem itemToDrop)
    {
        bHasLanded = false;
        startDropSpeed = Random.Range(0.0f, maxVelocity);
        velocity = Random.insideUnitCircle * startDropSpeed;
        velocity.y = Mathf.Abs(velocity.y);
        groundHeight = (dropper.transform.position - dropper.GetBaseOffset()).y;

        // Craftingitems can be a direct reference b/c they have no functionality, only data that doesn't change
        item = itemToDrop;
        droppedBy = dropper;

        if(item != null) {
            if(spriteRenderer == null) {
                spriteRenderer = GetComponent<SpriteRenderer>();
            }
            SetSpriteImage();
        }
    }
Beispiel #15
0
    public void CreateButton(int id)
    {
        CraftingItem newButton = Instantiate(buttonToClone.gameObject, background.transform).GetComponent <CraftingItem>();

        newButton.gameObject.SetActive(true);
        newButton.image.sprite       = GameManager.current.allParts[id].sprite;
        newButton.transform.position = buttonToClone.transform.position + new Vector3(xPos, -yPos, 0);
        newButton.ID = id;
        imageButtons.Add(newButton.GetComponent <Image>());

        xPos          += buttonWidth + spacing;
        currentNumber += 1;

        if (currentNumber > howManyPerLine)
        {
            currentNumber = 1;
            xPos          = spacing;
            yPos         += buttonWidth + spacing;
        }
    }
Beispiel #16
0
    // Crafting items are different b/c there is only one class, but any number of values
    public void DropCraftingItem(Pawn dropper, CraftingItem itemToDrop)
    {
        bHasLanded     = false;
        startDropSpeed = Random.Range(0.0f, maxVelocity);
        velocity       = Random.insideUnitCircle * startDropSpeed;
        velocity.y     = Mathf.Abs(velocity.y);
        groundHeight   = (dropper.transform.position - dropper.GetBaseOffset()).y;

        // Craftingitems can be a direct reference b/c they have no functionality, only data that doesn't change
        item      = itemToDrop;
        droppedBy = dropper;

        if (item != null)
        {
            if (spriteRenderer == null)
            {
                spriteRenderer = GetComponent <SpriteRenderer>();
            }
            SetSpriteImage();
        }
    }
Beispiel #17
0
 public float GetValueForItem(CraftingItem item)
 {
     return GetValueForItem(item.craftingItemName);
 }
Beispiel #18
0
 public string GetReactionToItem(CraftingItem item)
 {
     return GetReactionToItem(item.craftingItemName);
 }
Beispiel #19
0
        public IEnumerator CraftItems(
            WIBlueprint blueprint,
            CraftingItem craftingItem,
            int totalItems,
            List <List <InventorySquareCrafting> > rows,
            InventorySquareCraftingResult resultSquare)
        {
            int    currentItem          = 0;
            double startTime            = 0f;
            double endTime              = 0f;
            double timeOffset           = 0f;
            double timeMultiplier       = 1f;
            double craftTime            = 0f;
            double craftSkillUsageValue = 0f;

            mProgressValue = 0f;

            UseStart(true);

            //here we go with the crafting...
            while (currentItem < totalItems && !mCancelled)
            {
                craftTime            = blueprint.BaseCraftTime * EffectTime;
                craftSkillUsageValue = 1.0f;                //TODO apply modifiers

                startTime = WorldClock.RealTime;
                endTime   = startTime + craftTime;

                if (totalItems > 1)
                {
                    timeOffset     = (float)(currentItem - 1) / (float)totalItems;
                    timeMultiplier = 1.0f / totalItems;
                    //crafting time is reduced in proportion to the number of items you're crafting at once
                }
                //ok, if we can consume the requirements, we're good to go

                if (!ConsumeRequirements(rows))
                {
                    //Debug.Log ("Couldn't consume requirements");
                    break;
                }
                else
                {
                    while (WorldClock.RealTime < endTime && !ProgressCanceled)
                    {
                        double normalizedProgress = (WorldClock.RealTime - startTime) / (endTime - startTime);
                        mProgressValue = (float)((normalizedProgress * timeMultiplier) + timeOffset);                        //make sure it doesn't accidentally stop
                        mProgressValue = Mathf.Clamp(mProgressValue, 0.001f, 0.999f);
                        yield return(null);
                    }

                    if (!ProgressCanceled)
                    {
                        resultSquare.NumItemsCrafted++;
                        currentItem++;
                    }
                }
                yield return(null);
            }
            //just in case
            mProgressValue = 1.0f;

            UseFinish();
            yield break;
        }
    private void Update()
    {
        // Debug.Log("HoldingItem: " + holdigPickup + " HoldingCraftinItem: " + holdingCraftinItem);
        // Debug.Log("currObjInCol: " + currenObjectInCollision + " List: " + objectsInCollisionList.Count);
        if (Input.GetKeyUp(KeyCode.E) && currenObjectInCollision)
        {
            var craftingItem = currenObjectInCollision.GetComponent <CraftingItem>();


            //currenObjectInCollision = getNearestCollidesObject();
            if (!holdingPickup)
            {
                if (currenObjectInCollision.tag == "Pickup")
                {
                    holdingPickup = currenObjectInCollision.GetComponent <Pickup>();
                    PickItem();
                }

                if (currenObjectInCollision.tag == "CraftingItem" && isButtonPressedDown)
                {
                    craftingItem.BuildingFinished();
                    movement.EnableMovement();
                    OnTriggerExit(currenObjectInCollision.GetComponent <Collider>());
                    currenObjectInCollision = null;
                    ShowText(false);
                    Debug.Log("stop budowy");
                }
            }
            else // is Holding item
            {
                if (currenObjectInCollision.tag == "CraftingItem")
                {
                    if (craftingItem.PutItem(holdingPickup))
                    {
                        Debug.Log("udało się wsadzić item");

                        if (craftingItem.AlreadyCompleted)
                        {
                            if (objectsInCollisionList.Contains(craftingItem.gameObject))
                            {
                                Debug.Log("Removing: " + craftingItem.gameObject);
                                objectsInCollisionList.Remove(craftingItem.gameObject);
                            }
                        }


                        SoundManager.PlaySound(correctSound);
                        holdingPickup.gameObject.transform.SetParent(currenObjectInCollision.transform);
                        holdingPickup.gameObject.SetActive(false);
                        DropItem(true);
                        holdingPickup = null;
                    }
                    else
                    {
                        SoundManager.PlaySound(wrongSound);
                        //     Debug.Log("nie mozesz wsadzić itemu");
                    }
                }

                if (holdingPickup)
                {
                    DropItem(false);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            if (currenObjectInCollision && currenObjectInCollision.CompareTag("CraftingItem") && !holdingPickup)
            {
                CraftingItem item = currenObjectInCollision.GetComponent <CraftingItem>();
                if (item.AreRequirementsFullfilled())
                {
                    item.BuildingStarted();
                    if (objectsInCollisionList.Contains(item.gameObject))
                    {
                        Debug.Log("Removing: " + item.gameObject);
                        objectsInCollisionList.Remove(item.gameObject);
                    }
                    // movement.DisableMovement();
                    isButtonPressedDown     = false;
                    currenObjectInCollision = null;
                    ShowText(false);
                    //  Debug.Log("start budowy");
                }
            }
        }

        if (!currenObjectInCollision)
        {
            ShowText(false);
        }
        if (isCanvasActive)
        {
            playerCanvas.transform.rotation = Quaternion.Euler(0, -transform.rotation.y, 0);
        }
    }
Beispiel #21
0
        public static SaveDataResults FromJson(string jsonString)
        {
            var saveData = JsonConvert.DeserializeObject <SaveData>(jsonString);

            var materialsList = saveData.AllCraftingMaterials
                                .Select(x =>
            {
                return(new CraftingMaterial
                {
                    Name = x.Name,
                    SourceType = x.SourceType,
                    Location = x.Location
                });
            })
                                .ToList();

            Func <Guid, CraftingItemData>     lookupCraftingItem     = id => saveData.AllCraftingItems.FirstOrDefault(x => x.Id == id);
            Func <Guid, CraftingMaterialData> lookupCraftingMaterial = id => saveData.AllCraftingMaterials.FirstOrDefault(x => x.Id == id);

            CraftingItem convertCraftingItem(CraftingItemData item)
            {
                if (item == null)
                {
                    throw new InvalidOperationException("Cannot convert null crafting item data.");
                }

                var craftingItem = new CraftingItem
                {
                    Name       = item.Name,
                    SourceType = item.SourceType
                };

                var materials = item.Materials ?? Enumerable.Empty <CountedCraftingItemData>().ToList();

                craftingItem.SetMaterials(
                    materials
                    .Select(x =>
                {
                    ICraftingMaterial craftingMaterial;

                    if (x.IsMaterial)
                    {
                        var material = lookupCraftingMaterial(x.ItemId);

                        if (material == null)
                        {
                            throw new InvalidOperationException($"Cannot find saved material with id '{x.ItemId}'.");
                        }

                        craftingMaterial = new CraftingMaterial
                        {
                            Name       = material.Name,
                            SourceType = material.SourceType,
                            Location   = material.Location
                        };
                    }
                    else
                    {
                        var craftingItem = lookupCraftingItem(x.ItemId);

                        if (craftingItem == null)
                        {
                            throw new InvalidOperationException($"Cannot find saved crafting item with id '{x.ItemId}'.");
                        }

                        craftingMaterial = convertCraftingItem(craftingItem);
                    }

                    return(new SpecifiedCraftingMaterial
                    {
                        Material = craftingMaterial,
                        Count = x.Count
                    });
                }));

                return(craftingItem);
            };

            var itemsList = saveData.AllCraftingItems
                            .Select(item => convertCraftingItem(item))
                            .ToList();

            var listedItemsList = saveData.ListedItems
                                  .Select(item =>
            {
                var itemData = lookupCraftingItem(item.ItemId);

                if (itemData == null)
                {
                    throw new InvalidOperationException($"Cannot find saved crafting item with id '{item.ItemId}'.");
                }

                var craftingItem = itemsList.FirstOrDefault(x => StringComparer.OrdinalIgnoreCase.Equals(x.Name, itemData.Name));

                if (craftingItem == null)
                {
                    throw new InvalidOperationException($"Cannot find rendered crafting item with name '{itemData.Name}'.");
                }

                return(new SpecifiedCraftingItem
                {
                    Item = craftingItem,
                    Count = item.Count
                });
            })
                                  .ToList();

            return(new SaveDataResults
            {
                DefinedCraftingMaterials = materialsList,
                DefinedCraftingItems = itemsList,
                CraftingItems = listedItemsList
            });
        }
Beispiel #22
0
 public float GetValueForItem(CraftingItem item)
 {
     return(GetValueForItem(item.craftingItemName));
 }
Beispiel #23
0
 public string GetReactionToItem(CraftingItem item)
 {
     return(GetReactionToItem(item.craftingItemName));
 }