private void OnTroopDestroyed(uint entityID, bool remove) { DeployedTroop deployedTroop = this.deployedTroops[entityID]; if (deployedTroop.AbilityTimer != 0u) { Service.Get <SimTimerManager>().KillSimTimer(deployedTroop.AbilityTimer); deployedTroop.AbilityTimer = 0u; } if (deployedTroop.CoolDownTimer != 0u) { Service.Get <SimTimerManager>().KillSimTimer(deployedTroop.CoolDownTimer); deployedTroop.CoolDownTimer = 0u; } this.StopTrackingShooterClips(deployedTroop); if (remove) { this.deployedTroops.Remove(entityID); if (this.deployedTroops.Count == 0) { this.EnsureEvents(false); } if (this.autoActivatedEntityIDs != null && this.autoActivatedEntityIDs.Contains(entityID)) { this.autoActivatedEntityIDs.Remove(entityID); } if (this.userActivatedEntityIDs != null && this.userActivatedEntityIDs.Contains(entityID)) { this.userActivatedEntityIDs.Remove(entityID); } } }
public void OnTroopSpawned(SmartEntity troopEntity) { if (troopEntity != null && troopEntity.TroopComp != null) { ITroopDeployableVO troopType = troopEntity.TroopComp.TroopType; TroopAbilityVO abilityVO = troopEntity.TroopComp.AbilityVO; if (abilityVO != null) { if (this.deployedTroops == null) { this.deployedTroops = new Dictionary <uint, DeployedTroop>(); } if (this.deployedTroops.Count == 0) { this.EnsureEvents(true); } DeployedTroop deployedTroop = new DeployedTroop(troopType.Uid, troopEntity); this.deployedTroops.Add(troopEntity.ID, deployedTroop); if (abilityVO.Auto) { if (abilityVO.CooldownOnSpawn) { this.StartCoolDown(deployedTroop, abilityVO); return; } this.QueueAutoActivateAbility(troopEntity.ID); } } } }
private void ActivateAbilityViewEffects(DeployedTroop deployedTroop, TroopAbilityVO ability) { SmartEntity entity = deployedTroop.Entity; GameObjectViewComponent gameObjectViewComp = entity.GameObjectViewComp; if (gameObjectViewComp == null) { return; } if (ability.AltGunLocators != null && ability.AltGunLocators.Length != 0) { gameObjectViewComp.SwitchGunLocators(true); } GameObject mainGameObject = gameObjectViewComp.MainGameObject; mainGameObject.transform.localScale = Vector3.one * ability.PersistentScaling; if (!string.IsNullOrEmpty(ability.PersistentEffect)) { ITroopDeployableVO troopType = entity.TroopComp.TroopType; TransformComponent transformComp = entity.TransformComp; deployedTroop.LightSaberHitFx = new LightSaberHitEffect(ability.ProjectileType.SplashRadius, transformComp.CenterGridX(), transformComp.CenterGridZ(), mainGameObject.transform, ability.PersistentEffect, troopType.Faction); } if (deployedTroop.WeaponTrail != null && deployedTroop.WeaponTrailActivateLifetime > 0f) { deployedTroop.WeaponTrail.ChangeLifeTime(deployedTroop.WeaponTrailActivateLifetime); } }
private void StartCoolDown(DeployedTroop deployedTroop, TroopAbilityVO abilityVO) { if (abilityVO.CoolDownTime == 0u) { this.OnCoolDownTimer(0u, deployedTroop); return; } deployedTroop.CoolDownTimer = Service.Get <SimTimerManager>().CreateSimTimer(abilityVO.CoolDownTime, false, new TimerDelegate(this.OnCoolDownTimer), deployedTroop); }
private void StartTrackingShooterClips(DeployedTroop deployedTroop, int clipCount) { if (deployedTroop.Activated && clipCount > 0) { deployedTroop.AbilityClipCount = clipCount; deployedTroop.Entity.ShooterComp.ShouldCountClips = true; if (this.numActivatedTroopsWithClipCounts++ == 0) { Service.EventManager.RegisterObserver(this, EventId.ShooterClipUsed); } } }
private void OnCoolDownTimer(uint id, object cookie) { DeployedTroop deployedTroop = (DeployedTroop)cookie; deployedTroop.CoolDownTimer = 0u; SmartEntity entity = deployedTroop.Entity; Service.Get <EventManager>().SendEvent(EventId.TroopAbilityCoolDownComplete, entity); TroopAbilityVO abilityVO = entity.TroopComp.AbilityVO; if (abilityVO.Auto) { this.QueueAutoActivateAbility(entity.ID); } }
private void StopTrackingShooterClips(DeployedTroop deployedTroop) { if (deployedTroop.Activated && deployedTroop.AbilityClipCount > 0) { SmartEntity entity = deployedTroop.Entity; if (entity != null && entity.ShooterComp != null) { entity.ShooterComp.ShouldCountClips = false; } if (--this.numActivatedTroopsWithClipCounts == 0) { Service.EventManager.UnregisterObserver(this, EventId.ShooterClipUsed); } } }
public bool ActivateAbility(uint entityID) { if (!this.deployedTroops.ContainsKey(entityID)) { return(false); } DeployedTroop deployedTroop = this.deployedTroops[entityID]; SmartEntity entity = deployedTroop.Entity; if (entity.StateComp.CurState == EntityState.Dying) { return(false); } TroopComponent troopComp = entity.TroopComp; TroopAbilityVO abilityVO = troopComp.AbilityVO; if (abilityVO == null || (abilityVO.ClipCount == 0 && abilityVO.Duration == 0u)) { return(false); } deployedTroop.Activated = true; troopComp.SetVOData(abilityVO, abilityVO); troopComp.IsAbilityModeActive = true; troopComp.UpdateWallAttackerTroop = false; ShooterComponent shooterComp = entity.ShooterComp; if (shooterComp != null) { shooterComp.SetVOData(abilityVO); } this.ResetTargetAndSendEvent(entity, true); if (!deployedTroop.EffectsSetup) { this.SetupAbilityViewEffects(deployedTroop, abilityVO); deployedTroop.EffectsSetup = true; } this.ActivateAbilityViewEffects(deployedTroop, abilityVO); if (abilityVO.ClipCount > 0) { this.StartTrackingShooterClips(deployedTroop, abilityVO.ClipCount); } else { deployedTroop.AbilityTimer = Service.Get <SimTimerManager>().CreateSimTimer(abilityVO.Duration, false, new TimerDelegate(this.OnAbilityTimer), deployedTroop); } return(true); }
private void DeactivateAbility(DeployedTroop deployedTroop) { if (deployedTroop == null) { Service.Get <StaRTSLogger>().Error("TroopAbilityConroller.DeactivateAbility: DeployedTroop Null"); return; } deployedTroop.AbilityTimer = 0u; SmartEntity entity = deployedTroop.Entity; if (entity == null) { Service.Get <StaRTSLogger>().Error("TroopAbilityConroller.DeactivateAbility: SmartEntity troop = Null"); return; } TroopComponent troopComp = entity.TroopComp; if (troopComp == null) { Service.Get <StaRTSLogger>().Error("TroopAbilityConroller.DeactivateAbility: troopComp = Null"); return; } troopComp.SetVOData(troopComp.OriginalTroopShooterVO, troopComp.OriginalSpeedVO); troopComp.IsAbilityModeActive = false; ShooterComponent shooterComp = entity.ShooterComp; if (shooterComp != null) { shooterComp.SetVOData(shooterComp.OriginalShooterVO); } TroopAbilityVO abilityVO = troopComp.AbilityVO; if (abilityVO == null) { Service.Get <StaRTSLogger>().Error("TroopAbilityConroller.DeactivateAbility: TroopAbilityVO abilityVO = Null"); return; } this.ResetTargetAndSendEvent(entity, false); this.DeactivateAbilityViewEffects(deployedTroop); this.StopTrackingShooterClips(deployedTroop); deployedTroop.Activated = false; this.StartCoolDown(deployedTroop, abilityVO); }
private void DeactivateAbilityViewEffects(DeployedTroop deployedTroop) { SmartEntity entity = deployedTroop.Entity; GameObjectViewComponent gameObjectViewComp = entity.GameObjectViewComp; if (gameObjectViewComp == null) { return; } gameObjectViewComp.SwitchGunLocators(false); gameObjectViewComp.MainGameObject.transform.localScale = Vector3.one; if (deployedTroop.LightSaberHitFx != null) { deployedTroop.LightSaberHitFx.StopFxAndDestroy(); deployedTroop.LightSaberHitFx = null; } if (deployedTroop.WeaponTrail != null && deployedTroop.WeaponTrailDeactivateLifetime > 0f) { deployedTroop.WeaponTrail.ChangeLifeTime(deployedTroop.WeaponTrailDeactivateLifetime); } }
private void SetupAbilityViewEffects(DeployedTroop deployedTroop, TroopAbilityVO abilityVO) { GameObjectViewComponent gameObjectViewComp = deployedTroop.Entity.GameObjectViewComp; if (gameObjectViewComp == null) { return; } WeaponTrail componentInChildren = gameObjectViewComp.MainGameObject.GetComponentInChildren <WeaponTrail>(); if (componentInChildren != null) { deployedTroop.WeaponTrail = componentInChildren; float[] weaponTrailFxParams = abilityVO.WeaponTrailFxParams; if (weaponTrailFxParams != null && weaponTrailFxParams.Length >= 2) { deployedTroop.WeaponTrailActivateLifetime = weaponTrailFxParams[0]; deployedTroop.WeaponTrailDeactivateLifetime = weaponTrailFxParams[1]; } } }
public EatResponse OnEvent(EventId id, object cookie) { if (id != EventId.EntityDestroyed) { if (id != EventId.BattleEndProcessing) { if (id == EventId.ShooterClipUsed) { ShooterComponent shooterComponent = (ShooterComponent)cookie; if (shooterComponent != null) { SmartEntity smartEntity = (SmartEntity)shooterComponent.Entity; uint iD = smartEntity.ID; if (this.deployedTroops.ContainsKey(iD)) { DeployedTroop deployedTroop = this.deployedTroops[iD]; if ((ulong)shooterComponent.NumClipsUsed >= (ulong)((long)deployedTroop.AbilityClipCount)) { this.DeactivateAbility(deployedTroop); } } } } } else { this.RemoveAllDeployedTroops(); } } else { uint num = (uint)cookie; if (this.deployedTroops.ContainsKey(num)) { this.OnTroopDestroyed(num, true); } } return(EatResponse.NotEaten); }