小妖精的完美游戏教室——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

时间: 2024-11-07 15:25:58

小妖精的完美游戏教室——buff系统的相关文章

小妖精的完美游戏教室——技能系统

//================================================================//// Copyright (C) 2017 Team Saluka// All Rights Reserved//// Author:小妖精Balous////================================================================ using System.Collections;using System

小妖精的完美游戏教室——人工智能,状态机理论篇

今天也要直播魔法,求科学的! 欢迎来到小妖精Balous的完美游戏教室! 每一款好玩的游戏里面肯定有很多人工智能,例如一些帮助玩家的NPC,一些被玩家调教小怪物,更有输掉后会卖萌的Boss(小妖精真的没有玩过东方project,真的没有,小妖精甚至连这个游戏都没听说过!).那么,米娜桑想不想知道这些人工智能是如何实现的呢?那就跟着小妖精的步伐看下去吧~~但是小妖精现在的实力不是很强耶,目前还达不到妖精姐的水平,所以小妖精也只是教大家一些简单的基础.不要见怪哟. 人工智能简单来讲,是由状态跟转移条

小妖精的完美游戏教室——魔方塔防01,路径

今天也要直播魔法,求科学的! 欢迎来到小妖精Balous的完美游戏教室! 现在呢,小妖精要教大家如何制作一个游戏,是不是很激动呢?小妖精现在也是很兴奋呀.废话不多说,我们直接进入正题.作为一个游戏,必须得有策划案,所以呢,小妖精就先简单叙述下这个游戏的策划吧~ 这是个传统的塔防游戏,玩家通过建造防御塔,升级防御塔来抵御怪物的进攻.咦?这个策划看上去很low啊.但是要做一个大型游戏,得先有好的技术对不对?我们就拿这个很low的游戏入手吧.因为小妖精是美术白痴啦,所以这个游戏的防御塔都是立方体,怪物

小妖精的完美游戏教室——东方PROJECT,同人,符卡系统

//================================================================//// Copyright (C) 东方同人社// All Rights Reserved//// Author:小妖精Balous // //Summary:这次是符卡系统,这个系统能完成绝大多数符卡,算是比较通用的了////================================================================ usin

小妖精的完美游戏教室——东方PROJECT,同人,墙

//================================================================//// Copyright (C) 东方同人社// All Rights Reserved//// Author:小妖精Balous// //Summary:墙是很重要的,除非你想让玩家穿模.因为墙只有一个,所以就用静态的Singleton实现了 ////=======================================================

小妖精的完美游戏教室——东方PROJECT,同人,th12灵梦A

╮(╯▽╰)╭没办法,小妖精Balous也很讨厌学院化的教育呀,一点意义都没有. 这次就上传东方地灵殿灵梦A逻辑部分的核心代码吧,估计连老师都看不懂.动画部分的代码就不放上来了. //================================================================//// Copyright (C)// All Rights Reserved//// Author:小妖精Balous////=============================

小妖精的完美游戏教室——人工智能,A*算法,导航网络篇

//================================================================//// Copyright (C) 2017 Team Saluka// All Rights Reserved//// Author:小妖精Balous////================================================================ using System.Collections;using System

小妖精的完美游戏教室——人工智能,A*算法,实现篇

//================================================================//// Copyright (C) 2017 Team Saluka// All Rights Reserved//// Author:小妖精Balous////================================================================ using System.Collections;using System

小妖精的完美游戏教室——人工智能,A*算法,结点篇

//================================================================//// Copyright (C) 2017 Team Saluka// All Rights Reserved//// Author小妖精Balous////================================================================ using System.Collections;using System.