private async Task ConnectManagerClient() { try { await this.ManagerClient.ConnectToContract(); Debug.Log("Manager Client Start"); this.tokenBalance = await this.ManagerClient.BalanceOf(playerWallet.publicKey); getManagerGunState = await this.ManagerClient.getUnownedWeapons(); JsonGunState.Gun gun; Debug.Log(getManagerGunState); foreach (JsonGunState.Gun g in getManagerGunState.guns) { Debug.Log(g.name); Debug.Log(g.price); Debug.Log(g.index); gun = g; //await this.ManagerClient.buyWeapon(0, this.OwnerClient, g); if (g.index == 0) { //await this.ManagerClient.sellWeapon(0, this.OwnerClient, g); } } } catch (Exception e) { Debug.Log(e); } }
public async Task buyWeapon(uint _id, ItemOwnershipContractClient OwnerClient, JsonGunState.Gun gun) { try { await ConnectToContract(); Debug.Log("buyWepon start"); await this.contract.CallAsync("buyWeapon", _id); JsonGunState jsonGunState = await OwnerClient.GetWeapons(); if (jsonGunState == null) { jsonGunState = new JsonGunState(); } jsonGunState.guns.Add(gun); await OwnerClient.setUserWeapon(jsonGunState); Debug.Log("buyWepon end"); } catch (Exception e) { Debug.Log(e); } }
private async Task ConnectOwnerClient() { try { await this.OwnerClient.ConnectToContract(); Debug.Log("Owner Client Start"); this.myGunState = await this.OwnerClient.GetWeapons(); Debug.Log(this.myGunState); int n = 0; GameObject slotPanel = GameObject.Find("inventorypanel");//캔버스에서 슬롯을 생성시킬 위치 foreach (JsonGunState.Gun g in this.myGunState.guns) { GameObject go = Instantiate(slotPrefab, slotPanel.transform, false); //slotPrefab을 slotPanel위치에 생성 itemcount++; go.name = "Slot_" + g.name + "-" + itemcount; //생성된 슬롯의 이름 -0 SlotData_inventory slot = new SlotData_inventory(); //슬롯 객체 생성 //slot.ObjName = ""; slot.isEmpty = true; //슬롯 객체 상태 slot.slotObj = go; //슬롯 객체에 오브젝트 할당 slot.equipItemName = g.name; Instantiate(Resources.Load("prefabs/" + "image_" + g.name), go.transform, false); //현재 문자열 배열에 해당되는 오브젝트명 앞에 image를 붙여 해당 오브젝트의 이미지를 슬롯에 생성 n++; slots.Add(slot);//슬롯 추가 } } catch (Exception e) { Debug.Log(e); } }
public async Task setUserWeapon(JsonGunState jsonGunState) { Debug.Log("setUserWeapon"); await ConnectToContract(); string guns = JsonUtility.ToJson(jsonGunState); await this.contract.CallAsync("setUserWeapon", guns); Debug.Log("end setUserWeapon"); }
public async Task <JsonGunState> GetWeapons() { await ConnectToContract(); Debug.Log("itemOwernship getWeapons"); GetWeaponsOutput result = await this.contract.StaticCallDtoTypeOutputAsync <GetWeaponsOutput>("getWeapons"); JsonGunState jsonGunState = JsonUtility.FromJson <JsonGunState>(result.state); Debug.Log(jsonGunState.guns); return(jsonGunState); }
public async Task <JsonGunState> getUnownedWeaponList() { await ConnectToContract(); Debug.Log("getUnownedWeaponList"); GetWeaponsOutput result = await this.contract.StaticCallDtoTypeOutputAsync <GetWeaponsOutput>("getWeaponList"); Debug.Log(result.state); JsonGunState jsonGunState = JsonUtility.FromJson <JsonGunState>(result.state); return(jsonGunState); }
public async Task sellWeapon(uint _price, ItemOwnershipContractClient OwnerClient, JsonGunState.Gun gun) { try { await ConnectToContract(); Debug.Log("SellWeapon start"); await this.contract.CallAsync("sellWeapon", _price); Debug.Log("겜매니저 컨트ㅐㄺ트 클라이언트 가격 : " + _price); Debug.Log("Sell"); JsonGunState jsonGunState = await OwnerClient.GetWeapons(); Debug.Log("Get"); if (jsonGunState == null) { return; } int i = 0; Debug.Log("find Remove"); Debug.Log(jsonGunState.guns); Debug.Log(gun.index); foreach (JsonGunState.Gun g in jsonGunState.guns) { if (g.name == gun.name) { break; } i++; } Debug.Log("sell Wepon@@@@@@@@@@@@@@:" + jsonGunState.guns[i].name); jsonGunState.guns.RemoveAt(i); Debug.Log("Remove"); await OwnerClient.setUserWeapon(jsonGunState); Debug.Log("Sell Weapon End"); } catch (Exception e) { Debug.Log(e); } }
public async Task setUserWeapons() { try { Debug.Log("Shop setUserWeapons"); this.myGunState = await this.OwnerClient.GetWeapons(); if (this.myGunState == null) { this.myGunState = new JsonGunState(); } Debug.Log("getWeapons End"); Debug.Log(myGunState.guns); for (int i = 0; i < newGunsInShop.Length; i++) { if (String.IsNullOrEmpty(newGunsInShop[i])) { break; } else { string gunName = newGunsInShop[i]; Debug.Log(gunName); foreach (weapons.Gun g in this.weaponList.guns) { Debug.Log("weapon guname" + g.name); if (g.name == gunName) { Debug.Log("setUserWeapons:" + gunName); JsonGunState.Gun tempGun; tempGun.name = g.name; tempGun.price = g.price; tempGun.min_attack = g.min_attack; tempGun.max_attack = g.max_attack; tempGun.index = g.index; this.myGunState.guns.Add(tempGun); await this.OwnerClient.setUserWeapon(this.myGunState); } } } infoManager.newGuns[i] = null; } }catch (Exception e) { Debug.Log(e); } }
public async Task <JsonGunState> getUnownedWeapons() { try { await ConnectToContract(); Debug.Log("getUnownedWeapons start"); getUnownedWeaponsOutput result = await this.contract.StaticCallDtoTypeOutputAsync <getUnownedWeaponsOutput>("getUnownedWeapons"); Debug.Log(result.state); Debug.Log("getUnownedWeapons Finish"); JsonGunState jsonGunState = JsonUtility.FromJson <JsonGunState>(result.state); return(jsonGunState); } catch (Exception e) { Debug.Log(e); return(new JsonGunState()); } }
public async Task sellWeapon(int _id, ItemOwnershipContractClient OwnerClient, BankContractClient BankClient) { try{ await ConnectToContract(); Debug.Log("sellWepon start"); JsonGunState jsonGunState = await OwnerClient.GetWeapons(); if (jsonGunState == null) { return; } jsonGunState.guns.RemoveAt(_id); await OwnerClient.setUserWeapon(jsonGunState); Debug.Log("sellWeapon End"); }catch (Exception e) { Debug.Log(e); } }
private async Task ConnectFactoryClient() { try { await this.FactoryClient.ConnectToContract(); Debug.Log("Factory Client Start"); Debug.Log("start JsonGunState:"); // 블록체인에 저장할 데이터 JsonGunState.Gun gun = new JsonGunState.Gun { max_attack = 100000, min_attack = 43434, name = "rare_handgun", price = 4000, index = 0 }; JsonGunState.Gun gun2 = new JsonGunState.Gun { max_attack = 1000, min_attack = 5534, name = "rare_riple", price = 6000, index = 1 }; JsonGunState.Gun gun3 = new JsonGunState.Gun { max_attack = 1001, min_attack = 5531, name = "rare_machinegun", price = 8000, index = 2 }; JsonGunState.Gun gun4 = new JsonGunState.Gun { max_attack = 1002, min_attack = 5532, name = "rare_powergun", price = 10000, index = 3 }; JsonGunState.Gun gun5 = new JsonGunState.Gun { max_attack = 1003, min_attack = 5533, name = "rare_destroygun", price = 12000, index = 4 }; JsonGunState.Gun gun6 = new JsonGunState.Gun { max_attack = 100000, min_attack = 43434, name = "epic_handgun", price = 7000, index = 5 }; JsonGunState.Gun gun7 = new JsonGunState.Gun { max_attack = 1000, min_attack = 5534, name = "epic_riple", price = 10000, index = 6 }; JsonGunState.Gun gun8 = new JsonGunState.Gun { max_attack = 1001, min_attack = 5531, name = "epic_machinegun", price = 13000, index = 7 }; JsonGunState.Gun gun9 = new JsonGunState.Gun { max_attack = 1002, min_attack = 5532, name = "epic_powergun", price = 16000, index = 8 }; JsonGunState.Gun gun10 = new JsonGunState.Gun { max_attack = 1003, min_attack = 5533, name = "epic_destroygun", price = 19000, index = 9 }; JsonGunState.Gun gun11 = new JsonGunState.Gun { max_attack = 100000, min_attack = 43434, name = "normal_handgun", price = 1000, index = 10 }; JsonGunState.Gun gun12 = new JsonGunState.Gun { max_attack = 1000, min_attack = 5534, name = "normal_riple", price = 2000, index = 11 }; JsonGunState.Gun gun13 = new JsonGunState.Gun { max_attack = 1001, min_attack = 5531, name = "normal_machinegun", price = 3000, index = 12 }; JsonGunState.Gun gun14 = new JsonGunState.Gun { max_attack = 1002, min_attack = 5532, name = "normal_powergun", price = 4000, index = 13 }; JsonGunState.Gun gun15 = new JsonGunState.Gun { max_attack = 1003, min_attack = 5533, name = "normal_destroygun", price = 5000, index = 14 }; this.jsonGunState.guns.Add(gun); this.jsonGunState.guns.Add(gun2); this.jsonGunState.guns.Add(gun3); this.jsonGunState.guns.Add(gun4); this.jsonGunState.guns.Add(gun5); this.jsonGunState.guns.Add(gun6); this.jsonGunState.guns.Add(gun7); this.jsonGunState.guns.Add(gun8); this.jsonGunState.guns.Add(gun9); this.jsonGunState.guns.Add(gun10); this.jsonGunState.guns.Add(gun11); this.jsonGunState.guns.Add(gun12); this.jsonGunState.guns.Add(gun13); this.jsonGunState.guns.Add(gun14); this.jsonGunState.guns.Add(gun15); await this.FactoryClient.MakeWeapon(this.jsonGunState); JsonGunState testGuns = await this.FactoryClient.GetWeapons(); foreach (JsonGunState.Gun g in testGuns.guns) { Debug.Log(g.name); Debug.Log(g.price); Debug.Log(g.index); } Debug.Log("test JsonGunState:"); } catch (Exception e) { Debug.Log(e); } }