Exemple #1
0
        public bool StartAttack()
        {
            int    num            = 0;
            Target targetToAttack = this.shooterController.GetTargetToAttack(this.Entity);

            if (this.Entity.TroopComp != null && this.Entity.TroopComp.TroopShooterVO.TargetSelf)
            {
                return(this.SetState(this.WarmupState));
            }
            if (this.StateComponent.CurState == EntityState.Moving)
            {
                PathView           pathView = this.Entity.PathingComp.PathView;
                BoardCell <Entity> nextTurn = pathView.GetNextTurn();
                BoardCell <Entity> prevTurn = pathView.GetPrevTurn();
                if (prevTurn != null)
                {
                    this.lastLookAtX = nextTurn.X - prevTurn.X;
                    this.lastLookAtZ = nextTurn.Z - prevTurn.Z;
                }
            }
            int x = targetToAttack.TargetBoardX - this.TransformComponent.CenterGridX();
            int y = targetToAttack.TargetBoardZ - this.TransformComponent.CenterGridZ();

            if (this.lastLookAtX != 0 || this.lastLookAtZ != 0)
            {
                int num2 = IntMath.Atan2Lookup(this.lastLookAtX, this.lastLookAtZ);
                int num3 = IntMath.Atan2Lookup(x, y);
                int num4 = (num2 > num3) ? (num2 - num3) : (num3 - num2);
                if (num4 > 16384)
                {
                    num4 = 32768 - num4;
                }
                WalkerComponent walkerComp = this.Entity.WalkerComp;
                if (walkerComp != null)
                {
                    long num5 = (long)walkerComp.SpeedVO.RotationSpeed * 16384L;
                    if (num5 > 0L)
                    {
                        num  = (int)((long)num4 * 3142L * 1000L / num5);
                        num *= 2;
                    }
                }
            }
            this.lastLookAtX = x;
            this.lastLookAtZ = y;
            bool result;

            if (num > 0)
            {
                this.TurnState.SetDefaultLockDuration((uint)num);
                result = this.SetState(this.TurnState);
            }
            else
            {
                result = this.SetState(this.WarmupState);
            }
            return(result);
        }
        private void ChooseTargetLocationForDeathProjectile(SmartEntity attacker, int distance, ref int boardX, ref int boardZ, out int rotateDegrees)
        {
            int num  = boardX;
            int num2 = boardZ;
            PathingComponent pathingComp = attacker.PathingComp;

            if (pathingComp != null)
            {
                BoardCell <Entity> targetCell = pathingComp.TargetCell;
                if (targetCell != null && targetCell.Children != null)
                {
                    bool flag = false;
                    LinkedListNode <BoardItem <Entity> > linkedListNode = targetCell.Children.First;
                    while (linkedListNode != null && !flag)
                    {
                        SmartEntity target = (SmartEntity)linkedListNode.Value.Data;
                        flag           = this.TryGetBoardPositionFromTarget(target, ref num, ref num2);
                        linkedListNode = linkedListNode.Next;
                    }
                }
            }
            if (num == boardX && num2 == boardZ)
            {
                num  = 0;
                num2 = 0;
            }
            if (num == boardX && num2 == boardZ)
            {
                num++;
                num2++;
            }
            int num3 = num - boardX;
            int num4 = num2 - boardZ;
            int num5 = IntMath.FastDist(boardX, boardZ, num, num2);
            int num6 = 1024 * distance * 1;
            int num7 = num5 * 3;

            boardX       += num3 * num6 / num7;
            boardZ       += num4 * num6 / num7;
            rotateDegrees = -IntMath.Atan2Lookup(num3, num4) * 180 / 16384;
        }
        public bool StartPathing(SmartEntity troop, SmartEntity target, TransformComponent transform, bool clampPathLength, out bool found, int rangeOverride, PathTroopParams troopParams, PathBoardParams boardParams, bool isRepathing, bool allowTroopFanning)
        {
            if (troop == null || target == null)
            {
                found = false;
                return(true);
            }
            if (this.IsPathingOngoing())
            {
                found = false;
                return(false);
            }
            boardParams.IgnoreWall = (boardParams.IgnoreWall || troop.TroopComp.TroopType.IsFlying);
            this.troop             = troop;
            this.target            = target;
            this.noWall            = boardParams.IgnoreWall;
            this.crushesWalls      = troopParams.CrushesWalls;
            this.transform         = transform;
            SmartEntity         smartEntity    = (SmartEntity)transform.Entity;
            int                 x              = transform.X;
            int                 z              = transform.Z;
            BoardCell <Entity>  cellAt         = this.boardController.Board.GetCellAt(x, z);
            BoardCell <Entity>  boardCell      = null;
            DamageableComponent damageableComp = target.DamageableComp;
            ShooterComponent    shooterComp    = troop.ShooterComp;

            this.pathingComp = smartEntity.PathingComp;
            BoardCell <Entity> boardCell2;

            if ((this.pathingComp != null & isRepathing) && this.pathingComp.TargetCell != null && this.pathingComp.EndCell != null && damageableComp != null)
            {
                boardCell2 = this.pathingComp.TargetCell;
                boardCell  = this.pathingComp.EndCell;
            }
            else if (damageableComp != null)
            {
                uint maxRange = (uint)((rangeOverride >= 0) ? rangeOverride : ((int)shooterComp.ShooterVO.MaxAttackRange));
                boardCell = damageableComp.FindAttackCell(maxRange, troopParams.TroopWidth, x, z, allowTroopFanning);
                int x2;
                int z2;
                damageableComp.GetCenterPosition(out x2, out z2);
                boardCell2 = this.boardController.Board.GetCellAt(x2, z2);
            }
            else
            {
                TransformComponent transformComp = target.TransformComp;
                boardCell2 = this.boardController.Board.GetCellAt(transformComp.CenterGridX(), transformComp.CenterGridZ());
                int  squaredDistanceToTarget = GameUtils.GetSquaredDistanceToTarget(shooterComp, target);
                bool flag = (long)squaredDistanceToTarget > (long)((ulong)shooterComp.MaxAttackRangeSquared);
                if (boardCell2 != cellAt && !troopParams.IsHealer)
                {
                    if (flag)
                    {
                        int x3          = boardCell2.X - cellAt.X;
                        int y           = boardCell2.Z - cellAt.Z;
                        int num         = IntMath.Atan2Lookup(x3, y) * 180 / 16384;
                        int targetCount = target.TroopComp.TargetCount;
                        int num2        = (int)((troopParams.MaxRange > 1u) ? (troopParams.MaxRange - 1u) : 1u);
                        for (int i = num2; i > 0; i--)
                        {
                            if (boardCell != null)
                            {
                                break;
                            }
                            int num3 = i * 3 + 1;
                            int num4 = 180 / num3;
                            for (int j = 0; j < num3; j++)
                            {
                                int num5       = (j + targetCount) % num3;
                                int twiceAngle = (num + 90 + num5 * num4) % 360 * 2;
                                int x4         = boardCell2.X + IntMath.cosLookup(twiceAngle) * i / 1024;
                                int z3         = boardCell2.Z + IntMath.sinLookup(twiceAngle) * i / 1024;
                                boardCell = this.boardController.Board.GetClampedToBoardCellAt(x4, z3, troopParams.TroopWidth);
                                if ((boardCell.Children == null || boardCell.Children.Count == 0) && boardCell.Clearance >= troopParams.TroopWidth)
                                {
                                    break;
                                }
                                boardCell = null;
                            }
                        }
                    }
                    else
                    {
                        boardCell = cellAt;
                    }
                }
                if (boardCell == null)
                {
                    boardCell = boardCell2;
                    if (boardCell.Clearance < troopParams.TroopWidth)
                    {
                        this.pathingComp = null;
                        found            = false;
                        return(false);
                    }
                }
            }
            WalkerComponent walkerComp = smartEntity.WalkerComp;

            if (this.pathingComp == null)
            {
                this.pathingComp = new PathingComponent(walkerComp.SpeedVO.MaxSpeed, target);
            }
            else
            {
                this.pathingComp.Reset();
                this.pathingComp.MaxSpeed = walkerComp.SpeedVO.MaxSpeed;
                this.pathingComp.Target   = target;
            }
            this.pathingComp.TargetCell = boardCell2;
            this.pathingComp.EndCell    = boardCell;
            int maxLength = -1;
            BattleController battleController = Service.Get <BattleController>();

            if (clampPathLength && (battleController == null || battleController.GetCurrentBattle().Type == BattleType.Pvp || battleController.GetCurrentBattle().Type == BattleType.ClientBattle))
            {
                int num6 = IntMath.FastDist(cellAt.X, cellAt.Z, boardCell2.X, boardCell2.Z);
                maxLength = 2 * num6 / 1024 + 2;
            }
            this.path = new Path(cellAt, boardCell, boardCell2, maxLength, troopParams, boardParams);
            this.UpdatePathing(out found);
            return(true);
        }