protected override void InternalOnAddedToBattle(EntityParam param) { base.InternalOnAddedToBattle(param); this.property.Equal(Attr.Team, param.team); this.ApplyLevel(0); this._regenTime = 0f; this._numSkills = this._data.skills.Length; for (int i = 0; i < this._numSkills; i++) { Skill skill = this.skills[i]; skill.OnCreated(this._data.skills[i], this.rid); skill.OnAttrChanged += this.OnSkillAttrChanged; if (skill.isCommon) { skill.Upgrade(); //普攻默认等级1 this.commonSkill = skill; } } this.fsm.Start(); SyncEventHelper.ChangeState(this.rid, FSMStateType.Idle); this.ChangeState(FSMStateType.Idle); this.ActivePassiveBuffs(); }
private void Die(Bio killer) { this._script?.Call(Script.S_ON_ENTITY_DIE); killer?.OnKillTarget(this); int count = this._buffStates.Count; for (int i = 0; i < count; i++) { this._buffStates[i].OnDie(killer); } while (this._buffStates.Count > 0) { this.DestroyBuffStateImmediately(this._buffStates[0]); } this.UpdateVelocity(Vec3.zero); this.sensorySystem.Clear(); this.property.Add(Attr.Gold, -this.goldBountyAwarded); SyncEventHelper.ChangeState(this.rid, FSMStateType.Dead); this.ChangeState(FSMStateType.Dead); this.brain.Rearbitrate(); this.brain.enable = false; SyncEventHelper.EntityDie(this.rid, killer == null ? string.Empty : killer.rid); }
protected override void CreateInternal() { this.owner.brain.enable = false; this.owner.UpdateVelocity(Vec3.zero); SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); }
protected override void UpdateInternal(UpdateContext context) { if (!this.owner.CanCharmed()) { return; } this._time += context.deltaTime; if (this._time >= DETECT_INTERVAL) { this._time = 0f; if (this._lastTargetPos != this._target.property.position) { Vec3[] corners = this.owner.battle.GetPathCorners(this.owner.property.position, this._target.property.position); if (corners == null) { SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); return; } this.owner.steering.followPath.Set(corners); this.owner.steering.followPath.MaxVelocity(); this.owner.steering.On(SteeringBehaviors.BehaviorType.FollowPath); if (this.owner.property.ignoreVolumetric == 0) { this.owner.steering.On(SteeringBehaviors.BehaviorType.ObstacleAvoidance); } this._lastTargetPos = this._target.property.position; } } if (this.owner.steering.followPath.complete) { this.owner.UpdateVelocity(Vec3.zero); } }
protected override void OnUpdate(UpdateContext context) { if (!this.owner.steering.followPath.complete) { return; } SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); }
protected override void CreateInternal() { this.owner.brain.enable = false; this.owner.UpdateVelocity(Vec3.zero); SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); this._target = this.buff.caster; this._target.AddRef(); this._lastTargetPos = Vec3.zero; this._time = DETECT_INTERVAL; }
protected override void OnEnter(object[] param) { this._targetPoint = ( Vec3 )param[0]; Vec3[] corners = this.owner.battle.GetPathCorners(this.owner.property.position, this._targetPoint); if (corners == null) { SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); return; } this.owner.steering.followPath.Set(corners); this.owner.steering.followPath.MaxVelocity(); this.owner.steering.On(SteeringBehaviors.BehaviorType.FollowPath); if (this.owner.property.ignoreVolumetric == 0) { this.owner.steering.On(SteeringBehaviors.BehaviorType.ObstacleAvoidance); } }
public void Attack(Skill skill, Bio target, Vec3 targetPoint) { SyncEventHelper.ChangeState(this.rid, FSMStateType.Attack, true, skill.id, target == null ? string.Empty : target.rid, targetPoint); this.ChangeState(FSMStateType.Attack, true, skill, target, targetPoint); }
public void Pursue(Skill skill, Bio target, Vec3 targetPoint) { SyncEventHelper.ChangeState(this.rid, FSMStateType.Pursue, true); this.ChangeState(FSMStateType.Pursue, true, skill, target, targetPoint); }
public void Track(Bio target) { SyncEventHelper.ChangeState(this.rid, FSMStateType.Track, true); this.ChangeState(FSMStateType.Track, true, target); }
public void Move(Vec3 targetPoint) { SyncEventHelper.ChangeState(this.rid, FSMStateType.Move, true); this.ChangeState(FSMStateType.Move, true, targetPoint); }
private void NextState() { SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); }
protected override void OnUpdate(UpdateContext context) { if (this._target != null && (this._target.isDead || !this.owner.WithinFov(this._target))) //todo 超过fov放弃是否合理? { SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); return; } if (!this._moveComplete) { Vec3 targetPos = this.CalcTargetPoint(); float distance = this._skill.distance; if ((this.owner.property.position - targetPos).SqrMagnitude() <= distance * distance) { if (this._skill.ignoreObstacles) { this._moveComplete = true; } else { //检测和目标之间是否有障碍物 if (!this.owner.battle.NavMeshRaycast(this.owner.property.position, targetPos, out _, out _)) { this._moveComplete = true; } } } if (this._moveComplete) { this.owner.UpdateVelocity(Vec3.zero); this.owner.steering.Off(SteeringBehaviors.BehaviorType.FollowPath); this.owner.steering.Off(SteeringBehaviors.BehaviorType.ObstacleAvoidance); } } if (this._moveComplete && !this._rotComplete) { Vec3 targetPos = this._target?.property.position ?? this._targetPoint; Vec3 toDir = Vec3.Normalize(targetPos - this.owner.property.position); float angle = Vec3.Angle(this.owner.property.direction, toDir); if (angle < 15f) //x度内让他可以攻击了 { this._rotComplete = true; } else { this.owner.property.Equal(Attr.Direction, Vec3.Slerp(this.owner.property.direction, toDir, context.deltaTime * this.owner.rotSpeed * this.owner.property.moveSpeedFactor * 2f)); } } if (this._moveComplete && this._rotComplete) { this.owner.Attack(this._skill, this._target, this._targetPoint); return; } if (this._target != null) { this._time += context.deltaTime; if (this._time >= DETECT_INTERVAL) { this._time = 0f; if (this._lastTargetPos != this._target.property.position) { this._recalPath = true; this._lastTargetPos = this._target.property.position; } } } if (!this._recalPath) { return; } this._recalPath = false; Vec3[] corners = this.owner.battle.GetPathCorners(this.owner.property.position, this.CalcTargetPoint()); if (corners == null) { SyncEventHelper.ChangeState(this.owner.rid, FSMStateType.Idle); this.owner.ChangeState(FSMStateType.Idle); return; } this.owner.steering.followPath.Set(corners); this.owner.steering.followPath.MaxVelocity(); this.owner.steering.On(SteeringBehaviors.BehaviorType.FollowPath); if (this.owner.property.ignoreVolumetric == 0) { this.owner.steering.On(SteeringBehaviors.BehaviorType.ObstacleAvoidance); } this._moveComplete = false; }