baseInfo = new Info_UserBase();
$this->baseInfo->initialize();
# 添加默认战队设置
$this->heroTeamConfig = JsonUtil::encode(GameConfig::primordial_data()->User_HeroTeamConfig);
$this->store->initialize(); # 添加默认物品
$this->privateState->currentId = count((array) $this->store->equipment) + 1;
$this->heros->InitializeHero(); # 添加初始英雄
$this->pvp = new Info_UserPVP();
// $this->task->initialize(); # 任务初始化
$this->taskCardShop = new Info_TaskCard_Shop();
$this->college->initialize();
}
/**
* 构造函数
* @param type $arg
*/
public function __construct($arg = null) {
if (null === $arg) { # 未传参数的情况下
$this->shopdata = ObjectInit(); # 商城数据
$this->privateState = new Info_PrivateState(); # 私有字段
$this->privateState->initialize(); # 初始化默认数据
$this->store = new Info_Store(); # 背包数据
// $this->store->initialize(); # 添加默认物品
$this->heros = new Info_UserGameHero(); # 英雄数据
// $this->heros->InitializeHero(); # 添加初始英雄
$this->gates = new Info_UserGateDifficulty(); # 初始化关卡默认数据
$this->map = new Info_Map(); # 初始化地图解锁数据
// $this->heroManual = new HeroManualModel(); # 初始化图鉴数据结构
$this->NewbieGuide = new Info_NewbieGuide(); # 初始化新手引导结构
// $this->pvp = new UserPVPModel(); # 初始化pvp模块
$this->userSecretshop = new Info_UserSecretshop(); # 神秘商店
// $this->task = new Info_UserTask(); # 任务数据
$this->taskCardShop = new Info_TaskCard_Shop(); # 任务卡商店
$this->college = new Info_College();
} else { # 实参
parent::__construct($arg); # 调用Object的构造函数
// $this->shopdata = new Info_UserShop($this->shopdata);
//// $this->NewbieGuide= new info_us
// $this->baseInfo = new Info_UserBase($this->baseInfo);
// $this->gates = new Info_UserGateDifficulty($this->gates);
// $this->heros = new Info_UserGameHero($this->heros);
// $this->privateState = new Info_PrivateState($this->privateState);
//// $this->profile = n
// $this->pvp = new Info_UserPVP($this->pvp);
// $this->store = new Info_Store($this->store);
// $this->taskCardShop = new Info_TaskCard_Shop($this->taskCardShop);
// $this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
}
$this->profile = new Data_UserProfile(); # 初始化用户画像模块
}
//
/**
* 扣除玩家钻石
* @param Info_UserBase $user
* @param int $amt
* @return bool 成功与否
*/
static public function Consume_Cash($user, $amt) {
if ($amt >= 0 && isset($user) && isset($user->cash)) {
if ($user->cash - $amt >= 0) {
$user->cash -= $amt;
return true;
}
}
return false;
}
/**
* 扣除玩家金币
* @param Info_UserBase $user
* @param int $amt
* @return boolean true:成功, false:金币不足
*/
static public function Consume_Gold($user, $amt) {
if ($amt > 0 && isset($user) && isset($user->gold)) {
if ($user->gold - $amt >= 0) {
$user->gold -= $amt;
return true;
}
}
return false;
}
/**
* 扣除资源点
* @param Info_UserBase $user
* @param type $amt
* @return boolean true:成功, false:资源点不足
*/
static public function Consume_ResPoint($user, $amt) {
if ($amt > 0 && isset($user) && isset($user->resPoint)) {
if ($user->resPoint - $amt >= 0) {
$user->resPoint -= $amt;
return true;
}
}
return false;
}
/**
* 扣除玩家友情点
* @param Info_UserBase $user
* @param int $amt
*/
static public function Consume_FriendShipPoint($user, $amt) {
if ($amt > 0 && isset($user) && isset($user->friendPoint)) {
if ($user->friendPoint - $amt >= 0) {
$user->friendPoint -= $amt;
return true;
}
}
return false;
}
/**
* 扣除玩家碎片
* @param Data_UserGame $user
* @param int $segmentId 碎片ID
* @param int $amt 数量
* @return boolean true 成功, false 失败
*/
static public function Consume_HeroSegment($user, $segmentId, $amt) {
if ($amt > 0 && isset($user)) {
if (CommUtil::isPropertyExists($user->store->items, $segmentId)) {
if ($user->store->items->$segmentId - $amt >= 0) {
$user->store->items->$segmentId -= $amt;
return true;
}
}
}
return false;
}
/**
* 增加用户钻石
* @param Info_UserBase $user
* @param type $amt
* @return type
*/
static function Add_Cash($user, $amt) {
my_Assert($user, "user为空");
my_Assert($amt >= 0, "amt值为负");
$user->cash += $amt;
}
/**
* 增加用户友情点
* @param Info_UserBase $user
* @param type $amt
* @return type
*/
static function Add_FriendPoint($user, $amt) {
my_Assert($user, "user为空");
my_Assert($amt >= 0, "amt值为负");
$user->friendPoint += $amt; # 业务逻辑
}
/**
* 用户获得经验值
* @param Info_UserBase $user Description
* @param int $amt
*/
static function Add_Exp($user, $amt) {
my_Assert($user, "user为空");
my_Assert($amt >= 0, "amt值为负");
$cfgLVs = GameConfig::playerlevel();
$user->xp += $amt;
$initLevel = $curLevel = $user->level;
$nextLevel = $curLevel + 1;
while ($user->xp >= $cfgLVs->$nextLevel->xp_need) { # 超过升级所需经验
if ($user->level < glc()->Game_MaxPlayerLevel) { # 如果未到达最大等级
$user->level++;
$user->xp -= $cfgLVs->$nextLevel->xp_need;
$curLevel = $user->level;
$nextLevel = $curLevel + 1;
my_Assert(CommUtil::isPropertyExists($cfgLVs, $nextLevel), ErrCode::err_const_no); // "取英雄升级常量数据失败." . $nextLevel . "级");
$user->maxXp = $cfgLVs->$nextLevel->xp_need;
// StatProc::UserLevel($nowlv); // 等级统计
// todo:: 发发宝箱奖励, 如果有的话
} else { // 如果已到达最大等级则仅补齐缺失的经验即可
$user->xp = $user->maxXp; # 经验不能超过最大值
break;
}
}
if ($user->level != $initLevel) { # 插入玩家升级的系统消息
SystemProc::UserLevelUp(req()->zoneid, $user, $user->level);
TaskProc::OnUserLevelUp($user->level); # 通知任务模块,这里应该有事件模块
EventProc::OnUserLevelup($initLevel, $user->level); # 事件模块
}
}
/**
* 用户获得金币
* @param Info_UserBase $user 玩家数据
* @param int $amt
*/
static function Add_Gold(&$user, $amt) {
my_Assert($user, "参数null");
my_Assert($amt >= 0, "参数为负");
$user->gold += $amt;
}
/**
* 给玩家增加体力
* @param int $amt
* @return type
*/
static function Add_tili($amt) {
$user = req()->userInfo->game;
my_Assert($user, "user为空");
my_Assert($amt >= 0, "体力amt小于0");
ActiveProc::ChangeTili($amt);
}
/**
* 增加资源点
* @param Info_UserBase $user
* @param type $amt
*/
static function Add_resPoint(&$user, $amt) {
my_Assert($user, "参数null");
my_Assert($amt >= 0, "参数为负");
$user->resPoint += $amt;
}
//
//
/**
* 基础信息
* @param bool $save 是否需要回存
* @return Info_UserBase
*/
public function base($save = false) {
$this->baseInfo = new Info_UserBase($this->baseInfo);
if ($save) {
self::save_tag("baseInfo");
}
return $this->baseInfo;
}
/**
* 玩家仓库
* @param bool $save 是否需要回存
* @return Info_Store
*/
public function store($save = false) {
$this->store = new Info_Store($this->store);
if ($save) {
self::save_tag("store");
}
return $this->store;
}
/**
* 商店数据
* @param bool $save 是否需要回存
* @return Info_UserShop
*/
public function shop($save = false) {
$this->shopdata = new Info_UserShop($this->shopdata);
if ($save) {
self::save_tag("shopdata");
}
return $this->shopdata;
}
/**
* 神秘商店
* @param bool $save 是否需要回存
* @return Info_UserSecretshop
*/
public function secretshop($save = false) {
$this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
if ($save) {
self::save_tag("userSecretshop");
}
return $this->userSecretshop;
}
/**
* 英雄数据
* @param bool $save 是否需要回存
* @return Info_UserGameHero
*/
public function heros($save = false) {
$this->heros = new Info_UserGameHero($this->heros);
if ($save) {
self::save_tag("heros");
}
return $this->heros;
}
/**
* 私有数据
* @param bool $save 是否需要回存
* @return Info_PrivateState
*/
public function private($save = false) {
$this->privateState = new Info_PrivateState($this->privateState);
if ($save) {
self::save_tag("privateState");
}
return $this->privateState;
}
/**
* 关卡数据
* @param bool $save 是否需要回存
* @return Info_UserGateDifficulty
*/
public function gates($save = false) {
$this->gates = new Info_UserGateDifficulty($this->gates);
if ($save) {
self::save_tag("gates");
}
return $this->gates;
}
/**
* 地图数据
* @param bool $save 是否需要回存
* @return Info_Map
*/
public function map($save = false) {
$this->map = new Info_Map($this->map);
if ($save) {
self::save_tag("map");
}
return $this->map;
}
/**
* 任务卡商店
* @param bool $save 是否需要回存
* @return Info_TaskCard_Shop
*/
public function taskCardShop($save = false) {
$this->taskCardShop = new Info_TaskCard_Shop($this->taskCardShop);
if ($save) {
self::save_tag("taskCardShop");
}
return $this->taskCardShop;
}
/**
* pvp数据
* @param bool $save 是否需要回存
* @return Info_UserPVP
*/
public function pvp($save = false) {
$this->pvp = new Info_UserPVP($this->pvp);
if ($save) {
self::save_tag("pvp");
}
return $this->pvp;
}
/**
* 角色画像数据
* @param bool $save 是否需要回存
* @return Data_UserProfile
*/
public function profile($save = false) {
$this->profile = new Data_UserProfile($this->profile);
if ($save) {
self::save_tag("profile");
}
return $this->profile;
}
/**
* 圣哲学院
* @param bool $save 是否需要回存
* @return Info_College
*/
public function college($save = false) {
$this->college = new Info_College($this->college);
if ($save) {
self::save_tag("college");
}
return $this->college;
}
/**
* 新手引导
* @param bool $save 是否需要回存
* @return Info_NewbieGuide
*/
public function newbieGuide($save = false) {
$this->NewbieGuide = new Info_NewbieGuide($this->NewbieGuide);
if ($save) {
self::save_tag("NewbieGuide");
}
return $this->NewbieGuide;
}
/**
* 战队配置
* @param bool $save 是否需要回存
* @return Info_NewbieGuide
*/
public function &teamConfig($save = false) {
// $this->NewbieGuide = new Info_NewbieGuide($this->NewbieGuide);
if ($save) {
self::save_tag("heroTeamConfig");
}
return $this->heroTeamConfig;
}
//
//
}