当前位置: 首页>>代码示例>>PHP>>正文


PHP Common::clamp方法代码示例

本文整理汇总了PHP中Common::clamp方法的典型用法代码示例。如果您正苦于以下问题:PHP Common::clamp方法的具体用法?PHP Common::clamp怎么用?PHP Common::clamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Common的用法示例。


在下文中一共展示了Common::clamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parseStats

 public function parseStats($url)
 {
     if (false === ($result = GWF_HTTP::getFromURL($url, false))) {
         return htmlDisplayError(WC_HTML::lang('err_response', array(GWF_HTML::display($result), $this->displayName())));
     }
     $result = str_replace("", '', $result);
     # BOM
     $result = trim($result);
     $stats = explode(":", $result);
     if (count($stats) !== 7) {
         return htmlDisplayError(WC_HTML::lang('err_response', array(GWF_HTML::display($result), $this->displayName())));
     }
     $i = 0;
     $username = $stats[$i++];
     $rank = intval($stats[$i++]);
     $onsitescore = intval($stats[$i++]);
     $onsitescore = Common::clamp($onsitescore, 0);
     $maxscore = intval($stats[$i++]);
     $challssolved = intval($stats[$i++]);
     $challcount = intval($stats[$i++]);
     $usercount = intval($stats[$i++]);
     if ($maxscore === 0 || $challcount === 0 || $usercount === 0) {
         return htmlDisplayError(WC_HTML::lang('err_response', array(GWF_HTML::display($result), $this->displayName())));
     }
     return array($onsitescore, $rank, $challssolved, $maxscore, $usercount, $challcount);
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:26,代码来源:WCSite_PHM.php

示例2: onThrow

 public function onThrow(SR_Player $player, SR_Player $target)
 {
     $firearms = $player->get('firearms');
     $atk = 20 + $firearms;
     $mindmg = 1;
     $maxdmg = 6;
     $out_dmg = '';
     $out_dmgep = '';
     $out_eff = '';
     $inaccuracy = rand(2, 4) - ($firearms ? 1 : 0);
     $targets = $this->computeDistances($target, $inaccuracy);
     foreach ($targets as $data) {
         list($t, $d) = $data;
         $t instanceof SR_Player;
         $a = $atk - $d + rand(-1, 2);
         $a = Common::clamp($a, 0, $atk);
         $def = $t->get('defense');
         $arm = $t->get('marm');
         $hits = Shadowfunc::diceHits($mindmg, $arm, $atk, $def, $player, $t);
         $hits -= $arm;
         $hits = Common::clamp($hits, 0);
         if ($hits == 0) {
             continue;
         }
         $dmg = round($mindmg + $hits / 10, 2);
         if ($dmg <= 0) {
             continue;
         }
     }
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:30,代码来源:MolotovCocktail.php

示例3: execute

 public static function execute(SR_Player $player, array $args)
 {
     $pp = Shadowrun4::getParties();
     foreach ($pp as $i => $p) {
         $p instanceof SR_Party;
         if (!$p->isHuman()) {
             unset($pp[$i]);
         }
     }
     $page = isset($args[0]) ? intval($args[0]) : 1;
     $nItems = count($pp);
     $nPages = GWF_PageMenu::getPagecount(self::PPP, $nItems);
     $page = Common::clamp($page, 1, $nPages);
     $from = GWF_PageMenu::getFrom($page, self::PPP);
     $slice = array_slice($pp, $from, self::PPP);
     $out = '';
     $format = $player->lang('fmt_list');
     foreach ($slice as $p) {
         $p instanceof SR_Party;
         $leader = $p->getLeader()->displayName();
         $l = $p->getSum('level', true);
         $ll = $p->getSum('level', false);
         $mc = $p->getMemberCount();
         $item = sprintf('%s(L%s(%s))(M%s)', $leader, $l, $ll, $mc);
         $out .= sprintf($format, $item);
         // 			$out .= sprintf(', %s(L%s(%s))(M%s)', $leader, $l, $ll, $mc);
     }
     return self::rply($player, '5248', array($page, $nPages, ltrim($out, ',; ')));
     // 		$bot = Shadowrap::instance($player);
     // 		$bot->reply(sprintf('Parties page %s from %s: %s.', $page, $nPages, substr($out, 2)));
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:31,代码来源:parties.php

示例4: templateSongs

 private function templateSongs()
 {
     //		$user = GWF_Session::getUser();
     //		$uid = $user->getID();
     $table = GDO::table('Slay_Song');
     $joins = NULL;
     $headers = array();
     $headers[] = array($this->module->lang('th_artist'), 'ss_artist');
     $headers[] = array($this->module->lang('th_title'), 'ss_title');
     $headers[] = array($this->module->lang('th_duration'), 'ss_duration');
     $headers[] = array($this->module->lang('th_bpm'), 'ss_bpm');
     $headers[] = array($this->module->lang('th_key'), 'ss_key');
     $headers[] = array($this->module->lang('D'));
     $headers[] = array($this->module->lang('L'));
     $headers[] = array($this->module->lang('T'));
     $headers[] = array($this->module->lang('th_tags'));
     $where = "";
     $nItems = $table->selectVar('COUNT(ss_id)', $where, '', $joins);
     $nPages = GWF_PageMenu::getPagecount(self::IPP, $nItems);
     $page = Common::clamp(Common::getGetInt('page'), 1, $nPages);
     $by = Common::getGetString('by', self::BY);
     $dir = Common::getGetString('dir', self::DIR);
     $orderby = $table->getMultiOrderby($by, $dir, false);
     $songs = $table->selectAll('*', $where, $orderby, $joins, self::IPP, GWF_PageMenu::getFrom($page, self::IPP), GDO::ARRAY_O);
     $tVars = array('is_dj' => GWF_User::isInGroupS('dj'), 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=Slaytags&me=Songs&by=%BY%&dir=%DIR%&page=1', 'pagemenu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . sprintf('index.php?mo=Slaytags&me=Songs&by=%s&dir=%s&page=%%PAGE%%', urlencode($by), urlencode($dir))), 'songs' => $songs, 'headers' => $headers);
     return $this->module->template('songs.tpl', $tVars);
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:27,代码来源:Songs.php

示例5: onNPCTalk

 public function onNPCTalk(SR_Player $player, $word, array $args)
 {
     $price = 800 - Common::clamp($player->get('negotiation'), 0, 10) * 10;
     $time = 1000 * $player->get('charisma') * 60;
     $b = chr(2);
     switch ($word) {
         case 'shadowrun':
             return $this->reply("I am in for a run, Do you want to {$b}hire{$b} my hacking skills?");
         case 'yes':
             return $this->reply("Yes, {$b}hire{$b} me and i'll aid you in combat and hacking.");
         case 'no':
             if ($player->hasTemp(self::MANIFESTO)) {
                 return $this->reply('Yes, no, what else?');
             } else {
                 $this->reply("This is our world now... The world of the electron and the switch, the beauty of the baud.");
                 $this->reply("We make use of a service already existing without paying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals.");
                 $this->reply("We explore... And you call us criminals. We seek after knowledge... And you call us criminals. We exist without skin color, without nationality, without religious bias... And you call us criminals.");
                 $this->reply("You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it's for our own good, yet we're the criminals.");
                 $this->reply("Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.");
                 $this->reply("I am a hacker, and this is my manifesto. You may stop this individual, but you can't stop us all... After all, we're all alike.");
                 $player->setTemp(self::MANIFESTO, 1);
                 return true;
             }
             break;
         case 'hire':
             return $this->reply($this->onHire($player, $price, $time));
         default:
             return $this->reply("Need a hacker?");
             break;
     }
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:31,代码来源:HireDecker.php

示例6: getStoreItemsB

 /**
  * Filter Store Items through availability.
  * @param SR_Player $player
  */
 public function getStoreItemsB(SR_Player $player)
 {
     $key = $this->getStoreItemsKey();
     if ($player->hasTemp($key)) {
         return $player->getTemp($key);
     }
     $rep = Common::clamp($player->get('reputation'), 0, 25) * 0.5;
     $items = $this->getStoreItems($player);
     if (!is_array($items)) {
         return array();
     }
     $back = array();
     $unique = false;
     foreach ($items as $i => $data) {
         $avail = isset($data[1]) ? $data[1] : 100.0;
         $avail += $rep;
         if (Shadowfunc::dicePercent($avail)) {
             $back[] = $data;
         } else {
             $unique = true;
         }
     }
     if ($unique === true) {
         $player->setTemp($key, $back);
     }
     return $back;
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:31,代码来源:SR_Store.php

示例7: execute

 public function execute()
 {
     if (false === ($user = GWF_User::getByName(Common::getGetString('username')))) {
         return GWF_HTML::err('ERR_UNKNOWN_USER');
     }
     if (false !== ($error = $this->module->isExcludedFromAPI($user, false))) {
         return $error;
     }
     $this->module->includeClass('WC_RegAt');
     $format = Common::getGetString('format', self::FORMAT);
     $bg = Common::getGetString('bg', self::BGCOLOR);
     $fg = Common::getGetString('fg', self::FGCOLOR);
     $size = Common::clamp(Common::getGetInt('s', self::SIZE), 6, 30);
     $spacingx = Common::clamp(Common::getGetInt('sx', 1), 0, 30);
     $spacingy = Common::clamp(Common::getGetInt('sy', 1), 0, 30);
     $marginx = Common::clamp(Common::getGetInt('mx', 1), 0, 30);
     $marginy = Common::clamp(Common::getGetInt('my', 1), 0, 30);
     $divider = Common::getGetString('div', '  ');
     $font = Common::getGetString('font', self::FONT);
     $_GET['font'] = $font;
     if (!preg_match('/^[a-z_0-9]+$/iD', $font) || !Common::isFile(GWF_EXTRA_PATH . 'font/' . $font . '.ttf')) {
         return "Font not found. Available fonts: " . $this->listFonts();
     }
     die($this->displayBanner($user, $format, $bg, $fg, $size, $spacingx, $spacingy, $marginx, $marginy, $divider));
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:25,代码来源:API_UserBanner.php

示例8: templateUsers

 private function templateUsers($term = '')
 {
     $ipp = $this->module->cfgIPP();
     $form = $this->getFormQuick();
     $usertable = GDO::table('GWF_User');
     $by = Common::getGet('by', '');
     $dir = Common::getGet('dir', '');
     $orderby = $usertable->getMultiOrderby($by, $dir);
     if ($term === '') {
         $users = array();
         $page = 1;
         $nPages = 0;
     } else {
         $eterm = GDO::escape($term);
         $deleted = GWF_User::DELETED;
         $conditions = "user_name LIKE '%{$eterm}%' AND user_options&{$deleted}=0";
         $nItems = $usertable->countRows($conditions);
         $nPages = GWF_PageMenu::getPagecount($ipp, $nItems);
         $page = Common::clamp(intval(Common::getGet('page', 1)), 1, $nPages);
         $from = GWF_PageMenu::getFrom($page, $ipp);
         $users = $usertable->selectObjects('*', $conditions, $orderby, $ipp, $from);
     }
     $href_pagemenu = GWF_WEB_ROOT . 'index.php?mo=Usergroups&me=Search&term=' . urlencode($term) . '&by=' . urlencode($by) . '&dir=' . urlencode($dir) . '&page=%PAGE%';
     $tVars = array('form' => $form->templateX(false, false), 'users' => $users, 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=Usergroups&me=Search&term=' . urlencode($term) . '&by=%BY%&dir=%DIR%&page=1', 'page_menu' => GWF_PageMenu::display($page, $nPages, $href_pagemenu), 'href_adv' => $this->module->getMethodURL('SearchAdv'));
     return $this->module->templatePHP('search.php', $tVars);
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:26,代码来源:Search.php

示例9: onSearch

 public function onSearch()
 {
     $form = $this->getForm();
     //		if (false !== ($error = $form->validate($this->module))) {
     //			return $error.$this->templateSearch();
     //		}
     $users = GDO::table('GWF_User');
     $term = Common::getRequest('term');
     if (false !== ($error = $this->validate_term($this->module, $term))) {
         return $error;
     }
     $fields = array('user_name', 'user_email');
     $by = Common::getGet('by', self::DEFAULT_BY);
     $dir = Common::getGet('dir', self::DEFAULT_DIR);
     $orderby = $users->getMultiOrderby($by, $dir);
     if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($users, $fields, $term))) {
         $conditions = '0';
     }
     $hits = $users->countRows($conditions);
     $ipp = $this->module->cfgUsersPerPage();
     $nPages = GWF_PageMenu::getPagecount($ipp, $hits);
     $page = Common::clamp((int) Common::getGet('page', 1), 1, $nPages);
     $from = GWF_PageMenu::getFrom($page, $ipp);
     $tVars = array('searched' => true, 'form' => $form->templateX($this->module->lang('ft_search')), 'hits' => $hits, 'users' => $users->selectObjects('*', $conditions, $orderby, $ipp, $from), 'term' => $term, 'pagemenu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . 'index.php?mo=Admin&me=UserSearch&term=' . urlencode($term) . '&by=' . urlencode($by) . '&dir=' . urlencode($dir) . '&page=1'), 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=Admin&me=UserSearch&term=' . urlencode($term) . '&by=%BY%&dir=%DIR%&page=1');
     return $this->module->templatePHP('user_search.php', $tVars);
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:26,代码来源:UserSearch.php

示例10: display

 public static function display(GWF_Module $module, GDO $gdo, $user, $sortURL, $conditions = '', $ipp = 25, $pageURL = false, $joins = NULL)
 {
     $fields = $gdo->getSortableFields($user);
     $headers = self::getGDOHeaders2($module, $gdo, $user, $sortURL);
     $nItems = $gdo->countRows($conditions);
     $nPages = GWF_PageMenu::getPagecount($ipp, $nItems);
     $page = Common::clamp(intval(Common::getGet('page', 1)), 1, $nPages);
     $orderby = self::getMultiOrderBy($gdo, $user);
     $from = GWF_PageMenu::getFrom($page, $ipp);
     $i = 0;
     $data = array();
     if (false === ($result = $gdo->select('*', $conditions, $orderby, $joins, $ipp, $from))) {
         echo GWF_HTML::err(ERR_DATABASE, __FILE__, __LINE__);
         return false;
     }
     while (false !== ($row = $gdo->fetch($result, GDO::ARRAY_O))) {
         $row instanceof GWF_Sortable;
         $data[$i] = array();
         foreach ($fields as $field) {
             $data[$i][] = $row->displayColumn($module, $user, $field);
         }
         $i++;
     }
     $gdo->free($result);
     if ($pageURL === false) {
         $pageURL = '';
     } elseif ($pageURL === true) {
         $pageURL = str_replace(array('%BY%', '%DIR%'), array(urlencode(Common::getGet('by')), urlencode(Common::getGet('dir'))), $sortURL);
         $pageURL .= '&page=%PAGE%';
     }
     $pagemenu = $pageURL === '' ? '' : GWF_PageMenu::display($page, $nPages, $pageURL);
     return $pagemenu . self::display2($headers, $data) . $pagemenu;
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:33,代码来源:GWF_TableGDO.php

示例11: calcTicketPrice

 public function calcTicketPrice($price, SR_Player $player)
 {
     $neg = Common::clamp($player->get('negotiation'), 0, 10) * 0.01;
     $mc = $player->getParty()->getMemberCount();
     $price = $price * $mc;
     $price = $price * (1.0 - $neg);
     return $price;
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:8,代码来源:SR_Subway.php

示例12: getNPCMeetPercent

 public function getNPCMeetPercent(SR_Party $party)
 {
     if ($this->getNPCCityClass()->isAlert($party)) {
         return 300;
     }
     $bad_karma = $party->getSum('bad_karma', true);
     $perc = $bad_karma / 5 * 100;
     return Common::clamp($perc, 0.0, 100.0);
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:9,代码来源:GrayOp.php

示例13: getShoutWait

 private static function getShoutWait(SR_Player $player)
 {
     $range = self::MAX_DELAY - self::MIN_DELAY;
     $tpl = $range / self::MAX_LEVEL;
     $level = Common::clamp($player->getBase('level'), 0, self::MAX_LEVEL);
     $delay = self::MIN_DELAY + $tpl * (self::MAX_LEVEL - $level);
     $last = $player->hasTemp(self::TEMP_KEY) ? $player->getTemp(self::TEMP_KEY) : 0;
     $next = $last + $delay;
     return $next - time();
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:10,代码来源:Shadowshout.php

示例14: getTrollCount

 public function getTrollCount(SR_Player $player)
 {
     $c2 = SR_PlayerVar::getVal($player, 'THQLVTRC', 0);
     if ($c2 >= 1) {
         return 0;
     }
     $p = $player->getParty();
     $mc = $p->getMemberCount();
     $c = $mc * 2 + 1;
     return Common::clamp($c, 1, 10);
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:11,代码来源:LivingRoom.php

示例15: sanitize

 private function sanitize()
 {
     $this->table = new GWF_UserActivation(false);
     $this->ipp = $this->module->getActivationsPerPage();
     $this->nItems = $this->table->countRows();
     $this->nPages = GWF_PageMenu::getPagecount($this->ipp, $this->nItems);
     $this->page = Common::clamp((int) Common::getGet('page', 1), 1, $this->nPages);
     $this->by = $this->table->getWhitelistedBy(Common::getGetString('by'), 'timestamp');
     $this->dir = GDO::getWhitelistedDirS(Common::getGetString('dir'), 'DESC');
     $this->orderby = "{$this->by} {$this->dir}";
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:11,代码来源:Admin.php


注:本文中的Common::clamp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。