private void performMove(Unit unit, Tile dest) { dest.gameObject.networkView.RPC ("setOccupyingUnitNet", RPCMode.AllBuffered, unit.gameObject.networkView.viewID); unit.gameObject.networkView.RPC ("setLocationNet", RPCMode.AllBuffered, dest.gameObject.networkView.viewID); Village srcVillage = unit.getVillage (); UnitType srcUnitType = unit.getUnitType(); LandType destLandType = dest.getLandType (); if (destLandType == LandType.Meadow) { if (srcUnitType==UnitType.CANNON||srcUnitType==UnitType.SOLDIER||srcUnitType==UnitType.KNIGHT) { if (dest.hasRoad) { unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.Moved); } else { gameGUI.displayError (@"You have trampled the crops!"); dest.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Grass); dest.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered); } if (srcUnitType == UnitType.CANNON) { unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.CannonMoved); } } } else if (destLandType == LandType.Trees) { dest.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Grass); unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.ChoppingTree); srcVillage.gameObject.networkView.RPC ("addWoodNet",RPCMode.AllBuffered,1); dest.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered); } else if (destLandType == LandType.Tombstone) { dest.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Grass); unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.ClearingTombstone); dest.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered); } //movePrefab (unit,new Vector3 (dest.point.x, 0.15f,dest.point.y)); this.gameObject.networkView.RPC ("moveUnitPrefabNet", RPCMode.AllBuffered, unit.networkView.viewID, new Vector3 (dest.point.x, 0.15f, dest.point.y)); }
private bool canUnitMove(Unit u, Tile t) { // castle check foreach (Tile n in t.getNeighbours()) { try{ Village v = n.getVillage (); VillageType vt = v.getMyType(); Player them = v.getPlayer (); Player you = u.getVillage().getPlayer (); if (them!=you && vt==VillageType.Castle){ gameGUI.displayError (@"I cant even get near to their castle!"); return false; } } catch { continue; } } // friendly checks if (t.getVillage ()==null || t.getVillage ().controlledBy == u.getVillage ().controlledBy) { if((t.getLandType () == LandType.Trees || t.getLandType () == LandType.Tombstone) && (u.getUnitType() == UnitType.KNIGHT || u.getUnitType() == UnitType.CANNON)){ gameGUI.displayError (@"Knights are too fancy to do manual labour. ¯\(°_o)/¯"); return false; } else if (t.checkTower ()){ gameGUI.displayError (@"The tower doesn't want you to stand ontop of it. ¯\(°_o)/¯"); return false; } else if (t.getOccupyingUnit () != null) { gameGUI.displayError (@"There is a unit already standing there!!! ¯\(°_o)/¯"); return false; } else { return true; } // enemy checks } else if (t.getVillage ().controlledBy != u.getVillage ().controlledBy){ if (u.getUnitType()==UnitType.PEASANT){ gameGUI.displayError (@"Peasants cant attack! ¯\(°_o)/¯"); return false; } else if (u.getUnitType()==UnitType.CANNON){ gameGUI.displayError (@"Cannons cant move into enemy territory"); return false; } else if((t.getLandType () == LandType.Trees || t.getLandType () == LandType.Tombstone) && u.getUnitType() == UnitType.KNIGHT){ gameGUI.displayError (@"Knights are too fancy to do manual labour. ¯\(°_o)/¯"); return false; } else if (t.checkTower () == true && (u.getUnitType()!= UnitType.KNIGHT || u.getUnitType () != UnitType.SOLDIER)){ gameGUI.displayError (@"Only a soldiers and knights can destroy an enemy tower. ¯\(°_o)/¯"); return false; } else if (t.getOccupyingUnit()!=null && u.getUnitType()<=t.getOccupyingUnit().getUnitType()){ if (t.getOccupyingUnit().getUnitType()==UnitType.CANNON && u.getUnitType()<=UnitType.SOLDIER){ gameGUI.displayError (@"You need a knight to take out their cannon"); return false; } gameGUI.displayError (@"Your unit cant fight theirs. ¯\(°_o)/¯"); return false; } else { return true; } } //default return false; }