//a function to change the enemy child state and make the appropriate changes to the enemy child cell public void ChangeState(ECState _state) { m_CurrentState.Exit(); m_CurrentState = m_StatesDictionary[_state]; m_CurrentEnum = _state; m_CurrentState.Enter(); }
//Added this IEnumerator CheckState(float time) { while (true) { yield return(new WaitForSeconds(time)); state = Vector3.Distance(transform.position, PlayerController.instance.transform.position) < playerRange ? ECState.InRange : ECState.NotInRange; if (state == ECState.NotInRange) { rb.velocity = Vector2.zero; } } }
private static void _addCounterRules(ref string rule1, ref string rule2, ECState state, int algsCount, ECAction action) { string add = "("; add += Smv.EccStateVar + "=" + Smv.EccState(state.Name); add += " & "; add += Smv.EcActionsCounterVar + " = " + (action.Number); //(state.ActionsCount > 0 ? state.ActionsCount : 1); add += " & "; add += Smv.AlgStepsCounterVar + " {0} " + (algsCount > 0 ? algsCount : 1); add += ") | "; rule1 += String.Format(add, "<"); rule2 += String.Format(add, "="); }
private void AutoAvoid() { Collider2D[] NearbyObjects = Physics2D.OverlapCircleAll(gameObject.transform.position, 3 * GetComponent <SpriteRenderer>().bounds.size.x / 2, Constants.s_onlyEnemeyChildLayer); ECState ECCurrentState = ECState.Idle; //Dispatch a message to all nearby enemy child cells that are idling to defend the main cell for (int i = 0; i < NearbyObjects.Length; i++) { ECCurrentState = NearbyObjects[i].GetComponent <EnemyChildFSM>().CurrentStateEnum; if (ECCurrentState == ECState.Idle || ECCurrentState == ECState.Defend) { MessageDispatcher.Instance.DispatchMessage(gameObject, NearbyObjects[i].gameObject, MessageType.Avoid, 0); } } }
// void Start() { //Initialize the variables and data structure m_fRotationTarget = Random.Range(0f, 360f); m_RandomRotateSpeed = new Vector3(0f, 0f, 0.85f); m_bRotateCW = false; m_bRotateACW = false; m_PMain = GameObject.Find("Player_Cell"); m_EMain = GameObject.Find("Enemy_Cell"); m_EMFSM = m_EMain.GetComponent <EnemyMainFSM>(); m_EMControl = m_EMain.GetComponent <EMController>(); m_Rigidbody2D = GetComponent <Rigidbody2D>(); m_ChildTransform = transform; m_ChargeTarget = null; m_StatesDictionary = new Dictionary <ECState, IECState>(); m_AudioSource = GetComponent <AudioSource>(); //Initialize the various states for the enemy child cell and added them into the dictionary m_StatesDictionary.Add(ECState.Idle, new ECIdleState(this.gameObject, this)); m_StatesDictionary.Add(ECState.Defend, new ECDefendState(this.gameObject, this)); m_StatesDictionary.Add(ECState.Avoid, new ECAvoidState(this.gameObject, this)); m_StatesDictionary.Add(ECState.Attack, new ECAttackState(this.gameObject, this)); m_StatesDictionary.Add(ECState.ChargeMain, new ECChargeMState(this.gameObject, this)); m_StatesDictionary.Add(ECState.ChargeChild, new ECChargeCState(this.gameObject, this)); m_StatesDictionary.Add(ECState.TrickAttack, new ECTrickAttackState(this.gameObject, this)); m_StatesDictionary.Add(ECState.Landmine, new ECMineState(this.gameObject, this)); m_StatesDictionary.Add(ECState.Dead, new ECDeadState(this.gameObject, this)); //initialize the current state for the enemy child cell m_CurrentState = m_StatesDictionary[ECState.Dead]; m_CurrentEnum = ECState.Dead; m_CurrentCommand = MessageType.Empty; CurrentState.Enter(); }
public void PutState(ECState state) { EcStates.Add(state); }
// void Start() { //Initialize the variables and data structure m_fRotationTarget = Random.Range(0f,360f); m_RandomRotateSpeed = new Vector3(0f,0f,0.85f); m_bRotateCW = false; m_bRotateACW = false; m_PMain = GameObject.Find("Player_Cell"); m_EMain = GameObject.Find("Enemy_Cell"); m_EMFSM = m_EMain.GetComponent<EnemyMainFSM>(); m_EMControl = m_EMain.GetComponent<EMController>(); m_Rigidbody2D = GetComponent<Rigidbody2D>(); m_ChildTransform = transform; m_ChargeTarget = null; m_StatesDictionary = new Dictionary<ECState,IECState>(); m_AudioSource = GetComponent<AudioSource>(); //Initialize the various states for the enemy child cell and added them into the dictionary m_StatesDictionary.Add(ECState.Idle, new ECIdleState(this.gameObject,this)); m_StatesDictionary.Add(ECState.Defend, new ECDefendState(this.gameObject,this)); m_StatesDictionary.Add(ECState.Avoid, new ECAvoidState(this.gameObject,this)); m_StatesDictionary.Add(ECState.Attack, new ECAttackState(this.gameObject,this)); m_StatesDictionary.Add(ECState.ChargeMain, new ECChargeMState(this.gameObject,this)); m_StatesDictionary.Add(ECState.ChargeChild, new ECChargeCState(this.gameObject,this)); m_StatesDictionary.Add(ECState.TrickAttack, new ECTrickAttackState(this.gameObject,this)); m_StatesDictionary.Add(ECState.Landmine, new ECMineState(this.gameObject,this)); m_StatesDictionary.Add(ECState.Dead, new ECDeadState(this.gameObject,this)); //initialize the current state for the enemy child cell m_CurrentState = m_StatesDictionary[ECState.Dead]; m_CurrentEnum = ECState.Dead; m_CurrentCommand = MessageType.Empty; CurrentState.Enter(); }
private async void RunDevServer(ushort port) { try { var client = await GetCLIClient(); var call = client.RunDevServer(); var req = new Trail.Cli.Service.Cli.V1.RunDevServerReq { Start = new Trail.Cli.Service.Cli.V1.RunDevServerReq.Types.Start { ProjectPath = "", Port = port, RoomId = cliData.RoomId, }, }; await call.RequestStream.WriteAsync(req); var completed = false; var responseReaderTask = Task.Run(async() => { try { while (await call.ResponseStream.MoveNext(cancellationTokenSource.Token)) { if (call.ResponseStream.Current.Error != null) { errorMessage = call.ResponseStream.Current.Error.Message; RunCallback(false, this); } else if (call.ResponseStream.Current.Started != null) { State = ECState.Waiting; } else if (call.ResponseStream.Current.PlayerConnected != null && State != ECState.Disconnected) { State = ECState.Running; } else if (call.ResponseStream.Current.PlayerDisconnected != null) { State = ECState.Disconnected; } } } catch (Exception exception) { // For some reason MoveNext throws an exception when the server closes // the channel if (completed && exception is Grpc.Core.RpcException) { var rpcException = (Grpc.Core.RpcException)exception; if (rpcException.StatusCode == Grpc.Core.StatusCode.Unavailable) { State = ECState.Disconnected; errorMessage = rpcException.Message; RunCallback(false, this); return; } } throw exception; } }); await responseReaderTask; await call.RequestStream.CompleteAsync(); completed = true; State = ECState.Disconnected; RunCallback(true, this); } catch (System.Exception e) { State = ECState.Disconnected; errorMessage = e.Message; RunCallback(false, this); } }
public RunDevServerRequest(ushort port) : base() { State = ECState.Loading; RunDevServer(port); }