- <?php
- // (c) f33lix 12. Nov 2009
- class battle_enginge {
- // Angreifer
- protected $atk_name;
- protected $atk_hp;
- protected $atk_recoverrate;
- protected $atk_str;
- protected $atk_critrate;
- protected $atk_crit = false;
- protected $atk_dmg;
- protected $atk_waffe;
- protected $atk_add_dmg_waffe;
- // Verteidiger
- protected $def_name;
- protected $def_hp;
- protected $def_recoverrate;
- protected $def_str;
- protected $def_critrate;
- protected $def_crit = false;
- protected $def_dmg;
- protected $def_waffe;
- protected $def_add_dmg_waffe;
- // Neutral
- protected $mindmgmultiplikator = 19.9;
- protected $maxdmgmultiplikator = 25.9;
- protected $runden = 10; // Maximale Anzahl an Kampfrunden
- public function calc_dmg_attacker($a_str, $a_critrate, $a_waffe) {
- $criticalhit = false;
- $this->atk_str = $a_str;
- $this->atk_critrate = $a_critrate;
- $calc_critrate = rand($this->atk_critrate, 10);
- if ($calc_critrate == 10) {
- $criticalhit = true;
- $this->atk_crit = true;
- } else {
- $this->atk_crit = false;
- }
- $add = rand($this->mindmgmultiplikator, $this->maxdmgmultiplikator);
- $this->atk_dmg = $this->atk_str * $add;
- ($criticalhit == true) ? $add = 2 : $add = 1;
- $this->atk_dmg = $this->atk_dmg * $add + $a_waffe;
- }
- public function calc_dmg_defender($d_str, $d_critrate, $d_waffe) {
- $criticalhit = false;
- $this->def_str = $d_str;
- $this->def_critrate = $d_critrate;
- $calc_critrate = rand($this->def_critrate, 10);
- if ($calc_critrate == 10) {
- $criticalhit = true;
- $this->def_crit = true;
- } else {
- $this->def_crit = false;
- }
- $add = rand($this->mindmgmultiplikator, $this->maxdmgmultiplikator);
- $this->def_dmg = $this->def_str * $add;
- ($criticalhit == true) ? $add = 2 : $add = 1;
- $this->def_dmg = $this->def_dmg * $add + $b_waffe;
- }
- public function force($a_name, $a_hp, $a_str, $a_critrate, $a_regrate, $a_waffe, $d_name, $d_hp, $d_str, $d_critrate, $d_regrate, $d_waffe) {
- $atkmaxhp = $a_hp * 10;
- $defmaxhp = $d_hp * 10;
- $this->atk_hp = $a_hp;
- $this->atk_recoverrate = $a_regrate;
- $this->atk_waffe = $a_waffe;
- $this->def_hp = $d_hp;
- $this->def_recoverrate = $d_regrate;
- $this->def_waffe = $d_waffe;
- switch ($a_waffe) {
- case 0: $this->atk_waffe = "Keine";$this->atk_add_dmg_waffe = 0; break;
- case 1: $this->atk_waffe = "Messer";$this->atk_add_dmg_waffe = 2; break;
- case 2: $this->atk_waffe = "Dolch";$this->atk_add_dmg_waffe = 4; break;
- case 666: $this->atk_waffe = "Awesome Stick";$this->atk_add_dmg_waffe = 312341234155; break;
- }
- switch ($b_waffe) {
- case 0: $this->def_waffe = "Keine";$this->def_add_dmg_waffe = 0; break;
- case 1: $this->def_waffe = "Messer";$this->def_add_dmg_waffe = 2; break;
- case 2: $this->def_waffe = "Dolch";$this->def_add_dmg_waffe = 4; break;
- }
- echo "<span style=\"margin-left:50px;\">\nStarte Kampf zwischen <b style=\"color:red;\">".$a_name."</b> (Angreifer) und <b style=\"color:green;\">".$d_name."</b> (Verteidiger)\n</span>\n<br>\n<br>\n";
- $aprozcrit = $a_critrate * 10;
- $dprozcrit = $d_critrate * 10;
- echo "<b style=\"color:red;\">".$a_name."</b>: Stärke: <b>".$a_str."</b> +(".$this->atk_add_dmg_waffe.") - Kritische Trefferrate: <b>".$aprozcrit."%</b> - Regnerationsrate: <b>".$a_regrate."%</b> - Waffe: <b>".$this->atk_waffe."</b><br>\n";
- echo "<b style=\"color:green;\">".$d_name."</b>: Stärke: <b>".$d_str."</b> +(".$this->def_add_dmg_waffe.") - Kritische Trefferrate: <b>".$dprozcrit."%</b> - Regnerationsrate: <b>".$d_regrate."%</b> - Waffe: <b>".$this->def_waffe."<br><br>\n";
- for ($i = 0; $i < $this->runden; $i++) {
- if ($this->atk_hp > 0 && $this->def_hp > 0) {
- $runde = $i + 1;
- echo "<u>Kampfwelle ".$runde."</u>:\n<br><br>\n";
- echo "<span style=\"margin-left:50px;\">\n";
- $this->calc_dmg_attacker($a_str, $a_critrate, $this->atk_add_dmg_waffe);
- if ($this->def_crit == true) {
- $iscrit = " - <b style=\"font-weight:normal;color:blue\">Kritischer Treffer</b>\n";
- } else {
- $iscrit = "";
- }
- echo "<b style=\"color:red;\">".$a_name."</b> fügt <b style=\"color:green;\">".$d_name."</b> ".$this->atk_dmg." Schaden zu. ".$iscrit."<br>\n";
- echo "</span>\n";
- $this->def_hp = $this->def_hp - $this->atk_dmg;
- if ($this->def_hp > 0) {
- $this->calc_dmg_defender($d_str, $d_critrate, $this->def_add_dmg_waffe);
- if ($this->def_crit == true) {
- $iscrit = " - <b style=\"font-weight:normal;color:blue\">Kritischer Treffer</b>\n";
- } else {
- $iscrit = "";
- }
- echo "<span style=\"margin-left:50px;\">\n";
- echo "<b style=\"color:green;\">".$d_name."</b> fügt <b style=\"color:red;\">".$a_name."</b> ".$this->def_dmg." Schaden zu. ".$iscrit."<br>\n";
- echo "</span>\n";
- $this->atk_hp = $this->atk_hp - $this->def_dmg;
- } else {
- echo "<br>\n<span style=\"margin-left:100px;border:1px solid #9f9f9f;padding:2px;\">\nDer Angreifer <b style=\"color:red;\">".$a_name."</b> hat die Schlacht gewonnen!\n</span>\n<br>\n";
- }
- if ($this->atk_hp <= 0) {
- echo "<br><span style=\"margin-left:100px;border:1px solid #9f9f9f;padding:2px;\">\nDer Verteidiger <b style=\"color:green;\">".$d_name."</b> hat die Schlacht gewonnen!\n</span>\n<br>\n";
- }
- if ($this->atk_hp > 0 && $this->def_hp > 0) {
- $newhpdef = explode(".", $this->def_hp);
- $newhpatk = explode(".", $this->atk_hp);
- echo "<br><span style=\"margin-left:100px;\">";
- echo "<b style=\"color:green;\">".$d_name."</b> besitzt noch ".$newhpdef[0]." HP";
- echo "</span>";
- echo "<br><span style=\"margin-left:100px;\">";
- echo "<b style=\"color:red;\">".$a_name."</b> besitzt noch ".$newhpatk[0]." HP<br>";
- echo "</span>";
- // Regeneriere HP
- if ($this->def_hp <= $defmaxhp) {
- $this->def_hp = $this->def_hp / 100 * (100 + $this->def_recoverrate);
- $newhpdef = explode(".", $this->def_hp);
- echo "<br><span style=\"margin-left:100px;\">";
- echo "<i style=\"color:#6f6f6f;\"><b style=\"color:#7AB274;\">".$d_name."</b> Regeneriert ".$this->def_recoverrate."% HP und besitzt nun <b style=\"color:#7f7f7f;\">".$newhpdef[0]."</b> HP</i>";
- echo "</span>";
- } else {
- echo "<br><span style=\"margin-left:100px;\"><b style=\"color:#7AB274;\">".$d_name."</b> Können nicht mehr HP regeneriert werden</span>";
- }
- if ($this->atk_hp <= $atkmaxhp) {
- $this->atk_hp = $this->atk_hp / 100 * (100 + $this->atk_recoverrate);
- $newhpatk = explode(".", $this->atk_hp);
- echo "<br><span style=\"margin-left:100px;\">";
- echo "<i style=\"color:#6f6f6f;\"><b style=\"color:#FFA7A7;\">".$a_name."</b> Regeneriert ".$this->atk_recoverrate."% HP und besitzt nun <b style=\"color:#7f7f7f;\">".$newhpatk[0]."</b> HP</i>";
- echo "</span>";
- } else {
- echo "<br><span style=\"margin-left:100px;\"><b style=\"color:#FFA7A7;\">".$a_name."</b> Können nicht mehr HP regeneriert werden</span>";
- }
- }
- echo "<hr style=\"margin-left:10px;width: 300px;border:none;background-color:black;height:1px;\"><br>";
- }
- }
- if ($this->atk_hp > 0 && $this->def_hp > 0) {
- echo "<br><span style=\"margin-left:100px;border:1px solid #9f9f9f;padding:2px;\">Der Kampf endete Unentschieden!</span><br>";
- }
- }
- }
- ?>
- <html>
- <head>
- <style>
- body {font:11px arial;}
- </style>
- </head>
- <body>
- <?php
- $battle = new battle_enginge;
- $battle->force("Felix", 10634563400, 10, 0, 10, 666, "Lunatic", 1000523523452, 10, 0, 10, 0);
- ?>
- </body>
- </html>