Advertisement
Guest User

Artifact Weapon Crafter

a guest
Feb 18th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.51 KB | None | 0 0
  1. class ArtifactWeaponCrafter extends ArtifactCraftWeapon;
  2. //DependsOn(MapAllowedWeapons);
  3.  
  4. struct AvailableWeaponsStruct
  5. {
  6. var() class<Weapon> WeaponClass;
  7. var() int Chance;
  8. var() bool AdvancedSpawn;
  9. };
  10.  
  11. var array< AvailableWeaponsStruct > AvailableWeapons;
  12. var MapAllowedWeapons WeaponsInfo;
  13. var MapAllowedWeapons DefWeaponsInfo;
  14. var string MapName;
  15. var bool bIsMechanic;
  16. var bool bVerified;
  17. var bool bInitDone;
  18. var int iLastSelected;
  19. var float AltLastUseTime;
  20. var bool bHardMode;
  21.  
  22.  
  23. function GiveTo( pawn Other, optional Pickup Source )
  24. {
  25. local MapAllowedWeapons WNfo;
  26. local string s;
  27. local int is;
  28.  
  29. //log (self $ " Hi ");
  30. Instigator = Other;
  31. if ( Other.AddInventory( Self ) )
  32. {
  33. //log (self $ " Hi Hi ");
  34. GotoState('');
  35.  
  36. s = string(self);
  37. is = InStr(s,".");
  38. s = Left(s,is);
  39. //log (self $ " 0 " $ s);
  40.  
  41. DefWeaponsInfo = class'ArtifactWeaponCrafter'.default.DefWeaponsInfo;
  42. MapName = class'ArtifactWeaponCrafter'.default.MapName;
  43. //log (self $ " 1 " $ DefWeaponsInfo $ " <- " $ class'ArtifactWeaponCrafter'.default.DefWeaponsInfo);
  44. if(Source == None && MapName != s)
  45. {
  46. forEach DynamicActors( class'MapAllowedWeapons', WNfo )
  47. {
  48. if (WNfo.AllowedWeapons.length > 0 &&( (WNfo.AllowedWeapons[0].AllowedWeaponsArray.length > 0 && WNfo.AllowedWeapons[0].AllowedWeaponsArray[0].WeaponClass != None) || (WNfo.AllowedWeapons.length > 1 && WNfo.AllowedWeapons[1].AllowedWeaponsArray.length > 0 && WNfo.AllowedWeapons[1].AllowedWeaponsArray[0].WeaponClass != None) ) )
  49. {
  50. WeaponsInfo = WNfo;
  51. class'ArtifactWeaponCrafter'.default.DefWeaponsInfo = WNfo;
  52. DefWeaponsInfo = None;
  53. //log (self $ " 2 " $ class'ArtifactWeaponCrafter'.default.DefWeaponsInfo);
  54. }
  55. //log (self $ " 2.5 ");
  56. break;
  57. }
  58. class'ArtifactWeaponCrafter'.default.MapName = s;
  59. }
  60. if (Source == None && DefWeaponsInfo != None)
  61. WeaponsInfo = DefWeaponsInfo;
  62.  
  63. if(Source == None && WeaponsInfo!= None)
  64. bHardMode = WeaponsInfo.bHardMode;
  65. if(ArtifactWeaponCrafterPickup(Source) != None)
  66. bHardMode = ArtifactWeaponCrafterPickup(Source).bHardMode;
  67.  
  68. //log (self $ " 3 " $ WeaponsInfo);
  69. //InvMetal = InvScrapMetal(Other.FindInventoryType(class'InvScrapMetal'));
  70. if (!bInitDone)
  71. Init(Other, Source);
  72. }
  73. else
  74. {
  75. log (self $ " ded ");
  76. Destroy();
  77. }
  78. }
  79.  
  80. function bool HandlePickupQuery(Pickup Item)
  81. {
  82. local int i,k,j,L;
  83. local class<Weapon> WepClass;
  84. local bool bDuplicate;
  85. local ArtifactWeaponCrafterPickup Source;
  86.  
  87. if (item.InventoryType == class)
  88. {
  89. L = -1;
  90. k = -1;
  91. Source = ArtifactWeaponCrafterPickup(Item);
  92. if (Source != None)
  93. {
  94. if(!Source.bHardMode && bHardMode)
  95. bHardMode = false;
  96. L=AvailableWeapons.length;
  97. for( k=L; i < Source.AllowedWeapons.length; i++ )
  98. {
  99. bDuplicate = false;
  100. WepClass = Source.AllowedWeapons[i].WeaponClass;
  101. for(j=0; j < L ; j++)
  102. {
  103. if (WepClass==AvailableWeapons[j].WeaponClass)
  104. {bDuplicate = true;
  105. j=L;}
  106. }
  107. if (!Source.AllowedWeapons[i].AdvancedSpawn && !bDuplicate)
  108. {
  109. AvailableWeapons.length = AvailableWeapons.length + 1;
  110. AvailableWeapons[k].WeaponClass = WepClass;
  111. AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
  112. k++;
  113. }
  114. else if (Source.AllowedWeapons[i].AdvancedSpawn && bIsMechanic)
  115. {
  116. AvailableWeapons.length = AvailableWeapons.length + 1;
  117. AvailableWeapons[k].WeaponClass = WepClass;
  118. AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
  119. AvailableWeapons[k].AdvancedSpawn = true;
  120. k++;
  121. }
  122. }
  123. }
  124. if (k > 0 && L >= 0 && k > L)
  125. {
  126. Item.AnnouncePickup(Pawn(Owner));
  127. Item.SetRespawn();
  128. return true;
  129. }
  130. else
  131. return true;
  132. }
  133. if ( Inventory == None ) // Next in inventory chain
  134. return false;
  135.  
  136. return Inventory.HandlePickupQuery(Item);
  137. }
  138.  
  139. function Init(pawn Other, optional Pickup Pickup)
  140. {
  141. local RPGPlayerDataObject Data;
  142. local int i,j,k;
  143. local ArtifactWeaponCrafterPickup Source;
  144.  
  145.  
  146. Source = ArtifactWeaponCrafterPickup(Pickup);
  147.  
  148. if (!bIsMechanic)
  149. Data = RPGPlayerDataObject(FindObject("Package." $ Other.PlayerReplicationInfo.PlayerName, class'RPGPlayerDataObject'));
  150. if (Data != None && Data.Abilities.length > 0 && class<RPGClass>(Data.Abilities[0]) != None && class<RPGClass>(Data.Abilities[0]).default.ClassIDNumber == 5)
  151. bIsMechanic = true;
  152.  
  153. if (WeaponsInfo != None)
  154. {
  155. if (WeaponsInfo.AllowedWeapons.length > 0)
  156. for( i=0; i < WeaponsInfo.AllowedWeapons[0].AllowedWeaponsArray.length; i++ )
  157. {
  158. AvailableWeapons.length = AvailableWeapons.length + 1;
  159. AvailableWeapons[i].WeaponClass = WeaponsInfo.AllowedWeapons[0].AllowedWeaponsArray[i].WeaponClass;
  160. AvailableWeapons[i].Chance = WeaponsInfo.AllowedWeapons[0].AllowedWeaponsArray[i].Chance;
  161. }
  162. //log (self $ " Init 1 Is mechanic= " $ bIsMechanic $ ", " $ data);
  163. if(bIsMechanic)
  164. {
  165. //log (self $ " Init 2 " $ WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray.length);
  166. if (WeaponsInfo.AllowedWeapons.length > 1)
  167. for( j=i; k < WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray.length; j++ )
  168. {
  169. AvailableWeapons.length = AvailableWeapons.length + 1;
  170. AvailableWeapons[j].WeaponClass = WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray[k].WeaponClass;
  171. AvailableWeapons[j].Chance = WeaponsInfo.AllowedWeapons[1].AllowedWeaponsArray[k].Chance;
  172. AvailableWeapons[j].AdvancedSpawn = true;
  173. k++;
  174. }
  175. }
  176. }
  177. else if (Source != None)
  178. {
  179. for( i=0; i < Source.AllowedWeapons.length; i++ )
  180. {
  181. if (!Source.AllowedWeapons[i].AdvancedSpawn)
  182. {
  183. AvailableWeapons.length = AvailableWeapons.length + 1;
  184. AvailableWeapons[k].WeaponClass = Source.AllowedWeapons[i].WeaponClass;
  185. AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
  186. k++;
  187. }
  188.  
  189. else if (bIsMechanic)
  190. {
  191. AvailableWeapons.length = AvailableWeapons.length + 1;
  192. AvailableWeapons[k].WeaponClass = Source.AllowedWeapons[i].WeaponClass;
  193. AvailableWeapons[k].Chance = Source.AllowedWeapons[i].Chance;
  194. AvailableWeapons[k].AdvancedSpawn = true;
  195. k++;
  196. }
  197. }
  198. }
  199. bInitDone = true;
  200. }
  201.  
  202. function bool GetUsability()
  203. {
  204. //Can't use this if you don't have enough adrenaline...
  205. if (Instigator.Controller.Adrenaline < GetCost() )
  206. {
  207. Instigator.ReceiveLocalizedMessage(MessageClass, GetCost(), None, None, Class);
  208. return false;
  209. }
  210.  
  211. //Can't use this if we don't have scrap metal
  212. if (InvMetal != None && InvMetal.ScrapMetal[0] <= 0 && InvMetal.ScrapMetal[1] <= 0 && InvMetal.ScrapMetal[2] <= 0 && InvMetal.ScrapMetal[3] <= 0 && InvMetal.ScrapMetal[4] <= 0)
  213. {
  214. Instigator.ReceiveLocalizedMessage(MessageClass, 1000, None, None, Class);
  215. return false;
  216. }
  217.  
  218. return true;
  219. }
  220.  
  221. function Activate()
  222. {
  223. local int i;
  224.  
  225. for( i=0; i < AvailableWeapons.length; i++ )
  226. {
  227. Instigator.ClientMessage("[" $ i $ "] = " $ string(AvailableWeapons[i].WeaponClass) $ " Chance= " $ AvailableWeapons[i].Chance ); //.Default.FriendlyName);
  228. if (AvailableWeapons[i].AdvancedSpawn)
  229. Instigator.ClientMessage("is complicated");
  230. }
  231. }
  232.  
  233. function AltActivate(optional string Param)
  234. {
  235. local float TimeDelta;
  236. local int i,CT,R,F,CS;
  237.  
  238. TimeDelta = Level.TimeSeconds - AltLastUseTime;
  239. if (Level.TimeSeconds - AltLastUseTime < UseDelay)
  240. {
  241. Instigator.ReceiveLocalizedMessage(MessageClass, 5000 + UseDelay - TimeDelta, None, None, Class);
  242. bActive = false;
  243. GotoState('');
  244. return;
  245. }
  246. AltLastUseTime = Level.TimeSeconds;
  247.  
  248. if (InvMetal == None)
  249. InvMetal = InvScrapMetal(Instigator.FindInventoryType(class'InvScrapMetal'));
  250. if (!bVerified && InvMetal == None)
  251. {
  252. if (bIsMechanic)
  253. log (self $ " Mechanic RPGClass detection error ");
  254. for( i=0; i < AvailableWeapons.length; i++ )
  255. if(AvailableWeapons[i].AdvancedSpawn)
  256. {
  257. AvailableWeapons.Remove(i, 1);
  258. i--;
  259. }
  260. bVerified = true;
  261. }
  262.  
  263. if (!bIsFree && !GetUsability())
  264. return;
  265.  
  266. for( i=0; i < AvailableWeapons.length; i++ )
  267. CT += AvailableWeapons[i].Chance;
  268.  
  269. if( CT <= 0 )
  270. {
  271. log (self $ " Chance total <= 0 ");
  272. return;
  273. }
  274. R = Rand(CT);
  275. F = CT - R;
  276. //log (self $ " AltAct 1 " $ InvMetal);
  277. for( i=0; i < AvailableWeapons.length; i++ )
  278. {
  279. CS += AvailableWeapons[i].Chance;
  280. if(F <= CS)
  281. {
  282. WeaponClass = AvailableWeapons[i].WeaponClass;
  283. iLastSelected = i;
  284. Super.AltActivate();
  285. break;
  286. }
  287. }
  288. }
  289.  
  290. function bool shouldBreak()
  291. {
  292. if (InvMetal == None)
  293. Return true;
  294. Return false;
  295. }
  296.  
  297. function PayUp ()
  298. {
  299. local int i;
  300.  
  301. Instigator.Controller.Adrenaline -= GetCost();
  302. if (Instigator.Controller.Adrenaline < 0)
  303. Instigator.Controller.Adrenaline = 0;
  304.  
  305. //Remove scrap metal
  306. if (InvMetal != None)
  307. {
  308. i = 4;
  309. while (InvMetal.ScrapMetal[i] <= 0 && i >= 0)
  310. i--;
  311. InvMetal.RemoveMetal(i);
  312. }
  313.  
  314. if (AvailableWeapons[iLastSelected].AdvancedSpawn || bHardMode)
  315. {
  316. AvailableWeapons.Remove(iLastSelected, 1);
  317. }
  318. if ( shouldBreak() )
  319. {
  320. Destroy();
  321. Instigator.NextItem();
  322. Return;
  323. }
  324. }
  325.  
  326.  
  327. defaultproperties
  328. {
  329. ChangelingClass=Class'SillyRPG.XIsAChangeling'
  330. AbilityLevel=1
  331. UseDelay=2
  332. WeaponClass=None
  333. bIsFree=false
  334. bIsDropped=true
  335. MinActivationTime=0.000001
  336. ActivateSound=Sound'WeaponSounds.BaseGunTech.BReload2'
  337. PickupClass=Class'SillyRPGv1-1.ArtifactWeaponCrafterPickup'
  338. IconMaterial=Texture'ME_RPGExpansion.Icons.CraftSpiderMines'
  339. ItemName="Weapon Crafter"
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement