Example #1
0
        public override void Execute()
        {
            base.Execute();
            Entity entity = null;
            NodeList <BuildingNode> nodeList = Service.Get <EntityController>().GetNodeList <BuildingNode>();

            for (BuildingNode buildingNode = nodeList.Head; buildingNode != null; buildingNode = buildingNode.Next)
            {
                if (buildingNode.BuildingComp.BuildingType.BuildingID.Equals(this.prepareArgs[0], 5))
                {
                    entity             = buildingNode.Entity;
                    this.buildingFound = true;
                    break;
                }
            }
            if (entity != null)
            {
                this.width  = Units.GridToBoardX(entity.Get <BuildingComponent>().BuildingType.SizeX);
                this.depth  = Units.GridToBoardZ(entity.Get <BuildingComponent>().BuildingType.SizeY);
                this.boardX = entity.Get <BoardItemComponent>().BoardItem.BoardX + this.width / 2;
                this.boardZ = entity.Get <BoardItemComponent>().BoardItem.BoardZ + this.depth / 2;
            }
            if (this.buildingFound)
            {
                Service.Get <BuildingController>().HighlightBuilding(entity);
                Service.Get <UXController>().MiscElementsManager.HighlightRegion((float)this.boardX, (float)this.boardZ, this.width, this.depth);
                Vector3 zero = Vector3.zero;
                zero.x = Units.BoardToWorldX(this.boardX);
                zero.z = Units.BoardToWorldZ(this.boardZ);
                Service.Get <WorldInitializer>().View.PanToLocation(zero);
                Service.Get <UserInputInhibitor>().AllowOnly(entity);
            }
            this.parent.ChildComplete(this);
        }
        public Bullet SpawnProjectileForDeath(Vector3 spawnWorldLocation, SmartEntity attacker, ProjectileTypeVO deathProjectileType, uint deathProjectileDelay, int deathProjectileDistance, int deathProjectileDamage, out bool useRotation, ref int rotateDegrees)
        {
            useRotation = false;
            TransformComponent transformComp = attacker.TransformComp;
            int num  = transformComp.CenterGridX();
            int num2 = transformComp.CenterGridZ();

            if (spawnWorldLocation.y < 0f)
            {
                spawnWorldLocation = new Vector3(Units.BoardToWorldX(num), 0f, Units.BoardToWorldZ(num2));
            }
            Vector3 vector = spawnWorldLocation;

            if (deathProjectileDistance > 0)
            {
                this.ChooseTargetLocationForDeathProjectile(attacker, deathProjectileDistance, ref num, ref num2, out rotateDegrees);
                useRotation = true;
                Vector3 point = Vector3.right * (float)deathProjectileDistance;
                vector += Quaternion.Euler(0f, (float)rotateDegrees, 0f) * point;
            }
            HealthFragment healthFrag = new HealthFragment(attacker, HealthType.Damaging, deathProjectileDamage);
            TeamType       teamType   = attacker.TeamComp.TeamType;
            Bullet         bullet     = new Bullet();

            bullet.InitWithTargetPositionAndTravelTime(deathProjectileDelay, spawnWorldLocation, num, num2, teamType, attacker, healthFrag, deathProjectileType, null, FactionType.Invalid);
            bullet.SetTargetWorldLocation(vector);
            bullet.FlashTarget = (deathProjectileType.ApplyBuffs == null || deathProjectileType.ApplyBuffs.Length == 0);
            this.SpawnProjectileInternal(bullet, true, false);
            return(bullet);
        }
Example #3
0
        private void MoveLiftedBuilding(Entity building, Vector3 worldGroundPosition, bool isPartOfSelection)
        {
            Entity             selectedBuilding    = this.buildingSelector.SelectedBuilding;
            TransformComponent transformComponent  = building.Get <TransformComponent>();
            TransformComponent transformComponent2 = selectedBuilding.Get <TransformComponent>();
            float   num       = (float)transformComponent2.X - (float)transformComponent.BoardWidth / 2f + (float)transformComponent2.BoardWidth / 2f;
            float   num2      = (float)transformComponent2.Z - (float)transformComponent.BoardDepth / 2f + (float)transformComponent2.BoardDepth / 2f;
            float   num3      = (float)transformComponent.X;
            float   num4      = (float)transformComponent.Z;
            float   num5      = Units.BoardToWorldX(num3 - num);
            float   num6      = Units.BoardToWorldZ(num4 - num2);
            Vector3 grabPoint = this.buildingSelector.GrabPoint;
            float   num7      = worldGroundPosition.x - grabPoint.x + num5;
            float   num8      = worldGroundPosition.z - grabPoint.z + num6;
            float   num9;
            float   num10;

            EditBaseController.BuildingBoardToWorld(building, 0, 0, out num9, out num10);
            float num11 = num7 - num9;
            float num12 = num8 - num10;

            Units.SnapWorldToGridX(ref num11);
            Units.SnapWorldToGridZ(ref num12);
            int num13 = Units.WorldToBoardX(num11);
            int num14 = Units.WorldToBoardZ(num12);

            transformComponent.X = num13;
            transformComponent.Z = num14;
            int num15 = -2147483648;

            if (this.prevBoardAnchorX.ContainsKey(building))
            {
                num15 = this.prevBoardAnchorX[building];
            }
            int num16 = -2147483648;

            if (this.prevBoardAnchorZ.ContainsKey(building))
            {
                num16 = this.prevBoardAnchorZ[building];
            }
            if (num13 != num15 || num14 != num16)
            {
                this.canOccupy = this.EntireSelectionIsPlaceable();
                Service.UXController.MiscElementsManager.EnableConfirmGroupAcceptButton(this.canOccupy);
                FootprintMoveData cookie = new FootprintMoveData(building, num11, num12, this.canOccupy);
                Service.EventManager.SendEvent(EventId.UserMovedLiftedBuilding, cookie);
            }
            GameObjectViewComponent gameObjectViewComponent = building.Get <GameObjectViewComponent>();

            if (gameObjectViewComponent != null)
            {
                gameObjectViewComponent.SetXYZ(num7, 3f, num8);
            }
            if (this.canOccupy && !isPartOfSelection)
            {
                this.prevValidBoardAnchorX[building] = num13;
                this.prevValidBoardAnchorZ[building] = num14;
            }
        }
        private void SetGridQuadVertices(int x, int z, int index, Vector3[] vertices)
        {
            float num  = Units.BoardToWorldX(x);
            float num2 = Units.BoardToWorldZ(z);
            float maxX = num + 3f;
            float maxZ = num2 + 3f;

            UnityUtils.SetQuadVertices(num, num2, maxX, maxZ, index, vertices);
        }
