1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import 'package:x_haven_server/core/models/monster.dart';
class SummonModel {
final String name;
final StatValue health;
final int move;
final int attack;
final int range;
final int level;
final String gfx;
final int standees;
const SummonModel(
this.name,
this.health,
this.move,
this.attack,
this.range,
this.level,
this.gfx,
this.standees,
);
factory SummonModel.fromJson(Map<String, dynamic> data, String key) {
final String name = key;
StatValue health = const IntStatValue(2); //default to 2 not to die
if (data.containsKey('health')) {
health = StatValue.fromJson(data['health']);
}
int move = 0;
if (data.containsKey('move')) {
move = data['move'];
}
int attack = 0;
if (data.containsKey('attack')) {
attack = data['attack'];
}
int range = 0;
if (data.containsKey('range')) {
range = data['range'];
}
int level = 0;
if (data.containsKey('level')) {
level = data['level'];
}
String gfx = "";
if (data.containsKey('gfx')) {
gfx = data['gfx'];
}
int standees = 1;
if (data.containsKey('standees')) {
standees = data['standees'];
}
return SummonModel(name, health, move, attack, range, level, gfx, standees);
}
}
|