Ejemplo n.º 1
0
 private bool ShouldSeekAlternativeTarget(SmartEntity troopEntity)
 {
     if (troopEntity.TroopComp == null)
     {
         Service.Logger.Error("Non troop entity checking for alternative target in TargetingSystem");
         return(false);
     }
     return(troopEntity.DefenderComp == null && !TroopController.IsEntityHealer(troopEntity) && !TroopController.IsEntityPhantom(troopEntity));
 }
Ejemplo n.º 2
0
        private bool WillCrushNearTarget(SmartEntity troop, SmartEntity target)
        {
            if (!TroopController.CanEntityCrushWalls(troop))
            {
                return(false);
            }
            BuildingComponent buildingComp = target.BuildingComp;

            return(buildingComp != null && buildingComp.BuildingType.Type == BuildingType.Wall);
        }
Ejemplo n.º 3
0
        private void UpdateShieldInLineOfShoot(SmartEntity troop, SmartEntity target)
        {
            if (troop.TeamComp.TeamType == TeamType.Defender || TroopController.IsEntityHealer(troop))
            {
                return;
            }
            int x;
            int y;
            int x2;
            int y2;

            this.GetAttackEndPoints(troop, target, out x, out y, out x2, out y2);
            this.hitShieldCell = BoardUtils.WhereDoesLineCrossFlag(Service.BoardController.Board, x, y, x2, y2, 8u);
        }
Ejemplo n.º 4
0
        public bool FindTargetForTroopNode(SmartEntity entity, bool onlyUpdateIfNewTargetFound)
        {
            if (entity.TroopComp.TroopShooterVO.TargetLocking && entity.ShooterComp.Target != null)
            {
                return(!onlyUpdateIfNewTargetFound);
            }
            if (!onlyUpdateIfNewTargetFound)
            {
                entity.ShooterComp.Target = null;
            }
            if (entity.TroopComp.TroopShooterVO.TargetSelf)
            {
                return(this.UpdateShooterTarget(onlyUpdateIfNewTargetFound, entity, entity));
            }
            bool flag = false;

            if (TroopController.IsEntityHealer(entity))
            {
                SmartEntity smartEntity = this.FindBestTargetForHealer(entity);
                flag = this.UpdateShooterTarget(onlyUpdateIfNewTargetFound, entity, smartEntity);
            }
            else if (entity.TeamComp.TeamType == TeamType.Attacker)
            {
                SmartEntity smartEntity = this.FindTargetForAttacker(entity);
                if (smartEntity != null && entity.ShooterComp != null && entity.ShooterComp.ShooterVO.NewTargetOnReload)
                {
                    entity.ShooterComp.AddEntityTargetIdToHistory(smartEntity.ID);
                }
                flag = this.UpdateShooterTarget(onlyUpdateIfNewTargetFound, entity, smartEntity);
            }
            else if (entity.TeamComp.TeamType == TeamType.Defender)
            {
                DefenderComponent defenderComp = entity.DefenderComp;
                SmartEntity       smartEntity  = this.FindOffensiveTroopAsTarget(entity);
                flag = this.UpdateShooterTarget(onlyUpdateIfNewTargetFound, entity, smartEntity);
                if (smartEntity != null && entity.ShooterComp != null && entity.ShooterComp.ShooterVO.NewTargetOnReload)
                {
                    entity.ShooterComp.AddEntityTargetIdToHistory(smartEntity.ID);
                }
                if (flag)
                {
                    entity.DefenderComp.Patrolling = false;
                }
                else if ((defenderComp.Leashed || !entity.ShooterComp.FirstTargetAcquired) && !onlyUpdateIfNewTargetFound && entity.StateComp.CurState != EntityState.Disable)
                {
                    this.TroopWandering(entity);
                }
            }
            return(flag);
        }
Ejemplo n.º 5
0
        public void DeployDropShipTroops(IntPosition spawnPosition, string troopUid, uint count, TeamType teamType)
        {
            int num = 0;
            StaticDataController staticDataController = Service.StaticDataController;
            TroopTypeVO          troopVO         = staticDataController.Get <TroopTypeVO>(troopUid);
            TroopController      troopController = Service.TroopController;
            int num2 = 0;

            while ((long)num2 < (long)((ulong)count))
            {
                troopController.DeployTroopWithOffset(troopVO, ref num, spawnPosition, true, teamType);
                num2++;
            }
            this.numHoveringInbound--;
        }
