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 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); } }
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); } }