public override void Update(GameTime gameTime) { if (CloakingTokens > 0) { SearchTime += gameTime.ElapsedGameTime.Milliseconds; if (SearchTime > CloakSearchTime) { SearchTime -= CloakSearchTime; QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(MaxEngagementDistance))) { if (o.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret u = (UnitTurret)o; u.fieldState = FieldState.Cloaked; u.FieldStateTime = 1000000; CloakingTokens--; fieldState = FieldState.Cloaked; FieldStateTime = 1000000; if (CloakingTokens == 0) { break; } } } } } base.Update(gameTime); }
protected override void AISearch(GameTime gameTime) { CurrentAttackTarget = null; float BestDistance = 1000000; foreach (Basic2DObject o in FactionManager.SortedUnits[WaveManager.ActiveTeam]) { if (o != this && o.GetType().IsSubclassOf(typeof(UnitTurret))) { float d = Vector2.Distance(getPosition(), o.getPosition()); if (d < BestDistance) { UnitTurret s = (UnitTurret)o; if (s.GetTeam() == WaveManager.ActiveTeam && s.ShutDownTime < 1 && !s.Dead && !s.IsAlly(this) && s.Resistence != AttackType.Green) { if (d / s.ThreatLevel < BestDistance && !PathFindingManager.CollisionLine(Position.get(), o.Position.get())) { BestDistance = d / s.ThreatLevel; CurrentAttackTarget = s; } } } } } }
public override void Draw2D(GameObjectTag DrawTag) { bool IsUpgraded = false; if (GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret u = (UnitTurret)this; IsUpgraded = u.IsUpdgraded; } if (ShieldDamage > 0 || HullDamage > 0 || Dead || IsUpgraded || GetType().IsSubclassOf(typeof(MiningPlatform))) { float HealthMult = 1 - (((HullDamage > HullToughness ? HullToughness : HullDamage) + (ShieldDamage > ShieldToughness ? ShieldToughness : ShieldDamage)) / (ShieldToughness + HullToughness)); Vector3 Position3 = Game1.graphicsDevice.Viewport.Project( new Vector3(this.Position.X(), Y, this.Position.Y()), StarshipScene.CurrentCamera.ProjectionMatrix, StarshipScene.CurrentCamera.ViewMatrix, Matrix.Identity); Vector3 Size3 = Game1.graphicsDevice.Viewport.Project( new Vector3(this.Position.X() + this.Size.X(), Y, this.Position.Y()), StarshipScene.CurrentCamera.ProjectionMatrix, StarshipScene.CurrentCamera.ViewMatrix, Matrix.Identity); Vector2 Position = new Vector2(Position3.X, Position3.Y) - Render.CurrentView.Position; float Size = Vector2.Distance(Position, new Vector2(Size3.X, Size3.Y) - Render.CurrentView.Position) / 1.6f; Position.Y -= Size; DrawHealthBar(HealthMult, Position, Size); } base.Draw2D(DrawTag); }
public override void Update(GameTime gameTime) { float Mult = 0.1f + TimeAlive / (float)LifeTime; float Offset = 200 * Mult; Vector3 Position3 = new Vector3(0, ParentUnit.Y, 0); float Theta = -Logic.ToAngle(Speed) - (float)Math.PI * 1f; float TargetTheta = Theta + (float)(Math.PI * 1.05); float Alpha = 1 - (float)LifeTime / TimeAlive; for (; Theta < TargetTheta; Theta += (float)Math.PI / 20) { Position3.X = Position.X() + (float)Math.Cos(Theta) * Offset; Position3.Z = Position.Y() + (float)Math.Sin(Theta) * Offset; ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor * Alpha, Offset * 4, 1); //ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, Offset, 0); } Position3.X = Position.X(); Position3.Z = Position.Y(); if (!Flashed) { Mult *= 2; ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 80 * Mult, 0); ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 80 * Mult, 4); Flashed = true; } QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(Offset * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitTurret)) && o != FirstHitTurret && Vector2.Distance(o.Position.get(), Position.get()) < Offset) { UnitTurret u = (UnitTurret)o; if (u.CanBeTargeted()) { if (FirstHitTurret == null) { FirstHitTurret = u; } else { u.ShutDownTime = (int)(1000 * Level); } } } } base.Update(gameTime); }
public override void Destroy() { this.Armed = false; Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y()); for (int i = 0; i < 10; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 2000, ParticleColor, 20, 5); } ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, 4000, 5); for (int i = 0; i < 2; i++) { FlamingChunkSystem.AddParticle(Position3, Rand.V3() / 1.5f, new Vector3(0, -0.25f, 0), Rand.V3(), Rand.V3() / 10, 150, 30, new Vector3(0.2f, 0.5f, 1), new Vector3(0.2f, 0.5f, 1), 0, 3); } ParticleManager.CreateParticle(Position3, Vector3.Zero, new Color(0.5f, 0.75f, 1), Size.X() * 50, 4); for (int i = 0; i < 30; i++) { ParticleManager.CreateParticle(Position3, Rand.V3() * 200, new Color(0.5f, 0.75f, 1), 200, 5); } QuadGrid quadGrid = Parent2DScene.quadGrids.First.Value; float MaxDist = 100 * Level; foreach (GameObject g in quadGrid.Enumerate(Position.get(), new Vector2(MaxDist * 2))) { if (g.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret s = (UnitTurret)g; if (Vector2.Distance(Position.get(), s.Position.get()) < MaxDist && !s.IsAlly(ParentUnit)) { s.Relocate(); } } } base.Destroy(); }
public virtual void Virus(int VirusTime) { if (this.VirusTime < VirusTime) { this.VirusTime = VirusTime; QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(VirusTime / 50f * 2))) { if (o.GetType().IsSubclassOf(typeof(UnitTurret)) && Vector2.Distance(o.Position.get(), Position.get()) < VirusTime / 50f) { UnitTurret u = (UnitTurret)o; if (u.CanBeTargeted() && u.IsAlly(this)) { u.Virus(VirusTime); } } } } }
public override void Update(GameTime gameTime) { if (Shots > 0) { PauseTime += gameTime.ElapsedGameTime.Milliseconds; if (PauseTime > MaxPauseTime) { if (MissileAttackTarget == null || !MissileAttackTarget.CanBeTargeted()) { float BestDistance = 100000; foreach (BasicShipGameObject o in FactionManager.SortedUnits[WaveManager.ActiveTeam]) { if (o.GetType().IsSubclassOf(typeof(UnitTurret))) { float d = Vector2.Distance(Position.get(), o.Position.get()); if (d < BestDistance) { BestDistance = d; MissileAttackTarget = (UnitTurret)o; } } } } else { float TargetRotation = Logic.ToAngle(MissileAttackTarget.Position.get() - Position.get()); Rotation.set(MathHelper.ToDegrees(Logic.Clerp(Rotation.getAsRadians(), TargetRotation, RotationSpeed * gameTime.ElapsedGameTime.Milliseconds * 60.0f / 1000.0f))); RotationMatrix = Matrix.CreateFromYawPitchRoll(Rotation.getAsRadians() + RotationOffset.X, RotationOffset.Y, RotationOffset.Z); if (Math.Abs(Rotation.getAsRadians() - TargetRotation) < 0.1f) { PauseTime = 0; Shots = 1; EmpFireMode.SetParent(this); EmpFireMode.Fire(TargetRotation); } } } } base.Update(gameTime); }
public override bool APress(PlayerShip Ship, bool APrevious) { if (!APrevious) { { int CardCost = CardCellsCost; if (FactionCostIncreases.ContainsKey(Ship.FactionNumber)) { CardCost += CardCellsCostIncrease * FactionCostIncreases[Ship.FactionNumber]; } if (FactionManager.CanAfford(Ship.FactionNumber, CardCost) && Ship.CanPlaceTurret(TurretSize)) { if (FactionCostIncreases.ContainsKey(Ship.FactionNumber)) { FactionCostIncreases[Ship.FactionNumber]++; } else { FactionCostIncreases.Add(Ship.FactionNumber, 1); } FactionManager.AddCells(Ship.FactionNumber, -CardCost); UnitTurret u = (UnitTurret)GetUnit(Ship.FactionNumber); u.MyCard = this; Ship.PlaceTurret(u); return(true); } else { RedFlashAlpha = 1; } } } return(false); }
public virtual Vector2 GetPlacePosition(int FactionNumber) { float BestScore = -500000; Vector2 BestPosition = Vector2.Zero; float Distance = 1000; float JumpSize = 100; Vector2 MinPos = new Vector2(10000); Vector2 MaxPos = new Vector2(-10000); foreach (MiningPlatform m in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform))) { if (m.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m.Dead) { MinPos = Vector2.Min(MinPos, m.Position.get() - new Vector2(Distance)); MaxPos = Vector2.Max(MaxPos, m.Position.get() + new Vector2(Distance)); } } Basic2DScene b = (Basic2DScene)GameManager.GetLevel().getCurrentScene(); MinPos = Vector2.Max(MinPos, b.MinBoundary.get()); MaxPos = Vector2.Min(MaxPos, b.MaxBoundary.get()); for (float x = MinPos.X; x < MaxPos.X; x += JumpSize) { for (float y = MinPos.Y; y < MaxPos.Y; y += JumpSize) { if (TestFree(new Vector2(x, y), TurretSize, FactionNumber) && PathFindingManager.GetCellValue(new Vector2(x, y)) != PathFindingManager.DeadCell) { float score = 5000; if (GetTurretFragility() != 0) { if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 0, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 0, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, 1, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, -1, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, -1, 2)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, -1, 2)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 1, 2)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 1, 2)) { score += 100 * GetTurretFragility(); } } foreach (NeutralSpawn spawn in NeutralManager.SpawnList) { if (PathFindingManager.GetCellValue(spawn.Position.get()) > PathFindingManager.StartingCell - 50 && PathFindingManager.GetCellValue(spawn.Position.get()) < PathFindingManager.StartingCell - 20 && PathFindingManager.GetAreaClear(spawn.Position.get())) { if (GetTurretFragility() != 0 && PathFindingManager.CollisionLine(new Vector2(x, y), spawn.Position.get())) { score += 500 * GetTurretFragility(); } if (score > BestScore) { MiningPlatform NearestMiningPlatform = null; float NearestDistance = 10000; foreach (MiningPlatform m2 in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform))) { if (m2.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m2.Dead) { float d = Vector2.Distance(m2.Position.get(), spawn.Position.get()); if (d < NearestDistance) { NearestDistance = d; NearestMiningPlatform = m2; } } } score -= Logic.DistanceLineSegmentToPoint(spawn.Position.get(), NearestMiningPlatform.Position.get(), new Vector2(x, y)) * GetTurretAgression(); } } } if (score > BestScore) { Basic2DScene Parent2DScene = (Basic2DScene)GameManager.GetLevel().getCurrentScene(); QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(new Vector2(x, y), new Vector2(200))) { if (o.GetType().IsSubclassOf(typeof(UnitBuilding))) { UnitBuilding s = (UnitBuilding)o; if (s.GetTeam() == FactionManager.GetTeam(FactionNumber)) { float d = Vector2.Distance(o.Position.get(), new Vector2(x, y)); if (d < 2000) { score -= (2000 - d) * GetBuildingAvoidence(); if (s.GetType().IsSubclassOf(typeof(MiningPlatform))) { score -= (2000 - d) * GetBaseAvoidence(); } else if (s.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret t = (UnitTurret)s; if (t.MyCard != null) { if (t.MyCard.StrongVs.Equals(StrongVs)) { score -= (2000 - d) * GetTurretAvoidence(); } } else { if (StrongVs.Equals("Heavy")) { score -= (2000 - d) * GetTurretAvoidence(); } } } } } } } if (score > BestScore) { BestScore = score; BestPosition = new Vector2(x, y); } } } } } return(BestPosition); }
public override void Update(GameTime gameTime) { int JobCount = CellJobQue.Count; while (JobCount > 0) { Drawing = true; int x = CellJobQue.Dequeue(); int y = CellJobQue.Dequeue(); int value = CellJobQue.Dequeue(); if (x > -1 && y > -1 && x < CellsX.get() && y < CellsY.get() && CellGrid[x, y] < value && CellGrid[x, y] != DeadCell) { CellGrid[x, y] = value; CellAlpha[x, y] = 1; MakeJob(x - 1, y, value - 1); MakeJob(x + 1, y, value - 1); MakeJob(x, y - 1, value - 1); MakeJob(x, y + 1, value - 1); } JobCount -= 3; } JobCount = AttackJobQue.Count; while (JobCount > 0) { Drawing = true; int x = AttackJobQue.Dequeue(); int y = AttackJobQue.Dequeue(); int value = AttackJobQue.Dequeue(); if (x > -1 && y > -1 && x < CellsX.get() && y < CellsY.get() && AttackGrid[x, y] < value) { AttackGrid[x, y] = value; int NewValue = value - 1; foreach (UnitBasic u in FactionManager.SortedUnits[WaveManager.ActiveTeam]) { if (u.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret t = (UnitTurret)u; if (t.MyCard != null) { if ((!t.MyCard.StrongVs.Equals("Light") && !t.MyCard.StrongVs.Equals("")) && Vector2.Distance(TransformToWorld(x, y), t.Position.get()) < t.MaxEngagementDistance) { NewValue -= 10; } } else if (Vector2.Distance(TransformToWorld(x, y), t.Position.get()) < t.MaxEngagementDistance) { NewValue -= 10; } } } MakeAttackJob(x - 1, y, NewValue); MakeAttackJob(x + 1, y, NewValue); MakeAttackJob(x, y - 1, NewValue); MakeAttackJob(x, y + 1, NewValue); } JobCount -= 3; } if (Drawing) { Drawing = false; for (int x = 0; x < CellsX.get(); x++) { for (int y = 0; y < CellsY.get(); y++) { if (CellAlpha[x, y] > 0) { CellAlpha[x, y] -= gameTime.ElapsedGameTime.Milliseconds * 60 / 100000f; Drawing = true; } } } } base.Update(gameTime); }
public override bool TriggerAsCurrent(BasicMarker m) { if (BasicMarker.SelectSound != null) { BasicMarker.SelectSound.Play(BasicMarker.SelectVolume, 0, 0); } Faction f = FactionManager.Factions[ParentShip.FactionNumber]; FlashAlpha = 1; if (FactionManager.GetFaction(ParentShip.FactionNumber).PickingCards) { if (Selected) { for (int i = 0; i < f.Cards.Count; i++) { if (f.Cards[i] == MyCard) { f.Cards[i] = null; Selected = false; return(true); } } } else { for (int i = 0; i < f.Cards.Count; i++) { if (f.Cards[i] == null) { f.Cards[i] = MyCard; Selected = true; break; } } if (!Selected) { f.Cards.Add(MyCard); Selected = true; } if (Faction.MaxCards == f.Cards.Count) { for (int i = 0; i < f.Cards.Count; i++) { if (f.Cards[i] == null) { return(true); } } ParentShip.ReadyMenu(); } } } else { int CardCost = MyCard.CardCellsCost; if (MyCard.FactionCostIncreases.ContainsKey(ParentShip.FactionNumber)) { CardCost += MyCard.CardCellsCostIncrease * MyCard.FactionCostIncreases[ParentShip.FactionNumber]; } if (FactionManager.CanAfford(ParentShip.FactionNumber, CardCost) && ParentShip.CanPlaceTurret(MyCard.TurretSize)) { if (MyCard.FactionCostIncreases.ContainsKey(ParentShip.FactionNumber)) { MyCard.FactionCostIncreases[ParentShip.FactionNumber]++; } else { MyCard.FactionCostIncreases.Add(ParentShip.FactionNumber, 1); } FactionManager.AddCells(ParentShip.FactionNumber, -CardCost); UnitTurret u = (UnitTurret)MyCard.GetUnit(ParentShip.FactionNumber); u.MyCard = MyCard; ParentShip.PlaceTurret(u); //ParentFrame.DeActivate(); } else { ErrorAlpha = 1; } } return(base.TriggerAsCurrent(m)); }
public BustedTurret(UnitTurret ParentTurret) : base(-1) { this.ParentTurret = ParentTurret; }
public override void Update(GameTime gameTime) { float dist = SplinterTurretCard.EngagementDistance; UnitTurret u = (UnitTurret)ParentUnit; if (u.IsUpdgraded) { dist *= 1.5f; } Vector2 StartPosition = Position.get(); Vector2 EndPosition = Position.get() + Vector2.Normalize(Speed) * dist; ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, ParticleColor, 300, 5); ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, ParticleColor, 300, 4); for (int i = 0; i < 100; i++) { ParticleManager.CreateParticle( new Vector3(StartPosition.X, 0, StartPosition.Y) + (new Vector3(EndPosition.X - StartPosition.X, 0, EndPosition.Y - StartPosition.Y) * i / 100), Vector3.Zero, ParticleColor, 100, 5); } ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, ParticleColor, 300, 5); ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, ParticleColor, 300, 4); QuadGrid quadGrid = Parent2DScene.quadGrids.First.Value; Vector2 UpperLeftCorner = Logic.Min(StartPosition, EndPosition) - new Vector2(200); Vector2 LowerRightCorner = Logic.Max(StartPosition, EndPosition) + new Vector2(200); QuadGridXMin = (int)((UpperLeftCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X); QuadGridXMax = (int)((LowerRightCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X); QuadGridYMin = (int)((UpperLeftCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y); QuadGridYMax = (int)((LowerRightCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y); if (QuadGridXMax > quadGrid.CellsX - 1) { QuadGridXMax = quadGrid.CellsX - 1; } if (QuadGridXMin > quadGrid.CellsX - 1) { QuadGridXMin = quadGrid.CellsX - 1; } if (QuadGridYMax > quadGrid.CellsY - 1) { QuadGridYMax = quadGrid.CellsY - 1; } if (QuadGridYMin > quadGrid.CellsY - 1) { QuadGridYMin = quadGrid.CellsY - 1; } if (QuadGridXMax < 0) { QuadGridXMax = 0; } if (QuadGridXMin < 0) { QuadGridXMin = 0; } if (QuadGridYMax < 0) { QuadGridYMax = 0; } if (QuadGridYMin < 0) { QuadGridYMin = 0; } foreach (Basic2DObject g in quadGrid.Enumerate(QuadGridXMin, QuadGridYMin, QuadGridXMax, QuadGridYMax)) { if (g.GetType().IsSubclassOf(typeof(BasicShipGameObject))) { BasicShipGameObject s = (BasicShipGameObject)g; if (!s.IsAlly(ParentUnit) && CheckCircle(s, StartPosition, EndPosition, AttackLineWidth)) { s = s.ReturnCollision(); if (s != null) { s.Damage(Damage, 0.75f, EndPosition - StartPosition, ParentUnit, AttackType.Red); } } } } Destroy(); }