小妖精的完美游戏教室——buff系统
作者:小妖精Balous,未经作者允许,任何个人与单位不得将此源代码用于商业化项目
#region buff
/// <summary>
/// 是否魔法免疫,魔法免疫的生物不会受到除自己以外的生物施放的buff
/// </summary>
public bool isMagicalImmunity
{
set;
get;
}
/// <summary>
/// 添加buff前触发
/// </summary>
public event AddBuff OnAddBuff;
/// <summary>
/// 增益buff集合
/// </summary>
private LinkedList<Buff> buffList;
/// <summary>
/// 减益buff集合
/// </summary>
private LinkedList<Buff> debuffList;
/// <summary>
/// 执行所有buff效果
/// </summary>
private void buffExecute()
{
if (buffList.Count != 0)
{
for (var item = buffList.First; item != null;)
{
//如果buff有效时间结束,移除buff,否则执行buff效果
if (item.Value.activeTime <= 0)
{
item.Value.Exit();
var next = item.Next;
buffList.Remove(item);
item = next;
continue;
}
else
{
item.Value.Execute();
item.Value.activeTime -= Time.deltaTime;
}
item = item.Next;
}
}
if (debuffList.Count != 0)
{
for (var item = debuffList.First; item != null;)
{
//如果buff有效时间结束,移除buff,否则执行buff效果
if (item.Value.activeTime <= 0)
{
item.Value.Exit();
var next = item.Next;
debuffList.Remove(item);
item = next;
continue;
}
else
{
item.Value.Execute();
item.Value.activeTime -= Time.deltaTime;
}
item = item.Next;
}
}
}
/// <summary>
/// 驱散除击退型硬直外的所有buff
/// </summary>
public void dispellAll()
{
dispellBuff();
dispellDebuff();
}
/// <summary>
/// 驱散所有增益buff
/// </summary>
public void dispellBuff()
{
foreach (Buff buff in buffList) buff.Exit();
buffList.Clear();
}
/// <summary>
/// 驱散除击退型硬直外的所有减益buff
/// </summary>
public void dispellDebuff()
{
LinkedList<Buff> KnockBuffs = new LinkedList<Buff>();
foreach (Buff debuff in debuffList)
{
if (debuff.GetType() == typeof(KnockbackByHit))
{
KnockBuffs.AddLast(debuff);
continue;
}
debuff.Exit();
}
debuffList.Clear();
debuffList = KnockBuffs;
}
/// <summary>
/// 添加不能重叠的buff
/// </summary>
/// <param name="newBuff">新buff</param>
public void buffAddSingle(Buff newBuff)
{
//禁止添加击退型硬直buff
if (newBuff.GetType() == typeof(KnockbackByHit)) return;
//触发添加buff事件
if (OnAddBuff != null)
{
BuffAddingEventArgs e = new BuffAddingEventArgs(newBuff);
OnAddBuff(this, e);
//如果添加buff被撤销,不能添加
if (e.Cancel) return;
}
//如果魔法免疫,不能添加其它生物施放的buff
if (isMagicalImmunity && newBuff.source.gameObject != gameObject) return;
//如果是增益buff,添加进buffList
if (newBuff.buffType == BuffType.Buff)
{
//如果新buff已经存在,则刷新buff
if (buffList.Count != 0)
{
for (var buff = buffList.First; buff != buffList.Last.Next; buff = buff.Next)
{
//如果类型跟施法者相同,视为同一个buff
if (buff.Value.GetType() == newBuff.GetType() && buff.Value.source.gameObject == newBuff.source.gameObject)
{
//如果新buff强度更高,则刷新整个buff
if (buff.Value.level <= newBuff.level)
{
buff.Value.Exit();
buff.Value = newBuff;
newBuff.owner = this;
newBuff.Enter();
newBuff.activeTime = newBuff.initialActiveTime;
}
return;
}
}
}
buffList.AddLast(newBuff);
newBuff.owner = this;
newBuff.Enter();
newBuff.activeTime = newBuff.initialActiveTime;
}
//如果是减益buff,添加进debuffList
else
{
if (debuffList.Count != 0)
{
for (var debuff = debuffList.First; debuff != debuffList.Last.Next; debuff = debuff.Next)
{
//如果类型跟施法者相同,视为同一个buff
if (debuff.Value.GetType() == newBuff.GetType() && debuff.Value.source.gameObject == newBuff.source.gameObject)
{
//如果新buff强度更高,则刷新整个buff
if (debuff.Value.level <= newBuff.level)
{
debuff.Value.Exit();
debuff.Value = newBuff;
newBuff.owner = this;
newBuff.Enter();
newBuff.activeTime = newBuff.initialActiveTime;
}
return;
}
}
}
debuffList.AddLast(newBuff);
newBuff.owner = this;
newBuff.Enter();
newBuff.activeTime = newBuff.initialActiveTime;
}
}
/// <summary>
/// 添加可以重叠的buff
/// </summary>
/// <param name="newBuff">新buff</param>
public void buffAddMult(Buff newBuff)
{
//禁止添击退型硬直buff
if (newBuff.GetType() == typeof(KnockbackByHit)) return;
//触发添加buff事件
if (OnAddBuff != null)
{
BuffAddingEventArgs e = new BuffAddingEventArgs(newBuff);
OnAddBuff(this, e);
//如果添加buff被撤销,不能添加
if (e.Cancel) return;
}
//如果魔法免疫,不能添加其它生物施放的buff
if (isMagicalImmunity && newBuff.source.gameObject != gameObject) return;
//如果是增益buff,添加进buffList
if (newBuff.buffType == BuffType.Buff)
{
buffList.AddLast(newBuff);
newBuff.owner = this;
newBuff.Enter();
newBuff.activeTime = newBuff.initialActiveTime;
}
//如果是减益buff,添加进debuffList
else
{
debuffList.AddLast(newBuff);
newBuff.owner = this;
newBuff.Enter();
newBuff.activeTime = newBuff.initialActiveTime;
}
}
#endregion
小妖精的完美游戏教室——buff系统的更多相关文章
- 小妖精的完美游戏教室——人工智能,A*算法,引言
今天也要直播魔法,求科学的! 欢迎来到小妖精Balous的完美游戏教室! 经过前两周的学习,相信米娜桑已经对状态机有所了解了呢~虽然状态机能够实现几乎所有的人工智能,但是,在实践中,你们有没有发现,自 ...
- 小妖精的完美游戏教室——东方PROJECT,同人,符卡系统
//================================================================//// Copyright (C) 东方同人社// All Rig ...
- 小妖精的完美游戏教室——人工智能,A*算法,启发因子篇
//================================================================//// Copyright (C) 2017 Team Saluk ...
- 小妖精的完美游戏教室——人工智能,A*算法,导航网络篇
//================================================================//// Copyright (C) 2017 Team Saluk ...
- 小妖精的完美游戏教室——人工智能,A*算法,结点篇
//================================================================//// Copyright (C) 2017 Team Saluk ...
- 小妖精的完美游戏教室——人工智能,A*算法,实现篇
//================================================================//// Copyright (C) 2017 Team Saluk ...
- 小妖精的完美游戏教室——东方PROJECT,同人,墙
//================================================================//// Copyright (C) 东方同人社// All Rig ...
- 小妖精的完美游戏教室——东方PROJECT,同人,th12灵梦A
╮(╯▽╰)╭没办法,小妖精Balous也很讨厌学院化的教育呀,一点意义都没有. 这次就上传东方地灵殿灵梦A逻辑部分的核心代码吧,估计连老师都看不懂.动画部分的代码就不放上来了. //======== ...
- 小妖精的完美游戏教室——东方PROJECT,同人,子机
//================================================================//// Copyright (C)// All Rights Re ...
随机推荐
- 基于服务器AAA的实验
1.实验拓扑 2.地址分配 Device Interface IP Address Subnet Mask R0 Fa0/0 192.168.1.2 255.255.255.0 S ...
- multiprocessing
multiprocessing multiprocessing模块是跨平台版本的多进程模块. multiprocessing模块提供了一个Process类来代表一个进程对象. multiprocess ...
- 【webpack学习笔记】a05-模块热替换
什么是模块热替换? 这个功能会在程序运行过程中替换.添加或删除模块,而无需重新加载整个页面 有什么用呢? 保留在完全重新加载页面时丢失的应用程序状态. 只更新变更内容,以节省宝贵的开发时间. 调整样式 ...
- 所有不同的序列串-----LCS算法的变种
今天遇到LEETCODE的第115题: Distinct Subsequences Given a string S and a string T, count the number of disti ...
- [转载]关于laravel中表关系的一对一、一对多、多对一、多对多实践
这是转载的文章 出处:https://blog.csdn.net/weixin_38112233/article/details/79220535 作者:重新遇到 一.建表和插入测试数据 1.用户表建 ...
- static(静态)关键字
class Person{String name; //成员变量,实例变量(实例中的变量) //共享数据出现在对象之前static String country="cn"; //对 ...
- 配置jQuery环境
获取最新版jQuery 一.jq库类型说明 jQuery.js(开发版):完整无压缩,主要用于学习.开发和测试 jQuery.min.js(生产版):主要用于产品开发和项目 二.在页面引入 <s ...
- Exploit-Exercises nebule 旅行日志(二)
接着上次的路程继续在ubuntu下对漏洞的探索练习,这次是level01了 先看下level01的问题描述: 目标还是要能运行getflag这个可执行的程序,但如果直接运行是不行的,会提示: getf ...
- java 的序列化与反序列化
前言: 一直很不理解java的序列化的概念,为什么java对象的序列化要实现 Serializable的接口?或者要实现Externalizable的接口?而且Externalizable 的父类还是 ...
- shell练习题2
需求如下: 写一个shell脚本,检查指定的shell脚本是否有语法错误,若有错误,首先显示错误信息,然后提示用户输入q或Q退出脚本, 输入其他内容则直接用vim打开该shell脚本. 参考解答如下 ...