private void InsertDocument(DocumentDbContext dbContext, ResourceChange change)
 {
     var collection = dbContext.Database.GetCollection(change.CollectionName);
     var document   = DocumentDbDSPConverter.CreateJsonDocument(change.Resource, this.dbMetadata, change.CollectionName);
     //collection.Insert(document);
     //change.Resource.SetValue(DocumentDbMetadata.MappedObjectIdName, document.GetValue(DocumentDbMetadata.ProviderObjectIdName).ToString());
 }
        public override void SetValue(object targetResource, string propertyName, object propertyValue)
        {
            base.SetValue(targetResource, propertyName, propertyValue);

            var resource      = targetResource as DSPResource;
            var pendingChange = this.pendingChanges.SingleOrDefault(x => x.Resource == resource && x.Action == InsertDocument);

            if (pendingChange == null)
            {
                pendingChange = this.pendingChanges.SingleOrDefault(x => x.Resource == resource && x.Action == UpdateDocument);
                if (pendingChange == null)
                {
                    pendingChange = new ResourceChange(resource.ResourceType.Name, resource, UpdateDocument);
                    this.pendingChanges.Add(pendingChange);
                }
            }

            var properties = pendingChange.ModifiedProperties;

            if (properties.ContainsKey(propertyName))
            {
                properties[propertyName] = propertyValue;
            }
            else
            {
                properties.Add(propertyName, propertyValue);
            }
        }
        private void UpdateDocument(DocumentDbContext dbContext, ResourceChange change)
        {
            if (!change.ModifiedProperties.Any())
            {
                return;
            }

            var collection = dbContext.Database.GetCollection(change.CollectionName);
            //var query = Query.EQ(DocumentDbMetadata.ProviderObjectIdName, ObjectId.Parse(change.Resource.GetValue(DocumentDbMetadata.MappedObjectIdName).ToString()));
            //UpdateBuilder update = null;

            //foreach (var resourceProperty in change.ModifiedProperties)
            //{
            //    if (update == null)
            //    {
            //        if (resourceProperty.Value != null)
            //            update = Update.Set(resourceProperty.Key, JsonValue.Create(resourceProperty.Value));
            //        else
            //            update = Update.Unset(resourceProperty.Key);
            //    }
            //    else
            //    {
            //        if (resourceProperty.Value != null)
            //            update = update.Set(resourceProperty.Key, JsonValue.Create(resourceProperty.Value));
            //        else
            //            update = update.Unset(resourceProperty.Key);
            //    }
            //}

            //collection.Update(query, update);
        }
Exemple #4
0
        public bool Perform()
        {
            if (Forest.Mana < Forest.GetValue(ManaCost))
            {
                Console.WriteLine("Not enough mana! " + Name + " costs " + Forest.GetValue(ManaCost));
                return(false);
            }
            if ((ResourceChange == null || ResourceChange.CanAfford(Forest, 1)) &&
                TestRequirements())
            {
                Forest.SpendMana(Forest.GetValue(ManaCost));
                if (ResourceChange != null)
                {
                    ResourceChange.Print(Forest, 1);
                    ResourceChange.Apply(Forest, 1);
                }
                foreach (CodeInject c in Injects["perform"])
                {
                    c(Forest, this, null);
                }
                Console.WriteLine(Text);
                Unlocked = RemainUnlocked;

                return(true);
            }
            else
            {
                Console.WriteLine(FailText);
                return(false);
            }
        }
Exemple #5
0
        private void RemoveDocument(MongoContext mongoContext, ResourceChange change)
        {
            var collection = mongoContext.Database.GetCollection(change.CollectionName);
            var query      = Query.EQ(MongoMetadata.ProviderObjectIdName, ObjectId.Parse(change.Resource.GetValue(MongoMetadata.MappedObjectIdName).ToString()));

            collection.Remove(query);
        }
