Ejemplo n.º 1
0
 public function resetpop($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     $ret['bshopnum'] = $tu->numch(TT::SHOP_NUM, 0);
     $ret['ashopnum'] = $tu->numch(TT::SHOP_NUM, 0 - $ret['bshopnum']);
     /*
     $ret['bpop'] = $tu->numch( TT::POPU,0 );
     $ret['apop'] = $tu->numch( TT::POPU,0-$ret['bpop'] );
     */
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * 达成成就
  * @param $params
  *  require    u      --  userid
  *             tag    --  成就种类,对应xml的id
  * @return
  *   s                --  OK,others fail
  */
 public function finish($params)
 {
     $uid = $params['u'];
     $tag = $params['tag'];
     $tu = new TTUser($uid);
     $id = $tu->getoid('achieves', TT::OTHER_GROUP);
     $achieves = $tu->getbyid($id);
     if ($achieves[$tag]) {
         $ret['s'] = 'repeat';
         return $ret;
     }
     $config = AchieveConfig::getAchieve($tag);
     $count = $tu->getf($config['group']);
     if ($count < $config['aimNum']) {
         //检验是否真的完成
         $ret['s'] = 'unfinish';
         return $ret;
     }
     $achieves[$tag] = time();
     $money = $tu->chMoney($config['rewardMoney']);
     $exp = $tu->numch('exp', $config['rewardRep']);
     if ($config['item']) {
         //成就达成的物品奖励
     }
     $achieves['id'] = $id;
     //		$ret['b'] = $achieves;
     $tu->puto($achieves);
     $ret['a'] = $tu->getbyid($id);
     $ret['s'] = 'OK';
     return $ret;
 }
Ejemplo n.º 3
0
            break;
        }
    }
} else {
    if (!is_array($ids)) {
        $ids = array();
    }
    if (array_key_exists($touser, $ids)) {
        $invite = true;
    }
    if (array_key_exists($touser, $getted)) {
        $got = true;
    }
}
if ($invite && $new == 1 && !$gemd && !$ut && !$got) {
    $ftu->numch('invite_num', 1);
    $cid = $ftu->getoid('copilot', TT::OTHER_GROUP);
    $copilot = $ftu->getbyid($cid);
    $copilot['id'] = $cid;
    $copilot['bag'][2004] += 1;
    $ftu->puto($copilot);
    $tsess['gemd'] = 1;
    TTGenid::update($tsess, $tsess['id']);
}
if ($invite) {
    $gid = $link['gift'];
    if ($gid) {
        ?>
		<div id='content'>
	<div class='container'>
        <div class='canvas'>
Ejemplo n.º 4
0
 /**
  * 进货
  * @param $params
  * require  u           -- user_id
  * require  c           -- the car to be lold
  *                      id         -- id of the car
  *                      goodsTag   -- goods type the car can load
  * @return
  *          s           -- OK
  *          c           -- car status
  */
 public function go_goods($params)
 {
     $uid = $params['u'];
     $goodsTag = $params['c']['goodsTag'];
     $cid = $params['c']['id'];
     $tu = new TTUser($uid);
     $car_obj = $tu->getbyid($cid);
     if (!$car_obj) {
         $ret['s'] = 'notexist';
         return $ret;
     }
     if ($car_obj['t']) {
         $ret['s'] = 'doing';
         return $ret;
     }
     $car = ItemConfig::getItem($car_obj['tag']);
     if (!$car) {
         $ret['s'] = 'caritemnotexist';
         return $ret;
     }
     $goods = ItemConfig::getItem($goodsTag);
     if (!$goods) {
         $ret['s'] = 'goodsitemnotexist';
         return $ret;
     }
     $buy_ret = $tu->buyItem($goods['tag'], $car['goodsNumber']);
     if ($buy_ret['s'] != 'OK') {
         return $buy_ret;
     }
     $add_exp = $goods['exp'] * $car['goodsNumber'];
     if ($add_exp) {
         $tu->addExp($add_exp);
     }
     $now = time();
     $car_obj['goodsTag'] = $goodsTag;
     $car_obj['t'] = $now;
     $tu->puto($car_obj, TT::CAR_GROUP);
     $gogoods_count = $tu->numch('gogoods_count', 1);
     $ret['s'] = 'OK';
     $params['c']['t'] = $now;
     $ret['c'] = $params['c'];
     //		$ret['c'] = $car_obj;
     return $ret;
 }
Ejemplo n.º 5
0
 /**
          * update
 * @param $params
 *  require u        -- user 
 *          type     -- 满足type
 * @return 
 *  s   -- OK ,or other fail
                    max,超出限制
                    notype,超出限制
          *  money  -- total money
          *  exp    -- total exp 
 *  award 
                  money
                  exp
 *  d   --新的对象
 */
 public function satisfy($params)
 {
     static $type2award = array(1 => array('money' => 10, 'exp' => 2));
     $uid = $params['u'];
     $type = $params['type'];
     $award = $type2award[$type];
     //$type  = 1;
     if (!$award) {
         $ret['s'] = 'notype';
         return $ret;
     }
     $tu = new TTUser($uid);
     $id = $tu->getoid('satisfy', TT::OTHER_GROUP);
     $data = $tu->getbyid($id);
     $data['id'] = $id;
     $now = time();
     $now_date = date('Ymd', $now);
     if ($data['date'] != $now_date) {
         $data['r'] = array();
         $data['date'] = $now_date;
     }
     if (++$data['r'][$type] > 10) {
         $ret['s'] = 'max';
         return $ret;
     }
     $ret['award'] = $award;
     foreach ($award as $k => $v) {
         $ret[$k] = $tu->numch($k, $v);
     }
     $ret['d'] = $data;
     $ret['s'] = 'OK';
     $tu->puto($data, '', false);
     return $ret;
 }
Ejemplo n.º 6
0
 /**
  * 卖出
  * @param $data (对应数据库的一条记录)
  * @param $num
  * @return 
  */
 public function saleItem(&$data, $num = 1)
 {
     $tag = $data['tag'];
     $stat['tag'] = $tag;
     $stat['num'] = $num;
     $stat['u'] = $this->_u;
     $stat['op'] = 'sale';
     $stat['tm'] = $_SERVER['REQUEST_TIME'];
     $gemt = TT::GemTT();
     $item = ItemConfig::getItem($tag);
     if (!$item || !isset($item['tag'])) {
         $ret['s'] = 'notfind';
         $stat['s'] = $ret['s'];
         $gemt->putKeep(null, $stat);
         return $ret;
     }
     if ($item['onlygem'] == 'true') {
         //对用宝石购买的物品,按1:10000换成金币再3折
         $num = $item['gem'] * 3000;
     } else {
         if ($item['group'] == 'g') {
             $num = $item['sellmoney'] * $item['unitcout'] * 0.3;
         } else {
             $num = $item['money'] * 0.3;
         }
     }
     $rnum = $this->numch(TT::MONEY_STAT, $num);
     $tusys = new TTUser(0);
     $statid = 'usalenum_' . $item['tag'];
     $saled = $tusys->numch($statid, $num);
     //记录系统回购每种商品总数
     $ret['s'] = 'OK';
     $ret['money'] = $rnum;
     $stat['money'] = $cnum;
     $stat['t'] = 'money';
     $stat['s'] = $ret['s'];
     $gemt->putKeep(null, $stat);
     return $ret;
 }
Ejemplo n.º 7
0
 /**
  * 结算卖货
  * @param $params use shop
  *   u   - userid
  *   sids  - shop ids
  * @return 
  *   s  - OK,noneed(短期内没有需要结算的商品),busy(太快)
  *   income  - 获得金币
  *   money   - 总金币
  *   selloutids - 卖完删除的id
  *   goods   --数量有辩护的商品列表
  */
 public static function shop_checkout($params)
 {
     $uid = $params['u'];
     $sids = $params['sids'];
     $now = $params['now'];
     if (!$now) {
         $now = time();
     }
     $tu = new TTUser($uid);
     //获取人气和宣传值
     $shops = $tu->get(TT::SHOP_GROUP);
     foreach ($shops as $shop) {
         if ($shop['pos'] != 's') {
             $item = ItemConfig::getItem($shop['tag']);
             @asort($shop['goods']);
             $gids = @array_keys($shop['goods']);
             if ($gids) {
                 $gs = $tu->getbyids($gids);
                 if ($gs['g']) {
                     $condata[$shop['id']]['sconfig'] = $item;
                     $condata[$shop['id']]['shop'] = $shop;
                     $condata[$shop['id']]['goods'] =& $gs['g'];
                     $total_width += $item['gridWidth'];
                 } else {
                     unset($shop['goods']);
                     //=array();
                     $tu->puto($shop);
                 }
             }
         }
     }
     if (!$condata || !$total_width) {
         $ret['s'] = 'OK';
         $ret['msg'] = 'nogoods';
         return $ret;
     }
     $params = $tu->getf(array(TT::POPU, TT::EXP_STAT));
     $popu = $params[TT::POPU];
     $ua = UpgradeConfig::getUpgradeNeed($params['exp']);
     $maxpopu = $ua['maxpopu'];
     $aid = $tu->getoid('advert', TT::OTHER_GROUP);
     $adv = $tu->getbyid($aid);
     $used_advert = $adv['use'];
     if (!$used_advert) {
         $used_advert = array();
     }
     //处理广告
     foreach ($used_advert as $k => $v) {
         $adv = AdvertConfig::getAdvert($tag);
         if ($start + $adv['allTime'] < $now) {
             continue;
         }
         $savead[$k] = $v;
     }
     if ($savead) {
         $adv['use'] = $savead;
         $tu->puto($adv);
     } else {
         if ($used_advert) {
             unset($adv['use']);
             $tu->puto($adv);
         }
     }
     $selloutids = array();
     $income = 0;
     $sale_count = 0;
     //销售份数
     $popu += 15 * $total_width;
     foreach ($condata as $s => $vvv) {
         $sconfig =& $vvv['sconfig'];
         $gs =& $vvv['goods'];
         $shop =& $vvv['shop'];
         $curtime = $shop['ctime'];
         //可以售卖新商品时间
         $cgoods = array();
         $shop_changed = false;
         foreach ($gs as $t => $g) {
             $gconfig = ItemConfig::getItem($g['tag']);
             if (!$gconfig) {
                 continue;
             }
             $ctime = $g['ctime'];
             //上次结算时间
             if ($curtime < $t) {
                 $curtime = $t;
             }
             //上架时间
             if ($curtime < $ctime) {
                 $curtime = $ctime;
             }
             if ($curtime < $g['stime']) {
                 $curtime = $g['stime'];
             }
             $gaps = self::getTimeRates($used_advert, $curtime, $now, $popu, $maxpopu, $total_width);
             foreach ($gaps as $k => $gr) {
                 //测试信息需要该索引值
                 //$snum = floor( $gr[0]/$gconfig['selltime']*$gr[1] );
                 $pertime = $gr[0] / $gconfig['selltime'] * $gr[1] * $sconfig['gridWidth'];
                 $snum = floor($gr[0] / $pertime);
                 if ($snum >= $g['num']) {
                     //卖完了
                     $asnum = $g['num'];
                 } else {
                     $asnum = $snum;
                 }
                 if ($asnum == 0) {
                     break;
                 }
                 $ret['sell'][$g['tag']] += $asnum;
                 $sale_count += $asnum;
                 //记录销售份数,成就用
                 $income += $asnum * $gconfig['sellmoney'];
                 //sellmoney是单份物品的卖价
                 $g['num'] -= $asnum;
                 $curtime += floor($asnum * $pertime);
                 //
                 $shop_changed = true;
                 $shop['ctime'] = $curtime;
                 $g['ctime'] = $curtime;
                 if ($g['num'] == 0) {
                     //当前时间段卖光此箱货物,继续卖下一个货物
                     $cgoods[] = $g;
                     $selloutids[] = $g['id'];
                     unset($shop['goods'][$g['id']]);
                     break;
                     //跳出时间段循环,继续卖同一商店下一个上架时间的货物(在同一商店,同一时间上架但售卖顺序不同的货物,已在上架时微调成不同上架时间)
                 }
             }
             //foreach group
             if ($g['num'] != 0) {
                 $tu->puto($g, TT::GOODS_GROUP);
                 break;
                 //跳出上架时间循环,但是继续店铺循环,终止同一店铺的货物队列中其他货物的结算
             }
         }
         //foreach goods
         if ($shop_changed) {
             $tu->puto($shop);
         }
     }
     //foreach shop
     //总销售份数
     $now_sale_count = $tu->numch('total_count', $sale_count);
     //总销售额
     $now_total_sale = $tu->numch('total_sale', $income);
     //记录玩家每一种物品卖出量
     if ($ret['sell']) {
         foreach ($ret['sell'] as $gid => $num) {
             $tu->numch("sale_goods_{$gid}", $num);
         }
     }
     $ret['s'] = 'OK';
     $ret['income'] = $income;
     $ret['money'] = $tu->chMoney($income);
     $ret['t'] = $now;
     $ret['rids'] = $selloutids;
     $ret['u'] = $uid;
     TTLog::record(array('m' => __METHOD__, 'u' => $uid, 'tm' => $_SERVER['REQUEST_TIME'], 'p' => json_encode($ret)));
     $tu->remove($selloutids);
     return $ret;
 }
Ejemplo n.º 8
0
<?php

echo "<pre>\n";
require_once '../base.php';
$u = $argv[1];
if (!$u) {
    $u = $_REQUEST['u'];
}
if (!$u) {
    $pid = $argv[2];
    if (!$pid) {
        $pid = $_REQUEST['pid'];
    }
    if (!$pid) {
        $pid = $_COOKIE['user_name'];
    }
    if (!$pid) {
        die("no param");
    }
    $data = TTGenid::getbypid($pid);
} else {
    $data = TTGenid::getbyid($u);
}
$u = $data['id'];
if (!$u) {
    die("no u get");
}
$tu = new TTUser($u);
$tu->numch('money', 100000);
$tu->numch('gem', 500);
echo "OK\n";
Ejemplo n.º 9
0
 /**
  * 完成任务
  *   
  * @param $params
  *  require   u       --  uid
  *            tag     --  任务id
  *            rids     -- 消耗物品ids(只能是空闲物品)
  *            minus  (money=>11,gem=>122)
  * @return 
  *            s       --  OK,正常
  *            award    --  和新手等一致
  *                        finished,该任务不存在
  */
 public function finish($params)
 {
     $uid = $params['u'];
     $tag = $params['tag'];
     //判断用户是否正在任务中
     $tu = new TTUser($uid);
     $tid = $tu->getoid($tag, 'to');
     $to = $tu->getbyid($tid);
     if (!$to) {
         //	$ret['s']='no';
         //	return $ret;
         $to['id'] = $tid;
     }
     if ($to['s'] == 'finished') {
         $ret['s'] = 'finished';
         return $ret;
     }
     $conf = self::getConf($tag);
     $d = $conf['award'];
     if ($d) {
         foreach ($d as $k => $v) {
             $tu->numch($k, $v);
             $award[$k] = $v;
         }
     }
     $d = $params['minus'];
     if ($d) {
         foreach ($d as $k => $v) {
             $tu->numch($k, -$v);
         }
     }
     $items = $conf['items'];
     if ($items) {
         foreach ($items as $item) {
             $num = $item['num'];
             unset($item['num']);
             $iconf = ItemConfig::getItem($item['tag']);
             $g = $iconf['group'];
             if (!$g) {
                 $g = 'o';
             }
             if (!$num) {
                 $num = 1;
             }
             for ($i = 0; $i < $num; $i++) {
                 $item['pos'] = 's';
                 $item['id'] = $tu->getoid(null, $g);
                 $tu->puto($item);
                 $award['items'][] = $item;
             }
         }
     }
     $rids = $params['rids'];
     if ($rids) {
         $tu->remove($rids);
     }
     $ret['award'] = $award;
     $to['id'] = $tid;
     $to['s'] = 'finished';
     $to['ut'] = time();
     $tu->puto($to);
     $ret['s'] = 'OK';
     return $ret;
 }
Ejemplo n.º 10
0
 /**
  * 卖出
  * @param $params
  *  require u  -- user id
  *  require d  -- item_id 数组
  *     
  * @return 
  *  s   -- OK ,or other fail
  *                                     notexsit ,不存在配置
  *                                     notsale ,不能购买的物品
  *                                     level,等级未到 
  *                                     achive, 所需成就buy_need_achiveid 未达成 
  *                                     task,所需任务未达成
  *                                     buynumlimit,限量版已经卖完
  *                                     money,
  *				      gem
  */
 public function sale($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     if ($tu->check_dup($params['_cid'], $ret)) {
         return $ret;
     }
     foreach ($params['d'] as $index => $id) {
         $item_obj = $tu->getbyid($id);
         if (!$item_obj) {
             $ret['s'] = 'notexsit';
             $ret['index'] = $index;
             return $ret;
         }
         $item = ItemConfig::getItem($item_obj['tag']);
         if (!$item) {
             $ret['s'] = 'notexsit';
             $ret['index'] = $index;
             return $ret;
         }
         $sale_ret = $tu->saleItem($item_obj);
         if ($sale_ret['s'] != 'OK') {
             $sale_ret['index'] = $index;
             return $sale_ret;
         }
         if ($item_obj['pos'] != 's') {
             $pop -= $item['pop'];
         }
     }
     if ($pop) {
         $tu->numch(TT::POPU, $pop);
     }
     $tu->remove($params['d']);
     $ret['s'] = 'OK';
     return $ret;
 }
Ejemplo n.º 11
0
 /**
  * 金手指
  * @param $params
  *   require  u               -- 玩家id
  *            money           -- 增加金币数
  *            gem             -- 增加宝石数
  *            exp             -- 增加经验数
  * @return 
  *            s         --  OK
  */
 public function cheat($params)
 {
     $uid = $params['u'];
     $tu = new TTUser($uid);
     $tu->chMoney($params['money']);
     $tu->numch(TT::GEM_STAT, $params['gem']);
     //		$tu->numch( TT::EXP_STAT,$params['exp'] );
     $tu->addExp($params['exp']);
     $ret['a'] = $tu->getf(array(TT::MONEY_STAT, TT::GEM_STAT, TT::EXP_STAT));
     $ret['s'] = 'OK';
     return $ret;
 }
Ejemplo n.º 12
0
    $data = TTGenid::getbyid($u);
}
if (!$data || !$data['id']) {
    echo "<p>查找用户</p>";
    echo "<p><form method='get'>PID: <input name='pid' type='text' /><input type='submit' value='获取用户' /> </form></p>";
} else {
    $u = $data['id'];
    $name = $data['name'];
    if (!$u) {
        die("no u get");
    }
    $tu = new TTUser($u);
    echo "<p><a href='add_user_money.php'>换个用户</a>&nbsp&nbsp;&nbsp;<a target='_blank' href='get_user.php?u=" . $u . "'>用户信息</a><p>";
    echo "<p>" . $name . "</p>";
    if ($_POST['money'] !== null && $_POST['gem'] !== null && $_POST['money'] >= 0 && $_POST['gem'] >= 0 && $_POST['money'] <= 1000000000 && $_POST['gem'] <= 1000) {
        $tu->numch('money', $_POST['money']);
        $tu->numch('gem', $_POST['gem']);
        echo "<p>OK,  <a target='_blank' href='http://msg.renren.com/SendMessage.do?id=" . $data['pid'] . "'>发送站内信通知" . $name . "</a></p>";
    } else {
        echo "<p>输入要加的金币和宝石数</p>";
        echo "<form method='post'>";
        echo "<p>金币: <input name='money' value='0' type='text' /></p>";
        echo "<p>宝石: <input name='gem' value='0' type='text' /></p>";
        echo "<p><input type='submit' value='确定'/></p></form>";
    }
    echo "<p>现有金币" . $tu->chMoney(0) . ",宝石" . $tu->chGem(0) . "</p><br/><br/>";
}
?>
</body>
</html>