protected override void CreateWorkflow() { if (Mode == LearnModes.LearnModeDisable) { ActionUnits.Add(new StartActionUnit(SetStateCompleting, TimeoutMs, cmZWaveSetLearnModeStop)); } else { if ((Mode & LearnModes.LearnModeNWE) == LearnModes.LearnModeNWE) { ActionUnits.Add(new StartActionUnit(null, TimeoutMs, cmZWaveSetLearnModeStart, cmZWaveExploreRequestExclusion, new RandomTimeInterval(0, 1000, 3000))); ActionUnits.Add(new TimeElapsedUnit(0, OnTimeElapsed, 0, cmZWaveExploreRequestExclusion, new RandomTimeInterval(0, 1000, 3000))); } else if ((Mode & LearnModes.LearnModeNWI) == LearnModes.LearnModeNWI) { ActionUnits.Add(new StartActionUnit(null, TimeoutMs, cmZWaveSetLearnModeStart, cmZWaveExploreRequestInclusion, new RandomTimeInterval(0, 1000, 3000))); ActionUnits.Add(new TimeElapsedUnit(0, OnTimeElapsed, 0, cmZWaveExploreRequestInclusion, new RandomTimeInterval(0, 1000, 3000))); } else { ActionUnits.Add(new StartActionUnit(null, TimeoutMs, cmZWaveSetLearnModeStart)); } ActionUnits.Add(new DataReceivedUnit(chZWaveSetLearnModeStarted, OnStarted)); ActionUnits.Add(new DataReceivedUnit(chZWaveSetLearnModeFailed, SetStateFailing, cmZWaveSetLearnModeStop)); ActionUnits.Add(new DataReceivedUnit(chZWaveSetLearnModeDone, OnDone, cmZWaveSetLearnModeStop)); ActionUnitStop = new ActionUnit(cmZWaveSetLearnModeStop); } }
protected override void SetStateCompleted(ActionUnit ou) { byte[] res = ((DataReceivedUnit)ou).DataFrame.Payload; SpecificResult.HomeId = new byte[] { res[0], res[1], res[2], res[3] }; SpecificResult.NodeId = res[4]; base.SetStateCompleted(ou); }
private int actionID = 0;//action的id,从0开始自增,范围是int.max;如果超过max则成负数,理论上不影响id的使用 public void Init() { m_Pool = new List <ActionUnit>(); m_Active = new List <ActionUnit>(); m_removeList = new List <ActionUnit>(); m_NewEvent = null; }
private void OnLearnReady(ActionUnit ou) { if (_isAssignCompleteReceived) { SetStateCompleted(ou); } }
public void Update() { ActionUnit target = _host.TargetAttack; if (!target || !target.Alive || !_host.IsEnemyInRangeAttack()) { // _host._navMeshAgent.enabled = false; _host.TargetAttack = null; if (Time.time - _host.TimeOfLastAttack > ((ActionUnitData)_host.CurrentStatus).baseAttackRate) { //attack done change state _host.ChangeState(ActionUnit.UnitState.Idle); } // _host._characterAnimationEventCalls.RegisterListener(CharacterAnimationEventCalls.K_ACTION_ATTACK_END) return; } else if (Time.time - _host.TimeOfLastAttack > ((ActionUnitData)_host.CurrentStatus).baseAttackRate) { Debug.DrawLine(_host.transform.position, _host.TargetAttack.transform.position, Color.red, 0.5f); _host.AnimateAttack(); // _host._characterAnimationEventCalls.OnAttack.AddListener(_attackUnit.DamageTarget); _host.TimeOfLastAttack = Time.time; } }
public void MarkTargetAttack(ActionUnit monster) { if (Host.TargetAttack == monster) { return; } if (Host.TargetAttack != null) { Debug.Log("Change Target"); // Host.TargetAttack.OnDestroyNotify.Detach(OnTargetDestroy); Host.ChangeState(ActionUnit.UnitState.Idle); } Host.TargetAttack = monster; if (monster != null) { // Host.TargetAttack.OnDestroyNotify.Attach(OnTargetDestroy); if (Host.IsEnemyInRangeAttack()) { Host.ChangeState(ActionUnit.UnitState.Attack); } else { Host.ChangeState(ActionUnit.UnitState.Move); } } }
protected void SetStateCompletedSecurityFailed(ActionUnit ou) { SecurityManagerInfo.IsInclusion = false; SecurityManagerInfo.Network.ResetSecuritySchemes(SpecificResult.Id); SecurityManagerInfo.Network.SetSecuritySchemesSpecified(SpecificResult.Id); SetStateCompleted(ou); }
protected override void SetStateCompleted(ActionUnit ou) { SpecificResult.NodeIds = new List <byte>(); byte[] res = ((DataReceivedUnit)ou).DataFrame.Payload; if (res != null) { for (int i = 0; i < res.Length; i++) { byte maskByte = res[i]; if (maskByte == 0) { continue; } byte bitMask = 0x01; byte bitOffset = 0x01;//nodes starting from 1 in mask bytes array for (int j = 0; j < 8; j++) { if ((bitMask & maskByte) != 0) { byte nodeID = (byte)(((i * 8) + j) + bitOffset); SpecificResult.NodeIds.Add(nodeID); } bitMask <<= 1; } } } base.SetStateCompleted(ou); }
public bool ValidLevelUpUnit(ActionUnit unit, bool levelUp = true) { if (unit.CurrentStatus.NextLevel == null) { return(false); } List <ActionUnit> materials = Game.Instance.board.GetBattleTilesGroup(-1).Where(x => x.ActionUnit != null && x.ActionUnit.Group == unit.Group && x.ActionUnit.UnitID != unit.UnitID && ((ActionUnitData)(x.ActionUnit.CurrentStatus)).unitName == ((ActionUnitData)(unit.CurrentStatus)).unitName && ((ActionUnitData)(x.ActionUnit.CurrentStatus)).Level == ((ActionUnitData)(unit.CurrentStatus)).Level) .Select(x => x.ActionUnit).ToList(); Debug.Log("UnitLevelManager " + materials.Count); if (materials.Count == 2) { if (levelUp) { return(PerformLevelUpUnit(unit, materials)); } else { return(true); } } return(false); }
protected void OnKexFailReceived(ActionUnit ou) { if (_KexFailReceived.Result) { SetStateCompletedSecurityFailed(ou); } }
protected override void injured(ActionUnit attacker) { base.injured(attacker); transform.LookAt(attacker.transform); Vector3 v = transform.localRotation.eulerAngles; transform.localRotation = Quaternion.Euler(0, v.y, v.z); }
protected override void SetStateCompleted(ActionUnit ou) { System.Text.UTF7Encoding utf = new System.Text.UTF7Encoding(); byte[] res = ((DataReceivedUnit)ou).DataFrame.Payload; if (res.Length > 6 + 6) { byte length = 0; for (length = 12; length > 0; length--) { if (res[length - 1] != 0) { break; } } if (length > 0) { SpecificResult.Version = utf.GetString(res, 0, length); } else { SpecificResult.Version = ""; } SpecificResult.Library = (Libraries)res[12]; } base.SetStateCompleted(ou); }
private void OnSegmentComplete(ActionUnit actionUnit) { if (_segmentCompleteExpect.Result.State == ActionStates.Expired) { if (!_isLastSegmentRetransmited) { _segmentCompleteExpect.NewToken(); _nextSegmentSendOperation.NewToken(); _dataOffset -= _subsequentSegmentPayloadSize; _nextSegmentSendOperation.Data = CreateSubsequentSegmentCmd(_data, _dataOffset); actionUnit.SetNextActionItems(_segmentCompleteExpect, _nextSegmentSendOperation); _dataOffset += _subsequentSegmentPayloadSize; _isLastSegmentRetransmited = true; } else { SpecificResult.SubstituteStatus = SubstituteStatuses.Failed; SetStateFailed(actionUnit); } } else if (_segmentCompleteExpect.Result.State == ActionStates.Completed) { SpecificResult.SubstituteStatus = SubstituteStatuses.Done; SetStateCompleted(actionUnit); } }
// Start is called before the first frame update void Start() { Host = gameObject.GetComponent <ActionUnit>(); CharacterAnimationEventCalls eventUnit = gameObject.GetComponentInChildren <CharacterAnimationEventCalls>(); eventUnit.RegisterListener(CharacterAnimationEventCalls.K_STATE_ATTACK_IN).AddListener(UnlockTarget); }
//List<ActionUnit> /// <summary> /// 初始化 /// </summary> public void Init(ActionUnit owner) { Owner = owner; _mInputStatesBase = new InputStateBase[2]; _mInputStatesBase[0] = InputStateBase.CreateStateByType(GameInputType.Move, KeyCode.None); _mInputStatesBase[1] = InputStateBase.CreateStateByType(GameInputType.Attack, KeyCode.J); }
public ActionUnit Get() { ActionUnit instance = CreateGameObjectInstance(prefab); instance.OriginFactory = this; return(instance); }
bool AcquireTargetOld() { Collider[] targets = Physics.OverlapSphere( gameObject.transform.localPosition, CalculateSight(Host), Host.MonstersLayerMask ); if (targets.Length > 1) { //target = targets[0].GetComponent<TargetPoint>(); //Debug.Assert(target != null, "Targeted non-enemy!", targets[0]); float shortestDistance = -1f; ActionUnit temTarget = null; for (var i = 0; i < targets.Length; i++) { ActionUnit monster = targets[i].transform.parent.transform.parent.GetComponent <ActionUnit>(); if (monster.UnitID != Host.UnitID && monster.Group != Host.Group) { float distance = Vector3.Distance(Host.transform.position, monster.transform.position); if (shortestDistance < 0f || distance < shortestDistance) { shortestDistance = distance; temTarget = monster; } } } if (temTarget != null) { MarkTargetAttack(temTarget); } return(true); } MarkTargetAttack(null); return(false); }
protected void SetStateCompletedSecurityDone(ActionUnit ou) { _securityManagerInfo.Network.SetSecuritySchemes(SecuritySchemeSet.S0); _securityManagerInfo.Network.SetSecuritySchemes(NodeId, SecuritySchemeSet.S0); _securityManagerInfo.IsInclusion = false; SetStateCompleted(ou); }
protected override void SetStateFailed(ActionUnit ou) { _securityManagerInfo.Network.ResetSecuritySchemes(); _securityManagerInfo.Network.ResetSecuritySchemes(NodeId); _securityManagerInfo.IsInclusion = false; base.SetStateFailed(ou); }
// Start is called before the first frame update void Start() { _host = gameObject.GetComponent <ActionUnit>(); Slider slider = CalculateSlider(); StartCoroutine(ActiveSlider(slider)); }
protected void SetStateCompletedSecurityFailed(ActionUnit ou) { _securityManagerInfo.Network.ResetSecuritySchemes(); _securityManagerInfo.Network.ResetSecuritySchemes(NodeId); _securityManagerInfo.IsInclusion = false; SetStateCompleted(ou); }
void HandleTouch() { GameTile tile = board.GetTile(InputUtils.GetTouchRayMouse()); if (tile == null) { return; } if (InputUtils.LeftControlPress()) { Vector3 faceTarget = tile.transform.position; // faceTarget.y = tile.transform.position.z; // faceTarget.z = tile.transform.position.y; for (int i = 0; i < ActionUnitManger.Total; i++) { ActionUnitManger.GetAll()[i].FaceTarget(faceTarget); } return; } ActionUnit focus = ActionUnitManger.GetUnit(InputUtils.GetTouchRayMouse()); if (focus != null) { // RemoveUnit(focus); OnUnitSelected.Invoke((ActionUnit)focus); } // else if (!RoundMode) // { // RandomSpawnMonster(tile, InputUtils.LeftShiftPress() ? 1 : 0); // } }
private ApiHandler handlerNotPrimary; // code=23 protected override void CreateWorkflow() { if ((InitMode & ControllerChangeModes.Start) == ControllerChangeModes.Start) { ActionUnits.Add(new StartActionUnit(null, TimeoutMs, messageStart)); ActionUnits.Add(new DataReceivedUnit(handlerLearnReady, OnLearnReady)); ActionUnits.Add(new DataReceivedUnit(handlerNodeFound, OnNodeFound)); ActionUnits.Add(new DataReceivedUnit(handlerAddingController, OnAddingController)); ActionUnits.Add(new DataReceivedUnit(handlerAddingSlave, OnAddingSlave)); if (IsModeStopEnabled) { ActionUnits.Add(new DataReceivedUnit(handlerFailed, OnFailed, messageStopFailed)); ActionUnits.Add(new DataReceivedUnit(handlerProtocolDone, OnProtocolDone, messageStop)); ActionUnits.Add(new DataReceivedUnit(handlerDone, OnDone, messageStopDone)); ActionUnits.Add(new DataReceivedUnit(handlerNotPrimary, OnNotPrimary, messageStopDone)); ActionUnitStop = new ActionUnit(messageStopDone); } else { ActionUnits.Add(new DataReceivedUnit(handlerFailed, OnFailed)); ActionUnits.Add(new DataReceivedUnit(handlerProtocolDone, OnDone)); ActionUnits.Add(new DataReceivedUnit(handlerNotPrimary, OnNotPrimary)); } } else { ActionUnits.Add(new StartActionUnit(SetStateCompleting, 0, messageStopDone)); } }
protected override void SetStateCompleted(ActionUnit ou) { byte[] res = ((DataReceivedUnit)ou).DataFrame.Payload; SpecificResult.SerialApplicationVersion = res[0]; SpecificResult.SerialApplicationRevision = res[1]; SpecificResult.ManufacturerId = (ushort)((res[2] << 8) + res[3]); SpecificResult.ManufacturerProductType = (ushort)((res[4] << 8) + res[5]); SpecificResult.ManufacturerProductId = (ushort)((res[6] << 8) + res[7]); byte funcIdx = 0; List <byte> SupportedFuncIds = new List <byte>(); for (int j = 8; j < res.Length; j++) { byte availabilityMask = res[j]; for (byte bit = 0; bit < 8; bit++) { funcIdx++; if ((availabilityMask & (1 << bit)) > 0) { SupportedFuncIds.Add(funcIdx); } } } SpecificResult.SupportedSerialApiCommands = SupportedFuncIds.ToArray(); base.SetStateCompleted(ou); }
protected override void CreateWorkflow() { ActionUnits.Add(new StartActionUnit(null, 0, message)); ActionUnits.Add(new DataReceivedUnit(handlerRetFailed, SetStateFailed)); ActionUnits.Add(new DataReceivedUnit(handlerCallback, OnHandle)); ActionUnitStop = new ActionUnit(messageStop); }
bool AcquireTarget() { ActionUnit closest = null; IOrderedEnumerable <ActionUnit> potentialTarget = ActionUnitManger.Instance.GetAll() .Where(x => x.UnitID != Host.UnitID && x.Group != Host.Group && x.Alive && x.BattleMode) .OrderBy(x => (Host.transform.position - x.transform.position).magnitude); NavMeshAgent nma = Host.GetComponent <NavMeshAgent>(); NavMeshObstacle nmo = Host.GetComponent <NavMeshObstacle>(); closest = potentialTarget.Where(x => _unreachable.IndexOf(x.UnitID) == -1).FirstOrDefault(); if (closest) { MarkTargetAttack(closest); return(true); } closest = potentialTarget.FirstOrDefault(); if (closest) { _unreachable.Clear(); //k tìm thấy mục tiêu thay thế thì giữ nguyên MarkTargetAttack(closest); return(true); } MarkTargetAttack(null); return(false); }
protected override void SetStateCompleted(ActionUnit ou) { SpecificResult.SerialApiVersion = ((DataReceivedUnit)ou).DataFrame.Payload[0]; SpecificResult.SerialApiCapability = ((DataReceivedUnit)ou).DataFrame.Payload[1]; byte nodeIdx = 0; List <byte> includedNodes = new List <byte>(); for (int i = 0; i < ((DataReceivedUnit)ou).DataFrame.Payload[2]; i++) { byte availabilityMask = ((DataReceivedUnit)ou).DataFrame.Payload[3 + i]; for (byte bit = 0; bit < 8; bit++) { nodeIdx++; if ((availabilityMask & (1 << bit)) > 0) { includedNodes.Add(nodeIdx); } } } SpecificResult.IncludedNodes = includedNodes.ToArray(); SpecificResult.ChipType = (ChipTypes)((DataReceivedUnit)ou).DataFrame.Payload[3 + ((DataReceivedUnit)ou).DataFrame.Payload[2]]; SpecificResult.ChipRevision = ((DataReceivedUnit)ou).DataFrame.Payload[4 + ((DataReceivedUnit)ou).DataFrame.Payload[2]]; base.SetStateCompleted(ou); }
protected override void SetStateCompleted(ActionUnit ou) { byte[] res = ((DataReceivedUnit)ou).DataFrame.Payload; SpecificResult.Lenght = Lenght; SpecificResult.NVRValue = res; base.SetStateCompleted(ou); }
protected override void SetStateCompleted(ActionUnit ou) { byte[] res = ((DataReceivedUnit)ou).DataFrame.Payload; if (res[2] > 0) { try { SpecificResult.NodeId = NodeId; SpecificResult.NodeInfo = new byte[res[2]]; Array.Copy(res, 3, SpecificResult.NodeInfo, 0, SpecificResult.NodeInfo.Length); if (SpecificResult.NodeInfo.Length > 0) { SpecificResult.Basic = SpecificResult.NodeInfo[0]; } if (SpecificResult.NodeInfo.Length > 1) { SpecificResult.Generic = SpecificResult.NodeInfo[1]; } if (SpecificResult.NodeInfo.Length > 2) { SpecificResult.Specific = SpecificResult.NodeInfo[2]; } if (SpecificResult.NodeInfo.Length > 3) { SpecificResult.CommandClasses = SpecificResult.NodeInfo.Skip(3).TakeWhile(x => x != 0xEF).ToArray(); } } catch (Exception) { } } base.SetStateCompleted(ou); }
public virtual bool SellUnit(ActionUnit focusUnit) { if (focusUnit != null) { Game.Instance.DestroyUnit(focusUnit); return(true); } return(false); }
protected override void SetStateCompleted(ActionUnit ou) { byte[] res = ((DataReceivedUnit)ou).DataFrame.Payload; if (res != null && res.Length > 1) { SpecificResult.IsSet = res[1] > 0; } base.SetStateCompleted(ou); }
public void showInjured(ActionUnit attacker,float delay) { this.attacker = attacker; Invoke("playInjured", delay); }
//是否在攻击范围 public bool isAttackable(ActionUnit player,ActionUnit monster) { Vector3 v1 = player.transform.localPosition; Vector3 v2 = monster.transform.localPosition; if(Vector3.Distance(v1, v2) <= player.attackRange) { if (Vector3.Dot(player.transform.forward,monster.transform.position - player.transform.position) > 0) { float t = Vector3.Cross(player.transform.forward, monster.transform.position - player.transform.position).y; if(Mathf.Abs(t) < 0.5) { return true; } } } return false; }
protected virtual void injured(ActionUnit attacker) { }