Ejemplo n.º 6
0
        public Entity DeployTroopWithOffset(TroopTypeVO troopVO, ref int currentOffsetIndex, IntPosition spawnPosition, bool forceAllow, TeamType teamType)
        {
            TroopController troopController = Service.TroopController;
            IntPosition     ip            = TroopDeployer.OFFSETS[currentOffsetIndex] * troopVO.AutoSpawnSpreadingScale;
            IntPosition     boardPosition = spawnPosition + ip;

            if (!troopController.ValidateAttackerTroopPlacement(boardPosition, troopVO.SizeX, false))
            {
                boardPosition = spawnPosition;
            }
            if (++currentOffsetIndex == TroopDeployer.OFFSETS.Length)
            {
                currentOffsetIndex = 0;
            }
            return(troopController.SpawnTroop(troopVO, teamType, boardPosition, TroopSpawnMode.Unleashed, true, forceAllow));
        }
Ejemplo n.º 7
0
        private bool HasLineOfSight(SmartEntity troop, SmartEntity target)
        {
            int x;
            int y;
            int x2;
            int y2;

            this.GetAttackEndPoints(troop, target, out x, out y, out x2, out y2);
            BoardCell boardCell = null;
            bool      result    = TroopController.IsEntityHealer(troop) || troop.TeamComp.TeamType == TeamType.Defender || BoardUtils.HasLineOfSight(Service.BoardController.Board, x, y, x2, y2, troop, target, out boardCell);

            if (this.ShouldSeekObstacleTarget(troop))
            {
                this.hitShieldCell = boardCell;
            }
            return(result);
        }
Ejemplo n.º 8
0
        public void StartDefenseMission(CampaignMissionVO mission)
        {
            if (this.activeDefenseBattle)
            {
                Service.Logger.WarnFormat("Mission {0} is already in progress.  Cannot start Mission {1}.", new object[]
                {
                    this.currentMission.Uid,
                    mission.Uid
                });
                return;
            }
            this.troopController     = Service.TroopController;
            this.eventManager        = Service.EventManager;
            this.activeDefenseBattle = true;
            this.autoMoveCamera      = false;
            this.currentMission      = mission;
            this.randomizeWaves      = !mission.FixedWaves;
            this.waves         = DefensiveBattleController.ParseWaves(this.currentMission.Waves);
            this.wavesDeployed = 0;
            this.waveCount     = this.waves.Count;
            this.AllWavesClear = false;
            if (mission.IsRaidDefense())
            {
                Service.RaidDefenseController.OnStartRaidDefenseMission();
            }
            this.eventManager.RegisterObserver(this, EventId.EntityKilled, EventPriority.BeforeDefault);
            this.eventManager.RegisterObserver(this, EventId.UserStartedCameraMove, EventPriority.Default);
            this.eventManager.RegisterObserver(this, EventId.CameraFinishedMoving, EventPriority.Default);
            this.eventManager.RegisterObserver(this, EventId.PreEntityKilled, EventPriority.Default);
            this.eventManager.RegisterObserver(this, EventId.EntityHit, EventPriority.Default);
            TrapViewController  trapViewController = Service.TrapViewController;
            NodeList <TrapNode> trapNodeList       = Service.BuildingLookupController.TrapNodeList;

            for (TrapNode trapNode = trapNodeList.Head; trapNode != null; trapNode = trapNode.Next)
            {
                trapViewController.UpdateTrapVisibility((SmartEntity)trapNode.Entity);
            }
            Vector3 zero = Vector3.zero;

            Service.WorldInitializer.View.ZoomTo(0.7f);
            Service.WorldInitializer.View.PanToLocation(zero);
            this.DeployNextWave(0u, null);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
            }
            if (TroopController.IsEntityPhantom(target))
            {
                return(false);
            }
            if (shooterComp.OriginalShooterVO.NewTargetOnReload && !shooterComp.IsPotentialTargetNew(target.ID))
            {
                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);
        }
