This commit is contained in:
hujiabin 2024-02-26 16:35:11 +08:00
parent ddfc4280ee
commit 358f127b0c
4 changed files with 238 additions and 1 deletions

View File

@ -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);

View File

@ -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');

24
webapp/mt/LootConfig.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace mt;
class LootConfig
{
public static function find($id){
return getXVal(self::getMetaList(), $id, null);
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('lootConfig@lootConfig.php');
}
return self::$metaList;
}
protected static $metaList;
}

View File

@ -0,0 +1,212 @@
<?php
namespace services;
require_once('mt/LootConfig.php');
use mt;
class LootService
{
const EMPTY_DROP_TYPE = 1; //空掉落
const WHERE_DROP_TYPE = 2; //条件掉落
const ORDER_DROP_TYPE = 3; //有序全掉落
const HAVE_RAND_DROP_TYPE = 4; //有放回随机掉落
const NOT_HAVE_RAND_DROP_TYPE = 5; //无放回随机掉落
const DYN_RAND_DROP_TYPE = 6; //动态概率掉落
const STEP_RAND_DROP_TYPE = 7; //步长随机掉落
public static function dropOutReward($dropIndex){
$lootMeta = mt\LootConfig::find($dropIndex);
if (! $lootMeta){
return ;
}
$items = array();
switch ($lootMeta['method']){
// case self::EMPTY_DROP_TYPE: {
//
// }
// break;
case self::WHERE_DROP_TYPE: {
//暂定
}
break;
case self::ORDER_DROP_TYPE: {
$items = self::disposeDropContent1($lootMeta);
}
break;
case self::HAVE_RAND_DROP_TYPE: {
$items = self::disposeDropContent2($lootMeta);
}
case self::NOT_HAVE_RAND_DROP_TYPE: {
$items = self::disposeDropContent3($lootMeta);
}
break;
case self::DYN_RAND_DROP_TYPE: {
$items = self::disposeDropContent4($lootMeta);
}
break;
}
return $items;
}
private static function disposeDropContent4($lootMeta) {
$totalTimes = myself()->_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;
}
}