private bool CheckTarget(SmartEntity shooter, SmartEntity target, ref int maxWeight) { if (shooter == null || target == null) { return(false); } TransformComponent transformComp = target.TransformComp; TroopComponent troopComp = target.TroopComp; if (transformComp == null || troopComp == null) { return(false); } ShooterComponent shooterComp = shooter.ShooterComp; if ((long)GameUtils.GetSquaredDistanceToTarget(shooterComp, target) < (long)((ulong)shooterComp.MinAttackRangeSquared)) { return(false); } TransformComponent transformComp2 = shooter.TransformComp; int squaredDistance = GameUtils.SquaredDistance(transformComp2.CenterGridX(), transformComp2.CenterGridZ(), transformComp.CenterGridX(), transformComp.CenterGridZ()); int targetNearness = this.spatialIndexController.CalcNearness(squaredDistance); int num = this.CalculateWeight(shooterComp, null, troopComp.TroopType.ArmorType, targetNearness); if (num > maxWeight) { maxWeight = num; return(true); } return(false); }
private SmartEntity GetPrefferedBuilding(ShooterComponent shooterComp, PriorityList <SmartEntity> buildings, ref int maxWeight) { HashSet <string> hashSet = new HashSet <string>(); SmartEntity result = null; int i = 0; int count = buildings.Count; while (i < count) { ElementPriorityPair <SmartEntity> elementPriorityPair = buildings.Get(i); SmartEntity element = elementPriorityPair.Element; HealthComponent healthComp = element.HealthComp; if (healthComp != null && !healthComp.IsDead()) { BuildingComponent buildingComp = element.BuildingComp; if (buildingComp.BuildingType.Type != BuildingType.Blocker && (element.TrapComp == null || element.TrapComp.CurrentState == TrapState.Armed) && hashSet.Add(buildingComp.BuildingType.BuildingID)) { int num = this.CalculateWeight(shooterComp, null, healthComp.ArmorType, elementPriorityPair.Priority); if (num > maxWeight) { maxWeight = num; result = element; } } } i++; } return(result); }
public void ApplyAggroBuff(BuffEventData data) { if (data.BuffObj.BuffData.ContainsKey("originator")) { Buff buffObj = data.BuffObj; SmartEntity smartEntity = (SmartEntity)buffObj.BuffData["originator"]; ShooterComponent shooterComp = data.Target.ShooterComp; if (data.Target.TurretShooterComp == null && shooterComp == null) { return; } if (smartEntity == null) { return; } if (smartEntity.HealthComp == null) { return; } if (smartEntity.HealthComp.IsDead()) { return; } int squaredDistanceToTarget = GameUtils.GetSquaredDistanceToTarget(shooterComp, smartEntity); if ((long)squaredDistanceToTarget > (long)((ulong)shooterComp.MaxAttackRangeSquared) || (long)squaredDistanceToTarget <= (long)((ulong)shooterComp.MinAttackRangeSquared)) { return; } this.InvalidateCurrentTarget(data.Target); this.UpdateShooterTarget(true, data.Target, smartEntity); } }
public EntityPlayer(Texture2D playerTexture, int spriteId, Texture2D shadowTexture, int shadowOffset) : base() { PositionComponent = new PositionComponent(new Vector2(200, 200)); RenderComponent = new RenderComponent(playerTexture, new Vector2(0, spriteId), shadowTexture, shadowOffset, Color.White); ShooterComponent = new ShooterComponent(); ControlComponent = new ControlComponent(this); }
private bool ShouldAttackAlternateTarget(ShooterComponent shooterComp, Entity alternateTarget) { if (alternateTarget == null) { return(false); } BuildingComponent buildingComponent = alternateTarget.Get <BuildingComponent>(); TransformComponent transformComponent = alternateTarget.Get <TransformComponent>(); if (buildingComponent == null || buildingComponent.BuildingType == null || transformComponent == null) { return(false); } if (buildingComponent.BuildingType.Type == BuildingType.Blocker) { return(false); } if (buildingComponent.BuildingType.Type != BuildingType.Wall) { return(true); } SmartEntity primaryTarget = this.GetPrimaryTarget(shooterComp); return(primaryTarget != null && primaryTarget.Get <TransformComponent>() != null); }
private SmartEntity FindBestTargetForHealer(SmartEntity entity) { ShooterComponent shooterComp = entity.ShooterComp; TransformComponent transformComp = entity.TransformComp; SmartEntity smartEntity = this.TraverseSpiralToFindTarget((int)shooterComp.ShooterVO.ViewRange, transformComp.CenterGridX(), transformComp.CenterGridZ(), new TargetingController.TargetValidator(this.IsHealable), entity); if (smartEntity == null) { if (entity.TeamComp.TeamType == TeamType.Defender) { for (DefensiveTroopNode defensiveTroopNode = this.defensiveTroopNodeList.Head; defensiveTroopNode != null; defensiveTroopNode = defensiveTroopNode.Next) { SmartEntity smartEntity2 = (SmartEntity)defensiveTroopNode.Entity; if (this.IsHealable(smartEntity2, entity)) { smartEntity = smartEntity2; break; } } } else { for (OffensiveTroopNode offensiveTroopNode = this.offensiveTroopNodeList.Head; offensiveTroopNode != null; offensiveTroopNode = offensiveTroopNode.Next) { SmartEntity smartEntity3 = (SmartEntity)offensiveTroopNode.Entity; if (this.IsHealable(smartEntity3, entity)) { smartEntity = smartEntity3; break; } } } } return(smartEntity); }
public void ReevaluateTarget(ShooterComponent shooterComp) { shooterComp.ReevaluateTarget = true; SmartEntity smartEntity = (SmartEntity)shooterComp.Entity; if (smartEntity.TurretShooterComp != null) { SmartEntity target = shooterComp.Target; int targetWeight = -1; if (target != null && !GameUtils.IsEntityDead(target)) { List <EntityElementPriorityPair> turretsInRangeOf = this.spatialIndexController.GetTurretsInRangeOf(target.TransformComp.CenterGridX(), target.TransformComp.CenterGridZ()); int i = 0; int count = turretsInRangeOf.Count; while (i < count) { EntityElementPriorityPair entityElementPriorityPair = turretsInRangeOf[i]; if (smartEntity == entityElementPriorityPair.Element) { TroopComponent troopComp = target.TroopComp; targetWeight = this.CalculateWeight(shooterComp, null, troopComp.TroopType.ArmorType, entityElementPriorityPair.Priority); break; } i++; } } smartEntity.TurretShooterComp.TargetWeight = targetWeight; } }
private void AddTurretTarget(ShooterComponent shooterComp, TurretShooterComponent turretShooterComp, SmartEntity target, int nearness, HashSet <ShooterComponent> resetReevaluateTargetSet) { if (!shooterComp.Searching && !shooterComp.ReevaluateTarget) { return; } if (shooterComp.ReevaluateTarget) { resetReevaluateTargetSet.Add(shooterComp); } TroopComponent troopComp = target.TroopComp; if (shooterComp.ShooterVO.Preference[(int)troopComp.TroopType.ArmorType] <= 0) { return; } int num = this.CalculateWeight(shooterComp, null, troopComp.TroopType.ArmorType, nearness); Entity turretTarget = this.shooterController.GetTurretTarget(shooterComp); if (turretTarget == null || num > turretShooterComp.TargetWeight) { turretShooterComp.TargetWeight = num; if (shooterComp.ReevaluateTarget && shooterComp.Target != target) { shooterComp.AttackFSM.StopAttacking(false); } shooterComp.Target = target; } }
public bool RestartPathing(SmartEntity troopEntity, out bool found, bool ignoreWall) { ShooterComponent shooterComp = troopEntity.ShooterComp; IShooterVO shooterVO = shooterComp.ShooterVO; TroopComponent troopComp = troopEntity.TroopComp; TeamComponent teamComp = troopEntity.TeamComp; ITroopDeployableVO troopType = troopComp.TroopType; uint maxAttackRange = this.GetMaxAttackRange(troopEntity, shooterComp.Target); PathTroopParams troopParams = new PathTroopParams { TroopWidth = troopEntity.SizeComp.Width, DPS = shooterVO.DPS, MinRange = shooterVO.MinAttackRange, MaxRange = maxAttackRange, MaxSpeed = troopComp.SpeedVO.MaxSpeed, PathSearchWidth = troopType.PathSearchWidth, IsMelee = shooterComp.IsMelee, IsOverWall = shooterVO.OverWalls, IsHealer = troopType.IsHealer, SupportRange = troopType.SupportFollowDistance, ProjectileType = shooterVO.ProjectileType, CrushesWalls = troopType.CrushesWalls, IsTargetShield = GameUtils.IsEntityShieldGenerator(troopEntity.ShooterComp.Target), TargetInRangeModifier = troopType.TargetInRangeModifier }; PathBoardParams boardParams = new PathBoardParams { IgnoreWall = (teamComp.IsDefender() || ignoreWall), Destructible = teamComp.CanDestructBuildings() }; return(this.StartPathing(troopEntity, shooterComp.Target, troopEntity.TransformComp, true, out found, -1, troopParams, boardParams, true, false)); }
public void InformTurretsAboutTroop(List <EntityElementPriorityPair> turretsInRangeOf, SmartEntity entity, HashSet <ShooterComponent> resetReevaluateTargetSet) { int i = 0; int count = turretsInRangeOf.Count; while (i < count) { EntityElementPriorityPair entityElementPriorityPair = turretsInRangeOf[i]; SmartEntity smartEntity = (SmartEntity)entityElementPriorityPair.Element; HealthComponent healthComp = smartEntity.HealthComp; if (healthComp != null && !healthComp.IsDead()) { ShooterComponent shooterComp = smartEntity.ShooterComp; if (shooterComp != null) { TurretShooterComponent turretShooterComp = smartEntity.TurretShooterComp; if (turretShooterComp != null) { this.AddTurretTarget(shooterComp, turretShooterComp, entity, entityElementPriorityPair.Priority, resetReevaluateTargetSet); } } } i++; } }
private void SpawnChargeEmitter(SmartEntity owner) { ShooterComponent shooterComp = owner.ShooterComp; if (shooterComp == null) { return; } ProjectileTypeVO projectileType = shooterComp.ShooterVO.ProjectileType; if (string.IsNullOrEmpty(projectileType.ChargeAssetName)) { return; } GameObjectViewComponent gameObjectViewComp = owner.GameObjectViewComp; if (gameObjectViewComp == null || gameObjectViewComp.GunLocators.Count == 0 || gameObjectViewComp.GunLocators[0].Count == 0) { return; } GameObject gameObject = gameObjectViewComp.GunLocators[0][0]; if (gameObject == null) { return; } Vector3 position = gameObject.transform.position; this.StartDirectionalEmitter(owner, gameObject, position, Vector3.zero, projectileType.ChargeAssetName, projectileType.MuzzleFlashFadeTime); }
public EntityPlayer(Texture2D playerTexture, int spriteId, Texture2D shadowTexture, int shadowOffset) : base() { PositionComponent = new PositionComponent(new Vector2(200, 200)); RenderComponent = new RenderComponent(playerTexture, new Vector2(0, spriteId), shadowTexture, shadowOffset, Color.White); ShooterComponent = new ShooterComponent(); ControlComponent = new ControlComponent(this); }
public void RandomizeTargetingDelay(ShooterComponent ShooterComp) { if (ShooterComp.TargetingDelayed) { ShooterComp.TargetingDelayAmount = TargetingController.randomTargetingDelays[this.delayIndex]; this.delayIndex = (this.delayIndex + 1) % TargetingController.randomTargetingDelays.Length; } }
public void StopSearchIfTargetFound(ShooterComponent shooterComp) { if (shooterComp.Target == null) { return; } this.shooterController.StopSearch(shooterComp); }
public SmartEntity GetPrimaryTarget(ShooterComponent shooterComp) { if (shooterComp == null) { return(null); } return(shooterComp.Target); }
private void SetupGunLocators(SmartEntity entity, AssetMeshDataMonoBehaviour meta) { ShooterComponent shooterComp = entity.ShooterComp; if (shooterComp == null) { return; } if (meta == null || meta.GunLocatorGameObjects == null || meta.GunLocatorGameObjects.Count == 0) { return; } List <GameObject> list = null; if (entity.TroopComp != null) { TroopAbilityVO abilityVO = entity.TroopComp.AbilityVO; if (abilityVO != null) { int[] altGunLocators = abilityVO.AltGunLocators; if (altGunLocators != null && altGunLocators.Length > 0) { int count = meta.GunLocatorGameObjects.Count; List <GameObject> list2 = new List <GameObject>(); int i = 0; int num = altGunLocators.Length; while (i < num) { int num2 = altGunLocators[i]; if (num2 >= 1 && num2 < count) { GameObject item = meta.GunLocatorGameObjects[num2 - 1]; list2.Add(item); } i++; } if (list2.Count > 0) { list = new List <GameObject>(); for (int j = 0; j < count; j++) { GameObject item2 = meta.GunLocatorGameObjects[j]; if (!list2.Contains(item2)) { list.Add(item2); } } this.SetupGunLocatorsBySequence(entity, list2, abilityVO.GunSequence, true); } } } } if (list == null) { list = meta.GunLocatorGameObjects; } this.SetupGunLocatorsBySequence(entity, list, shooterComp.ShooterVO.GunSequence, false); }
public void Reload(ShooterComponent shooterComp) { if (shooterComp.ShouldCountClips && shooterComp.ShotsRemainingInClip == 0u) { shooterComp.NumClipsUsed += 1u; Service.EventManager.SendEvent(EventId.ShooterClipUsed, shooterComp); } shooterComp.ShotsRemainingInClip = shooterComp.ShooterVO.ShotCount; }
protected bool IsTargetInRange(ShooterComponent shooterComp, SmartEntity target) { if (target.ShieldBorderComp != null) { return(true); } int squaredDistanceToTarget = GameUtils.GetSquaredDistanceToTarget(shooterComp, target); return(this.shooterController.InRange(squaredDistanceToTarget, shooterComp)); }
public void Reload(ShooterComponent shooterComp) { if (shooterComp.ShouldCountClips && shooterComp.ShotsRemainingInClip == 0u) { uint numClipsUsed = shooterComp.NumClipsUsed; shooterComp.NumClipsUsed = numClipsUsed + 1u; Service.Get <EventManager>().SendEvent(EventId.ShooterClipUsed, shooterComp); } shooterComp.ShotsRemainingInClip = shooterComp.ShooterVO.ShotCount; }
public bool CanBeHealed(SmartEntity target, SmartEntity healer) { if (target == null || healer == null) { return(false); } TroopComponent troopComp = target.TroopComp; ShooterComponent shooterComp = healer.ShooterComp; return(troopComp != null && shooterComp != null && shooterComp.ShooterVO.Preference[(int)troopComp.TroopType.ArmorType] > 0); }
private void EnsurePrimaryTarget(SmartEntity entity) { if (entity.ShooterComp.Target != null) { ShooterComponent shooterComp = entity.ShooterComp; HealthComponent healthComp = shooterComp.Target.HealthComp; if (healthComp == null || healthComp.IsDead()) { Service.TargetingController.InvalidateCurrentTarget(entity); } } }
public void AddTurretsInRangeOf(Entity entity, int distanceSquared, int nearness) { ShooterComponent shooterComponent = entity.Get <ShooterComponent>(); if (shooterComponent == null) { return; } if (Service.ShooterController.InRange(distanceSquared, shooterComponent)) { this.turretsInRange.Add(new EntityElementPriorityPair(entity, nearness)); } }
private SmartEntity FindBuildingAsTarget(SmartEntity entity, ref int maxWeight) { TransformComponent transformComp = entity.TransformComp; this.buildingsToAttack = this.spatialIndexController.GetBuildingsToAttack(transformComp.CenterGridX(), transformComp.CenterGridZ()); SmartEntity result = null; if (this.buildingsToAttack != null) { ShooterComponent shooterComp = entity.ShooterComp; result = this.GetPrefferedBuilding(shooterComp, this.buildingsToAttack, ref maxWeight); } return(result); }
public void AddTurretComponentsToEntity(SmartEntity buildingEntity, TurretTypeVO turretType) { if (buildingEntity.TrackingComp == null) { buildingEntity.Add(new TrackingComponent(turretType, turretType.ProjectileType.Arcs)); } TransformComponent transformComp = buildingEntity.TransformComp; ShooterComponent shooterComponent = new ShooterComponent(turretType); shooterComponent.AttackFSM = new AttackFSM(Service.Get <BattleController>(), buildingEntity, buildingEntity.StateComp, shooterComponent, transformComp, HealthType.Damaging); buildingEntity.Add(shooterComponent); TurretShooterComponent component = new TurretShooterComponent(); buildingEntity.Add(component); }
private void EnsureTetheredDistance(SmartEntity entity) { DefenderComponent defenderComp = entity.DefenderComp; TransformComponent transformComp = entity.TransformComp; if (defenderComp == null || transformComp == null) { return; } ShooterComponent shooterComp = entity.ShooterComp; if (shooterComp.Target != null && (long)GameUtils.SquaredDistance(transformComp.CenterGridX(), transformComp.CenterGridZ(), defenderComp.SpawnX, defenderComp.SpawnZ) > (long)((ulong)(shooterComp.ShooterVO.ViewRange * shooterComp.ShooterVO.ViewRange))) { Service.TargetingController.InvalidateCurrentTarget(entity); } }
private int CalculateWeight(ShooterComponent shooterComp, HealthComponent healthComp, ArmorType targetArmorType, int targetNearness) { int num = 0; if (shooterComp.ShooterVO.Preference != null) { num = shooterComp.ShooterVO.Preference[(int)targetArmorType] * 100; } int num2 = 1; if (healthComp != null) { num2 = (healthComp.MaxHealth - healthComp.Health) * 10000 / healthComp.MaxHealth; } return(num * shooterComp.ShooterVO.PreferencePercentile + targetNearness * shooterComp.ShooterVO.NearnessPercentile + num2); }
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); }
public Target GetTargetToAttack(SmartEntity entity) { ShooterComponent shooterComp = entity.ShooterComp; if (shooterComp == null) { return(null); } SecondaryTargetsComponent secondaryTargetsComp = entity.SecondaryTargetsComp; SmartEntity targetEntity; if (secondaryTargetsComp != null) { targetEntity = this.GetTroopTarget(secondaryTargetsComp, shooterComp); return(Target.CreateTargetForTroop(entity, targetEntity, secondaryTargetsComp)); } targetEntity = this.GetTurretTarget(shooterComp); return(Target.CreateTargetForTurret(targetEntity)); }
protected bool IsTargetInRangeForAttack(SmartEntity troop, SmartEntity target, bool isLastTile) { if (target.ShieldBorderComp != null) { return(true); } if (this.WillCrushNearTarget(troop, target)) { return(false); } if (isLastTile && GameUtils.IsEntityShieldGenerator(troop.ShooterComp.Target) && troop.ShooterComp.Target != target) { return(true); } ShooterComponent shooterComp = troop.ShooterComp; int num = GameUtils.GetSquaredDistanceToTarget(shooterComp, target); TroopComponent troopComp = troop.TroopComp; uint num2 = 0u; if (troopComp != null) { if (TroopController.IsEntityHealer(troop)) { num += (int)((shooterComp.MaxAttackRangeSquared - shooterComp.MinAttackRangeSquared) / 2u); } if (!shooterComp.IsMelee) { num2 = Service.PathingManager.GetMaxAttackRange(troop, target); } } if (num2 != 0u) { if (!this.shooterController.InRange(num, shooterComp, num2)) { return(false); } } else if (!this.shooterController.InRange(num, shooterComp)) { return(false); } return(true); }
public EatResponse OnEvent(EventId id, object cookie) { Entity entity = null; if (id != EventId.TroopAcquiredFirstTarget) { if (id == EventId.SpecialAttackDeployed) { SpecialAttack specialAttack = cookie as SpecialAttack; TargetReticle fromPool = this.GetFromPool(true); fromPool.SetWorldTarget((float)specialAttack.TargetBoardX + 0.5f, (float)specialAttack.TargetBoardZ + 0.5f, specialAttack.VO.ReticleScale, specialAttack.VO.ReticleScale); Service.ViewTimerManager.CreateViewTimer(specialAttack.VO.ReticleDuration, false, new TimerDelegate(this.DeactivateTargetReticle), fromPool); } } else { Entity entity2 = cookie as Entity; TeamComponent teamComponent = entity2.Get <TeamComponent>(); if (teamComponent != null && teamComponent.TeamType != TeamType.Attacker) { return(EatResponse.NotEaten); } TroopComponent troopComponent = entity2.Get <TroopComponent>(); if (troopComponent != null && troopComponent.TroopShooterVO.TargetSelf) { return(EatResponse.NotEaten); } ShooterComponent shooterComponent = entity2.Get <ShooterComponent>(); if (shooterComponent != null) { entity = Service.ShooterController.GetPrimaryTarget(shooterComponent); } if (entity == null) { return(EatResponse.NotEaten); } TargetReticle fromPool2 = this.GetFromPool(true); fromPool2.SetTarget(entity); Service.ViewTimerManager.CreateViewTimer(1.5f, false, new TimerDelegate(this.DeactivateTargetReticle), fromPool2); } return(EatResponse.NotEaten); }