236 lines
8.5 KiB
PHP
236 lines
8.5 KiB
PHP
<?php
|
|
|
|
|
|
namespace services;
|
|
|
|
require_once('mt/LootConfig.php');
|
|
require_once('mt/ServerTaskTime.php');
|
|
require_once('models/ServerTaskBattleCount.php');
|
|
require_once('models/Hero.php');
|
|
|
|
use models\ServerTaskBattleCount;
|
|
use models\Hero;
|
|
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 dropOutItem($dropIndex){
|
|
$items = array();
|
|
$depth = 0;
|
|
self::disposeLootIndex($dropIndex,$depth,$items);
|
|
// $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;
|
|
return myself()->_mergeAlikeItemKey($items);
|
|
}
|
|
|
|
private static function disposeLootIndex($dropIndex,&$depth,&$items){
|
|
$lootMeta = mt\LootConfig::find($dropIndex);
|
|
if (! $lootMeta){
|
|
return ;
|
|
}
|
|
$depth++;
|
|
if ($depth > 10){
|
|
error_log("An endless loop occurs in the program. Terminate the program");
|
|
return ;
|
|
}
|
|
if ($lootMeta['isAffected']){
|
|
$lucky = Hero::getAccountLuckyTemp();
|
|
$luckyParam = \mt\Parameter::getVal('economy_account_luck_K',0);
|
|
$rangeArr = explode("|",\mt\Parameter::getVal('economy_account_luck_range',0));
|
|
$rate = ($rangeArr[1]-$rangeArr[0]) * $lucky/($lucky+$luckyParam) + $rangeArr[0];
|
|
$rnd = rand() / (mt_getrandmax() + 1);
|
|
if ($rnd <= $rate){
|
|
self::doMethod($lootMeta,$depth,$items);
|
|
}
|
|
}else{
|
|
self::doMethod($lootMeta,$depth,$items);
|
|
}
|
|
|
|
}
|
|
|
|
private static function doMethod($lootMeta,&$depth,&$items){
|
|
switch ($lootMeta['method']){
|
|
// case self::EMPTY_DROP_TYPE: {
|
|
//
|
|
// }
|
|
// break;
|
|
case self::WHERE_DROP_TYPE: {
|
|
//暂定
|
|
}
|
|
break;
|
|
case self::ORDER_DROP_TYPE: {
|
|
self::disposeDropContent1($lootMeta,$depth,$items);
|
|
}
|
|
break;
|
|
case self::HAVE_RAND_DROP_TYPE: {
|
|
self::disposeDropContent2($lootMeta,$depth,$items);
|
|
}
|
|
break;
|
|
case self::NOT_HAVE_RAND_DROP_TYPE: {
|
|
self::disposeDropContent3($lootMeta,$depth,$items);
|
|
}
|
|
break;
|
|
case self::DYN_RAND_DROP_TYPE: {
|
|
self::disposeDropContent4($lootMeta,$depth,$items);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static function disposeDropContent4($lootMeta,&$depth,&$items) {
|
|
// $serverTaskMeta = mt\ServerTaskTime::getCurrentTime();
|
|
// $period = $serverTaskMeta?$serverTaskMeta['id']:0;
|
|
|
|
$totalTimes = myself()->_getV(TN_TOTAL_LOOT_TIMES,0);
|
|
// $totalTimes = ServerTaskBattleCount::getV($period,$lootMeta['id'],ServerTaskBattleCount::TOTAL_COUNT);
|
|
$recycleTimes = myself()->_getV(TN_TOTAL_LOOT_TIMES,1);
|
|
// $recycleTimes = ServerTaskBattleCount::getV(0,$lootMeta['id'],ServerTaskBattleCount::LOOP_COUNT);
|
|
$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);
|
|
// ServerTaskBattleCount::incV($period,$lootMeta['id'],ServerTaskBattleCount::TOTAL_COUNT,1);
|
|
if ($rnd <= $p){
|
|
myself()->_setV(TN_TOTAL_LOOT_TIMES,1,1);
|
|
// ServerTaskBattleCount::setV(0,$lootMeta['id'],ServerTaskBattleCount::LOOP_COUNT,1);
|
|
self::disposeLootIndex($index1,$depth,$items);
|
|
}else{
|
|
myself()->_incV(TN_TOTAL_LOOT_TIMES,1,1);
|
|
// ServerTaskBattleCount::incV(0,$lootMeta['id'],ServerTaskBattleCount::LOOP_COUNT,1);
|
|
self::disposeLootIndex($index2,$depth,$items);
|
|
}
|
|
}
|
|
|
|
private static function disposeDropContent3($lootMeta,&$depth,&$items) {
|
|
$numPara = explode("|",$lootMeta['numPara']);
|
|
$times = $numPara[0];
|
|
$number = $numPara[1];
|
|
$contentArr = explode("|",$lootMeta['content']);
|
|
for ($i=0;$i<$times*$number;$i++){
|
|
self::randWeight2($contentArr,$depth,$items);
|
|
}
|
|
}
|
|
|
|
private static function randWeight2(&$contentArr,&$depth,&$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: {
|
|
self::disposeLootIndex($contentArrEx[1],$depth,$items);
|
|
}
|
|
break;
|
|
}
|
|
unset($contentArr[$key]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static function disposeDropContent2($lootMeta,&$depth,&$items) {
|
|
$numPara = explode("|",$lootMeta['numPara']);
|
|
$times = $numPara[0];
|
|
$number = $numPara[1];
|
|
for ($i=0;$i<$times*$number;$i++){
|
|
self::randWeight($lootMeta['content'],$depth,$items);
|
|
}
|
|
}
|
|
|
|
private static function randWeight($content,&$depth,&$items){
|
|
$contentArr = explode("|",$content);
|
|
$totalWeight = 0;
|
|
foreach ($contentArr as $value){
|
|
$contentArrEx = explode(":",$value);
|
|
$totalWeight += $contentArrEx[3];
|
|
}
|
|
$rnd = rand() % $totalWeight;
|
|
$currWeight = 0;
|
|
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: {
|
|
self::disposeLootIndex($contentArrEx[1],$depth,$items);
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private static function disposeDropContent1($lootMeta,&$depth,&$items){
|
|
$contentArr = explode("|",$lootMeta['content']);
|
|
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: {
|
|
self::disposeLootIndex($contentArrEx[1],$depth,$items);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} |