public override IEnumerator UpdateView(FightStatus fightStatus) { if (fightStatus.TryGetEntity(concernedEntity, out PlayerStatus entityStatus)) { AbstractPlayerUIRework view = entityStatus.view; if (null != view) { int count = moves.Count; IEnumerator[] array = new IEnumerator[count]; for (int i = 0; i < count; i++) { SpellMovement spellMovement = moves[i]; if (spellMovement.From == Ankama.Cube.Protocols.FightCommonProtocol.SpellMovementZone.Hand) { int spellInstanceId = spellMovement.Spell.SpellInstanceId; array[i] = view.RemoveSpell(spellInstanceId, i); } else if (spellMovement.To == Ankama.Cube.Protocols.FightCommonProtocol.SpellMovementZone.Hand) { array[i] = view.AddSpell(spellMovement.Spell, i); } } yield return(EnumeratorUtility.ParallelRecursiveImmediateSafeExecution(array)); } } else { Log.Error(FightEventErrors.PlayerNotFound(concernedEntity), 112, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\Events\\SpellsMovedEvent.cs"); } FightLogicExecutor.FireUpdateView(fightStatus.fightId, EventCategory.SpellsMoved); }
void setNewSpellDir(Vector3 origin, Vector3 target, int InstantiateID, int OwnerID, PhotonMessageInfo info) { double timestamp = info.timestamp; m_sceneAbilities.RemoveAll(item => item = null); SpellData spell = m_sceneAbilities.Find(item => item.InstantiateID() == InstantiateID); if (spell == null) { Debug.Log("Spell is null!!!!"); } SpellMovement spellMove = spell.GetComponent <SpellMovement>(); spell.setOwnerID(OwnerID); for (int i = 0; i < charMananager.Players.Count; i++) { if (charMananager.Players[i].playerID == OwnerID) { spell.setOwner(charMananager.Players[i].GetComponent <SpellManager>()); } } spellMove.SetCreationTime(timestamp); spellMove.SetStartPosition(origin); spellMove.SetSpellDirection(origin, target); }
/// <summary> /// The function that gets called after a "spellcast" event. /// Rotates the instantiated spell towards the right direction. /// </summary> private void SpellCast() { dir = charAnim.lookDir; GameObject spell = Instantiate(fireBall, transform.position, Quaternion.identity) as GameObject; SpellMovement spellMovement = spell.GetComponent <SpellMovement>(); spellMovement.lookDir = dir; spell.transform.SetParent(transform); }
public override void UpdateStatus(FightStatus fightStatus) { if (fightStatus.TryGetEntity(concernedEntity, out PlayerStatus entityStatus)) { bool flag = fightStatus == FightStatus.local; int count = moves.Count; for (int i = 0; i < count; i++) { SpellMovement spellMovement = moves[i]; if (flag) { FightCastManager.CheckSpellPlayed(spellMovement.Spell.SpellInstanceId); } switch (spellMovement.To) { case Ankama.Cube.Protocols.FightCommonProtocol.SpellMovementZone.Nowhere: case Ankama.Cube.Protocols.FightCommonProtocol.SpellMovementZone.Deck: if (spellMovement.From == Ankama.Cube.Protocols.FightCommonProtocol.SpellMovementZone.Hand) { int spellInstanceId = spellMovement.Spell.SpellInstanceId; entityStatus.RemoveSpell(spellInstanceId); AbstractPlayerUIRework view2 = entityStatus.view; if (null != view2) { view2.RemoveSpellStatus(spellInstanceId, i); } } break; case Ankama.Cube.Protocols.FightCommonProtocol.SpellMovementZone.Hand: { SpellInfo spell = spellMovement.Spell; SpellStatus spellStatus = SpellStatus.TryCreate(spell, entityStatus); if (spellStatus != null) { entityStatus.AddSpell(spellStatus); AbstractPlayerUIRework view = entityStatus.view; if (null != view) { view.AddSpellStatus(spell, i); } } break; } default: throw new ArgumentOutOfRangeException($"Spell moved to unknown zone: {spellMovement.To}"); } } } else { Log.Error(FightEventErrors.PlayerNotFound(concernedEntity), 75, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\Events\\SpellsMovedEvent.cs"); } FightLogicExecutor.FireUpdateStatus(fightStatus.fightId, EventCategory.SpellsMoved); }
public void Setup (){ //(List<ElementManager> list) { //elements = new List<elementType> (); //foreach(ElementManager e in list){ // elements.Add(e.elementType); //} //Choose Texture spellMovement = instance.GetComponent<SpellMovement> (); spellCollision = instance.GetComponent<SpellCollision> (); spellCollision.id = id; }
public void CreateProjectile(Vector3 startPos, Vector3 targetPos, double createTime, int ownerID, int spellID, int instantiateID) { GameObject go = (GameObject)Instantiate(Spell[spellID], startPos, Quaternion.identity); SpellData spellData = go.GetComponent <SpellData>(); audio.PlayOneShot(spellData.CastSound()); SpellMovement projectileMovement = go.GetComponent <SpellMovement>(); spellData.setOwnerID(ownerID); if (ownerID == GetComponent <CharacterManager_NET>().playerID) { spellData.setOwner(this); } spellData.setInstantiateID(instantiateID); projectileMovement.SetCreationTime(createTime); projectileMovement.SetStartPosition(startPos); projectileMovement.SetSpellDirection(startPos, targetPos); m_sceneAbilities.Add(spellData); }
/**A function to set a spell animator with respect to the spell*/ public void SetSpellAnimator(GameObject spell_default_prefab) { SpellName spell_class_name = spell_default_prefab.GetComponent <SpellMovement>().m_SpellClassToCast.m_SpellName; SpellMovement spell_movement_component = spell_default_prefab.GetComponent <SpellMovement> (); switch ((int)spell_class_name) { case (int)SpellName.Fireball: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Fireball animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_FireballAnimator); break; } //end case fireball case (int)SpellName.Iceball: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Iceball animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_IceballAnimator); break; } case (int)SpellName.Shield: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Shield animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_ShieldAnimator); break; } case (int)SpellName.Thunderball: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Thunderball animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_ThunderballAnimator); break; } case (int)SpellName.Thunderstorm: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Thunderstorm animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_ThunderStormAnimator); break; } case (int)SpellName.Heal: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Heal animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_HealAnimator); break; } case (int)SpellName.Tornado: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Tornado animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_TornadoAnimator); break; } case (int)SpellName.WaterBubble: { #if TESTING_SUCCESSFUL_ANIMATOR_ASSIGNMENT Debug.Log("Water bubble animator controller assigned"); #endif spell_movement_component.SetAnimatorController(this.m_WaterBubbleAnimator); break; } default: { //Impossible break; } } //end switch } //end f'n void SetSpellAnimator(GameObject)
protected override void ExecutePatternState() { switch ((int)this.m_AttackPatternState) { //Case for when the enemy is healing case (int)AttackPatternState.HEAL: { if (this.m_GeneratedSpellInstance == null) { this.GenerateSpellPrefabInstance(); GameObject.Destroy(this.m_GeneratedSpellInstance, 1.0f); } //Debug.Log("I am hurt damnit"); SpellMovement spell_movement = this.m_GeneratedSpellInstance.GetComponent <SpellMovement> (); spell_movement.transform.position = this.GetComponent <Transform>().position; this.GetComponent <DefaultEnemy>().AffectHealth(1.5f); break; } case (int)AttackPatternState.MELEE: { if (this.m_AttackTimer == 0.0f) { // this.m_IsAttacking_Melee = true; this.m_Enemy.SetAttackDamageValue(); this.GetComponent <Animator>().SetBool(STRINGKEY_PARAM_ISATTACKING_MELEE, true); this.gameObject.GetComponent <AudioSource>().PlayOneShot(this.m_EnemyMeleeAttackSound); this.m_MeleeDetectionRegion.m_Player.AffectHealth(-this.m_Enemy.m_AttackDamageValue); // This line instantiates the animation for a the attack hit of the enemy. GameObject attackHit = Instantiate(this.m_EnemyHitAnimation, this.m_Enemy.m_MovementPattern.m_PatrolRegion.m_Player.transform.position, Quaternion.identity); this.m_AttackTimer += Time.deltaTime; } else if (0.0f < this.m_AttackTimer && this.m_AttackTimer < 2.0f * Time.deltaTime) { this.GetComponent <Animator> ().SetBool(STRINGKEY_PARAM_ISATTACKING_MELEE, false); this.m_AttackTimer += Time.deltaTime; } else if (0.0f < this.m_AttackTimer && this.m_AttackTimer < this.m_IntervalBetweenAttacks) { this.m_AttackTimer += Time.deltaTime; } else if (this.m_AttackTimer >= this.m_IntervalBetweenAttacks) { this.m_AttackTimer = 0.0f; } break; } case (int)AttackPatternState.RANGED: { // Debug.Log ("Am I running?"); if (this.m_AttackTimer == 0.0f) { this.m_Enemy.SetAttackDamageValue(); this.GetComponent <Animator>().SetBool(STRINGKEY_PARAM_ISATTACKING_RANGED, true); this.GenerateSpellPrefabInstance(); BossEnemy boss_enemy_component = this.GetComponent <BossEnemy> (); if (boss_enemy_component != null) { boss_enemy_component.m_SpellCastCount++; } Player player_detected = this.m_Enemy.m_MovementPattern.m_PatrolRegion.m_Player; //if the player was detected in the movement region... if (player_detected != null) { this.m_EnemySpellSound = player_detected.m_PlayerAudio.getAudioForSpell(this.m_SpellToCast.m_SpellName); this.m_AudioSource.PlayOneShot(this.m_EnemySpellSound); } //in the event that the player wasn't actually detected in the movement region but was detected from the attack region else { //...then get the attack region's player instance player_detected = this.m_AttackDetectionRegion.m_Player; if (player_detected != null) { this.m_EnemySpellSound = player_detected.m_PlayerAudio.getAudioForSpell(this.m_SpellToCast.m_SpellName); this.m_AudioSource.PlayOneShot(this.m_EnemySpellSound); } } this.m_PlayerInstance = player_detected; } switch ((int)this.m_SpellToCast.m_SpellType) { case (int)SpellType.BASIC_PROJECTILE_ON_TARGET: { if (this.m_AttackTimer == 0.0f) { this.m_GeneratedSpellInstance.transform.position = this.transform.position; SpellMovement spell_movement = this.m_GeneratedSpellInstance.GetComponent <SpellMovement> (); //if the player reference exists... if (this.m_PlayerInstance != null) { //...then continue with the spell casting // spell_movement.SetEnemyTarget (this.m_Enemy.m_MovementPattern.m_PatrolRegion.m_Player.gameObject); spell_movement.SetEnemyTarget(this.m_PlayerInstance.gameObject); spell_movement.SetSpellToCast(this.m_SpellToCast); } //Worst-case, destroy the generated spell instance after given time this.DestroySpellAfterTime(1.5f); this.m_AttackTimer += Time.deltaTime; } else if (0.0f < this.m_AttackTimer && this.m_AttackTimer < 2.0f * Time.deltaTime) { this.GetComponent <Animator>().SetBool(STRINGKEY_PARAM_ISATTACKING_RANGED, false); this.m_AttackTimer += Time.deltaTime; } else if (0.0f < this.m_AttackTimer && this.m_AttackTimer < this.m_IntervalBetweenAttacks) { this.m_AttackTimer += Time.deltaTime; } else if (this.m_AttackTimer >= this.m_IntervalBetweenAttacks) { this.m_AttackTimer = 0.0f; } break; } case (int)SpellType.AOE_ON_TARGET: { Player player = this.m_Enemy.m_MovementPattern.m_PatrolRegion.m_Player; if (player == null) { player = this.m_AttackDetectionRegion.m_Player; } if (this.m_AttackTimer == 0.0f) { if (player != null) { //Spawn AOE at caster's position this.m_GeneratedSpellInstance.transform.position = this.transform.position; } SpellMovement spell_movement = this.m_GeneratedSpellInstance.GetComponent <SpellMovement> (); spell_movement.SetSpellToCast(this.m_SpellToCast); //Update animator this.m_SpellAnimatorManager.SetSpellAnimator(this.m_GeneratedSpellInstance); //Update timer this.m_AttackTimer += Time.deltaTime; } //if the timer's greater than 0, then the player's still in the region and the spell instance is created. //So all we need to do is make the spell follow the player else if (this.m_AttackTimer > 0.0f) { //...then ensure the spell's always at our chosen position SpellMovement spell_movement = this.m_GeneratedSpellInstance.GetComponent <SpellMovement> (); Vector3 displacement = Vector3.Normalize(player.gameObject.transform.position - this.m_GeneratedSpellInstance.transform.position) * spell_movement.m_MaximalVelocity * Time.deltaTime * (Time.deltaTime * 4.0f); Vector3 spell_current_position = this.m_GeneratedSpellInstance.transform.position; this.m_GeneratedSpellInstance.transform.position = spell_current_position + displacement; this.ApplyAOEToAllInRange(spell_current_position); this.m_AttackTimer += Time.deltaTime; } break; } //end case AOE_ON_TARGET } //end switch spelltype break; } //end case RANGED case (int)AttackPatternState.DO_NOTHING: { //Do nothing //In case the player is slipping in and out of the enemy's detection region, make the timer run its course anyway if (0.0f < this.m_AttackTimer && !(this.m_AttackTimer >= this.m_IntervalBetweenAttacks)) { this.m_AttackTimer += Time.deltaTime; } else if (this.m_AttackTimer >= this.m_IntervalBetweenAttacks) { this.m_AttackTimer = 0.0f; this.GetComponent <Animator>().SetBool(STRINGKEY_PARAM_ISATTACKING_RANGED, false); this.DestroySpellAfterTime(1.5f); } break; } } //end switch }
/**A function to be called if the long list of conditions for spell-casting to be valid are met; assigns the respective movement for the corresponding spell type. * When this function is called the player could be either pressing or holding the mouse.*/ private void AssignSpellMovement() { //If the input button is tapped if (Input.GetButtonDown(STRINGKEY_INPUT_CASTSPELL)) { // Debug.Log ("Active spell: " + this.m_Player.GetComponent<PlayerInventory> ().m_ActiveSpellClass.m_SpellName.ToString ()); if (!this.m_SpellClassToFire.m_IsPersistent) { // Debug.Log ("The mouse was pressed"); switch ((int)this.m_SpellClassToFire.m_SpellType) { case (int)SpellType.BASIC_PROJECTILE_ON_TARGET: { //All basic projectile spells have the same movement pattern Ray ray = this.m_MainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit[] targets_hit = Physics.RaycastAll(ray); //We need to find the raycast hit furthest from the camera in the event that none of the raycasthits are //mobile character as the furthest raycast hit will be the ground. RaycastHit furthest = targets_hit [0]; bool any_mobile_characters = false; foreach (RaycastHit hit in targets_hit) { //if the hit's distance is greater than that of the furthest... if (hit.distance > furthest.distance) { //...then update the furthest furthest = hit; } //end if //if the hit has a DefaultEnemy component (avoiding the player hitting himself/herself)... if (hit.collider.gameObject.GetComponent <DefaultEnemy> () != null) { m_Target = hit.collider.gameObject; this.m_SpellCubeInstance = GameObject.Instantiate(this.m_SpellCube); this.m_Player.m_audioSource.PlayOneShot(this.m_Player.m_PlayerAudio.getAudioForSpell(this.m_SpellClassToFire.m_SpellName)); this.m_SpellCubeInstance.transform.position = this.transform.position; SpellMovement spell_movement = this.m_SpellCubeInstance.GetComponent <SpellMovement> (); spell_movement.m_IsMobileCharacter = true; spell_movement.SetTarget(hit); any_mobile_characters = true; spell_movement.SetSpellToCast(this.m_SpellClassToFire); this.m_SpellAnimatorManager.SetSpellAnimator(this.m_SpellCubeInstance); //return to ensure we only launch one spell return; } //end if } //end foreach //if none of the gameobjects found in the raycastall were mobile characters... if (!any_mobile_characters) { //...then send the spell to the furthest Raycast hit #if TESTING_SPELLMOVEMENT Debug.Log("PlayerCastSpell::Update\tNo mobile characters found\tRay hit\tx: " + furthest.point.x + " y: " + furthest.point.y + " z: " + furthest.point.z); #endif this.m_SpellCubeInstance = GameObject.Instantiate(this.m_SpellCube); this.m_Player.m_audioSource.PlayOneShot(this.m_Player.m_PlayerAudio.getAudioForSpell(this.m_SpellClassToFire.m_SpellName)); this.m_SpellCubeInstance.transform.position = this.transform.position; SpellMovement spell_movement = this.m_SpellCubeInstance.GetComponent <SpellMovement> (); spell_movement.m_IsMobileCharacter = false; spell_movement.SetTarget(furthest); // spell_movement.m_MaximalVelocity = 10.0f; spell_movement.SetSpellToCast(this.m_SpellClassToFire); this.m_SpellAnimatorManager.SetSpellAnimator(this.m_SpellCubeInstance); GameObject.Destroy(this.m_SpellCubeInstance, TIME_UNTIL_DESTROY); } //end if this.m_Player.AffectMana(-this.m_SpellClassToFire.m_ManaCost / this.m_Player.m_MagicAffinity); break; } //end case basic projectile on target } //end switch } //end if active spell is not persistent } //end if mouse is pressed //else if mouse is held else if ((Input.GetButton(STRINGKEY_INPUT_CASTSPELL))) { //if the active spell is persistent if (this.m_SpellClassToFire.m_IsPersistent) { // Debug.Log ("The mouse was held"); switch ((int)this.m_SpellClassToFire.m_SpellType) { case (int)SpellType.ON_PLAYER: { //Any spell cast on the player has the same basic movement pattern //if the spell cube instance is null (which can only mean the last spell cube was destroyed)... if (this.m_SpellCubeInstance == null) { //...then create a new spell cube this.m_SpellCubeInstance = GameObject.Instantiate(this.m_SpellCube); this.m_Player.m_audioSource.PlayOneShot(this.m_Player.m_PlayerAudio.getAudioForSpell(this.m_SpellClassToFire.m_SpellName)); this.m_SpellCubeInstance.transform.position = this.transform.position; SpellMovement spell_movement = this.m_SpellCubeInstance.GetComponent <SpellMovement> (); spell_movement.SetSpellToCast(this.m_SpellClassToFire); this.m_SpellAnimatorManager.SetSpellAnimator(this.m_SpellCubeInstance); } //end if //if the spell cube instance exists (meaning we're in the process of casting a spell)... if (this.m_SpellCubeInstance != null) { //...then ensure the spell's always at our chosen position SpellMovement spell_movement = this.m_SpellCubeInstance.GetComponent <SpellMovement> (); spell_movement.MaintainPosition(this.transform.position); } //end if the spell cube instance exists //However, most (if not all) on-player spells have different effects on both enemies and player mana. this.m_Player.AffectMana(-(this.m_SpellClassToFire.m_ManaCost / this.m_Player.m_MagicAffinity) * Time.deltaTime); switch ((int)this.m_SpellClassToFire.m_SpellName) { case (int)SpellName.Shield: { // this.m_Player.AffectMana (-this.m_SpellClassToFire.SHIELD_MANA_COST); this.m_Player.m_IsShielded = true; break; } //end case Shield case (int)SpellName.Heal: { // this.m_Player.AffectMana (-this.m_SpellClassToFire.HEAL_MANA_COST); //Some arbitrary value just to test this.m_Player.AffectHealth(2.0f); break; } //end case Heal } //end switch break; } //end case ON PLAYER case (int)SpellType.AOE_ON_TARGET: { //Any AOE spell cast on a target has the same basic movement pattern //if the spell cube instance is null (which can only mean the last spell cube was destroyed)... if (this.m_SpellCubeInstance == null) { //...then create a new spell cube this.m_SpellCubeInstance = GameObject.Instantiate(this.m_SpellCube); this.m_Player.m_audioSource.PlayOneShot(this.m_Player.m_PlayerAudio.getAudioForSpell(this.m_SpellClassToFire.m_SpellName)); this.m_SpellCubeInstance.transform.position = this.transform.position; SpellMovement spell_movement = this.m_SpellCubeInstance.GetComponent <SpellMovement> (); spell_movement.SetSpellToCast(this.m_SpellClassToFire); this.m_SpellAnimatorManager.SetSpellAnimator(this.m_SpellCubeInstance); } //end if //if the spell cube instance exists (meaning we're in the process of casting a spell)... if (this.m_SpellCubeInstance != null) { //...then ensure the spell's always at our chosen position SpellMovement spell_movement = this.m_SpellCubeInstance.GetComponent <SpellMovement> (); Ray ray = this.m_MainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit[] targets_hit = Physics.RaycastAll(ray); RaycastHit target = targets_hit [0]; bool any_mobile_characters = false; foreach (RaycastHit hit in targets_hit) { //if the hit's distance is greater than that of the furthest... if (hit.collider.gameObject == this.m_Floor) { target = hit; break; } } //end foreach //Set position of AOE spell animation Vector3 modified_target = new Vector3(target.point.x, 0.0f, target.point.z); Vector3 position = modified_target + AOE_offset; spell_movement.MaintainPosition(position); //If we're just starting to cast the spell... if (this.AOE_Timer == 0.0f) { //... then apply the AOE to the enemies this.ApplyAOEToEnemies(position - AOE_offset); //Then set AOE timer to 1, to avoid repeating the base case this.AOE_Timer = 1.0f; } //end if //else if the AOE timer is greater than or equal to 1 + the time it takes for the specific AOE spell to wear off... else if (this.AOE_Timer >= 1.0f + this.m_SpellClassToFire.m_EffectDuration) { //...then apply damage to the enemies and reset AOE timer to 1.0f this.ApplyAOEToEnemies(position - AOE_offset); this.AOE_Timer = 1.0f; } //end else if //else increment AOE timer by time.delta time else { this.AOE_Timer += Time.deltaTime; } //end else } //end if the spell cube instance exists //However, most (if not all) AOE on-target spells have different effects on both enemies and player mana. this.m_Player.AffectMana(-(this.m_SpellClassToFire.m_ManaCost / this.m_Player.m_MagicAffinity) * Time.deltaTime); switch ((int)this.m_SpellClassToFire.m_SpellName) { case (int)SpellName.Thunderstorm: { //Nothing really special about thunderstorm // this.m_Player.AffectMana (-this.m_SpellClassToFire.THUNDERSTORM_MANA_COST); break; } //end case thunderstorm } //end switch break; } //end case AOE ON TARGET } //end switch } //end if active spell is persistent } //end if mouse is held }
void Start() { spellData = GetComponentInParent <SpellData>(); _spellMovement = GetComponentInParent <SpellMovement>(); direction = _spellMovement.GetSpellDir(); }