public void OnTick() { var map = Map; if (map == null) { return; } else if (CannonsOperational && NextShoot < DateTime.UtcNow) { foreach (var cannon in Cannons.Where(c => c != null && !c.Deleted && (c.CanFireUnmanned || (c.Operator != null && !c.Operator.Deleted && c.Operator.Alive)))) { cannon.Scan(true); } NextShoot = DateTime.UtcNow + TimeSpan.FromSeconds(2); } if (NextSpawn < DateTime.UtcNow) { if (SpawnCount() < MaxSpawn) { Point3D p = Location; var range = 15; if (Beacon.LastDamager != null && Beacon.LastDamager.InRange(Location, 20)) { p = Beacon.LastDamager.Location; range = 8; } BaseCreature creature = Activator.CreateInstance(_SpawnTypes[Utility.Random(_SpawnTypes.Length)]) as BaseCreature; for (int i = 0; i < 50; i++) { var spawnLoc = new Point3D(Utility.RandomMinMax(p.X - range, p.X + range), Utility.RandomMinMax(p.Y - range, p.Y + range), -5); if (map.CanFit(spawnLoc.X, spawnLoc.Y, spawnLoc.Z, 16, true, true, false, creature)) { if (creature != null) { creature.MoveToWorld(spawnLoc, map); creature.Home = spawnLoc; creature.RangeHome = 10; Spawn.Add(creature); NextSpawn = DateTime.UtcNow + TimeSpan.FromSeconds(Utility.RandomMinMax(30, 60)); return; } } } creature.Delete(); } } }
public void OnTick() { if (_CheckSpawn) { if (BaseCreature.IsSoulboundEnemies && Spawn != null) { foreach (BaseCreature bc in Spawn.Keys) { if (!bc.Deleted) { bc.IsSoulBound = true; } } } _CheckSpawn = false; } Map map = Map; if (map == null) { return; } else if (!InitialSpawn) { for (int i = 0; i < MaxSpawn; i++) { SpawnHelper(true); InitialSpawn = true; } } else if (CannonsOperational && NextShoot < DateTime.UtcNow) { foreach (MannedCannon cannon in Cannons.Where(c => c != null && !c.Deleted && (c.CanFireUnmanned || (c.Operator != null && !c.Operator.Deleted && c.Operator.Alive)))) { cannon.Scan(true); } NextShoot = DateTime.UtcNow + TimeSpan.FromSeconds(2); } if (NextSpawn < DateTime.UtcNow) { Timer.DelayCall(TimeSpan.FromSeconds(1), () => { if (SpawnCount() < MaxSpawn) { SpawnHelper(false); } }); } }
public override void PostDrawExtraSelectionOverlays() { base.PostDrawExtraSelectionOverlays(); if (Cannons?.Where(x => x.cannonDef.weaponType == WeaponType.Static).Count() > 0 && this.Pawn.Drafted) { if (MinRange > 0) { GenDraw.DrawRadiusRing(this.Pawn.DrawPosTransformed(CompShip.Props.hitboxOffsetX, CompShip.Props.hitboxOffsetZ, CompShip.Angle).ToIntVec3(), this.MinRange, Color.red); } GenDraw.DrawRadiusRing(this.Pawn.DrawPosTransformed(CompShip.Props.hitboxOffsetX, CompShip.Props.hitboxOffsetZ, CompShip.Angle).ToIntVec3(), this.Range); } }
public override void PostSpawnSetup(bool respawningAfterLoad) { base.PostSpawnSetup(respawningAfterLoad); if (!respawningAfterLoad) { InitializeCannons(); } foreach (CannonHandler cannon in Cannons) { if (!string.IsNullOrEmpty(cannon.key)) { Cannons.Where(x => x.parentKey == cannon.key).ToList().ForEach(y => y.attachedTo = cannon); } } broadsideFire = new List <SPTuple <Stack <int>, CannonHandler, int> >(); multiFireCannon = new List <SPTuple <int, CannonHandler, SPTuple2 <int, int> > >(); }
public void OnTick() { var map = Map; if (map == null) { return; } else if (!InitialSpawn) { for (int i = 0; i < MaxSpawn; i++) { SpawnHelper(true); InitialSpawn = true; } } else if (CannonsOperational && NextShoot < DateTime.UtcNow) { foreach (var cannon in Cannons.Where(c => c != null && !c.Deleted && (c.CanFireUnmanned || (c.Operator != null && !c.Operator.Deleted && c.Operator.Alive)))) { cannon.Scan(true); } NextShoot = DateTime.UtcNow + TimeSpan.FromSeconds(2); } if (NextSpawn < DateTime.UtcNow) { Timer.DelayCall(TimeSpan.FromSeconds(1), () => { if (SpawnCount() < MaxSpawn) { SpawnHelper(false); } }); } }
public override IEnumerable <Gizmo> CompGetGizmosExtra() { if (this.Pawn.Drafted) { if (Cannons.Count > 0) { if (Cannons.Any(x => x.cannonDef.weaponType == WeaponType.Rotatable)) { int i = 0; foreach (CannonHandler cannon in Cannons.Where(x => x.cannonDef.weaponLocation == WeaponLocation.Turret)) { Command_TargeterCooldownAction turretCannons = new Command_TargeterCooldownAction(); turretCannons.cannon = cannon; turretCannons.comp = this; turretCannons.defaultLabel = "TestFire".Translate(cannon.cannonDef.label) + i; turretCannons.icon = cannon.GizmoIcon; if (!string.IsNullOrEmpty(cannon.cannonDef.gizmoDescription)) { turretCannons.defaultDesc = cannon.cannonDef.gizmoDescription; } turretCannons.targetingParams = new TargetingParameters { //Buildings, Things, Animals, Humans, and Mechs default to targetable canTargetLocations = true }; i++; yield return(turretCannons); } } if (Cannons.Any(x => x.cannonDef.weaponType == WeaponType.Static)) { if (Cannons.Any(x => x.cannonDef.weaponLocation == WeaponLocation.Port)) { foreach (CannonHandler cannon in Cannons.Where(x => x.cannonDef.weaponLocation == WeaponLocation.Port)) { Command_CooldownAction portSideCannons = new Command_CooldownAction(); portSideCannons.cannon = cannon; portSideCannons.comp = this; portSideCannons.defaultLabel = "CannonLabel".Translate(cannon.cannonDef.label); if (!string.IsNullOrEmpty(cannon.cannonDef.gizmoDescription)) { portSideCannons.defaultDesc = cannon.cannonDef.gizmoDescription; } portSideCannons.icon = cannon.GizmoIcon; if (!string.IsNullOrEmpty(cannon.cannonDef.gizmoDescription)) { portSideCannons.defaultDesc = cannon.cannonDef.gizmoDescription; } portSideCannons.action = delegate() { SPTuple <Stack <int>, CannonHandler, int> tmpCannonItem = new SPTuple <Stack <int>, CannonHandler, int>(new Stack <int>(), cannon, 0); List <int> cannonOrder = Enumerable.Range(0, cannon.cannonDef.numberCannons).ToList(); if (RimShipMod.mod.settings.shuffledCannonFire) { cannonOrder.Shuffle(); } foreach (int i in cannonOrder) { tmpCannonItem.First.Push(i); } this.broadsideFire.Add(tmpCannonItem); }; foreach (ShipHandler handler in this.CompShip.handlers) { if (!RimShipMod.mod.settings.debugDraftAnyShip && handler.role.handlingType == HandlingTypeFlags.Cannons && handler.handlers.Count < handler.role.slotsToOperate) { portSideCannons.Disable("NotEnoughCannonCrew".Translate(this.Pawn.LabelShort, handler.role.label)); } } yield return(portSideCannons); } } if (Cannons.Any(x => x.cannonDef.weaponLocation == WeaponLocation.Starboard)) { foreach (CannonHandler cannon in Cannons.Where(x => x.cannonDef.weaponLocation == WeaponLocation.Starboard)) { Command_CooldownAction starboardSideCannons = new Command_CooldownAction(); starboardSideCannons.cannon = cannon; starboardSideCannons.comp = this; starboardSideCannons.defaultLabel = "CannonLabel".Translate(cannon.cannonDef.label); if (!string.IsNullOrEmpty(cannon.cannonDef.gizmoDescription)) { starboardSideCannons.defaultDesc = cannon.cannonDef.gizmoDescription; } starboardSideCannons.icon = cannon.GizmoIcon; starboardSideCannons.action = delegate() { SPTuple <Stack <int>, CannonHandler, int> tmpCannonItem = new SPTuple <Stack <int>, CannonHandler, int>(new Stack <int>(), cannon, 0); List <int> cannonOrder = Enumerable.Range(0, cannon.cannonDef.numberCannons).ToList(); if (RimShipMod.mod.settings.shuffledCannonFire) { cannonOrder.Shuffle(); } foreach (int i in cannonOrder) { tmpCannonItem.First.Push(i); } this.broadsideFire.Add(tmpCannonItem); }; foreach (ShipHandler handler in this.CompShip.handlers) { if (!RimShipMod.mod.settings.debugDraftAnyShip && handler.role.handlingType == HandlingTypeFlags.Cannons && handler.handlers.Count < handler.role.slotsToOperate) { starboardSideCannons.Disable("NotEnoughCannonCrew".Translate(Pawn.LabelShort, handler.role.label)); } } yield return(starboardSideCannons); } } if (Cannons.Any(x => x.cannonDef.weaponLocation == WeaponLocation.Bow)) { foreach (CannonHandler cannon in Cannons.Where(x => x.cannonDef.weaponLocation == WeaponLocation.Bow)) { Command_CooldownAction bowSideCannons = new Command_CooldownAction(); bowSideCannons.cannon = cannon; bowSideCannons.comp = this; bowSideCannons.defaultLabel = "CannonLabel".Translate(cannon.cannonDef.label); if (!string.IsNullOrEmpty(cannon.cannonDef.gizmoDescription)) { bowSideCannons.defaultDesc = cannon.cannonDef.gizmoDescription; } bowSideCannons.icon = cannon.GizmoIcon; bowSideCannons.action = delegate() { SPTuple <Stack <int>, CannonHandler, int> tmpCannonItem = new SPTuple <Stack <int>, CannonHandler, int>(new Stack <int>(), cannon, 0); List <int> cannonOrder = Enumerable.Range(0, cannon.cannonDef.numberCannons).ToList(); if (RimShipMod.mod.settings.shuffledCannonFire) { cannonOrder.Shuffle(); } foreach (int i in cannonOrder) { tmpCannonItem.First.Push(i); } this.broadsideFire.Add(tmpCannonItem); }; foreach (ShipHandler handler in this.CompShip.handlers) { if (!RimShipMod.mod.settings.debugDraftAnyShip && handler.role.handlingType == HandlingTypeFlags.Cannons && handler.handlers.Count < handler.role.slotsToOperate) { bowSideCannons.Disable("NotEnoughCannonCrew".Translate(Pawn.LabelShort, handler.role.label)); } } yield return(bowSideCannons); } } if (Cannons.Any(x => x.cannonDef.weaponLocation == WeaponLocation.Stern)) { foreach (CannonHandler cannon in Cannons.Where(x => x.cannonDef.weaponLocation == WeaponLocation.Starboard)) { Command_CooldownAction sternSideCannons = new Command_CooldownAction(); sternSideCannons.cannon = cannon; sternSideCannons.comp = this; sternSideCannons.defaultLabel = "CannonLabel".Translate(cannon.cannonDef.label); if (!string.IsNullOrEmpty(cannon.cannonDef.gizmoDescription)) { sternSideCannons.defaultDesc = cannon.cannonDef.gizmoDescription; } sternSideCannons.icon = cannon.GizmoIcon; sternSideCannons.action = delegate() { SPTuple <Stack <int>, CannonHandler, int> tmpCannonItem = new SPTuple <Stack <int>, CannonHandler, int>(new Stack <int>(), cannon, 0); List <int> cannonOrder = Enumerable.Range(0, cannon.cannonDef.numberCannons).ToList(); if (RimShipMod.mod.settings.shuffledCannonFire) { cannonOrder.Shuffle(); } foreach (int i in cannonOrder) { tmpCannonItem.First.Push(i); } this.broadsideFire.Add(tmpCannonItem); }; foreach (ShipHandler handler in this.CompShip.handlers) { if (!RimShipMod.mod.settings.debugDraftAnyShip && handler.role.handlingType == HandlingTypeFlags.Cannons && handler.handlers.Count < handler.role.slotsToOperate) { sternSideCannons.Disable("NotEnoughCannonCrew".Translate(Pawn.LabelShort, handler.role.label)); } } yield return(sternSideCannons); } } Command_SetRange range = new Command_SetRange(); range.defaultLabel = "SetRange".Translate(); range.icon = TexCommand.Attack; range.activeCannons = Cannons.FindAll(x => x.cannonDef.weaponType == WeaponType.Static); range.cannonComp = this; yield return(range); } } } }