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

Simple crafting system #1260

Merged
merged 38 commits into from
Oct 9, 2023
Merged

Simple crafting system #1260

merged 38 commits into from
Oct 9, 2023

Conversation

stilnat
Copy link
Contributor

@stilnat stilnat commented Sep 18, 2023

Summary

Simple item replacement crafting, as described on gitbook :
https://ss3d.gitbook.io/design/actions/crafting/makeshift-crafting

System is mostly functionnal, does not include "steps" in the recipe for now, it's a simple item replacement.
However, it can handle arbitrary complex recipes.

A recipe is made of a crafting interaction (screw, slice, hammer...), a target (the item on which to apply the interaction), and a list of items and the needed count for each item.

The crafting interaction is only available when all conditions are present :

  • The right target
  • The right items needed in the right amount
  • The right interaction (so a tool able to produce it)

Items counted as available are items in close proximity from the target item. So to get the crafting interaction available, for now you have to drop all necessary items close to the target item.

The system works when other close items are not part of the recipe as well.

It currently consumes all crafting ressources and spawn the product of the recipe.

It implements some delays for some interactions. So the crafting only occurs after a while.

Currently, if the source interaction moves too far from its position during the interaction, it stops the interaction. This is necessary on some interaction that will have animation such as cutting some stuff. You don't want the player to look like they are cutting air.

Changes to Files

Technical Notes (optional)

Recipes are simple scriptable objects in Assets/Content/Data/Recipes currently. Easy to set up.

image

For now, you must enter the name of the interaction, in it. Not perfect because strings tend to break easily when code is changed.

Known issues

None as of now

Fixes (optional)

TODO

  • Support multiple products.

Futur work

  • It'd be nice if recipes could also work with traits, not just with type of items. Would be useful for makeshift weapon and other stuff.
  • Support checking needed items in inventory too (needs to be correctly defined) ?

@singulocity
Copy link
Contributor

To test, I spawned a knife, took off my hat, place it on the ground, then with the knife active, I clicked on it so that it would start the crafting. If I do nothing else, it works fine. If I walk away, it cancels which is great.

But I can pick up the hat while I am interacting with it with the knife. The recipe completes, the items spawn where the hat was in my hand and drop on the ground, and the hat is still maintained by the UI as being in my hand still.

Same thing if I put the hat in a pocket quickly.

Although while it was in my hand at least I could "drop" it to fix the state. Now it is stuck in my pocket forever. Haha.

We may need some kind of check to prevent players from picking up the thing they are interacting with.

@singulocity
Copy link
Contributor

singulocity commented Sep 19, 2023

Can't build to test host/client. Console log:

Failed to compile player scripts
UnityEditor.AddressableAssets.Settings.AddressableAssetSettings:BuildPlayerContent (UnityEditor.AddressableAssets.Build.AddressablesPlayerBuildResult&)
AddressablesPlayerBuildProcessor:PrepareForPlayerbuild (UnityEditor.AddressableAssets.Settings.AddressableAssetSettings,UnityEditor.Build.BuildPlayerContext,bool) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:100)
AddressablesPlayerBuildProcessor:PrepareForBuild (UnityEditor.Build.BuildPlayerContext) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:79)
UnityEditor.GenericMenu:CatchMenu (object,string[],int)

SBP ErrorError
UnityEditor.AddressableAssets.Settings.AddressableAssetSettings:BuildPlayerContent (UnityEditor.AddressableAssets.Build.AddressablesPlayerBuildResult&)
AddressablesPlayerBuildProcessor:PrepareForPlayerbuild (UnityEditor.AddressableAssets.Settings.AddressableAssetSettings,UnityEditor.Build.BuildPlayerContext,bool) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:100)
AddressablesPlayerBuildProcessor:PrepareForBuild (UnityEditor.Build.BuildPlayerContext) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:79)
UnityEditor.GenericMenu:CatchMenu (object,string[],int)

