From 358f127b0c474ed809f3eb514870cc4e8012c6f5 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Mon, 26 Feb 2024 16:35:11 +0800 Subject: [PATCH] 1 --- webapp/bootstrap/constant.php | 1 + webapp/controller/BoxController.class.php | 2 +- webapp/mt/LootConfig.php | 24 +++ webapp/services/LootService.php | 212 ++++++++++++++++++++++ 4 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 webapp/mt/LootConfig.php create mode 100644 webapp/services/LootService.php diff --git a/webapp/bootstrap/constant.php b/webapp/bootstrap/constant.php index 15f1a9d0..609eee53 100644 --- a/webapp/bootstrap/constant.php +++ b/webapp/bootstrap/constant.php @@ -42,6 +42,7 @@ define('TN_TOTAL_RANK_NUM', 8015); define('TN_TOTAL_DIAMOND_CONSUME', 8016);//钻石消耗 define('TN_TOTAL_CEG_CONSUME', 8017);//ceg消耗 define('TN_TOTAL_GATHER_GOLD', 8018);//收集金币 +define('TN_TOTAL_LOOT_TIMES', 8019);//掉落包操作计数 0总计数 1循环计数 define('TN_DAILY_BEGIN', 9001); define('TN_DAILY_LOGINS', 9001); diff --git a/webapp/controller/BoxController.class.php b/webapp/controller/BoxController.class.php index 3c210125..c3e4b32a 100644 --- a/webapp/controller/BoxController.class.php +++ b/webapp/controller/BoxController.class.php @@ -14,7 +14,7 @@ require_once('models/Nft.php'); require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); require_once('services/LogService.php'); -require_once('services/NameService.php'); +require_once('services/LootService.php'); require_once('services/HashRateService.php'); require_once('services/TameBattleDataService.php'); require_once('services/AwardService.php'); diff --git a/webapp/mt/LootConfig.php b/webapp/mt/LootConfig.php new file mode 100644 index 00000000..017d4eb9 --- /dev/null +++ b/webapp/mt/LootConfig.php @@ -0,0 +1,24 @@ +_getV(TN_TOTAL_LOOT_TIMES,0); + $recycleTimes = myself()->_getV(TN_TOTAL_LOOT_TIMES,1); + $contentArr = explode("|",$lootMeta['content']); + $initTimes = $contentArr[0]; + $po = $contentArr[1]; + $pd = $contentArr[2]; + $pm = $contentArr[3]; + $index1 = $contentArr[4]; + $index2 = $contentArr[5]; + if ($totalTimes == 0){ + $recycleTimes = $initTimes; + } + $p = min($po + ($recycleTimes-1) * $pd,$pm) * 100 ; + $rnd = rand(1,100); + myself()->_incV(TN_TOTAL_LOOT_TIMES,0,1); + if ($rnd <= $p){ + myself()->_setV(TN_TOTAL_LOOT_TIMES,1,1); + return self::dropOutReward($index1); + }else{ + myself()->_incV(TN_TOTAL_LOOT_TIMES,1,1); + return self::dropOutReward($index2); + } + } + + private static function disposeDropContent3($lootMeta) { + $numPara = explode("|",$lootMeta['numPara']); + $items = array(); + $times = $numPara[0]; + $number = $numPara[1]; + $contentArr = explode("|",$lootMeta['content']); + for ($i=0;$i<$times;$i++){ + for ($j=0;$j<$number;$j++){ + self::randWeight2($contentArr,$items); + } + } + return $items; + } + + private static function randWeight2(&$contentArr,&$items){ + $totalWeight = 0; + foreach ($contentArr as $value){ + $contentArrEx = explode(":",$value); + $totalWeight += $contentArrEx[3]; + } + $rnd = rand() % $totalWeight; + $currWeight = 0; + foreach ($contentArr as $key=>$value){ + $contentArrEx = explode(":",$value); + $currWeight += $contentArrEx[3]; + if ($currWeight > $rnd){ + + switch ($contentArrEx[0]){ + case 1: { + array_push($items,array( + "item_id" => $contentArrEx[1], + "item_num" => $contentArrEx[2], + )); + } + break; + case 2: { + $rewards = self::dropOutReward($contentArrEx[1]); + $items = array_merge($items,$rewards); + } + break; + } + unset($contentArr[$key]); + break; + } + } + } + + private static function disposeDropContent2($lootMeta) { + $numPara = explode("|",$lootMeta['numPara']); + $items = array(); + $times = $numPara[0]; + $number = $numPara[1]; + for ($i=0;$i<$times;$i++){ + for ($j=0;$j<$number;$j++){ + $result = self::randWeight($lootMeta['content']); +// array_push($items,$result); + $items = array_merge($items,$result); + } + } + $hashItems = array(); + foreach ($items as $item){ + if (isset($hashItems[$item['item_id']])){ + $hashItems[$item['item_id']]['item_num'] += $item['item_num']; + }else{ + $hashItems[$item['item_id']] = $item; + } + } + $finalItems = array(); + foreach ($hashItems as $hashItem){ + array_push($finalItems,$hashItem); + } + return $finalItems; + } + + private static function randWeight($content){ + $contentArr = explode("|",$content); + $totalWeight = 0; + foreach ($contentArr as $value){ + $contentArrEx = explode(":",$value); + $totalWeight += $contentArrEx[3]; + } + $rnd = rand() % $totalWeight; + $currWeight = 0; + $items = array(); + foreach ($contentArr as $value){ + $contentArrEx = explode(":",$value); + $currWeight += $contentArrEx[3]; + if ($currWeight > $rnd){ + switch ($contentArrEx[0]){ + case 1: { + array_push($items,array( + "item_id" => $contentArrEx[1], + "item_num" => $contentArrEx[2], + )); + } + break; + case 2: { + $items = self::dropOutReward($contentArrEx[1]); + } + break; + } + break; + } + } + return $items; + } + + + private static function disposeDropContent1($lootMeta){ + $contentArr = explode("|",$lootMeta['content']); + $items = array(); + if (count($contentArr) > 0){ + foreach ($contentArr as $value){ + $contentArrEx = explode(":",$value); + switch ($contentArrEx[0]){ + case 1: { + array_push($items,array( + "item_id" => $contentArrEx[1], + "item_num" => $contentArrEx[2], + )); + } + break; + case 2: { + $rewards = self::dropOutReward($contentArrEx[1]); + $items = array_merge($items,$rewards); + } + break; + } + } + } + return $items; + } + +} \ No newline at end of file