Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need more ex #118

Open
Aconment opened this issue Sep 10, 2023 · 3 comments
Open

need more ex #118

Aconment opened this issue Sep 10, 2023 · 3 comments

Comments

@Aconment
Copy link

tooltip for item's property,
save and load inventory
Random parameter for generating system

@benjamin-kirkbride
Copy link

and multiplayer :)

@peter-kish
Copy link
Owner

Hi!

  • Tooltips are a nice idea, will definitely try adding those at some point. Right now the GLoot UI code is somewhat messy and I'll probably need to clean it up a bit first.
  • Saving/loading inventories should be doable using the Inventory.serialize and Inventory.deserialize methods
  • Not sure what you mean by "random parameter for generating system", but if you mean random item properties, those can be set from from code using InventoryItem.set_property.
  • Yeah, not sure what multiplayer functionality GLoot would need, but again, I guess you could serialize/deserialize an inventory and send the data across the network...

@Aconment
Copy link
Author

yet,InventoryItem.set_property can do it , u can refer to this script https://github.com/don-tnowe/godot-wyvernbox-inventory/blob/master/addons/wyvernbox/crafting/item_conversion.gd , likes by GPT:

```extends Object

class_name ItemSelector

var cumulativeProbabilities := []
var totalProbability := 0.0

func _init():
    randomize()

func calculateCumulativeProbabilities(probabilityArray: Array):
    totalProbability = 0.0
    cumulativeProbabilities.clear()
    for i in range(probabilityArray.size()):
        totalProbability += probabilityArray[i]
        cumulativeProbabilities.append(totalProbability)

func selectItem(itemArray: Array, probabilityArray: Array, count: int) -> Array:
    if itemArray.size() != probabilityArray.size():
        print("Error: itemArray and probabilityArray sizes do not match.")
        return []
    # sum probability
    calculateCumulativeProbabilities(probabilityArray)
    var selectedIndices := []
    for i in range(count):
        var randomValue := randf() * totalProbability
        for j in range(cumulativeProbabilities.size()):
            if randomValue <= cumulativeProbabilities[j]:
                selectedIndices.append(j)
                cumulativeProbabilities[j] -= probabilityArray[j]  # pop it
                break

    return selectedIndices


    # use:

    # var itemSelector = ItemSelector.new()
    # var itemArray = ["A", "B", "C", "D"]
    # var probabilityArray = [3, 4, 3, 1]
    # var itemCount = 3

    # var selectedIndices = itemSelector.selectItem(itemArray, probabilityArray, itemCount)
    # print(selectedIndices)  # 输出选中的itemArray的下标

var myDictionary = {
    "name": ["string1", "string2", "string3", "string4", "string5"],
    "Probability": [1, 2, 3, 4, 5],
    "string1": [6, 12, 18, 24],
    "string1_Probability": [5, 3, 2, 1],
    "string2": [6, 12, 18, 24],
    "string2_Probability": [5, 3, 2, 1],
    "string3": [6, 12, 18, 24], 
    "string3_Probability": [5, 3, 2, 1],
    "string4": [6, 12, 18, 24],
    "string4_Probability": [5, 3, 2, 1],
    "string5": [6, 12, 18, 24],
    "string5_Probability": [5, 3, 2, 1],
}

var selectedIndices2 = itemSelector.selectItem(myDictionary["name"], myDictionary["Probability"], 3)

# mabey selectedIndices2= [1,3,4]

var propertyDict = {}

for i in selectedIndices2:
    var select_property = myDictionary["name"][selectedIndices2[i]]
    var select_property_Probability = select_property + "_Probability"
    var index = itemSelector.selectItem(myDictionary[select_property], myDictionary[select_property_Probability], 1)
    propertyDict.set(select_property,select_property[index])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants