0
\$\begingroup\$

I am trying to add a warp into the existing farm map using SMAPI. I tried the following things but both didn't work.

Setting the Warp inside the map properties:

Map farm = Game1.getLocationFromName("Farm").Map;
farm.Properties.TryGetValue("Warp", out PropertyValue initialWarps);
farm.Properties.Remove("Warp");
farm.Properties.Add("Warp", initialWarps + "64 18 TestRoom 5 5");

Setting the Warp inside a Tile:

Game1.currentLocation.setTileProperty(64, 18, "Back", "Warp", "64 18 TestRoom 5 5");

I can confirm that the first approach works when you set the Warp property directly in the map file but it doesn't seem to work if you add it afterwards.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Until someone finds out how to solve this problem using the build in warp property, i came up with my own solution. It isn't as nice but i thought i am gonna share it with you if someone has the same problem.

ModEntry.cs

using System;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewModdingAPI.Utilities;
using StardewValley;
using xTile;

namespace StardewValleyMod {

    public class ModEntry : Mod {

        private IModHelper helper;
        private WarpManager warpManager;

        public override void Entry(IModHelper helper) {
            this.helper = helper;
            warpManager = new WarpManager();

            warpManager.add(new Warp(new Vector2(60, 15), "Farm", new Vector2(5, 5), "TestRoom"));

            GameEvents.FourthUpdateTick += warpManager.update;
        }
    }
}

WarpManager.cs

using System;
using System.Collections.Generic;
using StardewModdingAPI;
using StardewValley;

namespace StardewValleyMod {

    class WarpManager {
        private List<Warp> warps;

        public WarpManager() {
            warps = new List<Warp>();
        }

        public void add(Warp warp) {
            warps.Add(warp);
        }

        public void update(object sender, EventArgs args){
            update();
        }

        public void update() {
            if(Context.IsWorldReady) {
                int x = Game1.player.getStandingX() / Game1.tileSize;
                int y = Game1.player.getStandingY() / Game1.tileSize;

                foreach(Warp warp in warps) {
                    warp.tryToWarp(x, y, Game1.currentLocation.Name);
                }
            }
        }
    }
}

Warp.cs

using System;
using Microsoft.Xna.Framework;
using StardewValley;

namespace StardewValleyMod {

    class Warp {
        private Vector2 from;
        private Vector2 to;
        String fromMap;
        String toMap;
        private int rotation;

        private bool triggerFlag;

        public Warp(Vector2 from, String fromMap, Vector2 to, String toMap, int rotation) : this(from, fromMap, to, toMap) {
            this.rotation = rotation;
        }

        public Warp(Vector2 from, String fromMap, Vector2 to, String toMap) {
            this.from = from;
            this.to = to;
            this.fromMap = fromMap;
            this.toMap = toMap;
            rotation = 2;
        }

        public bool tryToWarp(int x, int y, String mapName) {
            if(!triggerFlag) {
                if(x == from.X && y == from.Y && mapName.Equals(fromMap)) {
                    Game1.warpFarmer(toMap, (int) to.X, (int) to.Y, (int) rotation);
                    triggerFlag = true;
                    return true;
                }
            } else if(!mapName.Equals(fromMap)) {
                triggerFlag = false;
            }

            return false;
        }
    }
}
\$\endgroup\$
0
\$\begingroup\$

This is what I bhave figured out:

List<Warp> warps = new List<Warp>();
warps.Add(new Warp(5, 53, "BusStop", 34, 23, false));
warps.Add(new Warp(5, 54, "BusStop", 34, 23, false));
warps.Add(new Warp(5, 55, "BusStop", 34, 23, false));

foreach (Warp warpy in warps)
{
  location.warps.Add(warpy);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .