Esempio n. 1
0
    private void loadVillagerData(Villager2 v, VillagerHouse2 vh, bool raw = false)
    {
        try
        {
            Villager2      newV  = v;
            VillagerHouse2 newVH = vh;
            VillagerHouse2 loadedVillagerHouse = GetCurrentLoadedVillagerHouse(); // non indexed so search for the correct one
            int            index = loadedVillagerHouses.IndexOf(loadedVillagerHouse);
            if (!raw && index != -1)
            {
                newV.SetMemories(loadedVillager.GetMemories());
                newV.SetEventFlagsSave(loadedVillager.GetEventFlagsSave());
                newV.CatchPhrase = GameInfo.Strings.GetVillagerDefaultPhrase(newV.InternalName);
            }

            if (index == -1)
            {
                //inject to earliest available house
                foreach (var house in loadedVillagerHouses)
                {
                    if (house.NPC1 == -1)
                    {
                        loadedVillagerHouse = house;
                        index      = loadedVillagerHouses.IndexOf(loadedVillagerHouse);
                        house.NPC1 = (sbyte)currentlyLoadedVillagerIndex;
                        break;
                    }
                }

                if (index == -1)
                {
                    throw new Exception("Selected villager has no house, and no houses are available.");
                }
            }

            // check if they are moving in
            if (loadedVillagerHouse.WallUniqueID == WallType.HouseWallNForSale || loadedVillagerHouse.WallUniqueID == WallType.HouseWallNSoldOut)
            {
                loadedVillagerHouse.WallUniqueID = newVH.WallUniqueID;
            }
            if (checkIfMovingIn(loadedVillagerHouse))
            {
                newVH = combineHouseOrders(newVH, loadedVillagerHouse);
            }
            newVH.NPC1 = loadedVillagerHouse.NPC1;

            loadedVillagerHouses[index] = newVH;
            loadedVillager = newV;
            loadedVillagerShellsList[currentlyLoadedVillagerIndex] = newV;

            TenVillagers[currentlyLoadedVillagerIndex].texture = SpriteBehaviour.PullTextureFromParser(villagerSprites, newV.InternalName);
            setCurrentVillager(); // where the magic happens
            VillagerToUI(loadedVillager);
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
            PopupHelper.CreateError(e.Message, 2f);
        }
    }
Esempio n. 2
0
    private VillagerHouse2 combineHouseOrders(VillagerHouse2 vNew, VillagerHouse2 vOld)
    {
        VillagerHouse2 vTmp = new VillagerHouse2(vOld.Data);

        vTmp.OrderWallUniqueID = vNew.OrderWallUniqueID;
        vTmp.OrderRoofUniqueID = vNew.OrderRoofUniqueID;
        vTmp.OrderDoorUniqueID = vNew.OrderDoorUniqueID;
        return(vTmp);
    }
Esempio n. 3
0
    public void WriteVillagerDataVillager(Villager2 v)
    {
        checkReloadVillager();
        VillagerHouse2 loadedVillagerHouse = loadedVillagerHouses.Find(x => x.NPC1 == (sbyte)currentlyLoadedVillagerIndex); // non indexed so search for the correct one
        int            index = loadedVillagerHouses.IndexOf(loadedVillagerHouse);

        if (index == -1)
        {
            throw new Exception("The villager having their house replaced doesn't have a house on your island."); // not sure why but it can get unloaded during the check
        }
        loadVillagerData(v, loadedVillagerHouse, true);
    }
Esempio n. 4
0
    // villager data

    public void WriteVillagerDataHouse(VillagerHouse2 vh)
    {
        checkReloadVillager();
        loadVillagerData(loadedVillager, vh, true);
    }
Esempio n. 5
0
 private bool checkIfMovingIn(VillagerHouse2 vOld) => vOld.WallUniqueID == WallType.HouseWallNSoldOut;