Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.97 KB | None | 0 0
  1. /***********************************************************************/
  2. /** © 2015 CD PROJEKT S.A. All rights reserved.
  3. /** THE WITCHER® is a trademark of CD PROJEKT S. A.
  4. /** The Witcher game is based on the prose of Andrzej Sapkowski.
  5. /***********************************************************************/
  6. struct SCookingSchematic
  7. {
  8. var cookedItemName : name;
  9. var cookedItemQuantity : int;
  10. var ingredients : array<SItemParts>;
  11. var schemName : name;
  12. };
  13.  
  14. abstract class W3CookingPlace extends W3Container
  15. {
  16.  
  17. editable var cookingTime : float;
  18.  
  19. private var schematics : array<SCookingSchematic>;
  20.  
  21. protected var isActive : bool;
  22.  
  23. protected var cookingStarted : bool;
  24. protected var cookingCompleted : bool;
  25.  
  26. protected autobind secondaryLootInteractionComponent : CInteractionComponent = "Loot2";
  27.  
  28. default cookingTime = 1.0;
  29.  
  30. event OnSpawned( spawnData : SEntitySpawnData )
  31. {
  32. super.OnSpawned(spawnData);
  33. LoadXMLData();
  34.  
  35. if ( schematics.Size() <= 0 )
  36. LogChannel('CookingPlace', "No cooking schematics was loaded from the XML! for: " + this);
  37.  
  38. isActive = true;
  39. cookingCompleted = false;
  40. cookingStarted = false;
  41. }
  42.  
  43.  
  44. event OnInteraction( actionName : string, activator : CEntity )
  45. {
  46. var hud : CR4ScriptedHud;
  47. if ( activator != thePlayer || isInteractionBlocked)
  48. return false;
  49.  
  50. if(actionName != "Container")
  51. return false;
  52.  
  53. if(cookingCompleted)
  54. {
  55. TakeAllItems();
  56. OnContainerClosed();
  57. cookingCompleted = false;
  58. if( lootInteractionComponent && secondaryLootInteractionComponent )
  59. {
  60. lootInteractionComponent.SetEnabled(true);
  61. secondaryLootInteractionComponent.SetEnabled(false);
  62. }
  63. }
  64. else
  65. {
  66. theGame.RequestMenuWithBackground( 'InventoryMenu', 'CommonMenu', this );
  67. }
  68.  
  69. return true;
  70. }
  71.  
  72. public function OnContainerClosed()
  73. {
  74. super.OnContainerClosed();
  75.  
  76. if ( !IsEmpty() && this.isActive )
  77. {
  78. if ( Cook() )
  79. {
  80. CookingStarted();
  81. lfilled && !listener )
  82. {
  83. RegisterListener( true );
  84. }
  85. return isFulfilled;
  86. }
  87.  
  88. public function EvaluateImpl()
  89. {
  90. isFulfilled = false;
  91. if ( bookFactName == "" )
  92. {
  93. if( IsNameValid( bookName ) )
  94. {
  95. bookFactName = GetBooar ing : SItemParts;
  96.  
  97. dm = theGame.GetDefinitionsManager();
  98. main = dm.GetCustomDefinition('cooking_recipes');
  99.  
  100.  
  101. for(i=0; i<main.subNodes.Size(); i+=1)
  102. {
  103. if( dm.GetCustomNodeAttributeValueName(main.subNodes[i], 'name_name', tmpName) )
  104. schem.schemName = tmpName;
  105.  
  106. if(dm.GetCustomNodeAttributeValueName(main.subNodes[i], 'cookedItem_name', tmpName))
  107. schem.cookedItemName = tmpName;
  108.  
  109. if(dm.GetCustomNodeAttributeValueInt(main.subNodes[i], 'cookedItemQuantity', tmpInt))
  110. schem.cookedItemQuantity = tmpInt;
  111.  
  112.  
  113. ingredients = dm.GetCustomDefinitionSubNode(main.subNodes[i],'ingredients');
  114. for(k=0; k<ingredients.subNodes.Size(); k+=1)
  115. {
  116. ing.itemName = '';
  117. ing.quantity = -1;
  118.  
  119. if(dm.GetCustomNodeAttributeValueName(ingredients.subNodes[k], 'item_name', tmpName))
  120. ing.itemName = tmpName;
  121. if(dm.GetCustomNodeAttributeValueInt(ingredients.subNodes[k], 'quantity', tmpInt))
  122. ing.quantity = tmpInt;
  123.  
  124. schem.ingredients.PushBack(ing);
  125. }
  126.  
  127. schematics.PushBack(schem);
  128.  
  129.  
  130. schem.cookedItemName = '';
  131. schem.ingredients.Clear();
  132. schem.schemName = '';
  133. }
  134. }
  135.  
  136.  
  137.  
  138. protected function CookingStarted()
  139. {
  140. cookingStarted = true;
  141.  
  142. if( lootInteractionComponent )
  143. {
  144. lootInteractionComponent.SetEnabled(false);
  145. }
  146.  
  147. AddTimer('Cooking',cookingTime,false, , , true);
  148. }
  149.  
  150. protected function CookingDone()
  151. {
  152. cookingStarted = false;
  153. if ( !this.IsEmpty() )
  154. {
  155. cookingCompleted = true;
  156.  
  157. if( lootInteractionComponent && secondaryLootInteractionComponent )
  158. {
  159. lootInteractionComponent.SetEnabled(false);
  160. secondaryLootInteractionComponent.SetEnabled(true);
  161. }
  162. }
  163. else
  164. {
  165. cookingCompleted = false;
  166.  
  167. if( lootInteractionComponent && secondaryLootInteractionComponent )
  168. {
  169. lootInteractionComponent.SetEnabled(true);
  170. secondaryLootInteractionComponent.SetEnabled(false);
  171. }
  172. }
  173. }
  174.  
  175. private timer function Cooking( dt : float , id : int)
  176. {
  177. CookingDone();
  178. }
  179.  
  180.  
  181. protected function Cook() : bool
  182. {
  183. var allItems : array< SItemUniqueId >;
  184. var ingredients : array< SItemParts >;
  185. var matchedIngredients : array< SItemParts >;
  186. var tmpItems : array<SItemUniqueId>;
  187. var tmpIngredient : SItemParts;
  188. var tmpSchematicsIterator : int;
  189. var tmpSchematic : SCookingSchematic;
  190. var i, tmpQuantity, quantity : int;
  191.  
  192. if( inv )
  193. {
  194. inv.GetAllItems( allItems );
  195. }
  196.  
  197. if ( allItems.Size() == 0 )
  198. return false;
  199.  
  200.  
  201. for(i=0; i<allItems.Size(); i+=1)
  202. {
  203. tmpIngredient.itemName = inv.GetItemName(allItems[i]);
  204. tmpIngredient.quantity = inv.GetItemQuantity(allItems[i]);
  205.  
  206. ingredients.PushBack(tmpIngredient);
  207.  
  208. }
  209.  
  210.  
  211. tmpSchematicsIterator = FindSchematicForIngredients( ingredients, matchedIngredients );
  212.  
  213. if ( tmpSchematicsIterator != -1 )
  214. {
  215. tmpSchematic = schematics[tmpSchematicsIterator];
  216.  
  217. for ( i=0 ; i<matchedIngredients.Size() ; i+=1 )
  218. {
  219.  
  220. tmpQuantity = FloorF( matchedIngredients[i].quantity/tmpSchematic.ingredients[i].quantity );
  221. if ( i==0 || tmpQuantity <= quantity )
  222. quantity = tmpQuantity;
  223. }
  224.  
  225. UseSchematic(schematics[tmpSchematicsIterator], quantity);
  226.  
  227. for ( i=0 ; i<matchedIngredients.Size() ; i+=1 )
  228. {
  229. matchedIngredients[i].quantity *= quantity;
  230. }
  231.  
  232. UseIngredients(matchedIngredients);
  233.  
  234. return true;
  235. }
  236.  
  237. if( allItems.Size() > 1 )
  238. return false;
  239.  
  240.  
  241. if (tmpIngredient.quantity > 1 )
  242. tmpSchematicsIterator = FindSchematicByIngredientName(tmpIngredient.itemName);
  243. else
  244. return false;
  245.  
  246. if ( tmpSchematicsIterator != -1 )
  247. {
  248. tmpSchematic = schematics[tmpSchematicsIterator];
  249. if (tmpSchematic.ingredients.Size() == 1 )
  250. {
  251. tmpIngredient = tmpSchematic.ingredients[0];
  252.  
  253. if( !inv )
  254. {
  255. quantity = 0;
  256. }
  257. else
  258. {
  259. quantity = FloorF(inv.GetItemQuantity(allItems[0])/tmpIngredient.quantity);
  260. }
  261.  
  262. tmpIngredient.quantity *= quantity;
  263.  
  264. UseSchematic(tmpSchematic, quantity);
  265.  
  266. matchedIngredients.Clear();
  267. matchedIngredients.PushBack(tmpIngredient);
  268.  
  269. UseIngredients(matchedIngredients);
  270.  
  271. return true;
  272. }
  273. }
  274.  
  275. return false;
  276. }
  277.  
  278. private function UseSchematic( schematic : SCookingSchematic, optional quantity : int )
  279. {
  280. var i : int;
  281.  
  282. if ( !quantity )
  283. quantity = 1;
  284.  
  285. LogChannel('CookingPlace', "Used Schematic: " + schematic.schemName);
  286.  
  287.  
  288. for ( i=0 ; i < quantity ; i+=1 )
  289. {
  290. if( schematic.cookedItemQuantity >= 1 )
  291. {
  292. LogChannel('CookingPlace', "Adding: " + schematic.cookedItemName + " to the inventory");
  293. if( inv )
  294. {
  295. inv.AddAnItem(schematic.cookedItemName, schematic.cookedItemQuantity);
  296. }
  297. }
  298. }
  299.  
  300. switch ( schematic.schemName )
  301. {
  302. case 'Voodoo doll Curse' : VoodooDollCurse(); break;
  303. case 'Treasure Nekker' : TreasureNekker(); break;
  304. case 'Spawn Random Enemies' : SpawnRandomEnemies(); break;
  305. case 'Master of Puppets' : break;
  306. default: break;
  307. }
  308. }
  309.  
  310. private function UseIngredients( items : array< SItemParts >)
  311. {
  312. var i,j : int;
  313. var itemIds : array<SItemUniqueId>;
  314.  
  315. if( !inv )
  316. {
  317. return;
  318. }
  319.  
  320. for ( i=0 ; i<items.Size() ; i+=1 )
  321. {
  322. itemIds = inv.GetItemsIds(items[i].itemName);
  323. for ( j=0 ; j<itemIds.Size() ; j+=1 )
  324. {
  325. if(!inv.ItemHasTag(itemIds[j], 'Quest') && inv.GetItemName(itemIds[j]) != 'Philosophers Stone' )
  326. {
  327.  
  328. inv.RemoveItem(itemIds[j],items[i].quantity);
  329. }
  330. }
  331. }
  332. }
  333.  
  334.  
  335. protected function FindSchematicForIngredients( ingredients : array<SItemParts>, out matchedIngredients : array<SItemParts> ) : int
  336. {
  337. var i,j,k : int;
  338. var outIngredient : SItemParts;
  339.  
  340.  
  341.  
  342. for ( i=0 ; i<schematics.Size() ; i+=1 )
  343. {
  344. matchedIngredients.Clear();
  345. for ( j=0 ; j<schematics[i].ingredients.Size() ; j+=1 )
  346. {
  347. for ( k=0 ; k<ingredients.Size() ; k+=1)
  348. {
  349. if ( schematics[i].ingredients[j].itemName == ingredients[k].itemName )
  350. {
  351. if ( schematics[i].ingredients[j].quantity <= ingredients[k].quantity )
  352. matchedIngredients.PushBack(ingredients[k]);
  353. }
  354. }
  355. }
  356. if ( matchedIngredients.Size() == schematics[i].ingredients.Size() )
  357. {
  358. return i;
  359. }
  360. }
  361.  
  362. return -1;
  363. }
  364.  
  365. protected function FindSchematicByIngredientName( ingredientName : name ) : int
  366. {
  367. var i,j : int;
  368.  
  369. for ( i=0 ; i<schematics.Size() ; i+=1 )
  370. {
  371. for ( j=0 ; j<schematics[i].ingredients.Size() ; j+=1 )
  372. {
  373. if ( schematics[i].ingredients[j].itemName == ingredientName )
  374. {
  375. return i;
  376. }
  377. }
  378. }
  379.  
  380. return -1;
  381. }
  382.  
  383.  
  384. protected function VoodooDollCurse();
  385.  
  386. protected function TreasureNekker(){}
  387.  
  388. protected function SpawnRandomEnemies(){}
  389.  
  390. }
  391.  
  392. class W3CampfirePlace extends W3CookingPlace
  393. {
  394. protected var victims : array<CActor>;
  395. var bombs : array<SItemUniqueId> ;
  396.  
  397. protected function CookingStarted()
  398. {
  399. super.CookingStarted();
  400. PlayEffect('fire_big');
  401. }
  402.  
  403. protected function CookingDone()
  404. {
  405. StopEffect('fire_big');
  406. ExplodeBombs();
  407. bombs.Clear();
  408. super.CookingDone();
  409. }
  410.  
  411. event OnFireHit(source : CGameplayEntity)
  412. {
  413. super.OnFireHit(source);
  414. if ( !isActive )
  415. {
  416. isActive = true;
  417. PlayEffect('fire_01');
  418. OnContainerClosed();
  419. }
  420. }
  421. event OnAardHit( sign : W3AardProjectile )
  422. {
  423. super.OnAardHit( sign );
  424. if ( isActive )
  425. {
  426. isActive = false;
  427. StopEffect('fire_01');
  428. }
  429.  
  430. }
  431.  
  432.  
  433. event OnInteractionActivated( interactionComponentName : string, activator : CEntity )
  434. {
  435. var victim : CActor;
  436.  
  437. if ( interactionComponentName == "DamageArea" )
  438. {
  439. victim = (CActor)activator;
  440. if ( victim && isActive )
  441. {
  442. victims.PushBack(victim);
  443. if ( victims.Size() == 1 )
  444. AddTimer( 'ApplyBurning', 0.1, true );
  445. }
  446. }
  447. else
  448. super.OnInteractionActivated(interactionComponentName, activator);
  449. }
  450.  
  451.  
  452. event OnInteractionDeactivated( interactionComponentName : string, activator : CEntity )
  453. {
  454. var victim : CActor;
  455. if ( interactionComponentName == "DamageArea" )
  456. {
  457. victim = (CActor)activator;
  458. if ( victims.Contains(victim) )
  459. {
  460. victims.Remove(victim);
  461. if ( victims.Size() == 0 )
  462. RemoveTimer( 'ApplyBurning' );
  463. }
  464. }
  465. super.OnInteractionDeactivated(interactionComponentName, activator);
  466. }
  467.  
  468. timer function ApplyBurning( dt : float , id : int)
  469. {
  470. var i : int;
  471.  
  472. for ( i=0; i<victims.Size(); i+=1 )
  473. victims[i].AddEffectDefault( EET_Burning, this, this.GetName() );
  474. }
  475.  
  476. function OnContainerClosed()
  477. {
  478. var allItems : array< SItemUniqueId >;
  479. var i : int;
  480.  
  481. bombs.Clear();
  482.  
  483. if ( inv && !IsEmpty() && isActive )
  484. {
  485. inv.GetAllItems( allItems );
  486.  
  487. for ( i=0; i < allItems.Size() ; i+=1)
  488. {
  489. if ( inv.IsItemBomb(allItems[i]) )
  490. bombs.PushBack(allItems[i]);
  491. }
  492.  
  493. }
  494.  
  495. super.OnContainerClosed();
  496.  
  497. if ( !cookingStarted && bombs.Size() >= 1 )
  498. CookingStarted();
  499.  
  500. }
  501.  
  502. function ExplodeBombs()
  503. {
  504. var i : int;
  505. var bombEntity : W3Petard;
  506.  
  507. if( !inv )
  508. {
  509. return;
  510. }
  511.  
  512. for ( i=0; i < bombs.Size() ; i+=1)
  513. {
  514. bombEntity = (W3Petard)inv.GetDeploymentItemEntity( bombs[i], this.GetWorldPosition() );
  515. if ( bombEntity )
  516. {
  517. inv.RemoveItem(bombs[i],inv.GetItemQuantity(bombs[i]));
  518. bombEntity.Initialize(NULL);
  519. bombEntity.ProcessEffect();
  520. }
  521. }
  522. }
  523.  
  524. protected function VoodooDollCurse()
  525. {
  526. var params : SCustomEffectParams;
  527.  
  528. params.effectType = EET_Burning;
  529. params.creator = this;
  530. params.duration = 30;
  531.  
  532. thePlayer.AddEffectCustom(params);
  533. }
  534. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement