public InnerShineRecord(InnerShineItem ISI) { label = ISI.label; spawned = new List <Thing>(); ticksLeft = ISI.NewPeriod(); lastColor = Color.black; }
public static void UpdateMotes(this InnerShineItem ISI, InnerShineRecord ISR, Pawn pawn, bool debug = false) { if (ISR.spawned.NullOrEmpty()) { return; } for (int i = ISR.spawned.Count - 1; i >= 0; i--) { Thing curT = ISR.spawned[i]; if (curT.DestroyedOrNull()) { ISR.spawned.RemoveAt(i); continue; } if (!ISI.HasCompatibleActivity(pawn)) { curT.Destroy(); ISR.spawned.RemoveAt(i); continue; } if (curT is Mote mote) { mote.exactPosition = pawn.DrawPos + pawn.GetLinkOffset(ISI.linkType) + ISI.GetDrawOffset(pawn); //if (debug) Log.Warning(ISR.label + $" => mote.exactPosition: {mote.exactPosition} mote.DrawPos:{mote.DrawPos}"); } } }
public static void GetSpecifities(this InnerShineItem ISI, Pawn p, out Vector3 offset, out float scale) { offset = Vector3.zero; scale = 1; if (p.story?.bodyType == null || !ISI.HasBodyTypeDrawRules) { if (ISI.HasDefaultDrawRules) { offset = ISI.defaultDrawRules.GetRotationOffset(p); scale = ISI.defaultDrawRules.randomScale.RandomInRange; } return; } BodyTypeSpecificities BTS = ISI.bodyTypeDrawRules.Where(b => b.bodyTypeDef == p.story.bodyType).FirstOrFallback(); if (BTS == null) { if (ISI.HasDefaultDrawRules) { offset = ISI.defaultDrawRules.GetRotationOffset(p); scale = ISI.defaultDrawRules.randomScale.RandomInRange; } return; } offset = BTS.drawRules.GetRotationOffset(p); scale = BTS.drawRules.randomScale.RandomInRange; }
public static bool HasCompatibleActivity(this InnerShineItem ISI, Pawn p) { if (!ISI.HasRestriction) { return(true); } ActivityRestriction restrict = ISI.restriction; if (restrict.HasPostureRestriction && !restrict.allowedPostures.Contains(p.GetPosture())) { return(false); } if (restrict.HasJobRestriction && p.CurJob != null && !restrict.allowedJobs.Contains(p.CurJob.def)) { return(false); } if (restrict.HasAllowedRotation && !restrict.allowedRotation.Contains(p.Rotation)) { return(false); } return(true); }
public static bool ShouldSpawnMote(this InnerShineItem ISI, InnerShineRecord ISR, Pawn p) { if (!ISI.HasCompatibleActivity(p)) { return(false); } if (ISI.HasMoteNumLimit()) { return(!ISR.AlreadyReachedMax(ISI.spawningRules.spawnedMax)); } return(true); }
public override void CompPostTick(ref float severityAdjustment) { if (Pawn.Negligible()) { if (MyDebug) { Log.Warning("null pawn"); } return; } if (HasEmptyTracer) { this.CreateTracer(); } foreach (InnerShineRecord ISR in Tracer) { //InnerShineItem ISI = Props.innerShinePool.Where(i => i.label == ISR.label).FirstOrFallback(); InnerShineItem ISI = this.RetrieveISI(ISR.label); if (ISI == null) { if (MyDebug) { Log.Warning("Did not find ISI with label:" + ISR.label); } continue; } if (ISR.ticksLeft <= 0) { if (ISI.ShouldSpawnMote(ISR, Pawn)) { ISI.TryPlaceMote(ISR, Pawn); } ISI.ResetTicks(ISR); } else { ISR.ticksLeft--; } ISI.UpdateMotes(ISR, Pawn, MyDebug); } //if (MyDebug) Log.Warning(Pawn.ThingID + " trying to spawn mote - bodytype:" + Pawn.story?.bodyType?.defName); }
public static void ChangeMoteColor(this InnerShineItem ISI, InnerShineRecord ISR, Mote mote) { if (!ISI.HasColorRange || mote == null) { return; } if (ISR.lastColor == Color.black) { ISR.lastColor = ISI.colorRange.colorA; } ISR.lastColor = ISI.colorRange.RandomPickColor(ISR.lastColor, ISI.debug); mote.instanceColor = ISR.lastColor; }
public static void InitSpecs(this InnerShineItem ISI, InnerShineRecord ISR, Pawn pawn, out Vector3 drawPosWithOffset, out float scale) { Vector3 drawPos = pawn.DrawPos; ISI.GetSpecifities(pawn, out Vector3 bodyTypeOffset, out scale); Vector3 linkOffset = pawn.GetLinkOffset(ISI.linkType); drawPosWithOffset = drawPos + linkOffset + bodyTypeOffset; if (ISI.debug) { Log.Warning( pawn.ThingID + " " + ISI.label + " TryPlaceMote - " + "drawPos: " + drawPos + " linkOffset:" + linkOffset + " bodyTypeOffset:" + bodyTypeOffset + "scale: " + scale ); } }
public static Vector3 GetDrawOffset(this InnerShineItem ISI, Pawn p) { if (p.story?.bodyType == null || !ISI.HasBodyTypeDrawRules) { if (ISI.HasDefaultDrawRules) { return(ISI.defaultDrawRules.GetRotationOffset(p)); } else { return(Vector3.zero); } } BodyTypeSpecificities BTS = ISI.bodyTypeDrawRules.Where(b => b.bodyTypeDef == p.story.bodyType).FirstOrFallback(); if (BTS == null) { return(ISI.HasDefaultDrawRules ? ISI.defaultDrawRules.GetRotationOffset(p) : Vector3.zero); } return(BTS.drawRules.GetRotationOffset(p)); }
public static void TryPlaceMote(this InnerShineItem ISI, InnerShineRecord ISR, Pawn pawn) { //if (!HasShinePool)return; //Thing result = null; // wont exit because we want to record lastFootPos + use old value before recording it if (pawn.Position.InBounds(pawn.Map)) { float rot = 0; ISI.InitSpecs(ISR, pawn, out Vector3 drawPosWithOffset, out float scale); if (drawPosWithOffset.ToIntVec3().InBounds(pawn.Map)) { ThingDef moteDef = ISI.motePool.RandomElementWithFallback(); if (drawPosWithOffset.TryAnyMoteSpawn(pawn.Map, rot, scale, moteDef, ISI.debug) is Mote mote) { ISI.ChangeMoteColor(ISR, mote); ISR.spawned.Add(mote); ISI.NewPeriod(); } } } }
public static bool HasMoteNumLimit(this InnerShineItem ISI) => !ISI.spawningRules.IsUnlimited;
public static void ResetTicks(this InnerShineItem ISI, InnerShineRecord ISR) => ISR.ticksLeft = ISI.NewPeriod();
public static int NewPeriod(this InnerShineItem ISI) => ISI.spawningRules.period.RandomInRange;