Ejemplo n.º 11
0
        public bool IsHealable(SmartEntity target, object self)
        {
            if (target == null)
            {
                return(false);
            }
            SmartEntity smartEntity = (SmartEntity)self;

            if (target == smartEntity)
            {
                return(false);
            }
            TroopComponent  troopComp  = target.TroopComp;
            HealthComponent healthComp = target.HealthComp;
            TeamComponent   teamComp   = target.TeamComp;

            if (troopComp == null || healthComp == null || teamComp == null)
            {
                return(false);
            }
            if (target.TeamComp.TeamType != smartEntity.TeamComp.TeamType)
            {
                return(false);
            }
            if (TroopController.IsEntityPhantom(target))
            {
                return(false);
            }
            if (TroopController.IsEntityHealer(target))
            {
                return(false);
            }
            TroopComponent troopComp2 = smartEntity.TroopComp;

            return(troopComp2 == null || !TroopController.IsEntityHealer(smartEntity) || this.CanBeHealed(target, smartEntity));
        }
Ejemplo n.º 12
0
 public unsafe static long $Invoke0(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(TroopController.IsEntityHealer((SmartEntity)GCHandledObjects.GCHandleToObject(*args))));
 }
Ejemplo n.º 13
0
 private bool ShouldSeekObstacleTarget(SmartEntity troop)
 {
     return(!TroopController.IsEntityHealer(troop) && !troop.ShooterComp.ShooterVO.ProjectileType.PassThroughShield && troop.DefenderComp == null);
 }
Ejemplo n.º 14
0
        public void RotateGameObject(SmartEntity entity, float dx, float dz, float dt)
        {
            GameObjectViewComponent gameObjectViewComp = entity.GameObjectViewComp;
            TransformComponent      transformComp      = entity.TransformComp;

            if (entity.TroopComp != null && entity.TroopComp.TroopShooterVO.TargetSelf && transformComp.RotationInitialized)
            {
                return;
            }
            float                     num                     = transformComp.Rotation;
            bool                      flag                    = dx != 0f || dz != 0f;
            SmartEntity               smartEntity             = null;
            GameObjectViewComponent   gameObjectViewComponent = null;
            SecondaryTargetsComponent secondaryTargetsComp    = entity.SecondaryTargetsComp;
            ShooterComponent          shooterComp             = entity.ShooterComp;

            if (secondaryTargetsComp != null && shooterComp != null)
            {
                ShooterController shooterController = Service.Get <ShooterController>();
                smartEntity = shooterController.GetTroopTarget(secondaryTargetsComp, shooterComp);
                if (smartEntity != null && (gameObjectViewComponent = smartEntity.GameObjectViewComp) == null)
                {
                    smartEntity = shooterController.GetPrimaryTarget(shooterComp);
                    if (smartEntity != null)
                    {
                        gameObjectViewComponent = smartEntity.GameObjectViewComp;
                    }
                }
            }
            else
            {
                PathingComponent pathingComp = entity.PathingComp;
                if (pathingComp != null)
                {
                    smartEntity = pathingComp.Target;
                    if (smartEntity != null)
                    {
                        gameObjectViewComponent = smartEntity.GameObjectViewComp;
                    }
                }
            }
            bool flag2 = !transformComp.RotationInitialized;

            if (flag2 && smartEntity == null && (entity.DefenderComp != null || TroopController.IsEntityHealer(entity)))
            {
                gameObjectViewComp.MainGameObject.SetActive(true);
                transformComp.RotationInitialized = true;
            }
            else
            {
                bool flag3 = flag2 || entity.StateComp.CurState == EntityState.Attacking || entity.StateComp.CurState == EntityState.Turning;
                if (flag3 && gameObjectViewComponent != null)
                {
                    gameObjectViewComp.ComputeRotationToTarget(gameObjectViewComponent, ref num);
                    flag = false;
                    if (flag2)
                    {
                        gameObjectViewComp.MainGameObject.SetActive(true);
                        transformComp.Rotation            = num;
                        transformComp.RotationInitialized = true;
                    }
                }
            }
            if (flag)
            {
                num = Mathf.Atan2(dz, dx);
            }
            num = MathUtils.MinAngle(transformComp.Rotation, num);
            float num2       = (float)entity.WalkerComp.SpeedVO.RotationSpeed / 1000f;
            float smoothTime = 0.7853982f / num2;
            float num3       = (dt == 0f) ? transformComp.Rotation : Mathf.SmoothDampAngle(transformComp.Rotation, num, ref transformComp.RotationVelocity, smoothTime, num2, dt);

            num3 = MathUtils.WrapAngle(num3);
            gameObjectViewComp.Rotate(num3 + -1.57079637f);
            transformComp.Rotation = num3;
        }
