예제 #1
0
        private void addPinToRoom(PinData pin)
        {
            string roomName = (pin.PinScene != null) ? pin.PinScene : PinData_S.All[pin.ID].SceneName;

            GameObject newPin = new GameObject("pin_rando");

            newPin.transform.parent      = this.custPinGroup.transform;
            newPin.layer                 = 30;
            newPin.transform.localScale *= 1.2f;

            SpriteRenderer sr = newPin.AddComponent <SpriteRenderer>();

            if (pin.isShop)
            {
                sr.sprite = Resources.Sprite("Map.shopPin");
            }
            else
            {
                sr.sprite = Resources.Sprite("Map.randoPin");
            }
            sr.sortingLayerName = "HUD";
            sr.size             = new Vector2(1f, 1f);

            Pin pinC = newPin.AddComponent <Pin>();

            pinC.PinData = pin;

            Vector3 vec = this.getRoomPos(roomName) + pin.Offset;

            newPin.transform.localPosition = new Vector3(vec.x, vec.y, (vec.z - 0.5f));
        }
        /// <summary>
        /// Parses our `pindata.xml` file.
        /// </summary>
        private static Dictionary <string, PinData> loadPinData(Stream stream)
        {
            Dictionary <string, PinData> retVal = new Dictionary <string, PinData>();

            XmlDocument xml = new XmlDocument();

            xml.Load(stream);
            foreach (XmlNode node in xml.SelectNodes("randomap/pin"))
            {
                PinData newPin = new PinData();
                newPin.ID = node.Attributes["name"].Value;
                foreach (XmlNode chld in node.ChildNodes)
                {
                    if (chld.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    switch (chld.Name)
                    {
                    case "pinScene":
                        newPin.PinScene = chld.InnerText;
                        break;

                    case "checkBool":
                        newPin.CheckBool = chld.InnerText;
                        break;

                    case "offsetX":
                        newPin.OffsetX = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "offsetY":
                        newPin.OffsetY = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "offsetZ":
                        newPin.OffsetZ = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "hasPrereq":
                        newPin.hasPrereq = XmlConvert.ToBoolean(chld.InnerText);
                        break;

                    case "isShop":
                        newPin.isShop = XmlConvert.ToBoolean(chld.InnerText);
                        break;

                    default:
                        logger.Error($"Pin '{newPin.ID}' in XML had node '{chld.Name}' not parsable!");
                        break;
                    }
                }
                retVal.Add(newPin.ID, newPin);
            }
            return(retVal);
        }
        public static string Get(PinData pinD)
        {
            if (dict == null)
            {
                Load(GameManager.instance.profileID);
            }

            string newName = "";

            if (dict.TryGetValue(pinD.ID, out newName))
            {
                return(newName);
            }
            else
            {
                return(pinD.OriginalName);
            }
        }
        private static void loadPinData(Stream stream)
        {
            pPinData = new Dictionary <string, PinData>();

            XmlDocument xml = new XmlDocument();

            xml.Load(stream);
            foreach (XmlNode node in xml.SelectNodes("randomap/pin"))
            {
                PinData newPin = new PinData();
                newPin.ID = node.Attributes["name"].Value;
                //Dev.Log("Load Pin Data: " + newPin.ID);
                string line = "";

                foreach (XmlNode chld in node.ChildNodes)
                {
                    switch (chld.Name)
                    {
                    case "pinScene":
                        line           += ", pinScene = " + chld.InnerText;
                        newPin.PinScene = chld.InnerText;
                        break;

                    case "checkType":
                        line            += ", checkType = " + chld.InnerText;
                        newPin.CheckType = selectCheckType(chld.InnerText);
                        break;

                    case "checkBool":
                        line            += ", checkBool = " + chld.InnerText;
                        newPin.CheckBool = chld.InnerText;
                        break;

                    case "prereq":
                        line            += ", prereq = " + chld.InnerText;
                        newPin.PrereqRaw = chld.InnerText;
                        break;

                    case "offsetX":
                        line          += ", offsetX = " + chld.InnerText;
                        newPin.OffsetX = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "offsetY":
                        line          += ", offsetY = " + chld.InnerText;
                        newPin.OffsetY = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "offsetZ":
                        line          += ", offsetZ = " + chld.InnerText;
                        newPin.OffsetZ = XmlConvert.ToSingle(chld.InnerText);
                        break;

                    case "hasPrereq":
                        line            += ", hasPrereq = " + chld.InnerText;
                        newPin.hasPrereq = XmlConvert.ToBoolean(chld.InnerText);
                        break;

                    case "isShop":
                        line         += ", isShop = " + chld.InnerText;
                        newPin.isShop = XmlConvert.ToBoolean(chld.InnerText);
                        break;

                    default:
                        DebugLog.Error("Pin '" + newPin.ID + "' in XML had node '" + chld.Name + "' not parsable!");
                        break;
                    }
                }

                pPinData.Add(newPin.ID, newPin);
                //Dev.Log(newPin.ID + " Pin added: " + pPinData.ContainsKey(newPin.ID));
            }
        }
        private static void loadItemData(XmlNodeList nodes)
        {
            foreach (XmlNode node in nodes)
            {
                string itemName = node.Attributes["name"].Value;
                if (!pPinData.ContainsKey(itemName))
                {
                    DebugLog.Error("Could not find item '" + itemName + "' in PinData Dict!");
                    continue;
                }

                PinData pinD = pPinData[itemName];
                foreach (XmlNode chld in node.ChildNodes)
                {
                    if (chld.Name == "sceneName")
                    {
                        pinD.SceneName = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "objectName")
                    {
                        pinD.OriginalName = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "itemLogic")
                    {
                        pinD.LogicRaw = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "boolName")
                    {
                        pinD.ObtainedBool = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "inChest")
                    {
                        pinD.InChest = true;
                        continue;
                    }

                    if (chld.Name == "newShiny")
                    {
                        pinD.NewShiny = true;
                        continue;
                    }

                    if (chld.Name == "x")
                    {
                        pinD.NewX = (int)XmlConvert.ToDouble(chld.InnerText);
                        continue;
                    }

                    if (chld.Name == "y")
                    {
                        pinD.NewY = (int)XmlConvert.ToDouble(chld.InnerText);
                        continue;
                    }

                    if (chld.Name == "pool")
                    {
                        pinD.Pool = chld.InnerText;
                        continue;
                    }
                }
            }
        }
        public static void Load(int saveSlot)
        {
            /*
             * GOOD LORD WHY REMOVE THE STRINGVALUES
             * foreach ( string val in RandomizerMod.RandomizerMod.Instance.Settings.StringValues.Values ) {
             *      if ( val.Contains( "newShinyName" ) ) {
             *              ObjectName newONC = JsonUtility.FromJson<ObjectName>( val );
             *              Add( newONC );
             *      }
             */
            dict = new Dictionary <string, string>();

            Platform.Current.ReadSaveSlot(saveSlot, (Action <byte[]>)(fileBytes =>
            {
                try {
                    SaveGameData data = JsonUtility.FromJson <SaveGameData>(!GameManager.instance.gameConfig.useSaveEncryption || Platform.Current.IsFileSystemProtected ? Encoding.UTF8.GetString(fileBytes) : Encryption.Decrypt((string)new BinaryFormatter().Deserialize((Stream) new MemoryStream(fileBytes))));
                    foreach (string key in data.modData["RandomizerMod"].StringValues.Keys)
                    {
                        JSONAction.Type type = JSONAction.Type.NONE;
                        type = getActionType(key);
                        if (type == JSONAction.Type.NONE)
                        {
                            continue;
                        }

                        string val            = data.modData["RandomizerMod"].StringValues[key];
                        JSONAction actionData = JsonUtility.FromJson <JSONAction>(val);
                        PinData pinD          = null;
                        string newName        = "";
                        switch (type)
                        {
                        case JSONAction.Type.AddShinyToChest:
                        case JSONAction.Type.ReplaceObjectWithShiny:
                            pinD = PinData_S.All.Values.Where(
                                pins => pins.SceneName == actionData.sceneName &&
                                pins.OriginalName == actionData.objectName
                                ).FirstOrDefault();
                            newName = actionData.newShinyName;
                            break;

                        case JSONAction.Type.CreateNewShiny:
                            pinD = PinData_S.All.Values.Where(
                                pins => pins.SceneName == actionData.sceneName &&
                                pins.NewX == (int)actionData.x &&
                                pins.NewY == (int)actionData.y &&
                                pins.NewShiny == true
                                ).FirstOrDefault();
                            newName = actionData.newShinyName;
                            break;

                        case JSONAction.Type.ChangeChestGeo:
                            pinD = PinData_S.All.Values.Where(
                                pins => pins.SceneName == actionData.sceneName &&
                                pins.InChest == true
                                ).FirstOrDefault();
                            newName = actionData.objectName;
                            break;

                        case JSONAction.Type.NONE:
                        default:
                            DebugLog.Error("What the crap just happened...? This enum is weeeeird.");
                            break;
                        }
                        if (pinD != null && newName != "")
                        {
                            //DebugLog.Write( "ONC Added: Item '" + pinD.ID + "' ObjectName '" + newName + "' Type '" + type + "'" );
                            Add(pinD.ID, newName);
                        }
                    }
                } catch (Exception ex) {
                    DebugLog.Error("Error trying to MANUALLY FREAKING LOAD the save data");
                    DebugLog.Error(ex.ToString());
                }
            }));
        }
        /// <summary>
        /// Loads items from RandomizerMod's item list, and merges it with our own pindata.xml
        /// </summary>
        /// <param name="nodes">The item nodes from Randomizer Mod's items.xml file</param>
        private void loadItemData(XmlNodeList nodes)
        {
            foreach (XmlNode node in nodes)
            {
                string itemName = node.Attributes["name"].Value;
                if (!pPinData.ContainsKey(itemName))
                {
                    //logger.Log($"RandomizerMod has an item.xml entry for {itemName} but there is no matching entry in RandoMapMod's pindata.xml. This is probably intentional to avoid pins that would otherwise mislead the player.");
                    continue;
                }

                PinData pinD = pPinData[itemName];
                foreach (XmlNode chld in node.ChildNodes)
                {
                    if (chld.Name == "sceneName")
                    {
                        pinD.SceneName = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "objectName")
                    {
                        pinD.OriginalName = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "itemLogic")
                    {
                        pinD.LogicRaw = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "boolName")
                    {
                        pinD.ObtainedBool = chld.InnerText;
                        continue;
                    }

                    if (chld.Name == "inChest")
                    {
                        pinD.InChest = true;
                        continue;
                    }

                    if (chld.Name == "newShiny")
                    {
                        pinD.NewShiny = true;
                        continue;
                    }

                    if (chld.Name == "x")
                    {
                        pinD.NewX = (int)XmlConvert.ToDouble(chld.InnerText);
                        continue;
                    }

                    if (chld.Name == "y")
                    {
                        pinD.NewY = (int)XmlConvert.ToDouble(chld.InnerText);
                        continue;
                    }

                    if (chld.Name == "pool")
                    {
                        pinD.Pool = chld.InnerText;
                        continue;
                    }
                }
            }
        }
        public void AddPinToRoom(PinData pinData, GameMap gameMap)
        {
            if (_pins.Any(pin => pin.PinData.ID == pinData.ID))
            {
                //Already in the list... Probably shouldn't add them.
                DebugLog.Warn($"Duplicate pin found for group: {pinData.ID} - Skipped.");
                return;
            }

            string roomName  = pinData.PinScene ?? ResourceHelper.PinData[pinData.ID].SceneName;
            Sprite pinSprite = pinData.IsShop ?
                               pinSprite                         = ResourceHelper.FetchSprite(ResourceHelper.Sprites.Shop) :
                                                       pinSprite = ResourceHelper.FetchSpriteByPool(pinData.Pool);

            GameObject newPin = new GameObject("pin_rando");

            if (pinSprite.name.StartsWith("req"))
            {
                if (HelperGroup == null)
                {
                    HelperGroup = new GameObject("Resource Helpers");
                    HelperGroup.transform.SetParent(this.transform);
                    //default to off
                    HelperGroup.SetActive(false);
                }

                newPin.transform.SetParent(HelperGroup.transform);
            }
            else
            {
                if (MainGroup == null)
                {
                    MainGroup = new GameObject("Main Group");
                    MainGroup.transform.SetParent(this.transform);
                    //default to off
                    MainGroup.SetActive(false);
                }

                newPin.transform.SetParent(MainGroup.transform);
            }
            newPin.layer = 30;
            newPin.transform.localScale *= 1.2f;

            SpriteRenderer sr = newPin.AddComponent <SpriteRenderer>();

            sr.sprite           = pinSprite;
            sr.sortingLayerName = "HUD";
            sr.size             = new Vector2(1f, 1f);

            Vector3 vec = __GetRoomPos() + pinData.Offset;

            newPin.transform.localPosition = new Vector3(vec.x, vec.y, vec.z - 1f + (vec.y / 100) + (vec.x / 100));

            //Disable to avoid the Pin component's OnEnable before setting the pindata...
            //   Yay Constructorless Components...
            newPin.SetActive(false);

            Pin pinC = newPin.AddComponent <Pin>();

            pinC.SetPinData(pinData);

            //Don't worry about this one. It just does some totally normal non-spoilery things.
            newPin.AddComponent <BoringPinThing>();

            newPin.SetActive(true);

            _pins.Add(pinC);

            Vector3 __GetRoomPos()
            {
                //@@OPTIMIZE: Should be indexed or hard-coded but it runs once per game session. Small gain.
                Vector3 pos      = new Vector3(-30f, -30f, -0.5f);
                bool    exitLoop = false;

                for (int index1 = 0; index1 < gameMap.transform.childCount; ++index1)
                {
                    GameObject areaObj = gameMap.transform.GetChild(index1).gameObject;
                    for (int index2 = 0; index2 < areaObj.transform.childCount; ++index2)
                    {
                        GameObject roomObj = areaObj.transform.GetChild(index2).gameObject;
                        if (roomObj.name == roomName)
                        {
                            pos      = roomObj.transform.position;
                            exitLoop = true;
                            break;
                        }
                    }
                    if (exitLoop)
                    {
                        break;
                    }
                }

                return(pos);
            }
        }