protected Marker(TerrainIns terrain, Vector2 location) { Terrain = terrain; HasElement = terrain.HasElement; HasMonster = terrain.HasMonster; Location = location; CharMap = new char[16, 16]; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { CharMap[x, y] = 'E'; } } }
//Terrain internal void SetActiveTerrain(TerrainIns currentTerrain) { _terrain = currentTerrain; }
public Marker(TerrainIns terrain, Vector2 location, int key) { Terrain = terrain; Location = location; MarkerIndex = key; }
public void OpenMiniMap() { Vector3 currentPos = _player.position; Vector2 mapPos = _terrainManager.WorldToMapPosition(currentPos); Debug.Log("OpenMiniMap " + "currentPos =" + currentPos + "mapPos =" + mapPos); //Preparing to switch the scene GameObject go = new GameObject(); //Make go unDestroyable GameObject.DontDestroyOnLoad(go); var starter = go.AddComponent<SceneStarter>(); starter.Key = Key; starter.MapPosition = mapPos; starter.PreviousPosition = currentPos; go.name = "Scene Starter"; //switch the scene SceneManager.LoadScene(SceneSettings.SceneIdForMiniMap); } private void LoadCaches() { foreach (var item in _cache.Find("Digging", transform.position, _horizontalTiles, false)) CreateDigging(item.Location,false); foreach (var item in _cache.Find("Item", transform.position, _horizontalTiles, false)) CreateItem(item.Location, Int32.Parse(item.Content)); } //Terrains public TerrainIns SelectTerrain(float x, float y) { return SelectTerrain(new Vector2(x, y)); } public TerrainIns SelectTerrain(Vector2 pos) { return Marker.Closest(_markers, pos, Key).Terrain; } //Elements private void SetAvailableMarketElements(TerrainIns terrain) { _elementTypes.Clear(); if (terrain.HasElement) for (int i = 0; i < _allElements.Count; i++) if (_allElements[i].FavoriteTerrainTypes == terrain.Type) _elementTypes.Add(_allElements[i]); } void SetElements(char[,] charMap, Vector2 location) { int elementMass = RandomHelper.Range(location.x, location.y, Key, 14 * 14) / 4; for (int i = 0; i < elementMass; i++) {
float distance = Vector2.Distance(bLoc, pos); if (distance < 0.5) return element; } return null; } internal bool DestroyElement(ActiveElementType element, bool useTool) { if (useTool) if (!_inv.ElementToolUse(element.ElementTypeInUse)) return false; _elements.Remove(element); Destroy(element.gameObject); return true; } //Monsters private void SetAvailableMarketMonsters(TerrainIns terrain) { //Todo:Performance: this get executed 9 time each time the terrain load not good _monsterTypes.Clear(); if (terrain.HasMonster) for (int i = 0; i < _allMonster.Count; i++) if (_allMonster[i].FavoriteTerrainTypes == terrain.Type ) _monsterTypes.Add(_allMonster[i]); } private void SetMonsters(char[,] charMap, Vector2 location) { int monstersMass = RandomHelper.Range(location.x, location.y, Key, 14 * 14) /30; for (int i = 0; i < monstersMass; i++) {
// Update is called once per frame void Update() { if (_inv.InventoryPanelStat()) { return; } InLineOfSight(); var pos = transform.position; pos.z += 0.01f; if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { _popupAction.SetActive(false); var touchLocation = Camera.main.ScreenToWorldPoint(Input.mousePosition); float distance = Vector2.Distance(touchLocation, pos); //AttackTarget Also check AttackInside foreach (var monster in _terrainManager.GetMonster(touchLocation, 0.4f)) { _popupAction.GetComponent <ActionHandler>().SetActiveMonster(monster, transform, "Terrain"); CreateFloatingAction(touchLocation, "Monster"); return; } //Consume Element var currentElement = _terrainManager.GetElement(touchLocation); if (currentElement != null) { if (distance < 1) { _popupAction.GetComponent <ActionHandler>().SetActiveElement(currentElement); CreateFloatingAction(touchLocation, "Element"); return; } } //Pick Up Item var currentItem = _terrainManager.GetDropItem(touchLocation); if (currentItem != null) { print("currentItem happening :" + distance + " _item:" + currentItem.ItemTypeInUse.Name); if (distance < 1) { _popupAction.GetComponent <ActionHandler>().SetActiveItem(currentItem, "Terrain"); _popupAction.GetComponent <ActionHandler>().GrabItem(); //Performance: Less click approach //CreateFloatingAction(touchLocation, "Item"); } else { _GUIManager.PrintMessage("Too Far from this Target!", Color.yellow); } return; } //Digging if (distance < 1) { TerrainIns currentTerrain = _terrainManager.SelectTerrain(touchLocation); //print("TerrainIns distance < 1" +currentTerrain.MyInfo()); if (currentTerrain.Digable) { touchLocation.z = pos.z; _popupAction.GetComponent <ActionHandler>().SetActiveTerrain(currentTerrain); CreateFloatingAction(touchLocation, "Dig"); return; } } CreateFloatingAction(touchLocation, "Map"); } }