void Debuff(Transform target) { if (targetEnemy) { Enemy e = target.GetComponent <Enemy>(); if (e != null) { e.TakeDamage(damage); foreach (Debuff debuff in debuffs) { BuffHelper.AddDebuff(e, debuff); } } } else if (!targetEnemy) { Turret t = target.GetComponent <Turret>(); if (t != null) { foreach (Debuff buff in buffs) { BuffHelper.AddDebuff(t, buff); } } } }
void Update() { BuffHelper.ResetDebuffs(this); BuffHelper.CheckDebuffs(this); fireCountDown -= Time.deltaTime; if (target == null) { if (useSpawner && noTarget && fireCountDown <= 0) { Spawn(); fireCountDown = 1f / fireRate; return; } if (useLaser) { if (lineRenderer.enabled) { lineRenderer.enabled = false; impactEffect.Stop(); impactLight.enabled = false; } } return; } if (!useSpawner && !childTurret) { LockOnTarget(); } if (useLaser) { Laser(); } else { if (fireCountDown <= 0) { if (useSpawner) { Spawn(); } else { Shoot(); } fireCountDown = 1f / fireRate; } } }
void Damage(Transform enemy) { Enemy e = enemy.GetComponent <Enemy>(); if (e != null) { foreach (Debuff debuff in debuffs) { BuffHelper.AddDebuff(e, debuff); } e.TakeDamage(damage, reducedByArmor); } }
public static void CheckDebuffs(Turret t) //Calls BuffHelper on every debuff in this enemies list { if (t.debuffList.Count == 0) { return; } for (int i = t.debuffList.Count - 1; i >= 0; --i) { if (t.debuffList[i].type == DebuffType.AtkSpeed) { BuffHelper.atkSpeed(t, i); } } if (t.fireRate < 0) { t.fireRate = 0; } }
public void AltShoot() { shootEffect2.Play(); Collider[] colliders = Physics.OverlapSphere(transform.position, range / 3); foreach (Collider collider in colliders) { if (collider.tag == "Turret") { Turret target = collider.transform.GetComponent <Turret>(); if (target != null) { BuffHelper.AddDebuff(target, DebuffType.AtkSpeed, 5f, 1f, altShootBuffEffect); } } } }
/// <summary> /// 结束目标单位的buff效果 /// </summary> /// <param name="name">buff名称</param> /// <param name="target">目标单位</param> public static void RemoveBuff(BuffName name, Unit target) { BuffHelper.RemoveBuff(name, target); }
/// <summary> /// 给目标单位增加buff效果 /// </summary> /// <param name="name">buff名称</param> /// <param name="target">目标单位</param> /// <param name="caster">施法单位</param> public static void AddBuff(BuffName name, Unit target, Unit caster) { BuffHelper.AddBuff(name, target, caster); }
//private (string[], int[]) LoadConfig(string configName) //{ // var data = AssetDatabase.LoadAssetAtPath<IdNameTableObject>($"Assets/{configName}.asset"); // var kArr = new string[data.Names.Length + 1]; // kArr[0] = "(空)"; // var vArr = new int[data.Names.Length + 1]; // for (int i = 0; i < data.Names.Length; i++) // { // kArr[i + 1] = data.Names[i]; // } // for (int i = 0; i < vArr.Length; i++) // { // vArr[i] = i; // } // return (kArr, vArr); //} private void OnGUI() { BuffHelper.Init(); //textColor = GUI.skin.textField.normal.textColor; //BuffHelper.buffTypeKArr = BuffHelper.buffTypes.Values.ToArray(); //BuffHelper.buffTypeVArr = BuffHelper.buffTypes.Keys.ToArray(); //BuffHelper.logicTypeKArr = BuffHelper.logicTypes.Values.ToArray(); //BuffHelper.logicTypeVArr = BuffHelper.logicTypes.Keys.ToArray(); //(BuffHelper.stateTypeKArr, BuffHelper.stateTypeVArr) = LoadConfig("状态配置"); //BuffHelper.stateTypeKArr[0] = "(请选择状态)"; //(BuffHelper.numericTypeKArr, BuffHelper.numericTypeVArr) = LoadConfig("属性配置"); //BuffHelper.numericTypeKArr[0] = "(请选择属性)"; //(BuffHelper.actionTypeKArr, BuffHelper.actionTypeVArr) = LoadConfig("动作配置"); //BuffHelper.actionTypeKArr[0] = "(请选择动作)"; //(BuffHelper.conditionTypeKArr, BuffHelper.conditionTypeVArr) = LoadConfig("条件配置"); //BuffHelper.conditionTypeKArr[0] = "(请选择条件)"; textColor = GUI.skin.textField.normal.textColor; scrollPos = EditorGUILayout.BeginScrollView(scrollPos); // 组开始 BuffConfig removeBuff = null; foreach (var item in buffConfigs) { EditorGUILayout.BeginHorizontal(/*GUILayout.Height(16)*/); { EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); GUILayout.Label("ID:"); item.Id = EditorGUILayout.IntField(item.Id, GUILayout.Width(60)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); GUILayout.Label("名称:"); item.Name = EditorGUILayout.TextField(item.Name, GUILayout.Width(60)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); GUILayout.Label("时间:"); item.Duration = EditorGUILayout.FloatField(item.Duration, GUILayout.Width(60)); GUILayout.Label(":"); EditorGUILayout.EndHorizontal(); if (item.Functions == null) { item.Functions = new List <FunctionConfig>() { new FunctionConfig() { Type = 1 } }; } FunctionConfig removeFunc = null; EditorGUILayout.BeginVertical(); foreach (var func in item.Functions) { EditorGUILayout.BeginHorizontal(); OnFuncDraw(func); { EditorGUILayout.BeginHorizontal(GUILayout.Width(30)); if (GUILayout.Button("-")) { removeFunc = (func); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndHorizontal(); } if (removeFunc != null) { item.Functions.Remove(removeFunc); } if (item.Functions.Count == 0) { removeBuff = item; } GUI.color = Color.white; { EditorGUILayout.BeginHorizontal(GUILayout.Width(30)); if (GUILayout.Button("+")) { item.Functions.Add(new FunctionConfig()); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); } if (removeBuff != null) { buffConfigs.Remove(removeBuff); } if (GUILayout.Button("+", GUILayout.Height(30))) { buffConfigs.Add(new BuffConfig() { Id = buffConfigs.Count }); } EditorGUILayout.EndScrollView(); // 组结束 }
public static void CheckDebuffs(Enemy e) //Calls BuffHelper on every debuff in this enemies list { if (e.debuffList.Count == 0) { return; } //e.debuffList.Sort(delegate(Debuff d1, Debuff d2) { return d1.time.CompareTo(d2.time); }); //sorts debuff list by time remaining (low->high) so that for example if one stun makes moveable true (by ending) the remaining stun can set it back to false for (int i = e.debuffList.Count - 1; i >= 0; --i) { switch (e.debuffList[i].type) { case DebuffType.LaserSlow: BuffHelper.LaserSlow(e, i); break; case DebuffType.Freeze: BuffHelper.Freeze(e, i); break; case DebuffType.Fear: BuffHelper.Fear(e, i); break; case DebuffType.Poison: BuffHelper.Poison(e, i); break; case DebuffType.Heal: BuffHelper.Heal(e, i); break; case DebuffType.Slow: BuffHelper.Slow(e, i); break; case DebuffType.AmplifyDmg: BuffHelper.AmplifyDmg(e, i); break; case DebuffType.ShieldBreak: BuffHelper.ShieldBreak(e, i); break; case DebuffType.DebuffLimitExceededMaximumOverdriveEngagedIsThatTheBestYouCanDoYourAttacksAreMeaningless: BuffHelper.DebuffLimit(e, i); break; } } if (e.speed < e.minSpeed && e.moveable) { e.speed = e.minSpeed; } if (e.damageMulti < 0) { e.damageMulti = 0; //don't heal from damage. } if (!e.moveable || e.enemyMovement.fear) { e.debuffLimitTimer += Time.deltaTime; } if (e.debuffLimitTimer >= e.debuffLimitThreshold) { AddDebuff(e, new Debuff(DebuffType.DebuffLimitExceededMaximumOverdriveEngagedIsThatTheBestYouCanDoYourAttacksAreMeaningless, 100f, 1f, WaveSpawner.Instance.immuneEffect)); //make enemy immune to stuns/fear e.debuffLimitTimer = 0f; } }
// BUG 2018.10.22 针对Buff之间的关系,抽象出一个接口, // 提供给外部 caster(释放buff者)给自身owner添加Buff 处理buff之间的相互关系 重叠/替换/抵消 public void AttachBuff(BaseEntity caster, int buffId) { BuffLog.Assert(!_owner.AttributeProp.IsDead(), "目标[{0}]已经死亡,无法添加Buff:[{1}]", _owner.ToDes(), buffId); if (_owner.AttributeProp.IsDead()) { return; } // 1.根据Id查找对应的ID BuffCnf newCnf = BuffHelper.FindBuffById(buffId); BuffLog.Log("Attach Buff [{0}]", newCnf.desc); // 2.检测buff之间的 关系 int count = 0; int length = _buffList.Count; for (int i = length - 1; i >= 0; i--) { BaseBuff oldBuff = _buffList[i]; if (!oldBuff.Info.CheckGroupById(newCnf.groupID)) { continue; } count++; // TODO BUG逻辑有一定的问题,如果注释掉下面一行代码 //if (count != 1) continue; int newLv = newCnf.level; // 1/0/-1 1=本buff等级更高,0=等级相等,-1=本buff等级会第一点 BuffInfo oldInfo = oldBuff.Info; int lvInfo = oldInfo.CheckLevel(newLv); if (lvInfo == BuffInfo.LESS) // 新buff等级低 { BuffLog.Log("新buff等级低 不处理,新Buff:[{0}],levell:[{1}],老Buff[{2}],level:[{3}]", newCnf.desc, newCnf.level, oldInfo.ToDes(), oldInfo.Level); continue; } if (lvInfo == BuffInfo.EQUAL && oldInfo.Multilayer) // 等级相等,可层级叠加 { BuffLog.Log("Buff:[{0}],等级相等,可层级叠加", oldInfo.ToDes()); _internal_buff_overlap(oldBuff, newCnf); } else if (lvInfo == BuffInfo.EQUAL && !oldInfo.Multilayer) // 等级相等,不可叠加 { BuffLog.Log("Buff:[{0}],等级相等,不可叠加", oldInfo.ToDes()); _internal_buff_refresh_time(oldBuff); } else // 新buff等级高 { BuffLog.Log("Buff:[{0}],新Buff等级高,覆盖", oldInfo.ToDes()); _internal_buff_overlay(caster, _buffList[i], newCnf); } _update_attr(0); //让在update中发挥作用的buff马上生效 } if (count == 0) { _internal_add_new_buff(caster, newCnf); } else if (count > 1) { LogManager.Error("Buff Group Id 超过1个数量"); } }
void Laser() { targetEnemy.TakeDamage(damageOverTime * Time.deltaTime * (float)fireRate); //for multitarget bool debuffApplied = false; //if a debuff is applied, apply it to any other targets needed bool resetTargets = false; //if the mulitargets are still valid dont update the array (targets[]) if (buildUpTime != 0) { if (currentBuildUp >= buildUpTime) { BuffHelper.AddDebuff(targetEnemy, type, debuffDuration, debuffAmount, debuffEffect); currentBuildUp = 0.001f; debuffApplied = true; } else { currentBuildUp += Time.deltaTime * (float)fireRate; } } else if (debuffAmount != 0) { BuffHelper.AddDebuff(targetEnemy, type, 0.01f, debuffAmount, null); //if buildUpTime is 0 just apply it for the minimum time } if (!lineRenderer.enabled) { lineRenderer.enabled = true; impactEffect.Play(); impactLight.enabled = true; } lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, target.position); #region multi-target if (extraTargetNumber != 0) { if (target == null) { return; } if (targets[0] == null) { resetTargets = true; } else { for (int i = 1; i < targets.Length; ++i) { if (targets[i] == null) { resetTargets = true; break; } if (Vector3.Distance(targets[i].position, targets[i - 1].position) > extraTargetFindRange) { resetTargets = true; break; } } } if (resetTargets) { for (int i = 0; i < targets.Length; ++i) { targets[i] = null; //reset targets so that the current targets aren't ignored } for (int i = 0; i < targetEnemies.Length; ++i) { targetEnemies[i] = null; } int currentTargets = 0; targets[0] = target.transform; //excluding 0 (initial target) find extra targets in range for (int i = 1; i < targets.Length; ++i) { targets[i] = newTarget(targets[i - 1], extraTargetFindRange, targets); //find a new target within range, excluding things already targeted if (targets[i] == null) { break; } currentTargets++; } //linerender update lineRenderer.positionCount = currentTargets + 2; //position 0 and 1 are already used on the starting position and the initial enemy } for (int i = 1; i < lineRenderer.positionCount - 1; ++i) //position count is no. of extra targets + initial two points (at turret and first enemy { //position count - 1 means points from first enemy to the last enemy if (targets[i] == null) { break; } lineRenderer.SetPosition(i + 1, targets[i].position); } //lineRenderer.positionCount = //number of targets //make enemies take damage (not initial target (already took damage)) for (int i = 1; i < targets.Length; ++i) { if (targets[i] == null) { break; } targetEnemies[i] = targets[i].GetComponent <Enemy>(); targetEnemies[i].TakeDamage(damageOverTime * Time.deltaTime * (float)fireRate); if (debuffApplied && debuffDuration != 0) //don't keep track of build up on all enemies just apply it to all when one is affected { BuffHelper.AddDebuff(targetEnemies[i], type, debuffDuration, debuffAmount, debuffEffect); } else if (debuffDuration == 0) { if (debuffAmount != 0) { BuffHelper.AddDebuff(targetEnemy, type, 0.01f, debuffAmount, null); } } } } else { lineRenderer.positionCount = 2; } #endregion Vector3 dir = firePoint.position - target.position; //TODO: add effect to all extra tagets impactEffect.transform.position = target.position + dir.normalized; impactEffect.transform.rotation = Quaternion.LookRotation(dir); }
private void Update() { BuffHelper.ResetDebuffs(enemy); BuffHelper.CheckDebuffs(enemy); Move(); }