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


PHP misc::newId方法代码示例

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


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

示例1: add

 public function add()
 {
     global $db;
     $recipient = new user();
     if ($recipient->get('name', $this->data['recipient']) == 'done') {
         $sender = new user();
         if ($sender->get('name', $this->data['sender']) == 'done') {
             if (!$sender->isBlocked($recipient->data['id'])) {
                 $this->data['id'] = misc::newId('messages');
                 $sent = strftime('%Y-%m-%d %H:%M:%S', time());
                 $db->query('insert into messages (id, sender, recipient, subject, body, sent, viewed) values ("' . $this->data['id'] . '", "' . $sender->data['id'] . '", "' . $recipient->data['id'] . '", "' . $this->data['subject'] . '", "' . $this->data['body'] . '", "' . $sent . '", "' . $this->data['viewed'] . '")');
                 if ($db->affected_rows() > -1) {
                     $status = 'done';
                 } else {
                     $status = 'error';
                 }
             } else {
                 $status = 'blocked';
             }
         } else {
             $status = 'noSender';
         }
     } else {
         $status = 'noRecipient';
     }
     return $status;
 }
开发者ID:yunsite,项目名称:devana-heroic,代码行数:27,代码来源:message.class.php

示例2: add

 public function add($nodeId)
 {
     global $db, $game;
     $alliance = new alliance();
     if ($alliance->get('name', $this->data['name']) == 'noAlliance') {
         $node = new node();
         if ($node->get('id', $nodeId) == 'done') {
             $node->checkResources(time());
             $addCost = $game['factions'][$node->data['faction']]['costs']['alliance'];
             $addCostData = $node->checkCost($addCost, 'alliance');
             if ($addCostData['ok']) {
                 $ok = 1;
                 foreach ($addCost as $cost) {
                     $node->resources[$cost['resource']]['value'] -= $cost['value'] * $game['users']['cost']['alliance'];
                     $db->query('update resources set value="' . $node->resources[$cost['resource']]['value'] . '" where node="' . $node->data['id'] . '" and id="' . $cost['resource'] . '"');
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                 }
                 $this->data['id'] = misc::newId('alliances');
                 $db->query('insert into alliances (id, user, name) values ("' . $this->data['id'] . '", "' . $node->data['user'] . '", "' . $this->data['name'] . '")');
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 $db->query('update users set alliance="' . $this->data['id'] . '" where id="' . $this->data['user'] . '"');
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 if ($ok) {
                     $status = 'done';
                 } else {
                     $status = 'error';
                 }
             } else {
                 $status = 'notEnoughResources';
             }
         } else {
             $status = 'noNode';
         }
     } else {
         $status = 'nameTaken';
     }
     return $status;
 }
开发者ID:yunsite,项目名称:devana-heroic,代码行数:44,代码来源:alliance.class.php

示例3: add

 public function add()
 {
     global $db, $game;
     $user = new user();
     if ($user->get('name', $this->data['name']) == 'noUser') {
         if ($user->get('email', $this->data['email']) == 'noUser') {
             if (!blacklist::check('ip', $this->data['ip'])) {
                 if (!blacklist::check('email', $this->data['email'])) {
                     $ok = 1;
                     $this->data['id'] = misc::newId('users');
                     $db->query('insert into users (id, name, password, email, level, joined, lastVisit, ip, template, locale) values ("' . $this->data['id'] . '", "' . $this->data['name'] . '", "' . $this->data['password'] . '", "' . $this->data['email'] . '", "' . $this->data['level'] . '", "' . $this->data['joined'] . '", "' . $this->data['lastVisit'] . '", "' . $this->data['ip'] . '", "' . $this->data['template'] . '", "' . $this->data['locale'] . '")');
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                     $preferences = array();
                     foreach ($game['users']['preferences'] as $key => $preference) {
                         $preferences[] = '("' . $this->data['id'] . '", "' . $key . '", "' . $preference . '")';
                     }
                     $preferences = implode(', ', $preferences);
                     $db->query('insert into preferences (user, name, value) values ' . $preferences);
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                     if ($ok) {
                         $status = 'done';
                     } else {
                         $status = 'error';
                     }
                 } else {
                     $status = 'emailBanned';
                 }
             } else {
                 $status = 'ipBanned';
             }
         } else {
             $status = 'emailInUse';
         }
     } else {
         $status = 'nameTaken';
     }
     return $status;
 }
