- Joined
- Jul 23, 2017
- Messages
- 3
- Reaction score
- 0
- First Language
- English
- Primarily Uses
- RMMV
Hey all! This is my first post on these forums so I hope I'm in the right place.
In my game, you have to learn each of 6 elements as you progress through the game. In the style of Pokémon or Rock Paper Scissors, each element has elements that it's effective or ineffective against. As the player learns new elements, I'd like the effectiveness (Element Rate) across each element to be averaged out between all the elements the player knows.
For example, the player knows Air, Earth, and Fire. Lightning is effective against Air, ineffective against Earth, and normal against Fire. I want these to average out to be normal, or a 100% Lightning element rate for the player.
I have some knowledge of programming, but not too much with JavaScript specifically. Below is my code, and for the life of me, I can't figure out how to make it work the way I want it to.
If anyone with more experience could help me figure this out, I'd greatly appreciate it! Thanks!
In my game, you have to learn each of 6 elements as you progress through the game. In the style of Pokémon or Rock Paper Scissors, each element has elements that it's effective or ineffective against. As the player learns new elements, I'd like the effectiveness (Element Rate) across each element to be averaged out between all the elements the player knows.
For example, the player knows Air, Earth, and Fire. Lightning is effective against Air, ineffective against Earth, and normal against Fire. I want these to average out to be normal, or a 100% Lightning element rate for the player.
I have some knowledge of programming, but not too much with JavaScript specifically. Below is my code, and for the life of me, I can't figure out how to make it work the way I want it to.
If anyone with more experience could help me figure this out, I'd greatly appreciate it! Thanks!
Code:
//=============================================================================
// Element Rate Calculator
// by 02409tt
// Date: 5/29/18
//=============================================================================
/*:
* @plugindesc Element Rate Calculator
* @author 02409tt
*
* @param ---Global Rates---
* @default
*
* @param Normal
* @desc The element rate of normal effectiveness.
* @parent ---Global Rates---
* @default 1
*
* @param Strong
* @desc The element rate of strong effectiveness.
* @parent ---Global Rates---
* @default 1.25
*
* @param Weak
* @desc The element rate of weak effectiveness.
* @parent ---Global Rates---
* @default .75
*
* @param ---Elements---
* @default
*
* @param Earth
* @type struct<Elements>
* @parent ---Elements---
* @desc Adjust the effectiveness of elements against the Earth element here.
* @default {"Earth":"Weak","Fire":"Strong","Air":"Weak","Water":"Strong","Poison":"Weak","Lightning":"Weak"}
*
* @param Fire
* @type struct<Elements>
* @parent ---Elements---
* @desc Adjust the effectiveness of elements against the Fire element here.
* @default {"Earth":"Weak","Fire":"Weak","Air":"Strong","Water":"Strong","Poison":"Normal","Lightning":"Normal"}
*
* @param Air
* @type struct<Elements>
* @parent ---Elements---
* @desc Adjust the effectiveness of elements against the Air element here.
* @default {"Earth":"Weak","Fire":"Weak","Air":"Weak","Water":"Normal","Poison":"Normal","Lightning":"Strong"}
*
* @param Water
* @type struct<Elements>
* @parent ---Elements---
* @desc Adjust the effectiveness of elements against the Water element here.
* @default {"Earth":"Weak","Fire":"Weak","Air":"Normal","Water":"Weak","Poison":"Strong","Lightning":"Strong"}
*
* @param Poison
* @type struct<Elements>
* @parent ---Elements---
* @desc Adjust the effectiveness of elements against the Poison element here.
* @default {"Earth":"Strong","Fire":"Normal","Air":"Normal","Water":"Weak","Poison":"Weak","Lightning":"Normal"}
*
* @param Lightning
* @type struct<Elements>
* @parent ---Elements---
* @desc Adjust the effectiveness of elements against the Lightning element here.
* @default {"Earth":"Strong","Fire":"Normal","Air":"Weak","Water":"Weak","Poison":"Normal","Lightning":"Weak"}
*
* @param ---Switches---
* @default
*
* @param Earth Learned ID
* @desc The ID of the switch that is ON when Earth is learned.
* @parent ---Switches---
* @default 28
*
* @param Fire Learned ID
* @desc The ID of the switch that is ON when Fire is learned.
* @parent ---Switches---
* @default 29
*
* @param Air Learned ID
* @desc The ID of the switch that is ON when Air is learned.
* @parent ---Switches---
* @default 30
*
* @param Water Learned ID
* @desc The ID of the switch that is ON when Water is learned.
* @parent ---Switches---
* @default 31
*
* @param Poison Learned ID
* @desc The ID of the switch that is ON when Poison is learned.
* @parent ---Switches---
* @default 32
*
* @param Lightning Learned ID
* @desc The ID of the switch that is ON when Lightning is learned.
* @parent ---Switches---
* @default 33
*/
/*~struct~Elements:
*
* @param Earth
* @type text
* @desc Effectiveness of Earth against other elements.
* @default Normal
*
* @param Fire
* @type text
* @desc Effectiveness of Fire against other elements.
* @default Normal
*
* @param Air
* @type text
* @desc Effectiveness of Air against other elements.
* @default Normal
*
* @param Water
* @type text
* @desc Effectiveness of Water against other elements.
* @default Normal
*
* @param Poison
* @type text
* @desc Effectiveness of Poison against other elements.
* @default Normal
*
* @param Lightning
* @type text
* @desc Effectiveness of Lightning against other elements.
* @default Normal
*/
(function() {
var params = PluginManager.parameters('ElementRateCalculator');
function elementRateUpdater(earthValue, fireValue, airValue, waterValue, poisonValue, lightningValue) {
$gameParty.leader().currentClass().traits.push({
code: 11,
dataId: 1,
value: earthValue});
$gameParty.leader().currentClass().traits.push({
code: 11,
dataId: 2,
value: fireValue});
$gameParty.leader().currentClass().traits.push({
code: 11,
dataId: 3,
value: airValue});
$gameParty.leader().currentClass().traits.push({
code: 11,
dataId: 4,
value: waterValue});
$gameParty.leader().currentClass().traits.push({
code: 11,
dataId: 5,
value: poisonValue});
$gameParty.leader().currentClass().traits.push({
code: 11,
dataId: 6,
value: lightningValue});
};
function elementRateInitialize() {
elementRateUpdater(1, 1, 1, 1, 1, 1);
};
function elementRateManager() {
var stringToValue = {
'Normal': Number(params['Normal']),
'Strong': Number(params['Strong']),
'Weak': Number(params['Weak'])
};
var possibleLearnedElements = {
'earthLearned': $gameSwitches.value(Number(params['Earth Learned ID'])),
'fireLearned': $gameSwitches.value(Number(params['Fire Learned ID'])),
'airLearned': $gameSwitches.value(Number(params['Air Learned ID'])),
'waterLearned': $gameSwitches.value(Number(params['Water Learned ID'])),
'poisonLearned': $gameSwitches.value(Number(params['Poison Learned ID'])),
'lightningLearned': $gameSwitches.value(Number(params['Lightning Learned ID']))
};
var learnedElements = [];
if (possibleLearnedElements['earthLearned'] == true) {
learnedElements.push('Earth');
};
if (possibleLearnedElements['fireLearned'] == true) {
learnedElements.push('Fire');
};
if (possibleLearnedElements['airLearned'] == true) {
learnedElements.push('Air');
};
if (possibleLearnedElements['waterLearned'] == true) {
learnedElements.push('Water');
};
if (possibleLearnedElements['poisonLearned'] == true) {
learnedElements.push('Poison');
};
if (possibleLearnedElements['lightningLearned'] == true) {
learnedElements.push('Lightning');
};
var numberLearned = learnedElements.length;
var earthAddition = 0;
var fireAddition = 0;
var airAddition = 0;
var waterAddition = 0;
var poisonAddition = 0;
var lightningAddition = 0;
for (var i = 0; i < numberLearned; i++) {
var interactions = JSON.parse(params[learnedElements[i]]);
earthAddition = stringToValue[interactions.Earth] + earthAddition;
fireAddition = stringToValue[interactions.Fire] + fireAddition;
airAddition = stringToValue[interactions.Air] + airAddition;
waterAddition = stringToValue[interactions.Water] + waterAddition;
poisonAddition = stringToValue[interactions.Poison] + poisonAddition;
lightningAddition = stringToValue[interactions.Lightning] + lightningAddition;
};
overallEarthRate = earthAddition/numberLearned;
overallFireRate = fireAddition/numberLearned;
overallAirRate = airAddition/numberLearned;
overallWaterRate = waterAddition/numberLearned;
overallPoisonRate = poisonAddition/numberLearned;
overallLightningRate = lightningAddition/numberLearned;
};
// Plugin Commands //
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command == "ElementRate") {
var subCommand = args[0];
if (subCommand == "update") {
elementRateUpdater(1,1,1,1,1,1);
elementRateManager();
elementRateUpdater(overallEarthRate, overallFireRate, overallAirRate, overallWaterRate, overallPoisonRate, overallLightningRate);
};
if (subCommand == "set") {
earthValue = Number(args[1]);
fireValue = Number(args[2]);
airValue = Number(args[3]);
waterValue = Number(args[4]);
poisonValue = Number(args[5]);
lightningValue = Number(args[6]);
elementRateUpdater(earthValue, fireValue, airValue, waterValue, poisonValue, lightningValue);
};
};
};
})();

