void Awake() { animationManager = GetComponent<AnimationManager>(); attr = GetComponent<UnitAttributes>(); movement = GetComponent<UnitMovement>(); energyCost = 2; }
void Awake() { mask = -1; attr = GetComponent<UnitAttributes>(); movement = GetComponent<UnitMovement>(); animationManager = GetComponent<AnimationManager>(); }
// Use this for initialization void Awake() { this.identity = this.gameObject.GetComponent<Identity> (); this.range = DataManager.Instance.unitDatas [identity.unitType].stats [Stat.Range]; this.atkDmg = DataManager.Instance.unitDatas [identity.unitType].stats [Stat.Attack]; um = gameObject.GetComponent<UnitMovement> (); animator = this.gameObject.GetComponent<Animator>(); }
private bool AttackNearestEnemyMelee() { if (currentSelectedMeleeWeapon != null) { //die ist nur != null wenn diese selected ist if (attackAtWill && !didWeSendHimAwayFromAFight) { //also nur wenn er stillsteht UnitMovement nearestEnemy = GetNearestTargetInRange(attackAtWillDistance); if (nearestEnemy != null) { Attack(nearestEnemy); return(true); } } } return(false); }
private bool AttackNearestEnemyMissile() { if (currentSelectedMissileWeapon != null) { //die ist nur != null wenn diese selected ist if (fireAtWill && !didWeSendHimAwayFromAFight) //!agent.pathPending && !agent.hasPath) { //also nur wenn er stillsteht UnitMovement nearestEnemy = GetNearestTargetInRange(currentSelectedMissileWeapon.missileRange); if (nearestEnemy != null) { Attack(nearestEnemy); return(true); } } } return(false); }
protected override IEnumerator PerformAction() { GameObject explosion = Instantiate(explosionPrefab); explosion.transform.position = actor.transform.position; float adjOuterRadius = outerRadius * actor.AbilityRangeMultiplier.Current; Collider[] colliders = Physics.OverlapSphere(actor.transform.position, adjOuterRadius); foreach (Collider coll in colliders) { Vector3 delta = coll.transform.position - actor.transform.position; float dist = delta.magnitude; float t = Mathf.Clamp01((dist - innerRadius) / (adjOuterRadius - innerRadius)); float power = powerCurve.Evaluate(t);//Mathf.Clamp01((dist - innerRadius) / (adjOuterRadius - innerRadius)); Rigidbody rb = coll.GetComponentInParent <Rigidbody>(); Unit target = coll.GetComponentInParent <Unit>(); if (rb != null && target != actor) { Vector3 force = delta.normalized * (power * (innerForce - outerForce) + outerForce); if (target != null) { UnitMovement movement = target.GetComponent <UnitMovement>(); movement.AddForce(actor, force); } else { rb.AddForce(force); } } Health health = coll.GetComponentInParent <Health>(); if (health != null && target != actor) { float damageAmount = power * (innerDamage - outerDamage) + outerDamage; DamageInfo damageInfo = new DamageInfo(this, damageAmount, damageType); health.Damage(damageInfo); } } DamageInfo selfDamageInfo = new DamageInfo(this, selfDamage, damageType); actor.Health.Damage(selfDamageInfo); yield break; }
private static void UnitsInGameListRemoveUnit(UnitMovement unitToRemoveFromList) { List <UnitMovement> temp = new List <UnitMovement>(); foreach (UnitMovement unit in unitsInGameList) { if (unit.gameObject != unitToRemoveFromList.gameObject) { temp.Add(unit); } } unitsInGameList.Clear(); unitsInGameList = temp; QueueOfUnits.QueueHasChanged = true; }
public Dictionary <Tile, bool> GetAllLegalTilesAndIfTheyAreSafe(UnitMovement unit, bool isAffectedByCombat) { Dictionary <Tile, bool> theDictionary = new Dictionary <Tile, bool>(); for (int i = 0; i < Map.mapWidth; i++) { for (int j = 0; j < Map.mapHeight; j++) { if (IsTileLegal(i, j, unit, isAffectedByCombat)) { theDictionary.Add(Map.Board[i, j], EnemyOccupations[i, j]); } } } // Debug.Log("Unit: " + unit + " Tilecount: " + theDictionary.Count); return(theDictionary); }
private void ServerProduceAUnit() { GameObject unitInstance = Instantiate(unitPrefab.gameObject, unitSpawnPoint.position, unitSpawnPoint.rotation); NetworkServer.Spawn(unitInstance, connectionToClient); // random vector in a sphere Vector3 spawnOffset = UnityEngine.Random.insideUnitSphere * spawnMoveRange; // don't want to move up/down... keep that as it was spawnOffset.y = unitSpawnPoint.position.y; // move our unit a touch (so they don't all stack up) UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>(); unitMovement.ServerMove(unitSpawnPoint.position + spawnOffset); }
// public UnitMovement[] UnitsPlaced() { if (presentUnt == 0) { return(null); } else { UnitMovement[] result = new UnitMovement[presentUnt]; for (int r = 0; r < result.Length; r += 1) { result[r] = units[r]; } return(result); } }
private void markTileOnPath() { Quaternion newQuaternion = new Quaternion(); newQuaternion.eulerAngles = new Vector3(90, 0, 0); UnitMovement markedUnit = inputManager.getMarkedUnit(); if (tilePathFinder.getValue() < markedUnit.GetComponent <UnitController>().getActionPoints()) { GameObject.Instantiate(lightPathSource, tileTransform.position + new Vector3(0, height / 2 + lightDistance, 0), newQuaternion); } if (tilePathFinder.getPreviousTile() != null) { tilePathFinder.getPreviousTile().GetComponent <TileSelect>().markTileOnPath(); } }
private void SwitchMapData(UnitMovement unitMovement, Unit unit, Entity unitEntity, int2 targetCoord) { var currentData = _mapDataSystem.MapData[unitMovement.CurrentCellCoord]; currentData.Fraction = Fractions.NEUTRAL; currentData.ContentType = CellContentTypes.EMPTY; currentData.ContentEntity = Entity.Null; _mapDataSystem.MapData[unitMovement.CurrentCellCoord] = currentData; var nextData = _mapDataSystem.MapData[targetCoord]; nextData.Fraction = unit.Fraction; nextData.ContentEntity = unitEntity; nextData.ContentType = CellContentTypes.UNIT; _mapDataSystem.MapData[targetCoord] = nextData; }
public void Setup() { if (prefab != null) { GameObject pawn = Instantiate(prefab, transform.localPosition, Quaternion.identity) as GameObject; pawn.transform.SetParent(transform); if (UIPrefab != null) { GameObject ap = Instantiate(UIPrefab) as GameObject; var buttons = ap.GetComponentsInChildren <Button>(); UnitMovement um = pawn.GetComponent <UnitMovement>(); foreach (var b in buttons) { if (b.name.Contains("Attack")) { b.onClick.AddListener( delegate { um.Action(GameObject.Find("EnemySpawn").transform); } ); } if (b.name.Contains("Endturn")) { b.onClick.AddListener( delegate { um.Action(GameObject.Find("PlayerSpawn").transform); } ); } } } if (pawn.GetComponent <UnitMono>() == null) { throw new UnityException("SpawnController is trying to spawn an object that does not have a unit mono"); } m_unit = pawn.GetComponent <UnitMono>(); if (faceRight) { pawn.transform.forward = Vector3.right; } else { pawn.transform.forward = Vector3.left; } } }
}//Update End //selects Units (Enemies or allies) , selects or deselects multiple with shift key private void HandleLmbUp() { Ray ray = cam.ScreenPointToRay(Input.mousePosition); // this is our mouse position ray RaycastHit hit; //if we hit unit if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Unit") { UnitMovement hittedUnit = hit.collider.gameObject.GetComponent <UnitMovement>(); if (!Input.GetKey(KeyCode.LeftShift)) { if (selectionGroup.Count() > 0) { selectionGroup.DeselectAll(); } selectionGroup.Add(hittedUnit); } else { if (!selectionGroup.Contains(hittedUnit)) { selectionGroup.Add(hittedUnit); } else { selectionGroup.Remove(hittedUnit); hittedUnit.Deselect(); } } selectionGroup.SelectAll(); } else { if (!Input.GetKey(KeyCode.LeftShift)) { if (selectionGroup.Count() > 0) { selectionGroup.DeselectAll(); } } } }
void FinishQC(bool didDie, int unitX, int unitZ) { if (didDie == false) { UnitScript QCUnit = Map.Board[unitX, unitZ].myUnit; QCUnit.isQuittingCombat = true; UnitMovement uMovement = QCUnit.GetComponent <UnitMovement>(); uMovement.CanMove = true; MovementSystem.Instance.DoMovement(uMovement); if (QCUnit.GetComponent <ShootingScript>() != null) { QCUnit.GetComponent <ShootingScript>().hasAlreadyShot = true; } uMovement.CanMove = true; FinalTile = null; } PlayerChoosesWhetherToQC = false; }
// NOTE - currently THIS is JUST doing NORMAL MOVEMENT. Please do not add special movments (like QC) here in ANY WAY! // ALSO - use THIS instead of SendCommand, if its already in a command, obviously. public void DoMovement(UnitMovement unit) { if (GameStateManager.Instance.IsCurrentPlayerAI()) { GameStateManager.Instance.Animate(); } MovementExecutor METool = new MovementExecutor(unit, PathCreator.Instance.GetMovementPath()); if (unit is UnitFlight) { StartCoroutine(METool.Fly((unit as UnitFlight), PathCreator.Instance.Path[PathCreator.Instance.Path.Count - 1].transform.position)); } else { StartCoroutine(METool.Travel()); } TileColouringTool.UncolourAllTiles(); MovementQuestions.Instance.CheckIfAnyMoreUnitsToMove(); }
private void Awake() { enemy = GetComponent <Enemy>(); mController = GetComponent <MovementController>(); anim = GetComponent <Animator>(); mControl = GetComponent <UnitMovement>(); uState = new UnitState(); if (player == null) { player = GameObject.Find("Player"); } shadow.SetActive(false); m_attackTimer = m_attackCooldown; stageEvents = phase1Events.Length; }
//[Command] void CmdSpawnUnit() { GameObject unitInstance = Instantiate(unitPrefab.gameObject, spawnPoint.position, spawnPoint.rotation); NetworkServer.Spawn(unitInstance, connectionToClient); //Vector3 spawnOffset = spawnMoveRange * UnityEngine.Random.onUnitSphere; //spawnOffset.y = unitInstance.transform.position.y; Vector3 spawnOffset = spawnPoint.transform.forward * UnityEngine.Random.Range(2f, 4f); spawnOffset.x = UnityEngine.Random.Range(-3f, 3f); Debug.Log("spawn offset: " + spawnOffset); UnitMovement unitMovement = unitInstance.GetComponent <UnitMovement>(); unitMovement.ServerMove(unitInstance.transform.position + spawnOffset); //TargetSelectNewlySpawnedUnit(connectionToClient, unitInstance); }
public static void RemoveUnit(UnitMovement unitToRemove) { List <UnitMovement> teamList; List <UnitMovement> teamWithoutRemovedUnit; teamList = teams[unitToRemove.tag]; teamWithoutRemovedUnit = new List <UnitMovement>(); foreach (UnitMovement unit in teamList) { if (unit != unitToRemove) { teamWithoutRemovedUnit.Add(unit); } } teams[unitToRemove.tag] = teamWithoutRemovedUnit; UnitsInGameListRemoveUnit(unitToRemove); }
public void ColourPossibleTiles(UnitMovement unit, bool notQuittingCombat) { BFS(unit.GetComponent <UnitScript>().myTile, true); //TileColouringTool.UncolourAllTiles(); //Debug.LogError(unit + " " + colourRed); for (int i = 0; i < Map.mapWidth; i++) { for (int j = 0; j < Map.mapHeight; j++) { if (Distances[i, j] <= unit.GetCurrentMoveSpeed(notQuittingCombat) && Distances[i, j] != -1) { if (notQuittingCombat || EnemyOccupations[i, j] == false) { Map.Board[i, j].TCTool.ColourTileFor(unit.GetComponent <UnitScript>()); } } } } }
protected void InitSupportClasses() { Debug.Log(baseStats.type + " | " + baseStats.moveCosts); //Initialize Sight Class sight = this.gameObject.AddComponent <UnitSight>(); Debug.Log(this + " | " + sight + " | " + overlord + " | " + assets + " | " + mainMap + " | " + baseStats.sight); sight.InitSight(this, overlord, assets.sightSphere, baseStats.sight, mainMap.tileWidth); //Initialize Movement Class move = this.gameObject.AddComponent <UnitMovement> (); move.InitMovement(mainMap, assets, baseStats.speed, baseStats.moveCosts, tileLocation, con); //Initialize Selection Class selection = this.gameObject.AddComponent <UnitSelection> (); selection.InitSelection(this); //initialize body trigger bodyTrig.Init(this, mainMap); }
public Vector3 GetInputDirection(UnitMovement p) { if (!Input.GetMouseButton(0)) { return(Vector2.zero); } Vector3 input = new Vector2(); Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(r, out hit, float.MaxValue, 1 << LayerMask.NameToLayer("PlayerInput"), QueryTriggerInteraction.Collide)) { input = (hit.point - p.transform.position); input.y = 0; input = input.normalized; } return(input); }
public static void AddUnit(UnitMovement unitMovement) { List <UnitMovement> list; if (!teams.ContainsKey(unitMovement.tag)) { list = new List <UnitMovement>(); teams[unitMovement.tag] = list; if (!teamTag.Contains(unitMovement.tag)) { teamTag.Enqueue(unitMovement.tag); } } else { list = teams[unitMovement.tag]; } list.Add(unitMovement); }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { //leftClickPos = GetMousePosition(); RaycastHit2D hit = Physics2D.Raycast(GetMousePosition(), camGirl.transform.forward, 100); if (hit) { GameObject obj = hit.transform.gameObject; if (!selectedObjects.Contains(obj) && obj.tag == "Unit") { selectedObjects.Add(obj); } } } //if (Input.GetMouseButtonUp(0)) //{ // //Collider2D[] colliderArray = Physics2D.OverlapAreaAll(leftClickPos, GetMousePosition()); // foreach (Collider2D collide in colliderArray) // { // Debug.Log(collide); // selectedObjects.Add(collide.gameObject); // // collide.gameObject.transform.Translate(1, 1, 1); // } //} if (Input.GetMouseButtonUp(1)) { foreach (GameObject obj in selectedObjects) { // NavMeshAgent agent = obj.GetComponent(typeof(NavMeshAgent)) as NavMeshAgent; //agent.Warp(obj.transform.position); //agent.SetDestination(GetMousePosition()); UnitMovement uM = obj.GetComponent(typeof(UnitMovement)) as UnitMovement; uM.SetMovePosition(GetMousePosition()); } selectedObjects.Clear(); } }
public bool Damage(float dmg, UnitMovement attacker) { life -= dmg; //Debug.Log("Il me reste : " + life + " Damage ? "+ damage); if(life <= 0) { if(tagToAttack == "FriendlyTAG") { Data.gold += this.loot; Debug.Log ("JE MEURT et je donne mes gold : " + this.loot); } else if(tagToAttack == "EnnemiTAG") { attacker.loot += this.loot; } Destroy(gameObject); return true; } return false; }
private void UnitMovementFSM() { switch (unitMovement) { case UnitMovement.rightClickTargetNode: RightClickTargetNode(); break; case UnitMovement.calculateMoveArea: CreateWalkalbeArea(originalRightClickPosition); break; case UnitMovement.createFormation: FindTargetForSelectedUnits(); break; case UnitMovement.clearLists: listOfVectors.Clear(); unitMovement = UnitMovement.rightClickTargetNode; break; } }
public override void finishCast() { List <GameObject> targets = null; if (parent.tag.Equals("Player")) { targets = UnitList.getHostileUnitsInArea(parent.transform.position, areaRadius); } else { targets = UnitList.getPlayerUnitsInArea(parent.transform.position, areaRadius); } foreach (GameObject target in targets) { //Check for line of sight before dealing damage if (UnitMovement.lineOfSight(parent.transform.position, target.transform.position, false)) { target.GetComponent <UnitCombat>().takeDamage(parent.GetComponent <UnitCombat>().calculateDamage(Tuner.DamageType.melee, Tuner.BASE_WHIRLWIND_DAMAGE_MULTIPLIER), parent, Tuner.DamageType.melee); } } currentCooldown = maxCooldown; }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { NativeArray <UnitMovement> movements = chunk.GetNativeArray(UnitMovementType); NativeArray <MoveTo> unitMoveTo = chunk.GetNativeArray(UnitMoveToType); NativeArray <Entity> entities = chunk.GetNativeArray(EntityType); for (var i = 0; i < movements.Length; i++) { var move = movements[i]; var moveTo = unitMoveTo[i]; if (move.CurrentCellCoord.x != moveTo.Coord.x || move.CurrentCellCoord.y != moveTo.Coord.y) { EntityCommandBuffer.AddComponent <Path>(chunkIndex, entities[i]); EntityCommandBuffer.SetComponent(chunkIndex, entities[i], new Path { StartCoord = move.CurrentCellCoord, GoalCoord = moveTo.Coord, InProgress = true, Reachable = false }); EntityCommandBuffer.AddBuffer <PathNode>(chunkIndex, entities[i]); EntityCommandBuffer.AddBuffer <SearchNode>(chunkIndex, entities[i]); movements[i] = UnitMovement.Reset(move); #if UNITY_EDITOR EntityCommandBuffer.AddBuffer <DebugNode>(chunkIndex, entities[i]); #endif } EntityCommandBuffer.RemoveComponent <MoveTo>(chunkIndex, entities[i]); } }
protected override void OnUpdate() { if (!Simulate()) { return; } float deltTime = Time.deltaTime; for (int i = 0; i < _units.Length; i++) { var move = _units.MovementDatas[i]; Simulator.Instance.setAgentPosition(move.RVOAgentID, _units.Positions[i].Value + new float2(0.5f, 0.5f)); if (_units.MovementDatas[i].IsMoving) { Simulator.Instance.setAgentPrefVelocity(move.RVOAgentID, move.Velocity + move.Force * deltTime); } else { Simulator.Instance.setAgentPrefVelocity(move.RVOAgentID, new float2(0f, 0f)); } } Simulator.Instance.setTimeStep(Time.deltaTime); Simulator.Instance.doStep(); for (int i = 0; i < _units.Length; i++) { UnitMovement move = _units.MovementDatas[i]; move.Velocity = Simulator.Instance.getAgentVelocity(move.RVOAgentID); _units.MovementDatas[i] = move; } }
public static void EndUnitTurn() { UnitMovement unit = turnOfTheTeam.Dequeue(); unit.EndUnitTurn(); if (forceEndTeamTurn) { EndTeamTurn(); } UnitsInGameListEndUnitTurn(); QueueOfUnits.QueueHasChanged = true; if (turnOfTheTeam.Count <= 0) { EndTeamTurn(); } else { StartUnitTurn(); } }
/// <summary> /// Used to either perform movement in offline modes or send an RPC in online mode. /// </summary> /// <param name="unit"> Unit to be moved to the last tile in Path made by PathCreator</param> public void SendCommandToMove(UnitMovement unit) { if (GameStateManager.Instance.MatchType == MatchTypes.Online) { Tile target = GetFinalTile(); int startX = Mathf.RoundToInt(unit.transform.position.x); int startZ = Mathf.RoundToInt(unit.transform.position.z); int endX = Mathf.RoundToInt(target.transform.position.x); int endZ = Mathf.RoundToInt(target.transform.position.z); photonView.RPC( "RPCDoMovement", PhotonTargets.All, startX, startZ, endX, endZ); } else { DoMovement(unit); } }
public List <AUnitController> SpawnUnits(IGrid grid, InitialUnitConfig[] unitsConfigs) { _grid = grid; _unitsSpawned = new List <AUnitController>(unitsConfigs.Length); for (var i = 0; i < unitsConfigs.Length; ++i) { var unitConfig = unitsConfigs[i]; var unit = GetNewUnit(i, unitConfig, grid); var unitController = _unitInstatiator.InstantiateUnit(unitConfig.UnitConfig.Prefab, _unitsParent); var unitAttack = GetUnitAttack(unit, grid); var unitHealth = new UnitHealth(unit); var unitMovement = new UnitMovement(unitController.transform, unit, grid, unitAttack); var unitAI = GetUnitAI(unit, grid, unitMovement); unitController.InjectDependencies(unit, _turnDealer, grid, unitHealth, unitMovement, unitAI); unitController.InjectMonobehaviourDependencies(); unitController.Spawn(); unitController.UnitHealth.OnDeath += ReleaseUnit; _unitsSpawned.Add(unitController); } return(_unitsSpawned); }
//BaseUnitCopy void Awake() { //Load models //GameObject classModel = Instantiate(unitClassStats.classModel, modelController.transform); //GameObject weaponModel = Instantiate(unitWeapon.weaponModel, classModel.GetComponent<WeaponPosition>().hand); //Initiate Variables// ////////////////////// //Get Unit movement points movePoints = unitClassStats.maxUnitMovePoints; //get unit tile coordinates //Add the map incase its missing mapConfig = GameObject.FindGameObjectWithTag("Map").GetComponent <MapConfig>(); actionPoints = GetComponent <ActionPoints>(); health = GetComponent <Health>(); movement = GetComponent <UnitMovement>(); //if (!isFriendly) // InitializeEnemy(); Vector3 tileCoords = mapConfig.tileMap.WorldCoordToTileCoord((int)transform.position.x, (int)transform.position.z); //Set unit position on grid tileX = (int)tileCoords.x; tileY = (int)tileCoords.z; line = GetComponent <LineRenderer>(); animator = GetComponentInChildren <AnimationScript>(); actionPoints = GetComponent <ActionPoints>(); health = GetComponent <Health>(); animatorHealthbar = GetComponentInChildren <Animator>(); //movement = GetComponent<UnitMovement>(); }
protected override void ApplyEffect(UnitMovement unit) { unit.Attacked(bombDamage); }
protected override void ApplyEffect(UnitMovement unit) { unit.Attacked(-healAmount); }
protected override void UnApplyEffect(UnitMovement unit) { }
void Start() { unitMovement = GetComponent <UnitMovement>(); animator = GetComponent <Animator>(); }
protected override void UnApplyEffect(UnitMovement unit) { unit.damage -= strengthMod; }
protected override void UnApplyEffect(UnitMovement unit) { unit.moveSpeed += speedMod; }
void Awake() { goingToCollect = false; unitMovement = GetComponent<UnitMovement>(); animator = GetComponent<Animator>(); resourceBank = new ResourceValueDictionary(); foreach( Resource resource in Enum.GetValues(typeof(Resource))) { resourceBank.Add(resource, 0); } }
protected override void UnApplyEffect(UnitMovement unit) { unit.attackInterval /= atkSpeedMultiplier; unit.moveSpeed /= moveSpeedMultiplier; }
protected abstract void UnApplyEffect(UnitMovement unit);