[Resolved] [C#] Hidden Incident Messages?

Started by jecrell, September 24, 2016, 09:46:05 AM

Previous topic - Next topic

jecrell

I'd like to have a hidden raid that will surprise the player. How can I go about having a raid occur without an incident message?
...Psst. Still there? If you'd like to support
me and my works, do check out my Patreon.
Someday, I could work for RimWorld full time!

https://www.patreon.com/jecrell

skullywag

Just fire the incident worker but dont call the method that sends the letter.

See here for an older example but it should be somewhat valid:

https://github.com/Skullywag/RazorRain/blob/master/Source/RazorRainEvent/IncidentWorker_RazorRain.cs
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

jecrell

You're right. However, I want to do it with a raid. So, I inherited the IncidentWorker_Raid for my class. That one doesn't seem to be possible to clear the letter being sent to players.

What should I do?

...Psst. Still there? If you'd like to support
me and my works, do check out my Patreon.
Someday, I could work for RimWorld full time!

https://www.patreon.com/jecrell

skullywag

well my first thought is copy the base class into another custom class, remove the letter line, set your incident to use it as its base and done. Dont know if theres any other dependencies in there, this is usually where the rabbit holes start lol.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

theubie

TryExecute can be overridden. 

I would override it by copying its code from ILSpy then remove the ReceiveLetter command or alter it to your liking.

jecrell

Thanks guys. As skullywag suggested, I copied a lot of the base class over and made a lot of fine tuning. Here's the solution I arrived at.

I can't tell you guys how happy I am that this worked out. I'll have to show you in the update.


///Always required
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
///Possible libraries
using RimWorld;
using Verse;
using Verse.Sound;
//using RimWorld.Planet;
//using Verse.AI;
//using Verse.AI.Group;


namespace CosmicHorror
{
    public class IncidentWorker_StarVampireAttack : IncidentWorker
    {
        private CosmicHorrorPawn iwVampire;   //The Star Vampire Pawn
        private PawnKindDef iwKind;           //For the PawnType
        private Pawn iwPawn;                  //For the PawnGenerator
        private Faction iwFac;                //The Star Vampire Faction
        private IntVec3 iwLoc;                //The Star Vampire location
        private SoundDef iwWarn;              //The Star Vampire Warning Noise
       
        public override bool TryExecute(IncidentParms parms)
        {

            //Resolve parameters.
            ResolveSpawnCenter(parms);
           
            //Initialize variables.
            iwKind      = PawnKindDef.Named("CosmicHorror_StarVampire");
            iwFac       = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("StarVampire"));
            iwWarn      = SoundDef.Named("Pawn_CosmicHorror_StarVampire_Warning");
            iwPawn      = PawnGenerator.GeneratePawn(iwKind, iwFac);
            iwVampire   = iwPawn as CosmicHorrorPawn;
            iwLoc       = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, 8);

            //In-case there's something silly happening...
            if (iwFac == null)
            {
                iwFac = Find.FactionManager.FirstFactionOfDef(FactionDefOf.SpacerHostile);
            }

            //Play a sound.
            iwWarn.PlayOneShotOnCamera();
            //Spawn the Star Vampire.
            SpawnStarVampires(parms);
            return true;
        }

        /// <summary>
        /// Where to, Cthulhu?
        /// </summary>
        /// <param name="parms"></param>
        protected void ResolveSpawnCenter(IncidentParms parms)
        {
            if (parms.spawnCenter.IsValid)
            {
                return;
            }
            if (Rand.Value < 0.4f && Find.ListerBuildings.ColonistsHaveBuildingWithPowerOn(ThingDefOf.OrbitalTradeBeacon))
            {
                parms.spawnCenter = DropCellFinder.TradeDropSpot();
            }
            else
            {
                RCellFinder.TryFindRandomPawnEntryCell(out parms.spawnCenter);
            }
        }

        /// <summary>
        /// Finds the best number of Star Vampires
        /// to spawn. Then spawns them according
        /// to a previously resolved location.
        /// </summary>
        /// <param name="parms"></param>
        protected void SpawnStarVampires(IncidentParms parms)
        {
            int iwCount = 1;

            if (parms.points <= 700f)
            {
                iwCount = 1;
            }
            else if (parms.points <= 1400f)
            {
                iwCount = 2;
            }
            else if (parms.points <= 2500f)
            {
                iwCount = 3;
            }

            for (int i = 0; i < iwCount; i++)
            {
                GenSpawn.Spawn(iwVampire, iwLoc);
            }
        }
    }
}
...Psst. Still there? If you'd like to support
me and my works, do check out my Patreon.
Someday, I could work for RimWorld full time!

https://www.patreon.com/jecrell