protected override Toil GetPlayToil(Pawn musician, Thing instrument, Thing venue)
        {
            // custom toil.
            Toil play = new Toil();

            CompProperties_MusicalInstrument props = instrument.TryGetComp <CompMusicalInstrument>().Props;

            play.initAction = delegate
            {
                pawn.Map.GetComponent <PerformanceManager>().StartPlaying(musician, instrument, venue, false);
            };



            play.tickAction = delegate
            {
                if (props.isBuilding)
                {
                    pawn.rotationTracker.FaceTarget(TargetC);
                    pawn.GainComfortFromCellIfPossible();
                }
                else
                {
                    pawn.rotationTracker.FaceCell(ClosestMusicSpotParentCell);
                }

                if (ticksLeftThisToil % 100 == 99)
                {
                    ThrowMusicNotes(musician.DrawPos, this.Map);
                }

                JoyUtility.JoyTickCheckEnd(musician, JoyTickFullJoyAction.GoToNextToil, 1f, null);
            };

            play.handlingFacing      = true;
            play.defaultCompleteMode = ToilCompleteMode.Delay;
            play.defaultDuration     = this.job.def.joyDuration;

            play.AddFinishAction(delegate
            {
                pawn.Map.GetComponent <PerformanceManager>().StopPlaying(musician, venue);

                if (pawn.carryTracker.CarriedThing != null)
                {
                    if (!pawn.carryTracker.innerContainer.TryTransferToContainer(pawn.carryTracker.CarriedThing, pawn.inventory.innerContainer, true))
                    {
                        Thing thing;
                        pawn.carryTracker.TryDropCarriedThing(pawn.Position, pawn.carryTracker.CarriedThing.stackCount, ThingPlaceMode.Near, out thing, null);
                    }
                }
            });

            play.socialMode = RandomSocialMode.Quiet;

            return(play);
        }
Exemple #2
0
        public override bool ModifyCarriedThingDrawPos(ref Vector3 drawPos, ref bool behind, ref bool flip)
        {
            Thing instrument = this.TargetC.Thing;
            CompProperties_MusicalInstrument props = (CompProperties_MusicalInstrument)(instrument.TryGetComp <CompMusicalInstrument>().props);

            Rot4 rotation = pawn.Rotation;

            if (rotation == Rot4.North)
            {
                behind = true;

                if (!pawn.pather.Moving)
                {
                    drawPos += new Vector3(0f - props.xOffsetFacing, 0f, props.zOffset);
                }
                return(true);
            }
            else if (rotation == Rot4.East)
            {
                if (!pawn.pather.Moving)
                {
                    flip     = true;
                    drawPos += new Vector3(props.xOffset, 0f, props.zOffset);
                }
                return(true);
            }
            else if (rotation == Rot4.South)
            {
                if (!pawn.pather.Moving)
                {
                    flip     = true;
                    drawPos += new Vector3(props.xOffsetFacing, 0f, props.zOffset);
                }
                return(true);
            }
            else if (rotation == Rot4.West)
            {
                if (!pawn.pather.Moving)
                {
                    drawPos += new Vector3(0f - props.xOffset, 0f, props.zOffset);
                }
                return(true);
            }

            return(false);
        }
Exemple #3
0
        protected bool PowerMissing(Thing instrument)
        {
            CompProperties_MusicalInstrument propsinstrument = instrument.TryGetComp <CompMusicalInstrument>().Props;

            if (!propsinstrument.isBuilding)
            {
                return(false);
            }

            CompPowerTrader compPower = instrument.TryGetComp <CompPowerTrader>();

            if (compPower == null)
            {
                return(false);
            }

            return(!compPower.PowerOn);
        }
Exemple #4
0
        // this function does three things:
        // it adds generic delegate functions to globalFailConditions (inherited from IJobEndable) via `This.EndOn...` extensions
        // it also yield returns a collection of toils: some generic, some custom
        // it also interacts with the JoyUtility static class so the pawns get joy

        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(MusicSpotParentInd, JobCondition.Incompletable);

            //Verse.Log.Message(String.Format("Gather Spot ID = {0}", TargetA.Thing.GetHashCode()));

            Pawn musician = this.pawn;

            this.FailOnDestroyedNullOrForbidden(InstrumentInd);

            Thing instrument = this.TargetC.Thing;

            Thing venue = this.TargetA.Thing;

            CompProperties_MusicalInstrument props = instrument.TryGetComp <CompMusicalInstrument>().Props;

            if (props.isBuilding)
            {
                this.FailOn(() => PowerMissing(instrument));

                // go to where instrument is
                yield return(Toils_Goto.GotoThing(InstrumentInd, PathEndMode.InteractionCell)
                             .FailOnSomeonePhysicallyInteracting(InstrumentInd));

                yield return(GetPlayToil(musician, instrument, venue));
            }
            else
            {
                if (instrument.ParentHolder != musician.inventory)
                {
                    // go to where instrument is
                    yield return(Toils_Goto.GotoThing(InstrumentInd, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(InstrumentInd));

                    //drop other instruments if any
                    List <Thing> heldInstruments = pawn.inventory.innerContainer.Where(x => PerformanceManager.IsInstrument(x)).ToList();

                    if (heldInstruments.Any())
                    {
                        Toil dropInstruments = new Toil();
                        dropInstruments.initAction = delegate
                        {
                            Thing result;

                            foreach (Thing heldInstrument in heldInstruments)
                            {
                                pawn.inventory.innerContainer.TryDrop(heldInstrument, pawn.Position, pawn.Map, ThingPlaceMode.Near, out result);
                            }
                        };

                        yield return(dropInstruments);
                    }

                    // pick up instrument
                    yield return(Toils_Haul.StartCarryThing(InstrumentInd));
                }
                else
                {
                    //get instrument out ready to play
                    yield return(Toils_Misc.TakeItemFromInventoryToCarrier(musician, InstrumentInd));
                }

                // go to the sitting / standing spot
                yield return(Toils_Goto.GotoCell(StandingSpotOrChairInd, PathEndMode.OnCell));

                yield return(GetPlayToil(musician, instrument, venue));

                //yield return Toils_General.PutCarriedThingInInventory();
            }
        }