Tokiwa Battle Royale  GE777
A PHP Battle Royale inspired game
 All Data Structures Namespaces Files Functions Variables Pages
alive.php
Go to the documentation of this file.
1 <?php
2 
3 define('CURSCRIPT', 'alive');
4 
5 require './include/common.inc.php';
6 //extract(gkillquotes($_POST));
7 //unset($_GET);
8 
9 if(!isset($alivemode) || $alivemode == 'last'){
10  $result = $db->query("SELECT * FROM {$tablepre}users RIGHT JOIN {$tablepre}players ON {$tablepre}players.name={$tablepre}users.username WHERE {$tablepre}players.type=0 AND {$tablepre}players.hp>0 ORDER BY {$tablepre}players.money DESC, {$tablepre}players.killnum DESC LIMIT $alivelimit");
11 }elseif($alivemode == 'all'){
12  $result = $db->query("SELECT * FROM {$tablepre}users RIGHT JOIN {$tablepre}players ON {$tablepre}players.name={$tablepre}users.username WHERE {$tablepre}players.type=0 AND {$tablepre}players.hp>0 ORDER BY {$tablepre}players.money DESC, {$tablepre}players.killnum DESC");
13 }else{
14  echo 'error';
15  exit();
16 }
17 $alivedata = $apdata = Array();
18 while($apdata = $db->fetch_array($result)) {
19  $apdata['iconImg'] = "{$apdata['gd']}_{$apdata['icon']}.gif";
20  $apdata['winrate'] = $apdata['wingames'] ? round($apdata['wingames']/$apdata['validgames']*100).'%' : '0%';
21  if (($apdata['endtime'] - $apdata['validtime'])>0) {
22  $apdata['apm'] = round($apdata['cmdnum']/($apdata['endtime'] - $apdata['validtime']) * 60 * 1000)/1000;
23  } else{
24  $apdata['apm'] = 0;
25  }
26  // $result3 = $db->query("SELECT motto FROM {$tablepre}users WHERE username = '".$apdata['name']."'");
27 // $apdata['motto'] = $db->result($result3, 0);
28 
29  $alivedata[$apdata['pid']] = $apdata;
30 }
31 
32 $adata = Array();
33 if($gamblingon){
34  $gbinfo = '';
35  $gbingdata = $gbeddata = $gambled = Array();
36  $gbpool = 0;
37  $nowodds = odds();
38  //读取赌局信息
39  $result2 = $db->query("SELECT * FROM {$tablepre}gambling WHERE 1");
40  $gbnum = $db->num_rows($result2);
41  if($gbnum){
42  while($gbdata = $db->fetch_array($result2)) {
43  $gbingdata[$gbdata['bid']][$gbdata['uid']] = $gbdata;
44  $gbeddata[$gbdata['uid']] = $gbdata;
45  $gbpool += $gbdata['wager'];
46  }
47  }
48  foreach($alivedata as &$ad){
49  $ad['gbnum'] = gbnum($ad);
50  $ad['gbsum'] = gbsum($ad);
51 // if($gbnum && isset($gbingdata[$ad['pid']])){
52 // $ad['gbnum'] = count($gbingdata[$ad['pid']]);
53 // $ad['gbsum'] = 0;
54 // foreach($gbingdata[$ad['pid']] as $gad){
55 // $ad['gbsum'] += $gad['wager'];
56 // }
57 // }else{$ad['gbnum'] = 0;$ad['gbsum'] = 0;}
58 // $ad['odds'] = podds($ad);
59  }
60  //判断是否满足下注条件
61  if($cuser && $cpass){
62  if($gamestate < 20) { $gbinfo .= $_ERROR['no_start']; }
63  //elseif($now - $starttime >= 600) { $gbinfo .= '游戏开始超过10分钟,不可进行下注!'; }
64  elseif($areanum >= $areaadd) { $gbinfo .= '游戏超过一禁,不可进行下注!'; }
65  elseif($gamestate >= 30) { $gbinfo .= '游戏已停止激活,不可进行下注!'; }
66  elseif($gbpool >= 8000 && $wager>50) { $gbinfo .= '本局总奖池已经超过8000切糕上限,此时每人最多只能下注50切糕!'; }
67  else{
68  $uresult = $db->query("SELECT * FROM {$tablepre}users WHERE username='$cuser'");
69  if(!$db->num_rows($uresult)) { $gbinfo .= $_ERROR['login_check']; }
70  else{
71  $udata = $db->fetch_array($uresult);
72  if($udata['password'] != $cpass) { $gbinfo .= $_ERROR['wrong_pw']; }
73  elseif($udata['groupid'] <= 0) { $gbinfo .= $_ERROR['user_ban']; }
74  elseif($alivenum <= 0){ $gbinfo .= '当前生存人数为0,无法下注!';}
75  else{
76  $uid = $udata['uid'];$uname = $udata['username'];
77  $credits2 = $udata['credits2'];
78  if($gbmode == 'gamble'){
79  $wager = ceil((int)$wager);
80  if(!$bet || $bet == 'none'){ $gbinfo .= '投注对象有误,请检查输入。';}
81  elseif($wager <= 0){ $gbinfo .= '投注数额有误,请检查输入。';}
82  elseif($wager > $credits2 || $wager > 1000 ){ $gbinfo .= '投注数额过大。每人每局最多只能投注总计不超过1000切糕。';}
83  elseif ($gbpool >= 8000 && $wager > 50) { $gbinfo .= '本局总奖池已经超过8000切糕上限,此时每人最多只能下注50切糕!'; }
84  else{
85  $bet = (int)$bet;
86  $bresult = $db->query("SELECT * FROM {$tablepre}players LEFT JOIN {$tablepre}users ON {$tablepre}players.name={$tablepre}users.username WHERE {$tablepre}players.pid='$bet'");
87  if(!$db->num_rows($bresult)) { $gbinfo .= '投注对象不存在。'; }
88  else{
89  $bdata = $db->fetch_array($bresult);
90  $bname = $bdata['name'];
91  if($bdata['hp'] <= 0 || $bdata['state'] >= 10) {$gbinfo .= '投注对象已死亡,无法下注。'; }
92  elseif($bdata['type'] >=1) {$gbinfo .= '投注对象不是人类!'; }
93  elseif($gbnum && isset($gbeddata[$udata['uid']])){//已经下注
94  $gbudata = $gbeddata[$udata['uid']];
95  if ($gbudata['wager'] + $wager > 1000 )
96  {
97  $gbinfo .= '投注数额过大。每人每局最多只能投注总计不超过1000切糕。';
98  }
99  else if ($gbpool >= 8000 && $gbudata['wager'] + $wager > 50)
100  {
101  $gbinfo .= '本局总奖池已经超过8000切糕上限,此时每人最多只能下注50切糕!';
102  }
103  else if($gbudata['bid'] != $bet){$gbinfo .= '追加切糕的对象必须跟之前相同。';}
104  else{
105  $bwager = $gbudata['wager'] + $wager;
106  $odds = ($gbudata['wager'] * $gbudata['odds'] + $nowodds * $wager)/$bwager;
107  $db->query("UPDATE {$tablepre}gambling SET wager='$bwager',odds='$odds' WHERE uid='$uid'");
108  if($db->affected_rows() == 1){
109  $gbeddata[$udata['uid']]['wager']+=$wager;
110  //$gbeddata[$udata['uid']]['odds']=$odds;
111  $gbinfo .= '成功对'.$bname.'追加下注。';
112  $credits2 -= $wager;
113  if(isset($alivedata[$bet])){
114  $alivedata[$bet]['gbsum']+=$wager;
115  //$alivedata[$bet]['odds'] = podds($alivedata[$bet]);
116  }
117 
118  $db->query("UPDATE {$tablepre}users SET credits2='$credits2' WHERE uid='$uid'");
119  }else{$gbinfo .= '数据库错误,请联系管理员。';}
120  }
121  }else{//未下注
122  //$odds = podds($bdata);
123  //echo $odds;
124  $db->query("INSERT INTO {$tablepre}gambling (uid,uname,bid,bname,wager,odds) VALUES ('$uid','$uname','$bet','$bname','$wager','$nowodds')");
125  if($db->affected_rows() == 1){
126  $gbeddata[$udata['uid']]['wager']=$wager;
127  $gbeddata[$udata['uid']]['bname']=$bname;
128  //$gbeddata[$udata['uid']]['odds']=$odds;
129  $gbinfo .= '成功对'.$bname.'下注。';
130  $credits2 -= $wager;
131  $gbnum++;
132  if(isset($alivedata[$bet])){
133  $alivedata[$bet]['gbnum']++;
134  $alivedata[$bet]['gbsum']+=$wager;
135  //$alivedata[$bet]['odds'] = podds($alivedata[$bet]);
136  }
137 
138  $db->query("UPDATE {$tablepre}users SET credits2='$credits2' WHERE uid='$uid'");
139  }else{$gbinfo .= '数据库错误,请联系管理员。';}
140  }
141  }
142  }
143  }
144  if($gbnum && isset($gbeddata[$udata['uid']])){
145  $gbudata = $gbeddata[$udata['uid']];
146  $gbinfo .= '你已下注,对象为:'.$gbudata['bname'].',切糕为:'.$gbudata['wager'].';';
147  //var_dump($gbeddata[$udata['uid']]);
148  $gbact = 1;
149  }else{
150  $gbinfo .= '你尚未下注。';
151  $gbact = 0;
152  }
153  }
154  }
155  }
156  $adata['innerHTML']['gbinfo'] .= $gbinfo;
157  }else{
158  $gbinfo .= $_ERROR['no_login'];
159  }
160 }
161 
162 if(!isset($alivemode)){
163  include template('alive');
164 }else{
165  include template('alivelist');
166  $adata['innerHTML']['alivelist'] = ob_get_contents();
167  if($gamblingon){
168  $adata['innerHTML']['gbinfo'] = $gbinfo;
169  if(isset($credits2)){$adata['innerHTML']['credits2'] = $credits2;}
170  }
171  if(isset($error)){$adata['innerHTML']['error'] = $error;}
172  ob_clean();
174  echo $jgamedata;
175  ob_end_flush();
176 }
177 
178 //include template('alive');
179 
180 function gbnum($pdata){
181  global $gbnum,$gbingdata;
182  if($gbnum && isset($gbingdata[$pdata['pid']])){
183  return count($gbingdata[$pdata['pid']]);
184  }else{return 0;}
185 }
186 
187 function gbsum($pdata){
188  global $gbnum,$gbingdata;
189  if($gbnum && isset($gbingdata[$pdata['pid']])){
190  $gbsum = 0;
191  foreach($gbingdata[$pdata['pid']] as $gad){
192  $gbsum += $gad['wager'];
193  }
194  return $gbsum;
195  }else{return 0;}
196 }
197 
198 function odds(){//判断赔率的
200 
201 // $areaodds = 2/(1+$areanum/$areaadd);//0禁赔率奖励为2,1禁赔率奖励为1,逐步降低
202  $pasttime = $now - $starttime;
203  if($pasttime <= 180){$timeodds = 5;}//前3分钟系数为5;
204  else{$timeodds = 5/($pasttime/180);}//系数趋近于0;
205 
206  $timeodds = round($timeodds * 100000)/100000;
207 // $validodds = $validnum/100;//激活赔率;
208 // $deathodds = $deathnum/400;//死亡赔率,增长很慢
209 // $winrate = $pdata['validgames'] ? $pdata['wingames']/$pdata['validgames'] : 0;
210 // $wrodds = 4*(0.5-$winrate);$wrodds = $wrodds < 0 ? 1 : $wrodds + 1;//胜率赔率倍数,0胜率是5,超过50%为1;
211 // $gbsum = gbsum($pdata);
212 // $wagerodds = (100-$gbsum)/100; $wagerodds = $wagerodds < 0 ? 1 : $wagerodds + 1;//投注的影响,0投注是2,超过100投注是1;
213 // $odds = round((1 + $areaodds + $validodds + $deathodds)*$wrodds*$wagerodds*1000)/1000;
214 
215  return $timeodds;
216 }
217 ?>
$areanum
Definition: gameinfo.php:9
$validnum
Definition: gameinfo.php:13
while($apdata=$db->fetch_array($result)) $adata
Definition: alive.php:32
$db
Definition: clear.php:32
$deathnum
Definition: gameinfo.php:15
【生存者数:<?php echo $alivenum?> 人】< input type="button"value="显示全部幸存者"onClick="$('alivemode').value='all';$('gbmode').value='none';postCmd('alive','alive.php');"></p > if($gamblingon &&$gamestate >=20) elseif($gamblingon &&$gamestate<=10)
Definition: 1_alive.tpl.php:18
gbnum($pdata)
Definition: alive.php:180
if(!$db->num_rows($result)) $pdata
Definition: botservice.php:18
$alivenum
Definition: gameinfo.php:14
$error
Definition: errorpage.php:2
$now
Definition: clear.php:23
$_ERROR
$alivedata
Definition: alive.php:17
$jgamedata
Definition: alive.php:173
$gamestate
Definition: gameinfo.php:4
$gbinfo
Definition: gambling.php:7
gbsum($pdata)
Definition: alive.php:187
if(!$db->num_rows($result)) $udata
Definition: admin.php:27
$starttime
Definition: gameinfo.php:5
if(!$cuser||!$cpass) $result
Definition: admin.php:25
$cpass
Definition: common.inc.php:207
$areaadd
Definition: gamecfg_1.php:7
odds()
Definition: alive.php:198
$gamblingon
Definition: gamecfg_1.php:41
compatible_json_encode($data)