Addressable content build failure (duration : 0:00:01.81)
UnityEditor.AddressableAssets.Settings.AddressableAssetSettings:BuildPlayerContent (UnityEditor.AddressableAssets.Build.AddressablesPlayerBuildResult&)
AddressablesPlayerBuildProcessor:PrepareForPlayerbuild (UnityEditor.AddressableAssets.Settings.AddressableAssetSettings,UnityEditor.Build.BuildPlayerContext,bool) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:100)
AddressablesPlayerBuildProcessor:PrepareForBuild (UnityEditor.Build.BuildPlayerContext) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:79)
UnityEditor.GenericMenu:CatchMenu (object,string[],int)

Failed to build Addressables content, content not included in Player Build. "SBP ErrorError"
UnityEngine.Debug:LogError (object)
AddressablesPlayerBuildProcessor:PrepareForPlayerbuild (UnityEditor.AddressableAssets.Settings.AddressableAssetSettings,UnityEditor.Build.BuildPlayerContext,bool) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:103)
AddressablesPlayerBuildProcessor:PrepareForBuild (UnityEditor.Build.BuildPlayerContext) (at Library/PackageCache/com.unity.addressables@1.19.19/Editor/Build/AddressablesPlayerBuildProcessor.cs:79)
UnityEditor.GenericMenu:CatchMenu (object,string[],int)

Assets\Scripts\SS3D\Systems\Crafting\CraftingRecipe.cs(15,53): error CS0535: 'CraftingRecipe' does not implement interface member 'ISerializationCallbackReceiver.OnBeforeSerialize()'

Assets\Scripts\SS3D\Systems\Crafting\CraftingRecipe.cs(15,53): error CS0535: 'CraftingRecipe' does not implement interface member 'ISerializationCallbackReceiver.OnAfterDeserialize()'

Error building Player because scripts had compiler errors

Build completed with a result of 'Failed' in 19 seconds (19265 ms)
UnityEditor.GenericMenu:CatchMenu (object,string[],int)

UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
  at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in <63965ae56af7489797f355b7c1211ab2>:0 
  at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <63965ae56af7489797f355b7c1211ab2>:0 
UnityEditor.GenericMenu:CatchMenu (object,string[],int)

The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(AttachedContainer) _initialized

@stilnat stilnat changed the title [WIP] Simple crafting system Simple crafting system Sep 27, 2023
@stilnat
Copy link
Contributor Author

stilnat commented Oct 5, 2023

Issues above spotted by @singulocity are fixed

Copy link
Member

@cosmiccoincidence cosmiccoincidence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When play testing, the first recipe worked fine for me but the "weird complex recipe" did not. The target is a bike horn which also has it's own interaction when clicked, I noticed this is overriding the crafting interaction and preventing it from happening. Changing the target to something w/o any unique interactions and the recipe works fine. I suggest preventing the item's unique interactions from occurring when holding an item to fix this, as it doesn't make sense for me to honk the bikehorn if i click it with a knife.

@stilnat
Copy link
Contributor Author

stilnat commented Oct 8, 2023

@cosmiccoincidence I simply added a condition for the honk interaction, stating you need a hand to honk (so won't happen when holding a knife). I'm afraid always overriding the interaction for all cases, might be a bad idea. I rather have each interaction handle that on their own. Fixed the issue for the bikehorn.

@cosmiccoincidence
Copy link
Member

@cosmiccoincidence I simply added a condition for the honk interaction, stating you need a hand to honk (so won't happen when holding a knife). I'm afraid always overriding the interaction for all cases, might be a bad idea. I rather have each interaction handle that on their own. Fixed the issue for the bikehorn.

I'm not sure I agree. Imo I think the default interaction for an empty hand should be to grab the item, but if the hand has something held the interaction would be to use the held item on the target. I don't think people will use interactions on Items without grabbing them first very often. And if they do, they can easily right click it.

@stilnat
Copy link
Contributor Author

stilnat commented Oct 9, 2023

@cosmiccoincidence the default interaction is still picking up. Just try and test and let me know how this feels, I think it'll be the way you wanted.

@cosmiccoincidence cosmiccoincidence merged commit 92bcdcd into RE-SS3D:develop Oct 9, 2023
2 checks passed
@stilnat stilnat deleted the Crafting branch November 11, 2023 15:01
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

Successfully merging this pull request may close these issues.

None yet

3 participants