Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Lab Assistant
Original Poster
#1 Old 25th Jan 2021 at 2:56 PM
Default Problems with trying to reproduce the Haunt Interaction
I am getting errors in this specific line of code:

Code:
Sims3.Gameplay.Actors.Sim.ExorciseObject.Definition definition = new Sims3.Gameplay.Actors.Sim.ExorciseObject.Definition(this);


While I think I've reproduced it exactly as IlSpy decompiled, I get errors CS1503 and CS1502. How to fix that?
Advertisement
Space Pony
#2 Old 25th Jan 2021 at 3:33 PM
What is "this" referring to? Where in your code is this being done?

"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

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Lab Assistant
Original Poster
#3 Old 25th Jan 2021 at 4:26 PM
The code of the interaction. Here's the complete code, for the context:

Code:
public class Haunt : Interaction<Sim, Sim>, IHauntInteraction
{
	public class Definition : SoloSimInteractionDefinition<Haunt>
	{
		public override bool Test(Sim a, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
		{
			if (target is IRockingRider && !a.SimDescription.ChildOrBelow)
			{
				return false;
			}
			if (a.SimDescription.IsGhost && !a.Autonomy.Motives.HasMotive(CommodityKind.BeAngryGhost))
			{
				if (!a.CanHauntObjects)
				{
					greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(Sims3.Gameplay.Actors.Sim.LocalizeString("RecentlyExorcised"));
					return false;
				}
				return true;
			}
			return false;
		}
	}

	[TunableComment("Description:  Number of sim minutes a ghost sim will be unable to haunt after being exorcised")]
	[Tunable]
	public static float kExorcisedHauntTimeout = 60f;

	public static ISoloInteractionDefinition Singleton = new Definition();

	public GameObject mObject;

	public ObjectSound hauntLoop;

	public Sim mExorcisingSim;

	public GameObject ObjectBeingHaunted
	{
		get
		{
			return mObject;
		}
	}

	public override bool Run()
	{
		if (Actor.IsHorse)
		{
			mObject = GetHorseHauntableObjects();
		}
		if (mObject == null)
		{
			mObject = GetObjectForHaunting(Actor.LotCurrent);
		}
		if (mObject == null || !Actor.RouteToObjectRadiusAndCheckInUse(mObject, 1f))
		{
			return false;
		}
		Sims3.Gameplay.Actors.Sim.ExorciseObject.Definition definition = new Sims3.Gameplay.Actors.Sim.ExorciseObject.Definition(this);
		mObject.AddInteraction(definition);
		mObject.AddToUseList(Actor);
		StateMachineClient stateMachineClient = StateMachineClient.Acquire(Actor, "Haunt");
		stateMachineClient.SetActor("x", Actor);
		stateMachineClient.SetActor("object", mObject);
		if (mObject is IRockingChair)
		{
			stateMachineClient.SetParameter("ObjectType", HauntedObjectType.RockingChair);
		}
		else if (mObject is IRockingRider)
		{
			stateMachineClient.SetParameter("ObjectType", HauntedObjectType.RockingRider);
		}
		else if (mObject is IBedSingle || mObject is IAltar)
		{
			stateMachineClient.SetParameter("ObjectType", HauntedObjectType.SingleBed);
		}
		else
		{
			stateMachineClient.SetParameter("ObjectType", HauntedObjectType.Generic);
		}
		stateMachineClient.AddOneShotScriptEventHandler(1001u, EventCallbackStartSound);
		stateMachineClient.AddOneShotScriptEventHandler(1002u, EventCallbackStopSound);
		stateMachineClient.EnterState("x", "Enter");
		stateMachineClient.RequestState("x", "HauntLoop");
		BeginCommodityUpdates();
		PetStartleBehavior.CheckForStartle(Actor, StartleType.GhostHaunting);
		bool flag = DoTimedLoop(RandomUtil.GetFloat(3f, 10f), ExitReason.Default, 30);
		stateMachineClient.RequestState("x", "Exit");
		if (flag)
		{
			switch (Actor.SimDescription.DeathStyle)
			{
			case SimDescription.DeathType.Burn:
				mObject.Charred = true;
				break;
			case SimDescription.DeathType.Drown:
			{
				RepairableComponent repairable2 = mObject.Repairable;
				if (repairable2 != null && repairable2.ObjectRepairableType == RepairableComponent.RepairableType.Plumbing)
				{
					repairable2.BreakObject();
				}
				else
				{
					Sims3.Gameplay.Controllers.PuddleManager.AddPuddle(mObject.Position);
				}
				break;
			}
			case SimDescription.DeathType.Electrocution:
			{
				RepairableComponent repairable = mObject.Repairable;
				if (repairable != null && repairable.ObjectRepairableType == RepairableComponent.RepairableType.Electrical)
				{
					repairable.BreakObject();
				}
				break;
			}
			}
		}
		if (Actor.HasExitReason(ExitReason.CanceledByScript))
		{
			if (mExorcisingSim != null)
			{
				Actor.PlayReaction(ReactionTypes.Startled, ReactionSpeed.AfterInteraction);
				ThoughtBalloonManager.BalloonData balloonData = new ThoughtBalloonManager.BalloonData(mExorcisingSim.GetThumbnailKey());
				balloonData.LowAxis = ThoughtBalloonAxis.kDislike;
				Actor.ThoughtBalloonManager.ShowBalloon(balloonData);
				Actor.ResetHauntTimeout(kExorcisedHauntTimeout);
			}
		}
		else if (mExorcisingSim != null && mExorcisingSim.InteractionQueue.HasInteractionOfTypeAndTarget(definition, mObject))
		{
			mExorcisingSim.AddExitReason(ExitReason.CanceledByScript);
		}
		mObject.RemoveFromUseList(Actor);
		mObject.RemoveInteractionByType(definition);
		EndCommodityUpdates(true);
		return true;
	}

