Files
burrow-server/swf-src/AJClient.as
T

1988 lines
70 KiB
ActionScript

package
{
import avatar.AvatarManager;
import avatar.AvatarWorldView;
import com.sbi.debug.DebugUtility;
import den.DenItem;
import item.Item;
import com.sbi.loader.ResourceStack;
import com.sbi.popup.SBOkPopup;
import com.sbi.popup.SBStandardPopup;
import com.sbi.popup.SBYesNoPopup;
import createAccountFlow.CreateAccount;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.UncaughtErrorEvent;
import flash.external.ExternalInterface;
import flash.system.Capabilities;
import flash.system.Security;
import flash.ui.Mouse;
import flash.utils.Dictionary;
import flash.utils.Timer;
import flash.utils.getTimer;
import game.MinigameManager;
import gamePlayFlow.GamePlay;
import gskinner.motion.GTween;
import gui.DarkenManager;
import gui.GuiManager;
import loadProgress.LoadProgress;
import loader.DefPacksDefHelper;
import localization.LocalizationManager;
import resource.LoadAvatarCarouselResourceStackable;
import resource.LoadCursorResourceStackable;
import room.DebugGUITextbox;
import room.RoomManagerWorld;
import waitingRoomFlow.WaitingRoom;
[SWF(width="900", height="550", backgroundColor="#393625", frameRate="24")]
public class AJClient extends Sprite
{
private static var _globalDebugLog:DebugGUITextbox;
private static var _toolsInstance:AJClient;
private var _resourceStackLoader:ResourceStack;
private var _finder:Sprite;
private var _finderPanel:Sprite;
private var _finderInputBar:MovieClip;
private var _finderColourBar:MovieClip;
private var _finderInput:TextField;
private var _finderStatus:TextField;
private var _finderPageLabel:TextField;
private var _finderKindButton:MovieClip;
private var _finderRows:Sprite;
private var _finderResults:Array;
private var _finderTotal:int;
private var _finderPage:int;
private var _finderKind:int;
private var _finderColourInput:TextField;
public function AJClient()
{
super();
addEventListener("addedToStage",addedToStageHandler);
}
public static function get globalDebugLog() : DebugGUITextbox
{
return _globalDebugLog;
}
private function addedToStageHandler(param1:Event) : void
{
var _loc2_:Object = null;
var _loc3_:int = 0;
removeEventListener("addedToStage",addedToStageHandler);
addEventListener("enterFrame",onSmoothFrame);
try
{
if(ExternalInterface.available)
{
ExternalInterface.addCallback("ajHud",setHudShown);
}
}
catch(e:Error)
{
}
// the official client lets a SWF from any domain reach into it here
// (Security.allowDomain("*")). on this server the page, the client
// and every asset come from one address, so nothing needs that, and
// a stranger's SWF that got itself loaded must not have it.
var _loc4_:Boolean = ExternalInterface.available;
if(_loc4_)
{
DebugUtility.debugTrace("addedToStageHandler - extIntAvail is true");
DebugUtility.debugTrace("mrc dm init ctor starting up call returned:" + ExternalInterface.call("mrc",["dm","AJClient addedToStageHandler starting up"]));
ExternalInterface.call("handleGAEvent","flashStarted");
}
else
{
DebugUtility.debugTrace("addedToStageHandler - extIntAvail is false");
}
if(!MainFrame.isInitialized())
{
if(parent != null)
{
if(parent.hasOwnProperty("flashVars"))
{
_loc2_ = parent["flashVars"];
}
else
{
_loc2_ = parent.loaderInfo.parameters;
}
}
else
{
_loc2_ = loaderInfo.parameters;
}
DebugUtility.debugTrace("addedToStageHandler - printing loaderInfo parameters flashvars...");
_loc3_ = 0;
for(var _loc5_:String in _loc2_)
{
DebugUtility.debugTrace(" flashvar " + _loc5_ + ":" + _loc2_[_loc5_]);
_loc3_++;
}
DebugUtility.debugTrace("addedToStageHandler - ...done printing loaderInfo parameters flashvars - i:" + _loc3_);
MainFrame.handleLocalExternalCall = GamePlay.handleLocalExternalCall;
MainFrame.getInstance(_loc2_,setupInit,"",this);
LoadProgress.updateProgress(2);
_globalDebugLog = new DebugGUITextbox(this,"","Debug Log [F4]",false,true,true,750,276,true);
_globalDebugLog.x = 80;
_globalDebugLog.y = 50;
DebugUtility.setDebugGUIHandler(_globalDebugLog.appendHtml);
loaderInfo.uncaughtErrorEvents.addEventListener("uncaughtError",handleGlobalErrors);
}
DebugUtility.debugTrace("AJClient addedToStageHandler finished");
}
public function setupInit() : void
{
gMainFrame.stage.addEventListener("Localization",LocalizationManager.onLocalizationEvent,false,0,true);
LocalizationManager.currentLanguage = LocalizationManager.accountLanguage = LocalizationManager.getLanguageIdForLocale(gMainFrame.clientInfo.locale);
LocalizationManager.countryCode = gMainFrame.clientInfo.countryCode;
var _loc1_:DefPacksDefHelper = new DefPacksDefHelper();
_loc1_.init(uint("1023" + LocalizationManager.currentLanguage),LocalizationXtCommManager.onLocalizationListResponse,loadResourceItems,2);
DefPacksDefHelper.mediaArray["1023" + LocalizationManager.currentLanguage] = _loc1_;
_loc1_ = new DefPacksDefHelper();
_loc1_.init(uint("1055" + LocalizationManager.accountLanguage),LocalizationXtCommManager.onPreferredLocalizationListResponse,null,2);
DefPacksDefHelper.mediaArray["1055" + LocalizationManager.accountLanguage] = _loc1_;
}
public function loadResourceItems() : void
{
LoadProgress.updateProgress(3);
Utility.init(DarkenManager.showLoadingSpiral,DarkenManager.darken,DarkenManager.unDarken);
_resourceStackLoader = new ResourceStack(gMainFrame.path,gMainFrame.loaderCache.openFile);
_resourceStackLoader.pushFile("assets/sharedFonts.swf",true);
_resourceStackLoader.pushFile("assets/HUDAssets.swf",true);
if(gMainFrame.clientInfo.isCreateAccount)
{
_resourceStackLoader.pushClass(new LoadAvatarCarouselResourceStackable());
}
if(Mouse["supportsNativeCursor"])
{
_resourceStackLoader.pushClass(new LoadCursorResourceStackable());
}
if(ExternalInterface.available)
{
ExternalInterface.call("aj_initialized");
}
if("failedToInitiate" in gMainFrame.clientInfo && gMainFrame.clientInfo.failedToInitiate == true)
{
_resourceStackLoader.start(onInitiationFailure);
}
else if(gMainFrame.clientInfo.isCreateAccount)
{
_resourceStackLoader.start(setupCreateAccount);
}
else if(gMainFrame.clientInfo.waitingMode)
{
_resourceStackLoader.start(setupWaitingRoom);
}
else
{
_resourceStackLoader.start(setupGamePlay);
}
}
public function setupCreateAccount() : void
{
var _loc1_:CreateAccount = new CreateAccount(gMainFrame.clientInfo);
addChild(_loc1_);
gMainFrame.createAccount = _loc1_;
_loc1_.loginCtorHelper();
}
public function setupWaitingRoom() : void
{
var _loc1_:WaitingRoom = new WaitingRoom(gMainFrame.clientInfo);
addChild(_loc1_);
gMainFrame.waitingRoom = _loc1_;
_loc1_.waitCtorHelper();
}
public function setupGamePlay(param1:Event = null, param2:Event = null) : void
{
DebugUtility.debugTrace("setupGamePlay - loginEvt:" + param1 + " connectEvt:" + param2);
if(gMainFrame.createAccount)
{
if(contains(gMainFrame.createAccount))
{
removeChild(gMainFrame.createAccount);
}
gMainFrame.createAccount = null;
_resourceStackLoader = null;
}
DebugUtility.debugTrace("setupGamePlay - constructing GamePlay - gMainFrame.clientInfo:" + gMainFrame.clientInfo);
var _loc3_:GamePlay = new GamePlay(gMainFrame.clientInfo,param1,param2);
addChild(_loc3_);
gMainFrame.gamePlay = _loc3_;
DebugUtility.debugTrace("setupGamePlay - gp:" + _loc3_ + " calling worldCtorHelper");
_loc3_.worldCtorHelper();
setupItemFinder();
}
private function setupItemFinder() : void
{
if(_toolsInstance != null)
{
return;
}
_toolsInstance = this;
_finderResults = [];
try
{
loadFilterLists();
}
catch(e:Error)
{
GlobalErrorCatch.reportToServer("chat filter: " + e);
}
gMainFrame.stage.addEventListener("keyDown",onFinderKey,true,1000);
gMainFrame.stage.addEventListener("keyDown",onFinderKey,false,1000);
}
public static function openTool(param1:int) : void
{
if(_toolsInstance == null)
{
return;
}
try
{
if(param1 == 1)
{
_toolsInstance.showChatFilter(true);
}
else
{
_toolsInstance.showItemFinder(true);
}
}
catch(e:Error)
{
GlobalErrorCatch.reportToServer((param1 == 1 ? "chat filter: " : "item finder: ") + e + "\n" + e.getStackTrace());
}
}
// when a player was last seen, for their card: param1 is the time in
// seconds the server sends in place of "days since last login".
// "12:13 (1 hour ago)" within a day, "10:45 October 10 (1 day ago)"
// within thirty, "8:44 January 1 2026" beyond. in this computer's
// time zone.
public static function lastSeenText(param1:int) : String
{
var _loc2_:Array = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var _loc3_:Date = new Date(param1 * 1000);
var _loc4_:Number = Math.max(0,Math.floor((new Date().time - _loc3_.time) / 60000));
var _loc5_:int = int(_loc4_ / 60);
var _loc6_:int = int(_loc4_ / 1440);
var _loc7_:String = _loc3_.hours + ":" + (_loc3_.minutes < 10 ? "0" : "") + _loc3_.minutes;
if(_loc6_ >= 30)
{
return _loc7_ + " " + _loc2_[_loc3_.month] + " " + _loc3_.date + " " + _loc3_.fullYear;
}
if(_loc6_ >= 1)
{
return _loc7_ + " " + _loc2_[_loc3_.month] + " " + _loc3_.date + " (" + _loc6_ + (_loc6_ == 1 ? " day ago)" : " days ago)");
}
if(_loc5_ >= 1)
{
return _loc7_ + " (" + _loc5_ + (_loc5_ == 1 ? " hour ago)" : " hours ago)");
}
if(_loc4_ >= 1)
{
return _loc7_ + " (" + _loc4_ + (_loc4_ == 1 ? " minute ago)" : " minutes ago)");
}
return _loc7_ + " (just now)";
}
public static function setTheme(param1:String) : void
{
var _loc2_:URLRequest = new URLRequest(gMainFrame.clientInfo.websiteURL + "api/theme");
_loc2_.method = "POST";
_loc2_.contentType = "application/json";
_loc2_.data = JSON.stringify({
"username":gMainFrame.server.userName,
"token":gMainFrame.clientInfo.authToken,
"theme":param1
});
var _loc3_:URLLoader = new URLLoader();
_loc3_.addEventListener("ioError",onThemeFailed);
_loc3_.addEventListener("securityError",onThemeFailed);
_loc3_.load(_loc2_);
}
// " (have 2)" after the name of a shop item the player owns already.
public static function ownedSuffix(param1:Object) : String
{
var _loc2_:int = 0;
var _loc3_:int = 0;
var _loc4_:Object = null;
try
{
if(param1 is Item)
{
_loc4_ = gMainFrame.userInfo.playerAvatarInfo.getFullItems();
while(_loc3_ < _loc4_.length)
{
if(_loc4_.getAccItem(_loc3_).defId == param1.defId)
{
_loc2_++;
}
_loc3_++;
}
}
else if(param1 is DenItem)
{
_loc4_ = AvatarManager.playerAvatar.inventoryDenFull.denItemCollection;
while(_loc3_ < _loc4_.length)
{
if(_loc4_.getDenItem(_loc3_).defId == param1.defId)
{
_loc2_++;
}
_loc3_++;
}
}
}
catch(e:Error)
{
return "";
}
return _loc2_ > 0 ? " (have " + _loc2_ + ")" : "";
}
// "xls" from the server: when each offline buddy was last seen, for
// the buddy list's rows. [.., .., count, (username, seconds)...]
private static var _lastSeen:Object = {};
public static function noteLastSeen(param1:Object) : void
{
var _loc2_:int = int(param1[2]);
var _loc3_:int = 0;
_lastSeen = {};
while(_loc3_ < _loc2_)
{
_lastSeen[String(param1[3 + _loc3_ * 2]).toLowerCase()] = int(param1[4 + _loc3_ * 2]);
_loc3_++;
}
}
// " (5m)", " (3h)", " (12d)", " (Jan 2025)" after an offline buddy's
// name; nothing when it is not known.
public static function lastSeenShort(param1:String) : String
{
var _loc2_:Array = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var _loc3_:int = int(_lastSeen[param1.toLowerCase()]);
var _loc4_:Date = new Date(_loc3_ * 1000);
var _loc5_:Number = Math.max(0,Math.floor((new Date().time - _loc4_.time) / 60000));
if(_loc3_ < 100000)
{
return "";
}
if(_loc5_ < 60)
{
return " (" + Math.max(1,_loc5_) + "m)";
}
if(_loc5_ < 1440)
{
return " (" + int(_loc5_ / 60) + "h)";
}
if(_loc5_ < 43200)
{
return " (" + int(_loc5_ / 1440) + "d)";
}
return " (" + _loc2_[_loc4_.month] + " " + _loc4_.fullYear + ")";
}
// "Joined Oct 2026", for the label on a player's card.
public static function joinedText(param1:int) : String
{
var _loc2_:Array = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var _loc3_:Date = new Date(param1 * 1000);
return param1 > 100000 ? "Joined " + _loc2_[_loc3_.month] + " " + _loc3_.fullYear : "";
}
// is the game's own font there to be used in a text field made here?
public static function hasGameFont() : Boolean
{
for each(var _loc1_:Font in Font.enumerateFonts(false))
{
if(_loc1_.fontName == "CCDigitalDelivery")
{
return true;
}
}
return false;
}
// an oval label: white text in the game's font on a colour, with a
// darker edge, and room on the left for an icon when param4 is set.
// used for "Banned" and "Joined" on player cards and for buttons the
// artwork has none for.
public static function makePill(param1:String, param2:uint, param3:uint, param4:Boolean = false, param5:int = 12) : Sprite
{
var _loc6_:Sprite = new Sprite();
var _loc7_:TextField = new TextField();
var _loc8_:int = param5 + 10;
var _loc9_:Number = 0;
_loc7_.embedFonts = hasGameFont();
_loc7_.selectable = false;
_loc7_.mouseEnabled = false;
_loc7_.autoSize = "left";
_loc7_.defaultTextFormat = new TextFormat("CCDigitalDelivery",param5,16777215,true);
_loc7_.text = param1;
_loc7_.name = "txt";
_loc7_.x = param4 ? _loc8_ + 6 : 10;
_loc7_.y = int((_loc8_ - _loc7_.height) * 0.5);
_loc9_ = _loc7_.x + _loc7_.width + 9;
_loc6_.graphics.lineStyle(2,param3);
_loc6_.graphics.beginFill(param2);
_loc6_.graphics.drawRoundRect(0,0,_loc9_,_loc8_,_loc8_,_loc8_);
_loc6_.graphics.endFill();
_loc6_.addChild(_loc7_);
_loc6_.mouseChildren = false;
return _loc6_;
}
// "xtl": [.., .., text]. A plain message box; what a chat command says.
public static function showMessage(param1:Object) : void
{
new SBOkPopup(GuiManager.guiLayer,String(param1[2]));
}
// "xyn": [.., .., id, text]. A yes-or-no box; the answer goes back as
// "xyn" [id, 1 | 0].
public static function askYesNo(param1:Object) : void
{
new SBYesNoPopup(GuiManager.guiLayer,String(param1[3]),true,onYesNo,int(param1[2]));
}
private static function onYesNo(param1:Object) : void
{
gMainFrame.server.setXtObject_Str("xyn",[param1.passback,param1.status ? 1 : 0]);
}
// "xw": a whisper. [.., .., 1]: the chat line that follows is one, and
// its bubble is drawn light green (gui.ChatBalloon reads whisperNext).
// [.., .., 0, from, text]: from another room, so a message box, in
// the same green.
public static var whisperNext:Boolean = false;
public static function onWhisper(param1:Object) : void
{
var _loc2_:SBOkPopup = null;
if(String(param1[2]) == "1")
{
whisperNext = true;
return;
}
// through the reader's chat filter, as a bubble would be.
var _loc3_:String = filterText(String(param1[4]));
if(_loc3_ == null)
{
return;
}
_loc2_ = new SBOkPopup(GuiManager.guiLayer,String(param1[3]) + " whispers:\n" + _loc3_);
_loc2_.transform.colorTransform = whisperTint();
}
public static function whisperTint() : ColorTransform
{
return new ColorTransform(0.72,1,0.72,1,0,18,0,0);
}
private static var _renaming:Dictionary = new Dictionary(true);
private static var _renameField:TextField;
private static var _renameOld:String;
private static var _renameHosts:Dictionary = new Dictionary(true);
private static var _nameDownField:TextField;
private static var _nameDownAt:int;
// makes a name's text field one that a double click turns into a box
// to type in. param2 is "a" or "p", param3 the animal's perUserAvId or
// the pet's inventory id; param4, if given, is told the new name once
// the server has taken it. param5 is what hears the mouse there (the
// cell or window the name is drawn in: the artwork's text fields hear
// nothing themselves), so the presses are caught on it, ahead of its
// own listeners, and those on the name are kept from them.
public static function makeRenamable(param1:TextField, param2:String, param3:int, param4:Function, param5:DisplayObject) : void
{
if(param1 == null || param5 == null)
{
return;
}
_renaming[param1] = {
"kind":param2,
"id":param3,
"done":param4
};
_renameHosts[param5] = param1;
param5.addEventListener("mouseDown",onRenameHostDown,true,1000,true);
param5.addEventListener("mouseDown",onRenameHostDown,false,1000,true);
}
private static function onRenameHostDown(param1:MouseEvent) : void
{
var _loc2_:TextField = _renameHosts[param1.currentTarget];
var _loc3_:int = getTimer();
if(_loc2_ == null || _loc2_.stage == null || _renaming[_loc2_] == null)
{
return;
}
if(!_loc2_.getBounds(_loc2_.stage).contains(param1.stageX,param1.stageY))
{
if(_renameField == _loc2_)
{
endRename(true);
}
return;
}
param1.stopImmediatePropagation();
if(_renameField != null)
{
return;
}
if(_nameDownField == _loc2_ && _loc3_ - _nameDownAt < 500)
{
_nameDownField = null;
startRename(_loc2_);
return;
}
_nameDownField = _loc2_;
_nameDownAt = _loc3_;
}
private static function startRename(param1:TextField) : void
{
_renameField = param1;
_renameOld = param1.text;
param1.type = "input";
param1.selectable = true;
param1.mouseEnabled = true;
param1.maxChars = 20;
param1.restrict = "A-Za-z0-9 '.\\-";
param1.addEventListener("keyDown",onRenameKey,false,0,true);
param1.addEventListener("focusOut",onRenameFocusOut,false,0,true);
gMainFrame.stage.focus = param1;
param1.setSelection(0,param1.text.length);
}
private static function onRenameKey(param1:KeyboardEvent) : void
{
param1.stopPropagation();
if(param1.keyCode == 13)
{
endRename(true);
}
else if(param1.keyCode == 27)
{
endRename(false);
}
}
private static function onRenameFocusOut(param1:Event) : void
{
endRename(true);
}
private static function endRename(param1:Boolean) : void
{
var _loc2_:TextField = _renameField;
var _loc3_:Object = null;
var _loc4_:String = null;
if(_loc2_ == null)
{
return;
}
_renameField = null;
_loc3_ = _renaming[_loc2_];
_loc4_ = _loc2_.text.replace(/^\s+|\s+$/g,"");
_loc2_.removeEventListener("keyDown",onRenameKey);
_loc2_.removeEventListener("focusOut",onRenameFocusOut);
_loc2_.type = "dynamic";
_loc2_.selectable = false;
_loc2_.setSelection(0,0);
if(gMainFrame.stage.focus == _loc2_)
{
gMainFrame.stage.focus = null;
}
if(!param1 || _loc3_ == null || _loc4_.length == 0 || _loc4_ == _renameOld)
{
_loc2_.text = _renameOld;
return;
}
_loc2_.text = _loc4_;
_loc3_.old = _renameOld;
_loc3_.field = _loc2_;
_pendingRenames[_loc3_.kind + ":" + _loc3_.id] = _loc3_;
gMainFrame.server.setXtObject_Str("xrn",[_loc3_.kind,_loc3_.id,_loc4_]);
}
private static var _pendingRenames:Object = {};
// "xrn": [.., .., kind, id, 1 | 0, the name as it now is]
public static function onRenamed(param1:Object) : void
{
var _loc2_:String = String(param1[2]) + ":" + String(param1[3]);
var _loc3_:Object = _pendingRenames[_loc2_];
delete _pendingRenames[_loc2_];
if(_loc3_ == null)
{
return;
}
if(String(param1[4]) != "1")
{
_loc3_.field.text = _loc3_.old;
new SBOkPopup(GuiManager.guiLayer,"Names are letters, digits and spaces, up to 20 long.");
}
else if(_loc3_.done != null)
{
_loc3_.done(String(param1[5]));
}
}
// ---- items picked several at a time (the item picker, recycling)
//
// which items are picked, by kind and inventory id. an item cell
// (gui.itemWindows.ItemWindowOriginal) draws its green ring from this,
// so a pick stays shown through scrolling, tabs and searches.
private static var _picked:Object = {};
public static var pickedCount:int = 0;
public static function pickKey(param1:Object) : String
{
return (param1 is Item ? "c" : (param1 is DenItem ? "d" : "p")) + param1.invIdx;
}
public static function isPicked(param1:Object) : Boolean
{
return param1 != null && _picked[pickKey(param1)] != null;
}
public static function setPicked(param1:Object, param2:Boolean) : void
{
var _loc3_:String = pickKey(param1);
if(param2 && _picked[_loc3_] == null)
{
_picked[_loc3_] = param1;
pickedCount++;
}
else if(!param2 && _picked[_loc3_] != null)
{
delete _picked[_loc3_];
pickedCount--;
}
}
public static function pickedItems() : Array
{
var _loc1_:Array = [];
for each(var _loc2_:Object in _picked)
{
_loc1_.push(_loc2_);
}
return _loc1_;
}
public static function clearPicked() : void
{
_picked = {};
pickedCount = 0;
}
// ---- the HUD shown or not, from the client's top bar (ajHud in the
// game's page calls setHudShown). the game shows its HUD again by
// itself on the way into a room, so while it is to be hidden it is
// hidden again every frame (onSmoothFrame).
private static var _hudHidden:Boolean;
private static function setHudShown(param1:Boolean) : void
{
_hudHidden = !param1;
try
{
if(GuiManager.mainHud == null)
{
return;
}
if(_hudHidden)
{
GuiManager.mainHud.visible = false;
gMainFrame.stage.focus = null;
}
else if(!AvatarManager.isMyAvtInPreviewRoom && !MinigameManager.inMinigame())
{
// where the game keeps it hidden itself, it stays so.
GuiManager.mainHud.visible = true;
}
}
catch(e:Error)
{
}
}
// ---- smooth graphics, and the settings behind it
//
// the game draws 24 pictures a second and moves everything once a
// picture. with "Graphics: Smooth" what the game moves by the clock is
// also moved between two pictures and the screen drawn again each
// time: animals that are walking, the camera, and the windows and tabs
// that slide (GTween). the drawing quality is "high" where the game
// keeps "medium", and a click or a key is acted on at once. the 24
// frames themselves are left alone, so nothing that counts frames
// (animations, the rooms' own artwork, minigames) runs any faster; in
// a minigame all of this is off.
//
// the settings, user vars of this server's own, in the settings menu
// (gui.itemWindows.ItemWindowToggle):
// 9003 Graphics: 1 Default (the game as it was: all of it off; not
// called "Performance", since it is little lighter on any but
// the weakest machine), 2 Smooth; unset is
// the server's default (config.smooth: it sends 1 or nothing).
// 9004 Frame rate: 1 is 60; anything else is Max, as fast as the
// timer goes (about 80 a second on the owner's machine, where
// the 120 and 144 this once offered came to the same).
// 9005 Camera: 1 Smooth (room.RoomManagerWorld.easeCamera), else the
// game's own.
private static var _smoothTimer:Timer;
private static var _smoothAt:int; // when things were last moved, by a frame or between two
private static var _smoothQuality:Boolean; // the quality is ours at the moment
private static var _smoothBroken:Boolean; // it threw three times: off until the game is started again
private static var _smoothErrors:int;
private static var _drawn:int; // pictures since the count was last told
private static var _drawnSince:int;
private static function settingOf(param1:int) : int
{
return int(gMainFrame.userInfo.userVarCache.getUserVarValueById(param1));
}
public static function smoothOn() : Boolean
{
return settingOf(9003) != 1;
}
// pictures a second asked for, or 0 for no limit.
public static function frameRate() : int
{
return settingOf(9004) == 1 ? 60 : 0;
}
public static function cameraEases() : Boolean
{
var _loc1_:Boolean = false;
try
{
_loc1_ = smoothOn() && settingOf(9005) == 1;
}
catch(e:Error)
{
}
return _loc1_;
}
// every frame: whether the extra steps should be running just now, and
// once a second how many pictures were drawn, for the client's top bar
// (ajFps in the game's page).
private function onSmoothFrame(param1:Event) : void
{
var _loc2_:Boolean = false;
var _loc3_:int = getTimer();
var _loc4_:int = 0;
_smoothAt = _loc3_;
_drawn++;
if(_hudHidden && GuiManager.mainHud != null && GuiManager.mainHud.visible)
{
GuiManager.mainHud.visible = false;
}
if(_loc3_ - _drawnSince >= 1000)
{
try
{
if(ExternalInterface.available)
{
ExternalInterface.call("ajFps",Math.round(_drawn * 1000 / (_loc3_ - _drawnSince)));
}
}
catch(e:Error)
{
}
_drawn = 0;
_drawnSince = _loc3_;
}
try
{
_loc2_ = !_smoothBroken && MainFrame.isInitialized() && gMainFrame.userInfo != null && gMainFrame.userInfo.userVarCache != null && AvatarManager.playerAvatarWorldView != null && !MinigameManager.inMinigame() && smoothOn();
}
catch(e:Error)
{
_loc2_ = false;
}
if(_loc2_)
{
_loc4_ = frameRate() > 0 ? Math.round(1000 / frameRate()) : 1;
if(_smoothTimer == null)
{
_smoothTimer = new Timer(_loc4_);
_smoothTimer.addEventListener("timer",onSmoothTimer);
}
if(_smoothTimer.delay != _loc4_)
{
_smoothTimer.delay = _loc4_;
}
if(!_smoothTimer.running)
{
_smoothTimer.start();
}
if(gMainFrame.stage.quality != "HIGH")
{
gMainFrame.stage.quality = "high";
}
_smoothQuality = true;
}
else
{
if(_smoothTimer != null && _smoothTimer.running)
{
_smoothTimer.stop();
}
if(_smoothQuality)
{
_smoothQuality = false;
gMainFrame.stage.quality = gMainFrame.currStageQuality != null ? gMainFrame.currStageQuality : "medium";
}
}
}
// between two frames: every animal that is walking goes on by the
// time since it last moved, the camera follows the player's, sliding
// windows slide on, and if any of that moved the screen is drawn.
private static function onSmoothTimer(param1:TimerEvent) : void
{
var _loc2_:int = getTimer();
var _loc3_:int = _loc2_ - _smoothAt;
var _loc4_:Object = null;
var _loc5_:AvatarWorldView = null;
var _loc6_:Boolean = false;
// too soon after the last step for the rate asked for, or a pause
// too long to be a step.
if(_loc3_ < 1 || _loc3_ * 2 < _smoothTimer.delay || _loc3_ > 100)
{
return;
}
try
{
_loc4_ = AvatarManager.avatarViewList;
for each(_loc5_ in _loc4_)
{
if(_loc5_ != null && _loc5_.glide(_loc3_))
{
_loc6_ = true;
}
}
_smoothAt = _loc2_;
if(RoomManagerWorld.instance.glideCamera(_loc3_))
{
_loc6_ = true;
}
if(GTween.tickNow())
{
_loc6_ = true;
}
if(_loc6_)
{
_drawn++;
param1.updateAfterEvent();
}
}
catch(e:Error)
{
// #1502, "a script ran too long", is not this code's: the game
// gets it now and then whatever is running (it is in the notes
// as a known problem), and one step lost to it is nothing.
// anything else three times and it is this code that is wrong.
if(e.errorID != 1502)
{
_smoothErrors++;
if(_smoothErrors >= 3)
{
_smoothBroken = true;
_smoothTimer.stop();
GlobalErrorCatch.reportToServer("smooth graphics stopped: " + e + "\n" + e.getStackTrace());
}
}
}
}
public static function wasdOn() : Boolean
{
return gMainFrame.userInfo.userVarCache.getUserVarValueById(9002) == 1;
}
// the arrow key a key stands for: itself, or with the setting on and
// nothing being typed, the arrow W, A, S or D stands for.
public static function moveKey(param1:int) : int
{
if(param1 < 65 || param1 > 87 || gMainFrame.stage.focus is TextField || !wasdOn())
{
return param1;
}
switch(param1)
{
case 87:
return 38;
case 65:
return 37;
case 83:
return 40;
case 68:
return 39;
}
return param1;
}
// A short list of words to pick from, drawn here: the game's sort
// menu was pictures. param1 the words, param2 is told the one picked
// (its place in the list), param3 the one to mark as the current one.
public static function makeTextMenu(param1:Array, param2:Function, param3:int = -1) : Sprite
{
var _loc4_:Sprite = new Sprite();
var _loc5_:int = 0;
var _loc6_:Sprite = null;
var _loc7_:TextField = null;
var _loc8_:int = 78;
var _loc9_:int = 19;
// one panel in the inventory's colours, a row of it per word.
_loc4_.graphics.lineStyle(2,8349508);
_loc4_.graphics.beginFill(16774084);
_loc4_.graphics.drawRoundRect(0,0,_loc8_ + 8,param1.length * _loc9_ + 8,14,14);
_loc4_.graphics.endFill();
while(_loc5_ < param1.length)
{
_loc6_ = new Sprite();
_loc6_.graphics.beginFill(3184463,_loc5_ == param3 ? 1 : 0);
_loc6_.graphics.drawRoundRect(0,0,_loc8_,_loc9_ - 1,10,10);
_loc6_.graphics.endFill();
_loc7_ = new TextField();
_loc7_.embedFonts = hasGameFont();
_loc7_.selectable = false;
_loc7_.autoSize = "left";
_loc7_.defaultTextFormat = new TextFormat("CCDigitalDelivery",12,_loc5_ == param3 ? 16777215 : 6045213,true);
_loc7_.text = param1[_loc5_];
_loc7_.x = 8;
_loc7_.y = int((_loc9_ - 1 - _loc7_.height) * 0.5);
_loc6_.addChild(_loc7_);
_loc6_.x = 4;
_loc6_.y = 4 + _loc5_ * _loc9_;
_loc6_.name = "pick" + _loc5_;
_loc6_.buttonMode = true;
_loc6_.mouseChildren = false;
_loc6_.addEventListener("mouseDown",onTextMenuPick,false,0,false);
_loc4_.addChild(_loc6_);
_loc5_++;
}
_textMenuCallbacks[_loc4_] = param2;
return _loc4_;
}
private static var _textMenuCallbacks:Dictionary = new Dictionary(true);
private static function onTextMenuPick(param1:MouseEvent) : void
{
var _loc2_:Sprite = param1.currentTarget as Sprite;
var _loc3_:Function = _textMenuCallbacks[_loc2_.parent];
param1.stopPropagation();
if(_loc3_ != null)
{
_loc3_(int(_loc2_.name.substr(4)));
}
}
// runs one of the chat commands the settings menu's Outfits and Den
// layouts lists stand for (the server takes only those).
public static function runCommand(param1:String) : void
{
var _loc2_:URLRequest = new URLRequest(gMainFrame.clientInfo.websiteURL + "api/command");
_loc2_.method = "POST";
_loc2_.contentType = "application/json";
_loc2_.data = JSON.stringify({
"username":gMainFrame.server.userName,
"token":gMainFrame.clientInfo.authToken,
"text":param1
});
var _loc3_:URLLoader = new URLLoader();
_loc3_.addEventListener("ioError",onThemeFailed);
_loc3_.addEventListener("securityError",onThemeFailed);
_loc3_.load(_loc2_);
}
private static function onThemeFailed(param1:Event) : void
{
GlobalErrorCatch.reportToServer("theme change failed: " + param1);
}
// ---- the chat filter
//
// what other players wrote is filtered here, in each player's own
// game, as that player chose: the server passes chat on as it was
// typed. three levels (filterLevel): 0 nothing, which is where an
// account starts, 1 keeps out extreme threats and common slurs, 2
// swearing as well; and whatever words the
// player listed themselves (filterOwn) at any level. two ways
// (filterMode): 0 puts stars over a filtered word, 1 leaves the
// whole message out. the words of levels 1 and 2 are two files on
// the server (public/filter/level1.txt, level2.txt), fetched as the
// game starts; the choice is kept with the account ("xfl").
//
// A word is matched whole, never inside another. digits and signs
// standing in for letters are read as the letters, and a word with a
// letter drawn out ("heeello") is matched as if it were not.
public static var filterLevel:int = 0;
public static var filterMode:int = 0;
public static var filterOwn:String = "";
public static var filterChosen:Boolean = true;
public static var FILTER_HIDDEN:String = "(hidden by your chat filter)";
private static var _filterLists:Array = [[],[]];
private static var _filterOwnEntries:Array = [];
private static var _filterLoaders:Array = [];
private static function filterPlain(param1:String) : String
{
var _loc2_:String = param1.toLowerCase().replace(/^[0-9]+|[0-9]+$/g,"");
_loc2_ = _loc2_.replace(/[@4]/g,"a").replace(/[$5]/g,"s").replace(/0/g,"o").replace(/1/g,"i").replace(/3/g,"e").replace(/7/g,"t");
return _loc2_.replace(/[^a-z]/g,"");
}
private static function filterSquash(param1:String) : String
{
return param1.replace(/(.)\1+/g,"$1");
}
// the entries of a word list: a line is a word or a phrase, "#" starts
// a note, and a "*" at the end stands for "and longer words that
// start so". each entry: {t the words made plain, n how many words,
// p whether it had the star, q the same with drawn-out letters undone}.
private static function filterEntries(param1:String) : Array
{
var _loc2_:Array = [];
var _loc3_:Array = param1.split(/\r\n|\r|\n|,/);
var _loc4_:int = 0;
var _loc5_:String = null;
var _loc6_:Boolean = false;
var _loc7_:Array = null;
var _loc8_:Array = null;
var _loc9_:int = 0;
var _loc10_:String = null;
while(_loc4_ < _loc3_.length)
{
_loc5_ = String(_loc3_[_loc4_]).replace(/^\s+|\s+$/g,"");
_loc4_++;
if(_loc5_.length == 0 || _loc5_.charAt(0) == "#")
{
continue;
}
_loc6_ = _loc5_.charAt(_loc5_.length - 1) == "*";
_loc7_ = _loc5_.split(/\s+/);
_loc8_ = [];
_loc9_ = 0;
while(_loc9_ < _loc7_.length)
{
_loc10_ = filterPlain(String(_loc7_[_loc9_]));
if(_loc10_.length > 0)
{
_loc8_.push(_loc10_);
}
_loc9_++;
}
if(_loc8_.length > 0 && _loc8_.join("").length >= 2)
{
_loc2_.push({
"t":_loc8_.join(" "),
"n":_loc8_.length,
"p":_loc6_,
"q":filterSquash(_loc8_.join(" "))
});
}
}
return _loc2_;
}
private static function loadFilterLists() : void
{
var _loc1_:int = 0;
var _loc2_:URLLoader = null;
while(_loc1_ < 2)
{
_loc2_ = new URLLoader();
_loc2_.addEventListener("complete",onFilterListLoaded);
_loc2_.addEventListener("ioError",onFilterListFailed);
_loc2_.addEventListener("securityError",onFilterListFailed);
_filterLoaders[_loc1_] = _loc2_;
_loc2_.load(new URLRequest(gMainFrame.clientInfo.websiteURL + "filter/level" + (_loc1_ + 1) + ".txt"));
_loc1_++;
}
}
private static function onFilterListLoaded(param1:Event) : void
{
var _loc2_:int = _filterLoaders.indexOf(param1.target);
if(_loc2_ >= 0)
{
_filterLists[_loc2_] = filterEntries(String(URLLoader(param1.target).data));
}
}
private static function onFilterListFailed(param1:Event) : void
{
GlobalErrorCatch.reportToServer("chat filter: a word list did not load: " + param1);
}
// "xfl": [.., .., chosen, level, mode, own words]. the account's
// choice, at login and after each change.
public static function onFilterState(param1:Object) : void
{
filterChosen = String(param1[2]) == "1";
filterLevel = int(param1[3]);
filterMode = int(param1[4]);
filterOwn = param1[5] == null ? "" : String(param1[5]);
_filterOwnEntries = filterEntries(filterOwn);
}
// "xfa": the account has never chosen; the window is put to it once.
public static function onFilterAsk(param1:Object) : void
{
openTool(1);
}
// is the word at `param2` of the plain words `param1` (and those after
// it, for a phrase) the entry `param3`?
private static function filterHit(param1:Array, param2:int, param3:Object) : Boolean
{
var _loc4_:String = null;
var _loc5_:String = null;
if(param3.n > 1)
{
return param2 + param3.n <= param1.length && param1.slice(param2,param2 + param3.n).join(" ") == param3.t;
}
_loc4_ = param1[param2];
if(_loc4_ == param3.t || param3.p && _loc4_.indexOf(param3.t) == 0)
{
return true;
}
if(/(.)\1\1/.test(_loc4_))
{
_loc5_ = filterSquash(_loc4_);
return _loc5_ == param3.q || param3.p && _loc5_.indexOf(param3.q) == 0;
}
return false;
}
// what the player is to see of something another player wrote: the
// text as it was, the text with stars over the filtered words, or
// null when it is to be left out altogether.
public static function filterText(param1:String) : String
{
var _loc2_:Array = _filterOwnEntries;
var _loc3_:Array = [];
var _loc4_:Array = [];
var _loc5_:Array = [];
var _loc6_:RegExp = /[A-Za-z0-9@$]+/g;
var _loc7_:Object = null;
var _loc8_:String = null;
var _loc9_:int = 0;
var _loc10_:int = 0;
var _loc11_:int = 0;
var _loc12_:Array = null;
var _loc13_:Boolean = false;
if(param1 == null || param1.length == 0)
{
return param1;
}
if(filterLevel >= 1)
{
_loc2_ = _loc2_.concat(_filterLists[0]);
}
if(filterLevel >= 2)
{
_loc2_ = _loc2_.concat(_filterLists[1]);
}
if(_loc2_.length == 0)
{
return param1;
}
_loc7_ = _loc6_.exec(param1);
while(_loc7_ != null)
{
_loc8_ = filterPlain(String(_loc7_[0]));
if(_loc8_.length > 0)
{
_loc3_.push(_loc8_);
_loc4_.push(int(_loc7_.index));
_loc5_.push(int(_loc7_.index) + String(_loc7_[0]).length);
}
_loc7_ = _loc6_.exec(param1);
}
_loc12_ = param1.split("");
_loc9_ = 0;
while(_loc9_ < _loc3_.length)
{
_loc10_ = 0;
while(_loc10_ < _loc2_.length)
{
if(filterHit(_loc3_,_loc9_,_loc2_[_loc10_]))
{
_loc13_ = true;
_loc11_ = _loc4_[_loc9_];
while(_loc11_ < _loc5_[_loc9_ + _loc2_[_loc10_].n - 1])
{
if(_loc12_[_loc11_] != " ")
{
_loc12_[_loc11_] = "*";
}
_loc11_++;
}
}
_loc10_++;
}
_loc9_++;
}
if(!_loc13_)
{
return param1;
}
return filterMode == 1 ? null : _loc12_.join("");
}
// the same for text that has a place of its own (a Jam-A-Gram, a wall
// post, a bio): left out, it is replaced by a note saying so.
public static function filterOrNote(param1:String) : String
{
var _loc2_:String = filterText(param1);
return _loc2_ == null ? FILTER_HIDDEN : _loc2_;
}
// the window: the settings menu's "Chat Filter" row, and by itself
// the first time an account plays. built like the item finder, from
// the same pieces of the game's artwork. two lists to pick one row
// of each from, the row in use tinted green: what is filtered, and
// what becomes of a filtered word. under them the player's own words
// and one wide Save button: nothing changes until it is pressed, and
// it lights up when there is something to save.
private static var FILTER_LEVELS:Array = [0,1,2];
private static var FILTER_ROW_NAMES:Array = ["No filter","Slurs and threats","Slurs, threats and swearing","Censor the words (****)","Hide the whole message"];
private static var FILTER_ROW_Y:Array = [-104,-64,-24,44,84];
private var _filterWin:Sprite;
private var _filterRowClips:Array;
private var _filterSave:Sprite;
private var _filterWordsBar:MovieClip;
private var _filterWordsInput:TextField;
private var _filterPickLevel:int;
private var _filterPickMode:int;
private function buildChatFilter() : void
{
var _loc1_:MovieClip = GETDEFINITIONBYNAME("ReportRulesPopupSkin");
var _loc2_:MovieClip = GETDEFINITIONBYNAME("ReportRulesPopupContent");
var _loc3_:int = 1;
var _loc4_:Sprite = new Sprite();
var _loc6_:MovieClip = null;
var _loc8_:TextField = null;
var _loc9_:Matrix = new Matrix();
_filterWin = new Sprite();
_filterWin.graphics.beginFill(0,0.45);
_filterWin.graphics.drawRect(0,0,900,550);
_filterWin.graphics.endFill();
_loc4_.x = 450;
_loc4_.y = 275;
_filterWin.addChild(_loc4_);
_loc4_.addChild(_loc1_);
_loc2_.x = _loc1_.c.x;
_loc2_.y = _loc1_.c.y;
_loc4_.addChild(_loc2_);
_loc1_.bx.addEventListener("mouseDown",onFilterCloseClick);
while(_loc3_ <= 5)
{
_loc2_["ruleTxt" + _loc3_].visible = false;
_loc2_["ruleBodyTxt" + _loc3_].visible = false;
_loc3_++;
}
_loc2_.titleTxt.text = "Chat Filter";
_loc8_ = _loc2_.ruleBodyTxt1;
_loc8_.visible = true;
_loc8_.wordWrap = false;
_loc8_.x = -171;
_loc8_.y = -152;
_loc8_.width = 346;
_loc8_.height = 24;
_loc8_.text = "Choose what you don't want to see.";
_loc8_ = _loc2_.ruleBodyTxt2;
_loc8_.visible = true;
_loc8_.wordWrap = false;
_loc8_.x = -171;
_loc8_.y = 0;
_loc8_.width = 346;
_loc8_.height = 24;
_loc8_.text = "When a word is filtered:";
_filterRowClips = [];
_loc3_ = 0;
while(_loc3_ < 5)
{
_loc6_ = GETDEFINITIONBYNAME("textBtnCont");
_loc6_.x = 2;
_loc6_.y = FILTER_ROW_Y[_loc3_];
_loc6_.name = "pick" + _loc3_;
_loc6_.currTxt.mouseEnabled = false;
_loc6_.currTxt.text = FILTER_ROW_NAMES[_loc3_];
_loc6_.addEventListener("mouseDown",onFilterPick);
_loc2_.addChild(_loc6_);
_filterRowClips.push(_loc6_);
_loc3_++;
}
_filterWordsBar = finderSearchBar(-171,108,346,"Your own words, spaces between","^%",300,false);
_filterWordsInput = _filterWordsBar.searchTxt;
_filterWordsInput.addEventListener("change",onFilterTyped);
_loc2_.addChild(_filterWordsBar);
// the Save button: as wide as the rows, in the game's green.
_filterSave = new Sprite();
_filterSave.graphics.beginFill(1924906);
_filterSave.graphics.drawRoundRect(0,0,346,38,38,38);
_filterSave.graphics.endFill();
_loc9_.createGradientBox(340,32,Math.PI / 2,3,3);
_filterSave.graphics.beginGradientFill("linear",[8314449,4105022],[1,1],[0,255],_loc9_);
_filterSave.graphics.drawRoundRect(3,3,340,32,32,32);
_filterSave.graphics.endFill();
_loc8_ = new TextField();
_loc8_.embedFonts = hasGameFont();
_loc8_.selectable = false;
_loc8_.mouseEnabled = false;
_loc8_.autoSize = "left";
_loc8_.defaultTextFormat = new TextFormat("CCDigitalDelivery",18,16777215,true);
_loc8_.text = "Save";
_loc8_.x = int((346 - _loc8_.width) * 0.5);
_loc8_.y = int((38 - _loc8_.height) * 0.5);
_filterSave.addChild(_loc8_);
_filterSave.x = -171;
_filterSave.y = 157;
_filterSave.buttonMode = true;
_filterSave.mouseChildren = false;
_filterSave.addEventListener("mouseDown",onFilterSaveClick);
_loc2_.addChild(_filterSave);
_filterWin.addEventListener("mouseDown",onFinderMouse);
_filterWin.addEventListener("mouseUp",onFinderMouse);
_filterWin.addEventListener("click",onFinderMouse);
_filterWin.addEventListener("mouseWheel",onFinderMouse);
_filterWin.visible = false;
addChild(_filterWin);
}
private function filterWordsTyped() : String
{
var _loc1_:Array = _filterWordsInput.text.split(/[\s,]+/);
var _loc2_:Array = [];
var _loc3_:int = 0;
while(_loc3_ < _loc1_.length && _loc2_.length < 100)
{
if(String(_loc1_[_loc3_]).length > 0)
{
_loc2_.push(String(_loc1_[_loc3_]).substr(0,30));
}
_loc3_++;
}
return _loc2_.join(",");
}
// the rows as the picks stand, and the Save button: bright when what
// shows differs from what is kept (or nothing was ever chosen), pale
// when there is nothing to save.
private function drawChatFilter() : void
{
var _loc1_:int = 0;
var _loc2_:Boolean = false;
while(_loc1_ < 5)
{
_loc2_ = _loc1_ < 3 ? FILTER_LEVELS[_loc1_] == _filterPickLevel : _loc1_ - 3 == _filterPickMode;
_filterRowClips[_loc1_].transform.colorTransform = _loc2_ ? whisperTint() : new ColorTransform();
_loc1_++;
}
_filterWordsBar.txt.visible = _filterWordsInput.text.length == 0;
_loc2_ = !filterChosen || _filterPickLevel != filterLevel || _filterPickMode != (filterMode == 1 ? 1 : 0) || filterWordsTyped() != filterOwn;
_filterSave.alpha = _loc2_ ? 1 : 0.45;
}
private function onFilterTyped(param1:Event) : void
{
drawChatFilter();
}
private function showChatFilter(param1:Boolean) : void
{
if(_filterWin == null)
{
buildChatFilter();
}
_filterWin.visible = param1;
if(param1)
{
_filterPickLevel = filterLevel;
_filterPickMode = filterMode == 1 ? 1 : 0;
_filterWordsInput.text = filterOwn.split(",").join(" ");
drawChatFilter();
setChildIndex(_filterWin,numChildren - 1);
}
else
{
gMainFrame.stage.focus = null;
}
}
private function onFilterPick(param1:MouseEvent) : void
{
var _loc2_:int = int(DisplayObject(param1.currentTarget).name.substr(4));
param1.stopPropagation();
if(_loc2_ < 3)
{
_filterPickLevel = FILTER_LEVELS[_loc2_];
}
else
{
_filterPickMode = _loc2_ - 3;
}
drawChatFilter();
}
// the picks go to the server, which keeps them with the account and
// answers with them ("xfl"), and that answer is what takes effect.
private function saveChatFilter() : void
{
gMainFrame.server.setXtObject_Str("xfl",[_filterPickLevel,_filterPickMode,filterWordsTyped()]);
showChatFilter(false);
}
private function onFilterSaveClick(param1:MouseEvent) : void
{
param1.stopPropagation();
saveChatFilter();
}
// closed without saving: nothing changes. the first time, that still
// counts as having been asked, and what was showing is kept.
private function onFilterCloseClick(param1:MouseEvent) : void
{
param1.stopPropagation();
if(!filterChosen)
{
saveChatFilter();
return;
}
showChatFilter(false);
}
private function finderButtonText(param1:MovieClip, param2:String) : void
{
var _loc3_:Array = [param1.getChildByName("gray"),param1.getChildByName("down")];
var _loc4_:MovieClip = param1.getChildByName("mouse") as MovieClip;
var _loc5_:MovieClip = null;
var _loc6_:TextField = null;
var _loc7_:int = 0;
if(_loc4_ != null)
{
_loc3_.push(_loc4_.getChildByName("up"));
_loc3_.push(_loc4_.getChildByName("mouse"));
_loc7_ = 0;
while(_loc7_ < _loc4_.numChildren)
{
_loc3_.push(_loc4_.getChildAt(_loc7_));
_loc7_++;
}
}
_loc7_ = 0;
while(_loc7_ < _loc3_.length)
{
_loc5_ = _loc3_[_loc7_] as MovieClip;
if(_loc5_ != null)
{
_loc6_ = _loc5_.getChildByName("txt") as TextField;
if(_loc6_ != null)
{
_loc6_.text = param2;
}
}
_loc7_++;
}
}
private function finderSearchBar(param1:Number, param2:Number, param3:Number, param4:String, param5:String, param6:int, param7:Boolean) : MovieClip
{
var _loc8_:MovieClip = GETDEFINITIONBYNAME("searchBar_den");
var _loc9_:TextField = _loc8_.searchTxt;
var _loc10_:Shape = new Shape();
var _loc11_:Matrix = new Matrix();
var _loc12_:int = 0;
var _loc13_:Number = param7 ? 35 : 16;
_loc8_.t.visible = false;
_loc8_.m.visible = false;
_loc8_.b.visible = false;
if(!param7)
{
while(_loc12_ < _loc8_.numChildren)
{
if(_loc8_.getChildAt(_loc12_) is Shape)
{
_loc8_.getChildAt(_loc12_).visible = false;
}
_loc12_++;
}
}
_loc10_.graphics.beginFill(7160624);
_loc10_.graphics.drawRoundRect(0,4,param3,34,34,34);
_loc10_.graphics.endFill();
_loc10_.graphics.beginFill(10115109);
_loc10_.graphics.drawRoundRect(1,5,param3 - 2,32,32,32);
_loc10_.graphics.endFill();
_loc11_.createGradientBox(param3 - 8,26,Math.PI / 2,4,8);
_loc10_.graphics.beginGradientFill("linear",[11459790,15261660,16250099],[1,1,1],[0,127,255],_loc11_);
_loc10_.graphics.drawRoundRect(4,8,param3 - 8,26,26,26);
_loc10_.graphics.endFill();
_loc8_.addChildAt(_loc10_,0);
_loc8_.txt.text = param4;
_loc8_.txt.x = _loc13_;
_loc8_.txt.width = param3 - _loc13_ - 12;
_loc8_.txt.mouseEnabled = false;
_loc9_.type = "input";
_loc9_.selectable = true;
_loc9_.mouseEnabled = true;
_loc9_.visible = true;
_loc9_.x = _loc13_;
_loc9_.width = param3 - _loc13_ - 12;
_loc9_.maxChars = param6;
_loc9_.text = "";
if(param5 != null)
{
_loc9_.restrict = param5;
}
_loc9_.addEventListener("change",onFinderTyped);
_loc8_.x = param1;
_loc8_.y = param2;
return _loc8_;
}
// A bar's hint shows while nothing is typed in it.
private function onFinderTyped(param1:Event) : void
{
var _loc2_:TextField = param1.target as TextField;
var _loc3_:MovieClip = _loc2_ == null ? null : _loc2_.parent as MovieClip;
if(_loc3_ != null && _loc3_.txt != null)
{
_loc3_.txt.visible = _loc2_.text.length == 0;
}
}
private function buildItemFinder() : void
{
var _loc1_:MovieClip = GETDEFINITIONBYNAME("ReportRulesPopupSkin");
var _loc2_:MovieClip = GETDEFINITIONBYNAME("ReportRulesPopupContent");
var _loc3_:int = 1;
var _loc4_:MovieClip = null;
var _loc5_:MovieClip = null;
_finder = new Sprite();
_finder.graphics.beginFill(0,0.45);
_finder.graphics.drawRect(0,0,900,550);
_finder.graphics.endFill();
_finderPanel = new Sprite();
_finderPanel.x = 450;
_finderPanel.y = 275;
_finder.addChild(_finderPanel);
_finderPanel.addChild(_loc1_);
_loc2_.x = _loc1_.c.x;
_loc2_.y = _loc1_.c.y;
_finderPanel.addChild(_loc2_);
_loc1_.bx.addEventListener("mouseDown",onFinderCloseClick);
while(_loc3_ <= 5)
{
_loc2_["ruleTxt" + _loc3_].visible = false;
_loc2_["ruleBodyTxt" + _loc3_].visible = false;
_loc3_++;
}
_loc2_.titleTxt.text = "Item Finder";
_finderStatus = _loc2_.ruleBodyTxt1;
_finderStatus.visible = true;
_finderStatus.wordWrap = false;
_finderStatus.x = -245;
_finderStatus.y = -112;
_finderStatus.width = 490;
_finderStatus.height = 24;
_finderStatus.text = "Type a name or an id, then press Enter.";
_finderPageLabel = _loc2_.ruleBodyTxt2;
_finderPageLabel.visible = true;
_finderPageLabel.wordWrap = false;
_finderPageLabel.x = -60;
_finderPageLabel.y = 154;
_finderPageLabel.width = 200;
_finderPageLabel.height = 24;
_finderPageLabel.text = "";
_finderInputBar = finderSearchBar(-247,-160,212,"Name or id",null,60,true);
_finderInput = _finderInputBar.searchTxt;
_loc2_.addChild(_finderInputBar);
_finderKindButton = GETDEFINITIONBYNAME("introBtnCont");
_finderKindButton.x = -30;
_finderKindButton.y = -156;
finderButtonText(_finderKindButton,"All items");
_finderKindButton.addEventListener("mouseDown",onFinderKindClick);
_loc2_.addChild(_finderKindButton);
_finderColourBar = finderSearchBar(93,-160,156,"Colour ID","0-9",10,false);
_finderColourInput = _finderColourBar.searchTxt;
_loc2_.addChild(_finderColourBar);
_finderRows = new Sprite();
_finderRows.x = 0;
_finderRows.y = -62;
_loc2_.addChild(_finderRows);
_loc4_ = GETDEFINITIONBYNAME("arrow_l_btnContOld");
_loc4_.x = -228;
_loc4_.y = 166;
_loc4_.addEventListener("mouseDown",onFinderPrevClick);
_loc2_.addChild(_loc4_);
_loc5_ = GETDEFINITIONBYNAME("arrow_r_btnContOld");
_loc5_.x = 228;
_loc5_.y = 166;
_loc5_.addEventListener("mouseDown",onFinderNextClick);
_loc2_.addChild(_loc5_);
_finder.addEventListener("mouseDown",onFinderMouse);
_finder.addEventListener("mouseUp",onFinderMouse);
_finder.addEventListener("click",onFinderMouse);
_finder.addEventListener("mouseWheel",onFinderMouse);
_finder.visible = false;
addChild(_finder);
}
private function showItemFinder(param1:Boolean) : void
{
if(_finder == null)
{
buildItemFinder();
}
_finder.visible = param1;
if(param1)
{
setChildIndex(_finder,numChildren - 1);
gMainFrame.stage.focus = _finderInput;
}
else
{
gMainFrame.stage.focus = null;
}
}
private function onFinderMouse(param1:Event) : void
{
param1.stopPropagation();
}
private function onFinderCloseClick(param1:MouseEvent) : void
{
param1.stopPropagation();
showItemFinder(false);
}
private function onFinderKey(param1:KeyboardEvent) : void
{
if(param1.eventPhase == 3)
{
return;
}
var _loc2_:Boolean = _finder != null && _finder.visible;
// the chat filter's window: Esc leaves it as its X does, Enter
// saves, and no key gets past it to the game.
if(_filterWin != null && _filterWin.visible)
{
if(param1.keyCode == 27)
{
onFilterCloseClick(new MouseEvent("mouseDown"));
}
else if(param1.keyCode == 13)
{
saveChatFilter();
}
param1.stopImmediatePropagation();
return;
}
if(param1.keyCode == 120)
{
openTool(0);
if(_loc2_)
{
showItemFinder(false);
}
param1.stopImmediatePropagation();
return;
}
if(_loc2_)
{
if(param1.keyCode == 27)
{
showItemFinder(false);
}
else if(param1.keyCode == 13)
{
finderSearch();
}
param1.stopImmediatePropagation();
}
}
private function onFinderKindClick(param1:MouseEvent) : void
{
param1.stopPropagation();
_finderKind = (_finderKind + 1) % 3;
finderButtonText(_finderKindButton,_finderKind == 0 ? "All items" : (_finderKind == 1 ? "Clothing" : "Den items"));
finderSearch();
}
private function finderSearch() : void
{
if(gMainFrame.stage.focus != _finderColourInput)
{
gMainFrame.stage.focus = _finderInput;
}
if(_finderInput.text.length == 0)
{
_finderStatus.text = "Type a name or an id, then press Enter.";
return;
}
var _loc1_:String = _finderKind == 0 ? "all" : (_finderKind == 1 ? "clothing" : "den");
var _loc2_:URLLoader = new URLLoader();
_loc2_.addEventListener("complete",onFinderSearchDone);
_loc2_.addEventListener("ioError",onFinderFailed);
_loc2_.addEventListener("securityError",onFinderFailed);
_finderStatus.text = "Searching...";
_loc2_.load(new URLRequest(gMainFrame.clientInfo.websiteURL + "api/search?kind=" + _loc1_ + "&q=" + encodeURIComponent(_finderInput.text) + "&username=" + encodeURIComponent(gMainFrame.server.userName) + "&token=" + encodeURIComponent(gMainFrame.clientInfo.authToken)));
}
private function onFinderFailed(param1:Event) : void
{
_finderStatus.text = "The server did not accept that.";
}
private function onFinderSearchDone(param1:Event) : void
{
var _loc2_:Object = JSON.parse(String(URLLoader(param1.target).data));
_finderResults = _loc2_.results as Array;
_finderTotal = int(_loc2_.total);
_finderPage = 0;
for each(var _loc3_:Object in _finderResults)
{
_loc3_.colorIndex = 0;
}
if(_finderTotal == 0)
{
_finderStatus.text = "Nothing matches.";
}
else if(_finderTotal > _finderResults.length)
{
_finderStatus.text = "Showing the first " + _finderResults.length + " of " + _finderTotal + " matches.";
}
else
{
_finderStatus.text = _finderTotal + (_finderTotal == 1 ? " match." : " matches.") + " Click a row to change its colour.";
}
renderFinderRows();
}
private function finderRowText(param1:Object) : String
{
var _loc2_:String = param1.id + " " + param1.name + " (" + (param1.kind == "den" ? "den item" : "clothing");
if(int(param1.colors) > 1)
{
_loc2_ += ", colour " + (int(param1.colorIndex) + 1) + "/" + param1.colors;
}
return _loc2_ + ")";
}
private function renderFinderRows() : void
{
var _loc1_:Object = null;
var _loc2_:int = 0;
var _loc3_:MovieClip = null;
var _loc4_:MovieClip = null;
while(_finderRows.numChildren > 0)
{
_finderRows.removeChildAt(0);
}
var _loc5_:int = Math.max(1,Math.ceil(_finderResults.length / 6));
_loc2_ = _finderPage * 6;
while(_loc2_ < _finderResults.length && _loc2_ < _finderPage * 6 + 6)
{
_loc1_ = _finderResults[_loc2_];
_loc3_ = GETDEFINITIONBYNAME("textBtnCont");
_loc3_.x = -74;
_loc3_.y = (_loc2_ - _finderPage * 6) * 40;
_loc3_.name = "row" + _loc2_;
_loc3_.currTxt.mouseEnabled = false;
_loc3_.currTxt.text = finderRowText(_loc1_);
_loc3_.addEventListener("mouseDown",onFinderColourClick);
_finderRows.addChild(_loc3_);
_loc4_ = GETDEFINITIONBYNAME("buyBtnCont");
_loc4_.scaleX = 0.8;
_loc4_.scaleY = 0.8;
_loc4_.x = 160;
_loc4_.y = _loc3_.y;
_loc4_.name = "give" + _loc2_;
finderButtonText(_loc4_,"Give");
_loc4_.addEventListener("mouseDown",onFinderGiveClick);
_finderRows.addChild(_loc4_);
_loc2_++;
}
_finderPageLabel.text = _finderResults.length == 0 ? "" : "Page " + (_finderPage + 1) + " of " + _loc5_;
}
private function onFinderPrevClick(param1:MouseEvent) : void
{
param1.stopPropagation();
if(_finderPage > 0)
{
_finderPage--;
renderFinderRows();
}
}
private function onFinderNextClick(param1:MouseEvent) : void
{
param1.stopPropagation();
if((_finderPage + 1) * 6 < _finderResults.length)
{
_finderPage++;
renderFinderRows();
}
}
private function onFinderColourClick(param1:MouseEvent) : void
{
var _loc2_:MovieClip = MovieClip(param1.currentTarget);
var _loc3_:Object = _finderResults[int(_loc2_.name.substr(3))];
param1.stopPropagation();
if(_loc3_ != null && int(_loc3_.colors) > 1)
{
_loc3_.colorIndex = (int(_loc3_.colorIndex) + 1) % int(_loc3_.colors);
_loc2_.currTxt.text = finderRowText(_loc3_);
}
}
private function onFinderGiveClick(param1:MouseEvent) : void
{
var _loc2_:Object = _finderResults[int(MovieClip(param1.currentTarget).name.substr(4))];
var _loc3_:URLRequest = new URLRequest(gMainFrame.clientInfo.websiteURL + "api/give");
param1.stopPropagation();
_loc3_.method = "POST";
_loc3_.contentType = "application/json";
var _loc5_:Object = {
"username":gMainFrame.server.userName,
"token":gMainFrame.clientInfo.authToken,
"kind":_loc2_.kind,
"id":_loc2_.id,
"colorIndex":_loc2_.colorIndex
};
if(_finderColourInput.text.length > 0 && _loc2_.kind != "den")
{
_loc5_.color = _finderColourInput.text;
}
_loc3_.data = JSON.stringify(_loc5_);
var _loc4_:URLLoader = new URLLoader();
_loc4_.addEventListener("complete",onFinderGiveDone);
_loc4_.addEventListener("ioError",onFinderFailed);
_loc4_.addEventListener("securityError",onFinderFailed);
_finderStatus.text = "Adding " + _loc2_.name + "...";
_loc4_.load(_loc3_);
}
private function onFinderGiveDone(param1:Event) : void
{
_finderStatus.text = "Added to your inventory.";
}
private function onInitiationFailure() : void
{
new SBStandardPopup(gMainFrame.stage,LocalizationManager.translateIdOnly(11202),false);
}
private function createAvatar() : void
{
}
private function shardSelection() : void
{
}
private function enterGame() : void
{
}
private function handleGlobalErrors(param1:UncaughtErrorEvent) : void
{
GlobalErrorCatch.globalErrorListener(param1);
}
}
}