Example #5
0
        public override void Execute()
        {
            base.Execute();
            Vector3 zero = Vector3.zero;

            zero.x = Units.BoardToWorldX(this.boardX);
            zero.z = Units.BoardToWorldZ(this.boardZ);
            Service.WorldInitializer.View.PanToLocation(zero);
            this.parent.ChildComplete(this);
        }
        public static void BuildingBoardToWorld(Entity building, int boardX, int boardZ, out float worldX, out float worldZ)
        {
            SizeComponent     sizeComp     = ((SmartEntity)building).SizeComp;
            BuildingComponent buildingComp = ((SmartEntity)building).BuildingComp;
            int num = 0;

            if (buildingComp.BuildingType.Type != BuildingType.Blocker && sizeComp.Width > 1 && sizeComp.Depth > 1)
            {
                num = 1;
            }
            worldX = Units.BoardToWorldX((float)boardX + (float)(sizeComp.Width - num) * 0.5f);
            worldZ = Units.BoardToWorldZ((float)boardZ + (float)(sizeComp.Depth - num) * 0.5f);
        }
        private void LoadAsset(GameObject parentObject, Transform locator, BuildingTypeVO buildingVO, AssetManager assetManager)
        {
            Transform transform = parentObject.transform;

            transform.parent        = locator;
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;
            transform.localScale    = Vector3.one;
            BoxCollider boxCollider = parentObject.AddComponent <BoxCollider>();
            float       x           = Units.BoardToWorldZ(buildingVO.SizeY);
            float       num         = Units.BoardToWorldX(buildingVO.SizeX);

            boxCollider.size = new Vector3(x, num, num);
            AssetHandle item = AssetHandle.Invalid;

            assetManager.Load(ref item, buildingVO.AssetName, new AssetSuccessDelegate(this.OnAssetLoaded), null, transform);
            this.assetHandles.Add(item);
        }
Example #8
0
        public void AdvanceNextTurn()
        {
            float num  = 0f;
            float num2 = 0f;

            this.GetTroopClusterOffset(ref num, ref num2);
            float num3 = Units.BoardToWorldX((float)this.PathComponent.CurrentPath.TroopWidth / 2f);
            GameObjectViewComponent gameObjectViewComponent = this.PathComponent.Entity.Get <GameObjectViewComponent>();

            if (gameObjectViewComponent == null)
            {
                TransformComponent transformComponent = this.PathComponent.Entity.Get <TransformComponent>();
                this.StartPos = new Vector3(Units.BoardToWorldX(transformComponent.CenterX()), 0f, Units.BoardToWorldZ(transformComponent.CenterZ()));
            }
            else
            {
                this.StartPos = gameObjectViewComponent.MainTransform.position;
            }
            this.StartPos -= new Vector3(num3 + num, 0f, num3 + num2);
            if (this.nextTurnIndex < this.PathComponent.CurrentPath.TurnCount - 1)
            {
                this.nextTurnIndex++;
                this.TimeOnPathSegment = 0f;
                this.TimeToTarget      = (float)(this.PathComponent.CurrentPath.GetTurnDistance(this.nextTurnIndex) * this.PathComponent.TimePerBoardCellMs) * 1E-06f;
                if (this.TimeToTarget == 0f)
                {
                    this.Speed = 0f;
                }
                else
                {
                    BoardCell <Entity> turn  = this.PathComponent.CurrentPath.GetTurn(this.nextTurnIndex - 1);
                    BoardCell <Entity> turn2 = this.PathComponent.CurrentPath.GetTurn(this.nextTurnIndex);
                    float num4 = Units.BoardToWorldX(turn2.X - turn.X) + num;
                    float num5 = Units.BoardToWorldZ(turn2.Z - turn.Z) + num2;
                    this.Speed = Mathf.Sqrt(num4 * num4 + num5 * num5) / this.TimeToTarget;
                }
                TransformComponent transformComponent2 = this.PathComponent.Entity.Get <TransformComponent>();
                if (transformComponent2 != null)
                {
                    transformComponent2.RotationVelocity = 0f;
                }
            }
        }
