<?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 Info_UserShop
     */
    public $shopdata;

    /**
     * @var Info_UserSecretshop 玩家神秘商城数据
     */
    public $userSecretshop;

    /**
     * 英雄
     * @var Info_UserGameHero
     */
    public $heros;

    /**
     * 私有字段
     * @var Info_PrivateState
     */
    public $privateState;

    /**
     * 关卡
     * @var Info_UserGateDifficulty
     */
    public $gates;

    /**
     * 地图解锁信息
     * @var Info_Map
     */
    public $map;

//    /**
//     * @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;

    /**
     * 圣哲学院
     * @var Info_College
     */
    public $college;
    
    /**
     * 神庙
     * @var Info_ShenMiao
     */
    public $shenmiao;

    /**
     * 用于给各个字段赋默认初始值
     * @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();
        $this->college->initialize();
        $this->shenmiao->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();
            $this->shenmiao = new Info_ShenMiao();
        } 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="实例方法">

    /**
     * 基础信息
     * @param bool $save 是否需要回存
     * @return Info_UserBase
     */
    public function base($save = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
        $this->heros = new Info_UserGameHero($this->heros);
        if ($save) {
            self::save_tag("heros");
        }
        return $this->heros;
    }

    /**
     * 私有数据
     * @param bool $save 是否需要回存
     * @return Info_PrivateState
     */
    public function privateData($save = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
        $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 = true) {
//        $this->NewbieGuide = new Info_NewbieGuide($this->NewbieGuide);
        if ($save) {
            self::save_tag("heroTeamConfig");
        }
        return $this->heroTeamConfig;
    }

    // 
// </editor-fold>
}
