This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
clone.go
117 lines (100 loc) · 2.63 KB
/
clone.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package models
// Clone returns a deep copy of the Stream struct. Any changes made to this copy
// should not affect the original struct.
func (s Stream) Clone() Stream {
s.Place = s.Place.Clone()
s.Enmity = s.Enmity.Clone()
if s.CraftingInfo != nil {
craftInfoClone := *s.CraftingInfo
s.CraftingInfo = &craftInfoClone
}
if len(s.EntitiesMap) > 0 {
entitiesMap := make(map[uint64]*Entity)
for id, ent := range s.EntitiesMap {
if ent == nil {
entitiesMap[id] = nil
continue
}
entClone := ent.Clone()
entitiesMap[id] = &entClone
}
s.EntitiesMap = entitiesMap
}
return s
}
// Clone returns a deep copy of the Place struct. Any changes made to this copy
// should not affect the original struct.
func (p Place) Clone() Place {
if len(p.Maps) > 0 {
maps := make([]MapInfo, len(p.Maps))
copy(maps, p.Maps)
p.Maps = maps
}
return p
}
// Clone returns a deep copy of the Enmity struct. Any changes made to this copy
// should not affect the original struct.
func (e Enmity) Clone() Enmity {
if len(e.TargetHateRanking) > 0 {
hateRankings := make([]HateRanking, len(e.TargetHateRanking))
copy(hateRankings, e.TargetHateRanking)
e.TargetHateRanking = hateRankings
}
if len(e.NearbyEnemyHate) > 0 {
enemyHate := make([]HateEntry, len(e.NearbyEnemyHate))
copy(enemyHate, e.NearbyEnemyHate)
e.NearbyEnemyHate = enemyHate
}
return e
}
// Clone returns a deep copy of the Entity struct. Any changes made to this copy
// should not affect the original struct.
func (e Entity) Clone() Entity {
if e.BNPCInfo != nil {
bNPCInfoClone := e.BNPCInfo.Clone()
e.BNPCInfo = &bNPCInfoClone
}
if e.LastAction != nil {
lastActionClone := e.LastAction.Clone()
e.LastAction = &lastActionClone
}
if e.CastingInfo != nil {
castingInfoClone := *e.CastingInfo
e.CastingInfo = &castingInfoClone
}
if len(e.Statuses) > 0 {
statuses := make([]*Status, len(e.Statuses))
for i, v := range e.Statuses {
if v == nil {
continue
}
vClone := *v
statuses[i] = &vClone
}
e.Statuses = statuses
}
return e
}
// Clone returns a deep copy of the NPCInfo struct. Any changes made to this copy
// should not affect the original struct.
func (n NPCInfo) Clone() NPCInfo {
if n.Name != nil {
nameClone := *n.Name
n.Name = &nameClone
}
if n.Size != nil {
sizeClone := *n.Size
n.Size = &sizeClone
}
return n
}
// Clone returns a deep copy of the Action struct. Any changes made to this copy
// should not affect the original struct.
func (a Action) Clone() Action {
if len(a.Effects) > 0 {
effects := make([]ActionEffect, len(a.Effects))
copy(effects, a.Effects)
a.Effects = effects
}
return a
}