DarkShadow44

JS Buy Test

Mar 15th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. var backpackStatus = {};
  2. backpackStatus.price = 100;
  3. backpackStatus.multiplier = 1.1
  4.  
  5. var statStatus = {};
  6. statStatus.price = 500;
  7. statStatus.muliplier = 1.01;
  8.  
  9. function buyStuff(type, count) {
  10. var priceTemp = type.price;
  11. var priceToPay = 0;
  12. for(i=0; i < count; i++) {
  13. priceToPay += priceTemp;
  14. priceTemp = Math.round(priceTemp * type.multiplier);
  15. }
  16.  
  17. if (player.gold >= priceToPay) {
  18. type.price = priceTemp;
  19. player.gold -= priceToPay;
  20. return true;
  21. }
  22. Log("You do not have enough money to buy this. You need " + priceTemp + " gold.")
  23. return false;
  24. }
  25.  
  26. function buyBackpack(count) {
  27. if(buyStuff(backpackStatus, count) {
  28. player.backpackUpgrade += count;
  29. document.getElementById("backpack").innerHTML = backpackStatus.price;
  30. CreateInventoryWeaponHtml();
  31. Log("You max inventory slots upgraded by " + count + ", now you have: " + player.inventory() + " inventory slots");
  32. }
  33. }
  34.  
  35. function buyStat(count) {
  36. if(buyStuff(statStatus, count) {
  37. player.stats += count;
  38. document.getElementById("buyStat").innerHTML = statStatus.price;
  39. Log("Your stat points increased by " + count + ".");
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment