123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?php
- namespace loyalsoft;
- /**
- * Description of UserGameModel
- * 游戏数据
- * @author gwang (mail@wanggangzero.cn)
- */
- class Data_UserGame extends HashSaver {
- /**
- * @var Info_UserBase 基础数据
- */
- public $baseInfo;
- /**
- * 玩家仓库
- * @var Info_Store
- */
- public $store;
- /**
- * 商城
- * @var {}
- */
- public $shopdata;
- /**
- * 英雄
- * @var Info_UserGameHero
- */
- public $heros;
- /**
- * 私有字段
- * @var Info_PrivateState
- */
- public $privateState;
- /**
- * @var Info_UserSecretshop 玩家神秘商城数据
- */
- public $userSecretshop;
- /**
- * 关卡
- * @var Info_UserGateDifficulty
- */
- public $gates;
- // /**
- // * @var Info_UserTask 玩家任务数据
- // */
- // public $task;
- /**
- * 玩家任务卡商店数据
- * @var Info_TaskCard_Shop
- */
- public $taskCardShop;
- /**
- *
- * @var Info_UserPVP pvp信息
- */
- public $pvp;
- /**
- * 战斗队伍配置信息(使用时必须先json_decode)
- * @var dictionary
- */
- public $heroTeamConfig;
- /**
- * 新手引导
- * @var object
- */
- public $NewbieGuide;
- /**
- * 新手引导是否已经结束
- * @var type
- */
- public $NewbieGuideOver = 1;
- /**
- * @var Data_UserProfile 角色画像
- */
- public $profile;
- /**
- * 用于给各个字段赋默认初始值
- * @return \UserGameModel
- */
- public function initialize() {
- my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
- $this->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(); # 初始化用户画像模块
- }
- // <editor-fold defaultstate="collapsed" desc=" functions ">
- /**
- * 设置钻石数
- * @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);
- }
- // </editor-fold>
- // <editor-fold defaultstate="collapsed" desc="私有方法">
- //
- // </editor-fold>
- }
|