Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.turpitude.weddingStreet.modules.core.model {
- import com.turpitude.utils.MathUtils;
- import com.turpitude.weddingStreet.FacadeNames;
- import com.turpitude.weddingStreet.main.model.buffs.BuffVo;
- import com.turpitude.weddingStreet.main.model.buffs.BuffsProxy;
- import com.turpitude.weddingStreet.main.model.missions.ActiveMissionsProxy;
- import com.turpitude.weddingStreet.main.model.missions.JobTypes;
- import com.turpitude.weddingStreet.main.model.missions.valueobjects.JobVo;
- import com.turpitude.weddingStreet.main.model.missions.valueobjects.MissionVo;
- import com.turpitude.weddingStreet.main.model.shopping.ShopVo;
- import com.turpitude.weddingStreet.main.model.shopping.ShoppingProxy;
- import com.turpitude.weddingStreet.main.model.shopping.valueobjects.ShoppingItemVO;
- import com.turpitude.weddingStreet.main.model.user.AccountControllerProxy;
- import com.turpitude.weddingStreet.main.model.user.UserItemVO;
- import com.turpitude.weddingStreet.main.model.user.UserItemsProxy;
- import com.turpitude.weddingStreet.modules.core.model.valueobjects.CreationAssetVo;
- import com.turpitude.weddingStreet.modules.core.model.valueobjects.CreationStepVo;
- import com.turpitude.weddingStreet.modules.core.model.valueobjects.SortVo;
- import com.turpitude.weddingStreet.modules.core.model.valueobjects.VariantAssetVo;
- import com.turpitude.weddingStreet.modules.core.view.screens.creatorgame.components.selectionbar.ISelectionBarProxy;
- import org.puremvc.as3.multicore.interfaces.IFacade;
- import org.puremvc.as3.multicore.interfaces.IProxy;
- import org.puremvc.as3.multicore.patterns.facade.Facade;
- import org.puremvc.as3.multicore.patterns.proxy.Proxy;
- /**
- * @author marc
- */
- public class CreatorGameProxy extends Proxy implements IProxy, ISelectionBarProxy
- {
- // Cake Budget Dress Budget Décor Budget Bouquet Budget Invites Budget
- // 0.05 0.1 0.1 0.05 0.05
- private static const BUDGET_SCALER_BAKERY : Number = 0.05;
- private static const BUDGET_SCALER_DRESSMAKER : Number = 0.1;
- private static const BUDGET_SCALER_PARTY : Number = 0.1;
- private static const BUDGET_SCALER_FLOWER : Number = 0.05;
- private static const BUDGET_SCALER_PRINTER : Number = 0.05;
- protected static const ITEM_COST_TO_MISSION_BUDGET_SCALER : Number = 0.0001;
- public static const ALLOWED_OVERSPEND : Number = 1.15;
- protected var _weddingObject : IUserCreatedObject;
- protected var _creationStepsData : Vector.<CreationStepVo>;
- protected var _currentStep : uint = 0;
- protected var _unlockedSteps : uint = 0;
- protected var _numSteps : uint;
- protected var _displayCaseData : XML;
- //cache the budget and profit scaler because they're an expensive look up
- private var _cachedBudget : Number = -1;
- private var _cachedProfitScaler : Number = -1;
- private var _cachedCreateTimeModifier : Number = -1;
- private var _cachedBuffModifier : Array = new Array;
- public function CreatorGameProxy( proxyName : String = null, data : Object = null ) {
- super(proxyName, data);
- if(data) _setCreationStepsData(new XML(data));
- }
- public function getFacade() : IFacade {
- return facade;
- }
- public function setDisplayCaseData(displayCaseData : XML) : void {
- _displayCaseData = displayCaseData;
- }
- public function setWeddingObject( weddingObject : IUserCreatedObject ) : void {
- _weddingObject = weddingObject;
- }
- public function getCreationStepData( stepNum : uint ) : CreationStepVo {
- stepNum = MathUtils.clamp(stepNum, 0, _creationStepsData.length - 1);
- return _creationStepsData[stepNum];
- }
- public function getCreationStepsData() : Vector.<CreationStepVo> {
- return _creationStepsData;
- }
- public function getWeddingObject() : IUserCreatedObject {
- return _weddingObject;
- }
- public function getCreateTime() : Number
- {
- // if(_cachedCreateTimeModifier != -1) return _cachedCreateTimeModifier;
- var createTime : Number = 0;
- _cachedCreateTimeModifier = _cachedCreateTimeModifier == -1 ? _getCreateTimeModifier() : _cachedCreateTimeModifier;
- //step 1 in the excel
- var itemCost : Number = _weddingObject.cost;
- //step 2 in the excel
- var originalBudget : Number;
- switch(_weddingObject.shoptype)
- {
- case ShopVo.BAKERY:
- originalBudget = itemCost / BUDGET_SCALER_BAKERY;
- break;
- case ShopVo.DRESSMAKER:
- originalBudget = itemCost / BUDGET_SCALER_DRESSMAKER;
- break;
- case ShopVo.FLOWER:
- originalBudget = itemCost / BUDGET_SCALER_FLOWER;
- break;
- case ShopVo.PARTY:
- originalBudget = itemCost / BUDGET_SCALER_PARTY;
- break;
- case ShopVo.PRINTER:
- originalBudget = itemCost / BUDGET_SCALER_PRINTER;
- break;
- }
- //step 3 in the spreadsheet
- var level : Number = originalBudget * ITEM_COST_TO_MISSION_BUDGET_SCALER;
- createTime = Math.max( level, Math.round(Math.pow(level, 2.44)/10)+1 );
- createTime *= _cachedCreateTimeModifier;
- return ( Math.round(createTime)* 60 );
- }
- private function _getCreateTimeModifier() : Number
- {
- var createTimeModifier : Number = 0;
- try{
- var mainfacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
- var userOwnedProxy : UserItemsProxy = mainfacade.retrieveProxy(UserItemsProxy.NAME) as UserItemsProxy;
- if(!userOwnedProxy) return createTimeModifier;
- //get all the users shop items
- var shopItems : Vector.<UserItemVO> = userOwnedProxy.getItemsByShopAndCategory(_weddingObject.shoptype);
- var upgradeTable : Array = new Array();
- for each (var item : UserItemVO in shopItems)
- {
- //if item is an upgrade, check we have the upgrade with
- //the highest possible effect (highest upgrade in class)
- if(item.shopItemVO.category == ShoppingItemVO.CATEGORY_UPGRADE)
- {
- if( item.shopItemVO.effect_one && item.shopItemVO.effect_one.indexOf("_Time") != -1 )
- {
- //if we already found an upgrade of this type
- if(upgradeTable[item.shopItemVO.itemType]){
- //replace the last upgrade
- if(item.shopItemVO.magnitude_one < upgradeTable[item.shopItemVO.itemType].magnitude_one)
- upgradeTable[item.shopItemVO.itemType] = item.shopItemVO;
- }else
- upgradeTable[item.shopItemVO.itemType] = item.shopItemVO;
- }
- }
- }
- for (var type : String in upgradeTable)
- createTimeModifier += (upgradeTable[type] as ShoppingItemVO).magnitude_one;
- createTimeModifier += (_getBuffModifier(BuffsProxy.EFFECT_TYPE_TIME, false));
- // var accountProxy : AccountControllerProxy = mainfacade.retrieveProxy(AccountControllerProxy.NAME) as AccountControllerProxy;
- // if(!accountProxy) return createTime;
- // var userLevel : uint = accountProxy.accountProfile.getLevelByShop(_weddingObject.shoptype);
- // createTime = Math.max( userLevel, Math.round(Math.pow(userLevel, 2.44)/10)+1 );
- // createTime *= createTimeModifier;
- }catch(error:Error){
- trace(error);
- createTimeModifier = 0;
- }
- return createTimeModifier;
- // return ( Math.round(createTime)* 60 );
- }
- public function budgetSpent() : Number
- {
- // trace('_getBuffModifier(BuffsProxy.EFFECT_TYPE_COST): ' + (_getBuffModifier(BuffsProxy.EFFECT_TYPE_COST)));
- return _weddingObject.cost * _getBuffModifier(BuffsProxy.EFFECT_TYPE_COST);
- }
- public function budgetRemaining() : Number
- {
- if(missionType == JobTypes.TYPE_FOR_FRIEND)
- return Number.POSITIVE_INFINITY;
- //WS-984.... The player should be able to exceed this figure by 15%
- //so scale the budget percent down to fit in this range
- return (_getBudget()*ALLOWED_OVERSPEND) - budgetSpent();
- }
- public function budgetSpentPercent() : Number {
- return budgetSpent() / (_getBudget()*ALLOWED_OVERSPEND);
- }
- public function totalBudget() : uint {
- return _getBudget();
- }
- public function get currentStep() : uint {
- return _currentStep;
- }
- public function get missionType() : String
- {
- var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
- if(missionProxy) return missionProxy.activeTaskType;
- return JobTypes.TYPE_DISPLAY_CASE;
- }
- public function set currentStep( currentStep : uint) : void {
- _currentStep = Math.max(currentStep, 0);
- _currentStep = Math.min(_currentStep, numUnlockedSteps);
- }
- public function get numUnlockedSteps() : uint {
- return _unlockedSteps;
- }
- public function unlockStep( stepNum : uint) : void {
- getCreationStepData(stepNum).unlocked = true;
- _unlockedSteps = MathUtils.clamp(stepNum, 0, _creationStepsData.length - 1);
- }
- public function resetSteps() : void {
- for ( var i : uint = 1;i < numSteps;i++ )
- getCreationStepData(i).unlocked = false;
- currentStep = 0;
- _cachedBudget = -1;
- _cachedProfitScaler = -1;
- _cachedCreateTimeModifier = -1;
- _cachedBuffModifier = new Array();
- _weddingObject.reset();
- }
- public function reset() : void
- {
- _creationStepsData = null;
- if(data) _setCreationStepsData(new XML(data));
- }
- public function get weddingObject() : IUserCreatedObject {
- return _weddingObject;
- }
- public function get numSteps() : uint {
- return _creationStepsData.length;
- }
- public function getCreationAssetByExcelId( creationStep : uint, id : String ) : CreationAssetVo {
- for each (var asset : CreationAssetVo in _creationStepsData[creationStep].assets) {
- if(asset.xml)
- if(asset.xml.@excelId == id) return asset;
- }
- return null;
- }
- public function numHearts() : uint {
- var numHearts : uint = 0;
- var mainFacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
- var activeMissionProxy : ActiveMissionsProxy = mainFacade.retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
- //if the submitted job is for the display case
- if( !activeMissionProxy || activeMissionProxy.activeTaskType == JobTypes.TYPE_DISPLAY_CASE ) return numHearts;
- // Between 0-60% of budget, the player earns no hearts.
- //· Between 61-100% of budget, the player earns 1 heart.
- //· Between 101-115%, the player earns no hearts.
- var budgetPercent : Number = budgetSpent() / (_getBudget());//budgetSpentPercent();
- numHearts = (budgetPercent > .6 && budgetPercent < 1.1) ? 1 : 0;
- return numHearts * _getBuffModifier(BuffsProxy.EFFECT_TYPE_HAPPINESS);
- }
- public function getCompletedGoalsXML() : XML {
- var mainFacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
- var activeMissionProxy : ActiveMissionsProxy = mainFacade.retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
- if( !activeMissionProxy) return null;
- var taskXML : XML = <task/>;
- taskXML.@score = numHearts();
- var shoppingProxy : ShoppingProxy = mainFacade.retrieveProxy(ShoppingProxy.NAME) as ShoppingProxy;
- var shop : ShopVo = shoppingProxy.getShop(getWeddingObject().shoptype);
- taskXML.@shop_id = shop.id;
- var objectives : XML = <objectives/>;
- taskXML.appendChild(objectives);
- if(activeMissionProxy.activeTask)
- taskXML.@id = activeMissionProxy.activeTask.id;
- return taskXML;
- }
- protected function _getSortData() : XML
- {
- var sortData : XML = <sortCategories>
- <sort label="name" value="name" />
- <sort label="price" value="cost" />
- </sortCategories>;
- // DISABLING THE FAVORITES SORT TEMPORARILY
- // var sortData : XML = <sortCategories>
- // <sort label="name" value="name" />
- // <sort label="price" value="cost" />
- // <sort label="favorite" value="favorite" />
- // </sortCategories>;
- return sortData;
- }
- /**
- * Returns a scaler value to modifier Cost, Happiness and Time
- * values with if buffs/boosts are active for this creator game
- */
- protected function _getBuffModifier( effectType : String, includeUpgrades : Boolean = true ) : Number
- {
- trace("\n\nCreatorGameProxy._getBuffModifier("+arguments+")");
- if(_cachedBuffModifier[effectType]!=null) return _cachedBuffModifier[effectType];
- var buffModifier : Number = 1;
- var mainFacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
- var buffsProxy : BuffsProxy = mainFacade.retrieveProxy(BuffsProxy.NAME) as BuffsProxy;
- if( buffsProxy )
- {
- var activeBuffs : Vector.<BuffVo> = buffsProxy.getShopBuffs(_weddingObject.shoptype, effectType);
- activeBuffs = activeBuffs.concat( buffsProxy.getShopBuffs(ShopVo.PLANNER, effectType) );
- if(activeBuffs.length > 0)
- {
- for each (var buff : BuffVo in activeBuffs)
- {
- trace('buff.name: ' + (buff.name ) + " : " + buff.percent);
- buffModifier += buff.percent;
- trace('buffModifier: ' + (buffModifier));
- }
- }
- }
- var useritemsProxy : UserItemsProxy = mainFacade.retrieveProxy(UserItemsProxy.NAME) as UserItemsProxy;
- if( includeUpgrades && useritemsProxy )
- {
- var ownedShopItems : Vector.<UserItemVO> = useritemsProxy.getItemsByShopAndCategory( _weddingObject.shoptype, ShoppingItemVO.CATEGORY_UPGRADE );
- for each (var item : UserItemVO in ownedShopItems)
- {
- var highestMagnitude : Number = 0;
- var highestMagnitudeItem : UserItemVO;
- if( item.shopItemVO.effect_one.indexOf(effectType)!=-1 )
- {
- // trace('item.shopItemVO: ' + (item.shopItemVO.itemName + " : " + item.shopItemVO.magnitude_one) );
- if( highestMagnitude < Math.abs(item.shopItemVO.magnitude_one) )
- {
- highestMagnitude = Math.abs(item.shopItemVO.magnitude_one);
- highestMagnitudeItem = item;
- }
- // buffModifier += item.shopItemVO.magnitude_one;
- }
- }
- if(highestMagnitudeItem) buffModifier += highestMagnitudeItem.shopItemVO.magnitude_one;
- }
- //if its a happiness bu
- // if(effectType==BuffsProxy.EFFECT_TYPE_HAPPINESS)
- // buffModifier = 1 + (1-buffModifier);
- _cachedBuffModifier[effectType] = buffModifier;
- return (buffModifier);
- }
- protected function _jobData() : JobVo {
- var job : JobVo;
- var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
- if(missionProxy) job = missionProxy.activeTask;
- return job;
- }
- protected function _missionData() : MissionVo {
- var mission : MissionVo;
- var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
- if(missionProxy && missionProxy.activeTask)
- mission = missionProxy.getMissionByChildJob(missionProxy.activeTask);
- return mission;
- }
- protected function _getBudget() : Number
- {
- if(_cachedBudget != -1) return _cachedBudget;
- //test budget ammount
- var totalBudget : Number = 1500;
- var job : JobVo = _jobData();
- if( job )
- totalBudget = job.budget;
- else if(_displayCaseData)
- {
- var managerXML : XML = _getActiveShopManagerXML();
- if(managerXML) totalBudget = Number(managerXML.budgetMax);
- }
- _cachedBudget = totalBudget;
- return totalBudget;
- }
- protected function _getActiveShopManagerXML() : XML
- {
- //if mission type is for display case
- var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
- var buffsProxy : BuffsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(BuffsProxy.NAME) as BuffsProxy;
- if(buffsProxy && missionProxy && missionProxy.activeTaskType == JobTypes.TYPE_DISPLAY_CASE)
- {
- var activeBuffs : Vector.<BuffVo> = buffsProxy.getShopBuffs(_weddingObject.shoptype);
- //should be a display case manager buff here but just in case
- if(activeBuffs.length>0)
- {
- var strongestBuff : BuffVo = activeBuffs[0];
- //find the highest ranking active manager buff
- for each (var buff : BuffVo in activeBuffs)
- if(buff.excel_id > strongestBuff.excel_id) strongestBuff = buff;
- return _displayCaseData.manager.(@excelId == strongestBuff.excel_id)[0];
- }
- }
- return null;
- }
- protected function _getProfitScaler() : Number
- {
- if(_cachedProfitScaler != -1) return _cachedProfitScaler;
- var managerXML : XML = _getActiveShopManagerXML();
- if(managerXML) _cachedProfitScaler = managerXML.profitmult;
- else _cachedProfitScaler = 0;
- return _cachedProfitScaler;
- }
- protected function _getMissionBudget() : Number {
- return _missionData() == null ? 0 : _missionData().budget;
- }
- protected function _setCreationStepsData( gameXML : XML ) : void {
- _creationStepsData = new Vector.<CreationStepVo>();
- var stepData : CreationStepVo, stepName : String, stepInstructions : String, stepType : String, sortCategories : SortVo;
- for (var i : int = 0;i < gameXML..creatorPanel.length();i++) {
- stepName = gameXML..creatorPanel[i].@btnLabel;
- stepInstructions = gameXML..creatorPanel[i].instructions_txt.toString();
- stepType = gameXML..creatorPanel[i].@type;
- sortCategories = _getSortCategories(gameXML..creatorPanel[i].sortCategories..sort);
- stepData = new CreationStepVo(i, stepName, stepType, sortCategories);
- stepData.unlocked = gameXML..creatorPanel[i].@locked == "false";
- var assetsPath : String = gameXML..creatorPanel[i].@assetsPath;
- if(assetsPath) stepData.assetsPath = assetsPath;
- var iconsPath : String = gameXML..creatorPanel[i].@iconsPath;
- if(iconsPath) stepData.iconsPath = iconsPath;
- _setCreationAssets(stepData, gameXML..creatorPanel[i].uiAssets..btn);
- _creationStepsData[i] = stepData;
- trace(_creationStepsData[i].assets.length);
- }
- _creationStepsData[0].unlocked = true;
- }
- protected function _setCreationAssets( stepData : CreationStepVo, assetsXMLList : XMLList ) : void {
- for each(var assetData : XML in assetsXMLList) {
- var id : uint = stepData.assets.length;
- var name : String = assetData.@name;
- var description : String = assetData.@description;
- var type : String = assetData.@type;
- var assetLinkageId : String = assetData.@assetLinkageId;
- var unlocked : Boolean = assetData.@unlocked == "true";
- var favorite : Boolean = assetData.@favorite == "true";
- var cost : Number = Number(assetData.@cost);
- var createTime : Number = Number(assetData.@createTime);
- var colordata : String = assetData.@colordata;
- var metadata : String = assetData.@metadata;
- var xformdata : String = assetData.@xformdata;
- var assetVo : CreationAssetVo = new CreationAssetVo(id, name, description, type, assetLinkageId, unlocked, favorite, cost, createTime, colordata, metadata, xformdata);
- assetVo.assetPath = stepData.assetsPath;
- assetVo.iconPath = stepData.iconsPath;
- assetVo.file = assetData.asset.@file;
- assetVo.icon = assetData.asset.@icon;
- assetVo.xml = assetData;
- stepData.assets.push(assetVo);
- }
- }
- protected function _getSortCategories( assetsXMLList : XMLList ) : SortVo {
- var labels : Vector.<String> = new Vector.<String>;
- var values : Vector.<String> = new Vector.<String>;
- var filters : Vector.<String> = new Vector.<String>;
- for each(var assetData : XML in assetsXMLList) {
- labels.push(assetData.@label);
- values.push(assetData.@value);
- filters.push(assetData.@filter);
- }
- var sortVo : SortVo = new SortVo(labels, values, filters);
- return sortVo;
- }
- /**
- * Check whether the user owns the asset
- *
- * @param assetData
- */
- protected function _assetInInventory(assetData : XML) : Boolean {
- //if asset has no friend points costs its free to use (and doesnt have to exist in inventory)
- if(assetData.hasOwnProperty("fp_cost") && uint(assetData.fp_cost.text()) == 0) return true;
- var mainfacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
- var userOwnedProxy : UserItemsProxy = mainfacade.retrieveProxy(UserItemsProxy.NAME) as UserItemsProxy;
- //if no useritems proxy we're running in standalone mode so unlock all items
- if(!userOwnedProxy) return true;
- return userOwnedProxy.getItemsByName(assetData.name.text()).length > 0;
- }
- /**
- * Returns a vector of selected assets that need to be purchased
- *
- * @return Vector.<CreationAssetVo>
- */
- public function getLockedItems() : Vector.<CreationAssetVo> {
- var lockedItems : Vector.<CreationAssetVo> = new Vector.<CreationAssetVo>();
- var selectedItems : Vector.<CreationAssetVo> = _weddingObject.getAssets();
- for each (var item : CreationAssetVo in selectedItems) {
- if(item && !item.unlocked) {
- lockedItems.push(item);
- }
- }
- return lockedItems;
- }
- public function getItemById(id : uint) : CreationAssetVo {
- for each (var stepData : CreationStepVo in _creationStepsData) {
- for each (var asset : CreationAssetVo in stepData.assets)
- {
- //if asset is a variant iterate through all the
- //variants assets
- if(asset is VariantAssetVo)
- {
- for each (var variant : CreationAssetVo in (asset as VariantAssetVo).variants )
- {
- if(variant.id == id) return variant;
- }
- }else if(asset.id == id) return asset;
- }
- }
- return null;
- }
- public function getItemRetailPrice() : Number
- {
- return (_getProfitScaler() * budgetSpent());
- // return _weddingObject.cost + (_getProfitScaler() * _weddingObject.cost);
- }
- public function getCreationStepCost( stepNum : uint) : uint
- {
- var cost : uint = 0;
- var selectedAssets : Vector.<CreationAssetVo> = _weddingObject.getAssets();
- for each (var asset : CreationAssetVo in selectedAssets)
- {
- if(asset==null) continue;
- //this is slow, but we have to use ids instead of indexOf because this could be a clone
- for each (var stepAsset : CreationAssetVo in _creationStepsData[stepNum].assets)
- if( stepAsset.excelId == asset.excelId )
- cost += asset.cost;
- // if( _creationStepsData[stepNum].assets.indexOf(asset)!=-1 )
- }
- return cost;
- }
- }
- }
Add Comment
Please, Sign In to add comment