|
1 | | -///Always required |
2 | | -///Possible libraries |
3 | | -using RimWorld; |
| 1 | +using RimWorld; |
| 2 | +using System; |
| 3 | +using System.Linq; |
| 4 | +using UnityEngine; |
4 | 5 | using Verse; |
5 | 6 | using Verse.Sound; |
6 | | -using Verse.AI.Group; |
7 | | -//using RimWorld.Planet; |
8 | | -//using Verse.AI; |
9 | | -//using Verse.AI.Group; |
10 | | - |
11 | 7 |
|
12 | 8 | namespace CosmicHorror |
13 | 9 | { |
14 | | - public class IncidentWorker_StarVampireAttack : IncidentWorker |
15 | | - { |
16 | | - private CosmicHorrorPawn iwVampire; //The Star Vampire Pawn |
17 | | - private ThingDef iwDef; //For the custom Spawner from JecsTools |
18 | | - private Faction iwFac; //The Star Vampire Faction |
19 | | - private IntVec3 iwLoc; //The Star Vampire location |
20 | | - private SoundDef iwWarn; //The Star Vampire Warning Noise |
21 | | - private Lord lord; //The Star Vampire AI manager |
22 | | - |
23 | | - protected override bool CanFireNowSub(IncidentParms parms) |
24 | | - { |
25 | | - if (GenDate.DaysPassed < (ModInfo.cosmicHorrorRaidDelay + this.def.earliestDay)) |
26 | | - { |
27 | | - Log.Message("Cosmic Horrors :: CantFireDueTo Time :: " + GenDate.DaysPassed + " days passed, but we need " + ModInfo.cosmicHorrorRaidDelay.ToString() + " days + " + this.def.earliestDay); |
28 | | - return false; |
29 | | - } |
30 | | - return true; |
31 | | - } |
32 | | - |
33 | | - protected override bool TryExecuteWorker(IncidentParms parms) |
34 | | - { |
35 | | - |
36 | | - //Resolve parameters. |
37 | | - ResolveSpawnCenter(parms); |
38 | | - |
39 | | - //Initialize variables. |
40 | | - this.iwDef = ResolveSpawner(parms); |
41 | | - this.iwWarn = MonsterDefOf.Pawn_ROM_StarVampire_Warning; |
42 | | - this.iwVampire = null; //iwPawn as CosmicHorrorPawn; |
43 | | - this.iwLoc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, (Map)parms.target, 8); |
44 | | - |
45 | | - //In-case there's something silly happening... |
46 | | - if (this.iwFac == null) |
47 | | - { |
48 | | - this.iwFac = Find.FactionManager.FirstFactionOfDef(FactionDefOf.AncientsHostile); |
49 | | - } |
50 | | - |
51 | | - //Slow down time |
52 | | - Find.TickManager.slower.SignalForceNormalSpeed(); |
53 | | - //Play a sound. |
54 | | - this.iwWarn.PlayOneShotOnCamera(); |
55 | | - //Show the warning message. |
56 | | - Messages.Message("StarVampireIncidentMessage".Translate(), new RimWorld.Planet.GlobalTargetInfo(IntVec3.Invalid, (Map)parms.target), MessageTypeDefOf.SituationResolved); |
57 | | - //Spawn the Star Vampire. |
58 | | - SpawnStarVampires(parms); |
59 | | - return true; |
60 | | - } |
61 | | - |
62 | | - private static ThingDef ResolveSpawner(IncidentParms parms) |
| 10 | + public class IncidentWorker_StarVampireAttack : IncidentWorker |
| 11 | + { |
| 12 | + protected override bool CanFireNowSub(IncidentParms parms) |
| 13 | + { |
| 14 | + if (!base.CanFireNowSub(parms)) |
| 15 | + { |
| 16 | + return false; |
| 17 | + } |
| 18 | + Map map = (Map)parms.target; |
| 19 | + IntVec3 intVec; |
| 20 | + return RCellFinder.TryFindRandomPawnEntryCell(out intVec, map, CellFinder.EdgeRoadChance_Animal, false, null); |
| 21 | + } |
| 22 | + |
| 23 | + private int NumberToSpawn(IncidentParms parms) |
63 | 24 | { |
64 | | - Map iwMap = (Map)parms.target; |
65 | | - var abberation = (GenCelestial.IsDaytime(GenCelestial.CelestialSunGlow(iwMap, Find.TickManager.TicksAbs))) |
66 | | - ? MonsterDefOf.ROM_StarVampireSpawnerAbberation |
67 | | - : MonsterDefOf.ROM_StarVampireSpawnerNight; |
68 | | - |
69 | | - var chance = Rand.Value; |
70 | | - if (chance > 0.3) |
71 | | - return MonsterDefOf.ROM_StarVampireSpawner; |
72 | | - else if (chance > 0.05) |
73 | | - return abberation; |
74 | | - else |
75 | | - return MonsterDefOf.ROM_StarVampireSpawnerAlbino; |
76 | | - } |
77 | | - |
78 | | - /// <summary> |
79 | | - /// Where to, Cthulhu? |
80 | | - /// </summary> |
81 | | - /// <param name="parms"></param> |
82 | | - protected void ResolveSpawnCenter(IncidentParms parms) |
83 | | - { |
84 | | - Map iwMap = (Map)parms.target; |
85 | | - if (parms.spawnCenter.IsValid) |
86 | | - { |
87 | | - return; |
88 | | - } |
89 | | - if (Rand.Value < 0.4f && iwMap.listerBuildings.ColonistsHaveBuildingWithPowerOn(ThingDefOf.OrbitalTradeBeacon)) |
90 | | - { |
91 | | - parms.spawnCenter = DropCellFinder.TradeDropSpot(iwMap); |
92 | | - } |
93 | | - else |
94 | | - { |
95 | | - RCellFinder.TryFindRandomPawnEntryCell(out parms.spawnCenter, iwMap, 0.0f); |
96 | | - } |
97 | | - } |
98 | | - |
99 | | - /// <summary> |
100 | | - /// Finds the best number of Star Vampires |
101 | | - /// to spawn. Then spawns them according |
102 | | - /// to a previously resolved location. |
103 | | - /// </summary> |
104 | | - /// <param name="parms"></param> |
105 | | - protected void SpawnStarVampires(IncidentParms parms) |
106 | | - { |
107 | | - Map iwMap = (Map)parms.target; |
108 | | - |
109 | | - int iwCount = 1; |
110 | | - |
111 | | - if (parms.points <= 2000f) |
112 | | - { |
113 | | - iwCount = 1; |
114 | | - } |
115 | | - else if (parms.points <= 3000f) |
116 | | - { |
117 | | - iwCount = 2; |
118 | | - } |
119 | | - else if (parms.points <= 5000f) |
120 | | - { |
121 | | - iwCount = 3; |
122 | | - } |
123 | | - |
124 | | - for (int i = 0; i < iwCount; i++) |
125 | | - { |
126 | | - Thing iwSpawner = ThingMaker.MakeThing(iwDef, null); |
127 | | - GenPlace.TryPlaceThing(iwSpawner, iwLoc, iwMap, ThingPlaceMode.Near); |
128 | | - // CosmicHorrorPawn temp = null; |
129 | | - // this.iwVampire = null; |
130 | | - // this.iwSpawner = ThingMaker.MakeThing(this.iwKind, this.iwFac); |
131 | | - // this.iwVampire = this.iwPawn as CosmicHorrorPawn; |
132 | | - |
133 | | - //if (this.lord == null) |
134 | | - //{ |
135 | | - // LordJob_StarVampire lordJob = new LordJob_StarVampire(this.iwFac, this.iwLoc); |
136 | | - // this.lord = LordMaker.MakeNewLord(this.iwFac, lordJob, iwMap, null); |
137 | | - //} |
138 | | - //temp = (CosmicHorrorPawn)GenSpawn.Spawn(this.iwVampire, this.iwLoc, iwMap); |
139 | | - //this.lord.AddPawn(temp); |
140 | | - } |
141 | | - } |
142 | | - } |
| 25 | + Map iwMap = (Map)parms.target; |
| 26 | + |
| 27 | + int iwCount = 1; |
| 28 | + |
| 29 | + if (parms.points <= 2000f) |
| 30 | + { |
| 31 | + iwCount = 1; |
| 32 | + } |
| 33 | + else if (parms.points <= 3000f) |
| 34 | + { |
| 35 | + iwCount = 2; |
| 36 | + } |
| 37 | + else |
| 38 | + { |
| 39 | + iwCount = 3; |
| 40 | + } |
| 41 | + return iwCount; |
| 42 | + } |
| 43 | + |
| 44 | + protected override bool TryExecuteWorker(IncidentParms parms) |
| 45 | + { |
| 46 | + Map map = (Map)parms.target; |
| 47 | + IntVec3 intVec; |
| 48 | + if (!RCellFinder.TryFindRandomPawnEntryCell(out intVec, map, CellFinder.EdgeRoadChance_Animal, false, null)) |
| 49 | + { |
| 50 | + return false; |
| 51 | + } |
| 52 | + map.GetComponent<MapComponent_StarVampireTracker>().AddNewStarVampireSpawner(intVec, NumberToSpawn(parms)); |
| 53 | + |
| 54 | + //Slow down time |
| 55 | + Find.TickManager.slower.SignalForceNormalSpeed(); |
| 56 | + //Play a sound. |
| 57 | + MonsterDefOf.Pawn_ROM_StarVampire_Warning.PlayOneShotOnCamera(); |
| 58 | + //Show the warning message. |
| 59 | + Messages.Message("StarVampireIncidentMessage".Translate(), new RimWorld.Planet.GlobalTargetInfo(IntVec3.Invalid, (Map)parms.target), MessageTypeDefOf.SituationResolved); |
| 60 | + |
| 61 | + return true; |
| 62 | + } |
| 63 | + |
| 64 | + } |
143 | 65 | } |
0 commit comments