PVE结算

This commit is contained in:
hujiabin 2023-03-24 16:41:24 +08:00
parent 46499846a8
commit 88172383cb
3 changed files with 170 additions and 10 deletions

View File

@ -127,7 +127,9 @@ class BattleSettlement extends BaseModel
'battle_uuid' => $battleUuid,
'room_uuid' => $roomUuid,
),
array(),
array(
'data' => json_encode($data)
),
array(
'battle_uuid' => $battleUuid,
'room_uuid' => $roomUuid,

View File

@ -10,15 +10,18 @@ class LevelUp
$meta = self::getMetaList();
if ($exp > 0){
for ($i=1;$i<=count($meta);$i++){
if ($exp > $meta[count($meta)]['total_exp']){
if ($exp >= $meta[count($meta)]['total_exp']){
$exp = min($exp, $meta[count($meta)]['total_exp']);
$lv = $meta[count($meta)]['id'];
}else{
if ($exp >= $meta[$i]['total_exp'] &&
$exp < $meta[$i+1]['total_exp'])
{
$lv = $meta[$i]['id'];
if ($meta[$i+1]){
if ($exp >= $meta[$i]['total_exp'] &&
$exp < $meta[$i+1]['total_exp'])
{
$lv = $meta[$i]['id'];
}
}
}
}
}

View File

@ -59,8 +59,10 @@ use services\FormulaService;
use services\LogService;
class TameBattleDataService extends BaseService {
const MAX_DROP_NUM = 2;
const ROOM_MODE_PVP = 0;
// const MATCH_MODE_MATCH = 1;
const ROOM_MODE_PVE = 1;
const MATCH_MODE_PVP = 0;
@ -72,6 +74,7 @@ class TameBattleDataService extends BaseService {
public $teamList = array();
private $userInfo = array();
private $heroDto = array();
private $pveGeminiMeta = null;
private $reward = array(
'hero' => array(
@ -140,11 +143,10 @@ class TameBattleDataService extends BaseService {
//PVE模式
case self::ROOM_MODE_PVE:
{
return;
//pve
$this->updatePveData();
if ($this->pveGeminiMeta &&
$this->pveGeminiModeMeta) {
if ($this->pveGeminiMeta ) {
$this->rewardFragmentPve();
}
myself()->_incDailyV(TN_DAILY_PVE_BATTLE_TIMES, 0, 1);
@ -158,6 +160,158 @@ class TameBattleDataService extends BaseService {
}
private function updatePveData()
{
error_log('updatePveData');
$instanceId = getXVal($this->allInfo,'pve_instance_id', 0);
$pveRankScore = getXVal($this->battleInfo,'pve_score', 0);
$pveBossKilled = getXVal($this->battleInfo,'pve_boss_killed', 0);
$userInfo = myself()->_getOrmUserInfo();
$this->pveGeminiMeta = mt\PveGemini::get($instanceId);
if ($this->pveGeminiMeta) {
if (!(
$instanceId == mt\PveGemini::FIRST_INSTANCE_ID ||
$userInfo['pve_instance_id'] == $instanceId ||
$userInfo['pve_instance_id'] + 1 == $instanceId)
) {
$this->pveGeminiMeta = null;
}
}
// $this->pveGeminiModeMeta = mt\PveGeminiMode::get($instanceMode);
// if ($this->pveGeminiModeMeta) {
// $this->instanceRank = mt\PveGeminiMode::calcStar($this->pveGeminiModeMeta, $pveRankScore);
// }
if ($pveBossKilled == 1) {
if ($this->pveGeminiMeta) {
myself()->_updateUserInfo(array(
'pve_instance_id' => $instanceId
));
}
}
}
private function rewardFragmentPve()
{
error_log('rewardFragmentPve');
$bossReward = getXVal($this->battleInfo,'pve_boss_killed', 0) ? 1 : 0;
if ( !$bossReward) {
return;
}
$dropRate = $this->pveGeminiMeta['drop_rate'];
$todayPveGetHeroFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_HERO_FRAGMENT_NUM, 0);
$todayPveGetGunFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_GUN_FRAGMENT_NUM, 0);
$reward = array();
if ($todayPveGetHeroFragmentNum < self::MAX_DROP_NUM) {
$gamesNum = FragmentRecord::getGamesNum(FragmentRecord::HERO_FRAGMENT);
$rate = $dropRate*($gamesNum+1);
if (rand(1,100) < $rate*100){
$dropHeroFragmentId = $this->randWeight2(1);
$this->drop($reward,$dropHeroFragmentId,1);
FragmentRecord::upsertGamesNum(FragmentRecord::HERO_FRAGMENT,0);
}else{
FragmentRecord::upsertGamesNum(FragmentRecord::HERO_FRAGMENT,$gamesNum+1);
}
}
if ($todayPveGetGunFragmentNum < self::MAX_DROP_NUM) {
$gamesNum = FragmentRecord::getGamesNum(FragmentRecord::GUN_FRAGMENT);
$rate = $dropRate*($gamesNum+1);
if (rand(1,100) < $rate*100){
$dropGunFragmentId = $this->randWeight2(2);
$this->drop($reward,$dropGunFragmentId,2);
FragmentRecord::upsertGamesNum(FragmentRecord::GUN_FRAGMENT,0);
}else{
FragmentRecord::upsertGamesNum(FragmentRecord::GUN_FRAGMENT,$gamesNum+1);
}
}
if ($reward){
//记录获得得碎片奖励
$battle_uuid = getXVal($this->allInfo,'battle_uuid', 0);
$room_uuid = getXVal($this->allInfo,'room_uuid', 0);
$db = BattleSettlement::findTeam($battle_uuid,$room_uuid);
if ($db){
$data = emptyReplace(json_decode($db['data'], true), array());
if ($data){
foreach ($data['members'] as &$member){
if ($member['account_id'] == myself()->_getAccountId()){
$member['reward']['items'] = $reward;
}
}
}
BattleSettlement::addTeam($battle_uuid,$room_uuid,$data);
}
}
}
private function randWeight2($type){
$itemMeta = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
$heroFragment = array();
$gunFragment = array();
foreach ($itemMeta as $meta){
if ($meta['sub_type'] == 3 || $meta['sub_type'] == 1){
array_push($heroFragment,$meta['id']);
}
if ($meta['sub_type'] == 4 || $meta['sub_type'] == 2){
array_push($gunFragment,$meta['id']);
}
}
$weightRate = array(
array(0,4),
array(1,12),
array(2,12),
array(3,12),
array(4,12),
array(5,12),
array(6,12),
array(7,12),
array(8,12),
);
$weight = 0;
$tempData = array ();
foreach ($weightRate as $one) {
$weight += $one[1];
for ($i = 0; $i < $one[1]; $i++) {
$tempData[] = $one;
}
}
$key = $tempData[rand(0, $weight -1)][0];
switch ($type){
case 1:return $heroFragment[$key];
case 2:return $gunFragment[$key];
default:return null;
}
}
private function drop(&$reward,$itemId,$type){
$itemMeta = mt\Item::get($itemId);
if ($itemMeta){
$propertyChgService = new services\PropertyChgService();
$awardService = new services\AwardService();
array_push($reward,
array(
'item_id' => $itemId,
'item_num' => 1
));
myself()->_addItems(
array(
array(
'item_id' => $itemId,
'item_num' => 1
)),
$awardService,
$propertyChgService
);
switch ($type){
case 1:myself()->_incDailyV(TN_DAILY_PVE_GET_HERO_FRAGMENT_NUM, 0, 1);break;
case 2:myself()->_incDailyV(TN_DAILY_PVE_GET_GUN_FRAGMENT_NUM, 0, 1);break;
}
}
}
private function updatePvpData()
{
@ -393,6 +547,7 @@ class TameBattleDataService extends BaseService {
case self::ROOM_MODE_PVE:
{
//pve 奖励碎片
// print_r($data);die;
}
break;
default:{}