Example #9
0
        public RegionHighlight(UXElement highlight, float boardX, float boardZ, int width, int depth)
        {
            this.buttonHighlight        = highlight;
            this.buttonHighlight.Parent = Service.UXController.WorldAnchor;
            UnityUtils.SetLayerRecursively(highlight.Root, 8);
            this.buttonHighlight.UXCamera = Service.CameraManager.UXCamera;
            float num  = (float)depth / 2f;
            float num2 = (float)width / 2f;

            this.top    = new Vector3(Units.BoardToWorldX(boardX - num2), 0f, Units.BoardToWorldZ(boardZ - num));
            this.bottom = new Vector3(Units.BoardToWorldX(boardX + num2), 0f, Units.BoardToWorldZ(boardZ + num));
            this.left   = new Vector3(Units.BoardToWorldX(boardX - num2), 0f, Units.BoardToWorldZ(boardZ + num));
            this.right  = new Vector3(Units.BoardToWorldX(boardX + num2), 0f, Units.BoardToWorldZ(boardZ - num));
            this.center = (this.left + this.right) / 2f;
            this.cam    = Service.CameraManager.MainCamera;
            this.age    = 0f;
            this.UpdateHighlightPosition(0f);
            Service.ViewTimeEngine.RegisterFrameTimeObserver(this);
            this.buttonHighlight.Visible = true;
        }
Example #10
0
        private void DeployGroupAfterDelay(uint id, object cookie)
        {
            this.timers.Remove(id);
            DefenseTroopGroup defenseTroopGroup = (DefenseTroopGroup)cookie;
            TroopTypeVO       troop             = this.sdc.Get <TroopTypeVO>(defenseTroopGroup.TroopUid);

            for (int i = 0; i < defenseTroopGroup.Quantity; i++)
            {
                this.DeployTroopGroup(i, troop, defenseTroopGroup);
            }
            if (this.waves[this.currentWaveIndex].Troops.Count == 0 && this.timers.Count == 0)
            {
                this.EndCurrentWave();
            }
            if (Service.CurrentPlayer.CampaignProgress.FueInProgress)
            {
                int boardX = 0;
                int boardZ = 0;
                DefensiveBattleController.GetBoardEdge(defenseTroopGroup.Direction, defenseTroopGroup.Range, out boardX, out boardZ);
                this.AddCameraEvent(Units.BoardToWorldX(boardX), Units.BoardToWorldZ(boardZ), DefensiveCameraEventType.TroopSpawned);
            }
        }
Example #11
0
        public void RotateSelectedBuildings(Entity building)
        {
            this.AutoLiftSelectedBuilding();
            float   num       = Mathf.Sin(-1.57079637f);
            float   num2      = Mathf.Cos(-1.57079637f);
            Vector3 grabPoint = this.buildingSelector.GrabPoint;
            float   num3;
            float   num4;

            EditBaseController.BuildingBoardToWorld(building, 0, 0, out num3, out num4);
            TransformComponent transformComponent = building.Get <TransformComponent>();
            float   num5 = (float)transformComponent.X;
            float   num6 = (float)transformComponent.Z;
            Vector3 worldGroundPosition = new Vector3(Units.BoardToWorldX(num5), 0f, Units.BoardToWorldX(num6));

            worldGroundPosition.x += num3 + grabPoint.x;
            worldGroundPosition.z += num4 + grabPoint.z;
            int count = this.buildingSelector.AdditionalSelectedBuildings.Count;

            this.MoveLiftedBuilding(building, worldGroundPosition, count > 0);
            for (int i = 0; i < count; i++)
            {
                Entity             entity = this.buildingSelector.AdditionalSelectedBuildings[i];
                TransformComponent transformComponent2 = entity.Get <TransformComponent>();
                float   num7  = (float)transformComponent2.X + (float)transformComponent2.BoardWidth / 2f - (float)transformComponent.BoardWidth / 2f;
                float   num8  = (float)transformComponent2.Z + (float)transformComponent2.BoardDepth / 2f - (float)transformComponent.BoardWidth / 2f;
                float   num9  = num7 - num5;
                float   num10 = num8 - num6;
                float   num11 = num5 + (num9 * num2 - num10 * num);
                float   num12 = num6 + (num9 * num + num10 * num2);
                Vector3 worldGroundPosition2 = new Vector3(Units.BoardToWorldX(num11 - num9), 0f, Units.BoardToWorldZ(num12 - num10));
                worldGroundPosition2.x += num3 + grabPoint.x;
                worldGroundPosition2.z += num4 + grabPoint.z;
                this.MoveLiftedBuilding(entity, worldGroundPosition2, true);
            }
            this.canOccupy = this.EntireSelectionIsPlaceable();
            if (this.canOccupy)
            {
                this.UpdatePrevValidBoardAnchors();
                this.LowerLiftedBuilding(DropKind.JustDrop, true, true, true, true);
            }
            else
            {
                this.UpdateWallConnectorsInSelection(true);
            }
        }
Example #12
0
 private static void SetDefaultTargetWorldLocation(Target target, float targetWorldY)
 {
     target.TargetWorldLocation = new Vector3(Units.BoardToWorldX(target.TargetBoardX), targetWorldY, Units.BoardToWorldZ(target.TargetBoardZ));
 }