Ejemplo n.º 15
0
        public void UpdateTroop(SmartEntity troop)
        {
            this.EnsurePrimaryTarget(troop);
            this.UpdateTroopShield(troop);
            SmartEntity troopTarget = this.shooterController.GetTroopTarget(troop);

            for (SmartEntity troopWallCrushingTarget = this.shooterController.GetTroopWallCrushingTarget(troop); troopWallCrushingTarget != null; troopWallCrushingTarget = this.shooterController.GetTroopWallCrushingTarget(troop))
            {
                if (!this.CanCrushNearTargetNow(troop, troopWallCrushingTarget))
                {
                    break;
                }
                this.OnTargetWallIsDestroyed(troop, troopWallCrushingTarget);
            }
            while (troopTarget != null)
            {
                HealthComponent healthComp = troopTarget.HealthComp;
                if (healthComp != null && !healthComp.IsDead())
                {
                    break;
                }
                this.OnTargetIsDead(troop);
                troopTarget = this.shooterController.GetTroopTarget(troop);
            }
            ShooterComponent shooterComp = troop.ShooterComp;
            bool             flag        = shooterComp.PrimaryTargetMoved();
            PathingComponent pathingComp = troop.PathingComp;
            bool             flag2       = pathingComp == null || pathingComp.CurrentPath == null || pathingComp.GetNextTile() == null;

            if (troopTarget == null)
            {
                this.OnTargetIsNull(troop);
            }
            else if (!this.IsTargetInRangeForAttack(troop, troopTarget, flag2) || (flag && shooterComp.Target != troopTarget))
            {
                this.OnTargetIsOutOfRange(troop, flag);
            }
            else
            {
                if (troopTarget.TransformComp == null)
                {
                    base.UpdateShooter(troop);
                    return;
                }
                this.hitShieldCell = null;
                if (flag2)
                {
                    this.UpdateShieldInLineOfShoot(troop, troopTarget);
                    base.UpdateShooter(troop);
                    return;
                }
                if (this.HasLineOfSight(troop, troopTarget))
                {
                    if (!TroopController.IsEntityHealer(troop) || flag2)
                    {
                        base.UpdateShooter(troop);
                    }
                    return;
                }
                this.OnTargetIsOutOfRange(troop, flag2 || flag);
            }
        }
