using System;
using System.Collections.Generic;
using UnityEngine;
namespace YLBattle
{
///
/// 子弹定义
///
public class CBullet
{
///
/// 子弹唯一标示符
///
private string mID = string.Empty;
///
/// 子弹隶属技能模板ID
///
private string mTID = string.Empty;
///
/// 是否为必杀技
///
private bool mIsKill = false;
///
/// 技能等级
///
private int mLevel = 0;
///
/// 是否标记目标
///
private bool mIsMarkTrg = false;
///
/// 生成序号
///
private int mSN = 0;
///
/// 技能创建者id
///
private string mCastFighter = null;
///
/// 子弹目标
///
private string mTrgFighter = null;
///
/// 当前所在位置
///
private Vector3 mCurrentPos = Vector3.zero;
///
/// 子弹目标类型
///
private EBulletTargeType mTargetType;
///
/// 当前子弹瞄准策略
///
private IBulletAIM mAimPolicy;
///
/// 当前子弹伤害目标锁定策略
///
private IBulletAIM mDamagePolicy;
///
/// 子弹目标参数
///
private object mTargetParam;
///
/// 子弹状态机
///
private CBulletFSM mFSM = null;
///
/// 发射时间
///
private long mLaunchTime = long.MinValue;
///
/// 子弹回收标志
///
private bool mIsDead = false;
///
/// 碰撞事件队列
///
private Queue mCollideQueue = new Queue();
///
/// 外部触发回传参数
///
public string mTriggerParm = string.Empty;
///
/// 构造函数
///
/// 环境上下文数据
/// 唯一编号
/// 模板编号
/// 序列号
/// 施法者
/// 目标
/// 技能等级
/// 瞄准策略
/// 瞄准附加
public CBullet(BattleParam env, string id, string tid, int sn, string caster, string target, bool ismarktrg,
int level,
IBulletAIM aimPolicy,
IBulletAIM damaPolicy,
int aimPrm = 0,
string triggerparm = "")
{
this.mID = id;
this.mTID = tid;
this.mSN = sn;
this.mCastFighter = caster;
this.mTrgFighter = target;
this.mLevel = level;
this.mIsMarkTrg = ismarktrg;
this.mCurrentPos = Vector3.zero;
this.mAimPolicy = aimPolicy;
this.mDamagePolicy = damaPolicy;
this.mTriggerParm = triggerparm;
this.mFSM = new CBulletFSM();
this.mFSM.Initialize(env, this);
}
///
/// 获取子弹状态机
///
/// 状态机对象
public CBulletFSM FSM()
{
return this.mFSM;
}
///
/// 帧周期调度
///
public void OnUpdate()
{
if (null != this.mFSM)
{
this.mFSM.OnUpdateFSM();
}
}
#region(数据相关)
///
/// 获取子弹实例ID
///
/// 实例id
public string ID()
{
return this.mID;
}
///
/// 获取模板(所属技能)数据ID
///
/// 模板数据id
public string TID()
{
return this.mTID;
}
///
/// 必杀技能
///
/// 模板数据id
public bool IsKill()
{
return this.mIsKill;
}
///
/// 获取技能等级
///
/// 技能等级
public int Level()
{
return this.mLevel;
}
///
/// 获取子弹生成序号
///
/// 序号id
public int SN()
{
return this.mSN;
}
///
/// 获取子弹发射者
///
/// 发射者id
public string Owner()
{
return this.mCastFighter;
}
///
/// 子弹瞄准的目标
///
/// 发射者id
public string AimTarget()
{
return this.mTrgFighter;
}
///
/// 瞄准策略
///
///
public IBulletAIM AimPolicy()
{
return this.mAimPolicy;
}
///
/// 伤害策略
///
///
public IBulletAIM DamagePolicy()
{
return this.mDamagePolicy;
}
///
/// 获取子弹当前所在位置
///
/// 位置信息
public Vector3 CurrentPos()
{
return this.mCurrentPos;
}
///
/// 修改子弹当前位置
///
/// 占位
public void ModifyCurrentPos(Vector3 pos)
{
this.mCurrentPos = pos;
}
///
/// 获取目标类型
///
/// 目标类型
public EBulletTargeType CurrentTargetType()
{
return this.mTargetType;
}
///
/// 获取子弹目标参数(目标ID)
///
/// 目标ID
public object CurrentTargetParam()
{
return this.mTargetParam;
}
///
/// 设置目标数据
///
/// 目标类型
/// 参数
public void SetTarget(EBulletTargeType type, object param)
{
this.mTargetType = type;
this.mTargetParam = param;
}
///
/// 设置子弹发射时间
///
/// 时间
public void SetLaunchTime(long time)
{
this.mLaunchTime = time;
}
///
/// 获取子弹发射时间
///
/// 时间
public long GetLaunchTime()
{
return this.mLaunchTime;
}
///
/// 获取碰撞事件数量
///
/// 数量值
public int HasCollideEvent()
{
return this.mCollideQueue.Count;
}
///
/// 出队碰撞事件
///
/// 没有事件返回NULL
public BulletCollideEvent CollideEvent()
{
if (this.mCollideQueue.Count == 0)
{
return null;
}
return this.mCollideQueue.Dequeue();
}
///
/// 入队碰撞事件
///
/// 事件描述
public void EnqueueCollideEvent(BulletCollideEvent bce)
{
this.mCollideQueue.Enqueue(bce);
}
///
/// 标记子弹为待回收状态
///
public void MarkBulletDead()
{
this.mIsDead = true;
}
///
/// 检测子弹是否为待回收状态
///
/// true待回收, false不用回收
public bool IsBulletDead()
{
return this.mIsDead;
}
///
/// 检测子弹是否为待回收状态
///
/// true待回收, false不用回收
public bool IsMarkTrg()
{
return this.mIsMarkTrg;
}
#endregion
}
}