Skip to content

Commit

Permalink
Support classboard command spell effect
Browse files Browse the repository at this point in the history
  • Loading branch information
narumi147 committed Sep 18, 2024
1 parent 2c17fb5 commit f84e10b
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 17 deletions.
6 changes: 6 additions & 0 deletions lib/app/battle/functions/function_executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class FunctionExecutor {
battleData.functionResults.add(null);
continue;
}
final actMasterGenderType = dataVal.ActMasterGenderType ?? 0;
if (actMasterGenderType != 0) {
if (!(db.curUser.isGirl ? actMasterGenderType == 2 : actMasterGenderType == 1)) {
continue;
}
}

final updatedResult = await FunctionExecutor.executeFunction(
battleData,
Expand Down
11 changes: 11 additions & 0 deletions lib/app/battle/models/skill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ class BattleSkillInfoData {
if (curSkill.type == SkillType.active) {
await activator?.activateBuff(battleData, BuffAction.functionSkillAfter);
}
for (final svt in wouldAffectTargets) {
if (type == SkillInfoType.commandSpell) {
final csId = curSkill.functions.firstOrNull?.svals.firstOrNull?.CommandSpellId;
if (csId == 1 || csId == 9) {
await svt.activateBuff(battleData, BuffAction.functionClassboardCommandSpellAfter, skillInfo: this);
}
}
}
return true;
}

Expand Down Expand Up @@ -328,6 +336,7 @@ class CommonCustomSkills {
'Rate': 1000,
'Value': 1000,
'Unaffected': 1,
"CommandSpellId": 1,
})
],
)
Expand All @@ -352,6 +361,7 @@ class CommonCustomSkills {
'Rate': 3000,
'Value': 10000,
'Unaffected': 1,
"CommandSpellId": 9,
})
],
)
Expand All @@ -375,6 +385,7 @@ class CommonCustomSkills {
'Rate': 5000,
'Value': 10000,
'Unaffected': 1,
"CommandSpellId": 1001,
})
],
)
Expand Down
34 changes: 26 additions & 8 deletions lib/app/battle/models/svt_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1809,22 +1809,40 @@ class BattleServantData {
for (final buff in collectBuffsPerAction(battleBuff.validBuffsActiveFirst, buffAction)) {
final List<NiceTrait> selfTraits = fetchSelfTraits(buffAction, buff, this, cardData: card);
final List<NiceTrait>? otherTraits = fetchOtherTraits(buffAction, buff, other, cardData: card);

if (await buff.shouldActivateBuff(
battleData,
selfTraits,
opTraits: otherTraits,
skillInfoType: skillInfo?.type,
)) {
final skillId = buff.param;
BaseSkill? skill = db.gameData.baseSkills[skillId];
skill ??= await showEasyLoading(() => AtlasApi.skill(skillId), mask: true);
if (skill == null) {
BaseSkill? skill;
if (buff.buff.type == BuffType.classboardCommandSpellAfterFunction) {
final spellId = buff.param;
final targetCommandSpell = db.gameData.classBoards.values
.expand((e) => e.squares)
.map((e) => e.targetCommandSpell)
.firstWhereOrNull((e) => e?.id == spellId);
if (targetCommandSpell != null) {
skill = targetCommandSpell.toSkill();
}
if (skill == null) {
battleData.battleLogger.debug(
'Buff ID [${buff.buff.id}]: ${S.current.command_spell}(classboard) [$spellId] ${S.current.not_found}');
continue;
}
battleData.battleLogger
.debug('Buff ID [${buff.buff.id}]: ${S.current.skill} [$skillId] ${S.current.not_found}');
continue;
.function('$lBattleName - ${buff.buff.lName.l} ${S.current.command_spell}(classboard) [$spellId]');
} else {
final skillId = buff.param;
skill = db.gameData.baseSkills[skillId];
skill ??= await showEasyLoading(() => AtlasApi.skill(skillId), mask: true);
if (skill == null) {
battleData.battleLogger
.debug('Buff ID [${buff.buff.id}]: ${S.current.skill} [$skillId] ${S.current.not_found}');
continue;
}
battleData.battleLogger.function('$lBattleName - ${buff.buff.lName.l} ${S.current.skill} [$skillId]');
}
battleData.battleLogger.function('$lBattleName - ${buff.buff.lName.l} ${S.current.skill} [$skillId]');
await FunctionExecutor.executeFunctions(
battleData,
skill.functions,
Expand Down
1 change: 1 addition & 0 deletions lib/models/gamedata/buff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ enum BuffType {
toFieldChangeField(10001),
toFieldAvoidBuff(10002),
toFieldSubIndividualityField(10003),
classboardCommandSpellAfterFunction(200001),
;

final int value;
Expand Down
58 changes: 49 additions & 9 deletions lib/models/gamedata/class_board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,66 @@ class ClassBoard with RouteInfo {

NiceSkill? toSkill(ClassBoardPlan v) {
Map<int, NiceSkill> skills = {};
Map<int, int> levels = {};
Map<int, int> skillLvs = {};
Map<int, ClassBoardCommandSpell> spells = {};
Map<int, int> spellLvs = {};
for (final square in squares) {
final targetSkill = square.targetSkill;
if (targetSkill == null) continue;
if (v.enhancedSquares.contains(square.id)) {
skills.putIfAbsent(targetSkill.id, () => targetSkill);
levels.addNum(targetSkill.id, square.upSkillLv);
final targetCommandSpell = square.targetCommandSpell;
if (targetSkill != null) {
if (v.enhancedSquares.contains(square.id)) {
skills.putIfAbsent(targetSkill.id, () => targetSkill);
skillLvs.addNum(targetSkill.id, square.upSkillLv);
}
} else if (targetCommandSpell != null) {
if (v.enhancedSquares.contains(square.id)) {
spells.putIfAbsent(targetCommandSpell.id, () => targetCommandSpell);
spellLvs.addNum(targetCommandSpell.id, square.upSkillLv);
}
}
}
List<NiceFunction> functions = [];
for (final skillId in levels.keys) {
for (final skillId in skillLvs.keys) {
final skill = skills[skillId]!;
final lv = levels[skillId]!.clamp(0, skill.maxLv);
final lv = skillLvs[skillId]!.clamp(0, skill.maxLv);
if (lv == 0) continue;
for (final func in skill.functions) {
final func2 = NiceFunction.fromJson(func.toJson());
func2.svals = [func.svals[lv - 1]];
functions.add(func2);
}
}
for (final spellId in spellLvs.keys) {
final spell = spells[spellId]!;
final lv = spellLvs[spellId]!.clamp(0, spell.functions.firstOrNull?.svals.length ?? 0);
if (lv == 0 || spell.functions.isEmpty) continue;
final func = spell.functions.first;
functions.add(NiceFunction(
funcId: -spellId,
funcType: FuncType.addState,
funcTargetType: FuncTargetType.self,
funcPopupText: spell.name,
funcPopupIcon: func.funcPopupIcon,
buffs: [
Buff(
id: -spellId,
type: BuffType.classboardCommandSpellAfterFunction,
name: spell.name,
detail: spell.detail,
icon: func.funcPopupIcon,
)
],
svals: [
DataVals({
"Turn": -1,
"Count": -1,
"Rate": 5000,
// "ClassBoardId": id,
"Value": spellId,
"Value2": lv,
})
]));
}
if (functions.isEmpty) return null;
return NiceSkill(
id: -(1000000 + DateTime.now().timestamp % 1000000),
Expand Down Expand Up @@ -214,7 +254,7 @@ class ClassBoardSquare {
@JsonSerializable()
class ClassBoardCommandSpell {
int id;
int commandSpellId;
int commandSpellId; // current only dump csId=1 one, but not csId=9. They are the same, but should always check csId
// int lv;
String name;
String detail;
Expand All @@ -234,7 +274,7 @@ class ClassBoardCommandSpell {

NiceSkill toSkill({String? icon}) {
return NiceSkill(
id: -commandSpellId,
id: -id,
name: name,
unmodifiedDetail: detail,
icon: icon ?? ClassBoardSquare.csIcon(db.curUser.isGirl),
Expand Down
13 changes: 13 additions & 0 deletions lib/models/gamedata/const_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ class ConstGameData {
this.config = const ConstDataConfig(),
this.destinyOrderSummons = const [],
}) : buffTypeActionMap = {} {
if (buffActions.isNotEmpty) {
buffActions[BuffAction.functionClassboardCommandSpellAfter] = BuffActionInfo(
limit: BuffLimit.none,
plusTypes: [BuffType.classboardCommandSpellAfterFunction],
minusTypes: [],
baseParam: 0,
baseValue: 0,
isRec: true,
plusAction: BuffAction.none,
maxRate: [0],
);
}
for (final entry in buffActions.entries) {
for (final type in [...entry.value.plusTypes, ...entry.value.minusTypes]) {
buffTypeActionMap.putIfAbsent(type, () => []).add(entry.key);
Expand Down Expand Up @@ -1245,6 +1257,7 @@ enum BuffAction {
functionStepInAfter(142),
shortenSkillAfterUseSkill(143),
pierceSpecialInvincible(144),
functionClassboardCommandSpellAfter(301),
;

final int value;
Expand Down
2 changes: 2 additions & 0 deletions lib/models/gamedata/vals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ class DataVals {
int? get AddCount => _vals['AddCount'];
int? get RateCount => _vals['RateCount'];
int? get DropRateCount => _vals['DropRateCount'];
// custom fields
int? get CommandSpellId => _vals['CommandSpellId'];

List<T>? _parseObjList<T>(String key, T Function(Map<String, dynamic> json) fromJson) {
final v = _vals[key];
Expand Down

0 comments on commit f84e10b

Please sign in to comment.