/** * construct hull based on manifest */ void Construct(HullManifest manifest) { this.manifest = manifest; foreach (ExternalModuleManifest extModManifest in manifest.modules) { HullSlot slot; if (!slots.TryGetValue(extModManifest.position, out slot)) { slot = Instantiate(slotPrefab) as HullSlot; slot.transform.parent = transform; slot.transform.localPosition = extModManifest.position; slots.Add(extModManifest.position, slot); } ExternalConstructionModule extMod = Instantiate(game.GetConstructionModulePrefab(extModManifest.type)) as ExternalConstructionModule; extMod.transform.localRotation = extModManifest.rotation; extMod.stats = extModManifest.stats; extMod.hitPointsLeft = extModManifest.hitPointsLeft; extMod.manifest = extModManifest; Equip(extMod, slot); if (extMod is HullConstructionModule) { if (extModManifest.internalModule != null) { InternalConstructionModule intMod = Instantiate(game.GetConstructionModulePrefab(extModManifest.internalModule.type)) as InternalConstructionModule; intMod.stats = extModManifest.internalModule.stats; intMod.hitPointsLeft = extModManifest.internalModule.hitPointsLeft; intMod.SetContents(extModManifest.internalModule.contents); intMod.manifest = extModManifest.internalModule; Equip(intMod, (HullConstructionModule)extMod); } } } }
public void Unequip(InternalConstructionModule module) { if (module.hullModule == null) { return; } if (module is BatteryConstructionModule) { energy.batteries.Remove((BatteryConstructionModule)module); } else if (module is PowerConstructionModule) { energy.powerPlants.Remove((PowerConstructionModule)module); } else if (module is FuelConstructionModule) { fuel.fuelTanks.Remove((FuelConstructionModule)module); } else if (module is CrewConstructionModule) { crew.crewPods.Remove((CrewConstructionModule)module); } HullConstructionModule hullModule = module.hullModule; hullModule.internalModule = null; module.hullModule = null; hullModule.Activate(); module.OnUnequip(); }
/** * Wipe out everything */ public void Clear() { // delete current stuff if (slots != null) { foreach (var pair in slots) { var slot = pair.Value; if (slot.module != null) { ExternalConstructionModule extMod = slot.module; if (slot.module is HullConstructionModule) { InternalConstructionModule intMod = ((HullConstructionModule)extMod).internalModule; if (intMod != null) { Unequip(intMod); Destroy(intMod.gameObject); } } Unequip(extMod); Destroy(extMod.gameObject); } Destroy(slot.gameObject); } } slots = new Dictionary <Vector3, HullSlot>(); hullModules = new Dictionary <Vector3, HullConstructionModule>(); }
public void Unequip(InternalConstructionModule module, HullConstructionModule hullModule) { if (module.hullModule != hullModule) { return; } Unequip(module); }
/** * Save state to manifest */ public HullManifest CreateManifest() { HullManifest manifest = new HullManifest(); manifest.position = this.manifest.position; manifest.rotation = this.manifest.rotation; manifest.velocity = this.manifest.velocity; manifest.angularVelocity = this.manifest.angularVelocity; manifest.constellation = this.manifest.constellation; manifest.star = this.manifest.star; manifest.planet = this.manifest.planet; foreach (KeyValuePair <Vector3, HullSlot> pair in slots) { // external module ExternalConstructionModule extMod = pair.Value.module; if (extMod == null) { continue; } ExternalModuleManifest extModManifest = new ExternalModuleManifest( extMod.hullSlot.transform.localPosition, extMod.transform.localRotation ); extModManifest.name = extMod.manifest.name; extModManifest.type = (ModuleType)extMod.GetType().GetField("type").GetRawConstantValue(); extModManifest.stats = extMod.stats; extModManifest.hitPointsLeft = extMod.hitPointsLeft; // internal module manifest.modules.Add(extModManifest); if (extMod is HullConstructionModule) { InternalConstructionModule intMod = ((HullConstructionModule)extMod).internalModule; if (intMod != null) { InternalModuleManifest intModManifest = new InternalModuleManifest(extMod.hullSlot); intModManifest.name = intMod.manifest.name; intModManifest.type = (ModuleType)intMod.GetType().GetField("type").GetRawConstantValue(); intModManifest.stats = intMod.stats; intModManifest.hitPointsLeft = intMod.hitPointsLeft; intModManifest.contents = intMod.GetContents(); extModManifest.internalModule = intModManifest; } } } this.manifest = manifest; return(manifest); }
public void Equip(InternalConstructionModule module, HullConstructionModule hullModule) { if (module.hullModule == hullModule) { module.transform.localPosition = Vector2.zero; return; } if (!hullModule.available) { return; } if (module.hullModule != null) { Unequip(module); } module.transform.parent = hullModule.transform; module.transform.localPosition = Vector2.zero; hullModule.internalModule = module; module.hullModule = hullModule; hullModule.Deactivate(); inventory.RemoveModule(module); module.OnEquip(); if (module is BatteryConstructionModule) { energy.batteries.Add((BatteryConstructionModule)module); } else if (module is PowerConstructionModule) { energy.powerPlants.Add((PowerConstructionModule)module); } else if (module is FuelConstructionModule) { fuel.fuelTanks.Add((FuelConstructionModule)module); } else if (module is CrewConstructionModule) { crew.crewPods.Add((CrewConstructionModule)module); } }