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

Editor: setup initial Character's inventory #2600

Open
ivan-mogilko opened this issue Dec 2, 2024 · 8 comments
Open

Editor: setup initial Character's inventory #2600

ivan-mogilko opened this issue Dec 2, 2024 · 8 comments
Labels
ags 4 related to the ags4 development context: game logic type: enhancement a suggestion or necessity to have something improved what: editor related to the game editor

Comments

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Dec 2, 2024

This suggestion is opened after a user's question.

Currently AGS only allows to mark inventory items that are added to player character at game start. This is done by setting each item's "PlayerStartsWithItem" property.

Sometimes it may be desired to have several characters begin with some items in their inventories. The character roles is mostly irrelevant, these may be playable characters, or NPCs. This may be done in script, but would be convenient for users to also have a way to set this up in the editor directly.

The idea is to have Inventory property in Character instead. This property would hold a list of inventory items. In Properties Grid this property would have a "..." button, which opens a dialog window with a list, that lets add and remove items, set their quantity and change their order.

These lists would be added to the compiled game data, and used to initialize each character's starting inventory contents.

The Character has "inv" array already present in the game data, but it's only filled for the starting player character, and only for items marked as "player starts with this item":

foreach (InventoryItem invItem in game.InventoryItems) // inv[MAX_INV]
{
if ((isPlayer) && (invItem.PlayerStartsWithItem)) writer.Write((short)1);
else writer.Write((short)0);
}

@ivan-mogilko ivan-mogilko added type: enhancement a suggestion or necessity to have something improved what: editor related to the game editor ags 4 related to the ags4 development context: game logic labels Dec 2, 2024
@ericoporto
Copy link
Member

This can be done very easily with code generation afaict.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Dec 6, 2024

Then, where would be the line between things written into the game data and added to generated code?
Every new feature added to characters and other global objects may in theory be put into generated code instead of game data.
(Rooms probably may too, although for that they would have to support extra init script)

@ericoporto
Copy link
Member

Well, it can be done by adding things in game28.dta too.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Dec 6, 2024

I actually am not against the idea of doing things in script in general, that sounds rather flexible, and especially suitable if we support dynamic creation of objects. But there may be caveats.

We must keep in mind that anything done in script may have side effects, and that may be not good when we are initializing an initial game state, especially in the auto generated code (that user may not be aware of).

For instance, AddInventory function triggers eEventAddInventory event, so it should not be used. There may be other similar cases, and there's no guarantee that something of that sort is not added in the future.
If we want to secure initialization stage, we'd need to have a flag that enables and disables side-effects. There was something similar in WinForms, which wraps the code in xxxDesigner.cs.


In regards to inventory though, I just realized that Character data already has inventory array in game data. It was simply never used when compiling the game:

short inv[MAX_INV];

in->ReadArrayOfInt16(inv, MAX_INV);

Since it's already there, I suppose it's easier to just put this data there.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Dec 6, 2024

Wait, I was an idiot. This array IS used when compiling the game, that's how the "player starts with this item" works:
(For some reason I thought this is a flag in inventory item)

foreach (InventoryItem invItem in game.InventoryItems) // inv[MAX_INV]
{
if ((isPlayer) && (invItem.PlayerStartsWithItem)) writer.Write((short)1);
else writer.Write((short)0);
}

So, right, this is the most natural place to write it then.

@ericoporto
Copy link
Member

ericoporto commented Dec 6, 2024

since the characters may have any items, and possibly repeating items - at minimum it would require the checkbox combobox we use for game platform settings. If we want to be able to setup the number of such item, it may require a proper custom editor for this or an overview pane of all characters and their inventories.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Dec 6, 2024

Yes, I suggest a dialog with a list inside:

The idea is to have Inventory property in Character instead. This property would hold a list of inventory items. In Properties Grid this property would have a "..." button, which opens a dialog window with a list, that lets add and remove items, set their quantity and change their order.

I am not sure if item order can be done through the editor though, because order is a separate array in the runtime data which is not present in game data... so maybe not.
EDIT: ...unless we add a new array of item orders into game data, but idk if it's necessary at this moment.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Dec 6, 2024

In regards to UI, i dont have any final vision.
The primitive variant is to have a simple list with Add/Remove buttons.
Then there is also a variant of having 2 lists: one with character inventory and another with the list of items, and Add/Remove buttons move items from one list to another. This way user can see which items are added and which other items exist at the same time.
Then, maybe it will be convenient for users to see same tree structure with folders when selecting items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags 4 related to the ags4 development context: game logic type: enhancement a suggestion or necessity to have something improved what: editor related to the game editor
Projects
None yet
Development

No branches or pull requests

2 participants