Advertisement
Thibaudv

AlchemyManager.ws

Oct 25th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.56 KB | None | 0 0
  1. public function IsBaseForRecipe( recipe : SAlchemyRecipe, itemName : name ) : bool //recipe.level = 1 or recipe.level == 1 ?????? MIGHT BE CAUSING ERRORS
  2. {
  3. /*
  4. if( recipe.cookedItemType == EACIT_Potion && recipe.level == 1 && IsPotionDilutor( itemName ) )
  5. {
  6. return true;
  7. }
  8. if( recipe.cookedItemType == EACIT_Potion && recipe.level == 2 && IsEnhancedPotionDilutor( itemName ) )
  9. {
  10. return true;
  11. }
  12. if( recipe.cookedItemType == EACIT_Potion && recipe.level == 3 && IsSuperiorPotionDilutor( itemName ) )
  13. {
  14. return true;
  15. }
  16. if( recipe.cookedItemType == EACIT_MutagenPotion && IsDecoctionDilutor( itemName ) )
  17. {
  18. return true;
  19. }
  20. if( recipe.cookedItemType == EACIT_Oil && recipe.level == 1 && IsOilDilutor( itemName ) )
  21. {
  22. return true;
  23. }
  24. if( recipe.cookedItemType == EACIT_Oil && recipe.level == 2 && IsEnhancedOilDilutor( itemName ) )
  25. {
  26. return true;
  27. }
  28. if( recipe.cookedItemType == EACIT_Oil && recipe.level == 3 && IsSuperiorOilDilutor( itemName ) )
  29. {
  30. return true;
  31. }
  32. if( recipe.cookedItemType == EACIT_Bomb && recipe.level == 1 && IsBombDilutor( itemName ) )
  33. {
  34. return true;
  35. }
  36. if( recipe.cookedItemType == EACIT_Bomb && recipe.level == 2 && IsEnhancedBombDilutor( itemName ) )
  37. {
  38. return true;
  39. }
  40. //if( recipe.cookedItemType == EACIT_Bomb && recipe.level == 3 && IsSuperiorBombDilutor( itemName ) )
  41. //{
  42. // return true;
  43. //}
  44. return false;
  45. }*/
  46.  
  47.  
  48.  
  49. if( ( recipe.cookedItemType == EACIT_Potion || recipe.cookedItemType == EACIT_MutagenPotion ) &&
  50. IsAlcohol( itemName ) )
  51. {
  52. return true;
  53. }
  54. if( recipe.cookedItemType == EACIT_Bomb && IsPowder( itemName ) )
  55. {
  56. return true;
  57. }
  58. if( recipe.cookedItemType == EACIT_Oil && IsFat( itemName ) )
  59. {
  60. return true;
  61. }
  62. return false;
  63. }
  64.  
  65.  
  66. public function IsRefillNeeded( recipe : SAlchemyRecipe ) : bool
  67. {
  68. var ids : array<SItemUniqueId>;
  69.  
  70. if( theGame.GetDefinitionsManager().IsItemSingletonItem( recipe.cookedItemName ) &&
  71. ( recipe.cookedItemType == EACIT_Potion || recipe.cookedItemType == EACIT_MutagenPotion ||
  72. recipe.cookedItemType == EACIT_Bomb || recipe.cookedItemType == EACIT_Oil ) )
  73. {
  74. ids = thePlayer.inv.GetItemsByName( recipe.cookedItemName );
  75. if( ids.Size() == 1 )
  76. {
  77. if( thePlayer.inv.SingletonItemGetAmmo( ids[0] ) < thePlayer.inv.SingletonItemGetMaxAmmo( ids[0] ) )
  78. {
  79. return true;
  80. }
  81. }
  82. }
  83. return false;
  84. }
  85.  
  86. public function IsAlcohol( item : name ) : bool
  87. {
  88. if( item == 'Dwarven spirit' || item == 'Alcohest' || item == 'White Gull 1' )
  89. {
  90. return true;
  91. }
  92. return false;
  93. }
  94.  
  95. public function IsPowder( item : name ) : bool
  96. {
  97. if( item == 'Saltpetre' || item == 'Stammelfords dust' || item == 'Alchemists powder' )
  98. {
  99. return true;
  100. }
  101. return false;
  102. }
  103.  
  104. public function IsFat( item : name ) : bool
  105. {
  106. if( item == 'Dog tallow' || item == 'Bear fat' || item == 'Alchemical paste' )
  107. {
  108. return true;
  109. }
  110. return false;
  111. }
  112.  
  113.  
  114. public function CalculateCookChance( recipe : SAlchemyRecipe ) : int
  115. {
  116. if( recipe.cookedItemType == EACIT_Oil )
  117. return 0;
  118. else
  119. return 100;
  120. }
  121.  
  122. /*if ( ( recipe.cookedItemType ) == EACIT_Potion )
  123. || ( theGame.GetDefinitionsManager().IsItemSingletonItem( recipe.cookedItemType ) == EACIT_Oil )
  124. || ( theGame.GetDefinitionsManager().IsItemSingletonItem( recipe.cookedItemType ) == EACIT_Bomb )
  125. && recipe.level == 1 )
  126. return 75;
  127. else if ( theGame.GetDefinitionsManager().IsItemSingletonItem( recipe.cookedItemName ) &&( recipe.cookedItemType == EACIT_Potion || recipe.cookedItemType == EACIT_Oil || recipe.cookedItemType == EACIT_Bomb ) && recipe.level == 2 )
  128. return 55;
  129. else if ( theGame.GetDefinitionsManager().IsItemSingletonItem( recipe.cookedItemName )( recipe.cookedItemType == EACIT_Potion || recipe.cookedItemType == EACIT_Oil || recipe.cookedItemType == EACIT_Bomb ) && recipe.level == 3 )
  130. return 40;
  131. else if ( theGame.GetDefinitionsManager().IsItemSingletonItem( recipe.cookedItemName )recipe.cookedItemType == EACIT_MutagenPotion )
  132. return 45;
  133. else
  134. return 0;
  135. }*/
  136.  
  137. public function IsPotionDilutor( item : name ) : bool
  138. {
  139. if( item == 'Potion Dilutor 1' || item == 'Potion Dilutor 2' || item == 'Potion Dilutor 3' || item == 'Dog Tallow' )
  140. {
  141. return true;
  142. }
  143. return false;
  144. }
  145.  
  146. public function IsEnhancedPotionDilutor( item : name ) : bool
  147. {
  148. if( item == 'Enhanced Potion Dilutor 1' || item == 'Enhanced Potion Dilutor 2' || item == 'Enhanced Potion Dilutor 3' )
  149. {
  150. return true;
  151. }
  152. return false;
  153. }
  154.  
  155. public function IsSuperiorPotionDilutor( item : name ) : bool
  156. {
  157. if( item =='Superior Potion Dilutor 1' || item =='Superior Potion Dilutor 2' || item == 'Superior Potion Dilutor 3' )
  158. {
  159. return true;
  160. }
  161. return false;
  162. }
  163.  
  164. public function IsDecoctionDilutor( item : name ) : bool
  165. {
  166. if( item == 'Decoction Dilutor 1' || item == 'Decoction Dilutor 2' || item == 'Decoction Dilutor 3' )
  167. {
  168. return true;
  169. }
  170. return false;
  171. }
  172.  
  173. public function IsOilDilutor( item : name ) : bool
  174. {
  175. if( item == 'Oil Dilutor 1' || item == 'Oil Dilutor 2' || item == 'Oil Dilutor 3' )
  176. {
  177. return true;
  178. }
  179. return false;
  180. }
  181.  
  182. public function IsEnhancedOilDilutor( item : name ) : bool
  183. {
  184. if( item == 'Enhanced Oil Dilutor 1' || item == 'Enhanced Oil Dilutor 2' || item == 'Enhanced Oil Dilutor 3' )
  185. {
  186. return true;
  187. }
  188. return false;
  189. }
  190.  
  191. public function IsSuperiorOilDilutor( item : name ) : bool
  192. {
  193. if( item == 'Superior Oil Dilutor 1' || item == 'Superior Oil Dilutor 2' || item == 'Superior Oil Dilutor 3' )
  194. {
  195. return true;
  196. }
  197. return false;
  198. }
  199.  
  200. public function IsBombDilutor( item : name ) : bool
  201. {
  202. if( item == 'Bomb Dilutor 1' || item == 'Bomb Dilutor 2' || item == 'Bomb Dilutor 3' )
  203. {
  204. return true;
  205. }
  206. return false;
  207. }
  208.  
  209. public function IsEnhancedBombDilutor( item : name ) : bool
  210. {
  211. if( item == 'Enhanced Bomb Dilutor 1' || item == 'Enhanced Bomb Dilutor 2' || item == 'Enhanced Bomb Dilutor 3')
  212. {
  213. return true;
  214. }
  215. return false;
  216. }
  217.  
  218. /*public function IsSuperiorBombDilutor( itme : name ) : bool
  219. {
  220. if( item == 'Superior Bomb Dilutor 1' || item == 'Superior Bomb Dilutor 2' || item == 'Superior Bomb Dilutor 3')
  221. {
  222. return true;
  223. }
  224. return false;
  225. }*/
  226.  
  227.  
  228.  
  229. public function CookItem(recipeName : name)
  230. {
  231. var i, j, quantity, removedIngQuantity, maxAmmo, setAmmo: int;
  232. var recipe : SAlchemyRecipe;
  233. var dm : CDefinitionsManagerAccessor;
  234. var crossbowID : SItemUniqueId;
  235. var min, max : SAbilityAttributeValue;
  236. var uiStateAlchemy : W3TutorialManagerUIHandlerStateAlchemy;
  237. var uiStateAlchemyMutagens : W3TutorialManagerUIHandlerStateAlchemyMutagens;
  238. var ids : array<SItemUniqueId>;
  239. var items, alchIngs : array<SItemUniqueId>;
  240. var isPotion, isSingletonItem : bool;
  241. var witcher : W3PlayerWitcher;
  242. var equippedOnSlot : EEquipmentSlots;
  243. //---=== modPreparations ===---
  244. var refillNeeded : bool;
  245. var refilled : bool;
  246. //---=== modPreparations ===---
  247. //MODSOR++
  248. var cookChance: int;
  249. cookChance = CalculateCookChance( recipe );
  250. /*
  251. if ( ( recipe.cookedItemType == EACIT_Potion || recipe.cookedItemType == EACIT_Oil || recipe.cookedItemType == EACIT_Bomb ) && recipe.level == 1 )
  252. cookChance = 75;
  253. else if ( ( recipe.cookedItemType == EACIT_Potion || recipe.cookedItemType == EACIT_Oil || recipe.cookedItemType == EACIT_Bomb ) && recipe.level == 2 )
  254. cookChance = 55;
  255. else if ( ( recipe.cookedItemType == EACIT_Potion || recipe.cookedItemType == EACIT_Oil || recipe.cookedItemType == EACIT_Bomb ) && recipe.level == 3 )
  256. cookChance = 40;
  257. else if ( recipe.cookedItemType == EACIT_MutagenPotion )
  258. cookChance = 45;*/
  259.  
  260. GetRecipe(recipeName, recipe);
  261.  
  262. //calculate quantity to cook
  263. equippedOnSlot = EES_InvalidSlot;
  264. dm = theGame.GetDefinitionsManager();
  265.  
  266. quantity = 1;
  267.  
  268.  
  269. //---=== modPreparations ===---
  270. refillNeeded = IsRefillNeeded( recipe );
  271. //---=== modPreparations ===---
  272.  
  273. //cook item
  274. isSingletonItem = dm.IsItemSingletonItem(recipe.cookedItemName);
  275. if(isSingletonItem && thePlayer.inv.GetItemQuantityByName(recipe.cookedItemName) > 0 )
  276. {
  277. items = thePlayer.inv.GetItemsByName(recipe.cookedItemName);
  278. if (items.Size() == 1 && thePlayer.inv.ItemHasTag(items[0], 'NoShow'))
  279. {
  280. //potential bug
  281. //thePlayer.inv.RemoveItemTag(items[i], 'NoShow');
  282. thePlayer.inv.RemoveItemTag(items[0], 'NoShow');
  283. }
  284. ids = thePlayer.inv.GetItemsIds(recipe.cookedItemName);
  285. }
  286. if (!ids.Size() )
  287. {
  288. ids = thePlayer.inv.AddAnItem(recipe.cookedItemName, quantity);
  289. setAmmo = 1;
  290. }
  291. else
  292. cookChance = Clamp(cookChance, 0, 100);
  293. if (RandRange(100) < cookChance)
  294. {
  295. setAmmo = thePlayer.inv.SingletonItemGetAmmo(ids[0]) + 1;
  296. }
  297. else
  298. setAmmo = thePlayer.inv.SingletonItemGetAmmo(ids[0]);
  299.  
  300.  
  301. for(i=0; i<ids.Size(); i+=1)
  302. thePlayer.inv.SetItemModifierInt(ids[i],'ammo_current', setAmmo);
  303. theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnAmmoChanged );
  304. //remove ingredients
  305. for(i=0; i<recipe.requiredIngredients.Size(); i+=1)
  306. {
  307.  
  308. //if alchemy item is ingredient it might be equipped - we need to unequip first
  309. if(dm.IsItemAlchemyItem(recipe.requiredIngredients[i].itemName))
  310. {
  311. removedIngQuantity = 0;
  312. alchIngs = thePlayer.inv.GetItemsByName(recipe.requiredIngredients[i].itemName);
  313. witcher = GetWitcherPlayer();
  314.  
  315. for(j=0; j<alchIngs.Size(); j+=1)
  316. {
  317. equippedOnSlot = witcher.GetItemSlot(alchIngs[j]);
  318. if(equippedOnSlot != EES_InvalidSlot)
  319. witcher.UnequipItem(alchIngs[j]);
  320.  
  321. removedIngQuantity += 1;
  322. witcher.inv.RemoveItem(alchIngs[j]);
  323.  
  324. if(removedIngQuantity >= recipe.requiredIngredients[i].quantity)
  325. break;
  326. }
  327. }
  328. else
  329. {
  330. //just remove
  331. thePlayer.inv.RemoveItemByName(recipe.requiredIngredients[i].itemName, recipe.requiredIngredients[i].quantity);
  332. }
  333. }
  334.  
  335. LogAlchemy("Item <<" + recipe.cookedItemName + ">> cooked x" + recipe.cookedItemQuantity);
  336. //tutorial
  337. if(ShouldProcessTutorial('TutorialAlchemyCook'))
  338. {
  339. uiStateAlchemy = (W3TutorialManagerUIHandlerStateAlchemy)theGame.GetTutorialSystem().uiHandler.GetCurrentState();
  340. if(uiStateAlchemy)
  341. {
  342. uiStateAlchemy.CookedItem(recipeName);
  343. }
  344. else
  345. {
  346. uiStateAlchemyMutagens = (W3TutorialManagerUIHandlerStateAlchemyMutagens)theGame.GetTutorialSystem().uiHandler.GetCurrentState();
  347. if(uiStateAlchemyMutagens)
  348. uiStateAlchemyMutagens.CookedItem(recipeName);
  349. }
  350. }
  351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement