修改组队功能

This commit is contained in:
hujiabin 2023-03-15 16:21:16 +08:00
parent a524e73546
commit 05a5ef3db7
6 changed files with 375 additions and 113 deletions

View File

@ -145,5 +145,62 @@ class Team(object):
'response': [
_common.RspHead(),
]
},{
'name': 'doReady',
'desc': '准备/取消',
'group': 'Team',
'url': 'webapp/index.php?c=Team&a=doReady',
'params': [
_common.ReqHead(),
['team_uuid', '', '队伍唯一id'],
['ready_state', 0, '1准备 0取消'],
],
'response': [
_common.RspHead(),
]
},{
'name': 'setHero',
'desc': '设置出战英雄',
'group': 'Team',
'url': 'webapp/index.php?c=Team&a=setHero',
'params': [
_common.ReqHead(),
['team_uuid', '', '队伍唯一id'],
['hero_uid', 0, '英雄uniid'],
],
'response': [
_common.RspHead(),
]
},{
'name': 'setPreset',
'desc': '设置备战',
'group': 'Team',
'url': 'webapp/index.php?c=Team&a=setPreset',
'params': [
_common.ReqHead(),
['team_uuid', '', '队伍唯一id'],
['hero_uid', 0, '英雄uniid'],
['chip_page', 0, '铭文页id'],
['skill_id', 0, '技能item id'],
['weapon_uid1', 0, '枪1uniid'],
['weapon_uid2', 0, '枪2uniid'],
],
'response': [
_common.RspHead(),
]
},{
'name': 'setHeroSkin',
'desc': '设置英雄皮肤',
'group': 'Team',
'url': 'webapp/index.php?c=Team&a=setHeroSkin',
'params': [
_common.ReqHead(),
['team_uuid', '', '队伍唯一id'],
['hero_uid', 0, '英雄uniid'],
['skin_id', 0, '皮肤item id'],
],
'response': [
_common.RspHead(),
]
},
]

View File

@ -1,41 +1,30 @@
<?php
require_once('mt/Shop.php');
require_once('mt/Hero.php');
require_once('mt/Item.php');
require_once('mt/HeroLevel.php');
require_once('mt/HeroLevelAttr.php');
require_once('mt/HeroQuality.php');
require_once('mt/AttrHelper.php');
require_once('mt/Parameter.php');
require_once('mt/SkillCommon.php');
require_once('mt/Skill.php');
require_once('models/Hero.php');
require_once('models/Bag.php');
require_once('models/HeroSkin.php');
require_once('models/Nft.php');
require_once('models/NftUpReceive.php');
require_once('models/Transaction.php');
require_once('models/ChipPage.php');
require_once('models/Gun.php');
require_once('models/HeroPreset.php');
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
require_once('services/RankActivityService.php');
require_once('services/LogService.php');
use phpcommon\SqlHelper;
use models\Hero;
use models\Bag;
use models\HeroSkin;
use models\ChipPage;
use models\Gun;
use models\Nft;
use models\NftUpReceive;
use models\Transaction;
use models\HeroPreset;
use services\LogService;
class HeroController extends BaseAuthedController {
@ -265,48 +254,13 @@ class HeroController extends BaseAuthedController {
}
public function presetHero(){
$heroId = getReqVal('hero_uid',0);
$heroDb = Hero::find($heroId);
$heroUid = getReqVal('hero_uid',0);
$heroDb = Hero::find($heroUid);
if (! $heroDb){
$this->_rspErr(1, "You don't have the hero yet");
return;
}
$row = SqlHelper::ormSelectOne(
$this->_getSelfMysql(),
't_hero_preset',
array(
'account_id' => $this->_getAccountId(),
'hero_uid' => $heroId,
)
);
if ($row){
$data = array(
'skill_id' => $row['skill_id'],
'weapon_uid1' => $row['weapon_uid1'],
'weapon_uid2' => $row['weapon_uid2'],
'chip_page' => $row['chip_page'],
'gun_id1'=>0,
'gun_id2'=>0,
);
$gunDb1 = Gun::find($row['weapon_uid1']);
$gunDb2 = Gun::find($row['weapon_uid2']);
if ($gunDb1){
$data['gun_id1'] = $gunDb1['gun_id'];
}
if ($gunDb1){
$data['gun_id2'] = $gunDb2['gun_id'];
}
}else{
$data = array(
'skill_id' => \mt\Skill::DEFAULT_SKILL,
'weapon_uid1' => 0,
'weapon_uid2' => 0,
'gun_id1'=>0,
'gun_id2'=>0,
'chip_page' => 1,
);
}
$data = HeroPreset::getHeroPreset($heroUid);
$this->_rspData(array(
'data' => $data,
));
@ -347,32 +301,7 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(1,'skill_id parameter error');
return ;
}
SqlHelper::upsert
($this->_getSelfMysql(),
't_hero_preset',
array(
'account_id' => $this->_getAccountId(),
'hero_uid' => $heroId,
),
array(
'skill_id' => $skillId,
'weapon_uid1' => $weaponUid1,
'weapon_uid2' => $weaponUid2,
'chip_page' => $chipPageId,
'modifytime' => $this->_getNowTime(),
),
array(
'account_id' => $this->_getAccountId(),
'hero_uid' => $heroId,
'skill_id' => $skillId,
'weapon_uid1' => $weaponUid1,
'weapon_uid2' => $weaponUid2,
'chip_page' => $chipPageId,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime(),
)
);
HeroPreset::upsertPreset($heroId,$skillId,$chipPageId,$weaponUid1,$weaponUid2);
$this->_rspOk();
}

View File

@ -2,12 +2,21 @@
require_once('models/User.php');
require_once('models/Hero.php');
require_once('models/Gun.php');
require_once('models/ChipPage.php');
require_once('models/HeroPreset.php');
require_once('models/HeroSkin.php');
require_once('mt/PveGemini.php');
require_once('mt/Skill.php');
use phpcommon\SqlHelper;
use models\User;
use models\Hero;
use models\Gun;
use models\ChipPage;
use models\HeroPreset;
use models\HeroSkin;
class TeamController extends BaseAuthedController {
@ -60,8 +69,9 @@ class TeamController extends BaseAuthedController {
return;
}
}
$userDto = User::info($userDb);
$userDto['is_leader'] =1;
$userDto = User::toPreset($userDb);
$userDto['is_leader'] = 1;
$userDto['is_ready'] = 1;
$userDto['createtime'] = $userDb['createtime'];
$teamDb = array(
'team_uuid' => $teamUuid,
@ -69,7 +79,7 @@ class TeamController extends BaseAuthedController {
'payload' => '',
'match_mode' => $matchMode,
'pve_instance_id' => $pveInstanceId,
'slot_num' => 1,
// 'slot_num' => 1,
'member_list' => array($userDto));
$r = $this->_getRedis($teamUuid);
@ -103,10 +113,10 @@ class TeamController extends BaseAuthedController {
$this->_rspErr(1, 'The team has been disbanded');
return;
}
if (count($teamDb['member_list']) >= $teamDb['slot_num']) {
$this->_rspErr(2, 'The team is full');
return;
}
// if (count($teamDb['member_list']) >= $teamDb['slot_num']) {
// $this->_rspErr(2, 'The team is full');
// return;
// }
foreach ($teamDb['member_list'] as $member) {
if ($member['account_id'] == $this->_getAccountId()) {
$this->_rspData(array(
@ -136,7 +146,7 @@ class TeamController extends BaseAuthedController {
}
}
$userDto = User::info($userDb);
$userDto = User::toPreset($userDb);
$userDto['createtime'] = $userDb['createtime'];
array_push($teamDb['member_list'], $userDto);
$this->saveTeamDb($r, $teamUuid, $teamDb);
@ -362,6 +372,154 @@ class TeamController extends BaseAuthedController {
$this->_rspOk();
}
public function doReady(){
$teamUuid = getReqVal('team_uuid', '');
$readyState = getReqVal('ready_state', 0); //1准备 0取消
if(!in_array($readyState,array(0,1))){
$this->_rspErr(1, 'ready_state param error');
return;
}
$r = $this->_getRedis($teamUuid);
$teamDb = $this->readTeamDb($r, $teamUuid);
if (empty($teamDb)) {
$this->_rspErr(1, 'The team has been disbanded');
return;
}
foreach ($teamDb['member_list'] as &$member) {
if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] == 1){
$this->_rspErr(1, 'Captain no operation');
return;
}
if ($member['account_id'] == $this->_getAccountId()){
$member['is_ready'] = $readyState?:0;
}
}
$this->saveTeamDb($r, $teamUuid, $teamDb);
$this->_rspOk();
}
public function setHero(){
$teamUuid = getReqVal('team_uuid', '');
$heroUid = getReqVal('hero_uid', '');
$heroDb = Hero::find($heroUid);
if (! $heroDb){
$this->_rspErr(1, 'hero_uid param error');
return;
}
$r = $this->_getRedis($teamUuid);
$teamDb = $this->readTeamDb($r, $teamUuid);
if (empty($teamDb)) {
$this->_rspErr(1, 'The team has been disbanded');
return;
}
$this->_updateUserInfo(array(
'hero_id' => $heroUid
));
$newUserInfo = User::toPreset($this->_getOrmUserInfo());
foreach ($teamDb['member_list'] as &$member) {
if ($member['account_id'] == $this->_getAccountId()){
$newUserInfo['is_leader'] = $member['is_leader'];
$newUserInfo['is_ready'] = $member['is_ready'];
$member = $newUserInfo;
}
}
$this->saveTeamDb($r, $teamUuid, $teamDb);
$this->_rspOk();
}
public function setPreset(){
$teamUuid = getReqVal('team_uuid', '');
$heroId = getReqVal('hero_uid',0);
$chipPageId = getReqVal('chip_page',0);
$weaponUid1 = getReqVal('weapon_uid1',0);
$weaponUid2 = getReqVal('weapon_uid2',0);
$skillId = getReqVal('skill_id',0);
$r = $this->_getRedis($teamUuid);
$teamDb = $this->readTeamDb($r, $teamUuid);
if (empty($teamDb)) {
$this->_rspErr(1, 'The team has been disbanded');
return;
}
$heroDb = Hero::find($heroId);
if (! $heroDb){
$this->_rspErr(1, "You don't have the hero yet");
return;
}
$chipPageDb = ChipPage::find($chipPageId);
if (! $chipPageDb){
$this->_rspErr(1, "You don't have the chip page");
return;
}
if ($weaponUid1){
$gunDb1 = Gun::find($weaponUid1);
if (!$gunDb1){
$this->_rspErr(1, "You don't have the gun1 yet");
return;
}
}
if ($weaponUid2){
$gunDb2 = Gun::find($weaponUid2);
if (!$gunDb2){
$this->_rspErr(1, "You don't have the gun2 yet");
return;
}
}
$skillMeta = mt\Skill::get($skillId);
if (! $skillMeta){
$this->_rspErr(1,'skill_id parameter error');
return ;
}
HeroPreset::upsertPreset($heroId,$skillId,$chipPageId,$weaponUid1,$weaponUid2);
$newUserInfo = User::toPreset($this->_getOrmUserInfo());
foreach ($teamDb['member_list'] as &$member) {
if ($member['account_id'] == $this->_getAccountId()){
$newUserInfo['is_leader'] = $member['is_leader'];
$newUserInfo['is_ready'] = $member['is_ready'];
$member = $newUserInfo;
}
}
$this->saveTeamDb($r, $teamUuid, $teamDb);
$this->_rspOk();
}
public function setHeroSkin(){
$teamUuid = getReqVal('team_uuid', '');
$heroUniId = getReqVal('hero_uid', 0);
$skinId = getReqVal('skin_id', 0);
$r = $this->_getRedis($teamUuid);
$teamDb = $this->readTeamDb($r, $teamUuid);
if (empty($teamDb)) {
$this->_rspErr(1, 'The team has been disbanded');
return;
}
$heroDb = Hero::find($heroUniId);
$heroSkinDb = HeroSkin::find($skinId);
if (!$heroDb) {
$this->_rspErr(1, "You don't have the hero yet");
return;
}
if (!$heroSkinDb) {
$this->_rspErr(2, "You don't have the skin yet");
return;
}
HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']);
$newUserInfo = User::toPreset($this->_getOrmUserInfo());
foreach ($teamDb['member_list'] as &$member) {
if ($member['account_id'] == $this->_getAccountId()){
$newUserInfo['is_leader'] = $member['is_leader'];
$newUserInfo['is_ready'] = $member['is_ready'];
$member = $newUserInfo;
}
}
$this->saveTeamDb($r, $teamUuid, $teamDb);
$this->_rspOk();
}
private function readTeamDb($r, $teamUuid)
{
$teamDbStr = $r->get(TEAMID_KEY . $teamUuid);

View File

@ -8,7 +8,6 @@ require_once('mt/HeroQuality.php');
require_once('mt/HeroLevel.php');
require_once('mt/AttrHelper.php');
require_once('mt/Item.php');
require_once('mt/SkillCommon.php');
require_once('models/HeroSkin.php');
require_once('models/Chip.php');
require_once('models/User.php');
@ -425,12 +424,14 @@ class Hero extends BaseModel {
$heroList = array();
Hero::getHeroList(function ($row) use($heroId, &$heroList) {
if ($row['state'] == self::GETED_STATE) {
// if ($row['state'] == self::GETED_STATE) {
array_push($heroList, Hero::toDto($row));
}
// }
});
$key = array_rand($heroList, 1);
$key = null;
if (count($heroList)>0){
$key = array_rand($heroList, 1);
}
if (!is_null($key)) {
$heroUniId = $heroList[$key]['idx'];
$heroId = $heroList[$key]['hero_id'];

View File

@ -0,0 +1,80 @@
<?php
namespace models;
require_once('mt/Skill.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
class HeroPreset extends BaseModel {
public static function getHeroPreset($heroUid){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_hero_preset',
array(
'account_id' => myself()->_getAccountId(),
'hero_uid' => $heroUid,
)
);
if ($row){
$data = array(
'skill_id' => $row['skill_id'],
'weapon_uid1' => $row['weapon_uid1'],
'weapon_uid2' => $row['weapon_uid2'],
'chip_page' => $row['chip_page'],
'gun_id1'=>0,
'gun_id2'=>0,
);
$gunDb1 = Gun::find($row['weapon_uid1']);
$gunDb2 = Gun::find($row['weapon_uid2']);
if ($gunDb1){
$data['gun_id1'] = $gunDb1['gun_id'];
}
if ($gunDb2){
$data['gun_id2'] = $gunDb2['gun_id'];
}
}else{
$data = array(
'skill_id' => mt\Skill::DEFAULT_SKILL,
'weapon_uid1' => 0,
'weapon_uid2' => 0,
'gun_id1'=>0,
'gun_id2'=>0,
'chip_page' => 1,
);
}
return $data;
}
public static function upsertPreset($heroId,$skillId,$chipPageId,$weaponUid1,$weaponUid2){
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_hero_preset',
array(
'account_id' => myself()->_getAccountId(),
'hero_uid' => $heroId,
),
array(
'skill_id' => $skillId,
'weapon_uid1' => $weaponUid1,
'weapon_uid2' => $weaponUid2,
'chip_page' => $chipPageId,
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => myself()->_getAccountId(),
'hero_uid' => $heroId,
'skill_id' => $skillId,
'weapon_uid1' => $weaponUid1,
'weapon_uid2' => $weaponUid2,
'chip_page' => $chipPageId,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
}

View File

@ -7,6 +7,7 @@ require_once('mt/LevelUp.php');
require_once('models/UserSeasonRing.php');
require_once('models/Parachute.php');
require_once('models/Hero.php');
require_once('models/HeroPreset.php');
use mt;
use phpcommon;
@ -45,9 +46,15 @@ class User extends BaseModel {
{
mt\LevelUp::getExpByLv($row['level'],$row['exp']);
$heroDb = Hero::find($row['hero_id']);
$heroId = 0;
if ($heroDb){
$heroId = $heroDb['hero_id'];
}else{
$heroUniId = 0;
$heroId = 0;
Hero::randHero($heroUniId,$heroId);
self::update(array(
'hero_id' => $heroUniId
));
}
return array(
'activated' => $row['activated'],
@ -90,10 +97,17 @@ class User extends BaseModel {
{
mt\LevelUp::getExpByLv($row['level'],$row['exp']);
$heroDb = Hero::find($row['hero_id']);
$heroId = 0;
if ($heroDb){
$heroId = $heroDb['hero_id'];
}else{
$heroUniId = 0;
$heroId = 0;
Hero::randHero($heroUniId,$heroId);
self::update(array(
'hero_id' => $heroUniId
));
}
return array(
'activated' => $row['activated'],
'rename_count' => $row['rename_count'],
@ -136,10 +150,17 @@ class User extends BaseModel {
{
mt\LevelUp::getExpByLv($row['level'],$row['exp']);
$heroDb = Hero::find($row['hero_id']);
$heroId = 0;
if ($heroDb){
$heroId = $heroDb['hero_id'];
}else{
$heroUniId = 0;
$heroId = 0;
Hero::randHero($heroUniId,$heroId);
self::update(array(
'hero_id' => $heroUniId
));
}
return array(
'account_id' => $row['account_id'],
'address' => phpcommon\extractOpenId($row['account_id']),
@ -160,19 +181,50 @@ class User extends BaseModel {
);
}
public static function toPreset($row){
mt\LevelUp::getExpByLv($row['level'],$row['exp']);
$heroDb = Hero::find($row['hero_id']);
$heroId = 0;
if ($heroDb){
$heroId = $heroDb['hero_id'];
}
$preset = HeroPreset::getHeroPreset($row['hero_id']);
$skinDb = HeroSkin::findBx($heroId);
return array(
'account_id' => $row['account_id'],
'address' => phpcommon\extractOpenId($row['account_id']),
'name' => $row['name'],
// 'sex' => $row['sex'],
// 'head_id' => $row['head_id'],
// 'head_frame' => $row['head_frame'],
'level' => $row['level'],
'exp' => $row['exp'],
'rank' => $row['rank'],
'score' => $row['score'],
// 'gold' => cegFormat($row['gold']),
// 'diamond' => cecFormat($row['diamond']),
'pve_instance_id' => $row['pve_instance_id'],
// 'like_count' => $row['like_count'],
'first_fight' => $row['first_fight'],
'parachute' => $row['parachute'] ? $row['parachute'] : Parachute::$parachute,
'hero_uniId' => $row['hero_id'],
'hero_id' => $heroId,
'hero_skin' =>$skinDb['skin_id'],
'presetInfo' => $preset,
'is_leader' => 0,
'is_ready' => 0,
);
}
public static function isValidHeadId($userInfo, $headId)
{
// $headList = self::exportHeadList($userInfo);
// return in_array($headId, $headList['head_list']);
$headList = emptyReplace(json_decode($userInfo['head_list'], true), array());
return in_array($headId, $headList);
}
public static function isValidHeroId($userInfo, $heroId)
{
// $heroList = self::exportHeadList($userInfo);
// return in_array($heroId, $heroList['hero_list']);
$heroDb = Hero::find($heroId);
$heroDb = Hero::findByAccountId($userInfo['account_id'],$heroId);
return empty($heroDb) ? false : true ;
}
@ -208,21 +260,6 @@ class User extends BaseModel {
return $headList;
}
private static function exportHeadList($userInfo){
$list = emptyReplace(json_decode($userInfo['head_list'], true), array());
$head_list = array();
$hero_list = array();
foreach ($list as $value){
$temp = explode('|',$value);
array_push($head_list,$temp[0]);
array_push($hero_list,$temp[1]);
}
return array(
'head_list'=>$head_list,
'hero_list'=>$hero_list,
);
}
public static function update( $fieldsKv){
SqlHelper::update
(myself()->_getSelfMysql(),