c1cc1291-376d-4080-b4e7-38c602d88f62.js
3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"use strict";
cc._RF.push(module, 'c1cc1KRN21AgLTnOMYC2I9i', 'PlotUtils');
// script/avg/utils/PlotUtils.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseTextWithVariables = exports.evalConditionExpr = void 0;
const ConditionModel_1 = require("../model/ConditionModel");
const GameRecord_1 = require("../game-data/GameRecord");
const simba_utils_1 = require("simba-utils");
const ConfigManager_1 = require("../../common/gameplay/managers/ConfigManager");
function evalConditionItem(item) {
let op1 = GameRecord_1.GameRecord.getVariableValue(item.target);
let op2;
if (item.oprand.type === ConditionModel_1.ConditionOprandType.Const) {
op2 = item.target;
}
else {
op2 = GameRecord_1.GameRecord.getVariableValue(item.target);
}
switch (item.operator) {
case ConditionModel_1.ConditionOperator.Equal:
return op1 == op2;
case ConditionModel_1.ConditionOperator.Greater:
return op1 > op2;
case ConditionModel_1.ConditionOperator.GreaterOrEqual:
return op1 >= op2;
case ConditionModel_1.ConditionOperator.Less:
return op1 < op2;
case ConditionModel_1.ConditionOperator.LessOrEqual:
return op1 <= op2;
case ConditionModel_1.ConditionOperator.NotEqual:
return op1 != op2;
}
}
function evalConditionExpr(condition) {
let ret = condition.relation === ConditionModel_1.ConditionRelation.Or ? false : true;
for (let group of condition.groups) {
for (let item of group.items) {
ret = evalConditionItem(item);
if ((ret && group.relation === ConditionModel_1.ConditionRelation.Or) || (!ret && group.relation === ConditionModel_1.ConditionRelation.And)) {
break;
}
}
if ((ret && condition.relation === ConditionModel_1.ConditionRelation.Or) || (!ret && condition.relation === ConditionModel_1.ConditionRelation.And)) {
break;
}
}
return ret;
}
exports.evalConditionExpr = evalConditionExpr;
function parseTextWithVariables(text) {
if (text.charCodeAt(0) !== 1)
return { parsedText: text, variables: [] };
text = text.substr(1);
let parsedText = text;
let matches = parsedText.match(/\${(.*?)}/g);
if (!matches)
return { parsedText: text, variables: [] };
let matchVars = simba_utils_1.uniqArray(matches);
let variables = matchVars.map(v => v.substring(2, v.length - 1));
for (let i = 0; i < matchVars.length; i++) {
let varName = variables[i];
if (/^[gr]\./.test(varName)) {
parsedText = parsedText.replace(new RegExp(matchVars[i].replace(/\./gm, "\\.").replace(/\$/gm, "\\$"), "gm"), GameRecord_1.GameRecord.getVariableValue(varName).toString());
}
else { // value from table
let index = varName.indexOf(".");
let index1 = varName.indexOf("[");
if (index >= 0) {
let tableName = varName.substring(0, index1);
let valueId = parseInt(varName.substring(index1 + 1, index - 1));
let fieldName = varName.substring(index + 1);
try {
let text = ConfigManager_1.ConfigManager.getConfig({ name: tableName }, valueId)[fieldName];
if (typeof text === "number") {
text = text.toString();
}
else {
text = parseTextWithVariables(text);
}
parsedText = parsedText.replace(new RegExp(matchVars[i].replace(/\./gm, "\\.").replace(/\$/gm, "\\$"), "gm"), text);
}
catch (e) {
console.error(e);
}
}
else {
console.error("Invalid variable");
}
}
}
return { parsedText, variables };
}
exports.parseTextWithVariables = parseTextWithVariables;
cc._RF.pop();