-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathsoullink.dm
160 lines (127 loc) · 4.54 KB
/
soullink.dm
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/mob/living
var/list/ownedSoullinks //soullinks we are the owner of
var/list/sharedSoullinks //soullinks we are a/the sharer of
/mob/living/Destroy()
for(var/s in ownedSoullinks)
var/datum/soullink/S = s
S.ownerDies(FALSE)
qdel(s) //If the owner is destroy()'d, the soullink is destroy()'d
ownedSoullinks = null
for(var/s in sharedSoullinks)
var/datum/soullink/S = s
S.sharerDies(FALSE)
S.removeSoulsharer(src) //If a sharer is destroy()'d, they are simply removed
sharedSoullinks = null
return ..()
//Keeps track of a Mob->Mob (potentially Player->Player) connection
//Can be used to trigger actions on one party when events happen to another
//Eg: shared deaths
//Can be used to form a linked list of mob-hopping
//Does NOT transfer with minds
/datum/soullink
var/mob/living/soulowner
var/mob/living/soulsharer
var/id //Optional ID, for tagging and finding specific instances
/datum/soullink/Destroy()
if(soulowner)
LAZYREMOVE(soulowner.ownedSoullinks, src)
soulowner = null
if(soulsharer)
LAZYREMOVE(soulsharer.sharedSoullinks, src)
soulsharer = null
return ..()
/datum/soullink/proc/removeSoulsharer(mob/living/sharer)
if(soulsharer == sharer)
soulsharer = null
LAZYREMOVE(sharer.sharedSoullinks, src)
//Used to assign variables, called primarily by soullink()
//Override this to create more unique soullinks (Eg: 1->Many relationships)
//Return TRUE/FALSE to return the soullink/null in soullink()
/datum/soullink/proc/parseArgs(mob/living/owner, mob/living/sharer)
if(!owner || !sharer)
return FALSE
soulowner = owner
soulsharer = sharer
LAZYADD(owner.ownedSoullinks, src)
LAZYADD(sharer.sharedSoullinks, src)
return TRUE
//Runs after /living death()
//Override this for content
/datum/soullink/proc/ownerDies(gibbed, mob/living/owner)
//Runs after /living death()
//Override this for content
/datum/soullink/proc/sharerDies(gibbed, mob/living/owner)
//Quick-use helper
/proc/soullink(typepath, ...)
var/datum/soullink/S = new typepath()
if(S.parseArgs(arglist(args.Copy(2, 0))))
return S
/////////////////
// MULTISHARER //
/////////////////
//Abstract soullink for use with 1 Owner -> Many Sharer setups
/datum/soullink/multisharer
var/list/soulsharers
/datum/soullink/multisharer/parseArgs(mob/living/owner, list/sharers)
if(!owner || !LAZYLEN(sharers))
return FALSE
soulowner = owner
soulsharers = sharers
LAZYADD(owner.ownedSoullinks, src)
for(var/l in sharers)
var/mob/living/L = l
LAZYADD(L.sharedSoullinks, src)
return TRUE
/datum/soullink/multisharer/removeSoulsharer(mob/living/sharer)
LAZYREMOVE(soulsharers, sharer)
/////////////////
// SHARED FATE //
/////////////////
//When the soulowner dies, the soulsharer dies, and vice versa
//This is intended for two players(or AI) and two mobs
/datum/soullink/sharedfate/ownerDies(gibbed, mob/living/owner)
if(soulsharer)
soulsharer.death(gibbed)
/datum/soullink/sharedfate/sharerDies(gibbed, mob/living/sharer)
if(soulowner)
soulowner.death(gibbed)
/////////////////
// Demon Bind //
/////////////////
//When the soulowner dies, the soulsharer dies, but NOT vice versa
//This is intended for two players(or AI) and two mobs
/datum/soullink/oneway/ownerDies(gibbed, mob/living/owner)
if(soulsharer)
soulsharer.dust(FALSE)
/////////////////
// SHARED BODY //
/////////////////
//When the soulsharer dies, they're placed in the soulowner, who remains alive
//If the soulowner dies, the soulsharer is killed and placed into the soulowner (who is still dying)
//This one is intended for one player moving between many mobs
/datum/soullink/sharedbody/ownerDies(gibbed, mob/living/owner)
if(soulowner && soulsharer)
if(soulsharer.mind)
soulsharer.mind.transfer_to(soulowner)
soulsharer.death(gibbed)
/datum/soullink/sharedbody/sharerDies(gibbed, mob/living/sharer)
if(soulowner && soulsharer && soulsharer.mind)
soulsharer.mind.transfer_to(soulowner)
//////////////////////
// REPLACEMENT POOL //
//////////////////////
//When the owner dies, one of the sharers is placed in the owner's body, fully healed
//Sort of a "winner-stays-on" soullink
//Gibbing ends it immediately
/datum/soullink/multisharer/replacementpool/ownerDies(gibbed, mob/living/owner)
if(LAZYLEN(soulsharers) && !gibbed) //let's not put them in some gibs
var/list/souls = shuffle(soulsharers.Copy())
for(var/l in souls)
var/mob/living/L = l
if(L.stat != DEAD && L.mind)
L.mind.transfer_to(soulowner)
soulowner.revive(TRUE, TRUE)
L.death(FALSE)
//Lose your claim to the throne!
/datum/soullink/multisharer/replacementpool/sharerDies(gibbed, mob/living/sharer)
removeSoulsharer(sharer)