Exemplo n.º 1
0
        //What should we do?
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Check it out. Can we go there?
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);

            if (this.job.targetA.Thing is Building_Radio)
            {
                report = "Turning off radio.";
            }

            // Toil 1:
            // Reserve Target (TargetPack A is selected (It has the info where the target cell is))
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

            // Toil 2:
            // Go to the thing.
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            // Toil 3:
            // Turn off music.

            Toil toilStopMusic = new Toil();

            toilStopMusic.defaultCompleteMode = ToilCompleteMode.Instant;
            toilStopMusic.initAction          = delegate
            {
                Building_Gramophone gramophone = this.job.targetA.Thing as Building_Gramophone;
                gramophone.StopMusic();
            };
            yield return(toilStopMusic);

            yield break;
        }
        public static bool TryFindBestListenCell(Thing toListen, Pawn pawn, bool desireSit, out IntVec3 result, out Building chair)
        {
            IntVec3               intVec        = IntVec3.Invalid;
            Building_Gramophone   musicBuilding = toListen as Building_Gramophone;
            IEnumerable <IntVec3> cells         = musicBuilding.ListenableCells;
            var random = new Random();
            IEnumerable <IntVec3> cellsRandom = cells.OrderBy(order => random.Next()).ToList();

            foreach (IntVec3 current in cellsRandom)
            {
                bool     flag     = false;
                Building building = null;
                if (desireSit)
                {
                    building = current.GetEdifice(pawn.Map);
                    if (building != null && building.def.building.isSittable && pawn.CanReserve(building, 1))
                    {
                        flag = true;
                    }
                }
                else if (!current.IsForbidden(pawn) && pawn.CanReserve(current, 1))
                {
                    flag = true;
                }
                if (flag)
                {
                    result = current;
                    chair  = building;
                    return(true);
                }
            }
            result = IntVec3.Invalid;
            chair  = null;
            return(false);
        }
        //What should we do?
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Check it out. Can we go there?
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);

            if (this.job.targetA.Thing is Building_Radio)
            {
                report = "Playing the radio.";
            }

            // Toil 1:
            // Reserve Target (TargetPack A is selected (It has the info where the target cell is))
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

            // Toil 2:
            // Go to the thing.
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            // Toil 3:
            // Wind up the gramophone
            Toil toil = new Toil();

            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = this.Duration;
            toil.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
            if (this.job.targetA.Thing is Building_Radio)
            {
                toil.PlaySustainerOrSound(DefDatabase <SoundDef> .GetNamed("Estate_RadioSeeking"));
            }
            else
            {
                toil.PlaySustainerOrSound(DefDatabase <SoundDef> .GetNamed("Estate_GramophoneWindup"));
            }
            toil.initAction = delegate
            {
                Building_Gramophone gramophone = this.job.targetA.Thing as Building_Gramophone;
                gramophone.StopMusic();
            };
            yield return(toil);

            // Toil 4:
            // Play music.

            Toil toilPlayMusic = new Toil();

            toilPlayMusic.defaultCompleteMode = ToilCompleteMode.Instant;
            toilPlayMusic.initAction          = delegate
            {
                Building_Gramophone gramophone = this.job.targetA.Thing as Building_Gramophone;
                gramophone.PlayMusic(this.pawn);
            };
            yield return(toilPlayMusic);

            yield break;
        }
        protected virtual void ListenTickAction()
        {
            Building_Gramophone gramo = base.TargetA.Thing as Building_Gramophone;

            if (!gramo.IsOn())
            {
                base.EndJobWith(JobCondition.Incompletable);
                return;
            }
            this.pawn.rotationTracker.FaceCell(base.TargetA.Cell);
            this.pawn.GainComfortFromCellIfPossible();
            float statValue          = base.TargetThingA.GetStatValue(StatDefOf.JoyGainFactor, true);
            float extraJoyGainFactor = statValue;

            JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.EndJob, extraJoyGainFactor);
        }
        // RimWorld.WatchBuildingUtility
        public static bool CanListenFromBed(Pawn pawn, Building_Bed bed, Thing toListen)
        {
            if (!pawn.Position.Standable(pawn.Map) || (pawn.Position.GetEdifice(pawn.Map) is Building_Bed))
            {
                return(false);
            }
            Building_Gramophone   musicBuilding = toListen as Building_Gramophone;
            IEnumerable <IntVec3> cells         = musicBuilding.ListenableCells;

            foreach (IntVec3 current in cells)
            {
                if (current == pawn.Position)
                {
                    return(true);
                }
            }
            return(false);
        }
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol, Thing thing = null)
        {
            var visibleMap = Find.CurrentMap;

            GenDraw.DrawFieldEdges(Building_Gramophone.ListenableCellsAround(center, visibleMap));
        }