2016-07-01 12:43:26 -07:00
|
|
|
function Upgrade() {}
|
|
|
|
|
|
|
|
|
|
const UPGRADING_PROGRESS_INTERVAL = 250;
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.Schema =
|
|
|
|
|
"<oneOrMore>" +
|
|
|
|
|
"<element>" +
|
|
|
|
|
"<anyName />" +
|
|
|
|
|
"<interleave>" +
|
|
|
|
|
"<element name='Entity' a:help='Entity to upgrade to'>" +
|
|
|
|
|
"<text/>" +
|
|
|
|
|
"</element>" +
|
|
|
|
|
"<optional>" +
|
|
|
|
|
"<element name='Icon' a:help='Icon to show in the GUI'>" +
|
|
|
|
|
"<text/>" +
|
|
|
|
|
"</element>" +
|
|
|
|
|
"</optional>" +
|
2019-11-24 03:34:57 -08:00
|
|
|
"<optional>" +
|
|
|
|
|
"<element name='Variant' a:help='The name of the variant to switch to when upgrading'>" +
|
|
|
|
|
"<text/>" +
|
|
|
|
|
"</element>" +
|
|
|
|
|
"</optional>" +
|
2016-07-01 12:43:26 -07:00
|
|
|
"<optional>" +
|
|
|
|
|
"<element name='Tooltip' a:help='This will be added to the tooltip to help the player choose why to upgrade.'>" +
|
|
|
|
|
"<text/>" +
|
|
|
|
|
"</element>" +
|
|
|
|
|
"</optional>" +
|
|
|
|
|
"<optional>" +
|
2016-07-02 09:05:56 -07:00
|
|
|
"<element name='Time' a:help='Time required to upgrade this entity, in seconds'>" +
|
2016-07-01 12:43:26 -07:00
|
|
|
"<data type='nonNegativeInteger'/>" +
|
|
|
|
|
"</element>" +
|
|
|
|
|
"</optional>" +
|
|
|
|
|
"<optional>" +
|
|
|
|
|
"<element name='Cost' a:help='Resource cost to upgrade this unit'>" +
|
|
|
|
|
"<oneOrMore>" +
|
|
|
|
|
"<choice>" +
|
2016-11-19 06:29:45 -08:00
|
|
|
Resources.BuildSchema("nonNegativeInteger") +
|
2016-07-01 12:43:26 -07:00
|
|
|
"</choice>" +
|
|
|
|
|
"</oneOrMore>" +
|
|
|
|
|
"</element>" +
|
|
|
|
|
"</optional>" +
|
|
|
|
|
"<optional>" +
|
2022-11-24 03:20:11 -08:00
|
|
|
RequirementsHelper.BuildSchema() +
|
2016-07-01 12:43:26 -07:00
|
|
|
"</optional>" +
|
|
|
|
|
"<optional>" +
|
|
|
|
|
"<element name='CheckPlacementRestrictions' a:help='Upgrading will check for placement restrictions (nb:GUI only)'><empty/></element>" +
|
|
|
|
|
"</optional>" +
|
|
|
|
|
"</interleave>" +
|
|
|
|
|
"</element>" +
|
|
|
|
|
"</oneOrMore>";
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.Init = function()
|
|
|
|
|
{
|
|
|
|
|
this.elapsedTime = 0;
|
2017-04-05 08:27:59 -07:00
|
|
|
this.expendedResources = {};
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// This will also deal with the "OnDestroy" case.
|
|
|
|
|
Upgrade.prototype.OnOwnershipChanged = function(msg)
|
|
|
|
|
{
|
2016-09-29 05:01:34 -07:00
|
|
|
if (!this.completed)
|
|
|
|
|
this.CancelUpgrade(msg.from);
|
2018-01-21 17:02:29 -08:00
|
|
|
|
|
|
|
|
if (msg.to != INVALID_PLAYER)
|
2022-07-15 10:16:00 -07:00
|
|
|
{
|
2016-07-01 12:43:26 -07:00
|
|
|
this.owner = msg.to;
|
2022-07-15 10:16:00 -07:00
|
|
|
this.DetermineUpgrades();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.DetermineUpgrades = function()
|
|
|
|
|
{
|
|
|
|
|
this.upgradeTemplates = {};
|
|
|
|
|
|
|
|
|
|
for (const choice in this.template)
|
|
|
|
|
{
|
|
|
|
|
const nativeCiv = Engine.QueryInterface(this.entity, IID_Identity).GetCiv();
|
|
|
|
|
const playerCiv = QueryPlayerIDInterface(this.owner, IID_Identity).GetCiv();
|
|
|
|
|
const name = this.template[choice].Entity.
|
|
|
|
|
replace(/\{native\}/g, nativeCiv).
|
|
|
|
|
replace(/\{civ\}/g, playerCiv);
|
|
|
|
|
|
|
|
|
|
if (!Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).TemplateExists(name))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (this.upgradeTemplates[name])
|
|
|
|
|
warn("Upgrade Component: entity " + this.entity + " has two upgrades to the same entity, only the last will be used.");
|
|
|
|
|
|
|
|
|
|
this.upgradeTemplates[name] = choice;
|
|
|
|
|
}
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.ChangeUpgradedEntityCount = function(amount)
|
|
|
|
|
{
|
|
|
|
|
if (!this.IsUpgrading())
|
|
|
|
|
return;
|
2016-09-29 05:01:34 -07:00
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
|
|
|
|
|
const template = cmpTempMan.GetTemplate(this.upgrading);
|
2016-07-01 12:43:26 -07:00
|
|
|
|
Don't increase entity limit counter when we upgrade to an entity with the same restriction category.
Summary:
In some mods (for hero) or in the current game (for sentry tower), when
we have reach the entity limit related to a restriction category, we
can't upgrade any entity wich have that restriction category to one with
the same restriction category (for example, upgrading an hero to an hero
as the 1 max limit is yet reached).
That diff should allow that in the gui and the sim.
Code could be concatenated. So comments are welcome.
Test Plan:
For in game testing, you can for example in the Player template reduce
the DefenseTower limit to 2. Then build 2 sentry towers.
Without the patch you can't upgrade any of them. With you can upgrade
them to defense tower.
Reviewers: wraitii, O8 JS GUI, O2 JS Simulation
Reviewed By: wraitii, O8 JS GUI, O2 JS Simulation
Subscribers: leper, mimo, wraitii, Vulcan, O8 JS GUI
Differential Revision: https://code.wildfiregames.com/D81
This was SVN commit r19195.
2017-02-01 08:35:08 -08:00
|
|
|
let categoryTo;
|
2016-07-01 12:43:26 -07:00
|
|
|
if (template.TrainingRestrictions)
|
Don't increase entity limit counter when we upgrade to an entity with the same restriction category.
Summary:
In some mods (for hero) or in the current game (for sentry tower), when
we have reach the entity limit related to a restriction category, we
can't upgrade any entity wich have that restriction category to one with
the same restriction category (for example, upgrading an hero to an hero
as the 1 max limit is yet reached).
That diff should allow that in the gui and the sim.
Code could be concatenated. So comments are welcome.
Test Plan:
For in game testing, you can for example in the Player template reduce
the DefenseTower limit to 2. Then build 2 sentry towers.
Without the patch you can't upgrade any of them. With you can upgrade
them to defense tower.
Reviewers: wraitii, O8 JS GUI, O2 JS Simulation
Reviewed By: wraitii, O8 JS GUI, O2 JS Simulation
Subscribers: leper, mimo, wraitii, Vulcan, O8 JS GUI
Differential Revision: https://code.wildfiregames.com/D81
This was SVN commit r19195.
2017-02-01 08:35:08 -08:00
|
|
|
categoryTo = template.TrainingRestrictions.Category;
|
2016-07-01 12:43:26 -07:00
|
|
|
else if (template.BuildRestrictions)
|
Don't increase entity limit counter when we upgrade to an entity with the same restriction category.
Summary:
In some mods (for hero) or in the current game (for sentry tower), when
we have reach the entity limit related to a restriction category, we
can't upgrade any entity wich have that restriction category to one with
the same restriction category (for example, upgrading an hero to an hero
as the 1 max limit is yet reached).
That diff should allow that in the gui and the sim.
Code could be concatenated. So comments are welcome.
Test Plan:
For in game testing, you can for example in the Player template reduce
the DefenseTower limit to 2. Then build 2 sentry towers.
Without the patch you can't upgrade any of them. With you can upgrade
them to defense tower.
Reviewers: wraitii, O8 JS GUI, O2 JS Simulation
Reviewed By: wraitii, O8 JS GUI, O2 JS Simulation
Subscribers: leper, mimo, wraitii, Vulcan, O8 JS GUI
Differential Revision: https://code.wildfiregames.com/D81
This was SVN commit r19195.
2017-02-01 08:35:08 -08:00
|
|
|
categoryTo = template.BuildRestrictions.Category;
|
2016-07-01 12:43:26 -07:00
|
|
|
|
Don't increase entity limit counter when we upgrade to an entity with the same restriction category.
Summary:
In some mods (for hero) or in the current game (for sentry tower), when
we have reach the entity limit related to a restriction category, we
can't upgrade any entity wich have that restriction category to one with
the same restriction category (for example, upgrading an hero to an hero
as the 1 max limit is yet reached).
That diff should allow that in the gui and the sim.
Code could be concatenated. So comments are welcome.
Test Plan:
For in game testing, you can for example in the Player template reduce
the DefenseTower limit to 2. Then build 2 sentry towers.
Without the patch you can't upgrade any of them. With you can upgrade
them to defense tower.
Reviewers: wraitii, O8 JS GUI, O2 JS Simulation
Reviewed By: wraitii, O8 JS GUI, O2 JS Simulation
Subscribers: leper, mimo, wraitii, Vulcan, O8 JS GUI
Differential Revision: https://code.wildfiregames.com/D81
This was SVN commit r19195.
2017-02-01 08:35:08 -08:00
|
|
|
if (!categoryTo)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
let categoryFrom;
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpTrainingRestrictions = Engine.QueryInterface(this.entity, IID_TrainingRestrictions);
|
|
|
|
|
const cmpBuildRestrictions = Engine.QueryInterface(this.entity, IID_BuildRestrictions);
|
Don't increase entity limit counter when we upgrade to an entity with the same restriction category.
Summary:
In some mods (for hero) or in the current game (for sentry tower), when
we have reach the entity limit related to a restriction category, we
can't upgrade any entity wich have that restriction category to one with
the same restriction category (for example, upgrading an hero to an hero
as the 1 max limit is yet reached).
That diff should allow that in the gui and the sim.
Code could be concatenated. So comments are welcome.
Test Plan:
For in game testing, you can for example in the Player template reduce
the DefenseTower limit to 2. Then build 2 sentry towers.
Without the patch you can't upgrade any of them. With you can upgrade
them to defense tower.
Reviewers: wraitii, O8 JS GUI, O2 JS Simulation
Reviewed By: wraitii, O8 JS GUI, O2 JS Simulation
Subscribers: leper, mimo, wraitii, Vulcan, O8 JS GUI
Differential Revision: https://code.wildfiregames.com/D81
This was SVN commit r19195.
2017-02-01 08:35:08 -08:00
|
|
|
if (cmpTrainingRestrictions)
|
|
|
|
|
categoryFrom = cmpTrainingRestrictions.GetCategory();
|
|
|
|
|
else if (cmpBuildRestrictions)
|
|
|
|
|
categoryFrom = cmpBuildRestrictions.GetCategory();
|
2018-01-20 07:22:02 -08:00
|
|
|
|
Don't increase entity limit counter when we upgrade to an entity with the same restriction category.
Summary:
In some mods (for hero) or in the current game (for sentry tower), when
we have reach the entity limit related to a restriction category, we
can't upgrade any entity wich have that restriction category to one with
the same restriction category (for example, upgrading an hero to an hero
as the 1 max limit is yet reached).
That diff should allow that in the gui and the sim.
Code could be concatenated. So comments are welcome.
Test Plan:
For in game testing, you can for example in the Player template reduce
the DefenseTower limit to 2. Then build 2 sentry towers.
Without the patch you can't upgrade any of them. With you can upgrade
them to defense tower.
Reviewers: wraitii, O8 JS GUI, O2 JS Simulation
Reviewed By: wraitii, O8 JS GUI, O2 JS Simulation
Subscribers: leper, mimo, wraitii, Vulcan, O8 JS GUI
Differential Revision: https://code.wildfiregames.com/D81
This was SVN commit r19195.
2017-02-01 08:35:08 -08:00
|
|
|
if (categoryTo == categoryFrom)
|
2016-07-01 12:43:26 -07:00
|
|
|
return;
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpEntityLimits = QueryPlayerIDInterface(this.owner, IID_EntityLimits);
|
2020-09-21 11:54:32 -07:00
|
|
|
if (cmpEntityLimits)
|
|
|
|
|
cmpEntityLimits.ChangeCount(categoryTo, amount);
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.CanUpgradeTo = function(template)
|
|
|
|
|
{
|
|
|
|
|
return this.upgradeTemplates[template] !== undefined;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.CancelTimer = function()
|
|
|
|
|
{
|
|
|
|
|
if (!this.timer)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
2016-07-01 12:43:26 -07:00
|
|
|
cmpTimer.CancelTimer(this.timer);
|
2022-07-15 10:16:00 -07:00
|
|
|
delete this.timer;
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.IsUpgrading = function()
|
|
|
|
|
{
|
|
|
|
|
return !!this.upgrading;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.GetUpgradingTo = function()
|
|
|
|
|
{
|
|
|
|
|
return this.upgrading;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.WillCheckPlacementRestrictions = function(template)
|
|
|
|
|
{
|
|
|
|
|
if (!this.upgradeTemplates[template])
|
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
|
|
// is undefined by default so use X in Y
|
|
|
|
|
return "CheckPlacementRestrictions" in this.template[this.upgradeTemplates[template]];
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-24 03:20:11 -08:00
|
|
|
Upgrade.prototype.GetRequirements = function(templateArg)
|
2016-07-01 12:43:26 -07:00
|
|
|
{
|
2025-05-12 04:10:26 -07:00
|
|
|
const choice = this.upgradeTemplates[templateArg] || templateArg;
|
2016-07-01 12:43:26 -07:00
|
|
|
|
2022-11-24 03:20:11 -08:00
|
|
|
if (this.template[choice].Requirements)
|
|
|
|
|
return this.template[choice].Requirements;
|
2016-07-01 12:43:26 -07:00
|
|
|
|
2022-11-24 03:20:11 -08:00
|
|
|
if (!("Requirements" in this.template[choice]))
|
2016-07-01 12:43:26 -07:00
|
|
|
return undefined;
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
|
|
|
|
|
const cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
|
2016-07-01 12:43:26 -07:00
|
|
|
|
|
|
|
|
let entType = this.template[choice].Entity;
|
|
|
|
|
if (cmpIdentity)
|
|
|
|
|
entType = entType.replace(/\{civ\}/g, cmpIdentity.GetCiv());
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const template = cmpTemplateManager.GetTemplate(entType);
|
2022-11-24 03:20:11 -08:00
|
|
|
return template.Identity.Requirements || undefined;
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.GetResourceCosts = function(template)
|
|
|
|
|
{
|
|
|
|
|
if (!this.upgradeTemplates[template])
|
|
|
|
|
return undefined;
|
|
|
|
|
|
2017-04-05 08:27:59 -07:00
|
|
|
if (this.IsUpgrading() && template == this.GetUpgradingTo())
|
|
|
|
|
return clone(this.expendedResources);
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const choice = this.upgradeTemplates[template];
|
2016-07-01 12:43:26 -07:00
|
|
|
if (!this.template[choice].Cost)
|
|
|
|
|
return {};
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const costs = {};
|
|
|
|
|
for (const r in this.template[choice].Cost)
|
2016-07-01 12:43:26 -07:00
|
|
|
costs[r] = ApplyValueModificationsToEntity("Upgrade/Cost/"+r, +this.template[choice].Cost[r], this.entity);
|
2016-07-02 14:32:09 -07:00
|
|
|
|
2016-07-01 12:43:26 -07:00
|
|
|
return costs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.Upgrade = function(template)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsUpgrading() || !this.upgradeTemplates[template])
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
|
2020-10-04 03:20:20 -07:00
|
|
|
if (!cmpPlayer)
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue);
|
2020-10-04 03:20:20 -07:00
|
|
|
if (cmpProductionQueue && cmpProductionQueue.HasQueuedProduction())
|
|
|
|
|
{
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
2020-10-04 03:20:20 -07:00
|
|
|
cmpGUIInterface.PushNotification({
|
|
|
|
|
"players": [cmpPlayer.GetPlayerID()],
|
|
|
|
|
"message": markForTranslation("Entity is producing. Cannot start upgrading."),
|
|
|
|
|
"translateMessage": true
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-07-01 12:43:26 -07:00
|
|
|
|
2017-04-05 08:27:59 -07:00
|
|
|
this.expendedResources = this.GetResourceCosts(template);
|
2020-09-19 10:55:34 -07:00
|
|
|
if (!cmpPlayer || !cmpPlayer.TrySubtractResources(this.expendedResources))
|
2017-04-05 08:27:59 -07:00
|
|
|
{
|
|
|
|
|
this.expendedResources = {};
|
2016-07-01 12:43:26 -07:00
|
|
|
return false;
|
2017-04-05 08:27:59 -07:00
|
|
|
}
|
2016-07-01 12:43:26 -07:00
|
|
|
|
|
|
|
|
this.upgrading = template;
|
2019-11-24 03:34:57 -08:00
|
|
|
this.SetUpgradeAnimationVariant();
|
2016-07-01 12:43:26 -07:00
|
|
|
|
|
|
|
|
// Prevent cheating
|
|
|
|
|
this.ChangeUpgradedEntityCount(1);
|
|
|
|
|
|
|
|
|
|
if (this.GetUpgradeTime(template) !== 0)
|
|
|
|
|
{
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
2016-07-01 12:43:26 -07:00
|
|
|
this.timer = cmpTimer.SetInterval(this.entity, IID_Upgrade, "UpgradeProgress", 0, UPGRADING_PROGRESS_INTERVAL, { "upgrading": template });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this.UpgradeProgress();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-02 18:50:55 -07:00
|
|
|
Upgrade.prototype.CancelUpgrade = function(owner)
|
2016-07-01 12:43:26 -07:00
|
|
|
{
|
|
|
|
|
if (!this.IsUpgrading())
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpPlayer = QueryPlayerIDInterface(owner, IID_Player);
|
2016-07-01 12:43:26 -07:00
|
|
|
if (cmpPlayer)
|
2017-04-05 08:27:59 -07:00
|
|
|
cmpPlayer.AddResources(this.expendedResources);
|
2016-07-01 12:43:26 -07:00
|
|
|
|
2017-04-05 08:27:59 -07:00
|
|
|
this.expendedResources = {};
|
2016-07-01 12:43:26 -07:00
|
|
|
this.ChangeUpgradedEntityCount(-1);
|
|
|
|
|
|
2019-11-24 03:34:57 -08:00
|
|
|
// Do not update visual actor if the animation didn't change.
|
2025-05-12 04:10:26 -07:00
|
|
|
const choice = this.upgradeTemplates[this.upgrading];
|
2019-11-24 03:34:57 -08:00
|
|
|
if (choice && this.template[choice].Variant)
|
|
|
|
|
{
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
|
2019-11-24 03:34:57 -08:00
|
|
|
if (cmpVisual)
|
|
|
|
|
cmpVisual.SelectAnimation("idle", false, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 10:16:00 -07:00
|
|
|
delete this.upgrading;
|
2016-07-01 12:43:26 -07:00
|
|
|
this.CancelTimer();
|
|
|
|
|
this.SetElapsedTime(0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.GetUpgradeTime = function(templateArg)
|
|
|
|
|
{
|
2025-05-12 04:10:26 -07:00
|
|
|
const template = this.upgrading || templateArg;
|
|
|
|
|
const choice = this.upgradeTemplates[template];
|
2016-07-02 18:50:55 -07:00
|
|
|
|
2016-07-01 12:43:26 -07:00
|
|
|
if (!choice)
|
|
|
|
|
return undefined;
|
2016-07-02 18:50:55 -07:00
|
|
|
|
|
|
|
|
if (!this.template[choice].Time)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2019-09-22 00:46:29 -07:00
|
|
|
return ApplyValueModificationsToEntity("Upgrade/Time", +this.template[choice].Time, this.entity);
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.GetElapsedTime = function()
|
|
|
|
|
{
|
|
|
|
|
return this.elapsedTime;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.GetProgress = function()
|
|
|
|
|
{
|
|
|
|
|
if (!this.IsUpgrading())
|
|
|
|
|
return undefined;
|
2016-07-02 09:05:56 -07:00
|
|
|
return this.GetUpgradeTime() == 0 ? 1 : Math.min(this.elapsedTime / 1000.0 / this.GetUpgradeTime(), 1.0);
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Upgrade.prototype.SetElapsedTime = function(time)
|
|
|
|
|
{
|
|
|
|
|
this.elapsedTime = time;
|
2019-12-07 05:40:40 -08:00
|
|
|
Engine.PostMessage(this.entity, MT_UpgradeProgressUpdate, null);
|
2016-07-01 12:43:26 -07:00
|
|
|
};
|
|
|
|
|
|
2019-11-24 03:34:57 -08:00
|
|
|
Upgrade.prototype.SetUpgradeAnimationVariant = function()
|
|
|
|
|
{
|
2025-05-12 04:10:26 -07:00
|
|
|
const choice = this.upgradeTemplates[this.upgrading];
|
2019-11-24 03:34:57 -08:00
|
|
|
|
|
|
|
|
if (!choice || !this.template[choice].Variant)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
|
2019-11-24 03:34:57 -08:00
|
|
|
if (!cmpVisual)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cmpVisual.SelectAnimation(this.template[choice].Variant, false, 1.0);
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-01 12:43:26 -07:00
|
|
|
Upgrade.prototype.UpgradeProgress = function(data, lateness)
|
|
|
|
|
{
|
2016-07-02 09:05:56 -07:00
|
|
|
if (this.elapsedTime/1000.0 < this.GetUpgradeTime())
|
2016-07-01 12:43:26 -07:00
|
|
|
{
|
|
|
|
|
this.SetElapsedTime(this.GetElapsedTime() + UPGRADING_PROGRESS_INTERVAL + lateness);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.CancelTimer();
|
|
|
|
|
|
2016-09-29 05:01:34 -07:00
|
|
|
this.completed = true;
|
2016-10-01 04:27:08 -07:00
|
|
|
this.ChangeUpgradedEntityCount(-1);
|
2017-04-05 08:27:59 -07:00
|
|
|
this.expendedResources = {};
|
2016-09-29 05:01:34 -07:00
|
|
|
|
2025-05-12 04:10:26 -07:00
|
|
|
const newEntity = ChangeEntityTemplate(this.entity, this.upgrading);
|
2016-07-01 12:43:26 -07:00
|
|
|
|
|
|
|
|
if (newEntity)
|
|
|
|
|
PlaySound("upgraded", newEntity);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_Upgrade, "Upgrade", Upgrade);
|