コード例 #1
0
    private void loadVillagerData(Villager2 v, VillagerHouse vh, bool raw = false)
    {
        try
        {
            Villager2     newV  = v;
            VillagerHouse newVH = vh;
            VillagerHouse 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);
        }
    }
コード例 #2
0
 private void checkReloadVillager()
 {
     if (ReloadVillagerToggle.isOn)
     {
         Villager2 v = loadVillagerExternal(currentlyLoadedVillagerIndex, true);
         if (v != null)
         {
             loadedVillager.SetMemories(v.GetMemories());
             loadedVillager.SetEventFlagsSave(v.GetEventFlagsSave());
             loadedVillager.MovingOut = v.MovingOut;
         }
     }
 }
コード例 #3
0
    private void loadVillagerData(Villager2 v, VillagerHouse vh, bool raw = false)
    {
        try
        {
            Villager2     newV  = v;
            VillagerHouse newVH = vh;
            if (!raw)
            {
                newV.SetMemories(loadedVillager.GetMemories());
                newV.SetEventFlagsSave(loadedVillager.GetEventFlagsSave());
                newV.CatchPhrase = GameInfo.Strings.GetVillagerDefaultPhrase(newV.InternalName);
            }

            VillagerHouse loadedVillagerHouse = GetCurrentLoadedVillagerHouse(); // non indexed so search for the correct one
            int           index = loadedVillagerHouses.IndexOf(loadedVillagerHouse);
            if (index == -1)
            {
                throw new Exception("The villager being replaced doesn't have a house on your island.");
            }

            // check if they are moving in
            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);
        }
    }