Hello peeps,
I've been trying to develop an orb system that is similar to how defect operates in Slay the Spire if any of you are familiar. If not, this is how it works: There are slots for orbs to go in, each orb does something (usually at turn end but not necessarily) and when you have all slots full and create more, the oldest one gets popped and the newly created one gets added to the front. There are also skills that make use of these orbs to do things.
They way I've done it so far is that I have one visible state(passive state) that contains the array of possible and current orbs. Here's my code for it:
Then I have a skill to create each type of orb as well as a state that deals with each type of orb. Here are my codes for the skills and states.
The effects of the orbs run smoothly, but today I tried to add the duration ticking mechanic and encountered a big problem. When I have multiples of the same type of orb, ticking down one's duration ticks down the duplicates as well. Not only that, ticking down the duration of an orb in the active orbs array ticks down the duration of the originals that are in the original array.
I had thought that pushing objects from the original array into the active orbs array would make copies that could be independently modified but this suggests to me that I'm merely referencing the same object instead of making independent copies.
I've fished around the internet for solutions but haven't found an easy way to circumvent this. How would I be able to do what I want to do here?
I've been trying to develop an orb system that is similar to how defect operates in Slay the Spire if any of you are familiar. If not, this is how it works: There are slots for orbs to go in, each orb does something (usually at turn end but not necessarily) and when you have all slots full and create more, the oldest one gets popped and the newly created one gets added to the front. There are also skills that make use of these orbs to do things.
They way I've done it so far is that I have one visible state(passive state) that contains the array of possible and current orbs. Here's my code for it:
JavaScript:
<Custom Battle Effect>
target.orbsAll = [
{
"type": "plasma",
"duration": 5,
},
{
"type": "staff",
"duration": 10,
},
{
"type": "book",
"duration": 3,
}
];
target.orbs = [];
</Custom Battle Effect>
Then I have a skill to create each type of orb as well as a state that deals with each type of orb. Here are my codes for the skills and states.
Skill 1
State 1
Skill 2
State 2
JavaScript:
<Instant>
<Custom Execution>
user.addState(43);
user.orbs.unshift(user.orbsAll[0]);
if (user.orbs.length > 3)
user.orbs.pop();
</Custom Execution>
State 1
JavaScript:
<Custom Turn End Effect>
var group = $gameTroop.aliveMembers();
if (target.orbs[0].type == "plasma") {
var targeted = group[Math.floor(Math.random() * group.length)];
targeted.gainHp(-8);
targeted.startDamagePopup();
target.orbs[0].duration = target.orbs[0].duration -1;
}
if (target.orbs[1].type == "plasma") {
var targeted = group[Math.floor(Math.random() * group.length)];
targeted.gainHp(-8);
targeted.startDamagePopup();
target.orbs[1].duration = target.orbs[1].duration -1;
}
if (target.orbs[2].type == "plasma") {
var targeted = group[Math.floor(Math.random() * group.length)];
targeted.gainHp(-8);
targeted.startDamagePopup();
target.orbs[2].duration = target.orbs[2].duration -1;
}
</Custom Turn End Effect>
Skill 2
Code:
<Instant>
<Custom Execution>
user.addState(44);
user.orbs.unshift(user.orbsAll[1]);
if (user.orbs.length > 3)
user.orbs.pop();
</Custom Execution>
State 2
Code:
<Custom Turn End Effect>
var group = $gameParty.aliveMembers().filter(member => member.hp < member.mhp);
if (target.orbs[0].type == "staff" && group.length > 0) {
var targeted = group[Math.floor(Math.random() * group.length)];
targeted.gainHp(5);
targeted.startDamagePopup();
target.orbs[0].duration = target.orbs[0].duration -1;
}
if (target.orbs[1].type == "staff" && group.length > 0) {
var targeted = group[Math.floor(Math.random() * group.length)];
targeted.gainHp(5);
targeted.startDamagePopup();
target.orbs[1].duration = target.orbs[1].duration -1;
}
if (target.orbs[2].type == "staff" && group.length > 0) {
var targeted = group[Math.floor(Math.random() * group.length)];
targeted.gainHp(5);
targeted.startDamagePopup();
target.orbs[2].duration = target.orbs[2].duration -1;
}
</Custom Turn End Effect>
The effects of the orbs run smoothly, but today I tried to add the duration ticking mechanic and encountered a big problem. When I have multiples of the same type of orb, ticking down one's duration ticks down the duplicates as well. Not only that, ticking down the duration of an orb in the active orbs array ticks down the duration of the originals that are in the original array.
I had thought that pushing objects from the original array into the active orbs array would make copies that could be independently modified but this suggests to me that I'm merely referencing the same object instead of making independent copies.
I've fished around the internet for solutions but haven't found an easy way to circumvent this. How would I be able to do what I want to do here?