/// <summary> /// returns a vector3 for the "effective" starting location for this turn. /// </summary> /// <returns></returns> public Vector3 GetOrigin() { //loop over turns in our unit's combat queue excepting this ons. Vector3 og = self.transform.position; List <Turn> copy = self.GetCombatActionQueue(); int count = self.GetCombatActionCount(); if (copy == null) { return(og); } if (copy.Contains(this)) { count -= 1; } for (int i = 0; i < count; i++) { og += copy[i].displacement; } return(og); }
// Update is called once per frame void Update() { if (MyUnit.isDead) { MyUnit.gameObject.SetActive(false); } if (player == null) { player = transform.GetComponent <EnemyBehaviour>().Target.GetComponent <UnitBehavior>(); return; } //executes if we need to give our unit a turn. if (MyUnit.GetCombatActionCount() < player.GetCombatActionCount()) { //add a turn. if (MyUnit.TurnNum % 2 == 0) { //move Turn X = new Turn(); X.actiontype = "move"; //ensures the turn knows it has a movement type command X.ran = 1.8f; //preserve range for this action X.Start(MyUnit); //ensures the target and targetlocator exist. if (!MyUnit.PushCombatAction(X)) { X.Destroy(); } X.TargetLocator.SetActive(true); //target the player's next location. X.SetTarget((player.GetCombatActionQueue()[0].GetOrigin() - MyUnit.transform.position).normalized * X.GetRange() + X.GetOrigin()); X.ExternalUpdate = MoveUpdate; //prevent player from seeing our targetlocation X.TargetLocator.transform.Find("RangeIndicator/Plane").GetComponent <Renderer>().enabled = false; } else { //fix the previous move command. if (MyUnit.GetCombatActionCount() > 0) { Turn Y = MyUnit.GetCombatActionQueue()[MyUnit.GetCombatActionCount() - 1]; if (Y.actiontype == "move") { Y.SetTarget((player.GetCombatActionQueue()[0].GetOrigin() - MyUnit.transform.position).normalized * Y.GetRange() + Y.GetOrigin()); } } // then add an attack Turn X = new Turn(); X.actiontype = "basicattack"; //ensures the turn knows it has a basic attack type command X.ran = 1.5f; //preserve range for this action X.Start(MyUnit); //ensures the target and targetlocator exist. X.SetProcTime(1.0f); MyUnit.AttackDMG = new Vector2(4, 2); //REEEEEEEEE TODO don't do this shit. this is hard coding because framework isnt done to pull damages from weapon+stats if (!MyUnit.PushCombatAction(X)) { X.Destroy(); } X.TargetLocator.SetActive(true); X.SetTarget((player.GetCombatActionQueue()[0].GetOrigin() - MyUnit.transform.position).normalized * X.GetRange() + X.GetOrigin()); X.ExternalStart = BasicAttackStart; X.ExternalUpdate = BasicAttackUpdate; X.ExternalEnd = BasicAttackEnd; //prevent player from seeing our targetlocation X.TargetLocator.transform.Find("RangeIndicator/Plane").GetComponent <Renderer>().enabled = false; } Debug.Log("Turn: " + TurnNum); } }
//preserved the first n actions. public void PreserveNActions(int n) { TurnNumber -= (myUnit.GetCombatActionCount() - n); myUnit.PreserveFirstNActions(n); }
void Update() { UpdateQueueImages(); //if we have a combatants list, we should remove dead ones from the active list.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //depends on UnitBehavior.GetHealth() being accurate\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ if (Combatants != null) { Vector3 UnitHP; foreach (UnitBehavior unit in Combatants) { UnitHP = unit.GetHealth(); // if wounds plus damage exceed maximum health, remove from activecombatants, and remove UI tags tracking it. if ((UnitHP[1] + UnitHP[2] > UnitHP[0])) { Kill(unit); } } } //likely that we have an active battle if the combatants list exists. if (ActiveCombatants != null) { ActiveCount = 0; //test to see if any are dead. If any are dead, they can be removed from our list. foreach (UnitBehavior o in ActiveCombatants) { o.inBattle = true; //make sure live units understand they are in battle. if (o.gameObject.GetComponent <EnemyBehaviour>() != null) { ActiveCount += 1; //slowly kill active enemies. Kills enemies earliest in list fastest. //DEV AOE //o.DamageHealth(new Vector2(Random.value / (float)ActiveCount / 2.0f, 0.0f)); } /* * // make sure it has an active tag. * if (!o.GetComponent<HealthOverTarget>() && !o.isDead) * { * o.gameObject.AddComponent<HealthOverTarget>(); * } */ } if (ActiveCount == 0) { foreach (UnitBehavior o in Combatants) { o.inBattle = false; //END COMBAT BECAUSE ALL ENEMY SCRIPTS REPORTED DEATH. } } GameObject.Find("UICanvas/enemycount").GetComponent <Text>().text = "EnemyCount: " + ActiveCount.ToString(); } if (ActiveCount <= 0) { playerRange.SetActive(false); ActivateQueueImages(false); ActivateButtons(false); //make sure the combat buttons are invisible. return; //short if there are no active combatants } //ActivateQueueImages(true); //if we get here, there was an activecombatants list, and there are enemies around. //test if there is no turn queue for the player. If so, then unset playActive, as there are no turns left to play. if (playerObject.GetCombatActionCount() == 0) { playActive = false; //there are no turns left to account for or plays to produce activeTime = 0; //TODO END PLAY } //make sure combat buttons are available during combat. ActivateButtons(!playActive); //ONLY HAPPENS when someone clicked "play" and there are turns available in the player's turn Queue. //retains active state until the player's combat action count is 0. //in this block we need to keep track of time, if (playActive) { //IDEALLY, 0=start. 0-cutoff=update. cutoff-buffer=nothing. buffer=end. buffer-wait=nothing. wait=beginNextturn //if activetime is 0, play was just pressed or the last turn just ended, so we can start a turn. if (activeTime == 0) { activeTime = Time.time; BeginNextTurn(); //ask the units to begin their next turn. } //when we get here, we expect a turn to have been started if it needed to be started. if this goes through, it indicates the time for which the turns need their update scripts called. if (!turnTimeBufferHit) { //turnTimeCutoff=1.5f, turnTimeBuffer=0.5f, turnWaitTime = 1f; //executes during the time between turn start and if ((Time.time - (turnTimeBuffer + turnTimeCutoff)) > activeTime) { turnTimeCutoffHit = true; turnTimeBufferHit = true; } //Debug.Log("update time frame"); UpdateCurrentTurn(); //ask the unit's to execute their turn's update func. } //this is the wait time in between turns after the previous turn has "ended" and before the next turn "begins" else if (!turnWaitTimeHit) { //Debug.Log("active time: " + activeTime.ToString() + " now: " + (Time.time - (turnTimeBuffer + turnTimeCutoff + turnWaitTime)).ToString()); if ((Time.time - (turnTimeBuffer + turnTimeCutoff + turnWaitTime)) > activeTime) { turnWaitTimeHit = true; } } //previous turn has ended. reset activeTime and end this current turn that has been updating. if (turnWaitTimeHit) { //Debug.Log("wait time proc"); EndCurrentTurn(); activeTime = 0; //on the next frame, all flags will be reset. if playActive is true, then the next turn will begin. } } else { //if the mouse button (left) is held down, we update our target location for the last action stacked on the player's queue. if (Input.GetMouseButton(0)) { //vector3 of the mouse. Vector3 dif = gameObject.GetComponent <OverWorldControllerScript>().GetVector3FromRaycast(Input.mousePosition); if (dif == Vector3.zero) { return; } //break off if we get shit data from vector3raycast //dif = dif - playerObject.transform.position; //if the mouse is held, change the location of the action's direction locator. if (playerObject.GetCombatActionCount() > 0) { dif = dif - playerObject.GetCombatActionQueue()[playerObject.GetCombatActionCount() - 1].GetOrigin(); float range = playerRange.GetComponent <RangeIndicator>().radius; if (dif.magnitude > range) { dif = dif.normalized * range; } PlayerSetTurn = playerObject.GetCombatActionQueue()[playerObject.GetCombatActionCount() - 1]; PlayerSetTurn.SetTarget(playerObject.GetCombatActionQueue()[playerObject.GetCombatActionCount() - 1].GetOrigin() + dif); } else { } } //turn off all images. ActivateQueueImages(false); //TODO activate turn images based on action queue for (int c = 0; c < playerObject.GetCombatActionCount(); c++) { I[c].gameObject.SetActive(true); string typing = playerObject.GetCombatActionQueue()[c].actiontype; if (typing.Contains("attack")) { } else if (typing.Contains("cast")) { } else if (typing.Contains("block")) { } else if (typing.Contains("move")) { } else { } // TURN IMAGES NEEDS SETTING HERE. } //if we get here, playActive is false. this is where we care to handle button presses. //buttons ARE active when we get here. bool actionselected = false; //whenever a button procs, try to add it to the list (handle move). if (MoveButtonProc) { MoveButtonProc = false; //consume the flag and push a move turn to the player queue. Turn X = new Turn(); X.actiontype = "move"; //ensures the turn knows it has a movement type command X.ran = playerRange.GetComponent <RangeIndicator>().radius; //preserve range for this action X.Start(playerObject); //ensures the target and targetlocator exist. if (!playerObject.PushCombatAction(X)) { X.Destroy(); } X.TargetLocator.SetActive(true); X.ExternalUpdate = X.MoveToLocation; actionselected = true; } //whenever a button procs, try to add it to the list (handle move). if (CastButtonProc) { CastButtonProc = false; //consume the flag and push a casting turn to the player queue. Turn X = new Turn(); X.actiontype = "cast"; //ensures the turn knows it has a cast type command X.ran = playerRange.GetComponent <RangeIndicator>().radius; //preserve range for this action X.Start(playerObject); //ensures the target and targetlocator exist. X.SetProcTime(0.75f); if (!playerObject.PushCombatAction(X)) { X.Destroy(); } X.TargetLocator.SetActive(true); X.ExternalStart = X.CastFireStart; X.ExternalUpdate = X.CastFireUpdate; X.ExternalEnd = X.CastFireEnd; actionselected = true; } //whenever a button procs, try to add it to the list (handle move). if (AttackButtonProc) { AttackButtonProc = false; //consume the flag and push an attack turn to the player queue. Turn X = new Turn(); X.actiontype = "basicattack"; //ensures the turn knows it has a basic attack type command X.ran = playerRange.GetComponent <RangeIndicator>().radius; //preserve range for this action X.Start(playerObject); //ensures the target and targetlocator exist. X.SetProcTime(0.6f); if (!playerObject.PushCombatAction(X)) { X.Destroy(); } X.TargetLocator.SetActive(true); X.ExternalStart = X.BasicAttackStart; X.ExternalUpdate = X.BasicAttackUpdate; X.ExternalEnd = X.BasicAttackEnd; actionselected = true; } //whenever a button procs, try to add it to the list (handle move). if (BlockButtonProc) { BlockButtonProc = false; //consume the flag and push a defend turn to the player queue. Turn X = new Turn(); X.actiontype = "block"; //ensures the turn knows it has a block type command X.ran = playerRange.GetComponent <RangeIndicator>().radius; //preserve range for this action X.Start(playerObject); //ensures the target and targetlocator exist. if (!playerObject.PushCombatAction(X)) { X.Destroy(); } X.TargetLocator.SetActive(true); X.ExternalStart = X.BlockStart; X.ExternalUpdate = X.CastFireUpdate; //face that direction. X.ExternalEnd = X.BlockEnd; actionselected = true; } //one of the above actions has been chosen this frame. adjust playerRange. if (actionselected) { playerRange.transform.position = playerObject.GetCombatActionQueue()[0].GetOrigin(); Renderer r1 = playerRange.transform.Find("Plane").GetComponent <Renderer>(); Renderer r2 = playerObject.GetCombatActionQueue()[playerObject.GetCombatActionCount() - 1].TargetLocator.transform.Find("RangeIndicator/Plane").GetComponent <Renderer>(); Color col = r2.material.GetColor("_MainColor"); //col.a = 0.25f; r1.material.SetColor("_MainColor", col); } } }