//发起请求,更新一个
 public void UpdateInventoryItemDB(InventoryItemDB itemDB)
 {
     itemDB.Role = null;
     Dictionary<byte, object> parameters = new Dictionary<byte, object>();
     ParameterTool.AddParameter(parameters, ParameterCode.InventoryItemDB, itemDB);
     PhotonEngine.Instance.SendRequest(OpCode, SubCode.UpdateInventoryItemDB, parameters);
 }
	public InventoryItemDB CreateInventoryItemDB()
	{
		inventoryItemDB = new InventoryItemDB();
		inventoryItemDB.Count = Count;
		inventoryItemDB.Level = Level;
		inventoryItemDB.InventoryID = Inventory.ID;
		inventoryItemDB.IsDressed = IsDressed;
		return inventoryItemDB;
	}
	public InventoryItem(InventoryItemDB itemDB)
	{
		this.inventoryItemDB = itemDB;
		Inventory inventoryTemp;
		InventoryManager._instance.inventoryDic.TryGetValue(itemDB.InventoryID, out inventoryTemp);
		inventory = inventoryTemp;
		Level = itemDB.Level;
		Count = itemDB.Count;
		IsDressed = itemDB.IsDressed;
	}
    //升级装备
    public void UpgradeEquip(InventoryItemDB itemDB)
    {
        itemDB.Role = null;
        Role role = PhotonEngine.Instance.role;
        role.User = null;
        Dictionary<byte,object> parameters = new Dictionary<byte, object>();
        ParameterTool.AddParameter(parameters,ParameterCode.InventoryItemDB, itemDB);
        ParameterTool.AddParameter(parameters,ParameterCode.Role, role);

        PhotonEngine.Instance.SendRequest(OpCode,SubCode.UpgradeEquip,parameters);
    }
 //更新,一个的情况
 public void UpdateInventoryItemDB(InventoryItemDB itemDB)
 {
     using (var session = NHibernateHelper.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Update(itemDB);
             transaction.Commit();
         }
     }
 }
 //更新装备升级
 public void UpgradeEquip(InventoryItemDB itemDb4, Role role)
 {
     using (var session = NHibernateHelper.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Update(itemDb4);
             session.Update(role);
             transaction.Commit();
         }
     }
 }
    //同步服务器的卸下和穿上的装备,更新两个
    public void UpdateInventoryItemDBList(InventoryItemDB itemDB1,InventoryItemDB itemDB2)
    {
        itemDB1.Role = null;
        itemDB2.Role = null;
        List<InventoryItemDB> list = new List<InventoryItemDB>();
        list.Add(itemDB1);
        list.Add(itemDB2);
        //添加到字典
        Dictionary<byte,object> parameters = new Dictionary<byte, object>();
        ParameterTool.AddParameter(parameters,ParameterCode.InventoryItemDBList, list);
        PhotonEngine.Instance.SendRequest(OpCode,SubCode.UpdateInventoryItemDBList,parameters);

    }
Beispiel #8
0
    //回调
    public void OnAddInventoryItemDB(InventoryItemDB itemDB)
    {
        InventoryItem it  = new InventoryItem(itemDB);
        inventoryItemList.Add(it);


        OnInventoryChange();
    }
Beispiel #9
0
    private void PickUp()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            int id = Random.Range(1001, 1020);
            Inventory i = null;
            inventoryDict.TryGetValue(id,out i);
            if (i.InventoryType == InventoryType.Equip)
            {
                //InventoryItem it = new InventoryItem();
                //it.Inventory = i;
                //it.Level = Random.Range(1, 10);
                //it.Count = 1;
                //inventoryItemList.Add(it);
                //InventoryItemDB itemDB = it.CreateInventoryItemDB();
                //inventoryItemDBController.AddInventoryItemDB(itemDB);

                //先发起请求,创建InventoryItemDB,把InventoryItemDB存到数据库里面,再去创建InventoryItem
                InventoryItemDB itemDB = new InventoryItemDB();
                itemDB.InventoryID = id;
                itemDB.Count = 1;
                itemDB.IsDressed = false;
                itemDB.Level = Random.Range(1, 10);
                inventoryItemDBController.AddInventoryItemDB(itemDB);
            }
            else
            {
                //不是装备,则可以叠加
                //先判断背包里面是否已经存在
                InventoryItem it = null;
                bool isExist = false;
                foreach (InventoryItem temp in inventoryItemList)
                {
                    if (temp.Inventory.ID == id)
                    {
                        isExist = true;
                        it = temp;
                        break;
                    }
                }

                if (isExist)
                {
                    it.Count++;
                    //同步InventoryItemDB 进行update
                    inventoryItemDBController.UpdateInventoryItemDB(it.InventoryItemDB);
                }
                else
                {
                    InventoryItemDB itemDB = new InventoryItemDB();
                    itemDB.InventoryID = id;
                    itemDB.Count = 1;
                    itemDB.IsDressed = false;
                    itemDB.Level = Random.Range(1, 10);
                    inventoryItemDBController.AddInventoryItemDB(itemDB);
                }
            }
        }
    }