Example #13
0
 public void SetWorldTarget(float boardX, float boardZ, float width, float depth)
 {
     if (this.View == null)
     {
         return;
     }
     this.View.name = this.name;
     this.ViewTransform.position         = new Vector3(Units.BoardToWorldX(boardX), 0.09f, Units.BoardToWorldZ(boardZ));
     this.reticleScale                   = 1.4f * Mathf.Max(Units.BoardToWorldX(width), Units.BoardToWorldZ(depth));
     this.ViewTransform.localScale       = new Vector3(3f * this.reticleScale, 3f * this.reticleScale, 3f * this.reticleScale);
     this.ViewTransform.localEulerAngles = Vector3.zero;
     this.View.SetActive(true);
     this.StartLockon();
 }
        private void ImpactAreaWithSplash(Bullet bullet)
        {
            int targetBoardX = bullet.TargetBoardX;
            int targetBoardZ = bullet.TargetBoardZ;
            int splashRadius = bullet.SplashVO.SplashRadius;
            List <BoardCell <Entity> > cellsInSquare = Service.Get <BoardController>().Board.GetCellsInSquare(splashRadius, targetBoardX, targetBoardZ);
            Dictionary <Entity, bool>  dictionary    = new Dictionary <Entity, bool>();
            Vector3 targetWorldLocation = bullet.TargetWorldLocation;

            foreach (BoardCell <Entity> current in cellsInSquare)
            {
                int chessboardDistance  = BoardUtils.GetChessboardDistance(current.X, current.Z, targetBoardX, targetBoardZ);
                int splashDamagePercent = bullet.SplashVO.GetSplashDamagePercent(chessboardDistance);
                if (splashDamagePercent != 0)
                {
                    ShieldGeneratorComponent activeShieldAffectingBoardPos = Service.Get <ShieldController>().GetActiveShieldAffectingBoardPos(current.X, current.Z);
                    if (activeShieldAffectingBoardPos != null && !bullet.ProjectileType.PassThroughShield && activeShieldAffectingBoardPos.Entity.Get <TeamComponent>().TeamType != bullet.OwnerTeam)
                    {
                        TransformComponent transformComponent = activeShieldAffectingBoardPos.Entity.Get <TransformComponent>();
                        Vector3            targetPos          = new Vector3(Units.BoardToWorldX(transformComponent.CenterX()), transformComponent.CenterX(), Units.BoardToWorldZ(transformComponent.CenterZ()));
                        Vector3            zero = Vector3.zero;
                        if (Service.Get <ShieldController>().GetRayShieldIntersection(targetWorldLocation, targetPos, activeShieldAffectingBoardPos, out zero))
                        {
                            bullet.SetTargetWorldLocation(zero);
                        }
                        this.ImpactTargetFromSplashDamage((SmartEntity)activeShieldAffectingBoardPos.ShieldBorderEntity, bullet, splashDamagePercent, ref dictionary);
                    }
                    else if (current.Children != null)
                    {
                        LinkedListNode <BoardItem <Entity> > next;
                        for (LinkedListNode <BoardItem <Entity> > linkedListNode = current.Children.First; linkedListNode != null; linkedListNode = next)
                        {
                            next = linkedListNode.Next;
                            this.ImpactTargetFromSplashDamage((SmartEntity)linkedListNode.Value.Data, bullet, splashDamagePercent, ref dictionary);
                        }
                    }
                }
            }
        }
        private void SpecialAttackDeployedActionCallback(uint id, object cookie)
        {
            SpecialAttackDeployedAction specialAttackDeployedAction = cookie as SpecialAttackDeployedAction;
            IDataController             dataController      = Service.Get <IDataController>();
            SpecialAttackTypeVO         specialAttackTypeVO = dataController.Get <SpecialAttackTypeVO>(specialAttackDeployedAction.SpecialAttackId);
            Vector3 vector = new Vector3(Units.BoardToWorldX(specialAttackDeployedAction.BoardX), 0f, Units.BoardToWorldZ(specialAttackDeployedAction.BoardZ));

            Service.Get <SpecialAttackController>().DeploySpecialAttack(specialAttackTypeVO, specialAttackDeployedAction.TeamType, vector);
            IntPosition boardPosition = Units.WorldToBoardIntPosition(vector);

            this.battleController.OnSpecialAttackDeployed(specialAttackTypeVO.Uid, specialAttackDeployedAction.TeamType, boardPosition);
        }
Example #16
0
        private void SpawnTransport(ContractEventData contractData)
        {
            if (!this.CountTransportRequest(contractData))
            {
                return;
            }
            Entity         entity     = contractData.Entity;
            BuildingTypeVO buildingVO = contractData.BuildingVO;
            string         uid;

            if (buildingVO.Faction == FactionType.Empire)
            {
                uid = this.TRANSPORT_SHIP_EMPIRE;
            }
            else
            {
                if (buildingVO.Faction != FactionType.Rebel)
                {
                    return;
                }
                uid = this.TRANSPORT_SHIP_REBEL;
            }
            TransportTypeVO transportType = Service.StaticDataController.Get <TransportTypeVO>(uid);
            Entity          entity2       = this.FindIdleTransport(transportType);

            if (entity2 == null)
            {
                return;
            }
            Entity entity3 = this.FindIdleStarport(contractData);

            if (entity3 == null)
            {
                return;
            }
            TransformComponent transformComponent = entity.Get <TransformComponent>();
            Vector3            vector             = new Vector3(Units.BoardToWorldX(transformComponent.CenterX()), 0f, Units.BoardToWorldZ(transformComponent.CenterZ()));
            GameObject         vehicleLocator     = entity.Get <GameObjectViewComponent>().VehicleLocator;

            if (vehicleLocator != null)
            {
                this.factoryOffset = new Vector3(0f, vehicleLocator.transform.position.y + TransportController.FACTORY_WALL_HEIGHT, 0f);
            }
            else
            {
                this.factoryOffset = new Vector3(0f, TransportController.FACTORY_WALL_HEIGHT, 0f);
            }
            vector            += this.factoryOffset;
            transformComponent = entity3.Get <TransformComponent>();
            Vector3 vector2 = new Vector3(Units.BoardToWorldX(transformComponent.CenterX()), 0f, Units.BoardToWorldZ(transformComponent.CenterZ()));

            vector2 += TransportController.DOCK_OFFSET;
            TransportComponent transportComponent = entity2.Get <TransportComponent>();

            this.BuildSpline(transportComponent.Spline, TransportController.SPAWN_POSITION, vector, vector2, entity3, contractData);
            entity2.Get <StateComponent>().CurState = EntityState.Moving;
        }
        private void AddLoweredFootprint(SmartEntity building)
        {
            TransformComponent transformComp = building.TransformComp;
            Vector3            vector        = new Vector3(Units.BoardToWorldX(transformComp.X), 0f, Units.BoardToWorldZ(transformComp.Z));
            SizeComponent      sizeComp      = building.SizeComp;

            this.loweredFootprint.AddTiles(vector.x, vector.z, sizeComp.Width, sizeComp.Depth, building.WallComp != null);
        }