Exemple #6
0
    void AddToResource(ResourceChange rc)
    {
        var type   = rc.resource;
        var nAdded = rc.amount;

        Debug.Log("Added " + nAdded + " " + type);

        switch (type)
        {
        case ResourceType.Wood:
            _wood += nAdded;
            break;

        case ResourceType.Iron:
            _iron += nAdded;
            break;

        case ResourceType.Food:
            _food += nAdded;
            break;

        case ResourceType.Weapon:
            MakeNWeapons(nAdded);
            break;

        default:
            break;
        }
    }
Exemple #7
0
        public MainWindow()
        {
            Configuration.Load(false);

            // choose language
            if (!LanguageWindow.ShowSelection(Configuration.Language))
            {
                Close();
                return;
            }

            if (Configuration.Language != Localization.LanguageIndex)
            {
                Configuration.Language = Localization.LanguageIndex;
            }
            StartTroopChange.Load();
            ResourceChange.Load();
            Version.AddExternalChanges();

            // init main window
            InitializeComponent();

            // set title
            this.Title = string.Format("{0} {1}", Localization.Get("Name"), Version.PatcherVersion);

            // set search path in ui
            SetBrowsePath();

            SetLocalizedUIElements();
            DisplayLicense();
        }
Exemple #8
0
        private void InsertDocument(MongoContext mongoContext, ResourceChange change)
        {
            var collection = mongoContext.Database.GetCollection(change.CollectionName);
            var document   = MongoDSPConverter.CreateBSonDocument(change.Resource, this.mongoMetadata, change.CollectionName);

            collection.Insert(document);
            change.Resource.SetValue(MongoMetadata.MappedObjectIdName, document.GetValue(MongoMetadata.ProviderObjectIdName).ToString());
        }
Exemple #9
0
    public ResourceChange Affect()
    {
        ResourceChange rc = new ResourceChange();

        rc.resource = resource;
        rc.amount   = amount;

        return(rc);
    }
 static void Main(string[] args)
 {
     Configuration.Load();
     StartTroopChange.Load();
     ResourceChange.Load();
     Version.AddExternalChanges();
     ResolvePath();
     ResolveArgs(args);
     SilentInstall();
 }
Exemple #11
0
        public override void VisitResourceNode(ResourceNode node)
        {
            if (node.DifferenceDecoration == DifferenceDecoration.NoDifferences)
            {
                return;
            }

            Change change = new ResourceChange(
                node.Namespace,
                node.Name,
                node.DifferenceDecoration);

            if (_ignoreChangeSet.Contains(change))
            {
                return;
            }

            _changeSetBuilder.AddChange(change);
        }
Exemple #12
0
        private void UpdateDocument(MongoContext mongoContext, ResourceChange change)
        {
            if (!change.ModifiedProperties.Any())
            {
                return;
            }

            var           collection = mongoContext.Database.GetCollection(change.CollectionName);
            var           query      = Query.EQ(MongoMetadata.ProviderObjectIdName, ObjectId.Parse(change.Resource.GetValue(MongoMetadata.MappedObjectIdName).ToString()));
            UpdateBuilder update     = null;

            foreach (var resourceProperty in change.ModifiedProperties)
            {
                if (update == null)
                {
                    if (resourceProperty.Value != null)
                    {
                        update = Update.Set(resourceProperty.Key, BsonValue.Create(resourceProperty.Value));
                    }
                    else
                    {
                        update = Update.Unset(resourceProperty.Key);
                    }
                }
                else
                {
                    if (resourceProperty.Value != null)
                    {
                        update = update.Set(resourceProperty.Key, BsonValue.Create(resourceProperty.Value));
                    }
                    else
                    {
                        update = update.Unset(resourceProperty.Key);
                    }
                }
            }

            collection.Update(query, update);
        }
        public override void SetValue(object targetResource, string propertyName, object propertyValue)
        {
            base.SetValue(targetResource, propertyName, propertyValue);

            var resource = targetResource as DSPResource;
            var pendingChange = _pendingChanges.SingleOrDefault(x => x.Resource == resource && x.Action == InsertDocument);
            if (pendingChange == null)
            {
                pendingChange = _pendingChanges.SingleOrDefault(x => x.Resource == resource && x.Action == UpdateDocument);
                if (pendingChange == null)
                {
                    pendingChange = new ResourceChange(resource.ResourceType.Name, resource, UpdateDocument);
                    _pendingChanges.Add(pendingChange);
                }
            }

            var properties = pendingChange.ModifiedProperties;
            if (properties.ContainsKey(propertyName))
                properties[propertyName] = propertyValue;
            else
                properties.Add(propertyName, propertyValue);
        }
 public void merge(List <IResourceProducer> otherBuildingInput)
 {
     foreach (IResourceProducer prod in otherBuildingInput)
     {
         // Look through all the producers and measure exactly what
         // the input cost is
         ResourceChange requiredInput = prod.simulate(1);
         if (!this.req.ContainsKey(requiredInput.resourceType))
         {
             // New resource type as a pre-rec
             req[requiredInput.resourceType] = requiredInput.change;
         }
         else
         {
             // Else, the least efficent input wins
             // Note, this is comparing between efficency of buildings
             req[requiredInput.resourceType] =
                 Mathf.Max(req[requiredInput.resourceType],
                           requiredInput.change);
         }
     }
 }
