void MonkeyAttack() { // TODO here applies the following rules: // Astronaut: disable only the patrol drone // Saboteur: attack a building, disabling it; // attack a disabled drone, reprogramming it // attack any drone, temporarily disabling it (CHECK) // Cientist: get rocket parts // Engineer: attack a disabled drone, turning it in metal // 'attack' a saboutaged building, repairing it // All monkeys: 'attack' the command center, entering in it // NEW CODE // Perform the action according to the mouse state switch(mouseState) { // Astronaut monkey case MouseWorldPosition.eMouseStates.TargetingForBrawl: { CDrone droneTarget = transTarget.gameObject.GetComponent<CDrone>(); if(droneTarget != null) { // Play the attack animation if(meshObject) { stAnimationWorking = stAnimTargetingForBrawl; meshObject.animation.Play(stAnimationWorking); } playAttackAckSound(); droneTarget.Attacked(); } EnterNewState(FSMState.STATE_IDLE); } break; // Engineer monkey case MouseWorldPosition.eMouseStates.EngineerFix: { // Sets the time need to fix this building fWorkingTargetTime = fBuildingFixTime; workingMouseState = mouseState; // Play the attack animation if(meshObject) { stAnimationWorking = stAnimEngineerFix; meshObject.animation.Play(stAnimationWorking); } playAttackAckSound(); EnterNewState(FSMState.STATE_WORKING); } break; case MouseWorldPosition.eMouseStates.TargetingForRecycle: { fWorkingTargetTime = fDroneRecycleTime; workingMouseState = mouseState; // Play the attack animation if(meshObject) { stAnimationWorking = stAnimTargetingForRecycle; meshObject.animation.Play(stAnimationWorking); } playAttackAckSound(); EnterNewState(FSMState.STATE_WORKING); } break; // Cientist monkey case MouseWorldPosition.eMouseStates.CanCapture: { // Cientist monkey capturing a RocketPart CBaseEntity cCapturedEntity = transTarget.GetComponent<CBaseEntity>(); playAttackAckSound(); if(!cCapturedEntity) { // DEBUG Debug.LogError("Cannot find component CBaseEntity for this object: " + transTarget.name); } cCapturedEntity.CapturedBy(this.transform, this.captureSpot, this.captureRaySpot); this.capturedEntity = cCapturedEntity; EnterNewState(FSMState.STATE_IDLE); } break; // Saboteur monkey case MouseWorldPosition.eMouseStates.TargetingForReprogram: { // Sets the time needed to reprogram this drone fWorkingTargetTime = fDroneReprogramTime; sfxWorking = sfxReprogramming; workingMouseState = mouseState; // Play the attack animation if(meshObject) { stAnimationWorking = stAnimTargetingForReprogram; meshObject.animation.Play(stAnimationWorking); } playAttackAckSound(); EnterNewState(FSMState.STATE_WORKING); } break; case MouseWorldPosition.eMouseStates.CanSabotageBuilding: { // Sets the time needed to sabotage a building fWorkingTargetTime = fBuildingSabotageTime; workingMouseState = mouseState; // Play the attack animation if(meshObject) { stAnimationWorking = stAnimCanSabotageBuilding; meshObject.animation.Play(stAnimationWorking); } playAttackAckSound(); EnterNewState(FSMState.STATE_WORKING); } break; case MouseWorldPosition.eMouseStates.CanSabotageDrone: { // Sets the time needed to sabotage a building fWorkingTargetTime = fDroneSabotageTime; workingMouseState = mouseState; // Play the attack animation if(meshObject) { stAnimationWorking = stAnimCanSabotageDrone; meshObject.animation.Play(stAnimationWorking); } playAttackAckSound(); EnterNewState(FSMState.STATE_WORKING); } break; // All monkeys case MouseWorldPosition.eMouseStates.MonkeyCanEnterBuilding: { CBuilding attackedBuilding = transTarget.gameObject.GetComponent<CBuilding>(); if(!attackedBuilding) { // DEBUG Debug.LogError("CBuilding component not found for " + transTarget.name); return; } // Check if we are entering the rocket if(attackedBuilding.buildingType == CBuilding.eBuildingType.LaunchingPlatform) { attackedBuilding.PutAMonkeyInsideRocket(this.transform, this.monkeyClass); } else { attackedBuilding.PutAMonkeyInside(this.transform); } // DEBUG Debug.Log("MouseState for this action " + mouseState + " in " + attackedBuilding.transform); EnterNewState(FSMState.STATE_INSIDE_BUILDING); // Deselect this object this.Deselect(); } break; default: // DEBUG Debug.LogError("I shouldn't be here..."); break; } }
/// <summary> /// Attack a target. Actually, 'attack' could be replaced by 'perform some action on...', because we using /// this function also to repair buildings, capture rocket parts, etc. /// </summary> /// <param name="transTarget"> Transform of the targeted object </param> /// <param name="currentMouseState"> A enum with the mouse state when the player issued an order </param> /// <summary> /// Performs the 'attack' of the monkey /// </summary> public void PerformAction(Transform transTarget, MouseWorldPosition.eMouseStates currentMouseState) { this.transTarget = transTarget; mouseState = currentMouseState; // DEBUG Debug.LogWarning(this.transform + " performing " + mouseState); // Go into pursuit mode -> walk to the target. When it is in range, perform the action EnterNewState(FSMState.STATE_PURSUIT); }