Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.45 KB | None | 0 0
  1. package com.turpitude.weddingStreet.modules.core.model {
  2. import com.turpitude.utils.MathUtils;
  3. import com.turpitude.weddingStreet.FacadeNames;
  4. import com.turpitude.weddingStreet.main.model.buffs.BuffVo;
  5. import com.turpitude.weddingStreet.main.model.buffs.BuffsProxy;
  6. import com.turpitude.weddingStreet.main.model.missions.ActiveMissionsProxy;
  7. import com.turpitude.weddingStreet.main.model.missions.JobTypes;
  8. import com.turpitude.weddingStreet.main.model.missions.valueobjects.JobVo;
  9. import com.turpitude.weddingStreet.main.model.missions.valueobjects.MissionVo;
  10. import com.turpitude.weddingStreet.main.model.shopping.ShopVo;
  11. import com.turpitude.weddingStreet.main.model.shopping.ShoppingProxy;
  12. import com.turpitude.weddingStreet.main.model.shopping.valueobjects.ShoppingItemVO;
  13. import com.turpitude.weddingStreet.main.model.user.AccountControllerProxy;
  14. import com.turpitude.weddingStreet.main.model.user.UserItemVO;
  15. import com.turpitude.weddingStreet.main.model.user.UserItemsProxy;
  16. import com.turpitude.weddingStreet.modules.core.model.valueobjects.CreationAssetVo;
  17. import com.turpitude.weddingStreet.modules.core.model.valueobjects.CreationStepVo;
  18. import com.turpitude.weddingStreet.modules.core.model.valueobjects.SortVo;
  19. import com.turpitude.weddingStreet.modules.core.model.valueobjects.VariantAssetVo;
  20. import com.turpitude.weddingStreet.modules.core.view.screens.creatorgame.components.selectionbar.ISelectionBarProxy;
  21.  
  22. import org.puremvc.as3.multicore.interfaces.IFacade;
  23. import org.puremvc.as3.multicore.interfaces.IProxy;
  24. import org.puremvc.as3.multicore.patterns.facade.Facade;
  25. import org.puremvc.as3.multicore.patterns.proxy.Proxy;
  26.  
  27. /**
  28. * @author marc
  29. */
  30. public class CreatorGameProxy extends Proxy implements IProxy, ISelectionBarProxy
  31. {
  32. // Cake Budget Dress Budget Décor Budget Bouquet Budget Invites Budget
  33. // 0.05 0.1 0.1 0.05 0.05
  34. private static const BUDGET_SCALER_BAKERY : Number = 0.05;
  35. private static const BUDGET_SCALER_DRESSMAKER : Number = 0.1;
  36. private static const BUDGET_SCALER_PARTY : Number = 0.1;
  37. private static const BUDGET_SCALER_FLOWER : Number = 0.05;
  38. private static const BUDGET_SCALER_PRINTER : Number = 0.05;
  39. protected static const ITEM_COST_TO_MISSION_BUDGET_SCALER : Number = 0.0001;
  40.  
  41. public static const ALLOWED_OVERSPEND : Number = 1.15;
  42.  
  43. protected var _weddingObject : IUserCreatedObject;
  44. protected var _creationStepsData : Vector.<CreationStepVo>;
  45.  
  46. protected var _currentStep : uint = 0;
  47. protected var _unlockedSteps : uint = 0;
  48. protected var _numSteps : uint;
  49. protected var _displayCaseData : XML;
  50.  
  51. //cache the budget and profit scaler because they're an expensive look up
  52. private var _cachedBudget : Number = -1;
  53. private var _cachedProfitScaler : Number = -1;
  54. private var _cachedCreateTimeModifier : Number = -1;
  55. private var _cachedBuffModifier : Array = new Array;
  56.  
  57. public function CreatorGameProxy( proxyName : String = null, data : Object = null ) {
  58. super(proxyName, data);
  59. if(data) _setCreationStepsData(new XML(data));
  60. }
  61.  
  62. public function getFacade() : IFacade {
  63. return facade;
  64. }
  65.  
  66. public function setDisplayCaseData(displayCaseData : XML) : void {
  67. _displayCaseData = displayCaseData;
  68. }
  69.  
  70. public function setWeddingObject( weddingObject : IUserCreatedObject ) : void {
  71. _weddingObject = weddingObject;
  72. }
  73.  
  74. public function getCreationStepData( stepNum : uint ) : CreationStepVo {
  75. stepNum = MathUtils.clamp(stepNum, 0, _creationStepsData.length - 1);
  76. return _creationStepsData[stepNum];
  77. }
  78.  
  79. public function getCreationStepsData() : Vector.<CreationStepVo> {
  80. return _creationStepsData;
  81. }
  82.  
  83. public function getWeddingObject() : IUserCreatedObject {
  84. return _weddingObject;
  85. }
  86.  
  87. public function getCreateTime() : Number
  88. {
  89. // if(_cachedCreateTimeModifier != -1) return _cachedCreateTimeModifier;
  90.  
  91. var createTime : Number = 0;
  92. _cachedCreateTimeModifier = _cachedCreateTimeModifier == -1 ? _getCreateTimeModifier() : _cachedCreateTimeModifier;
  93.  
  94. //step 1 in the excel
  95. var itemCost : Number = _weddingObject.cost;
  96. //step 2 in the excel
  97. var originalBudget : Number;
  98. switch(_weddingObject.shoptype)
  99. {
  100. case ShopVo.BAKERY:
  101. originalBudget = itemCost / BUDGET_SCALER_BAKERY;
  102. break;
  103. case ShopVo.DRESSMAKER:
  104. originalBudget = itemCost / BUDGET_SCALER_DRESSMAKER;
  105. break;
  106. case ShopVo.FLOWER:
  107. originalBudget = itemCost / BUDGET_SCALER_FLOWER;
  108. break;
  109. case ShopVo.PARTY:
  110. originalBudget = itemCost / BUDGET_SCALER_PARTY;
  111. break;
  112. case ShopVo.PRINTER:
  113. originalBudget = itemCost / BUDGET_SCALER_PRINTER;
  114. break;
  115. }
  116. //step 3 in the spreadsheet
  117. var level : Number = originalBudget * ITEM_COST_TO_MISSION_BUDGET_SCALER;
  118. createTime = Math.max( level, Math.round(Math.pow(level, 2.44)/10)+1 );
  119. createTime *= _cachedCreateTimeModifier;
  120.  
  121. return ( Math.round(createTime)* 60 );
  122. }
  123.  
  124. private function _getCreateTimeModifier() : Number
  125. {
  126. var createTimeModifier : Number = 0;
  127.  
  128. try{
  129.  
  130. var mainfacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
  131. var userOwnedProxy : UserItemsProxy = mainfacade.retrieveProxy(UserItemsProxy.NAME) as UserItemsProxy;
  132. if(!userOwnedProxy) return createTimeModifier;
  133. //get all the users shop items
  134. var shopItems : Vector.<UserItemVO> = userOwnedProxy.getItemsByShopAndCategory(_weddingObject.shoptype);
  135.  
  136. var upgradeTable : Array = new Array();
  137. for each (var item : UserItemVO in shopItems)
  138. {
  139. //if item is an upgrade, check we have the upgrade with
  140. //the highest possible effect (highest upgrade in class)
  141. if(item.shopItemVO.category == ShoppingItemVO.CATEGORY_UPGRADE)
  142. {
  143. if( item.shopItemVO.effect_one && item.shopItemVO.effect_one.indexOf("_Time") != -1 )
  144. {
  145. //if we already found an upgrade of this type
  146. if(upgradeTable[item.shopItemVO.itemType]){
  147. //replace the last upgrade
  148. if(item.shopItemVO.magnitude_one < upgradeTable[item.shopItemVO.itemType].magnitude_one)
  149. upgradeTable[item.shopItemVO.itemType] = item.shopItemVO;
  150.  
  151. }else
  152. upgradeTable[item.shopItemVO.itemType] = item.shopItemVO;
  153. }
  154. }
  155. }
  156.  
  157. for (var type : String in upgradeTable)
  158. createTimeModifier += (upgradeTable[type] as ShoppingItemVO).magnitude_one;
  159.  
  160. createTimeModifier += (_getBuffModifier(BuffsProxy.EFFECT_TYPE_TIME, false));
  161.  
  162. // var accountProxy : AccountControllerProxy = mainfacade.retrieveProxy(AccountControllerProxy.NAME) as AccountControllerProxy;
  163. // if(!accountProxy) return createTime;
  164. // var userLevel : uint = accountProxy.accountProfile.getLevelByShop(_weddingObject.shoptype);
  165. // createTime = Math.max( userLevel, Math.round(Math.pow(userLevel, 2.44)/10)+1 );
  166. // createTime *= createTimeModifier;
  167.  
  168. }catch(error:Error){
  169. trace(error);
  170. createTimeModifier = 0;
  171. }
  172.  
  173. return createTimeModifier;
  174. // return ( Math.round(createTime)* 60 );
  175. }
  176.  
  177.  
  178. public function budgetSpent() : Number
  179. {
  180. // trace('_getBuffModifier(BuffsProxy.EFFECT_TYPE_COST): ' + (_getBuffModifier(BuffsProxy.EFFECT_TYPE_COST)));
  181.  
  182. return _weddingObject.cost * _getBuffModifier(BuffsProxy.EFFECT_TYPE_COST);
  183. }
  184.  
  185. public function budgetRemaining() : Number
  186. {
  187. if(missionType == JobTypes.TYPE_FOR_FRIEND)
  188. return Number.POSITIVE_INFINITY;
  189.  
  190. //WS-984.... The player should be able to exceed this figure by 15%
  191. //so scale the budget percent down to fit in this range
  192. return (_getBudget()*ALLOWED_OVERSPEND) - budgetSpent();
  193. }
  194.  
  195. public function budgetSpentPercent() : Number {
  196. return budgetSpent() / (_getBudget()*ALLOWED_OVERSPEND);
  197. }
  198.  
  199. public function totalBudget() : uint {
  200. return _getBudget();
  201. }
  202.  
  203. public function get currentStep() : uint {
  204. return _currentStep;
  205. }
  206.  
  207. public function get missionType() : String
  208. {
  209. var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
  210. if(missionProxy) return missionProxy.activeTaskType;
  211. return JobTypes.TYPE_DISPLAY_CASE;
  212. }
  213.  
  214. public function set currentStep( currentStep : uint) : void {
  215. _currentStep = Math.max(currentStep, 0);
  216. _currentStep = Math.min(_currentStep, numUnlockedSteps);
  217. }
  218.  
  219. public function get numUnlockedSteps() : uint {
  220. return _unlockedSteps;
  221. }
  222.  
  223. public function unlockStep( stepNum : uint) : void {
  224. getCreationStepData(stepNum).unlocked = true;
  225. _unlockedSteps = MathUtils.clamp(stepNum, 0, _creationStepsData.length - 1);
  226. }
  227.  
  228. public function resetSteps() : void {
  229. for ( var i : uint = 1;i < numSteps;i++ )
  230. getCreationStepData(i).unlocked = false;
  231.  
  232. currentStep = 0;
  233. _cachedBudget = -1;
  234. _cachedProfitScaler = -1;
  235. _cachedCreateTimeModifier = -1;
  236. _cachedBuffModifier = new Array();
  237. _weddingObject.reset();
  238. }
  239.  
  240. public function reset() : void
  241. {
  242. _creationStepsData = null;
  243. if(data) _setCreationStepsData(new XML(data));
  244. }
  245.  
  246. public function get weddingObject() : IUserCreatedObject {
  247. return _weddingObject;
  248. }
  249.  
  250. public function get numSteps() : uint {
  251. return _creationStepsData.length;
  252. }
  253.  
  254. public function getCreationAssetByExcelId( creationStep : uint, id : String ) : CreationAssetVo {
  255. for each (var asset : CreationAssetVo in _creationStepsData[creationStep].assets) {
  256. if(asset.xml)
  257. if(asset.xml.@excelId == id) return asset;
  258. }
  259.  
  260. return null;
  261. }
  262.  
  263. public function numHearts() : uint {
  264.  
  265. var numHearts : uint = 0;
  266. var mainFacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
  267. var activeMissionProxy : ActiveMissionsProxy = mainFacade.retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
  268. //if the submitted job is for the display case
  269. if( !activeMissionProxy || activeMissionProxy.activeTaskType == JobTypes.TYPE_DISPLAY_CASE ) return numHearts;
  270.  
  271. // Between 0-60% of budget, the player earns no hearts.
  272. //· Between 61-100% of budget, the player earns 1 heart.
  273. //· Between 101-115%, the player earns no hearts.
  274. var budgetPercent : Number = budgetSpent() / (_getBudget());//budgetSpentPercent();
  275. numHearts = (budgetPercent > .6 && budgetPercent < 1.1) ? 1 : 0;
  276.  
  277. return numHearts * _getBuffModifier(BuffsProxy.EFFECT_TYPE_HAPPINESS);
  278. }
  279.  
  280. public function getCompletedGoalsXML() : XML {
  281. var mainFacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
  282. var activeMissionProxy : ActiveMissionsProxy = mainFacade.retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
  283. if( !activeMissionProxy) return null;
  284.  
  285. var taskXML : XML = <task/>;
  286. taskXML.@score = numHearts();
  287.  
  288. var shoppingProxy : ShoppingProxy = mainFacade.retrieveProxy(ShoppingProxy.NAME) as ShoppingProxy;
  289. var shop : ShopVo = shoppingProxy.getShop(getWeddingObject().shoptype);
  290. taskXML.@shop_id = shop.id;
  291.  
  292. var objectives : XML = <objectives/>;
  293. taskXML.appendChild(objectives);
  294.  
  295. if(activeMissionProxy.activeTask)
  296. taskXML.@id = activeMissionProxy.activeTask.id;
  297.  
  298. return taskXML;
  299. }
  300.  
  301. protected function _getSortData() : XML
  302. {
  303. var sortData : XML = <sortCategories>
  304. <sort label="name" value="name" />
  305. <sort label="price" value="cost" />
  306. </sortCategories>;
  307. // DISABLING THE FAVORITES SORT TEMPORARILY
  308. // var sortData : XML = <sortCategories>
  309. // <sort label="name" value="name" />
  310. // <sort label="price" value="cost" />
  311. // <sort label="favorite" value="favorite" />
  312. // </sortCategories>;
  313.  
  314. return sortData;
  315. }
  316.  
  317. /**
  318. * Returns a scaler value to modifier Cost, Happiness and Time
  319. * values with if buffs/boosts are active for this creator game
  320. */
  321. protected function _getBuffModifier( effectType : String, includeUpgrades : Boolean = true ) : Number
  322. {
  323. trace("\n\nCreatorGameProxy._getBuffModifier("+arguments+")");
  324. if(_cachedBuffModifier[effectType]!=null) return _cachedBuffModifier[effectType];
  325.  
  326. var buffModifier : Number = 1;
  327. var mainFacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
  328. var buffsProxy : BuffsProxy = mainFacade.retrieveProxy(BuffsProxy.NAME) as BuffsProxy;
  329. if( buffsProxy )
  330. {
  331. var activeBuffs : Vector.<BuffVo> = buffsProxy.getShopBuffs(_weddingObject.shoptype, effectType);
  332. activeBuffs = activeBuffs.concat( buffsProxy.getShopBuffs(ShopVo.PLANNER, effectType) );
  333. if(activeBuffs.length > 0)
  334. {
  335. for each (var buff : BuffVo in activeBuffs)
  336. {
  337. trace('buff.name: ' + (buff.name ) + " : " + buff.percent);
  338. buffModifier += buff.percent;
  339. trace('buffModifier: ' + (buffModifier));
  340. }
  341. }
  342. }
  343.  
  344. var useritemsProxy : UserItemsProxy = mainFacade.retrieveProxy(UserItemsProxy.NAME) as UserItemsProxy;
  345. if( includeUpgrades && useritemsProxy )
  346. {
  347. var ownedShopItems : Vector.<UserItemVO> = useritemsProxy.getItemsByShopAndCategory( _weddingObject.shoptype, ShoppingItemVO.CATEGORY_UPGRADE );
  348. for each (var item : UserItemVO in ownedShopItems)
  349. {
  350. var highestMagnitude : Number = 0;
  351. var highestMagnitudeItem : UserItemVO;
  352.  
  353. if( item.shopItemVO.effect_one.indexOf(effectType)!=-1 )
  354. {
  355. // trace('item.shopItemVO: ' + (item.shopItemVO.itemName + " : " + item.shopItemVO.magnitude_one) );
  356. if( highestMagnitude < Math.abs(item.shopItemVO.magnitude_one) )
  357. {
  358. highestMagnitude = Math.abs(item.shopItemVO.magnitude_one);
  359. highestMagnitudeItem = item;
  360. }
  361. // buffModifier += item.shopItemVO.magnitude_one;
  362. }
  363. }
  364. if(highestMagnitudeItem) buffModifier += highestMagnitudeItem.shopItemVO.magnitude_one;
  365. }
  366.  
  367. //if its a happiness bu
  368. // if(effectType==BuffsProxy.EFFECT_TYPE_HAPPINESS)
  369. // buffModifier = 1 + (1-buffModifier);
  370.  
  371. _cachedBuffModifier[effectType] = buffModifier;
  372. return (buffModifier);
  373. }
  374.  
  375. protected function _jobData() : JobVo {
  376. var job : JobVo;
  377. var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
  378. if(missionProxy) job = missionProxy.activeTask;
  379.  
  380. return job;
  381. }
  382.  
  383. protected function _missionData() : MissionVo {
  384. var mission : MissionVo;
  385. var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
  386. if(missionProxy && missionProxy.activeTask)
  387. mission = missionProxy.getMissionByChildJob(missionProxy.activeTask);
  388.  
  389. return mission;
  390. }
  391.  
  392. protected function _getBudget() : Number
  393. {
  394. if(_cachedBudget != -1) return _cachedBudget;
  395.  
  396. //test budget ammount
  397. var totalBudget : Number = 1500;
  398. var job : JobVo = _jobData();
  399. if( job )
  400. totalBudget = job.budget;
  401. else if(_displayCaseData)
  402. {
  403. var managerXML : XML = _getActiveShopManagerXML();
  404. if(managerXML) totalBudget = Number(managerXML.budgetMax);
  405. }
  406. _cachedBudget = totalBudget;
  407. return totalBudget;
  408. }
  409.  
  410. protected function _getActiveShopManagerXML() : XML
  411. {
  412. //if mission type is for display case
  413. var missionProxy : ActiveMissionsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(ActiveMissionsProxy.NAME) as ActiveMissionsProxy;
  414. var buffsProxy : BuffsProxy = Facade.getInstance(FacadeNames.MAIN).retrieveProxy(BuffsProxy.NAME) as BuffsProxy;
  415.  
  416. if(buffsProxy && missionProxy && missionProxy.activeTaskType == JobTypes.TYPE_DISPLAY_CASE)
  417. {
  418. var activeBuffs : Vector.<BuffVo> = buffsProxy.getShopBuffs(_weddingObject.shoptype);
  419. //should be a display case manager buff here but just in case
  420. if(activeBuffs.length>0)
  421. {
  422. var strongestBuff : BuffVo = activeBuffs[0];
  423. //find the highest ranking active manager buff
  424. for each (var buff : BuffVo in activeBuffs)
  425. if(buff.excel_id > strongestBuff.excel_id) strongestBuff = buff;
  426.  
  427. return _displayCaseData.manager.(@excelId == strongestBuff.excel_id)[0];
  428. }
  429. }
  430.  
  431. return null;
  432. }
  433.  
  434. protected function _getProfitScaler() : Number
  435. {
  436. if(_cachedProfitScaler != -1) return _cachedProfitScaler;
  437. var managerXML : XML = _getActiveShopManagerXML();
  438. if(managerXML) _cachedProfitScaler = managerXML.profitmult;
  439. else _cachedProfitScaler = 0;
  440. return _cachedProfitScaler;
  441. }
  442.  
  443. protected function _getMissionBudget() : Number {
  444. return _missionData() == null ? 0 : _missionData().budget;
  445. }
  446.  
  447. protected function _setCreationStepsData( gameXML : XML ) : void {
  448. _creationStepsData = new Vector.<CreationStepVo>();
  449. var stepData : CreationStepVo, stepName : String, stepInstructions : String, stepType : String, sortCategories : SortVo;
  450.  
  451. for (var i : int = 0;i < gameXML..creatorPanel.length();i++) {
  452. stepName = gameXML..creatorPanel[i].@btnLabel;
  453. stepInstructions = gameXML..creatorPanel[i].instructions_txt.toString();
  454. stepType = gameXML..creatorPanel[i].@type;
  455. sortCategories = _getSortCategories(gameXML..creatorPanel[i].sortCategories..sort);
  456. stepData = new CreationStepVo(i, stepName, stepType, sortCategories);
  457. stepData.unlocked = gameXML..creatorPanel[i].@locked == "false";
  458.  
  459. var assetsPath : String = gameXML..creatorPanel[i].@assetsPath;
  460. if(assetsPath) stepData.assetsPath = assetsPath;
  461. var iconsPath : String = gameXML..creatorPanel[i].@iconsPath;
  462. if(iconsPath) stepData.iconsPath = iconsPath;
  463.  
  464. _setCreationAssets(stepData, gameXML..creatorPanel[i].uiAssets..btn);
  465.  
  466. _creationStepsData[i] = stepData;
  467. trace(_creationStepsData[i].assets.length);
  468. }
  469.  
  470. _creationStepsData[0].unlocked = true;
  471. }
  472.  
  473. protected function _setCreationAssets( stepData : CreationStepVo, assetsXMLList : XMLList ) : void {
  474. for each(var assetData : XML in assetsXMLList) {
  475. var id : uint = stepData.assets.length;
  476. var name : String = assetData.@name;
  477. var description : String = assetData.@description;
  478. var type : String = assetData.@type;
  479. var assetLinkageId : String = assetData.@assetLinkageId;
  480. var unlocked : Boolean = assetData.@unlocked == "true";
  481. var favorite : Boolean = assetData.@favorite == "true";
  482. var cost : Number = Number(assetData.@cost);
  483. var createTime : Number = Number(assetData.@createTime);
  484. var colordata : String = assetData.@colordata;
  485. var metadata : String = assetData.@metadata;
  486. var xformdata : String = assetData.@xformdata;
  487.  
  488. var assetVo : CreationAssetVo = new CreationAssetVo(id, name, description, type, assetLinkageId, unlocked, favorite, cost, createTime, colordata, metadata, xformdata);
  489.  
  490. assetVo.assetPath = stepData.assetsPath;
  491. assetVo.iconPath = stepData.iconsPath;
  492. assetVo.file = assetData.asset.@file;
  493. assetVo.icon = assetData.asset.@icon;
  494. assetVo.xml = assetData;
  495. stepData.assets.push(assetVo);
  496. }
  497. }
  498.  
  499. protected function _getSortCategories( assetsXMLList : XMLList ) : SortVo {
  500. var labels : Vector.<String> = new Vector.<String>;
  501. var values : Vector.<String> = new Vector.<String>;
  502. var filters : Vector.<String> = new Vector.<String>;
  503.  
  504. for each(var assetData : XML in assetsXMLList) {
  505. labels.push(assetData.@label);
  506. values.push(assetData.@value);
  507. filters.push(assetData.@filter);
  508. }
  509. var sortVo : SortVo = new SortVo(labels, values, filters);
  510. return sortVo;
  511. }
  512.  
  513. /**
  514. * Check whether the user owns the asset
  515. *
  516. * @param assetData
  517. */
  518. protected function _assetInInventory(assetData : XML) : Boolean {
  519. //if asset has no friend points costs its free to use (and doesnt have to exist in inventory)
  520. if(assetData.hasOwnProperty("fp_cost") && uint(assetData.fp_cost.text()) == 0) return true;
  521.  
  522. var mainfacade : IFacade = Facade.getInstance(FacadeNames.MAIN);
  523. var userOwnedProxy : UserItemsProxy = mainfacade.retrieveProxy(UserItemsProxy.NAME) as UserItemsProxy;
  524.  
  525. //if no useritems proxy we're running in standalone mode so unlock all items
  526. if(!userOwnedProxy) return true;
  527. return userOwnedProxy.getItemsByName(assetData.name.text()).length > 0;
  528. }
  529.  
  530. /**
  531. * Returns a vector of selected assets that need to be purchased
  532. *
  533. * @return Vector.<CreationAssetVo>
  534. */
  535. public function getLockedItems() : Vector.<CreationAssetVo> {
  536. var lockedItems : Vector.<CreationAssetVo> = new Vector.<CreationAssetVo>();
  537. var selectedItems : Vector.<CreationAssetVo> = _weddingObject.getAssets();
  538.  
  539. for each (var item : CreationAssetVo in selectedItems) {
  540. if(item && !item.unlocked) {
  541. lockedItems.push(item);
  542. }
  543. }
  544.  
  545. return lockedItems;
  546. }
  547.  
  548. public function getItemById(id : uint) : CreationAssetVo {
  549. for each (var stepData : CreationStepVo in _creationStepsData) {
  550. for each (var asset : CreationAssetVo in stepData.assets)
  551. {
  552.  
  553. //if asset is a variant iterate through all the
  554. //variants assets
  555. if(asset is VariantAssetVo)
  556. {
  557. for each (var variant : CreationAssetVo in (asset as VariantAssetVo).variants )
  558. {
  559. if(variant.id == id) return variant;
  560. }
  561.  
  562. }else if(asset.id == id) return asset;
  563. }
  564. }
  565. return null;
  566. }
  567.  
  568. public function getItemRetailPrice() : Number
  569. {
  570. return (_getProfitScaler() * budgetSpent());
  571. // return _weddingObject.cost + (_getProfitScaler() * _weddingObject.cost);
  572. }
  573.  
  574. public function getCreationStepCost( stepNum : uint) : uint
  575. {
  576. var cost : uint = 0;
  577. var selectedAssets : Vector.<CreationAssetVo> = _weddingObject.getAssets();
  578.  
  579. for each (var asset : CreationAssetVo in selectedAssets)
  580. {
  581. if(asset==null) continue;
  582. //this is slow, but we have to use ids instead of indexOf because this could be a clone
  583. for each (var stepAsset : CreationAssetVo in _creationStepsData[stepNum].assets)
  584. if( stepAsset.excelId == asset.excelId )
  585. cost += asset.cost;
  586.  
  587. // if( _creationStepsData[stepNum].assets.indexOf(asset)!=-1 )
  588. }
  589.  
  590. return cost;
  591. }
  592.  
  593. }
  594. }
Add Comment
Please, Sign In to add comment