Mana Link skill (shared MP pool between two actors)

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
1,064
Reaction score
1,326
First Language
Swedish
Primarily Uses
RMVXA
I think this is the correct place to ask for help with creating a complex skill?

I watched this and got inspired:
What I would like to create is kinda similar, but a bit more complex (I think).

I’d like to make a ”Mana Link” skill.

The skill can be broken down into two parts. The first part of the skill combines the casters and target’s max (and current MP) into one (basically, they’ll get added together and both characters MP changes to reflect this).

The second part of the skill is what slightly resembles yanfly's heal link, but expands the concept. Any MP changes (subtraction or addition, etc) that happens to one character would happen to the other one’s MP too at the same time. Achieving perfect synchronization between the two actors MP supply.

For balancing reasons, this skill would be limited to be used only once per battle and at the end of battle the effect would wear off. Both character’s maxMP would reset to default, and the current MP would be split in half.

Hm, yeah, as I write this down I realize that this skill could be even trickier to make than I first realized. I know it’s already outside of my scope without help, but I’ll still post this and see if some genius swings by. You never know...

And even if you are not a genius, thanks anyway for reading the entire post. :kaoluv:
 

Lay

Veteran
Veteran
Joined
Jul 18, 2019
Messages
124
Reaction score
47
First Language
French
Primarily Uses
RMMV
let say that the following is an advanced draft. I'm sure you can complete it.
I didn't tackle the cooldown you want to.

The following require few plugins from yanfly library :
  • SkillCore
  • BuffsStatesCore
  • TargetCore
  • SelectionControl
  • BaseParamControl

Skill notetag :
JavaScript:
<Select Conditions>
  Not User
</Select Conditions>

<Before Eval>
user.addState(22);
</Before Eval>
Skill Effect : Add State Mana Link 100%

Skill Scope : 1 ally


State notetag (Mana Link, ID 22):

JavaScript:
<Custom Apply Effect>
if (target != origin){
  var oriMp = origin.mmp;
  var tarMp = user.mmp;
  origin.addMaxMp(tarMp);
  origin._manaLinkBuff = tarMp;
  user.addMaxMp(oriMp);
  user._manaLinkBuff = oriMp
  var oriMp = origin.mp;
  var tarMp = user.mp;
  user.gainMp(oriMp);
  origin.gainMp(tarMp);
}
origin._manaLink = user;
user._manaLink = origin;
</Custom Apply Effect>

<Custom Action End Effect>
if (user._manaLink.mp != user.mp){
  var dmg = user.mp - user._manaLink.mp
  user._manaLink.gainMp(dmg)
}
</Custom Action End Effect>

<Custom Respond Effect>
if (target._manaLink.mp != target.mp){
  var dmg = target.mp - target._manaLink.mp
  target._manaLink.gainMp(dmg)
}
</Custom Respond Effect>

<Custom Leave Effect>
var mpRatio = user.mp / user.mmp
user._manaLink.removeState(22);
user.addMaxMp(-user._mmpBuff);
var curMp = Math.floor(user.mmp * mpRatio)
user.setMp(curMp)
</Custom Leave Effect>
 
Last edited:

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
1,064
Reaction score
1,326
First Language
Swedish
Primarily Uses
RMVXA
@Lay
Thank you so much. Just from testing I can tell it's not working yet. Would you be able to point me towards which parts which would need fixing? I guess:

<Select Conditions>
Not User
</Select Conditions>

Is a placeholder? since I can still target the user and "Not User" is not valid script... right?

I do have the plugins you mentioned installed of course...

As for the "once in battle", I think I can easily get that effect with Yanfly's SkillCooldown plugin so that should not be a problem.
 

Lay

Veteran
Veteran
Joined
Jul 18, 2019
Messages
124
Reaction score
47
First Language
French
Primarily Uses
RMMV
For the plugin you miss SkillCore I think.

For the <Selection Control>, I really don't understand it works fine for me and I can select any actor but user.

I've revised the code a bit, corrected a mistake and add some notes...
In my RMMV session, the spell works nicely, I can only select a friend unit, the state ManaLink is applied on both caster and target. Max MP and current MP are equalized by reciprocal addition. If one use a skill that consume MP, the other lost the same amount of MP. If one is hit by a MP Damage skill, the other lost the same amount of MP.
However, I'm sure I've missed many situation where you want the mp to be synchronized. That's why I ve told about a draft

