private void CalcDamage(Bio caster, Bio target, int triggerIndex) { BuffData.Trigger trigger = this._buff.trigger; if (trigger.damaged == null) { return; } int index = trigger.damaged.Length - 1; index = triggerIndex <= index ? triggerIndex : index; if (!trigger.damaged[index]) { return; } float damage = this.CalcDamageInternal(caster, target, index); target.property.Add(Attr.Hp, -damage); if (target.property.hp <= 0) { target.sensorySystem.killer = caster; } SyncEventHelper.Damage(this._buff.rid, damage, caster.rid, target.rid); this.OnDamage(damage, caster, target, triggerIndex); caster.OnDamage(this._buff, target, damage); target.OnHurt(this._buff, caster, damage); }
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 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 DestroyBuffStateImmediately(BSBase buffState) { SyncEventHelper.BuffStateRemoved(this.rid, buffState.id); buffState.OnDestroy(); this._buffStates.Remove(buffState); BuffStatePool.Push(buffState); }
internal void OnAddedToBattle(EntityParam param) { SyncEventHelper.SpawnEntity(this.GetType().Name, param); this._rid = param.rid; this._data = ModelFactory.GetEntityData(Utils.GetIDFromRID(this._rid)); this.property.Init(this._data); this.property.Equal(Attr.Position, param.position); this.property.Equal(Attr.Direction, param.direction); this.size = this._data.size * this.property.scale; this.bornPosition = param.position; this.bornDirection = param.direction; AIData[] aiDatas = this._data.aiDatas; if (aiDatas != null) { int count = aiDatas.Length; for (int i = 0; i < count; i++) { this.CreateAIEvaluator(aiDatas[i]); } } this.InternalOnAddedToBattle(param); SyncEventHelper.EntityAttrInitialized(this.rid); if (!string.IsNullOrEmpty(this._data.script)) { this._script = new Script(this, this.battle.luaEnv, this._data.script); this._script.Call(Script.S_ON_ENTITY_ADDED_TO_BATTLE); } }
internal void Update(UpdateContext context) { if (!this._enable) { return; } this._elapsed += context.deltaTime; this.UpdateInternal(context); if (this.trigger != null) { this._triggerDt += context.deltaTime; float interval = this.trigger.interval; interval = interval < context.deltaTime ? context.deltaTime : interval; if (this._triggerDt >= interval) { SyncEventHelper.BuffStateTriggered(this.owner.rid, this.id, this._triggerIndex); this.TriggerAttr(this._triggerIndex); ++this._triggerIndex; this._triggerDt -= interval; } } if (this.duration >= 0f && this._elapsed >= this.duration) { this.TimeupInternal(); this.owner.DestroyBuffState(this); } }
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); } }
internal override void UpdateState(UpdateContext context) { this.time += context.deltaTime; this._regenTime += context.deltaTime; if (this._regenTime >= 5f) { this._regenTime -= 5f; if (!this.isDead) { this.property.Add(Attr.Hp, this.property.hpRegen); this.property.Add(Attr.Mana, this.property.manaRegen); } } this.UpdateThink(context); this.fsm.Update(context); for (int i = 0; i < this._numSkills; i++) { this.skills[i].Update(context.deltaTime); } int count = this._buffStates.Count; for (int i = 0; i < count; i++) { this._buffStates[i].Update(context); } count = this._buffStatesToDestroy.Count; if (count > 0) { for (int i = 0; i < count; i++) { BSBase buffState = this._buffStatesToDestroy[i]; this.DestroyBuffStateImmediately(buffState); } this._buffStatesToDestroy.Clear(); } this.UpdateSteering(context); this.sensorySystem.Update(context); if (this.debugDraw) { SyncEventHelper.DebugDraw(SyncEvent.DebugDrawType.WireCube, this.property.position + new Vec3(0, this.size.y * 0.5f, 0), this.size, null, 0, Color4.gray); } if (this.lifeTime > 0 && this.time >= this.lifeTime) { this.markToDestroy = true; } }
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 virtual void OnAttrChanged(Attr attr, object oldValue, object value) { switch (attr) { case Attr.Scale: this.size = this._data.size * ( float )value; break; } SyncEventHelper.EntityAttrChanged(this.rid, attr, oldValue, value); }
private void OnTargetEnter(Bio target) { SyncEventHelper.EnterBuff(this._buff.rid, target.rid); target.OnEnterBuff(this._buff); if (this._buff.enterStates != null) { this.CreateStates(this._buff.enterStates, target); } }
public void Relive() { SyncEventHelper.Relive(this.rid, this.bornPosition, this.bornDirection); this.ChangeState(FSMStateType.Idle); this.property.Equal(Attr.Hp, this.property.mhp); this.property.Equal(Attr.Mana, this.property.mmana); this.property.Equal(Attr.Position, this.bornPosition); this.property.Equal(Attr.Direction, this.bornDirection); this.ActivePassiveBuffs(); this.brain.enable = true; //todo 重新计算属性 }
internal void OnRemoveFromBattle() { this._implement.OnDestroy(); BuffImplPool.Push(this._implement); this._implement = null; this.target?.RedRef(); this.caster.RedRef(); this.target = null; this.caster = null; this.skillData = null; this.markToDestroy = false; SyncEventHelper.DespawnBuff(this.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); this._target = this.buff.caster; this._target.AddRef(); this._lastTargetPos = Vec3.zero; this._time = DETECT_INTERVAL; }
internal void OnRemoveFromBattle() { this.InternalOnRemoveFromBattle(); if (this._script != null) { this._script.Call(Script.S_ON_ENTITY_REMOVED_FROM_BATTLE); this._script.Dispose(); this._script = null; } this.RemoveAllAIEvaluator(); this.markToDestroy = false; this._data = null; SyncEventHelper.DespawnEntity(this.rid); }
public void Dispose() { this._pathManager.Dispose(); this._buffManager.Dispose(); this._entityManager.Dispose(); //顺序很重要 if (this._script != null) { this._script.Call(Script.S_ON_BATTLE_DESTROIED); this._script.Dispose(); this._script = null; } this._timer0.Dispose(); this._luaEnv = null; this.data = null; SyncEventHelper.DestroyBattle(); }
internal virtual void UpdateState(UpdateContext context) { this.time += context.deltaTime; this.UpdateThink(context); this.UpdateSteering(context); if (this.debugDraw) { SyncEventHelper.DebugDraw(SyncEvent.DebugDrawType.WireCube, this.property.position + new Vec3(0, this.size.y * 0.5f, 0), this.size, null, 0, Color4.gray); } if (this.lifeTime > 0 && this.time >= this.lifeTime) { this.markToDestroy = true; } }
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); } }
internal void CreateBuffState(string id, Buff buff) { BuffStateData buffStateData = ModelFactory.GetBuffStateData(id); //有免疫限制技能的属性,并且将要产生的state是限制类型,则不会生效 if (this.property.immuneDisables > 0 && buffStateData.beneficialType == BeneficialType.Debuff) { return; } bool create = true; if (buffStateData.overlapType == BuffStateOverlapType.Replace || buffStateData.overlapType == BuffStateOverlapType.Unique) { BSBase bs = this.GetBuffState(id); if (bs != null) { switch (buffStateData.overlapType) { case BuffStateOverlapType.Replace: this.DestroyBuffStateImmediately(bs); break; case BuffStateOverlapType.Unique: bs.Unite(); create = false; break; } } } if (create) { SyncEventHelper.BuffStateAdded(this.rid, id, buff.rid); BSBase buffState = BSBase.Create(buffStateData.type); buffState.Init(id, this, buff); this._buffStates.Add(buffState); } }
private void OnMoveComplete() { SyncEventHelper.HandleMissileComplete(this.rid, this.property.position, this.property.direction); this.ChangeState(FSMStateType.Idle); this.markToDestroy = true; if (this.target != null && this.target.isDead) { return; } SkillData skillData = ModelFactory.GetSkillData(this._skillId); int count = skillData.buffs.Length; for (int i = 0; i < count; i++) { this.battle.CreateBuff(skillData.buffs[i], skillData.id, this._skillLvl, this.caster, this.target, this.targetPoint); } }
protected virtual void OnTargetTrigger(Bio target, int triggerIndex) { if (!this._triggerCountMap.ContainsKey(target)) { this._triggerCountMap[target] = 0; } if (this._triggerCountMap[target] >= this._buff.perTargetTriggerCount) { return; } SyncEventHelper.TriggerTarget(this._buff.rid, target.rid, triggerIndex); this._triggerCountMap[target]++; ++this._totalTriggerCount; this.CalcDamage(this._buff.caster, target, triggerIndex); if (this._buff.triggerStates != null) { this.CreateStates(this._buff.triggerStates, target); } }
private void OnAttrChanged(Attr attr, object oldvalue, object newvalue) { SyncEventHelper.BuffAttrChanged(this.rid, attr, oldvalue, newvalue); }
internal void OnAddedToBattle(string rid, string skillId, int lvl, Bio caster, Bio target, Vec3 targetPoint) { SyncEventHelper.SpawnBuff(rid, skillId, lvl, caster.rid, target == null ? string.Empty : target.rid, targetPoint); this._rid = rid; this._data = ModelFactory.GetBuffData(Utils.GetIDFromRID(this._rid)); this.skillData = ModelFactory.GetSkillData(skillId); this.campType = this._data.campType == 0 ? this.skillData.campType : this._data.campType; this.targetFlag = this._data.targetFlag == 0 ? this.skillData.targetFlag : this._data.targetFlag; this.rangeType = this._data.rangeType == 0 ? this.skillData.rangeType : this._data.rangeType; this.caster = caster; this.target = target; if (this.target == null && (this.campType & CampType.Self) > 0) { this.target = caster; } this.caster.AddRef(); this.target?.AddRef(); this.targetPoint = targetPoint; this.deadType = this._data.deadType; if (this.target == null) { if (this.deadType == DeadType.WithMainTarget) { LLogger.Error("Dead_type of the buff that has no target can not set to DeadType.WithMainTarget"); } if (this.skillData.rangeType == RangeType.Single) { LLogger.Error("Range_type of the buff that has no target can not set to RangeType.Single"); } if (this.orbit == Orbit.FollowTarget) { LLogger.Error("Orbit_type of the buff that has no target can not set to Orbit.FollowTarget"); } } else { this.deadType = DeadType.WithMainTarget; } this.property.Init(this._data); this.ApplyLevel(lvl); targetPoint = this.target?.property.position ?? this.targetPoint; switch (this.spawnPoint) { case SpawnPoint.Target: this.property.Equal(Attr.Position, targetPoint); break; case SpawnPoint.Caster: this.property.Equal(Attr.Position, this.caster.property.position); break; } this.property.Equal(Attr.Direction, targetPoint == this.caster.property.position ? this.caster.property.direction : Vec3.Normalize(targetPoint - this.caster.property.position)); SyncEventHelper.BuffAttrInitialized(this.rid); this._implement = BIBase.Create(this.id); this._implement.Init(this); }
private void DebugDrawDetectRadius(float detectRadius) { SyncEventHelper.DebugDraw(SyncEvent.DebugDrawType.WireSphere, this._behaviors.owner.property.position, Vec3.zero, null, detectRadius, Color4.blue); }
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 OnSkillAttrChanged(Skill skill, Attr attr, object oldValue, object value) { SyncEventHelper.SkillAttrChanged(this.rid, skill.id, attr, oldValue, value); }