Merge pull request #5222 from Crazylemon64/json_serialization2

Lets you convert people to text and back again
This commit is contained in:
TheDZD
2016-08-01 20:55:08 -04:00
committed by GitHub
12 changed files with 338 additions and 23 deletions
+109 -9
View File
@@ -8,7 +8,7 @@
//why are these here and not in human_defines.dm
//var/list/hud_list[10]
var/datum/species/species //Contains icon generation and language information, set during New().
var/embedded_flag //To check if we've need to roll for damage on movement while an item is imbedded in us.
var/embedded_flag //To check if we've need to roll for damage on movement while an item is imbedded in us.
var/obj/item/weapon/rig/wearing_rig // This is very not good, but it's much much better than calling get_rig() every update_canmove() call.
/mob/living/carbon/human/New(var/new_loc, var/new_species = null, var/delay_ready_dna = 0)
@@ -482,8 +482,8 @@
if(3 to 4) stunprob = 30
if(5 to 6) stunprob = 40
if(7 to 8) stunprob = 60
if(9) stunprob = 70
if(10) stunprob = 95
if(9) stunprob = 70
if(10) stunprob = 95
if(prob(stunprob))
M.powerlevel -= 3
@@ -944,7 +944,7 @@
for(var/datum/data/record/R in data_core.security)
if(R.fields["id"] == E.fields["id"])
if(hasHUD(usr,"security"))
var/t1 = sanitize(copytext(input("Add Comment:", "Sec. records", null, null) as message,1,MAX_MESSAGE_LEN))
var/t1 = sanitize(copytext(input("Add Comment:", "Sec. records", null, null) as message,1,MAX_MESSAGE_LEN))
if( !(t1) || usr.stat || usr.restrained() || !(hasHUD(usr,"security")) )
return
var/counter = 1
@@ -1075,7 +1075,7 @@
for(var/datum/data/record/R in data_core.medical)
if(R.fields["id"] == E.fields["id"])
if(hasHUD(usr,"medical"))
var/t1 = sanitize(copytext(input("Add Comment:", "Med. records", null, null) as message,1,MAX_MESSAGE_LEN))
var/t1 = sanitize(copytext(input("Add Comment:", "Med. records", null, null) as message,1,MAX_MESSAGE_LEN))
if( !(t1) || usr.stat || usr.restrained() || !(hasHUD(usr,"medical")) )
return
var/counter = 1
@@ -1285,8 +1285,8 @@
var/limb_path = organ_data["path"]
var/obj/item/organ/external/O = new limb_path(temp_holder)
if(H.get_limb_by_name(O.name)) //Check to see if the user already has an limb with the same name as the 'missing limb'. If they do, skip regrowth.
continue //In an example, this will prevent duplication of the mob's right arm if the mob is a Human and they have a Diona right arm, since,
//while the limb with the name 'right_arm' the mob has may not be listed in their species' bodyparts definition, it is still viable and has the appropriate limb name.
continue //In an example, this will prevent duplication of the mob's right arm if the mob is a Human and they have a Diona right arm, since,
//while the limb with the name 'right_arm' the mob has may not be listed in their species' bodyparts definition, it is still viable and has the appropriate limb name.
else
O = new limb_path(H) //Create the limb on the player.
O.owner = H
@@ -1704,7 +1704,7 @@
if((head_organ.species.name in tmp_hair.species_allowed) && (robohead.company in tmp_hair.models_allowed)) //Populate the list of available monitor styles only with styles that the monitor-head is allowed to use.
hair += i
var/new_style = input(src, "Select a monitor display", "Monitor Display", head_organ.h_style) as null|anything in hair
var/new_style = input(src, "Select a monitor display", "Monitor Display", head_organ.h_style) as null|anything in hair
if(incapacitated())
to_chat(src, "<span class='warning'>You were interrupted while changing your monitor display.</span>")
return
@@ -1909,7 +1909,7 @@
if(current_size >= STAGE_THREE)
var/list/handlist = list(l_hand, r_hand)
for(var/obj/item/hand in handlist)
if(prob(current_size * 5) && hand.w_class >= ((11-current_size)/2) && unEquip(hand))
if(prob(current_size * 5) && hand.w_class >= ((11-current_size)/2) && unEquip(hand))
step_towards(hand, src)
to_chat(src, "<span class='warning'>\The [S] pulls \the [hand] from your grip!</span>")
apply_effect(current_size * 3, IRRADIATE)
@@ -2031,3 +2031,103 @@
return 0
return .
/mob/living/carbon/human/serialize()
// Currently: Limbs/organs only
var/list/data = ..()
var/list/limbs_list = list()
var/list/organs_list = list()
var/list/equip_list = list()
data["limbs"] = limbs_list
data["iorgans"] = organs_list
data["equip"] = equip_list
data["dna"] = dna.serialize()
data["age"] = age
// No being naked
data["ushirt"] = undershirt
data["socks"] = socks
data["uwear"] = underwear
// Limbs
for(var/limb in organs_by_name)
var/obj/item/organ/O = organs_by_name[limb]
if(!O)
limbs_list[limb] = "missing"
continue
limbs_list[limb] = O.serialize()
// Internal organs/augments
for(var/organ in internal_organs)
var/obj/item/organ/O = organ
organs_list[O.name] = O.serialize()
// Equipment
equip_list.len = slots_amt
for(var/i = 1, i < slots_amt, i++)
var/obj/item/thing = get_item_by_slot(i)
if(thing != null)
equip_list[i] = thing.serialize()
return data
/mob/living/carbon/human/deserialize(list/data)
var/list/limbs_list = data["limbs"]
var/list/organs_list = data["iorgans"]
var/list/equip_list = data["equip"]
var/turf/T = get_turf(src)
if(!islist(data["limbs"]))
throw EXCEPTION("Expected a limbs list, but found none")
if(islist(data["dna"]))
dna.deserialize(data["dna"])
real_name = dna.real_name
name = real_name
UpdateAppearance()
set_species(dna.species)
age = data["age"]
undershirt = data["ushirt"]
underwear = data["uwear"]
socks = data["socks"]
for(var/obj/item/organ/internal/iorgan in internal_organs)
qdel(iorgan)
for(var/obj/item/organ/external/organ in organs)
qdel(organ)
for(var/limb in limbs_list)
// Missing means skip this part - it's missing
if(limbs_list[limb] == "missing")
continue
// "New" code handles insertion and DNA sync'ing
var/obj/item/organ/external/E = list_to_object(limbs_list[limb], src)
E.sync_colour_to_dna()
for(var/organ in organs_list)
// As above, "New" code handles insertion, DNA sync
list_to_object(organs_list[organ], src)
// De-serialize equipment
// #1: Jumpsuit
// #2: Outer suit
// #3+: Everything else
if(islist(equip_list[slot_w_uniform]))
var/obj/item/clothing/C = list_to_object(equip_list[slot_w_uniform], T)
equip_to_slot_if_possible(C, slot_w_uniform)
if(islist(equip_list[slot_wear_suit]))
var/obj/item/clothing/C = list_to_object(equip_list[slot_wear_suit], T)
equip_to_slot_if_possible(C, slot_wear_suit)
for(var/i = 1, i < slots_amt, i++)
if(i == slot_w_uniform || i == slot_wear_suit)
continue
if(islist(equip_list[i]))
var/obj/item/clothing/C = list_to_object(equip_list[i], T)
equip_to_slot_if_possible(C, i)
update_icons()
..()