tell me if it works, I really don't uderstand why it shouldn't I have the same plugin list that you (but with SkillCore)..

ManaLink State :
JavaScript:
<Custom Apply Effect>

if (target != origin){
// code below will run only for the non caster of the spell

  var oriMp = origin.mmp;     // get the cater max mp
  var tarMp = user.mmp;       // get the user max mp

  origin.addMaxMp(tarMp);     // add the max mp of user to caster max mp
  origin._mmpBuff = tarMp;    // store this value somewhere

  user.addMaxMp(oriMp);       // add the max mp of caster to user max mp
  user._mmpBuff = oriMp       // store the value

  var oriMp = origin.mp;      // get the caster current mp
  var tarMp = user.mp;        // get the user current mp
  user.gainMp(oriMp);         // increase user mp by caster mp
  origin.gainMp(tarMp);       // increase caster mp by user mp
}

origin._manaLink = user;      // store the user in caster
user._manaLink = origin;      // store the caster in user
</Custom Apply Effect>


<Custom Action End Effect>
if (user._manaLink.mp != user.mp){
  // the code below will run if manaLinked friend don't have the same MP.
  var dmg = user.mp - user._manaLink.mp // get the difference
  user._manaLink.gainMp(dmg) // modify mp by this difference
}
</Custom Action End Effect>

<Custom Respond Effect>
if (target._manaLink.mp != target.mp){
  var dmg = target.mp - target._manaLink.mp
  target._manaLink.gainMp(dmg)
}
</Custom Respond Effect>

<Custom Leave Effect>
var mpRatio = user.mp / user.mmp // get mp ratio
user._manaLink.removeState(22);  // remove state of manaLinked friend
user.addMaxMp(-user._mmpBuff);   // remove the max mp buff
user.setMp(user.mmp * mpRatio)   // scale current MP on new max.
</Custom Leave Effect>
 
Last edited:

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
1,064
Reaction score
1,326
First Language
Swedish
Primarily Uses
RMVXA
How silly of me. I forgot to add the SkillCore plugin. I guess I'm sleep deprived (we have a newborn baby in the house).

In any case, I tried it out and it kinda works. Thank you for helping out and even updating and commenting the code for me. Much appreciated.

I noticed that the synchronization is somewhat delayed though. If actor B casts a spell, the MP equal amount of MP is not subtracted from actor A until it's actor A's turn it seem? It doesn't happen right away.

An example would be this screenshot below:


Delilah and Melody are likened together with the Mana Lnk so they have double the max MP of Lydia. But Delilah also has a MP Regen state that restores 5% of max MP each turn. As you can see, Delilah has had her MP restored this turn but Melody has not (yet).

Is there a way to make the synchronization instantaneous for both actors no matter if it's MP being used, damaged or regenerated?
 

Lay

Veteran
Veteran
Joined
Jul 18, 2019
Messages
124
Reaction score
47
First Language
French
Primarily Uses
RMMV
Congratz for your newborn baby.
It's an amazing news that a panda recently got a baby !!!

Yes I've already noticed that the MP cost is delayed. This is because the notetag used run only when the battler action ends. The problem is, with the best of my knowledge, that it is not possible to run a portion of script all the time in a loop (could be usefull for perfect synchronization). So, the best I could do is to identify the closest moment to run the script.
You can try to insert the code in the <Custom Action End Effect> into other notetags provided by the yanfly BuffsStatesCore and see if you can find one that give better result.
You can also insert it in all the notetags the plugin provide.

For the cooldown requirement, you can try this notetag in the skill :
Code:
<Custom Requirement>
if (user._manaLink) value = false
</Custom Requirement>
Don't know if the skill disabling persist thought successive battles (I'm not in position to test right now :( sorry)

Well I did my best to simulate the closest synchronization but I didn't tackle the problem deep enough.
There are a lot of things to check from this draft and I can't really dedicate the time it requires to do it, sorry :(
 

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
1,064
Reaction score
1,326
First Language
Swedish
Primarily Uses
RMVXA
@Lay
No problem. You've been more than helpful~! Thanks a lot. And panda cub is indeed fantastic news! maybe you'll read about it in the news paper? :kaojoy:

I'll see what can be done to improve the skill from here on (unless some other rouge-scripter decides to swings by).

Here, take some virtual hugs as a thank you! :kaoluv::kaoluv:
 

Lay

