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

//================================================================
//
// Copyright (C) 2017 Team Saluka
// All Rights Reserved
//
// Author:小妖精Balous
//
//================================================================

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Saruka
{
/// <summary>
/// 技能系统
/// </summary>
public class SkillSystem
{
/// <summary>
/// 拥有本技能系统的生物
/// </summary>
Creature owner;

/// <summary>
/// 是否进入后摇
/// </summary>
bool isAfterComplete;

/// <summary>
/// 技能集合
/// </summary>
public Skill[] skillList;

/// <summary>
/// 构造器
/// </summary>
/// <param name="owner">拥有本技能系统的生物</param>
public SkillSystem(Creature _owner)
{
owner = _owner;
}

/// <summary>
/// 正在施放的技能
/// </summary>
public Skill skillOnCasting
{
private set;
get;
}

/// <summary>
/// 取消正在施放的技能
/// </summary>
public void CancelSkill()
{
if (skillOnCasting != null)
{
skillOnCasting.Exit(owner);
//技能开始冷却
skillOnCasting.coldDownTime = skillOnCasting.totalColdDownTime;

skillOnCasting = null;
}
}

/// <summary>
/// 施放技能
/// </summary>
/// <param name="index">要施放的技能在技能集合中的索引</param>
/// <param name="force">是否强制施放</param>
public void CastSkill(int index, bool isForce = false)
{
//判断生物是否处于打断状态
if (owner.interrupt > 0) return;
//判断冷却时间
if (skillList[index].coldDownTime > 0) return;
//判断魔法值是否足够
if (owner.mana < skillList[index].manaCost) return;

//判断是否有技能在施放中
if (skillOnCasting != null)
{
if (isForce)
{
skillOnCasting.Exit(owner);
//技能开始冷却
skillOnCasting.coldDownTime = skillOnCasting.totalColdDownTime;
}
else return;
}

skillOnCasting = skillList[index];
//消耗魔法值
owner.mana -= skillOnCasting.manaCost;
//记录技能施放时间
skillOnCasting.castingTime = skillOnCasting.totalCastingTime;
//初始化后摇
isAfterComplete = false;
skillOnCasting.afterCompleteTime = skillOnCasting.totalAfterCompleteTime;
//调用Enter
skillOnCasting.Enter(owner);
}

/// <summary>
/// 刷新技能状态,在Update中调用
/// </summary>
public void Refresh()
{
//刷新技能冷却时间
if (skillList != null) foreach (Skill skill in skillList) skill.coldDownTime -= Time.deltaTime;

//如果有技能正在施放
if (skillOnCasting != null)
{
//如果技能被打断
if (owner.interrupt > 0)
{
skillOnCasting.Exit(owner);
//技能开始冷却
skillOnCasting.coldDownTime = skillOnCasting.totalColdDownTime;

skillOnCasting = null;
return;
}

//如果没有进入后摇
if (!isAfterComplete)
{
//刷新技能施放时间
skillOnCasting.castingTime -= Time.deltaTime;
//如果技能施放完毕
if (skillOnCasting.castingTime <= 0.0f)
{
skillOnCasting.Complete(owner);
isAfterComplete = true;
}
//如果技能没有施放完毕
else skillOnCasting.Execute(owner);
}
//如果进入后摇
if (isAfterComplete)
{
//刷新后摇时间
skillOnCasting.afterCompleteTime -= Time.deltaTime;
//如果后摇结束
if (skillOnCasting.afterCompleteTime <= 0.0f)
{
skillOnCasting.Exit(owner);
//技能开始冷却
skillOnCasting.coldDownTime = skillOnCasting.totalColdDownTime;

skillOnCasting = null;
}
//如果后摇没有结束
else skillOnCasting.AfterComplete(owner);
}
}
}
}

/// <summary>
/// 技能
/// </summary>
public abstract class Skill
{
public Skill() { }
public Skill(int _level, float _totalColdDownTime, float _totalCastingTime, float _totalAfterCompleteTime, int _manaCost)
{
level = _level;
totalColdDownTime = _totalColdDownTime;
totalCastingTime = _totalCastingTime;
totalAfterCompleteTime = _totalAfterCompleteTime;
manaCost = _manaCost;
}

/// <summary>
/// 技能等级
/// </summary>
public int level;

/// <summary>
/// 全部冷却时间
/// </summary>
public float totalColdDownTime;
/// <summary>
/// 当前冷却时间
/// </summary>
public float coldDownTime
{
set
{
if (value < 0.0f) _coldDownTime = 0.0f;
else if (value > totalColdDownTime) _coldDownTime = totalColdDownTime;
else _coldDownTime = value;
}
get{ return _coldDownTime; }
}
private float _coldDownTime;

/// <summary>
/// 当前后摇时间
/// </summary>
public float afterCompleteTime
{
set;
get;
}
/// <summary>
/// 全部后摇时间
/// </summary>
public float totalAfterCompleteTime = 0;

/// <summary>
/// 魔法值消耗
/// </summary>
public int manaCost;

/// <summary>
/// 全部施放时间
/// </summary>
public float totalCastingTime;
/// <summary>
/// 当前施放时间
/// </summary>
public float castingTime
{
set;
get;
}

public virtual void Enter(Creature owner) { }
public virtual void Execute(Creature owner) { }
public abstract void Complete(Creature owner);
public virtual void AfterComplete(Creature owner) { }
public virtual void Exit(Creature owner) { }
}
}

时间: 2024-10-11 18:25:14

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

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

作者:小妖精Balous,未经作者允许,任何个人与单位不得将此源代码用于商业化项目 #region buff /// <summary> /// 是否魔法免疫,魔法免疫的生物不会受到除自己以外的生物施放的buff /// </summary> public bool isMagicalImmunity { set; get; } /// <summary> /// 添加buff前触发 /// </summary> public event AddBuff O

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

今天也要直播魔法,求科学的! 欢迎来到小妖精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.