Example #18
0
        private bool LowerLiftedBuildingHelper(SmartEntity buildingInSelection, DropKind dropKind, bool affectBoard, bool sendLoweredEvent, bool playLoweredSound, bool showContextButtons, string tag)
        {
            this.lifted = false;
            this.moved  = false;
            BuildingTypeVO buildingTypeVO = null;
            int            num            = 0;
            int            num2           = 0;

            if ((this.canOccupy || dropKind != DropKind.JustDrop) && this.prevValidBoardAnchorX.ContainsKey(buildingInSelection) && this.prevValidBoardAnchorZ.ContainsKey(buildingInSelection))
            {
                num  = this.prevValidBoardAnchorX[buildingInSelection];
                num2 = this.prevValidBoardAnchorZ[buildingInSelection];
            }
            else if (this.prevValidBoardAnchorX.ContainsKey(buildingInSelection) && this.prevValidBoardAnchorZ.ContainsKey(buildingInSelection))
            {
                num  = this.prevValidBoardAnchorX[buildingInSelection];
                num2 = this.prevValidBoardAnchorZ[buildingInSelection];
            }
            else if (this.buildingSelector.AdditionalSelectedBuildings.Count == 0)
            {
                if (buildingInSelection != null)
                {
                    Service.Logger.Warn("Something went wrong placing " + buildingInSelection.ToString() + " we should not be hitting this case where prevValidBoardAnchorX and prevValidBoardAnchorZ do not contain buildingInSelection");
                }
                else
                {
                    Service.Logger.Warn("Something went wrong, we should not be hitting this case where prevValidBoardAnchorX and prevValidBoardAnchorZ do not contain buildingInSelection");
                }
            }
            if (affectBoard)
            {
                BoardCell boardCell = this.buildingController.OnLowerLiftedBuilding(buildingInSelection, num, num2, dropKind == DropKind.ConfirmPurchase, ref buildingTypeVO, tag);
                if (boardCell == null)
                {
                    this.buildingSelector.DeselectSelectedBuilding();
                    Service.EventManager.SendEvent(EventId.UserLoweredBuilding, buildingInSelection);
                    this.DestroyBuilding(buildingInSelection);
                    return(false);
                }
                BoardItemComponent boardItemComponent = buildingInSelection.Get <BoardItemComponent>();
                if (boardItemComponent.BoardItem.Filter == CollisionFilters.BUILDING_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.BUILDING;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.TRAP_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.TRAP;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.WALL_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.WALL;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.BLOCKER_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.BLOCKER;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.PLATFORM_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.PLATFORM;
                }
                else
                {
                    Service.Logger.ErrorFormat("LowerLiftedBuilding : Unexpected filter type {0}", new object[]
                    {
                        boardItemComponent.BoardItem.Filter
                    });
                    boardItemComponent.BoardItem.Filter = CollisionFilters.BUILDING;
                }
                num  = boardCell.X;
                num2 = boardCell.Z;
            }
            else
            {
                float x;
                float z;
                EditBaseController.BuildingBoardToWorld(this.buildingSelector.SelectedBuilding, num, num2, out x, out z);
                Vector3 worldGroundPosition = new Vector3(x, 0f, z);
                worldGroundPosition.x += this.buildingSelector.GrabPoint.x;
                worldGroundPosition.z += this.buildingSelector.GrabPoint.z;
                this.MoveLiftedBuilding(this.buildingSelector.SelectedBuilding, worldGroundPosition);
            }
            GameObjectViewComponent gameObjectViewComponent = buildingInSelection.Get <GameObjectViewComponent>();

            if (gameObjectViewComponent != null)
            {
                TransformComponent transformComponent = buildingInSelection.Get <TransformComponent>();
                gameObjectViewComponent.SetXYZ(Units.BoardToWorldX(transformComponent.CenterX()), 0f, Units.BoardToWorldZ(transformComponent.CenterZ()));
            }
            Service.EntityViewManager.SetCollider(buildingInSelection, true);
            if (sendLoweredEvent)
            {
                Service.EventManager.SendEvent(EventId.UserLoweredBuilding, buildingInSelection);
            }
            if (playLoweredSound)
            {
                Service.EventManager.SendEvent(EventId.UserLoweredBuildingAudio, buildingInSelection);
            }
            this.buildingSelector.ApplySelectedEffect(buildingInSelection);
            if (buildingTypeVO != null)
            {
                this.buildingController.StartPurchaseBuilding(buildingTypeVO, -1);
            }
            else if (showContextButtons)
            {
                Service.UXController.HUD.ShowContextButtons(buildingInSelection);
            }
            Service.BuildingTooltipController.EnsureBuildingTooltip(buildingInSelection);
            return(true);
        }
