function gGetItherianBonus($itid, $cid, $level)
{
    global $db, $gdTravelChallengeCreatureSelect, $gdItherianComboBonus, $gdItherianComboBonusDescription;
    // fetch creature
    $sql = "SELECT {$gdTravelChallengeCreatureSelect} FROM creatures AS c, races AS r WHERE c.id = '{$cid}' AND c.race = r.id";
    $result = $db->query($sql);
    $row = $db->fetch_array($result);
    $creature = new Creature($row);
    $skill = $creature->data["skill"];
    $baseskillmultiplier = $skill / (gdItherianCreatureTopSkill * gdItherianSkillMultiplier);
    //echo "baseskillmultiplier: $baseskillmultiplier<br>";
    // fetch item sacrifices
    $sql = "SELECT * FROM Itheriansacs WHERE Itherian = '{$itid}' ORDER BY id ASC";
    $result = $db->query($sql);
    $sacs = array();
    while ($row = $db->fetch_array($result)) {
        $sacs[] = $row;
    }
    // calculate bonus
    $bonus = array("description" => "Vibrating", "value" => 0);
    // max modifier used to raise the max bonus for Itherian channelers
    $maxmodifier = 1;
    // active combo's
    $active = array();
    // total amount of combo points
    $points = 0;
    // maximum amount of combo's active at one moment
    $maxactive = 0;
    // all the combo's
    $combonames = array("level_raise" => 2.0, "level_lower" => 1.8, "level_same" => 1.2, "skill_raise" => 2.5, "skill_lower" => 2.3, "skill_same" => 2.0, "class_same" => 1.0, "class_four" => 5.0, "race_same" => 1.3);
    // calculate account skill based on level (calculate in exponential resource cost)
    $levelskill = (gdStartingPoints + $level * gdSkillPointsPerLevel) * gdSkillPointsOnMain * 2;
    $skillexponent = gGetCreatureExponent($levelskill);
    $levelskill = pow($levelskill, $skillexponent);
    $maxskilldif = $levelskill * gdItherianCreatureSkillMaxDifference;
    // set combo length to 0
    foreach ($combonames as $name => $bla) {
        $combos[$name]["length"] = 0;
    }
    // walk all the sacrifices
    for ($i = 0; $i < count($sacs); $i++) {
        $c = $sacs[$i];
        // check for Itherian channeler
        if ($c["type"] == 5 && $c["skill"] == gdItherianChannelerSkill && $c["class"] == $creature->data["class"]) {
            $maxmodifier += gdItherianChannelerBonus;
        }
        // cancelled combo's
        $cancel = array();
        // check already activated combo's
        if ($active["level_raise"]) {
            if ($c["level"] < $combos["level_raise"]["level"]) {
                $cancel["level_raise"] = TRUE;
            }
        }
        if ($active["level_lower"]) {
            if ($c["level"] > $combos["level_lower"]["level"]) {
                $cancel["level_lower"] = TRUE;
            }
        }
        if ($active["level_same"]) {
            if ($c["level"] != $combos["level_same"]["level"]) {
                $cancel["level_same"] = TRUE;
            }
        }
        if ($active["skill_raise"]) {
            if ($c["skill"] < $combos["skill_raise"]["skill"]) {
                $cancel["skill_raise"] = TRUE;
            }
        }
        if ($active["skill_lower"]) {
            if ($c["skill"] < $combos["skill_lower"]["skill"]) {
                $cancel["skill_lower"] = TRUE;
            }
        }
        if ($active["skill_same"]) {
            if ($c["skill"] != $combos["skill_same"]["skill"]) {
                $cancel["skill_same"] = TRUE;
            }
        }
        if ($active["class_same"]) {
            if ($c["class"] != $combos["class_same"]["class"]) {
                $cancel["class_same"] = TRUE;
            }
        }
        if ($active["class_four"]) {
            switch ($combos["class_four"]["class"]) {
                case 1:
                    $next = 4;
                    break;
                case 2:
                    $next = 3;
                    break;
                case 3:
                    $next = 1;
                    break;
                case 4:
                    $next = 2;
                    break;
            }
            if ($next == $c["class"]) {
                $combos["class_four"]["class"] = $next;
            } else {
                $cancel["class_four"] = TRUE;
            }
        }
        if ($active["race_same"]) {
            if ($c["race"] != $combos["race_same"]["race"]) {
                $cancel["race_same"] = TRUE;
            }
        }
        /*echo "cancelled: ";
          print_r($cancel);
          echo "<br>";*/
        // remove cancelled combo's
        foreach ($cancel as $key => $value) {
            if ($value) {
                $active[$key] = FALSE;
                $combos[$key]["length"] = 0;
            }
        }
        // calculate amount of active combo's + base score based on combo details
        $activecombos = 0;
        $score = 0;
        foreach ($active as $key => $value) {
            if ($value) {
                $combos[$key]["length"]++;
                if ($combos[$key]["length"] > gdItherianMaxComboLength) {
                    $combos[$key]["length"] = 0;
                }
                $activecombos++;
                $score += (1 + $combos[$key]["length"] * gdItherianComboLengthMultiplier) * $combonames[$key];
            }
        }
        //echo "activecombos: $activecombos, score: $score<br>";
        // calculate creature difference with levelskill penalty
        $cexponent = gGetCreatureExponent($c["skill"]);
        $cskill = pow($c["skill"], $cexponent);
        $dif = ($levelskill - $cskill) / $maxskilldif;
        if ($dif < 0) {
            $dif = 0;
        }
        if ($dif > 1) {
            $dif = 1;
        }
        $skillpenalty = (1 - $dif) * (1 - gdItherianMaxSkillPenalty) + gdItherianMaxSkillPenalty;
        $score *= $skillpenalty;
        //echo "dif: $dif, skillpenalty: $skillpenalty, score: $score<br>";
        // calculate activate time penalty
        $activatepenalty = (1 - (gdItherianActivateTime - $c["activatetime"]) / gdItherianActivateTime) * (1 - gdItherianActivateTimePenalty) + gdItherianActivateTimePenalty;
        $score *= $activatepenalty;
        //echo "activatepenalty: $activatepenalty, score: $score<br>";
        // give combo points
        if ($activecombos > 0) {
            // update max active
            if ($activecombos > $maxactive) {
                $maxactive = $activecombos;
            }
            // get multiple combos bonus multiplier
            if (isset($gdItherianComboBonus[$activecombos])) {
                $multiplier = $gdItherianComboBonus[$activecombos];
            } else {
                $multiplier = 1.0;
            }
            // update total score
            $score *= $multiplier;
            $points += $score;
            //echo "multiplier: $multiplier, final score: $score, points: $points<br>";
        }
        // new combos?
        if (!$active["level_raise"]) {
            $combos["level_raise"]["level"] = $sacs["level"];
            $active["level_raise"] = TRUE;
        }
        if (!$active["level_lower"]) {
            $combos["level_lower"]["level"] = $sacs["level"];
            $active["level_lower"] = TRUE;
        }
        if (!$active["level_same"]) {
            $combos["level_same"]["level"] = $sacs["level"];
            $active["level_same"] = TRUE;
        }
        if (!$active["skill_raise"]) {
            $combos["skill_raise"]["skill"] = $sacs["skill"];
            $active["skill_raise"] = TRUE;
        }
        if (!$active["skill_lower"]) {
            $combos["skill_lower"]["skill"] = $sacs["skill"];
            $active["skill_lower"] = TRUE;
        }
        if (!$active["skill_same"]) {
            $combos["skill_same"]["skill"] = $sacs["skill"];
            $active["skill_same"] = TRUE;
        }
        if (!$active["class_four"]) {
            $combos["class_four"]["class"] = $sacs["class"];
            $active["class_four"] = TRUE;
        }
        if (!$active["class_same"]) {
            $combos["class_same"]["class"] = $sacs["class"];
            $active["class_same"] = TRUE;
        }
        if (!$active["race_same"]) {
            $combos["race_same"]["race"] = $sacs["race"];
            $active["race_same"] = TRUE;
        }
        //echo "<br>";
    }
    // get description word
    if (isset($gdItherianComboBonusDescription[$maxactive])) {
        $bonus["description"] = $gdItherianComboBonusDescription[$maxactive];
    }
    // multiply points with base bound creature skill multiplier
    $points *= $baseskillmultiplier;
    //echo "FINAL POINTS: $points<br>";
    // calculate the actual bonus
    if ($points > gdItherianMaxBonusPoints * $maxmodifier) {
        $points = gdItherianMaxBonusPoints * $maxmodifier;
    }
    $bonus["value"] = round(gdItherianMaxBonus * $points / gdItherianMaxBonusPoints) + 100;
    //echo "<br><br><br> bonus: ";
    //print_r($bonus);
    // return
    return $bonus;
}
Example #2
0
 function calculateResources()
 {
     // exponentially increase resource cost
     $exponent = gGetCreatureExponent($this->data["skill"]);
     // cost calculation
     $totaldefense = $this->data["forest"] + $this->data["death"] + $this->data["air"] + $this->data["earth"];
     $this->resources["brimstone"] = round(pow($this->data["damage"] * 2 * gdCostMultiplier, $exponent));
     $this->resources["crystal"] = round(pow((2 / 30 * ($totaldefense / 40) * $this->data["maxhealth"] + 2 / 3 * $this->data["maxhealth"]) * gdCostMultiplier, $exponent));
     // amulet check
     if ($this->amulet == TRUE) {
         $this->resources["brimstone"] = floor($this->resources["brimstone"] / 2);
         $this->resources["crystal"] = floor($this->resources["crystal"] / 2);
     }
 }