protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; var affectedPawns = new List <Pawn>(map.mapPawns.PrisonersOfColony); foreach (var pawn in map.mapPawns.PrisonersOfColony) { if (pawn.IsColonist) { continue; } var need = pawn.needs.TryGetNeed <Need_Treatment>(); if (need == null) { continue; } if (need.CurCategory <= TreatmentCategory.Bad) { // If treatment is only bad reduce chance by 50% if (need.CurCategory == TreatmentCategory.Bad && !parms.forced) { if (UnityEngine.Random.value < 0.5f) { continue; } } SendStandardLetter(new TargetInfo(pawn.Position, pawn.Map), null, new string[] { pawn.Name.ToStringShort }); parms.faction = pawn.Faction; DamageInfo dinfo = new DamageInfo(DamageDefOf.Cut, 29, 0, 0, pawn, pawn.RaceProps.body.AllParts.Find(p => p.def == BodyPartDefOf.Neck)); while (!pawn.Dead) { pawn.TakeDamage(dinfo); } Tutorials.Treatment(); return(true); } } return(false); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; Pawn prisoner = null; var affectedPawns = new List <Pawn>(map.mapPawns.PrisonersOfColony); foreach (var pawn in map.mapPawns.PrisonersOfColony) { if (pawn.IsColonist || !pawn.Spawned) { continue; } var treatment = pawn.needs.TryGetNeed <Need_Treatment>(); if (treatment == null) { continue; } if (treatment.CurLevel >= BGP.ResocializationLevel) { treatment.ResocializationReady = true; parms.faction = pawn.Faction; prisoner = pawn; break; } } if (prisoner == null) { return(false); } Tutorials.Treatment(); if (prisoner.Faction == null) { SendStandardLetter(parms, prisoner, prisoner.Name.ToStringShort); } else { SendStandardLetter(parms, prisoner, prisoner.Name.ToStringShort, prisoner.Faction.Name); } return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { try { Map map = (Map)parms.target; Pawn t = null; var affectedPawns = new List <Pawn>(map.mapPawns.PrisonersOfColony); // Calculate chance for blocking incident if prisoners are treated good float treatment = 0f; float chance = 0f; foreach (Pawn pawn in affectedPawns) { if (pawn.needs.TryGetNeed <Need_Treatment>() != null) { treatment += (float)pawn.needs.TryGetNeed <Need_Treatment>().CurCategory; } } treatment = treatment / affectedPawns.Count; if (treatment < 0.5) { chance = 1f; } else if (treatment < 1.5) { chance = 0.95f; } else if (treatment < 2.5) { chance = 0.5f; } else if (treatment < 3.5) { chance = 0.1f; } // When incident is forced, log instead of blocking if (!parms.forced) { if (Prefs.DevMode) { string msg = $"Prison Labor: Revolt blocking chance is currently equal to {chance * 100}% (overall treatment = {treatment}). Rolling ..."; Log.Message(msg); } if (Verse.Rand.Value > chance) { return(false); } } foreach (Pawn pawn in affectedPawns) { if (pawn.Faction.HostileTo(Faction.OfPlayer)) { parms.faction = pawn.Faction; t = pawn; break; } } float points = parms.points; int prisonersLeft = affectedPawns.Count; foreach (Pawn pawn in affectedPawns) { pawn.ClearMind(); pawn.guest.SetGuestStatus(null, GuestStatus.Guest); pawn.SetFaction(parms.faction); ThingWithComps weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("MeleeWeapon_Knife"), ThingDefOf.WoodLog) as ThingWithComps; ThingWithComps ammo = null; int pointsToRemove = 0; if (parms.points >= 1000) { weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("MeleeWeapon_Knife"), ThingDefOf.Steel) as ThingWithComps; } if (points >= 1000) { // If combat extended is enabled if (DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeStickBomb", false) != null) { if (Verse.Rand.Value > 0.5f) { weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeStickBomb")) as ThingWithComps; ammo = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeStickBomb")) as ThingWithComps; ammo.stackCount = 6; } else { weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeMolotov")) as ThingWithComps; ammo = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeMolotov")) as ThingWithComps; ammo.stackCount = 6; } } else { weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeMolotov")) as ThingWithComps; } pointsToRemove = 500; } else if (points >= 500) { weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Bow_Short")) as ThingWithComps; if (DefDatabase <ThingDef> .GetNamed("Ammo_Arrow_Stone", false) != null) { ammo = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Ammo_Arrow_Stone")) as ThingWithComps; ammo.stackCount = 30; } pointsToRemove = 100; } else if (points >= 300) { weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("MeleeWeapon_Club"), ThingDefOf.Granite) as ThingWithComps; pointsToRemove = 100; } if (pawn.equipment.Primary == null) { pawn.equipment.AddEquipment(weapon); if (ammo != null) { pawn.inventory.innerContainer.TryAdd(ammo); } points -= pointsToRemove; } } var lordJob = new LordJob_AssaultColony(parms.faction, true, true, false, true, true); //TODO old code: LordMaker.MakeNewLord(parms.faction, lordJob /*(new RaidStrategyWorker_ImmediateAttackSmart()).MakeLordJob(parms, map)*/, map, affectedPawns); SendStandardLetter(parms, t, t.Name.ToStringShort, t.Faction.Name); Find.TickManager.slower.SignalForceNormalSpeedShort(); Tutorials.Treatment(); return(true); } catch (Exception e) { Log.Error($"PrisonLabor: Erron on executing Revolt Incident: {e.ToString()}"); return(false); } }