public static Thing ShadowMoteSpawner_ThrowObjectAt(this JobDriver_PlayGenericTargetingGame PGTG) { Pawn thrower = PGTG.pawn; IntVec3 targetCell = PGTG.PetanqueSpotCell; SkillDef skillDef = PGTG.SkillDefScaling; ThingDef moteDef = PGTG.MoteDef; if (!thrower.AllowedMoteSpawn()) { return(null); } float randomSpeed = PGTG.Speed.RandomInRange; Vector3 destinationCell = targetCell.ToVector3Shifted() + Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(skillDef).Level / 20f) * 1.8f); destinationCell.y = thrower.DrawPos.y; ShadowMote moteThrown = (ShadowMote)ThingMaker.MakeThing(moteDef); //moteThrown.Initialization(thrower.DrawPos, destinationCell, PGTG.PetanqueSpotCell.ToVector3Shifted(), thrower); moteThrown.Initialization(PGTG, destinationCell); moteThrown.Scale = 1f; moteThrown.rotationRate = PGTG.Rotation.RandomInRange; moteThrown.exactPosition = thrower.DrawPos; moteThrown.SetVelocity((destinationCell - moteThrown.exactPosition).AngleFlat(), randomSpeed); moteThrown.airTimeLeft = Mathf.RoundToInt((moteThrown.exactPosition - destinationCell).MagnitudeHorizontal() / randomSpeed); return(GenSpawn.Spawn(moteThrown, thrower.Position, thrower.Map)); }
public static Thing MoteSpawner_ThrowObjectAt(this JobDriver_PlayGenericTargetingGame PGTG) { IntVec3 targetCell = PGTG.PetanqueSpotCell; Pawn thrower = PGTG.pawn; ThingDef moteDef = PGTG.MoteDef; SkillDef skillDef = PGTG.SkillDefScaling; if (thrower.Position.ShouldSpawnMotesAt(thrower.Map) && !thrower.Map.moteCounter.Saturated) { float randomSpeed = PGTG.Speed.RandomInRange; Vector3 destinationCell = targetCell.ToVector3Shifted() + Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(skillDef).Level / 20f) * 1.8f); destinationCell.y = thrower.DrawPos.y; MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(moteDef); moteThrown.Scale = 1f; moteThrown.rotationRate = PGTG.Rotation.RandomInRange; moteThrown.exactPosition = thrower.DrawPos; moteThrown.SetVelocity((destinationCell - moteThrown.exactPosition).AngleFlat(), randomSpeed); moteThrown.airTimeLeft = Mathf.RoundToInt((moteThrown.exactPosition - destinationCell).MagnitudeHorizontal() / randomSpeed); return(GenSpawn.Spawn(moteThrown, thrower.Position, thrower.Map)); } return(null); }
public static void Initialization(this ShadowMote SM, JobDriver_PlayGenericTargetingGame TG, Vector3 DestinationCell) { SM.TG_parent = TG; SM.InitCoordinates(DestinationCell); SM.InitGroundShadowGraphic(); }
public static bool RetrieveProjectileParam(this JobDriver_PlayGenericTargetingGame PGTG) { bool myDebug = PGTG.gameSettings.debug; string DebugStr = PGTG.pawn.LabelShort + " - RetrieveProjectileParam"; Tools.Warn(DebugStr + " - Entering", myDebug); int randomIndex = PGTG.gameSettings.GetWeightedRandomIndex(); PGTG.projectileOption = PGTG.gameSettings.projectileOptionList[randomIndex]; if (PGTG.projectileOption.IsMoteType) { PGTG.PickedMoteParam = PGTG.projectileOption.mote; Tools.Warn(DebugStr + " - Found mote => " + PGTG.MoteDef.defName, myDebug); } else if (PGTG.projectileOption.IsShadowMoteType) { PGTG.PickedMoteParam = PGTG.projectileOption.shadowMote; Tools.Warn(DebugStr + " - Found shadow mote", myDebug); } else { Tools.Warn(DebugStr + " - Found nothing", myDebug); } return(PGTG.HasProjectileOption); }
public static void ComputeThrowQuality(this JobDriver_PlayGenericTargetingGame TG, float throwDistance, bool myDebug = false) { string myDebugStr = TG.PawnLabel + " - ComputeThrowQuality - "; if (!TG.HasGameSettings) { return; } foreach (ThoughtParameter TP in TG.gameSettings.thoughtList.thoughtOptionPerShot) { ThoughtDef TD = TP.thoughtPool.RandomElement(); Tools.Warn(myDebugStr + " browsing >" + TD.defName + " - " + TP.distanceThreshold, myDebug); if (TP.distanceThreshold.Includes(throwDistance)) { Tools.Warn(myDebugStr + ">Throw is in range : " + TP.distanceThreshold, myDebug); float TriggerChange = TP.triggerChance + TG.OtherPlayersNum * TP.rivalryChancePerOpponent; if (!Rand.Chance(TriggerChange)) { Tools.Warn(myDebugStr + "> RNG gods do no want: " + TP.triggerChance, myDebug); return; } Tools.Warn(myDebugStr + "> Trying to apply thought: ", myDebug); TryApplySoloThought( TG.pawn, TP.thoughtPool.RandomElement(), ContentFinder <Texture2D> .Get(TP.iconPool.RandomElement()), TP.bubblePool.RandomElement(), TG.DestroyingMotes, TG.ResistantMotes ); return; } } }
public static void ResetPickedOption(this JobDriver_PlayGenericTargetingGame PGTG) { PGTG.projectileOption = null; PGTG.PickedMoteParam = null; PGTG.RetrieveProjectileParam(); }
public static bool IsSomeonePlayingWithMe(this JobDriver_PlayGenericTargetingGame TG, out int playerNum, bool debug = false) { string myDebugStr = debug? TG.PawnLabel + " - IsSomeonePlayingWithMe - " : ""; playerNum = 0; Tools.Warn(myDebugStr + " - Entering", debug); if (!TG.HasPlayingTogetherThoughts || !TG.HasWatchCells) { Tools.Warn(myDebugStr + " - Found no together thought, or no watch cells", debug); return(false); } IEnumerable <Pawn> foundPawns = TG.pawn.Map.reservationManager.ReservationsReadOnly.Where( r => r.Claimant != TG.pawn && r.Job.def == TG.pawn.CurJobDef && TG.WatchCells.Contains(r.Claimant.Position) && r.Claimant.CurJob != null && r.Claimant.CurJob.targetA == TG.JoyBuilding ).Select(r => r.Claimant).Distinct(); if (foundPawns.EnumerableNullOrEmpty()) { return(false); } playerNum = foundPawns.Count(); Tools.Warn(myDebugStr + " - found " + playerNum + " other players", debug); if (debug) { for (int i = 0; i < foundPawns.Count(); i++) { Tools.Warn(myDebugStr + i + " - " + foundPawns.ElementAt(i).LabelShort, debug); } } if (!TG.SingleTogetherThought.IsUnlimitedThought && TG.TogetherThoughtsNum >= TG.SingleTogetherThought.numberOfThoughtsPerJob) { return(false); } if (!TG.pawn.PlayedLongEnough(TG.PlayedTogetherThreshold)) { Tools.Warn(myDebugStr + " - did not play long enough : " + TG.PlayedTogetherThreshold, debug); return(false); } foreach (Pawn player in foundPawns.InRandomOrder()) { Tools.Warn(myDebugStr + " - browsing : " + player.LabelShort, debug); if (player.PlayedLongEnough(TG.PlayedTogetherThreshold)) { float baseChance = TG.TogetherThoughtChance; float finalChance = Math.Max(TG.MinThoughtChance, AgregatedOpinion(TG.pawn, player) * baseChance); if (Rand.Chance(finalChance)) { Tools.Warn(myDebugStr + " - RNG agreed(" + TG.TogetherThoughtChance + "), trying to apply " + TG.PlayedTogetherThought.defName, debug); TryApplyTogetherThought(TG.pawn, player, TG.PlayedTogetherThought, TG.PlayedTogetherIcon, TG.PlayedTogetherBubble, TG.DestroyingMotes, TG.ResistantMotes, debug); TG.TogetherThoughtsNum++; JobDriver_PlayGenericTargetingGame OtherPlayerTG = (JobDriver_PlayGenericTargetingGame)(player.jobs.curDriver); if (OtherPlayerTG != null) { OtherPlayerTG.TogetherThoughtsNum++; } return(true); } else { Tools.Warn(myDebugStr + " - RNG did not agree " + TG.TogetherThoughtChance, debug); } } else { Tools.Warn(myDebugStr + " - opponent did not play long enough : " + TG.PlayedTogetherThreshold, debug); } } Tools.Warn(myDebugStr + " - found nothing to do", debug); return(false); }