313 lines
21 KiB
ActionScript
313 lines
21 KiB
ActionScript
package {
|
|
import flash.system.ApplicationDomain;
|
|
|
|
/**
|
|
* Offline adapter for RAW loadMasterData snapshots, never derived stats.
|
|
*
|
|
* Contract: after original Table/RM initialization, call
|
|
* var roster:Object = SnapshotBridge.build(domain, rawSnapshot, "teamA");
|
|
* Returns {master: original MasterVo, selectedTeam: original TeamVo,
|
|
* validation: JSON-safe provenance/selection metadata}.
|
|
* Success installs master in this domain's Game.getIns().master because
|
|
* original MonsterVo/BagCenter/TeamCenter getters use the Master accessor.
|
|
* Failure throws Error("SnapshotBridge[code] path: explanation") and leaves
|
|
* the previous Game.master installed. Input snapshots are never mutated.
|
|
* Caller owns BattlePosition, battle contexts, resources and result handling.
|
|
* Required raw roots: master, monsters, items, teams, monsterAttributes,
|
|
* history. An explicit empty monsterAttributes array is valid: absent rows
|
|
* leave the ORIGINAL MonsterAdd constructor state unchanged. Present rows
|
|
* need explicit values for every ADD_FIELDS key; no bonuses are rebuilt.
|
|
* Equipment requires itemClass 3 and the original JSON-string equipParams.
|
|
*
|
|
* Source references below are relative to analysis/as3/scripts/net/pixvi/myr/.
|
|
* Only the pure loader calls from center/MasterCenter.as:loadMasterData are
|
|
* used. Do not call loadMasterData itself: its surrounding startup path
|
|
* accesses SDK, account, persistence, achievements and UI state.
|
|
*/
|
|
public class SnapshotBridge {
|
|
private static const ADD_FIELDS:Array = ["atk", "def", "hp", "dex", "crit", "atkSpd",
|
|
"atkVim", "selfCure", "deadBoom", "atkStun", "defStun", "atkPoi", "atkPoiDmg",
|
|
"apCostSave", "skillCooldown", "sunFire", "moonHeal", "thorns"];
|
|
private static const MON_FIELDS:Array = ["id", "typeId", "level", "exp", "tpLevel", "tpExp",
|
|
"feel", "process", "mode", "gAtk", "gDef", "gHp", "gDex", "pAtk", "pDef", "pHp",
|
|
"pDex", "potentialLevel", "equip1", "equip2", "equip3", "equip4", "equip5",
|
|
"entangleLevel", "skin"];
|
|
|
|
public static function build(domain:ApplicationDomain, snapshot:Object, teamName:String):Object {
|
|
if (domain == null) reject("domain", "domain", "original ApplicationDomain is required");
|
|
objectAt(snapshot, "snapshot");
|
|
if (teamName == null || teamName.length == 0)
|
|
reject("team_name", "teamName", "select an explicit snapshot team");
|
|
// Copy before calling loaders: BagCenter adds equipPara and HistoryVo
|
|
// normalizes maps/flags in place (center/BagCenter.as:getItemByItemData;
|
|
// element/master/HistoryVo.as:loadHistoryData).
|
|
var data:Object = copy(snapshot);
|
|
var rawMaster:Object = objectAt(data.master, "master");
|
|
numbers(rawMaster, ["id", "level", "globalAtk", "globalDef", "globalHp", "globalDex"], "master");
|
|
positiveId(rawMaster.id, "master.id", 2147483647);
|
|
positiveId(rawMaster.level, "master.level", 2147483647);
|
|
var monsters:Array = arrayAt(data.monsters, "monsters");
|
|
var items:Array = arrayAt(data.items, "items");
|
|
var teams:Array = arrayAt(data.teams, "teams");
|
|
var attributes:Array = arrayAt(data.monsterAttributes, "monsterAttributes");
|
|
validateHistory(data);
|
|
|
|
var table:Class = definition(domain, "net.pixvi.myr.center.Table");
|
|
for each (var tableName:String in ["monster_info", "item_info", "game_setting", "team_info", "task_info"])
|
|
objectAt(table[tableName], "Table." + tableName);
|
|
// Table.startUp normally derives city_info from game_setting.cityInfo;
|
|
// the caller may instead inject it. The history loader tolerates null
|
|
// city_info; this bridge never rewrites caller resource tables.
|
|
var monById:Object = {};
|
|
var attrById:Object = {};
|
|
var itemById:Object = {};
|
|
var equipment:Object = {};
|
|
var rawTeam:Object = null;
|
|
var names:Object = {};
|
|
var i:int;
|
|
var row:Object;
|
|
var path:String;
|
|
var key:String;
|
|
for (i = 0; i < monsters.length; i++) {
|
|
path = "monsters[" + i + "]"; row = objectAt(monsters[i], path);
|
|
numbers(row, MON_FIELDS, path);
|
|
positiveId(row.id, path + ".id"); positiveId(row.typeId, path + ".typeId", 2147483647);
|
|
// Non-selected eggs may legitimately carry level/potential 0.
|
|
// Positive combat levels are required below for selected IDs.
|
|
flag(row.inExploreTeam, path + ".inExploreTeam"); flag(row.entangle, path + ".entangle");
|
|
if (monById.hasOwnProperty(String(row.id))) reject("duplicate_monster", path + ".id", "duplicate instance ID");
|
|
monById[String(row.id)] = row;
|
|
if (table["monster_info"][row.typeId] == null)
|
|
reject("monster_type", path + ".typeId", "missing original monster table row");
|
|
if (row.skin > 0) {
|
|
// center/Table.as:startUp assigns RM.TXT.getJson("skin_info").skins.
|
|
// element/mon/SkinVo.as:table indexes that FLAT map by typeId.
|
|
var skins:Object = objectAt(table["skin_info"], "Table.skin_info");
|
|
if (skins[row.skin] == null || Number(skins[row.skin].monType) != row.typeId)
|
|
reject("skin", path + ".skin", "skin must exist for this monster species");
|
|
}
|
|
// MonsterCenter itself supplies table skills, up-star skills,
|
|
// potential PointLockers, SkinVo and decoded entangleSkills.
|
|
if (row.upStar != null && Number(row.upStar) > 0) {
|
|
numbers(row, ["upStar"], path);
|
|
if (table["upstar_info"] == null || table["upstar_info"][row.typeId] == null)
|
|
reject("upstar", path + ".upStar", "missing original up-star table row");
|
|
}
|
|
if (row.entangleSkills != null) {
|
|
var entangleSkills:Object = jsonObject(row.entangleSkills, path + ".entangleSkills");
|
|
for (key in entangleSkills) {
|
|
if (Number(entangleSkills[key]) > 0 && (table["entangle_info"] == null ||
|
|
table["entangle_info"].entangleSkill == null ||
|
|
table["entangle_info"].entangleSkill[entangleSkills[key]] == null))
|
|
reject("entangle_skill", path + ".entangleSkills", "missing original entangle skill");
|
|
}
|
|
}
|
|
}
|
|
for (i = 0; i < attributes.length; i++) {
|
|
path = "monsterAttributes[" + i + "]"; row = objectAt(attributes[i], path);
|
|
positiveId(row.monsterId, path + ".monsterId");
|
|
key = String(row.monsterId);
|
|
if (attrById.hasOwnProperty(key)) reject("duplicate_attributes", path + ".monsterId", "ambiguous instance attributes");
|
|
if (!monById.hasOwnProperty(key)) reject("orphan_attributes", path + ".monsterId", "monster instance is absent");
|
|
numbers(row, ADD_FIELDS, path);
|
|
attrById[key] = row;
|
|
}
|
|
var itemVoClass:Class = definition(domain, "net.pixvi.myr.element.bag.ItemVo");
|
|
var itemTypeClass:Class = definition(domain, "net.pixvi.myr.element.bag.ItemType");
|
|
for (i = 0; i < items.length; i++) {
|
|
path = "items[" + i + "]"; row = objectAt(items[i], path);
|
|
numbers(row, ["id", "typeId", "num"], path);
|
|
positiveId(row.id, path + ".id"); positiveId(row.typeId, path + ".typeId", 2147483647);
|
|
if (itemById.hasOwnProperty(String(row.id))) reject("duplicate_item", path + ".id", "duplicate inventory instance ID");
|
|
itemById[String(row.id)] = row;
|
|
if (table["item_info"][row.typeId] == null && table["monster_info"][row.typeId] == null)
|
|
reject("item_type", path + ".typeId", "missing original item/egg table row");
|
|
if (itemVoClass["getItemType"](row.typeId) == itemTypeClass["TYPE_EQUIP"]) {
|
|
numbers(row, ["itemClass", "isUsed"], path);
|
|
if (row.itemClass != 3) reject("equipment_class", path + ".itemClass", "original equipment loader requires itemClass 3");
|
|
// Preflight avoids BagCenter's missing-params Alert/fake-zero
|
|
// error branch. The original loader still decodes equipParams.
|
|
var equip:Object = jsonObject(row.equipParams, path + ".equipParams");
|
|
numbers(equip, ADD_FIELDS, path + ".equipParams");
|
|
if (equip.atkPoi > 0) numbers(equip, ["atkPoiType"], path + ".equipParams");
|
|
equipment[String(row.id)] = row;
|
|
}
|
|
}
|
|
for (i = 0; i < monsters.length; i++) {
|
|
row = monsters[i];
|
|
for (var slot:int = 1; slot <= 5; slot++) {
|
|
var equipId:Number = Number(row["equip" + slot]);
|
|
if (equipId < 0 || equipId > 2147483647 || equipId != Math.floor(equipId))
|
|
reject("equipment_id", "monsters[" + i + "].equip" + slot, "expected zero or inventory instance ID within original equip:int range");
|
|
if (equipId > 0 && !equipment.hasOwnProperty(String(equipId)))
|
|
reject("missing_equipment", "monsters[" + i + "].equip" + slot, "equipped inventory instance is absent or is not equipment");
|
|
}
|
|
}
|
|
var selectedIds:Array = [];
|
|
var selectedSlots:Array = [];
|
|
var selectedSeen:Object = {};
|
|
for (i = 0; i < teams.length; i++) {
|
|
path = "teams[" + i + "]"; row = objectAt(teams[i], path);
|
|
if (!(row.teamName is String) || row.teamName.length == 0 || !(row.teamType is String))
|
|
reject("team_fields", path, "original teamName and teamType are required");
|
|
if (names.hasOwnProperty(row.teamName)) reject("duplicate_team", path + ".teamName", "ambiguous team name");
|
|
names[row.teamName] = true;
|
|
var rawSlots:Array = arrayAt(row.monsters, path + ".monsters");
|
|
var slotInfo:Object = objectAt(table["team_info"][row.teamType], "Table.team_info." + row.teamType);
|
|
for (var pos:int = 0; pos < rawSlots.length; pos++) {
|
|
var mid:Number = numberAt(rawSlots[pos], path + ".monsters[" + pos + "]");
|
|
if (mid < 0 || mid != Math.floor(mid)) reject("team_member_id", path + ".monsters[" + pos + "]", "expected zero or positive monster instance ID");
|
|
// Original loaders may discard trailing empty padding. An
|
|
// occupied unsupported position must never be discarded.
|
|
if (slotInfo[pos] == null && mid > 0) reject("team_slot", path + ".monsters[" + pos + "]", "occupied position is absent from the original team table");
|
|
if (mid > 0 && !monById.hasOwnProperty(String(mid)))
|
|
reject("missing_team_member", path + ".monsters[" + pos + "]", "reference must be a supplied monster instance ID, not a species ID");
|
|
if (row.teamName == teamName && mid > 0) {
|
|
var member:Object = monById[String(mid)];
|
|
if (selectedSeen.hasOwnProperty(String(mid))) reject("duplicate_member", path, "monster instance occupies multiple selected slots");
|
|
selectedSeen[String(mid)] = true;
|
|
if (member.process != 3 || (member.mode != 1 && member.mode != 2))
|
|
reject("incubating_member", path + ".monsters[" + pos + "]", "selected monster must be out of incubation (process 3, mode 1 or 2)");
|
|
if (member.inExploreTeam == true)
|
|
reject("exploring_member", path + ".monsters[" + pos + "]", "selected monster is exploring");
|
|
positiveId(member.level, path + ".monsters[" + pos + "].level", 2147483647);
|
|
positiveId(member.potentialLevel, path + ".monsters[" + pos + "].potentialLevel", 2147483647);
|
|
selectedIds.push(mid); selectedSlots.push(pos);
|
|
}
|
|
}
|
|
if (row.teamName == teamName) rawTeam = row;
|
|
}
|
|
if (rawTeam == null) reject("team_missing", "teams", "requested teamName is absent");
|
|
if (selectedIds.length == 0) reject("empty_team", "teams", "selected team has no positive monster instance IDs");
|
|
|
|
var game:Object = definition(domain, "net.pixvi.myr.center.Game")["getIns"]();
|
|
var previous:Object = game["master"];
|
|
var masterClass:Class = definition(domain, "net.pixvi.myr.element.master.MasterVo");
|
|
var monsterCenter:Class = definition(domain, "net.pixvi.myr.center.MonsterCenter");
|
|
var bagCenter:Class = definition(domain, "net.pixvi.myr.center.BagCenter");
|
|
var teamCenter:Class = definition(domain, "net.pixvi.myr.center.TeamCenter");
|
|
var master:Object = new masterClass();
|
|
try {
|
|
game["master"] = master; master["init"]();
|
|
// center/MasterCenter.as:loadMasterData scalar mapping. AP is
|
|
// read-only MasterVo.ap -> GameMath.apByLevel(raw level).
|
|
for each (key in ["id", "createTime", "level", "farmName", "avatar", "exp", "money", "ti", "ke"])
|
|
if (rawMaster.hasOwnProperty(key)) master[key] = rawMaster[key];
|
|
if (rawMaster.hasOwnProperty("roleName")) master["name"] = rawMaster.roleName;
|
|
if (rawMaster.hasOwnProperty("timeTi")) master["timeTi"] = rawMaster.timeTi / 1000;
|
|
master["curBattleTeam"] = teamName;
|
|
// Native reflection confirms HistoryVo.loadHistoryData(Object,
|
|
// Object); there is no HistoryVo.onData API in this SWF.
|
|
master["history"]["loadHistoryData"](data.history, data.data2);
|
|
if (data.activityHistory != null) {
|
|
master["activityHistory"]["loadActivityData"](data.activityHistory);
|
|
master["vipTime"] = data.activityHistory.vipInfo.vipTime;
|
|
}
|
|
if (data.payInfo != null) {
|
|
if (data.payInfo.payPoint != null) master["history"]["payPoint"] = data.payInfo.payPoint;
|
|
var giftTypes:Object = data.payInfo.payGiftTypes == null ? data.payInfo.payGitfTypes : data.payInfo.payGiftTypes;
|
|
if (giftTypes != null) for each (key in String(giftTypes).split(",")) master["history"]["payGiftTypes"][key] = true;
|
|
}
|
|
master["globalAdd"]["update"](rawMaster);
|
|
if (data.masterEventTimer != null) master["randomEventTimer"] = data.masterEventTimer;
|
|
if (data.masterCurrentEvent != null) master["randomEvent"] = data.masterCurrentEvent;
|
|
for each (row in monsters) {
|
|
var mon:Object = monsterCenter["getMonByMonData"](row);
|
|
// center/MasterCenter.as:loadMasterData only updates an
|
|
// existing allMbs[mon.id]; [] and absent per-instance rows
|
|
// intentionally preserve the original MonsterAdd defaults.
|
|
if (attrById.hasOwnProperty(String(row.id))) mon["abilityAdd"]["update"](attrById[String(row.id)]);
|
|
master["monsters"].push(mon);
|
|
}
|
|
for each (row in items) master["bag"]["items"].push(bagCenter["getItemByItemData"](row));
|
|
var selectedTeam:Object = null;
|
|
for each (row in teams) {
|
|
var team:Object = teamCenter["getTeamVoByData"](row);
|
|
master["teams"].push(team);
|
|
if (row.teamName == teamName) selectedTeam = team;
|
|
}
|
|
for each (pos in selectedSlots)
|
|
if (selectedTeam.monsters[pos] != rawTeam.monsters[pos])
|
|
reject("team_slot", "teams", "original loader shifted an occupied selected slot");
|
|
return {master:master, selectedTeam:selectedTeam, validation:{schema:1,
|
|
source:"original_loadMasterData", teamName:teamName, teamType:rawTeam.teamType,
|
|
selectedIds:selectedIds, selectedSlots:selectedSlots, rawSlots:rawTeam.monsters.concat(),
|
|
monsterCount:monsters.length, attributeCount:attributes.length, itemCount:items.length,
|
|
masterLevel:master["level"], ap:master["ap"], apSource:"MasterVo.ap/GameMath.apByLevel",
|
|
historyLoader:"HistoryVo.loadHistoryData", installed:true}};
|
|
} catch (error:Error) {
|
|
game["master"] = previous;
|
|
reject("original_loader", "snapshot", error.name + ": " + error.message);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static function validateHistory(data:Object):void {
|
|
var h:Object = objectAt(data.history, "history");
|
|
// Exact required shapes read by HistoryVo.loadHistoryData. Original
|
|
// conversions produce guide/unlock/pass boolean maps, not arrays.
|
|
for each (var name:String in ["monLib", "equipLib", "passAchi", "guide_record", "unlockCity"])
|
|
arrayAt(h[name], "history." + name);
|
|
for each (name in ["numFeedMonsters", "numKillMonsters", "historyGacha", "passTask", "unlockTask",
|
|
"loopTask", "unlockStage", "passStage", "payTypeCount", "everyDayBuyProductNum"])
|
|
objectAt(h[name], "history." + name);
|
|
numbers(h, ["numAddMoney", "numChicken", "countBattle"], "history");
|
|
for each (name in ["unlockStage", "passStage"])
|
|
for (var key:String in h[name]) if (key != "") arrayAt(h[name][key], "history." + name + "." + key);
|
|
if (data.data2 != null) {
|
|
objectAt(data.data2, "data2"); arrayAt(data.data2.unlockSkins, "data2.unlockSkins");
|
|
}
|
|
if (data.activityHistory != null) {
|
|
var activity:Object = objectAt(data.activityHistory, "activityHistory");
|
|
var daily:Object = objectAt(activity.dailyGift, "activityHistory.dailyGift");
|
|
numbers(daily, ["dailyGiftCheckTime", "dailyGiftLevel", "dailyGiftCount", "signCount"], "activityHistory.dailyGift");
|
|
}
|
|
}
|
|
|
|
private static function definition(domain:ApplicationDomain, name:String):Class {
|
|
if (!domain.hasDefinition(name)) reject("definition", name, "original library definition is missing");
|
|
return domain.getDefinition(name) as Class;
|
|
}
|
|
private static function objectAt(value:Object, path:String):Object {
|
|
if (value == null || typeof(value) != "object" || value is Array)
|
|
reject("missing_object", path, "expected an explicit object");
|
|
return value;
|
|
}
|
|
private static function arrayAt(value:Object, path:String):Array {
|
|
if (!(value is Array)) reject("missing_array", path, "expected an explicit array, including when empty");
|
|
return value as Array;
|
|
}
|
|
private static function numberAt(value:Object, path:String):Number {
|
|
if (value == null || typeof(value) != "number" || !isFinite(Number(value)))
|
|
reject("missing_number", path, "expected an explicit finite number; no stat defaults are supplied");
|
|
return Number(value);
|
|
}
|
|
private static function numbers(row:Object, names:Array, path:String):void {
|
|
for each (var name:String in names) numberAt(row[name], path + "." + name);
|
|
}
|
|
private static function positiveId(value:Object, path:String, max:Number = 9007199254740991):void {
|
|
var n:Number = numberAt(value, path);
|
|
if (n < 1 || n != Math.floor(n) || n > max) reject("positive_integer", path, "expected an exact positive integer within the original field range");
|
|
}
|
|
private static function flag(value:Object, path:String):void {
|
|
if (!(value is Boolean) && !(value === 0 || value === 1)) reject("missing_flag", path, "expected explicit boolean or 0/1 flag");
|
|
}
|
|
private static function jsonObject(value:Object, path:String):Object {
|
|
if (!(value is String)) reject("json_string", path, "original loader requires a JSON object string");
|
|
var decoded:Object;
|
|
try { decoded = JSON.parse(String(value)); }
|
|
catch (error:Error) { reject("json_string", path, "invalid JSON object string"); }
|
|
return objectAt(decoded, path);
|
|
}
|
|
private static function copy(value:Object):Object {
|
|
if (value == null || typeof(value) != "object") return value;
|
|
var result:Object = value is Array ? [] : {};
|
|
for (var key:String in value) result[key] = copy(value[key]);
|
|
return result;
|
|
}
|
|
private static function reject(code:String, path:String, message:String):void {
|
|
throw new Error("SnapshotBridge[" + code + "] " + path + ": " + message);
|
|
}
|
|
}
|
|
}
|