public static BodyPartRecord Copy(this BodyPartRecord record, BodyPartRecord parent) { BodyPartRecord newRecord; if (record is DroidChassisPartRecord) { newRecord = new DroidChassisPartRecord(); DroidChassisPartRecord oldRec = record as DroidChassisPartRecord; ((DroidChassisPartRecord)newRecord).bodyPosition = oldRec.bodyPosition; } else { newRecord = new BodyPartRecord(); } newRecord.def = record.def; newRecord.customLabel = record.customLabel; newRecord.height = record.height; newRecord.depth = record.depth; newRecord.coverage = record.coverage; if (parent != null) { newRecord.parent = parent; } if (record.parts.Count > 0) { foreach (var part in record.parts) { newRecord.parts.Add(part.Copy(newRecord)); } } return(newRecord); }
public List <PartCustomisePack> GetPartCustomisePacks(DroidCustomiseGroupDef group, bool silentFail = false) { if (!partsGrouped.Keys.Contains(group)) { List <PartCustomisePack> list = new List <PartCustomisePack>(); foreach (var li in group.Parts) { //Make a new part customise pack var baseParts = GetBasePartAt(li.ChassisPoint, li.BodyPosition).ToList(); if (baseParts.Count > 0) { foreach (var partRecord in baseParts) { if (partRecord is DroidChassisPartRecord) { //Check the body position. If the position passed is undefined, don't care what position the part has DroidChassisPartRecord droidRecord = partRecord as DroidChassisPartRecord; if (li.BodyPosition == BodyPosition.Undefined || droidRecord.bodyPosition == li.BodyPosition) { DroidChassisPartDef dcpd = droidRecord.defAsDroidDef; if (dcpd == null) { throw new InvalidOperationException($"{partRecord.body.defName} contains a bodypart which is not type DroidChassisPartDef: {partRecord.def.defName}"); } var newPCP = new PartCustomisePack(li.ChassisPoint, dcpd, droidRecord.bodyPosition); list.Add(newPCP); } } else { //Otherwise, just make a new part with undefined body position DroidChassisPartDef dcpd = partRecord.GetChassisPartDef(); if (dcpd == null) { throw new InvalidOperationException($"{partRecord.body.defName} contains a bodypart which is not type DroidChassisPartDef: {partRecord.def.defName}"); } var newPCP = new PartCustomisePack(li.ChassisPoint, dcpd); list.Add(newPCP); } } } else { if (!silentFail) { Log.Error($"Unable to find any base parts at ChassisPoint: {li.ChassisPoint} and BodyPosition: {li.BodyPosition} for BaseBodyDef: {BaseBodyDef.defName}"); } } } partsGrouped.Add(group, list); return(partsGrouped[group]); } else { return(partsGrouped[group]); } }
public BodyDef GenerateBodyDef(bool addToDatabase) { BodyDef bd = BaseBodyDef.Copy(BaseBodyDef.defName + this.GetHashCode().ToString()); var list = (from t in Parts where t.Part.BasePart == false select t).ToList(); if (list.Count > 0) { foreach (var part in list) { var list2 = (from t in bd.AllParts where t.def is DroidChassisPartDef && ((DroidChassisPartDef)t.def).ChassisType == part.Part.ChassisType && ((DroidChassisPartDef)t.def).ChassisPoint == part.Part.ChassisPoint select t).ToList(); if (list2.Count > 0) { foreach (var record in list2) { if (record is DroidChassisPartRecord) { DroidChassisPartRecord dRec = record as DroidChassisPartRecord; if (dRec.bodyPosition == part.BodyPosition) { record.def = part.Part; } } else { record.def = part.Part; } if (!record.customLabel.NullOrEmpty()) { if (record.customLabel.StartsWith("left")) { record.customLabel = $"left {record.def.label}"; } else if (record.customLabel.StartsWith("right")) { record.customLabel = $"right {record.def.label}"; } } } } } } if (addToDatabase) { DefDatabase <BodyDef> .Add(bd); } return(bd); }