private void SavePlayer() { Monitor.Log("Save player data."); this.restoreData = true; this.map = Game1.player.currentLocation.NameOrUniqueName; this.pos = Game1.player.Position; this.facing = Game1.player.facingDirection; this.sitted = Game1.player.sittingFurniture; this.stamina = Game1.player.stamina; this.health = Game1.player.health; this.horse = Game1.getCharacterFromName <Horse>(Game1.player.horseName, false); if (this.horse != null) { Monitor.Log("Save horse data."); this.horseMap = this.horse.currentLocation.NameOrUniqueName; this.horsePos = this.horse.Position; this.horseFacing = this.horse.FacingDirection; } }
static void Main(string[] args) { //Polymorphism Example: // f1 and f2 are both Furniture type references, but because // they are instantiated differently, they can have different behavior (f1 points to a Sofa object in memory and f2 points to a Chair object in memory) // Furniture f1 = new Sofa(0, 3); Furniture f2 = new Chair(0, 4); // Instantiation of an array of Furniture references Furniture[] fArray = new Furniture[] { f1, f2 }; foreach (Furniture f in fArray) { // The Furniture references will have different behavior/outputs based on the object type they refer to // This proves that C# supports Polymorphism Console.WriteLine(f.Identify()); } //Interface practical Example // Lets say I want to put my Furniture objects (that i know implements ISittable) // in an array to call Sit method on them // and thats the only functionality i need, then we can make an array of ISittable references. // and iterate over them with foreach and call Sit() on each of them Sofa s1 = new Sofa(); Chair c1 = new Chair(); ISittable[] sittableFArray = new ISittable[] { s1, c1 }; foreach (ISittable sittableF in sittableFArray) { sittableF.Sit(); Console.WriteLine(sittableF.SitCounter); } }
public override bool Run() { try { SitData data2; Slot slot2; object obj2; SittingPosture posture2; ISittable sittable = SittingHelpers.CastToSittable(Target); if (sittable == null) { Actor.AddExitReason(ExitReason.FailedToStart); return(false); } Slot containmentSlotClosestToHit = GetContainmentSlotClosestToHit(); if (Actor.Posture.Container == Target) { SittingPosture posture = Actor.Posture as SittingPosture; if (posture != null) { SitData target = posture.Part.Target; if (containmentSlotClosestToHit == target.ContainmentSlot) { return(true); } if (!Stand.Singleton.CreateInstance(Target, Actor, GetPriority(), Autonomous, CancellableByPlayer).RunInteraction()) { return(false); } } } SimQueue simLine = Target.SimLine; if ((simLine != null) && !simLine.WaitForTurn(this, SimQueue.WaitBehavior.DontPlayRouteFail | SimQueue.WaitBehavior.NeverWait, ~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), 0f)) { Sim firstSim = simLine.FirstSim; if ((firstSim != null) && (firstSim.InteractionQueue.TransitionInteraction is Stand)) { Actor.RemoveExitReason(ExitReason.ObjectInUse); simLine.WaitForTurn(this, SimQueue.WaitBehavior.DontPlayRouteFail | SimQueue.WaitBehavior.OnlyWaitAtHeadOfLine, ~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), kTimeToWait); } } if (!sittable.RouteToForSitting(Actor, containmentSlotClosestToHit, true, out data2, out slot2, out obj2)) { return(false); } sittable = SittingHelpers.CastToSittable(data2.Container); if (!SittingHelpers.ReserveSittable(this, Actor, sittable, data2)) { return(false); } StateMachineClient smc = sittable.StateMachineAcquireAndInit(Actor); if (smc == null) { Actor.AddExitReason(ExitReason.NullValueFound); SittingHelpers.UnreserveSittable(this, sittable, data2); return(false); } ISittingPostureCreator parent = data2.Container.Parent as ISittingPostureCreator; if (parent != null) { posture2 = parent.CreatePosture(data2.Container, Actor, smc, data2); } else { posture2 = new SittingPosture(data2.Container, Actor, smc, data2); } if (smc.HasActorDefinition("surface")) { smc.SetActor("surface", data2.Container); } BeginCommodityUpdates(); Actor.LookAtManager.DisableLookAts(); bool flag = (Actor.CarryStateMachine != null) && (Actor.GetObjectInRightHand() is IUseCarrySitTransitions); if (flag) { Actor.CarryStateMachine.RequestState(false, "x", "CarrySitting"); } Definition definition = InteractionDefinition as Definition; if (!SaunaClassicEx.StateMachineEnterAndSit(sittable as SaunaClassic, definition.mForWoohoo, smc, posture2, slot2, obj2)) { if (flag) { Actor.CarryStateMachine.RequestState(false, "x", "Carry"); } Actor.LookAtManager.EnableLookAts(); Actor.AddExitReason(ExitReason.NullValueFound); SittingHelpers.UnreserveSittable(this, sittable, data2); EndCommodityUpdates(false); return(false); } Actor.LookAtManager.EnableLookAts(); Actor.Posture = posture2; if (sittable.ComfyScore > 0x0) { Actor.BuffManager.AddElement(BuffNames.Comfy, sittable.ComfyScore, Origin.FromComfyObject); } EndCommodityUpdates(true); StandardExit(false, false); if (Actor.HasExitReason(ExitReason.UserCanceled)) { Actor.AddExitReason(ExitReason.CancelledByPosture); } if (mIsMaster) { SaunaSit linked = LinkedInteractionInstance as SaunaSit; if (linked != null) { Sim linkedActor = linked.Actor; while (!Cancelled) { if (!linkedActor.InteractionQueue.HasInteraction(linked)) { break; } if (linked.mCompleted) { break; } SpeedTrap.Sleep(10); } } } return(!Actor.HasExitReason()); } catch (ResetException) { throw; } catch (Exception e) { Common.Exception(Actor, Target, e); return(false); } }
public static EatingPosture GetPostureParam(Sim sim) { IEdible target = (IEdible)RandomUtil.GetRandomObjectFromList(Recipe.Recipes); if (sim.Posture.Satisfies(CommodityKind.Standing, target)) { return(EatingPosture.standing); } if (sim.Posture.Satisfies(CommodityKind.Sitting, target)) { SitData sitData = null; SittingPosture sittingPosture = sim.Posture as SittingPosture; if (sittingPosture != null) { sitData = sittingPosture.Part.Target; } else { ISittable sittable = SittingHelpers.CastToSittable(sim.Posture.Container as GameObject); if (sittable != null) { PartData partSimIsIn = sittable.PartComponent.GetPartSimIsIn(sim); sitData = (partSimIsIn as SitData); } } if (sitData != null) { switch (sitData.SitStyle) { case SitStyle.Dining: { if (target.Parent != sim) { return(EatingPosture.diningIn); } return(EatingPosture.diningOut); } case SitStyle.Living: { if (target is HotBeverageMachine.Cup) { return(EatingPosture.living); } if (target.Parent != sim) { return(EatingPosture.diningIn); } return(EatingPosture.diningOut); } case SitStyle.Stool: { if (target.Parent != sim) { return(EatingPosture.barstoolIn); } return(EatingPosture.barstoolOut); } } } return(EatingPosture.diningOut); } return(EatingPosture.standing); }