Example #19
0
        public void StashBuilding(SmartEntity buildingEntity, bool allowRevert)
        {
            BuildingComponent buildingComponent = buildingEntity.Get <BuildingComponent>();

            if (buildingComponent.BuildingType.Type == BuildingType.Clearable)
            {
                Service.Logger.Warn("BLT: Can't stash clearable: " + buildingComponent.BuildingTO.Key + ":" + buildingComponent.BuildingTO.Uid);
                return;
            }
            string uid = buildingComponent.BuildingTO.Uid;

            if (this.stashedBuildingMap == null)
            {
                this.stashedBuildingMap = new Dictionary <string, List <SmartEntity> >();
            }
            if (!this.stashedBuildingMap.ContainsKey(uid))
            {
                this.stashedBuildingMap.Add(uid, new List <SmartEntity>());
            }
            List <SmartEntity> list = this.stashedBuildingMap[uid];

            if (!list.Contains(buildingEntity))
            {
                list.Add(buildingEntity);
            }
            GameObjectViewComponent gameObjectViewComp = buildingEntity.GameObjectViewComp;

            if (gameObjectViewComp != null)
            {
                TransformComponent transformComp = buildingEntity.TransformComp;
                gameObjectViewComp.SetXYZ(Units.BoardToWorldX(transformComp.CenterX()), -1000f, Units.BoardToWorldZ(transformComp.CenterZ()));
            }
            if (buildingEntity.HealthViewComp != null)
            {
                HealthViewComponent healthViewComponent = buildingEntity.Get <HealthViewComponent>();
                healthViewComponent.TeardownElements();
            }
            Service.EventManager.SendEvent(EventId.UserStashedBuilding, buildingEntity);
            Service.BoardController.RemoveEntity(buildingEntity, true);
            Service.EventManager.SendEvent(EventId.EntityDestroyed, buildingEntity.ID);
            Service.EventManager.SendEvent(EventId.BuildingMovedOnBoard, buildingEntity);
            Service.BuildingController.DisableUnstashStampingState();
            if (allowRevert)
            {
                this.ShouldRevertMap = true;
            }
        }
Example #20
0
        private void SetDefaultTargetWorldLocation(float targetWorldY)
        {
            float num = 0f;

            if (this.Target == null)
            {
                num = 1f;
            }
            this.SetTargetWorldLocation(new Vector3(Units.BoardToWorldX(this.TargetBoardX) + num, targetWorldY, Units.BoardToWorldZ(this.TargetBoardZ) + num));
        }
Example #21
0
        public EatResponse OnEvent(EventId id, object cookie)
        {
            switch (id)
            {
            case EventId.PreEntityKilled:
            {
                Entity             entity             = (Entity)cookie;
                BuildingComponent  buildingComponent  = entity.Get <BuildingComponent>();
                TransformComponent transformComponent = entity.Get <TransformComponent>();
                if (transformComponent != null)
                {
                    DefensiveCameraEventType type = DefensiveCameraEventType.TroopDestroyed;
                    if (buildingComponent != null)
                    {
                        if (buildingComponent.BuildingType.Type == BuildingType.Wall)
                        {
                            type = DefensiveCameraEventType.WallDestroyed;
                        }
                        else
                        {
                            type = DefensiveCameraEventType.BuildingDestroyed;
                        }
                    }
                    this.AddCameraEvent(Units.BoardToWorldX(transformComponent.CenterX()), Units.BoardToWorldZ(transformComponent.CenterZ()), type);
                }
                return(EatResponse.NotEaten);
            }

            case EventId.EntityKilled:
            {
                Entity item = (Entity)cookie;
                if (this.currentWave != null && this.currentWave.Troops.Contains(item))
                {
                    this.currentWave.Troops.Remove(item);
                    if (this.currentWave.Troops.Count == 0 && this.timers.Count == 0)
                    {
                        this.EndCurrentWave();
                    }
                }
                return(EatResponse.NotEaten);
            }

            case EventId.PostBuildingEntityKilled:
            case EventId.EntityDestroyed:
IL_1D:
                if (id == EventId.CameraFinishedMoving)
                {
                    this.MoveCameraToAction();
                    return(EatResponse.NotEaten);
                }
                if (id != EventId.UserStartedCameraMove)
                {
                    return(EatResponse.NotEaten);
                }
                this.autoMoveCamera = false;
                this.cameraEvents.Clear();
                this.numTimesEntityHit.Clear();
                this.UnRegisterObservers();
                return(EatResponse.NotEaten);

            case EventId.EntityHit:
            {
                Bullet             bullet        = (Bullet)cookie;
                SmartEntity        target        = bullet.Target;
                uint               iD            = target.ID;
                TransformComponent transformComp = target.TransformComp;
                BuildingComponent  buildingComp  = target.BuildingComp;
                if (buildingComp != null && transformComp != null)
                {
                    if (this.numTimesEntityHit.ContainsKey(iD))
                    {
                        Dictionary <uint, int> dictionary;
                        uint key;
                        (dictionary = this.numTimesEntityHit)[key = iD] = dictionary[key] + 1;
                    }
                    else
                    {
                        this.numTimesEntityHit.Add(iD, 1);
                    }
                    if (this.currentCameraEvent == null || this.numTimesEntityHit[iD] > 5)
                    {
                        this.numTimesEntityHit[iD] = 0;
                        this.AddCameraEvent(Units.BoardToWorldX(transformComp.CenterX()), Units.BoardToWorldZ(transformComp.CenterZ()), DefensiveCameraEventType.EntityDamaged);
                    }
                }
                return(EatResponse.NotEaten);
            }
            }
            goto IL_1D;
        }
