/// <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> /// 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); }