/// /// /// /// /// /// /// module WorldState { var worldTurn : number = 0; var playerTurn : number = 0; export var player : Humanoid = new Humanoid({isMale : false, name : "Player", unique : true}); player.description = Humanoid.getPlayerDescription; var memoryRooms = new StoredVariable>({ id : "Remembered Rooms", value : [] }); let allRememberedRooms : Array = []; let rememberedRoomsForIntelligence = 2; let rememberedRoomsForSurvival = 1; export var RememberingRoomRulebook : Rulebook = new Rulebook("Remembering Room something"); export function isTurnWaiting () { return worldTurn < playerTurn; } export function incrementWorldTurn () { worldTurn++; } export function incrementPlayerTurn () { playerTurn++; } export function getCurrentTurn () { return playerTurn; } export function setCurrentTurn (turn : number) { playerTurn = turn; worldTurn = turn; } export let RememberingRoomInList = RememberingRoomRulebook.createAndAddRule({ name : "Is room listed in remembered rooms?", firstPriority : Rule.PRIORITY_LOWEST, priority : Rule.PRIORITY_LOW, code : runner => { if (allRememberedRooms.includes(runner.noun)) { return true; } } }); export let RememberingRoomInMap = RememberingRoomRulebook.createAndAddRule({ name : "Is room shown on a map?", firstPriority : Rule.PRIORITY_LOWEST, priority : Rule.PRIORITY_LOWEST, code : runner => { let maps = > Thing.CarryRelation.getRightType(player, MapNote); for (let i = 0; i < maps.length; i++) { if (maps[i].contains(runner.noun)) { return true; } } } }); export function isPlayer (thing : any) { return player === thing; } export async function isRoomRemembered (room : Room) : Promise { if (room == WorldState.player.getRoom()) return true; let result = await RememberingRoomRulebook.execute({noun : room}); return result == true; // can return "undefined" } export function getRememberedRooms () { let roomNames = []; allRememberedRooms.forEach(room => { roomNames.push(room.getName()); }); return roomNames; } export function getRememberedRoomsAsRooms () : Array { return [...allRememberedRooms]; } export function getMaximumRememberedRooms () { let intRooms = player.getStat(Attributes.Intelligence) * rememberedRoomsForIntelligence; let skillRooms = player.getSkill(Skills.Survival) * rememberedRoomsForSurvival; return intRooms + skillRooms; } export function truncateRooms () { while (allRememberedRooms.length > getMaximumRememberedRooms()){ allRememberedRooms.pop(); } } export function rememberRoom (...rooms : Array) { rooms.forEach((value) => { if (value instanceof Room) { let idx = allRememberedRooms.indexOf(value); if (idx == -1) { allRememberedRooms.unshift(value); } else { allRememberedRooms.splice(idx, 1); allRememberedRooms.unshift(value); } value.visited = true; } }); truncateRooms(); } export function saveState () { let things = { carried: [], worn: [], wielded: [] }; return { Things : things }; } export let CorrectRememberedRoomsRule = PlayBegins.rulebook.createAndAddRule({ name : "Correct remembered rooms", firstPriority : Rule.PRIORITY_LOWEST, priority : Rule.PRIORITY_MEDIUM, code : () => { if (memoryRooms.value.length > 0 && allRememberedRooms.length == 0) { // loading a save memoryRooms.value.forEach(roomName => { let room = Room.getRoom(roomName); allRememberedRooms.push(room); // Already ordered }); truncateRooms(); } if (!isRoomRemembered(WorldState.player.getRoom())) { rememberRoom(WorldState.player.getRoom()); } let cleanRoomNames = []; allRememberedRooms.forEach(room => { if (!room.fodder) { cleanRoomNames.push(room.getName()); } }); memoryRooms.value = cleanRoomNames; // let allRooms = rememberedRooms.value; // let currentRoom = WorldState.player.getRoom(); // if (allRooms.length == 0) { // rememberedRooms.value = [currentRoom.getName()]; // return; // } // let newRooms = []; // // let tentativeFodder = []; // function recursivelyAddRooms (room : Room) { // if (room instanceof RoomRandom) { // if (room.fodder && !tentativeFodder.includes(room)) { // tentativeFodder.push(room); // room.connections.forEach((newRoom) => { // recursivelyAddRooms(newRoom); // }); // } else if (allRooms.indexOf(room.getName()) != -1 && newRooms.indexOf(room.getName()) == -1) { // tentativeFodder.forEach(fodder => { // rememberedFodder.push(fodder); // }); // tentativeFodder = []; // newRooms.push(room.getName()); // room.connections.forEach((newRoom) => { // recursivelyAddRooms(newRoom); // }); // } // } // } // // recursivelyAddRooms(currentRoom); // rememberedRooms.value = newRooms; } }) }