	public void EventCallbackStartSound(StateMachineClient sender, IEvent evt)
	{
		hauntLoop = new ObjectSound(mObject.ObjectId, "ghost_haunt_obj_float_obj");
		hauntLoop.StartLoop();
	}

	public void EventCallbackStopSound(StateMachineClient sender, IEvent evt)
	{
		hauntLoop.Dispose();
		hauntLoop = null;
	}

	public bool ObjectTest(GameObject obj)
	{
		if (obj is INotHauntable)
		{
			IMaybeHauntable maybeHauntable = obj as IMaybeHauntable;
			if (maybeHauntable != null)
			{
				return maybeHauntable.CanHaunt();
			}
			return false;
		}
		return true;
	}

	public bool OutsideObjectTest(GameObject obj)
	{
		if (obj.IsOutside)
		{
			return ObjectTest(obj);
		}
		return false;
	}

	public GameObject GetHorseHauntableObjects()
	{
		IHorseHauntableObject[] objects = Actor.LotCurrent.GetObjects<IHorseHauntableObject>();
		if (objects.Length > 0)
		{
			return RandomUtil.GetRandomObjectFromList(objects) as GameObject;
		}
		GameObject[] objects2 = Actor.LotCurrent.GetObjects<GameObject>();
		return GameObject.GetObjectForCommonInteraction(objects2, OutsideObjectTest);
	}

	public GameObject GetObjectForHaunting(Lot lot)
	{
		GameObject[] objects = lot.GetObjects<GameObject>();
		GameObject[] array = objects;
		foreach (GameObject gameObject in array)
		{
			IHauntedGnome hauntedGnome = gameObject as IHauntedGnome;
			if (hauntedGnome != null && RandomUtil.RandomChance(hauntedGnome.GnomeHauntingChance) && hauntedGnome.CanHaunt())
			{
				return gameObject;
			}
		}
		return GameObject.GetObjectForCommonInteraction(objects, ObjectTest);
	}

	public void ObjectExorcised()
	{
		Actor.AddExitReason(ExitReason.CanceledByScript);
	}

	public bool CanExorcise()
	{
		return mExorcisingSim == null;
	}

	public bool StartExorcise(Sim sim)
	{
		if (!CanExorcise())
		{
			return false;
		}
		mExorcisingSim = sim;
		return true;
	}

	public override void Cleanup()
	{
		mExorcisingSim = null;
		base.Cleanup();
	}
}
Space Pony
#4 Old 25th Jan 2021 at 4:36 PM
Ok, I see. You'll need to make your custom Haunt interaction inherit directly from Sim.Haunt, so change the first line to:

Code:
public class Haunt : Sim.Haunt


Then the constructor argument will be of the correct type.

"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

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Back to top