public IEnumerator coLoadWormHoles() { WWWForm wwwform = new WWWForm(); wwwform.AddField("username", "kmw8sf"); WWW request = new WWW("localhost:8080/myapp/world/wormholes", wwwform); yield return(request); WormHole[] wormholes = JsonMapper.ToObject <WormHole[]>(request.text); destroyWormHoleObjects(); currentWormHoleObjects = new GameObject[wormholes.Length]; for (int i = 0; i < wormholes.Length; i++) { GameObject wormholeObj = (GameObject)Instantiate(prefab, wormholes[i].getWorldCoords(), new Quaternion()); currentWormHoleObjects[i] = wormholeObj; wormholeObj.name = "WormHole" + wormholes[i].wormholeId; ObjectInstanceDictionary.registerGameObject(wormholeObj.name, wormholeObj); wormholes[i].gameObject = wormholeObj; angleTowardsBase(wormholeObj, wormholes[i].b.getGameObject()); GameObject objectInfoPanel = (GameObject)Instantiate(objectInfoPanelPrefab, new Vector3(0, 0, 0), Quaternion.identity); objectInfoPanel.transform.SetParent(GenerateWorld.instance.canvas.transform, false); // TODO: check if I need the following line objectInfoPanel.GetComponent <ObjectInfoPanelScript>().o = wormholeObj; wormholeObj.GetComponent <InstanceObjectScript>().instanceObject = wormholes[i]; wormholes[i].objectInfoPanel = objectInfoPanel; objectInfoPanel.GetComponent <RectTransform>().pivot = wormholeObj.GetComponent <UIPlacer>().getPivot(); } EventManager.positionText(); AttackHandler.instance.loadAttacks(); UnderAttackHandler.instance.loadUnderAttacks(); }
private IEnumerator coClearBases() { //WWW request = RequestService.makeRequest ("world/clear", currentBases [0].GetComponent<TouchBase>().b); WWW request = RequestService.makeRequest("world/clear", ObjectInstanceDictionary.getObjectInstanceById("Base", 1)); yield return(request); ObjectInstanceDictionary.clearDictionary(); UpdateGold.instance.syncGold(); GenerateWorld.instance.resetWorldView(); }
public void addBase(Base b) { Vector3 loc = b.convertBaseCoordsToWorld(); // adjust for base prefab loc = loc + new Vector3(0, 0, .5f); GameObject baseObj = (GameObject)Instantiate(basePrefab, loc, basePrefab.transform.rotation); baseObj.GetComponent <Renderer>().material = materials[b.colorId % materials.Length]; TouchBase tb = baseObj.GetComponent <TouchBase>(); tb.b = b; baseObj.name = "Base" + b.baseId; ObjectInstanceDictionary.registerGameObject(baseObj.name, baseObj); baseObj.GetComponent <InstanceObjectScript>().instanceObject = b; b.gameObject = baseObj; currentBases.Add(baseObj); GameObject objectInfoPanel = (GameObject)Instantiate(objectInfoPanelPrefab, new Vector3(0, 0, 0), Quaternion.identity); objectInfoPanel.transform.SetParent(canvas.transform, false); // TODO: check if I need the following line objectInfoPanel.GetComponent <ObjectInfoPanelScript>().o = baseObj; baseObj.GetComponent <BaseScript>().objectInfoPanel = objectInfoPanel; GameObject prodText = (GameObject)Instantiate(OIPItemPrefab, new Vector3(0, 0, -1000), Quaternion.identity); prodText.transform.SetParent(objectInfoPanel.transform, false); prodText.GetComponentInChildren <Image>().sprite = prodSprite; tb.b.updateProdRateEvent += prodText.GetComponent <OIPItemScript>().updateContent; GameObject unitsText = (GameObject)Instantiate(OIPItemPrefab, new Vector3(0, 0, 0), Quaternion.identity); unitsText.transform.SetParent(objectInfoPanel.transform, false); unitsText.GetComponentInChildren <Image>().sprite = unitSprite; tb.b.updateUnitsEvent += unitsText.GetComponent <OIPItemScript>().updateContent; // create progress bar ui // There is always one progress bar per base and it just hides and shows GameObject progressBar = (GameObject)Instantiate(ProgressBarPrefab, new Vector3(0, 0, 0), Quaternion.identity); progressBar.transform.SetParent(objectInfoPanel.transform); progressBar.GetComponentInChildren <Image> ().sprite = addUnitSprite; progressBar.SetActive(false); tb.b.updateAddUnitProgress += progressBar.GetComponent <OIPProgressScript> ().updateContent; }
public GameObject createPortal(Vector3 p1, Vector3 p2, Portal2 portal) { GameObject portalObj = (GameObject)Instantiate(portalPrefab, (p1 + p2) / 2, Quaternion.identity); if (portal != null) { portalObj.name = "Portal" + portal.portalId; portal.gameObject = portalObj; portalObj.GetComponent <InstanceObjectScript> ().instanceObject = portal; ObjectInstanceDictionary.registerGameObject(portalObj.name, portalObj); } else { portalObj.name = "Portal" + -1; } scalePortalBetweenPoints(portalObj, p1, p2); rotatePortalBetweenPoints(portalObj, p1, p2); return(portalObj); }
private static void processAttackDefendingResults(Attack attack, AttackResultObj result) { bool isWinner = result.winnerUsername.Equals(Globals.username); Debug.Log("AttackID: " + attack.attackId + " Won? " + isWinner + " result: " + result); if (isWinner) { Debug.Log("Survived attack! Surviving units - New num units: " + result.numUnitsLeft); // Update num units Base b = (Base)ObjectInstanceDictionary.getObjectInstanceById("Base", attack.defenderBaseId); GenerateWorld.instance.message.text = "Survived getting attacked! Lost " + (b.units - result.numUnitsLeft) + " units"; b.units = result.numUnitsLeft; EventManager.positionText(); WormHole w = attack.defenderWormHole; w.attackState = AttackState.NoAttack; // Remove progress bar } else { GenerateWorld.instance.message.text = "Defeated in attack. Base lost."; Debug.Log("Didn't survive attack - lost base BaseId: " + attack.defenderBaseId); // Delete base and connecting portals // Get all connecting portals foreach (int pId in result.lostPortalIds) { GameObject p = ObjectInstanceDictionary.getObjectInstanceById("Portal", pId).gameObject; Destroy(p); } // TODO: Delete all of the base's wormholes, not just the one that the attack came through Destroy(attack.defenderWormHole.gameObject); GameObject b = ObjectInstanceDictionary.getObjectInstanceById("Base", attack.defenderBaseId).gameObject; Destroy(b.GetComponent <BaseScript>().objectInfoPanel); Destroy(b); EventManager.positionText(); } }
public IEnumerator coOnAttackConfirmed(int numUnits) { WormHole w = (WormHole)gameObject.GetComponent <InstanceObjectScript> ().instanceObject; Base b = w.b; WWWForm wwwform = new WWWForm(); wwwform.AddField("username", "kmw8sf"); wwwform.AddField("baseId", b.baseId); wwwform.AddField("wormholeId", w.wormholeId); wwwform.AddField("numUnits", numUnits); WWW request = new WWW("localhost:8080/myapp/world/attack", wwwform); yield return(request); Attack attack = LitJson.JsonMapper.ToObject <Attack> (request.text); if (attack.attackerBaseId != null) { AttackHandler.instance.addAttack(attack); Base attackBase = (Base)ObjectInstanceDictionary.getObjectInstanceById("Base", attack.attackerBaseId); attackBase.units -= numUnits; EventManager.positionText(); } }