Beispiel #1
0
        public bool SetStateOf <T> (object stateData) where T : WIScript
        {
            if (SaveState == null || SaveState.Scripts == null)
            {
                return(false);
            }

            string scriptName        = typeof(T).Name;
            string scriptStateName   = scriptName + "State";          //<-this shit is going to get people in trouble, haha
            string scriptStateString = string.Empty;

            //make sure the type matches the state type
            if (stateData.GetType().Name != scriptStateName)
            {
                return(false);
            }
            if (!SaveState.Scripts.ContainsKey(scriptName))
            {
                return(false);
            }

            if (SaveState.Scripts.ContainsKey(scriptName))
            {
                scriptStateString = WIScript.XmlSerializeToString(stateData);
                SaveState.Scripts [scriptName] = scriptStateString;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public bool GetStateOf <T> (out object stateData) where T : WIScript
        {
            stateData = null;
            if (SaveState == null || SaveState.Scripts == null)
            {
                return(false);
            }

            string scriptName        = typeof(T).Name;
            string scriptStateName   = typeof(T).FullName + "State";          //<-this shit is going to get people in trouble, haha
            string scriptStateString = string.Empty;

            if (SaveState.Scripts.TryGetValue(scriptName, out scriptStateString))
            {
                stateData = WIScript.XmlDeserializeFromString(scriptStateString, scriptStateName);
                if (stateData != null)
                {
                    return(true);
                }
                else
                {
                    Debug.Log("Couldn't deserialize state data for " + scriptStateName);
                }
            }
            else
            {
                Debug.Log("Couldn't get state data for " + scriptName + " in " + FileName);
            }
            return(false);
        }
Beispiel #3
0
        protected int CalculateLocalBaseCurrencyValue()
        {
            int baseCurrencyValue = Mathf.CeilToInt(GlobalProps.BaseCurrencyValue);

            if (SaveState != null && SaveState.Scripts != null)
            {
                var enumerator = this.SaveState.Scripts.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    //Debug.Log("Checking script " + enumerator.Current.Key);
                    Type scriptType = System.Type.GetType("Frontiers.World.WIScripts." + enumerator.Current.Key);
                    if (scriptType == null)
                    {
                        //Debug.Log("Couldn't get script type for name " + enumerator.Current.Key);
                    }
                    else
                    {
                        var calculateLocalPriceMethod = scriptType.GetMethod("CalculateLocalPrice", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
                        if (calculateLocalPriceMethod != null)
                        {
                            //Debug.Log("Got calcualate price method from " + enumerator.Current.Key);
                            object stateData         = null;
                            string scriptStateName   = scriptType.FullName + "State";                          //<-this shit is going to get people in trouble, haha
                            string scriptStateString = string.Empty;
                            stateData         = WIScript.XmlDeserializeFromString(enumerator.Current.Value, scriptStateName);
                            baseCurrencyValue = (int)calculateLocalPriceMethod.Invoke(null, new object [] {
                                baseCurrencyValue,
                                this
                            });
                        }
                    }
                }
            }
            else
            {
                Debug.Log("Didn't have states");
            }
            if (Props.Local.CraftedByPlayer)
            {
                baseCurrencyValue = Mathf.CeilToInt(baseCurrencyValue * Globals.BaseValueCraftingBonus);
            }
            //apply wealth level
            baseCurrencyValue = Mathf.Max(baseCurrencyValue, Mathf.CeilToInt(baseCurrencyValue * FlagSet.GetAverageValue(GlobalProps.Flags.Wealth) * 0.25f));
            return(baseCurrencyValue);
        }
Beispiel #4
0
        public bool SetStateData <T> (T stateData) where T : class, new()
        {
            if (SaveState == null || SaveState.Scripts == null)
            {
                return(false);
            }

            string stateStateName    = stateData.GetType().Name;
            string scriptName        = stateStateName.Substring(0, stateStateName.Length - 5);      //this removes "State"
            string scriptStateString = string.Empty;

            if (!SaveState.Scripts.ContainsKey(scriptName))
            {
                return(false);
            }
            else
            {
                scriptStateString = WIScript.XmlSerializeToString(stateData);
                SaveState.Scripts [scriptName] = scriptStateString;
            }
            return(true);
        }
Beispiel #5
0
        public bool GetStateData <T> (out T stateData) where T : class, new()
        {
            stateData = null;
            if (SaveState == null || SaveState.Scripts == null)
            {
                return(false);
            }

            string stateName         = typeof(T).Name;
            string scriptName        = ReplaceLastOccurrence(stateName, "State", "");
            string scriptStateString = string.Empty;

            //okay, here we're removing State from the state name type to get the script name
            //this is probably going to get people in shit tons of trouble but whatever
            if (SaveState.Scripts.TryGetValue(scriptName, out scriptStateString))                       //alright we've got the data, now it's time to pray we can deserialize it
            {
                stateData = WIScript.XmlDeserializeFromString <T> (scriptStateString);
                //TODO wrap this in try/catch?
                return(true);
            }
            return(false);
        }