PageRenderTime 65ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Templates/Build/17_3.tpl

https://github.com/TravianWar/Travianx
Smarty Template | 256 lines | 229 code | 27 blank | 0 comment | 66 complexity | 42fd0f740141aa8d315174adf0a528f8 MD5 | raw file
  1. <div id="build" class="gid17"><a href="#" onClick="return Popup(17,4);" class="build_logo">
  2. <img class="building g17" src="img/x.gif" alt="Marketplace" title="Marketplace" />
  3. </a>
  4. <h1>Marketplace <span class="level">level <?php echo $village->resarray['f'.$id]; ?></span></h1>
  5. <p class="build_desc">At the Marketplace you can trade resources with other players. The higher its level, the more resources can be transported at the same time.
  6. </p>
  7. <?php include("17_menu.tpl");
  8. if(isset($_GET['c'])){
  9. ?>
  10. <p><b>NPC completed.</b> Cost 3<img src="img/x.gif" class="gold" alt="Gold" title="Gold" /></p> <?php } else { ?>
  11. <p>With the NPC merchant you can distribute the resources in your warehouse as you desire. <br /><br />
  12. The first line shows the current stock. In the second line you can choose another distribution. The third line shows the difference between the old and new stock.</p>
  13. <script language="JavaScript">
  14. var overall;
  15. function calculateRes() {
  16. resObj=document.getElementsByName("m2");
  17. overall=0;
  18. for (i=0; i<resObj.length; i++) {
  19. var tmp="";
  20. for (j=0; j<resObj[i].value.length; j++)
  21. if ((resObj[i].value.charAt(j)>="0") && (resObj[i].value.charAt(j)<="9")) tmp=tmp+resObj[i].value.charAt(j);
  22. resObj[i].value=tmp;
  23. if (tmp=="") tmp="0";
  24. newRes=Math.round(parseInt(tmp)*summe/100);
  25. if (((i<3) && (newRes<=max123)) || ((i==3) && (newRes<=max4)))
  26. newHTML=newRes;
  27. else
  28. newHTML="<span class='corr'>"+newRes+"</span>";
  29. document.getElementById("new"+i).innerHTML=newHTML;
  30. overall+=parseInt(tmp);
  31. }
  32. document.getElementById("overall").innerHTML=overall+"%";
  33. }
  34. function normalize() {
  35. calculateRes();
  36. resObj=document.getElementsByName("m2");
  37. for (i=0; i<resObj.length; i++) {
  38. tmp=parseInt(resObj[i].value);
  39. tmp=tmp*(100/overall);
  40. resObj[i].value=Math.round(tmp);
  41. }
  42. calculateRes();
  43. }
  44. function calculateRest() {
  45. resObj=document.getElementsByName("m2[]");
  46. overall=0;
  47. for (i=0; i<resObj.length; i++) {
  48. var tmp="";
  49. for (j=0; j<resObj[i].value.length; j++)
  50. if ((resObj[i].value.charAt(j)>="0") && (resObj[i].value.charAt(j)<="9")) tmp=tmp+resObj[i].value.charAt(j);
  51. if (tmp=="") {
  52. tmp="0";
  53. newRes=0;
  54. resObj[i].value="";
  55. } else {
  56. newRes=parseInt(tmp);
  57. if ((i<3) && (newRes>max123)) newRes=max123;
  58. if ((i==3) && (newRes>max4)) newRes=max4;
  59. resObj[i].value=newRes;
  60. }
  61. dif=newRes-parseInt(document.getElementById("org"+i).innerHTML);
  62. newHTML=dif;
  63. if (dif>0) newHTML="+"+dif;
  64. document.getElementById("diff"+i).innerHTML=newHTML;
  65. overall+=newRes;
  66. }
  67. document.getElementById("newsum").innerHTML=overall;
  68. rest=parseInt(document.getElementById("org4").innerHTML)-overall;
  69. document.getElementById("remain").innerHTML=rest;
  70. testSum();
  71. }
  72. function fillup(nr) {
  73. resObj=document.getElementsByName("m2[]");
  74. if (nr<3) {
  75. resObj[nr].value=max123;
  76. } else {
  77. resObj[nr].value=max4;
  78. }
  79. calculateRest();
  80. }
  81. function portionOut() {
  82. restRes=parseInt(document.getElementById("remain").innerHTML);
  83. rest=restRes;
  84. resObj=document.getElementsByName("m2[]");
  85. nullCount=0;
  86. notNullCount=0;
  87. // Z&#65533;hlen
  88. for (j=0; j<resObj.length; j++) {
  89. if ((restRes>0) && (resObj[j].value=="")) nullCount++;
  90. if ((restRes<0) && (resObj[j].value!="")) notNullCount++;
  91. }
  92. // Verteilen
  93. nullCount2=0;
  94. if (restRes>0) {
  95. // In allen Feldern schon Zahlen?
  96. if (nullCount==0) {
  97. for (i=0; i<resObj.length; i++) {
  98. free=max123-parseInt(resObj[i].value);
  99. resObj[i].value=(parseInt(resObj[i].value)+Math.round(rest/(4-i)));
  100. rest=rest-Math.min(free,Math.round(rest/(4-i)));
  101. if ((i<3) && (parseInt(resObj[i].value)<max123)) nullCount2++;
  102. }
  103. } else {
  104. for (i=0; i<resObj.length; i++) {
  105. if (resObj[i].value=="") {
  106. resObj[i].value=Math.round(rest/nullCount);
  107. rest=rest-Math.round(rest/nullCount);
  108. nullCount--;
  109. }
  110. if ((i<3) && (parseInt(resObj[i].value)<max123)) nullCount2++;
  111. }
  112. }
  113. } else {
  114. for (j=0; j<resObj.length; j++) {
  115. if (parseInt(resObj[j].value)>0) {
  116. resObj[j].value=(parseInt(resObj[j].value)+Math.round(rest/notNullCount));
  117. rest=rest-Math.round(rest/notNullCount);
  118. notNullCount--;
  119. }
  120. }
  121. }
  122. calculateRest();
  123. // Noch irgendein Rest?
  124. if (rest>0) {
  125. if (max123>max4) {
  126. for (j=0; j<3; j++) {
  127. if (parseInt(resObj[j].value)<max123) {
  128. resObj[j].value=(parseInt(resObj[j].value)+Math.round(rest/nullCount2));
  129. rest=rest-Math.round(rest/nullCount2);
  130. nullCount2--;
  131. }
  132. }
  133. } else {
  134. resObj[3].value=(parseInt(resObj[3].value)+rest);
  135. }
  136. }
  137. calculateRest();
  138. }
  139. function testSum() {
  140. if (document.getElementById("remain").innerHTML!=0) {
  141. document.getElementById("submitText").innerHTML="<a href='javascript:portionOut();'>Distribute resources at (step 1 of 2)</a>";
  142. document.getElementById("submitText").style.display="block";
  143. document.getElementById("submitButton").style.display="none";
  144. } else {
  145. document.getElementById("submitText").innerHTML="";
  146. document.getElementById("submitText").style.display="none";
  147. document.getElementById("submitButton").style.display="block";
  148. }
  149. }
  150. </script>
  151. <script language="JavaScript">var summe=<?php echo floor($village->awood+$village->acrop+$village->airon+$village->aclay); ?>;var max123=<?php echo $village->maxstore; ?>;var max4=<?php echo $village->maxcrop; ?>;</script>
  152. <form method="post" name="snd" action="build.php">
  153. <input type="hidden" name="id" value="<?php echo $id; ?>" />
  154. <input type="hidden" name="ft" value="mk3" />
  155. <input type="hidden" name="t" value="3" />
  156. <table id="npc" cellpadding="1" cellspacing="1">
  157. <thead>
  158. <tr>
  159. <th colspan="5">NPC Trade</th>
  160. </tr>
  161. <tr>
  162. <td class="all">
  163. <a href="javascript:fillup(0);"><img class="r1" src="img/x.gif" alt="Lumber" title="Lumber" /></a>
  164. <span id="org0"><?php echo floor($village->awood); ?></span>
  165. </td>
  166. <td class="all">
  167. <a href="javascript:fillup(1);"><img class="r2" src="img/x.gif" alt="Clay" title="Clay" /></a>
  168. <span id="org1"><?php echo floor($village->aclay); ?></span>
  169. </td>
  170. <td class="all">
  171. <a href="javascript:fillup(2);"><img class="r3" src="img/x.gif" alt="Iron" title="Iron" /></a>
  172. <span id="org2"><?php echo floor($village->airon); ?></span>
  173. </td>
  174. <td class="all">
  175. <a href="javascript:fillup(3);"><img class="r4" src="img/x.gif" alt="Crop" title="Crop" /></a>
  176. <span id="org3"><?php echo floor($village->acrop); ?></span>
  177. </td>
  178. <td class="sum">Sum:&nbsp;<span id="org4"><?php echo floor($village->awood+$village->acrop+$village->airon+$village->aclay); ?></span></td>
  179. </tr>
  180. </thead>
  181. <tbody>
  182. <tr>
  183. <td class="sel">
  184. <input class="text" onkeyup="calculateRest();" name="m2[]" size="5" maxlength="7" <?php if(isset($_GET['r1'])) { echo "value=\"".$_GET['r1']."\""; } ?>/>
  185. <input type="hidden" name="m1[]" value="<?php echo floor($village->awood); ?>" />
  186. </td>
  187. <td class="sel">
  188. <input class="text" onkeyup="calculateRest();" name="m2[]" size="5" maxlength="7" <?php if(isset($_GET['r2'])) { echo "value=\"".$_GET['r2']."\""; } ?>/>
  189. <input type="hidden" name="m1[]" value="<?php echo floor($village->aclay); ?>" />
  190. </td>
  191. <td class="sel">
  192. <input class="text" onkeyup="calculateRest();" name="m2[]" size="5" maxlength="7" <?php if(isset($_GET['r3'])) { echo "value=\"".$_GET['r3']."\""; } ?>/>
  193. <input type="hidden" name="m1[]" value="<?php echo floor($village->airon); ?>" />
  194. </td>
  195. <td class="sel">
  196. <input class="text" onkeyup="calculateRest();" name="m2[]" size="5" maxlength="7" <?php if(isset($_GET['r4'])) { echo "value=\"".$_GET['r4']."\""; } ?>/>
  197. <input type="hidden" name="m1[]" value="<?php echo floor($village->acrop); ?>" />
  198. </td>
  199. <td class="sum">Sum:&nbsp;<span id="newsum"><?php if(isset($_GET['r1']) && isset($_GET['r2']) && isset($_GET['r3']) && isset($_GET['r4'])) { echo $_GET['r1']+$_GET['r2']+$_GET['r3']+$_GET['r4']; } else { echo 0; } ?></span></td>
  200. </tr>
  201. <tr>
  202. <td class="rem">
  203. <span id="diff0"><?php echo 0-floor($village->awood); ?></span>
  204. </td>
  205. <td class="rem">
  206. <span id="diff1"><?php echo 0-floor($village->aclay); ?></span>
  207. </td>
  208. <td class="rem">
  209. <span id="diff2"><?php echo 0-floor($village->airon); ?></span>
  210. </td>
  211. <td class="rem">
  212. <span id="diff3"><?php echo 0-floor($village->acrop); ?></span>
  213. </td>
  214. <td class="sum">Rest:&nbsp;<span id="remain">
  215. <?php if(isset($_GET['r1']) && isset($_GET['r2']) && isset($_GET['r3']) && isset($_GET['r4'])) {
  216. echo floor($village->awood+$village->acrop+$village->airon+$village->aclay)-($_GET['r1']+$_GET['r2']+$_GET['r3']+$_GET['r4']);
  217. } else { echo floor($village->awood+$village->acrop+$village->airon+$village->aclay); } ?></span></td>
  218. </tr>
  219. </tbody>
  220. </table>
  221. <p id="submitButton">
  222. <?php if($session->userinfo['gold'] > 3) { ?><a href="javascript:document.snd.submit();">Trade resources at (step 2 of 2)</a> <span class="none">(Costs: <img src="img/x.gif" class="gold_g" alt="Gold" title="Gold" /><b>3</b>)</span><?php } else { echo"<span class='none'>Trade resources at (step 2 of 2)</span> (Costs: <img src='img/x.gif' class='gold' alt='Gold' title='Gold' /><b>3</b>)"; }?> </p>
  223. <p id="submitText"></p>
  224. </form>
  225. <script>
  226. testSum();
  227. </script>
  228. <?php } ?>
  229. </div>