mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-20 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,518 @@
|
||||
package
|
||||
{
|
||||
import com.sbi.corelib.Utils;
|
||||
import com.sbi.corelib.audio.SBAudio;
|
||||
import flash.net.SharedObject;
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class AJAudio
|
||||
{
|
||||
|
||||
private static var _hasLoadedDailySpinSfx:Boolean;
|
||||
|
||||
private static var _hasLoadedGiftUnwrapSfx:Boolean;
|
||||
|
||||
private static var _hasLoadedJourneyBookWorldSfx:Boolean;
|
||||
|
||||
private static var _hasLoadedJourneyBookBookSfx:Boolean;
|
||||
|
||||
private static var _hasLoadedTradeSfx:Boolean;
|
||||
|
||||
private static var _defaultVolumes:Dictionary;
|
||||
|
||||
public function AJAudio()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(muteCallback:Function = null) : void
|
||||
{
|
||||
var cachedSounds:Object = null;
|
||||
if(!SBAudio.isInitialized)
|
||||
{
|
||||
cachedSounds = {};
|
||||
cachedSounds["HudBtnRollover"] = {
|
||||
"className":Utils.getDefByName("HudBtnRollover") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["HudBtnClick"] = {
|
||||
"className":Utils.getDefByName("HudBtnClick") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["SubMenuBtnRollover"] = {
|
||||
"className":Utils.getDefByName("SubMenuBtnRollover") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["SubMenuBtnClick"] = {
|
||||
"className":Utils.getDefByName("SubMenuBtnClick") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ExitBtnRollover"] = {
|
||||
"className":Utils.getDefByName("ExitBtnRollover") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ExitBtnClick"] = {
|
||||
"className":Utils.getDefByName("ExitBtnClick") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ScrollUpDown"] = {
|
||||
"className":Utils.getDefByName("ScrollUpDown") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ScrollLeftRight"] = {
|
||||
"className":Utils.getDefByName("ScrollLeftRight") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["TextType"] = {
|
||||
"className":Utils.getDefByName("TextType") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["TextEnter"] = {
|
||||
"className":Utils.getDefByName("TextEnter") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["IdleWarningSound"] = {
|
||||
"className":Utils.getDefByName("IdleWarningSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ShopCachingSound"] = {
|
||||
"className":Utils.getDefByName("ShopCachingSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["GemsEarnedSound"] = {
|
||||
"className":Utils.getDefByName("GemsEarnedSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ItemRecycledSound"] = {
|
||||
"className":Utils.getDefByName("ItemRecycledSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["MailReceivedSound"] = {
|
||||
"className":Utils.getDefByName("MailReceivedSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["BuddyOnlineOfflineSound"] = {
|
||||
"className":Utils.getDefByName("BuddyOnlineOfflineSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["NewspaperSound"] = {
|
||||
"className":Utils.getDefByName("NewspaperSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["MailSentSound"] = {
|
||||
"className":Utils.getDefByName("MailSentSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["AchievementSound"] = {
|
||||
"className":Utils.getDefByName("AchievementSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["BuddyCardOpen"] = {
|
||||
"className":Utils.getDefByName("BuddyCardOpen") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["BuddyCardClose"] = {
|
||||
"className":Utils.getDefByName("BuddyCardClose") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["LimitedChatErrorSound"] = {
|
||||
"className":Utils.getDefByName("LimitedChatErrorSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ChatOpenSound"] = {
|
||||
"className":Utils.getDefByName("ChatOpenSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["ChatCloseSound"] = {
|
||||
"className":Utils.getDefByName("ChatCloseSound") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["RandomLever"] = {
|
||||
"className":Utils.getDefByName("RandomLever") as Class,
|
||||
"volume":0.2
|
||||
};
|
||||
cachedSounds["NameGenRotationSound"] = {
|
||||
"className":Utils.getDefByName("NameGenRotationSound") as Class,
|
||||
"volume":1
|
||||
};
|
||||
cachedSounds["NameGenStopSound"] = {
|
||||
"className":Utils.getDefByName("NameGenStopSound") as Class,
|
||||
"volume":1
|
||||
};
|
||||
cachedSounds["DoorBellSound"] = {
|
||||
"className":Utils.getDefByName("DoorBellSound") as Class,
|
||||
"volume":1
|
||||
};
|
||||
SBAudio.init(cachedSounds,muteCallback);
|
||||
_defaultVolumes = new Dictionary();
|
||||
_defaultVolumes["FW_TRAIL_1"] = 0.2;
|
||||
_defaultVolumes["FW_TRAIL_2"] = 0.2;
|
||||
_defaultVolumes["FW_TRAIL_3"] = 0.2;
|
||||
_defaultVolumes["FW_LAUNCH_1"] = 0.3;
|
||||
_defaultVolumes["FW_LAUNCH_2"] = 0.3;
|
||||
_defaultVolumes["FW_LAUNCH_3"] = 0.3;
|
||||
_defaultVolumes["FW_EXPLOSION_1"] = 0.3;
|
||||
_defaultVolumes["FW_EXPLOSION_2"] = 0.3;
|
||||
_defaultVolumes["FW_EXPLOSION_3"] = 0.3;
|
||||
_defaultVolumes["DOOR_WOOD_OPEN"] = 0.3;
|
||||
_defaultVolumes["DOOR_WOOD_CLOSE"] = 0.3;
|
||||
_defaultVolumes["DOOR_SLIDE"] = 0.3;
|
||||
_defaultVolumes["DOOR_STONE_SLIDE"] = 0.3;
|
||||
_defaultVolumes["aj_water_fs1"] = 0;
|
||||
_defaultVolumes["aj_water_fs2"] = 0;
|
||||
_defaultVolumes["aj_water_fs3"] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadSfx(className:String, classVar:Class, defVolume:Number = 0.3) : void
|
||||
{
|
||||
if(Boolean(_defaultVolumes[className]))
|
||||
{
|
||||
defVolume = Number(_defaultVolumes[className]);
|
||||
}
|
||||
SBAudio.addCachedSound(className,classVar,defVolume);
|
||||
}
|
||||
|
||||
public static function setupSharedObject(sharedObj:SharedObject) : void
|
||||
{
|
||||
SBAudio.setupSharedObject(sharedObj);
|
||||
}
|
||||
|
||||
public static function playSfx(className:String, loopCount:int = 1) : void
|
||||
{
|
||||
SBAudio.playCachedSound(className,loopCount);
|
||||
}
|
||||
|
||||
public static function stopSfx(className:String) : void
|
||||
{
|
||||
SBAudio.stopCachedSound(className);
|
||||
}
|
||||
|
||||
public static function playHudBtnRollover() : void
|
||||
{
|
||||
playSfx("HudBtnRollover");
|
||||
}
|
||||
|
||||
public static function playHudBtnClick() : void
|
||||
{
|
||||
playSfx("HudBtnClick");
|
||||
}
|
||||
|
||||
public static function playSubMenuBtnRollover() : void
|
||||
{
|
||||
playSfx("SubMenuBtnRollover");
|
||||
}
|
||||
|
||||
public static function playSubMenuBtnClick() : void
|
||||
{
|
||||
playSfx("SubMenuBtnClick");
|
||||
}
|
||||
|
||||
public static function playExitBtnRollover() : void
|
||||
{
|
||||
playSfx("ExitBtnRollover");
|
||||
}
|
||||
|
||||
public static function playExitBtnClick() : void
|
||||
{
|
||||
playSfx("ExitBtnClick");
|
||||
}
|
||||
|
||||
public static function playScrollUpDown() : void
|
||||
{
|
||||
playSfx("ScrollUpDown");
|
||||
}
|
||||
|
||||
public static function playScrollLeftRight() : void
|
||||
{
|
||||
playSfx("ScrollLeftRight");
|
||||
}
|
||||
|
||||
public static function playTextType() : void
|
||||
{
|
||||
playSfx("TextType");
|
||||
}
|
||||
|
||||
public static function playTextEnter() : void
|
||||
{
|
||||
playSfx("TextEnter");
|
||||
}
|
||||
|
||||
public static function playIdleWarningSound() : void
|
||||
{
|
||||
playSfx("IdleWarningSound");
|
||||
}
|
||||
|
||||
public static function playShopCachingSound() : void
|
||||
{
|
||||
playSfx("ShopCachingSound");
|
||||
}
|
||||
|
||||
public static function playGemsEarnedSound() : void
|
||||
{
|
||||
playSfx("GemsEarnedSound");
|
||||
}
|
||||
|
||||
public static function playItemRecycledSound() : void
|
||||
{
|
||||
playSfx("ItemRecycledSound");
|
||||
}
|
||||
|
||||
public static function playMailReceivedSound() : void
|
||||
{
|
||||
playSfx("MailReceivedSound");
|
||||
}
|
||||
|
||||
public static function playMailSentSound() : void
|
||||
{
|
||||
playSfx("MailSentSound");
|
||||
}
|
||||
|
||||
public static function playBuddyOnlineOfflineSound() : void
|
||||
{
|
||||
playSfx("BuddyOnlineOfflineSound");
|
||||
}
|
||||
|
||||
public static function playNewspaperSound() : void
|
||||
{
|
||||
playSfx("NewspaperSound");
|
||||
}
|
||||
|
||||
public static function playAchievementSound() : void
|
||||
{
|
||||
playSfx("AchievementSound");
|
||||
}
|
||||
|
||||
public static function playBuddyCardOpen() : void
|
||||
{
|
||||
playSfx("BuddyCardOpen");
|
||||
}
|
||||
|
||||
public static function playBuddyCardClose() : void
|
||||
{
|
||||
playSfx("BuddyCardClose");
|
||||
}
|
||||
|
||||
public static function playLimitedChatErrorSound() : void
|
||||
{
|
||||
playSfx("LimitedChatErrorSound");
|
||||
}
|
||||
|
||||
public static function playChatOpenSound() : void
|
||||
{
|
||||
playSfx("ChatOpenSound");
|
||||
}
|
||||
|
||||
public static function playChatCloseSound() : void
|
||||
{
|
||||
playSfx("ChatCloseSound");
|
||||
}
|
||||
|
||||
public static function playRandomLever() : void
|
||||
{
|
||||
playSfx("RandomLever");
|
||||
}
|
||||
|
||||
public static function playNameGenRotationSound(loopCount:int = 1) : void
|
||||
{
|
||||
playSfx("NameGenRotationSound",loopCount);
|
||||
}
|
||||
|
||||
public static function playNameGenStopSound() : void
|
||||
{
|
||||
playSfx("NameGenStopSound");
|
||||
}
|
||||
|
||||
public static function playDoorBellSound() : void
|
||||
{
|
||||
playSfx("DoorBellSound");
|
||||
}
|
||||
|
||||
public static function stopNameGenRotationSound() : void
|
||||
{
|
||||
stopSfx("NameGenRotationSound");
|
||||
}
|
||||
|
||||
public static function stopRandomLever() : void
|
||||
{
|
||||
stopSfx("RandomLever");
|
||||
}
|
||||
|
||||
public static function get hasLoadedDailySpinSfx() : Boolean
|
||||
{
|
||||
return _hasLoadedDailySpinSfx;
|
||||
}
|
||||
|
||||
public static function set hasLoadedDailySpinSfx(value:Boolean) : void
|
||||
{
|
||||
_hasLoadedDailySpinSfx = value;
|
||||
}
|
||||
|
||||
public static function playDailySpinSpin() : void
|
||||
{
|
||||
if(!_hasLoadedDailySpinSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("DailySpinSpin");
|
||||
}
|
||||
|
||||
public static function playDailySpinBub1() : void
|
||||
{
|
||||
if(!_hasLoadedDailySpinSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("DailySpinBub1");
|
||||
}
|
||||
|
||||
public static function playDailySpinBub2() : void
|
||||
{
|
||||
if(!_hasLoadedDailySpinSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("DailySpinBub2");
|
||||
}
|
||||
|
||||
public static function playDailySpinBub3() : void
|
||||
{
|
||||
if(!_hasLoadedDailySpinSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("DailySpinBub3");
|
||||
}
|
||||
|
||||
public static function get hasLoadedGiftUnwrapSfx() : Boolean
|
||||
{
|
||||
return _hasLoadedGiftUnwrapSfx;
|
||||
}
|
||||
|
||||
public static function set hasLoadedGiftUnwrapSfx(value:Boolean) : void
|
||||
{
|
||||
_hasLoadedGiftUnwrapSfx = value;
|
||||
}
|
||||
|
||||
public static function playGiftUnwrap() : void
|
||||
{
|
||||
if(!_hasLoadedGiftUnwrapSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("GiftUnwrap");
|
||||
}
|
||||
|
||||
public static function playTreasureUnwrap() : void
|
||||
{
|
||||
if(!_hasLoadedGiftUnwrapSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("TreasureUnwrap");
|
||||
}
|
||||
|
||||
public static function get hasLoadedJourneyBookWorldSfx() : Boolean
|
||||
{
|
||||
return _hasLoadedJourneyBookWorldSfx;
|
||||
}
|
||||
|
||||
public static function set hasLoadedJourneyBookWorldSfx(value:Boolean) : void
|
||||
{
|
||||
_hasLoadedJourneyBookWorldSfx = value;
|
||||
}
|
||||
|
||||
public static function playJBPrizeEarned() : void
|
||||
{
|
||||
if(!_hasLoadedJourneyBookWorldSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("JBPrizeEarned");
|
||||
}
|
||||
|
||||
public static function playJBWorldFactClose() : void
|
||||
{
|
||||
if(!_hasLoadedJourneyBookWorldSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("JBWorldFactClose");
|
||||
}
|
||||
|
||||
public static function playJBWorldFactOpen() : void
|
||||
{
|
||||
if(!_hasLoadedJourneyBookWorldSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("JBWorldFactOpen");
|
||||
}
|
||||
|
||||
public static function get hasLoadedJourneyBookBookSfx() : Boolean
|
||||
{
|
||||
return _hasLoadedJourneyBookBookSfx;
|
||||
}
|
||||
|
||||
public static function set hasLoadedJourneyBookBookSfx(value:Boolean) : void
|
||||
{
|
||||
_hasLoadedJourneyBookBookSfx = value;
|
||||
}
|
||||
|
||||
public static function playJBBookFactClose() : void
|
||||
{
|
||||
if(!_hasLoadedJourneyBookBookSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("JBBookFactClose");
|
||||
}
|
||||
|
||||
public static function playJBBookFactOpen() : void
|
||||
{
|
||||
if(!_hasLoadedJourneyBookBookSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("JBBookFactOpen");
|
||||
}
|
||||
|
||||
public static function get hasLoadedTradeSfx() : Boolean
|
||||
{
|
||||
return _hasLoadedTradeSfx;
|
||||
}
|
||||
|
||||
public static function set hasLoadedTradeSfx(value:Boolean) : void
|
||||
{
|
||||
_hasLoadedTradeSfx = value;
|
||||
}
|
||||
|
||||
public static function playTradeSuccessSound() : void
|
||||
{
|
||||
if(!_hasLoadedTradeSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("TradeSuccessSound");
|
||||
}
|
||||
|
||||
public static function playTradeFailedSound() : void
|
||||
{
|
||||
if(!_hasLoadedTradeSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("TradeFailedSound");
|
||||
}
|
||||
|
||||
public static function playTradeRequestSound() : void
|
||||
{
|
||||
if(!_hasLoadedTradeSfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
playSfx("TradeRequestSound");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
package
|
||||
{
|
||||
import com.sbi.analytics.SBTracker;
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import com.sbi.loader.FileServerEvent;
|
||||
import com.sbi.loader.LoaderCache;
|
||||
import com.sbi.loader.ResourceStack;
|
||||
import createAccountFlow.CreateAccount;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.UncaughtErrorEvent;
|
||||
import flash.external.ExternalInterface;
|
||||
import flash.ui.Mouse;
|
||||
import gamePlayFlow.GamePlay;
|
||||
import gui.DarkenManager;
|
||||
import loader.DefPacksDefHelper;
|
||||
import localization.LocalizationManager;
|
||||
import resource.FetchClientIPResourceStackable;
|
||||
import resource.LoadAvatarCarouselResourceStackable;
|
||||
import resource.LoadCursorResourceStackable;
|
||||
import room.DebugGUITextbox;
|
||||
import waitingRoomFlow.WaitingRoom;
|
||||
|
||||
[SWF(width="900", height="550", backgroundColor="#393625", frameRate="24")]
|
||||
[SWF(width="900",height="550",backgroundColor="#00393625",frameRate="24")]
|
||||
public class AJClient extends Sprite
|
||||
{
|
||||
|
||||
private static var _globalErrorDebugTxt:DebugGUITextbox;
|
||||
|
||||
private var _resourceStackLoader:ResourceStack;
|
||||
|
||||
public function AJClient()
|
||||
{
|
||||
super();
|
||||
addEventListener(Event.ADDED_TO_STAGE,this.addedToStageHandler);
|
||||
}
|
||||
|
||||
public static function get globalErrorDebugTxt() : DebugGUITextbox
|
||||
{
|
||||
return _globalErrorDebugTxt;
|
||||
}
|
||||
|
||||
private static function handleGlobalErrors(evt:UncaughtErrorEvent) : void
|
||||
{
|
||||
_globalErrorDebugTxt.text = GlobalErrorCatch.setupGlobalErrorListener(evt);
|
||||
}
|
||||
|
||||
private function addedToStageHandler(e:Event) : void
|
||||
{
|
||||
var flashvars:Object = null;
|
||||
var i:int = 0;
|
||||
var k:String = null;
|
||||
removeEventListener(Event.ADDED_TO_STAGE,this.addedToStageHandler);
|
||||
var extIntAvail:Boolean = ExternalInterface.available;
|
||||
if(extIntAvail)
|
||||
{
|
||||
DebugUtility.debugTrace("addedToStageHandler - extIntAvail is true");
|
||||
DebugUtility.debugTrace("mrc dm init ctor starting up call returned:" + ExternalInterface.call("mrc",["dm","AJClient addedToStageHandler starting up"]));
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("addedToStageHandler - extIntAvail is false");
|
||||
}
|
||||
if(!MainFrame.isInitialized())
|
||||
{
|
||||
if(parent != null)
|
||||
{
|
||||
flashvars = parent.loaderInfo.parameters;
|
||||
}
|
||||
else
|
||||
{
|
||||
flashvars = loaderInfo.parameters;
|
||||
}
|
||||
DebugUtility.debugTrace("addedToStageHandler - printing loaderInfo parameters flashvars...");
|
||||
i = 0;
|
||||
for(k in flashvars)
|
||||
{
|
||||
DebugUtility.debugTrace(" flashvar " + k + ":" + flashvars[k]);
|
||||
i++;
|
||||
}
|
||||
DebugUtility.debugTrace("addedToStageHandler - ...done printing loaderInfo parameters flashvars - i:" + i);
|
||||
MainFrame.handleLocalExternalCall = GamePlay.handleLocalExternalCall;
|
||||
MainFrame.getInstance(flashvars,this.setupInit,"",this);
|
||||
_globalErrorDebugTxt = new DebugGUITextbox();
|
||||
_globalErrorDebugTxt.init(this,"Global Error Catcher Initialized",false,true,true,600);
|
||||
_globalErrorDebugTxt.txt.textColor = 2236962;
|
||||
_globalErrorDebugTxt.x = 222;
|
||||
_globalErrorDebugTxt.y = 300;
|
||||
if(loaderInfo.hasOwnProperty("uncaughtErrorEvents"))
|
||||
{
|
||||
loaderInfo["uncaughtErrorEvents"].addEventListener("uncaughtError",handleGlobalErrors);
|
||||
}
|
||||
}
|
||||
DebugUtility.debugTrace("AJClient addedToStageHandler finished");
|
||||
}
|
||||
|
||||
public function setupInit() : void
|
||||
{
|
||||
LoaderCache.clientIp = String(gMainFrame.clientInfo.clientIp);
|
||||
gMainFrame.stage.addEventListener("Localization",LocalizationManager.onLocalizationEvent,false,0,true);
|
||||
var dpdh:DefPacksDefHelper = new DefPacksDefHelper();
|
||||
LocalizationManager.currentLanguage = LocalizationManager.accountLanguage = LocalizationManager.getLanguageIdForLocale(gMainFrame.clientInfo.locale);
|
||||
dpdh.init(uint(DefPacksDefHelper.DEF_LOCALIZATION + "" + LocalizationManager.currentLanguage),LocalizationXtCommManager.onLocalizationListResponse,this.loadResourceItems,FileServerEvent.AMF3_TYPE);
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_LOCALIZATION + "" + LocalizationManager.currentLanguage] = dpdh;
|
||||
dpdh = new DefPacksDefHelper();
|
||||
dpdh.init(uint(DefPacksDefHelper.DEF_PREFERRED_LOCALIZATION + "" + LocalizationManager.accountLanguage),LocalizationXtCommManager.onPreferredLocalizationListResponse,null,FileServerEvent.AMF3_TYPE);
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_PREFERRED_LOCALIZATION + "" + LocalizationManager.accountLanguage] = dpdh;
|
||||
}
|
||||
|
||||
public function loadResourceItems() : void
|
||||
{
|
||||
Utility.init(DarkenManager.showLoadingSpiral,DarkenManager.darken,DarkenManager.unDarken);
|
||||
this._resourceStackLoader = new ResourceStack(gMainFrame.path,gMainFrame.loaderCache.openFile);
|
||||
this._resourceStackLoader.pushClass(new FetchClientIPResourceStackable(),true);
|
||||
this._resourceStackLoader.pushFile("assets/sharedFonts.swf",true);
|
||||
this._resourceStackLoader.pushFile("assets/HUDAssets.swf",true);
|
||||
if(Boolean(gMainFrame.clientInfo.isCreateAccount))
|
||||
{
|
||||
this._resourceStackLoader.pushClass(new LoadAvatarCarouselResourceStackable());
|
||||
}
|
||||
if(Boolean(Mouse["supportsNativeCursor"]))
|
||||
{
|
||||
this._resourceStackLoader.pushClass(new LoadCursorResourceStackable());
|
||||
}
|
||||
if(Boolean(gMainFrame.clientInfo.isCreateAccount))
|
||||
{
|
||||
this._resourceStackLoader.start(this.setupCreateAccount);
|
||||
}
|
||||
else if(Boolean(gMainFrame.clientInfo.waitingMode))
|
||||
{
|
||||
this._resourceStackLoader.start(this.setupWaitingRoom);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._resourceStackLoader.start(this.setupGamePlay);
|
||||
}
|
||||
}
|
||||
|
||||
public function setupCreateAccount() : void
|
||||
{
|
||||
if(gMainFrame.clientInfo.landingPage != "undefined")
|
||||
{
|
||||
SBTracker.trackPageview("/game/play/homepage/" + gMainFrame.clientInfo.landingPage,0,SBTracker.TYPE_EVENT);
|
||||
}
|
||||
var ca:CreateAccount = new CreateAccount(gMainFrame.clientInfo);
|
||||
addChild(ca);
|
||||
gMainFrame.createAccount = ca;
|
||||
ca.loginCtorHelper();
|
||||
}
|
||||
|
||||
public function setupWaitingRoom() : void
|
||||
{
|
||||
var wr:WaitingRoom = new WaitingRoom(gMainFrame.clientInfo);
|
||||
addChild(wr);
|
||||
gMainFrame.waitingRoom = wr;
|
||||
wr.waitCtorHelper();
|
||||
}
|
||||
|
||||
public function setupGamePlay(loginEvt:Event = null, connectEvt:Event = null) : void
|
||||
{
|
||||
DebugUtility.debugTrace("setupGamePlay - loginEvt:" + loginEvt + " connectEvt:" + connectEvt);
|
||||
if(Boolean(gMainFrame.createAccount))
|
||||
{
|
||||
if(contains(gMainFrame.createAccount))
|
||||
{
|
||||
removeChild(gMainFrame.createAccount);
|
||||
}
|
||||
gMainFrame.createAccount = null;
|
||||
this._resourceStackLoader = null;
|
||||
}
|
||||
DebugUtility.debugTrace("setupGamePlay - constructing GamePlay - gMainFrame.clientInfo:" + gMainFrame.clientInfo);
|
||||
var gp:GamePlay = new GamePlay(gMainFrame.clientInfo,loginEvt,connectEvt);
|
||||
addChild(gp);
|
||||
gMainFrame.gamePlay = gp;
|
||||
DebugUtility.debugTrace("setupGamePlay - gp:" + gp + " calling worldCtorHelper");
|
||||
gp.worldCtorHelper();
|
||||
}
|
||||
|
||||
private function createAvatar() : void
|
||||
{
|
||||
}
|
||||
|
||||
private function shardSelection() : void
|
||||
{
|
||||
}
|
||||
|
||||
private function enterGame() : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package
|
||||
{
|
||||
import flash.display.Sprite;
|
||||
|
||||
public dynamic class DisplayLayer extends Sprite
|
||||
{
|
||||
|
||||
public function DisplayLayer()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package
|
||||
{
|
||||
import flash.system.Capabilities;
|
||||
|
||||
public class FlashCapabilities
|
||||
{
|
||||
|
||||
private static const CAPABILITIES_AV_HARDWARE_DISABLE:uint = 0;
|
||||
|
||||
private static const CAPABILITIES_HAS_ACCESSIBILITY:uint = 1;
|
||||
|
||||
private static const CAPABILITIES_HAS_AUDIO:uint = 2;
|
||||
|
||||
private static const CAPABILITIES_HAS_AUDIO_ENCODER:uint = 3;
|
||||
|
||||
private static const CAPABILITIES_HAS_EMBEDDED_VIDEO:uint = 4;
|
||||
|
||||
private static const CAPABILITIES_HAS_IME:uint = 5;
|
||||
|
||||
private static const CAPABILITIES_HAS_MP3:uint = 6;
|
||||
|
||||
private static const CAPABILITIES_HAS_PRINTING:uint = 7;
|
||||
|
||||
private static const CAPABILITIES_HAS_SCREEN_BROADCAST:uint = 8;
|
||||
|
||||
private static const CAPABILITIES_HAS_SCREEN_PLAYBACK:uint = 9;
|
||||
|
||||
private static const CAPABILITIES_HAS_STREAMING_AUDIO:uint = 10;
|
||||
|
||||
private static const CAPABILITIES_HAS_STREAMING_VIDEO:uint = 11;
|
||||
|
||||
private static const CAPABILITIES_HAS_TLS:uint = 12;
|
||||
|
||||
private static const CAPABILITIES_HAS_VIDEO_ENCODER:uint = 13;
|
||||
|
||||
private static const CAPABILITIES_IS_DEBUGGER:uint = 14;
|
||||
|
||||
private static const CAPABILITIES_IS_EMBEDDED_IN_ACROBAT:uint = 15;
|
||||
|
||||
private static const CAPABILITIES_LOCAL_FILE_READ_DISABLE:uint = 16;
|
||||
|
||||
private static const CAPABILITIES_UNKNOWN_VALUE:int = -1;
|
||||
|
||||
private static const CAPABILITIES_PLAYER_TYPE_ACTIVEX:uint = 0;
|
||||
|
||||
private static const CAPABILITIES_PLAYER_TYPE_DESKTOP:uint = 1;
|
||||
|
||||
private static const CAPABILITIES_PLAYER_TYPE_EXTERNAL:uint = 2;
|
||||
|
||||
private static const CAPABILITIES_PLAYER_TYPE_PLUGIN:uint = 3;
|
||||
|
||||
private static const CAPABILITIES_PLAYER_TYPE_STANDALONE:uint = 4;
|
||||
|
||||
private static const CAPABILITIES_SCREEN_COLOR_COLOR:uint = 0;
|
||||
|
||||
private static const CAPABILITIES_SCREEN_COLOR_GRAY:uint = 1;
|
||||
|
||||
private static const CAPABILITIES_SCREEN_COLOR_BW:uint = 2;
|
||||
|
||||
private static const CAPABILITIES_VERSION_PLATFORM_WIN:uint = 0;
|
||||
|
||||
private static const CAPABILITIES_VERSION_PLATFORM_MAC:uint = 1;
|
||||
|
||||
private static const CAPABILITIES_VERSION_PLATFORM_UNIX:uint = 2;
|
||||
|
||||
public function FlashCapabilities()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function SendCapabilities() : void
|
||||
{
|
||||
var capFlags:int = 0;
|
||||
if(Capabilities.avHardwareDisable)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_AV_HARDWARE_DISABLE;
|
||||
}
|
||||
if(Capabilities.hasAccessibility)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_ACCESSIBILITY;
|
||||
}
|
||||
if(Capabilities.hasAudio)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_AUDIO;
|
||||
}
|
||||
if(Capabilities.hasAudioEncoder)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_AUDIO_ENCODER;
|
||||
}
|
||||
if(Capabilities.hasEmbeddedVideo)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_EMBEDDED_VIDEO;
|
||||
}
|
||||
if(Capabilities.hasIME)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_IME;
|
||||
}
|
||||
if(Capabilities.hasMP3)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_MP3;
|
||||
}
|
||||
if(Capabilities.hasPrinting)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_PRINTING;
|
||||
}
|
||||
if(Capabilities.hasScreenBroadcast)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_SCREEN_BROADCAST;
|
||||
}
|
||||
if(Capabilities.hasScreenPlayback)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_SCREEN_PLAYBACK;
|
||||
}
|
||||
if(Capabilities.hasStreamingAudio)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_STREAMING_AUDIO;
|
||||
}
|
||||
if(Capabilities.hasStreamingVideo)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_STREAMING_VIDEO;
|
||||
}
|
||||
if(Capabilities.hasTLS)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_TLS;
|
||||
}
|
||||
if(Capabilities.hasVideoEncoder)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_HAS_VIDEO_ENCODER;
|
||||
}
|
||||
if(Capabilities.isDebugger)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_IS_DEBUGGER;
|
||||
}
|
||||
if(Capabilities.isEmbeddedInAcrobat)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_IS_EMBEDDED_IN_ACROBAT;
|
||||
}
|
||||
if(Capabilities.localFileReadDisable)
|
||||
{
|
||||
capFlags |= 1 << CAPABILITIES_LOCAL_FILE_READ_DISABLE;
|
||||
}
|
||||
var capPlayerType:int = CAPABILITIES_UNKNOWN_VALUE;
|
||||
switch(Capabilities.playerType)
|
||||
{
|
||||
case "ActiveX":
|
||||
capPlayerType = int(CAPABILITIES_PLAYER_TYPE_ACTIVEX);
|
||||
break;
|
||||
case "Desktop":
|
||||
capPlayerType = int(CAPABILITIES_PLAYER_TYPE_DESKTOP);
|
||||
break;
|
||||
case "External":
|
||||
capPlayerType = int(CAPABILITIES_PLAYER_TYPE_EXTERNAL);
|
||||
break;
|
||||
case "PlugIn":
|
||||
capPlayerType = int(CAPABILITIES_PLAYER_TYPE_PLUGIN);
|
||||
break;
|
||||
case "StandAlone":
|
||||
capPlayerType = int(CAPABILITIES_PLAYER_TYPE_STANDALONE);
|
||||
}
|
||||
var capScreenColor:int = CAPABILITIES_UNKNOWN_VALUE;
|
||||
switch(Capabilities.screenColor)
|
||||
{
|
||||
case "color":
|
||||
capScreenColor = int(CAPABILITIES_SCREEN_COLOR_COLOR);
|
||||
break;
|
||||
case "gray":
|
||||
capScreenColor = int(CAPABILITIES_SCREEN_COLOR_GRAY);
|
||||
break;
|
||||
case "bw":
|
||||
capScreenColor = int(CAPABILITIES_SCREEN_COLOR_BW);
|
||||
}
|
||||
var capVersionArray:Array = Capabilities.version.substring(Capabilities.version.indexOf(" ") + 1).split(",");
|
||||
var capArray:Array = [];
|
||||
capArray.push(capFlags);
|
||||
capArray.push(Capabilities.language);
|
||||
capArray.push(Capabilities.manufacturer);
|
||||
capArray.push(Capabilities.os);
|
||||
capArray.push(Capabilities.pixelAspectRatio);
|
||||
capArray.push(capPlayerType);
|
||||
capArray.push(capScreenColor);
|
||||
capArray.push(Capabilities.screenDPI);
|
||||
capArray.push(Capabilities.screenResolutionX);
|
||||
capArray.push(Capabilities.screenResolutionY);
|
||||
for(var i:int = 0; i < 4; i++)
|
||||
{
|
||||
if(i < capVersionArray.length)
|
||||
{
|
||||
capArray.push(capVersionArray[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
capArray.push(0);
|
||||
}
|
||||
}
|
||||
gMainFrame.server.setXtObject_Str("us",capArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package
|
||||
{
|
||||
import flash.utils.getDefinitionByName;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public function GETDEFINITIONBYNAME(a:String, localize:Boolean = true) : *
|
||||
{
|
||||
var item:* = new (getDefinitionByName(a) as Class)();
|
||||
if(localize)
|
||||
{
|
||||
LocalizationManager.findAllTextfields(item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,609 @@
|
||||
package
|
||||
{
|
||||
import com.sbi.client.SFEvent;
|
||||
import den.DenItem;
|
||||
import gui.GenericListGuiManager;
|
||||
import item.Item;
|
||||
import item.ItemXtCommManager;
|
||||
import loader.DefPacksDefHelper;
|
||||
|
||||
public class GenericListXtCommManager
|
||||
{
|
||||
|
||||
private static var _requestCallbackQueue:Object;
|
||||
|
||||
private static var _streamQueue:Object;
|
||||
|
||||
private static var _requestPassback:Object;
|
||||
|
||||
private static var _cachedResponses:Object;
|
||||
|
||||
private static var _availDefs:Object;
|
||||
|
||||
private static var _availUniqueListId:int;
|
||||
|
||||
public static const AVAIL_LIST_ID:int = 1;
|
||||
|
||||
public static const AVAIL_TYPE_CLOTHING:int = 0;
|
||||
|
||||
public static const AVAIL_TYPE_DEN_ACC:int = 1;
|
||||
|
||||
public static const AVAIL_TYPE_PARTY:int = 2;
|
||||
|
||||
public static const AVAIL_TYPE_DEN_ROOM:int = 3;
|
||||
|
||||
public static const AVAIL_TYPE_ROOM:int = 4;
|
||||
|
||||
public static const AVAIL_TYPE_STREAM:int = 5;
|
||||
|
||||
public static const AVAIL_TYPE_DIAMOND:int = 6;
|
||||
|
||||
public static const ACC_JAMAA_SHOP_ID:int = 11;
|
||||
|
||||
public static const ACC_BAHARIBAY_SHOP_ID:int = 50;
|
||||
|
||||
public static const DEN_ITEM_MAIN_SHOP_ID:int = 12;
|
||||
|
||||
public static const DEN_ITEM_CRYSTALREEF_SHOP_ID:int = 51;
|
||||
|
||||
public static const DEN_ITEM_AUDIO_SHOP_ID:int = 56;
|
||||
|
||||
public static const DEN_ITEM_PET_LAND:int = 85;
|
||||
|
||||
public static const DEN_ITEM_PET_OCEAN:int = 89;
|
||||
|
||||
public static const DEN_ITEM_FIRST_TIME_SHOP_ID:int = 234;
|
||||
|
||||
public static const REDEMPTION_STORE_LIST_ID:int = 172;
|
||||
|
||||
public static const DEN_ROOM_SHOP_ID:int = 13;
|
||||
|
||||
public static const DEN_ROOM_FULL_SHOP_ID:int = 215;
|
||||
|
||||
public static const MEDIA_EBOOK_1_ID:int = 23;
|
||||
|
||||
public static const AVATAR_LIST_ID:int = 64;
|
||||
|
||||
public static const MEDIA_JAG_CARD_LIST_ID:int = 10;
|
||||
|
||||
public static const MEDIA_JAG_STAMP_LIST_ID:int = 44;
|
||||
|
||||
private static var _availDefExpireTime:int = 0;
|
||||
|
||||
public function GenericListXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init() : void
|
||||
{
|
||||
_cachedResponses = new Object();
|
||||
_requestCallbackQueue = new Object();
|
||||
_streamQueue = new Object();
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
}
|
||||
|
||||
public static function requestGenericList(glId:int, callback:Function = null, passback:Object = null, isFromWorld:Boolean = true) : void
|
||||
{
|
||||
if(callback != null)
|
||||
{
|
||||
_requestCallbackQueue[glId] = callback;
|
||||
}
|
||||
_requestPassback = passback;
|
||||
if(Boolean(_cachedResponses[glId]) && glId != AVAIL_LIST_ID)
|
||||
{
|
||||
handleNewData(_cachedResponses[glId].concat());
|
||||
}
|
||||
else
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("gl",[glId],isFromWorld);
|
||||
}
|
||||
}
|
||||
|
||||
public static function requestStreamList(glId:int, callback:Function, helper:Object = null) : void
|
||||
{
|
||||
_streamQueue[glId] = {
|
||||
"c":callback,
|
||||
"h":helper
|
||||
};
|
||||
if(Boolean(_cachedResponses[glId]))
|
||||
{
|
||||
handleNewData(_cachedResponses[glId].concat());
|
||||
}
|
||||
else
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("gl",[glId]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function handleXtReply(evt:SFEvent) : void
|
||||
{
|
||||
var data:Array = evt.obj;
|
||||
if(data[0] == "gl")
|
||||
{
|
||||
_cachedResponses[int(data[2])] = data;
|
||||
}
|
||||
handleNewData(data.concat());
|
||||
}
|
||||
|
||||
public static function isAvailListExpired() : Boolean
|
||||
{
|
||||
var date:Date = new Date();
|
||||
var timeSeconds:uint = date.getTime() / 1000;
|
||||
if(_availDefExpireTime == 0 || _availDefExpireTime > 0 && timeSeconds >= _availDefExpireTime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getAvailListUniqueId() : int
|
||||
{
|
||||
return _availUniqueListId;
|
||||
}
|
||||
|
||||
public static function getDefIdFromDef(def:Object) : int
|
||||
{
|
||||
var defId:int = 0;
|
||||
if(Boolean(def))
|
||||
{
|
||||
if(def is Item)
|
||||
{
|
||||
defId = int(def.defId);
|
||||
}
|
||||
else if(def is DenItem)
|
||||
{
|
||||
defId = int(def.itemDefId);
|
||||
}
|
||||
}
|
||||
return defId;
|
||||
}
|
||||
|
||||
public static function filterList(listDefType:int, items:Array, extraList:Object = null) : void
|
||||
{
|
||||
var availType:int = 0;
|
||||
var removed:Boolean = false;
|
||||
var defId:int = 0;
|
||||
var j:int = 0;
|
||||
var a:Array = null;
|
||||
switch(listDefType)
|
||||
{
|
||||
case DefPacksDefHelper.DEF_ITEM:
|
||||
availType = AVAIL_TYPE_CLOTHING;
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_DEN_ITEM:
|
||||
availType = AVAIL_TYPE_DEN_ACC;
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_DEN_ROOM:
|
||||
availType = AVAIL_TYPE_DEN_ROOM;
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_STREAM:
|
||||
availType = AVAIL_TYPE_STREAM;
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_DIAMOND:
|
||||
availType = AVAIL_TYPE_DIAMOND;
|
||||
break;
|
||||
default:
|
||||
trace("filtering of gl is not setup for listDefType=" + listDefType + ". Returning list passed in");
|
||||
return;
|
||||
}
|
||||
var availDefs:Array = _availDefs[availType];
|
||||
if(!availDefs || availDefs.length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var newItemsIdx:int = 0;
|
||||
while(newItemsIdx < items.length)
|
||||
{
|
||||
removed = false;
|
||||
switch(availType)
|
||||
{
|
||||
case AVAIL_TYPE_CLOTHING:
|
||||
defId = int(items[newItemsIdx].defId);
|
||||
break;
|
||||
case AVAIL_TYPE_DEN_ACC:
|
||||
defId = int(items[newItemsIdx].itemDefId);
|
||||
break;
|
||||
case AVAIL_TYPE_DEN_ROOM:
|
||||
defId = int(items[newItemsIdx].itemDefId);
|
||||
break;
|
||||
case AVAIL_TYPE_STREAM:
|
||||
defId = int(items[newItemsIdx]);
|
||||
break;
|
||||
case AVAIL_TYPE_DIAMOND:
|
||||
defId = int(items[newItemsIdx].diamondDefId);
|
||||
break;
|
||||
default:
|
||||
throw new Error("ERROR: Availability type=" + availType + " is not yet implemented!");
|
||||
}
|
||||
if(defId > 0)
|
||||
{
|
||||
for(j = 0; j < availDefs.length; j++)
|
||||
{
|
||||
if(defId == availDefs[j].defId)
|
||||
{
|
||||
if(availType != AVAIL_TYPE_STREAM)
|
||||
{
|
||||
items[newItemsIdx].endTime = availDefs[j].endTime;
|
||||
}
|
||||
if(!availDefs[j].active)
|
||||
{
|
||||
items.splice(newItemsIdx,1);
|
||||
if(Boolean(extraList))
|
||||
{
|
||||
if(availType == AVAIL_TYPE_STREAM)
|
||||
{
|
||||
for each(a in extraList)
|
||||
{
|
||||
a.splice(newItemsIdx,1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
extraList.splice(newItemsIdx,1);
|
||||
}
|
||||
}
|
||||
removed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!removed)
|
||||
{
|
||||
newItemsIdx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleNewData(data:Array) : void
|
||||
{
|
||||
var defType:int = 0;
|
||||
if(data[0] == "gl")
|
||||
{
|
||||
defType = int(data[3]);
|
||||
switch(defType)
|
||||
{
|
||||
case DefPacksDefHelper.DEF_ITEM:
|
||||
case DefPacksDefHelper.DEF_DEN_ITEM:
|
||||
case DefPacksDefHelper.DEF_DEN_ROOM:
|
||||
case DefPacksDefHelper.DEF_CURRENCY_EXCHANGE:
|
||||
case DefPacksDefHelper.DEF_DIAMOND:
|
||||
handleItemResponse(data,defType);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_LOCALIZATION:
|
||||
handleLocalizationResponse(data);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_MEDIA:
|
||||
handleMediaResponse(data);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_FACT:
|
||||
handleFactResponse(data);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_STREAM:
|
||||
handleStreamResponse(data);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_AVATAR:
|
||||
handleAvatarResponse(data);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_AVAILABILITY:
|
||||
handleAvailabilityResponse(data);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_NAMEBAR_BADGE:
|
||||
handleNamebarBadgeResposne(data);
|
||||
break;
|
||||
case DefPacksDefHelper.DEF_SCRIPT:
|
||||
handleScriptResponse(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new Error("GenericListXtCommManager illegal data cmd:" + data[0]);
|
||||
}
|
||||
|
||||
public static function genericListTypeResponse(dfdh:DefPacksDefHelper) : void
|
||||
{
|
||||
var obj:Object = null;
|
||||
var o:Object = null;
|
||||
var data:Object = dfdh.def;
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_GENERIC_LIST_TYPE] = null;
|
||||
var gld:Object = new Object();
|
||||
for each(obj in data)
|
||||
{
|
||||
o = {
|
||||
"defId":int(obj.id),
|
||||
"typeId":int(obj.typeId)
|
||||
};
|
||||
gld[obj.id] = o;
|
||||
}
|
||||
gMainFrame.userInfo.genericListDefs = gld;
|
||||
}
|
||||
|
||||
private static function handleItemResponse(data:Array, glType:int) : void
|
||||
{
|
||||
ItemXtCommManager.shopListResponse(data,glType);
|
||||
}
|
||||
|
||||
private static function handleLocalizationResponse(data:Array) : void
|
||||
{
|
||||
var callbackObject:Object = null;
|
||||
var j:int = 6;
|
||||
var numLocalizationStrings:int = int(data[j++]);
|
||||
var locStrs:Array = new Array(numLocalizationStrings);
|
||||
for(var i:int = 0; i < numLocalizationStrings; i++)
|
||||
{
|
||||
locStrs[i] = data[j++];
|
||||
}
|
||||
var glId:int = int(data[2]);
|
||||
var callback:Function = _requestCallbackQueue[glId];
|
||||
if(callback != null)
|
||||
{
|
||||
callback(glId,locStrs);
|
||||
for each(callbackObject in _requestCallbackQueue)
|
||||
{
|
||||
if(callbackObject == callback)
|
||||
{
|
||||
delete _requestCallbackQueue[glId];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleMediaResponse(data:Array) : void
|
||||
{
|
||||
var callbackObject:Object = null;
|
||||
var j:int = 6;
|
||||
var numMediaIds:int = int(data[j++]);
|
||||
var mediaIds:Array = new Array(numMediaIds);
|
||||
var locStrs:Array = new Array(numMediaIds);
|
||||
for(var i:int = 0; i < numMediaIds; i++)
|
||||
{
|
||||
mediaIds[i] = int(data[j++]);
|
||||
locStrs[i] = data[j++];
|
||||
}
|
||||
var glId:int = int(data[2]);
|
||||
var callback:Function = _requestCallbackQueue[glId];
|
||||
if(callback != null)
|
||||
{
|
||||
callback(glId,mediaIds,locStrs);
|
||||
for each(callbackObject in _requestCallbackQueue)
|
||||
{
|
||||
if(callbackObject == callback)
|
||||
{
|
||||
delete _requestCallbackQueue[glId];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleFactResponse(data:Array) : void
|
||||
{
|
||||
var fact:Object = null;
|
||||
var callbackObject:Object = null;
|
||||
var j:int = 6;
|
||||
var numFacts:int = int(data[j++]);
|
||||
var factDefs:Array = new Array();
|
||||
for(var i:int = 0; i < numFacts; i++)
|
||||
{
|
||||
fact = {
|
||||
"id":int(data[j++]),
|
||||
"media":int(data[j++]),
|
||||
"title":int(data[j++]),
|
||||
"description":int(data[j++]),
|
||||
"type":int(data[j++]),
|
||||
"userVarId":int(data[j++]),
|
||||
"bitIdx":int(data[j++])
|
||||
};
|
||||
factDefs.push(fact);
|
||||
}
|
||||
var glId:int = int(data[2]);
|
||||
var callback:Function = _requestCallbackQueue[glId];
|
||||
if(callback != null)
|
||||
{
|
||||
callback(factDefs);
|
||||
for each(callbackObject in _requestCallbackQueue)
|
||||
{
|
||||
if(callbackObject == callback)
|
||||
{
|
||||
delete _requestCallbackQueue[glId];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleStreamResponse(data:Array) : void
|
||||
{
|
||||
var temp:Array = null;
|
||||
var streamQueue:Object = null;
|
||||
if(GenericListXtCommManager.isAvailListExpired())
|
||||
{
|
||||
if(Boolean(GenericListGuiManager) && Boolean(GenericListGuiManager.movieSelector))
|
||||
{
|
||||
GenericListGuiManager.movieSelector.destroy();
|
||||
GenericListGuiManager.movieSelector = null;
|
||||
}
|
||||
GenericListXtCommManager.requestGenericList(GenericListXtCommManager.AVAIL_LIST_ID,handleStreamResponse,data);
|
||||
return;
|
||||
}
|
||||
var j:int = 6;
|
||||
var titleTxt:String = data[4];
|
||||
var numStreams:int = int(data[j++]);
|
||||
var streamIds:Array = new Array(numStreams);
|
||||
var thumbIds:Array = new Array(numStreams);
|
||||
var baseTitles:Array = new Array(numStreams);
|
||||
var indivTitles:Array = new Array(numStreams);
|
||||
var status:Array = new Array(numStreams);
|
||||
var subtitleIds:Array = new Array(numStreams);
|
||||
for(var i:int = 0; i < numStreams; i++)
|
||||
{
|
||||
streamIds[i] = int(data[j++]);
|
||||
thumbIds[i] = int(data[j++]);
|
||||
temp = data[j++].split("|");
|
||||
baseTitles[i] = temp[0];
|
||||
if(Boolean(temp[1]))
|
||||
{
|
||||
indivTitles[i] = temp[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
indivTitles[i] = temp[0];
|
||||
}
|
||||
status[i] = int(data[j++]);
|
||||
subtitleIds[i] = int(data[j++]);
|
||||
}
|
||||
var glId:int = int(data[2]);
|
||||
var o:Object = _streamQueue[glId];
|
||||
if(Boolean(o))
|
||||
{
|
||||
if(Boolean(o.h))
|
||||
{
|
||||
o.h.titleTxt = titleTxt;
|
||||
o.c(glId,streamIds,thumbIds,baseTitles,indivTitles,status,subtitleIds,o.h);
|
||||
}
|
||||
else
|
||||
{
|
||||
o.c(glId,streamIds,thumbIds,baseTitles,indivTitles,status,subtitleIds);
|
||||
}
|
||||
for each(streamQueue in _streamQueue)
|
||||
{
|
||||
if(streamQueue == _streamQueue[glId])
|
||||
{
|
||||
delete _streamQueue[glId];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleAvatarResponse(data:Array) : void
|
||||
{
|
||||
var callbackObject:Object = null;
|
||||
var j:int = 6;
|
||||
var numAvtDefIds:int = int(data[j++]);
|
||||
var avDefIds:Array = new Array(numAvtDefIds);
|
||||
for(var i:int = 0; i < numAvtDefIds; i++)
|
||||
{
|
||||
avDefIds[i] = int(data[j++]);
|
||||
}
|
||||
var glId:int = int(data[2]);
|
||||
var callback:Function = _requestCallbackQueue[glId];
|
||||
if(callback != null)
|
||||
{
|
||||
callback(avDefIds);
|
||||
for each(callbackObject in _requestCallbackQueue)
|
||||
{
|
||||
if(callbackObject == callback)
|
||||
{
|
||||
delete _requestCallbackQueue[glId];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleAvailabilityResponse(data:Array) : void
|
||||
{
|
||||
var type:int = 0;
|
||||
var date:Date = null;
|
||||
var callbackObject:Object = null;
|
||||
var glId:int = int(data[2]);
|
||||
var j:int = 4;
|
||||
_availUniqueListId = int(data[j++]);
|
||||
var secUntilExpir:int = int(data[j++]);
|
||||
var numDefs:int = int(data[j++]);
|
||||
if(secUntilExpir < 0)
|
||||
{
|
||||
_availDefExpireTime = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
date = new Date();
|
||||
_availDefExpireTime = date.getTime() / 1000 + secUntilExpir;
|
||||
}
|
||||
_availDefs = new Object();
|
||||
for(var i:int = 0; i < numDefs; i++)
|
||||
{
|
||||
type = int(data[j++]);
|
||||
if(!_availDefs[type])
|
||||
{
|
||||
_availDefs[type] = [];
|
||||
}
|
||||
_availDefs[type].push({
|
||||
"defId":int(data[j++]),
|
||||
"endTime":uint(data[j++]),
|
||||
"active":data[j++] == "1"
|
||||
});
|
||||
}
|
||||
var callback:Function = _requestCallbackQueue[glId];
|
||||
if(callback != null)
|
||||
{
|
||||
if(Boolean(_requestPassback))
|
||||
{
|
||||
callback(_requestPassback);
|
||||
_requestPassback = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
callback();
|
||||
}
|
||||
for each(callbackObject in _requestCallbackQueue)
|
||||
{
|
||||
if(callbackObject == callback)
|
||||
{
|
||||
delete _requestCallbackQueue[glId];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleNamebarBadgeResposne(data:Array) : void
|
||||
{
|
||||
var callbackObject:Object = null;
|
||||
var j:int = 6;
|
||||
var numBadges:int = int(data[j++]);
|
||||
var badges:Array = new Array(numBadges);
|
||||
for(var i:int = 0; i < numBadges; i++)
|
||||
{
|
||||
badges[i] = int(data[j++]);
|
||||
}
|
||||
var glId:int = int(data[2]);
|
||||
var callback:Function = _requestCallbackQueue[glId];
|
||||
if(callback != null)
|
||||
{
|
||||
callback(badges);
|
||||
for each(callbackObject in _requestCallbackQueue)
|
||||
{
|
||||
if(callbackObject == callback)
|
||||
{
|
||||
delete _requestCallbackQueue[glId];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleScriptResponse(data:Array) : void
|
||||
{
|
||||
var j:int = 6;
|
||||
var numItems:int = int(data[j++]);
|
||||
var scriptIds:Array = new Array(numItems);
|
||||
for(var i:int = 0; i < numItems; i++)
|
||||
{
|
||||
scriptIds[i] = int(data[j++]);
|
||||
}
|
||||
var glId:int = int(data[2]);
|
||||
var callback:Function = _requestCallbackQueue[glId];
|
||||
if(callback != null)
|
||||
{
|
||||
callback(glId,scriptIds,_requestPassback);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package
|
||||
{
|
||||
import flash.events.ErrorEvent;
|
||||
import flash.events.UncaughtErrorEvent;
|
||||
import flash.system.Capabilities;
|
||||
|
||||
public class GlobalErrorCatch
|
||||
{
|
||||
|
||||
public function GlobalErrorCatch()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function setupGlobalErrorListener(evt:UncaughtErrorEvent) : String
|
||||
{
|
||||
var message:String = null;
|
||||
var ucEvt:UncaughtErrorEvent = UncaughtErrorEvent(evt);
|
||||
var showErrors:Boolean = gMainFrame.clientInfo.accountType == Utility.INTERNAL;
|
||||
showErrors = true;
|
||||
if(Boolean(ucEvt))
|
||||
{
|
||||
if(!showErrors)
|
||||
{
|
||||
ucEvt.preventDefault();
|
||||
}
|
||||
if(ucEvt.error is Error)
|
||||
{
|
||||
if(Capabilities.isDebugger)
|
||||
{
|
||||
message = Error(ucEvt.error).getStackTrace();
|
||||
}
|
||||
else
|
||||
{
|
||||
message = Error(ucEvt.error).message;
|
||||
}
|
||||
}
|
||||
else if(ucEvt.error is ErrorEvent)
|
||||
{
|
||||
message = ErrorEvent(ucEvt.error).text;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = ucEvt.error.toString();
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package
|
||||
{
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import com.sbi.loader.LoaderCacheEntry_Base;
|
||||
import com.sbi.loader.LoaderEvent;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Loader;
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.Event;
|
||||
import flash.utils.ByteArray;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class LoadProgress
|
||||
{
|
||||
|
||||
private static var _entry:LoaderCacheEntry_Base;
|
||||
|
||||
private static var _loadScreen:Loader;
|
||||
|
||||
private static var _loadLayer:DisplayObjectContainer;
|
||||
|
||||
private static var _completeCallback:Function;
|
||||
|
||||
private static var _target:String;
|
||||
|
||||
private static var _displayTarget:String;
|
||||
|
||||
private static var _bChangeLoadingScreen:Boolean;
|
||||
|
||||
private static var _progressCounter:int;
|
||||
|
||||
private static var _visible:Boolean;
|
||||
|
||||
public static const INITIALIZING:int = 1;
|
||||
|
||||
public static const LOADING_GAMES:int = 2;
|
||||
|
||||
public static const LOADING_ANIMALS:int = 3;
|
||||
|
||||
public static const LOADING_WORLDMAP:int = 4;
|
||||
|
||||
public static const FINDING_ROOM:int = 5;
|
||||
|
||||
public static const LOADING_ROOM:int = 6;
|
||||
|
||||
public static const JOINING_SERVER:int = 7;
|
||||
|
||||
private static const LoadScreenSWF:Class = LoadProgress_LoadScreenSWF;
|
||||
|
||||
public function LoadProgress()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function get loadScreen() : Loader
|
||||
{
|
||||
return _loadScreen;
|
||||
}
|
||||
|
||||
public static function get entry() : LoaderCacheEntry_Base
|
||||
{
|
||||
return _entry;
|
||||
}
|
||||
|
||||
public static function get loadLayer() : DisplayObjectContainer
|
||||
{
|
||||
return _loadLayer;
|
||||
}
|
||||
|
||||
public static function get visible() : Boolean
|
||||
{
|
||||
return _visible;
|
||||
}
|
||||
|
||||
public static function init(initLoadLayer:DisplayObjectContainer) : void
|
||||
{
|
||||
var ba:ByteArray = null;
|
||||
if(_loadScreen == null)
|
||||
{
|
||||
_bChangeLoadingScreen = true;
|
||||
_progressCounter = 0;
|
||||
_loadLayer = initLoadLayer;
|
||||
_loadScreen = new Loader();
|
||||
_loadScreen.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadScreenComplete);
|
||||
ba = ByteArray(new LoadScreenSWF());
|
||||
_loadScreen.loadBytes(ba);
|
||||
}
|
||||
}
|
||||
|
||||
public static function show(bShow:Boolean, displayString:Object = null) : void
|
||||
{
|
||||
var mc:MovieClip = null;
|
||||
if(bShow)
|
||||
{
|
||||
_visible = true;
|
||||
mc = MovieClip(_loadScreen.content);
|
||||
if(!loadLayer.contains(_loadScreen))
|
||||
{
|
||||
loadLayer.addChild(_loadScreen);
|
||||
}
|
||||
if(Boolean(mc) && _bChangeLoadingScreen)
|
||||
{
|
||||
mc.showScreen(true);
|
||||
mc.setProgress(_progressCounter);
|
||||
if(!LocalizationManager.hasLocalizations)
|
||||
{
|
||||
mc.setCallback(onLoadProgressTextChange);
|
||||
mc.textBox.visible = false;
|
||||
mc.loadText.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.setCallback(null);
|
||||
mc.textBox.visible = true;
|
||||
mc.loadText.visible = true;
|
||||
}
|
||||
_bChangeLoadingScreen = false;
|
||||
}
|
||||
}
|
||||
else if(loadLayer.contains(_loadScreen))
|
||||
{
|
||||
_visible = false;
|
||||
loadLayer.removeChild(_loadScreen);
|
||||
_bChangeLoadingScreen = true;
|
||||
_progressCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static function load(loadTarget:String, progress:int, loadCompleteCallback:Function) : void
|
||||
{
|
||||
_entry = null;
|
||||
_completeCallback = loadCompleteCallback;
|
||||
_target = gMainFrame.path + loadTarget;
|
||||
_progressCounter = progress;
|
||||
var mc:MovieClip = MovieClip(_loadScreen.content);
|
||||
if(Boolean(mc))
|
||||
{
|
||||
mc.setProgress(progress);
|
||||
}
|
||||
DebugUtility.debugTrace("loading target:" + _target);
|
||||
if(Boolean(_loadScreen))
|
||||
{
|
||||
startLoad();
|
||||
return;
|
||||
}
|
||||
throw new Error("preloader was not embedded?!");
|
||||
}
|
||||
|
||||
private static function onLoadProgressTextChange() : void
|
||||
{
|
||||
var mc:MovieClip = null;
|
||||
if(LocalizationManager.hasLocalizations)
|
||||
{
|
||||
mc = MovieClip(_loadScreen.content);
|
||||
if(Boolean(_loadScreen.content))
|
||||
{
|
||||
mc.relocalize();
|
||||
mc.setCallback(null);
|
||||
mc.textBox.visible = true;
|
||||
mc.loadText.visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function onLoadScreenComplete(e:Event) : void
|
||||
{
|
||||
show(true);
|
||||
}
|
||||
|
||||
private static function startLoad() : void
|
||||
{
|
||||
show(true);
|
||||
gMainFrame.loaderCache.openFile(_target,loadCompleteHandler,loadProgressHandler);
|
||||
}
|
||||
|
||||
private static function loadCompleteHandler(e:LoaderEvent) : void
|
||||
{
|
||||
_entry = e.entry;
|
||||
if(_completeCallback != null)
|
||||
{
|
||||
_completeCallback();
|
||||
}
|
||||
}
|
||||
|
||||
private static function loadProgressHandler(evt:LoaderEvent) : void
|
||||
{
|
||||
if(evt.status && Boolean(_loadScreen))
|
||||
{
|
||||
return;
|
||||
}
|
||||
throw new Error("ERROR: Unable to show loading progress! status:" + evt.status + " preloader:" + _loadScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package
|
||||
{
|
||||
import mx.core.ByteArrayAsset;
|
||||
|
||||
[ExcludeClass]
|
||||
[Embed(source="/_assets/2_LoadProgress_LoadScreenSWF.bin", mimeType="application/octet-stream")]
|
||||
public class LoadProgress_LoadScreenSWF extends ByteArrayAsset
|
||||
{
|
||||
|
||||
public function LoadProgress_LoadScreenSWF()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package
|
||||
{
|
||||
import avatar.AvatarManager;
|
||||
import com.sbi.client.SFEvent;
|
||||
import com.sbi.loader.FileServerEvent;
|
||||
import gui.GuiManager;
|
||||
import loader.DefPacksDefHelper;
|
||||
import localization.LocalizationManager;
|
||||
import room.RoomXtCommManager;
|
||||
|
||||
public class LocalizationXtCommManager
|
||||
{
|
||||
|
||||
public function LocalizationXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init() : void
|
||||
{
|
||||
XtReplyDemuxer.addModule(handleXtReply,"l");
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
XtReplyDemuxer.removeModule(handleXtReply);
|
||||
}
|
||||
|
||||
public static function sendLocalizationShardRequest(shardId:int) : void
|
||||
{
|
||||
RoomXtCommManager.waitForLangPack = true;
|
||||
AvatarManager.waitForLangPack = true;
|
||||
gMainFrame.server.setXtObject_Str("ls",[shardId]);
|
||||
}
|
||||
|
||||
public static function sendLocalizationShardsRequest(shardIds:Array) : void
|
||||
{
|
||||
RoomXtCommManager.waitForLangPack = true;
|
||||
AvatarManager.waitForLangPack = true;
|
||||
gMainFrame.server.setXtObject_Str("ls",shardIds);
|
||||
}
|
||||
|
||||
public static function handleXtReply(evt:SFEvent) : void
|
||||
{
|
||||
var data:Object = evt.obj;
|
||||
switch(data[0])
|
||||
{
|
||||
case "ls":
|
||||
handleLocalizationShardResponse(data);
|
||||
return;
|
||||
default:
|
||||
throw new Error("LocalizationXtCommManager: Received illegal cmd: " + data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleLocalizationShardResponse(data:Object) : void
|
||||
{
|
||||
var langIdResponseMsg:String = data[2];
|
||||
onLocalizationShardResponse(langIdResponseMsg);
|
||||
}
|
||||
|
||||
public static function onLocalizationShardResponse(langIdResponseMsg:String) : void
|
||||
{
|
||||
var langIdResponse:String = null;
|
||||
var langIdResponseParsed:Array = null;
|
||||
var shardId:int = 0;
|
||||
var langId:int = 0;
|
||||
var langIdResponses:Array = langIdResponseMsg.split(",");
|
||||
var _loc7_:int = 0;
|
||||
var _loc8_:* = langIdResponses;
|
||||
for each(langIdResponse in _loc8_)
|
||||
{
|
||||
langIdResponseParsed = langIdResponse.split(":");
|
||||
shardId = int(langIdResponseParsed[0]);
|
||||
langId = int(langIdResponseParsed[1]);
|
||||
requestLocalizationPack(langId);
|
||||
}
|
||||
}
|
||||
|
||||
public static function requestLocalizationPack(languageId:int) : void
|
||||
{
|
||||
var dpdh:DefPacksDefHelper = new DefPacksDefHelper();
|
||||
LocalizationManager.currentLanguage = languageId;
|
||||
LocalizationManager.hasLocalizations = false;
|
||||
RoomXtCommManager.waitForLangPack = true;
|
||||
AvatarManager.waitForLangPack = true;
|
||||
dpdh.init(uint(DefPacksDefHelper.DEF_LOCALIZATION + "" + languageId),onLocalizationListResponse,RoomXtCommManager.startRoomLoadIfReady,FileServerEvent.AMF3_TYPE);
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_LOCALIZATION + "" + languageId] = dpdh;
|
||||
}
|
||||
|
||||
public static function onLocalizationListResponse(dfdh:DefPacksDefHelper) : void
|
||||
{
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_LOCALIZATION + "." + LocalizationManager.currentLanguage] = null;
|
||||
LocalizationManager.setLocalizations(dfdh.def,GuiManager.mainHud != null ? GuiManager.rebuildMainHud : null);
|
||||
if(Boolean(dfdh.passback))
|
||||
{
|
||||
dfdh.passback();
|
||||
}
|
||||
}
|
||||
|
||||
public static function onPreferredLocalizationListResponse(dfdh:DefPacksDefHelper) : void
|
||||
{
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_PREFERRED_LOCALIZATION + "." + LocalizationManager.accountLanguage] = null;
|
||||
LocalizationManager.setPreferredLocalizations(dfdh.def);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,516 @@
|
||||
package
|
||||
{
|
||||
import avatar.UserInfoCache;
|
||||
import com.sbi.analytics.SBTracker;
|
||||
import com.sbi.client.SFClient;
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import com.sbi.graphics.LayerAnim;
|
||||
import com.sbi.loader.ImageServerURL;
|
||||
import com.sbi.loader.LoaderCache;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Stage;
|
||||
import flash.display.StageScaleMode;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.external.ExternalInterface;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import gamePlayFlow.GamePlay;
|
||||
import room.LayerManager;
|
||||
|
||||
public class MainFrame extends Sprite
|
||||
{
|
||||
|
||||
public static var avatarCreationLogin:MovieClip;
|
||||
|
||||
public static var avatarCreationVO:MovieClip;
|
||||
|
||||
public static var handleLocalExternalCall:Function;
|
||||
|
||||
private static var _configLoadedCallback:Function;
|
||||
|
||||
private static var m:MainFrame;
|
||||
|
||||
private static var _flashVarUserName:String;
|
||||
|
||||
public static const VIEW_WIDTH:int = 900;
|
||||
|
||||
public static const VIEW_HEIGHT:int = 550;
|
||||
|
||||
public static const ROOMS_FOLDER:String = "roomDefs/";
|
||||
|
||||
public static const CDN_SALT:String = "J@mnim4L";
|
||||
|
||||
public static const MSG_ID_LOGIN_IN_USE:int = -11;
|
||||
|
||||
public static const MSG_ID_LOGIN_ACCT_MAINT:int = -12;
|
||||
|
||||
public static const MSG_ID_LOGIN_CONNECTION:int = -14;
|
||||
|
||||
public static const MSG_ID_LOGIN_BANNED:int = -15;
|
||||
|
||||
public static const MSG_ID_LOGIN_SERVER_MAINT:int = -16;
|
||||
|
||||
private static const _configDebugFile:String = "clientdevtest.xml";
|
||||
|
||||
private static const _configDebugTemplateFile:String = "clientdevtest.template.xml";
|
||||
|
||||
private var _client:SFClient = null;
|
||||
|
||||
private var _path:String = null;
|
||||
|
||||
private var _stage:Stage;
|
||||
|
||||
private var _gamePlay:DisplayObjectContainer;
|
||||
|
||||
private var _waitingRoom:DisplayObjectContainer;
|
||||
|
||||
private var _createAccount:DisplayObjectContainer;
|
||||
|
||||
private var _loaderCache:LoaderCache;
|
||||
|
||||
public var userInfo:UserInfoCache;
|
||||
|
||||
public var clientInfo:Object;
|
||||
|
||||
public var classNames:Array;
|
||||
|
||||
private var _layerInfo:Object;
|
||||
|
||||
public function MainFrame()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getInstance(flashVars:Object = null, configLoadedCallback:Function = null, path:String = "", main:DisplayObjectContainer = null) : MainFrame
|
||||
{
|
||||
var stg:Stage = null;
|
||||
var extIntAvail:Boolean = false;
|
||||
var msk:Shape = null;
|
||||
var haveFlashVars:Boolean = false;
|
||||
var loadit:URLLoader = null;
|
||||
if(m == null)
|
||||
{
|
||||
if(path == null || main == null || main.stage == null)
|
||||
{
|
||||
throw new Error("ERROR: Attempted to call initial getInstance on MainFrame without correct parameters!");
|
||||
}
|
||||
stg = main.stage;
|
||||
LoadProgress.init(stg);
|
||||
LoadProgress.show(true,LoadProgress.INITIALIZING);
|
||||
LoaderCache.cdnSalt = CDN_SALT;
|
||||
extIntAvail = ExternalInterface.available;
|
||||
if(extIntAvail)
|
||||
{
|
||||
DebugUtility.debugTrace("extIntAvail is true");
|
||||
DebugUtility.debugTrace("mrc dm init starting up call returned:" + ExternalInterface.call("mrc",["dm","init:starting up"]));
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("extIntAvail is false");
|
||||
}
|
||||
msk = new Shape();
|
||||
msk.graphics.clear();
|
||||
msk.graphics.lineStyle(1,16777215);
|
||||
msk.graphics.beginFill(16777215);
|
||||
msk.graphics.drawRect(0,0,VIEW_WIDTH,VIEW_HEIGHT);
|
||||
msk.graphics.endFill();
|
||||
main.addChild(msk);
|
||||
main.mask = msk;
|
||||
stg.showDefaultContextMenu = false;
|
||||
stg.scaleMode = StageScaleMode.NO_SCALE;
|
||||
m = new MainFrame();
|
||||
m.init(new Singleton(),path,stg);
|
||||
gMainFrame = m;
|
||||
if(extIntAvail)
|
||||
{
|
||||
try
|
||||
{
|
||||
DebugUtility.debugTrace("init:adding mec callback");
|
||||
ExternalInterface.addCallback("mec",handleLocalExternalCall);
|
||||
DebugUtility.debugTrace("init:mec added, calling lc...");
|
||||
ExternalInterface.call("mrc",["lc"]);
|
||||
DebugUtility.debugTrace("init:... lc called, waiting for ixm...");
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
DebugUtility.debugTrace("init:ERROR hit during AJC ext mod setup! msg:" + e.message + " stack:" + e.getStackTrace());
|
||||
}
|
||||
}
|
||||
DebugUtility.debugTrace("init: setting extCallsActive to false");
|
||||
gMainFrame.clientInfo.extCallsActive = false;
|
||||
DebugUtility.debugTrace("init: set extCallsActive to false");
|
||||
_configLoadedCallback = configLoadedCallback;
|
||||
haveFlashVars = Boolean(flashVars && flashVars.smartfoxServer);
|
||||
DebugUtility.debugTrace("MainFrame.getInstance - haveFlashVars:" + haveFlashVars);
|
||||
gMainFrame.clientInfo.devMode = !haveFlashVars;
|
||||
if(haveFlashVars)
|
||||
{
|
||||
_flashVarUserName = flashVars.username;
|
||||
DebugUtility.debugTrace("MainFrame.getInstance - flashVars.smartfoxServer:" + flashVars.smartfoxServer + " flashVars.smartfoxPort:" + flashVars.smartfoxPort + " flashVars.blueboxServer:" + flashVars.blueboxServer + " flashVars.blueboxPort:" + flashVars.blueboxPort + " flashVars.content:" + flashVars.content + " flashVars.website:" + flashVars.website);
|
||||
if(!(Boolean(flashVars.smartfoxServer) && Boolean(flashVars.smartfoxPort) && Boolean(flashVars.blueboxServer) && Boolean(flashVars.blueboxPort) && Boolean(flashVars.content) && Boolean(flashVars.website)))
|
||||
{
|
||||
DebugUtility.debugTrace("MainFrame.getInstance - Invalid FlashVars! Throwing error...");
|
||||
throw new Error("Invalid FlashVars!");
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("startupRoom"))
|
||||
{
|
||||
flashVars.startupRoom = "jamaa_township.room_main";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("worldmapRoom"))
|
||||
{
|
||||
flashVars.worldmapRoom = "world_map/room_main.xroom";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("dangermapRoom"))
|
||||
{
|
||||
flashVars.dangermapRoom = "danger_map/room_main.xroom";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("clientDebug"))
|
||||
{
|
||||
flashVars.clientDebug = "false";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("build_version"))
|
||||
{
|
||||
flashVars.build_version = "0";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("deploy_version"))
|
||||
{
|
||||
flashVars.deploy_version = "0";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("locale"))
|
||||
{
|
||||
flashVars.locale = "en-US";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("sg_params"))
|
||||
{
|
||||
flashVars.sg_params = "";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("buddyRoomTimerInterval"))
|
||||
{
|
||||
flashVars.buddyRoomTimerInterval = "30000";
|
||||
}
|
||||
if(!flashVars.hasOwnProperty("countryCode"))
|
||||
{
|
||||
flashVars.countryCode = "";
|
||||
}
|
||||
if(String(flashVars.sg_params).indexOf("%") >= 0)
|
||||
{
|
||||
throw new Error("Invalid sg_params!");
|
||||
}
|
||||
gMainFrame.clientInfo.localMode = false;
|
||||
LoaderCache.localMode = false;
|
||||
applyConfigVars(flashVars);
|
||||
}
|
||||
else
|
||||
{
|
||||
loadit = new URLLoader();
|
||||
loadit.dataFormat = URLLoaderDataFormat.TEXT;
|
||||
loadit.addEventListener(Event.COMPLETE,configDebugLoadCompleteHandler);
|
||||
loadit.addEventListener(IOErrorEvent.IO_ERROR,configDebugLoadIOErrorHandler);
|
||||
loadit.load(new URLRequest(_configDebugFile));
|
||||
}
|
||||
}
|
||||
SBTracker.create();
|
||||
return m;
|
||||
}
|
||||
|
||||
public static function isInitialized() : Boolean
|
||||
{
|
||||
return Boolean(m != null);
|
||||
}
|
||||
|
||||
private static function applyConfigVars(cfgVars:Object) : void
|
||||
{
|
||||
var p:String = null;
|
||||
var sfServers:Array = null;
|
||||
var si:int = 0;
|
||||
for(p in cfgVars)
|
||||
{
|
||||
gMainFrame.clientInfo[p] = cfgVars[p];
|
||||
}
|
||||
sfServers = [cfgVars.smartfoxServer];
|
||||
si = 1;
|
||||
while(cfgVars.hasOwnProperty("smartfoxServer" + si))
|
||||
{
|
||||
sfServers.push(cfgVars["smartfoxServer" + si]);
|
||||
si++;
|
||||
}
|
||||
var bbServers:Array = [cfgVars.blueboxServer];
|
||||
var bi:int = 1;
|
||||
while(cfgVars.hasOwnProperty("blueboxServer" + bi))
|
||||
{
|
||||
bbServers.push(cfgVars["blueboxServer" + bi]);
|
||||
bi++;
|
||||
}
|
||||
gMainFrame.server.setServerConfig(sfServers,cfgVars.smartfoxPort,bbServers,cfgVars.blueboxPort,cfgVars.clientDebug);
|
||||
var buildVersionStr:String = cfgVars.build_version;
|
||||
gMainFrame.clientInfo.buildVersion = buildVersionStr;
|
||||
LoaderCache.buildVersion = buildVersionStr;
|
||||
var deployVersionStr:String = cfgVars.deploy_version;
|
||||
gMainFrame.clientInfo.deployVersion = deployVersionStr;
|
||||
LoaderCache.deployVersion = deployVersionStr;
|
||||
var localeStr:String = cfgVars.locale;
|
||||
gMainFrame.clientInfo.locale = localeStr;
|
||||
var clientIpStr:String = cfgVars.myExternalIp;
|
||||
gMainFrame.clientInfo.clientIp = clientIpStr;
|
||||
gMainFrame.clientInfo.websiteURL = cfgVars.website;
|
||||
var contentStr:String = cfgVars.content;
|
||||
gMainFrame.clientInfo.contentURL = contentStr;
|
||||
LoaderCache.contentURL = contentStr;
|
||||
var isCreateAccount:Boolean = Boolean(cfgVars.webRefPath == "create_account");
|
||||
gMainFrame.clientInfo.isCreateAccount = isCreateAccount;
|
||||
var isWaitingMode:Boolean = Boolean(cfgVars.waitingMode == "true");
|
||||
gMainFrame.clientInfo.waitingMode = isWaitingMode;
|
||||
var buddyRoomTimerInterval:int = int(cfgVars.buddyRoomTimerInterval);
|
||||
gMainFrame.clientInfo.buddyRoomTimerInterval = buddyRoomTimerInterval;
|
||||
gMainFrame.clientInfo.startUpRoom = String(cfgVars.startupRoom);
|
||||
gMainFrame.clientInfo.worldMapRoom = ROOMS_FOLDER + cfgVars.worldmapRoom;
|
||||
gMainFrame.clientInfo.dangerMapRoom = ROOMS_FOLDER + cfgVars.dangermapRoom;
|
||||
gMainFrame.clientInfo.clientDebug = cfgVars.clientDebug;
|
||||
gMainFrame.clientInfo.sgParams = String(cfgVars.sg_params);
|
||||
gMainFrame.clientInfo.mdUrl = String(cfgVars.mdUrl);
|
||||
gMainFrame.clientInfo.currentTimestamp = Number(cfgVars.currentTimestamp);
|
||||
gMainFrame.clientInfo.sbTrackerIp = String(cfgVars.sbStatTrackerIp);
|
||||
gMainFrame.clientInfo.sbTrackerModulator = cfgVars.sbStatModulator;
|
||||
gMainFrame.clientInfo.landingPage = String(cfgVars.landingPage);
|
||||
gMainFrame.clientInfo.authToken = cfgVars.auth_token;
|
||||
gMainFrame.clientInfo.countryCode = cfgVars.countryCode;
|
||||
if(gMainFrame.clientInfo.countryCode == undefined)
|
||||
{
|
||||
gMainFrame.clientInfo.countryCode = "";
|
||||
}
|
||||
DebugUtility.debugTrace("-configXml/flashVars info-");
|
||||
DebugUtility.debugTrace("smartfoxAddress:" + cfgVars.smartfoxServer);
|
||||
DebugUtility.debugTrace("smartfoxPort:" + cfgVars.smartfoxPort);
|
||||
DebugUtility.debugTrace("blueboxAddress:" + cfgVars.blueboxServer);
|
||||
DebugUtility.debugTrace("blueboxPort:" + cfgVars.blueboxPort);
|
||||
DebugUtility.debugTrace("buildVersionStr:" + buildVersionStr);
|
||||
DebugUtility.debugTrace("deployVersionStr:" + deployVersionStr);
|
||||
DebugUtility.debugTrace("localeStr:" + localeStr);
|
||||
DebugUtility.debugTrace("clientIpStr:" + clientIpStr);
|
||||
DebugUtility.debugTrace("contentURL:" + gMainFrame.clientInfo.contentURL);
|
||||
DebugUtility.debugTrace("websiteURL:" + gMainFrame.clientInfo.websiteURL);
|
||||
DebugUtility.debugTrace("isCreateAccount:" + isCreateAccount + " webRefPath:" + cfgVars.webRefPath);
|
||||
DebugUtility.debugTrace("isWaitingMode:" + isWaitingMode + " cfgVars.waitingMode:" + cfgVars.waitingMode);
|
||||
DebugUtility.debugTrace("startUpRoom:" + gMainFrame.clientInfo.startUpRoom);
|
||||
DebugUtility.debugTrace("worldMapRoom:" + gMainFrame.clientInfo.worldMapRoom);
|
||||
DebugUtility.debugTrace("dangerMapRoom:" + gMainFrame.clientInfo.dangerMapRoom);
|
||||
DebugUtility.debugTrace("clientDebug:" + cfgVars.clientDebug);
|
||||
DebugUtility.debugTrace("sgParams:" + gMainFrame.clientInfo.sgParams);
|
||||
DebugUtility.debugTrace("buddyRoomTimerInterval:" + gMainFrame.clientInfo.buddyRoomTimerInterval);
|
||||
m._loaderCache = new LoaderCache();
|
||||
_configLoadedCallback();
|
||||
}
|
||||
|
||||
private static function configDebugLoadIOErrorHandler(ioe:IOErrorEvent) : void
|
||||
{
|
||||
var loadit:URLLoader = new URLLoader();
|
||||
loadit.dataFormat = URLLoaderDataFormat.TEXT;
|
||||
loadit.addEventListener(Event.COMPLETE,configDebugLoadCompleteHandler);
|
||||
loadit.addEventListener(IOErrorEvent.IO_ERROR,configDebugTemplateLoadIOErrorHandler);
|
||||
loadit.load(new URLRequest(_configDebugTemplateFile));
|
||||
}
|
||||
|
||||
private static function configDebugTemplateLoadIOErrorHandler(ioe:IOErrorEvent) : void
|
||||
{
|
||||
throw new Error("IOError reading " + _configDebugFile + " or " + _configDebugTemplateFile + "! ioe:" + ioe);
|
||||
}
|
||||
|
||||
private static function configDebugLoadCompleteHandler(event:Event) : void
|
||||
{
|
||||
var alx:XML = null;
|
||||
var localStr:String = null;
|
||||
var xs:String = null;
|
||||
var configXml:XML = new XML(event.target.data);
|
||||
var alxl:XMLList = configXml.autoLogins.children();
|
||||
var n:int = 0;
|
||||
for each(alx in alxl)
|
||||
{
|
||||
gMainFrame.clientInfo["autoLogin" + ++n] = [String(alx.name.text()),String(alx.token.text())];
|
||||
}
|
||||
localStr = configXml.local.text();
|
||||
if(localStr == "false")
|
||||
{
|
||||
gMainFrame.clientInfo.localMode = false;
|
||||
LoaderCache.localMode = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
gMainFrame.clientInfo.localMode = true;
|
||||
}
|
||||
var clientDebug:String = configXml.clientDebug.text();
|
||||
if(clientDebug != "true")
|
||||
{
|
||||
clientDebug = "false";
|
||||
}
|
||||
var isWaitingMode:String = "false";
|
||||
if(configXml.hasOwnProperty("waitingMode"))
|
||||
{
|
||||
isWaitingMode = configXml.waitingMode.text();
|
||||
}
|
||||
var xmlVars:Object = {
|
||||
"smartfoxServer":configXml.smartfoxServer.text(),
|
||||
"smartfoxPort":configXml.smartfoxPort.text(),
|
||||
"blueboxServer":configXml.blueboxServer.text(),
|
||||
"blueboxPort":configXml.blueboxPort.text(),
|
||||
"content":configXml.content.text(),
|
||||
"website":configXml.website.text(),
|
||||
"startupRoom":configXml.startupRoom.text(),
|
||||
"worldmapRoom":configXml.worldmapRoom.text(),
|
||||
"dangermapRoom":configXml.dangermapRoom.text(),
|
||||
"clientDebug":clientDebug,
|
||||
"waitingMode":isWaitingMode,
|
||||
"sg_params":"",
|
||||
"mdUrl":configXml.mdUrl
|
||||
};
|
||||
var xsi:int = 1;
|
||||
while(configXml.hasOwnProperty("smartfoxServer" + xsi))
|
||||
{
|
||||
xmlVars["smartfoxServer" + xsi] = configXml["smartfoxServer" + xsi].text();
|
||||
xsi++;
|
||||
}
|
||||
var xbi:int = 1;
|
||||
while(configXml.hasOwnProperty("blueboxServer" + xbi))
|
||||
{
|
||||
xmlVars["blueboxServer" + xbi] = configXml["blueboxServer" + xbi].text();
|
||||
xbi++;
|
||||
}
|
||||
xmlVars["build_version"] = configXml.hasOwnProperty("build_version") ? configXml.build_version.text() : "0";
|
||||
xmlVars["deploy_version"] = configXml.hasOwnProperty("deploy_version") ? configXml.deploy_version.text() : "0";
|
||||
xmlVars["locale"] = configXml.hasOwnProperty("locale") ? configXml.locale.text() : "en";
|
||||
xmlVars["myExternalIp"] = configXml.hasOwnProperty("myExternalIp") ? configXml.myExternalIp.text() : "";
|
||||
xmlVars["webRefPath"] = configXml.hasOwnProperty("webRefPath") ? configXml.webRefPath.text() : "";
|
||||
xmlVars["buddyRoomTimerInterval"] = configXml.hasOwnProperty("buddyRoomTimerInterval") ? configXml.buddyRoomTimerInterval.text() : "30000";
|
||||
for(xs in xmlVars)
|
||||
{
|
||||
if(xmlVars[xs] is XMLList && XMLList(xmlVars[xs]).length() > 1)
|
||||
{
|
||||
throw new Error("Invalid clientdevtest xml config! Found multiple tags of same name:" + xs);
|
||||
}
|
||||
}
|
||||
applyConfigVars(xmlVars);
|
||||
}
|
||||
|
||||
public function init(s:Singleton, path:String, st:Stage) : void
|
||||
{
|
||||
this._path = path;
|
||||
this._stage = st;
|
||||
this._client = new SFClient();
|
||||
this.userInfo = new UserInfoCache();
|
||||
this.userInfo.init();
|
||||
this.clientInfo = new Object();
|
||||
this.clientInfo.invisMode = false;
|
||||
this.classNames = null;
|
||||
}
|
||||
|
||||
public function get server() : SFClient
|
||||
{
|
||||
return this._client;
|
||||
}
|
||||
|
||||
public function get path() : String
|
||||
{
|
||||
return this._path;
|
||||
}
|
||||
|
||||
override public function get stage() : Stage
|
||||
{
|
||||
return this._stage;
|
||||
}
|
||||
|
||||
public function set createAccount(newCreateAccount:DisplayObjectContainer) : void
|
||||
{
|
||||
this._createAccount = newCreateAccount;
|
||||
}
|
||||
|
||||
public function get createAccount() : DisplayObjectContainer
|
||||
{
|
||||
return this._createAccount;
|
||||
}
|
||||
|
||||
public function set waitingRoom(newWaitingRoom:DisplayObjectContainer) : void
|
||||
{
|
||||
this._waitingRoom = newWaitingRoom;
|
||||
}
|
||||
|
||||
public function get waitingRoom() : DisplayObjectContainer
|
||||
{
|
||||
return this._waitingRoom;
|
||||
}
|
||||
|
||||
public function set gamePlay(newGamePlay:DisplayObjectContainer) : void
|
||||
{
|
||||
this._gamePlay = newGamePlay;
|
||||
}
|
||||
|
||||
public function get gamePlay() : DisplayObjectContainer
|
||||
{
|
||||
return this._gamePlay;
|
||||
}
|
||||
|
||||
public function get layerManager() : LayerManager
|
||||
{
|
||||
return (this._gamePlay as GamePlay).layerManager;
|
||||
}
|
||||
|
||||
public function get loaderCache() : LoaderCache
|
||||
{
|
||||
return this._loaderCache;
|
||||
}
|
||||
|
||||
public function set layerInfo(o:Object) : void
|
||||
{
|
||||
this._layerInfo = o;
|
||||
ImageServerURL.instance.layerInfo = o;
|
||||
}
|
||||
|
||||
public function get myFlashVarUserName() : String
|
||||
{
|
||||
return _flashVarUserName;
|
||||
}
|
||||
|
||||
public function set myFlashVarUserName(name:String) : void
|
||||
{
|
||||
_flashVarUserName = name;
|
||||
}
|
||||
|
||||
public function isInMinigame() : Boolean
|
||||
{
|
||||
return this._gamePlay != null && Boolean(this._gamePlay["isInMinigame"]());
|
||||
}
|
||||
|
||||
public function setAvatarOffsets(a:Array) : void
|
||||
{
|
||||
LayerAnim.avOffsets = a;
|
||||
}
|
||||
|
||||
public function switchServersIfNeeded(newNode:String) : Boolean
|
||||
{
|
||||
DebugUtility.debugTrace("switchServersIfNeeded called with newNode:" + newNode);
|
||||
var newServerNodeIp:String = newNode;
|
||||
DebugUtility.debugTrace("checking new node:" + newServerNodeIp + " vs old node:" + this._client.serverIp);
|
||||
if(this._client.serverIp == newServerNodeIp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this._gamePlay["reconnecting"] = true;
|
||||
this._gamePlay["showLoadProgress"](true,LoadProgress.JOINING_SERVER);
|
||||
this._client.switchServerNode(newServerNodeIp);
|
||||
this._client.disconnect();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Singleton
|
||||
{
|
||||
|
||||
public function Singleton()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package Party
|
||||
{
|
||||
import com.sbi.client.SFEvent;
|
||||
import gui.PartyManager;
|
||||
|
||||
public class PartyXtCommManager
|
||||
{
|
||||
|
||||
public function PartyXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init() : void
|
||||
{
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
}
|
||||
|
||||
public static function sendJoinPartyRequest(partyDefId:int) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("sj",[partyDefId]);
|
||||
}
|
||||
|
||||
public static function handleXtReply(evt:SFEvent) : void
|
||||
{
|
||||
var data:Object = evt.obj;
|
||||
switch(data[0])
|
||||
{
|
||||
case "sl":
|
||||
PartyManager.partyListResponse(data);
|
||||
break;
|
||||
case "sj":
|
||||
PartyManager.roomSoireeResponse(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,739 @@
|
||||
package
|
||||
{
|
||||
import achievement.AchievementXtCommManager;
|
||||
import avatar.NameBar;
|
||||
import com.sbi.analytics.SBTracker;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.globalization.Collator;
|
||||
import flash.globalization.NumberFormatter;
|
||||
import item.Item;
|
||||
import loader.MediaHelper;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class Utility
|
||||
{
|
||||
|
||||
private static var _notEnoughGemsPopup:MovieClip;
|
||||
|
||||
private static var _loadingMediaHelper:MediaHelper;
|
||||
|
||||
private static var _showLoadingSpiral:Function;
|
||||
|
||||
private static var _darken:Function;
|
||||
|
||||
private static var _undarken:Function;
|
||||
|
||||
private static var _levelShapeHelper:MediaHelper;
|
||||
|
||||
private static var _shapesMediaHelperArray:Array;
|
||||
|
||||
private static const AUDIO_TYPE:int = 4;
|
||||
|
||||
private static const NOT_ENOUGH_GEMS_POPUP_ID:int = 1245;
|
||||
|
||||
public static const ACCOUNT_TYPE_ARCHIVED:int = -2;
|
||||
|
||||
public static const ACCOUNT_TYPE_NEW:int = -1;
|
||||
|
||||
public static const ACCOUNT_TYPE_NONE:int = 0;
|
||||
|
||||
public static const NON_MEMBER:int = 1;
|
||||
|
||||
public static const PREMIUM_MEMBER:int = 2;
|
||||
|
||||
public static const BETA_MEMBER:int = 3;
|
||||
|
||||
public static const INTERNAL:int = 4;
|
||||
|
||||
public static const COMMUNITY:int = 5;
|
||||
|
||||
public static const INTERACTION_TYPE_BUDDY:int = 0;
|
||||
|
||||
public static const INTERACTION_TYPE_TRADE:int = 1;
|
||||
|
||||
public static const INTERACTION_TYPE_GIFT:int = 2;
|
||||
|
||||
public static const INTERACTION_TYPE_CHAT:int = 3;
|
||||
|
||||
public static const INTERACTION_TYPE_JAG:int = 4;
|
||||
|
||||
public static const INTERACTION_TYPE_MULTIPLAYER:int = 5;
|
||||
|
||||
public static const INTERACTION_TYPE_PVP:int = 6;
|
||||
|
||||
public static const INTERACTION_TYPE_QUEST:int = 7;
|
||||
|
||||
public static const ENVIRO_LAND:int = 0;
|
||||
|
||||
public static const ENVIRO_OCEAN:int = 1;
|
||||
|
||||
public static const ENVIRO_AIR:int = 2;
|
||||
|
||||
public static const ROOMTYPE_WORLD:int = 0;
|
||||
|
||||
public static const ROOMTYPE_GAME:int = 1;
|
||||
|
||||
public static const ROOMTYPE_DEN:int = 2;
|
||||
|
||||
public static const ROOMTYPE_LOBBY:int = 3;
|
||||
|
||||
public static const ROOMTYPE_FFM:int = 4;
|
||||
|
||||
public static const ROOMTYPE_PARTY:int = 5;
|
||||
|
||||
public static const ROOMTYPE_WORLDGAME:int = 6;
|
||||
|
||||
public static const ROOMTYPE_QUEST:int = 7;
|
||||
|
||||
public static const ROOMTYPE_QUEST_STAGING:int = 8;
|
||||
|
||||
public function Utility()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(showLoadingSpiral:Function, darken:Function, undarken:Function) : void
|
||||
{
|
||||
_showLoadingSpiral = showLoadingSpiral;
|
||||
_darken = darken;
|
||||
_undarken = undarken;
|
||||
}
|
||||
|
||||
public static function isLand(flag:int) : Boolean
|
||||
{
|
||||
return (flag & 1) == 1;
|
||||
}
|
||||
|
||||
public static function isOcean(flag:int) : Boolean
|
||||
{
|
||||
return (flag >> ENVIRO_OCEAN & 1) == 1;
|
||||
}
|
||||
|
||||
public static function isAir(flag:int) : Boolean
|
||||
{
|
||||
return (flag >> ENVIRO_AIR & 1) == 1;
|
||||
}
|
||||
|
||||
public static function isSameEnviroType(enviroTypeFlag:int, currEnviroType:int) : Boolean
|
||||
{
|
||||
if(currEnviroType == ENVIRO_LAND)
|
||||
{
|
||||
return isLand(enviroTypeFlag);
|
||||
}
|
||||
if(currEnviroType == ENVIRO_AIR)
|
||||
{
|
||||
return isAir(enviroTypeFlag);
|
||||
}
|
||||
return isOcean(enviroTypeFlag);
|
||||
}
|
||||
|
||||
public static function isRoomOfThisType(type:int) : Boolean
|
||||
{
|
||||
return gMainFrame.clientInfo.roomType == type;
|
||||
}
|
||||
|
||||
public static function sortItems(items:Array, startIdx:int, sortId:int, sortId2:int = -1, sortId3:int = -1) : Array
|
||||
{
|
||||
var newItemArray:Array = null;
|
||||
var itemObj:Object = null;
|
||||
var type:int = 0;
|
||||
var oldItems:Array = items.concat();
|
||||
newItemArray = [];
|
||||
var i:int = startIdx;
|
||||
var j:int = 0;
|
||||
var oceanSortId:int = -1;
|
||||
var oldItemLength:int = int(oldItems.length);
|
||||
while(i < oldItemLength)
|
||||
{
|
||||
itemObj = oldItems[i];
|
||||
if(itemObj is Item)
|
||||
{
|
||||
type = int(itemObj.layerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
type = int(itemObj.sortId);
|
||||
}
|
||||
if(Boolean(itemObj.isOcean))
|
||||
{
|
||||
if(oceanSortId == -1)
|
||||
{
|
||||
oceanSortId = convertOceanSortId(sortId);
|
||||
}
|
||||
if(type == oceanSortId)
|
||||
{
|
||||
newItemArray[j] = oldItems[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
else if(type == sortId || type == sortId2 || type == sortId3)
|
||||
{
|
||||
newItemArray[j] = oldItems[i];
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return newItemArray;
|
||||
}
|
||||
|
||||
public static function sortItemsAll(items:Array, startIdx:int, sortId:int, sortId2:int = -1, sortId3:int = -1) : Array
|
||||
{
|
||||
var newItemArray:Array = null;
|
||||
var itemAdded:Boolean = false;
|
||||
var itemObj:Object = null;
|
||||
var type:int = 0;
|
||||
var oldItems:Array = items.concat();
|
||||
newItemArray = [];
|
||||
var i:int = startIdx;
|
||||
var j:int = 0;
|
||||
var oceanSortId:int = -1;
|
||||
while(i < oldItems.length)
|
||||
{
|
||||
itemAdded = false;
|
||||
itemObj = oldItems[i];
|
||||
if(itemObj is Item)
|
||||
{
|
||||
type = int(itemObj.layerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
type = int(itemObj.sortId);
|
||||
}
|
||||
if(Boolean(itemObj.isOcean))
|
||||
{
|
||||
if(oceanSortId == -1)
|
||||
{
|
||||
oceanSortId = convertOceanSortId(sortId);
|
||||
}
|
||||
if(type == oceanSortId)
|
||||
{
|
||||
newItemArray[j] = oldItems[i];
|
||||
itemAdded = true;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
else if(type == sortId || type == sortId2 || type == sortId3)
|
||||
{
|
||||
newItemArray[j] = oldItems[i];
|
||||
itemAdded = true;
|
||||
j++;
|
||||
}
|
||||
if(itemAdded)
|
||||
{
|
||||
oldItems.splice(i,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return newItemArray.concat(oldItems);
|
||||
}
|
||||
|
||||
public static function sortByItem(items:Array, startIdx:int) : Array
|
||||
{
|
||||
var newItems:Array = items.concat();
|
||||
if(newItems[0] is Item)
|
||||
{
|
||||
newItems.sortOn(["accId","color"],Array.NUMERIC | Array.DESCENDING);
|
||||
}
|
||||
else
|
||||
{
|
||||
newItems.sortOn(["sortId","itemDefId","version"],Array.NUMERIC);
|
||||
}
|
||||
return newItems;
|
||||
}
|
||||
|
||||
private static function convertOceanSortId(sortId:int) : int
|
||||
{
|
||||
switch(sortId)
|
||||
{
|
||||
case Item.HEAD_LAYER_1:
|
||||
case Item.HEAD_LAYER_2:
|
||||
case Item.HEAD_LAYER_3:
|
||||
return Item.OCEAN_HEAD_LAYER;
|
||||
case Item.BACK_LAYER:
|
||||
return Item.OCEAN_BACK_LAYER;
|
||||
case Item.LEG_LAYER:
|
||||
return Item.OCEAN_LEG_LAYER;
|
||||
case Item.NECK_LAYER:
|
||||
return Item.OCEAN_NECK_LAYER;
|
||||
default:
|
||||
return sortId;
|
||||
}
|
||||
}
|
||||
|
||||
public static function numDenItemsInList(itemArray:Array, enviroType:int, findAudioItemsOnly:Boolean = false) : int
|
||||
{
|
||||
return int(denItemsInList(itemArray,enviroType,true,findAudioItemsOnly));
|
||||
}
|
||||
|
||||
public static function denItemListByEnviroType(itemArray:Array, enviroType:int, findAudioItemsOnly:Boolean = false) : Array
|
||||
{
|
||||
return denItemsInList(itemArray,enviroType,false,findAudioItemsOnly) as Array;
|
||||
}
|
||||
|
||||
private static function denItemsInList(itemArray:Array, enviroType:int, returnItemCount:Boolean = false, findAudioItemsOnly:Boolean = false) : Object
|
||||
{
|
||||
var itemArrayLength:int = 0;
|
||||
var i:int = 0;
|
||||
var returnArray:Array = [];
|
||||
if(Boolean(itemArray))
|
||||
{
|
||||
itemArrayLength = int(itemArray.length);
|
||||
for(i = 0; i < itemArrayLength; i++)
|
||||
{
|
||||
if(findAudioItemsOnly)
|
||||
{
|
||||
if(itemArray[i].sortId == AUDIO_TYPE)
|
||||
{
|
||||
returnArray.push(itemArray[i]);
|
||||
}
|
||||
}
|
||||
else if(itemArray[i].sortId != AUDIO_TYPE)
|
||||
{
|
||||
if(enviroType == -1 || itemArray[i].enviroType == enviroType)
|
||||
{
|
||||
returnArray.push(itemArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(returnItemCount)
|
||||
{
|
||||
return returnArray.length;
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
public static function numClothingItemsInList(itemArray:Array, enviroType:int) : int
|
||||
{
|
||||
return int(clothingItemsInList(itemArray,enviroType,true));
|
||||
}
|
||||
|
||||
public static function clothingItemListByEnviroType(itemArray:Array, enviroType:int) : Array
|
||||
{
|
||||
return clothingItemsInList(itemArray,enviroType,false) as Array;
|
||||
}
|
||||
|
||||
private static function clothingItemsInList(itemArray:Array, enviroType:int, returnItemCount:Boolean = false) : Object
|
||||
{
|
||||
var listLength:int = 0;
|
||||
var i:int = 0;
|
||||
var returnArray:Array = [];
|
||||
if(Boolean(itemArray))
|
||||
{
|
||||
listLength = int(itemArray.length);
|
||||
for(i = 0; i < listLength; i++)
|
||||
{
|
||||
if(itemArray[i].enviroType == enviroType)
|
||||
{
|
||||
returnArray.push(itemArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(returnItemCount)
|
||||
{
|
||||
return returnArray.length;
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
public static function setupNotEnoughGemsPopup(guiLayer:DisplayObjectContainer, itemCost:int, currencyType:int = 0, callback:Function = null) : void
|
||||
{
|
||||
if(Boolean(_notEnoughGemsPopup))
|
||||
{
|
||||
_showLoadingSpiral(false);
|
||||
_notEnoughGemsPopup.x = MainFrame.VIEW_WIDTH * 0.5;
|
||||
_notEnoughGemsPopup.y = MainFrame.VIEW_HEIGHT * 0.5;
|
||||
if(currencyType == Item.GEM_CURRENCY)
|
||||
{
|
||||
_notEnoughGemsPopup.currency.gotoAndStop("gems");
|
||||
_notEnoughGemsPopup.gemsTxt.text = gMainFrame.clientInfo.gemCount;
|
||||
}
|
||||
else if(currencyType == Item.TICKET_CURRENCY)
|
||||
{
|
||||
_notEnoughGemsPopup.currency.gotoAndStop("tickets");
|
||||
_notEnoughGemsPopup.gemsTxt.text = gMainFrame.clientInfo.ticketCount;
|
||||
}
|
||||
else if(currencyType == Item.ORB_CURRENCY)
|
||||
{
|
||||
_notEnoughGemsPopup.currency.gotoAndStop("orbs");
|
||||
_notEnoughGemsPopup.gemsTxt.text = gMainFrame.clientInfo.orbCount;
|
||||
}
|
||||
else if(currencyType == Item.DIAMOND_CURRENCY)
|
||||
{
|
||||
_notEnoughGemsPopup.currency.gotoAndStop("diamonds");
|
||||
_notEnoughGemsPopup.gemsTxt.text = gMainFrame.clientInfo.diamondCount;
|
||||
}
|
||||
_notEnoughGemsPopup.costTxt.text = itemCost;
|
||||
_notEnoughGemsPopup.needTxt.text = itemCost - int(_notEnoughGemsPopup.gemsTxt.text);
|
||||
_notEnoughGemsPopup.addEventListener(MouseEvent.MOUSE_DOWN,onPopupDown,false,0,true);
|
||||
_notEnoughGemsPopup.bx.addEventListener(MouseEvent.MOUSE_DOWN,onClose,false,0,true);
|
||||
_notEnoughGemsPopup.closeCallback = callback;
|
||||
guiLayer.addChild(_notEnoughGemsPopup);
|
||||
_darken(_notEnoughGemsPopup);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loadingMediaHelper = new MediaHelper();
|
||||
_loadingMediaHelper.init(NOT_ENOUGH_GEMS_POPUP_ID,onMediaItemLoaded,{
|
||||
"guiLayer":guiLayer,
|
||||
"itemCost":itemCost,
|
||||
"currencyType":currencyType,
|
||||
"callback":callback
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static function onMediaItemLoaded(img:MovieClip) : void
|
||||
{
|
||||
if(img.mediaHelper.id == NOT_ENOUGH_GEMS_POPUP_ID)
|
||||
{
|
||||
SBTracker.push();
|
||||
SBTracker.trackPageview("/game/play/popup/avatarSwitch/buyAnimal_notEnoughGems",-1,SBTracker.TYPE_EVENT);
|
||||
_notEnoughGemsPopup = MovieClip(img.getChildAt(0));
|
||||
setupNotEnoughGemsPopup(img.passback.guiLayer,img.passback.itemCost,img.passback.currencyType,img.passback.callback);
|
||||
}
|
||||
}
|
||||
|
||||
private static function onPopupDown(evt:MouseEvent) : void
|
||||
{
|
||||
evt.stopPropagation();
|
||||
}
|
||||
|
||||
private static function onClose(evt:MouseEvent) : void
|
||||
{
|
||||
evt.stopPropagation();
|
||||
if(evt.currentTarget.parent == _notEnoughGemsPopup)
|
||||
{
|
||||
SBTracker.pop();
|
||||
_undarken(_notEnoughGemsPopup);
|
||||
_notEnoughGemsPopup.parent.removeChild(_notEnoughGemsPopup);
|
||||
if(_notEnoughGemsPopup.closeCallback != null)
|
||||
{
|
||||
_notEnoughGemsPopup.closeCallback();
|
||||
_notEnoughGemsPopup.closeCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function canBuddy() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canTrade() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> INTERACTION_TYPE_TRADE & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canGift() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> INTERACTION_TYPE_GIFT & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canChat() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> INTERACTION_TYPE_CHAT & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canJAG() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> INTERACTION_TYPE_JAG & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canMultiplayer() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> INTERACTION_TYPE_MULTIPLAYER & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canPVP() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> INTERACTION_TYPE_PVP & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canQuest() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> INTERACTION_TYPE_QUEST & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canTradeNonDegraded() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> 8 & 1) == 1;
|
||||
}
|
||||
|
||||
public static function canGiftNonDegraded() : Boolean
|
||||
{
|
||||
return (gMainFrame.clientInfo.interactions >> 9 & 1) == 1;
|
||||
}
|
||||
|
||||
public static function toggleInteractionBit(bitIndex:int) : void
|
||||
{
|
||||
gMainFrame.clientInfo.interactions ^= 1 << bitIndex;
|
||||
}
|
||||
|
||||
public static function calculatePrintTime(mins:int, hours:int, showFullWords:Boolean = false, days:int = 0) : String
|
||||
{
|
||||
var time:String = "";
|
||||
if(hours > 0 || days > 0)
|
||||
{
|
||||
if(mins == 0)
|
||||
{
|
||||
showFullWords = true;
|
||||
}
|
||||
if(days > 0)
|
||||
{
|
||||
if(days == 1)
|
||||
{
|
||||
time = LocalizationManager.translateIdAndInsertOnly(11118,days).toLowerCase() + " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
time = LocalizationManager.translateIdAndInsertOnly(11119,days).toLowerCase() + " ";
|
||||
}
|
||||
}
|
||||
if(showFullWords)
|
||||
{
|
||||
if(hours == 1)
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11120,hours).toLowerCase();
|
||||
}
|
||||
else
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11121,hours).toLowerCase();
|
||||
}
|
||||
if(mins == 1)
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11122,mins);
|
||||
}
|
||||
else if(mins != 0)
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11123,mins);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(hours == 1)
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11124,hours);
|
||||
}
|
||||
else
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11125,hours);
|
||||
}
|
||||
if(mins == 1)
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11126,mins);
|
||||
}
|
||||
else if(mins != 0)
|
||||
{
|
||||
time += LocalizationManager.translateIdAndInsertOnly(11127,mins);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(mins == 1)
|
||||
{
|
||||
time = LocalizationManager.translateIdAndInsertOnly(11128,mins);
|
||||
}
|
||||
else
|
||||
{
|
||||
time = LocalizationManager.translateIdAndInsertOnly(11129,mins);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
public static function calculateTime(sec:int) : Object
|
||||
{
|
||||
var hours:Number = NaN;
|
||||
var tempHours:Number = NaN;
|
||||
var mins:Number = NaN;
|
||||
var days:Number = 0;
|
||||
var tempTime:Number = Math.ceil(sec / 60);
|
||||
if(tempTime < 60)
|
||||
{
|
||||
mins = tempTime;
|
||||
hours = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempHours = tempTime / 60;
|
||||
if(tempHours >= 24)
|
||||
{
|
||||
days = tempHours / 24;
|
||||
hours = (days - Math.floor(days)) * 24;
|
||||
mins = (hours - Math.floor(hours)) * 60;
|
||||
hours = Math.floor(hours);
|
||||
days = int(days);
|
||||
}
|
||||
else
|
||||
{
|
||||
hours = Math.floor(tempHours);
|
||||
mins = Math.ceil((tempHours - Math.floor(tempHours)) * 60);
|
||||
}
|
||||
}
|
||||
return {
|
||||
"days":days,
|
||||
"hours":hours,
|
||||
"mins":mins
|
||||
};
|
||||
}
|
||||
|
||||
public static function convertNumberToString(num:int) : String
|
||||
{
|
||||
var nf:NumberFormatter = new NumberFormatter(LocalizationManager.localeForNumberFormatting);
|
||||
nf.trailingZeros = false;
|
||||
return nf.formatInt(num);
|
||||
}
|
||||
|
||||
public static function isMember(accountType:int) : Boolean
|
||||
{
|
||||
return accountType >= PREMIUM_MEMBER;
|
||||
}
|
||||
|
||||
public static function getColorId(nameBarData:int) : int
|
||||
{
|
||||
var frameId:int = 0;
|
||||
var color:int = nameBarData & 0xFF;
|
||||
if(color == 0)
|
||||
{
|
||||
frameId = 4;
|
||||
}
|
||||
else if(color > 3 && color <= NameBar.MAX_COLORS)
|
||||
{
|
||||
frameId = color + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
frameId = Math.min(4,color);
|
||||
}
|
||||
return frameId;
|
||||
}
|
||||
|
||||
public static function createXpShape(level:int, isMember:Boolean, iconHolderUp:MovieClip, iconHolderMouse:MovieClip = null, nameBarData:int = 65536) : void
|
||||
{
|
||||
var shapeId:int = 0;
|
||||
var arrayId:String = null;
|
||||
if((nameBarData >> 16 & 0xFF) == 0)
|
||||
{
|
||||
if(_shapesMediaHelperArray == null)
|
||||
{
|
||||
_shapesMediaHelperArray = [];
|
||||
}
|
||||
shapeId = Math.floor(level / 5) > NameBar.LEVEL_SHAPES.length - 1 ? int(NameBar.LEVEL_SHAPES[NameBar.LEVEL_SHAPES.length - 1]) : int(NameBar.LEVEL_SHAPES[Math.floor(level / 5)]);
|
||||
arrayId = String(_shapesMediaHelperArray.length);
|
||||
_levelShapeHelper = new MediaHelper();
|
||||
_levelShapeHelper.init(shapeId,onLevelShapeLoaded,{
|
||||
"shapeUp":true,
|
||||
"level":level,
|
||||
"isMember":isMember,
|
||||
"iconHolderUp":iconHolderUp,
|
||||
"iconHolderMouse":iconHolderMouse,
|
||||
"arrayId":arrayId
|
||||
});
|
||||
_shapesMediaHelperArray[arrayId] = _levelShapeHelper;
|
||||
if(iconHolderMouse != null)
|
||||
{
|
||||
arrayId = String(_shapesMediaHelperArray.length);
|
||||
_levelShapeHelper = new MediaHelper();
|
||||
_levelShapeHelper.init(shapeId,onLevelShapeLoaded,{
|
||||
"shapeUp":false,
|
||||
"level":level,
|
||||
"isMember":isMember,
|
||||
"iconHolderUp":iconHolderUp,
|
||||
"iconHolderMouse":iconHolderMouse,
|
||||
"arrayId":arrayId
|
||||
});
|
||||
_shapesMediaHelperArray[arrayId] = _levelShapeHelper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function onLevelShapeLoaded(img:MovieClip) : void
|
||||
{
|
||||
var shape:MovieClip = null;
|
||||
if(Boolean(img))
|
||||
{
|
||||
shape = MovieClip(img.getChildAt(0));
|
||||
if(Boolean(img.passback.isMember))
|
||||
{
|
||||
shape.gotoAndStop("member");
|
||||
}
|
||||
shape.text.text = img.passback.level;
|
||||
if(img.passback.shapeUp == true)
|
||||
{
|
||||
_shapesMediaHelperArray[img.passback.arrayId].destroy();
|
||||
delete _shapesMediaHelperArray[img.passback.arrayId];
|
||||
while(img.passback.iconHolderUp.numChildren > 0)
|
||||
{
|
||||
img.passback.iconHolderUp.removeChildAt(0);
|
||||
}
|
||||
img.passback.iconHolderUp.addChild(shape);
|
||||
img.passback.iconHolderUp.parent.parent.gotoAndStop(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shapesMediaHelperArray[img.passback.arrayId].destroy();
|
||||
delete _shapesMediaHelperArray[img.passback.arrayId];
|
||||
while(img.passback.iconHolderMouse.numChildren > 0)
|
||||
{
|
||||
img.passback.iconHolderMouse.removeChildAt(0);
|
||||
}
|
||||
img.passback.iconHolderMouse.addChild(shape);
|
||||
img.passback.iconHolderMouse.parent.parent.gotoAndStop(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function findIndexToInsert(array:Array, currName:String) : int
|
||||
{
|
||||
var col:Collator = null;
|
||||
var comparisonName:String = null;
|
||||
var i:int = 0;
|
||||
if(array.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
col = new Collator(LocalizationManager.localeForSorting);
|
||||
comparisonName = array[0];
|
||||
i = 0;
|
||||
while(col.compare(currName,comparisonName) > 0)
|
||||
{
|
||||
if(++i > array.length - 1)
|
||||
{
|
||||
return array.length;
|
||||
}
|
||||
comparisonName = array[i];
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static function isSettingOn(settingBit:int) : Boolean
|
||||
{
|
||||
var settingUV:int = int(gMainFrame.userInfo.userVarCache.getUserVarValueById(AchievementXtCommManager.UV_SETTINGS));
|
||||
if(settingUV == -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if((settingUV >> settingBit & 1) == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function numProperties(obj:Object) : int
|
||||
{
|
||||
var prop:Object = null;
|
||||
var count:int = 0;
|
||||
for each(prop in obj)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package
|
||||
{
|
||||
import com.sbi.client.SFEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.utils.Timer;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
public class XtReplyDemuxer
|
||||
{
|
||||
|
||||
private static var _delayList:Array;
|
||||
|
||||
private static var _delayTimer:Timer;
|
||||
|
||||
private static var _xtReplyCallbacks:Array;
|
||||
|
||||
private static var _xtReplyCommands:Array;
|
||||
|
||||
private static var MSG_DELAY_MS:int = 0;
|
||||
|
||||
public function XtReplyDemuxer()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init() : void
|
||||
{
|
||||
if(MSG_DELAY_MS > 0)
|
||||
{
|
||||
_delayList = [];
|
||||
_delayTimer = new Timer(10);
|
||||
_delayTimer.addEventListener(TimerEvent.TIMER,delayTimerHandler,false,0,true);
|
||||
_delayTimer.start();
|
||||
}
|
||||
_xtReplyCallbacks = [];
|
||||
_xtReplyCommands = [];
|
||||
gMainFrame.server.addEventListener(SFEvent.ON_XT_REPLY,xtReplyHandler,false,0,true);
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
_delayList = null;
|
||||
if(Boolean(_delayTimer))
|
||||
{
|
||||
if(_delayTimer.running)
|
||||
{
|
||||
_delayTimer.stop();
|
||||
}
|
||||
_delayTimer = null;
|
||||
}
|
||||
_xtReplyCallbacks = null;
|
||||
_xtReplyCommands = null;
|
||||
gMainFrame.server.removeEventListener(SFEvent.ON_XT_REPLY,xtReplyHandler);
|
||||
}
|
||||
|
||||
public static function addModule(callback:Function, command:String) : void
|
||||
{
|
||||
_xtReplyCallbacks.push(callback);
|
||||
_xtReplyCommands.push(command);
|
||||
}
|
||||
|
||||
public static function removeModule(callback:Function) : void
|
||||
{
|
||||
var modIdx:int = _xtReplyCallbacks.indexOf(callback);
|
||||
if(modIdx >= 0)
|
||||
{
|
||||
_xtReplyCallbacks.splice(modIdx,1);
|
||||
_xtReplyCommands.splice(modIdx,1);
|
||||
return;
|
||||
}
|
||||
throw new Error("module not found! callback:" + callback);
|
||||
}
|
||||
|
||||
public static function xtReplyHandler(evt:SFEvent) : void
|
||||
{
|
||||
if(_xtReplyCallbacks[_xtReplyCommands.indexOf(evt.obj[0].charAt(0))] == undefined)
|
||||
{
|
||||
throw new Error("ERROR: undefined module command:" + evt.obj[0]);
|
||||
}
|
||||
var xtReplyFunction:Function = _xtReplyCallbacks[_xtReplyCommands.indexOf(evt.obj[0].charAt(0))];
|
||||
if(MSG_DELAY_MS == 0)
|
||||
{
|
||||
xtReplyFunction(evt);
|
||||
}
|
||||
else
|
||||
{
|
||||
_delayList.push({
|
||||
"f":xtReplyFunction,
|
||||
"e":evt,
|
||||
"ts":getTimer() + MSG_DELAY_MS
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static function delayTimerHandler(te:TimerEvent) : void
|
||||
{
|
||||
var o:Object = null;
|
||||
var currTime:uint = uint(getTimer());
|
||||
for(var i:int = 0; i < _delayList.length; i++)
|
||||
{
|
||||
o = _delayList[i];
|
||||
if(o.ts >= currTime)
|
||||
{
|
||||
break;
|
||||
}
|
||||
o.f(o.e);
|
||||
_delayList.splice(0,1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
package achievement
|
||||
{
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import loader.MediaHelper;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class Achievement
|
||||
{
|
||||
|
||||
public static var GEMS_EARNED:int = 1;
|
||||
|
||||
public static var GEMS_SPENT:int = 2;
|
||||
|
||||
public static var SHOP_DEN_ITEM:int = 3;
|
||||
|
||||
public static var SHOP_ACCESSORY:int = 4;
|
||||
|
||||
public static var MAIL_SEND:int = 38;
|
||||
|
||||
public static var MAIL_GIFT:int = 39;
|
||||
|
||||
public static var BUDDY_ADDED:int = 40;
|
||||
|
||||
public static var MEMBER_NEW:int = 66;
|
||||
|
||||
public static var BASE_MEDAL_ID:int = 289;
|
||||
|
||||
public static var BASE_RIBBON_ID:int = 290;
|
||||
|
||||
public static var BASE_TROPHY_ID:int = 291;
|
||||
|
||||
private var _invId:int;
|
||||
|
||||
private var _baseImageMediaId:int;
|
||||
|
||||
private var _iconMediaId:int;
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _descr:String;
|
||||
|
||||
private var _mediaText:String;
|
||||
|
||||
private var _nameId:int;
|
||||
|
||||
private var _baseImage:Sprite;
|
||||
|
||||
private var _baseImageHelper:MediaHelper;
|
||||
|
||||
private var _icon:Sprite;
|
||||
|
||||
private var _iconHelper:MediaHelper;
|
||||
|
||||
private var _baseImageReceived:Boolean;
|
||||
|
||||
private var _iconReceived:Boolean;
|
||||
|
||||
private var _isMyAchievement:Boolean;
|
||||
|
||||
private var _scalePercent:Number = 1;
|
||||
|
||||
private var _xPos:Number = 0;
|
||||
|
||||
private var _yPos:Number = 0;
|
||||
|
||||
public function Achievement()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init(initInvId:int, initBaseMediaId:int, initIconMediaId:int, initNameId:int, initMediaText:String = "", initIsMyAchievement:Boolean = false) : void
|
||||
{
|
||||
var splitMediaText:Array = null;
|
||||
this._invId = initInvId;
|
||||
this._baseImageMediaId = initBaseMediaId;
|
||||
this._iconMediaId = initIconMediaId;
|
||||
this._nameId = initNameId;
|
||||
this._name = LocalizationManager.translateIdOnly(initNameId);
|
||||
if(initMediaText == "")
|
||||
{
|
||||
this._mediaText = initMediaText;
|
||||
}
|
||||
else
|
||||
{
|
||||
splitMediaText = initMediaText.split(",");
|
||||
if(splitMediaText.length > 1)
|
||||
{
|
||||
this._mediaText = Utility.convertNumberToString(int(splitMediaText.join("")));
|
||||
}
|
||||
else
|
||||
{
|
||||
this._mediaText = initMediaText;
|
||||
}
|
||||
}
|
||||
this._isMyAchievement = initIsMyAchievement;
|
||||
this._baseImage = new Sprite();
|
||||
this._baseImageHelper = new MediaHelper();
|
||||
this._baseImageHelper.init(this._baseImageMediaId,this.baseImageReceived);
|
||||
this._icon = new Sprite();
|
||||
this._iconHelper = new MediaHelper();
|
||||
this._iconHelper.init(this._iconMediaId,this.iconReceived);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
if(Boolean(this._iconHelper))
|
||||
{
|
||||
this._iconHelper.destroy();
|
||||
}
|
||||
if(Boolean(this._baseImageHelper))
|
||||
{
|
||||
this._baseImageHelper.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public function clone() : Achievement
|
||||
{
|
||||
var a:Achievement = null;
|
||||
a = new Achievement();
|
||||
a.init(this._invId,this._baseImageMediaId,this._iconMediaId,this._nameId,this._mediaText,this._isMyAchievement);
|
||||
return a;
|
||||
}
|
||||
|
||||
public function setScale(scalePercent:Number) : void
|
||||
{
|
||||
this._scalePercent = scalePercent;
|
||||
if(this._iconReceived && this._baseImageReceived)
|
||||
{
|
||||
this._baseImage.scaleX = this._scalePercent;
|
||||
this._baseImage.scaleY = this._scalePercent;
|
||||
}
|
||||
}
|
||||
|
||||
public function setPosition(xPos:Number, yPos:Number) : void
|
||||
{
|
||||
this._xPos = xPos;
|
||||
this._yPos = yPos;
|
||||
if(this._iconReceived && this._baseImageReceived)
|
||||
{
|
||||
this._baseImage.x = -this._baseImage.width * this._xPos;
|
||||
this._baseImage.y = -this._baseImage.height * this._yPos;
|
||||
}
|
||||
}
|
||||
|
||||
private function baseImageReceived(img:MovieClip) : void
|
||||
{
|
||||
var width:Number = NaN;
|
||||
if(Boolean(img))
|
||||
{
|
||||
img = MovieClip(img.getChildAt(0));
|
||||
this._baseImage.addChild(img);
|
||||
if(this._iconReceived)
|
||||
{
|
||||
img.itemBlock.addChild(this._icon);
|
||||
this.allImagesLoaded();
|
||||
}
|
||||
if(this._mediaText == "")
|
||||
{
|
||||
img.num.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
img.num.txt.text = this._mediaText;
|
||||
width = Number(img.num.txt.textWidth);
|
||||
if(width > 15)
|
||||
{
|
||||
if(width > 25)
|
||||
{
|
||||
img.num.gotoAndStop(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
img.num.gotoAndStop(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._baseImageHelper.destroy();
|
||||
this._baseImageHelper = null;
|
||||
this._baseImageReceived = true;
|
||||
}
|
||||
}
|
||||
|
||||
private function iconReceived(img:MovieClip) : void
|
||||
{
|
||||
if(Boolean(img))
|
||||
{
|
||||
this._icon.addChild(img);
|
||||
if(this._baseImageReceived)
|
||||
{
|
||||
MovieClip(this._baseImage.getChildAt(0)).itemBlock.addChild(this._icon);
|
||||
this.allImagesLoaded();
|
||||
}
|
||||
this._iconHelper.destroy();
|
||||
this._iconHelper = null;
|
||||
this._iconReceived = true;
|
||||
}
|
||||
}
|
||||
|
||||
private function allImagesLoaded() : void
|
||||
{
|
||||
var scale:Number = 0.9;
|
||||
if(this._isMyAchievement)
|
||||
{
|
||||
scale = 1;
|
||||
}
|
||||
this._baseImage.scaleX = scale * this._scalePercent;
|
||||
this._baseImage.scaleY = scale * this._scalePercent;
|
||||
this._baseImage.x = -this._baseImage.width * this._xPos;
|
||||
this._baseImage.y = -this._baseImage.height * this._yPos;
|
||||
}
|
||||
|
||||
public function get invId() : int
|
||||
{
|
||||
return this._invId;
|
||||
}
|
||||
|
||||
public function get baseImageMediaId() : int
|
||||
{
|
||||
return this._baseImageMediaId;
|
||||
}
|
||||
|
||||
public function get iconMediaId() : int
|
||||
{
|
||||
return this._iconMediaId;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function get descr() : String
|
||||
{
|
||||
return this._descr;
|
||||
}
|
||||
|
||||
public function get mediaText() : String
|
||||
{
|
||||
return this._mediaText;
|
||||
}
|
||||
|
||||
public function get image() : Sprite
|
||||
{
|
||||
return this._baseImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
package achievement
|
||||
{
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.utils.Timer;
|
||||
import loader.MediaHelper;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class AchievementManager
|
||||
{
|
||||
|
||||
private static var _newAchievements:Array;
|
||||
|
||||
private static var _finishedCallbacks:Array;
|
||||
|
||||
private static var _popupMediaHelper:MediaHelper;
|
||||
|
||||
private static var _achievementPopup:MovieClip;
|
||||
|
||||
private static var _achievementImg:Sprite;
|
||||
|
||||
private static var _popupDisplayTimer:Timer;
|
||||
|
||||
private static var _popupDelayTimer:Timer;
|
||||
|
||||
private static var _state:int;
|
||||
|
||||
private static var _fpsLayer:DisplayObjectContainer;
|
||||
|
||||
private static const ACHIEVEMENT_POPUP_MEDIA_ID:int = 2721;
|
||||
|
||||
private static const STATE_IDLE:int = 0;
|
||||
|
||||
private static const STATE_DISPLAYING:int = 1;
|
||||
|
||||
public function AchievementManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(initFpsLayer:DisplayObjectContainer) : void
|
||||
{
|
||||
_fpsLayer = initFpsLayer;
|
||||
_finishedCallbacks = [];
|
||||
_newAchievements = [];
|
||||
_popupDisplayTimer = new Timer(3000);
|
||||
_popupDelayTimer = new Timer(500);
|
||||
_state = STATE_IDLE;
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
_newAchievements.splice(0,_newAchievements.length);
|
||||
_newAchievements = null;
|
||||
_finishedCallbacks.splice(0,_finishedCallbacks.length);
|
||||
_finishedCallbacks = null;
|
||||
if(Boolean(_popupDisplayTimer))
|
||||
{
|
||||
_popupDisplayTimer.stop();
|
||||
_popupDisplayTimer = null;
|
||||
}
|
||||
if(Boolean(_popupDelayTimer))
|
||||
{
|
||||
_popupDelayTimer.stop();
|
||||
_popupDelayTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function hasAchievement() : Boolean
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function displayNewAchievements(finishedCallback:Function = null) : void
|
||||
{
|
||||
if(finishedCallback != null)
|
||||
{
|
||||
if(_finishedCallbacks.indexOf(finishedCallback) < 0 && _newAchievements.length > 0)
|
||||
{
|
||||
_finishedCallbacks.push(finishedCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
finishedCallback();
|
||||
}
|
||||
}
|
||||
if(_state == STATE_IDLE && _newAchievements.length > 0)
|
||||
{
|
||||
_state = STATE_DISPLAYING;
|
||||
displayNextAchievement();
|
||||
}
|
||||
}
|
||||
|
||||
private static function finishedDisplayingNewAchievements() : void
|
||||
{
|
||||
var length:int = int(_finishedCallbacks.length);
|
||||
for(var i:int = 0; i < length; i++)
|
||||
{
|
||||
_finishedCallbacks[i]();
|
||||
}
|
||||
_finishedCallbacks.splice(0,_finishedCallbacks.length);
|
||||
}
|
||||
|
||||
private static function displayNextAchievement() : void
|
||||
{
|
||||
var a:Achievement = _newAchievements[0];
|
||||
_achievementImg = a.image;
|
||||
a.setScale(2);
|
||||
a.setPosition(0.5,0.5);
|
||||
if(Boolean(_achievementPopup))
|
||||
{
|
||||
_achievementPopup.achievementWindow.itemBlock.addChild(_achievementImg);
|
||||
LocalizationManager.updateToFit(_achievementPopup.achievementWindow.acmtNameTxt,a.name,false,false);
|
||||
_fpsLayer.addChild(_achievementPopup);
|
||||
_achievementPopup.gotoAndPlay(1);
|
||||
_achievementPopup.achievementWindow.gotoAndPlay(1);
|
||||
AJAudio.playAchievementSound();
|
||||
_popupDisplayTimer.start();
|
||||
_popupDisplayTimer.addEventListener("timer",onDisplayTimerFinished,false,0,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_popupMediaHelper = new MediaHelper();
|
||||
_popupMediaHelper.init(ACHIEVEMENT_POPUP_MEDIA_ID,popupHelperCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private static function onDisplayTimerFinished(e:TimerEvent) : void
|
||||
{
|
||||
_popupDisplayTimer.stop();
|
||||
_fpsLayer.removeChild(_achievementPopup);
|
||||
_achievementPopup.achievementWindow.itemBlock.removeChild(_achievementImg);
|
||||
_newAchievements.splice(0,1);
|
||||
if(_newAchievements.length > 0)
|
||||
{
|
||||
_popupDelayTimer.start();
|
||||
_popupDelayTimer.addEventListener("timer",onDelayTimerFinished,false,0,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_state = STATE_IDLE;
|
||||
finishedDisplayingNewAchievements();
|
||||
}
|
||||
}
|
||||
|
||||
private static function onDelayTimerFinished(e:TimerEvent) : void
|
||||
{
|
||||
_popupDelayTimer.stop();
|
||||
displayNextAchievement();
|
||||
}
|
||||
|
||||
private static function popupHelperCallback(img:MovieClip) : void
|
||||
{
|
||||
if(Boolean(img))
|
||||
{
|
||||
_achievementPopup = new MovieClip();
|
||||
_achievementPopup = img;
|
||||
_achievementPopup.visible = true;
|
||||
_achievementPopup.addEventListener(MouseEvent.MOUSE_DOWN,onPopupDown,false,0,true);
|
||||
_popupMediaHelper.destroy();
|
||||
_popupMediaHelper = null;
|
||||
displayNextAchievement();
|
||||
}
|
||||
}
|
||||
|
||||
private static function onPopupDown(m:MouseEvent) : void
|
||||
{
|
||||
m.stopPropagation();
|
||||
}
|
||||
|
||||
public static function addAchievement(a:Achievement) : void
|
||||
{
|
||||
if(Boolean(a))
|
||||
{
|
||||
_newAchievements.push(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
package achievement
|
||||
{
|
||||
import avatar.UserInfo;
|
||||
import com.sbi.client.SFEvent;
|
||||
|
||||
public class AchievementXtCommManager
|
||||
{
|
||||
|
||||
private static var _zaCallback:Function;
|
||||
|
||||
private static var _inMinigame:Function;
|
||||
|
||||
private static var _onUserVarsReceived:Function;
|
||||
|
||||
private static var _setGemBonusValues:Function;
|
||||
|
||||
private static var _bMyUserVarsReceived:Boolean;
|
||||
|
||||
private static var _zsCallbacks:Object;
|
||||
|
||||
public static const UV_JAMAA_JOURNAL_TIMESTAMP:int = 112;
|
||||
|
||||
public static const UV_JAMAA_JOURNAL_TIMESTAMP_STARTUP:int = 158;
|
||||
|
||||
public static const UV_BRADY_BARR_COUNT:int = 128;
|
||||
|
||||
public static const UV_TRADING:int = 129;
|
||||
|
||||
public static const UV_PET_COUNTER:int = 212;
|
||||
|
||||
public static const UV_DAILY_GEM_BONUS:int = 214;
|
||||
|
||||
public static const UV_AVT_VIEWABLE_FLAG:int = 287;
|
||||
|
||||
public static const UV_TIERNEY_THYS_COUNT:int = 297;
|
||||
|
||||
public static const UV_PET_INVENTORY_MAX:int = 338;
|
||||
|
||||
public static const UV_PET_VIEWABLE_FLAG:int = 342;
|
||||
|
||||
public static const UV_SETTINGS:int = 363;
|
||||
|
||||
public static const UV_PARTY_JB_ENTER:int = 366;
|
||||
|
||||
public static const UV_PARTY_JB_ENTER_BIT_ARRAY:Array = [27];
|
||||
|
||||
public static const UV_TUTORIALS:int = 379;
|
||||
|
||||
public static const ACHIEVEMENT_REQUEST_INTERVAL:int = 10000;
|
||||
|
||||
public function AchievementXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(inMingame:Function, onUserVarsReceived:Function, setGemBonusValues:Function) : void
|
||||
{
|
||||
_inMinigame = inMingame;
|
||||
_onUserVarsReceived = onUserVarsReceived;
|
||||
_setGemBonusValues = setGemBonusValues;
|
||||
_zsCallbacks = new Object();
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
_zsCallbacks = null;
|
||||
}
|
||||
|
||||
public static function requestAchievements(userName:String, callback:Function = null) : void
|
||||
{
|
||||
var milliSecSinceLastRequestForThisUser:Number = NaN;
|
||||
var now:Number = NaN;
|
||||
var ui:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(userName);
|
||||
if(Boolean(ui))
|
||||
{
|
||||
milliSecSinceLastRequestForThisUser = ui.getTimeOfLastAchievementRequest();
|
||||
now = new Date().getTime();
|
||||
if(now - milliSecSinceLastRequestForThisUser > ACHIEVEMENT_REQUEST_INTERVAL)
|
||||
{
|
||||
_zaCallback = callback;
|
||||
ui.setTimeOfLastAchievementRequest(now);
|
||||
if(milliSecSinceLastRequestForThisUser == 0)
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("za",[userName,-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("za",[userName,int((now - milliSecSinceLastRequestForThisUser) / 1000)]);
|
||||
}
|
||||
}
|
||||
else if(callback != null)
|
||||
{
|
||||
callback(ui.achievements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function requestSetUserVar(userVarId:int, setValue:int, callback:Function = null, bitState:Boolean = true) : void
|
||||
{
|
||||
if(!gMainFrame.clientInfo.invisMode)
|
||||
{
|
||||
if(userVarId <= 0)
|
||||
{
|
||||
trace("ERROR: Illegal userVarId=" + userVarId);
|
||||
return;
|
||||
}
|
||||
if(callback != null)
|
||||
{
|
||||
_zsCallbacks[userVarId] = {
|
||||
"uv":userVarId,
|
||||
"c":callback
|
||||
};
|
||||
}
|
||||
gMainFrame.server.setXtObject_Str("zs",[userVarId,setValue,bitState ? 1 : 0]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function requestAllUserVars() : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("zg",[]);
|
||||
}
|
||||
|
||||
public static function requestDeleteAllAchievementsAndUserVars() : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("zd",[]);
|
||||
}
|
||||
|
||||
public static function handleXtReply(evt:SFEvent) : void
|
||||
{
|
||||
var data:Object = evt.obj;
|
||||
switch(data[0])
|
||||
{
|
||||
case "za":
|
||||
getAchievementsResponse(data);
|
||||
break;
|
||||
case "zs":
|
||||
setUserVarResponse(data);
|
||||
break;
|
||||
case "zg":
|
||||
getUserVarsResponse(data);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Did not expect ext cmd=" + data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function setUserVarResponse(data:Object) : void
|
||||
{
|
||||
var userVarDefId:int = 0;
|
||||
var shouldRequestAchievements:Boolean = false;
|
||||
var newAchievements:Array = null;
|
||||
var value:int = 0;
|
||||
var a:Achievement = null;
|
||||
var j:int = 2;
|
||||
var numUserVars:int = 1;
|
||||
for(var i:int = 0; i < numUserVars; i++)
|
||||
{
|
||||
userVarDefId = int(data[j++]);
|
||||
value = int(data[j++]);
|
||||
gMainFrame.userInfo.userVarCache.updateUserVar(userVarDefId,value);
|
||||
if(userVarDefId == UV_DAILY_GEM_BONUS)
|
||||
{
|
||||
_setGemBonusValues(value);
|
||||
}
|
||||
}
|
||||
var numAchievementsTriggered:int = int(data[j++]);
|
||||
if(numAchievementsTriggered > 0)
|
||||
{
|
||||
newAchievements = [];
|
||||
if(!gMainFrame.userInfo.playerUserInfo.achievements)
|
||||
{
|
||||
shouldRequestAchievements = true;
|
||||
}
|
||||
for(i = 0; i < numAchievementsTriggered; i++)
|
||||
{
|
||||
a = new Achievement();
|
||||
a.init(int(data[j++]),int(data[j++]),int(data[j++]),int(data[j++]),data[j++],true);
|
||||
newAchievements.unshift(a);
|
||||
AchievementManager.addAchievement(a.clone());
|
||||
}
|
||||
}
|
||||
if(shouldRequestAchievements)
|
||||
{
|
||||
requestAchievements(gMainFrame.userInfo.playerUserInfo.userName);
|
||||
}
|
||||
else if(Boolean(newAchievements))
|
||||
{
|
||||
for(i = 0; i < numAchievementsTriggered; i++)
|
||||
{
|
||||
gMainFrame.userInfo.playerUserInfo.achievements.unshift(newAchievements[i]);
|
||||
}
|
||||
}
|
||||
if(!_inMinigame())
|
||||
{
|
||||
AchievementManager.displayNewAchievements();
|
||||
}
|
||||
var callbackObj:Object = _zsCallbacks[userVarDefId];
|
||||
if(Boolean(callbackObj))
|
||||
{
|
||||
callbackObj.c(userVarDefId,value);
|
||||
}
|
||||
}
|
||||
|
||||
private static function getUserVarsResponse(data:Object) : void
|
||||
{
|
||||
var j:int = 2;
|
||||
var numUserVars:int = int(data[j++]);
|
||||
var userVars:Object = new Object();
|
||||
for(var i:int = 0; i < numUserVars; i++)
|
||||
{
|
||||
userVars[int(data[j++])] = {
|
||||
"type":int(data[j++]),
|
||||
"value":int(data[j++])
|
||||
};
|
||||
}
|
||||
gMainFrame.userInfo.userVarCache.playerUserVars = userVars;
|
||||
if(!_bMyUserVarsReceived)
|
||||
{
|
||||
_onUserVarsReceived();
|
||||
}
|
||||
}
|
||||
|
||||
private static function getAchievementsResponse(data:Object) : void
|
||||
{
|
||||
var aList:Array = null;
|
||||
var i:int = 0;
|
||||
var a:Achievement = null;
|
||||
var j:int = 2;
|
||||
var userName:String = data[j++];
|
||||
var numAchievements:int = int(data[j++]);
|
||||
var ui:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(userName);
|
||||
if(numAchievements > 0)
|
||||
{
|
||||
aList = new Array(numAchievements);
|
||||
for(i = 0; i < numAchievements; i++)
|
||||
{
|
||||
a = new Achievement();
|
||||
a.init(int(data[j++]),int(data[j++]),int(data[j++]),int(data[j++]),data[j++],userName == gMainFrame.userInfo.playerUserInfo.userName);
|
||||
aList[i] = a;
|
||||
}
|
||||
aList.sortOn("invId",Array.NUMERIC | Array.DESCENDING);
|
||||
if(Boolean(ui))
|
||||
{
|
||||
ui.addAchievementsTolist(aList);
|
||||
}
|
||||
}
|
||||
if(_zaCallback != null)
|
||||
{
|
||||
if(userName == gMainFrame.userInfo.myUserName)
|
||||
{
|
||||
_zaCallback(Boolean(ui) ? ui.achievements : null);
|
||||
}
|
||||
else
|
||||
{
|
||||
_zaCallback(Boolean(ui) ? ui.achievements : null,numAchievements == -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import item.Item;
|
||||
|
||||
public class AccessoryState
|
||||
{
|
||||
|
||||
private var _accShownItems:Array;
|
||||
|
||||
private var _accShownLayers:Array;
|
||||
|
||||
public var ownerAvatar:Avatar;
|
||||
|
||||
public function AccessoryState()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init(initOwnerAvatar:Avatar) : void
|
||||
{
|
||||
this._accShownItems = [];
|
||||
this._accShownLayers = [];
|
||||
this.ownerAvatar = initOwnerAvatar;
|
||||
if(this.ownerAvatar.avName == null)
|
||||
{
|
||||
DebugUtility.debugTrace("break here");
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
if(Boolean(this._accShownItems))
|
||||
{
|
||||
this._accShownItems = null;
|
||||
}
|
||||
if(Boolean(this._accShownLayers))
|
||||
{
|
||||
this._accShownLayers = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function copyShownAccRef(copyFrom:AccessoryState) : void
|
||||
{
|
||||
DebugUtility.debugTrace("AccState copyAcc - ownerAvatar:" + this.ownerAvatar + (Boolean(this.ownerAvatar) ? " name:" + this.ownerAvatar.avName : "") + " copyFrom avatar:" + copyFrom.ownerAvatar + " name:" + copyFrom.ownerAvatar.avName);
|
||||
this.accShownItems = copyFrom.accShownItems;
|
||||
this.accShownLayers = copyFrom.accShownLayers;
|
||||
}
|
||||
|
||||
public function cloneShownAcc(copyFrom:AccessoryState) : void
|
||||
{
|
||||
this.accShownItems = copyFrom.accShownItems;
|
||||
for(var i:int = 0; i < this.accShownItems.length; i++)
|
||||
{
|
||||
this.accShownItems[i] = this.accShownItems[i].clone();
|
||||
}
|
||||
this.accShownLayers = copyFrom.accShownLayers;
|
||||
}
|
||||
|
||||
public function matchShownItems(copyFrom:AccessoryState, clothingItems:Array, bodyModItems:Array) : void
|
||||
{
|
||||
var j:int = 0;
|
||||
var k:int = 0;
|
||||
var numShownItems:int = int(copyFrom.accShownItems.length);
|
||||
this.accShownLayers = copyFrom.accShownLayers;
|
||||
for(var i:int = 0; i < numShownItems; i++)
|
||||
{
|
||||
if(copyFrom.accShownItems[i].type == Item.CLOTHING_TYPE)
|
||||
{
|
||||
for(j = 0; j < clothingItems.length; j++)
|
||||
{
|
||||
if(copyFrom.accShownItems[i].invIdx == clothingItems[j].invIdx)
|
||||
{
|
||||
this.accShownItems[i] = clothingItems[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(copyFrom.accShownItems[i].type == Item.BODY_MOD_TYPE)
|
||||
{
|
||||
for(k = 0; k < bodyModItems.length; k++)
|
||||
{
|
||||
if(copyFrom.accShownItems[i].invIdx == bodyModItems[k].invIdx)
|
||||
{
|
||||
this.accShownItems[i] = bodyModItems[k];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get accShownItems() : Array
|
||||
{
|
||||
return this._accShownItems;
|
||||
}
|
||||
|
||||
public function set accShownItems(setShown:Array) : void
|
||||
{
|
||||
this._accShownItems = setShown.concat();
|
||||
}
|
||||
|
||||
public function get accShownLayers() : Array
|
||||
{
|
||||
return this._accShownLayers;
|
||||
}
|
||||
|
||||
public function set accShownLayers(setShownLayers:Array) : void
|
||||
{
|
||||
this._accShownLayers = setShownLayers.concat();
|
||||
}
|
||||
|
||||
public function showAccessory(showItem:Item) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var accLength:int = 0;
|
||||
if(Boolean(showItem))
|
||||
{
|
||||
i = 0;
|
||||
accLength = int(this._accShownItems.length);
|
||||
while(i < accLength)
|
||||
{
|
||||
if(this._accShownItems[i].invIdx == showItem.invIdx)
|
||||
{
|
||||
DebugUtility.debugTrace("accessory showId:" + this._accShownItems[i].invIdx + " is already visible!");
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(i == accLength)
|
||||
{
|
||||
showItem.setInUse(this.ownerAvatar.perUserAvId,true);
|
||||
this.adjustAvatarQuestValues(true,showItem);
|
||||
this._accShownItems.push(showItem);
|
||||
this._accShownLayers.push(-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("WARNING: showAccessory received a null item");
|
||||
}
|
||||
}
|
||||
|
||||
public function replaceAccessory(oldAcc:Item, newAcc:Item) : void
|
||||
{
|
||||
if(oldAcc.accId != newAcc.accId)
|
||||
{
|
||||
throw new Error("Tried to replace accessory with different accId! Layers may not match! oldId:" + oldAcc.accId + " newId:" + newAcc.accId);
|
||||
}
|
||||
var rsiLength:int = int(this._accShownItems.length);
|
||||
for(var rsai:int = 0; rsai < rsiLength; rsai++)
|
||||
{
|
||||
if(this._accShownItems[rsai] == oldAcc)
|
||||
{
|
||||
this._accShownItems[rsai] = newAcc;
|
||||
if(!newAcc.getInUse(this.ownerAvatar.perUserAvId))
|
||||
{
|
||||
this._accShownItems.splice(rsai,1);
|
||||
this._accShownLayers.splice(rsai,1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isAccessoryVisibleByItemId(hasItemInvIdx:int) : Boolean
|
||||
{
|
||||
var itemsLength:int = int(this._accShownItems.length);
|
||||
for(var hii:int = 0; hii < itemsLength; hii++)
|
||||
{
|
||||
if(this._accShownItems[hii].invIdx == hasItemInvIdx)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isAccessoryVisibleByAccId(hasAccId:int) : Boolean
|
||||
{
|
||||
var itemsLength:int = int(this._accShownItems.length);
|
||||
for(var hii:int = 0; hii < itemsLength; hii++)
|
||||
{
|
||||
if(this._accShownItems[hii].accId == hasAccId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isAccessoryVisibleByLayer(hasLayerId:int) : Boolean
|
||||
{
|
||||
var layersLength:int = int(this._accShownLayers.length);
|
||||
for(var hli:int = 0; hli < layersLength; hli++)
|
||||
{
|
||||
if(this._accShownLayers[hli] == hasLayerId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hideAccessory(hideItem:Item) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var accLength:int = 0;
|
||||
if(Boolean(hideItem))
|
||||
{
|
||||
i = 0;
|
||||
accLength = int(this._accShownItems.length);
|
||||
while(i < accLength)
|
||||
{
|
||||
if(this._accShownItems[i].invIdx == hideItem.invIdx)
|
||||
{
|
||||
hideItem.setInUse(this.ownerAvatar.perUserAvId,false);
|
||||
this.adjustAvatarQuestValues(false,hideItem);
|
||||
this._accShownItems.splice(i,1);
|
||||
this._accShownLayers.splice(i,1);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if(i == this._accShownItems.length)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hideAll() : void
|
||||
{
|
||||
while(this._accShownItems.length > 0)
|
||||
{
|
||||
this.hideAccessory(this._accShownItems[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAllItems() : void
|
||||
{
|
||||
this._accShownItems = [];
|
||||
this._accShownLayers = [];
|
||||
this.ownerAvatar.meleeAttack = [0,0];
|
||||
this.ownerAvatar.rangedAttack = [0,0];
|
||||
this.ownerAvatar.fierceAttack = [0,0];
|
||||
this.ownerAvatar.healingPower = [0,0];
|
||||
this.ownerAvatar.defense = [0,0];
|
||||
}
|
||||
|
||||
public function hideAllExceptBase() : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var accLength:int = int(this._accShownItems.length);
|
||||
while(i < accLength)
|
||||
{
|
||||
if(this._accShownLayers[i] != 1)
|
||||
{
|
||||
this.hideAccessory(this._accShownItems[i]);
|
||||
accLength--;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hideAllClothingArticles(itemsOff:Array = null) : void
|
||||
{
|
||||
var layerId:int = 0;
|
||||
var i:int = 0;
|
||||
var accLength:int = int(this._accShownItems.length);
|
||||
while(i < accLength)
|
||||
{
|
||||
layerId = int(this._accShownItems[i].layerId);
|
||||
if(layerId > 3)
|
||||
{
|
||||
if(Boolean(itemsOff))
|
||||
{
|
||||
itemsOff.push(this._accShownItems[i].invIdx);
|
||||
}
|
||||
this.hideAccessory(this._accShownItems[i]);
|
||||
accLength--;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function adjustAvatarQuestValues(add:Boolean, myitem:Item) : void
|
||||
{
|
||||
if(myitem.attack < 0)
|
||||
{
|
||||
if(add)
|
||||
{
|
||||
this.ownerAvatar.healingPower[0] += myitem.attack * -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.healingPower[0] -= myitem.attack * -1;
|
||||
}
|
||||
}
|
||||
else if(myitem.combatType == Item.COMBAT_TYPE_RANGED)
|
||||
{
|
||||
if(add)
|
||||
{
|
||||
this.ownerAvatar.rangedAttack[0] += myitem.attack;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.rangedAttack[0] -= myitem.attack;
|
||||
}
|
||||
}
|
||||
else if(add)
|
||||
{
|
||||
this.ownerAvatar.meleeAttack[0] += myitem.attack;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.meleeAttack[0] -= myitem.attack;
|
||||
}
|
||||
if(add)
|
||||
{
|
||||
this.ownerAvatar.fierceAttack[0] += myitem.fierceAttack;
|
||||
this.ownerAvatar.defense[0] += myitem.defense;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.fierceAttack[0] -= myitem.fierceAttack;
|
||||
this.ownerAvatar.defense[0] -= myitem.defense;
|
||||
}
|
||||
switch(myitem.modifierType)
|
||||
{
|
||||
case Item.MODIFIER_TYPE_DEFENSE:
|
||||
if(add)
|
||||
{
|
||||
this.ownerAvatar.defense[1] += myitem.modifierValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.defense[1] -= myitem.modifierValue;
|
||||
}
|
||||
break;
|
||||
case Item.MODIFIER_TYPE_MELEE:
|
||||
if(add)
|
||||
{
|
||||
this.ownerAvatar.meleeAttack[1] += myitem.modifierValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.meleeAttack[1] -= myitem.modifierValue;
|
||||
}
|
||||
break;
|
||||
case Item.MODIFIER_TYPE_RANGED:
|
||||
if(add)
|
||||
{
|
||||
this.ownerAvatar.rangedAttack[1] += myitem.modifierValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.rangedAttack[1] -= myitem.modifierValue;
|
||||
}
|
||||
break;
|
||||
case Item.MODIFIER_TYPE_RESTORE:
|
||||
if(add)
|
||||
{
|
||||
this.ownerAvatar.healingPower[1] += myitem.modifierValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ownerAvatar.healingPower[1] -= myitem.modifierValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,370 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import flash.events.EventDispatcher;
|
||||
import item.Inventory;
|
||||
import item.Item;
|
||||
import item.ItemXtCommManager;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class Avatar extends EventDispatcher
|
||||
{
|
||||
|
||||
private var _avName:String;
|
||||
|
||||
private var _userName:String;
|
||||
|
||||
private var _sfsUserId:int;
|
||||
|
||||
private var _perUserAvId:int;
|
||||
|
||||
private var _avTypeId:int;
|
||||
|
||||
private var _roomType:int;
|
||||
|
||||
private var _enviroTypeFlag:int;
|
||||
|
||||
private var _colors:Array;
|
||||
|
||||
private var _accState:AccessoryState;
|
||||
|
||||
public var inventoryClothing:Inventory;
|
||||
|
||||
public var inventoryBodyMod:Inventory;
|
||||
|
||||
public var inventoryDenFull:Inventory;
|
||||
|
||||
public var inventoryDenPartial:Inventory;
|
||||
|
||||
public var isShaman:Boolean;
|
||||
|
||||
public var shamanName:String;
|
||||
|
||||
public var shamanText:String;
|
||||
|
||||
public var rangedAttack:Array;
|
||||
|
||||
public var meleeAttack:Array;
|
||||
|
||||
public var fierceAttack:Array;
|
||||
|
||||
public var healingPower:Array;
|
||||
|
||||
public var defense:Array;
|
||||
|
||||
public function Avatar()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init(uniqueAvatarId:int, avName:String, type:int, colors:Array, initAccState:AccessoryState = null, initUserName:String = "", initSfsUserId:int = -1, initRoomType:int = 0, initRangedAttack:Array = null, initMeleeAttack:Array = null, initFierceAttack:Array = null, initHealingPower:Array = null, initDefense:Array = null) : void
|
||||
{
|
||||
this.avTypeId = type;
|
||||
this._perUserAvId = uniqueAvatarId;
|
||||
this._roomType = initRoomType;
|
||||
this._avName = avName;
|
||||
this.rangedAttack = initRangedAttack == null ? [0,0] : initRangedAttack;
|
||||
this.meleeAttack = initMeleeAttack == null ? [0,0] : initMeleeAttack;
|
||||
this.fierceAttack = initFierceAttack == null ? [0,0] : initFierceAttack;
|
||||
this.healingPower = initHealingPower == null ? [0,0] : initHealingPower;
|
||||
this.defense = initDefense == null ? [0,0] : initDefense;
|
||||
if(initUserName != "")
|
||||
{
|
||||
this.userName = initUserName;
|
||||
}
|
||||
this._sfsUserId = initSfsUserId;
|
||||
this._accState = new AccessoryState();
|
||||
if(Boolean(initAccState))
|
||||
{
|
||||
DebugUtility.debugTrace("Avatar init - copying accState");
|
||||
this._accState.copyShownAccRef(initAccState);
|
||||
DebugUtility.debugTrace("old ownerAvatar:" + (Boolean(this._accState.ownerAvatar) ? this._accState.ownerAvatar.avName : this._accState.ownerAvatar));
|
||||
this._accState.ownerAvatar = this;
|
||||
DebugUtility.debugTrace("new ownerAvatar:" + this._accState.ownerAvatar.avName);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._accState.init(this);
|
||||
}
|
||||
if(Boolean(colors))
|
||||
{
|
||||
this.copyColors(colors);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._colors = null;
|
||||
}
|
||||
this.inventoryClothing = new Inventory();
|
||||
this.inventoryBodyMod = new Inventory();
|
||||
this.inventoryDenFull = new Inventory();
|
||||
this.inventoryDenPartial = new Inventory();
|
||||
this.inventoryClothing.init(this._accState);
|
||||
this.inventoryBodyMod.init(this._accState);
|
||||
this.inventoryDenFull.init(this._accState);
|
||||
this.inventoryDenPartial.init(this._accState);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
if(Boolean(this._accState))
|
||||
{
|
||||
this._accState.destroy();
|
||||
this._accState = null;
|
||||
}
|
||||
if(Boolean(this.inventoryClothing))
|
||||
{
|
||||
this.inventoryClothing.destroy();
|
||||
this.inventoryClothing = null;
|
||||
}
|
||||
if(Boolean(this.inventoryBodyMod))
|
||||
{
|
||||
this.inventoryBodyMod.destroy();
|
||||
this.inventoryBodyMod = null;
|
||||
}
|
||||
if(Boolean(this.inventoryDenFull))
|
||||
{
|
||||
this.inventoryDenFull.destroy();
|
||||
this.inventoryDenFull = null;
|
||||
}
|
||||
if(Boolean(this.inventoryDenPartial))
|
||||
{
|
||||
this.inventoryDenPartial.destroy();
|
||||
this.inventoryDenPartial = null;
|
||||
}
|
||||
this._colors = null;
|
||||
}
|
||||
|
||||
public function get perUserAvId() : int
|
||||
{
|
||||
return this._perUserAvId;
|
||||
}
|
||||
|
||||
public function set perUserAvId(setperUserAvId:int) : void
|
||||
{
|
||||
this._perUserAvId = setperUserAvId;
|
||||
}
|
||||
|
||||
public function get avName() : String
|
||||
{
|
||||
return LocalizationManager.translateAvatarName(this._avName);
|
||||
}
|
||||
|
||||
public function set avName(setAvName:String) : void
|
||||
{
|
||||
this._avName = setAvName;
|
||||
}
|
||||
|
||||
public function get userName() : String
|
||||
{
|
||||
return this._userName;
|
||||
}
|
||||
|
||||
public function set userName(setUserName:String) : void
|
||||
{
|
||||
this._userName = setUserName;
|
||||
}
|
||||
|
||||
public function get sfsUserId() : int
|
||||
{
|
||||
return this._sfsUserId;
|
||||
}
|
||||
|
||||
public function set avTypeId(newType:int) : void
|
||||
{
|
||||
this._avTypeId = newType;
|
||||
this._enviroTypeFlag = gMainFrame.userInfo.getAvatarEnviroTypeFlagByAvType(this._avTypeId);
|
||||
}
|
||||
|
||||
public function get avTypeId() : int
|
||||
{
|
||||
return this._avTypeId;
|
||||
}
|
||||
|
||||
public function get enviroTypeFlag() : int
|
||||
{
|
||||
return this._enviroTypeFlag;
|
||||
}
|
||||
|
||||
public function set colors(setColorra:Array) : void
|
||||
{
|
||||
this.setColors(setColorra[0],setColorra[1],setColorra[2]);
|
||||
}
|
||||
|
||||
public function get colors() : Array
|
||||
{
|
||||
return this._colors;
|
||||
}
|
||||
|
||||
public function get accShownItems() : Array
|
||||
{
|
||||
return this._accState.accShownItems;
|
||||
}
|
||||
|
||||
public function set roomType(newRoomType:int) : void
|
||||
{
|
||||
this._roomType = newRoomType;
|
||||
}
|
||||
|
||||
public function copyShownAccRefsFromAvatar(fromAvatar:Avatar) : void
|
||||
{
|
||||
this._accState.copyShownAccRef(fromAvatar._accState);
|
||||
this.inventoryBodyMod.itemArray = fromAvatar.inventoryBodyMod.itemArray.concat();
|
||||
if(Boolean(fromAvatar.inventoryClothing))
|
||||
{
|
||||
this.inventoryClothing.itemArray = fromAvatar.inventoryClothing.itemArray.concat();
|
||||
}
|
||||
}
|
||||
|
||||
public function cloneShownAccFromAvatar(fromAvatar:Avatar) : void
|
||||
{
|
||||
this._accState.cloneShownAcc(fromAvatar._accState);
|
||||
this.inventoryBodyMod.itemArray = fromAvatar.inventoryBodyMod.itemArray.concat();
|
||||
if(Boolean(fromAvatar.inventoryClothing))
|
||||
{
|
||||
this.inventoryClothing.itemArray = fromAvatar.inventoryClothing.itemArray.concat();
|
||||
}
|
||||
}
|
||||
|
||||
public function matchShownAcc(fromAccState:AccessoryState) : void
|
||||
{
|
||||
this._accState.matchShownItems(fromAccState,this.inventoryClothing.itemArray,this.inventoryBodyMod.itemArray);
|
||||
}
|
||||
|
||||
public function setColors(color1:uint, color2:uint, color3:uint) : void
|
||||
{
|
||||
if(this._colors == null)
|
||||
{
|
||||
this._colors = new Array(3);
|
||||
}
|
||||
var presetLayer1Colors:uint = uint(gMainFrame.userInfo.getAvatarColorLayer1InfoByAvType(this._avTypeId));
|
||||
var base1:int = color1 >> 24 & 0xFF;
|
||||
var base2:int = color1 >> 16 & 0xFF;
|
||||
var base3:int = presetLayer1Colors >> 8 & 0xFF;
|
||||
var base4:int = presetLayer1Colors & 0xFF;
|
||||
var presetLayer3Colors:uint = uint(gMainFrame.userInfo.getAvatarColorLayer3InfoByAvType(this._avTypeId));
|
||||
var eyes1:int = color3 >> 24 & 0xFF;
|
||||
var eyes2:int = presetLayer3Colors >> 16 & 0xFF;
|
||||
var eyes3:int = presetLayer3Colors >> 8 & 0xFF;
|
||||
var eyes4:int = presetLayer3Colors & 0xFF;
|
||||
this._colors[0] = uint(base1 << 24 | base2 << 16 | base3 << 8 | base4);
|
||||
this._colors[1] = color2;
|
||||
this._colors[2] = uint(eyes1 << 24 | eyes2 << 16 | eyes3 << 8 | eyes4);
|
||||
dispatchEvent(new AvatarEvent(AvatarEvent.AVATAR_CHANGED));
|
||||
}
|
||||
|
||||
public function copyColors(copyColorra:Array) : void
|
||||
{
|
||||
this.colors = copyColorra.concat();
|
||||
}
|
||||
|
||||
public function itemResponseIntegrate(itemList:Array) : void
|
||||
{
|
||||
var itemListLength:int = 0;
|
||||
var currItem:Item = null;
|
||||
var si:int = 0;
|
||||
if(Boolean(this.inventoryBodyMod) && Boolean(this.inventoryClothing))
|
||||
{
|
||||
this.removeAllItems();
|
||||
itemListLength = int(itemList.length);
|
||||
for(si = 0; si < itemListLength; si++)
|
||||
{
|
||||
currItem = itemList[si];
|
||||
if(currItem.type == Item.BODY_MOD_TYPE)
|
||||
{
|
||||
if(ItemXtCommManager.canUseItem(currItem.defId,this._avTypeId))
|
||||
{
|
||||
this.inventoryBodyMod.addItem(currItem);
|
||||
if(currItem.getInUse(this._perUserAvId))
|
||||
{
|
||||
this._accState.showAccessory(currItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(currItem.type == Item.CLOTHING_TYPE)
|
||||
{
|
||||
if(this._enviroTypeFlag == 1 << Utility.ENVIRO_LAND || this._enviroTypeFlag == 1 << Utility.ENVIRO_OCEAN || this._enviroTypeFlag == 1 < Utility.ENVIRO_AIR || currItem.enviroType == this._roomType)
|
||||
{
|
||||
this.inventoryClothing.addItem(currItem);
|
||||
if(currItem.getInUse(this._perUserAvId))
|
||||
{
|
||||
this._accState.showAccessory(currItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("ERROR: Bad item type: " + currItem.type);
|
||||
}
|
||||
}
|
||||
dispatchEvent(new AvatarEvent(AvatarEvent.AVATAR_CHANGED));
|
||||
}
|
||||
}
|
||||
|
||||
public function accStateShowAccessory(showItem:Item, hideItemCallback:Function = null) : void
|
||||
{
|
||||
var tempItem:Item = null;
|
||||
var items:Array = showItem.type == Item.BODY_MOD_TYPE ? this.inventoryBodyMod.itemArray : this.inventoryClothing.itemArray;
|
||||
for(var i:int = 0; i < items.length; i++)
|
||||
{
|
||||
tempItem = items[i];
|
||||
if(tempItem.layerId == showItem.layerId && tempItem.getInUse(this._perUserAvId))
|
||||
{
|
||||
if(tempItem != showItem)
|
||||
{
|
||||
this.accStateHideAccessory(tempItem,false);
|
||||
if(hideItemCallback != null)
|
||||
{
|
||||
hideItemCallback(tempItem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._accState.showAccessory(showItem);
|
||||
dispatchEvent(new AvatarEvent(AvatarEvent.AVATAR_CHANGED));
|
||||
}
|
||||
|
||||
public function accStateHideAccessory(hideItem:Item, bDispatchEvent:Boolean = true) : void
|
||||
{
|
||||
this._accState.hideAccessory(hideItem);
|
||||
if(bDispatchEvent)
|
||||
{
|
||||
dispatchEvent(new AvatarEvent(AvatarEvent.AVATAR_CHANGED));
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAllItems() : void
|
||||
{
|
||||
this.inventoryBodyMod.itemArray = [];
|
||||
this.inventoryClothing.itemArray = [];
|
||||
this._accState.removeAllItems();
|
||||
}
|
||||
|
||||
public function get accState() : AccessoryState
|
||||
{
|
||||
return this._accState;
|
||||
}
|
||||
|
||||
public function clone(avatarToClone:Avatar) : void
|
||||
{
|
||||
this._avTypeId = avatarToClone.avTypeId;
|
||||
this._perUserAvId = avatarToClone.perUserAvId;
|
||||
this._avName = avatarToClone.avName;
|
||||
this.userName = avatarToClone.userName;
|
||||
this._sfsUserId = avatarToClone._sfsUserId;
|
||||
this._accState = new AccessoryState();
|
||||
this._accState.cloneShownAcc(avatarToClone.accState);
|
||||
this._accState.ownerAvatar = this;
|
||||
this.copyColors(avatarToClone.colors);
|
||||
this.inventoryClothing = new Inventory();
|
||||
this.inventoryClothing.clone(avatarToClone.inventoryClothing);
|
||||
this.inventoryBodyMod = new Inventory();
|
||||
this.inventoryBodyMod.clone(avatarToClone.inventoryBodyMod);
|
||||
this.inventoryDenFull = new Inventory();
|
||||
this.inventoryDenFull.clone(avatarToClone.inventoryDenFull);
|
||||
this.inventoryDenPartial = new Inventory();
|
||||
this.inventoryDenPartial.clone(avatarToClone.inventoryDenPartial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.graphics.LayerAnim;
|
||||
import item.Item;
|
||||
|
||||
public class AvatarEditorView extends AvatarView
|
||||
{
|
||||
|
||||
public function AvatarEditorView()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function init(worldAvatar:Avatar, avTypeCallback:Function = null) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var j:int = 0;
|
||||
_avatar = new Avatar();
|
||||
_avatar.init(worldAvatar.perUserAvId,"editorAvatar",worldAvatar.avTypeId,worldAvatar.colors,null,"",-1,0,worldAvatar.rangedAttack,worldAvatar.meleeAttack,worldAvatar.fierceAttack,worldAvatar.healingPower,worldAvatar.defense);
|
||||
if(Boolean(worldAvatar.inventoryClothing.itemArray))
|
||||
{
|
||||
_avatar.inventoryClothing.itemArray = worldAvatar.inventoryClothing.itemArray.concat();
|
||||
for(i = 0; i < _avatar.inventoryClothing.itemArray.length; i++)
|
||||
{
|
||||
_avatar.inventoryClothing.itemArray[i].makeSmallIcon();
|
||||
}
|
||||
}
|
||||
if(Boolean(worldAvatar.inventoryBodyMod.itemArray))
|
||||
{
|
||||
_avatar.inventoryBodyMod.itemArray = worldAvatar.inventoryBodyMod.itemArray.concat();
|
||||
for(j = 0; j < _avatar.inventoryBodyMod.itemArray.length; j++)
|
||||
{
|
||||
_avatar.inventoryBodyMod.itemArray[j].makeSmallIcon();
|
||||
}
|
||||
}
|
||||
_avatar.matchShownAcc(worldAvatar.accState);
|
||||
_avatar.addEventListener(AvatarEvent.AVATAR_CHANGED,avatarChanged,false,0,true);
|
||||
_layerAnim = LayerAnim.getNew();
|
||||
_layerAnim.avDefId = _avatar.avTypeId;
|
||||
_layerAnim.layers = AvatarUtility.layerArrayForItemsAndColors(worldAvatar.inventoryClothing.itemArray.concat(worldAvatar.inventoryBodyMod.itemArray.concat()),worldAvatar.colors,worldAvatar.perUserAvId);
|
||||
this.addChild(_layerAnim.bitmap);
|
||||
}
|
||||
|
||||
override public function destroy(destroyAvatar:Boolean = true) : void
|
||||
{
|
||||
if(destroyAvatar && Boolean(_avatar))
|
||||
{
|
||||
_avatar.removeEventListener(AvatarEvent.AVATAR_CHANGED,avatarChanged);
|
||||
_avatar.destroy();
|
||||
_avatar = null;
|
||||
}
|
||||
avTypeChangedCallback = null;
|
||||
LayerAnim.destroy(_layerAnim);
|
||||
_layerAnim = null;
|
||||
}
|
||||
|
||||
public function get colors() : Array
|
||||
{
|
||||
return _avatar.colors;
|
||||
}
|
||||
|
||||
public function set colors(colors:Array) : void
|
||||
{
|
||||
_avatar.colors = colors;
|
||||
}
|
||||
|
||||
public function get accState() : AccessoryState
|
||||
{
|
||||
return _avatar.accState;
|
||||
}
|
||||
|
||||
public function showAccessory(showItem:Item, callback:Function = null) : void
|
||||
{
|
||||
_avatar.accStateShowAccessory(showItem,callback);
|
||||
}
|
||||
|
||||
public function hideAccessory(hideItem:Item) : void
|
||||
{
|
||||
_avatar.accStateHideAccessory(hideItem);
|
||||
}
|
||||
|
||||
public function get viewAvatar() : Avatar
|
||||
{
|
||||
return _avatar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package avatar
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class AvatarEvent extends Event
|
||||
{
|
||||
|
||||
public static const AVATAR_CHANGED:String = "OnAvatarChanged";
|
||||
|
||||
public function AvatarEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new AvatarEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
package avatar
|
||||
{
|
||||
import localization.LocalizationManager;
|
||||
import pet.PetManager;
|
||||
|
||||
public class AvatarInfo
|
||||
{
|
||||
|
||||
public var perUserAvId:int;
|
||||
|
||||
public var userName:String;
|
||||
|
||||
public var type:int;
|
||||
|
||||
public var colors:Array;
|
||||
|
||||
public var currEnviroType:int;
|
||||
|
||||
public var landPetInvId:int;
|
||||
|
||||
public var oceanPetInvId:int;
|
||||
|
||||
public var questXp:int;
|
||||
|
||||
public var questLevel:int;
|
||||
|
||||
public var questXPPercentage:int;
|
||||
|
||||
public var questHealthPercentage:int;
|
||||
|
||||
public var questTorchStatus:Boolean;
|
||||
|
||||
public var isDead:Boolean;
|
||||
|
||||
public var healthBase:int;
|
||||
|
||||
public var attackBase:int;
|
||||
|
||||
public var attackMax:int;
|
||||
|
||||
public var defenseBase:int;
|
||||
|
||||
public var defenseMax:int;
|
||||
|
||||
private var _currPet:Object;
|
||||
|
||||
private var _avName:String;
|
||||
|
||||
public function AvatarInfo()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init(initPerUserAvatarId:int = -1, initAvName:String = "", initUserName:String = "", initType:int = -1, initColors:Array = null, initRoomType:int = 0, initCurrPet:Object = null, initLandPetInvId:int = 0, initOceanPetInvId:int = 0, initQuestXp:int = 0, initQuestLevel:int = 0, initQuestXPPercentage:int = 0, initHealthBase:int = 0, initAttackBase:int = 0, initAttackMax:int = 0, initDefenseMax:int = 0, initDefenseBase:int = 0, initQuestHealthPercentage:int = 100, initQuestTorchStatus:Boolean = false) : void
|
||||
{
|
||||
this.isDead = false;
|
||||
this.perUserAvId = initPerUserAvatarId;
|
||||
this._avName = initAvName;
|
||||
this.userName = initUserName;
|
||||
this.type = initType;
|
||||
this.colors = initColors == null ? [286331153,286331153,286331153] : initColors;
|
||||
this.currEnviroType = initRoomType;
|
||||
this.landPetInvId = initLandPetInvId;
|
||||
this.oceanPetInvId = initOceanPetInvId;
|
||||
this.questXp = initQuestXp;
|
||||
this.questLevel = initQuestLevel;
|
||||
this.questXPPercentage = initQuestXPPercentage;
|
||||
this.questHealthPercentage = initQuestHealthPercentage;
|
||||
this.questTorchStatus = initQuestTorchStatus;
|
||||
this.attackBase = initAttackBase;
|
||||
this.attackMax = initAttackMax;
|
||||
this.defenseBase = initDefenseBase;
|
||||
this.defenseMax = initDefenseMax;
|
||||
this.healthBase = initHealthBase;
|
||||
this._currPet = initCurrPet;
|
||||
}
|
||||
|
||||
public function get currPet() : Object
|
||||
{
|
||||
if(this.userName == gMainFrame.userInfo.myUserName)
|
||||
{
|
||||
return PetManager.myActivePet;
|
||||
}
|
||||
return this._currPet;
|
||||
}
|
||||
|
||||
public function set currPet(o:Object) : void
|
||||
{
|
||||
if(this.userName != gMainFrame.userInfo.myUserName)
|
||||
{
|
||||
this._currPet = o;
|
||||
}
|
||||
}
|
||||
|
||||
public function getItems(withBodyMods:Boolean = false) : Array
|
||||
{
|
||||
var userInf:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(this.userName);
|
||||
if(Boolean(userInf))
|
||||
{
|
||||
return userInf.getPartialItemList(this.type,withBodyMods);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getFullItems(withBodyMods:Boolean = false) : Array
|
||||
{
|
||||
var userInf:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(this.userName);
|
||||
if(Boolean(userInf))
|
||||
{
|
||||
return userInf.getFullItemList(withBodyMods);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function set fullItemList(list:Array) : void
|
||||
{
|
||||
var userInf:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(this.userName);
|
||||
if(Boolean(userInf))
|
||||
{
|
||||
userInf.fullItemList = list;
|
||||
}
|
||||
}
|
||||
|
||||
public function get denItems() : Array
|
||||
{
|
||||
var userInf:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(this.userName);
|
||||
if(Boolean(userInf))
|
||||
{
|
||||
return userInf.denItemsFull;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get achievements() : Array
|
||||
{
|
||||
var userInf:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(this.userName);
|
||||
if(Boolean(userInf))
|
||||
{
|
||||
return userInf.achievements;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function set denItems(items:Array) : void
|
||||
{
|
||||
var userInfo:UserInfo = null;
|
||||
if(Boolean(items))
|
||||
{
|
||||
userInfo = gMainFrame.userInfo.getUserInfoByUserName(this.userName);
|
||||
if(Boolean(userInfo))
|
||||
{
|
||||
userInfo.denItemsFull = items;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get accountType() : int
|
||||
{
|
||||
var userInfo:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(this.userName);
|
||||
if(Boolean(userInfo))
|
||||
{
|
||||
return userInfo.accountType;
|
||||
}
|
||||
return Utility.NON_MEMBER;
|
||||
}
|
||||
|
||||
public function get isMember() : Boolean
|
||||
{
|
||||
return Utility.isMember(this.accountType);
|
||||
}
|
||||
|
||||
public function get avName() : String
|
||||
{
|
||||
return LocalizationManager.translateAvatarName(this._avName);
|
||||
}
|
||||
|
||||
public function set avName(name:String) : void
|
||||
{
|
||||
this._avName = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,951 @@
|
||||
package avatar
|
||||
{
|
||||
import buddy.BuddyEvent;
|
||||
import com.sbi.analytics.SBTracker;
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.Event;
|
||||
import flash.media.SoundTransform;
|
||||
import gui.BuddyCard;
|
||||
import gui.BuddyManager;
|
||||
import gui.DarkenManager;
|
||||
import gui.GuiManager;
|
||||
import gui.GuiNameTypeScreen;
|
||||
import item.ItemXtCommManager;
|
||||
import loader.MediaHelper;
|
||||
import localization.LocalizationManager;
|
||||
import pet.PetManager;
|
||||
import quest.QuestManager;
|
||||
import room.RoomManagerWorld;
|
||||
import room.RoomXtCommManager;
|
||||
|
||||
public class AvatarSwitch
|
||||
{
|
||||
|
||||
public static var avatars:Array;
|
||||
|
||||
public static var activeAvatarIdx:int;
|
||||
|
||||
public static var playerUserInfo:UserInfo;
|
||||
|
||||
public static var nameTypeScreen:GuiNameTypeScreen;
|
||||
|
||||
public static var playerUsername:String;
|
||||
|
||||
public static var playerSfsUserId:int;
|
||||
|
||||
public static var isSlotAvail:int;
|
||||
|
||||
public static var isAddingSlot:Boolean;
|
||||
|
||||
public static var availSlotFlags:int;
|
||||
|
||||
public static var isChoosing:Boolean;
|
||||
|
||||
private static var _addSlotCallback:Function;
|
||||
|
||||
private static var _switchCallback:Function;
|
||||
|
||||
private static var _addIdx:int;
|
||||
|
||||
private static var _switchIdx:int;
|
||||
|
||||
private static var _addAvatarCallback:Function;
|
||||
|
||||
private static var _addAvatar:Avatar;
|
||||
|
||||
private static var _addAvName:String;
|
||||
|
||||
private static var _removeCallback:Function;
|
||||
|
||||
private static var _removeIdx:int;
|
||||
|
||||
private static var _isChoosing:Boolean;
|
||||
|
||||
private static var _asTransformVec:Vector.<MediaHelper>;
|
||||
|
||||
private static var _secondChosenAvtIdx:int;
|
||||
|
||||
private static var _numOpenNonMemberSlots:int;
|
||||
|
||||
private static var _caIdx:int;
|
||||
|
||||
private static var _avatarName:String;
|
||||
|
||||
private static var _avatarNameIndexes:Array;
|
||||
|
||||
private static var _shopId:int;
|
||||
|
||||
private static var _itemInShopDefId:int;
|
||||
|
||||
private static var _status:int;
|
||||
|
||||
public static const ASTRANSFORM_MEDIA_ID_TOP:int = 33;
|
||||
|
||||
public static const ASTRANSFORM_MEDIA_ID_BOTTOM:int = 34;
|
||||
|
||||
public static const ASTRANSFORM_OCEAN_MEDIA_ID_TOP:int = 1171;
|
||||
|
||||
public static const ASTRANSFORM_OCEAN_MEDIA_ID_BOTTOM:int = 1172;
|
||||
|
||||
public function AvatarSwitch()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init() : void
|
||||
{
|
||||
_asTransformVec = new Vector.<MediaHelper>();
|
||||
_secondChosenAvtIdx = -1;
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
_asTransformVec = null;
|
||||
}
|
||||
|
||||
public static function playerInfoSet() : void
|
||||
{
|
||||
var i:int = 0;
|
||||
if(playerUserInfo == null)
|
||||
{
|
||||
playerUserInfo = gMainFrame.userInfo.playerUserInfo;
|
||||
playerUsername = playerUserInfo.userName;
|
||||
playerSfsUserId = gMainFrame.server.userId;
|
||||
avatars = [];
|
||||
updateAvatars();
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]))
|
||||
{
|
||||
if(avatars[i].perUserAvId == gMainFrame.userInfo.myPerUserAvId)
|
||||
{
|
||||
if(i != 0)
|
||||
{
|
||||
avatars.unshift(avatars[i]);
|
||||
avatars.splice(i + 1,1);
|
||||
activeAvatarIdx = _switchIdx = 0;
|
||||
}
|
||||
}
|
||||
avatars[i].roomType = AvatarManager.roomEnviroType;
|
||||
}
|
||||
}
|
||||
avatars[activeAvatarIdx] = AvatarManager.playerAvatar;
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateSlotPositions() : void
|
||||
{
|
||||
var tempAvatars:Array = avatars.slice();
|
||||
var tempSwitchperUserAvId:int = int(avatars[_switchIdx].perUserAvId);
|
||||
var tempActiveAvatarperUserAvId:int = int(avatars[activeAvatarIdx].perUserAvId);
|
||||
var numSkipped:int = 0;
|
||||
avatars = [];
|
||||
for(var i:int = 0; i < tempAvatars.length; i++)
|
||||
{
|
||||
if(tempAvatars[i] != null)
|
||||
{
|
||||
avatars.push(tempAvatars[i]);
|
||||
if(tempSwitchperUserAvId == tempAvatars[i].perUserAvId)
|
||||
{
|
||||
_switchIdx = i - numSkipped;
|
||||
AvatarXtCommManager.avSlotInfo[tempSwitchperUserAvId].slotId = _switchIdx;
|
||||
}
|
||||
if(tempActiveAvatarperUserAvId == tempAvatars[i].perUserAvId)
|
||||
{
|
||||
activeAvatarIdx = i - numSkipped;
|
||||
AvatarXtCommManager.avSlotInfo[tempActiveAvatarperUserAvId].slotId = activeAvatarIdx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
numSkipped++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function updateAvatars() : void
|
||||
{
|
||||
var uai:AvatarInfo = null;
|
||||
var avatarsLength:int = 0;
|
||||
var i:int = 0;
|
||||
var av:Avatar = null;
|
||||
var sa:Avatar = null;
|
||||
for each(uai in playerUserInfo.avList)
|
||||
{
|
||||
if(uai.perUserAvId == playerUserInfo.currPerUserAvId)
|
||||
{
|
||||
av = AvatarManager.playerAvatar;
|
||||
}
|
||||
else
|
||||
{
|
||||
av = avatars[AvatarXtCommManager.avSlotInfo[uai.perUserAvId].slotId];
|
||||
if(!av)
|
||||
{
|
||||
av = new Avatar();
|
||||
av = AvatarUtility.generateNew(uai.perUserAvId,av,uai.userName,playerSfsUserId,AvatarManager.roomEnviroType);
|
||||
}
|
||||
}
|
||||
avatars[AvatarXtCommManager.avSlotInfo[uai.perUserAvId].slotId] = av;
|
||||
av = null;
|
||||
}
|
||||
avatarsLength = int(avatars.length);
|
||||
for(i = 0; i < avatarsLength; i++)
|
||||
{
|
||||
if(avatars[i] != null)
|
||||
{
|
||||
sa = avatars[i];
|
||||
if(playerUserInfo.currPerUserAvId == sa.perUserAvId)
|
||||
{
|
||||
activeAvatarIdx = _switchIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function shouldChoose() : Boolean
|
||||
{
|
||||
var nonMemberAvatars:int = 0;
|
||||
var numOceanOnlyAvatars:int = 0;
|
||||
var memberAvatars:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]))
|
||||
{
|
||||
if(isMemberOnlyAvatar(i))
|
||||
{
|
||||
memberAvatars++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(avatars[i].enviroTypeFlag == 2)
|
||||
{
|
||||
numOceanOnlyAvatars++;
|
||||
}
|
||||
nonMemberAvatars++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(nonMemberAvatars < 3 && nonMemberAvatars > 0 && numOceanOnlyAvatars < 2 && nonMemberAvatars != numOceanOnlyAvatars)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isMemberOnlyAvatar(index:int) : Boolean
|
||||
{
|
||||
return gMainFrame.userInfo.getAvatarMemberInfoByAvType(avatars[index].avTypeId);
|
||||
}
|
||||
|
||||
public static function get numTotalAvatars() : int
|
||||
{
|
||||
var numAvts:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]))
|
||||
{
|
||||
numAvts++;
|
||||
}
|
||||
}
|
||||
return numAvts;
|
||||
}
|
||||
|
||||
public static function getNumUsableLandAvatars(isChoosing:Boolean, isMember:Boolean) : int
|
||||
{
|
||||
var num:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]) && Utility.isLand(avatars[i].enviroTypeFlag))
|
||||
{
|
||||
if(isChoosing || isMember)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
else if((availSlotFlags & 1 << AvatarXtCommManager.avSlotInfo[avatars[i].perUserAvId].avInvId) > 0)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public static function get numMemberAvatars() : int
|
||||
{
|
||||
var num:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]) && Boolean(gMainFrame.userInfo.getAvatarMemberInfoByAvType(avatars[i].avTypeId)))
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public static function get numNonMemberAvatars() : int
|
||||
{
|
||||
var num:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]) && !gMainFrame.userInfo.getAvatarMemberInfoByAvType(avatars[i].avTypeId))
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public static function get numNonMemberOceanAvatars() : int
|
||||
{
|
||||
var num:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]) && Boolean(!gMainFrame.userInfo.getAvatarMemberInfoByAvType(avatars[i].avTypeId)) && avatars[i].enviroTypeFlag == 2)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public static function getNumNonMemberAvailableAvatars() : int
|
||||
{
|
||||
var num:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]) && Boolean(!gMainFrame.userInfo.getAvatarMemberInfoByAvType(avatars[i].avTypeId)) && (availSlotFlags & 1 << AvatarXtCommManager.avSlotInfo[avatars[i].perUserAvId].avInvId) > 0)
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public static function get numAvailAvatars() : int
|
||||
{
|
||||
var numAvailAvts:int = 0;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]) && (availSlotFlags & 1 << AvatarXtCommManager.avSlotInfo[avatars[i].perUserAvId].avInvId) > 0)
|
||||
{
|
||||
numAvailAvts++;
|
||||
}
|
||||
}
|
||||
return numAvailAvts;
|
||||
}
|
||||
|
||||
public static function isSwitching() : Boolean
|
||||
{
|
||||
return Boolean(activeAvatarIdx != _switchIdx);
|
||||
}
|
||||
|
||||
public static function isSlotAvailable(slotIdx:int) : Boolean
|
||||
{
|
||||
return (availSlotFlags & 1 << AvatarXtCommManager.avSlotInfo[avatars[slotIdx].perUserAvId].avInvId) > 0;
|
||||
}
|
||||
|
||||
public static function get numOpenNonMemberSlots() : int
|
||||
{
|
||||
return _numOpenNonMemberSlots;
|
||||
}
|
||||
|
||||
public static function set numOpenNonMemberSlots(value:int) : void
|
||||
{
|
||||
_numOpenNonMemberSlots = value;
|
||||
}
|
||||
|
||||
public static function addSlot(addSlotCallback:Function) : void
|
||||
{
|
||||
_addSlotCallback = addSlotCallback;
|
||||
AvatarXtCommManager.requestAvatarBuy(showNewAvatarPopup);
|
||||
}
|
||||
|
||||
public static function showNewAvatarPopup(success:Boolean) : void
|
||||
{
|
||||
if(success)
|
||||
{
|
||||
isAddingSlot = false;
|
||||
addNewWorldAvatar(_caIdx,_avatarName,_avatarNameIndexes);
|
||||
}
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
if(_addSlotCallback != null)
|
||||
{
|
||||
_addSlotCallback(success,true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function addAvatar(index:int, addingSlot:Boolean = false, addAvatarCallback:Function = null, isChoosing:Boolean = false, isChoosingOceanAnimal:Boolean = false, avatarTypeToShow:int = -1, skipToNameScreen:Boolean = false, currencyType:int = 0, specialValue:int = -1, shopId:int = -1, itemDefId:int = -1) : void
|
||||
{
|
||||
_addIdx = index;
|
||||
_addAvatarCallback = addAvatarCallback;
|
||||
_isChoosing = isChoosing;
|
||||
_shopId = shopId;
|
||||
_itemInShopDefId = itemDefId;
|
||||
isAddingSlot = addingSlot;
|
||||
var numNonMemberAvatars:int = AvatarUtility.numNonMemberAvatars();
|
||||
GuiManager.openAvatarCreator(isChoosingOceanAnimal,numNonMemberAvatars >= 1 && numNonMemberAvatars - numNonMemberOceanAvatars > 0 ? false : isChoosing,avatarTypeToShow,skipToNameScreen,currencyType,specialValue);
|
||||
}
|
||||
|
||||
public static function set addAvatarCallback(value:Function) : void
|
||||
{
|
||||
_addAvatarCallback = value;
|
||||
}
|
||||
|
||||
public static function addNewWorldAvatar(caIdx:int, avatarName:String, avatarNameIndexes:Array, isShopBuy:Boolean = false) : void
|
||||
{
|
||||
var nameIndex1:int = 0;
|
||||
var nameIndex2:int = 0;
|
||||
if(isAddingSlot)
|
||||
{
|
||||
_caIdx = caIdx;
|
||||
_avatarName = avatarName;
|
||||
_avatarNameIndexes = avatarNameIndexes;
|
||||
addSlot(_addAvatarCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_addAvatar = AvatarUtility.creationAvatars[AvatarUtility.findAvatarIndexByType(caIdx)];
|
||||
_addAvName = avatarName;
|
||||
if(_addAvatar != null && avatarNameIndexes[0] != null && avatarNameIndexes[1] != null && avatarNameIndexes[2] != null)
|
||||
{
|
||||
nameIndex1 = LocalizationManager.isCurrLanguageReversed() ? int(avatarNameIndexes[2]) : int(avatarNameIndexes[1]);
|
||||
nameIndex2 = LocalizationManager.isCurrLanguageReversed() ? int(avatarNameIndexes[1]) : int(avatarNameIndexes[2]);
|
||||
SBTracker.pop();
|
||||
if(_shopId != -1 && isShopBuy)
|
||||
{
|
||||
AvatarXtCommManager.requestAvatarShopBuy([_shopId,_itemInShopDefId,GenericListXtCommManager.getAvailListUniqueId(),avatarNameIndexes[0],nameIndex1,nameIndex2,_addAvatar.avTypeId],addAvatarResponse);
|
||||
}
|
||||
else
|
||||
{
|
||||
AvatarXtCommManager.requestAvatarAdd([avatarNameIndexes[0],nameIndex1,nameIndex2,_addAvatar.avTypeId],addAvatarResponse);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("Failed to request add avatar with addAvatar = " + _addAvatar + " AvatarNameIndexes[0] = " + avatarNameIndexes[0] + " AvatarNameIndexes[1] = " + avatarNameIndexes[1] + " AvatarNameIndexes[2] = " + avatarNameIndexes[2] + " addAvatar.avTypeId = " + (_addAvatar != null ? _addAvatar.avTypeId : null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function addAvatarResponse(status:int, newPerUserAvId:int, newAvInvId:int) : void
|
||||
{
|
||||
var addAvCopy:Avatar = null;
|
||||
_status = status;
|
||||
if(_status == 1)
|
||||
{
|
||||
addAvCopy = new Avatar();
|
||||
addAvCopy.init(newPerUserAvId,_addAvName,_addAvatar.avTypeId,null,null,playerUsername,playerSfsUserId);
|
||||
addAvCopy.copyColors(_addAvatar.colors);
|
||||
addAvCopy.cloneShownAccFromAvatar(_addAvatar);
|
||||
addAvCopy.accState.hideAllClothingArticles();
|
||||
if(_isChoosing)
|
||||
{
|
||||
AvatarXtCommManager.avSlotInfo[addAvCopy.perUserAvId] = {
|
||||
"slotId":_addIdx,
|
||||
"avInvId":newAvInvId
|
||||
};
|
||||
avatars[_addIdx] = addAvCopy;
|
||||
AvatarXtCommManager.requestADForAvatar(addAvCopy.perUserAvId,true,onChoosingAdReceive,addAvCopy);
|
||||
return;
|
||||
}
|
||||
if((availSlotFlags & 1 << newAvInvId) == 0)
|
||||
{
|
||||
availSlotFlags |= 1 << newAvInvId;
|
||||
}
|
||||
if(!Utility.isSameEnviroType(addAvCopy.enviroTypeFlag,AvatarManager.roomEnviroType))
|
||||
{
|
||||
avatars.splice(_addIdx,1);
|
||||
avatars.unshift(addAvCopy);
|
||||
AvatarXtCommManager.avSlotInfo[addAvCopy.perUserAvId] = {
|
||||
"slotId":0,
|
||||
"avInvId":newAvInvId
|
||||
};
|
||||
_addIdx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
AvatarXtCommManager.avSlotInfo[addAvCopy.perUserAvId] = {
|
||||
"slotId":_addIdx,
|
||||
"avInvId":newAvInvId
|
||||
};
|
||||
avatars[_addIdx] = addAvCopy;
|
||||
}
|
||||
switchAvatars(_addIdx);
|
||||
}
|
||||
if(_status != 1)
|
||||
{
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
if(_addAvatarCallback != null)
|
||||
{
|
||||
_addAvatarCallback(_status);
|
||||
_addAvatarCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function onChoosingAdReceive() : void
|
||||
{
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
if(_addAvatarCallback != null)
|
||||
{
|
||||
_addAvatarCallback(_status);
|
||||
_addAvatarCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function switchAvatars(switchIdx:int, switchAvatarsCallback:Function = null) : void
|
||||
{
|
||||
if(switchIdx < 0 || switchIdx >= avatars.length)
|
||||
{
|
||||
throw new Error("Invalid switchIdx:" + switchIdx);
|
||||
}
|
||||
_switchCallback = switchAvatarsCallback;
|
||||
_switchIdx = switchIdx;
|
||||
RoomXtCommManager.isSwitching = true;
|
||||
_isChoosing = false;
|
||||
DarkenManager.showLoadingSpiral(true);
|
||||
RoomManagerWorld.instance.forceStopMovement();
|
||||
AvatarXtCommManager.requestAvatarSwitch([avatars[switchIdx].perUserAvId]);
|
||||
}
|
||||
|
||||
public static function setAvatarSwitchCallback(switchAvatarsCallback:Function) : void
|
||||
{
|
||||
_switchCallback = switchAvatarsCallback;
|
||||
}
|
||||
|
||||
public static function avatarSwitchResponse(data:Array) : void
|
||||
{
|
||||
var sfsUserId:int = 0;
|
||||
var savw:AvatarWorldView = null;
|
||||
var asTransformTop:MediaHelper = null;
|
||||
var asTransformBtm:MediaHelper = null;
|
||||
var ftci:int = 0;
|
||||
var ftcdo:DisplayObject = null;
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
if(!_isChoosing)
|
||||
{
|
||||
if(_addAvatarCallback != null)
|
||||
{
|
||||
_addAvatarCallback(true);
|
||||
_addAvatarCallback = null;
|
||||
}
|
||||
}
|
||||
var asi:int = 2;
|
||||
var success:Boolean = Boolean(int(data[int(asi++)]));
|
||||
if(success)
|
||||
{
|
||||
sfsUserId = int(data[int(asi++)]);
|
||||
savw = AvatarManager.avatarViewList[sfsUserId];
|
||||
if(savw == null)
|
||||
{
|
||||
DebugUtility.debugTrace("ERROR: invalid avatar worldview savw:" + savw + " sfsUserId:" + sfsUserId + " data:" + data);
|
||||
return;
|
||||
}
|
||||
savw.setActivePet(0,0,0,"");
|
||||
if(savw.getChildAt(0).hasOwnProperty("onbottom1"))
|
||||
{
|
||||
ftci = savw.numChildren - 1;
|
||||
while(ftci > 0)
|
||||
{
|
||||
ftcdo = savw.getChildAt(ftci);
|
||||
if(ftcdo is MovieClip && MovieClip(ftcdo).hasOwnProperty("isTransformTop"))
|
||||
{
|
||||
endTransformAnim(MovieClip(ftcdo));
|
||||
break;
|
||||
}
|
||||
ftci--;
|
||||
}
|
||||
endTransformAnim(savw.getChildAt(0) as MovieClip);
|
||||
}
|
||||
if(_asTransformVec == null)
|
||||
{
|
||||
DebugUtility.debugTrace("ERROR: invalid AvatarSwitch state _asTransformTopMHVec:" + " data:" + data);
|
||||
return;
|
||||
}
|
||||
asTransformTop = new MediaHelper();
|
||||
asTransformTop.init(savw.roomType == Utility.ENVIRO_LAND ? uint(ASTRANSFORM_MEDIA_ID_TOP) : uint(ASTRANSFORM_OCEAN_MEDIA_ID_TOP),asTransformMediaHelper,[savw,data]);
|
||||
_asTransformVec.push(asTransformTop);
|
||||
asTransformBtm = new MediaHelper();
|
||||
asTransformBtm.init(savw.roomType == Utility.ENVIRO_LAND ? uint(ASTRANSFORM_MEDIA_ID_BOTTOM) : uint(ASTRANSFORM_OCEAN_MEDIA_ID_BOTTOM),asTransformMediaHelper,[savw]);
|
||||
_asTransformVec.push(asTransformBtm);
|
||||
if(sfsUserId == playerSfsUserId)
|
||||
{
|
||||
GuiManager.setSwapBtnGray(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("switch error!!!");
|
||||
RoomXtCommManager.isSwitching = false;
|
||||
if(!QuestManager.isInPrivateAdventureState)
|
||||
{
|
||||
GuiManager.setSwapBtnGray(false);
|
||||
}
|
||||
if(_switchIdx != activeAvatarIdx)
|
||||
{
|
||||
_switchIdx = activeAvatarIdx;
|
||||
}
|
||||
}
|
||||
if(_switchCallback != null)
|
||||
{
|
||||
_switchCallback(success,true);
|
||||
if(!success)
|
||||
{
|
||||
_switchCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function myAvatarListCallback(slotFlags:int) : void
|
||||
{
|
||||
availSlotFlags = slotFlags;
|
||||
}
|
||||
|
||||
public static function removeAvatar(removeIdx:int, removeAvatarCallback:Function) : void
|
||||
{
|
||||
if(removeIdx < 0 || removeIdx >= avatars.length)
|
||||
{
|
||||
throw new Error("Invalid removeIdx:" + removeIdx);
|
||||
}
|
||||
if(avatars.length <= 1)
|
||||
{
|
||||
throw new Error("Tried to remove avatar when less than 2 were left!");
|
||||
}
|
||||
_removeCallback = removeAvatarCallback;
|
||||
_removeIdx = removeIdx;
|
||||
AvatarXtCommManager.requestAvatarKill([avatars[removeIdx].perUserAvId],avatarKillResponse);
|
||||
}
|
||||
|
||||
public static function avatarKillResponse(success:Boolean, newGemBalance:int) : void
|
||||
{
|
||||
var removedAvInvId:int = 0;
|
||||
var isCurrSlotAvailable:Boolean = false;
|
||||
var ui:UserInfo = null;
|
||||
if(success)
|
||||
{
|
||||
isCurrSlotAvailable = isSlotAvailable(_removeIdx);
|
||||
removedAvInvId = int(AvatarXtCommManager.avSlotInfo[avatars[_removeIdx].perUserAvId].avInvId);
|
||||
ui = gMainFrame.userInfo.getUserInfoByUserName(avatars[_removeIdx].userName);
|
||||
ui.allItemsInUseOff(avatars[_removeIdx].perUserAvId);
|
||||
AvatarXtCommManager.avSlotInfo[avatars[_removeIdx].perUserAvId].avInvId = null;
|
||||
avatars[_removeIdx] = null;
|
||||
}
|
||||
if(_removeCallback != null)
|
||||
{
|
||||
_removeCallback(success,_removeIdx,removedAvInvId,newGemBalance,isCurrSlotAvailable);
|
||||
}
|
||||
_removeIdx = -1;
|
||||
}
|
||||
|
||||
public static function chooseTwo(switchIdxs:Array, aoCallback:Function) : void
|
||||
{
|
||||
_switchIdx = avatars[switchIdxs[0]].enviroTypeFlag == 2 ? int(switchIdxs[1]) : int(switchIdxs[0]);
|
||||
_secondChosenAvtIdx = -1;
|
||||
var switchInvIds:Array = [];
|
||||
switchInvIds[0] = AvatarXtCommManager.avSlotInfo[avatars[switchIdxs[0]].perUserAvId].avInvId;
|
||||
if(switchIdxs[1] != null && Boolean(AvatarSwitch.avatars[switchIdxs[1]]))
|
||||
{
|
||||
switchInvIds[1] = AvatarXtCommManager.avSlotInfo[avatars[switchIdxs[1]].perUserAvId].avInvId;
|
||||
_secondChosenAvtIdx = switchIdxs[1];
|
||||
}
|
||||
AvatarXtCommManager.requestAvatarOrdain(switchInvIds,aoCallback);
|
||||
}
|
||||
|
||||
private static function asTransformMediaHelper(mc:MovieClip) : void
|
||||
{
|
||||
if(!mc.hasOwnProperty("mediaHelper"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var mh:MediaHelper = MediaHelper(mc.mediaHelper);
|
||||
var mhid:int = mh.id;
|
||||
if(mhid != ASTRANSFORM_MEDIA_ID_TOP && mhid != ASTRANSFORM_MEDIA_ID_BOTTOM && mhid != ASTRANSFORM_OCEAN_MEDIA_ID_TOP && mhid != ASTRANSFORM_OCEAN_MEDIA_ID_BOTTOM)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mc.addEventListener(Event.ENTER_FRAME,transformEnterFrameHandler);
|
||||
var savw:AvatarView = AvatarView((mc.passback as Array)[0]);
|
||||
if(mhid == ASTRANSFORM_MEDIA_ID_TOP || mhid == ASTRANSFORM_OCEAN_MEDIA_ID_TOP)
|
||||
{
|
||||
mc.data = (mc.passback as Array)[1] as Array;
|
||||
DebugUtility.debugTrace("got top media for sfsUserId:" + int(mc.data[3]));
|
||||
mc.isTransformTop = true;
|
||||
savw.addChild(mc);
|
||||
_asTransformVec.splice(_asTransformVec.indexOf(mh),1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.isTransformBottom = true;
|
||||
savw.addChildAt(mc,0);
|
||||
_asTransformVec.splice(_asTransformVec.indexOf(mh),1);
|
||||
}
|
||||
mc.gotoAndPlay(1);
|
||||
mc.mediaHelper.destroy();
|
||||
delete mc.mediaHelper;
|
||||
delete mc.passback;
|
||||
}
|
||||
|
||||
private static function transformEnterFrameHandler(e:Event) : void
|
||||
{
|
||||
var data:Array = null;
|
||||
var asi:int = 0;
|
||||
var sfsUserId:int = 0;
|
||||
var selfSwitch:Boolean = false;
|
||||
var sav:Avatar = null;
|
||||
var otherAvatar:Avatar = null;
|
||||
var avatarWorldView:AvatarWorldView = null;
|
||||
var sai:AvatarInfo = null;
|
||||
var newAvatar:Avatar = null;
|
||||
var petInvId:int = 0;
|
||||
var myPet:Object = null;
|
||||
var newAvInfo:AvatarInfo = null;
|
||||
var lBits:int = 0;
|
||||
var uBits:int = 0;
|
||||
var eBits:int = 0;
|
||||
var petName:String = null;
|
||||
var questLevel:int = 0;
|
||||
var currPet:Object = null;
|
||||
var ble:BuddyEvent = null;
|
||||
var savw:AvatarWorldView = null;
|
||||
var etavw:AvatarWorldView = null;
|
||||
var tf:MovieClip = MovieClip(e.target);
|
||||
if(tf.parent == null || AvatarView(tf.parent).avatarData == null)
|
||||
{
|
||||
endTransformAnim(tf);
|
||||
return;
|
||||
}
|
||||
if(tf.currentFrameLabel != null)
|
||||
{
|
||||
DebugUtility.debugTrace("entered frame:" + tf.currentFrameLabel + " on transform effect for sfsUserId:" + AvatarView(tf.parent).userId);
|
||||
}
|
||||
if(tf.currentFrameLabel == "hideAvatar")
|
||||
{
|
||||
AvatarView(tf.parent).hideAvatar();
|
||||
if(tf.hasOwnProperty("data"))
|
||||
{
|
||||
data = tf.data;
|
||||
asi = 3;
|
||||
sfsUserId = int(data[int(asi++)]);
|
||||
selfSwitch = Boolean(sfsUserId == playerSfsUserId);
|
||||
sav = AvatarManager.getAvatarBySfsUserId(sfsUserId);
|
||||
if(selfSwitch)
|
||||
{
|
||||
otherAvatar = avatars[_switchIdx];
|
||||
otherAvatar.perUserAvId = sav.perUserAvId;
|
||||
otherAvatar.avTypeId = sav.avTypeId;
|
||||
otherAvatar.copyColors(sav.colors);
|
||||
otherAvatar.avName = sav.avName;
|
||||
otherAvatar.cloneShownAccFromAvatar(sav);
|
||||
AvatarManager.clearPlayerSplashColor();
|
||||
}
|
||||
sav.removeAllItems();
|
||||
sav.perUserAvId = int(data[int(asi++)]);
|
||||
sav.avTypeId = int(data[int(asi++)]);
|
||||
sav.setColors(uint(data[int(asi++)]),uint(data[int(asi++)]),uint(data[int(asi++)]));
|
||||
sav.avName = data[int(asi++)];
|
||||
if(sav.userName == gMainFrame.userInfo.myUserName && gMainFrame.userInfo.getAvatarInfoByUsernamePerUserAvId(sav.userName,sav.perUserAvId) == null)
|
||||
{
|
||||
AvatarXtCommManager.requestADForAvatar(sav.perUserAvId,true,null,sav);
|
||||
}
|
||||
else
|
||||
{
|
||||
sai = new AvatarInfo();
|
||||
sai.perUserAvId = sav.perUserAvId;
|
||||
sai.avName = sav.avName;
|
||||
sai.userName = sav.userName;
|
||||
sai.colors = sav.colors.concat();
|
||||
sai.type = sav.avTypeId;
|
||||
}
|
||||
avatarWorldView = AvatarManager.getAvatarWorldViewBySfsUserId(sfsUserId);
|
||||
if(Boolean(avatarWorldView))
|
||||
{
|
||||
if(avatarWorldView.parent != null)
|
||||
{
|
||||
avatarWorldView.parent.removeChild(avatarWorldView);
|
||||
}
|
||||
if(Boolean(sav.enviroTypeFlag & 1 << Utility.ENVIRO_AIR))
|
||||
{
|
||||
avatarWorldView.x += AvatarManager.getAvatarLayer.x + AvatarManager.getAvatarLayer.parent.x - AvatarManager.getFlyingLayer.x;
|
||||
avatarWorldView.y += AvatarManager.getAvatarLayer.y + AvatarManager.getAvatarLayer.parent.y - AvatarManager.getFlyingLayer.y;
|
||||
AvatarManager.getFlyingLayer.addChild(avatarWorldView);
|
||||
}
|
||||
else
|
||||
{
|
||||
avatarWorldView.x -= AvatarManager.getAvatarLayer.x + AvatarManager.getAvatarLayer.parent.x - AvatarManager.getFlyingLayer.x;
|
||||
avatarWorldView.y -= AvatarManager.getAvatarLayer.y + AvatarManager.getAvatarLayer.parent.y - AvatarManager.getFlyingLayer.y;
|
||||
AvatarManager.getAvatarLayer.addChild(avatarWorldView);
|
||||
}
|
||||
}
|
||||
if(selfSwitch)
|
||||
{
|
||||
if((otherAvatar.enviroTypeFlag & 1 << Utility.ENVIRO_AIR) != (sav.enviroTypeFlag & 1 << Utility.ENVIRO_AIR))
|
||||
{
|
||||
RoomManagerWorld.instance.rebuildGrid();
|
||||
if(avatarWorldView == null && !(sav.enviroTypeFlag & 1 << Utility.ENVIRO_AIR) || Boolean(RoomManagerWorld.instance.collisionTestGrid(avatarWorldView.x,avatarWorldView.y)))
|
||||
{
|
||||
RoomManagerWorld.instance.teleportPlayerToDefault();
|
||||
}
|
||||
}
|
||||
gMainFrame.userInfo.myPerUserAvId = sav.perUserAvId;
|
||||
GuiManager.positionHudAvatar();
|
||||
newAvatar = avatars[activeAvatarIdx];
|
||||
avatars.splice(activeAvatarIdx,1);
|
||||
avatars.unshift(avatars[_switchIdx - 1]);
|
||||
avatars.splice(_switchIdx,1);
|
||||
if(_secondChosenAvtIdx != -1)
|
||||
{
|
||||
avatars.unshift(avatars[_secondChosenAvtIdx - 1]);
|
||||
avatars.splice(_secondChosenAvtIdx,1);
|
||||
}
|
||||
avatars.unshift(newAvatar);
|
||||
activeAvatarIdx = 0;
|
||||
_switchIdx = 0;
|
||||
_secondChosenAvtIdx = -1;
|
||||
petInvId = int(data[asi++]);
|
||||
myPet = PetManager.getMyPetByInvId(petInvId);
|
||||
if(Boolean(AvatarManager.playerAvatarWorldView))
|
||||
{
|
||||
avatarWorldView = AvatarManager.playerAvatarWorldView;
|
||||
avatarWorldView.setActivePet(Boolean(myPet) ? uint(myPet.lBits) : 0,Boolean(myPet) ? uint(myPet.uBits) : 0,Boolean(myPet) ? uint(myPet.eBits) : 0,Boolean(myPet) ? myPet.name : "");
|
||||
}
|
||||
PetManager.myActivePetInvId = petInvId;
|
||||
newAvInfo = gMainFrame.userInfo.getAvatarInfoByUsernamePerUserAvId(sav.userName,sav.perUserAvId);
|
||||
if(Boolean(newAvInfo))
|
||||
{
|
||||
sai.questLevel = int(data[asi++]);
|
||||
sai.questHealthPercentage = newAvInfo.questHealthPercentage;
|
||||
sai.healthBase = newAvInfo.healthBase;
|
||||
sai.attackBase = newAvInfo.attackBase;
|
||||
sai.attackMax = newAvInfo.attackMax;
|
||||
sai.defenseBase = newAvInfo.defenseBase;
|
||||
sai.defenseMax = newAvInfo.defenseMax;
|
||||
gMainFrame.userInfo.setAvatarInfoByUsernamePerUserAvId(sav.perUserAvId,sai,true);
|
||||
sav.itemResponseIntegrate(gMainFrame.userInfo.getUserInfoByUserName(sav.userName).getPartialItemList(sav.avTypeId,true));
|
||||
avatarWorldView.updateNameBarLevelShape(sai.questLevel);
|
||||
}
|
||||
updateAvatarSlotIds();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemXtCommManager.requestItemListForAvatar(null,sav,false,false);
|
||||
if(Boolean(AvatarManager.buddyCardAvatarView) && sav.userName == AvatarManager.buddyCardAvatarView.userName)
|
||||
{
|
||||
BuddyCard.updateCurrBuddyCardAvatar(sav);
|
||||
}
|
||||
lBits = int(data[int(asi++)]);
|
||||
uBits = int(data[int(asi++)]);
|
||||
eBits = int(data[int(asi++)]);
|
||||
petName = data[int(asi++)];
|
||||
questLevel = int(data[asi++]);
|
||||
avatarWorldView = AvatarManager.getAvatarWorldViewBySfsUserId(sfsUserId);
|
||||
if(Boolean(avatarWorldView))
|
||||
{
|
||||
avatarWorldView.setActivePet(lBits,uBits,eBits,petName);
|
||||
}
|
||||
currPet = {
|
||||
"name":petName,
|
||||
"lBits":lBits,
|
||||
"uBits":uBits,
|
||||
"eBits":eBits
|
||||
};
|
||||
currPet.defId = PetManager.getDefIdFromLBits(currPet.lBits);
|
||||
currPet.type = PetManager.petTypeForDefId(currPet.defId);
|
||||
currPet.isGround = PetManager.isGround(currPet.type);
|
||||
sai.currPet = currPet;
|
||||
sai.questLevel = questLevel;
|
||||
gMainFrame.userInfo.setAvatarInfoByUsernamePerUserAvId(sav.perUserAvId,sai,true);
|
||||
avatarWorldView.updateNameBarLevelShape(sai.questLevel);
|
||||
ble = new BuddyEvent(BuddyEvent.BUDDY_CHANGED);
|
||||
ble.userName = sai.userName;
|
||||
BuddyManager.eventDispatcher.dispatchEvent(ble);
|
||||
}
|
||||
AvatarWorldView(tf.parent).setPos(tf.parent.x,tf.parent.y,false);
|
||||
delete tf.data;
|
||||
if(_switchCallback != null)
|
||||
{
|
||||
_switchCallback(true);
|
||||
_switchCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(tf.currentFrameLabel == "changeAvatar")
|
||||
{
|
||||
AvatarView(tf.parent).showAvatar();
|
||||
}
|
||||
else if(tf.currentFrameLabel == "tintOn")
|
||||
{
|
||||
savw = AvatarWorldView(tf.parent);
|
||||
if(savw.roomType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
savw.setBlendColor(4290903190,7534606);
|
||||
}
|
||||
else
|
||||
{
|
||||
savw.setBlendColor(4294967295,16777107);
|
||||
}
|
||||
}
|
||||
else if(tf.currentFrameLabel == "tintOff")
|
||||
{
|
||||
etavw = AvatarWorldView(tf.parent);
|
||||
etavw.setBlendColor(0);
|
||||
etavw.setAlphaLevel(100);
|
||||
if(etavw.userId == playerSfsUserId)
|
||||
{
|
||||
AvatarManager.clearPlayerSplashColor();
|
||||
}
|
||||
}
|
||||
else if(tf.currentFrame == tf.totalFrames)
|
||||
{
|
||||
endTransformAnim(tf);
|
||||
}
|
||||
}
|
||||
|
||||
private static function endTransformAnim(tf:MovieClip) : void
|
||||
{
|
||||
var etavw:AvatarView = AvatarView(tf.parent);
|
||||
if(tf.parent != null && etavw.avatarData != null)
|
||||
{
|
||||
DebugUtility.debugTrace("ending one of two transitions for sfsUserId:" + etavw.userId);
|
||||
}
|
||||
tf.removeEventListener(Event.ENTER_FRAME,transformEnterFrameHandler);
|
||||
var s:SoundTransform = tf.soundTransform;
|
||||
s.volume = 0;
|
||||
tf.soundTransform = s;
|
||||
tf.gotoAndStop(1);
|
||||
RoomXtCommManager.isSwitching = false;
|
||||
if(etavw.userName == gMainFrame.userInfo.myUserName && !QuestManager.isInPrivateAdventureState)
|
||||
{
|
||||
GuiManager.setSwapBtnGray(false);
|
||||
}
|
||||
if(tf.parent != null)
|
||||
{
|
||||
tf.parent.removeChild(tf);
|
||||
}
|
||||
}
|
||||
|
||||
private static function updateAvatarSlotIds() : void
|
||||
{
|
||||
var currAvtSlotInfo:Object = null;
|
||||
var ourAvatarSlotInfo:Object = AvatarXtCommManager.avSlotInfo;
|
||||
for(var i:int = 0; i < avatars.length; i++)
|
||||
{
|
||||
if(Boolean(avatars[i]))
|
||||
{
|
||||
currAvtSlotInfo = ourAvatarSlotInfo[avatars[i].perUserAvId];
|
||||
if(Boolean(currAvtSlotInfo))
|
||||
{
|
||||
currAvtSlotInfo.slotId = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,343 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.graphics.LayerAnim;
|
||||
import flash.display.Sprite;
|
||||
import flash.filters.ColorMatrixFilter;
|
||||
import item.Item;
|
||||
|
||||
public class AvatarView extends Sprite
|
||||
{
|
||||
|
||||
protected var _layerAnim:LayerAnim;
|
||||
|
||||
protected var _avatar:Avatar;
|
||||
|
||||
public var avTypeChangedCallback:Function;
|
||||
|
||||
private var _isOffScreen:Boolean;
|
||||
|
||||
private var _holdAnimId:int;
|
||||
|
||||
private var _lastAnimToHappen:int;
|
||||
|
||||
public function AvatarView()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function set lastAnimToHappen(lastAnimId:int) : void
|
||||
{
|
||||
this._lastAnimToHappen = lastAnimId;
|
||||
}
|
||||
|
||||
public function get lastAnimToHappen() : int
|
||||
{
|
||||
return this._lastAnimToHappen;
|
||||
}
|
||||
|
||||
public function set holdAnimId(inAnimId:int) : void
|
||||
{
|
||||
this._holdAnimId = inAnimId;
|
||||
}
|
||||
|
||||
public function init(avatar:Avatar, avTypeCallback:Function = null) : void
|
||||
{
|
||||
this._holdAnimId = 0;
|
||||
this._avatar = avatar;
|
||||
this._avatar.addEventListener(AvatarEvent.AVATAR_CHANGED,this.avatarChanged,false,0,true);
|
||||
this.avTypeChangedCallback = avTypeCallback;
|
||||
this._layerAnim = LayerAnim.getNew();
|
||||
this._layerAnim.avDefId = this._avatar.avTypeId;
|
||||
if(Boolean(this._avatar.colors))
|
||||
{
|
||||
this._layerAnim.layers = this.setLayerHelper();
|
||||
}
|
||||
this.addChild(this._layerAnim.bitmap);
|
||||
}
|
||||
|
||||
public function destroy(destroyAvatar:Boolean = false) : void
|
||||
{
|
||||
if(destroyAvatar && Boolean(this._avatar))
|
||||
{
|
||||
this._avatar.removeEventListener(AvatarEvent.AVATAR_CHANGED,this.avatarChanged);
|
||||
this._avatar.destroy();
|
||||
this._avatar = null;
|
||||
}
|
||||
this.avTypeChangedCallback = null;
|
||||
LayerAnim.destroy(this._layerAnim);
|
||||
this._layerAnim = null;
|
||||
}
|
||||
|
||||
public function resetAvatar(rAv:Avatar) : void
|
||||
{
|
||||
if(Boolean(this._avatar) && this._avatar.hasEventListener(AvatarEvent.AVATAR_CHANGED))
|
||||
{
|
||||
this._avatar.removeEventListener(AvatarEvent.AVATAR_CHANGED,this.avatarChanged);
|
||||
}
|
||||
this._avatar = rAv;
|
||||
this._avatar.addEventListener(AvatarEvent.AVATAR_CHANGED,this.avatarChanged,false,0,true);
|
||||
if(Boolean(this._layerAnim))
|
||||
{
|
||||
this._layerAnim.avDefId = this._avatar.avTypeId;
|
||||
if(Boolean(this._avatar.colors))
|
||||
{
|
||||
this._layerAnim.layers = this.setLayerHelper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isValid() : Boolean
|
||||
{
|
||||
return this._layerAnim != null;
|
||||
}
|
||||
|
||||
public function hideAvatar() : void
|
||||
{
|
||||
if(this._layerAnim != null)
|
||||
{
|
||||
this._layerAnim.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function showAvatar() : void
|
||||
{
|
||||
if(this._layerAnim != null)
|
||||
{
|
||||
this._layerAnim.visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function set isOffScreen(value:Boolean) : void
|
||||
{
|
||||
this._isOffScreen = value;
|
||||
}
|
||||
|
||||
public function get isOffScreen() : Boolean
|
||||
{
|
||||
return this._isOffScreen;
|
||||
}
|
||||
|
||||
public function pauseAnim(b:Boolean) : void
|
||||
{
|
||||
this._layerAnim.pause = b;
|
||||
}
|
||||
|
||||
public function advanceFrame() : void
|
||||
{
|
||||
++this._layerAnim.frame;
|
||||
}
|
||||
|
||||
public function get frame() : int
|
||||
{
|
||||
return this._layerAnim.frame;
|
||||
}
|
||||
|
||||
public function set frame(f:int) : void
|
||||
{
|
||||
this._layerAnim.frame = f;
|
||||
}
|
||||
|
||||
public function get flip() : Boolean
|
||||
{
|
||||
return this._layerAnim.hFlip;
|
||||
}
|
||||
|
||||
public function get animId() : int
|
||||
{
|
||||
return this._layerAnim.animId;
|
||||
}
|
||||
|
||||
protected function avatarChanged(evt:AvatarEvent) : void
|
||||
{
|
||||
if(Boolean(this._layerAnim))
|
||||
{
|
||||
if(this._layerAnim.avDefId != this._avatar.avTypeId)
|
||||
{
|
||||
this._layerAnim.avDefId = this._avatar.avTypeId;
|
||||
if(this.avTypeChangedCallback != null)
|
||||
{
|
||||
this.avTypeChangedCallback(this);
|
||||
}
|
||||
}
|
||||
this._layerAnim.layers = this.setLayerHelper();
|
||||
}
|
||||
}
|
||||
|
||||
protected function setLayerHelper() : Array
|
||||
{
|
||||
var avInfo:AvatarInfo = null;
|
||||
var tempItems:Array = null;
|
||||
var items:Array = null;
|
||||
if(Boolean(this._avatar.inventoryBodyMod) && Boolean(this._avatar.inventoryBodyMod.itemArray) && this._avatar.inventoryBodyMod.itemArray.length >= 1)
|
||||
{
|
||||
items = this._avatar.inventoryBodyMod.itemArray.concat(this._avatar.inventoryClothing.itemArray.concat());
|
||||
}
|
||||
else
|
||||
{
|
||||
avInfo = gMainFrame.userInfo.getAvatarInfoByUsernamePerUserAvId(this._avatar.userName,this._avatar.perUserAvId);
|
||||
if(Boolean(avInfo))
|
||||
{
|
||||
tempItems = avInfo.getItems(true);
|
||||
if(Boolean(tempItems))
|
||||
{
|
||||
items = tempItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
return AvatarUtility.layerArrayForItemsAndColors(items,this._avatar.colors,this._avatar.perUserAvId);
|
||||
}
|
||||
|
||||
public function playAnim(animId:int, hFlip:Boolean = false, mode:int = 0, callback:Function = null) : void
|
||||
{
|
||||
var needToChangeLayers:Boolean = false;
|
||||
var accItems:Array = null;
|
||||
var accItemsLength:int = 0;
|
||||
var ntci:int = 0;
|
||||
var layerArray:Array = null;
|
||||
var shownItems:Array = null;
|
||||
var obj:Object = null;
|
||||
var colors:Array = null;
|
||||
var color:uint = 0;
|
||||
var showItem:Item = null;
|
||||
if(Boolean(this._layerAnim) && Boolean(this._layerAnim.visible) && (this._holdAnimId == 0 || animId == this._holdAnimId))
|
||||
{
|
||||
if(!this._isOffScreen)
|
||||
{
|
||||
needToChangeLayers = false;
|
||||
accItems = this._avatar.accShownItems;
|
||||
if(!this._layerAnim.layers)
|
||||
{
|
||||
needToChangeLayers = true;
|
||||
}
|
||||
else if(this._layerAnim.layers.length != accItems.length)
|
||||
{
|
||||
needToChangeLayers = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
accItemsLength = int(accItems.length);
|
||||
for(ntci = 0; ntci < accItemsLength; ntci++)
|
||||
{
|
||||
if(this._layerAnim.layers.indexOf(accItems[ntci].accId) == -1)
|
||||
{
|
||||
needToChangeLayers = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(needToChangeLayers)
|
||||
{
|
||||
layerArray = [];
|
||||
shownItems = accItems;
|
||||
colors = this._avatar.colors;
|
||||
for each(showItem in shownItems)
|
||||
{
|
||||
if(showItem.getInUse(this._avatar.perUserAvId))
|
||||
{
|
||||
if(showItem.layerId == 1)
|
||||
{
|
||||
color = uint(colors[0]);
|
||||
}
|
||||
else if(showItem.layerId == 2)
|
||||
{
|
||||
color = uint(colors[1]);
|
||||
}
|
||||
else if(showItem.layerId == 3)
|
||||
{
|
||||
color = uint(colors[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = showItem.color;
|
||||
}
|
||||
obj = {
|
||||
"l":showItem.accId,
|
||||
"c":color
|
||||
};
|
||||
layerArray.push(obj);
|
||||
}
|
||||
}
|
||||
this._layerAnim.layers = layerArray;
|
||||
}
|
||||
this._layerAnim.hFlip = hFlip;
|
||||
this._layerAnim.playAnim(animId,mode,callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._lastAnimToHappen = animId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function reloadItemsFromCache() : void
|
||||
{
|
||||
var allItems:Array = gMainFrame.userInfo.getAvatarInfoByUsernamePerUserAvId(this._avatar.userName,this._avatar.perUserAvId).getItems(true);
|
||||
this._avatar.itemResponseIntegrate(allItems);
|
||||
}
|
||||
|
||||
public function preloadAnims(anims:Array, callback:Function = null) : void
|
||||
{
|
||||
this._layerAnim.preload(anims,callback);
|
||||
}
|
||||
|
||||
public function blackOut() : void
|
||||
{
|
||||
var matrix:Array = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0];
|
||||
this._layerAnim.bitmap.filters = [new ColorMatrixFilter(matrix)];
|
||||
}
|
||||
|
||||
public function get avatarData() : Avatar
|
||||
{
|
||||
return this._avatar;
|
||||
}
|
||||
|
||||
public function get userName() : String
|
||||
{
|
||||
if(this._avatar != null)
|
||||
{
|
||||
return this._avatar.userName;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function get userId() : int
|
||||
{
|
||||
if(this._avatar == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return this._avatar.sfsUserId;
|
||||
}
|
||||
|
||||
public function get avTypeId() : int
|
||||
{
|
||||
return this._avatar.avTypeId;
|
||||
}
|
||||
|
||||
public function get perUserAvId() : int
|
||||
{
|
||||
return this._avatar.perUserAvId;
|
||||
}
|
||||
|
||||
public function get inventoryBodyModItems() : Array
|
||||
{
|
||||
return this._avatar.inventoryBodyMod.itemArray;
|
||||
}
|
||||
|
||||
public function get inventoryClothingItems() : Array
|
||||
{
|
||||
return this._avatar.inventoryClothing.itemArray;
|
||||
}
|
||||
|
||||
public function setAvtColors(colors:Array) : void
|
||||
{
|
||||
this._avatar.colors = colors;
|
||||
}
|
||||
|
||||
public function get avName() : String
|
||||
{
|
||||
return this._avatar.avName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
package avatar
|
||||
{
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Loader;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import flash.geom.Matrix;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class AvatarViewExt_Splash
|
||||
{
|
||||
|
||||
private static const SHADOW_X_OFFSET:int = -100;
|
||||
|
||||
private static const SHADOW_Y_OFFSET:int = -20;
|
||||
|
||||
private static const Shadow:Class = AvatarViewExt_Splash_Shadow;
|
||||
|
||||
private static const WaterSplashSWF:Class = AvatarViewExt_Splash_WaterSplashSWF;
|
||||
|
||||
private const _constSplash:ByteArray = new WaterSplashSWF();
|
||||
|
||||
private var _mask:Shape;
|
||||
|
||||
private var _shadow:Bitmap;
|
||||
|
||||
private var _splash:Loader;
|
||||
|
||||
private var _parent:Sprite;
|
||||
|
||||
private var _maskLayer:DisplayObject;
|
||||
|
||||
private var _bLastSplashVolume:Boolean;
|
||||
|
||||
private var _bSplashInProgress:Boolean;
|
||||
|
||||
private var _lastSplashLiquid:String;
|
||||
|
||||
private var _shadowChildIndex:int;
|
||||
|
||||
public function AvatarViewExt_Splash(parent:Sprite, layerBitmap:DisplayObject)
|
||||
{
|
||||
super();
|
||||
this._parent = parent;
|
||||
this._bSplashInProgress = false;
|
||||
this._bLastSplashVolume = false;
|
||||
this.createShadow();
|
||||
this.createMask(layerBitmap);
|
||||
this._parent.addChild(layerBitmap);
|
||||
this.createSplash();
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
if(Boolean(this._shadow) && this._shadow.parent != null)
|
||||
{
|
||||
this._shadow.parent.removeChild(this._shadow);
|
||||
this._shadow = null;
|
||||
}
|
||||
if(Boolean(this._splash))
|
||||
{
|
||||
this._parent.removeChild(this._splash);
|
||||
this._splash.unloadAndStop();
|
||||
this._splash = null;
|
||||
}
|
||||
if(Boolean(this._mask))
|
||||
{
|
||||
this._parent.removeChild(this._mask);
|
||||
this._mask = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function showShadow(flag:Boolean = true) : void
|
||||
{
|
||||
this._shadow.visible = flag;
|
||||
}
|
||||
|
||||
private function createShadow() : void
|
||||
{
|
||||
this._shadow = new Shadow();
|
||||
this._shadow.x = SHADOW_X_OFFSET;
|
||||
this._shadow.y = SHADOW_Y_OFFSET;
|
||||
this._parent.addChild(this._shadow);
|
||||
}
|
||||
|
||||
private function createMask(maskLayer:DisplayObject) : void
|
||||
{
|
||||
var x:Number = NaN;
|
||||
var y:Number = NaN;
|
||||
this._maskLayer = maskLayer;
|
||||
this._mask = new Shape();
|
||||
this._parent.addChild(this._mask);
|
||||
this._mask.graphics.lineStyle();
|
||||
this._mask.graphics.beginFill(16777215,1);
|
||||
x = -150;
|
||||
y = -275;
|
||||
this._mask.graphics.moveTo(x,y);
|
||||
this._mask.graphics.lineTo(x + 245,y);
|
||||
this._mask.graphics.lineTo(x + 245,y + 235);
|
||||
this._mask.graphics.curveTo(x + 122.5,y + 260,x,y + 235);
|
||||
this._mask.graphics.lineTo(x,y);
|
||||
this._mask.graphics.endFill();
|
||||
this._maskLayer.mask = null;
|
||||
this._mask.visible = false;
|
||||
}
|
||||
|
||||
private function createSplash() : void
|
||||
{
|
||||
this._splash = new Loader();
|
||||
this._splash.loadBytes(this._constSplash);
|
||||
this._splash.x = -18;
|
||||
this._splash.y = -28;
|
||||
this._parent.addChild(this._splash);
|
||||
this._splash.visible = false;
|
||||
}
|
||||
|
||||
public function flipSplash(b:Boolean) : void
|
||||
{
|
||||
var matrix:Matrix = this._shadow.transform.matrix;
|
||||
if(b)
|
||||
{
|
||||
if(matrix.a != -1)
|
||||
{
|
||||
matrix.scale(-1,1);
|
||||
this._shadow.transform.matrix = matrix;
|
||||
matrix = this._splash.content.transform.matrix;
|
||||
matrix.scale(-1,1);
|
||||
this._splash.content.transform.matrix = matrix;
|
||||
}
|
||||
}
|
||||
else if(matrix.a == -1)
|
||||
{
|
||||
matrix.scale(-1,1);
|
||||
this._shadow.transform.matrix = matrix;
|
||||
matrix = this._splash.content.transform.matrix;
|
||||
matrix.scale(-1,1);
|
||||
this._splash.content.transform.matrix = matrix;
|
||||
}
|
||||
}
|
||||
|
||||
public function heartbeat(bInSplashVolume:Boolean, bIsSplashAnim:Boolean, splashLiquid:String, inAir:Boolean) : void
|
||||
{
|
||||
if(Boolean(this._shadow))
|
||||
{
|
||||
if(inAir)
|
||||
{
|
||||
if(this._shadow.parent != null)
|
||||
{
|
||||
this._shadowChildIndex = this._shadow.parent.getChildIndex(this._shadow);
|
||||
this._shadow.parent.removeChild(this._shadow);
|
||||
}
|
||||
}
|
||||
else if(this._shadow.parent == null)
|
||||
{
|
||||
this._parent.addChildAt(this._shadow,this._shadowChildIndex);
|
||||
}
|
||||
}
|
||||
var splashMC:MovieClip = MovieClip(this._splash.content);
|
||||
if(Boolean(splashMC))
|
||||
{
|
||||
if(splashLiquid == "ice" || splashLiquid == "fire" || splashLiquid == "ghost")
|
||||
{
|
||||
bInSplashVolume = false;
|
||||
}
|
||||
if(bInSplashVolume)
|
||||
{
|
||||
splashMC.setState(bIsSplashAnim ? 1 : 2);
|
||||
}
|
||||
else if(splashMC.currentFrame == 1 && this._splash.visible == true)
|
||||
{
|
||||
this._splash.visible = false;
|
||||
}
|
||||
if(bInSplashVolume != this._bLastSplashVolume || splashLiquid != this._lastSplashLiquid)
|
||||
{
|
||||
splashMC.setLiquid(splashLiquid);
|
||||
this._bLastSplashVolume = bInSplashVolume;
|
||||
this._lastSplashLiquid = splashLiquid;
|
||||
this.showMask(bInSplashVolume);
|
||||
if(bInSplashVolume)
|
||||
{
|
||||
if(this._splash.visible == false)
|
||||
{
|
||||
this._splash.visible = true;
|
||||
}
|
||||
splashMC.setState(bIsSplashAnim ? 1 : 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
splashMC.setState(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function showMask(show:Boolean = true) : void
|
||||
{
|
||||
if(show)
|
||||
{
|
||||
this._maskLayer.mask = this._mask;
|
||||
this.showShadow(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._maskLayer.mask = null;
|
||||
this.showShadow(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package avatar
|
||||
{
|
||||
import mx.core.BitmapAsset;
|
||||
|
||||
[ExcludeClass]
|
||||
[Embed(source="/_assets/4_avatar.AvatarViewExt_Splash_Shadow.png")]
|
||||
public class AvatarViewExt_Splash_Shadow extends BitmapAsset
|
||||
{
|
||||
|
||||
public function AvatarViewExt_Splash_Shadow()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package avatar
|
||||
{
|
||||
import mx.core.ByteArrayAsset;
|
||||
|
||||
[ExcludeClass]
|
||||
[Embed(source="/_assets/6_avatar.AvatarViewExt_Splash_WaterSplashSWF.bin", mimeType="application/octet-stream")]
|
||||
public class AvatarViewExt_Splash_WaterSplashSWF extends ByteArrayAsset
|
||||
{
|
||||
|
||||
public function AvatarViewExt_Splash_WaterSplashSWF()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,828 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.client.SFClient;
|
||||
import com.sbi.client.SFEvent;
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import com.sbi.loader.FileServerEvent;
|
||||
import flash.geom.Point;
|
||||
import flash.utils.Dictionary;
|
||||
import item.Item;
|
||||
import item.ItemXtCommManager;
|
||||
import loader.DefPacksDefHelper;
|
||||
import pet.PetManager;
|
||||
|
||||
public class AvatarXtCommManager
|
||||
{
|
||||
|
||||
public static var avSlotInfo:Object;
|
||||
|
||||
private static var _adAvatarQueue:Array;
|
||||
|
||||
private static var _agQueue:Dictionary;
|
||||
|
||||
private static var _agsQueue:Dictionary;
|
||||
|
||||
private static var _avatarCreateResponse:Function;
|
||||
|
||||
private static var _avatarUpdateResponse:Function;
|
||||
|
||||
private static var _avatarPaintResponse:Function;
|
||||
|
||||
private static var _avatarRemoveResponse:Function;
|
||||
|
||||
private static var _avatarListResponse:Function;
|
||||
|
||||
private static var _getAvatarByUsername:Function;
|
||||
|
||||
private static var _buddyCardUpdateDropDownHandler:Function;
|
||||
|
||||
private static var _avatarInfoCallback:Function;
|
||||
|
||||
private static var _abCallback:Function;
|
||||
|
||||
private static var _asCallback:Function;
|
||||
|
||||
private static var _aaCallback:Function;
|
||||
|
||||
private static var _alCallback:Function;
|
||||
|
||||
private static var _handleCreateAvatarData:Function;
|
||||
|
||||
private static var _akCallback:Function;
|
||||
|
||||
private static var _aoCallback:Function;
|
||||
|
||||
private static var _photoTakeCallback:Function;
|
||||
|
||||
private static var _avatarsInRoom:Object;
|
||||
|
||||
private static var _gameAvatarAdCallback:Function;
|
||||
|
||||
public function AvatarXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(initACResponse:Function = null, initAUResponse:Function = null, initAPResponse:Function = null, initARResponse:Function = null, initALResponse:Function = null, initAvatarsInRoom:Object = null, initGetAvatarByUserName:Function = null, initASResponse:Function = null, initBuddyCardUpdateDropDown:Function = null) : void
|
||||
{
|
||||
_avatarCreateResponse = initACResponse;
|
||||
_avatarUpdateResponse = initAUResponse;
|
||||
_avatarPaintResponse = initAPResponse;
|
||||
_avatarRemoveResponse = initARResponse;
|
||||
_avatarListResponse = initALResponse;
|
||||
_getAvatarByUsername = initGetAvatarByUserName;
|
||||
_asCallback = initASResponse;
|
||||
_buddyCardUpdateDropDownHandler = initBuddyCardUpdateDropDown;
|
||||
_adAvatarQueue = [];
|
||||
avSlotInfo = new Object();
|
||||
_agQueue = new Dictionary(false);
|
||||
_agsQueue = new Dictionary(false);
|
||||
_avatarsInRoom = initAvatarsInRoom;
|
||||
XtReplyDemuxer.addModule(handleXtReply,"a");
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
_adAvatarQueue = null;
|
||||
XtReplyDemuxer.removeModule(handleXtReply);
|
||||
}
|
||||
|
||||
public static function requestAvatarMake(initHandleCreateAvatarData:Function) : void
|
||||
{
|
||||
_handleCreateAvatarData = initHandleCreateAvatarData;
|
||||
gMainFrame.server.setXtObject_Str("am",[],gMainFrame.server.isWorldZone);
|
||||
}
|
||||
|
||||
public static function requestAvatarInfo(setAvatarInfoCallback:Function) : void
|
||||
{
|
||||
var dpdh:DefPacksDefHelper = null;
|
||||
_avatarInfoCallback = setAvatarInfoCallback;
|
||||
if(gMainFrame.userInfo.avtDefsCached)
|
||||
{
|
||||
if(_avatarInfoCallback != null)
|
||||
{
|
||||
_avatarInfoCallback();
|
||||
_avatarInfoCallback = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dpdh = new DefPacksDefHelper();
|
||||
dpdh.init(DefPacksDefHelper.DEF_AVATAR,avatarInfoResponse,null,FileServerEvent.AMF3_TYPE);
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_AVATAR] = dpdh;
|
||||
}
|
||||
}
|
||||
|
||||
public static function requestADForAvatar(getPerUserAvId:int, requestItemList:Boolean, getAvDataCallback:Function, getAvDataAvatar:Avatar) : void
|
||||
{
|
||||
_adAvatarQueue.push({
|
||||
"a":getAvDataAvatar,
|
||||
"c":(requestItemList ? null : getAvDataCallback)
|
||||
});
|
||||
var wasItemListAlreadyRequested:Boolean = gMainFrame.userInfo.myUserName == getAvDataAvatar.userName ? ItemXtCommManager.hasRequestedFullItemList : true;
|
||||
var cachedInfo:AvatarInfo = gMainFrame.userInfo.getAvatarInfoByUsernamePerUserAvId(getAvDataAvatar.userName,getPerUserAvId);
|
||||
if(Boolean(cachedInfo) && cachedInfo.type != -1)
|
||||
{
|
||||
avatarDataResponseIntegrate([cachedInfo.perUserAvId,cachedInfo.avName,cachedInfo.userName,cachedInfo.type,cachedInfo.colors[0],cachedInfo.colors[1],cachedInfo.colors[2]]);
|
||||
if(requestItemList)
|
||||
{
|
||||
if(getAvDataAvatar == null)
|
||||
{
|
||||
throw new Error("requestAvatarData got requestItemList=true but getAvDataAvatar=null!");
|
||||
}
|
||||
if(getAvDataAvatar.userName != gMainFrame.userInfo.myUserName)
|
||||
{
|
||||
ItemXtCommManager.requestItemListForAvatar(getAvDataCallback,getAvDataAvatar,!wasItemListAlreadyRequested);
|
||||
}
|
||||
else
|
||||
{
|
||||
getAvDataCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(requestItemList)
|
||||
{
|
||||
ItemXtCommManager.insertIntoILAvatarQueue(getPerUserAvId,getAvDataCallback,getAvDataAvatar);
|
||||
}
|
||||
sendAvatarDataRequest([getAvDataAvatar.userName,getPerUserAvId,requestItemList ? (wasItemListAlreadyRequested ? "2" : "1") : "0"]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function requestAvatarList(alParams:Array, alCallback:Function = null) : void
|
||||
{
|
||||
_alCallback = alCallback;
|
||||
gMainFrame.server.setXtObject_Str("al",alParams,gMainFrame.server.isWorldZone);
|
||||
}
|
||||
|
||||
public static function requestAvatarBuy(abCallback:Function) : void
|
||||
{
|
||||
_abCallback = abCallback;
|
||||
gMainFrame.server.setXtObject_Str("ab",[]);
|
||||
}
|
||||
|
||||
public static function requestAvatarSwitch(asParams:Array) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("as",asParams);
|
||||
}
|
||||
|
||||
public static function requestAvatarAdd(aaParams:Array, aaCallback:Function) : void
|
||||
{
|
||||
_aaCallback = aaCallback;
|
||||
gMainFrame.server.setXtObject_Str("aa",aaParams,gMainFrame.server.isWorldZone);
|
||||
}
|
||||
|
||||
public static function requestAvatarShopBuy(asbParams:Array, asbCallback:Function) : void
|
||||
{
|
||||
_aaCallback = asbCallback;
|
||||
gMainFrame.server.setXtObject_Str("asb",asbParams,gMainFrame.server.isWorldZone);
|
||||
}
|
||||
|
||||
public static function requestAvatarKill(akParams:Array, akCallback:Function) : void
|
||||
{
|
||||
_akCallback = akCallback;
|
||||
gMainFrame.server.setXtObject_Str("ak",akParams);
|
||||
}
|
||||
|
||||
public static function requestAvatarOrdain(avIdxs:Array, aoCallback:Function) : void
|
||||
{
|
||||
_aoCallback = aoCallback;
|
||||
gMainFrame.server.setXtObject_Str("ao",avIdxs);
|
||||
}
|
||||
|
||||
public static function requestAvatarGet(userName:String, callback:Function, isPlayerSearchLookup:Boolean = false) : void
|
||||
{
|
||||
_agQueue[userName.toLowerCase()] = callback;
|
||||
gMainFrame.server.setXtObject_Str("ag",[userName,isPlayerSearchLookup ? "1" : "0"]);
|
||||
}
|
||||
|
||||
public static function requestAvatarGetBySfsId(sfsUserId:int, callback:Function) : void
|
||||
{
|
||||
_agsQueue[sfsUserId] = callback;
|
||||
gMainFrame.server.setXtObject_Str("ags",[sfsUserId,"0"]);
|
||||
}
|
||||
|
||||
public static function requestColorChange(colors:Array, nameBarColor:int, requestColorsCallback:Function = null) : void
|
||||
{
|
||||
if(requestColorsCallback != null)
|
||||
{
|
||||
_avatarPaintResponse = requestColorsCallback;
|
||||
}
|
||||
gMainFrame.server.setXtObject_Str("ap",[colors[0],colors[1],colors[2],nameBarColor],gMainFrame.server.isWorldZone);
|
||||
}
|
||||
|
||||
public static function setGameAvatarAdCallback(callback:Function) : void
|
||||
{
|
||||
_gameAvatarAdCallback = callback;
|
||||
}
|
||||
|
||||
public static function sendAvatarPendingFlagsUpdate(bit:int) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("af",[bit]);
|
||||
gMainFrame.userInfo.pendingFlags |= 1 << bit;
|
||||
}
|
||||
|
||||
public static function sendAvatarPhotoTakeCheck(callback:Function) : void
|
||||
{
|
||||
_photoTakeCallback = callback;
|
||||
gMainFrame.server.setXtObject_Str("apc",[]);
|
||||
}
|
||||
|
||||
public static function sendAvatarPhotoTake(callback:Function) : void
|
||||
{
|
||||
_photoTakeCallback = callback;
|
||||
gMainFrame.server.setXtObject_Str("apb",[]);
|
||||
}
|
||||
|
||||
private static function sendAvatarDataRequest(radParams:Array) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("ad",radParams,gMainFrame.server.isWorldZone);
|
||||
}
|
||||
|
||||
public static function handleXtReply(evt:SFEvent) : void
|
||||
{
|
||||
if(!evt.status)
|
||||
{
|
||||
DebugUtility.debugTrace("ERROR: AvatarXtCommManager handleXtReply was called with bad evt.status:" + evt.status);
|
||||
return;
|
||||
}
|
||||
var data:Array = evt.obj;
|
||||
switch(data[0])
|
||||
{
|
||||
case "au":
|
||||
if(_avatarUpdateResponse != null)
|
||||
{
|
||||
_avatarUpdateResponse(data);
|
||||
}
|
||||
break;
|
||||
case "ad":
|
||||
avatarDataResponse(data);
|
||||
break;
|
||||
case "ac":
|
||||
if(_avatarCreateResponse != null)
|
||||
{
|
||||
_avatarCreateResponse(data);
|
||||
}
|
||||
break;
|
||||
case "ap":
|
||||
if(_avatarPaintResponse != null)
|
||||
{
|
||||
_avatarPaintResponse(data);
|
||||
}
|
||||
break;
|
||||
case "ag":
|
||||
avatarGetResponse(data);
|
||||
break;
|
||||
case "ar":
|
||||
if(_avatarRemoveResponse != null)
|
||||
{
|
||||
_avatarRemoveResponse(data);
|
||||
}
|
||||
break;
|
||||
case "al":
|
||||
avatarListResponse(data);
|
||||
break;
|
||||
case "ab":
|
||||
avatarBuyResponse(data);
|
||||
break;
|
||||
case "as":
|
||||
avatarSwitchResponse(data);
|
||||
break;
|
||||
case "aa":
|
||||
avatarAddResponse(data);
|
||||
break;
|
||||
case "ak":
|
||||
avatarKillResponse(data);
|
||||
break;
|
||||
case "am":
|
||||
_handleCreateAvatarData(data);
|
||||
break;
|
||||
case "ao":
|
||||
avatarOrdainResponse(data);
|
||||
break;
|
||||
case "apb":
|
||||
case "apc":
|
||||
if(_photoTakeCallback != null)
|
||||
{
|
||||
_photoTakeCallback(data);
|
||||
_photoTakeCallback = null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error("AvatarXtCommManager illegal data:" + data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarInfoResponse(df:DefPacksDefHelper) : void
|
||||
{
|
||||
var numTypes:int = 0;
|
||||
var currObj:Object = null;
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_AVATAR] = null;
|
||||
var data:Object = df.def;
|
||||
var avtDefs:Object = new Object();
|
||||
var avtOffsets:Array = [];
|
||||
for each(currObj in data)
|
||||
{
|
||||
avtOffsets[int(currObj.id)] = new Point(currObj.x,currObj.y);
|
||||
avtDefs[int(currObj.id)] = {
|
||||
"colorLayer1":uint(currObj.colorLayer1),
|
||||
"colorLayer2":uint(currObj.colorLayer2),
|
||||
"colorLayer3":uint(currObj.colorLayer3),
|
||||
"defPattern":int(currObj.basePatternId),
|
||||
"defEyes":int(currObj.baseEyesId),
|
||||
"isMemOnly":Boolean(currObj.membersOnly == "1"),
|
||||
"enviroTypeFlag":int(currObj.enviroTypeFlags),
|
||||
"cost":int(currObj.cost),
|
||||
"titleStrRef":int(currObj.titleStrRef),
|
||||
"availability":int(currObj.availability),
|
||||
"attackItemRefId":int(currObj.attackItemRefId),
|
||||
"iconMediaId":int(currObj.iconMediaRefId),
|
||||
"status":int(currObj.status)
|
||||
};
|
||||
}
|
||||
if(!gMainFrame.userInfo.avtDefsCached)
|
||||
{
|
||||
gMainFrame.setAvatarOffsets(avtOffsets);
|
||||
gMainFrame.userInfo.setAvatarDefs(avtDefs);
|
||||
}
|
||||
var dpdh:DefPacksDefHelper = new DefPacksDefHelper();
|
||||
dpdh.init(DefPacksDefHelper.DEF_LAYER,liDefPacksResponse,null,FileServerEvent.AMF3_TYPE);
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_LAYER] = dpdh;
|
||||
}
|
||||
|
||||
private static function liDefPacksResponse(df:DefPacksDefHelper) : void
|
||||
{
|
||||
var currObj:Object = null;
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_LAYER] = null;
|
||||
var data:Object = df.def;
|
||||
var layerInfoObj:Object = {};
|
||||
for each(currObj in data)
|
||||
{
|
||||
layerInfoObj[int(currObj.id)] = int(currObj.layerId);
|
||||
}
|
||||
gMainFrame.layerInfo = layerInfoObj;
|
||||
if(_avatarInfoCallback != null)
|
||||
{
|
||||
_avatarInfoCallback();
|
||||
_avatarInfoCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarDataResponse(data:Array) : void
|
||||
{
|
||||
var isForSelf:Boolean = false;
|
||||
var attackBase:int = 0;
|
||||
var attackMax:int = 0;
|
||||
var defenseBase:int = 0;
|
||||
var defenseMax:int = 0;
|
||||
var healthBase:int = 0;
|
||||
var lBits:int = 0;
|
||||
var uBits:int = 0;
|
||||
var eBits:int = 0;
|
||||
var avatarInfo:AvatarInfo = null;
|
||||
var avInfo:AvatarInfo = null;
|
||||
var setCacheInfo:UserInfo = null;
|
||||
var avList:Array = null;
|
||||
var adri:int = 2;
|
||||
var adUserName:String = data[adri++];
|
||||
var adNameBarData:int = int(data[adri++]);
|
||||
var currEnviroType:int = int(data[adri++]);
|
||||
var userNameModerationFlag:int = int(data[adri++]);
|
||||
var adPerUserAvId:int = int(data[adri++]);
|
||||
var adType:int = int(data[adri++]);
|
||||
var adColor1:uint = uint(data[adri++]);
|
||||
var adColor2:uint = uint(data[adri++]);
|
||||
var adColor3:uint = uint(data[adri++]);
|
||||
var adAvName:String = data[adri++];
|
||||
var questLevel:int = int(data[adri++]);
|
||||
var adAvInvId:int = -1;
|
||||
var landPetInvId:int = 0;
|
||||
var oceanPetInvId:int = 0;
|
||||
var questXp:int = 0;
|
||||
var questXPPercentage:int = 0;
|
||||
var petName:String = "";
|
||||
if(adUserName == gMainFrame.userInfo.myUserName)
|
||||
{
|
||||
isForSelf = true;
|
||||
adAvInvId = int(data[adri++]);
|
||||
landPetInvId = int(data[adri++]);
|
||||
oceanPetInvId = int(data[adri++]);
|
||||
attackBase = int(data[adri++]);
|
||||
attackMax = int(data[adri++]);
|
||||
defenseBase = int(data[adri++]);
|
||||
defenseMax = int(data[adri++]);
|
||||
healthBase = int(data[adri++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
lBits = int(data[adri++]);
|
||||
uBits = int(data[adri++]);
|
||||
eBits = int(data[adri++]);
|
||||
petName = data[adri++];
|
||||
}
|
||||
var userInfo:UserInfo = gMainFrame.userInfo.getUserInfoByUserName(adUserName);
|
||||
if(Boolean(userInfo))
|
||||
{
|
||||
for each(avInfo in userInfo.avList)
|
||||
{
|
||||
if(avInfo.perUserAvId == adPerUserAvId)
|
||||
{
|
||||
avatarInfo = avInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
userInfo.nameBarData = adNameBarData;
|
||||
userInfo.userNameModeratedFlag = userNameModerationFlag;
|
||||
}
|
||||
var currPet:Object = {
|
||||
"name":petName,
|
||||
"lBits":lBits,
|
||||
"uBits":uBits,
|
||||
"eBits":eBits
|
||||
};
|
||||
currPet.defId = PetManager.getDefIdFromLBits(currPet.lBits);
|
||||
currPet.type = PetManager.petTypeForDefId(currPet.defId);
|
||||
currPet.isGround = PetManager.isGround(currPet.type);
|
||||
if(Boolean(avatarInfo))
|
||||
{
|
||||
avatarInfo.avName = adAvName;
|
||||
avatarInfo.userName = adUserName;
|
||||
avatarInfo.type = adType;
|
||||
avatarInfo.colors = [adColor1,adColor2,adColor3];
|
||||
avatarInfo.currEnviroType = currEnviroType;
|
||||
avatarInfo.questLevel = questLevel;
|
||||
avatarInfo.currPet = currPet;
|
||||
if(isForSelf)
|
||||
{
|
||||
if(adAvInvId >= 0)
|
||||
{
|
||||
avSlotInfo[avatarInfo.perUserAvId].avInvId = adAvInvId;
|
||||
}
|
||||
avatarInfo.landPetInvId = landPetInvId;
|
||||
avatarInfo.oceanPetInvId = oceanPetInvId;
|
||||
avatarInfo.questXp = questXp;
|
||||
avatarInfo.healthBase = healthBase;
|
||||
avatarInfo.attackBase = attackBase;
|
||||
avatarInfo.attackMax = attackMax;
|
||||
avatarInfo.defenseBase = defenseBase;
|
||||
avatarInfo.defenseMax = defenseMax;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
avatarInfo = new AvatarInfo();
|
||||
avatarInfo.init(adPerUserAvId,adAvName,adUserName,adType,[adColor1,adColor2,adColor3],0,currPet);
|
||||
avatarInfo.questLevel = questLevel;
|
||||
if(isForSelf)
|
||||
{
|
||||
if(adAvInvId >= 0)
|
||||
{
|
||||
avSlotInfo[avatarInfo.perUserAvId] = {
|
||||
"slotId":-1,
|
||||
"avInvId":adAvInvId
|
||||
};
|
||||
}
|
||||
avatarInfo.landPetInvId = landPetInvId;
|
||||
avatarInfo.oceanPetInvId = oceanPetInvId;
|
||||
avatarInfo.questXp = questXp;
|
||||
avatarInfo.healthBase = healthBase;
|
||||
avatarInfo.attackBase = attackBase;
|
||||
avatarInfo.attackMax = attackMax;
|
||||
avatarInfo.defenseBase = defenseBase;
|
||||
avatarInfo.defenseMax = defenseMax;
|
||||
}
|
||||
if(Boolean(userInfo))
|
||||
{
|
||||
userInfo.addAvatarToList(avatarInfo);
|
||||
userInfo.nameBarData = adNameBarData;
|
||||
userInfo.userNameModeratedFlag = userNameModerationFlag;
|
||||
}
|
||||
else
|
||||
{
|
||||
setCacheInfo = new UserInfo();
|
||||
avList = new Array();
|
||||
avList[avatarInfo.perUserAvId] = avatarInfo;
|
||||
setCacheInfo.init(adUserName,avList,avatarInfo.perUserAvId,1,userNameModerationFlag);
|
||||
setCacheInfo.nameBarData = adNameBarData;
|
||||
gMainFrame.userInfo.setUserInfoByUserName(adUserName,setCacheInfo);
|
||||
}
|
||||
}
|
||||
avatarDataResponseIntegrate([adPerUserAvId,adAvName,adUserName,adType,adColor1,adColor2,adColor3]);
|
||||
}
|
||||
|
||||
private static function avatarDataResponseIntegrate(newAvData:Array) : void
|
||||
{
|
||||
var avtNotInQueueButInRoom:Boolean = false;
|
||||
var i:int = 0;
|
||||
var userName:String = null;
|
||||
var avt:Avatar = null;
|
||||
var di:int = 0;
|
||||
var dataAvatar:Avatar = null;
|
||||
var loadDataAvatarResult:Function = null;
|
||||
if(Boolean(_adAvatarQueue) && _adAvatarQueue.length > 0)
|
||||
{
|
||||
for(i = 0; i < _adAvatarQueue.length; i++)
|
||||
{
|
||||
if(_adAvatarQueue[i].a.perUserAvId == newAvData[0])
|
||||
{
|
||||
dataAvatar = _adAvatarQueue[i].a;
|
||||
loadDataAvatarResult = _adAvatarQueue[i].c;
|
||||
_adAvatarQueue.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Boolean(_avatarsInRoom))
|
||||
{
|
||||
userName = newAvData[2];
|
||||
if(_getAvatarByUsername != null)
|
||||
{
|
||||
avt = _getAvatarByUsername(userName);
|
||||
}
|
||||
if(Boolean(avt))
|
||||
{
|
||||
dataAvatar = avt;
|
||||
avtNotInQueueButInRoom = true;
|
||||
}
|
||||
}
|
||||
if(Boolean(dataAvatar))
|
||||
{
|
||||
di = 0;
|
||||
dataAvatar.perUserAvId = newAvData[di++];
|
||||
dataAvatar.avName = newAvData[di++];
|
||||
dataAvatar.userName = newAvData[di++];
|
||||
dataAvatar.avTypeId = int(newAvData[di++]);
|
||||
dataAvatar.setColors(uint(newAvData[di++]),uint(newAvData[di++]),uint(newAvData[di++]));
|
||||
if(!avtNotInQueueButInRoom)
|
||||
{
|
||||
if(loadDataAvatarResult != null)
|
||||
{
|
||||
loadDataAvatarResult();
|
||||
loadDataAvatarResult = null;
|
||||
}
|
||||
if(_gameAvatarAdCallback != null)
|
||||
{
|
||||
_gameAvatarAdCallback(dataAvatar);
|
||||
}
|
||||
}
|
||||
_buddyCardUpdateDropDownHandler(dataAvatar.userName);
|
||||
}
|
||||
else if(loadDataAvatarResult != null)
|
||||
{
|
||||
DebugUtility.debugTrace("calling loadDataAvatarResult even though dataAvatar was null...");
|
||||
loadDataAvatarResult();
|
||||
loadDataAvatarResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarGetResponse(data:Array) : void
|
||||
{
|
||||
var accountType:int = 0;
|
||||
var isGuide:Boolean = false;
|
||||
var perUserAvId:int = 0;
|
||||
var nameBarData:int = 0;
|
||||
var avType:int = 0;
|
||||
var colors:Array = null;
|
||||
var avName:String = null;
|
||||
var eyeDefId:int = 0;
|
||||
var pattDefId:int = 0;
|
||||
var questLevel:int = 0;
|
||||
var numClothingItems:int = 0;
|
||||
var sfsUserId:int = 0;
|
||||
var userNameModeratedFlag:int = 0;
|
||||
var lBits:int = 0;
|
||||
var uBits:int = 0;
|
||||
var eBits:int = 0;
|
||||
var petName:String = null;
|
||||
var numBodyModItems:int = 0;
|
||||
var items:Array = null;
|
||||
var i:int = 0;
|
||||
var currPet:Object = null;
|
||||
var userInfo:UserInfo = null;
|
||||
var avInfo:AvatarInfo = null;
|
||||
var aItem:Item = null;
|
||||
var avList:Array = null;
|
||||
var j:int = 2;
|
||||
var userName:String = data[j++];
|
||||
var avatarGetStatus:int = int(data[j++]);
|
||||
var onlineStatus:int = avatarGetStatus == 0 ? SFClient.STATUS_OFFLINE_ACTIVE : (avatarGetStatus == 1 ? SFClient.STATUS_ONLINE : (avatarGetStatus == 2 ? SFClient.STATUS_OFFLINE_ARCHIVED : SFClient.STATUS_OFFLINE_UNKNOWN));
|
||||
if(avatarGetStatus <= 1)
|
||||
{
|
||||
accountType = int(data[j++]);
|
||||
isGuide = data[j++] == "1";
|
||||
perUserAvId = int(data[j++]);
|
||||
nameBarData = int(data[j++]);
|
||||
avType = int(data[j++]);
|
||||
colors = new Array(3);
|
||||
colors[0] = uint(data[j++]);
|
||||
colors[1] = uint(data[j++]);
|
||||
colors[2] = uint(data[j++]);
|
||||
avName = data[j++];
|
||||
eyeDefId = int(data[j++]);
|
||||
pattDefId = int(data[j++]);
|
||||
questLevel = int(data[j++]);
|
||||
numClothingItems = int(data[j++]);
|
||||
sfsUserId = int(data[j++]);
|
||||
userNameModeratedFlag = int(data[j++]);
|
||||
lBits = int(data[j++]);
|
||||
uBits = int(data[j++]);
|
||||
eBits = int(data[j++]);
|
||||
petName = data[j++];
|
||||
numBodyModItems = pattDefId > 0 ? 3 : 2;
|
||||
items = new Array(numClothingItems + numBodyModItems);
|
||||
i = 0;
|
||||
items[i++] = ItemXtCommManager.getBodyModFromDefId(1,perUserAvId,true);
|
||||
items[i++] = ItemXtCommManager.getBodyModFromDefId(eyeDefId,perUserAvId,true);
|
||||
if(pattDefId > 0)
|
||||
{
|
||||
items[i++] = ItemXtCommManager.getBodyModFromDefId(pattDefId,perUserAvId,true);
|
||||
}
|
||||
for(DebugUtility.debugTrace("avatarGetResponse userName:" + userName + " numClothingItems:" + numClothingItems + " numBodyModItems:" + numBodyModItems + " pattDefId:" + pattDefId); i < numClothingItems + numBodyModItems; )
|
||||
{
|
||||
aItem = new Item();
|
||||
aItem.init(int(data[j++]),i,uint(data[j++]));
|
||||
aItem.setInUse(perUserAvId,true);
|
||||
items[i] = aItem;
|
||||
i++;
|
||||
}
|
||||
currPet = {
|
||||
"name":petName,
|
||||
"lBits":lBits,
|
||||
"uBits":uBits,
|
||||
"eBits":eBits
|
||||
};
|
||||
currPet.defId = PetManager.getDefIdFromLBits(currPet.lBits);
|
||||
currPet.type = PetManager.petTypeForDefId(currPet.defId);
|
||||
currPet.isGround = PetManager.isGround(currPet.type);
|
||||
userInfo = gMainFrame.userInfo.getUserInfoByUserName(userName);
|
||||
avInfo = new AvatarInfo();
|
||||
avInfo.init(perUserAvId,avName,userName,avType,colors,0,currPet,0,0,0,questLevel);
|
||||
if(!userInfo)
|
||||
{
|
||||
avList = new Array(1);
|
||||
avList[perUserAvId] = avInfo;
|
||||
userInfo = new UserInfo();
|
||||
userInfo.init(userName,avList,perUserAvId,accountType);
|
||||
}
|
||||
else
|
||||
{
|
||||
userInfo.currPerUserAvId = perUserAvId;
|
||||
userInfo.accountType = accountType;
|
||||
userInfo.addAvatarToList(avInfo);
|
||||
}
|
||||
userInfo.userNameModeratedFlag = userNameModeratedFlag;
|
||||
userInfo.nameBarData = nameBarData;
|
||||
userInfo.isGuide = isGuide;
|
||||
gMainFrame.userInfo.setUserInfoByUserName(userName,userInfo);
|
||||
}
|
||||
var lcUserName:String = userName.toLowerCase();
|
||||
if(Boolean(_agQueue[lcUserName]))
|
||||
{
|
||||
_agQueue[lcUserName](userName,avatarGetStatus < 3,onlineStatus);
|
||||
delete _agQueue[lcUserName];
|
||||
}
|
||||
if(Boolean(_agsQueue[sfsUserId]))
|
||||
{
|
||||
_agsQueue[sfsUserId](userName,avatarGetStatus < 3,onlineStatus,sfsUserId);
|
||||
delete _agsQueue[sfsUserId];
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarListResponse(data:Array) : void
|
||||
{
|
||||
var isForSelf:Boolean = false;
|
||||
var userName:String = null;
|
||||
var numAvNames:int = 0;
|
||||
var avList:Array = null;
|
||||
var currPerUserAvId:int = 0;
|
||||
var userInfo:UserInfo = null;
|
||||
var j:int = 0;
|
||||
var setUserInfo:UserInfo = null;
|
||||
var perUserAvId:int = 0;
|
||||
var avSlotIdx:int = 0;
|
||||
var avName:String = null;
|
||||
var avInfo:AvatarInfo = null;
|
||||
var al:int = 2;
|
||||
var numUserNames:int = int(data[al++]);
|
||||
var slotsAvailFlags:int = -1;
|
||||
for(var i:int = 0; i < numUserNames; i++)
|
||||
{
|
||||
userName = data[al++];
|
||||
if(userName == gMainFrame.server.userName)
|
||||
{
|
||||
isForSelf = true;
|
||||
slotsAvailFlags = int(data[al++]);
|
||||
}
|
||||
numAvNames = int(data[al++]);
|
||||
avList = [];
|
||||
userInfo = gMainFrame.userInfo.getUserInfoByUserName(userName);
|
||||
for(j = 0; j < numAvNames; j++)
|
||||
{
|
||||
perUserAvId = int(data[al++]);
|
||||
if(j == 0)
|
||||
{
|
||||
currPerUserAvId = perUserAvId;
|
||||
}
|
||||
avSlotIdx = int(data[al++]);
|
||||
avName = data[al++];
|
||||
if(Boolean(userInfo))
|
||||
{
|
||||
avInfo = userInfo.getAvatarInfoByPerUserAvId(perUserAvId);
|
||||
if(!avInfo)
|
||||
{
|
||||
avInfo = new AvatarInfo();
|
||||
avInfo.init(perUserAvId,avName,userName);
|
||||
}
|
||||
avList[perUserAvId] = avInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
avInfo = new AvatarInfo();
|
||||
avInfo.init(perUserAvId,avName,userName);
|
||||
avList[perUserAvId] = avInfo;
|
||||
}
|
||||
if(isForSelf)
|
||||
{
|
||||
avSlotInfo[perUserAvId] = {
|
||||
"slotId":j,
|
||||
"avInvId":avSlotIdx
|
||||
};
|
||||
}
|
||||
}
|
||||
setUserInfo = new UserInfo();
|
||||
if(Boolean(userInfo))
|
||||
{
|
||||
userInfo.avList = avList;
|
||||
userInfo.currPerUserAvId = currPerUserAvId;
|
||||
setUserInfo = userInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
setUserInfo.init(userName,avList,currPerUserAvId);
|
||||
}
|
||||
gMainFrame.userInfo.setUserInfoByUserName(userName,setUserInfo);
|
||||
}
|
||||
if(userName != gMainFrame.server.userName)
|
||||
{
|
||||
if(_avatarListResponse != null)
|
||||
{
|
||||
_avatarListResponse();
|
||||
}
|
||||
}
|
||||
if(_alCallback != null)
|
||||
{
|
||||
if(slotsAvailFlags >= 0)
|
||||
{
|
||||
_alCallback(slotsAvailFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
_alCallback(numUserNames == -1);
|
||||
}
|
||||
_alCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarBuyResponse(data:Array) : void
|
||||
{
|
||||
if(_abCallback != null)
|
||||
{
|
||||
_abCallback(Boolean(int(data[2])));
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarSwitchResponse(data:Array) : void
|
||||
{
|
||||
if(_asCallback != null)
|
||||
{
|
||||
_asCallback(data);
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarAddResponse(data:Array) : void
|
||||
{
|
||||
if(_aaCallback != null)
|
||||
{
|
||||
_aaCallback(int(data[2]),int(data[3]),int(data[4]));
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarKillResponse(data:Array) : void
|
||||
{
|
||||
if(_akCallback != null)
|
||||
{
|
||||
_akCallback(Boolean(int(data[2])),int(data[3]));
|
||||
}
|
||||
}
|
||||
|
||||
private static function avatarOrdainResponse(data:Array) : void
|
||||
{
|
||||
if(_aoCallback != null)
|
||||
{
|
||||
_aoCallback(Boolean(int(data[2])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package avatar
|
||||
{
|
||||
import flash.display.MovieClip;
|
||||
|
||||
public interface INewAvatar
|
||||
{
|
||||
|
||||
function screenInitCallback(param1:MovieClip) : void;
|
||||
|
||||
function get playSound() : Boolean;
|
||||
|
||||
function newAvatarData(param1:int, param2:String, param3:Array, param4:Function, param5:Boolean = false) : void;
|
||||
|
||||
function hideConnectingMsg() : void;
|
||||
|
||||
function logInForCreateAvatarData() : void;
|
||||
|
||||
function nameTypeScreenDone() : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,869 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.graphics.LayerAnim;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import flash.filters.GlowFilter;
|
||||
import flash.geom.Point;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
import gskinner.motion.GTween;
|
||||
import gskinner.motion.easing.Linear;
|
||||
import item.Item;
|
||||
import item.ItemXtCommManager;
|
||||
import loader.MediaHelper;
|
||||
import localization.LocalizationManager;
|
||||
import quest.QuestManager;
|
||||
import room.RoomManagerWorld;
|
||||
|
||||
public class NPCView extends Sprite
|
||||
{
|
||||
|
||||
public static const NPC_STATE_LOADING:int = -2;
|
||||
|
||||
public static const NPC_STATE_LOADED:int = -1;
|
||||
|
||||
public static const NPC_STATE_IDLE:int = 0;
|
||||
|
||||
public static const NPC_STATE_MOVE:int = 1;
|
||||
|
||||
public static const NPC_STATE_ATTACK:int = 2;
|
||||
|
||||
public static const NPC_STATE_RECOIL:int = 3;
|
||||
|
||||
public static const NPC_STATE_DEATH:int = 4;
|
||||
|
||||
public static const NPC_STATE_TREASURE_APPEAR:int = 5;
|
||||
|
||||
public static const NPC_STATE_TREASURE_OPEN:int = 6;
|
||||
|
||||
public static const NPC_STATE_TREASURE_DISAPPEAR:int = 7;
|
||||
|
||||
public static const NPC_STATE_DANCE:int = 8;
|
||||
|
||||
private var _npcDef:Object;
|
||||
|
||||
private var _npcMC:MovieClip;
|
||||
|
||||
private var _npcAvatarView:AvatarWorldView;
|
||||
|
||||
private var _playerId:int;
|
||||
|
||||
private var _namebar:NameBar;
|
||||
|
||||
private var _mediaHelperObj:MediaHelper;
|
||||
|
||||
private var _onLoadingCompleteCallback:Function;
|
||||
|
||||
private var _npcState:int;
|
||||
|
||||
private var _npcAngle:int;
|
||||
|
||||
private var _healthBar:MovieClip;
|
||||
|
||||
private var _hitText:TextField;
|
||||
|
||||
private var _hitTextTween:GTween;
|
||||
|
||||
private var _secondaryNpcMC:MovieClip;
|
||||
|
||||
public var _eye:MovieClip;
|
||||
|
||||
public var _beam:MovieClip;
|
||||
|
||||
public var _npcFacingSW:Boolean;
|
||||
|
||||
public function NPCView()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get npcState() : int
|
||||
{
|
||||
return this._npcState;
|
||||
}
|
||||
|
||||
public function get npcStateComplete() : Boolean
|
||||
{
|
||||
switch(this._npcState)
|
||||
{
|
||||
case NPC_STATE_LOADING:
|
||||
return false;
|
||||
case NPC_STATE_LOADED:
|
||||
return true;
|
||||
case NPC_STATE_TREASURE_APPEAR:
|
||||
case NPC_STATE_TREASURE_OPEN:
|
||||
case NPC_STATE_TREASURE_DISAPPEAR:
|
||||
return this._npcMC == null || Boolean(this._npcMC.finished);
|
||||
default:
|
||||
throw new Error("NPVView: npcStateComplete: Unsupported state");
|
||||
}
|
||||
}
|
||||
|
||||
public function get readyToLaunchAttack() : Boolean
|
||||
{
|
||||
if(this._npcState == NPC_STATE_ATTACK)
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
if(this._npcMC.attacking == true)
|
||||
{
|
||||
this._npcMC.attacking = false;
|
||||
return true;
|
||||
}
|
||||
if(this._npcMC.hasOwnProperty("counterAttacking") && this._npcMC.counterAttacking == true)
|
||||
{
|
||||
this._npcMC.counterAttacking = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get readyToAttack() : Boolean
|
||||
{
|
||||
var customCollisionPoints:Array = null;
|
||||
var colPointIndex:int = 0;
|
||||
var colPoint:Object = null;
|
||||
if(this._npcMC != null && this._npcMC.hasOwnProperty("getCustomCollisionPoints"))
|
||||
{
|
||||
customCollisionPoints = this._npcMC.getCustomCollisionPoints();
|
||||
if(customCollisionPoints != null)
|
||||
{
|
||||
for(colPointIndex = 0; colPointIndex < customCollisionPoints.length; colPointIndex++)
|
||||
{
|
||||
colPoint = customCollisionPoints[colPointIndex];
|
||||
if(colPoint.Type == 2)
|
||||
{
|
||||
return !this._npcMC.animActive && Boolean(this._npcMC.readyForAttack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this._npcState != NPC_STATE_ATTACK && this._npcState != NPC_STATE_DEATH)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get isDead() : Boolean
|
||||
{
|
||||
if(this._npcState == NPC_STATE_DEATH && (this._npcMC == null || this._npcMC.animActive == false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get isDying() : Boolean
|
||||
{
|
||||
return this._npcState == NPC_STATE_DEATH;
|
||||
}
|
||||
|
||||
public function moveFaceAnim(inAngle:Number) : void
|
||||
{
|
||||
var animDir:int = 0;
|
||||
var animFlip:Boolean = false;
|
||||
if(Boolean(this._npcAvatarView))
|
||||
{
|
||||
animDir = 0;
|
||||
for(animFlip = false; inAngle < 0; )
|
||||
{
|
||||
inAngle += 360;
|
||||
}
|
||||
while(inAngle >= 360)
|
||||
{
|
||||
inAngle -= 360;
|
||||
}
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
if(inAngle < 180)
|
||||
{
|
||||
if(inAngle < 35)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_NNE;
|
||||
}
|
||||
else if(inAngle < 70)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_NE;
|
||||
}
|
||||
else if(inAngle < 110)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_E;
|
||||
}
|
||||
else if(inAngle < 145)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_SE;
|
||||
}
|
||||
else
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_SSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
animFlip = true;
|
||||
if(inAngle < 215)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_SSE;
|
||||
}
|
||||
else if(inAngle < 250)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_SE;
|
||||
}
|
||||
else if(inAngle < 290)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_E;
|
||||
}
|
||||
else if(inAngle < 325)
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_NE;
|
||||
}
|
||||
else
|
||||
{
|
||||
animDir = LayerAnim.AN_MOVE_NNE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
if(inAngle < 180)
|
||||
{
|
||||
animDir = LayerAnim.AN_SWIM_E;
|
||||
}
|
||||
else
|
||||
{
|
||||
animFlip = true;
|
||||
animDir = LayerAnim.AN_SWIM_E;
|
||||
}
|
||||
}
|
||||
this._npcAvatarView.playAnim(animDir,animFlip,LayerAnim.PLAY_LOOP__KEEP_CURRENT_FRAME);
|
||||
}
|
||||
}
|
||||
|
||||
public function setNpcState(inState:int, inAngle:Number = 0) : void
|
||||
{
|
||||
if(this._npcState != NPC_STATE_DEATH)
|
||||
{
|
||||
switch(inState)
|
||||
{
|
||||
case NPC_STATE_TREASURE_APPEAR:
|
||||
if(Boolean(this._npcMC))
|
||||
{
|
||||
this._npcMC.appear();
|
||||
this._npcState = inState;
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_TREASURE_OPEN:
|
||||
if(Boolean(this._npcMC))
|
||||
{
|
||||
this._npcMC.openChest();
|
||||
this._npcState = inState;
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_TREASURE_DISAPPEAR:
|
||||
if(Boolean(this._npcMC))
|
||||
{
|
||||
this._npcMC.disappear();
|
||||
this._npcState = inState;
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_DEATH:
|
||||
if(Boolean(this._npcMC))
|
||||
{
|
||||
this._npcState = inState;
|
||||
this._npcMC.noHealth();
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_IDLE:
|
||||
if(Boolean(this._npcMC))
|
||||
{
|
||||
if(this._npcMC.animActive == false)
|
||||
{
|
||||
this._npcState = inState;
|
||||
this._npcMC.idle(270);
|
||||
}
|
||||
if(this._npcMC.hasOwnProperty("getSortHeight"))
|
||||
{
|
||||
if(Boolean(this._npcMC.parent.parent))
|
||||
{
|
||||
this._npcMC.parent.parent.name = this._npcMC.getSortHeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Boolean(this._npcAvatarView))
|
||||
{
|
||||
if(this._npcState != inState)
|
||||
{
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_IDLE_SE,false,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_FLOAT,false,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
this._npcState = inState;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_MOVE:
|
||||
if(this._npcAvatarView != null)
|
||||
{
|
||||
this._npcState = inState;
|
||||
if(this._npcAngle != inAngle)
|
||||
{
|
||||
this._npcAngle = inAngle;
|
||||
this.moveFaceAnim(this._npcAngle);
|
||||
}
|
||||
}
|
||||
else if(this._npcMC != null)
|
||||
{
|
||||
this._npcAngle = inAngle;
|
||||
if(this._npcMC.animActive == false)
|
||||
{
|
||||
this._npcState = inState;
|
||||
this._npcMC.moveCycle(this._npcAngle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_ATTACK:
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
this._npcState = inState;
|
||||
this._npcAngle = inAngle;
|
||||
this._npcMC.attack(this._npcAngle);
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_RECOIL:
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
if(this._npcState != NPC_STATE_RECOIL || this._npcMC.hasOwnProperty("animActive") == false || this._npcMC.animActive == false)
|
||||
{
|
||||
if(this._npcState == NPC_STATE_IDLE || this._npcState == NPC_STATE_MOVE)
|
||||
{
|
||||
this._npcState = inState;
|
||||
}
|
||||
this._npcMC.recoil(this._npcAngle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NPC_STATE_DANCE:
|
||||
if(this._npcAvatarView != null)
|
||||
{
|
||||
this._npcState = inState;
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_DANCE,false,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_WATER_JIG,false,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get collisionZapRadius() : Number
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
return this._npcMC.getCollisionRadius(0);
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
|
||||
public function get collisionRadiusMoving() : Number
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
if("getCollisionRadius" in this._npcMC)
|
||||
{
|
||||
return this._npcMC.getCollisionRadius(1);
|
||||
}
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
|
||||
public function get collisionRadiusAttack() : Number
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
if("getCollisionRadius" in this._npcMC)
|
||||
{
|
||||
return this._npcMC.getCollisionRadius(2);
|
||||
}
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
|
||||
public function get collisionMovingPoint() : Point
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
if("getCollisionPoint" in this._npcMC)
|
||||
{
|
||||
return this._npcMC.getCollisionPoint(1);
|
||||
}
|
||||
}
|
||||
return new Point(0,0);
|
||||
}
|
||||
|
||||
public function get collisionZapPoint() : Point
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
if("getCollisionPoint" in this._npcMC)
|
||||
{
|
||||
return this._npcMC.getCollisionPoint(2);
|
||||
}
|
||||
}
|
||||
return new Point(0,0);
|
||||
}
|
||||
|
||||
public function get collisionPointAttack() : Point
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
if("getCollisionPoint" in this._npcMC)
|
||||
{
|
||||
return this._npcMC.getCollisionPoint(0);
|
||||
}
|
||||
}
|
||||
return new Point(0,0);
|
||||
}
|
||||
|
||||
public function get avatar() : Avatar
|
||||
{
|
||||
if(this._npcAvatarView != null)
|
||||
{
|
||||
return this._npcAvatarView.avatarData;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get talkingHeadMediaId() : int
|
||||
{
|
||||
if(this._npcDef != null)
|
||||
{
|
||||
return this._npcDef.headMediaRefId;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function reset() : void
|
||||
{
|
||||
this._npcState = NPC_STATE_LOADING;
|
||||
}
|
||||
|
||||
public function init(npcDefId:int, playerId:int, namebarStrId:int = -1, hasHealthBar:Boolean = false, onLoadingCompleteCallback:Function = null) : void
|
||||
{
|
||||
var avt:Avatar = null;
|
||||
var itemsToUse:Array = null;
|
||||
var i:int = 0;
|
||||
var aiItem:Item = null;
|
||||
var index:int = 0;
|
||||
var colors:Array = null;
|
||||
var loadSelfAnims:Array = null;
|
||||
var text:String = null;
|
||||
this._npcFacingSW = false;
|
||||
this._npcState = NPC_STATE_LOADING;
|
||||
this._npcAngle = 0;
|
||||
this._npcDef = QuestManager.getNPCDef(npcDefId);
|
||||
this._playerId = playerId;
|
||||
this._onLoadingCompleteCallback = onLoadingCompleteCallback;
|
||||
this._hitText = new TextField();
|
||||
this._hitText.selectable = false;
|
||||
this._hitText.multiline = false;
|
||||
this._hitText.autoSize = TextFieldAutoSize.CENTER;
|
||||
this._hitText.visible = false;
|
||||
this._hitText.embedFonts = true;
|
||||
this._hitText.defaultTextFormat = new TextFormat("TikiIsland-Regular",36,4286945);
|
||||
this._hitText.filters = [new GlowFilter(0,1,3,3,10,2)];
|
||||
switch(this._npcDef.type)
|
||||
{
|
||||
case 0:
|
||||
this._mediaHelperObj = new MediaHelper();
|
||||
this._mediaHelperObj.init(this._npcDef.mediaRefId,this.onMediaLoaded);
|
||||
break;
|
||||
case 1:
|
||||
avt = new Avatar();
|
||||
avt.avName = "";
|
||||
avt.userName = "";
|
||||
this._npcAvatarView = new AvatarWorldView();
|
||||
this._npcAvatarView.initWorldView(avt,QuestManager._layerManager.room_chat,Utility.NON_MEMBER,true);
|
||||
avt.init(-1,avt.avName,this._npcDef.avatarRefId,[this._npcDef.baseColor,this._npcDef.patternColor,this._npcDef.eyesColor]);
|
||||
avt.itemResponseIntegrate(ItemXtCommManager.generateBodyModList(this._npcDef.avatarRefId,this._npcDef.patternItemRefId,this._npcDef.eyesItemRefId,false));
|
||||
if(namebarStrId > 0)
|
||||
{
|
||||
if(this._npcAvatarView != null && this._npcAvatarView.avatarData != null)
|
||||
{
|
||||
text = LocalizationManager.translateIdOnly(namebarStrId);
|
||||
this._npcAvatarView.avatarData.avName = text;
|
||||
this._npcAvatarView.avatarData.userName = text;
|
||||
if(this._npcAvatarView.nameBar != null)
|
||||
{
|
||||
this._npcAvatarView.nameBar.setAvName(text);
|
||||
this._npcAvatarView.nameBar.visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
itemsToUse = new Array();
|
||||
index = 100;
|
||||
for(i = 0; i < this._npcAvatarView.avatarData.inventoryBodyMod.itemArray.length; i++)
|
||||
{
|
||||
itemsToUse.push(this._npcAvatarView.avatarData.inventoryBodyMod.itemArray[i]);
|
||||
}
|
||||
if(this._npcDef.backItemRefId != 0)
|
||||
{
|
||||
aiItem = new Item();
|
||||
colors = ItemXtCommManager.getItemDef(this._npcDef.backItemRefId).colors;
|
||||
aiItem.init(this._npcDef.backItemRefId,index++,colors[Math.min(this._npcDef.backColor,colors.length - 1)],-1,-1);
|
||||
itemsToUse.push(aiItem);
|
||||
}
|
||||
if(this._npcDef.headItemRefId != 0)
|
||||
{
|
||||
aiItem = new Item();
|
||||
colors = ItemXtCommManager.getItemDef(this._npcDef.headItemRefId).colors;
|
||||
aiItem.init(this._npcDef.headItemRefId,index++,colors[Math.min(this._npcDef.headColor,colors.length - 1)],-1,-1);
|
||||
itemsToUse.push(aiItem);
|
||||
}
|
||||
if(this._npcDef.legItemRefId != 0)
|
||||
{
|
||||
aiItem = new Item();
|
||||
colors = ItemXtCommManager.getItemDef(this._npcDef.legItemRefId).colors;
|
||||
aiItem.init(this._npcDef.legItemRefId,index++,colors[Math.min(this._npcDef.legColor,colors.length - 1)],-1,-1);
|
||||
itemsToUse.push(aiItem);
|
||||
}
|
||||
if(this._npcDef.neckItemRefId != 0)
|
||||
{
|
||||
aiItem = new Item();
|
||||
colors = ItemXtCommManager.getItemDef(this._npcDef.neckItemRefId).colors;
|
||||
aiItem.init(this._npcDef.neckItemRefId,index++,colors[Math.min(this._npcDef.neckColor,colors.length - 1)],-1,-1);
|
||||
itemsToUse.push(aiItem);
|
||||
}
|
||||
if(this._npcDef.tailItemRefId != 0)
|
||||
{
|
||||
aiItem = new Item();
|
||||
colors = ItemXtCommManager.getItemDef(this._npcDef.tailItemRefId).colors;
|
||||
aiItem.init(this._npcDef.tailItemRefId,index++,colors[Math.min(this._npcDef.tailColor,colors.length - 1)],-1,-1);
|
||||
itemsToUse.push(aiItem);
|
||||
}
|
||||
this._npcAvatarView.avatarData.itemResponseIntegrate(itemsToUse);
|
||||
loadSelfAnims = new Array(15);
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
loadSelfAnims[0] = LayerAnim.AN_IDLE_SE;
|
||||
loadSelfAnims[1] = LayerAnim.AN_MOVE_NNE;
|
||||
loadSelfAnims[2] = LayerAnim.AN_MOVE_NE;
|
||||
loadSelfAnims[3] = LayerAnim.AN_MOVE_E;
|
||||
loadSelfAnims[4] = LayerAnim.AN_MOVE_SE;
|
||||
loadSelfAnims[5] = LayerAnim.AN_MOVE_SSE;
|
||||
loadSelfAnims[6] = LayerAnim.AN_DANCE;
|
||||
loadSelfAnims[7] = LayerAnim.AN_SLEEP;
|
||||
loadSelfAnims[8] = LayerAnim.AN_HOP;
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
loadSelfAnims[0] = LayerAnim.AN_FLOAT;
|
||||
loadSelfAnims[1] = LayerAnim.AN_SWIM_E;
|
||||
loadSelfAnims[2] = LayerAnim.AN_WATER_DIVE;
|
||||
loadSelfAnims[3] = LayerAnim.AN_WATER_PLAY;
|
||||
loadSelfAnims[4] = LayerAnim.AN_WATER_SPIN;
|
||||
loadSelfAnims[5] = LayerAnim.AN_WATER_JIG;
|
||||
loadSelfAnims[6] = LayerAnim.AN_WATER_POSE;
|
||||
}
|
||||
this._npcAvatarView.preloadAnims(loadSelfAnims,this.redrawCallback);
|
||||
}
|
||||
if(hasHealthBar)
|
||||
{
|
||||
this._healthBar = GETDEFINITIONBYNAME("NPCHealth");
|
||||
this._healthBar.x = -this._healthBar.width * 0.5;
|
||||
this._healthBar.y = 18;
|
||||
this._healthBar.hpBar.width = this._healthBar.hpEnemyBarContainer.width;
|
||||
addChild(this._healthBar);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
if(Boolean(this._mediaHelperObj))
|
||||
{
|
||||
this._mediaHelperObj.destroy();
|
||||
this._mediaHelperObj = null;
|
||||
}
|
||||
if(Boolean(this._npcMC))
|
||||
{
|
||||
if(this._npcMC.hasOwnProperty("destroyPhantomNPC"))
|
||||
{
|
||||
this._npcMC.destroyPhantomNPC();
|
||||
}
|
||||
if(this._npcMC.parent != null)
|
||||
{
|
||||
this._npcMC.parent.removeChild(this._npcMC);
|
||||
}
|
||||
}
|
||||
if(Boolean(this._secondaryNpcMC) && Boolean(this._secondaryNpcMC.parent != null) && this._secondaryNpcMC.parent is MovieClip)
|
||||
{
|
||||
this._secondaryNpcMC.parent.removeChild(this._secondaryNpcMC);
|
||||
}
|
||||
if(Boolean(this._namebar))
|
||||
{
|
||||
this._namebar.destroy();
|
||||
this._namebar = null;
|
||||
}
|
||||
if(Boolean(this._healthBar))
|
||||
{
|
||||
this._healthBar = null;
|
||||
}
|
||||
if(Boolean(this._npcAvatarView))
|
||||
{
|
||||
if(this._npcAvatarView.parent != null)
|
||||
{
|
||||
this._npcAvatarView.parent.removeChild(this._npcAvatarView);
|
||||
}
|
||||
this._npcAvatarView.destroy(true);
|
||||
}
|
||||
this._hitTextTween = null;
|
||||
}
|
||||
|
||||
public function updateHealthBar(healthPercent:int, damageAmount:int, criticalHit:Boolean, displayText:Boolean) : void
|
||||
{
|
||||
var text:String = null;
|
||||
if(Boolean(this._healthBar))
|
||||
{
|
||||
if(healthPercent == 0)
|
||||
{
|
||||
this._healthBar.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._healthBar.hpBar.width = this._healthBar.hpEnemyBarContainer.width * (healthPercent / 100);
|
||||
}
|
||||
}
|
||||
if(displayText)
|
||||
{
|
||||
if(damageAmount > 0 && Boolean(this._npcMC))
|
||||
{
|
||||
if(criticalHit)
|
||||
{
|
||||
text = "Fierce!\n" + Math.abs(damageAmount) * -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
text = String(Math.abs(damageAmount) * -1);
|
||||
}
|
||||
this.playHitText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function playHitText(hitString:String) : void
|
||||
{
|
||||
var attachmentPoint:Point = null;
|
||||
this._hitText.visible = true;
|
||||
this._hitText.alpha = 2;
|
||||
this._hitText.text = hitString;
|
||||
try
|
||||
{
|
||||
attachmentPoint = this._npcMC.getAttachmentPoint();
|
||||
this._hitText.x = attachmentPoint.x + this.x - this._hitText.textWidth * 0.5;
|
||||
this._hitText.y = attachmentPoint.y + this.y;
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
_hitText.x = this.x - _hitText.textWidth * 0.5;
|
||||
_hitText.y = this.y - _hitText.textHeight;
|
||||
}
|
||||
if(parent != null)
|
||||
{
|
||||
this._hitText.x += parent.x;
|
||||
this._hitText.y += parent.y;
|
||||
}
|
||||
if(Boolean(this._hitTextTween))
|
||||
{
|
||||
this._hitTextTween.resetValues({
|
||||
"y":this._hitText.y - 90,
|
||||
"alpha":0
|
||||
});
|
||||
this._hitTextTween.beginning();
|
||||
this._hitTextTween.paused = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._hitTextTween = new GTween(this._hitText,1,{
|
||||
"y":this._hitText.y - 90,
|
||||
"alpha":0
|
||||
},{"ease":Linear.easeNone});
|
||||
}
|
||||
}
|
||||
|
||||
public function playAnimationState(anim:int, bFlip:Boolean, loopMode:int, callback:Function) : void
|
||||
{
|
||||
if(Boolean(this._npcAvatarView))
|
||||
{
|
||||
this._npcAvatarView.playAnim(anim,bFlip,loopMode,callback);
|
||||
}
|
||||
}
|
||||
|
||||
public function get npcMC() : MovieClip
|
||||
{
|
||||
return this._npcMC;
|
||||
}
|
||||
|
||||
public function get defId() : int
|
||||
{
|
||||
return this._npcDef.defId;
|
||||
}
|
||||
|
||||
public function get npcDef() : Object
|
||||
{
|
||||
return this._npcDef;
|
||||
}
|
||||
|
||||
public function get secondaryNpcMC() : MovieClip
|
||||
{
|
||||
return this._secondaryNpcMC;
|
||||
}
|
||||
|
||||
private function onMediaLoaded(img:MovieClip) : void
|
||||
{
|
||||
this._npcMC = img;
|
||||
addChild(this._npcMC);
|
||||
if(this._npcMC.hasOwnProperty("eye"))
|
||||
{
|
||||
this._eye = this._npcMC.eye;
|
||||
}
|
||||
if(this._npcDef.headMediaRefId != 0)
|
||||
{
|
||||
this._mediaHelperObj = new MediaHelper();
|
||||
this._mediaHelperObj.init(this._npcDef.headMediaRefId,this.secondaryNPCLoaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.loadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private function secondaryNPCLoaded(img:MovieClip) : void
|
||||
{
|
||||
if(img.getChildAt(0) is MovieClip)
|
||||
{
|
||||
this._secondaryNpcMC = MovieClip(img.getChildAt(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
this._secondaryNpcMC = img;
|
||||
}
|
||||
this._mediaHelperObj.destroy();
|
||||
this._mediaHelperObj = null;
|
||||
this.loadingComplete();
|
||||
}
|
||||
|
||||
private function redrawCallback(layerAnim:LayerAnim) : void
|
||||
{
|
||||
if(Boolean(layerAnim) && Boolean(this._npcAvatarView))
|
||||
{
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_IDLE_SE,false,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_FLOAT,false,LayerAnim.AN_FLOAT,null);
|
||||
}
|
||||
addChild(this._npcAvatarView);
|
||||
this.loadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadingComplete() : void
|
||||
{
|
||||
this._npcState = NPC_STATE_LOADED;
|
||||
if(this._npcMC != null && this._npcMC.hasOwnProperty("setInit"))
|
||||
{
|
||||
this._npcMC.setInit(QuestManager._questDifficultyLevel);
|
||||
if(this._npcMC.hasOwnProperty("watcher"))
|
||||
{
|
||||
this._beam = this._npcMC.watcher;
|
||||
}
|
||||
}
|
||||
QuestManager._layerManager.room_chat.addChild(this._hitText);
|
||||
if(this._onLoadingCompleteCallback != null)
|
||||
{
|
||||
this._onLoadingCompleteCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public function setSwfState(swfStateName:String) : Number
|
||||
{
|
||||
if(this._npcMC != null)
|
||||
{
|
||||
return this._npcMC.setStateByScript(swfStateName);
|
||||
}
|
||||
if(this._npcAvatarView != null)
|
||||
{
|
||||
if(swfStateName == "dance")
|
||||
{
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_DANCE,this._npcFacingSW,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_WATER_JIG,this._npcFacingSW,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
}
|
||||
else if(swfStateName == "hop")
|
||||
{
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_HOP,this._npcFacingSW,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_WATER_DIVE,this._npcFacingSW,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
}
|
||||
else if(swfStateName == "spin")
|
||||
{
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_WATER_SPIN,this._npcFacingSW,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
}
|
||||
else if(swfStateName == "idle" || swfStateName == "facese")
|
||||
{
|
||||
this._npcFacingSW = false;
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_IDLE_SE,false,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_FLOAT,false,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
}
|
||||
else if(swfStateName == "facesw")
|
||||
{
|
||||
this._npcFacingSW = true;
|
||||
if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_LAND)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_IDLE_SE,true,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
else if(RoomManagerWorld.instance.roomEnviroType == Utility.ENVIRO_OCEAN)
|
||||
{
|
||||
this.playAnimationState(LayerAnim.AN_FLOAT,true,LayerAnim.PLAY_LOOP,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,743 @@
|
||||
package avatar
|
||||
{
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.Event;
|
||||
import flash.events.MouseEvent;
|
||||
import loader.MediaHelper;
|
||||
|
||||
public class NameBar extends MovieClip
|
||||
{
|
||||
|
||||
private static var _getNamebarIconsFunc:Function;
|
||||
|
||||
public static var NON_BUDDY:String = "nonBuddy";
|
||||
|
||||
public static var BUDDY:String = "buddy";
|
||||
|
||||
public static var GUIDE:String = "guide";
|
||||
|
||||
public static const LEVEL_SHAPES:Array = new Array(1851,1858,1853,1857);
|
||||
|
||||
public static const MAX_COLORS:int = 10;
|
||||
|
||||
private static var BADGE_ID_VIP_CAMERA:int = 31;
|
||||
|
||||
private var _iconIdsArray:Array;
|
||||
|
||||
private var _isBlocked:Boolean;
|
||||
|
||||
private var _nubType:String;
|
||||
|
||||
private var _left:MovieClip;
|
||||
|
||||
private var _mid:MovieClip;
|
||||
|
||||
private var _right:MovieClip;
|
||||
|
||||
private var _avName:MovieClip;
|
||||
|
||||
private var _meter:MovieClip;
|
||||
|
||||
private var _shape:MovieClip;
|
||||
|
||||
private var _iconsMediaHelperArray:Array;
|
||||
|
||||
private var _iconImages:Array;
|
||||
|
||||
private var _nubDataArray:Array;
|
||||
|
||||
private var _nameBarDataToBeLoaded:int;
|
||||
|
||||
private var _currframeName:String;
|
||||
|
||||
private var _packedNameBarData:int;
|
||||
|
||||
private var _badgeId:int;
|
||||
|
||||
private var _levelShapeHelper:MediaHelper;
|
||||
|
||||
private var _shapesMediaHelperArray:Array;
|
||||
|
||||
private var _currShapeMouse:MovieClip;
|
||||
|
||||
private var _currShapeUp:MovieClip;
|
||||
|
||||
private var _isMember:Boolean;
|
||||
|
||||
public function NameBar(initNubType:String = "nonBuddy", initIsBlocked:Boolean = false)
|
||||
{
|
||||
super();
|
||||
if(Boolean(this["e"].currentFrameLabel))
|
||||
{
|
||||
this._left = this["e"][String(this["e"].currentFrameLabel)];
|
||||
}
|
||||
else
|
||||
{
|
||||
this._left = this["e"];
|
||||
}
|
||||
if(Boolean(this["n"].currentFrameLabel))
|
||||
{
|
||||
this._mid = this["n"][String(this["n"].currentFrameLabel)];
|
||||
}
|
||||
else
|
||||
{
|
||||
this._mid = this["n"];
|
||||
}
|
||||
if(this["meter"] != null)
|
||||
{
|
||||
if(Boolean(this["meter"].currentFrameLabel))
|
||||
{
|
||||
this._meter = this["meter"][String(this["meter"].currentFrameLabel)];
|
||||
}
|
||||
else
|
||||
{
|
||||
this._meter = this["meter"];
|
||||
}
|
||||
}
|
||||
if(this["shape"] != null)
|
||||
{
|
||||
if(Boolean(this["shape"].currentFrameLabel))
|
||||
{
|
||||
this._shape = this["shape"][String(this["shape"].currentFrameLabel)];
|
||||
}
|
||||
else
|
||||
{
|
||||
this._shape = this["shape"];
|
||||
}
|
||||
}
|
||||
this._right = this["selnub"];
|
||||
this._avName = this["c"];
|
||||
if(!(Boolean(this._left) && Boolean(this._mid) && Boolean(this._right) && Boolean(this._avName) && this._avName.txt))
|
||||
{
|
||||
throw new Error("NameBar is missing parts or parts are named improperly!");
|
||||
}
|
||||
this._currframeName = "black";
|
||||
this.isBlocked = initIsBlocked;
|
||||
this.nubType = initNubType;
|
||||
this._iconsMediaHelperArray = [];
|
||||
this._shapesMediaHelperArray = [];
|
||||
this._iconImages = [];
|
||||
this._nubDataArray = [];
|
||||
if(_getNamebarIconsFunc != null)
|
||||
{
|
||||
this._iconIdsArray = _getNamebarIconsFunc();
|
||||
}
|
||||
if(!this._iconIdsArray)
|
||||
{
|
||||
this._iconIdsArray = [];
|
||||
}
|
||||
this._nameBarDataToBeLoaded = -1;
|
||||
this.cacheAsBitmap = true;
|
||||
addEventListener(MouseEvent.ROLL_OVER,this.onOverHandler,false,0,true);
|
||||
addEventListener(MouseEvent.ROLL_OUT,this.onOutHandler,false,0,true);
|
||||
}
|
||||
|
||||
public static function set getNamebarIconsFunc(func:Function) : void
|
||||
{
|
||||
_getNamebarIconsFunc = func;
|
||||
}
|
||||
|
||||
public static function isVIPBadge(packedNamebarData:int) : Boolean
|
||||
{
|
||||
var badgeIcon:int = packedNamebarData >> 8 & 0xFF;
|
||||
return badgeIcon + 1 == BADGE_ID_VIP_CAMERA;
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
this.removeListeners();
|
||||
}
|
||||
|
||||
public function set isBlocked(value:Boolean) : void
|
||||
{
|
||||
this._isBlocked = value;
|
||||
if(this._nubType != GUIDE)
|
||||
{
|
||||
this._right.blocked.visible = this._isBlocked;
|
||||
}
|
||||
}
|
||||
|
||||
public function setColorAndBadge(packedData:int) : void
|
||||
{
|
||||
this._packedNameBarData = packedData;
|
||||
var color:int = packedData & 0xFF;
|
||||
var badgeIcon:int = packedData >> 8 & 0xFF;
|
||||
this._badgeId = badgeIcon + 1;
|
||||
if(Boolean(this["e"].currentFrameLabel))
|
||||
{
|
||||
this.setColor(color);
|
||||
this.setBadgeIcon(badgeIcon);
|
||||
}
|
||||
}
|
||||
|
||||
public function setColorBadgeAndXp(packedData:int, level:int, isMember:Boolean, isInQuestRoom:Boolean = false) : void
|
||||
{
|
||||
this.setColorAndBadge(packedData);
|
||||
var showQuestLevel:Boolean = (packedData >> 16 & 0xFF) == 0 && isMember;
|
||||
this._isMember = isMember;
|
||||
if(level > 0 && (isInQuestRoom || showQuestLevel))
|
||||
{
|
||||
if(Boolean(this._currShapeMouse) && Boolean(this._currShapeMouse.level != null) && this._currShapeMouse.level == level)
|
||||
{
|
||||
this.setCurrShape();
|
||||
}
|
||||
else if(level > 0)
|
||||
{
|
||||
this.setShape(level);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(this._shape.mouse.up.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.up.icon.removeChildAt(0);
|
||||
}
|
||||
while(this._shape.mouse.mouse.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.mouse.icon.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setNubType(value:String, changeDimensions:Boolean = true) : void
|
||||
{
|
||||
this.nubType = value;
|
||||
this.resize(changeDimensions);
|
||||
}
|
||||
|
||||
public function setAvName(value:String, changeDimensions:Boolean = true) : void
|
||||
{
|
||||
this._avName.txt.text = value;
|
||||
this.resize(changeDimensions);
|
||||
}
|
||||
|
||||
public function removeShape() : void
|
||||
{
|
||||
while(this._shape.mouse.up.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.up.icon.removeChildAt(0);
|
||||
}
|
||||
while(this._shape.mouse.mouse.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.mouse.icon.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateMeter(value:int) : void
|
||||
{
|
||||
this.setMeter(value);
|
||||
}
|
||||
|
||||
public function getMeterValue() : int
|
||||
{
|
||||
if(Boolean(this["meter"]))
|
||||
{
|
||||
return this["meter"].hpBar.width;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function removeListeners() : void
|
||||
{
|
||||
removeEventListener(MouseEvent.ROLL_OVER,this.onOverHandler);
|
||||
removeEventListener(MouseEvent.ROLL_OUT,this.onOutHandler);
|
||||
}
|
||||
|
||||
public function get nubData() : Array
|
||||
{
|
||||
return this._nubDataArray;
|
||||
}
|
||||
|
||||
public function set nubData(data:Array) : void
|
||||
{
|
||||
this._nubDataArray = data;
|
||||
}
|
||||
|
||||
public function get iconIds() : Array
|
||||
{
|
||||
return this._iconIdsArray;
|
||||
}
|
||||
|
||||
public function set iconIds(ids:Array) : void
|
||||
{
|
||||
this._iconIdsArray = ids;
|
||||
}
|
||||
|
||||
public function get packedNameBarData() : int
|
||||
{
|
||||
return this._packedNameBarData;
|
||||
}
|
||||
|
||||
public function get xpShapeIcons() : Object
|
||||
{
|
||||
return {
|
||||
"mouseIcon":this._currShapeMouse,
|
||||
"upIcon":this._currShapeUp
|
||||
};
|
||||
}
|
||||
|
||||
public function set xpShapeIcons(obj:Object) : void
|
||||
{
|
||||
this._currShapeMouse = obj.mouseIcon;
|
||||
this._currShapeUp = obj.upIcon;
|
||||
if(Boolean(this._currShapeMouse) && this._currShapeMouse.level != null)
|
||||
{
|
||||
this.setShape(this._currShapeMouse.level);
|
||||
}
|
||||
}
|
||||
|
||||
public function get currentLevel() : int
|
||||
{
|
||||
if(Boolean(this._currShapeMouse) && this._currShapeMouse.level != null)
|
||||
{
|
||||
return this._currShapeMouse.level;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function setColor(colorValue:int) : void
|
||||
{
|
||||
var frameId:int = 0;
|
||||
if(colorValue == 0)
|
||||
{
|
||||
frameId = 4;
|
||||
}
|
||||
else if(colorValue > 3 && colorValue <= MAX_COLORS)
|
||||
{
|
||||
frameId = colorValue + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
frameId = Math.min(4,colorValue);
|
||||
}
|
||||
this._currframeName = this["e"].currentLabels[frameId - 1].name;
|
||||
this["e"].gotoAndStop(this._currframeName);
|
||||
this._left = this["e"][this._currframeName];
|
||||
this["n"].gotoAndStop(this._currframeName);
|
||||
this._mid = this["n"][this._currframeName];
|
||||
if(Boolean(this._meter))
|
||||
{
|
||||
this["meter"].gotoAndStop(this._currframeName);
|
||||
this._meter = this["meter"][this._currframeName];
|
||||
}
|
||||
if(Boolean(this._shape))
|
||||
{
|
||||
this["shape"].gotoAndStop(this._currframeName);
|
||||
this._shape = this["shape"][this._currframeName];
|
||||
}
|
||||
if(Boolean(this["selnub"].nub.currentFrameLabel))
|
||||
{
|
||||
this["selnub"].nub.gotoAndStop(this._currframeName);
|
||||
this._right = this["selnub"];
|
||||
}
|
||||
if(Boolean(this._avName.currentFrameLabel))
|
||||
{
|
||||
this._avName.gotoAndStop(this._currframeName);
|
||||
}
|
||||
this._left.mouse.gotoAndStop(1);
|
||||
this._mid.mouse.gotoAndStop(1);
|
||||
if(Boolean(this._shape))
|
||||
{
|
||||
this._shape.mouse.gotoAndStop(1);
|
||||
}
|
||||
if(Boolean(this._right.nub.currentFrameLabel))
|
||||
{
|
||||
this._right.nub[this._currframeName].mouse.gotoAndStop(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._right.nub.mouse.gotoAndStop(1);
|
||||
}
|
||||
}
|
||||
|
||||
private function setBadgeIcon(badgeIcon:int) : void
|
||||
{
|
||||
var id:int = 0;
|
||||
if(this._iconIdsArray.length > 0)
|
||||
{
|
||||
if(this["selnub"].currentFrameLabel == "buddy")
|
||||
{
|
||||
while(this._right.nub[String(this._right.nub.currentFrameLabel)].mouse.mouse.icon.numChildren > 0)
|
||||
{
|
||||
this._right.nub[String(this._right.nub.currentFrameLabel)].mouse.mouse.icon.removeChildAt(0);
|
||||
}
|
||||
while(this._right.nub[String(this._right.nub.currentFrameLabel)].mouse.up.icon.numChildren > 0)
|
||||
{
|
||||
this._right.nub[String(this._right.nub.currentFrameLabel)].mouse.up.icon.removeChildAt(0);
|
||||
}
|
||||
id = int(this._iconIdsArray[badgeIcon]);
|
||||
badgeIcon *= 2;
|
||||
if(badgeIcon % 2 != 0)
|
||||
{
|
||||
badgeIcon++;
|
||||
}
|
||||
if(Boolean(this._iconImages[badgeIcon]) && Boolean(this._iconImages[badgeIcon + 1]))
|
||||
{
|
||||
this._right.nub[String(this._right.nub.currentFrameLabel)].mouse.mouse.icon.addChild(this._iconImages[badgeIcon]);
|
||||
this._right.nub[String(this._right.nub.currentFrameLabel)].mouse.up.icon.addChild(this._iconImages[badgeIcon + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._nubDataArray[badgeIcon] = this._right.nub[String(this._right.nub.currentFrameLabel)].mouse;
|
||||
this.loadIcon(id,badgeIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._nameBarDataToBeLoaded = this._packedNameBarData;
|
||||
}
|
||||
}
|
||||
|
||||
private function set nubType(value:String) : void
|
||||
{
|
||||
if(value == "")
|
||||
{
|
||||
this._right.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._right.visible = true;
|
||||
this._nubType = value;
|
||||
this._right.gotoAndStop(this._nubType);
|
||||
if(Boolean(this._right.nub.currentFrameLabel))
|
||||
{
|
||||
this._right.nub.gotoAndStop(this._currframeName);
|
||||
this._right.nub[this._currframeName].mouse.gotoAndStop(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._right.nub.mouse.gotoAndStop(1);
|
||||
}
|
||||
if(this._isBlocked && this._nubType != GUIDE)
|
||||
{
|
||||
this._right.blocked.gotoAndStop(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function resize(changeDimensions:Boolean) : void
|
||||
{
|
||||
var offset:int = 0;
|
||||
var mid:MovieClip = null;
|
||||
var left:MovieClip = null;
|
||||
var shape:MovieClip = null;
|
||||
var meter:MovieClip = null;
|
||||
if(changeDimensions)
|
||||
{
|
||||
mid = this._mid.parent != this ? MovieClip(this._mid.parent) : this._mid;
|
||||
left = this._left.parent != this ? MovieClip(this._left.parent) : this._left;
|
||||
shape = Boolean(this._shape) && this._shape.parent != this ? MovieClip(this._shape.parent) : this._shape;
|
||||
meter = Boolean(this._meter) && this._meter.parent != this ? MovieClip(this._meter.parent) : this._meter;
|
||||
if(this._nubType == NON_BUDDY && !this._isBlocked)
|
||||
{
|
||||
offset = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = 20;
|
||||
}
|
||||
this._avName.txt.width = 300;
|
||||
if(this._avName.txt.textWidth + offset < 60)
|
||||
{
|
||||
mid.width = 60 + 0.5 * this._right.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
mid.width = Math.ceil(this._avName.txt.textWidth + offset);
|
||||
}
|
||||
mid.x = mid.width * 0.5 * -1;
|
||||
this._avName.txt.width = mid.width - offset + 5;
|
||||
left.x = mid.x - left.width;
|
||||
this._avName.x = mid.x + (this._isMember ? 2 : -2);
|
||||
this._right.x = mid.x + mid.width - 1;
|
||||
if(Boolean(shape))
|
||||
{
|
||||
shape.x = left.x;
|
||||
}
|
||||
if(Boolean(meter))
|
||||
{
|
||||
meter.width = this._avName.txt.width + 18;
|
||||
meter.x = this._avName.x - 7;
|
||||
}
|
||||
}
|
||||
this._left.mouse.gotoAndStop(1);
|
||||
this._mid.mouse.gotoAndStop(1);
|
||||
if(Boolean(this._shape))
|
||||
{
|
||||
this._shape.mouse.gotoAndStop(1);
|
||||
}
|
||||
if(Boolean(this._right.nub.currentFrameLabel))
|
||||
{
|
||||
this._right.nub[this._currframeName].mouse.gotoAndStop(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._right.nub.mouse.gotoAndStop(1);
|
||||
}
|
||||
}
|
||||
|
||||
private function loadIcon(id:int, index:int) : void
|
||||
{
|
||||
var iconsMediaHelper:MediaHelper = new MediaHelper();
|
||||
iconsMediaHelper.init(id,this.onIconsLoaded,index);
|
||||
this._iconsMediaHelperArray[index] = iconsMediaHelper;
|
||||
iconsMediaHelper = new MediaHelper();
|
||||
iconsMediaHelper.init(id,this.onIconsLoaded,index + 1);
|
||||
this._iconsMediaHelperArray[index + 1] = iconsMediaHelper;
|
||||
}
|
||||
|
||||
private function onIconsLoaded(img:MovieClip) : void
|
||||
{
|
||||
var nub:Object = null;
|
||||
var index:int = 0;
|
||||
if(Boolean(img))
|
||||
{
|
||||
img.cacheAsBitmap = true;
|
||||
index = int(img.passback);
|
||||
this._iconImages[index] = img;
|
||||
if(img.passback % 2 == 0)
|
||||
{
|
||||
nub = this._nubDataArray[index].mouse.icon;
|
||||
while(nub.numChildren > 0)
|
||||
{
|
||||
nub.removeChildAt(0);
|
||||
}
|
||||
nub.addChild(img);
|
||||
}
|
||||
else
|
||||
{
|
||||
nub = this._nubDataArray[index - 1].up.icon;
|
||||
while(nub.numChildren > 0)
|
||||
{
|
||||
nub.removeChildAt(0);
|
||||
}
|
||||
nub.addChild(img);
|
||||
}
|
||||
if(Boolean(this._iconsMediaHelperArray[index]))
|
||||
{
|
||||
this._iconsMediaHelperArray[index].destroy();
|
||||
this._iconsMediaHelperArray[index] = null;
|
||||
delete this._iconsMediaHelperArray[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setCurrShape() : void
|
||||
{
|
||||
while(this._shape.mouse.up.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.up.icon.removeChildAt(0);
|
||||
}
|
||||
this._shape.mouse.up.icon.addChild(this._currShapeUp);
|
||||
while(this._shape.mouse.mouse.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.mouse.icon.removeChildAt(0);
|
||||
}
|
||||
this._shape.mouse.mouse.icon.addChild(this._currShapeMouse);
|
||||
}
|
||||
|
||||
private function setShape(level:int) : void
|
||||
{
|
||||
var shapeId:int = 0;
|
||||
if(level > 0)
|
||||
{
|
||||
if(this._currShapeMouse == null || this._currShapeMouse.level != level && Math.floor(this._currShapeMouse.level / 5) != Math.floor(level / 5))
|
||||
{
|
||||
shapeId = Math.floor(level / 5) > LEVEL_SHAPES.length - 1 ? int(LEVEL_SHAPES[LEVEL_SHAPES.length - 1]) : int(LEVEL_SHAPES[Math.floor(level / 5)]);
|
||||
this._levelShapeHelper = new MediaHelper();
|
||||
this._levelShapeHelper.init(shapeId,this.onLevelShapeLoaded,-1);
|
||||
this._shapesMediaHelperArray.push(this._levelShapeHelper);
|
||||
this._levelShapeHelper = new MediaHelper();
|
||||
this._levelShapeHelper.init(shapeId,this.onLevelShapeLoaded,level);
|
||||
this._shapesMediaHelperArray.push(this._levelShapeHelper);
|
||||
}
|
||||
else
|
||||
{
|
||||
while(this._shape.mouse.up.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.up.icon.removeChildAt(0);
|
||||
}
|
||||
this._shape.mouse.up.icon.addChild(this._currShapeUp);
|
||||
while(this._shape.mouse.mouse.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.mouse.icon.removeChildAt(0);
|
||||
}
|
||||
this._shape.mouse.mouse.icon.addChild(this._currShapeMouse);
|
||||
this._currShapeMouse.text.text = level;
|
||||
this._currShapeUp.text.text = level;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(this._shape.mouse.up.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.up.icon.removeChildAt(0);
|
||||
}
|
||||
while(this._shape.mouse.mouse.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.mouse.icon.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onLevelShapeLoaded(img:MovieClip) : void
|
||||
{
|
||||
var shape:MovieClip = null;
|
||||
if(Boolean(img))
|
||||
{
|
||||
shape = MovieClip(img.getChildAt(0));
|
||||
if(img.passback == -1)
|
||||
{
|
||||
this._currShapeUp = shape;
|
||||
if(this._isMember)
|
||||
{
|
||||
this._currShapeUp.gotoAndStop("member");
|
||||
}
|
||||
if(Boolean(this._currShapeMouse))
|
||||
{
|
||||
this._currShapeUp.text.text = this._currShapeMouse.level;
|
||||
}
|
||||
this._shapesMediaHelperArray[0].destroy();
|
||||
this._shapesMediaHelperArray.splice(0,1);
|
||||
while(this._shape.mouse.up.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.up.icon.removeChildAt(0);
|
||||
}
|
||||
this._shape.mouse.up.icon.addChild(this._currShapeUp);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._currShapeMouse = shape;
|
||||
if(this._isMember)
|
||||
{
|
||||
this._currShapeMouse.gotoAndStop("member");
|
||||
}
|
||||
this._currShapeMouse.level = this._currShapeMouse.text.text = img.passback;
|
||||
if(Boolean(this._currShapeUp))
|
||||
{
|
||||
this._currShapeUp.text.text = this._currShapeMouse.level;
|
||||
}
|
||||
this._shapesMediaHelperArray[this._shapesMediaHelperArray.length - 1].destroy();
|
||||
this._shapesMediaHelperArray.pop();
|
||||
while(this._shape.mouse.mouse.icon.numChildren > 0)
|
||||
{
|
||||
this._shape.mouse.mouse.icon.removeChildAt(0);
|
||||
}
|
||||
this._shape.mouse.mouse.icon.addChild(this._currShapeMouse);
|
||||
}
|
||||
this._shape.mouse.gotoAndStop(1);
|
||||
}
|
||||
}
|
||||
|
||||
private function setMeter(healthPercentage:int) : void
|
||||
{
|
||||
if(Boolean(this["meter"]))
|
||||
{
|
||||
this["meter"].hpBar.width = this["meter"].hpBarContainer.width * (healthPercentage / 100);
|
||||
}
|
||||
}
|
||||
|
||||
private function onOverHandler(evt:MouseEvent) : void
|
||||
{
|
||||
this._left.mouse.gotoAndPlay(1);
|
||||
this._mid.mouse.gotoAndPlay(1);
|
||||
if(Boolean(this._shape))
|
||||
{
|
||||
this._shape.mouse.gotoAndPlay(1);
|
||||
}
|
||||
if(Boolean(this._right.nub.currentFrameLabel))
|
||||
{
|
||||
this._right.nub[String(this._right.nub.currentFrameLabel)].mouse.gotoAndPlay(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._right.nub.mouse.gotoAndPlay(1);
|
||||
}
|
||||
if(this._isBlocked && this._nubType != GUIDE)
|
||||
{
|
||||
this._right.blocked.mouse.gotoAndPlay(1);
|
||||
}
|
||||
}
|
||||
|
||||
private function onOutHandler(evt:MouseEvent) : void
|
||||
{
|
||||
var rightNub:MovieClip = null;
|
||||
if(Boolean(this._right.nub[String(this._right.nub.currentFrameLabel)]))
|
||||
{
|
||||
rightNub = this._right.nub[String(this._right.nub.currentFrameLabel)];
|
||||
}
|
||||
else
|
||||
{
|
||||
rightNub = this._right.nub;
|
||||
}
|
||||
if(this._left.mouse.currentFrame > 1)
|
||||
{
|
||||
this.playBackwards(this._left.mouse);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._left.mouse.stop();
|
||||
}
|
||||
if(this._mid.mouse.currentFrame > 1)
|
||||
{
|
||||
this.playBackwards(this._mid.mouse);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._mid.mouse.stop();
|
||||
}
|
||||
if(Boolean(this._shape))
|
||||
{
|
||||
if(this._shape.mouse.currentFrame > 1)
|
||||
{
|
||||
this.playBackwards(this._shape.mouse);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._shape.mouse.stop();
|
||||
}
|
||||
}
|
||||
if(rightNub.mouse.currentFrame > 1)
|
||||
{
|
||||
this.playBackwards(rightNub.mouse);
|
||||
}
|
||||
else
|
||||
{
|
||||
rightNub.mouse.stop();
|
||||
}
|
||||
if(this._isBlocked && this._nubType != GUIDE)
|
||||
{
|
||||
if(this._right.blocked.mouse.currentFrame > 1)
|
||||
{
|
||||
this.playBackwards(this._right.blocked.mouse);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._right.blocked.mouse.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function playBackwards(mc:MovieClip) : void
|
||||
{
|
||||
mc.addEventListener(Event.ENTER_FRAME,this.pbFrameHandler,false,0,true);
|
||||
}
|
||||
|
||||
private function pbFrameHandler(evt:Event) : void
|
||||
{
|
||||
var mch:MovieClip = null;
|
||||
if(Boolean(evt.target as MovieClip))
|
||||
{
|
||||
mch = MovieClip(evt.target);
|
||||
if(mch.currentFrame == 1)
|
||||
{
|
||||
mch.removeEventListener(Event.ENTER_FRAME,this.pbFrameHandler);
|
||||
return;
|
||||
}
|
||||
mch.prevFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.analytics.SBTracker;
|
||||
import flash.display.MovieClip;
|
||||
import gui.DarkenManager;
|
||||
import gui.GuiManager;
|
||||
|
||||
public class NewWorldAvatar implements INewAvatar
|
||||
{
|
||||
|
||||
public function NewWorldAvatar()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function screenInitCallback(soundBtn:MovieClip) : void
|
||||
{
|
||||
soundBtn.visible = false;
|
||||
}
|
||||
|
||||
public function get playSound() : Boolean
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function newAvatarData(type:int, avatarName:String, avatarNameIndexes:Array, avNameValidGuiCallback:Function, isShopBuy:Boolean = false) : void
|
||||
{
|
||||
SBTracker.trackPageview("/game/play/popup/avatarSwitch/buyAnimal");
|
||||
var avNameValid:Boolean = Boolean(avatarName && avatarName != "" && RegExp(/a-zA-Z0-9 /)["exec"](avatarName) == null);
|
||||
if(avNameValid)
|
||||
{
|
||||
AvatarSwitch.addNewWorldAvatar(type,avatarName,avatarNameIndexes,isShopBuy);
|
||||
}
|
||||
if(avNameValidGuiCallback != null && !AvatarSwitch.isAddingSlot)
|
||||
{
|
||||
avNameValidGuiCallback(avNameValid);
|
||||
}
|
||||
if(avNameValid)
|
||||
{
|
||||
DarkenManager.showLoadingSpiral(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function hideConnectingMsg() : void
|
||||
{
|
||||
}
|
||||
|
||||
public function nameTypeScreenDone() : void
|
||||
{
|
||||
GuiManager.closeAvatarCreator();
|
||||
}
|
||||
|
||||
public function logInForCreateAvatarData() : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,766 @@
|
||||
package avatar
|
||||
{
|
||||
import com.adobe.utils.StringUtil;
|
||||
import com.sbi.client.SFEvent;
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import com.sbi.loader.FileServerEvent;
|
||||
import com.sbi.popup.*;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.external.ExternalInterface;
|
||||
import flash.text.TextFormat;
|
||||
import game.MinigameInfo;
|
||||
import game.MinigameManager;
|
||||
import gui.ActionManager;
|
||||
import gui.ChatHistory;
|
||||
import gui.EmoticonManager;
|
||||
import gui.EmoticonUtility;
|
||||
import gui.GuiManager;
|
||||
import gui.SafeChatManager;
|
||||
import loader.DefPacksDefHelper;
|
||||
import loader.JCDefHelper;
|
||||
import localization.LocalizationManager;
|
||||
import quest.QuestXtCommManager;
|
||||
import room.RoomManagerWorld;
|
||||
|
||||
public class UserCommXtCommManager
|
||||
{
|
||||
|
||||
public static var RAW_STR:String;
|
||||
|
||||
private static var _mainHud:MovieClip;
|
||||
|
||||
private static var _chatHist:ChatHistory;
|
||||
|
||||
private static var _emoteMgr:EmoticonManager;
|
||||
|
||||
private static var _actionMgr:ActionManager;
|
||||
|
||||
private static var _roomMgr:RoomManagerWorld;
|
||||
|
||||
private static var _spellingCorrections:Object;
|
||||
|
||||
private static var _emoteDefs:Object;
|
||||
|
||||
private static var _specialWords:Object;
|
||||
|
||||
private static var _replacedWords:Object;
|
||||
|
||||
public static const CHAT_TYPE_TYPED:int = 0;
|
||||
|
||||
public static const CHAT_TYPE_SAFE:int = 1;
|
||||
|
||||
public static const CHAT_TYPE_EMOTE:int = 2;
|
||||
|
||||
public static const CHAT_TYPE_ACTION:int = 3;
|
||||
|
||||
public static const CHAT_TYPE_ATTACHMENT:int = 4;
|
||||
|
||||
public static const CHAT_TYPE_PERM_EMOTE:int = 5;
|
||||
|
||||
public static const CHAT_TYPE_SLIDE:int = 6;
|
||||
|
||||
public static const CHAT_TYPE_PET_ACTION:int = 7;
|
||||
|
||||
public static const CHAT_TYPE_BLEND_COLOR:int = 8;
|
||||
|
||||
public static const CHAT_TYPE_LIMITED:int = 9;
|
||||
|
||||
public static const CHAT_TYPE_ALPHA_LEVEL:int = 10;
|
||||
|
||||
public static const CHAT_TYPE_CUST_ADVENTURE:int = 11;
|
||||
|
||||
public static const CHAT_TYPE_CUST_PVP:int = 12;
|
||||
|
||||
private static var _playerSfsUserId:int = -1;
|
||||
|
||||
public function UserCommXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init() : void
|
||||
{
|
||||
DebugUtility.debugTrace("UserCommXtCommManager init - initializing");
|
||||
_mainHud = GuiManager.mainHud;
|
||||
_chatHist = GuiManager.chatHist;
|
||||
_emoteMgr = GuiManager.emoteMgr;
|
||||
_actionMgr = GuiManager.actionMgr;
|
||||
_roomMgr = RoomManagerWorld.instance;
|
||||
_playerSfsUserId = AvatarManager.playerSfsUserId;
|
||||
RAW_STR = gMainFrame.server.rawProtocolSeparator;
|
||||
var dpdh:DefPacksDefHelper = new DefPacksDefHelper();
|
||||
dpdh.init(DefPacksDefHelper.DEF_EMOTICON,onEmoticonDefsLoaded,null,FileServerEvent.AMF3_TYPE);
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_EMOTICON] = dpdh;
|
||||
dpdh = new DefPacksDefHelper();
|
||||
dpdh.init(uint(DefPacksDefHelper.AUTO_CORRECT_TEXT_FILE_TO_APPEND_TO + "" + 0),onAutoCorrectListLoaded,null,FileServerEvent.PLAIN_TEXT_TYPE);
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.AUTO_CORRECT_TEXT_FILE_TO_APPEND_TO + "" + 0] = dpdh;
|
||||
_specialWords = {};
|
||||
_specialWords[LocalizationManager.translateIdOnly(14855)] = LocalizationManager.translateIdOnly(11142);
|
||||
}
|
||||
|
||||
private static function onAutoCorrectListLoaded(df:DefPacksDefHelper) : void
|
||||
{
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.AUTO_CORRECT_TEXT_FILE_TO_APPEND_TO + "" + 0] = null;
|
||||
var str:String = df.def.toString().toLowerCase() as String;
|
||||
_spellingCorrections = {};
|
||||
var autoCorrectList:Array = str.split("\r\n");
|
||||
for(var i:int = 0; i < autoCorrectList.length; i++)
|
||||
{
|
||||
autoCorrectList[i] = autoCorrectList[i].split(",");
|
||||
if(!(autoCorrectList[i][0] == null || autoCorrectList[i][0].length == 0 || autoCorrectList[i][1] == null || autoCorrectList[i][1].length == 0))
|
||||
{
|
||||
_spellingCorrections[StringUtil.trim(autoCorrectList[i][0])] = StringUtil.trim(autoCorrectList[i][1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function onEmoticonDefsLoaded(ed:DefPacksDefHelper) : void
|
||||
{
|
||||
var currObj:Object = null;
|
||||
DefPacksDefHelper.mediaArray[DefPacksDefHelper.DEF_EMOTICON] = null;
|
||||
var data:Object = ed.def;
|
||||
var emoteDefs:Object = new Object();
|
||||
for each(currObj in data)
|
||||
{
|
||||
emoteDefs[currObj.id] = int(currObj.mediaRef);
|
||||
}
|
||||
_emoteDefs = emoteDefs;
|
||||
}
|
||||
|
||||
public static function destroy() : void
|
||||
{
|
||||
}
|
||||
|
||||
public static function set playerSfsUserId(s:int) : void
|
||||
{
|
||||
_playerSfsUserId = s;
|
||||
}
|
||||
|
||||
public static function getEmoticonMediaId(defId:int) : int
|
||||
{
|
||||
if(!_emoteDefs[defId])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return _emoteDefs[defId];
|
||||
}
|
||||
|
||||
public static function getEmoticonDefId(mediaId:int) : int
|
||||
{
|
||||
var defId:String = null;
|
||||
for(defId in _emoteDefs)
|
||||
{
|
||||
if(_emoteDefs[defId] == mediaId)
|
||||
{
|
||||
return int(defId);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function addChatMessage(msg:String) : void
|
||||
{
|
||||
_chatHist.addMessage(gMainFrame.userInfo.playerAvatarInfo.avName,gMainFrame.userInfo.playerAvatarInfo.userName,msg);
|
||||
}
|
||||
|
||||
public static function sendAvatarSafeChat(sctString:String, sctCode:String, pressSafeChatBtn:Boolean = true) : void
|
||||
{
|
||||
if(Boolean(gMainFrame.clientInfo.invisMode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
AvatarManager.addAvatarMessage(sctString,_playerSfsUserId,0);
|
||||
addChatMessage(sctString);
|
||||
gMainFrame.server.sendMessage(sctCode + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_SAFE);
|
||||
if(_chatHist.enableFreeChatValue)
|
||||
{
|
||||
_chatHist.resetTreeSearch();
|
||||
_chatHist.chatMsgText.text = "";
|
||||
_chatHist.setFocusOnMsgText();
|
||||
}
|
||||
if(pressSafeChatBtn)
|
||||
{
|
||||
GuiManager.safeChatBtnDownHandler(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static function sendAvatarEmote(emote:Sprite) : void
|
||||
{
|
||||
if(Boolean(gMainFrame.clientInfo.invisMode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
AvatarManager.setAvatarEmote(emote);
|
||||
if(!EmoticonUtility.getEmoteString(emote))
|
||||
{
|
||||
throw new Error("setAvatarEmote: sent invalid emote sprite?!");
|
||||
}
|
||||
addChatMessage(EmoticonUtility.getEmoteString(emote));
|
||||
gMainFrame.server.sendMessage(EmoticonUtility.idForEmote(emote) + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_EMOTE);
|
||||
if(_chatHist.enableFreeChatValue)
|
||||
{
|
||||
_chatHist.resetTreeSearch();
|
||||
_chatHist.chatMsgText.text = "";
|
||||
_chatHist.setFocusOnMsgText();
|
||||
}
|
||||
}
|
||||
|
||||
public static function sendAvatarAction(action:Sprite) : void
|
||||
{
|
||||
if(Boolean(gMainFrame.clientInfo.invisMode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
AvatarManager.setAvatarAction(action);
|
||||
if(!_actionMgr.getActionString(action))
|
||||
{
|
||||
throw new Error("setAvatarAction: sent invalid action sprite?!");
|
||||
}
|
||||
addChatMessage(_actionMgr.getActionString(action));
|
||||
var avView:AvatarWorldView = AvatarManager.avatarViewList[AvatarManager.playerSfsUserId];
|
||||
var packAnimFlip:int = avView.lastIdleAnim;
|
||||
gMainFrame.server.sendMessage(_actionMgr.getActionString(action) + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_ACTION + RAW_STR + packAnimFlip);
|
||||
if(_chatHist.enableFreeChatValue)
|
||||
{
|
||||
_chatHist.resetTreeSearch();
|
||||
_chatHist.chatMsgText.text = "";
|
||||
_chatHist.setFocusOnMsgText();
|
||||
}
|
||||
}
|
||||
|
||||
public static function sendAvatarAttachmentEmot(emotDefId:int, extra:String = null) : void
|
||||
{
|
||||
if(Boolean(gMainFrame.clientInfo.invisMode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(extra == null)
|
||||
{
|
||||
extra = "";
|
||||
}
|
||||
gMainFrame.server.sendMessage(emotDefId + "," + extra + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_ATTACHMENT);
|
||||
}
|
||||
|
||||
public static function sendAvatarBlendColor(c:uint) : void
|
||||
{
|
||||
gMainFrame.server.sendMessage(int(c) + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_BLEND_COLOR);
|
||||
}
|
||||
|
||||
public static function sendAvatarAlphaLevel(a:uint) : void
|
||||
{
|
||||
gMainFrame.server.sendMessage(int(a) + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_ALPHA_LEVEL);
|
||||
}
|
||||
|
||||
public static function sendChatMessage(senderId:int, msg:String, inGame:Boolean) : void
|
||||
{
|
||||
if(Boolean(gMainFrame.clientInfo.invisMode) || !Utility.canChat())
|
||||
{
|
||||
return;
|
||||
}
|
||||
msg = fixMispellings(msg);
|
||||
msg = adjustCamelCase(msg);
|
||||
AvatarManager.addAvatarMessage("...",senderId,0);
|
||||
msg = adjustSpecialWords(msg);
|
||||
var chatType:int = gMainFrame.userInfo.sgChatType == ChatHistory.SG_CHAT_TYPE_FREE ? CHAT_TYPE_TYPED : CHAT_TYPE_LIMITED;
|
||||
gMainFrame.server.sendMessage(msg + RAW_STR + int(inGame) + RAW_STR + chatType);
|
||||
if(_chatHist.enableFreeChatValue)
|
||||
{
|
||||
_chatHist.resetTreeSearch();
|
||||
_chatHist.chatMsgText.text = "";
|
||||
gMainFrame.stage.focus = _chatHist.chatMsgText;
|
||||
}
|
||||
}
|
||||
|
||||
private static function adjustSpecialWords(msg:String) : String
|
||||
{
|
||||
var currWord:String = null;
|
||||
var currWordLowerCase:String = null;
|
||||
var specialWord:String = null;
|
||||
var idx:int = 0;
|
||||
var prev:String = null;
|
||||
var word:String = null;
|
||||
var post:String = null;
|
||||
_replacedWords = {};
|
||||
var words:Array = msg.split(" ");
|
||||
var caseType:int = 0;
|
||||
for(var i:int = 0; i < words.length; i++)
|
||||
{
|
||||
currWord = words[i];
|
||||
currWordLowerCase = currWord.toLowerCase();
|
||||
for(specialWord in _specialWords)
|
||||
{
|
||||
idx = currWordLowerCase.indexOf(specialWord);
|
||||
if(idx >= 0)
|
||||
{
|
||||
prev = currWord.substr(0,idx);
|
||||
word = currWord.substr(idx,specialWord.length);
|
||||
post = currWord.substr(idx + specialWord.length);
|
||||
caseType = getCaseType(word);
|
||||
word = setCaseType(_specialWords[specialWord],caseType);
|
||||
words[i] = prev + word + post;
|
||||
_replacedWords[words[i]] = currWord;
|
||||
}
|
||||
}
|
||||
}
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
private static function getCaseType(word:String) : int
|
||||
{
|
||||
if(word.toLowerCase() == word)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
var firstLetter:String = word.charAt(0);
|
||||
var numCaps:int = int(word.match(/[A-Z]/g).length);
|
||||
if(numCaps == word.length)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
private static function setCaseType(word:String, caseType:int) : String
|
||||
{
|
||||
if(caseType == 0)
|
||||
{
|
||||
return word.toLowerCase();
|
||||
}
|
||||
if(caseType == 1)
|
||||
{
|
||||
return word.toUpperCase();
|
||||
}
|
||||
word = word.toLowerCase();
|
||||
var firstLetter:String = word.charAt(0).toUpperCase();
|
||||
return firstLetter + word.substr(1);
|
||||
}
|
||||
|
||||
private static function reverseSpecialWords(msg:String) : String
|
||||
{
|
||||
var currWord:String = null;
|
||||
if(_replacedWords == null)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
var words:Array = msg.split(" ");
|
||||
for(var i:int = 0; i < words.length; i++)
|
||||
{
|
||||
currWord = words[i].toLowerCase();
|
||||
if(!(_replacedWords[currWord] == null || currWord == "constructor"))
|
||||
{
|
||||
words[i] = _replacedWords[currWord];
|
||||
}
|
||||
}
|
||||
_replacedWords = null;
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
private static function adjustCamelCase(msg:String) : String
|
||||
{
|
||||
var numCaps:int = 0;
|
||||
var word:String = null;
|
||||
var lettersOnly:String = null;
|
||||
var firstLetter:String = null;
|
||||
var firstLetterIdx:int = 0;
|
||||
var words:Array = msg.split(" ");
|
||||
for(var i:int = 0; i < words.length; i++)
|
||||
{
|
||||
word = words[i];
|
||||
lettersOnly = word.match(/[a-zA-Z]/g).join("");
|
||||
firstLetter = lettersOnly.charAt(0);
|
||||
numCaps = int(lettersOnly.match(/[A-Z]/g).length);
|
||||
if(numCaps > 0 && numCaps != lettersOnly.length)
|
||||
{
|
||||
if(firstLetter.match(/[A-z]/g).length == 1)
|
||||
{
|
||||
firstLetterIdx = getIndexOfFirstLetter(word,lettersOnly);
|
||||
words[i] = word.substr(0,firstLetterIdx) + firstLetter + word.toLowerCase().substr(firstLetterIdx + 1,word.length);
|
||||
}
|
||||
else
|
||||
{
|
||||
words[i] = word.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
public static function getFirstLetter(msg:String) : String
|
||||
{
|
||||
var lettersOnly:String = msg.match(/[a-zA-Z]/g).join("");
|
||||
if(lettersOnly.length > 0)
|
||||
{
|
||||
return lettersOnly.charAt(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getIndexOfFirstLetter(msg:String, lettersOnly:String) : int
|
||||
{
|
||||
if(lettersOnly == "")
|
||||
{
|
||||
lettersOnly = msg.match(/[a-zA-Z]/g).join();
|
||||
}
|
||||
for(var i:int = 0; i < msg.length; i++)
|
||||
{
|
||||
if(msg.charAt(i) == lettersOnly.charAt(0))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static function fixMispellings(msg:String) : String
|
||||
{
|
||||
var word:String = null;
|
||||
if(!_spellingCorrections || LocalizationManager.currentLanguage != LocalizationManager.LANG_ENG)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
var words:Array = msg.split(" ");
|
||||
for(var i:int = 0; i < words.length; i++)
|
||||
{
|
||||
word = words[i].toLowerCase();
|
||||
word = stripPunctuation(word);
|
||||
if(_spellingCorrections[word] != null)
|
||||
{
|
||||
word = _spellingCorrections[word];
|
||||
words[i] = word;
|
||||
}
|
||||
}
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
public static function stripPunctuation(word:String) : String
|
||||
{
|
||||
return word.replace(/[^A-Za-z0-9 ']+/g,"");
|
||||
}
|
||||
|
||||
public static function sendAvatarSlide(name:String) : void
|
||||
{
|
||||
if(Boolean(gMainFrame.clientInfo.invisMode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
gMainFrame.server.sendMessage(name + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_SLIDE);
|
||||
}
|
||||
|
||||
public static function sendPermEmote(emoteMediaId:int, inGame:Boolean) : void
|
||||
{
|
||||
gMainFrame.server.sendMessage(emoteMediaId + RAW_STR + int(inGame) + RAW_STR + CHAT_TYPE_PERM_EMOTE);
|
||||
}
|
||||
|
||||
public static function sendPetAction(petActionId:int, extraId:int = 0) : void
|
||||
{
|
||||
gMainFrame.server.sendMessage(petActionId + "," + extraId + RAW_STR + int(MinigameManager.inMinigame) + RAW_STR + CHAT_TYPE_PET_ACTION);
|
||||
}
|
||||
|
||||
public static function sendCustomAdventureMessage(show:Boolean) : void
|
||||
{
|
||||
gMainFrame.server.sendMessage((show ? "on" : "off") + RAW_STR + 0 + RAW_STR + CHAT_TYPE_CUST_ADVENTURE);
|
||||
}
|
||||
|
||||
public static function sendCustomPVPMessage(show:Boolean, gameDefId:int) : void
|
||||
{
|
||||
gMainFrame.server.sendMessage((show ? "on" : "off") + RAW_STR + 0 + RAW_STR + CHAT_TYPE_CUST_PVP + RAW_STR + gameDefId);
|
||||
}
|
||||
|
||||
public static function onSendMessage(evt:MouseEvent, myMsg:String = "") : void
|
||||
{
|
||||
var acts:Sprite = null;
|
||||
var scc:String = null;
|
||||
if(_playerSfsUserId == -1)
|
||||
{
|
||||
DebugUtility.debugTrace("WARNING - UserCommXtCommManager.init was never called or the playerAvatarId is bad");
|
||||
_playerSfsUserId = AvatarManager.playerSfsUserId;
|
||||
}
|
||||
var msg:String = myMsg == "" ? _mainHud.chatBar.text01_chat.text : myMsg;
|
||||
msg = msg.split("\r").join("");
|
||||
msg = msg.split(RAW_STR).join("");
|
||||
msg = StringUtil.trim(msg);
|
||||
if(msg.length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var es:Object = EmoticonUtility.matchEmoteString(msg);
|
||||
if(Boolean(es.status))
|
||||
{
|
||||
if(Boolean(es.sprite))
|
||||
{
|
||||
sendAvatarEmote(es.sprite);
|
||||
AvatarManager.setAvatarEmote(es.sprite,-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
acts = _actionMgr.matchActionString(msg);
|
||||
if(Boolean(acts))
|
||||
{
|
||||
sendAvatarAction(acts);
|
||||
AvatarManager.setAvatarAction(acts,-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
scc = SafeChatManager.safeChatCodeForString(msg);
|
||||
if(Boolean(scc))
|
||||
{
|
||||
sendAvatarSafeChat(msg,scc,false);
|
||||
AvatarManager.addAvatarMessage(msg,_playerSfsUserId,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendChatMessage(_playerSfsUserId,msg,MinigameManager.inMinigame());
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
_chatHist.resetTreeSearch();
|
||||
_chatHist.chatMsgText.text = "";
|
||||
gMainFrame.stage.focus = _chatHist.chatMsgText;
|
||||
}
|
||||
|
||||
public static function handleXtReply(evt:SFEvent) : void
|
||||
{
|
||||
var data:Array = evt.obj;
|
||||
switch(data[0])
|
||||
{
|
||||
case "uc":
|
||||
userCommChatResponse(data);
|
||||
break;
|
||||
case "ua":
|
||||
userCommAdminMessageResponse(data);
|
||||
break;
|
||||
default:
|
||||
throw new Error("UserCommXtCommManager illegal data:" + data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function userCommChatResponse(data:Array) : void
|
||||
{
|
||||
var msg:String = null;
|
||||
var permEmoteMediaId:int = 0;
|
||||
var petMsgSplit:Array = null;
|
||||
var split:Array = null;
|
||||
var adventureInfoSplit:Array = null;
|
||||
var questScriptDef:Object = null;
|
||||
var splitData:Array = null;
|
||||
var jmi:MinigameInfo = null;
|
||||
var badChat:Boolean = false;
|
||||
var scm:String = null;
|
||||
var es:Sprite = null;
|
||||
var cacts:Sprite = null;
|
||||
var msgSplit:Array = null;
|
||||
var attId:int = 0;
|
||||
var chattyAv:Avatar = null;
|
||||
var splitMessage:Array = null;
|
||||
var chattyUserId:int = int(data[2]);
|
||||
var inGame:Boolean = Boolean(int(data[4]));
|
||||
var chatType:int = int(data[5]);
|
||||
var showChatterMsg:Boolean = true;
|
||||
if(showChatterMsg)
|
||||
{
|
||||
if(chatType == CHAT_TYPE_PERM_EMOTE)
|
||||
{
|
||||
permEmoteMediaId = int(data[3]);
|
||||
if(permEmoteMediaId >= 0)
|
||||
{
|
||||
AvatarManager.setAvatarEmote(null,chattyUserId,permEmoteMediaId);
|
||||
}
|
||||
else
|
||||
{
|
||||
AvatarManager.setChatBalloonReadyForClear(chattyUserId);
|
||||
}
|
||||
}
|
||||
else if(chatType == CHAT_TYPE_SLIDE)
|
||||
{
|
||||
if(chattyUserId != gMainFrame.server.userId)
|
||||
{
|
||||
_roomMgr.attachAvatarToSlide(AvatarManager.avatarViewList[chattyUserId],data[3]);
|
||||
}
|
||||
}
|
||||
else if(chatType == CHAT_TYPE_PET_ACTION)
|
||||
{
|
||||
petMsgSplit = data[3].split(",");
|
||||
AvatarManager.setPetAction(chattyUserId,petMsgSplit[0],petMsgSplit[1]);
|
||||
}
|
||||
else if(chatType == CHAT_TYPE_CUST_ADVENTURE)
|
||||
{
|
||||
msg = data[3];
|
||||
if(msg == "off")
|
||||
{
|
||||
AvatarManager.addCustomAdventureMessage("","off",chattyUserId,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
split = msg.split("|");
|
||||
adventureInfoSplit = split[0].split(",");
|
||||
questScriptDef = QuestXtCommManager.getScriptDef(adventureInfoSplit[0]);
|
||||
if(Boolean(questScriptDef))
|
||||
{
|
||||
AvatarManager.addCustomAdventureMessage(LocalizationManager.translateIdOnly(questScriptDef.titleStrId),split[1] + "|" + adventureInfoSplit[0],chattyUserId,adventureInfoSplit[2],int(data[6]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(chatType == CHAT_TYPE_CUST_PVP)
|
||||
{
|
||||
msg = data[3];
|
||||
splitData = data[3].split("|");
|
||||
if(splitData[0] == "off")
|
||||
{
|
||||
if(chattyUserId == AvatarManager.playerSfsUserId)
|
||||
{
|
||||
MinigameManager.readySelfForPvpGame({"typeDefId":splitData[1]},splitData[2],true,true);
|
||||
}
|
||||
AvatarManager.addCustomPvpMessage("",splitData[0],chattyUserId,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
jmi = MinigameManager.minigameInfoCache.getMinigameInfo(splitData[1]);
|
||||
AvatarManager.addCustomPvpMessage(LocalizationManager.translateIdOnly(jmi.titleStrId),msg,chattyUserId,0,int(data[6]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = data[3];
|
||||
badChat = false;
|
||||
if(chatType == CHAT_TYPE_SAFE)
|
||||
{
|
||||
scm = SafeChatManager.safeChatStringForCode(msg);
|
||||
if(Boolean(scm))
|
||||
{
|
||||
msg = scm;
|
||||
}
|
||||
else
|
||||
{
|
||||
badChat = true;
|
||||
}
|
||||
}
|
||||
if(!badChat)
|
||||
{
|
||||
switch(chatType)
|
||||
{
|
||||
case CHAT_TYPE_TYPED:
|
||||
case CHAT_TYPE_LIMITED:
|
||||
case CHAT_TYPE_SAFE:
|
||||
msg = adjustCamelCase(msg);
|
||||
if(chattyUserId == gMainFrame.server.userId)
|
||||
{
|
||||
msg = reverseSpecialWords(msg);
|
||||
}
|
||||
AvatarManager.addAvatarMessage(msg,chattyUserId,int(data[6]));
|
||||
break;
|
||||
case CHAT_TYPE_EMOTE:
|
||||
es = EmoticonUtility.emoteForId(int(msg));
|
||||
if(Boolean(es))
|
||||
{
|
||||
AvatarManager.setAvatarEmote(es,chattyUserId);
|
||||
}
|
||||
else
|
||||
{
|
||||
badChat = true;
|
||||
}
|
||||
msg = EmoticonUtility.stringForId(int(msg));
|
||||
break;
|
||||
case CHAT_TYPE_ACTION:
|
||||
cacts = _actionMgr.matchActionString(msg);
|
||||
if(Boolean(cacts))
|
||||
{
|
||||
AvatarManager.setAvatarAction(cacts,chattyUserId);
|
||||
}
|
||||
else
|
||||
{
|
||||
badChat = true;
|
||||
}
|
||||
break;
|
||||
case CHAT_TYPE_ATTACHMENT:
|
||||
msgSplit = msg.split(",");
|
||||
attId = int(msgSplit[0]);
|
||||
AvatarManager._setAvatarAttachmentEmot(attId,msgSplit[1],chattyUserId);
|
||||
break;
|
||||
case CHAT_TYPE_BLEND_COLOR:
|
||||
AvatarManager._setAvatarBlendColor(chattyUserId,uint(data[3]));
|
||||
return;
|
||||
case CHAT_TYPE_ALPHA_LEVEL:
|
||||
AvatarManager._setAvatarAlphaLevel(chattyUserId,uint(data[3]));
|
||||
return;
|
||||
default:
|
||||
badChat = true;
|
||||
}
|
||||
}
|
||||
if(badChat)
|
||||
{
|
||||
DebugUtility.debugTrace("WARNING - got bad chat! msg:" + msg + " chatType:" + chatType + " from userId:" + chattyUserId);
|
||||
return;
|
||||
}
|
||||
if(chatType != CHAT_TYPE_ATTACHMENT)
|
||||
{
|
||||
if(Boolean(gMainFrame.clientInfo.extCallsActive))
|
||||
{
|
||||
chattyAv = AvatarManager.getAvatarBySfsUserId(chattyUserId);
|
||||
DebugUtility.debugTrace("mrc:sending cm command - chattyUserId:" + chattyUserId + " chattyAv:" + chattyAv);
|
||||
if(int(data[6]) == 2)
|
||||
{
|
||||
splitMessage = msg.split("|");
|
||||
splitMessage.splice(0,1);
|
||||
msg = splitMessage.join("|");
|
||||
}
|
||||
ExternalInterface.call("mrc",["cm",chattyAv.userName,msg,int(data[6])]);
|
||||
DebugUtility.debugTrace("mrc:cm command sent - chattyUserName:" + chattyAv.userName + " msg:" + msg);
|
||||
}
|
||||
if((chattyUserId != gMainFrame.server.userId || chattyUserId == gMainFrame.server.userId && (chatType == CHAT_TYPE_TYPED || chatType == CHAT_TYPE_LIMITED)) && int(data[6]) <= 1)
|
||||
{
|
||||
_chatHist.addMessageById(chattyUserId,msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function userCommAdminMessageResponse(data:Array) : void
|
||||
{
|
||||
var jcDefHelper:JCDefHelper = null;
|
||||
var msgSplit:Array = null;
|
||||
var isSystemMsg:Boolean = false;
|
||||
var adminMsg:String = data[1];
|
||||
if(adminMsg == "__ABSU_CBS__")
|
||||
{
|
||||
jcDefHelper = new JCDefHelper();
|
||||
jcDefHelper.deleteIndexFileFromCache();
|
||||
jcDefHelper.destroy();
|
||||
jcDefHelper = null;
|
||||
GuiManager.refreshJammerCentral();
|
||||
}
|
||||
else
|
||||
{
|
||||
msgSplit = adminMsg.split("|");
|
||||
if(msgSplit.length > 1)
|
||||
{
|
||||
adminMsg = LocalizationManager.translateIdAndInsertOnly(msgSplit[0],msgSplit.slice(1));
|
||||
}
|
||||
isSystemMsg = data[2] == null || int(data[2]) == 1;
|
||||
if(!isSystemMsg)
|
||||
{
|
||||
gMainFrame.clientInfo.lastBroadcastMessage = adminMsg;
|
||||
GuiManager.updateSettingsMessage();
|
||||
}
|
||||
if(isSystemMsg || !gMainFrame.isInMinigame() && gMainFrame.clientInfo.roomType != Utility.ROOMTYPE_QUEST)
|
||||
{
|
||||
new SBAJOkPopup(GuiManager.guiLayer,adminMsg);
|
||||
}
|
||||
_chatHist.addPrivateMessage(LocalizationManager.translateIdOnly(15964),null,adminMsg);
|
||||
}
|
||||
}
|
||||
|
||||
private static function getSpecialFormat() : TextFormat
|
||||
{
|
||||
var specialFormat:TextFormat = new TextFormat();
|
||||
specialFormat.color = 12845056;
|
||||
specialFormat.bold = true;
|
||||
return specialFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package avatar
|
||||
{
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class UserInfo
|
||||
{
|
||||
|
||||
public var userName:String;
|
||||
|
||||
public var currPerUserAvId:int;
|
||||
|
||||
public var avList:Object;
|
||||
|
||||
public var denItemsFull:Array;
|
||||
|
||||
public var denItemsPartial:Array;
|
||||
|
||||
public var accountType:int;
|
||||
|
||||
public var nameBarData:int;
|
||||
|
||||
public var isGuide:Boolean;
|
||||
|
||||
public var userNameModeratedFlag:int;
|
||||
|
||||
private var _allItems:Array;
|
||||
|
||||
private var _achievements:Array;
|
||||
|
||||
private var _timeStampSinceLastRequest:Number;
|
||||
|
||||
public function UserInfo()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init(initUserName:String, initAvList:Array = null, initCurrPerUserAvId:int = -1, initAccountType:int = 1, initUserNameModerated:int = 0) : void
|
||||
{
|
||||
this.userName = initUserName;
|
||||
this._timeStampSinceLastRequest = 0;
|
||||
this._allItems = [];
|
||||
if(Boolean(initAvList))
|
||||
{
|
||||
this.avList = initAvList;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.avList = {};
|
||||
}
|
||||
if(initCurrPerUserAvId > 0)
|
||||
{
|
||||
this.currPerUserAvId = initCurrPerUserAvId;
|
||||
}
|
||||
this.accountType = initAccountType;
|
||||
this.userNameModeratedFlag = initUserNameModerated;
|
||||
}
|
||||
|
||||
public function addAvatarToList(avatarInfo:AvatarInfo) : void
|
||||
{
|
||||
this.avList[avatarInfo.perUserAvId] = avatarInfo;
|
||||
}
|
||||
|
||||
public function getAvatarInfoByPerUserAvId(perUserAvId:int) : AvatarInfo
|
||||
{
|
||||
if(perUserAvId == -1)
|
||||
{
|
||||
return this.avList[this.currPerUserAvId];
|
||||
}
|
||||
if(Boolean(this.avList[perUserAvId]))
|
||||
{
|
||||
return this.avList[perUserAvId];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addAchievementsTolist(achievs:Array) : void
|
||||
{
|
||||
if(!this._achievements)
|
||||
{
|
||||
this._achievements = [];
|
||||
}
|
||||
var j:int = int(this._achievements.length);
|
||||
for(var i:int = 0; i < achievs.length; i++)
|
||||
{
|
||||
this._achievements[j++] = achievs[i];
|
||||
}
|
||||
}
|
||||
|
||||
public function set fullItemList(a:Array) : void
|
||||
{
|
||||
this._allItems = a;
|
||||
}
|
||||
|
||||
public function get fullItemList() : Array
|
||||
{
|
||||
return this._allItems;
|
||||
}
|
||||
|
||||
public function getFullItemList(withBodyMods:Boolean) : Array
|
||||
{
|
||||
var items:Array = [];
|
||||
for(var i:int = 0; i < this._allItems.length; i++)
|
||||
{
|
||||
if(withBodyMods)
|
||||
{
|
||||
items.push(this._allItems[i]);
|
||||
}
|
||||
else if(this._allItems[i].invIdx >= 0)
|
||||
{
|
||||
items.push(this._allItems[i]);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public function getPartialItemList(avType:int, withBodyMods:Boolean) : Array
|
||||
{
|
||||
var items:Array = [];
|
||||
for(var i:int = 0; i < this._allItems.length; i++)
|
||||
{
|
||||
if(this._allItems[i].invIdx < 0 && withBodyMods || Utility.isSameEnviroType(gMainFrame.userInfo.getAvatarEnviroTypeFlagByAvType(avType),this._allItems[i].enviroType))
|
||||
{
|
||||
if(withBodyMods)
|
||||
{
|
||||
items.push(this._allItems[i]);
|
||||
}
|
||||
else if(this._allItems[i].invIdx >= 0)
|
||||
{
|
||||
items.push(this._allItems[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public function allItemsInUseOff(perUserAvId:int) : void
|
||||
{
|
||||
for(var i:int = 0; i < this._allItems.length; i++)
|
||||
{
|
||||
this._allItems[i].setInUse(perUserAvId,false);
|
||||
}
|
||||
}
|
||||
|
||||
public function get achievements() : Array
|
||||
{
|
||||
return this._achievements;
|
||||
}
|
||||
|
||||
public function get isMember() : Boolean
|
||||
{
|
||||
return Utility.isMember(this.accountType);
|
||||
}
|
||||
|
||||
public function resetAchievements() : void
|
||||
{
|
||||
this._achievements = [];
|
||||
}
|
||||
|
||||
public function getTimeOfLastAchievementRequest() : Number
|
||||
{
|
||||
return this._timeStampSinceLastRequest;
|
||||
}
|
||||
|
||||
public function setTimeOfLastAchievementRequest(time:Number) : void
|
||||
{
|
||||
this._timeStampSinceLastRequest = time;
|
||||
}
|
||||
|
||||
public function getModeratedUserName() : String
|
||||
{
|
||||
if(this.userNameModeratedFlag > 0)
|
||||
{
|
||||
return this.userName;
|
||||
}
|
||||
return LocalizationManager.translateIdOnly(LocalizationManager.NEW_JAMMER_USERNAME);
|
||||
}
|
||||
|
||||
public function getAccountType() : int
|
||||
{
|
||||
return this.accountType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
package avatar
|
||||
{
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import flash.utils.Dictionary;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class UserInfoCache
|
||||
{
|
||||
|
||||
public var myUserName:String;
|
||||
|
||||
public var myBuddyCount:int;
|
||||
|
||||
public var isMember:Boolean;
|
||||
|
||||
public var isModerator:Boolean;
|
||||
|
||||
public var isGuide:Boolean;
|
||||
|
||||
public var isSilenced:Boolean;
|
||||
|
||||
public var isMyDenPrivate:Boolean;
|
||||
|
||||
public var sgChatType:int;
|
||||
|
||||
public var sgChatTypeNonDegraded:int;
|
||||
|
||||
public var firstFiveMinutes:int;
|
||||
|
||||
public var pendingFlags:Number;
|
||||
|
||||
public var activeDenRoomInvId:int;
|
||||
|
||||
public var numLogins:int;
|
||||
|
||||
public var worldMapRoomName:String;
|
||||
|
||||
public var avtDefsCached:Boolean;
|
||||
|
||||
private var _userInfo:Object;
|
||||
|
||||
private var _perUserAvIdToUserName:Dictionary;
|
||||
|
||||
private var _myPerUserAvId:int;
|
||||
|
||||
private var _myUserVarCache:UserVarCache;
|
||||
|
||||
private var _avatarDefs:Object;
|
||||
|
||||
private var _denRoomDefs:Object;
|
||||
|
||||
private var _genericListDefsInfo:Object;
|
||||
|
||||
private var _myTradeList:Array;
|
||||
|
||||
private var _myPetsInDen:Array;
|
||||
|
||||
public function UserInfoCache()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init() : void
|
||||
{
|
||||
this._userInfo = {};
|
||||
this._myPerUserAvId = -1;
|
||||
this.myUserName = "";
|
||||
this.avtDefsCached = false;
|
||||
this._myUserVarCache = new UserVarCache();
|
||||
this._myUserVarCache.init();
|
||||
this._perUserAvIdToUserName = new Dictionary(true);
|
||||
this._avatarDefs = new Object();
|
||||
this._genericListDefsInfo = new Object();
|
||||
this._myTradeList = [];
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
this._userInfo = null;
|
||||
this._avatarDefs = null;
|
||||
this._denRoomDefs = null;
|
||||
this._genericListDefsInfo = null;
|
||||
this._myTradeList = null;
|
||||
}
|
||||
|
||||
public function getUserInfoByUserName(userName:String) : UserInfo
|
||||
{
|
||||
return this._userInfo[userName];
|
||||
}
|
||||
|
||||
public function setUserInfoByUserName(userNameParam:String, userInfoParam:UserInfo) : void
|
||||
{
|
||||
var info:UserInfo = null;
|
||||
var avInfo:AvatarInfo = null;
|
||||
if(Boolean(userNameParam) && userNameParam != "")
|
||||
{
|
||||
info = this._userInfo[userNameParam] = userInfoParam;
|
||||
for each(avInfo in info.avList)
|
||||
{
|
||||
this._perUserAvIdToUserName[avInfo.perUserAvId] = userNameParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvatarInfoByUsernamePerUserAvId(userName:String, perUserAvId:int) : AvatarInfo
|
||||
{
|
||||
var user:UserInfo = null;
|
||||
var avInfo:AvatarInfo = null;
|
||||
loop0:
|
||||
for each(user in this._userInfo)
|
||||
{
|
||||
var _loc7_:int = 0;
|
||||
var _loc8_:* = user.avList;
|
||||
do
|
||||
{
|
||||
for each(avInfo in _loc8_)
|
||||
{
|
||||
}
|
||||
continue loop0;
|
||||
}
|
||||
while(!(avInfo.userName == userName && avInfo.perUserAvId == perUserAvId));
|
||||
return avInfo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function changeUserName(oldUserName:String, newUserName:String, userNameModeratedFlag:int) : void
|
||||
{
|
||||
var info:UserInfo = null;
|
||||
var avInfo:AvatarInfo = null;
|
||||
if(this._userInfo.hasOwnProperty(oldUserName))
|
||||
{
|
||||
info = this._userInfo[oldUserName];
|
||||
this._userInfo[newUserName] = info;
|
||||
this._userInfo[newUserName].userName = newUserName;
|
||||
this._userInfo[newUserName].userNameModeratedFlag = userNameModeratedFlag;
|
||||
for each(avInfo in info.avList)
|
||||
{
|
||||
avInfo.userName = newUserName;
|
||||
this._perUserAvIdToUserName[avInfo.perUserAvId] = newUserName;
|
||||
}
|
||||
delete this._userInfo[oldUserName];
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvatarInfoByUserName(userName:String) : AvatarInfo
|
||||
{
|
||||
if(this._userInfo.hasOwnProperty(userName))
|
||||
{
|
||||
return this._userInfo[userName].avList[this._userInfo[userName].currPerUserAvId];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAvatarInfoByUserNameThenPerUserAvId(userName:String, perUserAvId:int) : AvatarInfo
|
||||
{
|
||||
var test:Object = null;
|
||||
if(this._userInfo.hasOwnProperty(userName))
|
||||
{
|
||||
test = this._userInfo[userName];
|
||||
return this._userInfo[userName].avList[perUserAvId];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get myPerUserAvId() : int
|
||||
{
|
||||
return this._myPerUserAvId;
|
||||
}
|
||||
|
||||
public function setCurrAvDbId(userName:String, currAvDbId:int) : void
|
||||
{
|
||||
if(this._userInfo.hasOwnProperty(userName))
|
||||
{
|
||||
this._userInfo[userName].currPerUserAvId = currAvDbId;
|
||||
}
|
||||
}
|
||||
|
||||
public function set myPerUserAvId(setperUserAvId:int) : void
|
||||
{
|
||||
this._myPerUserAvId = setperUserAvId;
|
||||
if(this._userInfo.hasOwnProperty(this.myUserName) && Boolean(this._userInfo[this.myUserName]))
|
||||
{
|
||||
UserInfo(this._userInfo[this.myUserName]).currPerUserAvId = setperUserAvId;
|
||||
}
|
||||
}
|
||||
|
||||
public function setAvatarInfoByUsernamePerUserAvId(perUserAvId:int, setAvatarInfo:AvatarInfo, updateCurrperUserAvId:Boolean = false) : void
|
||||
{
|
||||
var setAvUsername:String = setAvatarInfo.userName;
|
||||
if(!this._userInfo.hasOwnProperty(setAvUsername))
|
||||
{
|
||||
throw new Error("Invalid setAvatarInfo! Needs userName!");
|
||||
}
|
||||
this._userInfo[setAvUsername].avList[perUserAvId] = setAvatarInfo;
|
||||
if(updateCurrperUserAvId)
|
||||
{
|
||||
this._userInfo[setAvUsername].currPerUserAvId = perUserAvId;
|
||||
this._perUserAvIdToUserName[perUserAvId] = setAvUsername;
|
||||
}
|
||||
}
|
||||
|
||||
public function setAccountTypeByUserName(userName:String, accountType:int) : void
|
||||
{
|
||||
if(this._userInfo.hasOwnProperty(userName))
|
||||
{
|
||||
this._userInfo[userName].accountType = accountType;
|
||||
}
|
||||
}
|
||||
|
||||
public function set playerAvatarInfo(setAvInfo:AvatarInfo) : void
|
||||
{
|
||||
this._myPerUserAvId = setAvInfo.perUserAvId;
|
||||
this.myUserName = setAvInfo.userName;
|
||||
var myUserInfo:UserInfo = UserInfo(this._userInfo[this.myUserName]);
|
||||
if(Boolean(myUserInfo))
|
||||
{
|
||||
myUserInfo.avList[this._myPerUserAvId] = setAvInfo;
|
||||
myUserInfo.currPerUserAvId = this._myPerUserAvId;
|
||||
}
|
||||
}
|
||||
|
||||
public function get playerAvatarInfo() : AvatarInfo
|
||||
{
|
||||
try
|
||||
{
|
||||
return this._userInfo[this.myUserName].avList[this._myPerUserAvId];
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
DebugUtility.debugTrace("Error trying to get playerAvatarInfo! msg:" + e.message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get playerUserInfo() : UserInfo
|
||||
{
|
||||
return this.getUserInfoByUserName(this.myUserName);
|
||||
}
|
||||
|
||||
public function get userVarCache() : UserVarCache
|
||||
{
|
||||
return this._myUserVarCache;
|
||||
}
|
||||
|
||||
public function get userNameModerated() : String
|
||||
{
|
||||
if(gMainFrame.clientInfo.userNameModerated > 0)
|
||||
{
|
||||
return this.myUserName;
|
||||
}
|
||||
return LocalizationManager.translateIdOnly(LocalizationManager.NEW_JAMMER_USERNAME);
|
||||
}
|
||||
|
||||
public function setAvatarDefs(avtDefs:Object) : void
|
||||
{
|
||||
this._avatarDefs = avtDefs;
|
||||
this.avtDefsCached = true;
|
||||
}
|
||||
|
||||
public function getAvatarColorLayer1InfoByAvType(avType:uint) : uint
|
||||
{
|
||||
if(Boolean(this._avatarDefs[avType]))
|
||||
{
|
||||
return this._avatarDefs[avType].colorLayer1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAvatarColorLayer2InfoByAvType(avType:uint) : uint
|
||||
{
|
||||
if(Boolean(this._avatarDefs[avType]))
|
||||
{
|
||||
return this._avatarDefs[avType].colorLayer2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAvatarColorLayer3InfoByAvType(avType:uint) : uint
|
||||
{
|
||||
if(Boolean(this._avatarDefs[avType]))
|
||||
{
|
||||
return this._avatarDefs[avType].colorLayer3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAvatarDefPatternInfoByAvType(avType:int) : uint
|
||||
{
|
||||
if(Boolean(this._avatarDefs[avType]))
|
||||
{
|
||||
return this._avatarDefs[avType].defPattern;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAvatarDefEyesInfoByAvType(avType:int) : uint
|
||||
{
|
||||
if(Boolean(this._avatarDefs[avType]))
|
||||
{
|
||||
return this._avatarDefs[avType].defEyes;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAvatarMemberInfoByAvType(avType:int) : Boolean
|
||||
{
|
||||
if(Boolean(this._avatarDefs[avType]))
|
||||
{
|
||||
return this._avatarDefs[avType].isMemOnly;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getAvatarEnviroTypeFlagByAvType(avType:int) : int
|
||||
{
|
||||
if(Boolean(this._avatarDefs[avType]))
|
||||
{
|
||||
return this._avatarDefs[avType].enviroTypeFlag;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAvatarDefByAvType(avType:int) : Object
|
||||
{
|
||||
return this._avatarDefs[avType];
|
||||
}
|
||||
|
||||
public function set denRoomDefs(o:Object) : void
|
||||
{
|
||||
this._denRoomDefs = o;
|
||||
}
|
||||
|
||||
public function get denRoomDefs() : Object
|
||||
{
|
||||
return this._denRoomDefs;
|
||||
}
|
||||
|
||||
public function getDenRoomDefByDefId(defId:int) : Object
|
||||
{
|
||||
return this._denRoomDefs[defId];
|
||||
}
|
||||
|
||||
public function set genericListDefs(o:Object) : void
|
||||
{
|
||||
this._genericListDefsInfo = o;
|
||||
}
|
||||
|
||||
public function getGenericListDefByDefId(defId:int) : Object
|
||||
{
|
||||
return this._genericListDefsInfo[defId];
|
||||
}
|
||||
|
||||
public function getMyTradeList() : Array
|
||||
{
|
||||
return this._myTradeList;
|
||||
}
|
||||
|
||||
public function set myTradeList(value:Array) : void
|
||||
{
|
||||
this._myTradeList = value;
|
||||
}
|
||||
|
||||
public function removeFromMyTradeList(index:int) : void
|
||||
{
|
||||
this._myTradeList.splice(index,1);
|
||||
}
|
||||
|
||||
public function set myPetsInDen(value:Array) : void
|
||||
{
|
||||
this._myPetsInDen = value;
|
||||
}
|
||||
|
||||
public function get myPetsInDen() : Array
|
||||
{
|
||||
return this._myPetsInDen;
|
||||
}
|
||||
|
||||
public function isPendingFlagSet(bitIdx:int) : Boolean
|
||||
{
|
||||
return (this.pendingFlags & 1 << bitIdx) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package avatar
|
||||
{
|
||||
public class UserVarCache
|
||||
{
|
||||
|
||||
private var _cache:Object;
|
||||
|
||||
public function UserVarCache()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init() : void
|
||||
{
|
||||
this._cache = new Object();
|
||||
}
|
||||
|
||||
public function set playerUserVars(userVars:Object) : void
|
||||
{
|
||||
var userVarId:String = null;
|
||||
this._cache = new Object();
|
||||
for(userVarId in userVars)
|
||||
{
|
||||
this._cache[userVarId] = {
|
||||
"value":userVars[userVarId].value,
|
||||
"type":userVars[userVarId].type
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public function get playerUserVars() : Object
|
||||
{
|
||||
return this._cache;
|
||||
}
|
||||
|
||||
public function getUserVarValueById(userVarDefId:int) : int
|
||||
{
|
||||
if(Boolean(this._cache) && Boolean(this._cache[userVarDefId]))
|
||||
{
|
||||
return this._cache[userVarDefId].value;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getUserVarTypeById(userVarDefId:int) : int
|
||||
{
|
||||
if(Boolean(this._cache) && Boolean(this._cache[userVarDefId]))
|
||||
{
|
||||
return this._cache[userVarDefId].type;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function isBitSet(userVarDefId:int, bitIdx:int) : Boolean
|
||||
{
|
||||
if(Boolean(this._cache) && Boolean(this._cache[userVarDefId]))
|
||||
{
|
||||
return Boolean(this._cache[userVarDefId].value & 1 << bitIdx);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function numBitsSet(userVarValue:int, numBitsToCheck:int) : int
|
||||
{
|
||||
if(userVarValue == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
var numSet:int = 0;
|
||||
for(var i:int = 0; i < numBitsToCheck; i++)
|
||||
{
|
||||
if((userVarValue & 1 << i) != 0)
|
||||
{
|
||||
numSet++;
|
||||
}
|
||||
}
|
||||
return numSet;
|
||||
}
|
||||
|
||||
public function updateUserVar(defId:int, value:int, type:int = -1) : void
|
||||
{
|
||||
if(!this._cache)
|
||||
{
|
||||
this._cache = new Object();
|
||||
}
|
||||
if(Boolean(this._cache[defId]))
|
||||
{
|
||||
this._cache[defId].value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._cache[defId] = {
|
||||
"value":value,
|
||||
"type":type
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package buddy
|
||||
{
|
||||
import com.sbi.client.SFClient;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class Buddy
|
||||
{
|
||||
|
||||
private var _userName:String;
|
||||
|
||||
private var _onlineStatus:int;
|
||||
|
||||
private var _numDaysSinceLastLogin:int;
|
||||
|
||||
private var _userNameModerationFlag:int;
|
||||
|
||||
private var _accountType:int;
|
||||
|
||||
public function Buddy()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init(userName:String, userNameModerationFlag:int, onlineStatus:int, accountType:int, numDaysSinceLastLogin:int = 0) : void
|
||||
{
|
||||
this._userName = userName;
|
||||
this._onlineStatus = onlineStatus;
|
||||
this._numDaysSinceLastLogin = numDaysSinceLastLogin;
|
||||
this._userNameModerationFlag = userNameModerationFlag;
|
||||
this._accountType = accountType;
|
||||
}
|
||||
|
||||
public function get userName() : String
|
||||
{
|
||||
return this._userName;
|
||||
}
|
||||
|
||||
public function get userNameModerated() : String
|
||||
{
|
||||
if(this._userNameModerationFlag > 0)
|
||||
{
|
||||
return this._userName;
|
||||
}
|
||||
return LocalizationManager.translateIdOnly(LocalizationManager.NEW_JAMMER_USERNAME);
|
||||
}
|
||||
|
||||
public function get onlineStatus() : int
|
||||
{
|
||||
return this._onlineStatus;
|
||||
}
|
||||
|
||||
public function get isOnline() : Boolean
|
||||
{
|
||||
return this._onlineStatus == SFClient.STATUS_ONLINE;
|
||||
}
|
||||
|
||||
public function get numDaysSinceLastLogin() : int
|
||||
{
|
||||
return this._numDaysSinceLastLogin;
|
||||
}
|
||||
|
||||
public function get accountType() : int
|
||||
{
|
||||
return this._accountType;
|
||||
}
|
||||
|
||||
public function set userName(value:String) : void
|
||||
{
|
||||
this._userName = value;
|
||||
}
|
||||
|
||||
public function set userNameModeratedFlag(value:int) : void
|
||||
{
|
||||
this._userNameModerationFlag = value;
|
||||
}
|
||||
|
||||
public function set onlineStatus(value:int) : void
|
||||
{
|
||||
this._onlineStatus = value;
|
||||
}
|
||||
|
||||
public function set numDaysSinceLastLogin(value:int) : void
|
||||
{
|
||||
this._numDaysSinceLastLogin = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package buddy
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class BuddyEvent extends Event
|
||||
{
|
||||
|
||||
public static const BUDDY_LIST:String = "OnBuddyList";
|
||||
|
||||
public static const BUDDY_CHANGED:String = "OnBuddyChanged";
|
||||
|
||||
public var userName:String;
|
||||
|
||||
public function BuddyEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new BuddyEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package buddy
|
||||
{
|
||||
import flash.utils.Timer;
|
||||
|
||||
public class BuddyTimer extends Timer
|
||||
{
|
||||
|
||||
public var userName:String;
|
||||
|
||||
public function BuddyTimer(delay:Number, repeatCount:int = 0)
|
||||
{
|
||||
super(delay,repeatCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
package buddy
|
||||
{
|
||||
import com.sbi.client.SFEvent;
|
||||
import gui.BuddyCard;
|
||||
import gui.BuddyManager;
|
||||
|
||||
public class BuddyXtCommManager
|
||||
{
|
||||
|
||||
private static var _searchCallback:Function;
|
||||
|
||||
private static var _requestCallback:Function;
|
||||
|
||||
public function BuddyXtCommManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function sendBuddyListRequest(callback:Function = null) : void
|
||||
{
|
||||
_requestCallback = callback;
|
||||
gMainFrame.server.setXtObject_Str("bl",[]);
|
||||
}
|
||||
|
||||
public static function sendBuddyAddRequest(userName:String) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("ba",[userName]);
|
||||
}
|
||||
|
||||
public static function sendBuddyConfirmRequest(userName:String, acceptedRequest:Boolean) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("bc",[userName,acceptedRequest ? "1" : "0"]);
|
||||
}
|
||||
|
||||
public static function sendBuddyDeleteRequest(userName:String) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("bd",[userName]);
|
||||
}
|
||||
|
||||
public static function sendBuddyRoomRequest(userName:String) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("br",[userName],true,false,false);
|
||||
}
|
||||
|
||||
public static function sendBuddyBlockRequest(userName:String) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("bb",[userName]);
|
||||
}
|
||||
|
||||
public static function sendBuddyUnblockRequest(userName:String) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("bu",[userName]);
|
||||
}
|
||||
|
||||
public static function sendBuddyBlockInfoRequest(userName:String) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("bi",[userName]);
|
||||
}
|
||||
|
||||
public static function sendSearchRequest(userName:String, callback:Function) : void
|
||||
{
|
||||
_searchCallback = callback;
|
||||
userSearchResponse([false,-1]);
|
||||
}
|
||||
|
||||
public static function handleXtReply(evt:SFEvent) : void
|
||||
{
|
||||
var data:Array = evt.obj;
|
||||
switch(data[0])
|
||||
{
|
||||
case "bl":
|
||||
buddyListblockedListResponse(data);
|
||||
break;
|
||||
case "ba":
|
||||
buddyAddRequestResponse(int(data[2]),data[3],data[4]);
|
||||
break;
|
||||
case "bs":
|
||||
buddyStatusResponse(data);
|
||||
break;
|
||||
case "bd":
|
||||
buddyDeleteResponse(data[2]);
|
||||
break;
|
||||
case "br":
|
||||
buddyRoomResponse(data);
|
||||
break;
|
||||
case "bb":
|
||||
buddyBlockResponse(data);
|
||||
break;
|
||||
case "bu":
|
||||
buddyUnblockResponse(data);
|
||||
break;
|
||||
case "bi":
|
||||
buddyIsBlockingMeResponse(data);
|
||||
break;
|
||||
default:
|
||||
throw new Error("BuddyXtCommManager illegal data:" + data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function buddyListblockedListResponse(data:Object) : void
|
||||
{
|
||||
if(data[2] == "0")
|
||||
{
|
||||
BuddyManager.buddyListResponseHandler(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
BuddyManager.blockedListResponseHandler(data);
|
||||
}
|
||||
if(_requestCallback != null)
|
||||
{
|
||||
_requestCallback();
|
||||
_requestCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function buddyAddRequestResponse(flag:int, userName:String, userNameModerationFlag:int) : void
|
||||
{
|
||||
BuddyManager.buddyAddRequestResponseHandler(flag,userName,userNameModerationFlag);
|
||||
}
|
||||
|
||||
private static function buddyStatusResponse(data:Object) : void
|
||||
{
|
||||
if(data[2] == "1")
|
||||
{
|
||||
BuddyManager.buddyStatusResponseHandler(data[3],data[4],data[5] == "1",int(data[6]),int(data[7]),null,data[8],data[9]);
|
||||
}
|
||||
else
|
||||
{
|
||||
BuddyManager.buddyStatusResponseHandler(data[3],data[4],data[5] == "1",int(data[6]),int(data[7]),data[8]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function buddyDeleteResponse(userName:String) : void
|
||||
{
|
||||
BuddyManager.buddyDeleteResponseHandler(userName);
|
||||
}
|
||||
|
||||
private static function buddyRoomResponse(data:Object) : void
|
||||
{
|
||||
BuddyCard.buddyRoomResponseHandler(data[2],data[3],data[4],data[5] == "1",int(data[6]));
|
||||
}
|
||||
|
||||
private static function buddyBlockResponse(data:Object) : void
|
||||
{
|
||||
BuddyManager.buddyBlockResponseHandler(data[2],data[3] == "1");
|
||||
}
|
||||
|
||||
private static function buddyUnblockResponse(data:Object) : void
|
||||
{
|
||||
BuddyManager.buddyUnblockResponseHandler(data[2],data[3] == "1");
|
||||
}
|
||||
|
||||
private static function userSearchResponse(data:Object) : void
|
||||
{
|
||||
_searchCallback(data[0],data[1]);
|
||||
}
|
||||
|
||||
private static function buddyIsBlockingMeResponse(data:Object) : void
|
||||
{
|
||||
BuddyCard.buddyBlockInfoResponseHandler(data[2],data[3] == "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.adobe.crypto
|
||||
{
|
||||
import com.adobe.utils.IntUtil;
|
||||
|
||||
public class MD5
|
||||
{
|
||||
|
||||
public function MD5()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function hash(s:String) : String
|
||||
{
|
||||
var aa:int = 0;
|
||||
var bb:int = 0;
|
||||
var cc:int = 0;
|
||||
var dd:int = 0;
|
||||
var a:int = 1732584193;
|
||||
var b:int = -271733879;
|
||||
var c:int = -1732584194;
|
||||
var d:int = 271733878;
|
||||
var x:Array = createBlocks(s);
|
||||
var len:int = int(x.length);
|
||||
for(var i:int = 0; i < len; i += 16)
|
||||
{
|
||||
aa = a;
|
||||
bb = b;
|
||||
cc = c;
|
||||
dd = d;
|
||||
a = ff(a,b,c,d,x[i + 0],7,-680876936);
|
||||
d = ff(d,a,b,c,x[i + 1],12,-389564586);
|
||||
c = ff(c,d,a,b,x[i + 2],17,606105819);
|
||||
b = ff(b,c,d,a,x[i + 3],22,-1044525330);
|
||||
a = ff(a,b,c,d,x[i + 4],7,-176418897);
|
||||
d = ff(d,a,b,c,x[i + 5],12,1200080426);
|
||||
c = ff(c,d,a,b,x[i + 6],17,-1473231341);
|
||||
b = ff(b,c,d,a,x[i + 7],22,-45705983);
|
||||
a = ff(a,b,c,d,x[i + 8],7,1770035416);
|
||||
d = ff(d,a,b,c,x[i + 9],12,-1958414417);
|
||||
c = ff(c,d,a,b,x[i + 10],17,-42063);
|
||||
b = ff(b,c,d,a,x[i + 11],22,-1990404162);
|
||||
a = ff(a,b,c,d,x[i + 12],7,1804603682);
|
||||
d = ff(d,a,b,c,x[i + 13],12,-40341101);
|
||||
c = ff(c,d,a,b,x[i + 14],17,-1502002290);
|
||||
b = ff(b,c,d,a,x[i + 15],22,1236535329);
|
||||
a = gg(a,b,c,d,x[i + 1],5,-165796510);
|
||||
d = gg(d,a,b,c,x[i + 6],9,-1069501632);
|
||||
c = gg(c,d,a,b,x[i + 11],14,643717713);
|
||||
b = gg(b,c,d,a,x[i + 0],20,-373897302);
|
||||
a = gg(a,b,c,d,x[i + 5],5,-701558691);
|
||||
d = gg(d,a,b,c,x[i + 10],9,38016083);
|
||||
c = gg(c,d,a,b,x[i + 15],14,-660478335);
|
||||
b = gg(b,c,d,a,x[i + 4],20,-405537848);
|
||||
a = gg(a,b,c,d,x[i + 9],5,568446438);
|
||||
d = gg(d,a,b,c,x[i + 14],9,-1019803690);
|
||||
c = gg(c,d,a,b,x[i + 3],14,-187363961);
|
||||
b = gg(b,c,d,a,x[i + 8],20,1163531501);
|
||||
a = gg(a,b,c,d,x[i + 13],5,-1444681467);
|
||||
d = gg(d,a,b,c,x[i + 2],9,-51403784);
|
||||
c = gg(c,d,a,b,x[i + 7],14,1735328473);
|
||||
b = gg(b,c,d,a,x[i + 12],20,-1926607734);
|
||||
a = hh(a,b,c,d,x[i + 5],4,-378558);
|
||||
d = hh(d,a,b,c,x[i + 8],11,-2022574463);
|
||||
c = hh(c,d,a,b,x[i + 11],16,1839030562);
|
||||
b = hh(b,c,d,a,x[i + 14],23,-35309556);
|
||||
a = hh(a,b,c,d,x[i + 1],4,-1530992060);
|
||||
d = hh(d,a,b,c,x[i + 4],11,1272893353);
|
||||
c = hh(c,d,a,b,x[i + 7],16,-155497632);
|
||||
b = hh(b,c,d,a,x[i + 10],23,-1094730640);
|
||||
a = hh(a,b,c,d,x[i + 13],4,681279174);
|
||||
d = hh(d,a,b,c,x[i + 0],11,-358537222);
|
||||
c = hh(c,d,a,b,x[i + 3],16,-722521979);
|
||||
b = hh(b,c,d,a,x[i + 6],23,76029189);
|
||||
a = hh(a,b,c,d,x[i + 9],4,-640364487);
|
||||
d = hh(d,a,b,c,x[i + 12],11,-421815835);
|
||||
c = hh(c,d,a,b,x[i + 15],16,530742520);
|
||||
b = hh(b,c,d,a,x[i + 2],23,-995338651);
|
||||
a = ii(a,b,c,d,x[i + 0],6,-198630844);
|
||||
d = ii(d,a,b,c,x[i + 7],10,1126891415);
|
||||
c = ii(c,d,a,b,x[i + 14],15,-1416354905);
|
||||
b = ii(b,c,d,a,x[i + 5],21,-57434055);
|
||||
a = ii(a,b,c,d,x[i + 12],6,1700485571);
|
||||
d = ii(d,a,b,c,x[i + 3],10,-1894986606);
|
||||
c = ii(c,d,a,b,x[i + 10],15,-1051523);
|
||||
b = ii(b,c,d,a,x[i + 1],21,-2054922799);
|
||||
a = ii(a,b,c,d,x[i + 8],6,1873313359);
|
||||
d = ii(d,a,b,c,x[i + 15],10,-30611744);
|
||||
c = ii(c,d,a,b,x[i + 6],15,-1560198380);
|
||||
b = ii(b,c,d,a,x[i + 13],21,1309151649);
|
||||
a = ii(a,b,c,d,x[i + 4],6,-145523070);
|
||||
d = ii(d,a,b,c,x[i + 11],10,-1120210379);
|
||||
c = ii(c,d,a,b,x[i + 2],15,718787259);
|
||||
b = ii(b,c,d,a,x[i + 9],21,-343485551);
|
||||
a += aa;
|
||||
b += bb;
|
||||
c += cc;
|
||||
d += dd;
|
||||
}
|
||||
return IntUtil.toHex(a) + IntUtil.toHex(b) + IntUtil.toHex(c) + IntUtil.toHex(d);
|
||||
}
|
||||
|
||||
private static function f(x:int, y:int, z:int) : int
|
||||
{
|
||||
return x & y | ~x & z;
|
||||
}
|
||||
|
||||
private static function g(x:int, y:int, z:int) : int
|
||||
{
|
||||
return x & z | y & ~z;
|
||||
}
|
||||
|
||||
private static function h(x:int, y:int, z:int) : int
|
||||
{
|
||||
return x ^ y ^ z;
|
||||
}
|
||||
|
||||
private static function i(x:int, y:int, z:int) : int
|
||||
{
|
||||
return y ^ (x | ~z);
|
||||
}
|
||||
|
||||
private static function transform(func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
var tmp:int = a + int(func(b,c,d)) + x + t;
|
||||
return IntUtil.rol(tmp,s) + b;
|
||||
}
|
||||
|
||||
private static function ff(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(f,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function gg(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(g,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function hh(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(h,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function ii(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(i,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function createBlocks(s:String) : Array
|
||||
{
|
||||
var blocks:Array = new Array();
|
||||
var len:int = s.length * 8;
|
||||
var mask:int = 255;
|
||||
for(var i:int = 0; i < len; i += 8)
|
||||
{
|
||||
blocks[i >> 5] |= (s.charCodeAt(i / 8) & mask) << i % 32;
|
||||
}
|
||||
blocks[len >> 5] |= 128 << len % 32;
|
||||
blocks[(len + 64 >>> 9 << 4) + 14] = len;
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSON
|
||||
{
|
||||
|
||||
public function JSON()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function encode(o:Object) : String
|
||||
{
|
||||
var encoder:JSONEncoder = new JSONEncoder(o);
|
||||
return encoder.getString();
|
||||
}
|
||||
|
||||
public static function decode(s:String) : *
|
||||
{
|
||||
var decoder:JSONDecoder = new JSONDecoder(s);
|
||||
return decoder.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONDecoder
|
||||
{
|
||||
|
||||
private var value:*;
|
||||
|
||||
private var tokenizer:JSONTokenizer;
|
||||
|
||||
private var token:JSONToken;
|
||||
|
||||
public function JSONDecoder(s:String)
|
||||
{
|
||||
super();
|
||||
this.tokenizer = new JSONTokenizer(s);
|
||||
this.nextToken();
|
||||
this.value = this.parseValue();
|
||||
}
|
||||
|
||||
public function getValue() : *
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private function nextToken() : JSONToken
|
||||
{
|
||||
return this.token = this.tokenizer.getNextToken();
|
||||
}
|
||||
|
||||
private function parseArray() : Array
|
||||
{
|
||||
var a:Array = new Array();
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACKET)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
a.push(this.parseValue());
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACKET)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
if(this.token.type == JSONTokenType.COMMA)
|
||||
{
|
||||
this.nextToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting ] or , but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function parseObject() : Object
|
||||
{
|
||||
var key:String = null;
|
||||
var o:Object = new Object();
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACE)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
if(this.token.type == JSONTokenType.STRING)
|
||||
{
|
||||
key = String(this.token.value);
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.COLON)
|
||||
{
|
||||
this.nextToken();
|
||||
o[key] = this.parseValue();
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACE)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
if(this.token.type == JSONTokenType.COMMA)
|
||||
{
|
||||
this.nextToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting } or , but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting : but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting string but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function parseValue() : Object
|
||||
{
|
||||
switch(this.token.type)
|
||||
{
|
||||
case JSONTokenType.LEFT_BRACE:
|
||||
return this.parseObject();
|
||||
case JSONTokenType.LEFT_BRACKET:
|
||||
return this.parseArray();
|
||||
case JSONTokenType.STRING:
|
||||
case JSONTokenType.NUMBER:
|
||||
case JSONTokenType.TRUE:
|
||||
case JSONTokenType.FALSE:
|
||||
case JSONTokenType.NULL:
|
||||
return this.token.value;
|
||||
default:
|
||||
this.tokenizer.parseError("Unexpected " + this.token.value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
import flash.utils.describeType;
|
||||
|
||||
public class JSONEncoder
|
||||
{
|
||||
|
||||
private var jsonString:String;
|
||||
|
||||
public function JSONEncoder(value:*)
|
||||
{
|
||||
super();
|
||||
this.jsonString = this.convertToString(value);
|
||||
}
|
||||
|
||||
public function getString() : String
|
||||
{
|
||||
return this.jsonString;
|
||||
}
|
||||
|
||||
private function convertToString(value:*) : String
|
||||
{
|
||||
if(value is String)
|
||||
{
|
||||
return this.escapeString(value as String);
|
||||
}
|
||||
if(value is Number)
|
||||
{
|
||||
return isFinite(value as Number) ? value.toString() : "null";
|
||||
}
|
||||
if(value is Boolean)
|
||||
{
|
||||
return Boolean(value) ? "true" : "false";
|
||||
}
|
||||
if(value is Array)
|
||||
{
|
||||
return this.arrayToString(value as Array);
|
||||
}
|
||||
if(value is Object && value != null)
|
||||
{
|
||||
return this.objectToString(value);
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
private function escapeString(str:String) : String
|
||||
{
|
||||
var ch:String = null;
|
||||
var hexCode:String = null;
|
||||
var zeroPad:String = null;
|
||||
var s:String = "";
|
||||
var len:Number = str.length;
|
||||
for(var i:int = 0; i < len; i++)
|
||||
{
|
||||
ch = str.charAt(i);
|
||||
switch(ch)
|
||||
{
|
||||
case "\"":
|
||||
s += "\\\"";
|
||||
break;
|
||||
case "\\":
|
||||
s += "\\\\";
|
||||
break;
|
||||
case "\b":
|
||||
s += "\\b";
|
||||
break;
|
||||
case "\f":
|
||||
s += "\\f";
|
||||
break;
|
||||
case "\n":
|
||||
s += "\\n";
|
||||
break;
|
||||
case "\r":
|
||||
s += "\\r";
|
||||
break;
|
||||
case "\t":
|
||||
s += "\\t";
|
||||
break;
|
||||
default:
|
||||
if(ch < " ")
|
||||
{
|
||||
hexCode = ch.charCodeAt(0).toString(16);
|
||||
zeroPad = hexCode.length == 2 ? "00" : "000";
|
||||
s += "\\u" + zeroPad + hexCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
s += ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "\"" + s + "\"";
|
||||
}
|
||||
|
||||
private function arrayToString(a:Array) : String
|
||||
{
|
||||
var s:String = "";
|
||||
for(var i:int = 0; i < a.length; i++)
|
||||
{
|
||||
if(s.length > 0)
|
||||
{
|
||||
s += ",";
|
||||
}
|
||||
s += this.convertToString(a[i]);
|
||||
}
|
||||
return "[" + s + "]";
|
||||
}
|
||||
|
||||
private function objectToString(o:Object) : String
|
||||
{
|
||||
var value:Object = null;
|
||||
var key:String = null;
|
||||
var v:XML = null;
|
||||
var s:String = "";
|
||||
var classInfo:XML = describeType(o);
|
||||
if(classInfo.@name.toString() == "Object")
|
||||
{
|
||||
for(key in o)
|
||||
{
|
||||
value = o[key];
|
||||
if(!(value is Function))
|
||||
{
|
||||
if(s.length > 0)
|
||||
{
|
||||
s += ",";
|
||||
}
|
||||
s += this.escapeString(key) + ":" + this.convertToString(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for each(v in classInfo..*.(name() == "variable" || name() == "accessor"))
|
||||
{
|
||||
if(s.length > 0)
|
||||
{
|
||||
s += ",";
|
||||
}
|
||||
s += this.escapeString(v.@name.toString()) + ":" + this.convertToString(o[v.@name]);
|
||||
}
|
||||
}
|
||||
return "{" + s + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONParseError extends Error
|
||||
{
|
||||
|
||||
private var _location:int;
|
||||
|
||||
private var _text:String;
|
||||
|
||||
public function JSONParseError(message:String = "", location:int = 0, text:String = "")
|
||||
{
|
||||
super(message);
|
||||
this._location = location;
|
||||
this._text = text;
|
||||
}
|
||||
|
||||
public function get location() : int
|
||||
{
|
||||
return this._location;
|
||||
}
|
||||
|
||||
public function get text() : String
|
||||
{
|
||||
return this._text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONToken
|
||||
{
|
||||
|
||||
private var _type:int;
|
||||
|
||||
private var _value:Object;
|
||||
|
||||
public function JSONToken(type:int = -1, value:Object = null)
|
||||
{
|
||||
super();
|
||||
this._type = type;
|
||||
this._value = value;
|
||||
}
|
||||
|
||||
public function get type() : int
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public function set type(value:int) : void
|
||||
{
|
||||
this._type = value;
|
||||
}
|
||||
|
||||
public function get value() : Object
|
||||
{
|
||||
return this._value;
|
||||
}
|
||||
|
||||
public function set value(v:Object) : void
|
||||
{
|
||||
this._value = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONTokenType
|
||||
{
|
||||
|
||||
public static const UNKNOWN:int = -1;
|
||||
|
||||
public static const COMMA:int = 0;
|
||||
|
||||
public static const LEFT_BRACE:int = 1;
|
||||
|
||||
public static const RIGHT_BRACE:int = 2;
|
||||
|
||||
public static const LEFT_BRACKET:int = 3;
|
||||
|
||||
public static const RIGHT_BRACKET:int = 4;
|
||||
|
||||
public static const COLON:int = 6;
|
||||
|
||||
public static const TRUE:int = 7;
|
||||
|
||||
public static const FALSE:int = 8;
|
||||
|
||||
public static const NULL:int = 9;
|
||||
|
||||
public static const STRING:int = 10;
|
||||
|
||||
public static const NUMBER:int = 11;
|
||||
|
||||
public function JSONTokenType()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONTokenizer
|
||||
{
|
||||
|
||||
private var obj:Object;
|
||||
|
||||
private var jsonString:String;
|
||||
|
||||
private var loc:int;
|
||||
|
||||
private var ch:String;
|
||||
|
||||
public function JSONTokenizer(s:String)
|
||||
{
|
||||
super();
|
||||
this.jsonString = s;
|
||||
this.loc = 0;
|
||||
this.nextChar();
|
||||
}
|
||||
|
||||
public function getNextToken() : JSONToken
|
||||
{
|
||||
var possibleTrue:String = null;
|
||||
var possibleFalse:String = null;
|
||||
var possibleNull:String = null;
|
||||
var token:JSONToken = new JSONToken();
|
||||
this.skipIgnored();
|
||||
switch(this.ch)
|
||||
{
|
||||
case "{":
|
||||
token.type = JSONTokenType.LEFT_BRACE;
|
||||
token.value = "{";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "}":
|
||||
token.type = JSONTokenType.RIGHT_BRACE;
|
||||
token.value = "}";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "[":
|
||||
token.type = JSONTokenType.LEFT_BRACKET;
|
||||
token.value = "[";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "]":
|
||||
token.type = JSONTokenType.RIGHT_BRACKET;
|
||||
token.value = "]";
|
||||
this.nextChar();
|
||||
break;
|
||||
case ",":
|
||||
token.type = JSONTokenType.COMMA;
|
||||
token.value = ",";
|
||||
this.nextChar();
|
||||
break;
|
||||
case ":":
|
||||
token.type = JSONTokenType.COLON;
|
||||
token.value = ":";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "t":
|
||||
possibleTrue = "t" + this.nextChar() + this.nextChar() + this.nextChar();
|
||||
if(possibleTrue == "true")
|
||||
{
|
||||
token.type = JSONTokenType.TRUE;
|
||||
token.value = true;
|
||||
this.nextChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parseError("Expecting \'true\' but found " + possibleTrue);
|
||||
}
|
||||
break;
|
||||
case "f":
|
||||
possibleFalse = "f" + this.nextChar() + this.nextChar() + this.nextChar() + this.nextChar();
|
||||
if(possibleFalse == "false")
|
||||
{
|
||||
token.type = JSONTokenType.FALSE;
|
||||
token.value = false;
|
||||
this.nextChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parseError("Expecting \'false\' but found " + possibleFalse);
|
||||
}
|
||||
break;
|
||||
case "n":
|
||||
possibleNull = "n" + this.nextChar() + this.nextChar() + this.nextChar();
|
||||
if(possibleNull == "null")
|
||||
{
|
||||
token.type = JSONTokenType.NULL;
|
||||
token.value = null;
|
||||
this.nextChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parseError("Expecting \'null\' but found " + possibleNull);
|
||||
}
|
||||
break;
|
||||
case "\"":
|
||||
token = this.readString();
|
||||
break;
|
||||
default:
|
||||
if(this.isDigit(this.ch) || this.ch == "-")
|
||||
{
|
||||
token = this.readNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.ch == "")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
this.parseError("Unexpected " + this.ch + " encountered");
|
||||
}
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
private function readString() : JSONToken
|
||||
{
|
||||
var hexValue:String = null;
|
||||
var i:int = 0;
|
||||
var token:JSONToken = new JSONToken();
|
||||
token.type = JSONTokenType.STRING;
|
||||
var string:String = "";
|
||||
this.nextChar();
|
||||
while(this.ch != "\"" && this.ch != "")
|
||||
{
|
||||
if(this.ch == "\\")
|
||||
{
|
||||
this.nextChar();
|
||||
switch(this.ch)
|
||||
{
|
||||
case "\"":
|
||||
string += "\"";
|
||||
break;
|
||||
case "/":
|
||||
string += "/";
|
||||
break;
|
||||
case "\\":
|
||||
string += "\\";
|
||||
break;
|
||||
case "b":
|
||||
string += "\b";
|
||||
break;
|
||||
case "f":
|
||||
string += "\f";
|
||||
break;
|
||||
case "n":
|
||||
string += "\n";
|
||||
break;
|
||||
case "r":
|
||||
string += "\r";
|
||||
break;
|
||||
case "t":
|
||||
string += "\t";
|
||||
break;
|
||||
case "u":
|
||||
hexValue = "";
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
if(!this.isHexDigit(this.nextChar()))
|
||||
{
|
||||
this.parseError(" Excepted a hex digit, but found: " + this.ch);
|
||||
}
|
||||
hexValue += this.ch;
|
||||
}
|
||||
string += String.fromCharCode(parseInt(hexValue,16));
|
||||
break;
|
||||
default:
|
||||
string += "\\" + this.ch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string += this.ch;
|
||||
}
|
||||
this.nextChar();
|
||||
}
|
||||
if(this.ch == "")
|
||||
{
|
||||
this.parseError("Unterminated string literal");
|
||||
}
|
||||
this.nextChar();
|
||||
token.value = string;
|
||||
return token;
|
||||
}
|
||||
|
||||
private function readNumber() : JSONToken
|
||||
{
|
||||
var token:JSONToken = new JSONToken();
|
||||
token.type = JSONTokenType.NUMBER;
|
||||
var input:String = "";
|
||||
if(this.ch == "-")
|
||||
{
|
||||
input += "-";
|
||||
this.nextChar();
|
||||
}
|
||||
if(!this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("Expecting a digit");
|
||||
}
|
||||
if(this.ch == "0")
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
if(this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("A digit cannot immediately follow 0");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(this.isDigit(this.ch))
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
if(this.ch == ".")
|
||||
{
|
||||
input += ".";
|
||||
this.nextChar();
|
||||
if(!this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("Expecting a digit");
|
||||
}
|
||||
while(this.isDigit(this.ch))
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
if(this.ch == "e" || this.ch == "E")
|
||||
{
|
||||
input += "e";
|
||||
this.nextChar();
|
||||
if(this.ch == "+" || this.ch == "-")
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
if(!this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("Scientific notation number needs exponent value");
|
||||
}
|
||||
while(this.isDigit(this.ch))
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
var num:Number = Number(input);
|
||||
if(isFinite(num) && !isNaN(num))
|
||||
{
|
||||
token.value = num;
|
||||
return token;
|
||||
}
|
||||
this.parseError("Number " + num + " is not valid!");
|
||||
return null;
|
||||
}
|
||||
|
||||
private function nextChar() : String
|
||||
{
|
||||
return this.ch = this.jsonString.charAt(this.loc++);
|
||||
}
|
||||
|
||||
private function skipIgnored() : void
|
||||
{
|
||||
this.skipWhite();
|
||||
this.skipComments();
|
||||
this.skipWhite();
|
||||
}
|
||||
|
||||
private function skipComments() : void
|
||||
{
|
||||
if(this.ch == "/")
|
||||
{
|
||||
this.nextChar();
|
||||
switch(this.ch)
|
||||
{
|
||||
case "/":
|
||||
do
|
||||
{
|
||||
this.nextChar();
|
||||
}
|
||||
while(this.ch != "\n" && this.ch != "");
|
||||
this.nextChar();
|
||||
break;
|
||||
case "*":
|
||||
this.nextChar();
|
||||
while(true)
|
||||
{
|
||||
if(this.ch == "*")
|
||||
{
|
||||
this.nextChar();
|
||||
if(this.ch == "/")
|
||||
{
|
||||
this.nextChar();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.nextChar();
|
||||
}
|
||||
if(this.ch == "")
|
||||
{
|
||||
this.parseError("Multi-line comment not closed");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.parseError("Unexpected " + this.ch + " encountered (expecting \'/\' or \'*\' )");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function skipWhite() : void
|
||||
{
|
||||
while(this.isWhiteSpace(this.ch))
|
||||
{
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
|
||||
private function isWhiteSpace(ch:String) : Boolean
|
||||
{
|
||||
return ch == " " || ch == "\t" || ch == "\n";
|
||||
}
|
||||
|
||||
private function isDigit(ch:String) : Boolean
|
||||
{
|
||||
return ch >= "0" && ch <= "9";
|
||||
}
|
||||
|
||||
private function isHexDigit(ch:String) : Boolean
|
||||
{
|
||||
var uc:String = ch.toUpperCase();
|
||||
return this.isDigit(ch) || uc >= "A" && uc <= "F";
|
||||
}
|
||||
|
||||
public function parseError(message:String) : void
|
||||
{
|
||||
throw new JSONParseError(message,this.loc,this.jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.adobe.utils
|
||||
{
|
||||
public class IntUtil
|
||||
{
|
||||
|
||||
private static var hexChars:String = "0123456789abcdef";
|
||||
|
||||
public function IntUtil()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function rol(x:int, n:int) : int
|
||||
{
|
||||
return x << n | x >>> 32 - n;
|
||||
}
|
||||
|
||||
public static function ror(x:int, n:int) : uint
|
||||
{
|
||||
var nn:int = 32 - n;
|
||||
return x << nn | x >>> 32 - nn;
|
||||
}
|
||||
|
||||
public static function toHex(n:int, bigEndian:Boolean = false) : String
|
||||
{
|
||||
var i:int = 0;
|
||||
var x:int = 0;
|
||||
var s:String = "";
|
||||
if(bigEndian)
|
||||
{
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
s += hexChars.charAt(n >> (3 - i) * 8 + 4 & 0x0F) + hexChars.charAt(n >> (3 - i) * 8 & 0x0F);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(x = 0; x < 4; x++)
|
||||
{
|
||||
s += hexChars.charAt(n >> x * 8 + 4 & 0x0F) + hexChars.charAt(n >> x * 8 & 0x0F);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.adobe.utils
|
||||
{
|
||||
public class StringUtil
|
||||
{
|
||||
|
||||
public function StringUtil()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function stringsAreEqual(s1:String, s2:String, caseSensitive:Boolean) : Boolean
|
||||
{
|
||||
if(caseSensitive)
|
||||
{
|
||||
return s1 == s2;
|
||||
}
|
||||
return s1.toUpperCase() == s2.toUpperCase();
|
||||
}
|
||||
|
||||
public static function trim(input:String) : String
|
||||
{
|
||||
return StringUtil.ltrim(StringUtil.rtrim(input));
|
||||
}
|
||||
|
||||
public static function ltrim(input:String) : String
|
||||
{
|
||||
var size:Number = input.length;
|
||||
for(var i:Number = 0; i < size; i++)
|
||||
{
|
||||
if(input.charCodeAt(i) > 32)
|
||||
{
|
||||
return input.substring(i);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static function rtrim(input:String) : String
|
||||
{
|
||||
var size:Number = input.length;
|
||||
for(var i:Number = size; i > 0; i--)
|
||||
{
|
||||
if(input.charCodeAt(i - 1) > 32)
|
||||
{
|
||||
return input.substring(0,i);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static function beginsWith(input:String, prefix:String) : Boolean
|
||||
{
|
||||
return prefix == input.substring(0,prefix.length);
|
||||
}
|
||||
|
||||
public static function endsWith(input:String, suffix:String) : Boolean
|
||||
{
|
||||
return suffix == input.substring(input.length - suffix.length);
|
||||
}
|
||||
|
||||
public static function remove(input:String, remove:String) : String
|
||||
{
|
||||
return StringUtil.replace(input,remove,"");
|
||||
}
|
||||
|
||||
public static function replace(input:String, replace:String, replaceWith:String) : String
|
||||
{
|
||||
var j:Number = NaN;
|
||||
var sb:String = new String();
|
||||
var found:Boolean = false;
|
||||
var sLen:Number = input.length;
|
||||
var rLen:Number = replace.length;
|
||||
for(var i:Number = 0; i < sLen; i++)
|
||||
{
|
||||
if(input.charAt(i) == replace.charAt(0))
|
||||
{
|
||||
found = true;
|
||||
for(j = 0; j < rLen; j++)
|
||||
{
|
||||
if(input.charAt(i + j) != replace.charAt(j))
|
||||
{
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
sb += replaceWith;
|
||||
i += rLen - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
sb += input.charAt(i);
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.baseoneonline.astar
|
||||
{
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class AStar
|
||||
{
|
||||
|
||||
private var graph:Graph;
|
||||
|
||||
private var g:Vector.<Number>;
|
||||
|
||||
private var h:Vector.<Number>;
|
||||
|
||||
private var f:Vector.<Number>;
|
||||
|
||||
private var parent:Vector.<int>;
|
||||
|
||||
private var open:Vector.<int>;
|
||||
|
||||
private var closed:Vector.<int>;
|
||||
|
||||
private var closedDict:Dictionary;
|
||||
|
||||
private var goalReached:Boolean = false;
|
||||
|
||||
public function AStar(g:Graph = null)
|
||||
{
|
||||
super();
|
||||
if(Boolean(g))
|
||||
{
|
||||
this.setGraph(g);
|
||||
}
|
||||
}
|
||||
|
||||
public function setGraph(graph:Graph) : void
|
||||
{
|
||||
this.graph = graph;
|
||||
this.updateGraph();
|
||||
}
|
||||
|
||||
private function updateGraph() : void
|
||||
{
|
||||
var len:int = this.graph.size();
|
||||
this.g = new Vector.<Number>(len,true);
|
||||
this.h = new Vector.<Number>(len,true);
|
||||
this.f = new Vector.<Number>(len,true);
|
||||
this.parent = new Vector.<int>(len,true);
|
||||
}
|
||||
|
||||
public function solve(start:int, goal:int) : Vector.<int>
|
||||
{
|
||||
var n:int = 0;
|
||||
var tf:Number = NaN;
|
||||
var x:int = 0;
|
||||
var i:int = 0;
|
||||
var y:int = 0;
|
||||
var e:int = 0;
|
||||
var tg:Number = NaN;
|
||||
var better:Boolean = false;
|
||||
var d:Number = NaN;
|
||||
var neighbors:Vector.<int> = new Vector.<int>();
|
||||
this.goalReached = false;
|
||||
this.open = new Vector.<int>();
|
||||
this.closed = new Vector.<int>();
|
||||
this.closedDict = new Dictionary(true);
|
||||
this.open.push(start);
|
||||
this.g[start] = 0;
|
||||
this.h[start] = this.graph.distance(start,goal);
|
||||
this.f[start] = this.h[start];
|
||||
this.parent[start] = -1;
|
||||
this.graph.setStartGridPos(start);
|
||||
while(this.open.length > 0)
|
||||
{
|
||||
tf = Number.POSITIVE_INFINITY;
|
||||
x = -1;
|
||||
for(i = 0; i < this.open.length; i++)
|
||||
{
|
||||
e = this.open[i];
|
||||
if(this.f[e] < tf)
|
||||
{
|
||||
tf = this.f[e];
|
||||
x = e;
|
||||
}
|
||||
}
|
||||
if(x == goal)
|
||||
{
|
||||
this.goalReached = true;
|
||||
return this.createPath(goal,start);
|
||||
}
|
||||
this.open.splice(this.open.indexOf(x),1);
|
||||
this.closed.push(x);
|
||||
this.closedDict[x] = 1;
|
||||
for each(y in this.graph.getNeighbors(x,neighbors))
|
||||
{
|
||||
if(this.closedDict[y] != 1)
|
||||
{
|
||||
tg = this.g[x] + this.graph.distance(x,y);
|
||||
better = false;
|
||||
if(this.open.indexOf(y) == -1)
|
||||
{
|
||||
this.open.push(y);
|
||||
better = true;
|
||||
}
|
||||
else if(tg < this.g[y])
|
||||
{
|
||||
better = true;
|
||||
}
|
||||
if(better)
|
||||
{
|
||||
this.parent[y] = x;
|
||||
this.g[y] = tg;
|
||||
this.h[y] = this.graph.distance(y,goal);
|
||||
this.f[y] = this.g[y] + this.h[y];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var min:Number = Number.POSITIVE_INFINITY;
|
||||
var ng:int = -1;
|
||||
for each(n in this.closed)
|
||||
{
|
||||
d = this.h[n];
|
||||
if(d < min)
|
||||
{
|
||||
min = d;
|
||||
ng = n;
|
||||
}
|
||||
}
|
||||
return this.createPath(ng,start);
|
||||
}
|
||||
|
||||
public function hasReachedGoal() : Boolean
|
||||
{
|
||||
return this.goalReached;
|
||||
}
|
||||
|
||||
private function createPath(n:int, start:int) : Vector.<int>
|
||||
{
|
||||
var solution:Vector.<int> = new Vector.<int>();
|
||||
while(this.parent[n] != -1)
|
||||
{
|
||||
solution.push(n);
|
||||
n = this.parent[n];
|
||||
}
|
||||
solution.push(start);
|
||||
return solution.reverse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baseoneonline.astar
|
||||
{
|
||||
public interface Graph
|
||||
{
|
||||
|
||||
function getNeighbors(param1:int, param2:Vector.<int>) : Vector.<int>;
|
||||
|
||||
function distance(param1:int, param2:int) : Number;
|
||||
|
||||
function size() : int;
|
||||
|
||||
function setStartGridPos(param1:int) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
package com.carlcalderon.arthropod
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.Stage;
|
||||
import flash.events.StatusEvent;
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.net.LocalConnection;
|
||||
import flash.system.System;
|
||||
|
||||
public class Debug
|
||||
{
|
||||
|
||||
public static const NAME:String = "Debug";
|
||||
|
||||
public static const VERSION:String = "0.74";
|
||||
|
||||
public static var password:String = "CDC309AF";
|
||||
|
||||
public static var RED:uint = 13369344;
|
||||
|
||||
public static var GREEN:uint = 52224;
|
||||
|
||||
public static var BLUE:uint = 6710988;
|
||||
|
||||
public static var PINK:uint = 13369548;
|
||||
|
||||
public static var YELLOW:uint = 13421568;
|
||||
|
||||
public static var LIGHT_BLUE:uint = 52428;
|
||||
|
||||
public static var ignoreStatus:Boolean = true;
|
||||
|
||||
public static var secure:Boolean = false;
|
||||
|
||||
public static var secureDomain:String = "*";
|
||||
|
||||
public static var allowLog:Boolean = true;
|
||||
|
||||
private static const DOMAIN:String = "com.carlcalderon.Arthropod";
|
||||
|
||||
private static const CHECK:String = ".161E714B6C1A76DE7B9865F88B32FCCE8FABA7B5.1";
|
||||
|
||||
private static const TYPE:String = "app";
|
||||
|
||||
private static const CONNECTION:String = "arthropod";
|
||||
|
||||
private static const LOG_OPERATION:String = "debug";
|
||||
|
||||
private static const ERROR_OPERATION:String = "debugError";
|
||||
|
||||
private static const WARNING_OPERATION:String = "debugWarning";
|
||||
|
||||
private static const ARRAY_OPERATION:String = "debugArray";
|
||||
|
||||
private static const BITMAP_OPERATION:String = "debugBitmapData";
|
||||
|
||||
private static const OBJECT_OPERATION:String = "debugObject";
|
||||
|
||||
private static const MEMORY_OPERATION:String = "debugMemory";
|
||||
|
||||
private static const CLEAR_OPERATION:String = "debugClear";
|
||||
|
||||
private static var lc:LocalConnection = new LocalConnection();
|
||||
|
||||
private static var hasEventListeners:Boolean = false;
|
||||
|
||||
public function Debug()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function log(message:*, color:uint = 16711422) : Boolean
|
||||
{
|
||||
return send(LOG_OPERATION,String(message),color);
|
||||
}
|
||||
|
||||
public static function error(message:*) : Boolean
|
||||
{
|
||||
return send(ERROR_OPERATION,String(message),13369344);
|
||||
}
|
||||
|
||||
public static function warning(message:*) : Boolean
|
||||
{
|
||||
return send(WARNING_OPERATION,String(message),13421568);
|
||||
}
|
||||
|
||||
public static function clear() : Boolean
|
||||
{
|
||||
return send(CLEAR_OPERATION,0,0);
|
||||
}
|
||||
|
||||
public static function array(arr:Array) : Boolean
|
||||
{
|
||||
return send(ARRAY_OPERATION,arr,null);
|
||||
}
|
||||
|
||||
public static function bitmap(bmd:*, label:String = null) : Boolean
|
||||
{
|
||||
var bm:BitmapData = new BitmapData(100,100,true,16777215);
|
||||
var mtx:Matrix = new Matrix();
|
||||
var s:Number = 100 / (bmd.width >= bmd.height ? bmd.width : bmd.height);
|
||||
mtx.scale(s,s);
|
||||
bm.draw(bmd,mtx,null,null,null,true);
|
||||
var bounds:Rectangle = new Rectangle(0,0,Math.floor(bmd.width * s),Math.floor(bmd.height * s));
|
||||
return send(BITMAP_OPERATION,bm.getPixels(bounds),{
|
||||
"bounds":bounds,
|
||||
"lbl":label
|
||||
});
|
||||
}
|
||||
|
||||
public static function snapshot(stage:Stage, label:String = null) : Boolean
|
||||
{
|
||||
if(Boolean(stage))
|
||||
{
|
||||
return bitmap(stage,label);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function object(obj:*) : Boolean
|
||||
{
|
||||
return send(OBJECT_OPERATION,obj,null);
|
||||
}
|
||||
|
||||
public static function memory() : Boolean
|
||||
{
|
||||
return send(MEMORY_OPERATION,System.totalMemory,null);
|
||||
}
|
||||
|
||||
private static function send(operation:String, value:*, prop:*) : Boolean
|
||||
{
|
||||
if(!secure)
|
||||
{
|
||||
lc.allowInsecureDomain("*");
|
||||
}
|
||||
else
|
||||
{
|
||||
lc.allowDomain(secureDomain);
|
||||
}
|
||||
if(!hasEventListeners)
|
||||
{
|
||||
if(ignoreStatus)
|
||||
{
|
||||
lc.addEventListener(StatusEvent.STATUS,ignore);
|
||||
}
|
||||
else
|
||||
{
|
||||
lc.addEventListener(StatusEvent.STATUS,status);
|
||||
}
|
||||
hasEventListeners = true;
|
||||
}
|
||||
if(!allowLog)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
lc.send(TYPE + "#" + DOMAIN + CHECK + ":" + CONNECTION,operation,password,value,prop);
|
||||
return true;
|
||||
}
|
||||
catch(e:*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function status(e:StatusEvent) : void
|
||||
{
|
||||
trace("Arthropod status:\n" + e.toString());
|
||||
}
|
||||
|
||||
private static function ignore(e:StatusEvent) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.hurlant.crypto
|
||||
{
|
||||
import com.hurlant.crypto.hash.HMAC;
|
||||
import com.hurlant.crypto.hash.IHash;
|
||||
import com.hurlant.crypto.hash.MD2;
|
||||
import com.hurlant.crypto.hash.MD5;
|
||||
import com.hurlant.crypto.hash.SHA1;
|
||||
import com.hurlant.crypto.hash.SHA224;
|
||||
import com.hurlant.crypto.hash.SHA256;
|
||||
import com.hurlant.crypto.prng.ARC4;
|
||||
import com.hurlant.crypto.rsa.RSAKey;
|
||||
import com.hurlant.crypto.symmetric.AESKey;
|
||||
import com.hurlant.crypto.symmetric.BlowFishKey;
|
||||
import com.hurlant.crypto.symmetric.CBCMode;
|
||||
import com.hurlant.crypto.symmetric.CFB8Mode;
|
||||
import com.hurlant.crypto.symmetric.CFBMode;
|
||||
import com.hurlant.crypto.symmetric.CTRMode;
|
||||
import com.hurlant.crypto.symmetric.DESKey;
|
||||
import com.hurlant.crypto.symmetric.ECBMode;
|
||||
import com.hurlant.crypto.symmetric.ICipher;
|
||||
import com.hurlant.crypto.symmetric.IMode;
|
||||
import com.hurlant.crypto.symmetric.IPad;
|
||||
import com.hurlant.crypto.symmetric.ISymmetricKey;
|
||||
import com.hurlant.crypto.symmetric.IVMode;
|
||||
import com.hurlant.crypto.symmetric.NullPad;
|
||||
import com.hurlant.crypto.symmetric.OFBMode;
|
||||
import com.hurlant.crypto.symmetric.PKCS5;
|
||||
import com.hurlant.crypto.symmetric.SimpleIVMode;
|
||||
import com.hurlant.crypto.symmetric.TripleDESKey;
|
||||
import com.hurlant.crypto.symmetric.XTeaKey;
|
||||
import com.hurlant.util.Base64;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Crypto
|
||||
{
|
||||
|
||||
private var b64:Base64;
|
||||
|
||||
public function Crypto()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getCipher(name:String, key:ByteArray, pad:IPad = null) : ICipher
|
||||
{
|
||||
var cipher:ICipher = null;
|
||||
var keys:Array = name.split("-");
|
||||
switch(keys[0])
|
||||
{
|
||||
case "simple":
|
||||
keys.shift();
|
||||
name = keys.join("-");
|
||||
cipher = getCipher(name,key,pad);
|
||||
if(cipher is IVMode)
|
||||
{
|
||||
return new SimpleIVMode(cipher as IVMode);
|
||||
}
|
||||
return cipher;
|
||||
break;
|
||||
case "aes":
|
||||
case "aes128":
|
||||
case "aes192":
|
||||
case "aes256":
|
||||
keys.shift();
|
||||
if(key.length * 8 == keys[0])
|
||||
{
|
||||
keys.shift();
|
||||
}
|
||||
return getMode(keys[0],new AESKey(key),pad);
|
||||
case "bf":
|
||||
case "blowfish":
|
||||
keys.shift();
|
||||
return getMode(keys[0],new BlowFishKey(key),pad);
|
||||
case "des":
|
||||
keys.shift();
|
||||
if(keys[0] != "ede" && keys[0] != "ede3")
|
||||
{
|
||||
return getMode(keys[0],new DESKey(key),pad);
|
||||
}
|
||||
if(keys.length == 1)
|
||||
{
|
||||
keys.push("ecb");
|
||||
}
|
||||
break;
|
||||
case "3des":
|
||||
case "des3":
|
||||
break;
|
||||
case "xtea":
|
||||
keys.shift();
|
||||
return getMode(keys[0],new XTeaKey(key),pad);
|
||||
case "rc4":
|
||||
keys.shift();
|
||||
return new ARC4(key);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
keys.shift();
|
||||
return getMode(keys[0],new TripleDESKey(key),pad);
|
||||
}
|
||||
|
||||
public static function getKeySize(name:String) : uint
|
||||
{
|
||||
var keys:Array = name.split("-");
|
||||
switch(keys[0])
|
||||
{
|
||||
case "simple":
|
||||
keys.shift();
|
||||
return getKeySize(keys.join("-"));
|
||||
case "aes128":
|
||||
return 16;
|
||||
case "aes192":
|
||||
return 24;
|
||||
case "aes256":
|
||||
return 32;
|
||||
case "aes":
|
||||
keys.shift();
|
||||
return parseInt(keys[0]) / 8;
|
||||
case "bf":
|
||||
case "blowfish":
|
||||
return 16;
|
||||
case "des":
|
||||
keys.shift();
|
||||
switch(keys[0])
|
||||
{
|
||||
case "ede":
|
||||
return 16;
|
||||
case "ede3":
|
||||
return 24;
|
||||
default:
|
||||
return 8;
|
||||
}
|
||||
break;
|
||||
case "3des":
|
||||
case "des3":
|
||||
return 24;
|
||||
case "xtea":
|
||||
return 8;
|
||||
case "rc4":
|
||||
if(parseInt(keys[1]) > 0)
|
||||
{
|
||||
return parseInt(keys[1]) / 8;
|
||||
}
|
||||
return 16;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static function getMode(name:String, alg:ISymmetricKey, padding:IPad = null) : IMode
|
||||
{
|
||||
switch(name)
|
||||
{
|
||||
case "ecb":
|
||||
return new ECBMode(alg,padding);
|
||||
case "cfb":
|
||||
return new CFBMode(alg,padding);
|
||||
case "cfb8":
|
||||
return new CFB8Mode(alg,padding);
|
||||
case "ofb":
|
||||
return new OFBMode(alg,padding);
|
||||
case "ctr":
|
||||
return new CTRMode(alg,padding);
|
||||
case "cbc":
|
||||
}
|
||||
return new CBCMode(alg,padding);
|
||||
}
|
||||
|
||||
public static function getHash(name:String) : IHash
|
||||
{
|
||||
switch(name)
|
||||
{
|
||||
case "md2":
|
||||
return new MD2();
|
||||
case "md5":
|
||||
return new MD5();
|
||||
case "sha":
|
||||
case "sha1":
|
||||
return new SHA1();
|
||||
case "sha224":
|
||||
return new SHA224();
|
||||
case "sha256":
|
||||
return new SHA256();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getHMAC(name:String) : HMAC
|
||||
{
|
||||
var keys:Array = name.split("-");
|
||||
if(keys[0] == "hmac")
|
||||
{
|
||||
keys.shift();
|
||||
}
|
||||
var bits:uint = 0;
|
||||
if(keys.length > 1)
|
||||
{
|
||||
bits = parseInt(keys[1]);
|
||||
}
|
||||
return new HMAC(getHash(keys[0]),bits);
|
||||
}
|
||||
|
||||
public static function getPad(name:String) : IPad
|
||||
{
|
||||
switch(name)
|
||||
{
|
||||
case "null":
|
||||
return new NullPad();
|
||||
case "pkcs5":
|
||||
}
|
||||
return new PKCS5();
|
||||
}
|
||||
|
||||
public static function getRSA(E:String, M:String) : RSAKey
|
||||
{
|
||||
return RSAKey.parsePublicKey(M,E);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class HMAC
|
||||
{
|
||||
|
||||
private var hash:IHash;
|
||||
|
||||
private var bits:uint;
|
||||
|
||||
public function HMAC(hash:IHash, bits:uint = 0)
|
||||
{
|
||||
super();
|
||||
this.hash = hash;
|
||||
this.bits = bits;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
if(this.bits != 0)
|
||||
{
|
||||
return this.bits / 8;
|
||||
}
|
||||
return this.hash.getHashSize();
|
||||
}
|
||||
|
||||
public function compute(key:ByteArray, data:ByteArray) : ByteArray
|
||||
{
|
||||
var hashKey:ByteArray = null;
|
||||
if(key.length > this.hash.getInputSize())
|
||||
{
|
||||
hashKey = this.hash.hash(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
hashKey = new ByteArray();
|
||||
hashKey.writeBytes(key);
|
||||
}
|
||||
while(hashKey.length < this.hash.getInputSize())
|
||||
{
|
||||
hashKey[hashKey.length] = 0;
|
||||
}
|
||||
var innerKey:ByteArray = new ByteArray();
|
||||
var outerKey:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < hashKey.length; i++)
|
||||
{
|
||||
innerKey[i] = hashKey[i] ^ 0x36;
|
||||
outerKey[i] = hashKey[i] ^ 0x5C;
|
||||
}
|
||||
innerKey.position = hashKey.length;
|
||||
innerKey.writeBytes(data);
|
||||
var innerHash:ByteArray = this.hash.hash(innerKey);
|
||||
outerKey.position = hashKey.length;
|
||||
outerKey.writeBytes(innerHash);
|
||||
var outerHash:ByteArray = this.hash.hash(outerKey);
|
||||
if(this.bits > 0 && this.bits < 8 * outerHash.length)
|
||||
{
|
||||
outerHash.length = this.bits / 8;
|
||||
}
|
||||
return outerHash;
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.hash = null;
|
||||
this.bits = 0;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "hmac-" + (this.bits > 0 ? this.bits + "-" : "") + this.hash.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IHash
|
||||
{
|
||||
|
||||
function getInputSize() : uint;
|
||||
|
||||
function getHashSize() : uint;
|
||||
|
||||
function hash(param1:ByteArray) : ByteArray;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class MD2 implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 16;
|
||||
|
||||
private static const S:Array = [41,46,67,201,162,216,124,1,61,54,84,161,236,240,6,19,98,167,5,243,192,199,115,140,152,147,43,217,188,76,130,202,30,155,87,60,253,212,224,22,103,66,111,24,138,23,229,18,190,78,196,214,218,158,222,73,160,251,245,142,187,47,238,122,169,104,121,145,21,178,7,63,148,194,16,137,11,34,95,33,128,127,93,154,90,144,50,39,53,62,204,231,191,247,151,3,255,25,48,179,72,165,181,209,215,94,146,42,172,86,170,198,79,184,56,210,150,164,125,182,118,252,107,226,156,116,4,241,69,157,112,89,100,113,135,32,134,91,207,101,230,45,168,2,27,96,37,173,174,176,185,246,28,70,97,105,52,64,126,15,85,71,163,35,221,81,175,58,195,92,249,206,186,197,234,38,44,83,13,110,133,40,132,9,211,223,205,244,65,129,77,82,106,220,55,200,108,193,171,250,36,225,123,8,12,189,177,74,120,136,149,139,227,99,232,109,233,203,213,254,59,0,29,57,242,239,183,14,102,88,208,228,166,119,114,248,235,117,75,10,49,68,80,180,143,237,31,26,219,153,141,51,159,17,131,20];
|
||||
|
||||
public function MD2()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var j:uint = 0;
|
||||
var t:uint = 0;
|
||||
var k:uint = 0;
|
||||
var savedLength:uint = src.length;
|
||||
var i:uint = uint(uint(16 - src.length % 16) || 16);
|
||||
do
|
||||
{
|
||||
src[src.length] = i;
|
||||
}
|
||||
while(src.length % 16 != 0);
|
||||
var len:uint = src.length;
|
||||
var checksum:ByteArray = new ByteArray();
|
||||
var L:uint = 0;
|
||||
for(i = 0; i < len; i += 16)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
L = uint(checksum[j] = checksum[j] ^ S[src[i + j] ^ L]);
|
||||
}
|
||||
}
|
||||
src.position = src.length;
|
||||
src.writeBytes(checksum);
|
||||
len += 16;
|
||||
var X:ByteArray = new ByteArray();
|
||||
for(i = 0; i < len; i += 16)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
X[32 + j] = (X[16 + j] = src[i + j]) ^ X[j];
|
||||
}
|
||||
t = 0;
|
||||
for(j = 0; j < 18; j++)
|
||||
{
|
||||
for(k = 0; k < 48; k++)
|
||||
{
|
||||
X[k] = t = uint(X[k] ^ S[t]);
|
||||
}
|
||||
t = uint(t + j & 0xFF);
|
||||
}
|
||||
}
|
||||
X.length = 16;
|
||||
src.length = savedLength;
|
||||
return X;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "md2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
|
||||
public class MD5 implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 16;
|
||||
|
||||
public function MD5()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var len:uint = src.length * 8;
|
||||
var savedEndian:String = src.endian;
|
||||
while(src.length % 4 != 0)
|
||||
{
|
||||
src[src.length] = 0;
|
||||
}
|
||||
src.position = 0;
|
||||
var a:Array = [];
|
||||
src.endian = Endian.LITTLE_ENDIAN;
|
||||
for(var i:uint = 0; i < src.length; i += 4)
|
||||
{
|
||||
a.push(src.readUnsignedInt());
|
||||
}
|
||||
var h:Array = this.core_md5(a,len);
|
||||
var out:ByteArray = new ByteArray();
|
||||
out.endian = Endian.LITTLE_ENDIAN;
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
out.writeUnsignedInt(h[i]);
|
||||
}
|
||||
src.length = len / 8;
|
||||
src.endian = savedEndian;
|
||||
return out;
|
||||
}
|
||||
|
||||
private function core_md5(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
x[len >> 5] |= 128 << len % 32;
|
||||
x[(len + 64 >>> 9 << 4) + 14] = len;
|
||||
var a:uint = 1732584193;
|
||||
var b:uint = 4023233417;
|
||||
var c:uint = 2562383102;
|
||||
var d:uint = 271733878;
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
x[i] = x[i] || 0;
|
||||
x[i + 1] = x[i + 1] || 0;
|
||||
x[i + 2] = x[i + 2] || 0;
|
||||
x[i + 3] = x[i + 3] || 0;
|
||||
x[i + 4] = x[i + 4] || 0;
|
||||
x[i + 5] = x[i + 5] || 0;
|
||||
x[i + 6] = x[i + 6] || 0;
|
||||
x[i + 7] = x[i + 7] || 0;
|
||||
x[i + 8] = x[i + 8] || 0;
|
||||
x[i + 9] = x[i + 9] || 0;
|
||||
x[i + 10] = x[i + 10] || 0;
|
||||
x[i + 11] = x[i + 11] || 0;
|
||||
x[i + 12] = x[i + 12] || 0;
|
||||
x[i + 13] = x[i + 13] || 0;
|
||||
x[i + 14] = x[i + 14] || 0;
|
||||
x[i + 15] = x[i + 15] || 0;
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
a = this.ff(a,b,c,d,x[i + 0],7,3614090360);
|
||||
d = this.ff(d,a,b,c,x[i + 1],12,3905402710);
|
||||
c = this.ff(c,d,a,b,x[i + 2],17,606105819);
|
||||
b = this.ff(b,c,d,a,x[i + 3],22,3250441966);
|
||||
a = this.ff(a,b,c,d,x[i + 4],7,4118548399);
|
||||
d = this.ff(d,a,b,c,x[i + 5],12,1200080426);
|
||||
c = this.ff(c,d,a,b,x[i + 6],17,2821735955);
|
||||
b = this.ff(b,c,d,a,x[i + 7],22,4249261313);
|
||||
a = this.ff(a,b,c,d,x[i + 8],7,1770035416);
|
||||
d = this.ff(d,a,b,c,x[i + 9],12,2336552879);
|
||||
c = this.ff(c,d,a,b,x[i + 10],17,4294925233);
|
||||
b = this.ff(b,c,d,a,x[i + 11],22,2304563134);
|
||||
a = this.ff(a,b,c,d,x[i + 12],7,1804603682);
|
||||
d = this.ff(d,a,b,c,x[i + 13],12,4254626195);
|
||||
c = this.ff(c,d,a,b,x[i + 14],17,2792965006);
|
||||
b = this.ff(b,c,d,a,x[i + 15],22,1236535329);
|
||||
a = this.gg(a,b,c,d,x[i + 1],5,4129170786);
|
||||
d = this.gg(d,a,b,c,x[i + 6],9,3225465664);
|
||||
c = this.gg(c,d,a,b,x[i + 11],14,643717713);
|
||||
b = this.gg(b,c,d,a,x[i + 0],20,3921069994);
|
||||
a = this.gg(a,b,c,d,x[i + 5],5,3593408605);
|
||||
d = this.gg(d,a,b,c,x[i + 10],9,38016083);
|
||||
c = this.gg(c,d,a,b,x[i + 15],14,3634488961);
|
||||
b = this.gg(b,c,d,a,x[i + 4],20,3889429448);
|
||||
a = this.gg(a,b,c,d,x[i + 9],5,568446438);
|
||||
d = this.gg(d,a,b,c,x[i + 14],9,3275163606);
|
||||
c = this.gg(c,d,a,b,x[i + 3],14,4107603335);
|
||||
b = this.gg(b,c,d,a,x[i + 8],20,1163531501);
|
||||
a = this.gg(a,b,c,d,x[i + 13],5,2850285829);
|
||||
d = this.gg(d,a,b,c,x[i + 2],9,4243563512);
|
||||
c = this.gg(c,d,a,b,x[i + 7],14,1735328473);
|
||||
b = this.gg(b,c,d,a,x[i + 12],20,2368359562);
|
||||
a = this.hh(a,b,c,d,x[i + 5],4,4294588738);
|
||||
d = this.hh(d,a,b,c,x[i + 8],11,2272392833);
|
||||
c = this.hh(c,d,a,b,x[i + 11],16,1839030562);
|
||||
b = this.hh(b,c,d,a,x[i + 14],23,4259657740);
|
||||
a = this.hh(a,b,c,d,x[i + 1],4,2763975236);
|
||||
d = this.hh(d,a,b,c,x[i + 4],11,1272893353);
|
||||
c = this.hh(c,d,a,b,x[i + 7],16,4139469664);
|
||||
b = this.hh(b,c,d,a,x[i + 10],23,3200236656);
|
||||
a = this.hh(a,b,c,d,x[i + 13],4,681279174);
|
||||
d = this.hh(d,a,b,c,x[i + 0],11,3936430074);
|
||||
c = this.hh(c,d,a,b,x[i + 3],16,3572445317);
|
||||
b = this.hh(b,c,d,a,x[i + 6],23,76029189);
|
||||
a = this.hh(a,b,c,d,x[i + 9],4,3654602809);
|
||||
d = this.hh(d,a,b,c,x[i + 12],11,3873151461);
|
||||
c = this.hh(c,d,a,b,x[i + 15],16,530742520);
|
||||
b = this.hh(b,c,d,a,x[i + 2],23,3299628645);
|
||||
a = this.ii(a,b,c,d,x[i + 0],6,4096336452);
|
||||
d = this.ii(d,a,b,c,x[i + 7],10,1126891415);
|
||||
c = this.ii(c,d,a,b,x[i + 14],15,2878612391);
|
||||
b = this.ii(b,c,d,a,x[i + 5],21,4237533241);
|
||||
a = this.ii(a,b,c,d,x[i + 12],6,1700485571);
|
||||
d = this.ii(d,a,b,c,x[i + 3],10,2399980690);
|
||||
c = this.ii(c,d,a,b,x[i + 10],15,4293915773);
|
||||
b = this.ii(b,c,d,a,x[i + 1],21,2240044497);
|
||||
a = this.ii(a,b,c,d,x[i + 8],6,1873313359);
|
||||
d = this.ii(d,a,b,c,x[i + 15],10,4264355552);
|
||||
c = this.ii(c,d,a,b,x[i + 6],15,2734768916);
|
||||
b = this.ii(b,c,d,a,x[i + 13],21,1309151649);
|
||||
a = this.ii(a,b,c,d,x[i + 4],6,4149444226);
|
||||
d = this.ii(d,a,b,c,x[i + 11],10,3174756917);
|
||||
c = this.ii(c,d,a,b,x[i + 2],15,718787259);
|
||||
b = this.ii(b,c,d,a,x[i + 9],21,3951481745);
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
}
|
||||
return [a,b,c,d];
|
||||
}
|
||||
|
||||
private function rol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << cnt | num >>> 32 - cnt;
|
||||
}
|
||||
|
||||
private function cmn(q:uint, a:uint, b:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.rol(a + q + x + t,s) + b;
|
||||
}
|
||||
|
||||
private function ff(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b & c | ~b & d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function gg(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b & d | c & ~d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function hh(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b ^ c ^ d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function ii(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(c ^ (b | ~d),a,b,x,s,t);
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "md5";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA1 extends SHABase implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 20;
|
||||
|
||||
public function SHA1()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
override protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
var olde:uint = 0;
|
||||
var j:uint = 0;
|
||||
var t:uint = 0;
|
||||
x[len >> 5] |= 128 << 24 - len % 32;
|
||||
x[(len + 64 >> 9 << 4) + 15] = len;
|
||||
var w:Array = [];
|
||||
var a:uint = 1732584193;
|
||||
var b:uint = 4023233417;
|
||||
var c:uint = 2562383102;
|
||||
var d:uint = 271733878;
|
||||
var e:uint = 3285377520;
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
olde = e;
|
||||
for(j = 0; j < 80; j++)
|
||||
{
|
||||
if(j < 16)
|
||||
{
|
||||
w[j] = x[i + j] || 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
w[j] = this.rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16],1);
|
||||
}
|
||||
t = this.rol(a,5) + this.ft(j,b,c,d) + e + w[j] + this.kt(j);
|
||||
e = d;
|
||||
d = c;
|
||||
c = this.rol(b,30);
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
e += olde;
|
||||
}
|
||||
return [a,b,c,d,e];
|
||||
}
|
||||
|
||||
private function rol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << cnt | num >>> 32 - cnt;
|
||||
}
|
||||
|
||||
private function ft(t:uint, b:uint, c:uint, d:uint) : uint
|
||||
{
|
||||
if(t < 20)
|
||||
{
|
||||
return b & c | ~b & d;
|
||||
}
|
||||
if(t < 40)
|
||||
{
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
if(t < 60)
|
||||
{
|
||||
return b & c | b & d | c & d;
|
||||
}
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
|
||||
private function kt(t:uint) : uint
|
||||
{
|
||||
return t < 20 ? 1518500249 : (t < 40 ? 1859775393 : (t < 60 ? uint(2400959708) : uint(3395469782)));
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA224 extends SHA256
|
||||
{
|
||||
|
||||
public function SHA224()
|
||||
{
|
||||
super();
|
||||
_h = [3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428];
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return 28;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha224";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA256 extends SHABase implements IHash
|
||||
{
|
||||
|
||||
protected static const k:Array = [1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];
|
||||
|
||||
protected var _h:Array = [1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];
|
||||
|
||||
public function SHA256()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
override protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
var olde:uint = 0;
|
||||
var oldf:uint = 0;
|
||||
var oldg:uint = 0;
|
||||
var oldh:uint = 0;
|
||||
var j:uint = 0;
|
||||
var t2:uint = 0;
|
||||
var t1:uint = 0;
|
||||
var s0:uint = 0;
|
||||
var s1:uint = 0;
|
||||
x[len >> 5] |= 128 << 24 - len % 32;
|
||||
x[(len + 64 >> 9 << 4) + 15] = len;
|
||||
var w:Array = [];
|
||||
var a:uint = uint(this._h[0]);
|
||||
var b:uint = uint(this._h[1]);
|
||||
var c:uint = uint(this._h[2]);
|
||||
var d:uint = uint(this._h[3]);
|
||||
var e:uint = uint(this._h[4]);
|
||||
var f:uint = uint(this._h[5]);
|
||||
var g:uint = uint(this._h[6]);
|
||||
var h:uint = uint(this._h[7]);
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
olde = e;
|
||||
oldf = f;
|
||||
oldg = g;
|
||||
oldh = h;
|
||||
for(j = 0; j < 64; j++)
|
||||
{
|
||||
if(j < 16)
|
||||
{
|
||||
w[j] = x[i + j] || 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s0 = uint(this.rrol(w[j - 15],7) ^ this.rrol(w[j - 15],18) ^ w[j - 15] >>> 3);
|
||||
s1 = uint(this.rrol(w[j - 2],17) ^ this.rrol(w[j - 2],19) ^ w[j - 2] >>> 10);
|
||||
w[j] = w[j - 16] + s0 + w[j - 7] + s1;
|
||||
}
|
||||
t2 = (this.rrol(a,2) ^ this.rrol(a,13) ^ this.rrol(a,22)) + (a & b ^ a & c ^ b & c);
|
||||
t1 = h + (this.rrol(e,6) ^ this.rrol(e,11) ^ this.rrol(e,25)) + (e & f ^ g & ~e) + k[j] + w[j];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
e += olde;
|
||||
f += oldf;
|
||||
g += oldg;
|
||||
h += oldh;
|
||||
}
|
||||
return [a,b,c,d,e,f,g,h];
|
||||
}
|
||||
|
||||
protected function rrol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << 32 - cnt | num >>> cnt;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha256";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
|
||||
public class SHABase implements IHash
|
||||
{
|
||||
|
||||
public function SHABase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var savedLength:uint = src.length;
|
||||
var savedEndian:String = src.endian;
|
||||
src.endian = Endian.BIG_ENDIAN;
|
||||
var len:uint = savedLength * 8;
|
||||
while(src.length % 4 != 0)
|
||||
{
|
||||
src[src.length] = 0;
|
||||
}
|
||||
src.position = 0;
|
||||
var a:Array = [];
|
||||
for(var i:uint = 0; i < src.length; i += 4)
|
||||
{
|
||||
a.push(src.readUnsignedInt());
|
||||
}
|
||||
var h:Array = this.core(a,len);
|
||||
var out:ByteArray = new ByteArray();
|
||||
var words:uint = this.getHashSize() / 4;
|
||||
for(i = 0; i < words; i++)
|
||||
{
|
||||
out.writeUnsignedInt(h[i]);
|
||||
}
|
||||
src.length = savedLength;
|
||||
src.endian = savedEndian;
|
||||
return out;
|
||||
}
|
||||
|
||||
protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "sha";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import com.hurlant.crypto.symmetric.IStreamCipher;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ARC4 implements IPRNG, IStreamCipher
|
||||
{
|
||||
|
||||
private var i:int = 0;
|
||||
|
||||
private var j:int = 0;
|
||||
|
||||
private var S:ByteArray;
|
||||
|
||||
private const psize:uint = 256;
|
||||
|
||||
public function ARC4(key:ByteArray = null)
|
||||
{
|
||||
super();
|
||||
this.S = new ByteArray();
|
||||
if(Boolean(key))
|
||||
{
|
||||
this.init(key);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPoolSize() : uint
|
||||
{
|
||||
return this.psize;
|
||||
}
|
||||
|
||||
public function init(key:ByteArray) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var j:int = 0;
|
||||
var t:int = 0;
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
this.S[i] = i;
|
||||
}
|
||||
j = 0;
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
j = j + this.S[i] + key[i % key.length] & 0xFF;
|
||||
t = int(this.S[i]);
|
||||
this.S[i] = this.S[j];
|
||||
this.S[j] = t;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
}
|
||||
|
||||
public function next() : uint
|
||||
{
|
||||
var t:int = 0;
|
||||
this.i = this.i + 1 & 0xFF;
|
||||
this.j = this.j + this.S[this.i] & 0xFF;
|
||||
t = int(this.S[this.i]);
|
||||
this.S[this.i] = this.S[this.j];
|
||||
this.S[this.j] = t;
|
||||
return this.S[t + this.S[this.i] & 0xFF];
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
while(i < block.length)
|
||||
{
|
||||
var _temp_2:* = block;
|
||||
var _loc3_:uint = i++;
|
||||
_temp_2[_loc3_] ^= this.next();
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray) : void
|
||||
{
|
||||
this.encrypt(block);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
if(this.S != null)
|
||||
{
|
||||
for(i = 0; i < this.S.length; i++)
|
||||
{
|
||||
this.S[i] = Math.random() * 256;
|
||||
}
|
||||
this.S.length = 0;
|
||||
this.S = null;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "rc4";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IPRNG
|
||||
{
|
||||
|
||||
function getPoolSize() : uint;
|
||||
|
||||
function init(param1:ByteArray) : void;
|
||||
|
||||
function next() : uint;
|
||||
|
||||
function dispose() : void;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.system.Capabilities;
|
||||
import flash.system.System;
|
||||
import flash.text.Font;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
public class Random
|
||||
{
|
||||
|
||||
private var state:IPRNG;
|
||||
|
||||
private var ready:Boolean = false;
|
||||
|
||||
private var pool:ByteArray;
|
||||
|
||||
private var psize:int;
|
||||
|
||||
private var pptr:int;
|
||||
|
||||
private var seeded:Boolean = false;
|
||||
|
||||
public function Random(prng:Class = null)
|
||||
{
|
||||
var t:uint = 0;
|
||||
super();
|
||||
if(prng == null)
|
||||
{
|
||||
prng = ARC4;
|
||||
}
|
||||
this.state = new prng() as IPRNG;
|
||||
this.psize = this.state.getPoolSize();
|
||||
this.pool = new ByteArray();
|
||||
this.pptr = 0;
|
||||
while(this.pptr < this.psize)
|
||||
{
|
||||
t = 65536 * Math.random();
|
||||
this.pool[this.pptr++] = t >>> 8;
|
||||
this.pool[this.pptr++] = t & 0xFF;
|
||||
}
|
||||
this.pptr = 0;
|
||||
this.seed();
|
||||
}
|
||||
|
||||
public function seed(x:int = 0) : void
|
||||
{
|
||||
if(x == 0)
|
||||
{
|
||||
x = new Date().getTime();
|
||||
}
|
||||
var _temp_3:* = this.pool;
|
||||
var _loc2_:Number = this.pptr++;
|
||||
_temp_3[_loc2_] ^= x & 0xFF;
|
||||
var _temp_6:* = this.pool;
|
||||
var _loc3_:Number = this.pptr++;
|
||||
_temp_6[_loc3_] ^= x >> 8 & 0xFF;
|
||||
var _temp_9:* = this.pool;
|
||||
var _loc4_:Number = this.pptr++;
|
||||
_temp_9[_loc4_] ^= x >> 16 & 0xFF;
|
||||
var _temp_12:* = this.pool;
|
||||
var _loc5_:Number = this.pptr++;
|
||||
_temp_12[_loc5_] ^= x >> 24 & 0xFF;
|
||||
this.pptr %= this.psize;
|
||||
this.seeded = true;
|
||||
}
|
||||
|
||||
public function autoSeed() : void
|
||||
{
|
||||
var f:Font = null;
|
||||
var b:ByteArray = new ByteArray();
|
||||
b.writeUnsignedInt(System.totalMemory);
|
||||
b.writeUTF(Capabilities.serverString);
|
||||
b.writeUnsignedInt(getTimer());
|
||||
b.writeUnsignedInt(new Date().getTime());
|
||||
var a:Array = Font.enumerateFonts(true);
|
||||
for each(f in a)
|
||||
{
|
||||
b.writeUTF(f.fontName);
|
||||
b.writeUTF(f.fontStyle);
|
||||
b.writeUTF(f.fontType);
|
||||
}
|
||||
b.position = 0;
|
||||
while(b.bytesAvailable >= 4)
|
||||
{
|
||||
this.seed(b.readUnsignedInt());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextBytes(buffer:ByteArray, length:int) : void
|
||||
{
|
||||
while(Boolean(length--))
|
||||
{
|
||||
buffer.writeByte(this.nextByte());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextByte() : int
|
||||
{
|
||||
if(!this.ready)
|
||||
{
|
||||
if(!this.seeded)
|
||||
{
|
||||
this.autoSeed();
|
||||
}
|
||||
this.state.init(this.pool);
|
||||
this.pool.length = 0;
|
||||
this.pptr = 0;
|
||||
this.ready = true;
|
||||
}
|
||||
return this.state.next();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
for(var i:uint = 0; i < this.pool.length; i++)
|
||||
{
|
||||
this.pool[i] = Math.random() * 256;
|
||||
}
|
||||
this.pool.length = 0;
|
||||
this.pool = null;
|
||||
this.state.dispose();
|
||||
this.state = null;
|
||||
this.psize = 0;
|
||||
this.pptr = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "random-" + this.state.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
package com.hurlant.crypto.rsa
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.math.BigInteger;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class RSAKey
|
||||
{
|
||||
|
||||
public var e:int;
|
||||
|
||||
public var n:BigInteger;
|
||||
|
||||
public var d:BigInteger;
|
||||
|
||||
public var p:BigInteger;
|
||||
|
||||
public var q:BigInteger;
|
||||
|
||||
public var dmp1:BigInteger;
|
||||
|
||||
public var dmq1:BigInteger;
|
||||
|
||||
public var coeff:BigInteger;
|
||||
|
||||
protected var canDecrypt:Boolean;
|
||||
|
||||
protected var canEncrypt:Boolean;
|
||||
|
||||
public function RSAKey(N:BigInteger, E:int, D:BigInteger = null, P:BigInteger = null, Q:BigInteger = null, DP:BigInteger = null, DQ:BigInteger = null, C:BigInteger = null)
|
||||
{
|
||||
super();
|
||||
this.n = N;
|
||||
this.e = E;
|
||||
this.d = D;
|
||||
this.p = P;
|
||||
this.q = Q;
|
||||
this.dmp1 = DP;
|
||||
this.dmq1 = DQ;
|
||||
this.coeff = C;
|
||||
this.canEncrypt = this.n != null && this.e != 0;
|
||||
this.canDecrypt = this.canEncrypt && this.d != null;
|
||||
}
|
||||
|
||||
public static function parsePublicKey(N:String, E:String) : RSAKey
|
||||
{
|
||||
return new RSAKey(new BigInteger(N,16),parseInt(E,16));
|
||||
}
|
||||
|
||||
public static function parsePrivateKey(N:String, E:String, D:String, P:String = null, Q:String = null, DMP1:String = null, DMQ1:String = null, IQMP:String = null) : RSAKey
|
||||
{
|
||||
if(P == null)
|
||||
{
|
||||
return new RSAKey(new BigInteger(N,16),parseInt(E,16),new BigInteger(D,16));
|
||||
}
|
||||
return new RSAKey(new BigInteger(N,16),parseInt(E,16),new BigInteger(D,16),new BigInteger(P,16),new BigInteger(Q,16),new BigInteger(DMP1,16),new BigInteger(DMQ1),new BigInteger(IQMP));
|
||||
}
|
||||
|
||||
public static function generate(B:uint, E:String) : RSAKey
|
||||
{
|
||||
var p1:BigInteger = null;
|
||||
var q1:BigInteger = null;
|
||||
var phi:BigInteger = null;
|
||||
var t:BigInteger = null;
|
||||
var rng:Random = new Random();
|
||||
var qs:uint = uint(B >> 1);
|
||||
var key:RSAKey = new RSAKey(null,0,null);
|
||||
key.e = parseInt(E,16);
|
||||
for(var ee:BigInteger = new BigInteger(E,16); true; )
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
key.p = bigRandom(B - qs,rng);
|
||||
if(key.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && key.p.isProbablePrime(10))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
key.q = bigRandom(qs,rng);
|
||||
if(key.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && key.q.isProbablePrime(10))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(key.p.compareTo(key.q) <= 0)
|
||||
{
|
||||
t = key.p;
|
||||
key.p = key.q;
|
||||
key.q = t;
|
||||
}
|
||||
p1 = key.p.subtract(BigInteger.ONE);
|
||||
q1 = key.q.subtract(BigInteger.ONE);
|
||||
phi = p1.multiply(q1);
|
||||
if(phi.gcd(ee).compareTo(BigInteger.ONE) == 0)
|
||||
{
|
||||
key.n = key.p.multiply(key.q);
|
||||
key.d = ee.modInverse(phi);
|
||||
key.dmp1 = key.d.mod(p1);
|
||||
key.dmq1 = key.d.mod(q1);
|
||||
key.coeff = key.q.modInverse(key.p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
protected static function bigRandom(bits:int, rnd:Random) : BigInteger
|
||||
{
|
||||
if(bits < 2)
|
||||
{
|
||||
return BigInteger.nbv(1);
|
||||
}
|
||||
var x:ByteArray = new ByteArray();
|
||||
rnd.nextBytes(x,bits >> 3);
|
||||
x.position = 0;
|
||||
var b:BigInteger = new BigInteger(x);
|
||||
b.primify(bits,1);
|
||||
return b;
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return (this.n.bitLength() + 7) / 8;
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.e = 0;
|
||||
this.n.dispose();
|
||||
this.n = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._encrypt(this.doPublic,src,dst,length,pad,2);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._decrypt(this.doPrivate2,src,dst,length,pad,2);
|
||||
}
|
||||
|
||||
public function sign(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._encrypt(this.doPrivate2,src,dst,length,pad,1);
|
||||
}
|
||||
|
||||
public function verify(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._decrypt(this.doPublic,src,dst,length,pad,1);
|
||||
}
|
||||
|
||||
private function _encrypt(op:Function, src:ByteArray, dst:ByteArray, length:uint, pad:Function, padType:int) : void
|
||||
{
|
||||
var block:BigInteger = null;
|
||||
var chunk:BigInteger = null;
|
||||
if(pad == null)
|
||||
{
|
||||
pad = this.pkcs1pad;
|
||||
}
|
||||
if(src.position >= src.length)
|
||||
{
|
||||
src.position = 0;
|
||||
}
|
||||
var bl:uint = this.getBlockSize();
|
||||
var end:int = src.position + length;
|
||||
while(src.position < end)
|
||||
{
|
||||
block = new BigInteger(pad(src,end,bl,padType),bl);
|
||||
chunk = op(block);
|
||||
chunk.toArray(dst);
|
||||
}
|
||||
}
|
||||
|
||||
private function _decrypt(op:Function, src:ByteArray, dst:ByteArray, length:uint, pad:Function, padType:int) : void
|
||||
{
|
||||
var block:BigInteger = null;
|
||||
var chunk:BigInteger = null;
|
||||
var b:ByteArray = null;
|
||||
if(pad == null)
|
||||
{
|
||||
pad = this.pkcs1unpad;
|
||||
}
|
||||
if(src.position >= src.length)
|
||||
{
|
||||
src.position = 0;
|
||||
}
|
||||
var bl:uint = this.getBlockSize();
|
||||
var end:int = src.position + length;
|
||||
while(src.position < end)
|
||||
{
|
||||
block = new BigInteger(src,length);
|
||||
chunk = op(block);
|
||||
b = pad(chunk,bl);
|
||||
dst.writeBytes(b);
|
||||
}
|
||||
}
|
||||
|
||||
private function pkcs1pad(src:ByteArray, end:int, n:uint, type:uint = 2) : ByteArray
|
||||
{
|
||||
var x:int = 0;
|
||||
var out:ByteArray = new ByteArray();
|
||||
var p:int = int(src.position);
|
||||
end = Math.min(end,src.length,p + n - 11);
|
||||
src.position = end;
|
||||
var i:int = end - 1;
|
||||
while(i >= p && n > 11)
|
||||
{
|
||||
out[--n] = src[i--];
|
||||
}
|
||||
out[--n] = 0;
|
||||
var rng:Random = new Random();
|
||||
while(n > 2)
|
||||
{
|
||||
for(x = 0; x == 0; )
|
||||
{
|
||||
x = type == 2 ? rng.nextByte() : 255;
|
||||
}
|
||||
out[--n] = x;
|
||||
}
|
||||
out[--n] = type;
|
||||
out[--n] = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
private function pkcs1unpad(src:BigInteger, n:uint, type:uint = 2) : ByteArray
|
||||
{
|
||||
var b:ByteArray = src.toByteArray();
|
||||
var out:ByteArray = new ByteArray();
|
||||
var i:int = 0;
|
||||
while(i < b.length && b[i] == 0)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if(b.length - i != n - 1 || b[i] > 2)
|
||||
{
|
||||
trace("PKCS#1 unpad: i=" + i + ", expected b[i]==[0,1,2], got b[i]=" + b[i].toString(16));
|
||||
return null;
|
||||
}
|
||||
i++;
|
||||
while(b[i] != 0)
|
||||
{
|
||||
if(++i >= b.length)
|
||||
{
|
||||
trace("PKCS#1 unpad: i=" + i + ", b[i-1]!=0 (=" + b[i - 1].toString(16) + ")");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
while(++i < b.length)
|
||||
{
|
||||
out.writeByte(b[i]);
|
||||
}
|
||||
out.position = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
private function rawpad(src:ByteArray, end:int, n:uint) : ByteArray
|
||||
{
|
||||
return src;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "rsa";
|
||||
}
|
||||
|
||||
public function dump() : String
|
||||
{
|
||||
var s:String = "N=" + this.n.toString(16) + "\n" + "E=" + this.e.toString(16) + "\n";
|
||||
if(this.canDecrypt)
|
||||
{
|
||||
s += "D=" + this.d.toString(16) + "\n";
|
||||
if(this.p != null && this.q != null)
|
||||
{
|
||||
s += "P=" + this.p.toString(16) + "\n";
|
||||
s += "Q=" + this.q.toString(16) + "\n";
|
||||
s += "DMP1=" + this.dmp1.toString(16) + "\n";
|
||||
s += "DMQ1=" + this.dmq1.toString(16) + "\n";
|
||||
s += "IQMP=" + this.coeff.toString(16) + "\n";
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
protected function doPublic(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x.modPowInt(this.e,this.n);
|
||||
}
|
||||
|
||||
protected function doPrivate2(x:BigInteger) : BigInteger
|
||||
{
|
||||
if(this.p == null && this.q == null)
|
||||
{
|
||||
return x.modPow(this.d,this.n);
|
||||
}
|
||||
var xp:BigInteger = x.mod(this.p).modPow(this.dmp1,this.p);
|
||||
var xq:BigInteger = x.mod(this.q).modPow(this.dmq1,this.q);
|
||||
while(xp.compareTo(xq) < 0)
|
||||
{
|
||||
xp = xp.add(this.p);
|
||||
}
|
||||
return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
|
||||
}
|
||||
|
||||
protected function doPrivate(x:BigInteger) : BigInteger
|
||||
{
|
||||
if(this.p == null || this.q == null)
|
||||
{
|
||||
return x.modPow(this.d,this.n);
|
||||
}
|
||||
var xp:BigInteger = x.mod(this.p).modPow(this.dmp1,this.p);
|
||||
var xq:BigInteger = x.mod(this.q).modPow(this.dmq1,this.q);
|
||||
while(xp.compareTo(xq) < 0)
|
||||
{
|
||||
xp = xp.add(this.p);
|
||||
}
|
||||
return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class AESKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
private static const Nb:uint = 4;
|
||||
|
||||
private static const _Sbox:Array = [99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22];
|
||||
|
||||
private static const _InvSbox:Array = [82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125];
|
||||
|
||||
private static const _Xtime2Sbox:Array = [198,248,238,246,255,214,222,145,96,2,206,86,231,181,77,236,143,31,137,250,239,178,142,251,65,179,95,69,35,83,228,155,117,225,61,76,108,126,245,131,104,81,209,249,226,171,98,42,8,149,70,157,48,55,10,47,14,36,27,223,205,78,127,234,18,29,88,52,54,220,180,91,164,118,183,125,82,221,94,19,166,185,0,193,64,227,121,182,212,141,103,114,148,152,176,133,187,197,79,237,134,154,102,17,138,233,4,254,160,120,37,75,162,93,128,5,63,33,112,241,99,119,175,66,32,229,253,191,129,24,38,195,190,53,136,46,147,85,252,122,200,186,50,230,192,25,158,163,68,84,59,11,140,199,107,40,167,188,22,173,219,100,116,20,146,12,72,184,159,189,67,196,57,49,211,242,213,139,110,218,1,177,156,73,216,172,243,207,202,244,71,16,111,240,74,92,56,87,115,151,203,161,232,62,150,97,13,15,224,124,113,204,144,6,247,28,194,106,174,105,23,153,58,39,217,235,43,34,210,169,7,51,45,60,21,201,135,170,80,165,3,89,9,26,101,215,132,208,130,41,90,30,123,168,109,44];
|
||||
|
||||
private static const _Xtime3Sbox:Array = [165,132,153,141,13,189,177,84,80,3,169,125,25,98,230,154,69,157,64,135,21,235,201,11,236,103,253,234,191,247,150,91,194,28,174,106,90,65,2,79,92,244,52,8,147,115,83,63,12,82,101,94,40,161,15,181,9,54,155,61,38,105,205,159,27,158,116,46,45,178,238,251,246,77,97,206,123,62,113,151,245,104,0,44,96,31,200,237,190,70,217,75,222,212,232,74,107,42,229,22,197,215,85,148,207,16,6,129,240,68,186,227,243,254,192,138,173,188,72,4,223,193,117,99,48,26,14,109,76,20,53,47,225,162,204,57,87,242,130,71,172,231,43,149,160,152,209,127,102,126,171,131,202,41,211,60,121,226,29,118,59,86,78,30,219,10,108,228,93,110,239,166,168,164,55,139,50,67,89,183,140,100,210,224,180,250,7,37,175,142,233,24,213,136,111,114,36,241,199,81,35,124,156,33,221,220,134,133,144,66,196,170,216,5,1,18,163,95,249,208,145,88,39,185,56,19,179,51,187,112,137,167,182,34,146,32,73,255,120,122,143,248,128,23,218,49,198,184,195,176,119,17,203,252,214,58];
|
||||
|
||||
private static const _Xtime2:Array = [0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,27,25,31,29,19,17,23,21,11,9,15,13,3,1,7,5,59,57,63,61,51,49,55,53,43,41,47,45,35,33,39,37,91,89,95,93,83,81,87,85,75,73,79,77,67,65,71,69,123,121,127,125,115,113,119,117,107,105,111,109,99,97,103,101,155,153,159,157,147,145,151,149,139,137,143,141,131,129,135,133,187,185,191,189,179,177,183,181,171,169,175,173,163,161,167,165,219,217,223,221,211,209,215,213,203,201,207,205,195,193,199,197,251,249,255,253,243,241,247,245,235,233,239,237,227,225,231,229];
|
||||
|
||||
private static const _Xtime9:Array = [0,9,18,27,36,45,54,63,72,65,90,83,108,101,126,119,144,153,130,139,180,189,166,175,216,209,202,195,252,245,238,231,59,50,41,32,31,22,13,4,115,122,97,104,87,94,69,76,171,162,185,176,143,134,157,148,227,234,241,248,199,206,213,220,118,127,100,109,82,91,64,73,62,55,44,37,26,19,8,1,230,239,244,253,194,203,208,217,174,167,188,181,138,131,152,145,77,68,95,86,105,96,123,114,5,12,23,30,33,40,51,58,221,212,207,198,249,240,235,226,149,156,135,142,177,184,163,170,236,229,254,247,200,193,218,211,164,173,182,191,128,137,146,155,124,117,110,103,88,81,74,67,52,61,38,47,16,25,2,11,215,222,197,204,243,250,225,232,159,150,141,132,187,178,169,160,71,78,85,92,99,106,113,120,15,6,29,20,43,34,57,48,154,147,136,129,190,183,172,165,210,219,192,201,246,255,228,237,10,3,24,17,46,39,60,53,66,75,80,89,102,111,116,125,161,168,179,186,133,140,151,158,233,224,251,242,205,196,223,214,49,56,35,42,21,28,7,14,121,112,107,98,93,84,79,70];
|
||||
|
||||
private static const _XtimeB:Array = [0,11,22,29,44,39,58,49,88,83,78,69,116,127,98,105,176,187,166,173,156,151,138,129,232,227,254,245,196,207,210,217,123,112,109,102,87,92,65,74,35,40,53,62,15,4,25,18,203,192,221,214,231,236,241,250,147,152,133,142,191,180,169,162,246,253,224,235,218,209,204,199,174,165,184,179,130,137,148,159,70,77,80,91,106,97,124,119,30,21,8,3,50,57,36,47,141,134,155,144,161,170,183,188,213,222,195,200,249,242,239,228,61,54,43,32,17,26,7,12,101,110,115,120,73,66,95,84,247,252,225,234,219,208,205,198,175,164,185,178,131,136,149,158,71,76,81,90,107,96,125,118,31,20,9,2,51,56,37,46,140,135,154,145,160,171,182,189,212,223,194,201,248,243,238,229,60,55,42,33,16,27,6,13,100,111,114,121,72,67,94,85,1,10,23,28,45,38,59,48,89,82,79,68,117,126,99,104,177,186,167,172,157,150,139,128,233,226,255,244,197,206,211,216,122,113,108,103,86,93,64,75,34,41,52,63,14,5,24,19,202,193,220,215,230,237,240,251,146,153,132,143,190,181,168,163];
|
||||
|
||||
private static const _XtimeD:Array = [0,13,26,23,52,57,46,35,104,101,114,127,92,81,70,75,208,221,202,199,228,233,254,243,184,181,162,175,140,129,150,155,187,182,161,172,143,130,149,152,211,222,201,196,231,234,253,240,107,102,113,124,95,82,69,72,3,14,25,20,55,58,45,32,109,96,119,122,89,84,67,78,5,8,31,18,49,60,43,38,189,176,167,170,137,132,147,158,213,216,207,194,225,236,251,246,214,219,204,193,226,239,248,245,190,179,164,169,138,135,144,157,6,11,28,17,50,63,40,37,110,99,116,121,90,87,64,77,218,215,192,205,238,227,244,249,178,191,168,165,134,139,156,145,10,7,16,29,62,51,36,41,98,111,120,117,86,91,76,65,97,108,123,118,85,88,79,66,9,4,19,30,61,48,39,42,177,188,171,166,133,136,159,146,217,212,195,206,237,224,247,250,183,186,173,160,131,142,153,148,223,210,197,200,235,230,241,252,103,106,125,112,83,94,73,68,15,2,21,24,59,54,33,44,12,1,22,27,56,53,34,47,100,105,126,115,80,93,74,71,220,209,198,203,232,229,242,255,180,185,174,163,128,141,154,151];
|
||||
|
||||
private static const _XtimeE:Array = [0,14,28,18,56,54,36,42,112,126,108,98,72,70,84,90,224,238,252,242,216,214,196,202,144,158,140,130,168,166,180,186,219,213,199,201,227,237,255,241,171,165,183,185,147,157,143,129,59,53,39,41,3,13,31,17,75,69,87,89,115,125,111,97,173,163,177,191,149,155,137,135,221,211,193,207,229,235,249,247,77,67,81,95,117,123,105,103,61,51,33,47,5,11,25,23,118,120,106,100,78,64,82,92,6,8,26,20,62,48,34,44,150,152,138,132,174,160,178,188,230,232,250,244,222,208,194,204,65,79,93,83,121,119,101,107,49,63,45,35,9,7,21,27,161,175,189,179,153,151,133,139,209,223,205,195,233,231,245,251,154,148,134,136,162,172,190,176,234,228,246,248,210,220,206,192,122,116,102,104,66,76,94,80,10,4,22,24,50,60,46,32,236,226,240,254,212,218,200,198,156,146,128,142,164,170,184,182,12,2,16,30,52,58,40,38,124,114,96,110,68,74,88,86,55,57,43,37,15,1,19,29,71,73,91,85,127,113,99,109,215,217,203,197,239,225,243,253,167,169,187,181,159,145,131,141];
|
||||
|
||||
private static var _Rcon:Array = [0,1,2,4,8,16,32,64,128,27,54];
|
||||
|
||||
private static var Sbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var InvSbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime2Sbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime3Sbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime2:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime9:ByteArray = new ByteArray();
|
||||
|
||||
private static var XtimeB:ByteArray = new ByteArray();
|
||||
|
||||
private static var XtimeD:ByteArray = new ByteArray();
|
||||
|
||||
private static var XtimeE:ByteArray = new ByteArray();
|
||||
|
||||
private static var i:uint = 0;
|
||||
|
||||
while(i < 256)
|
||||
{
|
||||
Sbox[i] = _Sbox[i];
|
||||
InvSbox[i] = _InvSbox[i];
|
||||
Xtime2Sbox[i] = _Xtime2Sbox[i];
|
||||
Xtime3Sbox[i] = _Xtime3Sbox[i];
|
||||
Xtime2[i] = _Xtime2[i];
|
||||
Xtime9[i] = _Xtime9[i];
|
||||
XtimeB[i] = _XtimeB[i];
|
||||
XtimeD[i] = _XtimeD[i];
|
||||
XtimeE[i] = _XtimeE[i];
|
||||
++i;
|
||||
}
|
||||
|
||||
private static var Rcon:ByteArray = new ByteArray();
|
||||
|
||||
i = 0;
|
||||
while(i < _Rcon.length)
|
||||
{
|
||||
Rcon[i] = _Rcon[i];
|
||||
++i;
|
||||
}
|
||||
|
||||
private var key:ByteArray;
|
||||
|
||||
private var keyLength:uint;
|
||||
|
||||
private var Nr:uint;
|
||||
|
||||
private var state:ByteArray;
|
||||
|
||||
private var tmp:ByteArray;
|
||||
|
||||
public function AESKey(key:ByteArray)
|
||||
{
|
||||
super();
|
||||
this.tmp = new ByteArray();
|
||||
this.state = new ByteArray();
|
||||
this.keyLength = key.length;
|
||||
this.key = new ByteArray();
|
||||
this.key.writeBytes(key);
|
||||
this.expandKey();
|
||||
}
|
||||
|
||||
private function expandKey() : void
|
||||
{
|
||||
var tmp0:uint = 0;
|
||||
var tmp1:uint = 0;
|
||||
var tmp2:uint = 0;
|
||||
var tmp3:uint = 0;
|
||||
var tmp4:uint = 0;
|
||||
var idx:uint = 0;
|
||||
var Nk:uint = this.key.length / 4;
|
||||
this.Nr = Nk + 6;
|
||||
for(idx = Nk; idx < Nb * (this.Nr + 1); idx++)
|
||||
{
|
||||
tmp0 = uint(this.key[4 * idx - 4]);
|
||||
tmp1 = uint(this.key[4 * idx - 3]);
|
||||
tmp2 = uint(this.key[4 * idx - 2]);
|
||||
tmp3 = uint(this.key[4 * idx - 1]);
|
||||
if(!(idx % Nk))
|
||||
{
|
||||
tmp4 = tmp3;
|
||||
tmp3 = uint(Sbox[tmp0]);
|
||||
tmp0 = uint(Sbox[tmp1] ^ Rcon[idx / Nk]);
|
||||
tmp1 = uint(Sbox[tmp2]);
|
||||
tmp2 = uint(Sbox[tmp4]);
|
||||
}
|
||||
else if(Nk > 6 && idx % Nk == 4)
|
||||
{
|
||||
tmp0 = uint(Sbox[tmp0]);
|
||||
tmp1 = uint(Sbox[tmp1]);
|
||||
tmp2 = uint(Sbox[tmp2]);
|
||||
tmp3 = uint(Sbox[tmp3]);
|
||||
}
|
||||
this.key[4 * idx + 0] = this.key[4 * idx - 4 * Nk + 0] ^ tmp0;
|
||||
this.key[4 * idx + 1] = this.key[4 * idx - 4 * Nk + 1] ^ tmp1;
|
||||
this.key[4 * idx + 2] = this.key[4 * idx - 4 * Nk + 2] ^ tmp2;
|
||||
this.key[4 * idx + 3] = this.key[4 * idx - 4 * Nk + 3] ^ tmp3;
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var round:uint = 0;
|
||||
this.state.position = 0;
|
||||
this.state.writeBytes(block,index,Nb * 4);
|
||||
this.addRoundKey(this.key,0);
|
||||
for(round = 1; round < this.Nr + 1; round++)
|
||||
{
|
||||
if(round < this.Nr)
|
||||
{
|
||||
this.mixSubColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.shiftRows();
|
||||
}
|
||||
this.addRoundKey(this.key,round * Nb * 4);
|
||||
}
|
||||
block.position = index;
|
||||
block.writeBytes(this.state);
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var round:uint = 0;
|
||||
this.state.position = 0;
|
||||
this.state.writeBytes(block,index,Nb * 4);
|
||||
this.addRoundKey(this.key,this.Nr * Nb * 4);
|
||||
this.invShiftRows();
|
||||
for(round = this.Nr; Boolean(round--); )
|
||||
{
|
||||
this.addRoundKey(this.key,round * Nb * 4);
|
||||
if(Boolean(round))
|
||||
{
|
||||
this.invMixSubColumns();
|
||||
}
|
||||
}
|
||||
block.position = index;
|
||||
block.writeBytes(this.state);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
var r:Random = new Random();
|
||||
for(i = 0; i < this.key.length; i++)
|
||||
{
|
||||
this.key[i] = r.nextByte();
|
||||
}
|
||||
this.Nr = r.nextByte();
|
||||
for(i = 0; i < this.state.length; i++)
|
||||
{
|
||||
this.state[i] = r.nextByte();
|
||||
}
|
||||
for(i = 0; i < this.tmp.length; i++)
|
||||
{
|
||||
this.tmp[i] = r.nextByte();
|
||||
}
|
||||
this.key.length = 0;
|
||||
this.keyLength = 0;
|
||||
this.state.length = 0;
|
||||
this.tmp.length = 0;
|
||||
this.key = null;
|
||||
this.state = null;
|
||||
this.tmp = null;
|
||||
this.Nr = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
protected function shiftRows() : void
|
||||
{
|
||||
var tmp:uint = 0;
|
||||
this.state[0] = Sbox[this.state[0]];
|
||||
this.state[4] = Sbox[this.state[4]];
|
||||
this.state[8] = Sbox[this.state[8]];
|
||||
this.state[12] = Sbox[this.state[12]];
|
||||
tmp = uint(Sbox[this.state[1]]);
|
||||
this.state[1] = Sbox[this.state[5]];
|
||||
this.state[5] = Sbox[this.state[9]];
|
||||
this.state[9] = Sbox[this.state[13]];
|
||||
this.state[13] = tmp;
|
||||
tmp = uint(Sbox[this.state[2]]);
|
||||
this.state[2] = Sbox[this.state[10]];
|
||||
this.state[10] = tmp;
|
||||
tmp = uint(Sbox[this.state[6]]);
|
||||
this.state[6] = Sbox[this.state[14]];
|
||||
this.state[14] = tmp;
|
||||
tmp = uint(Sbox[this.state[15]]);
|
||||
this.state[15] = Sbox[this.state[11]];
|
||||
this.state[11] = Sbox[this.state[7]];
|
||||
this.state[7] = Sbox[this.state[3]];
|
||||
this.state[3] = tmp;
|
||||
}
|
||||
|
||||
protected function invShiftRows() : void
|
||||
{
|
||||
var tmp:uint = 0;
|
||||
this.state[0] = InvSbox[this.state[0]];
|
||||
this.state[4] = InvSbox[this.state[4]];
|
||||
this.state[8] = InvSbox[this.state[8]];
|
||||
this.state[12] = InvSbox[this.state[12]];
|
||||
tmp = uint(InvSbox[this.state[13]]);
|
||||
this.state[13] = InvSbox[this.state[9]];
|
||||
this.state[9] = InvSbox[this.state[5]];
|
||||
this.state[5] = InvSbox[this.state[1]];
|
||||
this.state[1] = tmp;
|
||||
tmp = uint(InvSbox[this.state[2]]);
|
||||
this.state[2] = InvSbox[this.state[10]];
|
||||
this.state[10] = tmp;
|
||||
tmp = uint(InvSbox[this.state[6]]);
|
||||
this.state[6] = InvSbox[this.state[14]];
|
||||
this.state[14] = tmp;
|
||||
tmp = uint(InvSbox[this.state[3]]);
|
||||
this.state[3] = InvSbox[this.state[7]];
|
||||
this.state[7] = InvSbox[this.state[11]];
|
||||
this.state[11] = InvSbox[this.state[15]];
|
||||
this.state[15] = tmp;
|
||||
}
|
||||
|
||||
protected function mixSubColumns() : void
|
||||
{
|
||||
this.tmp.length = 0;
|
||||
this.tmp[0] = Xtime2Sbox[this.state[0]] ^ Xtime3Sbox[this.state[5]] ^ Sbox[this.state[10]] ^ Sbox[this.state[15]];
|
||||
this.tmp[1] = Sbox[this.state[0]] ^ Xtime2Sbox[this.state[5]] ^ Xtime3Sbox[this.state[10]] ^ Sbox[this.state[15]];
|
||||
this.tmp[2] = Sbox[this.state[0]] ^ Sbox[this.state[5]] ^ Xtime2Sbox[this.state[10]] ^ Xtime3Sbox[this.state[15]];
|
||||
this.tmp[3] = Xtime3Sbox[this.state[0]] ^ Sbox[this.state[5]] ^ Sbox[this.state[10]] ^ Xtime2Sbox[this.state[15]];
|
||||
this.tmp[4] = Xtime2Sbox[this.state[4]] ^ Xtime3Sbox[this.state[9]] ^ Sbox[this.state[14]] ^ Sbox[this.state[3]];
|
||||
this.tmp[5] = Sbox[this.state[4]] ^ Xtime2Sbox[this.state[9]] ^ Xtime3Sbox[this.state[14]] ^ Sbox[this.state[3]];
|
||||
this.tmp[6] = Sbox[this.state[4]] ^ Sbox[this.state[9]] ^ Xtime2Sbox[this.state[14]] ^ Xtime3Sbox[this.state[3]];
|
||||
this.tmp[7] = Xtime3Sbox[this.state[4]] ^ Sbox[this.state[9]] ^ Sbox[this.state[14]] ^ Xtime2Sbox[this.state[3]];
|
||||
this.tmp[8] = Xtime2Sbox[this.state[8]] ^ Xtime3Sbox[this.state[13]] ^ Sbox[this.state[2]] ^ Sbox[this.state[7]];
|
||||
this.tmp[9] = Sbox[this.state[8]] ^ Xtime2Sbox[this.state[13]] ^ Xtime3Sbox[this.state[2]] ^ Sbox[this.state[7]];
|
||||
this.tmp[10] = Sbox[this.state[8]] ^ Sbox[this.state[13]] ^ Xtime2Sbox[this.state[2]] ^ Xtime3Sbox[this.state[7]];
|
||||
this.tmp[11] = Xtime3Sbox[this.state[8]] ^ Sbox[this.state[13]] ^ Sbox[this.state[2]] ^ Xtime2Sbox[this.state[7]];
|
||||
this.tmp[12] = Xtime2Sbox[this.state[12]] ^ Xtime3Sbox[this.state[1]] ^ Sbox[this.state[6]] ^ Sbox[this.state[11]];
|
||||
this.tmp[13] = Sbox[this.state[12]] ^ Xtime2Sbox[this.state[1]] ^ Xtime3Sbox[this.state[6]] ^ Sbox[this.state[11]];
|
||||
this.tmp[14] = Sbox[this.state[12]] ^ Sbox[this.state[1]] ^ Xtime2Sbox[this.state[6]] ^ Xtime3Sbox[this.state[11]];
|
||||
this.tmp[15] = Xtime3Sbox[this.state[12]] ^ Sbox[this.state[1]] ^ Sbox[this.state[6]] ^ Xtime2Sbox[this.state[11]];
|
||||
this.state.position = 0;
|
||||
this.state.writeBytes(this.tmp,0,Nb * 4);
|
||||
}
|
||||
|
||||
protected function invMixSubColumns() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
this.tmp.length = 0;
|
||||
this.tmp[0] = XtimeE[this.state[0]] ^ XtimeB[this.state[1]] ^ XtimeD[this.state[2]] ^ Xtime9[this.state[3]];
|
||||
this.tmp[5] = Xtime9[this.state[0]] ^ XtimeE[this.state[1]] ^ XtimeB[this.state[2]] ^ XtimeD[this.state[3]];
|
||||
this.tmp[10] = XtimeD[this.state[0]] ^ Xtime9[this.state[1]] ^ XtimeE[this.state[2]] ^ XtimeB[this.state[3]];
|
||||
this.tmp[15] = XtimeB[this.state[0]] ^ XtimeD[this.state[1]] ^ Xtime9[this.state[2]] ^ XtimeE[this.state[3]];
|
||||
this.tmp[4] = XtimeE[this.state[4]] ^ XtimeB[this.state[5]] ^ XtimeD[this.state[6]] ^ Xtime9[this.state[7]];
|
||||
this.tmp[9] = Xtime9[this.state[4]] ^ XtimeE[this.state[5]] ^ XtimeB[this.state[6]] ^ XtimeD[this.state[7]];
|
||||
this.tmp[14] = XtimeD[this.state[4]] ^ Xtime9[this.state[5]] ^ XtimeE[this.state[6]] ^ XtimeB[this.state[7]];
|
||||
this.tmp[3] = XtimeB[this.state[4]] ^ XtimeD[this.state[5]] ^ Xtime9[this.state[6]] ^ XtimeE[this.state[7]];
|
||||
this.tmp[8] = XtimeE[this.state[8]] ^ XtimeB[this.state[9]] ^ XtimeD[this.state[10]] ^ Xtime9[this.state[11]];
|
||||
this.tmp[13] = Xtime9[this.state[8]] ^ XtimeE[this.state[9]] ^ XtimeB[this.state[10]] ^ XtimeD[this.state[11]];
|
||||
this.tmp[2] = XtimeD[this.state[8]] ^ Xtime9[this.state[9]] ^ XtimeE[this.state[10]] ^ XtimeB[this.state[11]];
|
||||
this.tmp[7] = XtimeB[this.state[8]] ^ XtimeD[this.state[9]] ^ Xtime9[this.state[10]] ^ XtimeE[this.state[11]];
|
||||
this.tmp[12] = XtimeE[this.state[12]] ^ XtimeB[this.state[13]] ^ XtimeD[this.state[14]] ^ Xtime9[this.state[15]];
|
||||
this.tmp[1] = Xtime9[this.state[12]] ^ XtimeE[this.state[13]] ^ XtimeB[this.state[14]] ^ XtimeD[this.state[15]];
|
||||
this.tmp[6] = XtimeD[this.state[12]] ^ Xtime9[this.state[13]] ^ XtimeE[this.state[14]] ^ XtimeB[this.state[15]];
|
||||
this.tmp[11] = XtimeB[this.state[12]] ^ XtimeD[this.state[13]] ^ Xtime9[this.state[14]] ^ XtimeE[this.state[15]];
|
||||
for(i = 0; i < 4 * Nb; i++)
|
||||
{
|
||||
this.state[i] = InvSbox[this.tmp[i]];
|
||||
}
|
||||
}
|
||||
|
||||
protected function addRoundKey(key:ByteArray, offset:uint) : void
|
||||
{
|
||||
var idx:uint = 0;
|
||||
for(idx = 0; idx < 16; idx++)
|
||||
{
|
||||
this.state[idx] ^= key[idx + offset];
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "aes" + 8 * this.keyLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class BlowFishKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
private static const KP:Array = [608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731];
|
||||
|
||||
private static const KS0:Array = [3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486
|
||||
,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737
|
||||
,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946];
|
||||
|
||||
private static const KS1:Array = [1266315497,3048417604,3681880366,3289982499,2909710000,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616
|
||||
,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670
|
||||
,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055];
|
||||
|
||||
private static const KS2:Array = [3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280
|
||||
,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629
|
||||
,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504];
|
||||
|
||||
private static const KS3:Array = [976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805
|
||||
,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409000,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506
|
||||
,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462];
|
||||
|
||||
private static const ROUNDS:uint = 16;
|
||||
|
||||
private static const BLOCK_SIZE:uint = 8;
|
||||
|
||||
private static const SBOX_SK:uint = 256;
|
||||
|
||||
private static const P_SZ:uint = ROUNDS + 2;
|
||||
|
||||
private var S0:Array;
|
||||
|
||||
private var S1:Array;
|
||||
|
||||
private var S2:Array;
|
||||
|
||||
private var S3:Array;
|
||||
|
||||
private var P:Array;
|
||||
|
||||
private var key:ByteArray = null;
|
||||
|
||||
public function BlowFishKey(key:ByteArray)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
this.setKey(key);
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return BLOCK_SIZE;
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.decryptBlock(block,index,block,index);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
i = 0;
|
||||
while(i < this.S0.length)
|
||||
{
|
||||
this.S0[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.S1.length)
|
||||
{
|
||||
this.S1[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.S2.length)
|
||||
{
|
||||
this.S2[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.S3.length)
|
||||
{
|
||||
this.S3[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.P.length)
|
||||
{
|
||||
this.P[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.S0 = null;
|
||||
this.S1 = null;
|
||||
this.S2 = null;
|
||||
this.S3 = null;
|
||||
this.P = null;
|
||||
for(i = 0; i < this.key.length; i++)
|
||||
{
|
||||
this.key[i] = 0;
|
||||
}
|
||||
this.key.length = 0;
|
||||
this.key = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.encryptBlock(block,index,block,index);
|
||||
}
|
||||
|
||||
private function F(x:uint) : uint
|
||||
{
|
||||
return (this.S0[x >>> 24] + this.S1[x >>> 16 & 0xFF] ^ this.S2[x >>> 8 & 0xFF]) + this.S3[x & 0xFF];
|
||||
}
|
||||
|
||||
private function processTable(xl:uint, xr:uint, table:Array) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
var size:uint = table.length;
|
||||
for(var s:uint = 0; s < size; s += 2)
|
||||
{
|
||||
xl ^= this.P[0];
|
||||
for(i = 1; i < ROUNDS; i += 2)
|
||||
{
|
||||
xr ^= this.F(xl) ^ this.P[i];
|
||||
xl ^= this.F(xr) ^ this.P[i + 1];
|
||||
}
|
||||
xr ^= this.P[ROUNDS + 1];
|
||||
table[s] = xr;
|
||||
table[s + 1] = xl;
|
||||
xr = xl;
|
||||
xl = uint(table[s]);
|
||||
}
|
||||
}
|
||||
|
||||
private function setKey(key:ByteArray) : void
|
||||
{
|
||||
var data:uint = 0;
|
||||
var j:uint = 0;
|
||||
this.S0 = KS0.concat();
|
||||
this.S1 = KS1.concat();
|
||||
this.S2 = KS2.concat();
|
||||
this.S3 = KS3.concat();
|
||||
this.P = KP.concat();
|
||||
var keyLength:uint = key.length;
|
||||
var keyIndex:uint = 0;
|
||||
for(var i:uint = 0; i < P_SZ; i++)
|
||||
{
|
||||
data = 0;
|
||||
for(j = 0; j < 4; j++)
|
||||
{
|
||||
data = uint(data << 8 | key[keyIndex++] & 0xFF);
|
||||
if(keyIndex >= keyLength)
|
||||
{
|
||||
keyIndex = 0;
|
||||
}
|
||||
}
|
||||
this.P[i] ^= data;
|
||||
}
|
||||
this.processTable(0,0,this.P);
|
||||
this.processTable(this.P[P_SZ - 2],this.P[P_SZ - 1],this.S0);
|
||||
this.processTable(this.S0[SBOX_SK - 2],this.S0[SBOX_SK - 1],this.S1);
|
||||
this.processTable(this.S1[SBOX_SK - 2],this.S1[SBOX_SK - 1],this.S2);
|
||||
this.processTable(this.S2[SBOX_SK - 2],this.S2[SBOX_SK - 1],this.S3);
|
||||
}
|
||||
|
||||
private function encryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint) : void
|
||||
{
|
||||
var xl:uint = this.BytesTo32bits(src,srcIndex);
|
||||
var xr:uint = this.BytesTo32bits(src,srcIndex + 4);
|
||||
xl ^= this.P[0];
|
||||
for(var i:uint = 1; i < ROUNDS; i += 2)
|
||||
{
|
||||
xr ^= this.F(xl) ^ this.P[i];
|
||||
xl ^= this.F(xr) ^ this.P[i + 1];
|
||||
}
|
||||
xr ^= this.P[ROUNDS + 1];
|
||||
this.Bits32ToBytes(xr,dst,dstIndex);
|
||||
this.Bits32ToBytes(xl,dst,dstIndex + 4);
|
||||
}
|
||||
|
||||
private function decryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint) : void
|
||||
{
|
||||
var xl:uint = this.BytesTo32bits(src,srcIndex);
|
||||
var xr:uint = this.BytesTo32bits(src,srcIndex + 4);
|
||||
xl ^= this.P[ROUNDS + 1];
|
||||
for(var i:uint = ROUNDS; i > 0; i -= 2)
|
||||
{
|
||||
xr ^= this.F(xl) ^ this.P[i];
|
||||
xl ^= this.F(xr) ^ this.P[i - 1];
|
||||
}
|
||||
xr ^= this.P[0];
|
||||
this.Bits32ToBytes(xr,dst,dstIndex);
|
||||
this.Bits32ToBytes(xl,dst,dstIndex + 4);
|
||||
}
|
||||
|
||||
private function BytesTo32bits(b:ByteArray, i:uint) : uint
|
||||
{
|
||||
return (b[i] & 0xFF) << 24 | (b[i + 1] & 0xFF) << 16 | (b[i + 2] & 0xFF) << 8 | b[i + 3] & 0xFF;
|
||||
}
|
||||
|
||||
private function Bits32ToBytes(i:uint, b:ByteArray, offset:uint) : void
|
||||
{
|
||||
b[offset + 3] = i;
|
||||
b[offset + 2] = i >> 8;
|
||||
b[offset + 1] = i >> 16;
|
||||
b[offset] = i >> 24;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "blowfish";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CBCMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CBCMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,padding);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
padding.pad(src);
|
||||
var vector:ByteArray = getIV4e();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
for(j = 0; j < blockSize; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
key.encrypt(src,i);
|
||||
vector.position = 0;
|
||||
vector.writeBytes(src,i,blockSize);
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
var vector:ByteArray = getIV4d();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(src,i,blockSize);
|
||||
key.decrypt(src,i);
|
||||
for(j = 0; j < blockSize; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
vector.position = 0;
|
||||
vector.writeBytes(tmp,0,blockSize);
|
||||
}
|
||||
padding.unpad(src);
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-cbc";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CFB8Mode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CFB8Mode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,null);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
var vector:ByteArray = getIV4e();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i++)
|
||||
{
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(vector);
|
||||
key.encrypt(vector);
|
||||
src[i] ^= vector[0];
|
||||
for(j = 0; j < blockSize - 1; j++)
|
||||
{
|
||||
vector[j] = tmp[j + 1];
|
||||
}
|
||||
vector[blockSize - 1] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var c:uint = 0;
|
||||
var j:uint = 0;
|
||||
var vector:ByteArray = getIV4d();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i++)
|
||||
{
|
||||
c = uint(src[i]);
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(vector);
|
||||
key.encrypt(vector);
|
||||
src[i] ^= vector[0];
|
||||
for(j = 0; j < blockSize - 1; j++)
|
||||
{
|
||||
vector[j] = tmp[j + 1];
|
||||
}
|
||||
vector[blockSize - 1] = c;
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-cfb8";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CFBMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CFBMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,null);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var chunk:uint = 0;
|
||||
var j:uint = 0;
|
||||
var l:uint = src.length;
|
||||
var vector:ByteArray = getIV4e();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
key.encrypt(vector);
|
||||
chunk = i + blockSize < l ? blockSize : uint(l - i);
|
||||
for(j = 0; j < chunk; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
vector.position = 0;
|
||||
vector.writeBytes(src,i,chunk);
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var chunk:uint = 0;
|
||||
var j:uint = 0;
|
||||
var l:uint = src.length;
|
||||
var vector:ByteArray = getIV4d();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
key.encrypt(vector);
|
||||
chunk = i + blockSize < l ? blockSize : uint(l - i);
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(src,i,chunk);
|
||||
for(j = 0; j < chunk; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
vector.position = 0;
|
||||
vector.writeBytes(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-cfb";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CTRMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CTRMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,padding);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
padding.pad(src);
|
||||
var vector:ByteArray = getIV4e();
|
||||
this.core(src,vector);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var vector:ByteArray = getIV4d();
|
||||
this.core(src,vector);
|
||||
padding.unpad(src);
|
||||
}
|
||||
|
||||
private function core(src:ByteArray, iv:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
var X:ByteArray = new ByteArray();
|
||||
var Xenc:ByteArray = new ByteArray();
|
||||
X.writeBytes(iv);
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
Xenc.position = 0;
|
||||
Xenc.writeBytes(X);
|
||||
key.encrypt(Xenc);
|
||||
for(j = 0; j < blockSize; j++)
|
||||
{
|
||||
src[i + j] ^= Xenc[j];
|
||||
}
|
||||
for(j = blockSize - 1; j >= 0; j--)
|
||||
{
|
||||
++X[j];
|
||||
if(X[j] != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-ctr";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class DESKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
private static const Df_Key:Array = [1,35,69,103,137,171,205,239,254,220,186,152,118,84,50,16,137,171,205,239,1,35,69,103];
|
||||
|
||||
private static const bytebit:Array = [128,64,32,16,8,4,2,1];
|
||||
|
||||
private static const bigbyte:Array = [8388608,4194304,2097152,1048576,524288,262144,131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1];
|
||||
|
||||
private static const pc1:Array = [56,48,40,32,24,16,8,0,57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,60,52,44,36,28,20,12,4,27,19,11,3];
|
||||
|
||||
private static const totrot:Array = [1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28];
|
||||
|
||||
private static const pc2:Array = [13,16,10,23,0,4,2,27,14,5,20,9,22,18,11,3,25,7,15,6,26,19,12,1,40,51,30,36,46,54,29,39,50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31];
|
||||
|
||||
private static const SP1:Array = [16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756];
|
||||
|
||||
private static const SP2:Array = [2148565024,2147516416,32768,1081376,1048576,32,2148532256,2147516448,2147483680,2148565024,2148564992,2147483648,2147516416,1048576,32,2148532256,1081344,1048608,2147516448,0,2147483648,32768,1081376,2148532224,1048608,2147483680,0,1081344,32800,2148564992,2148532224,32800,0,1081376,2148532256,1048576,2147516448,2148532224,2148564992,32768,2148532224,2147516416,32,2148565024,1081376,32,32768,2147483648,32800,2148564992,1048576,2147483680,1048608,2147516448,2147483680,1048608,1081344,0,2147516416,32800,2147483648,2148532256,2148565024,1081344];
|
||||
|
||||
private static const SP3:Array = [520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584];
|
||||
|
||||
private static const SP4:Array = [8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928];
|
||||
|
||||
private static const SP5:Array = [256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080];
|
||||
|
||||
private static const SP6:Array = [536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312];
|
||||
|
||||
private static const SP7:Array = [2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154];
|
||||
|
||||
private static const SP8:Array = [268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];
|
||||
|
||||
protected var key:ByteArray;
|
||||
|
||||
protected var encKey:Array;
|
||||
|
||||
protected var decKey:Array;
|
||||
|
||||
public function DESKey(key:ByteArray)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
this.encKey = this.generateWorkingKey(true,key,0);
|
||||
this.decKey = this.generateWorkingKey(false,key,0);
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.desFunc(this.decKey,block,index,block,index);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
i = 0;
|
||||
while(i < this.encKey.length)
|
||||
{
|
||||
this.encKey[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.decKey.length)
|
||||
{
|
||||
this.decKey[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.encKey = null;
|
||||
this.decKey = null;
|
||||
i = 0;
|
||||
while(i < this.key.length)
|
||||
{
|
||||
this.key[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.key.length = 0;
|
||||
this.key = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.desFunc(this.encKey,block,index,block,index);
|
||||
}
|
||||
|
||||
protected function generateWorkingKey(encrypting:Boolean, key:ByteArray, off:uint) : Array
|
||||
{
|
||||
var l:uint = 0;
|
||||
var m:uint = 0;
|
||||
var n:uint = 0;
|
||||
var i1:uint = 0;
|
||||
var i2:uint = 0;
|
||||
var newKey:Array = [];
|
||||
var pc1m:ByteArray = new ByteArray();
|
||||
var pcr:ByteArray = new ByteArray();
|
||||
for(var j:uint = 0; j < 56; j++)
|
||||
{
|
||||
l = uint(pc1[j]);
|
||||
pc1m[j] = (key[off + (l >>> 3)] & bytebit[l & 7]) != 0;
|
||||
}
|
||||
for(var i:uint = 0; i < 16; i++)
|
||||
{
|
||||
if(encrypting)
|
||||
{
|
||||
m = uint(i << 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m = uint(15 - i << 1);
|
||||
}
|
||||
n = m + 1;
|
||||
newKey[m] = newKey[n] = 0;
|
||||
for(j = 0; j < 28; j++)
|
||||
{
|
||||
l = j + totrot[i];
|
||||
if(l < 28)
|
||||
{
|
||||
pcr[j] = pc1m[l];
|
||||
}
|
||||
else
|
||||
{
|
||||
pcr[j] = pc1m[l - 28];
|
||||
}
|
||||
}
|
||||
for(j = 28; j < 56; j++)
|
||||
{
|
||||
l = j + totrot[i];
|
||||
if(l < 56)
|
||||
{
|
||||
pcr[j] = pc1m[l];
|
||||
}
|
||||
else
|
||||
{
|
||||
pcr[j] = pc1m[l - 28];
|
||||
}
|
||||
}
|
||||
for(j = 0; j < 24; j++)
|
||||
{
|
||||
if(Boolean(pcr[pc2[j]]))
|
||||
{
|
||||
newKey[m] |= bigbyte[j];
|
||||
}
|
||||
if(Boolean(pcr[pc2[j + 24]]))
|
||||
{
|
||||
newKey[n] |= bigbyte[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i = 0; i != 32; i += 2)
|
||||
{
|
||||
i1 = uint(newKey[i]);
|
||||
i2 = uint(newKey[i + 1]);
|
||||
newKey[i] = (i1 & 0xFC0000) << 6 | (i1 & 0x0FC0) << 10 | (i2 & 0xFC0000) >>> 10 | (i2 & 0x0FC0) >>> 6;
|
||||
newKey[i + 1] = (i1 & 0x03F000) << 12 | (i1 & 0x3F) << 16 | (i2 & 0x03F000) >>> 4 | i2 & 0x3F;
|
||||
}
|
||||
return newKey;
|
||||
}
|
||||
|
||||
protected function desFunc(wKey:Array, inp:ByteArray, inOff:uint, out:ByteArray, outOff:uint) : void
|
||||
{
|
||||
var work:uint = 0;
|
||||
var right:uint = 0;
|
||||
var left:uint = 0;
|
||||
var fval:uint = 0;
|
||||
left = uint((inp[inOff + 0] & 0xFF) << 24);
|
||||
left |= (inp[inOff + 1] & 0xFF) << 16;
|
||||
left |= (inp[inOff + 2] & 0xFF) << 8;
|
||||
left |= inp[inOff + 3] & 0xFF;
|
||||
right = uint((inp[inOff + 4] & 0xFF) << 24);
|
||||
right |= (inp[inOff + 5] & 0xFF) << 16;
|
||||
right |= (inp[inOff + 6] & 0xFF) << 8;
|
||||
right |= inp[inOff + 7] & 0xFF;
|
||||
work = uint((left >>> 4 ^ right) & 0x0F0F0F0F);
|
||||
right ^= work;
|
||||
left ^= work << 4;
|
||||
work = uint((left >>> 16 ^ right) & 0xFFFF);
|
||||
right ^= work;
|
||||
left ^= work << 16;
|
||||
work = uint((right >>> 2 ^ left) & 0x33333333);
|
||||
left ^= work;
|
||||
right ^= work << 2;
|
||||
work = uint((right >>> 8 ^ left) & 0xFF00FF);
|
||||
left ^= work;
|
||||
right ^= work << 8;
|
||||
right = uint((right << 1 | right >>> 31 & 1) & 0xFFFFFFFF);
|
||||
work = uint((left ^ right) & 0xAAAAAAAA);
|
||||
left ^= work;
|
||||
right ^= work;
|
||||
left = uint((left << 1 | left >>> 31 & 1) & 0xFFFFFFFF);
|
||||
for(var round:uint = 0; round < 8; round++)
|
||||
{
|
||||
work = uint(right << 28 | right >>> 4);
|
||||
work ^= wKey[round * 4 + 0];
|
||||
fval = uint(SP7[work & 0x3F]);
|
||||
fval |= SP5[work >>> 8 & 0x3F];
|
||||
fval |= SP3[work >>> 16 & 0x3F];
|
||||
fval |= SP1[work >>> 24 & 0x3F];
|
||||
work = uint(right ^ wKey[round * 4 + 1]);
|
||||
fval |= SP8[work & 0x3F];
|
||||
fval |= SP6[work >>> 8 & 0x3F];
|
||||
fval |= SP4[work >>> 16 & 0x3F];
|
||||
fval |= SP2[work >>> 24 & 0x3F];
|
||||
left ^= fval;
|
||||
work = uint(left << 28 | left >>> 4);
|
||||
work ^= wKey[round * 4 + 2];
|
||||
fval = uint(SP7[work & 0x3F]);
|
||||
fval |= SP5[work >>> 8 & 0x3F];
|
||||
fval |= SP3[work >>> 16 & 0x3F];
|
||||
fval |= SP1[work >>> 24 & 0x3F];
|
||||
work = uint(left ^ wKey[round * 4 + 3]);
|
||||
fval |= SP8[work & 0x3F];
|
||||
fval |= SP6[work >>> 8 & 0x3F];
|
||||
fval |= SP4[work >>> 16 & 0x3F];
|
||||
fval |= SP2[work >>> 24 & 0x3F];
|
||||
right ^= fval;
|
||||
}
|
||||
right = uint(right << 31 | right >>> 1);
|
||||
work = uint((left ^ right) & 0xAAAAAAAA);
|
||||
left ^= work;
|
||||
right ^= work;
|
||||
left = uint(left << 31 | left >>> 1);
|
||||
work = uint((left >>> 8 ^ right) & 0xFF00FF);
|
||||
right ^= work;
|
||||
left ^= work << 8;
|
||||
work = uint((left >>> 2 ^ right) & 0x33333333);
|
||||
right ^= work;
|
||||
left ^= work << 2;
|
||||
work = uint((right >>> 16 ^ left) & 0xFFFF);
|
||||
left ^= work;
|
||||
right ^= work << 16;
|
||||
work = uint((right >>> 4 ^ left) & 0x0F0F0F0F);
|
||||
left ^= work;
|
||||
right ^= work << 4;
|
||||
out[outOff + 0] = right >>> 24 & 0xFF;
|
||||
out[outOff + 1] = right >>> 16 & 0xFF;
|
||||
out[outOff + 2] = right >>> 8 & 0xFF;
|
||||
out[outOff + 3] = right & 0xFF;
|
||||
out[outOff + 4] = left >>> 24 & 0xFF;
|
||||
out[outOff + 5] = left >>> 16 & 0xFF;
|
||||
out[outOff + 6] = left >>> 8 & 0xFF;
|
||||
out[outOff + 7] = left & 0xFF;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "des";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ECBMode implements IMode, ICipher
|
||||
{
|
||||
|
||||
private var key:ISymmetricKey;
|
||||
|
||||
private var padding:IPad;
|
||||
|
||||
public function ECBMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
if(padding == null)
|
||||
{
|
||||
padding = new PKCS5(key.getBlockSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
padding.setBlockSize(key.getBlockSize());
|
||||
}
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return this.key.getBlockSize();
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
this.padding.pad(src);
|
||||
src.position = 0;
|
||||
var blockSize:uint = this.key.getBlockSize();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
var dst:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
tmp.length = 0;
|
||||
src.readBytes(tmp,0,blockSize);
|
||||
this.key.encrypt(tmp);
|
||||
dst.writeBytes(tmp);
|
||||
}
|
||||
src.length = 0;
|
||||
src.writeBytes(dst);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
src.position = 0;
|
||||
var blockSize:uint = this.key.getBlockSize();
|
||||
if(src.length % blockSize != 0)
|
||||
{
|
||||
throw new Error("ECB mode cipher length must be a multiple of blocksize " + blockSize);
|
||||
}
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
var dst:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
tmp.length = 0;
|
||||
src.readBytes(tmp,0,blockSize);
|
||||
this.key.decrypt(tmp);
|
||||
dst.writeBytes(tmp);
|
||||
}
|
||||
this.padding.unpad(dst);
|
||||
src.length = 0;
|
||||
src.writeBytes(dst);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.key.dispose();
|
||||
this.key = null;
|
||||
this.padding = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return this.key.toString() + "-ecb";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface ICipher
|
||||
{
|
||||
|
||||
function getBlockSize() : uint;
|
||||
|
||||
function encrypt(param1:ByteArray) : void;
|
||||
|
||||
function decrypt(param1:ByteArray) : void;
|
||||
|
||||
function dispose() : void;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
public interface IMode extends ICipher
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IPad
|
||||
{
|
||||
|
||||
function pad(param1:ByteArray) : void;
|
||||
|
||||
function unpad(param1:ByteArray) : void;
|
||||
|
||||
function setBlockSize(param1:uint) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
public interface IStreamCipher extends ICipher
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface ISymmetricKey
|
||||
{
|
||||
|
||||
function getBlockSize() : uint;
|
||||
|
||||
function encrypt(param1:ByteArray, param2:uint = 0) : void;
|
||||
|
||||
function decrypt(param1:ByteArray, param2:uint = 0) : void;
|
||||
|
||||
function dispose() : void;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class IVMode
|
||||
{
|
||||
|
||||
protected var key:ISymmetricKey;
|
||||
|
||||
protected var padding:IPad;
|
||||
|
||||
protected var prng:Random;
|
||||
|
||||
protected var iv:ByteArray;
|
||||
|
||||
protected var lastIV:ByteArray;
|
||||
|
||||
protected var blockSize:uint;
|
||||
|
||||
public function IVMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
this.blockSize = key.getBlockSize();
|
||||
if(padding == null)
|
||||
{
|
||||
padding = new PKCS5(this.blockSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
padding.setBlockSize(this.blockSize);
|
||||
}
|
||||
this.padding = padding;
|
||||
this.prng = new Random();
|
||||
this.iv = null;
|
||||
this.lastIV = new ByteArray();
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return this.key.getBlockSize();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
if(this.iv != null)
|
||||
{
|
||||
for(i = 0; i < this.iv.length; i++)
|
||||
{
|
||||
this.iv[i] = this.prng.nextByte();
|
||||
}
|
||||
this.iv.length = 0;
|
||||
this.iv = null;
|
||||
}
|
||||
if(this.lastIV != null)
|
||||
{
|
||||
for(i = 0; i < this.iv.length; i++)
|
||||
{
|
||||
this.lastIV[i] = this.prng.nextByte();
|
||||
}
|
||||
this.lastIV.length = 0;
|
||||
this.lastIV = null;
|
||||
}
|
||||
this.key.dispose();
|
||||
this.key = null;
|
||||
this.padding = null;
|
||||
this.prng.dispose();
|
||||
this.prng = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function set IV(value:ByteArray) : void
|
||||
{
|
||||
this.iv = value;
|
||||
this.lastIV.length = 0;
|
||||
this.lastIV.writeBytes(this.iv);
|
||||
}
|
||||
|
||||
public function get IV() : ByteArray
|
||||
{
|
||||
return this.lastIV;
|
||||
}
|
||||
|
||||
protected function getIV4e() : ByteArray
|
||||
{
|
||||
var vec:ByteArray = new ByteArray();
|
||||
if(Boolean(this.iv))
|
||||
{
|
||||
vec.writeBytes(this.iv);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.prng.nextBytes(vec,this.blockSize);
|
||||
}
|
||||
this.lastIV.length = 0;
|
||||
this.lastIV.writeBytes(vec);
|
||||
return vec;
|
||||
}
|
||||
|
||||
protected function getIV4d() : ByteArray
|
||||
{
|
||||
var vec:ByteArray = new ByteArray();
|
||||
if(Boolean(this.iv))
|
||||
{
|
||||
vec.writeBytes(this.iv);
|
||||
return vec;
|
||||
}
|
||||
throw new Error("an IV must be set before calling decrypt()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class NullPad implements IPad
|
||||
{
|
||||
|
||||
public function NullPad()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function unpad(a:ByteArray) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function pad(a:ByteArray) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function setBlockSize(bs:uint) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class OFBMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function OFBMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,null);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var vector:ByteArray = getIV4e();
|
||||
this.core(src,vector);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var vector:ByteArray = getIV4d();
|
||||
this.core(src,vector);
|
||||
}
|
||||
|
||||
private function core(src:ByteArray, iv:ByteArray) : void
|
||||
{
|
||||
var chunk:uint = 0;
|
||||
var j:uint = 0;
|
||||
var l:uint = src.length;
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
key.encrypt(iv);
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(iv);
|
||||
chunk = i + blockSize < l ? blockSize : uint(l - i);
|
||||
for(j = 0; j < chunk; j++)
|
||||
{
|
||||
src[i + j] ^= iv[j];
|
||||
}
|
||||
iv.position = 0;
|
||||
iv.writeBytes(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-ofb";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class PKCS5 implements IPad
|
||||
{
|
||||
|
||||
private var blockSize:uint;
|
||||
|
||||
public function PKCS5(blockSize:uint = 0)
|
||||
{
|
||||
super();
|
||||
this.blockSize = blockSize;
|
||||
}
|
||||
|
||||
public function pad(a:ByteArray) : void
|
||||
{
|
||||
var c:uint = this.blockSize - a.length % this.blockSize;
|
||||
for(var i:uint = 0; i < c; i++)
|
||||
{
|
||||
a[a.length] = c;
|
||||
}
|
||||
}
|
||||
|
||||
public function unpad(a:ByteArray) : void
|
||||
{
|
||||
var v:uint = 0;
|
||||
var c:uint = a.length % this.blockSize;
|
||||
if(c != 0)
|
||||
{
|
||||
throw new Error("PKCS#5::unpad: ByteArray.length isn\'t a multiple of the blockSize");
|
||||
}
|
||||
c = uint(a[a.length - 1]);
|
||||
for(var i:uint = c; i > 0; i--)
|
||||
{
|
||||
v = uint(a[a.length - 1]);
|
||||
--a.length;
|
||||
if(c != v)
|
||||
{
|
||||
throw new Error("PKCS#5:unpad: Invalid padding value. expected [" + c + "], found [" + v + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setBlockSize(bs:uint) : void
|
||||
{
|
||||
this.blockSize = bs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class SimpleIVMode implements IMode, ICipher
|
||||
{
|
||||
|
||||
protected var mode:IVMode;
|
||||
|
||||
protected var cipher:ICipher;
|
||||
|
||||
public function SimpleIVMode(mode:IVMode)
|
||||
{
|
||||
super();
|
||||
this.mode = mode;
|
||||
this.cipher = mode as ICipher;
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return this.mode.getBlockSize();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.mode.dispose();
|
||||
this.mode = null;
|
||||
this.cipher = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
this.cipher.encrypt(src);
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
tmp.writeBytes(this.mode.IV);
|
||||
tmp.writeBytes(src);
|
||||
src.position = 0;
|
||||
src.writeBytes(tmp);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
tmp.writeBytes(src,0,this.getBlockSize());
|
||||
this.mode.IV = tmp;
|
||||
tmp = new ByteArray();
|
||||
tmp.writeBytes(src,this.getBlockSize());
|
||||
this.cipher.decrypt(tmp);
|
||||
src.length = 0;
|
||||
src.writeBytes(tmp);
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "simple-" + this.cipher.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class TripleDESKey extends DESKey
|
||||
{
|
||||
|
||||
protected var encKey2:Array;
|
||||
|
||||
protected var encKey3:Array;
|
||||
|
||||
protected var decKey2:Array;
|
||||
|
||||
protected var decKey3:Array;
|
||||
|
||||
public function TripleDESKey(key:ByteArray)
|
||||
{
|
||||
super(key);
|
||||
this.encKey2 = generateWorkingKey(false,key,8);
|
||||
this.decKey2 = generateWorkingKey(true,key,8);
|
||||
if(key.length > 16)
|
||||
{
|
||||
this.encKey3 = generateWorkingKey(true,key,16);
|
||||
this.decKey3 = generateWorkingKey(false,key,16);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.encKey3 = encKey;
|
||||
this.decKey3 = decKey;
|
||||
}
|
||||
}
|
||||
|
||||
override public function dispose() : void
|
||||
{
|
||||
super.dispose();
|
||||
var i:uint = 0;
|
||||
if(this.encKey2 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.encKey2.length)
|
||||
{
|
||||
this.encKey2[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.encKey2 = null;
|
||||
}
|
||||
if(this.encKey3 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.encKey3.length)
|
||||
{
|
||||
this.encKey3[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.encKey3 = null;
|
||||
}
|
||||
if(this.decKey2 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.decKey2.length)
|
||||
{
|
||||
this.decKey2[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.decKey2 = null;
|
||||
}
|
||||
if(this.decKey3 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.decKey3.length)
|
||||
{
|
||||
this.decKey3[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.decKey3 = null;
|
||||
}
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
override public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
desFunc(encKey,block,index,block,index);
|
||||
desFunc(this.encKey2,block,index,block,index);
|
||||
desFunc(this.encKey3,block,index,block,index);
|
||||
}
|
||||
|
||||
override public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
desFunc(this.decKey3,block,index,block,index);
|
||||
desFunc(this.decKey2,block,index,block,index);
|
||||
desFunc(decKey,block,index,block,index);
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "3des";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class XTeaKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
public const NUM_ROUNDS:uint = 64;
|
||||
|
||||
private var k:Array;
|
||||
|
||||
public function XTeaKey(a:ByteArray)
|
||||
{
|
||||
super();
|
||||
a.position = 0;
|
||||
this.k = [a.readUnsignedInt(),a.readUnsignedInt(),a.readUnsignedInt(),a.readUnsignedInt()];
|
||||
}
|
||||
|
||||
public static function parseKey(K:String) : XTeaKey
|
||||
{
|
||||
var a:ByteArray = new ByteArray();
|
||||
a.writeUnsignedInt(parseInt(K.substr(0,8),16));
|
||||
a.writeUnsignedInt(parseInt(K.substr(8,8),16));
|
||||
a.writeUnsignedInt(parseInt(K.substr(16,8),16));
|
||||
a.writeUnsignedInt(parseInt(K.substr(24,8),16));
|
||||
a.position = 0;
|
||||
return new XTeaKey(a);
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
block.position = index;
|
||||
var v0:uint = block.readUnsignedInt();
|
||||
var v1:uint = block.readUnsignedInt();
|
||||
var sum:uint = 0;
|
||||
var delta:uint = 2654435769;
|
||||
for(i = 0; i < this.NUM_ROUNDS; i++)
|
||||
{
|
||||
v0 += (v1 << 4 ^ v1 >> 5) + v1 ^ sum + this.k[sum & 3];
|
||||
sum += delta;
|
||||
v1 += (v0 << 4 ^ v0 >> 5) + v0 ^ sum + this.k[sum >> 11 & 3];
|
||||
}
|
||||
block.position -= 8;
|
||||
block.writeUnsignedInt(v0);
|
||||
block.writeUnsignedInt(v1);
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
block.position = index;
|
||||
var v0:uint = block.readUnsignedInt();
|
||||
var v1:uint = block.readUnsignedInt();
|
||||
var delta:uint = 2654435769;
|
||||
var sum:uint = delta * this.NUM_ROUNDS;
|
||||
for(i = 0; i < this.NUM_ROUNDS; i++)
|
||||
{
|
||||
v1 -= (v0 << 4 ^ v0 >> 5) + v0 ^ sum + this.k[sum >> 11 & 3];
|
||||
sum -= delta;
|
||||
v0 -= (v1 << 4 ^ v1 >> 5) + v1 ^ sum + this.k[sum & 3];
|
||||
}
|
||||
block.position -= 8;
|
||||
block.writeUnsignedInt(v0);
|
||||
block.writeUnsignedInt(v1);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var r:Random = new Random();
|
||||
for(var i:uint = 0; i < this.k.length; i++)
|
||||
{
|
||||
this.k[i] = r.nextByte();
|
||||
delete this.k[i];
|
||||
}
|
||||
this.k = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "xtea";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
internal class BarrettReduction implements IReduction
|
||||
{
|
||||
|
||||
private var m:BigInteger;
|
||||
|
||||
private var r2:BigInteger;
|
||||
|
||||
private var q3:BigInteger;
|
||||
|
||||
private var mu:BigInteger;
|
||||
|
||||
public function BarrettReduction(m:BigInteger)
|
||||
{
|
||||
super();
|
||||
this.r2 = new BigInteger();
|
||||
this.q3 = new BigInteger();
|
||||
BigInteger.ONE.dlShiftTo(2 * m.t,this.r2);
|
||||
this.mu = this.r2.divide(m);
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
var r:BigInteger = null;
|
||||
if(x.s < 0 || x.t > 2 * this.m.t)
|
||||
{
|
||||
return x.mod(this.m);
|
||||
}
|
||||
if(x.compareTo(this.m) < 0)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
r = new BigInteger();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public function reduce(lx:BigInteger) : void
|
||||
{
|
||||
var x:BigInteger = lx as BigInteger;
|
||||
x.drShiftTo(this.m.t - 1,this.r2);
|
||||
if(x.t > this.m.t + 1)
|
||||
{
|
||||
x.t = this.m.t + 1;
|
||||
x.clamp();
|
||||
}
|
||||
this.mu.multiplyUpperTo(this.r2,this.m.t + 1,this.q3);
|
||||
this.m.multiplyLowerTo(this.q3,this.m.t + 1,this.r2);
|
||||
while(x.compareTo(this.r2) < 0)
|
||||
{
|
||||
x.dAddOffset(1,this.m.t + 1);
|
||||
}
|
||||
x.subTo(this.r2,x);
|
||||
while(x.compareTo(this.m) >= 0)
|
||||
{
|
||||
x.subTo(this.m,x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,48 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
internal class ClassicReduction implements IReduction
|
||||
{
|
||||
|
||||
private var m:BigInteger;
|
||||
|
||||
public function ClassicReduction(m:BigInteger)
|
||||
{
|
||||
super();
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
if(x.s < 0 || x.compareTo(this.m) >= 0)
|
||||
{
|
||||
return x.mod(this.m);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function reduce(x:BigInteger) : void
|
||||
{
|
||||
x.divRemTo(this.m,null,x);
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
this.reduce(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
internal interface IReduction
|
||||
{
|
||||
|
||||
function convert(param1:BigInteger) : BigInteger;
|
||||
|
||||
function revert(param1:BigInteger) : BigInteger;
|
||||
|
||||
function reduce(param1:BigInteger) : void;
|
||||
|
||||
function mulTo(param1:BigInteger, param2:BigInteger, param3:BigInteger) : void;
|
||||
|
||||
function sqrTo(param1:BigInteger, param2:BigInteger) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
internal class MontgomeryReduction implements IReduction
|
||||
{
|
||||
|
||||
private var m:BigInteger;
|
||||
|
||||
private var mp:int;
|
||||
|
||||
private var mpl:int;
|
||||
|
||||
private var mph:int;
|
||||
|
||||
private var um:int;
|
||||
|
||||
private var mt2:int;
|
||||
|
||||
public function MontgomeryReduction(m:BigInteger)
|
||||
{
|
||||
super();
|
||||
this.m = m;
|
||||
this.mp = m.invDigit();
|
||||
this.mpl = this.mp & 0x7FFF;
|
||||
this.mph = this.mp >> 15;
|
||||
this.um = (1 << BigInteger.DB - 15) - 1;
|
||||
this.mt2 = 2 * m.t;
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
var r:BigInteger = new BigInteger();
|
||||
x.abs().dlShiftTo(this.m.t,r);
|
||||
r.divRemTo(this.m,null,r);
|
||||
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0)
|
||||
{
|
||||
this.m.subTo(r,r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
var r:BigInteger = new BigInteger();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public function reduce(x:BigInteger) : void
|
||||
{
|
||||
var j:int = 0;
|
||||
var u0:int = 0;
|
||||
while(x.t <= this.mt2)
|
||||
{
|
||||
x.a[x.t++] = 0;
|
||||
}
|
||||
for(var i:int = 0; i < this.m.t; i++)
|
||||
{
|
||||
j = x.a[i] & 0x7FFF;
|
||||
u0 = j * this.mpl + ((j * this.mph + (x.a[i] >> 15) * this.mpl & this.um) << 15) & BigInteger.DM;
|
||||
j = i + this.m.t;
|
||||
x.a[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||||
while(x.a[j] >= BigInteger.DV)
|
||||
{
|
||||
x.a[j] -= BigInteger.DV;
|
||||
++x.a[++j];
|
||||
}
|
||||
}
|
||||
x.clamp();
|
||||
x.drShiftTo(this.m.t,x);
|
||||
if(x.compareTo(this.m) >= 0)
|
||||
{
|
||||
x.subTo(this.m,x);
|
||||
}
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
this.reduce(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
public class NullReduction implements IReduction
|
||||
{
|
||||
|
||||
public function NullReduction()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function reduce(x:BigInteger) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
public namespace bi_internal = "http://crypto.hurlant.com/BigInteger";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Base64
|
||||
{
|
||||
|
||||
private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
public static const version:String = "1.0.0";
|
||||
|
||||
public function Base64()
|
||||
{
|
||||
super();
|
||||
throw new Error("Base64 class is static container only");
|
||||
}
|
||||
|
||||
public static function encode(data:String) : String
|
||||
{
|
||||
var bytes:ByteArray = new ByteArray();
|
||||
bytes.writeUTFBytes(data);
|
||||
return encodeByteArray(bytes);
|
||||
}
|
||||
|
||||
public static function encodeByteArray(data:ByteArray) : String
|
||||
{
|
||||
var dataBuffer:Array = null;
|
||||
var i:uint = 0;
|
||||
var j:uint = 0;
|
||||
var k:uint = 0;
|
||||
var output:String = "";
|
||||
var outputBuffer:Array = new Array(4);
|
||||
data.position = 0;
|
||||
while(data.bytesAvailable > 0)
|
||||
{
|
||||
dataBuffer = new Array();
|
||||
i = 0;
|
||||
while(i < 3 && data.bytesAvailable > 0)
|
||||
{
|
||||
dataBuffer[i] = data.readUnsignedByte();
|
||||
i++;
|
||||
}
|
||||
outputBuffer[0] = (dataBuffer[0] & 0xFC) >> 2;
|
||||
outputBuffer[1] = (dataBuffer[0] & 3) << 4 | dataBuffer[1] >> 4;
|
||||
outputBuffer[2] = (dataBuffer[1] & 0x0F) << 2 | dataBuffer[2] >> 6;
|
||||
outputBuffer[3] = dataBuffer[2] & 0x3F;
|
||||
for(j = dataBuffer.length; j < 3; j++)
|
||||
{
|
||||
outputBuffer[j + 1] = 64;
|
||||
}
|
||||
for(k = 0; k < outputBuffer.length; k++)
|
||||
{
|
||||
output += BASE64_CHARS.charAt(outputBuffer[k]);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static function decode(data:String) : String
|
||||
{
|
||||
var bytes:ByteArray = decodeToByteArray(data);
|
||||
return bytes.readUTFBytes(bytes.length);
|
||||
}
|
||||
|
||||
public static function decodeToByteArray(data:String) : ByteArray
|
||||
{
|
||||
var j:uint = 0;
|
||||
var k:uint = 0;
|
||||
var output:ByteArray = new ByteArray();
|
||||
var dataBuffer:Array = new Array(4);
|
||||
var outputBuffer:Array = new Array(3);
|
||||
for(var i:uint = 0; i < data.length; i += 4)
|
||||
{
|
||||
j = 0;
|
||||
while(j < 4 && i + j < data.length)
|
||||
{
|
||||
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));
|
||||
j++;
|
||||
}
|
||||
outputBuffer[0] = (dataBuffer[0] << 2) + ((dataBuffer[1] & 0x30) >> 4);
|
||||
outputBuffer[1] = ((dataBuffer[1] & 0x0F) << 4) + ((dataBuffer[2] & 0x3C) >> 2);
|
||||
outputBuffer[2] = ((dataBuffer[2] & 3) << 6) + dataBuffer[3];
|
||||
for(k = 0; k < outputBuffer.length; k++)
|
||||
{
|
||||
if(dataBuffer[k + 1] == 64)
|
||||
{
|
||||
break;
|
||||
}
|
||||
output.writeByte(outputBuffer[k]);
|
||||
}
|
||||
}
|
||||
output.position = 0;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Hex
|
||||
{
|
||||
|
||||
public function Hex()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function toArray(hex:String) : ByteArray
|
||||
{
|
||||
hex = hex.replace(/\s|:/gm,"");
|
||||
var a:ByteArray = new ByteArray();
|
||||
if(Boolean(hex.length & 1 == 1))
|
||||
{
|
||||
hex = "0" + hex;
|
||||
}
|
||||
for(var i:uint = 0; i < hex.length; i += 2)
|
||||
{
|
||||
a[i / 2] = parseInt(hex.substr(i,2),16);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
public static function fromArray(array:ByteArray, colons:Boolean = false) : String
|
||||
{
|
||||
var s:String = "";
|
||||
for(var i:uint = 0; i < array.length; i++)
|
||||
{
|
||||
s += ("0" + array[i].toString(16)).substr(-2,2);
|
||||
if(colons)
|
||||
{
|
||||
if(i < array.length - 1)
|
||||
{
|
||||
s += ":";
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static function toString(hex:String) : String
|
||||
{
|
||||
var a:ByteArray = toArray(hex);
|
||||
return a.readUTFBytes(a.length);
|
||||
}
|
||||
|
||||
public static function fromString(str:String, colons:Boolean = false) : String
|
||||
{
|
||||
var a:ByteArray = new ByteArray();
|
||||
a.writeUTFBytes(str);
|
||||
return fromArray(a,colons);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.net.LocalConnection;
|
||||
import flash.system.System;
|
||||
|
||||
public class Memory
|
||||
{
|
||||
|
||||
public function Memory()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function gc() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
new LocalConnection().connect("foo");
|
||||
new LocalConnection().connect("foo");
|
||||
}
|
||||
catch(e:*)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static function get used() : uint
|
||||
{
|
||||
return System.totalMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,469 @@
|
||||
package com.sbi.analytics
|
||||
{
|
||||
import com.carlcalderon.arthropod.Debug;
|
||||
import flash.events.DataEvent;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.external.ExternalInterface;
|
||||
import flash.net.Socket;
|
||||
import flash.utils.Dictionary;
|
||||
import flash.utils.Timer;
|
||||
|
||||
public class SBTracker
|
||||
{
|
||||
|
||||
private static var _pageStack:Array;
|
||||
|
||||
private static var _batchTimer:Timer;
|
||||
|
||||
private static var _isExternalAvailable:Boolean;
|
||||
|
||||
private static var _couldNotConnect:Boolean;
|
||||
|
||||
private static var _pageView:String;
|
||||
|
||||
private static var _socket:Socket;
|
||||
|
||||
private static var _timeOffset:Number;
|
||||
|
||||
private static var _isFromLogin:Boolean;
|
||||
|
||||
private static var _retryLimit:int;
|
||||
|
||||
private static var _lastBatchCallback:Function;
|
||||
|
||||
private static var _trackingObjects:Dictionary;
|
||||
|
||||
private static var _latestTrackTimeStamp:Dictionary;
|
||||
|
||||
private static var _lastestDuration:Dictionary;
|
||||
|
||||
public static const TYPE_NORMAL:int = 0;
|
||||
|
||||
public static const TYPE_EVENT:int = 1;
|
||||
|
||||
public static const TYPE_ERROR:int = 2;
|
||||
|
||||
private static var MAX_RETRIES:int = 3;
|
||||
|
||||
public function SBTracker()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function create() : void
|
||||
{
|
||||
if(ExternalInterface.available && gMainFrame.clientInfo.sbTrackerIp != -1)
|
||||
{
|
||||
_isExternalAvailable = true;
|
||||
ExternalInterface.addCallback("receiveClose",receiveClose);
|
||||
if(!isNaN(gMainFrame.clientInfo.currentTimestamp))
|
||||
{
|
||||
_timeOffset = gMainFrame.clientInfo.currentTimestamp - new Date().valueOf() / 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
_timeOffset = 0;
|
||||
}
|
||||
_pageView = null;
|
||||
_pageStack = [];
|
||||
_socket = new Socket();
|
||||
_socket.addEventListener(Event.CLOSE,closeHandler);
|
||||
_socket.addEventListener(Event.CONNECT,connectHandler);
|
||||
_socket.addEventListener(DataEvent.DATA,dataHandler);
|
||||
_socket.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
|
||||
_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
|
||||
_trackingObjects = new Dictionary();
|
||||
_trackingObjects[TYPE_NORMAL] = [];
|
||||
_trackingObjects[TYPE_EVENT] = [];
|
||||
_trackingObjects[TYPE_ERROR] = [];
|
||||
_latestTrackTimeStamp = new Dictionary();
|
||||
_latestTrackTimeStamp[TYPE_NORMAL] = 0;
|
||||
_lastestDuration = new Dictionary();
|
||||
_lastestDuration[TYPE_NORMAL] = 0;
|
||||
_batchTimer = new Timer(10000);
|
||||
_batchTimer.addEventListener(TimerEvent.TIMER,onBatchTimer,false,0,true);
|
||||
_batchTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static function receiveClose() : String
|
||||
{
|
||||
_batchTimer.stop();
|
||||
_batchTimer.removeEventListener(TimerEvent.TIMER,onBatchTimer);
|
||||
if(_pageView != null)
|
||||
{
|
||||
setupPageView();
|
||||
return _pageView;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function onError() : void
|
||||
{
|
||||
if(_isExternalAvailable)
|
||||
{
|
||||
ExternalInterface.call("reportAnalyticsError","Error Timeout",gMainFrame.clientInfo.sessionId);
|
||||
}
|
||||
Debug.log("Sending analytics error",Debug.RED);
|
||||
}
|
||||
|
||||
public static function trackPageview(pageURI:String, loginSessionId:int = -1, type:int = 0, throttled:Boolean = true) : void
|
||||
{
|
||||
var userId:int = 0;
|
||||
var currTime:Number = NaN;
|
||||
if(_isExternalAvailable && !_couldNotConnect)
|
||||
{
|
||||
_isFromLogin = loginSessionId != -1;
|
||||
if(_isFromLogin)
|
||||
{
|
||||
userId = 0;
|
||||
}
|
||||
else if(gMainFrame.clientInfo.dbUserId == undefined)
|
||||
{
|
||||
userId = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
userId = int(gMainFrame.clientInfo.dbUserId);
|
||||
}
|
||||
if(userId > 0)
|
||||
{
|
||||
if(throttled && userId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
currTime = Math.floor(new Date().valueOf() / 1000 + _timeOffset);
|
||||
if(gMainFrame.clientInfo.sessionId == undefined && _isFromLogin)
|
||||
{
|
||||
gMainFrame.clientInfo.sessionId = Math.floor(Math.random() * (int.MAX_VALUE + 1));
|
||||
}
|
||||
_trackingObjects[type].push(new URIObj(pageURI,currTime,_isFromLogin,type,_trackingObjects[type].length,throttled));
|
||||
}
|
||||
}
|
||||
|
||||
public static function handleErrorTracking(userId:int, time:int, order:int, duration:int, sessionId:Number, uri:String, uriParam:String, pop:int, value:int) : void
|
||||
{
|
||||
var tempSessionId:Number = Number(gMainFrame.clientInfo.sessionId);
|
||||
if(gMainFrame.clientInfo.sessionId == undefined)
|
||||
{
|
||||
tempSessionId = Math.round(Math.random() * (int.MAX_VALUE + 1));
|
||||
}
|
||||
if(gMainFrame.clientInfo.dbUserId == undefined)
|
||||
{
|
||||
gMainFrame.clientInfo.dbUserId = userId;
|
||||
}
|
||||
var customFields:Object = {
|
||||
"userId":(gMainFrame.clientInfo.dbUserId == undefined ? userId : null),
|
||||
"order":order,
|
||||
"duration":(duration == -1 ? null : duration),
|
||||
"sessionId":(sessionId == -1 ? tempSessionId : null)
|
||||
};
|
||||
_trackingObjects[TYPE_ERROR].push(new URIObj(uri + "#" + uriParam + "#" + pop + "#" + value,time == -1 ? Math.floor(new Date().valueOf() / 1000 + _timeOffset) : time,_isFromLogin,TYPE_ERROR,_trackingObjects[TYPE_ERROR].length,false,customFields));
|
||||
onBatchTimer(null);
|
||||
}
|
||||
|
||||
public static function handleOnKickOrLogout() : void
|
||||
{
|
||||
if(_isExternalAvailable && _pageView != null)
|
||||
{
|
||||
ExternalInterface.call("handleLogout",_pageView);
|
||||
}
|
||||
}
|
||||
|
||||
public static function push(type:int = 0) : void
|
||||
{
|
||||
var currTrackingObjects:Array = null;
|
||||
var trackingObject:Object = null;
|
||||
if(Boolean(_pageStack))
|
||||
{
|
||||
currTrackingObjects = _trackingObjects[type];
|
||||
if(currTrackingObjects.length > 0)
|
||||
{
|
||||
trackingObject = currTrackingObjects[currTrackingObjects.length - 1].trackingObject;
|
||||
_pageStack.push(trackingObject.uri + "#" + trackingObject.uriParams + "#pop#" + trackingObject.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function pop() : void
|
||||
{
|
||||
if(Boolean(_pageStack) && Boolean(_pageStack.length))
|
||||
{
|
||||
trackPageview(_pageStack.pop());
|
||||
}
|
||||
}
|
||||
|
||||
public static function flush(bPopFirst:Boolean = false) : void
|
||||
{
|
||||
if(Boolean(_pageStack) && Boolean(_pageStack.length))
|
||||
{
|
||||
if(bPopFirst)
|
||||
{
|
||||
trackPageview(_pageStack[0]);
|
||||
}
|
||||
_pageStack = [];
|
||||
}
|
||||
}
|
||||
|
||||
public static function completeLastTrackingBatch(callback:Function) : void
|
||||
{
|
||||
_lastBatchCallback = callback;
|
||||
if(Boolean(_batchTimer))
|
||||
{
|
||||
_batchTimer.stop();
|
||||
if(Boolean(_socket))
|
||||
{
|
||||
setupPageView(true);
|
||||
if(_pageView != null)
|
||||
{
|
||||
_batchTimer.reset();
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLastDuration(type:int) : Number
|
||||
{
|
||||
return _lastestDuration[type];
|
||||
}
|
||||
|
||||
public static function setLastDuration(type:int, duration:Number) : void
|
||||
{
|
||||
_lastestDuration[type] = duration;
|
||||
}
|
||||
|
||||
public static function getLastTimestamp(type:int) : Number
|
||||
{
|
||||
return _latestTrackTimeStamp[type];
|
||||
}
|
||||
|
||||
public static function setLastTimestamp(type:int, timeStamp:Number) : void
|
||||
{
|
||||
_latestTrackTimeStamp[type] = timeStamp;
|
||||
}
|
||||
|
||||
public static function getnextURIObjByType(index:int, type:int) : URIObj
|
||||
{
|
||||
var trackingArray:Array = _trackingObjects[type];
|
||||
if(trackingArray.length > 0 && trackingArray.length > index + 1)
|
||||
{
|
||||
return trackingArray[index + 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getPreviousURIObjByType(index:int, type:int) : URIObj
|
||||
{
|
||||
var trackingArray:Array = _trackingObjects[type];
|
||||
if(trackingArray.length > 0 && trackingArray.length > index - 1)
|
||||
{
|
||||
return trackingArray[index - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static function findLatestTrackedURIObjByThrottleType(trackingObjects:Array, throttle:Boolean) : URIObj
|
||||
{
|
||||
var i:int = 0;
|
||||
if(Boolean(trackingObjects))
|
||||
{
|
||||
for(i = trackingObjects.length - 1; i >= 0; i--)
|
||||
{
|
||||
if(trackingObjects[i].throttled == throttle)
|
||||
{
|
||||
return trackingObjects[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static function onBatchTimer(t:TimerEvent) : void
|
||||
{
|
||||
if(Boolean(_socket))
|
||||
{
|
||||
setupPageView();
|
||||
if(_pageView != null)
|
||||
{
|
||||
_batchTimer.reset();
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function setupPageView(updateLastItem:Boolean = false) : void
|
||||
{
|
||||
var myTrackString:String = null;
|
||||
var trackType:int = 0;
|
||||
var currUri:URIObj = null;
|
||||
var i:int = 0;
|
||||
var type:String = null;
|
||||
var currUriObjects:Array = null;
|
||||
var track:Boolean = false;
|
||||
if(_pageView == null)
|
||||
{
|
||||
myTrackString = "";
|
||||
for(type in _trackingObjects)
|
||||
{
|
||||
trackType = int(type);
|
||||
currUriObjects = _trackingObjects[trackType];
|
||||
if(currUriObjects.length > 0)
|
||||
{
|
||||
if(gMainFrame.clientInfo.sessionId != undefined)
|
||||
{
|
||||
for(i = 0; i < currUriObjects.length; i++)
|
||||
{
|
||||
currUri = currUriObjects[i];
|
||||
if(currUri.throttled)
|
||||
{
|
||||
if(!currUri.isFromLogin)
|
||||
{
|
||||
if(gMainFrame.clientInfo.dbUserId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if(gMainFrame.clientInfo.sessionId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
myTrackString += currUri.pageView;
|
||||
}
|
||||
if(updateLastItem)
|
||||
{
|
||||
if(currUri.throttled)
|
||||
{
|
||||
if(!currUri.isFromLogin)
|
||||
{
|
||||
if(gMainFrame.clientInfo.dbUserId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
track = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
track = true;
|
||||
}
|
||||
}
|
||||
else if(gMainFrame.clientInfo.sessionId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
track = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
track = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
track = true;
|
||||
}
|
||||
if(track)
|
||||
{
|
||||
myTrackString += currUri.ownPageView;
|
||||
}
|
||||
_trackingObjects[trackType] = [];
|
||||
currUriObjects = [];
|
||||
}
|
||||
else
|
||||
{
|
||||
_trackingObjects[trackType].splice(0,currUriObjects.length - 1);
|
||||
currUriObjects.splice(0,currUriObjects.length - 1);
|
||||
currUri.index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(myTrackString != "")
|
||||
{
|
||||
_pageView = myTrackString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function closeHandler(event:Event) : void
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
private static function connectHandler(event:Event) : void
|
||||
{
|
||||
Debug.log(_pageView,Debug.YELLOW);
|
||||
_socket.writeUTFBytes(_pageView);
|
||||
_pageView = null;
|
||||
_socket.flush();
|
||||
_socket.close();
|
||||
_retryLimit = 0;
|
||||
_batchTimer.start();
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function dataHandler(event:DataEvent) : void
|
||||
{
|
||||
}
|
||||
|
||||
private static function ioErrorHandler(event:IOErrorEvent) : void
|
||||
{
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
if(_retryLimit < MAX_RETRIES)
|
||||
{
|
||||
++_retryLimit;
|
||||
Debug.log("IO error - retrying analytics connection",Debug.RED);
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
_couldNotConnect = true;
|
||||
}
|
||||
|
||||
private static function securityErrorHandler(event:SecurityErrorEvent) : void
|
||||
{
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
if(_retryLimit < MAX_RETRIES)
|
||||
{
|
||||
Debug.log("Security error - retrying analytics connection",Debug.RED);
|
||||
++_retryLimit;
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
if(Boolean(_batchTimer))
|
||||
{
|
||||
_batchTimer.stop();
|
||||
_batchTimer.removeEventListener(TimerEvent.TIMER,onBatchTimer);
|
||||
}
|
||||
_couldNotConnect = true;
|
||||
_pageView = null;
|
||||
_socket = null;
|
||||
onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loaded 100 of 7925 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user