<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace loyalsoft;

/**
 * Description of Info_Store
 *
 * @author c'y'zhao
 */
class Info_Store extends Object_ext {

    /**
     * 道具
     * @var \stdClass()
     */
    public $items;

    /**
     * 宝石在背包库的唯一id
     * @var type
     */
    public $gemLength = 0;

    /**
     * 宝石背包
     * \stdClass() 
     */
    public $gemStore;

    /**
     * 装备界面默认页
     * @var int
     */
    public $equipPag = 1;

    /**
     * 装备背包数据
     * @var \stdClass()
     */
    public $equip;

    /**
     * 装备部位--废弃
     * @var \stdClass()
     */
    public $equipPosition;

    /**
     * 6个装备部位
     * @var type
     */
    public $equipLocation;

    /**
     * 宝石装备的信息--废弃
     * @var \stdClass()
     */
    public $gemEquip;

    /**
     * 装备信息 装备不跟hero走--废弃
     * @var type
     */
    //public $equipPosition = null;

    public $gemComposeNum = 0;

    /**
     * @var int current UID
     */
    public $cuid = 10000;

    /**
     * @var int $petUid
     */
    public $petUid = 1;

    /**
     *  宠物背包数据
     */
    public $pet;

    /**
     * 选中要在主界面显示的灵宠
     */
    #[ArrayType]
    public $mainShowPetList = array();

    /**
     * 出战位置 宠物id
     * @var type
     */
    public $petUid_fight_position = 0;

    /**
     * 助战
     * @var type
     */
    public $petUids_supportFight_position;

    /**
     * 孵蛋坑位信息
     * @var type
     */
    public $breedEggLocation;

    /**
     * 宠物探索区域
     * @var type
     */
    public $exploreArea;

    public function initialize() {
        StoreProc::AddMultiItemInStore(glc()->Init_Packet_Items, "UsrInit");
    }

    public function __construct($arg = null) {
        if ($arg == null) {
            $this->petUids_supportFight_position = new \stdClass();

            $this->items = new \stdClass();
            $this->gemStore = new \stdClass();
            $this->equip = new \stdClass();
            $this->equipLocation = new \stdClass();
            $this->pet = new \stdClass();
            $this->equipPosition = new \stdClass();
            for ($i = 1; $i <= 6; $i++) {
                $equip = new Ins_EquipPosition();
                $equip->typeId = $i;
                $this->equipPosition->$i = $equip;
            }

            $this->gemEquip = new \stdClass();
            for ($k = 1; $k <= 3; $k++) {
                $item = new \stdClass();
                for ($j = 1; $j <= 6; $j++) {
                    $item->$j = new \stdClass();
                }
                $this->gemEquip->$k = $item;
            }

            $str = GameConfig::glc2()->Pet_BreedLocationUnlockInfo;
            $this->breedEggLocation = new \stdClass();
            if ($str != null) {
                $list = explode(';', $str);
                foreach ($list as $value) {
                    $s = explode(',', $value);
                    $k = $s[0];
                    $ins_breed = new Ins_BreedEggSlot();
                    $ins_breed->uid = $k;
                    $ins_breed->unlock = 0;
                    if ($s[1] == 0) {
                        $ins_breed->unlock = 1;
                    }
                    $this->breedEggLocation->$k = $ins_breed;
                }
            }
            
            $this->initExploreArea();
            
        } else {
            parent::__construct($arg);
        }
    }

    public function removeItem($itemId, $num) {
        if (StlUtil::dictHasProperty($this->items, $itemId)) {
            $this->items->$itemId -= $num;
            if ($this->items->$itemId <= 0) {
                unset($this->items->$itemId);
            }
        }
    }

    /**
     * @return 产生下一个唯一ID
     */
    public function nextUID() {
        return $this->cuid++;
    }

    public function initExploreArea() {
        if($this->exploreArea == null){
            $this->exploreArea = new \stdClass();
        }
                   
        $exploreAreas = GameConfig::pet_area();
        foreach ($exploreAreas as $areaId => $areaArr) {
            if(!StlUtil::dictHasProperty($this->exploreArea, $areaId)){
                $Ins_ExploreArea = new Ins_ExploreArea($areaArr[0]);
                $this->exploreArea->$areaId = $Ins_ExploreArea;
            }                          
        }
    }
}
