private static ObjectItem MakeKegMeadItem(PreObjectDropInActionEvent @event) { var temp = (ObjectAccessor)Activator.CreateInstance(@event.ArgDroppedObject.Underlying.GetType(), new object[] { Vector2.Zero, 793, "Mead", false, true, false, false }); return(new ObjectItem(@event.ArgDroppedObject.Parent, temp)); //return @event.Proxy<ObjectAccessor, ObjectItem>(new ObjectDelegate(Vector2.Zero, 793, "Mead", false, true, false, false)); }
///////////////////////////////////////////////////////////////////////////////////////////// /// Helper functions ///////////////////////////////////////////////////////////////////////////////////////////// private static ObjectItem MakeKegVodkaItem(PreObjectDropInActionEvent @event) { //NOTE: It should be possible to use the ObjectDelegate that's commented out below (and indeed, it appears to work!), but // the XmlSerializer gets hung up on serializing a proxy object. So, we take the original StardewValley type and clone it. // This is kind of annoying, but much, MUCH easier than writing a hook into the XmlSerializer (I tried!) var temp = (ObjectAccessor)Activator.CreateInstance(@event.ArgDroppedObject.Underlying.GetType(), new object[] { Vector2.Zero, 792, "Vodka", false, true, false, false }); return(new ObjectItem(@event.ArgDroppedObject.Parent, temp)); //return @event.Proxy<ObjectAccessor, ObjectItem>(new ObjectDelegate(Vector2.Zero, 792, "Vodka", false, true, false, false)); }
public static DetourEvent PreObjectDropInActionCallback(ObjectAccessor accessor, ObjectAccessor dropAccessor, bool probe, FarmerAccessor who) { var @event = new PreObjectDropInActionEvent( new ObjectItem(WrappedGame, accessor), dropAccessor == null ? null : new ObjectItem(WrappedGame, dropAccessor), probe, who == null ? null : new Farmer(WrappedGame, who)); FireEvent(@event); return(@event); }
public void UpdateCallback(PreObjectDropInActionEvent @event) { //As always, do nothing if we're disabled. if (!ModConfig.EnablePlugin) { return; } //If "this" (the object being dropped on) already has an object it is cooking, don't do anything. if (@event.This.HeldObject != null) { return; } //If "this" is a "Keg" if (@event.This.Name.Equals("Keg")) { //..and we are dropping a "Potato". if (@event.ArgDroppedObject.Name.Equals("Potato")) { //Tell the keg that we are now holding a "Vodka". @event.This.HeldObject = MakeKegVodkaItem(@event); //The "Probe" parameter tells us if the caller is just asking what's inside (not setting it). //When this is false, we need to start our cooking timer. if ([email protected]) { //We reset the name here (just because that's what StardewValley does; I'm not convinced it's needed). @event.This.HeldObject.Name = "Vodka"; //Audio not implemented yet. //Game1.playSound("Ship"); //Game1.playSound("bubbles"); //Set how long until this object is fully cooked. The smallest you can (reasonably) set this to is "10", since it updates // on 10-minute intervals (like most things in the game). @event.This.MinutesUntilReady = 20000; //"Drop-In" animation not implemented yet. /* * @event.ArgWho.CurrentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(@event.Root.Animations, new Rectangle(256, 1856, 64, 128), 80f, 6, 999999, this.tileLocation * (float)Game1.tileSize + new Vector2(0f, (float)(-(float)Game1.tileSize * 2)), false, false, (this.tileLocation.Y + 1f) * (float)Game1.tileSize / 10000f + 0.0001f, 0f, Color.Yellow * 0.75f, 1f, 0f, 0f, 0f, false) * { * alphaFade = 0.005f * }); */ } //Returning "true" will cause the caller to decrease the Item we dropped in by 1. @event.ReturnValue = true; @event.ReturnEarly = true; return; } //...and we're dropping in a "Honey" if (@event.ArgDroppedObject.Name.Equals("Honey")) { //Tell the keg that we are now holding a "Mead". @event.This.HeldObject = MakeKegMeadItem(@event); //The "Probe" parameter tells us if the caller is just asking what's inside (not setting it). //When this is false, we need to start our cooking timer. if ([email protected]) { //We reset the name here (just because that's what StardewValley does; I'm not convinced it's needed). @event.This.HeldObject.Name = "Mead"; //Audio not implemented yet. //Game1.playSound("Ship"); //Game1.playSound("bubbles"); //Set how long until this object is fully cooked. The smallest you can (reasonably) set this to is "10", since it updates // on 10-minute intervals (like most things in the game). @event.This.MinutesUntilReady = 1900; //"Drop-In" animation not implemented yet. /* * @event.ArgWho.CurrentLocation.TemporarySprites.Add(new TemporaryAnimatedSprite(@event.Root.Animations, new Rectangle(256, 1856, 64, 128), 80f, 6, 999999, this.tileLocation * (float)Game1.tileSize + new Vector2(0f, (float)(-(float)Game1.tileSize * 2)), false, false, (this.tileLocation.Y + 1f) * (float)Game1.tileSize / 10000f + 0.0001f, 0f, Color.Yellow * 0.75f, 1f, 0f, 0f, 0f, false) * { * alphaFade = 0.005f * }); */ } //Returning "true" will cause the caller to decrease the Item we dropped in by 1. @event.ReturnValue = true; @event.ReturnEarly = true; return; } } }