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(); } /** * 构造函数 * @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->heroManual = new HeroManualModel(); # 初始化图鉴数据结构 $this->NewbieGuide = ObjectInit(); # 初始化新手引导结构 // $this->pvp = new UserPVPModel(); # 初始化pvp模块 $this->userSecretshop = new Info_UserSecretshop(); # 神秘商店 // $this->task = new Info_UserTask(); # 任务数据 $this->taskCardShop = new Info_TaskCard_Shop(); # 任务卡商店 } 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 Data_UserGame $user * @param int $amt 数量 */ static public function set_Cash($user, $amt) { my_Assert($amt >= 0, "数量小于0"); my_Assert($user, "user为空"); my_Assert(isset($user->cash), "找不到cash字段"); $user->cash = $amt; # 实际逻辑 } /** * 扣除玩家晶石 * @param Data_UserGame $user * @param int $amt */ static public function Consume_Spar($user, $amt) { if ($amt > 0 && isset($user) && isset($user->spar)) { if ($user->spar - $amt >= 0) { $user->spar -= $amt; return true; } } return false; } /** * 扣除玩家钻石 * @param Data_UserGame $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 Data_UserGame $user * @param int $amt */ 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 Data_UserGame $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 Data_UserGame $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 Data_UserGame $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 Req $req 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); # 通知任务模块,这里应该有事件模块 } } /** * 用户获得金币 * @param Data_UserGame $user 玩家数据 * @param int $amt */ static function Add_Gold(&$user, $amt) { my_Assert($user, "参数null"); my_Assert($amt >= 0, "参数为负"); $user->gold += $amt; } /** * 给玩家增加体力 * @param Req $req * @param int $amt * @return type */ static function Add_tili($req, $amt) { $user = $req->userInfo->game; my_Assert($user, "user为空"); my_Assert($amt >= 0, "体力amt小于0"); ActiveProc::ChangeTili($amt); } // // // // }