Veteran
Veteran
Joined
Jul 18, 2019
Messages
124
Reaction score
47
First Language
French
Primarily Uses
RMMV
Ho and an other thing you may take into account for synchronization.

There is a difference between the Actor current parameters and what is drawn on the screen. Basically, you don't need the graphical interface for a fight, the only thing that matter is how the parameters in the different game object evolved according to actions.
And what is drawn on the screen is not refreshed all the time (otherwise, I let you imagine how laggy the game could be, drawing sprites thousand of times every sec...)

per exemple, if you want perfect synchronization for MP skill cost, you can use the following script inside a new plugin (I've placed at the bottom of my plugin list).

JavaScript:
Game_BattlerBase_paySkillCost = Game_BattlerBase.prototype.paySkillCost;
Game_BattlerBase.prototype.paySkillCost = function(skill) {
    Game_BattlerBase_paySkillCost.call(this,skill);
    if ( this.isStateAffected(22) ) this.runManaLinkPaySkillCost(skill);
};


Game_BattlerBase.prototype.runManaLinkPaySkillCost = function(skill) {
    console.log(this._manaLink)
    console.log("mp cost : "+this.skillMpCost(skill));
    this._manaLink._mp -= this.skillMpCost(skill);
    this._manaLink.refresh();
};
The first function called paySkillCost run every time a battler cast a skill.
then, an other function will run to refresh what is draw on the screen and you will see the mp decreasing.
In this script I've edited this function in order to run an extra piece of code if the condition isStateAffected(22) is true. state id 22 is my Mana Link state...
If true, then a new function will run that simulate what paySkillCost does but for the mana linked unit.

However, the engine never plan that someone can pay the skill cost for an other battler. Thus, the only refreshed battler is the one currently acting.
this is why here, in order to visualize the synchronization, I need to also refresh the Mana Linked friend.

In conslusion, sometimes, thing appear to not be synchronized according to what the player see on the screen. But this doesn't mean that data management didn't deal things synchronously.
 

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
1,064
Reaction score
1,326
First Language
Swedish
Primarily Uses
RMVXA
Hm, that’s some good information. I’ll have to test it out and see if ot can be improved further. I’ll try that mini-plugin you made first thing tomorrow morning as I’m super sleepy but it seems very promising.

I guess ”battler” refers to both actors and enemies so whoever does whatever, this code will run.
 

Lay

Veteran
Veteran
Joined
Jul 18, 2019
Messages
124
Reaction score
47
First Language
French
Primarily Uses
RMMV
if you're talking about "Game_BattlerBase", this is a parent object of Game_Battler itself a parent of Game_Enemy and Game_Actor.
The function paySkillCost is only define in Game_BattlerBase meaning that the function paySkillCost of children objects is inherited from Game_BattlerBase. Thus, you're right, this function will run for both enemies and actors.
The function will run runManaLinkPaySkillCost, a newly added function here, only if the battler is affected by state 22. Thus, the code is not executed all the time since it has to meet this condition.

For optimization, considering that enemies will never be affected by state 22, it could be better to define this function only for Game_Actor. Doing so, the function for Game_Enemy will be inherited from BattlerBase and the function for Game_Actor will be edited by our new definition. But honestly, this is just a condition test, it doesn't require tons of resources, you will not see any differences except if your game is played on a Nokia 3310. And on the other hand, you will maybe want to implement new skills or states that run a portion of code right after the skill cost has been payed even for enemies.


I just want to add that I did this plugin test just for fun. If you want to create thousands of states and skill directly by editing the code, there is a high risk to meet plugin incompatibilities issues. Per example here, if a plugin edit the paySkillCost function, then this stuff will be erased by the plugin or is versa. Thus, if you want to use it, it's at your own risk.
The first think to try, in my own opinion, is to find a notetag implement by yanfly BuffsStatesCore and don't forget to use user._manaLink.refresh() in it.
 
Last edited:

Parallax Panda

Got into VxAce ~2014 and never stopped...
Veteran
Joined
Oct 29, 2015
Messages
1,064
Reaction score
1,326
First Language
Swedish
Primarily Uses
RMVXA
I apparently never replied even though I read your post. I guess I’ll blame my sleep deprivation. :kaoswt:

I got it to work decently after a bit of experimentation. There might still be some oddities and kinks to hammer out, but if I notice something I’ll get to it later. Thanks for all the help!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top