Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
So, anyways, I'm still working on my mod to make canes usable for young adults or higher. Still, I'm trying to get the cane posture to actually appear, but VS keeps giving me errors when I try to create a replacement for the a method that I think is responsible for populating the cane postures. Here's the code for the original method:
Code:
public static void PopCanePostureIfNecessary()
{
if (Simulator.CheckYieldingContext(shouldThrowException: false))
{
Cane.HoldingCanePosture holdingCanePosture = Posture as Cane.HoldingCanePosture;
if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
{
PopPosture();
}
}
}
And here's my edited method:
Code:
public static void PopCanePostureIfNecessary()
{
if (Simulator.CheckYieldingContext(shouldThrowException: false))
{
CyrusCane.NewHoldingCanePosture holdingCanePosture = Posture as CyrusCane.NewHoldingCanePosture;
if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
{
PopPosture();
}
}
}
When trying to write both, I get the same errors:
CS0119 C# "Posture" is a type, which is not valid in the given context
CS0103 C# The name "PopPosture" does not exist in the current context
What could I do to fix these errors?
Here's the complete code, for reference:
Code:
using Sims3.Gameplay.Abstracts;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.ActorSystems;
using Sims3.Gameplay.Autonomy;
using Sims3.Gameplay.CAS;
using Sims3.Gameplay.Core;
using Sims3.Gameplay.EventSystem;
using Sims3.Gameplay.Interactions;
using Sims3.Gameplay.Interfaces;
using Sims3.Gameplay.ObjectComponents;
using Sims3.Gameplay.Pools;
using Sims3.Gameplay.Skills;
using Sims3.Gameplay.Socializing;
using Sims3.Gameplay.ThoughtBalloons;
using Sims3.Gameplay.Utilities;
using Sims3.SimIFace;
using Sims3.SimIFace.CustomContent;
using Sims3.SimIFace.Enums;
using Sims3.UI.Hud;
using System;
using System.Collections.Generic;
using Sims3.Gameplay.Objects;
using Cyrus;
namespace Sims3.Gameplay.Objects.Cyrus
{
public class CyrusCane : Sims3.Gameplay.Objects.Cane
{
new public static bool IsAllowedToUseCane(Sim sim)
{
return sim.SimDescription.YoungAdultOrAbove;
}
public override string PropCaneName
{
get
{
return "accessoryCaneLlama";
}
}
public class CyrusSim
{
public static CyrusCane NewGetActiveCane(Sim sim)
{
if (sim.Inventory != null)
{
foreach (CyrusCane cane in sim.Inventory.FindAll<CyrusCane>(false))
{
if (cane.NewUsingCane)
return cane;
}
}
return null;
}
public static void PopCanePostureIfNecessary()
{
if (Simulator.CheckYieldingContext(shouldThrowException: false))
{
CyrusCane.NewHoldingCanePosture holdingCanePosture = Posture as CyrusCane.NewHoldingCanePosture;
if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
{
PopPosture();
}
}
}
}
public override void OnStartup()
{
Sims3.UI.StyledNotification.Show(new Sims3.UI.StyledNotification.Format(Initiator.test.ToString()
, Sims3.UI.StyledNotification.NotificationStyle.kGameMessagePositive));
AddInteraction(NewUseCane.Singleton);
AddInteraction(NewHarassEveryone.Singleton);
AddInteraction(NewSetWalkStyle.Singleton);
AddInteraction(NewStartUsingCane.Singleton);
AddInteraction(NewStopUsingCane.Singleton);
base.OnStartup();
/*AddInteraction(UseCane.Singleton);
AddInteraction(HarassEveryone.Singleton);
AddInteraction(SetWalkStyle.Singleton);
AddInteraction(StartUsingCane.Singleton);
AddInteraction(StopUsingCane.Singleton);
Sims3.UI.AcceptCancelDialog.Show("Im a cane");*/
}
public bool NewUsingCane
{
get
{
return this.mUseCane;
}
set
{
if (this.mUseCane == value)
return;
if (this.ItemComp.InventoryParent != null && this.ItemComp.InventoryParent.Owner is Sim owner && owner.SimRoutingComponent != null)
{
owner.SimRoutingComponent.OnCarSequenceFinished -= new SimRoutingComponent.CarSequenceEvent(CyrusCane.CarSequenceFinishedCallback);
if (value)
owner.SimRoutingComponent.OnCarSequenceFinished += new SimRoutingComponent.CarSequenceEvent(CyrusCane.CarSequenceFinishedCallback);
}
this.mUseCane = value;
}
}
new public static CyrusCane GetActiveCaneForActor(Sim sim)
{
if (sim != null && sim.Inventory != null)
{
List<CyrusCane> list = sim.Inventory.FindAll<CyrusCane>(checkInUse: false);
foreach (CyrusCane item in list)
{
if (item.NewUsingCane)
{
return item;
}
}
}
return null;
}
new public void OnAddToInventoryEvent(IGameObject objAdded, Inventory inventory)
{
Sim sim = inventory.Owner as Sim;
if (sim != null)
{
NewUsingCane = false;
}
}
new public static void StopUsingAnyActiveCanes(Sim sim)
{
CyrusCane activeCaneForActor = GetActiveCaneForActor(sim);
if (activeCaneForActor != null)
{
activeCaneForActor.NewUsingCane = false;
sim.PopCanePostureIfNecessary();
}
}
new public static bool SimRequiresCaneWalk(Sim sim, Sim.WalkStyle walkStyle)
{
CyrusCane activeCaneForActor = GetActiveCaneForActor(sim);
if (activeCaneForActor != null)
{
switch (walkStyle)
{
case Sim.WalkStyle.Run:
return activeCaneForActor.CurrentCaneWalkStyle == Sim.WalkStyle.ElderCaneWalk;
case Sim.WalkStyle.FastWalk:
case Sim.WalkStyle.FastJog:
case Sim.WalkStyle.Jog:
case Sim.WalkStyle.FastRun:
return activeCaneForActor.CurrentCaneWalkStyle == Sim.WalkStyle.ElderCaneWalk;
}
}
return false;
}
public class NewUseCane : ImmediateInteraction<Sim, CyrusCane>
{
[DoesntRequireTuning]
public class Definition : ImmediateInteractionDefinition<Sim, CyrusCane, NewUseCane>
{
public override string GetInteractionName(Sim a, CyrusCane target, InteractionObjectPair interaction)
{
if (target.NewUsingCane)
{
return LocalizeString(a.IsFemale, "StopUsingCane");
}
return LocalizeString(a.IsFemale, "StartUsingCane");
}
public override bool Test(Sim a, CyrusCane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (!IsAllowedToUseCane(a))
{
return false;
}
if (!a.SimDescription.YoungAdultOrAbove)
{
greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(LocalizeString(a.IsFemale, "AgeRestriction", a));
return false;
}
return true;
}
}
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
if (Target.NewUsingCane)
{
if (Actor.Posture is NewHoldingCanePosture)
{
if (!Actor.InteractionQueue.HasInteractionOfTypeAndTarget(NewStopUsingCane.Singleton, Target))
{
InteractionInstance interactionInstance = NewStopUsingCane.Singleton.CreateInstance(Target, Actor, new InteractionPriority(InteractionPriorityLevel.UserDirected), isAutonomous: false, cancellableByPlayer: true);
interactionInstance.Hidden = true;
Actor.InteractionQueue.PushAsContinuation(interactionInstance, mustRun: true);
}
}
else
{
Target.NewUsingCane = false;
}
}
else if (Actor.Posture is NewHoldingCanePosture || Actor.Posture == Actor.Standing)
{
if (!Actor.InteractionQueue.HasInteractionOfTypeAndTarget(NewStartUsingCane.Singleton, Target))
{
InteractionInstance interactionInstance2 = NewStartUsingCane.Singleton.CreateInstance(Target, Actor, new InteractionPriority(InteractionPriorityLevel.UserDirected), isAutonomous: false, cancellableByPlayer: true);
interactionInstance2.Hidden = true;
Actor.InteractionQueue.PushAsContinuation(interactionInstance2, mustRun: true);
}
}
else
{
Target.NewUsingCane = true;
}
return true;
}
}
public class NewHarassEveryone : TerrainInteraction, IRouteFromInventoryOrSelfWithoutCarrying
{
public class Definition : InteractionDefinition<Sim, Terrain, NewHarassEveryone>
{
public override bool Test(Sim a, Terrain target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (a.Posture is SwimmingInPool)
{
return false;
}
if (!IsAllowedToUseCane(a))
{
return false;
}
return a.Inventory.FindAll<CyrusCane>(checkInUse: false).Count > 0;
}
public override InteractionTestResult Test(ref InteractionInstanceParameters parameters, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (parameters.Hit.mType != GameObjectHitType.Terrain && parameters.Hit.mType != GameObjectHitType.LotTerrain && parameters.Hit.mType != GameObjectHitType.Object)
{
return InteractionTestResult.Gen_BadTerrainType;
}
InteractionTestResult interactionTestResult = base.Test(ref parameters, ref greyedOutTooltipCallback);
if (interactionTestResult != 0)
{
return interactionTestResult;
}
if (Terrain.GoHere.SharedGoHereTests(ref parameters))
{
Vector3 mPoint = parameters.Hit.mPoint;
Route route = parameters.Actor.CreateRoute();
if (route.IsPointRoutable(parameters.Hit.mPoint) && !World.IsInPool(mPoint))
{
return InteractionTestResult.Pass;
}
return InteractionTestResult.GenericFail;
}
return InteractionTestResult.GenericFail;
}
}
public CyrusCane mCane;
[Tunable]
[TunableComment("Distance away from the cane that the sim will route to in order to pick it up.")]
public static float kHarassEveryoneObjectSearchRadius = 5f;
[TunableComment("Distance away from a random object the sim will route to in order to 'harass' it.")]
[Tunable]
public static float[] kHarassEveryoneObjectRouteRadiusRange = new float[2]
{
0.5f,
3f
};
[Tunable]
[TunableComment("Chance a sim will harass a random object within the radius.")]
public static float kChanceToHarassObject = 0.7f;
public static InteractionDefinition Singleton = new Definition();
public override ThumbnailKey GetIconKey()
{
return Actor.GetThumbnailKey();
}
public override bool Run()
{
GameObject gameObject = null;
if (RandomUtil.RandomChance01(kChanceToHarassObject))
{
LotLocation location = LotLocation.Invalid;
ulong lotLocation = World.GetLotLocation(Destination, ref location);
int roomId = World.GetRoomId(lotLocation, location);
GameObject[] objects = Queries.GetObjects<GameObject>(Destination, kHarassEveryoneObjectSearchRadius);
List<GameObject> list = new List<GameObject>();
GameObject[] array = objects;
foreach (GameObject gameObject2 in array)
{
if (gameObject2.RoomId == roomId && !gameObject2.InUse && gameObject2 != Actor)
{
list.Add(gameObject2);
}
}
if (list.Count > 0)
{
gameObject = RandomUtil.GetRandomObjectFromList(list);
}
}
Route route = Actor.CreateRoute();
route.PlanToPointRadialRange(Destination, kHarassEveryoneObjectRouteRadiusRange[0], kHarassEveryoneObjectRouteRadiusRange[1], RouteDistancePreference.PreferNearestToRouteDestination, RouteOrientationPreference.NoPreference, 0uL, null);
if (!Actor.DoRoute(route))
{
return false;
}
if (gameObject != null)
{
Actor.RouteTurnToFace(gameObject.Position);
}
else
{
Actor.RouteTurnToFace(Destination + RandomUtil.GetRandomDirXZ());
}
if (Actor.Posture is SwimmingInPool)
{
Actor.PlayRouteFailure();
return false;
}
mCane = (CyrusSim.NewGetActiveCane(Actor) ?? Actor.Inventory.Find<CyrusCane>());
if (mCane == null)
{
return false;
}
mCane.CreatePropCane();
StandardEntry();
BeginCommodityUpdates();
EnterStateMachine("ElderCane", "Enter", "x");
SetActor("Cane", mCane.PropCane);
mCurrentStateMachine.AddOneShotStateEnteredEventHandler("Harass Everyone", FadePropCaneIn);
if (!(Actor.Posture is NewHoldingCanePosture))
{
mCurrentStateMachine.AddOneShotStateEnteredEventHandler("Exit", FadePropCaneOut);
}
if (gameObject != null)
{
ThoughtBalloonManager.BalloonData balloonData = new ThoughtBalloonManager.BalloonData(gameObject.GetThoughtBalloonThumbnailKey());
balloonData.BalloonType = ThoughtBalloonTypes.kThoughtBalloon;
balloonData.Duration = ThoughtBalloonDuration.Short;
balloonData.LowAxis = ThoughtBalloonAxis.kDislike;
Actor.ThoughtBalloonManager.ShowBalloon(balloonData);
}
AnimateSim("Harass Everyone");
EventTracker.SendEvent(EventTypeId.kHarassWithCane, Actor);
AnimateSim("Exit");
EndCommodityUpdates(succeeded: true);
StandardExit();
return true;
}
public override void Cleanup()
{
if (mCane != null && mCane != Actor.GetActiveCane())
{
mCane.DestroyPropCane();
}
base.Cleanup();
}
public void FadePropCaneIn(StateMachineClient smc, IEvent evt)
{
mCane.PropCane.FadeIn();
}
public void FadePropCaneOut(StateMachineClient smc, IEvent evt)
{
if (mCane.PropCane != null)
{
mCane.PropCane.FadeOut(yield: false, destroyObject: false);
}
}
}
public class NewHoldingCanePosture : Posture, IDisposable, IHaveCustomTransitionForNullPosturePreconditions
{
public Sim mActor;
public CyrusCane mCane;
public bool mIsExiting;
public bool IsExiting => mIsExiting;
public override bool PerformIdleLogic => false;
public override IGameObject Container => mActor;
public override string Name => Localization.LocalizeString(mActor.IsFemale, "Gameplay/Actors/Postures:HoldingCane");
public override bool Implicit => !kDebug;
public NewHoldingCanePosture()
{
}
public NewHoldingCanePosture(Sim actor, CyrusCane cane, StateMachineClient smc)
: base(smc)
{
mActor = actor;
mCane = cane;
mCane.NewUsingCane = true;
mCane.AddToUseList(mActor);
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished -= OnSimRouteActionsFinished;
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished += OnSimRouteActionsFinished;
mCane.CreatePropCane();
mCane.PropCane.ParentToSlot(mActor, Sim.ContainmentSlots.LeftHand);
smc.SetActor("x", mActor);
smc.SetActor("Cane", mCane.PropCane);
smc.EnterState("x", "Enter");
smc.AddOneShotStateEnteredEventHandler("Loop", OnAnimationEvent);
smc.AddSynchronousOneShotScriptEventHandler(101u, OnAnimationEvent);
smc.AddSynchronousOneShotScriptEventHandler(102u, OnAnimationEvent);
}
public void OnAnimationEvent(StateMachineClient smc, IEvent evt)
{
if (evt.EventId == 101 || evt.EventSubType == 3)
{
mCane.PropCane.FadeIn();
}
else if (evt.EventId == 102)
{
mCane.PropCane.FadeOut(yield: false, destroyObject: false);
}
}
public void OnSimRouteActionsFinished(GameObject routingObject, bool routeSuccess)
{
InteractionInstance headInteraction = mActor.InteractionQueue.GetHeadInteraction();
InteractionInstance transitionInteraction = mActor.InteractionQueue.TransitionInteraction;
if (((mActor.Posture is NewHoldingCanePosture && headInteraction != null && !(headInteraction is Terrain.GoHere) && !(headInteraction is TraitHarassWithCane) && !(headInteraction is NewHarassEveryone) && !(headInteraction is SocialInteraction)) || headInteraction is IPopCanePostureOnInteractionRouteEnd || transitionInteraction is IPopCanePostureOnInteractionRouteEnd) && !mActor.HasExitReason())
{
mActor.PopPosture();
}
}
public override bool AllowsReactionOverlay()
{
return false;
}
public override bool AllowsNormalSocials()
{
return true;
}
public override bool AllowsRouting()
{
return mActor.SimDescription.ToddlerOrAbove;
}
public override void PopulateInteractions()
{
}
public override float Satisfaction(CommodityKind condition, IGameObject target)
{
switch (condition)
{
case CommodityKind.Standing:
return 1f;
case CommodityKind.TargetInInventory:
return 1f;
case CommodityKind.PreferIfCurrentPosture:
if (mActor.Posture is NewHoldingCanePosture)
{
return 1f;
}
return 0f;
case CommodityKind.HoldingCane:
return 1f;
default:
return 0f;
}
}
public override bool Satisfies(PreconditionOptions options, IGameObject target, CommodityKind requiredCheck)
{
if (options == null && requiredCheck == CommodityKind.None)
{
return true;
}
return base.Satisfies(options, target, requiredCheck);
}
public override InteractionInstance GetTransition(InteractionInstance interaction)
{
if (interaction.Target == mActor && !(interaction is IRouteFromInventoryOrSelfWithoutCarrying))
{
return GetStandingTransition();
}
if (interaction.PosturePreconditions == null)
{
return null;
}
return Posture.FindTransitionInteraction(interaction, CommodityKind.None);
}
public override BridgeOrigin Idle()
{
base.Idle();
CurrentStateMachine.SetParameter("RestrictCaneIdles", paramValue: false);
GameObject gameObject = GlobalFunctions.CreateObjectOutOfWorld("elderCaneIdle_Jig", ProductVersion.EP4) as GameObject;
mActor.SetHiddenFlags(HiddenFlags.Everything);
if (!World.TestObjectPlacement(gameObject.ObjectId, TestObjectPlacementBooleans.TemporaryPlacement, mActor.Position, mActor.ForwardVector))
{
CurrentStateMachine.SetParameter("RestrictCaneIdles", paramValue: true);
}
mActor.SetHiddenFlags(HiddenFlags.Nothing);
gameObject.Destroy();
CurrentStateMachine.RequestState("x", "Loop");
return new BridgeOrigin(CurrentStateMachine, "x", "HoldCane");
}
public override InteractionInstance GetStandingTransition()
{
NewStopUsingCane stopUsingCane = NewStopUsingCane.Singleton.CreateInstance(mCane, mActor, mActor.InheritedPriority(), isAutonomous: false, cancellableByPlayer: true) as NewStopUsingCane;
stopUsingCane.UnsetUsingCane = false;
return stopUsingCane;
}
public override ScriptPosture GetSacsPostureParameter()
{
return ScriptPosture.Standing;
}
public override Posture OnReset(IGameObject objectBeingReset)
{
CleanUpPosture();
return null;
}
public override void OnExitPosture()
{
if (!mIsExiting)
{
mIsExiting = true;
if (CurrentStateMachine != null)
{
CurrentStateMachine.RequestState(yield: true, "x", "Exit");
}
CleanUpPosture();
}
}
public override void Shoo(bool yield, List<Sim> shooedSims)
{
throw new Exception("The method or operation is not implemented.");
}
public void CleanUpPosture()
{
if (mCane.IsActorUsingMe(mActor))
{
mCane.RemoveFromUseList(mActor);
}
mCane.DestroyPropCane();
if (CurrentStateMachine != null)
{
CurrentStateMachine.RemoveAllEventHandlers();
CurrentStateMachine.Dispose();
CurrentStateMachine = null;
}
if (mActor.SimRoutingComponent != null)
{
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished -= OnSimRouteActionsFinished;
}
}
public override string ToString()
{
return "Holding Cane Posture";
}
~NewHoldingCanePosture()
{
Dispose(fromDtor: true);
}
public void Dispose()
{
Dispose(fromDtor: false);
}
public void Dispose(bool fromDtor)
{
if (CurrentStateMachine != null)
{
CurrentStateMachine.RemoveAllEventHandlers();
CurrentStateMachine.Dispose();
CurrentStateMachine = null;
}
if (mActor.SimRoutingComponent != null)
{
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished -= OnSimRouteActionsFinished;
}
if (!fromDtor)
{
GC.SuppressFinalize(this);
}
}
}
public class NewSetWalkStyle : ImmediateInteraction<Sim, CyrusCane>
{
[DoesntRequireTuning]
public class Definition : ImmediateInteractionDefinition<Sim, CyrusCane, NewSetWalkStyle>
{
public Sim.WalkStyle CaneWalkStyle;
public Definition()
{
}
public Definition(Sim.WalkStyle walkStyle)
{
CaneWalkStyle = walkStyle;
}
public override string GetInteractionName(Sim a, CyrusCane target, InteractionObjectPair interaction)
{
if (CaneWalkStyle == kSouthernGentlemanCaneWalk)
{
return LocalizeString(a.IsFemale, "SouthernGentleman");
}
return LocalizeString(a.IsFemale, "Elderly");
}
public override string[] GetPath(bool isFemale)
{
return new string[1]
{
LocalizeString(isFemale, "SetWalkStyle")
};
}
public override bool Test(Sim a, CyrusCane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (!IsAllowedToUseCane(a))
{
return false;
}
if (!a.SimDescription.YoungAdultOrAbove)
{
greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(LocalizeString(a.IsFemale, "AgeRestriction", a));
return false;
}
if (CaneWalkStyle == target.CurrentCaneWalkStyle)
{
greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(LocalizeString(a.IsFemale, "WalkStyleInUse", a));
return false;
}
return true;
}
public override void AddInteractions(InteractionObjectPair iop, Sim actor, CyrusCane target, List<InteractionObjectPair> results)
{
Definition interaction = new Definition(kSouthernGentlemanCaneWalk);
results.Add(new InteractionObjectPair(interaction, target));
interaction = new Definition(kElderlyCaneWalk);
results.Add(new InteractionObjectPair(interaction, target));
}
}
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
Definition definition = base.InteractionDefinition as Definition;
Target.CurrentCaneWalkStyle = definition.CaneWalkStyle;
return true;
}
}
public class NewStartUsingCane : Interaction<Sim, CyrusCane>
{
public class Definition : InteractionDefinition<Sim, CyrusCane, NewStartUsingCane>
{
public override bool Test(Sim a, CyrusCane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
}
}
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
StandardEntry(addToUseList: false);
BeginCommodityUpdates();
StopUsingAnyActiveCanes(Actor);
if (!(Actor.Posture is NewHoldingCanePosture))
{
StateMachineClient smc = StateMachineClient.Acquire(Actor, "ElderCane");
Actor.Posture = new NewHoldingCanePosture(Actor, Target, smc);
Actor.Posture.CurrentStateMachine.RequestState("x", "Pull Out Cane");
}
EndCommodityUpdates(succeeded: true);
StandardExit(removeFromUseList: false, validateUseList: false);
return true;
}
}
public class NewStopUsingCane : Interaction<Sim, CyrusCane>
{
public class Definition : InteractionDefinition<Sim, CyrusCane, NewStopUsingCane>
{
public override bool Test(Sim a, CyrusCane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
}
}
public bool UnsetUsingCane = true;
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
StandardEntry(addToUseList: false);
BeginCommodityUpdates();
if (UnsetUsingCane)
{
StopUsingAnyActiveCanes(Actor);
Target.NewUsingCane = false;
}
else
{
Actor.PopCanePostureIfNecessary();
}
EndCommodityUpdates(succeeded: true);
StandardExit(removeFromUseList: false, validateUseList: false);
return true;
}
}
public class NewTraitHarassWithCane : Interaction<Sim, Sim>, IRouteFromInventoryOrSelfWithoutCarrying
{
public delegate bool HarassObjectCheckFunction(GameObject obj);
public class Definition : SoloSimInteractionDefinition<TraitHarassWithCane>
{
public override bool Test(Sim a, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (!IsAllowedToUseCane(a))
{
return false;
}
if (a.Inventory.ContainsType(typeof(CyrusCane), 1))
{
return a.TraitManager.HasAnyElement(HarassTraits);
}
return false;
}
}
public CyrusCane mCane;
public static TraitNames[] HarassTraits = new TraitNames[10]
{
TraitNames.Grumpy,
TraitNames.Evil,
TraitNames.MeanSpirited,
TraitNames.Insane,
TraitNames.HatesOutdoors,
TraitNames.DislikesChildren,
TraitNames.CantStandArt,
TraitNames.Frugal,
TraitNames.AntiTV,
TraitNames.Neat
};
public GameObject mHarassmentObject;
public string mIcon = string.Empty;
[Tunable]
[TunableComment("Value threshold of objects that a frugal sim will harass. Threshold is randomly chosen between these two values each time the interaction is run. If the value of an object is greater than the threshold, the sim will route over an complain about it.")]
public static int[] kFrugalValueThreshold = new int[2]
{
500,
1000
};
[TunableComment("Objects within this radius of the sim will be selected for the sim to complain about.")]
[Tunable]
public static float kObjectSearchRadius = 20f;
[TunableComment("Radial route min/max that the sim will try to route to if the find good location route fails.")]
[Tunable]
public static float[] kObjectFallbackRouteRadius = new float[2]
{
0f,
5f
};
public static ISoloInteractionDefinition Singleton = new Definition();
public override void ConfigureInteraction()
{
List<TraitNames> list = new List<TraitNames>();
TraitNames[] harassTraits = HarassTraits;
foreach (TraitNames traitNames in harassTraits)
{
if (Actor.TraitManager.HasElement(traitNames))
{
list.Add(traitNames);
}
}
if (list.Count == 0)
{
return;
}
GameObject[] objects = Queries.GetObjects<GameObject>(Actor.Position, kObjectSearchRadius);
List<GameObject> list2 = new List<GameObject>();
HarassObjectCheckFunction harassObjectCheckFunction = null;
switch (RandomUtil.GetRandomObjectFromList(list))
{
case TraitNames.Evil:
case TraitNames.Grumpy:
case TraitNames.MeanSpirited:
harassObjectCheckFunction = IsSimCheck;
mIcon = "Random";
break;
case TraitNames.Insane:
harassObjectCheckFunction = HatesOutdoorsCheck;
mIcon = "Talk About Conspiracies";
break;
case TraitNames.HatesOutdoors:
harassObjectCheckFunction = HatesOutdoorsCheck;
mIcon = "Great Outdoors";
break;
case TraitNames.DislikesChildren:
harassObjectCheckFunction = DislikesChildrenCheck;
mIcon = "TraitDislikesChildren";
break;
case TraitNames.CantStandArt:
harassObjectCheckFunction = CantStandArtCheck;
mIcon = "Art";
break;
case TraitNames.Frugal:
harassObjectCheckFunction = FrugalCheck;
mIcon = "TraitFrugal";
break;
case TraitNames.AntiTV:
harassObjectCheckFunction = AntiTVCheck;
mIcon = "TraitGenius";
break;
case TraitNames.Neat:
harassObjectCheckFunction = NeatCheck;
mIcon = "Insult";
break;
}
GameObject[] array = objects;
foreach (GameObject gameObject in array)
{
if (harassObjectCheckFunction(gameObject) && Actor.IsGreetedOnLot(gameObject.LotCurrent))
{
list2.Add(gameObject);
}
}
mHarassmentObject = Actor;
if (list2.Count > 0)
{
mHarassmentObject = RandomUtil.GetRandomObjectFromList(list2);
}
}
public override ThumbnailKey GetIconKey()
{
if (mHarassmentObject != null)
{
return mHarassmentObject.GetThumbnailKey();
}
return base.GetIconKey();
}
public override bool Run()
{
if (mHarassmentObject == null)
{
return false;
}
World.FindGoodLocationParams fglParams = new World.FindGoodLocationParams(mHarassmentObject.Position);
fglParams.StartPosition = mHarassmentObject.Position;
fglParams.RequiredRoomID = mHarassmentObject.RoomId;
bool flag = false;
if (GlobalFunctions.FindGoodLocation(Actor, fglParams, out Vector3 pos, out Vector3 _))
{
Route route = Actor.CreateRoute();
route.PlanToPoint(pos);
route.DoRouteFail = false;
flag = Actor.DoRoute(route);
}
if (!flag)
{
Actor.RouteToDynamicObjectRadiusWithCondition(mHarassmentObject, kObjectFallbackRouteRadius[0], kObjectFallbackRouteRadius[1], null, null, Route.RouteOption.DoLineOfSightCheckUserOverride);
}
Actor.RouteTurnToFace(mHarassmentObject.Position);
if (Actor.Posture is SwimmingInPool)
{
Actor.PlayRouteFailure();
return false;
}
mCane = (CyrusSim.NewGetActiveCane(Actor) ?? Actor.Inventory.Find<CyrusCane>());
if (mCane == null)
{
return false;
}
if (!mCane.NewUsingCane)
{
mCane.AddToUseList(Actor);
}
mCane.CreatePropCane();
StandardEntry();
BeginCommodityUpdates();
EnterStateMachine("ElderCane", "Enter", "x");
SetActor("Cane", mCane.PropCane);
mCurrentStateMachine.AddOneShotStateEnteredEventHandler("Harass Everyone", FadePropCaneIn);
if (!(Actor.Posture is NewHoldingCanePosture))
{
mCurrentStateMachine.AddOneShotStateEnteredEventHandler("Exit", FadePropCaneOut);
}
ThoughtBalloonManager.BalloonData balloonData = ThoughtBalloonManager.GetBalloonData(mIcon, Actor);
balloonData.BalloonType = ThoughtBalloonTypes.kThoughtBalloon;
balloonData.LowAxis = ThoughtBalloonAxis.kDislike;
balloonData.Duration = ThoughtBalloonDuration.Short;
Actor.ThoughtBalloonManager.ShowBalloon(balloonData);
AnimateSim("Harass Everyone");
AnimateSim("Exit");
EndCommodityUpdates(succeeded: true);
StandardExit();
return true;
}
public override void Cleanup()
{
if (mCane != null)
{
if (mCane.IsActorUsingMe(Actor) && !mCane.NewUsingCane)
{
mCane.RemoveFromUseList(Actor);
}
if (mCane != Actor.GetActiveCane())
{
mCane.DestroyPropCane();
}
}
base.Cleanup();
}
public void FadePropCaneIn(StateMachineClient smc, IEvent evt)
{
mCane.PropCane.FadeIn();
}
public void FadePropCaneOut(StateMachineClient smc, IEvent evt)
{
if (mCane.PropCane != null)
{
mCane.PropCane.FadeOut(yield: false, destroyObject: false);
}
}
public bool IsSimCheck(GameObject obj)
{
return obj is Sim;
}
public bool HatesOutdoorsCheck(GameObject obj)
{
if (obj.IsOutside && !obj.InUse)
{
return obj != Actor;
}
return false;
}
public bool DislikesChildrenCheck(GameObject obj)
{
Sim sim = obj as Sim;
if (sim != null && sim.IsHuman && (sim.SimDescription.IsPregnant || sim.SimDescription.ChildOrBelow) && obj != Actor)
{
return true;
}
return false;
}
public bool CantStandArtCheck(GameObject obj)
{
if (!(obj is IPainting) && !(obj is ISculpture))
{
return obj is IPhotograph;
}
return true;
}
public bool FrugalCheck(GameObject obj)
{
int @int = RandomUtil.GetInt(kFrugalValueThreshold[0], kFrugalValueThreshold[1]);
return obj.Value >= @int;
}
public bool AntiTVCheck(GameObject obj)
{
if (!(obj is ITelevision) && !(obj is IComputer))
{
return obj is IStereo;
}
return true;
}
public bool NeatCheck(GameObject obj)
{
Sim sim = obj as Sim;
if (sim != null && sim.BuffManager.HasAnyElement(BuffNames.Smelly, BuffNames.Grungy))
{
return true;
}
CleanableComponent cleanable = obj.Cleanable;
if (cleanable != null && cleanable.VisuallyDirty)
{
return true;
}
return false;
}
}
}
}
Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts 9 Achievements
Maybe the game thinks you are talking about something different when you say posture in the 2nd part? Try to specify more clearly what Posture means by stating what it belongs to.
Like Sims3.....Posture.
If you like my mods. Consider supporting me on Patreon
Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts 9 Achievements
No I meant more like Sims3.Gameplay.ActorSystems.Posture instead of just Posture. Sometimes there are multiple classes, variables, functions with the same name. So you need to specify which one you are talking about.
That's what I feel is the problem in your code.
If you like my mods. Consider supporting me on Patreon
When VS says "an object reference is required for non-static field," it means exactly what it says. Static fields, methods, etc. are shared across all instances of a class; for example, Sims3.Gameplay.Actors.Sim.sNumberOfActors represents the number of Sim objects currently in existence, and as such the value is associated with the Sim class itself, rather than any given Sim object.
On the other hand, Posture and PopPosture() are non-static members of Sim. This means that each Sim object has their own posture, and as such you must refer to a specific Sim object's Posture or SetPosture() method.
TL;DR You need to pass in the Sim whose posture you're trying to get, then set, like so:
Code:
public static void PopCanePostureIfNecessary(Sim sim)
{
if (Simulator.CheckYieldingContext(shouldThrowException: false))
{
CyrusCane.NewHoldingCanePosture holdingCanePosture = sim?.Posture as CyrusCane.NewHoldingCanePosture;
if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
{
sim.PopPosture();
}
}
}
"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt
Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts 9 Achievements
Yea what Gamefreak said. I thought there was some other problem because the error in the first was different. And I had a similar problem so replied accordingly.
When a class has static members
Code:
Class Example{
Static int a=6;
int b=3;
}
Class Example2{
Example.a=4; // is correct
Example.b=2; // error.
Example objectexample= new Example();
objectexample.b=2// is correct
objectexample.a=1// error.
If you like my mods. Consider supporting me on Patreon
Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
@gamefreak130 and @PuddingFace
I still can't do it, trying to specify the object as a Actor, or even a Sim, as gamefreak did. What I'm doing wrong? I put the object before the non-static field specified, like in the example.
Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
@PuddingFace ,
Nevermind, I've changed the approach to substituing the interactions, and it seems to have worked to solve this problem. But it I still can't get the code to make both the posture and the walkstyles from the canes to appear. Here's the new code:
Code:
using Sims3.Gameplay.Abstracts;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.ActorSystems;
using Sims3.Gameplay.Autonomy;
using Sims3.Gameplay.CAS;
using Sims3.Gameplay.Core;
using Sims3.Gameplay.EventSystem;
using Sims3.Gameplay.Interactions;
using Sims3.Gameplay.Interfaces;
using Sims3.Gameplay.ObjectComponents;
using Sims3.Gameplay.Pools;
using Sims3.Gameplay.Skills;
using Sims3.Gameplay.Socializing;
using Sims3.Gameplay.ThoughtBalloons;
using Sims3.Gameplay.Utilities;
using Sims3.SimIFace;
using Sims3.SimIFace.CustomContent;
using Sims3.SimIFace.Enums;
using Sims3.UI.Hud;
using System;
using System.Collections.Generic;
using Sims3.Gameplay.Objects;
using Sims3.Gameplay;
using static Sims3.Gameplay.Objects.Cane;
namespace Cyrus.Sims3Game.CanesForEveryone
{
class Class3
{
public class HoldingCanePosture : Posture, IDisposable, IHaveCustomTransitionForNullPosturePreconditions
{
public Sim mActor;
public Cane mCane;
public bool mIsExiting;
public bool IsExiting => mIsExiting;
public override bool PerformIdleLogic => false;
public override IGameObject Container => mActor;
public override string Name => Localization.LocalizeString(mActor.IsFemale, "Gameplay/Actors/Postures:HoldingCane");
public override bool Implicit => !kDebug;
public HoldingCanePosture()
{
}
public HoldingCanePosture(Sim actor, Cane cane, StateMachineClient smc)
: base(smc)
{
mActor = actor;
mCane = cane;
mCane.UsingCane = true;
mCane.AddToUseList(mActor);
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished -= OnSimRouteActionsFinished;
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished += OnSimRouteActionsFinished;
mCane.CreatePropCane();
mCane.PropCane.ParentToSlot(mActor, Sim.ContainmentSlots.LeftHand);
smc.SetActor("x", mActor);
smc.SetActor("Cane", mCane.PropCane);
smc.EnterState("x", "Enter");
smc.AddOneShotStateEnteredEventHandler("Loop", OnAnimationEvent);
smc.AddSynchronousOneShotScriptEventHandler(101u, OnAnimationEvent);
smc.AddSynchronousOneShotScriptEventHandler(102u, OnAnimationEvent);
}
public void OnAnimationEvent(StateMachineClient smc, IEvent evt)
{
if (evt.EventId == 101 || evt.EventSubType == 3)
{
mCane.PropCane.FadeIn();
}
else if (evt.EventId == 102)
{
mCane.PropCane.FadeOut(yield: false, destroyObject: false);
}
}
public void OnSimRouteActionsFinished(GameObject routingObject, bool routeSuccess)
{
InteractionInstance headInteraction = mActor.InteractionQueue.GetHeadInteraction();
InteractionInstance transitionInteraction = mActor.InteractionQueue.TransitionInteraction;
if (((mActor.Posture is HoldingCanePosture && headInteraction != null && !(headInteraction is Terrain.GoHere) && !(headInteraction is TraitHarassWithCane) && !(headInteraction is HarassEveryone) && !(headInteraction is SocialInteraction)) || headInteraction is IPopCanePostureOnInteractionRouteEnd || transitionInteraction is IPopCanePostureOnInteractionRouteEnd) && !mActor.HasExitReason())
{
mActor.PopPosture();
}
}
public override bool AllowsReactionOverlay()
{
return false;
}
public override bool AllowsNormalSocials()
{
return true;
}
public override bool AllowsRouting()
{
return mActor.SimDescription.ToddlerOrAbove;
}
public override void PopulateInteractions()
{
}
public override float Satisfaction(CommodityKind condition, IGameObject target)
{
switch (condition)
{
case CommodityKind.Standing:
return 1f;
case CommodityKind.TargetInInventory:
return 1f;
case CommodityKind.PreferIfCurrentPosture:
if (mActor.Posture is HoldingCanePosture)
{
return 1f;
}
return 0f;
case CommodityKind.HoldingCane:
return 1f;
default:
return 0f;
}
}
public override bool Satisfies(PreconditionOptions options, IGameObject target, CommodityKind requiredCheck)
{
if (options == null && requiredCheck == CommodityKind.None)
{
return true;
}
return base.Satisfies(options, target, requiredCheck);
}
public override InteractionInstance GetTransition(InteractionInstance interaction)
{
if (interaction.Target == mActor && !(interaction is IRouteFromInventoryOrSelfWithoutCarrying))
{
return GetStandingTransition();
}
if (interaction.PosturePreconditions == null)
{
return null;
}
return Posture.FindTransitionInteraction(interaction, CommodityKind.None);
}
public override BridgeOrigin Idle()
{
base.Idle();
CurrentStateMachine.SetParameter("RestrictCaneIdles", paramValue: false);
GameObject gameObject = GlobalFunctions.CreateObjectOutOfWorld("elderCaneIdle_Jig", ProductVersion.EP4) as GameObject;
mActor.SetHiddenFlags(HiddenFlags.Everything);
if (!World.TestObjectPlacement(gameObject.ObjectId, TestObjectPlacementBooleans.TemporaryPlacement, mActor.Position, mActor.ForwardVector))
{
CurrentStateMachine.SetParameter("RestrictCaneIdles", paramValue: true);
}
mActor.SetHiddenFlags(HiddenFlags.Nothing);
gameObject.Destroy();
CurrentStateMachine.RequestState("x", "Loop");
return new BridgeOrigin(CurrentStateMachine, "x", "HoldCane");
}
public override InteractionInstance GetStandingTransition()
{
StopUsingCane stopUsingCane = StopUsingCane.Singleton.CreateInstance(mCane, mActor, mActor.InheritedPriority(), isAutonomous: false, cancellableByPlayer: true) as StopUsingCane;
stopUsingCane.UnsetUsingCane = false;
return stopUsingCane;
}
public override ScriptPosture GetSacsPostureParameter()
{
return ScriptPosture.Standing;
}
public override Posture OnReset(IGameObject objectBeingReset)
{
CleanUpPosture();
return null;
}
public override void OnExitPosture()
{
if (!mIsExiting)
{
mIsExiting = true;
if (CurrentStateMachine != null)
{
CurrentStateMachine.RequestState(yield: true, "x", "Exit");
}
CleanUpPosture();
}
}
public override void Shoo(bool yield, List<Sim> shooedSims)
{
throw new Exception("The method or operation is not implemented.");
}
public void CleanUpPosture()
{
if (mCane.IsActorUsingMe(mActor))
{
mCane.RemoveFromUseList(mActor);
}
mCane.DestroyPropCane();
if (CurrentStateMachine != null)
{
CurrentStateMachine.RemoveAllEventHandlers();
CurrentStateMachine.Dispose();
CurrentStateMachine = null;
}
if (mActor.SimRoutingComponent != null)
{
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished -= OnSimRouteActionsFinished;
}
}
public override string ToString()
{
return "Holding Cane Posture";
}
~HoldingCanePosture()
{
Dispose(fromDtor: true);
}
public void Dispose()
{
Dispose(fromDtor: false);
}
public void Dispose(bool fromDtor)
{
if (CurrentStateMachine != null)
{
CurrentStateMachine.RemoveAllEventHandlers();
CurrentStateMachine.Dispose();
CurrentStateMachine = null;
}
if (mActor.SimRoutingComponent != null)
{
((RoutingComponent)mActor.SimRoutingComponent).OnRouteActionsFinished -= OnSimRouteActionsFinished;
}
if (!fromDtor)
{
GC.SuppressFinalize(this);
}
}
}
public class NewHarassEveryone : TerrainInteraction, IRouteFromInventoryOrSelfWithoutCarrying
{
public class Definition : InteractionDefinition<Sim, Terrain, NewHarassEveryone>
{
public override bool Test(Sim a, Terrain target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (a.Posture is SwimmingInPool)
{
return false;
}
if (!NewIsAllowedToUseCane(a))
{
return false;
}
return a.Inventory.FindAll<Cane>(checkInUse: false).Count > 0;
}
public override InteractionTestResult Test(ref InteractionInstanceParameters parameters, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (parameters.Hit.mType != GameObjectHitType.Terrain && parameters.Hit.mType != GameObjectHitType.LotTerrain && parameters.Hit.mType != GameObjectHitType.Object)
{
return InteractionTestResult.Gen_BadTerrainType;
}
InteractionTestResult interactionTestResult = base.Test(ref parameters, ref greyedOutTooltipCallback);
if (interactionTestResult != 0)
{
return interactionTestResult;
}
if (Terrain.GoHere.SharedGoHereTests(ref parameters))
{
Vector3 mPoint = parameters.Hit.mPoint;
Route route = parameters.Actor.CreateRoute();
if (route.IsPointRoutable(parameters.Hit.mPoint) && !World.IsInPool(mPoint))
{
return InteractionTestResult.Pass;
}
return InteractionTestResult.GenericFail;
}
return InteractionTestResult.GenericFail;
}
}
public Cane mCane;
[Tunable]
[TunableComment("Distance away from the cane that the sim will route to in order to pick it up.")]
public static float kHarassEveryoneObjectSearchRadius = 5f;
[TunableComment("Distance away from a random object the sim will route to in order to 'harass' it.")]
[Tunable]
public static float[] kHarassEveryoneObjectRouteRadiusRange = new float[2]
{
0.5f,
3f
};
[Tunable]
[TunableComment("Chance a sim will harass a random object within the radius.")]
public static float kChanceToHarassObject = 0.7f;
public static InteractionDefinition Singleton = new Definition();
public override ThumbnailKey GetIconKey()
{
return Actor.GetThumbnailKey();
}
public override bool Run()
{
GameObject gameObject = null;
if (RandomUtil.RandomChance01(kChanceToHarassObject))
{
LotLocation location = LotLocation.Invalid;
ulong lotLocation = World.GetLotLocation(Destination, ref location);
int roomId = World.GetRoomId(lotLocation, location);
GameObject[] objects = Sims3.Gameplay.Queries.GetObjects<GameObject>(Destination, kHarassEveryoneObjectSearchRadius);
List<GameObject> list = new List<GameObject>();
GameObject[] array = objects;
foreach (GameObject gameObject2 in array)
{
if (gameObject2.RoomId == roomId && !gameObject2.InUse && gameObject2 != Actor)
{
list.Add(gameObject2);
}
}
if (list.Count > 0)
{
gameObject = RandomUtil.GetRandomObjectFromList(list);
}
}
Route route = Actor.CreateRoute();
route.PlanToPointRadialRange(Destination, kHarassEveryoneObjectRouteRadiusRange[0], kHarassEveryoneObjectRouteRadiusRange[1], RouteDistancePreference.PreferNearestToRouteDestination, RouteOrientationPreference.NoPreference, 0uL, null);
if (!Actor.DoRoute(route))
{
return false;
}
if (gameObject != null)
{
Actor.RouteTurnToFace(gameObject.Position);
}
else
{
Actor.RouteTurnToFace(Destination + RandomUtil.GetRandomDirXZ());
}
if (Actor.Posture is SwimmingInPool)
{
Actor.PlayRouteFailure();
return false;
}
mCane = (Actor.GetActiveCane() ?? Actor.Inventory.Find<Cane>());
if (mCane == null)
{
return false;
}
mCane.CreatePropCane();
StandardEntry();
BeginCommodityUpdates();
EnterStateMachine("ElderCane", "Enter", "x");
SetActor("Cane", mCane.PropCane);
mCurrentStateMachine.AddOneShotStateEnteredEventHandler("Harass Everyone", FadePropCaneIn);
if (!(Actor.Posture is HoldingCanePosture))
{
mCurrentStateMachine.AddOneShotStateEnteredEventHandler("Exit", FadePropCaneOut);
}
if (gameObject != null)
{
ThoughtBalloonManager.BalloonData balloonData = new ThoughtBalloonManager.BalloonData(gameObject.GetThoughtBalloonThumbnailKey());
balloonData.BalloonType = ThoughtBalloonTypes.kThoughtBalloon;
balloonData.Duration = ThoughtBalloonDuration.Short;
balloonData.LowAxis = ThoughtBalloonAxis.kDislike;
Actor.ThoughtBalloonManager.ShowBalloon(balloonData);
}
AnimateSim("Harass Everyone");
EventTracker.SendEvent(EventTypeId.kHarassWithCane, Actor);
AnimateSim("Exit");
EndCommodityUpdates(succeeded: true);
StandardExit();
return true;
}
public override void Cleanup()
{
if (mCane != null && mCane != Actor.GetActiveCane())
{
mCane.DestroyPropCane();
}
base.Cleanup();
}
public void FadePropCaneIn(StateMachineClient smc, IEvent evt)
{
mCane.PropCane.FadeIn();
}
public void FadePropCaneOut(StateMachineClient smc, IEvent evt)
{
if (mCane.PropCane != null)
{
mCane.PropCane.FadeOut(yield: false, destroyObject: false);
}
}
}
public class NewUseCane : ImmediateInteraction<Sim, Cane>
{
[DoesntRequireTuning]
public class Definition : ImmediateInteractionDefinition<Sim, Cane, NewUseCane>
{
public override string GetInteractionName(Sim a, Cane target, InteractionObjectPair interaction)
{
if (target.UsingCane)
{
return LocalizeString(a.IsFemale, "StopUsingCane");
}
return LocalizeString(a.IsFemale, "StartUsingCane");
}
public override bool Test(Sim a, Cane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (!NewIsAllowedToUseCane(a))
{
return false;
}
if (!a.SimDescription.YoungAdultOrAbove)
{
greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(LocalizeString(a.IsFemale, "AgeRestriction", a));
return false;
}
return true;
}
}
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
if (Target.UsingCane)
{
if (Actor.Posture is HoldingCanePosture)
{
if (!Actor.InteractionQueue.HasInteractionOfTypeAndTarget(NewStopUsingCane.Singleton, Target))
{
InteractionInstance interactionInstance = NewStopUsingCane.Singleton.CreateInstance(Target, Actor, new InteractionPriority(InteractionPriorityLevel.UserDirected), isAutonomous: false, cancellableByPlayer: true);
interactionInstance.Hidden = true;
Actor.InteractionQueue.PushAsContinuation(interactionInstance, mustRun: true);
}
}
else
{
Target.UsingCane = false;
}
}
else if (Actor.Posture is HoldingCanePosture || Actor.Posture == Actor.Standing)
{
if (!Actor.InteractionQueue.HasInteractionOfTypeAndTarget(NewStartUsingCane.Singleton, Target))
{
InteractionInstance interactionInstance2 = NewStartUsingCane.Singleton.CreateInstance(Target, Actor, new InteractionPriority(InteractionPriorityLevel.UserDirected), isAutonomous: false, cancellableByPlayer: true);
interactionInstance2.Hidden = true;
Actor.InteractionQueue.PushAsContinuation(interactionInstance2, mustRun: true);
}
}
else
{
Target.UsingCane = true;
}
return true;
}
}
public class NewStopUsingCane : Interaction<Sim, Cane>
{
public class Definition : InteractionDefinition<Sim, Cane, NewStopUsingCane>
{
public override bool Test(Sim a, Cane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
}
}
public bool UnsetUsingCane = true;
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
StandardEntry(addToUseList: false);
BeginCommodityUpdates();
if (UnsetUsingCane)
{
StopUsingAnyActiveCanes(Actor);
Target.UsingCane = false;
}
else
{
Actor.PopCanePostureIfNecessary();
}
EndCommodityUpdates(succeeded: true);
StandardExit(removeFromUseList: false, validateUseList: false);
return true;
}
}
public class NewStartUsingCane : Interaction<Sim, Cane>
{
public class Definition : InteractionDefinition<Sim, Cane, NewStartUsingCane>
{
public override bool Test(Sim a, Cane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
}
}
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
StandardEntry(addToUseList: false);
BeginCommodityUpdates();
StopUsingAnyActiveCanes(Actor);
if (!(Actor.Posture is HoldingCanePosture))
{
StateMachineClient smc = StateMachineClient.Acquire(Actor, "ElderCane");
Actor.Posture = new HoldingCanePosture(Actor, Target, smc);
Actor.Posture.CurrentStateMachine.RequestState("x", "Pull Out Cane");
}
EndCommodityUpdates(succeeded: true);
StandardExit(removeFromUseList: false, validateUseList: false);
return true;
}
}
public class NewSetWalkStyle : ImmediateInteraction<Sim, Cane>
{
[DoesntRequireTuning]
public class Definition : ImmediateInteractionDefinition<Sim, Cane, NewSetWalkStyle>
{
public Sim.WalkStyle CaneWalkStyle;
public Definition()
{
}
public Definition(Sim.WalkStyle walkStyle)
{
CaneWalkStyle = walkStyle;
}
public override string GetInteractionName(Sim a, Cane target, InteractionObjectPair interaction)
{
if (CaneWalkStyle == kSouthernGentlemanCaneWalk)
{
return LocalizeString(a.IsFemale, "SouthernGentleman");
}
return LocalizeString(a.IsFemale, "Elderly");
}
public override string[] GetPath(bool isFemale)
{
return new string[1]
{
LocalizeString(isFemale, "SetWalkStyle")
};
}
public override bool Test(Sim a, Cane target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (!NewIsAllowedToUseCane(a))
{
return false;
}
if (!a.SimDescription.YoungAdultOrAbove)
{
greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(LocalizeString(a.IsFemale, "AgeRestriction", a));
return false;
}
if (CaneWalkStyle == target.CurrentCaneWalkStyle)
{
greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(LocalizeString(a.IsFemale, "WalkStyleInUse", a));
return false;
}
return true;
}
public override void AddInteractions(InteractionObjectPair iop, Sim actor, Cane target, List<InteractionObjectPair> results)
{
Definition interaction = new Definition(kSouthernGentlemanCaneWalk);
results.Add(new InteractionObjectPair(interaction, target));
interaction = new Definition(kElderlyCaneWalk);
results.Add(new InteractionObjectPair(interaction, target));
}
}
public static InteractionDefinition Singleton = new Definition();
public override bool RunFromInventory()
{
Definition definition = base.InteractionDefinition as Definition;
Target.CurrentCaneWalkStyle = definition.CaneWalkStyle;
return true;
}
}
public static bool NewIsAllowedToUseCane(Sim sim)
{
return sim.SimDescription.YoungAdultOrAbove;
}
}
}
In a nutshell, I preserved the original object and used a Instantiator class (not seem in this part of the code, because it is in another class) to replace the interactions with my versions. I really don't know what exactly is going wrong - By what I know, it SHOULD be working.
Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts 9 Achievements
@CyrusBanefort So what's happening in the game? Is there any change from the default behavior. Any error message from Nraas error trap? Is there no change at all?
If you like my mods. Consider supporting me on Patreon
Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
Quote:
Originally Posted by PuddingFace
@CyrusBanefort So what's happening in the game? Is there any change from the default behavior. Any error message from Nraas error trap? Is there no change at all?
@Battery
Basically, the thing that happens is that the cane appears in the sim's hand, but it does not play any of the animations, and when I try to make the sim stop using the cane, the prop cane doesn't disappear.
Join Date: Dec 2008
Posts: 385
Thanks: 827 in 5 Posts 8 Achievements
Hmm i would suggest creating an new interaction and testing each part of the functionality you need an if every single part works on its own put it all together.
So you might want to start with an interaction that changes just the walkstyle and then the posture and so on
Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts 9 Achievements
This is how I was requesting different walk/run styles in my mods.
Code:
Sim actor=new Sim();
actor.RequestWalkStyle(WalkStyle.VampireRun);
//Maybe you can try
actor.RequestWalkStyle(WalkStyle.ElderCaneWalk);
or
actor.RequestWalkStyle(WalkStyle.ElderCaneRun);
If you like my mods. Consider supporting me on Patreon
Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
@Battery and @PuddingFace
I don't know if trying that is the good way to maje the mod work. If I make a "Frankenstein" of code, I will not manage to have the cane code to function exactly as the original cane. Any chance that this is happening because I'm using the unprotected dlls?
EDIT: Also, why do I get errors when trying to simply put the code of the cane in Visual Studio?
Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts 9 Achievements
Unprotected DLLs make some things that are private public but also some other things that were public before became private. If you were trying to use something that was privated in the unprotected DLLs then you will get errors.
If you like my mods. Consider supporting me on Patreon
Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
I'm not getting errors with my code, to be exact. That thing about getting errors is when I try to simply plop down the complete code of the cane in VS and make the necessary edits.
Join Date: Dec 2013
Posts: 3,095
Thanks: 3444 in 22 Posts 24 Achievements
Quote:
Originally Posted by CyrusBanefort
I'm not getting errors with my code, to be exact. That thing about getting errors is when I try to simply plop down the complete code of the cane in VS and make the necessary edits.
So it's the game that returns the errors? Would you be able to share an image of that if that's the game? Â*That way it's easier to figure out if maybe it's just a null reference or whatever
Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
Quote:
Originally Posted by Lyralei
So it's the game that returns the errors? Would you be able to share an image of that if that's the game? Â*That way it's easier to figure out if maybe it's just a null reference or whatever
@Lyralei ,
No, not the game. The errors come from Visual Studio - I just find it strange because it is the exactly same code as the original one. Again, it's not the code I posted earlier that gives me errors, but the original cane code.
EDIT: Here are the errors that SharpDevelop gives me when I try to throw the cane code into it, not Visual Studio, as Battery requested. (It's in portuguese, as I don't know how to change the language of the errors window of SD, but I think a quick trip to Google Translate can solve things)
Last edited by CyrusBanefort : 30th Oct 2020 at 9:40 PM.
Join Date: Dec 2008
Posts: 385
Thanks: 827 in 5 Posts 8 Achievements
^^ Well i did not request it in SD but it seems youre missing some "end of Instruction" ;
also it looks your scope seems a bit of did you make sure you set your { and } right ?
As for the "frankensteined code" while you disagree there i am still of the opinion that testing each step one by one might be your best chance instead of trying to fix the whole code at once.
if you get a lot of errors could you upload the Solution aswell this (at least for me) makes it easier to fix pure coding errors and reupload it
Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts 4 Achievements
@Battery ,
I can try to do what you recommended. Let's see what comes from it.
Anyways, the code that is in that print is just the one from the cane. The original one, from the game dlls. I tried to used Jetbrains Rider as an alternate IDE to VS, to see if that was the problem, and got the following errors: