Hi, I was wondering about how to implement this, I'm sorry if the title is not perfect, I don't know how to call this operation:
my player can collect various items (start with 3, maybe more in the future) each item have a value in points.
When collected, the items are saved in a table with 6 slots (maybe more later)
when the table is "full" its content should be processed:
to make an example I will name those items with letters and give them values (A = 1,B = 3,C = 5)
tableOfCollectedItems = {
{A,1},{A,1},{B,3},{B,3},{C,5},{C,5}
}
resultOfAddition= 18 |
Each object in ipairs have its item name and its value in points, so I can easily add all the values and get a result.
This is where I'm stuck: I'd like to give bonus points based on the "composition" of the table.
- if all the "slots" are filled with the same item ,
- if 3 "slots" are filled with one item and 3 are filled with another,
- if there are 2*3 "slots" filled with the same item (as in tableOfCollectedItems before ) .
I can only think of a complex if/then table parsing to do this, which would most likely prevent me to easily add slots later in the game.
Do you have any idea to do it better?
It feels like something that bit operations can handle, but I don't know where to start.
Thank you
Comments
Likes: pie
The order doesn't matter, I will go for this.
Likes: pie
I'm sorry I didn't notice this yesterday I thought to add slots in pairs and check for "proportional" combinations.
I am thinking about counting item types and item occurrency in collectedTab, I believe that knowing the number of slots and those infos I could get my combos dynamically:
ie:
1 item type in 6 slots = combo 1
2 item types in 3+3 slots = combo 2
3 item types in 2+2+2 slots = combo 3
These could be easily translated to 8 slots and more, assuming that I provide at least max_slots/2 items to collect.
1 item type in 8 slots = combo 1
2 item types in 4+4 slots = combo 2
4 item types in 2+2+2+2 slots = combo 3
I am still thinking how to write it clean though
There is also an issue I didn't thought before: it should be a lot easier to get those combos with more slots available, so I don't know if it's worth doing it
Likes: pie