Exemple #15
0
        public override void VisitResourceNode(ResourceNode node)
        {
            if (node.DifferenceDecoration == DifferenceDecoration.NoDifferences)
            {
                return;
            }

            SourceText oldSourceText = null, newSourceText = null;

            if (IncludeSourceCode)
            {
                var oldSource = node.OldText;
                if (oldSource != null)
                {
                    oldSourceText = new SourceText(oldSource, _shaUtility.ComputeHashAsString(oldSource));
                }

                var newSource = node.NewText;
                if (newSource != null)
                {
                    newSourceText = new SourceText(newSource, _shaUtility.ComputeHashAsString(newSource));
                }
            }

            Change change = new ResourceChange(
                node.Namespace,
                node.Name,
                node.DifferenceDecoration,
                oldSourceText,
                newSourceText);

            if (_ignoreChangeSet.Contains(change))
            {
                return;
            }

            _changeSetBuilder.AddChange(change);
        }
    public List <ResourceChange> changePerTick()
    {
        List <ResourceChange> result = new List <ResourceChange>();

        // Calculate outputs
        // For a simple builing there should only ever be 1 output
        foreach (IResourceProducer producer in BuildingFactory.allBluePrints[this.bt].outputResourceProduction)
        {
            ResourceChange prodSimulate = producer.simulate(this.currentPop);
            result.Add(prodSimulate);
        }

        // Calculate inputs
        // For a simple building there should never be inputs
        foreach (IResourceProducer costs in BuildingFactory.allBluePrints[this.bt].inputResourceCosts)
        {
            // Remember, Blueprint.inputResourceCosts should always be positive despite intuition
            ResourceChange costSimulate = costs.simulate(this.currentPop);
            costSimulate.change = -1 * costSimulate.change;
            result.Add(costSimulate);
        }
        return(result);
    }
 private void InsertDocument(MongoContext mongoContext, ResourceChange change)
 {
     var collection = mongoContext.Database.GetCollection(change.CollectionName);
     var document = MongoDSPConverter.CreateBSonDocument(change.Resource, this.mongoMetadata, change.CollectionName);
     collection.Insert(document);
     change.Resource.SetValue(MongoMetadata.MappedObjectIdName, document.GetValue(MongoMetadata.ProviderObjectIdName).ToString());
 }
        private void UpdateDocument(MongoContext mongoContext, ResourceChange change)
        {
            if (!change.ModifiedProperties.Any())
                return;

            var collection = mongoContext.Database.GetCollection(change.CollectionName);
            var query = Query.EQ(MongoMetadata.ProviderObjectIdName, ObjectId.Parse(change.Resource.GetValue(MongoMetadata.MappedObjectIdName).ToString()));
            UpdateBuilder update = null;

            foreach (var resourceProperty in change.ModifiedProperties)
            {
                if (update == null)
                {
                    if (resourceProperty.Value != null)
                        update = Update.Set(resourceProperty.Key, BsonValue.Create(resourceProperty.Value));
                    else
                        update = Update.Unset(resourceProperty.Key);
                }
                else
                {
                    if (resourceProperty.Value != null)
                        update = update.Set(resourceProperty.Key, BsonValue.Create(resourceProperty.Value));
                    else
                        update = update.Unset(resourceProperty.Key);
                }
            }

            collection.Update(query, update);
        }
 private void RemoveDocument(MongoContext mongoContext, ResourceChange change)
 {
     var collection = mongoContext.Database.GetCollection(change.CollectionName);
     var query = Query.EQ(MongoMetadata.ProviderObjectIdName, ObjectId.Parse(change.Resource.GetValue(MongoMetadata.MappedObjectIdName).ToString()));
     collection.Remove(query);
 }
