private void _onDetectionZoneBodyExited(Node body) { if (body.HasMethod(nameof(Agent.GetCurrentTeam)) && body != _agent) { Agent agent = (Agent)body; // Clean up current target/possible target if (body == _targetAgent) { _targetAgent = null; } if (_targetAgents.ContainsKey(agent.GetUnitName())) { _targetAgents.Remove(agent.GetUnitName()); } // If target is not vaild, then will try to check for next target if (_targetAgent == null || IsInstanceValid(_targetAgent)) { // Compute target _checkTarget(); } } }
private void _on_RemoveSkill_pressed() { Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Skill") as Godot.Collections.Dictionary; if (jsonDictionary.Keys.Count > 1) { int skillId = skillSelected; while (skillId < jsonDictionary.Keys.Count - 1) { jsonDictionary["skill" + skillId] = jsonDictionary["skill" + (skillId + 1)]; skillId += 1; } jsonDictionary.Remove("skill" + skillId); this.GetParent().GetParent().Call("StoreData", "Skill", jsonDictionary); GetNode <OptionButton>("SkillButton").RemoveItem(skillSelected); if (skillSelected == 0) { GetNode <OptionButton>("SkillButton").Select(skillSelected + 1); skillSelected += 1; } else { GetNode <OptionButton>("SkillButton").Select(skillSelected - 1); skillSelected -= 1; } GetNode <OptionButton>("SkillButton").Select(skillSelected); RefreshData(skillSelected); } }
private void _on_RemoveClass_pressed() { Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Class") as Godot.Collections.Dictionary; if (jsonDictionary.Keys.Count > 1) { int classId = classSelected; while (classId < jsonDictionary.Keys.Count - 1) { jsonDictionary["class" + classId] = jsonDictionary["class" + (classId + 1)]; classId += 1; } jsonDictionary.Remove("class" + classId); this.GetParent().GetParent().Call("StoreData", "Class", jsonDictionary); GetNode <OptionButton>("ClassButton").RemoveItem(classSelected); if (classSelected == 0) { GetNode <OptionButton>("ClassButton").Select(classSelected + 1); classSelected += 1; } else { GetNode <OptionButton>("ClassButton").Select(classSelected - 1); classSelected -= 1; } GetNode <OptionButton>("ClassButton").Select(classSelected); RefreshData(classSelected); } }
private void _on_RemoveWeapon_pressed() { Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Weapon") as Godot.Collections.Dictionary; if (jsonDictionary.Keys.Count > 1) { int weaponId = weaponSelected; while (weaponId < jsonDictionary.Keys.Count - 1) { jsonDictionary["weapon" + weaponId] = jsonDictionary["weapon" + (weaponId + 1)]; weaponId += 1; } jsonDictionary.Remove("weapon" + weaponId); this.GetParent().GetParent().Call("StoreData", "Weapon", jsonDictionary); GetNode <OptionButton>("WeaponButton").RemoveItem(weaponSelected); if (weaponSelected == 0) { GetNode <OptionButton>("WeaponButton").Select(weaponSelected + 1); weaponSelected += 1; } else { GetNode <OptionButton>("WeaponButton").Select(weaponSelected - 1); weaponSelected -= 1; } GetNode <OptionButton>("WeaponButton").Select(weaponSelected); RefreshData(weaponSelected); } }
public void FreePort(RoadConnectorSide side_from, RoadConnectorSide side_to) { foreach (var item in connectedPorts.Where(tf => tf.Key == side_from.GetPath() && tf.Value == side_to.GetPath())) { connectedPorts.Remove(item); } }
private void _on_RemoveEnemy_pressed() { Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Enemy") as Godot.Collections.Dictionary; if (jsonDictionary.Keys.Count > 1) { int enemyId = enemySelected; while (enemyId < jsonDictionary.Keys.Count - 1) { jsonDictionary["Enemy" + enemyId] = jsonDictionary["Enemy" + (enemyId + 1)]; enemyId += 1; } jsonDictionary.Remove("Enemy" + enemyId); this.GetParent().GetParent().Call("StoreData", "Enemy", jsonDictionary); GetNode <OptionButton>("EnemyButton").RemoveItem(enemySelected); if (enemySelected == 0) { GetNode <OptionButton>("EnemyButton").Select(enemySelected + 1); enemySelected += 1; } else { GetNode <OptionButton>("EnemyButton").Select(enemySelected - 1); enemySelected -= 1; } GetNode <OptionButton>("EnemyButton").Select(enemySelected); RefreshData(enemySelected); } }
private void _on_RemoveCharacterButton_pressed() { Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Character") as Godot.Collections.Dictionary; if (jsonDictionary.Keys.Count > 1) { int chara = characterSelected; while (chara < jsonDictionary.Keys.Count - 1) { jsonDictionary["chara" + chara] = jsonDictionary["chara" + (chara + 1)]; chara += 1; } jsonDictionary.Remove("chara" + chara); this.GetParent().GetParent().Call("StoreData", "Character", jsonDictionary); GetNode <OptionButton>("CharacterButton").RemoveItem(characterSelected); if (characterSelected == 0) { GetNode <OptionButton>("CharacterButton").Select(characterSelected + 1); characterSelected += 1; } else { GetNode <OptionButton>("CharacterButton").Select(characterSelected - 1); characterSelected -= 1; } GetNode <OptionButton>("CharacterButton").Select(characterSelected); RefreshData(characterSelected); } }
private void _on_RemoveArmor_pressed() { Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Armor") as Godot.Collections.Dictionary; if (jsonDictionary.Keys.Count > 1) { int armorId = armorSelected; while (armorId < jsonDictionary.Keys.Count - 1) { jsonDictionary["armor" + armorId] = jsonDictionary["armor" + (armorId + 1)]; armorId += 1; } jsonDictionary.Remove("armor" + armorId); this.GetParent().GetParent().Call("StoreData", "Armor", jsonDictionary); GetNode <OptionButton>("ArmorButton").RemoveItem(armorSelected); if (armorSelected == 0) { GetNode <OptionButton>("ArmorButton").Select(armorSelected + 1); armorSelected += 1; } else { GetNode <OptionButton>("ArmorButton").Select(armorSelected - 1); armorSelected -= 1; } GetNode <OptionButton>("ArmorButton").Select(armorSelected); RefreshData(armorSelected); } }
private void _on_RemoveItem_pressed() { Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Item") as Godot.Collections.Dictionary; if (jsonDictionary.Keys.Count > 1) { int itemId = itemSelected; while (itemId < jsonDictionary.Keys.Count - 1) { jsonDictionary["item" + itemId] = jsonDictionary["item" + (itemId + 1)]; itemId += 1; } jsonDictionary.Remove("item" + itemId); this.GetParent().GetParent().Call("StoreData", "Item", jsonDictionary); GetNode <OptionButton>("ItemButton").RemoveItem(itemSelected); if (itemSelected == 0) { GetNode <OptionButton>("ItemButton").Select(itemSelected + 1); itemSelected += 1; } else { GetNode <OptionButton>("ItemButton").Select(itemSelected - 1); itemSelected -= 1; } GetNode <OptionButton>("ItemButton").Select(itemSelected); RefreshData(itemSelected); } }
// Unequip weapon at given index public void UnequipItem(Weapon.WeaponOrder weaponOrder, int weaponIndex) { int itemIndex = GetEquipItemIndex(weaponOrder, weaponIndex); _agent.UnequipWeapon(weaponOrder, weaponIndex); _equipmentIndex.Remove((int)weaponOrder + "_" + weaponIndex); _usedIndex.Remove(itemIndex); EmitSignal(nameof(WeaponChangeSignal), weaponOrder, weaponIndex); EmitSignal(nameof(InventoryChangeSignal)); }
public void RemoveAgent(Agent agent) { if (_agents.ContainsKey(agent.GetUnitName())) { // Add agent to dictonary _agents.Remove(agent.GetUnitName()); Sprite agentMarker = _agentMarkers[agent.GetUnitName()]; // Add marker to dictionary _agentMarkers.Remove(agent.GetUnitName()); agentMarker.QueueFree(); } }
private void _onObstacleDestroy(String obstacleName) { if (GetTree().IsNetworkServer()) { if (obstacles.ContainsKey(obstacleName)) { obstacles.Remove(obstacleName); } obstaclesDestroyed.Add(obstacleName); destroyObstacle(obstacleName); Rpc(nameof(destroyObstacle), obstacleName); } }
public bool Write <T>(string key, T value, bool save = true) { T oldValue = Read <T>(key); if (data.Contains(key)) { data.Remove(key); } data.Add(key, value); if (save) { Save(); } else { Dirty = true; } EmitSignal(nameof(DataChanged), key, new SignalParameter(oldValue), new SignalParameter(value)); return(true); }
// Entrypoint to the pathfinding algorithm. Will return either null or an array of Vector2s public Godot.Collections.Array path(Vector2 start, Vector2 end, World2D space_state, Godot.Collections.Array exclude_bodies, GameWorld gameWorld) { this.gameWorld = gameWorld; int iteration = 0; // Update class variables space = space_state; excludes = exclude_bodies; start = normalizePoint(start); end = normalizePoint(end); String startId = vector2ToId(start); String endId = vector2ToId(end); cameFrom = new Godot.Collections.Dictionary(); openSet = new Godot.Collections.Dictionary(); openSet.Add(startId, start); gScore = new Godot.Collections.Dictionary(); fScore = new Godot.Collections.Dictionary(); gScore.Add(startId, 0.0f); fScore.Add(startId, hDistance(end, start)); // As long as we have points to visit, let's visit them // But not more than max_iterations times. while (openSet.Count > 0 && iteration < max_iterations) { // We're going to grab the current best tile, then look at its neighbors String currentId = findSmallestFScore(); Vector2 current = (Vector2)openSet[currentId]; // We reached the goal, so stop here and return the path. if (currentId == endId) { return(reconstructPath(current)); } openSet.Remove(currentId); Godot.Collections.Array neighbors = getNeighbors(current); foreach (Vector2 neighbor in neighbors) { String neighborId = vector2ToId(neighbor); float neighborGScore = Int32.MaxValue; // We've seen this neighbor before, likely when passing through from a different path. if (gScore.Contains(neighborId)) { neighborGScore = (float)gScore[neighborId]; } // This is the "new" gScore as taken through _this_ path, not the previous path float tentativeGscore = ((float)(gScore[currentId])) + GRID_SIZE; // If this path is better than the previous path through this neighbor, record it if (tentativeGscore < neighborGScore) { // This lets us work backwards through best-points later if (!cameFrom.Contains(neighborId)) { cameFrom.Add(neighborId, current); } // gScore is the actual distance it took to get here from the start if (!gScore.Contains(neighborId)) { gScore.Add(neighborId, tentativeGscore); } // fScore is the actual distance from the start plus the estimated distance to the end // Whoever has the best fScore in the openSet gets our attention next // Therefore we are always inspecting the current best-guess-path if (!fScore.Contains(neighborId)) { fScore.Add(neighborId, tentativeGscore + hDistance(end, neighbor)); } // This would allow revisiting if the heuristic were not consistent // But in our use case we should not end up revisiting nodes if (!openSet.Contains(neighborId)) { openSet.Add(neighborId, neighbor); } } } iteration++; } // No path found return(null); }