Ejemplo n.º 16
0
        private bool UpdateNode(SmartEntity entity, TargetingController.OnTargetingDone onTroopTargetingDone, bool updateWallBreakingTroops)
        {
            if (entity.StateComp.CurState == EntityState.Disable)
            {
                return(false);
            }
            bool flag = false;

            if (updateWallBreakingTroops)
            {
                return(this.UpdateWallBreakingTroops(entity, onTroopTargetingDone));
            }
            if (!GameUtils.IsEligibleToFindTarget(entity.ShooterComp))
            {
                return(false);
            }
            ShooterComponent shooterComp = entity.ShooterComp;

            if (!shooterComp.Searching && !shooterComp.ReevaluateTarget)
            {
                return(false);
            }
            bool flag2;

            if (shooterComp.Searching)
            {
                if (shooterComp.TargetingDelayAmount > 0)
                {
                    shooterComp.TargetingDelayAmount--;
                    return(false);
                }
                flag2 = this.FindTargetForTroopNode(entity, false);
            }
            else
            {
                flag2 = this.FindTargetForTroopNode(entity, true);
            }
            shooterComp.ReevaluateTarget = false;
            if (!flag2)
            {
                return(false);
            }
            if (!shooterComp.Searching)
            {
                shooterComp.AttackFSM.StopAttacking(true);
            }
            SmartEntity primaryTarget = this.shooterController.GetPrimaryTarget(entity.ShooterComp);

            if (primaryTarget.TransformComp == null)
            {
                return(false);
            }
            flag = false;
            TroopComponent     troopComp   = entity.TroopComp;
            ITroopDeployableVO troopType   = troopComp.TroopType;
            IShooterVO         shooterVO   = shooterComp.ShooterVO;
            uint            maxAttackRange = this.pathingManager.GetMaxAttackRange(entity, primaryTarget);
            PathTroopParams troopParams    = new PathTroopParams
            {
                TroopWidth            = entity.SizeComp.Width,
                DPS                   = shooterVO.DPS,
                MinRange              = shooterVO.MinAttackRange,
                MaxRange              = maxAttackRange,
                MaxSpeed              = troopComp.SpeedVO.MaxSpeed,
                PathSearchWidth       = troopType.PathSearchWidth,
                IsMelee               = shooterComp.IsMelee,
                IsOverWall            = shooterComp.ShooterVO.OverWalls,
                IsHealer              = TroopController.IsEntityHealer(entity),
                SupportRange          = troopType.SupportFollowDistance,
                CrushesWalls          = TroopController.CanEntityCrushWalls(entity),
                ProjectileType        = shooterVO.ProjectileType,
                IsTargetShield        = GameUtils.IsEntityShieldGenerator(primaryTarget),
                TargetInRangeModifier = troopType.TargetInRangeModifier
            };
            PathBoardParams boardParams = new PathBoardParams
            {
                IgnoreWall   = TroopController.CanEntityIgnoreWalls(entity),
                Destructible = entity.TeamComp.CanDestructBuildings()
            };
            bool flag3 = this.pathingManager.StartPathing(entity, primaryTarget, entity.TransformComp, true, out flag, -1, troopParams, boardParams, false, false);

            if (!flag3)
            {
                onTroopTargetingDone(entity);
                this.shooterController.StopSearch(shooterComp);
                return(true);
            }
            if (!flag)
            {
                GameUtils.UpdateMinimumFrameCountForNextTargeting(shooterComp);
                return(false);
            }
            this.RandomizeTargetingDelay(shooterComp);
            onTroopTargetingDone(entity);
            this.shooterController.StopSearch(shooterComp);
            this.OnPathingComplete(entity, entity.SecondaryTargetsComp, entity.StateComp, shooterComp, primaryTarget);
            return(true);
        }
Ejemplo n.º 17
0
        private void TroopWandering(SmartEntity entity)
        {
            BoardController   boardController = Service.BoardController;
            DefenderComponent defenderComp    = entity.DefenderComp;

            if (defenderComp == null || defenderComp.Patrolling)
            {
                return;
            }
            TransformComponent transformComp = entity.TransformComp;

            if (transformComp == null)
            {
                return;
            }
            defenderComp.Patrolling = true;
            int       x         = transformComp.X;
            int       z         = transformComp.Z;
            BoardCell cellAt    = boardController.Board.GetCellAt(x, z);
            int       num       = defenderComp.PatrolLoc;
            int       num2      = (defenderComp.SpawnBuilding != null) ? 4 : 8;
            int       viewRange = (int)entity.ShooterComp.ShooterVO.ViewRange;

            for (int i = 0; i < num2; i++)
            {
                BoardCell boardCell;
                if (defenderComp.SpawnBuilding == null)
                {
                    num = (num + 1) % num2;
                    int x2 = defenderComp.SpawnX + viewRange * TargetingController.x_mul[num] / TargetingController.x_div[num] / 2;
                    int z2 = defenderComp.SpawnZ + viewRange * TargetingController.z_mul[num] / TargetingController.z_div[num] / 2;
                    boardCell = boardController.Board.GetClampedToBoardCellAt(x2, z2, entity.SizeComp.Width);
                }
                else
                {
                    boardCell = defenderComp.SpawnBuilding.FindNextPatrolPoint(entity.SizeComp.Width, ref num);
                }
                if (boardCell.IsWalkable())
                {
                    if (Service.PathingManager.StartPathingWorkerOrPatrol(entity, null, cellAt, boardCell, entity.SizeComp.Width, entity.TroopComp != null && TroopController.CanEntityCrushWalls(entity)))
                    {
                        Service.ShooterController.StartMoving(entity);
                        defenderComp.PatrolLoc = num;
                        Service.ShooterController.StopSearch(entity.ShooterComp);
                        return;
                    }
                }
            }
            entity.StateComp.CurState = EntityState.Idle;
        }