fix some problems of games

This commit is contained in:
2026-05-22 13:56:23 +08:00
parent 2f76e6a3ca
commit 09aa034f52
8 changed files with 274 additions and 33 deletions

View File

@@ -95,7 +95,20 @@
for (var i = 0; i < map.buildings.length; i++) {
var b = map.buildings[i];
if (!b || !b.grid) continue;
buildings.push({ type: b.type, mx: b.grid.mx, my: b.grid.my, level: b.level, money: b.money });
buildings.push({
type: b.type,
mx: b.grid.mx,
my: b.grid.my,
level: b.level,
money: b.money,
killed: b.killed,
damage: b.damage,
range: b.range,
speed: b.speed,
life: b.life,
shield: b.shield,
upgrade_records: b._upgrade_records || null
});
}
}
@@ -190,8 +203,36 @@
grid.addBuilding(bi.type);
var b = grid.building;
if (b) {
if (typeof bi.level !== 'undefined') b.level = bi.level;
var hasSavedBuildingAttrs = (
typeof bi.damage !== 'undefined' ||
typeof bi.range !== 'undefined' ||
typeof bi.speed !== 'undefined' ||
typeof bi.life !== 'undefined' ||
typeof bi.shield !== 'undefined'
);
if (!hasSavedBuildingAttrs && typeof bi.level !== 'undefined' && bi.level > 0 && typeof b.upgrade === 'function') {
for (var ul = 0; ul < bi.level; ul++) b.upgrade();
} else if (typeof bi.level !== 'undefined') {
b.level = bi.level;
}
if (typeof bi.damage !== 'undefined') b.damage = bi.damage;
if (typeof bi.range !== 'undefined') b.range = bi.range;
if (typeof bi.speed !== 'undefined') b.speed = bi.speed;
if (typeof bi.life !== 'undefined') b.life = bi.life;
if (typeof bi.shield !== 'undefined') b.shield = bi.shield;
if (typeof bi.money !== 'undefined') b.money = bi.money;
if (typeof bi.killed !== 'undefined') b.killed = bi.killed;
if (bi.upgrade_records) {
b._upgrade_records = {};
for (var rk in bi.upgrade_records) {
if (Object.prototype.hasOwnProperty.call(bi.upgrade_records, rk)) {
b._upgrade_records[rk] = bi.upgrade_records[rk];
}
}
}
b.range_px = b.range * TD.grid_size;
b.updateBtnDesc && b.updateBtnDesc();
}
}