PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/nacridan/conquest/inbuilding/cqspellclassroom.inc.php

https://gitlab.com/nacridan/Nacridan
PHP | 185 lines | 146 code | 27 blank | 12 comment | 19 complexity | 19277df740ef245c7273d141610fde04 MD5 | raw file
  1. <?php
  2. /**
  3. *Définit la classe CQHostel
  4. *
  5. * La <b>fonction toString</b> affiche la partie du menu qui gère <b>l'auberge</b>.
  6. *
  7. *
  8. *@author Aé Li
  9. *@version 1.1
  10. *@package NacridanV1
  11. *@subpackage Conquest
  12. */
  13. require_once (HOMEPATH . "/factory/InsideBuildingFactory.inc.php");
  14. require_once (HOMEPATH . "/factory/CityFactory.inc.php");
  15. class CQSpellclassroom extends HTMLObject
  16. {
  17. public $db;
  18. public $curplayer;
  19. public $curbuilding;
  20. public $nacridan;
  21. public $err;
  22. public function CQSpellclassroom($building, $nacridan, $db)
  23. {
  24. $this->db = $db;
  25. $this->nacridan = $nacridan;
  26. $this->curplayer = $this->nacridan->loadCurSessPlayer($db);
  27. $this->err = "";
  28. $this->curbuilding = $building;
  29. }
  30. public function toString()
  31. {
  32. $curplayer = $this->curplayer;
  33. $curbuilding = $this->curbuilding;
  34. $db = $this->db;
  35. $id = $curplayer->get("id");
  36. $err = $this->err;
  37. $str = "";
  38. $str .= "<table class='maintable insidebuildingleftwidth'>\n";
  39. $str .= "<tr>\n";
  40. $str .= "<td class='mainbgtitle'><b>" . localize('S A L L E &nbsp;&nbsp;&nbsp; D E &nbsp;&nbsp;&nbsp; C L A S S E') . "</b>\n";
  41. $str .= "</td>\n";
  42. $str .= "</tr>\n";
  43. $str .= "</table>\n";
  44. if ($curbuilding->get("school") != "")
  45. $schoolList = unserialize($curbuilding->get("school"));
  46. else
  47. $schoolList = array();
  48. $str .= "<table class='maintable insidebuildingleftwidth'>\n";
  49. if (isset($_POST["learn"]) && isset($_POST["IDSPELL"])) {
  50. $queryValues = array();
  51. $queryValues[] = $curplayer->get("id");
  52. $dbMScount = new DBCollectionPrepare("SELECT count(*) as nb FROM MagicSpell WHERE id_Player=?", $db, 0, 0, true, $queryValues);
  53. $nbSpellKnows = $dbMScount->get("nb");
  54. $mapObj = new Map($db, $curplayer->get("map"));
  55. $idStartKingdom = $mapObj->getStartKingdomIdFromMap($curplayer->get("x"), $curplayer->get("y"));
  56. $dbBMS = new DBCollection("SELECT name,level FROM BasicMagicSpell WHERE id=" . $_POST["IDSPELL"], $db, 0, 0);
  57. if ($dbBMS->get("level") == 0)
  58. // cout de 0 si premier sort basique appris en royaume
  59. $price = ($nbSpellKnows == 0 && $idStartKingdom != ID_UNKNOWN_KINGDOM) ? 0 : CityFactory::getBuildingActionPrice($curplayer->get("inbuilding"),
  60. SCHOOL_LEARN_SPELL_0, $db);
  61. elseif ($dbBMS->get("level") == 1)
  62. $price = CityFactory::getBuildingActionPrice($curplayer->get("inbuilding"), SCHOOL_LEARN_SPELL_1, $db);
  63. elseif ($dbBMS->get("level") == 2)
  64. $price = CityFactory::getBuildingActionPrice($curplayer->get("inbuilding"), SCHOOL_LEARN_SPELL_2, $db);
  65. $dbMS = new DBCollection("SELECT id FROM MagicSpell WHERE id_Player=" . $id . " AND id_BasicMagicSpell=" . $_POST["IDSPELL"], $db, 0, 0);
  66. if ($dbMS->count() > 0)
  67. $str .= "<tr><td class='mainbglabel'>Vous connaissez déjà ce sortilège.</td></tr>";
  68. elseif ($curplayer->get("money") < $price)
  69. $str .= "<tr><td class='mainbglabel'>Vous n'avez pas assez de PO.</td></tr>";
  70. elseif ($curplayer->get("ap") < (LEARN_AP - $curbuilding->get("value")))
  71. $str .= "<tr><td class='mainbglabel'>Vous n'avez pas assez de PA.</td></tr>";
  72. else {
  73. $str .= "<form name='form' method='POST' action='" . CONFIG_HOST . "/conquest/conquest.php?action=act" . "' target='_self'>";
  74. $str .= "<tr><td class='mainbglabel'>Vous allez apprendre le sort " . $dbBMS->get("name") . " pour " . $price . " PO (et " . (LEARN_AP - $curbuilding->get("value")) .
  75. " PA) ?";
  76. $str .= "<input id='submitbt' type='submit' name='submitbt' value='Continuer' /> </td></tr>";
  77. $str .= "<input name='action' type='hidden' value='" . SCHOOL_LEARN_SPELL . "' />";
  78. $str .= "<input name='IDSPELL' type='hidden' value='" . $_POST["IDSPELL"] . "' />";
  79. $str .= "<input name='idform' type='hidden' value='" . getCurrentPageId() . "' />\n";
  80. $str .= "</form>";
  81. }
  82. } else {
  83. $str .= "<form method='POST' action='" . CONFIG_HOST . "/conquest/conquest.php?center=view2d&bottom=viewpanel' target='_self'>\n";
  84. $str .= "<tr><td class='mainbglabel'>Temps d'apprentissage dans cette école : " . (LEARN_AP - $curbuilding->get("value")) . " PA.</td></tr>";
  85. $str .= "<tr><td class='mainbglabel'>Liste des enseignements : </td></tr>";
  86. // cout de 0 si premier sort basique appris en royaume
  87. $queryValues = array();
  88. $queryValues[] = $curplayer->get("id");
  89. $dbMScount = new DBCollectionPrepare("SELECT count(*) as nb FROM MagicSpell WHERE id_Player=?", $db, 0, 0, true, $queryValues);
  90. $nbSpellKnows = $dbMScount->get("nb");
  91. $mapObj = new Map($db, $curplayer->get("map"));
  92. $idStartKingdom = $mapObj->getStartKingdomIdFromMap($curplayer->get("x"), $curplayer->get("y"));
  93. foreach ($schoolList as $idname => $level) {
  94. if ($idname == SCHOOL_BASIC_WARRIOR || $idname == SCHOOL_BASIC_MAGIC) {
  95. $niveau = "";
  96. $price = ($nbSpellKnows == 0 && $idStartKingdom != ID_UNKNOWN_KINGDOM) ? 0 : CityFactory::getBuildingActionPrice($curplayer->get("inbuilding"),
  97. SCHOOL_LEARN_SPELL_0, $db);
  98. $str .= "<tr><td class='mainbgbody'><br/> <b class='stylepc'>" . getSchoolName($idname) . $niveau . ($price == 0 ? ", le premier sort est offert." : "&nbsp;") .
  99. "</b><br/> </td></tr>";
  100. $dbBMS = new DBCollection("SELECT id,name FROM BasicMagicSpell WHERE school=" . $idname, $db, 0, 0);
  101. while (! $dbBMS->eof()) {
  102. $str .= "<tr><td class='mainbgbody'><input type='radio' name='IDSPELL' value='" . $dbBMS->get("id") . "' id='" . $dbBMS->get("name") . "' /><label for='" .
  103. $dbBMS->get("name") . "'><a href=\"" . CONFIG_HOST . "/conquest/spell.php?id=" . $dbBMS->get("id") . "\" class='parchment popupify'>" .
  104. localize($dbBMS->get("name")) . "</a> (" . $price . " PO) </label></td></tr>";
  105. $dbBMS->next();
  106. }
  107. } else {
  108. if ($level == 1 or $level == 2) {
  109. $niveau = ", niveau Aspirant";
  110. $price = CityFactory::getBuildingActionPrice($curplayer->get("inbuilding"), SCHOOL_LEARN_SPELL_1, $db);
  111. $str .= "<tr><td class='mainbgbody'><br/> <b class='stylepc'>" . getSchoolName($idname) . $niveau . "</b><br/> </td></tr>";
  112. $enable = "disabled";
  113. if (InsideBuildingFactory::prerequisitesForLearningMagicSpell($id, $idname, 1, $db))
  114. $enable = "";
  115. else
  116. $str .= "<tr><td class='mainbgbody'>Vous devez maîtriser un sortilège élémentaire à 80% avant de pouvoir accéder au rang d'Aspirant</td></tr>";
  117. $dbBMS = new DBCollection("SELECT id,name FROM BasicMagicSpell WHERE school=" . $idname . " AND level=1", $db, 0, 0);
  118. while (! $dbBMS->eof()) {
  119. $str .= "<tr><td class='mainbgbody'><input type='radio'" . $enable . " name='IDSPELL' value='" . $dbBMS->get("id") . "' id='" . $dbBMS->get("name") .
  120. "' /><label for='" . $dbBMS->get("name") . "'><a href=\"" . CONFIG_HOST . "/conquest/spell.php?id=" . $dbBMS->get("id") .
  121. "\" class='parchment popupify'>" . localize($dbBMS->get("name")) . "</a> (" . $price . " PO) </label></td></tr>";
  122. $dbBMS->next();
  123. }
  124. }
  125. if ($level == 2) {
  126. $niveau = ", niveau Adepte";
  127. $price = CityFactory::getBuildingActionPrice($curplayer->get("inbuilding"), SCHOOL_LEARN_SPELL_2, $db);
  128. $str .= "<tr><td class='mainbgbody'><br/> <b class='stylepc'>" . getSchoolName($idname) . $niveau . "</b><br/> </td></tr>";
  129. $enable = "disabled";
  130. if (InsideBuildingFactory::prerequisitesForLearningMagicSpell($id, $idname, 2, $db))
  131. $enable = "";
  132. else
  133. $str .= "<tr><td class='mainbgbody'>Vous devez maîtriser deux sortilèges niveau Aspirant à 90% de cette école avant de pouvoir accéder au rang de Adepte</td></tr>";
  134. $dbBMS = new DBCollection("SELECT id,name FROM BasicMagicSpell WHERE school=" . $idname . " AND level=2", $db, 0, 0);
  135. while (! $dbBMS->eof()) {
  136. $str .= "<tr><td class='mainbgbody'><input type='radio'" . $enable . " name='IDSPELL' value='" . $dbBMS->get("id") . "' id='" . $dbBMS->get("name") .
  137. "' /><label for='" . $dbBMS->get("name") . "'><a href=\"" . CONFIG_HOST . "/conquest/spell.php?id=" . $dbBMS->get("id") .
  138. "\" class='parchment popupify'>" . localize($dbBMS->get("name")) . "</a> (" . $price . " PO) </label></td></tr>";
  139. $dbBMS->next();
  140. }
  141. }
  142. }
  143. }
  144. $str .= "<tr><td><input type='submit' name='learn' value='Apprendre'/> </td></tr>";
  145. $str .= "</form>";
  146. }
  147. $str .= "</table>\n";
  148. return $str;
  149. }
  150. }
  151. ?>