Ticket #3769: aurapatch.9.diff

File aurapatch.9.diff, 4.4 KB (added by fatherbushido, 8 years ago)
  • binaries/data/mods/public/simulation/components/AuraManager.js

     
    170170    if (!template || !template.Identity)
    171171        return value;
    172172    var classes = GetIdentityClasses(template.Identity);
    173 
    174173    var usedKeys = new Set();
    175174    var add = 0;
    176175    var multiply = 1;
    177     for (let c in cache)
     176    for (let [className, mods] of cache)
    178177    {
    179         if (!MatchesClassList(classes, c))
     178        if (!MatchesClassList(classes, className))
    180179            continue;
    181 
    182         for (let key in cache.get(c))
     180       
     181        for (let [key, mod] of mods)
    183182        {
    184183            // don't add an aura with the same key twice
    185184            if (usedKeys.has(key))
    186185                continue;
    187 
    188             add += cache.get(c).get(key).add;
    189             multiply *= cache.get(c).get(key).multiply;
     186            add += mod.add;
     187            multiply *= mod.multiply;
    190188            usedKeys.add(key);
    191189        }
    192190    }
    193     value *= multiply;
    194     value += add;
    195     return value;
     191    return value*multiply + add;
    196192};
    197193
    198194Engine.RegisterSystemComponentType(IID_AuraManager, "AuraManager", AuraManager);
  • binaries/data/mods/public/simulation/components/Cost.js

     
    6565    return costs;
    6666};
    6767
     68Cost.prototype.GetResourceCostsFromTemplate = function(owner)
     69{
     70    if (owner == undefined)
     71    {
     72        let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     73            owner=cmpOwnership.GetOwner();
     74    }
     75    let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
     76    let entityTemplateName = cmpTemplateManager.GetCurrentTemplateName(this.entity);
     77    let entityTemplate = cmpTemplateManager.GetTemplate(entityTemplateName);
     78    let costs = {};
     79    for (let r in this.template.Resources)
     80    {
     81        costs[r] = +this.template.Resources[r];
     82        costs[r] = ApplyValueModificationsToTemplate("Cost/Resources/"+r, costs[r], owner, entityTemplate);
     83    };
     84    return costs;
     85};
     86
    6887Cost.prototype.OnOwnershipChanged = function(msg)
    6988{
    7089    if (msg.from != -1)
  • binaries/data/mods/public/simulation/components/Foundation.js

     
    2626    // decoupled from its owner, so we need to remember it in here (and assume it won't change)
    2727    this.owner = owner;
    2828
    29     // Remember our cost here, so if it changes after construction begins (from technologies)
    30     //  we will use the correct values to refund partial construction costs
    31     var cmpCost = Engine.QueryInterface(this.entity, IID_Cost);
    32     this.costs = cmpCost.GetResourceCosts();
     29    // Remember our cost here, so if it changes after construction begins (from aura or technologies)
     30    // we will use the correct values to refund partial construction costs
     31    let cmpCost = Engine.QueryInterface(this.entity, IID_Cost);
     32    this.costs = cmpCost.GetResourceCostsFromTemplate(owner);
     33
    3334    this.maxProgress = 0;
    34 
    3535    this.initialised = true;
    3636};
    3737
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    968968        cmpPosition.MoveOutOfWorld();
    969969        Engine.DestroyEntity(ent);
    970970    }
    971    
    972     // We need the cost after tech modifications
     971
     972    // We need the cost after tech and aura modifications
    973973    // To calculate this with an entity requires ownership, so use the template instead
    974     var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    975     var template = cmpTemplateManager.GetTemplate(foundationTemplate);
    976     var costs = {};
    977     for (var r in template.Cost.Resources)
    978     {
    979         costs[r] = +template.Cost.Resources[r];
    980         if (cmpTechnologyManager)
    981             costs[r] = cmpTechnologyManager.ApplyModificationsTemplate("Cost/Resources/"+r, costs[r], template);
    982     }
     974    let cmpCost = Engine.QueryInterface(ent, IID_Cost);
     975    let costs = cmpCost.GetResourceCostsFromTemplate(player);   
    983976   
    984977    if (!cmpPlayer.TrySubtractResources(costs))
    985978    {