Skip to content

Commit

Permalink
Add Critical Buff (old PR MotocalDevelopers#245) and Sun-Touched Para…
Browse files Browse the repository at this point in the history
…side (MotocalDevelopers#250)

* Add Critical Buff and Sun-Touched Paraside

Recreate Branch. 'cuz whoopsie.

- Add Sun-Touched Paraside (烈日の楽園), Alanaan (アラナン).

* Fix missing curly bracket

* various

- remove redundant code in global.js and a missing semicolon
- identitation in profile.js
- jp text for 烈日の楽園説明

* Update global_logic.js

missed one line deletion

* Update global_logic.js

Fix backward compatibility

* remove state change in render()

and,
- correct some indentations.
- correct mismatched text (translate)
- minor logic change (reduce cases)

* correct usage of event handlers.

* Update global_logic.js

* Add CriticalBuffList component

This component will reduce 3 clone codes in profile, chara

Added optional Count change behavior, truncate=false option
that does not truncate array when count was changed.

`trancate=false` and set `initialCount` can keep modified array
but only "count" length available.

- Usage storybook -> components -> CriticaBuffList
  - properties
    - criticalArray (required)
    - label (default: criticalBuff) ... used for key prefix
    - maxCount (default: 20)
    - truncate (default: true)
    - initialCount (default: 0)
    - onBlur
    - onCountChange

* Add missing changes

for previous commit, my git operation mistake.

* Remove unnecessary code

They were already moved to CriticalListBuff component

* Update global_logic.js

* Update global_logic.js

- correct damageUP (shiva's passive/etc)

* Update global_logic.js

+

* Update translate.js

- add missing translation
  • Loading branch information
happypurpleduck authored and OrkunKocyigit committed Jun 27, 2019
1 parent de98d27 commit 5af0a40
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 29 deletions.
27 changes: 27 additions & 0 deletions src/chara.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var {Label, Checkbox, FormControl, InputGroup, FormGroup, Button, ButtonGroup, P
var CreateClass = require('create-react-class');
var {RegisteredChara} = require('./template.js');
var GlobalConst = require('./global_const.js');
var {CriticalBuffList} = require('./components.js');

// inject GlobalConst...
var elementRelation = GlobalConst.elementRelation;
Expand Down Expand Up @@ -313,6 +314,8 @@ var Chara = CreateClass({
EXLBKonshin: 0,
EXLBDA: 0,
EXLBTA: 0,
criticalBuffCount: 0,
criticalBuff: [],
};
},
componentDidMount: function () {
Expand Down Expand Up @@ -393,6 +396,18 @@ var Chara = CreateClass({
handleEvent: function (key, e) {
var newState = this.state;
newState[key] = e.target.value;

if (key == "criticalBuffCount") {
if (newState.criticalBuff.length > newState.criticalBuffCount) {
newState.criticalBuff = newState.criticalBuff.slice(0, newState.criticalBuffCount);
}
for (let i = 0; i < newState.criticalBuffCount; i++) {
if (newState.criticalBuff[i] == undefined) {
newState.criticalBuff[i] = {"value": 0.0, "attackRatio": 0.0};
}
}
}

this.setState(newState)
},
handleSelectEvent: function (key, e) {
Expand All @@ -403,6 +418,7 @@ var Chara = CreateClass({
} else {
newState[key] = e.target.value;
}

this.setState(newState);
this.props.onChange(this.props.id, newState, false);
},
Expand Down Expand Up @@ -606,6 +622,17 @@ var Chara = CreateClass({
onChange={this.handleSelectEvent.bind(this, "otherBuff2")}>{selector.buffLevel}</FormControl><InputGroup.Addon>%</InputGroup.Addon>
</InputGroup></td>
</tr>,
<tr key="criticalBuff">
<th className="bg-primary">{intl.translate("クリティカルバフ", locale)}</th>
<td>
<CriticalBuffList locale={locale}
onBlur={this.handleOnBlur.bind(this, null)}
onCountChange={(count) => this.setState({criticalBuffCount: count})}
label="criticalBuff"
criticalArray={this.state.criticalBuff}
initialCount={this.state.criticalBuffCount} />
</td>
</tr>,
<tr key="daBuff">
<th className="bg-primary">{intl.translate("DAバフ", locale)}</th>
<td><InputGroup><FormControl componentClass="select" value={this.state.daBuff}
Expand Down
134 changes: 134 additions & 0 deletions src/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"use strict";

const React = require('react');
const {FormControl, InputGroup} = require('react-bootstrap');
const intl = require('./translate.js');
const {selector} = require('./global_const.js');


/**
* Dynamic List component for Critical Buff inputs
*/
class CriticalBuffList extends React.Component {

constructor(props) {
super(props);

this.state = {
count: props.initialCount || props.criticalArray.length,
array: props.criticalArray
};
}

/**
* Notify event
*
* @param {number} count
*/
handleOnCountChange(count) {
if (this.props.onCountChange) {
this.props.onCountChange(count);
}
}

/**
* Notify event
*
* @param {string} key ... UNUSED
* @param {Object} e ... Event object
*/
handleOnBlur(key, e){
console.log(this, key, e)
if (this.props.onBlur) {
this.props.onBlur(e);
}
}

/**
* @param {string} key
* @param {number} idx
* @param {Object} e ... Event object
*
* when key is "count":
* Change array's size if needed.
*
* when key is "value" or "attackRatio":
* update value
*
*/
handleOnChange(key, idx, e) {
let array = this.props.criticalArray;

if (key === "count") {
const count = e.target.value;

while (count > array.length) {
array.push({value: 0.0, attackRatio: 0.0});
}
if (array.length > count && this.props.truncate) {
array.length = count;
}

this.setState({count: count, array: array});
this.handleOnCountChange(count);
} else if (key === "value" || key === "attackRatio") {
const val = parseInt(e.target.value);

array[idx][key] = val / 100;

this.setState({array: array});
}
}

/**
* Render Count form and list of Value/AttackRatio forms
*
* @return {ReactElement}
*/
render() {
const {state: {count, array}, props: {locale, label, maxCount}} = this;

return <React.Fragment>
<strong>{intl.translate("数", locale)}</strong>
<FormControl type="number"
min="0" max={maxCount} value={count}
onBlur={this.handleOnBlur.bind(this)}
onChange={this.handleOnChange.bind(this, "count", null)}/>
{array.slice(0, count).map(({value,attackRatio}, idx) =>
<div key={label + idx}>
<strong>{intl.translate("発動率", locale)}#{idx+1}</strong>
<InputGroup>
<FormControl
componentClass="select"
value={Math.round(100*value)}
onBlur={this.handleOnBlur.bind(this)}
onChange={this.handleOnChange.bind(this, "value", idx)}>
{selector.criticalRateLevel}
</FormControl>
<InputGroup.Addon>%</InputGroup.Addon>
</InputGroup>
<strong>{intl.translate("倍率", locale)}#{idx+1}</strong>
<InputGroup>
<FormControl
componentClass="select"
value={Math.round(100*attackRatio)}
onBlur={this.handleOnBlur.bind(this)}
onChange={this.handleOnChange.bind(this, "attackRatio", idx)}>
{selector.buffLevel}
</FormControl>
<InputGroup.Addon>%</InputGroup.Addon>
</InputGroup>
</div>)}
</React.Fragment>;
}
}

CriticalBuffList.defaultProps = {
maxCount: 20,
initialCount: 0,
truncate: true,
label: "criticalBuff",
};


module.exports.CriticalBuffList = CriticalBuffList;
4 changes: 4 additions & 0 deletions src/global_const.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ var buffLevelList = [
-5, -10, -15, -20, -25, -30, -35, -40, -45, -50, -55, -60, -65, -70, -75, -80, -85, -90, -95, -100
];
var ougiGageUpOugiBuffLevelList = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,];
var criticalRateLevelList = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100];
var ougiRatioList = [0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0];
var masterATKList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18];
var masterHPList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
Expand Down Expand Up @@ -2645,6 +2646,9 @@ module.exports.selector.buffLevel = buffLevelList.map(function (opt) {
module.exports.selector.ougiGageUpOugiBuffLevel = ougiGageUpOugiBuffLevelList.map(function (opt) {
return <option value={opt} key={opt}>{opt}</option>;
});
module.exports.selector.criticalRateLevel = criticalRateLevelList.map(function (opt) {
return <option value={opt} key={opt}>{opt}</option>;
});
module.exports.selector.ougiRatio = ougiRatioList.map(function (opt) {
return <option value={opt} key={opt}>{opt}</option>;
});
Expand Down
59 changes: 33 additions & 26 deletions src/global_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ module.exports.calcCriticalArray = function (_normalCritical, _magnaCritical, no
var probability = [];
// Store the corresponding magnification
var damageRatio = [];
//'ignore' any undefined
_normalCritical = _normalCritical == undefined ? 0 : _normalCritical;
_magnaCritical = _magnaCritical == undefined ? 0 : _magnaCritical;
normalOtherCritical = normalOtherCritical.filter((val) => val != undefined);

var magnaCritical = 0.01 * _magnaCritical * summon["magna"];
if (magnaCritical > 1.0) {
Expand Down Expand Up @@ -488,6 +492,7 @@ module.exports.calcBasedOneSummon = function (summonind, prof, buff, totals) {
if (key == "Djeeta") {
normalCoeff += 0.01 * totals["Djeeta"]["job"].kouzinBonus;
}
normalCoeff += prof.retsujitsuNoRakuen ? 0.25 : 0;

var normalHaisuiCoeff = 1.0 + 0.01 * totals[key]["normalHaisui"] * totalSummon["zeus"];
normalHaisuiCoeff += 0.01 * totals[key]["normalOtherHaisui"];
Expand Down Expand Up @@ -603,36 +608,34 @@ module.exports.calcBasedOneSummon = function (summonind, prof, buff, totals) {
var daRate = Math.min(1.0, Math.floor(totalDA * 100) / 100);
var expectedAttack = 3.0 * taRate + (1.0 - taRate) * (2.0 * daRate + (1.0 - daRate));

var damageUP = totals[key]["charaUniqueDamageUP"];
if (totals[key]["typeBonus"] == 1.5) {
// Supplemental damage rise support ability does not overlap with Tenshi skill (the strongest effect overwrites the lesser)
var damageUP = Math.max(totals[key]["tenshiDamageUP"], totals[key]["charaDamageUP"]);
damageUP += Math.max(totals[key]["tenshiDamageUP"], totals[key]["charaDamageUP"]);
damageUP += 0.01 * totalSummon["tenshiDamageUP"];
damageUP += totals[key]["charaUniqueDamageUP"];

// Generate normal critical skill arrays.
var LBCriticalArray = getLBCriticalArray(totals[key]["LB"]);
var EXLBCriticalArray = getEXLBCriticalArray(totals[key]["EXLB"]["Critical"]);
var normalOtherCriticalBuffArray = totals[key]["normalOtherCriticalBuff"];
var normalOtherCriticalArray = totals[key]["normalOtherCritical"].concat(LBCriticalArray, EXLBCriticalArray, normalOtherCriticalBuffArray);

var criticalArray = module.exports.calcCriticalArray(totals[key]["normalCritical"], totals[key]["magnaCritical"], normalOtherCriticalArray, totalSummon);
var criticalRatio = module.exports.calcCriticalRatio(criticalArray)
} else if (prof.enemyElement == "non-but-critical") {
// Processing in the case of "Non (with critical)"
var damageUP = 0.0;

var LBCriticalArray = getLBCriticalArray(totals[key]["LB"]);
var EXLBCriticalArray = getEXLBCriticalArray(totals[key]["EXLB"]["Critical"]);
var normalOtherCriticalBuffArray = totals[key]["normalOtherCriticalBuff"];
var normalOtherCriticalArray = totals[key]["normalOtherCritical"].concat(LBCriticalArray, EXLBCriticalArray, normalOtherCriticalBuffArray);

var criticalArray = module.exports.calcCriticalArray(totals[key]["normalCritical"], totals[key]["magnaCritical"], normalOtherCriticalArray, totalSummon);
var criticalRatio = module.exports.calcCriticalRatio(criticalArray)
} else {
var damageUP = 0.0;
var criticalArray = {};
var criticalRatio = 1.0
}

var criticalArray = {};
var criticalRatio = 1.0;
if (totals[key]["typeBonus"] == 1.5
|| prof.enemyElement == "non-but-critical"
|| prof.retsujitsuNoRakuen
) {
let LBCriticalArray = getLBCriticalArray(totals[key]["LB"]);
let EXLBCriticalArray = getEXLBCriticalArray(totals[key]["EXLB"]["Critical"]);
let normalOtherCriticalBuffArray = totals[key]["normalOtherCriticalBuff"];
let normalOtherCriticalArray = totals[key]["normalOtherCritical"].concat(
LBCriticalArray,
EXLBCriticalArray,
normalOtherCriticalBuffArray,
totals[key]["criticalBuff"] || [],
buff["criticalBuff"]
);

criticalArray = module.exports.calcCriticalArray(totals[key]["normalCritical"], totals[key]["magnaCritical"], normalOtherCriticalArray, totalSummon);
criticalRatio = module.exports.calcCriticalRatio(criticalArray);
}

//Enemy (Elemental) Resistance if not superior element.
var enemyResistance = totals[key]["typeBonus"] == 1.5 ? 0 : Math.max(0, Math.min(1.0, 0.01 * parseFloat(prof.enemyResistance)));

Expand Down Expand Up @@ -1371,6 +1374,7 @@ module.exports.getTotalBuff = function (prof) {
damageLimit: 0.0,
ougiDamageLimit: 0.0,
chainNumber: 1,
criticalBuff: [],
uplift: 0,
supplementalDamageBuff: 0,
//enemyBuffCount: 0,
Expand Down Expand Up @@ -1407,6 +1411,7 @@ module.exports.getTotalBuff = function (prof) {
totalBuff["zenithChainDamageLimit"] += zenithChainDamageLimit[prof.zenithChainDamageLimitBonus] != undefined ? zenithChainDamageLimit[prof.zenithChainDamageLimitBonus] : 0;
totalBuff["zenithElement"] += zenithElement[prof.zenithElementBonus] != undefined ? zenithElement[prof.zenithElementBonus] : 0;
totalBuff["zenithDamageLimit"] += zenithDamageLimit[prof.zenithDamageLimitBonus] != undefined ? zenithDamageLimit[prof.zenithDamageLimitBonus] : 0;
totalBuff["criticalBuff"] = prof.criticalBuff != undefined ? prof.criticalBuff : [];
totalBuff["supplementalDamageBuff"] += parseInt(prof.supplementalDamageBuff);

return totalBuff
Expand Down Expand Up @@ -2241,6 +2246,7 @@ module.exports.getInitialTotals = function (prof, chara, summon) {
charaDamageUP: 0,
tenshiDamageUP: 0,
charaUniqueDamageUP: 0,
criticalBuff: prof.personalCriticalBuff != undefined ? prof.personalCriticalBuff : [],
supplementalDamageBuff: 100 * djeetaBuffList['personalSupplementalDamageBuff'],
supplementalThirdHit: [],
covenant: null,
Expand Down Expand Up @@ -2402,6 +2408,7 @@ module.exports.getInitialTotals = function (prof, chara, summon) {
charaDamageUP: 0,
tenshiDamageUP: 0,
charaUniqueDamageUP: 0,
criticalBuff: chara[i].criticalBuff,
supplementalDamageBuff: 100 * charaBuffList['supplementalDamageBuff'],
supplementalThirdHit: [],
covenant: null,
Expand Down
Loading

0 comments on commit 5af0a40

Please sign in to comment.