Exemple #20
0
        static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            // only take binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // read original data & section preparation
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);

            // change stuff
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }
            AICChange.DoChange(args);
            StartTroopChange.DoChange(args);
            ResourceChange.DoChange(args);

            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file
            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }
            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            ShowFailures(filePath);
        }
 private void subtractFromStockpile(ResourceChange rc)
 {
     changeResources(rc, false);
 }
 private void changeResources(ResourceChange rc, bool addTo)
 {
     changeResources(rc.resourceType, rc.change, addTo);
 }
        public static void Load(bool changesOnly = false)
        {
            List <string> aicConfigurationList        = null;
            List <string> aivConfigurationList        = null;
            List <string> resourceConfigurationList   = null;
            List <string> startTroopConfigurationList = null;

            if (File.Exists(ConfigFile))
            {
                using (StreamReader sr = new StreamReader(ConfigFile))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (Regex.Replace(@"\s+", "", line).Contains("aic_"))
                        {
                            if (aicConfigurationList == null)
                            {
                                aicConfigurationList = new List <string>();
                            }
                            aicConfigurationList.Add(line);
                            continue;
                        }
                        else if (Regex.Replace(@"\s+", "", line).StartsWith("aiv_"))
                        {
                            if (aivConfigurationList == null)
                            {
                                aivConfigurationList = new List <string>();
                            }
                            aivConfigurationList.Add(line);
                            continue;
                        }
                        else if (Regex.Replace(@"\s+", "", line).StartsWith("res_"))
                        {
                            if (resourceConfigurationList == null)
                            {
                                resourceConfigurationList = new List <string>();
                            }
                            resourceConfigurationList.Add(line);
                            continue;
                        }
                        else if (Regex.Replace(@"\s+", "", line).StartsWith("s_"))
                        {
                            if (startTroopConfigurationList == null)
                            {
                                startTroopConfigurationList = new List <string>();
                            }
                            startTroopConfigurationList.Add(line);
                            continue;
                        }

                        string[] changeLine = line.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim()).ToArray();
                        if (changeLine.Length < 2)
                        {
                            continue;
                        }

                        string changeKey     = changeLine[0];
                        string changeSetting = changeLine[1];

                        if (!changesOnly)
                        {
                            if (changeKey == "Path")
                            {
                                Configuration.Path = changeSetting;
                            }
                            else if (changeKey == "Language")
                            {
                                if (int.TryParse(changeSetting, out int result))
                                {
                                    Configuration.Language = result;
                                }
                            }
                        }
                        if (changeKey == "Path" || changeKey == "Language")
                        {
                            continue;
                        }
                        Change change = Version.Changes.Find(c => c.TitleIdent == changeKey);
                        if (change == null)
                        {
                            continue;
                        }

                        int      numChanges = changeSetting.Count(ch => ch == '=');
                        string[] changes    = changeSetting.Split(new char[] { '}' }, numChanges, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < numChanges; i++)
                        {
                            string        headerKey   = changes[i].Split('=')[0].Replace(" ", "").Replace("{", String.Empty);
                            string        headerValue = changes[i].Split('=')[1].Replace(" ", "").Replace("{", String.Empty).Replace("}", String.Empty);
                            DefaultHeader header      = change.FirstOrDefault(c => c.DescrIdent == headerKey);
                            header.LoadValueString(headerValue);
                        }
                    }
                }
            }
            AICChange.LoadConfiguration(aicConfigurationList);
            AIVChange.LoadConfiguration(aivConfigurationList);
            ResourceChange.LoadConfiguration(resourceConfigurationList);
            StartTroopChange.LoadConfiguration(startTroopConfigurationList);
        }
        static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc)
        {
            fails.Clear();
            SectionEditor.Reset();

            string gameSeedsFolder = Path.Combine(Configuration.Path, GAME_SEEDS_FOLDER);

            if (!Directory.Exists(gameSeedsFolder))
            {
                Directory.CreateDirectory(gameSeedsFolder);
            }

            // Retrieve set of selected binary changes
            var           changes  = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange));
            List <Change> todoList = new List <Change>(changes);

            int    todoIndex = 0;
            double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data

            // Read original data & perform section preparation adding .ucp section to binary
            byte[] oriData = File.ReadAllBytes(filePath);
            byte[] data    = (byte[])oriData.Clone();
            SectionEditor.Init(data);
            todoIndex += 3;

            perc.Set(todoIndex / todoCount);

            ChangeArgs args = new ChangeArgs(data, oriData);

            // Change version display in main menu
            try
            {
                (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args);
            }
            catch (Exception e)
            {
                Debug.Error(e);
            }
            perc.Set(++todoIndex / todoCount);

            // Apply each selected binary change
            foreach (Change change in todoList)
            {
                change.Activate(args);
                perc.Set(++todoIndex / todoCount);
            }

            // Apply changes handled in their respective submodules
            AICChange.DoChange(args);
            StartTroopChange.DoChange(args);
            ResourceChange.DoChange(args);

            todoIndex += 2;
            perc.Set(todoIndex / todoCount);



            // Write everything to file
            data = SectionEditor.AttachSection(data);

            if (filePath.EndsWith(BackupFileEnding))
            {
                filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length);
            }
            else
            {
                File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup
            }
            File.WriteAllBytes(filePath, data);

            perc.Set(1);

            ShowFailures(filePath);
        }
 private void RemoveDocument(MongoContext mongoContext, ResourceChange change)
 {
     var collection = mongoContext.Database.GetCollection<BsonDocument>(change.CollectionName);
     var filter = Builders<BsonDocument>.Filter.Eq(MongoMetadata.ProviderObjectIdName, ObjectId.Parse(change.Resource.GetValue(MongoMetadata.MappedObjectIdName).ToString()));
     collection.DeleteOneAsync(filter).GetAwaiter().GetResult();
 }
 private void addToStockpile(ResourceChange rc)
 {
     changeResources(rc, true);
 }
        private void UpdateDocument(MongoContext mongoContext, ResourceChange change)
        {
            if (!change.ModifiedProperties.Any())
                return;

            var collection = mongoContext.Database.GetCollection<BsonDocument>(change.CollectionName);
            var filter = Builders<BsonDocument>.Filter.Eq(MongoMetadata.ProviderObjectIdName, ObjectId.Parse(change.Resource.GetValue(MongoMetadata.MappedObjectIdName).ToString()));

            UpdateDefinition<BsonDocument> update = null;

            foreach (var resourceProperty in change.ModifiedProperties)
            {
                if (update == null)
                {
                    if (resourceProperty.Value != null)
                    {
                        update = Builders<BsonDocument>.Update.Set(resourceProperty.Key, BsonValue.Create(resourceProperty.Value));
                    }
                    else
                    {
                        update = Builders<BsonDocument>.Update.Unset(resourceProperty.Key);
                    }
                }
                else
                {
                    if (resourceProperty.Value != null)
                    {
                        update = update.Set(resourceProperty.Key, BsonValue.Create(resourceProperty.Value));
                    }
                    else
                    {
                        update = update.Unset(resourceProperty.Key);
                    }
                }
            }

            collection.UpdateOneAsync(filter, update).GetAwaiter().GetResult();
        }