Example #22
0
        private void LiftSelectedBuilding(SmartEntity buildingInSelection, bool sendLiftedEvent, bool clearPreviousAnchorPos)
        {
            this.lifted = true;
            if (buildingInSelection == this.buildingSelector.SelectedBuilding)
            {
                Service.UXController.HUD.ShowContextButtons(buildingInSelection);
            }
            Vector3            grabPoint          = this.buildingSelector.GrabPoint;
            BoardItemComponent boardItemComponent = buildingInSelection.Get <BoardItemComponent>();

            if (boardItemComponent.BoardItem.Filter == CollisionFilters.BUILDING)
            {
                boardItemComponent.BoardItem.Filter = CollisionFilters.BUILDING_GHOST;
            }
            else if (boardItemComponent.BoardItem.Filter == CollisionFilters.TRAP)
            {
                boardItemComponent.BoardItem.Filter = CollisionFilters.TRAP_GHOST;
            }
            else if (boardItemComponent.BoardItem.Filter == CollisionFilters.WALL)
            {
                boardItemComponent.BoardItem.Filter = CollisionFilters.WALL_GHOST;
            }
            else if (boardItemComponent.BoardItem.Filter == CollisionFilters.BLOCKER)
            {
                boardItemComponent.BoardItem.Filter = CollisionFilters.BLOCKER_GHOST;
            }
            else if (boardItemComponent.BoardItem.Filter == CollisionFilters.PLATFORM)
            {
                boardItemComponent.BoardItem.Filter = CollisionFilters.PLATFORM_GHOST;
            }
            this.canOccupy = true;
            if (clearPreviousAnchorPos)
            {
                this.ClearPreviousAnchors();
            }
            TransformComponent transformComp       = this.buildingSelector.SelectedBuilding.TransformComp;
            Vector3            worldGroundPosition = new Vector3(Units.BoardToWorldX(transformComp.X), 0f, Units.BoardToWorldZ(transformComp.Z));

            if (sendLiftedEvent)
            {
                Service.EventManager.SendEvent(EventId.UserLiftedBuilding, buildingInSelection);
                Service.EventManager.SendEvent(EventId.UserLiftedBuildingAudio, buildingInSelection);
            }
            float num;
            float num2;

            EditBaseController.BuildingBoardToWorld(this.buildingSelector.SelectedBuilding, 0, 0, out num, out num2);
            worldGroundPosition.x += num + grabPoint.x;
            worldGroundPosition.z += num2 + grabPoint.z;
            this.MoveLiftedBuilding(buildingInSelection, worldGroundPosition);
            Service.EntityViewManager.SetCollider(buildingInSelection, false);
            this.buildingSelector.ApplySelectedEffect(buildingInSelection);
            Service.BuildingTooltipController.HideBuildingTooltip(buildingInSelection);
        }
Example #23
0
        public void UnstashBuildingByUID(string buildingUID, bool returnToOriginalPosition, bool stampable, bool panToBuilding, bool playLoweredSound)
        {
            if (this.stashedBuildingMap == null)
            {
                return;
            }
            if (!this.stashedBuildingMap.ContainsKey(buildingUID) || this.stashedBuildingMap[buildingUID].Count < 1)
            {
                Service.Logger.Error("Can't unstash! No buildings of : " + buildingUID + " currently stashed");
                return;
            }
            List <SmartEntity> list         = this.stashedBuildingMap[buildingUID];
            SmartEntity        smartEntity  = list[0];
            BuildingComponent  buildingComp = smartEntity.BuildingComp;
            bool flag = false;

            if (stampable && this.IsBuildingStampable(smartEntity))
            {
                flag = true;
            }
            Position pos = null;

            if (returnToOriginalPosition)
            {
                pos = this.lastSavedMap.GetPosition(buildingComp.BuildingTO.Key);
                if (flag)
                {
                    flag = false;
                    Service.Logger.Warn("No stamping while reverting!!");
                }
            }
            BuildingController      buildingController      = Service.BuildingController;
            GameObjectViewComponent gameObjectViewComponent = smartEntity.Get <GameObjectViewComponent>();
            TransformComponent      transformComponent      = smartEntity.Get <TransformComponent>();

            if (gameObjectViewComponent != null)
            {
                gameObjectViewComponent.SetXYZ(Units.BoardToWorldX(transformComponent.CenterX()), 0f, Units.BoardToWorldZ(transformComponent.CenterZ()));
            }
            if (smartEntity.Has <HealthViewComponent>())
            {
                HealthViewComponent healthViewComponent = smartEntity.Get <HealthViewComponent>();
                healthViewComponent.SetupElements();
            }
            List <SmartEntity> list2 = this.stashedBuildingMap[buildingUID];

            if (list2.Contains(smartEntity))
            {
                list2.Remove(smartEntity);
                if (!buildingController.PositionUnstashedBuilding(smartEntity, pos, flag, panToBuilding, playLoweredSound))
                {
                    Service.Logger.ErrorFormat("Unable to place building from stash.  Building {0} {1}", new object[]
                    {
                        smartEntity.Get <BuildingComponent>().BuildingTO.Key,
                        smartEntity.Get <BuildingComponent>().BuildingType.Uid
                    });
                    Service.UXController.MiscElementsManager.ShowPlayerInstructionsError(Service.Lang.Get("NO_VALID_POSITION_FOR_UNSTASH", new object[0]));
                    this.StashBuilding(smartEntity);
                }
            }
        }
