Skip to content

Commit

Permalink
All New tdTypeChange
Browse files Browse the repository at this point in the history
  • Loading branch information
narumi147 committed Aug 28, 2024
1 parent a4cbb6c commit 806f5d1
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 58 deletions.
28 changes: 13 additions & 15 deletions lib/app/battle/functions/add_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,39 +187,37 @@ class AddState {
final tdTypeChangeIDs = baseTd.script?.tdTypeChangeIDs;
if (tdTypeChangeIDs == null || tdTypeChangeIDs.isEmpty) return null;

final validCardTypes = <CardType>[CardType.arts, CardType.buster, CardType.quick];
final cardIdTypeMap = {for (final c in validCardTypes) c.value: c};
final validCardIndex = <int>[CardType.arts.value, CardType.buster.value, CardType.quick.value];

if (excludeTypes != null && excludeTypes.isNotEmpty) {
validCardTypes.removeWhere((e) => excludeTypes.contains(e.value));
validCardIndex.removeWhere((e) => excludeTypes.contains(e));
}
final tdExistTypes =
cardIdTypeMap.entries.where((e) => e.key <= tdTypeChangeIDs.length).map((e) => e.value).toList();
validCardTypes.removeWhere((e) => !tdExistTypes.contains(e));
if (validCardTypes.isEmpty) return null;
validCardIndex.retainWhere((e) => e <= tdTypeChangeIDs.length);
if (validCardIndex.isEmpty) return null;

// in UI, Q/A/B order
CardType? targetType;
int? targetType;
if (buff.type == BuffType.tdTypeChangeArts) {
targetType = CardType.arts;
targetType = CardType.arts.value;
} else if (buff.type == BuffType.tdTypeChangeBuster) {
targetType = CardType.buster;
targetType = CardType.buster.value;
} else if (buff.type == BuffType.tdTypeChangeQuick) {
targetType = CardType.quick;
targetType = CardType.quick.value;
} else if (buff.type == BuffType.tdTypeChange) {
if (battleData.delegate?.tdTypeChange != null) {
targetType = await battleData.delegate!.tdTypeChange!(svt, validCardTypes);
targetType = await battleData.delegate!.tdTypeChange!(svt, validCardIndex);
} else if (battleData.mounted) {
targetType = await TdTypeChangeSelector.show(battleData, validCardTypes);
targetType = await TdTypeChangeSelector.show(battleData, tdTypeChangeIDs, validCardIndex,
svt.getBaseTD()?.script?.selectTreasureDeviceInfo?.getOrNull(svt.tdLv - 1));
if (targetType != null) {
battleData.replayDataRecord.tdTypeChanges.add(targetType);
}
}
}
NiceTd? targetTd;
if (targetType != null && validCardTypes.contains(targetType)) {
if (targetType != null && validCardIndex.contains(targetType)) {
// start from Q/A/B=1/2/3 -> index 0/1/2
final tdId = tdTypeChangeIDs.getOrNull(targetType.value - 1);
final tdId = tdTypeChangeIDs.getOrNull(targetType - 1);
if (tdId == null) return null;

final List<NiceTd?> tds = svt.isPlayer
Expand Down
2 changes: 1 addition & 1 deletion lib/app/battle/interactions/_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../models/battle.dart';
class BattleDelegate {
Future<int?> Function(BattleServantData? actor)? actWeight;
Future<int?> Function(BattleServantData? actor)? skillActSelect;
Future<CardType?> Function(BattleServantData? actor, List<CardType> tdTypes)? tdTypeChange;
Future<int?> Function(BattleServantData? actor, List<int> tdIndex)? tdTypeChange;
Future<BattleServantData?> Function(List<BattleServantData> targets)? ptRandom;
Future<bool> Function(bool curResult)? canActivate;
Future<int> Function(int curRandom)? damageRandom;
Expand Down
91 changes: 69 additions & 22 deletions lib/app/battle/interactions/td_type_change_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,86 @@ import '_dialog.dart';

class TdTypeChangeSelector extends StatelessWidget {
final BattleData battleData;
final List<CardType> tdTypes;
final Completer<CardType?> completer;
const TdTypeChangeSelector({super.key, required this.battleData, required this.tdTypes, required this.completer});
final List<int> tdTypeChangeIds;
final List<int> tdIndexes;
final SelectTreasureDeviceInfo? selectTdInfo;
final Completer<int?> completer;

static Future<CardType?> show(BattleData battleData, List<CardType> tdTypes) {
const TdTypeChangeSelector({
super.key,
required this.battleData,
required this.tdTypeChangeIds,
required this.tdIndexes,
required this.selectTdInfo,
required this.completer,
});

static Future<int?> show(
BattleData battleData, List<int> tdTypeChangeIds, List<int> tdIndexes, SelectTreasureDeviceInfo? selectTdInfo) {
if (!battleData.mounted) return Future.value();
return showUserConfirm<CardType>(
return showUserConfirm<int>(
context: battleData.context!,
builder: (context, completer) =>
TdTypeChangeSelector(battleData: battleData, tdTypes: tdTypes, completer: completer),
builder: (context, completer) => TdTypeChangeSelector(
battleData: battleData,
tdTypeChangeIds: tdTypeChangeIds,
tdIndexes: tdIndexes,
selectTdInfo: selectTdInfo,
completer: completer),
);
}

@override
Widget build(BuildContext context) {
final tdTypes = this.tdTypes.toList();
tdTypes.sort2((e) => [CardType.quick, CardType.arts, CardType.buster].indexOf(e));
final tdIndexes = this.tdIndexes.toList();
if (selectTdInfo == null) {
tdIndexes.sort2((e) => [CardType.quick.value, CardType.arts.value, CardType.buster.value].indexOf(e));
}
List<Widget> children = [];
final transl = Transl.miscScope('selectTreasureDeviceInfo');
for (final tdIndex in tdIndexes) {
final tdId = tdTypeChangeIds.getOrNull(tdIndex - 1);
SelectTdInfoTdChangeParam? tdInfo;
if (selectTdInfo != null) {
tdInfo = selectTdInfo!.treasureDevices.firstWhereOrNull((e) => e.id == tdId);
}
CardType cardType = tdInfo?.type ?? CardType.values.firstWhere((e) => e.value == tdIndex);
Widget child = CommandCardWidget(card: cardType, width: 80);
if (tdInfo != null && tdInfo.message.isNotEmpty) {
child = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
child,
Text(
transl(tdInfo.message).l,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 12),
),
],
);
}
children.add(Flexible(
child: InkWell(
onTap: () {
Navigator.of(context).pop(tdIndex);
battleData.battleLogger.action('${S.current.battle_select_effect}: $tdIndex/${cardType.name.toTitle()}'
' ${S.current.battle_np_card}');
},
child: child,
),
));
}

// String? title;
// if (selectTdInfo != null) {
// title = transl(selectTdInfo!.title).l;
// title = title.replaceAll('\n', '');
// }
return SimpleCancelOkDialog(
title: Text(S.current.battle_select_effect),
content: Row(
children: [
for (final tdType in tdTypes)
Flexible(
child: InkWell(
onTap: () {
Navigator.of(context).pop(tdType);
battleData.battleLogger.action('${S.current.battle_select_effect}: ${tdType.name.toUpperCase()}'
' ${S.current.battle_np_card}');
},
child: CommandCardWidget(card: tdType, width: 80),
),
)
],
mainAxisAlignment: MainAxisAlignment.center,
children: children,
),
hideOk: true,
hideCancel: true,
Expand Down
33 changes: 33 additions & 0 deletions lib/generated/models/gamedata/skill.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions lib/generated/models/userdata/battle.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/models/gamedata/buff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ class RelationOverwriteDetail {
Map<String, dynamic> toJson() => _$RelationOverwriteDetailToJson(this);
}

enum BuffCheckIndivType {
orType(0),
andType(1),
bothOrOnlyInGroup(2), // bothOrType
bothAndAllType(3), // bothAndType
bothOrAll(4),
;

const BuffCheckIndivType(this.value);
final int value;
}

@JsonSerializable(includeIfNull: false)
class BuffScript with DataScriptBase {
int? checkIndvType; // 1-AND, default-OR
Expand Down
39 changes: 39 additions & 0 deletions lib/models/gamedata/skill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ class SkillScript with DataScriptBase {
// TD script
List<int>? get tdTypeChangeIDs => toList('tdTypeChangeIDs');
List<int>? get excludeTdChangeTypes => toList('excludeTdChangeTypes');
final List<SelectTreasureDeviceInfo>? selectTreasureDeviceInfo;

// skill.script, not in skillLv.script
final bool? IgnoreValueUp;
Expand All @@ -870,6 +871,7 @@ class SkillScript with DataScriptBase {
additionalSkillLv?.isNotEmpty == true ||
additionalSkillActorType?.isNotEmpty == true ||
SelectAddInfo?.isNotEmpty == true ||
selectTreasureDeviceInfo?.isNotEmpty == true ||
tdTypeChangeIDs?.isNotEmpty == true ||
excludeTdChangeTypes?.isNotEmpty == true ||
IgnoreValueUp != null ||
Expand All @@ -893,6 +895,7 @@ class SkillScript with DataScriptBase {
this.SelectAddInfo,
// this.tdTypeChangeIDs,
// this.excludeTdChangeTypes,
this.selectTreasureDeviceInfo,
dynamic IgnoreValueUp,
List? IgnoreBattlePointUp,
this.tdChangeByBattlePoint,
Expand Down Expand Up @@ -968,6 +971,42 @@ class SkillSelectAddInfoBtnCond {
Map<String, dynamic> toJson() => _$SkillSelectAddInfoBtnCondToJson(this);
}

@JsonSerializable()
class SelectTreasureDeviceInfo {
final int dialogType;
final String title;
final String messageOnSelected;
final List<SelectTdInfoTdChangeParam> treasureDevices;

SelectTreasureDeviceInfo({
this.dialogType = 0,
this.title = "",
this.messageOnSelected = "",
this.treasureDevices = const [],
});

factory SelectTreasureDeviceInfo.fromJson(Map<String, dynamic> json) => _$SelectTreasureDeviceInfoFromJson(json);

Map<String, dynamic> toJson() => _$SelectTreasureDeviceInfoToJson(this);
}

@JsonSerializable()
class SelectTdInfoTdChangeParam {
final int id;
final CardType type;
final String message;

SelectTdInfoTdChangeParam({
this.id = 0,
this.type = CardType.none,
this.message = "",
});

factory SelectTdInfoTdChangeParam.fromJson(Map<String, dynamic> json) => _$SelectTdInfoTdChangeParamFromJson(json);

Map<String, dynamic> toJson() => _$SelectTdInfoTdChangeParamToJson(this);
}

@JsonSerializable()
class TdChangeByBattlePoint {
int battlePointId;
Expand Down
15 changes: 12 additions & 3 deletions lib/models/userdata/battle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,19 @@ enum SupportSvtType {

@JsonSerializable()
class BattleReplayDelegateData {
static List<int>? _readTdTypeChanges(Map data, String key) {
List? values = data[key];
if (values == null) return null;
return values.map<int>((e) {
if (e is int) return e;
return CardType.values.firstWhere((card) => card.name == e).value;
}).toList();
}

List<int?> actWeightSelections;
List<int?> skillActSelectSelections;
@JsonKey(unknownEnumValue: CardType.none)
List<CardType> tdTypeChanges;
@JsonKey(readValue: BattleReplayDelegateData._readTdTypeChanges)
List<int> tdTypeChanges;
List<int?> ptRandomIndexes;
List<bool> canActivateDecisions;
List<int> damageSelections;
Expand All @@ -990,7 +999,7 @@ class BattleReplayDelegateData {
BattleReplayDelegateData({
List<int?>? actWeightSelections,
List<int?>? skillActSelectSelections,
List<CardType>? tdTypeChanges,
List<int>? tdTypeChanges,
List<int?>? ptRandomIndexes,
List<bool>? canActivateDecisions,
List<int>? damageSelections,
Expand Down
Loading

0 comments on commit 806f5d1

Please sign in to comment.