开发者ID:yunsite,项目名称:devana-heroic,代码行数:42,代码来源:user.class.php

示例4: addCombat

 public function addCombat($nodeId, $data)
 {
     global $db, $game;
     $this->getResources();
     $this->getUnits();
     $this->getLocation();
     $node = new node();
     $okUnits = 1;
     $army = array();
     foreach ($data['input']['attacker']['groups'] as $group) {
         if (isset($army[$group['unitId']])) {
             $army[$group['unitId']] += $group['quantity'];
         } else {
             $army[$group['unitId']] = $group['quantity'];
         }
     }
     $speed = 999999999;
     foreach ($this->units as $key => $group) {
         if (isset($army[$key])) {
             if ($army[$key] > $group['value']) {
                 $okUnits = 0;
             }
             if ($game['units'][$this->data['faction']][$key]['speed'] < $speed) {
                 $speed = $game['units'][$this->data['faction']][$key]['speed'];
             }
         }
     }
     $combatCost = $game['factions'][$this->data['id']]['costs']['combat'];
     $okCombatCost = $this->checkCost($combatCost, 'combat');
     if ($okUnits) {
         if ($okCombatCost['ok']) {
             if ($node->get('id', $nodeId) == 'done') {
                 $node->getLocation();
                 $distance = sqrt(pow(abs($this->location['x'] - $node->location['x']), 2) + pow(abs($this->location['y'] - $node->location['y']), 2));
                 $duration = $distance / ($speed * $game['users']['speed']['combat']);
                 $combatId = misc::newId('combat');
                 $ok = 1;
                 $cuBuffer = array();
                 foreach ($army as $key => $value) {
                     $cuBuffer[] = '("' . $combatId . '", "' . $key . '", "' . $value . '")';
                     $this->units[$key]['value'] -= $value;
                     $db->query('update units set value="' . $this->units[$key]['value'] . '" where node="' . $this->data['id'] . '" and id="' . $key . '"');
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                     $upkeepResource = $game['units'][$this->data['faction']][$key]['upkeepResource'];
                     $upkeep = $game['units'][$this->data['faction']][$key]['upkeep'];
                     $this->resources[$upkeepResource]['value'] += $upkeep * $value;
                     $db->query('update resources set value="' . $this->resources[$upkeepResource]['value'] . '" where node="' . $this->data['id'] . '" and id="' . $upkeepResource . '"');
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                 }
                 foreach ($combatCost as $cost) {
                     $this->resources[$cost['resource']]['value'] -= $cost['value'] * $game['users']['cost']['combat'];
                     $db->query('update resources set value="' . $this->resources[$cost['resource']]['value'] . '" where node="' . $this->data['id'] . '" and id="' . $cost['resource'] . '"');
                     if ($db->affected_rows() == -1) {
                         $ok = 0;
                     }
                 }
                 $db->query('insert into combat (id, sender, recipient, focus, stage, start, duration) values ("' . $combatId . '", "' . $this->data['id'] . '", "' . $node->data['id'] . '", "' . $data['input']['attacker']['focus'] . '", "0", "' . strftime('%Y-%m-%d %H:%M:%S', time()) . '", "' . $duration . '")');
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 $db->query('insert into combat_units (combat, id, value) values ' . implode(', ', $cuBuffer));
                 if ($db->affected_rows() == -1) {
                     $ok = 0;
                 }
                 if ($ok) {
                     $status = 'done';
                 } else {
                     $status = 'error';
                 }
             } else {
                 $status = 'noNode';
             }
         } else {
             $status = 'notEnoughResources';
         }
     } else {
         $status = 'notEnoughUnits';
     }
     return $status;
 }
开发者ID:yunsite,项目名称:devana-heroic,代码行数:84,代码来源:node.class.php


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