public static function decideCombat(SR_Player $player, array $args) { $args = SR_AIDecision::filterDecisions($args); $total = 0; $data = array(); foreach ($args as $decision) { $decision instanceof SR_AIDecision; $chance = (int) ($decision->getPreference() * 1000); $total += $chance; $data[] = array($decision, $chance); } $rand = Shadowfunc::randomData($data, $total); return $rand === false ? NULL : $rand; }
private function enemyContact(SR_Party $party, $friendly = false) { $dice = $friendly ? 18 : 8; if (rand(1, $dice) !== 1) { return false; } $mc = $party->getMemberCount(); $level = $party->getMax('level', true); $possible = array(); $total = 0; foreach ($this->npcs as $npc) { $npc instanceof SR_NPC; if ($npc->getNPCLevel() <= $level && $npc->isNPCFriendly($party) === $friendly && $npc->canNPCMeet($party)) { $multi = $friendly === true ? 1 : 1; $percent = round($npc->getNPCMeetPercent($party) * $multi * 100); $total += $percent; $possible[] = array($npc->getNPCClassName(), $percent); } } $npcs = array(); $x = 200; // 200% chance nothing do { $contact = false; if (false !== ($npc = Shadowfunc::randomData($possible, $total, $x * 100))) { $contact = true; $npcs[] = $npc; $x += 120 - Common::clamp($mc * 10, 0, 50); } if (count($npcs) >= $this->maxEnemies($party)) { break; } } while ($contact === true); if (count($npcs) === 0) { return false; } $ep = SR_NPC::createEnemyParty($npcs); if ($friendly === true) { $party->talk($ep, true); } else { $party->fight($ep, true); } return true; }
public static function randModifier(SR_Player $player, $level) { $luck = $player->get('luck'); $total = 0; $possible = array(); $level = intval($level + $luck * 2); foreach (self::getRuneData() as $data) { $minlvl = $data[self::RUNE_MIN_LEVEL]; if ($level < $minlvl) { continue; } $maxlvl = $data[self::RUNE_MAX_LEVEL]; $range = $maxlvl - $minlvl; # Percent of level $level = Common::clamp($level, 0, $maxlvl); $l = $level - $minlvl; $l = $l / $range; $dc = round($data[self::RUNE_DROP_CHANCE] * $l * 100); if ($dc < 1) { continue; } $possible[] = array($data, $dc); $total += $dc; } if (count($possible) === 0) { return false; } if (false === ($data = Shadowfunc::randomData($possible, $total, 0))) { return false; } $minlvl = $data[self::RUNE_MIN_LEVEL]; $maxlvl = $data[self::RUNE_MAX_LEVEL]; $range = $maxlvl - $minlvl; $l = $level - $minlvl; $l = $l / $range; $min = $data[self::RUNE_MIN_MODIFIER]; $max = $data[self::RUNE_MAX_MODIFIER]; $r = $max - $min; $max = $r * $l; $power = Shadowfunc::diceFloat($min, $min + $max, 2) * SR_Player::RUNE_MULTIPLIER; if ($power < 0.1) { return false; } // echo "RUNE POWER $min - $max: $power\n"; return array($data[self::RUNE_MODIFIER] => $power); }