Example #24
0
        public void UpdateNewEntityView(SmartEntity entity)
        {
            GameObjectViewComponent gameObjectViewComp = entity.GameObjectViewComp;
            TransformComponent      transformComp      = entity.TransformComp;

            if (gameObjectViewComp == null || transformComp == null)
            {
                Service.Get <StaRTSLogger>().WarnFormat("Entity is not ready for rendering. view: {0}, transform: {1}, entity: {2}", new object[]
                {
                    (gameObjectViewComp == null) ? "null" : gameObjectViewComp.ToString(),
                    (transformComp == null) ? "null" : transformComp.ToString(),
                    entity.ID
                });
                return;
            }
            gameObjectViewComp.MainTransform.position = new Vector3(Units.BoardToWorldX(transformComp.CenterX()), gameObjectViewComp.MainTransform.position.y, Units.BoardToWorldZ(transformComp.CenterZ()));
            if (entity.TroopComp != null || entity.DroidComp != null)
            {
                this.RotateGameObject(entity, 0f, 0f, 0f);
                float speed = Service.Get <BattlePlaybackController>().CurrentPlaybackScale;
                this.UpdateAnimationSpeed(gameObjectViewComp, speed);
                this.UpdateAnimationState(gameObjectViewComp, entity.StateComp);
                return;
            }
            if (entity.TrapComp != null)
            {
                gameObjectViewComp.MainGameObject.SetActive(true);
                Service.Get <TrapController>().SetTrapState(entity.TrapComp, entity.TrapComp.CurrentState);
                Service.Get <TrapViewController>().UpdateTrapVisibility(entity);
                gameObjectViewComp.Rotate(transformComp.Rotation);
                return;
            }
            gameObjectViewComp.Rotate(transformComp.Rotation);
            gameObjectViewComp.MainGameObject.SetActive(true);
        }
Example #25
0
        public bool GetRayShieldIntersection(Vector3 rayPos, Vector3 targetPos, ShieldGeneratorComponent shield, out Vector3 intersectionWorldPoint)
        {
            SmartEntity smartEntity = shield.Entity as SmartEntity;

            if (smartEntity == null)
            {
                intersectionWorldPoint = Vector3.zero;
                return(false);
            }
            TransformComponent transformComp = smartEntity.TransformComp;
            Vector3            ellipseOrigin = new Vector3(Units.BoardToWorldX(transformComp.CenterX()), 1.25f, Units.BoardToWorldZ(transformComp.CenterZ()));
            float   num           = 3f * (float)shield.CurrentRadius;
            Vector3 ellipseRadius = new Vector3(num, num, num);
            Vector3 rayDir        = targetPos - rayPos;

            targetPos.Normalize();
            return(UnityUtils.GetRayEllipsoidIntersection(rayPos, rayDir, ellipseOrigin, ellipseRadius, out intersectionWorldPoint));
        }
Example #26
0
 public EatResponse OnEvent(EventId id, object cookie)
 {
     if (id != EventId.BuildingQuickStashed)
     {
         if (id != EventId.UserLoweredBuilding)
         {
             if (id == EventId.BuildingViewReady)
             {
                 EntityViewParams entityViewParams = (EntityViewParams)cookie;
                 if (this.IsBuildingStashed(entityViewParams.Entity))
                 {
                     GameObjectViewComponent gameObjectViewComp = entityViewParams.Entity.GameObjectViewComp;
                     TransformComponent      transformComp      = entityViewParams.Entity.TransformComp;
                     gameObjectViewComp.SetXYZ(Units.BoardToWorldX(transformComp.CenterX()), -1000f, Units.BoardToWorldZ(transformComp.CenterZ()));
                 }
             }
         }
         else
         {
             Entity entity = (Entity)cookie;
             if (entity != null)
             {
                 Building buildingTO = entity.Get <BuildingComponent>().BuildingTO;
                 Position position   = this.lastSavedMap.GetPosition(buildingTO.Key);
                 if ((position != null && this.HasBuildingMoved(buildingTO, position)) || (Service.GameStateMachine.CurrentState is WarBaseEditorState && position == null))
                 {
                     this.ShouldRevertMap = true;
                 }
             }
         }
     }
     else if (this.IsQuickStashModeEnabled)
     {
         SmartEntity smartEntity = (SmartEntity)cookie;
         this.StashBuilding(smartEntity);
         string uid = smartEntity.BuildingComp.BuildingTO.Uid;
         Service.BuildingController.EnsureDeselectSelectedBuilding();
         Service.UXController.HUD.BaseLayoutToolView.RefreshStashedBuildingCount(uid);
     }
     return(EatResponse.NotEaten);
 }