var A4_EVENT_USE = 0; var A4_EVENT_PICKUP = 1; var A4_EVENT_ACTIVATE = 2; var A4_EVENT_DEACTIVATE = 3; var A4_EVENT_DROP = 4; var A4_EVENT_EQUIP = 5; var A4_EVENT_UNEQUIP = 6; var A4_EVENT_OPEN = 7; var A4_EVENT_CLOSE = 8; var A4_EVENT_PUSH = 9; var A4_EVENT_TIMER = 10; var A4_EVENT_RECEIVE = 11; var A4_EVENT_INTERACT = 12; var A4_EVENT_START = 13; var A4_EVENT_END = 14; var A4_EVENT_STORYSTATE = 15; var A4_EVENT_ACTION_TAKE = 16; var A4_EVENT_ACTION_DROP = 17; var A4_EVENT_ACTION_DROP_GOLD = 18; var A4_EVENT_ACTION_USE = 19; var A4_EVENT_ACTION_EQUIP = 20; var A4_EVENT_ACTION_UNEQUIP = 21; var A4_EVENT_ACTION_INTERACT = 22; var A4_EVENT_ACTION_TALK = 23; var A4_EVENT_ACTION_GIVE = 24; var A4_EVENT_ACTION_SELL = 25; var A4_EVENT_ACTION_BUY = 26; var A4_EVENT_ACTION_CHOP = 27; var A4_NEVENTS = 28; var A4_STORYSTATE_GAME = 0; var A4_STORYSTATE_MAP = 1; var A4_STORYSTATE_OBJECT = 2; var A4EventRule = /** @class */ (function () { function A4EventRule(event, script, once, time, period) { this.startTime = -1; this.variable = null; this.value = null; this.executed = false; this.effects = []; this.item = null; this.character = null; this.hit = -1; this.angry = -1; this.performative = -1; this.lastTimeGameStoryStateChanged = -1; this.lastTimeMapStoryStateChanged = -1; this.lastTimeObjectStoryStateChecked = -1; this.event = event; this.time = time; this.period = period; this.once = once; if (script != null) this.effects.push(script); } A4EventRule.fromXML = function (xml) { var r = new A4EventRule(0, null, true, 0, 0); var event_name = xml.getAttribute("event"); if (event_name == null) { console.error("A4EventRule: no event in rule!"); return null; } else { if (event_name == "use") { r.event = A4_EVENT_USE; } else if (event_name == "pickup") { r.event = A4_EVENT_PICKUP; } else if (event_name == "activate") { r.event = A4_EVENT_ACTIVATE; } else if (event_name == "deactivate") { r.event = A4_EVENT_DEACTIVATE; } else if (event_name == "drop") { r.event = A4_EVENT_DROP; } else if (event_name == "open") { r.event = A4_EVENT_OPEN; } else if (event_name == "close") { r.event = A4_EVENT_CLOSE; } else if (event_name == "push") { r.event = A4_EVENT_PUSH; } else if (event_name == "timer") { r.event = A4_EVENT_TIMER; r.time = Number(xml.getAttribute("time")); if (xml.getAttribute("period") != null) { r.period = Number(xml.getAttribute("period")); } else { r.period = 0; } } else if (event_name == "receive") { r.event = A4_EVENT_RECEIVE; r.item = xml.getAttribute("item"); } else if (event_name == "interact") { r.event = A4_EVENT_INTERACT; } else if (event_name == "start") { r.event = A4_EVENT_START; } else if (event_name == "end") { r.event = A4_EVENT_END; } else if (event_name == "story_state") { var scope_name = xml.getAttribute("scope"); if (scope_name != null) { // it's a story state rule: r.event = A4_EVENT_STORYSTATE; if (scope_name == "game") r.ss_scope = A4_STORYSTATE_GAME; else if (scope_name == "map") r.ss_scope = A4_STORYSTATE_MAP; else if (scope_name == "character") r.ss_scope = A4_STORYSTATE_OBJECT; else if (scope_name == "object") r.ss_scope = A4_STORYSTATE_OBJECT; else { console.error("A4EventRule: unrecognized scope '%s" + scope_name + "'"); return null; } r.variable = xml.getAttribute("variable"); r.value = xml.getAttribute("value"); } else { console.error("A4EventRule: no scope in story state rule!"); return null; } } else if (event_name == "action_take") { r.event = A4_EVENT_ACTION_TAKE; r.item = xml.getAttribute("item"); } else if (event_name == "action_drop") { r.event = A4_EVENT_ACTION_DROP; r.item = xml.getAttribute("item"); } else if (event_name == "action_drop_gold") { r.event = A4_EVENT_ACTION_DROP_GOLD; } else if (event_name == "action_use") { r.event = A4_EVENT_ACTION_USE; r.item = xml.getAttribute("item"); } else if (event_name == "action_equip") { r.event = A4_EVENT_ACTION_EQUIP; r.item = xml.getAttribute("item"); } else if (event_name == "action_unequip") { r.event = A4_EVENT_ACTION_UNEQUIP; r.item = xml.getAttribute("item"); } else if (event_name == "action_interact") { r.event = A4_EVENT_ACTION_INTERACT; r.item = xml.getAttribute("item"); /* } else if (event_name == "action_talk") { r.event = A4_EVENT_ACTION_TALK; let tmp:string = xml.getAttribute("performative"); let found:boolean = false; for(let i:number = 0;i = xml.children; var script_xml_l = xml.children; for (var i = 0; i < script_xml_l.length; i++) { r.effects.push(A4Script.fromXML(script_xml_l[i])); } return r; }; A4EventRule.fromA4EventRule = function (rule) { var r = new A4EventRule(rule.event, null, rule.once, rule.time, rule.period); r.startTime = rule.startTime; r.executed = rule.executed; r.variable = rule.variable; r.value = rule.value; r.item = rule.item; r.character = rule.character; r.hit = rule.hit; r.angry = rule.angry; r.performative = rule.performative; for (var _i = 0, _a = rule.effects; _i < _a.length; _i++) { var s = _a[_i]; r.effects.push(A4Script.fromA4Script(s)); } return r; }; A4EventRule.prototype.outerHTML = function () { return this.saveToXML(); }; A4EventRule.prototype.saveToXML = function () { var xmlString = ""; if (this.once && this.executed) return xmlString; // it has already been executed, so, no need to save it! // event rules: xmlString += " this.lastTimeGameStoryStateChanged) { this.lastTimeGameStoryStateChanged = game.cycle; if (game.getStoryStateVariable(this.variable) == this.value) { // console.log("Executing effect for game story state " + this.variable + " == " + this.value + "..."); return this.executeEffects(o, map, game, otherCharacter); } } break; case A4_STORYSTATE_MAP: if (map.lastTimeStoryStateChanged > this.lastTimeMapStoryStateChanged) { this.lastTimeMapStoryStateChanged = game.cycle; if (map.getStoryStateVariable(this.variable) == this.value) { return this.executeEffects(o, map, game, otherCharacter); } } break; case A4_STORYSTATE_OBJECT: if (o.lastTimeStoryStateChanged > this.lastTimeObjectStoryStateChecked) { // console.log("object story state check 1 ("+o.ID+"): " + o.lastTimeStoryStateChanged + " > " + this.lastTimeObjectStoryStateChecked); // console.log("object story state check 1 ("+o.ID+"): " + this.variable + " == " + this.value + " (" + o.getStoryStateVariable(this.variable) + ")"); this.lastTimeObjectStoryStateChecked = game.cycle; if (o.getStoryStateVariable(this.variable) == this.value) { // console.log("object story state rule triggered: " + o.lastTimeStoryStateChanged + " > " + this.lastTimeObjectStoryStateChecked); return this.executeEffects(o, map, game, otherCharacter); } } break; } break; } return SCRIPT_FINISHED; }; return A4EventRule; }());