private void Start() { _core = GetComponentInParent <MechaCoreComponent>(); if (_core) { Hardpoint hp = _core.hardpoints.Get(this); _core.EnableModule(hp); } }
/// <summary> /// Automatically grab the core system component. /// </summary> private void Start() { _core = GetComponent <MechaCoreComponent>(); // Called before component is registered. SystemStart(); // Register the system with the CoreSystemComponent _core.systems.Register(this); }
/// <summary>Frees up the Idle CPU and Energy from the ships systems.</summary> /// <returns> /// A <c>ModuleResult</c> to indicate the result of disabling the module. /// <list type="bullet"> /// <item> /// <description><c>AlreadyDisabled</c> if the module is already disabled.</description> /// </item> /// <item> /// <description><c>InvalidSystem</c> if the system reference is null already.</description> /// </item> /// </list> /// </returns> public virtual ModuleResult DisableModule(DisabledReason reason = DisabledReason.User) { if (!_isEnabled) { // Override any other disabled by reason if the user manually disabled the module, // so it won't auto re-enable. if (reason == DisabledReason.User) { _disabledBy = reason; } return(ModuleResult.AlreadyDisabled); } _isEnabled = false; _disabledBy = reason; if (_core != null) { // Make sure to disable any ActivatorComponents or ModifierComponents if (activator != null) { activator.Deactivate(this); } if (modifier != null) { modifier.Remove(); } // Reset the targeter if we have one if (targeter != null) { targeter.ResetToDefault(); } // Unload any loaded ammo if (ammoStore != null) { ammoStore.UnloadToInventory(); } // Deallocate the idle resources _core.computer.DeallocateCpu(idleComputerResources); _core.power.Free(idleEnergyDrain); _core = null; return(ModuleResult.Success); } else { return(ModuleResult.InvalidSystem); } }
/// <summary> /// Handles rendering custom GUI elements in the scene view for the ShipActorComponent. /// It renders the sockets and allows positioning of the sockets with the transform gizmos. /// </summary> private void OnSceneGUI() { ship = target as ShipActorComponent; shipTx = ship.transform; shipRot = (Tools.pivotRotation == PivotRotation.Local) ? shipTx.rotation : Quaternion.identity; MechaCoreComponent system = ship.GetComponent <MechaCoreComponent>(); Hardpoint[] hardpoints = system.hardpoints.GetAll(); for (int i = 0; i < hardpoints.Length; ++i) { SceneGUIHandleSocket(ref hardpoints[i]); } }
/// <summary> /// Virtual method that is used to destroy the module. This method /// destroys the GameObject the module is attached to and returns /// a reference to the prefab used to create the module, if any. /// </summary> public virtual GameObject DestroyModule() { GameObject prefab = this._prefab; this._core = null; this.ammoStore = null; this.activator = null; this.modifier = null; this.targeter = null; this._prefab = null; GameObject.Destroy(gameObject); return(prefab); }
/// <summary> /// Triggers the deactivation of the component. /// </summary> public ModuleResult Deactivate(ActorModule module) { // Make sure we're in the right state to Deactivate. if (!_isActive) { return(ModuleResult.AlreadyInactive); } ModuleResult result = OnDeactivation(module); MechaCoreComponent core = module.MechaCore; core.computer.DeallocateCpu(cpuResources); core.power.Free(energyUse); _isActive = false; return(result); }
// Use this for initialization void Start() { movement = GetComponent <ShipNavComponent>(); system = GetComponent <MechaCoreComponent>(); if (system != null && test != null) { system.InstallModuleIn(system.hardpoints.Get("TEST_P1"), test); } // Add the handlers for the computer system. system.computer.onResourcesChanged += HandleComputerResourcesChanged; system.computer.onDamaged += HandleComputerDamaged; // Add the handlers for the power system. system.power.onEnergyChanged += HandleEnergyChanged; system.power.onDamaged += HandlePowerDamaged; }
/// <summary>Allocates the idle CPU and reserves the idle energy required.</summary> /// <returns> /// A <c>ModuleResult</c> to indicate the result of disabling the module. /// <list type="bullet"> /// <item> /// <description><c>AlreadyEnabled</c> if the module is already enabled.</description> /// </item> /// <item> /// <description><c>InvalidSystem</c> if the system reference is null.</description> /// </item> /// <item> /// <description><c>InsufficientPower</c> if there is not enough power to enable the module.</description> /// </item> /// <item> /// <description><c>InsufficientCpu</c> if there is not enough CPU to enable the module.</description> /// </item> /// </list> /// </returns> public virtual ModuleResult EnableModule() { if (_isEnabled) { return(ModuleResult.AlreadyEnabled); } if (_core == null) { _core = gameObject.GetComponentInParent <MechaCoreComponent>(); if (_core == null) { return(ModuleResult.InvalidSystem); } } if (_core.computer.AllocateCpu(idleComputerResources)) { if (_core.power.Reserve(idleEnergyDrain)) { _isEnabled = true; _disabledBy = DisabledReason.NotDisabled; // If we have an ammoStore component, then do an initial ammo load. if (ammoStore != null) { ammoStore.LoadFromInventory(); } return(ModuleResult.Success); } else // Not enough power to enable module. { _core.computer.DeallocateCpu(idleComputerResources); _core = null; return(ModuleResult.InsufficientPower); } } else // Not enough CPU to enable module. { _core = null; return(ModuleResult.InsufficientCpu); } }
/// <summary> /// Trigger the activation for the component. /// </summary> public ModuleResult Activate(ActorModule module) { // Do the basic checks to see if we can activate it. if (_isActive) { return(ModuleResult.AlreadyActive); } else if (_cooldown != null) { return(ModuleResult.InCooldownState); } // Check if we are using ammo, and if so, that we have some. AmmoStoreComponent ammoStore = module.ammoStore; if (ammoStore != null && !ammoStore.HasAmmo) { if (ammoStore.IsReloading) { return(ModuleResult.Reloading); } else { return(ModuleResult.NoAmmo); } } // Try and allocate the resources for the activation. MechaCoreComponent core = module.MechaCore; if (!core.computer.AllocateCpu(cpuResources)) { return(ModuleResult.InsufficientCpu); } if ((isContinuous && !core.power.Reserve(energyUse)) || (!core.power.Consume(energyUse))) { core.computer.DeallocateCpu(cpuResources); return(ModuleResult.InsufficientPower); } // All good, so do the activation. _isActive = true; ModuleResult result = OnActivation(module); if (result != ModuleResult.Success) { core.computer.DeallocateCpu(cpuResources); if (isContinuous) { core.power.Free(energyUse); } _isActive = false; } else if (!isContinuous) { core.computer.DeallocateCpu(cpuResources); _isActive = false; StartCooldown(); } return(result); }