小妖精的完美游戏教室——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 ...
随机推荐
- PPT母版制作
选择母版 首先,去iSlide官网下载iSlide,下载iSlide后,power point的菜单栏会自动出现iSilde图标(如下图). 打开iSlide这一栏,点击“图示库”,会弹出一个窗口,就 ...
- Vasya And Password(CodeForces - 1051A)
Vasya came up with a password to register for EatForces — a string ss. The password in EatForces sho ...
- Linux VPS自动定时备份网站文件和MYSQL数据库到FTP空间(LNMP)
如果我们网站更新不是很频繁,我们可以定期手动进行备份网站文件和MYSQL数据库导出.如果我们网站数据更新频繁,且数据尤为重要,建议要采用定期自动 备份,至少需要多备份数据,无论我们选择何种优秀的VPS ...
- numpy 库使用
numpy 库简单使用 一.numpy库简介 Python标准库中提供了一个array类型,用于保存数组类型的数据,然而这个类型不支持多维数据,不适合数值运算.作为Python的第三方库numpy便有 ...
- 使用bitsadmin.exe 下载文件,配合bcn.bat玩出更多的花样~~
bitsadmin的简单介绍与基本用法: bitsadmin.exe 可以用来在windows 命令行下下载文件.bitsadmin是windows 后台智能传输服务的一个工具,windows 的自动 ...
- git 合并分支到master
git 合并分支到master 假如我们现在在dev分支上,刚开发完项目,执行了下列命令 git add .git commit -m ‘dev'git push -u origin dev 然后 ...
- Django在根据models生成数据库表时报错: __init__() missing 1 required positional argument: 'on_delete'
原因: 在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:TypeError: __init__() missing ...
- Oracle误删除数据和表的恢复办法包括truncate
在工作中我们操作数据库的时候经常会发生一个不该发生的问题:用户意外的删除一个非常重要的表或者是表中的数据而且没有备份,需要尽快的恢复,以下就是解决的办法: 主要是利用Oracle回收站的闪回特性ora ...
- javascript 对象数组排序(按照科目级次)
需求 从后台获取的数据是这样的 上帝要这样的 背景 从后台获取到表格数据,然后填充到excel.当然是用js来填充的.js 本身的数组具有sort()功能.但是是针对 ...
- WEB学习笔记6-正确闭合HTML标签
自闭合标签(空元素,即不能包含任何内容,这些元素对应的HTML标签成为自闭合标签) area/base/br/col/command/embed/hr/img/input/keygen/link/me ...